bnx2i.h 27 KB

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