2 * QLogic iSCSI Offload Driver
3 * Copyright (c) 2016 Cavium Inc.
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
13 #define __PREVENT_QED_HSI__
15 #include <scsi/scsi_transport_iscsi.h>
16 #include <scsi/libiscsi.h>
17 #include <scsi/scsi_host.h>
18 #include <linux/uio_driver.h>
21 #include <linux/qed/qed_if.h>
23 #include <linux/qed/qed_iscsi_if.h>
24 #include <linux/qed/qed_ll2_if.h>
25 #include "qedi_version.h"
27 #define QEDI_MODULE_NAME "qedi"
32 * PCI function probe defines
34 #define QEDI_MODE_NORMAL 0
35 #define QEDI_MODE_RECOVERY 1
37 #define ISCSI_WQE_SET_PTU_INVALIDATE 1
38 #define QEDI_MAX_ISCSI_TASK 4096
39 #define QEDI_MAX_TASK_NUM 0x0FFF
40 #define QEDI_MAX_ISCSI_CONNS_PER_HBA 1024
41 #define QEDI_ISCSI_MAX_BDS_PER_CMD 255 /* Firmware max BDs is 255 */
42 #define MAX_OUSTANDING_TASKS_PER_CON 1024
44 #define QEDI_MAX_BD_LEN 0xffff
45 #define QEDI_BD_SPLIT_SZ 0x1000
46 #define QEDI_PAGE_SIZE 4096
47 #define QEDI_FAST_SGE_COUNT 4
48 /* MAX Length for cached SGL */
49 #define MAX_SGLEN_FOR_CACHESGL ((1U << 16) - 1)
51 #define MAX_NUM_MSIX_PF 8
52 #define MIN_NUM_CPUS_MSIX(x) min((x)->msix_count, num_online_cpus())
54 #define QEDI_LOCAL_PORT_MIN 60000
55 #define QEDI_LOCAL_PORT_MAX 61024
56 #define QEDI_LOCAL_PORT_RANGE (QEDI_LOCAL_PORT_MAX - QEDI_LOCAL_PORT_MIN)
57 #define QEDI_LOCAL_PORT_INVALID 0xffff
59 #define RX_RING (TX_RX_RING - 1)
60 #define LL2_SINGLE_BUF_SIZE 0x400
61 #define QEDI_PAGE_SIZE 4096
62 #define QEDI_PAGE_ALIGN(addr) ALIGN(addr, QEDI_PAGE_SIZE)
63 #define QEDI_PAGE_MASK (~((QEDI_PAGE_SIZE) - 1))
65 #define QEDI_PAGE_SIZE 4096
66 #define QEDI_HW_DMA_BOUNDARY 0xfff
67 #define QEDI_PATH_HANDLE 0xFE0000000UL
69 struct qedi_uio_ctrl
{
97 #define QEDI_RX_DESC_CNT (QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd))
98 #define QEDI_MAX_RX_DESC_CNT (QEDI_RX_DESC_CNT - 1)
99 #define QEDI_NUM_RX_BD (QEDI_RX_DESC_CNT * 1)
100 #define QEDI_MAX_RX_BD (QEDI_NUM_RX_BD - 1)
102 #define QEDI_NEXT_RX_IDX(x) ((((x) & (QEDI_MAX_RX_DESC_CNT)) == \
103 (QEDI_MAX_RX_DESC_CNT - 1)) ? \
106 struct qedi_uio_dev
{
107 struct uio_info qedi_uinfo
;
109 struct list_head list
;
120 struct qedi_ctx
*qedi
;
121 struct pci_dev
*pdev
;
125 /* List to maintain the skb pointers */
126 struct skb_work_list
{
127 struct list_head list
;
132 /* Queue sizes in number of elements */
133 #define QEDI_SQ_SIZE MAX_OUSTANDING_TASKS_PER_CON
134 #define QEDI_CQ_SIZE 2048
135 #define QEDI_CMDQ_SIZE QEDI_MAX_ISCSI_TASK
136 #define QEDI_PROTO_CQ_PROD_IDX 0
138 struct qedi_glbl_q_params
{
139 u64 hw_p_cq
; /* Completion queue PBL */
140 u64 hw_p_rq
; /* Request queue PBL */
141 u64 hw_p_cmdq
; /* Command queue PBL */
144 struct global_queue
{
148 u32 cq_cons_idx
; /* Completion queue consumer index */
151 dma_addr_t cq_pbl_dma
;
156 struct qedi_fastpath
{
157 struct qed_sb_info
*sb_info
;
159 #define QEDI_NAME_SIZE 16
160 char name
[QEDI_NAME_SIZE
];
161 struct qedi_ctx
*qedi
;
164 /* Used to pass fastpath information needed to process CQEs */
165 struct qedi_io_work
{
166 struct list_head list
;
167 struct iscsi_cqe_solicited cqe
;
172 * struct iscsi_cid_queue - Per adapter iscsi cid queue
174 * @cid_que_base: queue base memory
175 * @cid_que: queue memory pointer
176 * @cid_q_prod_idx: produce index
177 * @cid_q_cons_idx: consumer index
178 * @cid_q_max_idx: max index. used to detect wrap around condition
179 * @cid_free_cnt: queue size
180 * @conn_cid_tbl: iscsi cid to conn structure mapping table
182 * Per adapter iSCSI CID Queue
184 struct iscsi_cid_queue
{
191 struct qedi_conn
**conn_cid_tbl
;
194 struct qedi_portid_tbl
{
195 spinlock_t lock
; /* Port id lock */
199 unsigned long *table
;
202 struct qedi_itt_map
{
204 struct qedi_cmd
*p_cmd
;
207 /* I/O tracing entry */
208 #define QEDI_IO_TRACE_SIZE 2048
210 #define QEDI_IO_TRACE_REQ 0
211 #define QEDI_IO_TRACE_RSP 1
215 u32 port_id
; /* Remote port fabric ID */
217 u8 op
; /* SCSI CDB */
219 unsigned int bufflen
; /* SCSI buffer length */
220 unsigned int sg_count
; /* Number of SG elements */
221 u8 fast_sgs
; /* number of fast sgls */
222 u8 slow_sgs
; /* number of slow sgls */
223 u8 cached_sgs
; /* number of cached sgls */
224 int result
; /* Result passed back to mid-layer */
225 unsigned long jiffies
; /* Time stamp when I/O logged */
226 int refcount
; /* Reference count for task id */
227 unsigned int blk_req_cpu
; /* CPU that the task is queued on by
230 unsigned int req_cpu
; /* CPU that the task is queued on */
231 unsigned int intr_cpu
; /* Interrupt CPU that the task is received on */
232 unsigned int blk_rsp_cpu
;/* CPU that task is actually processed and
233 * returned to blk layer
240 /* Number of entries in BDQ */
241 #define QEDI_BDQ_NUM 256
242 #define QEDI_BDQ_BUF_SIZE 256
244 /* DMA coherent buffers for BDQ */
245 struct qedi_bdq_buf
{
250 /* Main port level struct */
252 struct qedi_dbg_ctx dbg_ctx
;
253 struct Scsi_Host
*shost
;
254 struct pci_dev
*pdev
;
255 struct qed_dev
*cdev
;
256 struct qed_dev_iscsi_info dev_info
;
257 struct qed_int_info int_info
;
258 struct qedi_glbl_q_params
*p_cpuq
;
259 struct global_queue
**global_queues
;
260 /* uio declaration */
261 struct qedi_uio_dev
*udev
;
262 struct list_head ll2_skb_list
;
263 spinlock_t ll2_lock
; /* Light L2 lock */
264 spinlock_t hba_lock
; /* per port lock */
265 struct task_struct
*ll2_recv_thread
;
267 #define UIO_DEV_OPENED 1
268 #define QEDI_IOTHREAD_WAKE 2
269 #define QEDI_IN_RECOVERY 5
270 #define QEDI_IN_OFFLINE 6
276 /* Physical address of above array */
277 dma_addr_t hw_p_cpuq
;
279 struct qedi_bdq_buf bdq
[QEDI_BDQ_NUM
];
281 dma_addr_t bdq_pbl_dma
;
282 size_t bdq_pbl_mem_size
;
284 dma_addr_t bdq_pbl_list_dma
;
285 u8 bdq_pbl_list_num_entries
;
286 void __iomem
*bdq_primary_prod
;
287 void __iomem
*bdq_secondary_prod
;
294 u32 max_active_conns
;
296 struct iscsi_cid_queue cid_que
;
297 struct qedi_endpoint
**ep_tbl
;
298 struct qedi_portid_tbl lcl_port_tbl
;
300 /* Rx fast path intr context */
301 struct qed_sb_info
*sb_array
;
302 struct qedi_fastpath
*fp_array
;
303 struct qed_iscsi_tid tasks
;
305 #define QEDI_LINK_DOWN 0
306 #define QEDI_LINK_UP 1
309 #define QEDI_RESERVE_TASK_ID 0
310 #define MAX_ISCSI_TASK_ENTRIES 4096
311 #define QEDI_INVALID_TASK_ID (MAX_ISCSI_TASK_ENTRIES + 1)
312 unsigned long task_idx_map
[MAX_ISCSI_TASK_ENTRIES
/ BITS_PER_LONG
];
313 struct qedi_itt_map
*itt_map
;
314 u16 tid_reuse_count
[QEDI_MAX_ISCSI_TASK
];
315 struct qed_pf_params pf_params
;
317 struct workqueue_struct
*tmf_thread
;
318 struct workqueue_struct
*offload_thread
;
322 struct workqueue_struct
*dpc_wq
;
324 spinlock_t task_idx_lock
; /* To protect gbl context */
328 struct qedi_io_log io_trace_buf
[QEDI_IO_TRACE_SIZE
];
329 spinlock_t io_trace_lock
; /* prtect trace Log buf */
331 unsigned int intr_cpu
;
339 atomic_t num_offloads
;
343 struct list_head list
;
344 struct qedi_ctx
*qedi
;
350 struct qedi_percpu_s
{
351 struct task_struct
*iothread
;
352 struct list_head work_list
;
353 spinlock_t p_work_lock
; /* Per cpu worker lock */
356 static inline void *qedi_get_task_mem(struct qed_iscsi_tid
*info
, u32 tid
)
358 return (info
->blocks
[tid
/ info
->num_tids_per_block
] +
359 (tid
% info
->num_tids_per_block
) * info
->size
);
362 #define QEDI_U64_HI(val) ((u32)(((u64)(val)) >> 32))
363 #define QEDI_U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff))
365 #endif /* _QEDI_H_ */