bnx2i.h 25 KB

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