bnx2i.h 24 KB

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