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"
26 #include "qedi_nvm_iscsi_cfg.h"
28 #define QEDI_MODULE_NAME "qedi"
33 #define GET_FIELD2(value, name) \
34 (((value) & (name ## _MASK)) >> (name ## _OFFSET))
38 * PCI function probe defines
40 #define QEDI_MODE_NORMAL 0
41 #define QEDI_MODE_RECOVERY 1
43 #define ISCSI_WQE_SET_PTU_INVALIDATE 1
44 #define QEDI_MAX_ISCSI_TASK 4096
45 #define QEDI_MAX_TASK_NUM 0x0FFF
46 #define QEDI_MAX_ISCSI_CONNS_PER_HBA 1024
47 #define QEDI_ISCSI_MAX_BDS_PER_CMD 255 /* Firmware max BDs is 255 */
48 #define MAX_OUSTANDING_TASKS_PER_CON 1024
50 #define QEDI_MAX_BD_LEN 0xffff
51 #define QEDI_BD_SPLIT_SZ 0x1000
52 #define QEDI_PAGE_SIZE 4096
53 #define QEDI_FAST_SGE_COUNT 4
54 /* MAX Length for cached SGL */
55 #define MAX_SGLEN_FOR_CACHESGL ((1U << 16) - 1)
57 #define MIN_NUM_CPUS_MSIX(x) min_t(u32, x->dev_info.num_cqs, \
60 #define QEDI_LOCAL_PORT_MIN 60000
61 #define QEDI_LOCAL_PORT_MAX 61024
62 #define QEDI_LOCAL_PORT_RANGE (QEDI_LOCAL_PORT_MAX - QEDI_LOCAL_PORT_MIN)
63 #define QEDI_LOCAL_PORT_INVALID 0xffff
65 #define RX_RING (TX_RX_RING - 1)
66 #define LL2_SINGLE_BUF_SIZE 0x400
67 #define QEDI_PAGE_SIZE 4096
68 #define QEDI_PAGE_ALIGN(addr) ALIGN(addr, QEDI_PAGE_SIZE)
69 #define QEDI_PAGE_MASK (~((QEDI_PAGE_SIZE) - 1))
71 #define QEDI_PAGE_SIZE 4096
72 #define QEDI_HW_DMA_BOUNDARY 0xfff
73 #define QEDI_PATH_HANDLE 0xFE0000000UL
80 struct qedi_uio_ctrl
{
108 #define QEDI_RX_DESC_CNT (QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd))
109 #define QEDI_MAX_RX_DESC_CNT (QEDI_RX_DESC_CNT - 1)
110 #define QEDI_NUM_RX_BD (QEDI_RX_DESC_CNT * 1)
111 #define QEDI_MAX_RX_BD (QEDI_NUM_RX_BD - 1)
113 #define QEDI_NEXT_RX_IDX(x) ((((x) & (QEDI_MAX_RX_DESC_CNT)) == \
114 (QEDI_MAX_RX_DESC_CNT - 1)) ? \
117 struct qedi_uio_dev
{
118 struct uio_info qedi_uinfo
;
120 struct list_head list
;
131 struct qedi_ctx
*qedi
;
132 struct pci_dev
*pdev
;
136 /* List to maintain the skb pointers */
137 struct skb_work_list
{
138 struct list_head list
;
143 /* Queue sizes in number of elements */
144 #define QEDI_SQ_SIZE MAX_OUSTANDING_TASKS_PER_CON
145 #define QEDI_CQ_SIZE 2048
146 #define QEDI_CMDQ_SIZE QEDI_MAX_ISCSI_TASK
147 #define QEDI_PROTO_CQ_PROD_IDX 0
149 struct qedi_glbl_q_params
{
150 u64 hw_p_cq
; /* Completion queue PBL */
151 u64 hw_p_rq
; /* Request queue PBL */
152 u64 hw_p_cmdq
; /* Command queue PBL */
155 struct global_queue
{
159 u32 cq_cons_idx
; /* Completion queue consumer index */
162 dma_addr_t cq_pbl_dma
;
167 struct qedi_fastpath
{
168 struct qed_sb_info
*sb_info
;
170 #define QEDI_NAME_SIZE 16
171 char name
[QEDI_NAME_SIZE
];
172 struct qedi_ctx
*qedi
;
175 /* Used to pass fastpath information needed to process CQEs */
176 struct qedi_io_work
{
177 struct list_head list
;
178 struct iscsi_cqe_solicited cqe
;
183 * struct iscsi_cid_queue - Per adapter iscsi cid queue
185 * @cid_que_base: queue base memory
186 * @cid_que: queue memory pointer
187 * @cid_q_prod_idx: produce index
188 * @cid_q_cons_idx: consumer index
189 * @cid_q_max_idx: max index. used to detect wrap around condition
190 * @cid_free_cnt: queue size
191 * @conn_cid_tbl: iscsi cid to conn structure mapping table
193 * Per adapter iSCSI CID Queue
195 struct iscsi_cid_queue
{
202 struct qedi_conn
**conn_cid_tbl
;
205 struct qedi_portid_tbl
{
206 spinlock_t lock
; /* Port id lock */
210 unsigned long *table
;
213 struct qedi_itt_map
{
215 struct qedi_cmd
*p_cmd
;
218 /* I/O tracing entry */
219 #define QEDI_IO_TRACE_SIZE 2048
221 #define QEDI_IO_TRACE_REQ 0
222 #define QEDI_IO_TRACE_RSP 1
226 u32 port_id
; /* Remote port fabric ID */
228 u8 op
; /* SCSI CDB */
230 unsigned int bufflen
; /* SCSI buffer length */
231 unsigned int sg_count
; /* Number of SG elements */
232 u8 fast_sgs
; /* number of fast sgls */
233 u8 slow_sgs
; /* number of slow sgls */
234 u8 cached_sgs
; /* number of cached sgls */
235 int result
; /* Result passed back to mid-layer */
236 unsigned long jiffies
; /* Time stamp when I/O logged */
237 int refcount
; /* Reference count for task id */
238 unsigned int blk_req_cpu
; /* CPU that the task is queued on by
241 unsigned int req_cpu
; /* CPU that the task is queued on */
242 unsigned int intr_cpu
; /* Interrupt CPU that the task is received on */
243 unsigned int blk_rsp_cpu
;/* CPU that task is actually processed and
244 * returned to blk layer
251 /* Number of entries in BDQ */
252 #define QEDI_BDQ_NUM 256
253 #define QEDI_BDQ_BUF_SIZE 256
255 /* DMA coherent buffers for BDQ */
256 struct qedi_bdq_buf
{
261 /* Main port level struct */
263 struct qedi_dbg_ctx dbg_ctx
;
264 struct Scsi_Host
*shost
;
265 struct pci_dev
*pdev
;
266 struct qed_dev
*cdev
;
267 struct qed_dev_iscsi_info dev_info
;
268 struct qed_int_info int_info
;
269 struct qedi_glbl_q_params
*p_cpuq
;
270 struct global_queue
**global_queues
;
271 /* uio declaration */
272 struct qedi_uio_dev
*udev
;
273 struct list_head ll2_skb_list
;
274 spinlock_t ll2_lock
; /* Light L2 lock */
275 spinlock_t hba_lock
; /* per port lock */
276 struct task_struct
*ll2_recv_thread
;
278 #define UIO_DEV_OPENED 1
279 #define QEDI_IOTHREAD_WAKE 2
280 #define QEDI_IN_RECOVERY 5
281 #define QEDI_IN_OFFLINE 6
287 /* Physical address of above array */
288 dma_addr_t hw_p_cpuq
;
290 struct qedi_bdq_buf bdq
[QEDI_BDQ_NUM
];
292 dma_addr_t bdq_pbl_dma
;
293 size_t bdq_pbl_mem_size
;
295 dma_addr_t bdq_pbl_list_dma
;
296 u8 bdq_pbl_list_num_entries
;
297 struct nvm_iscsi_cfg
*iscsi_cfg
;
298 dma_addr_t nvm_buf_dma
;
299 void __iomem
*bdq_primary_prod
;
300 void __iomem
*bdq_secondary_prod
;
306 u32 max_active_conns
;
308 struct iscsi_cid_queue cid_que
;
309 struct qedi_endpoint
**ep_tbl
;
310 struct qedi_portid_tbl lcl_port_tbl
;
312 /* Rx fast path intr context */
313 struct qed_sb_info
*sb_array
;
314 struct qedi_fastpath
*fp_array
;
315 struct qed_iscsi_tid tasks
;
317 #define QEDI_LINK_DOWN 0
318 #define QEDI_LINK_UP 1
321 #define QEDI_RESERVE_TASK_ID 0
322 #define MAX_ISCSI_TASK_ENTRIES 4096
323 #define QEDI_INVALID_TASK_ID (MAX_ISCSI_TASK_ENTRIES + 1)
324 unsigned long task_idx_map
[MAX_ISCSI_TASK_ENTRIES
/ BITS_PER_LONG
];
325 struct qedi_itt_map
*itt_map
;
326 u16 tid_reuse_count
[QEDI_MAX_ISCSI_TASK
];
327 struct qed_pf_params pf_params
;
329 struct workqueue_struct
*tmf_thread
;
330 struct workqueue_struct
*offload_thread
;
334 struct workqueue_struct
*dpc_wq
;
336 spinlock_t task_idx_lock
; /* To protect gbl context */
340 struct qedi_io_log io_trace_buf
[QEDI_IO_TRACE_SIZE
];
341 spinlock_t io_trace_lock
; /* prtect trace Log buf */
343 unsigned int intr_cpu
;
351 atomic_t num_offloads
;
352 #define SYSFS_FLAG_FW_SEL_BOOT 2
355 struct iscsi_boot_kset
*boot_kset
;
357 /* Used for iscsi statistics */
358 struct mutex stats_lock
;
362 struct list_head list
;
363 struct qedi_ctx
*qedi
;
369 struct qedi_percpu_s
{
370 struct task_struct
*iothread
;
371 struct list_head work_list
;
372 spinlock_t p_work_lock
; /* Per cpu worker lock */
375 static inline void *qedi_get_task_mem(struct qed_iscsi_tid
*info
, u32 tid
)
377 return (info
->blocks
[tid
/ info
->num_tids_per_block
] +
378 (tid
% info
->num_tids_per_block
) * info
->size
);
381 #define QEDI_U64_HI(val) ((u32)(((u64)(val)) >> 32))
382 #define QEDI_U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff))
384 #endif /* _QEDI_H_ */