qedi.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /*
  2. * QLogic iSCSI Offload Driver
  3. * Copyright (c) 2016 Cavium Inc.
  4. *
  5. * This software is available under the terms of the GNU General Public License
  6. * (GPL) Version 2, available from the file COPYING in the main directory of
  7. * this source tree.
  8. */
  9. #ifndef _QEDI_H_
  10. #define _QEDI_H_
  11. #define __PREVENT_QED_HSI__
  12. #include <scsi/scsi_transport_iscsi.h>
  13. #include <scsi/libiscsi.h>
  14. #include <scsi/scsi_host.h>
  15. #include <linux/uio_driver.h>
  16. #include "qedi_hsi.h"
  17. #include <linux/qed/qed_if.h>
  18. #include "qedi_dbg.h"
  19. #include <linux/qed/qed_iscsi_if.h>
  20. #include <linux/qed/qed_ll2_if.h>
  21. #include "qedi_version.h"
  22. #include "qedi_nvm_iscsi_cfg.h"
  23. #define QEDI_MODULE_NAME "qedi"
  24. struct qedi_endpoint;
  25. #ifndef GET_FIELD2
  26. #define GET_FIELD2(value, name) \
  27. (((value) & (name ## _MASK)) >> (name ## _OFFSET))
  28. #endif
  29. /*
  30. * PCI function probe defines
  31. */
  32. #define QEDI_MODE_NORMAL 0
  33. #define QEDI_MODE_RECOVERY 1
  34. #define ISCSI_WQE_SET_PTU_INVALIDATE 1
  35. #define QEDI_MAX_ISCSI_TASK 4096
  36. #define QEDI_MAX_TASK_NUM 0x0FFF
  37. #define QEDI_MAX_ISCSI_CONNS_PER_HBA 1024
  38. #define QEDI_ISCSI_MAX_BDS_PER_CMD 255 /* Firmware max BDs is 255 */
  39. #define MAX_OUSTANDING_TASKS_PER_CON 1024
  40. #define QEDI_MAX_BD_LEN 0xffff
  41. #define QEDI_BD_SPLIT_SZ 0x1000
  42. #define QEDI_PAGE_SIZE 4096
  43. #define QEDI_FAST_SGE_COUNT 4
  44. /* MAX Length for cached SGL */
  45. #define MAX_SGLEN_FOR_CACHESGL ((1U << 16) - 1)
  46. #define MIN_NUM_CPUS_MSIX(x) min_t(u32, x->dev_info.num_cqs, \
  47. num_online_cpus())
  48. #define QEDI_LOCAL_PORT_MIN 60000
  49. #define QEDI_LOCAL_PORT_MAX 61024
  50. #define QEDI_LOCAL_PORT_RANGE (QEDI_LOCAL_PORT_MAX - QEDI_LOCAL_PORT_MIN)
  51. #define QEDI_LOCAL_PORT_INVALID 0xffff
  52. #define TX_RX_RING 16
  53. #define RX_RING (TX_RX_RING - 1)
  54. #define LL2_SINGLE_BUF_SIZE 0x400
  55. #define QEDI_PAGE_SIZE 4096
  56. #define QEDI_PAGE_ALIGN(addr) ALIGN(addr, QEDI_PAGE_SIZE)
  57. #define QEDI_PAGE_MASK (~((QEDI_PAGE_SIZE) - 1))
  58. #define QEDI_PAGE_SIZE 4096
  59. #define QEDI_HW_DMA_BOUNDARY 0xfff
  60. #define QEDI_PATH_HANDLE 0xFE0000000UL
  61. enum qedi_nvm_tgts {
  62. QEDI_NVM_TGT_PRI,
  63. QEDI_NVM_TGT_SEC,
  64. };
  65. struct qedi_nvm_iscsi_image {
  66. struct nvm_iscsi_cfg iscsi_cfg;
  67. u32 crc;
  68. };
  69. struct qedi_uio_ctrl {
  70. /* meta data */
  71. u32 uio_hsi_version;
  72. /* user writes */
  73. u32 host_tx_prod;
  74. u32 host_rx_cons;
  75. u32 host_rx_bd_cons;
  76. u32 host_tx_pkt_len;
  77. u32 host_rx_cons_cnt;
  78. /* driver writes */
  79. u32 hw_tx_cons;
  80. u32 hw_rx_prod;
  81. u32 hw_rx_bd_prod;
  82. u32 hw_rx_prod_cnt;
  83. /* other */
  84. u8 mac_addr[6];
  85. u8 reserve[2];
  86. };
  87. struct qedi_rx_bd {
  88. u32 rx_pkt_index;
  89. u32 rx_pkt_len;
  90. u16 vlan_id;
  91. };
  92. #define QEDI_RX_DESC_CNT (QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd))
  93. #define QEDI_MAX_RX_DESC_CNT (QEDI_RX_DESC_CNT - 1)
  94. #define QEDI_NUM_RX_BD (QEDI_RX_DESC_CNT * 1)
  95. #define QEDI_MAX_RX_BD (QEDI_NUM_RX_BD - 1)
  96. #define QEDI_NEXT_RX_IDX(x) ((((x) & (QEDI_MAX_RX_DESC_CNT)) == \
  97. (QEDI_MAX_RX_DESC_CNT - 1)) ? \
  98. (x) + 2 : (x) + 1)
  99. struct qedi_uio_dev {
  100. struct uio_info qedi_uinfo;
  101. u32 uio_dev;
  102. struct list_head list;
  103. u32 ll2_ring_size;
  104. void *ll2_ring;
  105. u32 ll2_buf_size;
  106. void *ll2_buf;
  107. void *rx_pkt;
  108. void *tx_pkt;
  109. struct qedi_ctx *qedi;
  110. struct pci_dev *pdev;
  111. void *uctrl;
  112. };
  113. /* List to maintain the skb pointers */
  114. struct skb_work_list {
  115. struct list_head list;
  116. struct sk_buff *skb;
  117. u16 vlan_id;
  118. };
  119. /* Queue sizes in number of elements */
  120. #define QEDI_SQ_SIZE MAX_OUSTANDING_TASKS_PER_CON
  121. #define QEDI_CQ_SIZE 2048
  122. #define QEDI_CMDQ_SIZE QEDI_MAX_ISCSI_TASK
  123. #define QEDI_PROTO_CQ_PROD_IDX 0
  124. struct qedi_glbl_q_params {
  125. u64 hw_p_cq; /* Completion queue PBL */
  126. u64 hw_p_rq; /* Request queue PBL */
  127. u64 hw_p_cmdq; /* Command queue PBL */
  128. };
  129. struct global_queue {
  130. union iscsi_cqe *cq;
  131. dma_addr_t cq_dma;
  132. u32 cq_mem_size;
  133. u32 cq_cons_idx; /* Completion queue consumer index */
  134. void *cq_pbl;
  135. dma_addr_t cq_pbl_dma;
  136. u32 cq_pbl_size;
  137. };
  138. struct qedi_fastpath {
  139. struct qed_sb_info *sb_info;
  140. u16 sb_id;
  141. #define QEDI_NAME_SIZE 16
  142. char name[QEDI_NAME_SIZE];
  143. struct qedi_ctx *qedi;
  144. };
  145. /* Used to pass fastpath information needed to process CQEs */
  146. struct qedi_io_work {
  147. struct list_head list;
  148. struct iscsi_cqe_solicited cqe;
  149. u16 que_idx;
  150. };
  151. /**
  152. * struct iscsi_cid_queue - Per adapter iscsi cid queue
  153. *
  154. * @cid_que_base: queue base memory
  155. * @cid_que: queue memory pointer
  156. * @cid_q_prod_idx: produce index
  157. * @cid_q_cons_idx: consumer index
  158. * @cid_q_max_idx: max index. used to detect wrap around condition
  159. * @cid_free_cnt: queue size
  160. * @conn_cid_tbl: iscsi cid to conn structure mapping table
  161. *
  162. * Per adapter iSCSI CID Queue
  163. */
  164. struct iscsi_cid_queue {
  165. void *cid_que_base;
  166. u32 *cid_que;
  167. u32 cid_q_prod_idx;
  168. u32 cid_q_cons_idx;
  169. u32 cid_q_max_idx;
  170. u32 cid_free_cnt;
  171. struct qedi_conn **conn_cid_tbl;
  172. };
  173. struct qedi_portid_tbl {
  174. spinlock_t lock; /* Port id lock */
  175. u16 start;
  176. u16 max;
  177. u16 next;
  178. unsigned long *table;
  179. };
  180. struct qedi_itt_map {
  181. __le32 itt;
  182. struct qedi_cmd *p_cmd;
  183. };
  184. /* I/O tracing entry */
  185. #define QEDI_IO_TRACE_SIZE 2048
  186. struct qedi_io_log {
  187. #define QEDI_IO_TRACE_REQ 0
  188. #define QEDI_IO_TRACE_RSP 1
  189. u8 direction;
  190. u16 task_id;
  191. u32 cid;
  192. u32 port_id; /* Remote port fabric ID */
  193. int lun;
  194. u8 op; /* SCSI CDB */
  195. u8 lba[4];
  196. unsigned int bufflen; /* SCSI buffer length */
  197. unsigned int sg_count; /* Number of SG elements */
  198. u8 fast_sgs; /* number of fast sgls */
  199. u8 slow_sgs; /* number of slow sgls */
  200. u8 cached_sgs; /* number of cached sgls */
  201. int result; /* Result passed back to mid-layer */
  202. unsigned long jiffies; /* Time stamp when I/O logged */
  203. int refcount; /* Reference count for task id */
  204. unsigned int blk_req_cpu; /* CPU that the task is queued on by
  205. * blk layer
  206. */
  207. unsigned int req_cpu; /* CPU that the task is queued on */
  208. unsigned int intr_cpu; /* Interrupt CPU that the task is received on */
  209. unsigned int blk_rsp_cpu;/* CPU that task is actually processed and
  210. * returned to blk layer
  211. */
  212. bool cached_sge;
  213. bool slow_sge;
  214. bool fast_sge;
  215. };
  216. /* Number of entries in BDQ */
  217. #define QEDI_BDQ_NUM 256
  218. #define QEDI_BDQ_BUF_SIZE 256
  219. /* DMA coherent buffers for BDQ */
  220. struct qedi_bdq_buf {
  221. void *buf_addr;
  222. dma_addr_t buf_dma;
  223. };
  224. /* Main port level struct */
  225. struct qedi_ctx {
  226. struct qedi_dbg_ctx dbg_ctx;
  227. struct Scsi_Host *shost;
  228. struct pci_dev *pdev;
  229. struct qed_dev *cdev;
  230. struct qed_dev_iscsi_info dev_info;
  231. struct qed_int_info int_info;
  232. struct qedi_glbl_q_params *p_cpuq;
  233. struct global_queue **global_queues;
  234. /* uio declaration */
  235. struct qedi_uio_dev *udev;
  236. struct list_head ll2_skb_list;
  237. spinlock_t ll2_lock; /* Light L2 lock */
  238. spinlock_t hba_lock; /* per port lock */
  239. struct task_struct *ll2_recv_thread;
  240. unsigned long flags;
  241. #define UIO_DEV_OPENED 1
  242. #define QEDI_IOTHREAD_WAKE 2
  243. #define QEDI_IN_RECOVERY 5
  244. #define QEDI_IN_OFFLINE 6
  245. u8 mac[ETH_ALEN];
  246. u32 src_ip[4];
  247. u8 ip_type;
  248. /* Physical address of above array */
  249. dma_addr_t hw_p_cpuq;
  250. struct qedi_bdq_buf bdq[QEDI_BDQ_NUM];
  251. void *bdq_pbl;
  252. dma_addr_t bdq_pbl_dma;
  253. size_t bdq_pbl_mem_size;
  254. void *bdq_pbl_list;
  255. dma_addr_t bdq_pbl_list_dma;
  256. u8 bdq_pbl_list_num_entries;
  257. struct qedi_nvm_iscsi_image *iscsi_image;
  258. dma_addr_t nvm_buf_dma;
  259. void __iomem *bdq_primary_prod;
  260. void __iomem *bdq_secondary_prod;
  261. u16 bdq_prod_idx;
  262. u16 rq_num_entries;
  263. u32 max_sqes;
  264. u8 num_queues;
  265. u32 max_active_conns;
  266. struct iscsi_cid_queue cid_que;
  267. struct qedi_endpoint **ep_tbl;
  268. struct qedi_portid_tbl lcl_port_tbl;
  269. /* Rx fast path intr context */
  270. struct qed_sb_info *sb_array;
  271. struct qedi_fastpath *fp_array;
  272. struct qed_iscsi_tid tasks;
  273. #define QEDI_LINK_DOWN 0
  274. #define QEDI_LINK_UP 1
  275. atomic_t link_state;
  276. #define QEDI_RESERVE_TASK_ID 0
  277. #define MAX_ISCSI_TASK_ENTRIES 4096
  278. #define QEDI_INVALID_TASK_ID (MAX_ISCSI_TASK_ENTRIES + 1)
  279. unsigned long task_idx_map[MAX_ISCSI_TASK_ENTRIES / BITS_PER_LONG];
  280. struct qedi_itt_map *itt_map;
  281. u16 tid_reuse_count[QEDI_MAX_ISCSI_TASK];
  282. struct qed_pf_params pf_params;
  283. struct workqueue_struct *tmf_thread;
  284. struct workqueue_struct *offload_thread;
  285. u16 ll2_mtu;
  286. struct workqueue_struct *dpc_wq;
  287. spinlock_t task_idx_lock; /* To protect gbl context */
  288. s32 last_tidx_alloc;
  289. s32 last_tidx_clear;
  290. struct qedi_io_log io_trace_buf[QEDI_IO_TRACE_SIZE];
  291. spinlock_t io_trace_lock; /* prtect trace Log buf */
  292. u16 io_trace_idx;
  293. unsigned int intr_cpu;
  294. u32 cached_sgls;
  295. bool use_cached_sge;
  296. u32 slow_sgls;
  297. bool use_slow_sge;
  298. u32 fast_sgls;
  299. bool use_fast_sge;
  300. atomic_t num_offloads;
  301. #define SYSFS_FLAG_FW_SEL_BOOT 2
  302. #define IPV6_LEN 41
  303. #define IPV4_LEN 17
  304. struct iscsi_boot_kset *boot_kset;
  305. /* Used for iscsi statistics */
  306. struct mutex stats_lock;
  307. };
  308. struct qedi_work {
  309. struct list_head list;
  310. struct qedi_ctx *qedi;
  311. union iscsi_cqe cqe;
  312. u16 que_idx;
  313. bool is_solicited;
  314. };
  315. struct qedi_percpu_s {
  316. struct task_struct *iothread;
  317. struct list_head work_list;
  318. spinlock_t p_work_lock; /* Per cpu worker lock */
  319. };
  320. static inline void *qedi_get_task_mem(struct qed_iscsi_tid *info, u32 tid)
  321. {
  322. return (info->blocks[tid / info->num_tids_per_block] +
  323. (tid % info->num_tids_per_block) * info->size);
  324. }
  325. #define QEDI_U64_HI(val) ((u32)(((u64)(val)) >> 32))
  326. #define QEDI_U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff))
  327. #endif /* _QEDI_H_ */