bnx2i.h 27 KB

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