x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / scsi / bnx2i / bnx2i.h
blobc73bbcb63c02049b1147b98829d8a3e4b4c8ebf5
1 /* bnx2i.h: Broadcom NetXtreme II iSCSI driver.
3 * Copyright (c) 2006 - 2013 Broadcom Corporation
4 * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
5 * Copyright (c) 2007, 2008 Mike Christie
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation.
11 * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
12 * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
15 #ifndef _BNX2I_H_
16 #define _BNX2I_H_
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
21 #include <linux/errno.h>
22 #include <linux/pci.h>
23 #include <linux/spinlock.h>
24 #include <linux/interrupt.h>
25 #include <linux/delay.h>
26 #include <linux/sched.h>
27 #include <linux/in.h>
28 #include <linux/kfifo.h>
29 #include <linux/netdevice.h>
30 #include <linux/completion.h>
31 #include <linux/kthread.h>
32 #include <linux/cpu.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <scsi/scsi_device.h>
36 #include <scsi/scsi_eh.h>
37 #include <scsi/scsi_host.h>
38 #include <scsi/scsi.h>
39 #include <scsi/iscsi_proto.h>
40 #include <scsi/libiscsi.h>
41 #include <scsi/scsi_transport_iscsi.h>
43 #include "../../net/ethernet/broadcom/cnic_if.h"
44 #include "57xx_iscsi_hsi.h"
45 #include "57xx_iscsi_constants.h"
47 #include "../../net/ethernet/broadcom/bnx2x/bnx2x_mfw_req.h"
49 #define BNX2_ISCSI_DRIVER_NAME "bnx2i"
51 #define BNX2I_MAX_ADAPTERS 8
53 #define ISCSI_MAX_CONNS_PER_HBA 128
54 #define ISCSI_MAX_SESS_PER_HBA ISCSI_MAX_CONNS_PER_HBA
55 #define ISCSI_MAX_CMDS_PER_SESS 128
57 /* Total active commands across all connections supported by devices */
58 #define ISCSI_MAX_CMDS_PER_HBA_5708 (28 * (ISCSI_MAX_CMDS_PER_SESS - 1))
59 #define ISCSI_MAX_CMDS_PER_HBA_5709 (128 * (ISCSI_MAX_CMDS_PER_SESS - 1))
60 #define ISCSI_MAX_CMDS_PER_HBA_57710 (256 * (ISCSI_MAX_CMDS_PER_SESS - 1))
62 #define ISCSI_MAX_BDS_PER_CMD 32
64 #define MAX_PAGES_PER_CTRL_STRUCT_POOL 8
65 #define BNX2I_RESERVED_SLOW_PATH_CMD_SLOTS 4
67 #define BNX2X_DB_SHIFT 3
69 /* 5706/08 hardware has limit on maximum buffer size per BD it can handle */
70 #define MAX_BD_LENGTH 65535
71 #define BD_SPLIT_SIZE 32768
73 /* min, max & default values for SQ/RQ/CQ size, configurable via' modparam */
74 #define BNX2I_SQ_WQES_MIN 16
75 #define BNX2I_570X_SQ_WQES_MAX 128
76 #define BNX2I_5770X_SQ_WQES_MAX 512
77 #define BNX2I_570X_SQ_WQES_DEFAULT 128
78 #define BNX2I_5770X_SQ_WQES_DEFAULT 128
80 #define BNX2I_570X_CQ_WQES_MAX 128
81 #define BNX2I_5770X_CQ_WQES_MAX 512
83 #define BNX2I_RQ_WQES_MIN 16
84 #define BNX2I_RQ_WQES_MAX 32
85 #define BNX2I_RQ_WQES_DEFAULT 16
87 /* CCELLs per conn */
88 #define BNX2I_CCELLS_MIN 16
89 #define BNX2I_CCELLS_MAX 96
90 #define BNX2I_CCELLS_DEFAULT 64
92 #define ITT_INVALID_SIGNATURE 0xFFFF
94 #define ISCSI_CMD_CLEANUP_TIMEOUT 100
96 #define BNX2I_CONN_CTX_BUF_SIZE 16384
98 #define BNX2I_SQ_WQE_SIZE 64
99 #define BNX2I_RQ_WQE_SIZE 256
100 #define BNX2I_CQE_SIZE 64
102 #define MB_KERNEL_CTX_SHIFT 8
103 #define MB_KERNEL_CTX_SIZE (1 << MB_KERNEL_CTX_SHIFT)
105 #define CTX_SHIFT 7
106 #define GET_CID_NUM(cid_addr) ((cid_addr) >> CTX_SHIFT)
108 #define CTX_OFFSET 0x10000
109 #define MAX_CID_CNT 0x4000
111 #define BNX2I_570X_PAGE_SIZE_DEFAULT 4096
113 /* 5709 context registers */
114 #define BNX2_MQ_CONFIG2 0x00003d00
115 #define BNX2_MQ_CONFIG2_CONT_SZ (0x7L<<4)
116 #define BNX2_MQ_CONFIG2_FIRST_L4L5 (0x1fL<<8)
118 /* 57710's BAR2 is mapped to doorbell registers */
119 #define BNX2X_DOORBELL_PCI_BAR 2
120 #define BNX2X_MAX_CQS 8
122 #define CNIC_ARM_CQE 1
123 #define CNIC_ARM_CQE_FP 2
124 #define CNIC_DISARM_CQE 0
126 #define REG_RD(__hba, offset) \
127 readl(__hba->regview + offset)
128 #define REG_WR(__hba, offset, val) \
129 writel(val, __hba->regview + offset)
131 #ifdef CONFIG_32BIT
132 #define GET_STATS_64(__hba, dst, field) \
133 do { \
134 spin_lock_bh(&__hba->stat_lock); \
135 dst->field##_lo = __hba->stats.field##_lo; \
136 dst->field##_hi = __hba->stats.field##_hi; \
137 spin_unlock_bh(&__hba->stat_lock); \
138 } while (0)
140 #define ADD_STATS_64(__hba, field, len) \
141 do { \
142 if (spin_trylock(&__hba->stat_lock)) { \
143 if (__hba->stats.field##_lo + len < \
144 __hba->stats.field##_lo) \
145 __hba->stats.field##_hi++; \
146 __hba->stats.field##_lo += len; \
147 spin_unlock(&__hba->stat_lock); \
149 } while (0)
151 #else
152 #define GET_STATS_64(__hba, dst, field) \
153 do { \
154 u64 val, *out; \
156 val = __hba->bnx2i_stats.field; \
157 out = (u64 *)&__hba->stats.field##_lo; \
158 *out = cpu_to_le64(val); \
159 out = (u64 *)&dst->field##_lo; \
160 *out = cpu_to_le64(val); \
161 } while (0)
163 #define ADD_STATS_64(__hba, field, len) \
164 do { \
165 __hba->bnx2i_stats.field += len; \
166 } while (0)
167 #endif
170 * struct generic_pdu_resc - login pdu resource structure
172 * @req_buf: driver buffer used to stage payload associated with
173 * the login request
174 * @req_dma_addr: dma address for iscsi login request payload buffer
175 * @req_buf_size: actual login request payload length
176 * @req_wr_ptr: pointer into login request buffer when next data is
177 * to be written
178 * @resp_hdr: iscsi header where iscsi login response header is to
179 * be recreated
180 * @resp_buf: buffer to stage login response payload
181 * @resp_dma_addr: login response payload buffer dma address
182 * @resp_buf_size: login response paylod length
183 * @resp_wr_ptr: pointer into login response buffer when next data is
184 * to be written
185 * @req_bd_tbl: iscsi login request payload BD table
186 * @req_bd_dma: login request BD table dma address
187 * @resp_bd_tbl: iscsi login response payload BD table
188 * @resp_bd_dma: login request BD table dma address
190 * following structure defines buffer info for generic pdus such as iSCSI Login,
191 * Logout and NOP
193 struct generic_pdu_resc {
194 char *req_buf;
195 dma_addr_t req_dma_addr;
196 u32 req_buf_size;
197 char *req_wr_ptr;
198 struct iscsi_hdr resp_hdr;
199 char *resp_buf;
200 dma_addr_t resp_dma_addr;
201 u32 resp_buf_size;
202 char *resp_wr_ptr;
203 char *req_bd_tbl;
204 dma_addr_t req_bd_dma;
205 char *resp_bd_tbl;
206 dma_addr_t resp_bd_dma;
211 * struct bd_resc_page - tracks DMA'able memory allocated for BD tables
213 * @link: list head to link elements
214 * @max_ptrs: maximun pointers that can be stored in this page
215 * @num_valid: number of pointer valid in this page
216 * @page: base addess for page pointer array
218 * structure to track DMA'able memory allocated for command BD tables
220 struct bd_resc_page {
221 struct list_head link;
222 u32 max_ptrs;
223 u32 num_valid;
224 void *page[1];
229 * struct io_bdt - I/O buffer destricptor table
231 * @bd_tbl: BD table's virtual address
232 * @bd_tbl_dma: BD table's dma address
233 * @bd_valid: num valid BD entries
235 * IO BD table
237 struct io_bdt {
238 struct iscsi_bd *bd_tbl;
239 dma_addr_t bd_tbl_dma;
240 u16 bd_valid;
245 * bnx2i_cmd - iscsi command structure
247 * @hdr: iSCSI header
248 * @conn: iscsi_conn pointer
249 * @scsi_cmd: SCSI-ML task pointer corresponding to this iscsi cmd
250 * @sg: SG list
251 * @io_tbl: buffer descriptor (BD) table
252 * @bd_tbl_dma: buffer descriptor (BD) table's dma address
253 * @req: bnx2i specific command request struct
255 struct bnx2i_cmd {
256 struct iscsi_hdr hdr;
257 struct bnx2i_conn *conn;
258 struct scsi_cmnd *scsi_cmd;
259 struct scatterlist *sg;
260 struct io_bdt io_tbl;
261 dma_addr_t bd_tbl_dma;
262 struct bnx2i_cmd_request req;
267 * struct bnx2i_conn - iscsi connection structure
269 * @cls_conn: pointer to iscsi cls conn
270 * @hba: adapter structure pointer
271 * @iscsi_conn_cid: iscsi conn id
272 * @fw_cid: firmware iscsi context id
273 * @ep: endpoint structure pointer
274 * @gen_pdu: login/nopout/logout pdu resources
275 * @violation_notified: bit mask used to track iscsi error/warning messages
276 * already printed out
277 * @work_cnt: keeps track of the number of outstanding work
279 * iSCSI connection structure
281 struct bnx2i_conn {
282 struct iscsi_cls_conn *cls_conn;
283 struct bnx2i_hba *hba;
284 struct completion cmd_cleanup_cmpl;
286 u32 iscsi_conn_cid;
287 #define BNX2I_CID_RESERVED 0x5AFF
288 u32 fw_cid;
290 struct timer_list poll_timer;
292 * Queue Pair (QP) related structure elements.
294 struct bnx2i_endpoint *ep;
297 * Buffer for login negotiation process
299 struct generic_pdu_resc gen_pdu;
300 u64 violation_notified;
302 atomic_t work_cnt;
308 * struct iscsi_cid_queue - Per adapter iscsi cid queue
310 * @cid_que_base: queue base memory
311 * @cid_que: queue memory pointer
312 * @cid_q_prod_idx: produce index
313 * @cid_q_cons_idx: consumer index
314 * @cid_q_max_idx: max index. used to detect wrap around condition
315 * @cid_free_cnt: queue size
316 * @conn_cid_tbl: iscsi cid to conn structure mapping table
318 * Per adapter iSCSI CID Queue
320 struct iscsi_cid_queue {
321 void *cid_que_base;
322 u32 *cid_que;
323 u32 cid_q_prod_idx;
324 u32 cid_q_cons_idx;
325 u32 cid_q_max_idx;
326 u32 cid_free_cnt;
327 struct bnx2i_conn **conn_cid_tbl;
331 struct bnx2i_stats_info {
332 u64 rx_pdus;
333 u64 rx_bytes;
334 u64 tx_pdus;
335 u64 tx_bytes;
340 * struct bnx2i_hba - bnx2i adapter structure
342 * @link: list head to link elements
343 * @cnic: pointer to cnic device
344 * @pcidev: pointer to pci dev
345 * @netdev: pointer to netdev structure
346 * @regview: mapped PCI register space
347 * @age: age, incremented by every recovery
348 * @cnic_dev_type: cnic device type, 5706/5708/5709/57710
349 * @mail_queue_access: mailbox queue access mode, applicable to 5709 only
350 * @reg_with_cnic: indicates whether the device is register with CNIC
351 * @adapter_state: adapter state, UP, GOING_DOWN, LINK_DOWN
352 * @mtu_supported: Ethernet MTU supported
353 * @shost: scsi host pointer
354 * @max_sqes: SQ size
355 * @max_rqes: RQ size
356 * @max_cqes: CQ size
357 * @num_ccell: number of command cells per connection
358 * @ofld_conns_active: active connection list
359 * @eh_wait: wait queue for the endpoint to shutdown
360 * @max_active_conns: max offload connections supported by this device
361 * @cid_que: iscsi cid queue
362 * @ep_rdwr_lock: read / write lock to synchronize various ep lists
363 * @ep_ofld_list: connection list for pending offload completion
364 * @ep_active_list: connection list for active offload endpoints
365 * @ep_destroy_list: connection list for pending offload completion
366 * @mp_bd_tbl: BD table to be used with middle path requests
367 * @mp_bd_dma: DMA address of 'mp_bd_tbl' memory buffer
368 * @dummy_buffer: Dummy buffer to be used with zero length scsicmd reqs
369 * @dummy_buf_dma: DMA address of 'dummy_buffer' memory buffer
370 * @lock: lock to synchonize access to hba structure
371 * @hba_shutdown_tmo: Timeout value to shutdown each connection
372 * @conn_teardown_tmo: Timeout value to tear down each connection
373 * @conn_ctx_destroy_tmo: Timeout value to destroy context of each connection
374 * @pci_did: PCI device ID
375 * @pci_vid: PCI vendor ID
376 * @pci_sdid: PCI subsystem device ID
377 * @pci_svid: PCI subsystem vendor ID
378 * @pci_func: PCI function number in system pci tree
379 * @pci_devno: PCI device number in system pci tree
380 * @num_wqe_sent: statistic counter, total wqe's sent
381 * @num_cqe_rcvd: statistic counter, total cqe's received
382 * @num_intr_claimed: statistic counter, total interrupts claimed
383 * @link_changed_count: statistic counter, num of link change notifications
384 * received
385 * @ipaddr_changed_count: statistic counter, num times IP address changed while
386 * at least one connection is offloaded
387 * @num_sess_opened: statistic counter, total num sessions opened
388 * @num_conn_opened: statistic counter, total num conns opened on this hba
389 * @ctx_ccell_tasks: captures number of ccells and tasks supported by
390 * currently offloaded connection, used to decode
391 * context memory
392 * @stat_lock: spin lock used by the statistic collector (32 bit)
393 * @stats: local iSCSI statistic collection place holder
395 * Adapter Data Structure
397 struct bnx2i_hba {
398 struct list_head link;
399 struct cnic_dev *cnic;
400 struct pci_dev *pcidev;
401 struct net_device *netdev;
402 void __iomem *regview;
403 resource_size_t reg_base;
405 u32 age;
406 unsigned long cnic_dev_type;
407 #define BNX2I_NX2_DEV_5706 0x0
408 #define BNX2I_NX2_DEV_5708 0x1
409 #define BNX2I_NX2_DEV_5709 0x2
410 #define BNX2I_NX2_DEV_57710 0x3
411 u32 mail_queue_access;
412 #define BNX2I_MQ_KERNEL_MODE 0x0
413 #define BNX2I_MQ_KERNEL_BYPASS_MODE 0x1
414 #define BNX2I_MQ_BIN_MODE 0x2
415 unsigned long reg_with_cnic;
416 #define BNX2I_CNIC_REGISTERED 1
418 unsigned long adapter_state;
419 #define ADAPTER_STATE_UP 0
420 #define ADAPTER_STATE_GOING_DOWN 1
421 #define ADAPTER_STATE_LINK_DOWN 2
422 #define ADAPTER_STATE_INIT_FAILED 31
423 unsigned int mtu_supported;
424 #define BNX2I_MAX_MTU_SUPPORTED 9000
426 struct Scsi_Host *shost;
428 u32 max_sqes;
429 u32 max_rqes;
430 u32 max_cqes;
431 u32 num_ccell;
433 int ofld_conns_active;
434 wait_queue_head_t eh_wait;
436 int max_active_conns;
437 struct iscsi_cid_queue cid_que;
439 rwlock_t ep_rdwr_lock;
440 struct list_head ep_ofld_list;
441 struct list_head ep_active_list;
442 struct list_head ep_destroy_list;
445 * BD table to be used with MP (Middle Path requests.
447 char *mp_bd_tbl;
448 dma_addr_t mp_bd_dma;
449 char *dummy_buffer;
450 dma_addr_t dummy_buf_dma;
452 spinlock_t lock; /* protects hba structure access */
453 struct mutex net_dev_lock;/* sync net device access */
455 int hba_shutdown_tmo;
456 int conn_teardown_tmo;
457 int conn_ctx_destroy_tmo;
459 * PCI related info.
461 u16 pci_did;
462 u16 pci_vid;
463 u16 pci_sdid;
464 u16 pci_svid;
465 u16 pci_func;
466 u16 pci_devno;
469 * Following are a bunch of statistics useful during development
470 * and later stage for score boarding.
472 u32 num_wqe_sent;
473 u32 num_cqe_rcvd;
474 u32 num_intr_claimed;
475 u32 link_changed_count;
476 u32 ipaddr_changed_count;
477 u32 num_sess_opened;
478 u32 num_conn_opened;
479 unsigned int ctx_ccell_tasks;
481 #ifdef CONFIG_32BIT
482 spinlock_t stat_lock;
483 #endif
484 struct bnx2i_stats_info bnx2i_stats;
485 struct iscsi_stats_info stats;
489 /*******************************************************************************
490 * QP [ SQ / RQ / CQ ] info.
491 ******************************************************************************/
494 * SQ/RQ/CQ generic structure definition
496 struct sqe {
497 u8 sqe_byte[BNX2I_SQ_WQE_SIZE];
500 struct rqe {
501 u8 rqe_byte[BNX2I_RQ_WQE_SIZE];
504 struct cqe {
505 u8 cqe_byte[BNX2I_CQE_SIZE];
509 enum {
510 #if defined(__LITTLE_ENDIAN)
511 CNIC_EVENT_COAL_INDEX = 0x0,
512 CNIC_SEND_DOORBELL = 0x4,
513 CNIC_EVENT_CQ_ARM = 0x7,
514 CNIC_RECV_DOORBELL = 0x8
515 #elif defined(__BIG_ENDIAN)
516 CNIC_EVENT_COAL_INDEX = 0x2,
517 CNIC_SEND_DOORBELL = 0x6,
518 CNIC_EVENT_CQ_ARM = 0x4,
519 CNIC_RECV_DOORBELL = 0xa
520 #endif
525 * CQ DB
527 struct bnx2x_iscsi_cq_pend_cmpl {
528 /* CQ producer, updated by Ustorm */
529 u16 ustrom_prod;
530 /* CQ pending completion counter */
531 u16 pend_cntr;
535 struct bnx2i_5771x_cq_db {
536 struct bnx2x_iscsi_cq_pend_cmpl qp_pend_cmpl[BNX2X_MAX_CQS];
537 /* CQ pending completion ITT array */
538 u16 itt[BNX2X_MAX_CQS];
539 /* Cstorm CQ sequence to notify array, updated by driver */;
540 u16 sqn[BNX2X_MAX_CQS];
541 u32 reserved[4] /* 16 byte allignment */;
545 struct bnx2i_5771x_sq_rq_db {
546 u16 prod_idx;
547 u8 reserved0[62]; /* Pad structure size to 64 bytes */
551 struct bnx2i_5771x_dbell_hdr {
552 u8 header;
553 /* 1 for rx doorbell, 0 for tx doorbell */
554 #define B577XX_DOORBELL_HDR_RX (0x1<<0)
555 #define B577XX_DOORBELL_HDR_RX_SHIFT 0
556 /* 0 for normal doorbell, 1 for advertise wnd doorbell */
557 #define B577XX_DOORBELL_HDR_DB_TYPE (0x1<<1)
558 #define B577XX_DOORBELL_HDR_DB_TYPE_SHIFT 1
559 /* rdma tx only: DPM transaction size specifier (64/128/256/512B) */
560 #define B577XX_DOORBELL_HDR_DPM_SIZE (0x3<<2)
561 #define B577XX_DOORBELL_HDR_DPM_SIZE_SHIFT 2
562 /* connection type */
563 #define B577XX_DOORBELL_HDR_CONN_TYPE (0xF<<4)
564 #define B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT 4
567 struct bnx2i_5771x_dbell {
568 struct bnx2i_5771x_dbell_hdr dbell;
569 u8 pad[3];
574 * struct qp_info - QP (share queue region) atrributes structure
576 * @ctx_base: ioremapped pci register base to access doorbell register
577 * pertaining to this offloaded connection
578 * @sq_virt: virtual address of send queue (SQ) region
579 * @sq_phys: DMA address of SQ memory region
580 * @sq_mem_size: SQ size
581 * @sq_prod_qe: SQ producer entry pointer
582 * @sq_cons_qe: SQ consumer entry pointer
583 * @sq_first_qe: virtual address of first entry in SQ
584 * @sq_last_qe: virtual address of last entry in SQ
585 * @sq_prod_idx: SQ producer index
586 * @sq_cons_idx: SQ consumer index
587 * @sqe_left: number sq entry left
588 * @sq_pgtbl_virt: page table describing buffer consituting SQ region
589 * @sq_pgtbl_phys: dma address of 'sq_pgtbl_virt'
590 * @sq_pgtbl_size: SQ page table size
591 * @cq_virt: virtual address of completion queue (CQ) region
592 * @cq_phys: DMA address of RQ memory region
593 * @cq_mem_size: CQ size
594 * @cq_prod_qe: CQ producer entry pointer
595 * @cq_cons_qe: CQ consumer entry pointer
596 * @cq_first_qe: virtual address of first entry in CQ
597 * @cq_last_qe: virtual address of last entry in CQ
598 * @cq_prod_idx: CQ producer index
599 * @cq_cons_idx: CQ consumer index
600 * @cqe_left: number cq entry left
601 * @cqe_size: size of each CQ entry
602 * @cqe_exp_seq_sn: next expected CQE sequence number
603 * @cq_pgtbl_virt: page table describing buffer consituting CQ region
604 * @cq_pgtbl_phys: dma address of 'cq_pgtbl_virt'
605 * @cq_pgtbl_size: CQ page table size
606 * @rq_virt: virtual address of receive queue (RQ) region
607 * @rq_phys: DMA address of RQ memory region
608 * @rq_mem_size: RQ size
609 * @rq_prod_qe: RQ producer entry pointer
610 * @rq_cons_qe: RQ consumer entry pointer
611 * @rq_first_qe: virtual address of first entry in RQ
612 * @rq_last_qe: virtual address of last entry in RQ
613 * @rq_prod_idx: RQ producer index
614 * @rq_cons_idx: RQ consumer index
615 * @rqe_left: number rq entry left
616 * @rq_pgtbl_virt: page table describing buffer consituting RQ region
617 * @rq_pgtbl_phys: dma address of 'rq_pgtbl_virt'
618 * @rq_pgtbl_size: RQ page table size
620 * queue pair (QP) is a per connection shared data structure which is used
621 * to send work requests (SQ), receive completion notifications (CQ)
622 * and receive asynchoronous / scsi sense info (RQ). 'qp_info' structure
623 * below holds queue memory, consumer/producer indexes and page table
624 * information
626 struct qp_info {
627 void __iomem *ctx_base;
628 #define DPM_TRIGER_TYPE 0x40
630 #define BNX2I_570x_QUE_DB_SIZE 0
631 #define BNX2I_5771x_QUE_DB_SIZE 16
632 struct sqe *sq_virt;
633 dma_addr_t sq_phys;
634 u32 sq_mem_size;
636 struct sqe *sq_prod_qe;
637 struct sqe *sq_cons_qe;
638 struct sqe *sq_first_qe;
639 struct sqe *sq_last_qe;
640 u16 sq_prod_idx;
641 u16 sq_cons_idx;
642 u32 sqe_left;
644 void *sq_pgtbl_virt;
645 dma_addr_t sq_pgtbl_phys;
646 u32 sq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
648 struct cqe *cq_virt;
649 dma_addr_t cq_phys;
650 u32 cq_mem_size;
652 struct cqe *cq_prod_qe;
653 struct cqe *cq_cons_qe;
654 struct cqe *cq_first_qe;
655 struct cqe *cq_last_qe;
656 u16 cq_prod_idx;
657 u16 cq_cons_idx;
658 u32 cqe_left;
659 u32 cqe_size;
660 u32 cqe_exp_seq_sn;
662 void *cq_pgtbl_virt;
663 dma_addr_t cq_pgtbl_phys;
664 u32 cq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
666 struct rqe *rq_virt;
667 dma_addr_t rq_phys;
668 u32 rq_mem_size;
670 struct rqe *rq_prod_qe;
671 struct rqe *rq_cons_qe;
672 struct rqe *rq_first_qe;
673 struct rqe *rq_last_qe;
674 u16 rq_prod_idx;
675 u16 rq_cons_idx;
676 u32 rqe_left;
678 void *rq_pgtbl_virt;
679 dma_addr_t rq_pgtbl_phys;
680 u32 rq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
686 * CID handles
688 struct ep_handles {
689 u32 fw_cid;
690 u32 drv_iscsi_cid;
691 u16 pg_cid;
692 u16 rsvd;
696 enum {
697 EP_STATE_IDLE = 0x0,
698 EP_STATE_PG_OFLD_START = 0x1,
699 EP_STATE_PG_OFLD_COMPL = 0x2,
700 EP_STATE_OFLD_START = 0x4,
701 EP_STATE_OFLD_COMPL = 0x8,
702 EP_STATE_CONNECT_START = 0x10,
703 EP_STATE_CONNECT_COMPL = 0x20,
704 EP_STATE_ULP_UPDATE_START = 0x40,
705 EP_STATE_ULP_UPDATE_COMPL = 0x80,
706 EP_STATE_DISCONN_START = 0x100,
707 EP_STATE_DISCONN_COMPL = 0x200,
708 EP_STATE_CLEANUP_START = 0x400,
709 EP_STATE_CLEANUP_CMPL = 0x800,
710 EP_STATE_TCP_FIN_RCVD = 0x1000,
711 EP_STATE_TCP_RST_RCVD = 0x2000,
712 EP_STATE_LOGOUT_SENT = 0x4000,
713 EP_STATE_LOGOUT_RESP_RCVD = 0x8000,
714 EP_STATE_PG_OFLD_FAILED = 0x1000000,
715 EP_STATE_ULP_UPDATE_FAILED = 0x2000000,
716 EP_STATE_CLEANUP_FAILED = 0x4000000,
717 EP_STATE_OFLD_FAILED = 0x8000000,
718 EP_STATE_CONNECT_FAILED = 0x10000000,
719 EP_STATE_DISCONN_TIMEDOUT = 0x20000000,
720 EP_STATE_OFLD_FAILED_CID_BUSY = 0x80000000,
724 * struct bnx2i_endpoint - representation of tcp connection in NX2 world
726 * @link: list head to link elements
727 * @hba: adapter to which this connection belongs
728 * @conn: iscsi connection this EP is linked to
729 * @cls_ep: associated iSCSI endpoint pointer
730 * @cm_sk: cnic sock struct
731 * @hba_age: age to detect if 'iscsid' issues ep_disconnect()
732 * after HBA reset is completed by bnx2i/cnic/bnx2
733 * modules
734 * @state: tracks offload connection state machine
735 * @timestamp: tracks the start time when the ep begins to connect
736 * @num_active_cmds: tracks the number of outstanding commands for this ep
737 * @ec_shift: the amount of shift as part of the event coal calc
738 * @qp: QP information
739 * @ids: contains chip allocated *context id* & driver assigned
740 * *iscsi cid*
741 * @ofld_timer: offload timer to detect timeout
742 * @ofld_wait: wait queue
744 * Endpoint Structure - equivalent of tcp socket structure
746 struct bnx2i_endpoint {
747 struct list_head link;
748 struct bnx2i_hba *hba;
749 struct bnx2i_conn *conn;
750 struct iscsi_endpoint *cls_ep;
751 struct cnic_sock *cm_sk;
752 u32 hba_age;
753 u32 state;
754 unsigned long timestamp;
755 atomic_t num_active_cmds;
756 u32 ec_shift;
758 struct qp_info qp;
759 struct ep_handles ids;
760 #define ep_iscsi_cid ids.drv_iscsi_cid
761 #define ep_cid ids.fw_cid
762 #define ep_pg_cid ids.pg_cid
763 struct timer_list ofld_timer;
764 wait_queue_head_t ofld_wait;
768 struct bnx2i_work {
769 struct list_head list;
770 struct iscsi_session *session;
771 struct bnx2i_conn *bnx2i_conn;
772 struct cqe cqe;
775 struct bnx2i_percpu_s {
776 struct task_struct *iothread;
777 struct list_head work_list;
778 spinlock_t p_work_lock;
782 /* Global variables */
783 extern unsigned int error_mask1, error_mask2;
784 extern u64 iscsi_error_mask;
785 extern unsigned int en_tcp_dack;
786 extern unsigned int event_coal_div;
787 extern unsigned int event_coal_min;
789 extern struct scsi_transport_template *bnx2i_scsi_xport_template;
790 extern struct iscsi_transport bnx2i_iscsi_transport;
791 extern struct cnic_ulp_ops bnx2i_cnic_cb;
793 extern unsigned int sq_size;
794 extern unsigned int rq_size;
796 extern struct device_attribute *bnx2i_dev_attributes[];
801 * Function Prototypes
803 extern void bnx2i_identify_device(struct bnx2i_hba *hba, struct cnic_dev *dev);
805 extern void bnx2i_ulp_init(struct cnic_dev *dev);
806 extern void bnx2i_ulp_exit(struct cnic_dev *dev);
807 extern void bnx2i_start(void *handle);
808 extern void bnx2i_stop(void *handle);
809 extern int bnx2i_get_stats(void *handle);
811 extern struct bnx2i_hba *get_adapter_list_head(void);
813 struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba,
814 u16 iscsi_cid);
816 int bnx2i_alloc_ep_pool(void);
817 void bnx2i_release_ep_pool(void);
818 struct bnx2i_endpoint *bnx2i_ep_ofld_list_next(struct bnx2i_hba *hba);
819 struct bnx2i_endpoint *bnx2i_ep_destroy_list_next(struct bnx2i_hba *hba);
821 struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic);
823 struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic);
824 void bnx2i_free_hba(struct bnx2i_hba *hba);
826 void bnx2i_get_rq_buf(struct bnx2i_conn *conn, char *ptr, int len);
827 void bnx2i_put_rq_buf(struct bnx2i_conn *conn, int count);
829 void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd);
831 void bnx2i_drop_session(struct iscsi_cls_session *session);
833 extern int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba);
834 extern int bnx2i_send_iscsi_login(struct bnx2i_conn *conn,
835 struct iscsi_task *mtask);
836 extern int bnx2i_send_iscsi_tmf(struct bnx2i_conn *conn,
837 struct iscsi_task *mtask);
838 extern int bnx2i_send_iscsi_text(struct bnx2i_conn *conn,
839 struct iscsi_task *mtask);
840 extern int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *conn,
841 struct bnx2i_cmd *cmnd);
842 extern int bnx2i_send_iscsi_nopout(struct bnx2i_conn *conn,
843 struct iscsi_task *mtask,
844 char *datap, int data_len, int unsol);
845 extern int bnx2i_send_iscsi_logout(struct bnx2i_conn *conn,
846 struct iscsi_task *mtask);
847 extern void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba,
848 struct bnx2i_cmd *cmd);
849 extern int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba,
850 struct bnx2i_endpoint *ep);
851 extern void bnx2i_update_iscsi_conn(struct iscsi_conn *conn);
852 extern int bnx2i_send_conn_destroy(struct bnx2i_hba *hba,
853 struct bnx2i_endpoint *ep);
855 extern int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
856 struct bnx2i_endpoint *ep);
857 extern void bnx2i_free_qp_resc(struct bnx2i_hba *hba,
858 struct bnx2i_endpoint *ep);
859 extern void bnx2i_ep_ofld_timer(unsigned long data);
860 extern struct bnx2i_endpoint *bnx2i_find_ep_in_ofld_list(
861 struct bnx2i_hba *hba, u32 iscsi_cid);
862 extern struct bnx2i_endpoint *bnx2i_find_ep_in_destroy_list(
863 struct bnx2i_hba *hba, u32 iscsi_cid);
865 extern int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep);
866 extern int bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action);
868 extern int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep);
870 /* Debug related function prototypes */
871 extern void bnx2i_print_pend_cmd_queue(struct bnx2i_conn *conn);
872 extern void bnx2i_print_active_cmd_queue(struct bnx2i_conn *conn);
873 extern void bnx2i_print_xmit_pdu_queue(struct bnx2i_conn *conn);
874 extern void bnx2i_print_recv_state(struct bnx2i_conn *conn);
876 extern int bnx2i_percpu_io_thread(void *arg);
877 extern int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
878 struct bnx2i_conn *bnx2i_conn,
879 struct cqe *cqe);
880 #endif