qedi.h 8.6 KB

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