be_main.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2017 Broadcom. All Rights Reserved.
  4. * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
  5. *
  6. * Contact Information:
  7. * linux-drivers@broadcom.com
  8. */
  9. #ifndef _BEISCSI_MAIN_
  10. #define _BEISCSI_MAIN_
  11. #include <linux/kernel.h>
  12. #include <linux/pci.h>
  13. #include <linux/if_ether.h>
  14. #include <linux/in.h>
  15. #include <linux/ctype.h>
  16. #include <linux/module.h>
  17. #include <scsi/scsi.h>
  18. #include <scsi/scsi_cmnd.h>
  19. #include <scsi/scsi_device.h>
  20. #include <scsi/scsi_host.h>
  21. #include <scsi/iscsi_proto.h>
  22. #include <scsi/libiscsi.h>
  23. #include <scsi/scsi_transport_iscsi.h>
  24. #define DRV_NAME "be2iscsi"
  25. #define BUILD_STR "11.4.0.1"
  26. #define BE_NAME "Emulex OneConnect" \
  27. "Open-iSCSI Driver version" BUILD_STR
  28. #define DRV_DESC BE_NAME " " "Driver"
  29. #define BE_VENDOR_ID 0x19A2
  30. #define ELX_VENDOR_ID 0x10DF
  31. /* DEVICE ID's for BE2 */
  32. #define BE_DEVICE_ID1 0x212
  33. #define OC_DEVICE_ID1 0x702
  34. #define OC_DEVICE_ID2 0x703
  35. /* DEVICE ID's for BE3 */
  36. #define BE_DEVICE_ID2 0x222
  37. #define OC_DEVICE_ID3 0x712
  38. /* DEVICE ID for SKH */
  39. #define OC_SKH_ID1 0x722
  40. #define BE2_IO_DEPTH 1024
  41. #define BE2_MAX_SESSIONS 256
  42. #define BE2_TMFS 16
  43. #define BE2_NOPOUT_REQ 16
  44. #define BE2_SGE 32
  45. #define BE2_DEFPDU_HDR_SZ 64
  46. #define BE2_DEFPDU_DATA_SZ 8192
  47. #define BE2_MAX_NUM_CQ_PROC 512
  48. #define MAX_CPUS 64U
  49. #define BEISCSI_MAX_NUM_CPUS 7
  50. #define BEISCSI_VER_STRLEN 32
  51. #define BEISCSI_SGLIST_ELEMENTS 30
  52. /**
  53. * BE_INVLDT_CMD_TBL_SZ is 128 which is total number commands that can
  54. * be invalidated at a time, consider it before changing the value of
  55. * BEISCSI_CMD_PER_LUN.
  56. */
  57. #define BEISCSI_CMD_PER_LUN 128 /* scsi_host->cmd_per_lun */
  58. #define BEISCSI_MAX_SECTORS 1024 /* scsi_host->max_sectors */
  59. #define BEISCSI_TEMPLATE_HDR_PER_CXN_SIZE 128 /* Template size per cxn */
  60. #define BEISCSI_MAX_CMD_LEN 16 /* scsi_host->max_cmd_len */
  61. #define BEISCSI_NUM_MAX_LUN 256 /* scsi_host->max_lun */
  62. #define BEISCSI_MAX_FRAGS_INIT 192
  63. #define BE_SENSE_INFO_SIZE 258
  64. #define BE_ISCSI_PDU_HEADER_SIZE 64
  65. #define BE_MIN_MEM_SIZE 16384
  66. #define MAX_CMD_SZ 65536
  67. #define IIOC_SCSI_DATA 0x05 /* Write Operation */
  68. /**
  69. * hardware needs the async PDU buffers to be posted in multiples of 8
  70. * So have atleast 8 of them by default
  71. */
  72. #define HWI_GET_ASYNC_PDU_CTX(phwi, ulp_num) \
  73. (phwi->phwi_ctxt->pasync_ctx[ulp_num])
  74. /********* Memory BAR register ************/
  75. #define PCICFG_MEMBAR_CTRL_INT_CTRL_OFFSET 0xfc
  76. /**
  77. * Host Interrupt Enable, if set interrupts are enabled although "PCI Interrupt
  78. * Disable" may still globally block interrupts in addition to individual
  79. * interrupt masks; a mechanism for the device driver to block all interrupts
  80. * atomically without having to arbitrate for the PCI Interrupt Disable bit
  81. * with the OS.
  82. */
  83. #define MEMBAR_CTRL_INT_CTRL_HOSTINTR_MASK (1 << 29) /* bit 29 */
  84. /********* ISR0 Register offset **********/
  85. #define CEV_ISR0_OFFSET 0xC18
  86. #define CEV_ISR_SIZE 4
  87. /**
  88. * Macros for reading/writing a protection domain or CSR registers
  89. * in BladeEngine.
  90. */
  91. #define DB_TXULP0_OFFSET 0x40
  92. #define DB_RXULP0_OFFSET 0xA0
  93. /********* Event Q door bell *************/
  94. #define DB_EQ_OFFSET DB_CQ_OFFSET
  95. #define DB_EQ_RING_ID_LOW_MASK 0x1FF /* bits 0 - 8 */
  96. /* Clear the interrupt for this eq */
  97. #define DB_EQ_CLR_SHIFT (9) /* bit 9 */
  98. /* Must be 1 */
  99. #define DB_EQ_EVNT_SHIFT (10) /* bit 10 */
  100. /* Higher Order EQ_ID bit */
  101. #define DB_EQ_RING_ID_HIGH_MASK 0x1F /* bits 11 - 15 */
  102. #define DB_EQ_HIGH_SET_SHIFT 11
  103. #define DB_EQ_HIGH_FEILD_SHIFT 9
  104. /* Number of event entries processed */
  105. #define DB_EQ_NUM_POPPED_SHIFT (16) /* bits 16 - 28 */
  106. /* Rearm bit */
  107. #define DB_EQ_REARM_SHIFT (29) /* bit 29 */
  108. /********* Compl Q door bell *************/
  109. #define DB_CQ_OFFSET 0x120
  110. #define DB_CQ_RING_ID_LOW_MASK 0x3FF /* bits 0 - 9 */
  111. /* Higher Order CQ_ID bit */
  112. #define DB_CQ_RING_ID_HIGH_MASK 0x1F /* bits 11 - 15 */
  113. #define DB_CQ_HIGH_SET_SHIFT 11
  114. #define DB_CQ_HIGH_FEILD_SHIFT 10
  115. /* Number of event entries processed */
  116. #define DB_CQ_NUM_POPPED_SHIFT (16) /* bits 16 - 28 */
  117. /* Rearm bit */
  118. #define DB_CQ_REARM_SHIFT (29) /* bit 29 */
  119. #define GET_HWI_CONTROLLER_WS(pc) (pc->phwi_ctrlr)
  120. #define HWI_GET_DEF_BUFQ_ID(pc, ulp_num) (((struct hwi_controller *)\
  121. (GET_HWI_CONTROLLER_WS(pc)))->default_pdu_data[ulp_num].id)
  122. #define HWI_GET_DEF_HDRQ_ID(pc, ulp_num) (((struct hwi_controller *)\
  123. (GET_HWI_CONTROLLER_WS(pc)))->default_pdu_hdr[ulp_num].id)
  124. #define PAGES_REQUIRED(x) \
  125. ((x < PAGE_SIZE) ? 1 : ((x + PAGE_SIZE - 1) / PAGE_SIZE))
  126. #define MEM_DESCR_OFFSET 8
  127. #define BEISCSI_DEFQ_HDR 1
  128. #define BEISCSI_DEFQ_DATA 0
  129. enum be_mem_enum {
  130. HWI_MEM_ADDN_CONTEXT,
  131. HWI_MEM_WRB,
  132. HWI_MEM_WRBH,
  133. HWI_MEM_SGLH,
  134. HWI_MEM_SGE,
  135. HWI_MEM_TEMPLATE_HDR_ULP0,
  136. HWI_MEM_ASYNC_HEADER_BUF_ULP0, /* 6 */
  137. HWI_MEM_ASYNC_DATA_BUF_ULP0,
  138. HWI_MEM_ASYNC_HEADER_RING_ULP0,
  139. HWI_MEM_ASYNC_DATA_RING_ULP0,
  140. HWI_MEM_ASYNC_HEADER_HANDLE_ULP0,
  141. HWI_MEM_ASYNC_DATA_HANDLE_ULP0, /* 11 */
  142. HWI_MEM_ASYNC_PDU_CONTEXT_ULP0,
  143. HWI_MEM_TEMPLATE_HDR_ULP1,
  144. HWI_MEM_ASYNC_HEADER_BUF_ULP1, /* 14 */
  145. HWI_MEM_ASYNC_DATA_BUF_ULP1,
  146. HWI_MEM_ASYNC_HEADER_RING_ULP1,
  147. HWI_MEM_ASYNC_DATA_RING_ULP1,
  148. HWI_MEM_ASYNC_HEADER_HANDLE_ULP1,
  149. HWI_MEM_ASYNC_DATA_HANDLE_ULP1, /* 19 */
  150. HWI_MEM_ASYNC_PDU_CONTEXT_ULP1,
  151. ISCSI_MEM_GLOBAL_HEADER,
  152. SE_MEM_MAX
  153. };
  154. struct be_bus_address32 {
  155. unsigned int address_lo;
  156. unsigned int address_hi;
  157. };
  158. struct be_bus_address64 {
  159. unsigned long long address;
  160. };
  161. struct be_bus_address {
  162. union {
  163. struct be_bus_address32 a32;
  164. struct be_bus_address64 a64;
  165. } u;
  166. };
  167. struct mem_array {
  168. struct be_bus_address bus_address; /* Bus address of location */
  169. void *virtual_address; /* virtual address to the location */
  170. unsigned int size; /* Size required by memory block */
  171. };
  172. struct be_mem_descriptor {
  173. unsigned int size_in_bytes; /* Size required by memory block */
  174. unsigned int num_elements;
  175. struct mem_array *mem_array;
  176. };
  177. struct sgl_handle {
  178. unsigned int sgl_index;
  179. unsigned int type;
  180. unsigned int cid;
  181. struct iscsi_task *task;
  182. struct iscsi_sge *pfrag;
  183. };
  184. struct hba_parameters {
  185. unsigned int ios_per_ctrl;
  186. unsigned int cxns_per_ctrl;
  187. unsigned int icds_per_ctrl;
  188. unsigned int num_sge_per_io;
  189. unsigned int defpdu_hdr_sz;
  190. unsigned int defpdu_data_sz;
  191. unsigned int num_cq_entries;
  192. unsigned int num_eq_entries;
  193. unsigned int wrbs_per_cxn;
  194. unsigned int hwi_ws_sz;
  195. };
  196. #define BEISCSI_GET_ULP_FROM_CRI(phwi_ctrlr, cri) \
  197. (phwi_ctrlr->wrb_context[cri].ulp_num)
  198. struct hwi_wrb_context {
  199. spinlock_t wrb_lock;
  200. struct wrb_handle **pwrb_handle_base;
  201. struct wrb_handle **pwrb_handle_basestd;
  202. struct iscsi_wrb *plast_wrb;
  203. unsigned short alloc_index;
  204. unsigned short free_index;
  205. unsigned short wrb_handles_available;
  206. unsigned short cid;
  207. uint8_t ulp_num; /* ULP to which CID binded */
  208. uint32_t doorbell_offset;
  209. };
  210. struct ulp_cid_info {
  211. unsigned short *cid_array;
  212. unsigned short avlbl_cids;
  213. unsigned short cid_alloc;
  214. unsigned short cid_free;
  215. };
  216. #include "be.h"
  217. #define chip_be2(phba) (phba->generation == BE_GEN2)
  218. #define chip_be3_r(phba) (phba->generation == BE_GEN3)
  219. #define is_chip_be2_be3r(phba) (chip_be3_r(phba) || (chip_be2(phba)))
  220. #define BEISCSI_ULP0 0
  221. #define BEISCSI_ULP1 1
  222. #define BEISCSI_ULP_COUNT 2
  223. #define BEISCSI_ULP0_LOADED 0x01
  224. #define BEISCSI_ULP1_LOADED 0x02
  225. #define BEISCSI_ULP_AVLBL_CID(phba, ulp_num) \
  226. (((struct ulp_cid_info *)phba->cid_array_info[ulp_num])->avlbl_cids)
  227. #define BEISCSI_ULP0_AVLBL_CID(phba) \
  228. BEISCSI_ULP_AVLBL_CID(phba, BEISCSI_ULP0)
  229. #define BEISCSI_ULP1_AVLBL_CID(phba) \
  230. BEISCSI_ULP_AVLBL_CID(phba, BEISCSI_ULP1)
  231. struct beiscsi_hba {
  232. struct hba_parameters params;
  233. struct hwi_controller *phwi_ctrlr;
  234. unsigned int mem_req[SE_MEM_MAX];
  235. /* PCI BAR mapped addresses */
  236. u8 __iomem *csr_va; /* CSR */
  237. u8 __iomem *db_va; /* Door Bell */
  238. u8 __iomem *pci_va; /* PCI Config */
  239. /* PCI representation of our HBA */
  240. struct pci_dev *pcidev;
  241. unsigned int num_cpus;
  242. unsigned int nxt_cqid;
  243. char *msi_name[MAX_CPUS];
  244. struct be_mem_descriptor *init_mem;
  245. unsigned short io_sgl_alloc_index;
  246. unsigned short io_sgl_free_index;
  247. unsigned short io_sgl_hndl_avbl;
  248. struct sgl_handle **io_sgl_hndl_base;
  249. unsigned short eh_sgl_alloc_index;
  250. unsigned short eh_sgl_free_index;
  251. unsigned short eh_sgl_hndl_avbl;
  252. struct sgl_handle **eh_sgl_hndl_base;
  253. spinlock_t io_sgl_lock;
  254. spinlock_t mgmt_sgl_lock;
  255. spinlock_t async_pdu_lock;
  256. struct list_head hba_queue;
  257. #define BE_MAX_SESSION 2048
  258. #define BE_INVALID_CID 0xffff
  259. #define BE_SET_CID_TO_CRI(cri_index, cid) \
  260. (phba->cid_to_cri_map[cid] = cri_index)
  261. #define BE_GET_CRI_FROM_CID(cid) (phba->cid_to_cri_map[cid])
  262. unsigned short cid_to_cri_map[BE_MAX_SESSION];
  263. struct ulp_cid_info *cid_array_info[BEISCSI_ULP_COUNT];
  264. struct iscsi_endpoint **ep_array;
  265. struct beiscsi_conn **conn_table;
  266. struct Scsi_Host *shost;
  267. struct iscsi_iface *ipv4_iface;
  268. struct iscsi_iface *ipv6_iface;
  269. struct {
  270. /**
  271. * group together since they are used most frequently
  272. * for cid to cri conversion
  273. */
  274. #define BEISCSI_PHYS_PORT_MAX 4
  275. unsigned int phys_port;
  276. /* valid values of phys_port id are 0, 1, 2, 3 */
  277. unsigned int eqid_count;
  278. unsigned int cqid_count;
  279. unsigned int iscsi_cid_start[BEISCSI_ULP_COUNT];
  280. #define BEISCSI_GET_CID_COUNT(phba, ulp_num) \
  281. (phba->fw_config.iscsi_cid_count[ulp_num])
  282. unsigned int iscsi_cid_count[BEISCSI_ULP_COUNT];
  283. unsigned int iscsi_icd_count[BEISCSI_ULP_COUNT];
  284. unsigned int iscsi_icd_start[BEISCSI_ULP_COUNT];
  285. unsigned int iscsi_chain_start[BEISCSI_ULP_COUNT];
  286. unsigned int iscsi_chain_count[BEISCSI_ULP_COUNT];
  287. unsigned short iscsi_features;
  288. uint16_t dual_ulp_aware;
  289. unsigned long ulp_supported;
  290. } fw_config;
  291. unsigned long state;
  292. #define BEISCSI_HBA_ONLINE 0
  293. #define BEISCSI_HBA_LINK_UP 1
  294. #define BEISCSI_HBA_BOOT_FOUND 2
  295. #define BEISCSI_HBA_BOOT_WORK 3
  296. #define BEISCSI_HBA_UER_SUPP 4
  297. #define BEISCSI_HBA_PCI_ERR 5
  298. #define BEISCSI_HBA_FW_TIMEOUT 6
  299. #define BEISCSI_HBA_IN_UE 7
  300. #define BEISCSI_HBA_IN_TPE 8
  301. /* error bits */
  302. #define BEISCSI_HBA_IN_ERR ((1 << BEISCSI_HBA_PCI_ERR) | \
  303. (1 << BEISCSI_HBA_FW_TIMEOUT) | \
  304. (1 << BEISCSI_HBA_IN_UE) | \
  305. (1 << BEISCSI_HBA_IN_TPE))
  306. u8 optic_state;
  307. struct delayed_work eqd_update;
  308. /* update EQ delay timer every 1000ms */
  309. #define BEISCSI_EQD_UPDATE_INTERVAL 1000
  310. struct timer_list hw_check;
  311. /* check for UE every 1000ms */
  312. #define BEISCSI_UE_DETECT_INTERVAL 1000
  313. u32 ue2rp;
  314. struct delayed_work recover_port;
  315. struct work_struct sess_work;
  316. bool mac_addr_set;
  317. u8 mac_address[ETH_ALEN];
  318. u8 port_name;
  319. u8 port_speed;
  320. char fw_ver_str[BEISCSI_VER_STRLEN];
  321. struct workqueue_struct *wq; /* The actuak work queue */
  322. struct be_ctrl_info ctrl;
  323. unsigned int generation;
  324. unsigned int interface_handle;
  325. struct be_aic_obj aic_obj[MAX_CPUS];
  326. unsigned int attr_log_enable;
  327. int (*iotask_fn)(struct iscsi_task *,
  328. struct scatterlist *sg,
  329. uint32_t num_sg, uint32_t xferlen,
  330. uint32_t writedir);
  331. struct boot_struct {
  332. int retry;
  333. unsigned int tag;
  334. unsigned int s_handle;
  335. struct be_dma_mem nonemb_cmd;
  336. enum {
  337. BEISCSI_BOOT_REOPEN_SESS = 1,
  338. BEISCSI_BOOT_GET_SHANDLE,
  339. BEISCSI_BOOT_GET_SINFO,
  340. BEISCSI_BOOT_LOGOUT_SESS,
  341. BEISCSI_BOOT_CREATE_KSET,
  342. } action;
  343. struct mgmt_session_info boot_sess;
  344. struct iscsi_boot_kset *boot_kset;
  345. } boot_struct;
  346. struct work_struct boot_work;
  347. };
  348. #define beiscsi_hba_in_error(phba) ((phba)->state & BEISCSI_HBA_IN_ERR)
  349. #define beiscsi_hba_is_online(phba) \
  350. (!beiscsi_hba_in_error((phba)) && \
  351. test_bit(BEISCSI_HBA_ONLINE, &phba->state))
  352. struct beiscsi_session {
  353. struct dma_pool *bhs_pool;
  354. };
  355. /**
  356. * struct beiscsi_conn - iscsi connection structure
  357. */
  358. struct beiscsi_conn {
  359. struct iscsi_conn *conn;
  360. struct beiscsi_hba *phba;
  361. u32 exp_statsn;
  362. u32 doorbell_offset;
  363. u32 beiscsi_conn_cid;
  364. struct beiscsi_endpoint *ep;
  365. unsigned short login_in_progress;
  366. struct wrb_handle *plogin_wrb_handle;
  367. struct sgl_handle *plogin_sgl_handle;
  368. struct beiscsi_session *beiscsi_sess;
  369. struct iscsi_task *task;
  370. };
  371. /* This structure is used by the chip */
  372. struct pdu_data_out {
  373. u32 dw[12];
  374. };
  375. /**
  376. * Pseudo amap definition in which each bit of the actual structure is defined
  377. * as a byte: used to calculate offset/shift/mask of each field
  378. */
  379. struct amap_pdu_data_out {
  380. u8 opcode[6]; /* opcode */
  381. u8 rsvd0[2]; /* should be 0 */
  382. u8 rsvd1[7];
  383. u8 final_bit; /* F bit */
  384. u8 rsvd2[16];
  385. u8 ahs_length[8]; /* no AHS */
  386. u8 data_len_hi[8];
  387. u8 data_len_lo[16]; /* DataSegmentLength */
  388. u8 lun[64];
  389. u8 itt[32]; /* ITT; initiator task tag */
  390. u8 ttt[32]; /* TTT; valid for R2T or 0xffffffff */
  391. u8 rsvd3[32];
  392. u8 exp_stat_sn[32];
  393. u8 rsvd4[32];
  394. u8 data_sn[32];
  395. u8 buffer_offset[32];
  396. u8 rsvd5[32];
  397. };
  398. struct be_cmd_bhs {
  399. struct iscsi_scsi_req iscsi_hdr;
  400. unsigned char pad1[16];
  401. struct pdu_data_out iscsi_data_pdu;
  402. unsigned char pad2[BE_SENSE_INFO_SIZE -
  403. sizeof(struct pdu_data_out)];
  404. };
  405. struct beiscsi_io_task {
  406. struct wrb_handle *pwrb_handle;
  407. struct sgl_handle *psgl_handle;
  408. struct beiscsi_conn *conn;
  409. struct scsi_cmnd *scsi_cmnd;
  410. int num_sg;
  411. struct hwi_wrb_context *pwrb_context;
  412. itt_t libiscsi_itt;
  413. struct be_cmd_bhs *cmd_bhs;
  414. struct be_bus_address bhs_pa;
  415. unsigned short bhs_len;
  416. dma_addr_t mtask_addr;
  417. uint32_t mtask_data_count;
  418. uint8_t wrb_type;
  419. };
  420. struct be_nonio_bhs {
  421. struct iscsi_hdr iscsi_hdr;
  422. unsigned char pad1[16];
  423. struct pdu_data_out iscsi_data_pdu;
  424. unsigned char pad2[BE_SENSE_INFO_SIZE -
  425. sizeof(struct pdu_data_out)];
  426. };
  427. struct be_status_bhs {
  428. struct iscsi_scsi_req iscsi_hdr;
  429. unsigned char pad1[16];
  430. /**
  431. * The plus 2 below is to hold the sense info length that gets
  432. * DMA'ed by RxULP
  433. */
  434. unsigned char sense_info[BE_SENSE_INFO_SIZE];
  435. };
  436. struct iscsi_sge {
  437. u32 dw[4];
  438. };
  439. /**
  440. * Pseudo amap definition in which each bit of the actual structure is defined
  441. * as a byte: used to calculate offset/shift/mask of each field
  442. */
  443. struct amap_iscsi_sge {
  444. u8 addr_hi[32];
  445. u8 addr_lo[32];
  446. u8 sge_offset[22]; /* DWORD 2 */
  447. u8 rsvd0[9]; /* DWORD 2 */
  448. u8 last_sge; /* DWORD 2 */
  449. u8 len[17]; /* DWORD 3 */
  450. u8 rsvd1[15]; /* DWORD 3 */
  451. };
  452. struct beiscsi_offload_params {
  453. u32 dw[6];
  454. };
  455. #define OFFLD_PARAMS_ERL 0x00000003
  456. #define OFFLD_PARAMS_DDE 0x00000004
  457. #define OFFLD_PARAMS_HDE 0x00000008
  458. #define OFFLD_PARAMS_IR2T 0x00000010
  459. #define OFFLD_PARAMS_IMD 0x00000020
  460. #define OFFLD_PARAMS_DATA_SEQ_INORDER 0x00000040
  461. #define OFFLD_PARAMS_PDU_SEQ_INORDER 0x00000080
  462. #define OFFLD_PARAMS_MAX_R2T 0x00FFFF00
  463. /**
  464. * Pseudo amap definition in which each bit of the actual structure is defined
  465. * as a byte: used to calculate offset/shift/mask of each field
  466. */
  467. struct amap_beiscsi_offload_params {
  468. u8 max_burst_length[32];
  469. u8 max_send_data_segment_length[32];
  470. u8 first_burst_length[32];
  471. u8 erl[2];
  472. u8 dde[1];
  473. u8 hde[1];
  474. u8 ir2t[1];
  475. u8 imd[1];
  476. u8 data_seq_inorder[1];
  477. u8 pdu_seq_inorder[1];
  478. u8 max_r2t[16];
  479. u8 pad[8];
  480. u8 exp_statsn[32];
  481. u8 max_recv_data_segment_length[32];
  482. };
  483. struct hd_async_handle {
  484. struct list_head link;
  485. struct be_bus_address pa;
  486. void *pbuffer;
  487. u32 buffer_len;
  488. u16 index;
  489. u16 cri;
  490. u8 is_header;
  491. u8 is_final;
  492. u8 in_use;
  493. };
  494. #define BEISCSI_ASYNC_HDQ_SIZE(phba, ulp) \
  495. (BEISCSI_GET_CID_COUNT((phba), (ulp)) * 2)
  496. /**
  497. * This has list of async PDUs that are waiting to be processed.
  498. * Buffers live in this list for a brief duration before they get
  499. * processed and posted back to hardware.
  500. * Note that we don't really need one cri_wait_queue per async_entry.
  501. * We need one cri_wait_queue per CRI. Its easier to manage if this
  502. * is tagged along with the async_entry.
  503. */
  504. struct hd_async_entry {
  505. struct cri_wait_queue {
  506. unsigned short hdr_len;
  507. unsigned int bytes_received;
  508. unsigned int bytes_needed;
  509. struct list_head list;
  510. } wq;
  511. /* handles posted to FW resides here */
  512. struct hd_async_handle *header;
  513. struct hd_async_handle *data;
  514. };
  515. struct hd_async_buf_context {
  516. struct be_bus_address pa_base;
  517. void *va_base;
  518. void *ring_base;
  519. struct hd_async_handle *handle_base;
  520. u32 buffer_size;
  521. u16 pi;
  522. };
  523. /**
  524. * hd_async_context is declared for each ULP supporting iSCSI function.
  525. */
  526. struct hd_async_context {
  527. struct hd_async_buf_context async_header;
  528. struct hd_async_buf_context async_data;
  529. u16 num_entries;
  530. /**
  531. * When unsol PDU is in, it needs to be chained till all the bytes are
  532. * received and then processing is done. hd_async_entry is created
  533. * based on the cid_count for each ULP. When unsol PDU comes in based
  534. * on the conn_id it needs to be added to the correct async_entry wq.
  535. * Below defined cid_to_async_cri_map is used to reterive the
  536. * async_cri_map for a particular connection.
  537. *
  538. * This array is initialized after beiscsi_create_wrb_rings returns.
  539. *
  540. * - this method takes more memory space, fixed to 2K
  541. * - any support for connections greater than this the array size needs
  542. * to be incremented
  543. */
  544. #define BE_GET_ASYNC_CRI_FROM_CID(cid) (pasync_ctx->cid_to_async_cri_map[cid])
  545. unsigned short cid_to_async_cri_map[BE_MAX_SESSION];
  546. /**
  547. * This is a variable size array. Don`t add anything after this field!!
  548. */
  549. struct hd_async_entry *async_entry;
  550. };
  551. struct i_t_dpdu_cqe {
  552. u32 dw[4];
  553. } __packed;
  554. /**
  555. * Pseudo amap definition in which each bit of the actual structure is defined
  556. * as a byte: used to calculate offset/shift/mask of each field
  557. */
  558. struct amap_i_t_dpdu_cqe {
  559. u8 db_addr_hi[32];
  560. u8 db_addr_lo[32];
  561. u8 code[6];
  562. u8 cid[10];
  563. u8 dpl[16];
  564. u8 index[16];
  565. u8 num_cons[10];
  566. u8 rsvd0[4];
  567. u8 final;
  568. u8 valid;
  569. } __packed;
  570. struct amap_i_t_dpdu_cqe_v2 {
  571. u8 db_addr_hi[32]; /* DWORD 0 */
  572. u8 db_addr_lo[32]; /* DWORD 1 */
  573. u8 code[6]; /* DWORD 2 */
  574. u8 num_cons; /* DWORD 2*/
  575. u8 rsvd0[8]; /* DWORD 2 */
  576. u8 dpl[17]; /* DWORD 2 */
  577. u8 index[16]; /* DWORD 3 */
  578. u8 cid[13]; /* DWORD 3 */
  579. u8 rsvd1; /* DWORD 3 */
  580. u8 final; /* DWORD 3 */
  581. u8 valid; /* DWORD 3 */
  582. } __packed;
  583. #define CQE_VALID_MASK 0x80000000
  584. #define CQE_CODE_MASK 0x0000003F
  585. #define CQE_CID_MASK 0x0000FFC0
  586. #define EQE_VALID_MASK 0x00000001
  587. #define EQE_MAJORCODE_MASK 0x0000000E
  588. #define EQE_RESID_MASK 0xFFFF0000
  589. struct be_eq_entry {
  590. u32 dw[1];
  591. } __packed;
  592. /**
  593. * Pseudo amap definition in which each bit of the actual structure is defined
  594. * as a byte: used to calculate offset/shift/mask of each field
  595. */
  596. struct amap_eq_entry {
  597. u8 valid; /* DWORD 0 */
  598. u8 major_code[3]; /* DWORD 0 */
  599. u8 minor_code[12]; /* DWORD 0 */
  600. u8 resource_id[16]; /* DWORD 0 */
  601. } __packed;
  602. struct cq_db {
  603. u32 dw[1];
  604. } __packed;
  605. /**
  606. * Pseudo amap definition in which each bit of the actual structure is defined
  607. * as a byte: used to calculate offset/shift/mask of each field
  608. */
  609. struct amap_cq_db {
  610. u8 qid[10];
  611. u8 event[1];
  612. u8 rsvd0[5];
  613. u8 num_popped[13];
  614. u8 rearm[1];
  615. u8 rsvd1[2];
  616. } __packed;
  617. void beiscsi_process_eq(struct beiscsi_hba *phba);
  618. struct iscsi_wrb {
  619. u32 dw[16];
  620. } __packed;
  621. #define WRB_TYPE_MASK 0xF0000000
  622. #define SKH_WRB_TYPE_OFFSET 27
  623. #define BE_WRB_TYPE_OFFSET 28
  624. #define ADAPTER_SET_WRB_TYPE(pwrb, wrb_type, type_offset) \
  625. (pwrb->dw[0] |= (wrb_type << type_offset))
  626. /**
  627. * Pseudo amap definition in which each bit of the actual structure is defined
  628. * as a byte: used to calculate offset/shift/mask of each field
  629. */
  630. struct amap_iscsi_wrb {
  631. u8 lun[14]; /* DWORD 0 */
  632. u8 lt; /* DWORD 0 */
  633. u8 invld; /* DWORD 0 */
  634. u8 wrb_idx[8]; /* DWORD 0 */
  635. u8 dsp; /* DWORD 0 */
  636. u8 dmsg; /* DWORD 0 */
  637. u8 undr_run; /* DWORD 0 */
  638. u8 over_run; /* DWORD 0 */
  639. u8 type[4]; /* DWORD 0 */
  640. u8 ptr2nextwrb[8]; /* DWORD 1 */
  641. u8 r2t_exp_dtl[24]; /* DWORD 1 */
  642. u8 sgl_icd_idx[12]; /* DWORD 2 */
  643. u8 rsvd0[20]; /* DWORD 2 */
  644. u8 exp_data_sn[32]; /* DWORD 3 */
  645. u8 iscsi_bhs_addr_hi[32]; /* DWORD 4 */
  646. u8 iscsi_bhs_addr_lo[32]; /* DWORD 5 */
  647. u8 cmdsn_itt[32]; /* DWORD 6 */
  648. u8 dif_ref_tag[32]; /* DWORD 7 */
  649. u8 sge0_addr_hi[32]; /* DWORD 8 */
  650. u8 sge0_addr_lo[32]; /* DWORD 9 */
  651. u8 sge0_offset[22]; /* DWORD 10 */
  652. u8 pbs; /* DWORD 10 */
  653. u8 dif_mode[2]; /* DWORD 10 */
  654. u8 rsvd1[6]; /* DWORD 10 */
  655. u8 sge0_last; /* DWORD 10 */
  656. u8 sge0_len[17]; /* DWORD 11 */
  657. u8 dif_meta_tag[14]; /* DWORD 11 */
  658. u8 sge0_in_ddr; /* DWORD 11 */
  659. u8 sge1_addr_hi[32]; /* DWORD 12 */
  660. u8 sge1_addr_lo[32]; /* DWORD 13 */
  661. u8 sge1_r2t_offset[22]; /* DWORD 14 */
  662. u8 rsvd2[9]; /* DWORD 14 */
  663. u8 sge1_last; /* DWORD 14 */
  664. u8 sge1_len[17]; /* DWORD 15 */
  665. u8 ref_sgl_icd_idx[12]; /* DWORD 15 */
  666. u8 rsvd3[2]; /* DWORD 15 */
  667. u8 sge1_in_ddr; /* DWORD 15 */
  668. } __packed;
  669. struct amap_iscsi_wrb_v2 {
  670. u8 r2t_exp_dtl[25]; /* DWORD 0 */
  671. u8 rsvd0[2]; /* DWORD 0*/
  672. u8 type[5]; /* DWORD 0 */
  673. u8 ptr2nextwrb[8]; /* DWORD 1 */
  674. u8 wrb_idx[8]; /* DWORD 1 */
  675. u8 lun[16]; /* DWORD 1 */
  676. u8 sgl_idx[16]; /* DWORD 2 */
  677. u8 ref_sgl_icd_idx[16]; /* DWORD 2 */
  678. u8 exp_data_sn[32]; /* DWORD 3 */
  679. u8 iscsi_bhs_addr_hi[32]; /* DWORD 4 */
  680. u8 iscsi_bhs_addr_lo[32]; /* DWORD 5 */
  681. u8 cq_id[16]; /* DWORD 6 */
  682. u8 rsvd1[16]; /* DWORD 6 */
  683. u8 cmdsn_itt[32]; /* DWORD 7 */
  684. u8 sge0_addr_hi[32]; /* DWORD 8 */
  685. u8 sge0_addr_lo[32]; /* DWORD 9 */
  686. u8 sge0_offset[24]; /* DWORD 10 */
  687. u8 rsvd2[7]; /* DWORD 10 */
  688. u8 sge0_last; /* DWORD 10 */
  689. u8 sge0_len[17]; /* DWORD 11 */
  690. u8 rsvd3[7]; /* DWORD 11 */
  691. u8 diff_enbl; /* DWORD 11 */
  692. u8 u_run; /* DWORD 11 */
  693. u8 o_run; /* DWORD 11 */
  694. u8 invld; /* DWORD 11 */
  695. u8 dsp; /* DWORD 11 */
  696. u8 dmsg; /* DWORD 11 */
  697. u8 rsvd4; /* DWORD 11 */
  698. u8 lt; /* DWORD 11 */
  699. u8 sge1_addr_hi[32]; /* DWORD 12 */
  700. u8 sge1_addr_lo[32]; /* DWORD 13 */
  701. u8 sge1_r2t_offset[24]; /* DWORD 14 */
  702. u8 rsvd5[7]; /* DWORD 14 */
  703. u8 sge1_last; /* DWORD 14 */
  704. u8 sge1_len[17]; /* DWORD 15 */
  705. u8 rsvd6[15]; /* DWORD 15 */
  706. } __packed;
  707. struct wrb_handle *alloc_wrb_handle(struct beiscsi_hba *phba, unsigned int cid,
  708. struct hwi_wrb_context **pcontext);
  709. void
  710. free_mgmt_sgl_handle(struct beiscsi_hba *phba, struct sgl_handle *psgl_handle);
  711. void beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
  712. struct iscsi_task *task);
  713. void hwi_ring_cq_db(struct beiscsi_hba *phba,
  714. unsigned int id, unsigned int num_processed,
  715. unsigned char rearm);
  716. unsigned int beiscsi_process_cq(struct be_eq_obj *pbe_eq, int budget);
  717. void beiscsi_process_mcc_cq(struct beiscsi_hba *phba);
  718. struct pdu_nop_out {
  719. u32 dw[12];
  720. };
  721. /**
  722. * Pseudo amap definition in which each bit of the actual structure is defined
  723. * as a byte: used to calculate offset/shift/mask of each field
  724. */
  725. struct amap_pdu_nop_out {
  726. u8 opcode[6]; /* opcode 0x00 */
  727. u8 i_bit; /* I Bit */
  728. u8 x_bit; /* reserved; should be 0 */
  729. u8 fp_bit_filler1[7];
  730. u8 f_bit; /* always 1 */
  731. u8 reserved1[16];
  732. u8 ahs_length[8]; /* no AHS */
  733. u8 data_len_hi[8];
  734. u8 data_len_lo[16]; /* DataSegmentLength */
  735. u8 lun[64];
  736. u8 itt[32]; /* initiator id for ping or 0xffffffff */
  737. u8 ttt[32]; /* target id for ping or 0xffffffff */
  738. u8 cmd_sn[32];
  739. u8 exp_stat_sn[32];
  740. u8 reserved5[128];
  741. };
  742. #define PDUBASE_OPCODE_MASK 0x0000003F
  743. #define PDUBASE_DATALENHI_MASK 0x0000FF00
  744. #define PDUBASE_DATALENLO_MASK 0xFFFF0000
  745. struct pdu_base {
  746. u32 dw[16];
  747. } __packed;
  748. /**
  749. * Pseudo amap definition in which each bit of the actual structure is defined
  750. * as a byte: used to calculate offset/shift/mask of each field
  751. */
  752. struct amap_pdu_base {
  753. u8 opcode[6];
  754. u8 i_bit; /* immediate bit */
  755. u8 x_bit; /* reserved, always 0 */
  756. u8 reserved1[24]; /* opcode-specific fields */
  757. u8 ahs_length[8]; /* length units is 4 byte words */
  758. u8 data_len_hi[8];
  759. u8 data_len_lo[16]; /* DatasegmentLength */
  760. u8 lun[64]; /* lun or opcode-specific fields */
  761. u8 itt[32]; /* initiator task tag */
  762. u8 reserved4[224];
  763. };
  764. struct iscsi_target_context_update_wrb {
  765. u32 dw[16];
  766. } __packed;
  767. /**
  768. * Pseudo amap definition in which each bit of the actual structure is defined
  769. * as a byte: used to calculate offset/shift/mask of each field
  770. */
  771. #define BE_TGT_CTX_UPDT_CMD 0x07
  772. struct amap_iscsi_target_context_update_wrb {
  773. u8 lun[14]; /* DWORD 0 */
  774. u8 lt; /* DWORD 0 */
  775. u8 invld; /* DWORD 0 */
  776. u8 wrb_idx[8]; /* DWORD 0 */
  777. u8 dsp; /* DWORD 0 */
  778. u8 dmsg; /* DWORD 0 */
  779. u8 undr_run; /* DWORD 0 */
  780. u8 over_run; /* DWORD 0 */
  781. u8 type[4]; /* DWORD 0 */
  782. u8 ptr2nextwrb[8]; /* DWORD 1 */
  783. u8 max_burst_length[19]; /* DWORD 1 */
  784. u8 rsvd0[5]; /* DWORD 1 */
  785. u8 rsvd1[15]; /* DWORD 2 */
  786. u8 max_send_data_segment_length[17]; /* DWORD 2 */
  787. u8 first_burst_length[14]; /* DWORD 3 */
  788. u8 rsvd2[2]; /* DWORD 3 */
  789. u8 tx_wrbindex_drv_msg[8]; /* DWORD 3 */
  790. u8 rsvd3[5]; /* DWORD 3 */
  791. u8 session_state[3]; /* DWORD 3 */
  792. u8 rsvd4[16]; /* DWORD 4 */
  793. u8 tx_jumbo; /* DWORD 4 */
  794. u8 hde; /* DWORD 4 */
  795. u8 dde; /* DWORD 4 */
  796. u8 erl[2]; /* DWORD 4 */
  797. u8 domain_id[5]; /* DWORD 4 */
  798. u8 mode; /* DWORD 4 */
  799. u8 imd; /* DWORD 4 */
  800. u8 ir2t; /* DWORD 4 */
  801. u8 notpredblq[2]; /* DWORD 4 */
  802. u8 compltonack; /* DWORD 4 */
  803. u8 stat_sn[32]; /* DWORD 5 */
  804. u8 pad_buffer_addr_hi[32]; /* DWORD 6 */
  805. u8 pad_buffer_addr_lo[32]; /* DWORD 7 */
  806. u8 pad_addr_hi[32]; /* DWORD 8 */
  807. u8 pad_addr_lo[32]; /* DWORD 9 */
  808. u8 rsvd5[32]; /* DWORD 10 */
  809. u8 rsvd6[32]; /* DWORD 11 */
  810. u8 rsvd7[32]; /* DWORD 12 */
  811. u8 rsvd8[32]; /* DWORD 13 */
  812. u8 rsvd9[32]; /* DWORD 14 */
  813. u8 rsvd10[32]; /* DWORD 15 */
  814. } __packed;
  815. #define BEISCSI_MAX_RECV_DATASEG_LEN (64 * 1024)
  816. #define BEISCSI_MAX_CXNS 1
  817. struct amap_iscsi_target_context_update_wrb_v2 {
  818. u8 max_burst_length[24]; /* DWORD 0 */
  819. u8 rsvd0[3]; /* DWORD 0 */
  820. u8 type[5]; /* DWORD 0 */
  821. u8 ptr2nextwrb[8]; /* DWORD 1 */
  822. u8 wrb_idx[8]; /* DWORD 1 */
  823. u8 rsvd1[16]; /* DWORD 1 */
  824. u8 max_send_data_segment_length[24]; /* DWORD 2 */
  825. u8 rsvd2[8]; /* DWORD 2 */
  826. u8 first_burst_length[24]; /* DWORD 3 */
  827. u8 rsvd3[8]; /* DOWRD 3 */
  828. u8 max_r2t[16]; /* DWORD 4 */
  829. u8 rsvd4; /* DWORD 4 */
  830. u8 hde; /* DWORD 4 */
  831. u8 dde; /* DWORD 4 */
  832. u8 erl[2]; /* DWORD 4 */
  833. u8 rsvd5[6]; /* DWORD 4 */
  834. u8 imd; /* DWORD 4 */
  835. u8 ir2t; /* DWORD 4 */
  836. u8 rsvd6[3]; /* DWORD 4 */
  837. u8 stat_sn[32]; /* DWORD 5 */
  838. u8 rsvd7[32]; /* DWORD 6 */
  839. u8 rsvd8[32]; /* DWORD 7 */
  840. u8 max_recv_dataseg_len[24]; /* DWORD 8 */
  841. u8 rsvd9[8]; /* DWORD 8 */
  842. u8 rsvd10[32]; /* DWORD 9 */
  843. u8 rsvd11[32]; /* DWORD 10 */
  844. u8 max_cxns[16]; /* DWORD 11 */
  845. u8 rsvd12[11]; /* DWORD 11*/
  846. u8 invld; /* DWORD 11 */
  847. u8 rsvd13;/* DWORD 11*/
  848. u8 dmsg; /* DWORD 11 */
  849. u8 data_seq_inorder; /* DWORD 11 */
  850. u8 pdu_seq_inorder; /* DWORD 11 */
  851. u8 rsvd14[32]; /*DWORD 12 */
  852. u8 rsvd15[32]; /* DWORD 13 */
  853. u8 rsvd16[32]; /* DWORD 14 */
  854. u8 rsvd17[32]; /* DWORD 15 */
  855. } __packed;
  856. struct be_ring {
  857. u32 pages; /* queue size in pages */
  858. u32 id; /* queue id assigned by beklib */
  859. u32 num; /* number of elements in queue */
  860. u32 cidx; /* consumer index */
  861. u32 pidx; /* producer index -- not used by most rings */
  862. u32 item_size; /* size in bytes of one object */
  863. u8 ulp_num; /* ULP to which CID binded */
  864. u16 register_set;
  865. u16 doorbell_format;
  866. u32 doorbell_offset;
  867. void *va; /* The virtual address of the ring. This
  868. * should be last to allow 32 & 64 bit debugger
  869. * extensions to work.
  870. */
  871. };
  872. struct hwi_controller {
  873. struct hwi_wrb_context *wrb_context;
  874. struct be_ring default_pdu_hdr[BEISCSI_ULP_COUNT];
  875. struct be_ring default_pdu_data[BEISCSI_ULP_COUNT];
  876. struct hwi_context_memory *phwi_ctxt;
  877. };
  878. enum hwh_type_enum {
  879. HWH_TYPE_IO = 1,
  880. HWH_TYPE_LOGOUT = 2,
  881. HWH_TYPE_TMF = 3,
  882. HWH_TYPE_NOP = 4,
  883. HWH_TYPE_IO_RD = 5,
  884. HWH_TYPE_LOGIN = 11,
  885. HWH_TYPE_INVALID = 0xFFFFFFFF
  886. };
  887. struct wrb_handle {
  888. unsigned short wrb_index;
  889. struct iscsi_task *pio_handle;
  890. struct iscsi_wrb *pwrb;
  891. };
  892. struct hwi_context_memory {
  893. struct be_eq_obj be_eq[MAX_CPUS];
  894. struct be_queue_info be_cq[MAX_CPUS - 1];
  895. struct be_queue_info *be_wrbq;
  896. /**
  897. * Create array of ULP number for below entries as DEFQ
  898. * will be created for both ULP if iSCSI Protocol is
  899. * loaded on both ULP.
  900. */
  901. struct be_queue_info be_def_hdrq[BEISCSI_ULP_COUNT];
  902. struct be_queue_info be_def_dataq[BEISCSI_ULP_COUNT];
  903. struct hd_async_context *pasync_ctx[BEISCSI_ULP_COUNT];
  904. };
  905. void beiscsi_start_boot_work(struct beiscsi_hba *phba, unsigned int s_handle);
  906. /* Logging related definitions */
  907. #define BEISCSI_LOG_INIT 0x0001 /* Initialization events */
  908. #define BEISCSI_LOG_MBOX 0x0002 /* Mailbox Events */
  909. #define BEISCSI_LOG_MISC 0x0004 /* Miscllaneous Events */
  910. #define BEISCSI_LOG_EH 0x0008 /* Error Handler */
  911. #define BEISCSI_LOG_IO 0x0010 /* IO Code Path */
  912. #define BEISCSI_LOG_CONFIG 0x0020 /* CONFIG Code Path */
  913. #define BEISCSI_LOG_ISCSI 0x0040 /* SCSI/iSCSI Protocol related Logs */
  914. #define __beiscsi_log(phba, level, fmt, arg...) \
  915. shost_printk(level, phba->shost, fmt, __LINE__, ##arg)
  916. #define beiscsi_log(phba, level, mask, fmt, arg...) \
  917. do { \
  918. uint32_t log_value = phba->attr_log_enable; \
  919. if (((mask) & log_value) || (level[1] <= '3')) \
  920. __beiscsi_log(phba, level, fmt, ##arg); \
  921. } while (0);
  922. #endif