bnx2i.h 24 KB

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