Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
bnx2i.h
Go to the documentation of this file.
1 /* bnx2i.h: Broadcom NetXtreme II iSCSI driver.
2  *
3  * Copyright (c) 2006 - 2012 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 ([email protected])
12  * Maintained by: Eddie Wai ([email protected])
13  */
14 
15 #ifndef _BNX2I_H_
16 #define _BNX2I_H_
17 
18 #include <linux/module.h>
19 #include <linux/moduleparam.h>
20 
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>
33 
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>
42 
43 #include "../../net/ethernet/broadcom/cnic_if.h"
44 #include "57xx_iscsi_hsi.h"
45 #include "57xx_iscsi_constants.h"
46 
47 #include "../../net/ethernet/broadcom/bnx2x/bnx2x_mfw_req.h"
48 
49 #define BNX2_ISCSI_DRIVER_NAME "bnx2i"
50 
51 #define BNX2I_MAX_ADAPTERS 8
52 
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
56 
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))
61 
62 #define ISCSI_MAX_BDS_PER_CMD 32
63 
64 #define MAX_PAGES_PER_CTRL_STRUCT_POOL 8
65 #define BNX2I_RESERVED_SLOW_PATH_CMD_SLOTS 4
66 
67 #define BNX2I_5771X_DBELL_PAGE_SIZE 128
68 
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
72 
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
79 
80 #define BNX2I_570X_CQ_WQES_MAX 128
81 #define BNX2I_5770X_CQ_WQES_MAX 512
82 
83 #define BNX2I_RQ_WQES_MIN 16
84 #define BNX2I_RQ_WQES_MAX 32
85 #define BNX2I_RQ_WQES_DEFAULT 16
86 
87 /* CCELLs per conn */
88 #define BNX2I_CCELLS_MIN 16
89 #define BNX2I_CCELLS_MAX 96
90 #define BNX2I_CCELLS_DEFAULT 64
91 
92 #define ITT_INVALID_SIGNATURE 0xFFFF
93 
94 #define ISCSI_CMD_CLEANUP_TIMEOUT 100
95 
96 #define BNX2I_CONN_CTX_BUF_SIZE 16384
97 
98 #define BNX2I_SQ_WQE_SIZE 64
99 #define BNX2I_RQ_WQE_SIZE 256
100 #define BNX2I_CQE_SIZE 64
101 
102 #define MB_KERNEL_CTX_SHIFT 8
103 #define MB_KERNEL_CTX_SIZE (1 << MB_KERNEL_CTX_SHIFT)
104 
105 #define CTX_SHIFT 7
106 #define GET_CID_NUM(cid_addr) ((cid_addr) >> CTX_SHIFT)
107 
108 #define CTX_OFFSET 0x10000
109 #define MAX_CID_CNT 0x4000
110 
111 #define BNX2I_570X_PAGE_SIZE_DEFAULT 4096
112 
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)
117 
118 /* 57710's BAR2 is mapped to doorbell registers */
119 #define BNX2X_DOORBELL_PCI_BAR 2
120 #define BNX2X_MAX_CQS 8
121 
122 #define CNIC_ARM_CQE 1
123 #define CNIC_ARM_CQE_FP 2
124 #define CNIC_DISARM_CQE 0
125 
126 #define REG_RD(__hba, offset) \
127  readl(__hba->regview + offset)
128 #define REG_WR(__hba, offset, val) \
129  writel(val, __hba->regview + offset)
130 
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)
139 
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); \
148  } \
149  } while (0)
150 
151 #else
152 #define GET_STATS_64(__hba, dst, field) \
153  do { \
154  u64 val, *out; \
155  \
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)
162 
163 #define ADD_STATS_64(__hba, field, len) \
164  do { \
165  __hba->bnx2i_stats.field += len; \
166  } while (0)
167 #endif
168 
194  char *req_buf;
197  char *req_wr_ptr;
199  char *resp_buf;
202  char *resp_wr_ptr;
203  char *req_bd_tbl;
205  char *resp_bd_tbl;
207 };
208 
209 
220 struct bd_resc_page {
221  struct list_head link;
224  void *page[1];
225 };
226 
227 
237 struct io_bdt {
238  struct iscsi_bd *bd_tbl;
240  u16 bd_valid;
241 };
242 
243 
255 struct bnx2i_cmd {
256  struct iscsi_hdr hdr;
257  struct bnx2i_conn *conn;
259  struct scatterlist *sg;
260  struct io_bdt io_tbl;
263 };
264 
265 
281 struct bnx2i_conn {
283  struct bnx2i_hba *hba;
285 
287 #define BNX2I_CID_RESERVED 0x5AFF
289 
291  /*
292  * Queue Pair (QP) related structure elements.
293  */
295 
296  /*
297  * Buffer for login negotiation process
298  */
301 
303 };
304 
305 
306 
328 };
329 
330 
336 };
337 
338 
397 struct bnx2i_hba {
398  struct list_head link;
399  struct cnic_dev *cnic;
400  struct pci_dev *pcidev;
404 
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
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
417 
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
425 
426  struct Scsi_Host *shost;
427 
432 
435 
438 
443 
444  /*
445  * BD table to be used with MP (Middle Path requests.
446  */
447  char *mp_bd_tbl;
451 
452  spinlock_t lock; /* protects hba structure access */
453  struct mutex net_dev_lock;/* sync net device access */
454 
458  /*
459  * PCI related info.
460  */
467 
468  /*
469  * Following are a bunch of statistics useful during development
470  * and later stage for score boarding.
471  */
479  unsigned int ctx_ccell_tasks;
480 
481 #ifdef CONFIG_32BIT
482  spinlock_t stat_lock;
483 #endif
486 };
487 
488 
489 /*******************************************************************************
490  * QP [ SQ / RQ / CQ ] info.
491  ******************************************************************************/
492 
493 /*
494  * SQ/RQ/CQ generic structure definition
495  */
496 struct sqe {
498 };
499 
500 struct rqe {
502 };
503 
504 struct cqe {
506 };
507 
508 
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
521 };
522 
523 
524 /*
525  * CQ DB
526  */
528  /* CQ producer, updated by Ustorm */
530  /* CQ pending completion counter */
532 };
533 
534 
537  /* CQ pending completion ITT array */
539  /* Cstorm CQ sequence to notify array, updated by driver */;
541  u32 reserved[4] /* 16 byte allignment */;
542 };
543 
544 
547  u8 reserved0[62]; /* Pad structure size to 64 bytes */
548 };
549 
550 
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
565 };
566 
569  u8 pad[3];
570 
571 };
572 
626 struct qp_info {
628 #define DPM_TRIGER_TYPE 0x40
629 
630 #define BNX2I_570x_QUE_DB_SIZE 0
631 #define BNX2I_5771x_QUE_DB_SIZE 16
632  struct sqe *sq_virt;
635 
636  struct sqe *sq_prod_qe;
637  struct sqe *sq_cons_qe;
638  struct sqe *sq_first_qe;
639  struct sqe *sq_last_qe;
643 
646  u32 sq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
647 
648  struct cqe *cq_virt;
651 
652  struct cqe *cq_prod_qe;
653  struct cqe *cq_cons_qe;
654  struct cqe *cq_first_qe;
655  struct cqe *cq_last_qe;
661 
664  u32 cq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
665 
666  struct rqe *rq_virt;
669 
670  struct rqe *rq_prod_qe;
671  struct rqe *rq_cons_qe;
672  struct rqe *rq_first_qe;
673  struct rqe *rq_last_qe;
677 
680  u32 rq_pgtbl_size; /* set to PAGE_SIZE for 5708 & 5709 */
681 };
682 
683 
684 
685 /*
686  * CID handles
687  */
688 struct ep_handles {
693 };
694 
695 
696 enum {
717  EP_STATE_OFLD_FAILED = 0x8000000,
721 };
722 
747  struct list_head link;
748  struct bnx2i_hba *hba;
749  struct bnx2i_conn *conn;
751  struct cnic_sock *cm_sk;
754  unsigned long timestamp;
757 
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
765 };
766 
767 
768 struct bnx2i_work {
769  struct list_head list;
772  struct cqe cqe;
773 };
774 
779 };
780 
781 
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;
788 
791 extern struct cnic_ulp_ops bnx2i_cnic_cb;
792 
793 extern unsigned int sq_size;
794 extern unsigned int rq_size;
795 
796 extern struct device_attribute *bnx2i_dev_attributes[];
797 
798 
799 
800 /*
801  * Function Prototypes
802  */
803 extern void bnx2i_identify_device(struct bnx2i_hba *hba);
804 
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);
810 
811 extern struct bnx2i_hba *get_adapter_list_head(void);
812 
814  u16 iscsi_cid);
815 
816 int bnx2i_alloc_ep_pool(void);
817 void bnx2i_release_ep_pool(void);
820 
822 
823 struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic);
824 void bnx2i_free_hba(struct bnx2i_hba *hba);
825 
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);
828 
830 
831 void bnx2i_drop_session(struct iscsi_cls_session *session);
832 
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);
854 
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);
861  struct bnx2i_hba *hba, u32 iscsi_cid);
863  struct bnx2i_hba *hba, u32 iscsi_cid);
864 
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);
867 
868 extern int bnx2i_hw_ep_disconnect(struct bnx2i_endpoint *bnx2i_ep);
869 
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);
875 
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