bnx2x, cnic, bnx2i: use new FW/HSI
[pandora-kernel.git] / drivers / scsi / bnx2i / bnx2i.h
1 /* bnx2i.h: Broadcom NetXtreme II iSCSI driver.
2  *
3  * Copyright (c) 2006 - 2009 Broadcom Corporation
4  * Copyright (c) 2007, 2008 Red Hat, Inc.  All rights reserved.
5  * Copyright (c) 2007, 2008 Mike Christie
6  *
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.
10  *
11  * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
12  */
13
14 #ifndef _BNX2I_H_
15 #define _BNX2I_H_
16
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19
20 #include <linux/errno.h>
21 #include <linux/pci.h>
22 #include <linux/spinlock.h>
23 #include <linux/interrupt.h>
24 #include <linux/sched.h>
25 #include <linux/in.h>
26 #include <linux/kfifo.h>
27 #include <linux/netdevice.h>
28 #include <linux/completion.h>
29
30 #include <scsi/scsi_cmnd.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_eh.h>
33 #include <scsi/scsi_host.h>
34 #include <scsi/scsi.h>
35 #include <scsi/iscsi_proto.h>
36 #include <scsi/libiscsi.h>
37 #include <scsi/scsi_transport_iscsi.h>
38
39 #include "../../net/cnic_if.h"
40 #include "57xx_iscsi_hsi.h"
41 #include "57xx_iscsi_constants.h"
42
43 #define BNX2_ISCSI_DRIVER_NAME          "bnx2i"
44
45 #define BNX2I_MAX_ADAPTERS              8
46
47 #define ISCSI_MAX_CONNS_PER_HBA         128
48 #define ISCSI_MAX_SESS_PER_HBA          ISCSI_MAX_CONNS_PER_HBA
49 #define ISCSI_MAX_CMDS_PER_SESS         128
50
51 /* Total active commands across all connections supported by devices */
52 #define ISCSI_MAX_CMDS_PER_HBA_5708     (28 * (ISCSI_MAX_CMDS_PER_SESS - 1))
53 #define ISCSI_MAX_CMDS_PER_HBA_5709     (128 * (ISCSI_MAX_CMDS_PER_SESS - 1))
54 #define ISCSI_MAX_CMDS_PER_HBA_57710    (256 * (ISCSI_MAX_CMDS_PER_SESS - 1))
55
56 #define ISCSI_MAX_BDS_PER_CMD           32
57
58 #define MAX_PAGES_PER_CTRL_STRUCT_POOL  8
59 #define BNX2I_RESERVED_SLOW_PATH_CMD_SLOTS      4
60
61 #define BNX2I_5771X_DBELL_PAGE_SIZE     128
62
63 /* 5706/08 hardware has limit on maximum buffer size per BD it can handle */
64 #define MAX_BD_LENGTH                   65535
65 #define BD_SPLIT_SIZE                   32768
66
67 /* min, max & default values for SQ/RQ/CQ size, configurable via' modparam */
68 #define BNX2I_SQ_WQES_MIN               16
69 #define BNX2I_570X_SQ_WQES_MAX          128
70 #define BNX2I_5770X_SQ_WQES_MAX         512
71 #define BNX2I_570X_SQ_WQES_DEFAULT      128
72 #define BNX2I_5770X_SQ_WQES_DEFAULT     256
73
74 #define BNX2I_570X_CQ_WQES_MAX          128
75 #define BNX2I_5770X_CQ_WQES_MAX         512
76
77 #define BNX2I_RQ_WQES_MIN               16
78 #define BNX2I_RQ_WQES_MAX               32
79 #define BNX2I_RQ_WQES_DEFAULT           16
80
81 /* CCELLs per conn */
82 #define BNX2I_CCELLS_MIN                16
83 #define BNX2I_CCELLS_MAX                96
84 #define BNX2I_CCELLS_DEFAULT            64
85
86 #define ITT_INVALID_SIGNATURE           0xFFFF
87
88 #define ISCSI_CMD_CLEANUP_TIMEOUT       100
89
90 #define BNX2I_CONN_CTX_BUF_SIZE         16384
91
92 #define BNX2I_SQ_WQE_SIZE               64
93 #define BNX2I_RQ_WQE_SIZE               256
94 #define BNX2I_CQE_SIZE                  64
95
96 #define MB_KERNEL_CTX_SHIFT             8
97 #define MB_KERNEL_CTX_SIZE              (1 << MB_KERNEL_CTX_SHIFT)
98
99 #define CTX_SHIFT                       7
100 #define GET_CID_NUM(cid_addr)           ((cid_addr) >> CTX_SHIFT)
101
102 #define CTX_OFFSET                      0x10000
103 #define MAX_CID_CNT                     0x4000
104
105 #define BNX2I_570X_PAGE_SIZE_DEFAULT    4096
106
107 /* 5709 context registers */
108 #define BNX2_MQ_CONFIG2                 0x00003d00
109 #define BNX2_MQ_CONFIG2_CONT_SZ         (0x7L<<4)
110 #define BNX2_MQ_CONFIG2_FIRST_L4L5      (0x1fL<<8)
111
112 /* 57710's BAR2 is mapped to doorbell registers */
113 #define BNX2X_DOORBELL_PCI_BAR          2
114 #define BNX2X_MAX_CQS                   8
115
116 #define CNIC_ARM_CQE                    1
117 #define CNIC_DISARM_CQE                 0
118
119 #define REG_RD(__hba, offset)                           \
120                 readl(__hba->regview + offset)
121 #define REG_WR(__hba, offset, val)                      \
122                 writel(val, __hba->regview + offset)
123
124
125 /**
126  * struct generic_pdu_resc - login pdu resource structure
127  *
128  * @req_buf:            driver buffer used to stage payload associated with
129  *                      the login request
130  * @req_dma_addr:       dma address for iscsi login request payload buffer
131  * @req_buf_size:       actual login request payload length
132  * @req_wr_ptr:         pointer into login request buffer when next data is
133  *                      to be written
134  * @resp_hdr:           iscsi header where iscsi login response header is to
135  *                      be recreated
136  * @resp_buf:           buffer to stage login response payload
137  * @resp_dma_addr:      login response payload buffer dma address
138  * @resp_buf_size:      login response paylod length
139  * @resp_wr_ptr:        pointer into login response buffer when next data is
140  *                      to be written
141  * @req_bd_tbl:         iscsi login request payload BD table
142  * @req_bd_dma:         login request BD table dma address
143  * @resp_bd_tbl:        iscsi login response payload BD table
144  * @resp_bd_dma:        login request BD table dma address
145  *
146  * following structure defines buffer info for generic pdus such as iSCSI Login,
147  *      Logout and NOP
148  */
149 struct generic_pdu_resc {
150         char *req_buf;
151         dma_addr_t req_dma_addr;
152         u32 req_buf_size;
153         char *req_wr_ptr;
154         struct iscsi_hdr resp_hdr;
155         char *resp_buf;
156         dma_addr_t resp_dma_addr;
157         u32 resp_buf_size;
158         char *resp_wr_ptr;
159         char *req_bd_tbl;
160         dma_addr_t req_bd_dma;
161         char *resp_bd_tbl;
162         dma_addr_t resp_bd_dma;
163 };
164
165
166 /**
167  * struct bd_resc_page - tracks DMA'able memory allocated for BD tables
168  *
169  * @link:               list head to link elements
170  * @max_ptrs:           maximun pointers that can be stored in this page
171  * @num_valid:          number of pointer valid in this page
172  * @page:               base addess for page pointer array
173  *
174  * structure to track DMA'able memory allocated for command BD tables
175  */
176 struct bd_resc_page {
177         struct list_head link;
178         u32 max_ptrs;
179         u32 num_valid;
180         void *page[1];
181 };
182
183
184 /**
185  * struct io_bdt - I/O buffer destricptor table
186  *
187  * @bd_tbl:             BD table's virtual address
188  * @bd_tbl_dma:         BD table's dma address
189  * @bd_valid:           num valid BD entries
190  *
191  * IO BD table
192  */
193 struct io_bdt {
194         struct iscsi_bd *bd_tbl;
195         dma_addr_t bd_tbl_dma;
196         u16 bd_valid;
197 };
198
199
200 /**
201  * bnx2i_cmd - iscsi command structure
202  *
203  * @scsi_cmd:           SCSI-ML task pointer corresponding to this iscsi cmd
204  * @sg:                 SG list
205  * @io_tbl:             buffer descriptor (BD) table
206  * @bd_tbl_dma:         buffer descriptor (BD) table's dma address
207  */
208 struct bnx2i_cmd {
209         struct iscsi_hdr hdr;
210         struct bnx2i_conn *conn;
211         struct scsi_cmnd *scsi_cmd;
212         struct scatterlist *sg;
213         struct io_bdt io_tbl;
214         dma_addr_t bd_tbl_dma;
215         struct bnx2i_cmd_request req;
216 };
217
218
219 /**
220  * struct bnx2i_conn - iscsi connection structure
221  *
222  * @cls_conn:              pointer to iscsi cls conn
223  * @hba:                   adapter structure pointer
224  * @iscsi_conn_cid:        iscsi conn id
225  * @fw_cid:                firmware iscsi context id
226  * @ep:                    endpoint structure pointer
227  * @gen_pdu:               login/nopout/logout pdu resources
228  * @violation_notified:    bit mask used to track iscsi error/warning messages
229  *                         already printed out
230  *
231  * iSCSI connection structure
232  */
233 struct bnx2i_conn {
234         struct iscsi_cls_conn *cls_conn;
235         struct bnx2i_hba *hba;
236         struct completion cmd_cleanup_cmpl;
237
238         u32 iscsi_conn_cid;
239 #define BNX2I_CID_RESERVED      0x5AFF
240         u32 fw_cid;
241
242         struct timer_list poll_timer;
243         /*
244          * Queue Pair (QP) related structure elements.
245          */
246         struct bnx2i_endpoint *ep;
247
248         /*
249          * Buffer for login negotiation process
250          */
251         struct generic_pdu_resc gen_pdu;
252         u64 violation_notified;
253 };
254
255
256
257 /**
258  * struct iscsi_cid_queue - Per adapter iscsi cid queue
259  *
260  * @cid_que_base:           queue base memory
261  * @cid_que:                queue memory pointer
262  * @cid_q_prod_idx:         produce index
263  * @cid_q_cons_idx:         consumer index
264  * @cid_q_max_idx:          max index. used to detect wrap around condition
265  * @cid_free_cnt:           queue size
266  * @conn_cid_tbl:           iscsi cid to conn structure mapping table
267  *
268  * Per adapter iSCSI CID Queue
269  */
270 struct iscsi_cid_queue {
271         void *cid_que_base;
272         u32 *cid_que;
273         u32 cid_q_prod_idx;
274         u32 cid_q_cons_idx;
275         u32 cid_q_max_idx;
276         u32 cid_free_cnt;
277         struct bnx2i_conn **conn_cid_tbl;
278 };
279
280 /**
281  * struct bnx2i_hba - bnx2i adapter structure
282  *
283  * @link:                  list head to link elements
284  * @cnic:                  pointer to cnic device
285  * @pcidev:                pointer to pci dev
286  * @netdev:                pointer to netdev structure
287  * @regview:               mapped PCI register space
288  * @age:                   age, incremented by every recovery
289  * @cnic_dev_type:         cnic device type, 5706/5708/5709/57710
290  * @mail_queue_access:     mailbox queue access mode, applicable to 5709 only
291  * @reg_with_cnic:         indicates whether the device is register with CNIC
292  * @adapter_state:         adapter state, UP, GOING_DOWN, LINK_DOWN
293  * @mtu_supported:         Ethernet MTU supported
294  * @shost:                 scsi host pointer
295  * @max_sqes:              SQ size
296  * @max_rqes:              RQ size
297  * @max_cqes:              CQ size
298  * @num_ccell:             number of command cells per connection
299  * @ofld_conns_active:     active connection list
300  * @eh_wait:               wait queue for the endpoint to shutdown
301  * @max_active_conns:      max offload connections supported by this device
302  * @cid_que:               iscsi cid queue
303  * @ep_rdwr_lock:          read / write lock to synchronize various ep lists
304  * @ep_ofld_list:          connection list for pending offload completion
305  * @ep_active_list:        connection list for active offload endpoints
306  * @ep_destroy_list:       connection list for pending offload completion
307  * @mp_bd_tbl:             BD table to be used with middle path requests
308  * @mp_bd_dma:             DMA address of 'mp_bd_tbl' memory buffer
309  * @dummy_buffer:          Dummy buffer to be used with zero length scsicmd reqs
310  * @dummy_buf_dma:         DMA address of 'dummy_buffer' memory buffer
311  * @lock:                  lock to synchonize access to hba structure
312  * @hba_shutdown_tmo:      Timeout value to shutdown each connection
313  * @conn_teardown_tmo:     Timeout value to tear down each connection
314  * @conn_ctx_destroy_tmo:  Timeout value to destroy context of each connection
315  * @pci_did:               PCI device ID
316  * @pci_vid:               PCI vendor ID
317  * @pci_sdid:              PCI subsystem device ID
318  * @pci_svid:              PCI subsystem vendor ID
319  * @pci_func:              PCI function number in system pci tree
320  * @pci_devno:             PCI device number in system pci tree
321  * @num_wqe_sent:          statistic counter, total wqe's sent
322  * @num_cqe_rcvd:          statistic counter, total cqe's received
323  * @num_intr_claimed:      statistic counter, total interrupts claimed
324  * @link_changed_count:    statistic counter, num of link change notifications
325  *                         received
326  * @ipaddr_changed_count:  statistic counter, num times IP address changed while
327  *                         at least one connection is offloaded
328  * @num_sess_opened:       statistic counter, total num sessions opened
329  * @num_conn_opened:       statistic counter, total num conns opened on this hba
330  * @ctx_ccell_tasks:       captures number of ccells and tasks supported by
331  *                         currently offloaded connection, used to decode
332  *                         context memory
333  *
334  * Adapter Data Structure
335  */
336 struct bnx2i_hba {
337         struct list_head link;
338         struct cnic_dev *cnic;
339         struct pci_dev *pcidev;
340         struct net_device *netdev;
341         void __iomem *regview;
342
343         u32 age;
344         unsigned long cnic_dev_type;
345                 #define BNX2I_NX2_DEV_5706              0x0
346                 #define BNX2I_NX2_DEV_5708              0x1
347                 #define BNX2I_NX2_DEV_5709              0x2
348                 #define BNX2I_NX2_DEV_57710             0x3
349         u32 mail_queue_access;
350                 #define BNX2I_MQ_KERNEL_MODE            0x0
351                 #define BNX2I_MQ_KERNEL_BYPASS_MODE     0x1
352                 #define BNX2I_MQ_BIN_MODE               0x2
353         unsigned long  reg_with_cnic;
354                 #define BNX2I_CNIC_REGISTERED           1
355
356         unsigned long  adapter_state;
357                 #define ADAPTER_STATE_UP                0
358                 #define ADAPTER_STATE_GOING_DOWN        1
359                 #define ADAPTER_STATE_LINK_DOWN         2
360                 #define ADAPTER_STATE_INIT_FAILED       31
361         unsigned int mtu_supported;
362                 #define BNX2I_MAX_MTU_SUPPORTED         1500
363
364         struct Scsi_Host *shost;
365
366         u32 max_sqes;
367         u32 max_rqes;
368         u32 max_cqes;
369         u32 num_ccell;
370
371         int ofld_conns_active;
372         wait_queue_head_t eh_wait;
373
374         int max_active_conns;
375         struct iscsi_cid_queue cid_que;
376
377         rwlock_t ep_rdwr_lock;
378         struct list_head ep_ofld_list;
379         struct list_head ep_active_list;
380         struct list_head ep_destroy_list;
381
382         /*
383          * BD table to be used with MP (Middle Path requests.
384          */
385         char *mp_bd_tbl;
386         dma_addr_t mp_bd_dma;
387         char *dummy_buffer;
388         dma_addr_t dummy_buf_dma;
389
390         spinlock_t lock;        /* protects hba structure access */
391         struct mutex net_dev_lock;/* sync net device access */
392
393         int hba_shutdown_tmo;
394         int conn_teardown_tmo;
395         int conn_ctx_destroy_tmo;
396         /*
397          * PCI related info.
398          */
399         u16 pci_did;
400         u16 pci_vid;
401         u16 pci_sdid;
402         u16 pci_svid;
403         u16 pci_func;
404         u16 pci_devno;
405
406         /*
407          * Following are a bunch of statistics useful during development
408          * and later stage for score boarding.
409          */
410         u32 num_wqe_sent;
411         u32 num_cqe_rcvd;
412         u32 num_intr_claimed;
413         u32 link_changed_count;
414         u32 ipaddr_changed_count;
415         u32 num_sess_opened;
416         u32 num_conn_opened;
417         unsigned int ctx_ccell_tasks;
418 };
419
420
421 /*******************************************************************************
422  *      QP [ SQ / RQ / CQ ] info.
423  ******************************************************************************/
424
425 /*
426  * SQ/RQ/CQ generic structure definition
427  */
428 struct  sqe {
429         u8 sqe_byte[BNX2I_SQ_WQE_SIZE];
430 };
431
432 struct  rqe {
433         u8 rqe_byte[BNX2I_RQ_WQE_SIZE];
434 };
435
436 struct  cqe {
437         u8 cqe_byte[BNX2I_CQE_SIZE];
438 };
439
440
441 enum {
442 #if defined(__LITTLE_ENDIAN)
443         CNIC_EVENT_COAL_INDEX   = 0x0,
444         CNIC_SEND_DOORBELL      = 0x4,
445         CNIC_EVENT_CQ_ARM       = 0x7,
446         CNIC_RECV_DOORBELL      = 0x8
447 #elif defined(__BIG_ENDIAN)
448         CNIC_EVENT_COAL_INDEX   = 0x2,
449         CNIC_SEND_DOORBELL      = 0x6,
450         CNIC_EVENT_CQ_ARM       = 0x4,
451         CNIC_RECV_DOORBELL      = 0xa
452 #endif
453 };
454
455
456 /*
457  * CQ DB
458  */
459 struct bnx2x_iscsi_cq_pend_cmpl {
460         /* CQ producer, updated by Ustorm */
461         u16 ustrom_prod;
462         /* CQ pending completion counter */
463         u16 pend_cntr;
464 };
465
466
467 struct bnx2i_5771x_cq_db {
468         struct bnx2x_iscsi_cq_pend_cmpl qp_pend_cmpl[BNX2X_MAX_CQS];
469         /* CQ pending completion ITT array */
470         u16 itt[BNX2X_MAX_CQS];
471         /* Cstorm CQ sequence to notify array, updated by driver */;
472         u16 sqn[BNX2X_MAX_CQS];
473         u32 reserved[4] /* 16 byte allignment */;
474 };
475
476
477 struct bnx2i_5771x_sq_rq_db {
478         u16 prod_idx;
479         u8 reserved0[14]; /* Pad structure size to 16 bytes */
480 };
481
482
483 struct bnx2i_5771x_dbell_hdr {
484         u8 header;
485         /* 1 for rx doorbell, 0 for tx doorbell */
486 #define B577XX_DOORBELL_HDR_RX                          (0x1<<0)
487 #define B577XX_DOORBELL_HDR_RX_SHIFT                    0
488         /* 0 for normal doorbell, 1 for advertise wnd doorbell */
489 #define B577XX_DOORBELL_HDR_DB_TYPE                     (0x1<<1)
490 #define B577XX_DOORBELL_HDR_DB_TYPE_SHIFT               1
491         /* rdma tx only: DPM transaction size specifier (64/128/256/512B) */
492 #define B577XX_DOORBELL_HDR_DPM_SIZE                    (0x3<<2)
493 #define B577XX_DOORBELL_HDR_DPM_SIZE_SHIFT              2
494         /* connection type */
495 #define B577XX_DOORBELL_HDR_CONN_TYPE                   (0xF<<4)
496 #define B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT             4
497 };
498
499 struct bnx2i_5771x_dbell {
500         struct bnx2i_5771x_dbell_hdr dbell;
501         u8 pad[3];
502
503 };
504
505 /**
506  * struct qp_info - QP (share queue region) atrributes structure
507  *
508  * @ctx_base:           ioremapped pci register base to access doorbell register
509  *                      pertaining to this offloaded connection
510  * @sq_virt:            virtual address of send queue (SQ) region
511  * @sq_phys:            DMA address of SQ memory region
512  * @sq_mem_size:        SQ size
513  * @sq_prod_qe:         SQ producer entry pointer
514  * @sq_cons_qe:         SQ consumer entry pointer
515  * @sq_first_qe:        virtaul address of first entry in SQ
516  * @sq_last_qe:         virtaul address of last entry in SQ
517  * @sq_prod_idx:        SQ producer index
518  * @sq_cons_idx:        SQ consumer index
519  * @sqe_left:           number sq entry left
520  * @sq_pgtbl_virt:      page table describing buffer consituting SQ region
521  * @sq_pgtbl_phys:      dma address of 'sq_pgtbl_virt'
522  * @sq_pgtbl_size:      SQ page table size
523  * @cq_virt:            virtual address of completion queue (CQ) region
524  * @cq_phys:            DMA address of RQ memory region
525  * @cq_mem_size:        CQ size
526  * @cq_prod_qe:         CQ producer entry pointer
527  * @cq_cons_qe:         CQ consumer entry pointer
528  * @cq_first_qe:        virtaul address of first entry in CQ
529  * @cq_last_qe:         virtaul address of last entry in CQ
530  * @cq_prod_idx:        CQ producer index
531  * @cq_cons_idx:        CQ consumer index
532  * @cqe_left:           number cq entry left
533  * @cqe_size:           size of each CQ entry
534  * @cqe_exp_seq_sn:     next expected CQE sequence number
535  * @cq_pgtbl_virt:      page table describing buffer consituting CQ region
536  * @cq_pgtbl_phys:      dma address of 'cq_pgtbl_virt'
537  * @cq_pgtbl_size:      CQ page table size
538  * @rq_virt:            virtual address of receive queue (RQ) region
539  * @rq_phys:            DMA address of RQ memory region
540  * @rq_mem_size:        RQ size
541  * @rq_prod_qe:         RQ producer entry pointer
542  * @rq_cons_qe:         RQ consumer entry pointer
543  * @rq_first_qe:        virtaul address of first entry in RQ
544  * @rq_last_qe:         virtaul address of last entry in RQ
545  * @rq_prod_idx:        RQ producer index
546  * @rq_cons_idx:        RQ consumer index
547  * @rqe_left:           number rq entry left
548  * @rq_pgtbl_virt:      page table describing buffer consituting RQ region
549  * @rq_pgtbl_phys:      dma address of 'rq_pgtbl_virt'
550  * @rq_pgtbl_size:      RQ page table size
551  *
552  * queue pair (QP) is a per connection shared data structure which is used
553  *      to send work requests (SQ), receive completion notifications (CQ)
554  *      and receive asynchoronous / scsi sense info (RQ). 'qp_info' structure
555  *      below holds queue memory, consumer/producer indexes and page table
556  *      information
557  */
558 struct qp_info {
559         void __iomem *ctx_base;
560 #define DPM_TRIGER_TYPE                 0x40
561
562 #define BNX2I_570x_QUE_DB_SIZE          0
563 #define BNX2I_5771x_QUE_DB_SIZE         16
564         struct sqe *sq_virt;
565         dma_addr_t sq_phys;
566         u32 sq_mem_size;
567
568         struct sqe *sq_prod_qe;
569         struct sqe *sq_cons_qe;
570         struct sqe *sq_first_qe;
571         struct sqe *sq_last_qe;
572         u16 sq_prod_idx;
573         u16 sq_cons_idx;
574         u32 sqe_left;
575
576         void *sq_pgtbl_virt;
577         dma_addr_t sq_pgtbl_phys;
578         u32 sq_pgtbl_size;      /* set to PAGE_SIZE for 5708 & 5709 */
579
580         struct cqe *cq_virt;
581         dma_addr_t cq_phys;
582         u32 cq_mem_size;
583
584         struct cqe *cq_prod_qe;
585         struct cqe *cq_cons_qe;
586         struct cqe *cq_first_qe;
587         struct cqe *cq_last_qe;
588         u16 cq_prod_idx;
589         u16 cq_cons_idx;
590         u32 cqe_left;
591         u32 cqe_size;
592         u32 cqe_exp_seq_sn;
593
594         void *cq_pgtbl_virt;
595         dma_addr_t cq_pgtbl_phys;
596         u32 cq_pgtbl_size;      /* set to PAGE_SIZE for 5708 & 5709 */
597
598         struct rqe *rq_virt;
599         dma_addr_t rq_phys;
600         u32 rq_mem_size;
601
602         struct rqe *rq_prod_qe;
603         struct rqe *rq_cons_qe;
604         struct rqe *rq_first_qe;
605         struct rqe *rq_last_qe;
606         u16 rq_prod_idx;
607         u16 rq_cons_idx;
608         u32 rqe_left;
609
610         void *rq_pgtbl_virt;
611         dma_addr_t rq_pgtbl_phys;
612         u32 rq_pgtbl_size;      /* set to PAGE_SIZE for 5708 & 5709 */
613 };
614
615
616
617 /*
618  * CID handles
619  */
620 struct ep_handles {
621         u32 fw_cid;
622         u32 drv_iscsi_cid;
623         u16 pg_cid;
624         u16 rsvd;
625 };
626
627
628 enum {
629         EP_STATE_IDLE                   = 0x0,
630         EP_STATE_PG_OFLD_START          = 0x1,
631         EP_STATE_PG_OFLD_COMPL          = 0x2,
632         EP_STATE_OFLD_START             = 0x4,
633         EP_STATE_OFLD_COMPL             = 0x8,
634         EP_STATE_CONNECT_START          = 0x10,
635         EP_STATE_CONNECT_COMPL          = 0x20,
636         EP_STATE_ULP_UPDATE_START       = 0x40,
637         EP_STATE_ULP_UPDATE_COMPL       = 0x80,
638         EP_STATE_DISCONN_START          = 0x100,
639         EP_STATE_DISCONN_COMPL          = 0x200,
640         EP_STATE_CLEANUP_START          = 0x400,
641         EP_STATE_CLEANUP_CMPL           = 0x800,
642         EP_STATE_TCP_FIN_RCVD           = 0x1000,
643         EP_STATE_TCP_RST_RCVD           = 0x2000,
644         EP_STATE_LOGOUT_SENT            = 0x4000,
645         EP_STATE_LOGOUT_RESP_RCVD       = 0x8000,
646         EP_STATE_PG_OFLD_FAILED         = 0x1000000,
647         EP_STATE_ULP_UPDATE_FAILED      = 0x2000000,
648         EP_STATE_CLEANUP_FAILED         = 0x4000000,
649         EP_STATE_OFLD_FAILED            = 0x8000000,
650         EP_STATE_CONNECT_FAILED         = 0x10000000,
651         EP_STATE_DISCONN_TIMEDOUT       = 0x20000000,
652 };
653
654 /**
655  * struct bnx2i_endpoint - representation of tcp connection in NX2 world
656  *
657  * @link:               list head to link elements
658  * @hba:                adapter to which this connection belongs
659  * @conn:               iscsi connection this EP is linked to
660  * @cls_ep:             associated iSCSI endpoint pointer
661  * @sess:               iscsi session this EP is linked to
662  * @cm_sk:              cnic sock struct
663  * @hba_age:            age to detect if 'iscsid' issues ep_disconnect()
664  *                      after HBA reset is completed by bnx2i/cnic/bnx2
665  *                      modules
666  * @state:              tracks offload connection state machine
667  * @teardown_mode:      indicates if conn teardown is abortive or orderly
668  * @qp:                 QP information
669  * @ids:                contains chip allocated *context id* & driver assigned
670  *                      *iscsi cid*
671  * @ofld_timer:         offload timer to detect timeout
672  * @ofld_wait:          wait queue
673  *
674  * Endpoint Structure - equivalent of tcp socket structure
675  */
676 struct bnx2i_endpoint {
677         struct list_head link;
678         struct bnx2i_hba *hba;
679         struct bnx2i_conn *conn;
680         struct iscsi_endpoint *cls_ep;
681         struct cnic_sock *cm_sk;
682         u32 hba_age;
683         u32 state;
684         unsigned long timestamp;
685         int num_active_cmds;
686
687         struct qp_info qp;
688         struct ep_handles ids;
689                 #define ep_iscsi_cid    ids.drv_iscsi_cid
690                 #define ep_cid          ids.fw_cid
691                 #define ep_pg_cid       ids.pg_cid
692         struct timer_list ofld_timer;
693         wait_queue_head_t ofld_wait;
694 };
695
696
697
698 /* Global variables */
699 extern unsigned int error_mask1, error_mask2;
700 extern u64 iscsi_error_mask;
701 extern unsigned int en_tcp_dack;
702 extern unsigned int event_coal_div;
703 extern unsigned int event_coal_min;
704
705 extern struct scsi_transport_template *bnx2i_scsi_xport_template;
706 extern struct iscsi_transport bnx2i_iscsi_transport;
707 extern struct cnic_ulp_ops bnx2i_cnic_cb;
708
709 extern unsigned int sq_size;
710 extern unsigned int rq_size;
711
712 extern struct device_attribute *bnx2i_dev_attributes[];
713
714
715
716 /*
717  * Function Prototypes
718  */
719 extern void bnx2i_identify_device(struct bnx2i_hba *hba);
720 extern void bnx2i_register_device(struct bnx2i_hba *hba);
721
722 extern void bnx2i_ulp_init(struct cnic_dev *dev);
723 extern void bnx2i_ulp_exit(struct cnic_dev *dev);
724 extern void bnx2i_start(void *handle);
725 extern void bnx2i_stop(void *handle);
726 extern void bnx2i_reg_dev_all(void);
727 extern void bnx2i_unreg_dev_all(void);
728 extern struct bnx2i_hba *get_adapter_list_head(void);
729
730 struct bnx2i_conn *bnx2i_get_conn_from_id(struct bnx2i_hba *hba,
731                                           u16 iscsi_cid);
732
733 int bnx2i_alloc_ep_pool(void);
734 void bnx2i_release_ep_pool(void);
735 struct bnx2i_endpoint *bnx2i_ep_ofld_list_next(struct bnx2i_hba *hba);
736 struct bnx2i_endpoint *bnx2i_ep_destroy_list_next(struct bnx2i_hba *hba);
737
738 struct bnx2i_hba *bnx2i_find_hba_for_cnic(struct cnic_dev *cnic);
739
740 struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic);
741 void bnx2i_free_hba(struct bnx2i_hba *hba);
742
743 void bnx2i_get_rq_buf(struct bnx2i_conn *conn, char *ptr, int len);
744 void bnx2i_put_rq_buf(struct bnx2i_conn *conn, int count);
745
746 void bnx2i_iscsi_unmap_sg_list(struct bnx2i_cmd *cmd);
747
748 void bnx2i_drop_session(struct iscsi_cls_session *session);
749
750 extern int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba);
751 extern int bnx2i_send_iscsi_login(struct bnx2i_conn *conn,
752                                   struct iscsi_task *mtask);
753 extern int bnx2i_send_iscsi_tmf(struct bnx2i_conn *conn,
754                                   struct iscsi_task *mtask);
755 extern int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *conn,
756                                     struct bnx2i_cmd *cmnd);
757 extern int bnx2i_send_iscsi_nopout(struct bnx2i_conn *conn,
758                                    struct iscsi_task *mtask, u32 ttt,
759                                    char *datap, int data_len, int unsol);
760 extern int bnx2i_send_iscsi_logout(struct bnx2i_conn *conn,
761                                    struct iscsi_task *mtask);
762 extern void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba,
763                                        struct bnx2i_cmd *cmd);
764 extern void bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba,
765                                      struct bnx2i_endpoint *ep);
766 extern void bnx2i_update_iscsi_conn(struct iscsi_conn *conn);
767 extern void bnx2i_send_conn_destroy(struct bnx2i_hba *hba,
768                                     struct bnx2i_endpoint *ep);
769
770 extern int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba,
771                                struct bnx2i_endpoint *ep);
772 extern void bnx2i_free_qp_resc(struct bnx2i_hba *hba,
773                                struct bnx2i_endpoint *ep);
774 extern void bnx2i_ep_ofld_timer(unsigned long data);
775 extern struct bnx2i_endpoint *bnx2i_find_ep_in_ofld_list(
776                 struct bnx2i_hba *hba, u32 iscsi_cid);
777 extern struct bnx2i_endpoint *bnx2i_find_ep_in_destroy_list(
778                 struct bnx2i_hba *hba, u32 iscsi_cid);
779
780 extern int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep);
781 extern void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action);
782
783 extern int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep);
784
785 /* Debug related function prototypes */
786 extern void bnx2i_print_pend_cmd_queue(struct bnx2i_conn *conn);
787 extern void bnx2i_print_active_cmd_queue(struct bnx2i_conn *conn);
788 extern void bnx2i_print_xmit_pdu_queue(struct bnx2i_conn *conn);
789 extern void bnx2i_print_recv_state(struct bnx2i_conn *conn);
790
791 #endif