1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * QLogic iSCSI Offload Driver
4 * Copyright (c) 2016 Cavium Inc.
10 #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>
18 #include <linux/qed/qed_if.h>
20 #include <linux/qed/qed_iscsi_if.h>
21 #include <linux/qed/qed_ll2_if.h>
22 #include "qedi_version.h"
23 #include "qedi_nvm_iscsi_cfg.h"
25 #define QEDI_MODULE_NAME "qedi"
30 #define GET_FIELD2(value, name) \
31 (((value) & (name ## _MASK)) >> (name ## _OFFSET))
35 * PCI function probe defines
37 #define QEDI_MODE_NORMAL 0
38 #define QEDI_MODE_RECOVERY 1
40 #define ISCSI_WQE_SET_PTU_INVALIDATE 1
41 #define QEDI_MAX_ISCSI_TASK 4096
42 #define QEDI_MAX_TASK_NUM 0x0FFF
43 #define QEDI_MAX_ISCSI_CONNS_PER_HBA 1024
44 #define QEDI_ISCSI_MAX_BDS_PER_CMD 255 /* Firmware max BDs is 255 */
45 #define MAX_OUTSTANDING_TASKS_PER_CON 1024
47 #define QEDI_MAX_BD_LEN 0xffff
48 #define QEDI_BD_SPLIT_SZ 0x1000
49 #define QEDI_PAGE_SIZE 4096
50 #define QEDI_FAST_SGE_COUNT 4
51 /* MAX Length for cached SGL */
52 #define MAX_SGLEN_FOR_CACHESGL ((1U << 16) - 1)
54 #define MIN_NUM_CPUS_MSIX(x) min_t(u32, x->dev_info.num_cqs, \
57 #define QEDI_LOCAL_PORT_MIN 60000
58 #define QEDI_LOCAL_PORT_MAX 61024
59 #define QEDI_LOCAL_PORT_RANGE (QEDI_LOCAL_PORT_MAX - QEDI_LOCAL_PORT_MIN)
60 #define QEDI_LOCAL_PORT_INVALID 0xffff
62 #define RX_RING (TX_RX_RING - 1)
63 #define QEDI_PAGE_ALIGN(addr) ALIGN(addr, QEDI_PAGE_SIZE)
64 #define QEDI_PAGE_MASK (~((QEDI_PAGE_SIZE) - 1))
66 #define QEDI_HW_DMA_BOUNDARY 0xfff
67 #define QEDI_PATH_HANDLE 0xFE0000000UL
74 struct qedi_nvm_iscsi_image
{
75 struct nvm_iscsi_cfg iscsi_cfg
;
79 struct qedi_uio_ctrl
{
107 #define QEDI_RX_DESC_CNT (QEDI_PAGE_SIZE / sizeof(struct qedi_rx_bd))
108 #define QEDI_MAX_RX_DESC_CNT (QEDI_RX_DESC_CNT - 1)
109 #define QEDI_NUM_RX_BD (QEDI_RX_DESC_CNT * 1)
110 #define QEDI_MAX_RX_BD (QEDI_NUM_RX_BD - 1)
112 #define QEDI_NEXT_RX_IDX(x) ((((x) & (QEDI_MAX_RX_DESC_CNT)) == \
113 (QEDI_MAX_RX_DESC_CNT - 1)) ? \
116 struct qedi_uio_dev
{
117 struct uio_info qedi_uinfo
;
119 struct list_head list
;
130 struct qedi_ctx
*qedi
;
131 struct pci_dev
*pdev
;
135 /* List to maintain the skb pointers */
136 struct skb_work_list
{
137 struct list_head list
;
142 /* Queue sizes in number of elements */
143 #define QEDI_SQ_SIZE MAX_OUTSTANDING_TASKS_PER_CON
144 #define QEDI_CQ_SIZE 2048
145 #define QEDI_CMDQ_SIZE QEDI_MAX_ISCSI_TASK
146 #define QEDI_PROTO_CQ_PROD_IDX 0
148 struct qedi_glbl_q_params
{
149 u64 hw_p_cq
; /* Completion queue PBL */
150 u64 hw_p_rq
; /* Request queue PBL */
151 u64 hw_p_cmdq
; /* Command queue PBL */
154 struct global_queue
{
158 u32 cq_cons_idx
; /* Completion queue consumer index */
161 dma_addr_t cq_pbl_dma
;
166 struct qedi_fastpath
{
167 struct qed_sb_info
*sb_info
;
169 #define QEDI_NAME_SIZE 16
170 char name
[QEDI_NAME_SIZE
];
171 struct qedi_ctx
*qedi
;
174 /* Used to pass fastpath information needed to process CQEs */
175 struct qedi_io_work
{
176 struct list_head list
;
177 struct iscsi_cqe_solicited cqe
;
182 * struct iscsi_cid_queue - Per adapter iscsi cid queue
184 * @cid_que_base: queue base memory
185 * @cid_que: queue memory pointer
186 * @cid_q_prod_idx: produce index
187 * @cid_q_cons_idx: consumer index
188 * @cid_q_max_idx: max index. used to detect wrap around condition
189 * @cid_free_cnt: queue size
190 * @conn_cid_tbl: iscsi cid to conn structure mapping table
192 * Per adapter iSCSI CID Queue
194 struct iscsi_cid_queue
{
201 struct qedi_conn
**conn_cid_tbl
;
204 struct qedi_portid_tbl
{
205 spinlock_t lock
; /* Port id lock */
209 unsigned long *table
;
212 struct qedi_itt_map
{
214 struct qedi_cmd
*p_cmd
;
217 /* I/O tracing entry */
218 #define QEDI_IO_TRACE_SIZE 2048
220 #define QEDI_IO_TRACE_REQ 0
221 #define QEDI_IO_TRACE_RSP 1
225 u32 port_id
; /* Remote port fabric ID */
227 u8 op
; /* SCSI CDB */
229 unsigned int bufflen
; /* SCSI buffer length */
230 unsigned int sg_count
; /* Number of SG elements */
231 u8 fast_sgs
; /* number of fast sgls */
232 u8 slow_sgs
; /* number of slow sgls */
233 u8 cached_sgs
; /* number of cached sgls */
234 int result
; /* Result passed back to mid-layer */
235 unsigned long jiffies
; /* Time stamp when I/O logged */
236 int refcount
; /* Reference count for task id */
237 unsigned int blk_req_cpu
; /* CPU that the task is queued on by
240 unsigned int req_cpu
; /* CPU that the task is queued on */
241 unsigned int intr_cpu
; /* Interrupt CPU that the task is received on */
242 unsigned int blk_rsp_cpu
;/* CPU that task is actually processed and
243 * returned to blk layer
250 /* Number of entries in BDQ */
251 #define QEDI_BDQ_NUM 256
252 #define QEDI_BDQ_BUF_SIZE 256
254 /* DMA coherent buffers for BDQ */
255 struct qedi_bdq_buf
{
260 /* Main port level struct */
262 struct qedi_dbg_ctx dbg_ctx
;
263 struct Scsi_Host
*shost
;
264 struct pci_dev
*pdev
;
265 struct qed_dev
*cdev
;
266 struct qed_dev_iscsi_info dev_info
;
267 struct qed_int_info int_info
;
268 struct qedi_glbl_q_params
*p_cpuq
;
269 struct global_queue
**global_queues
;
270 /* uio declaration */
271 struct qedi_uio_dev
*udev
;
272 struct list_head ll2_skb_list
;
273 spinlock_t ll2_lock
; /* Light L2 lock */
274 spinlock_t hba_lock
; /* per port lock */
275 struct task_struct
*ll2_recv_thread
;
277 #define UIO_DEV_OPENED 1
278 #define QEDI_IOTHREAD_WAKE 2
279 #define QEDI_IN_RECOVERY 5
280 #define QEDI_IN_OFFLINE 6
286 /* Physical address of above array */
287 dma_addr_t hw_p_cpuq
;
289 struct qedi_bdq_buf bdq
[QEDI_BDQ_NUM
];
291 dma_addr_t bdq_pbl_dma
;
292 size_t bdq_pbl_mem_size
;
294 dma_addr_t bdq_pbl_list_dma
;
295 u8 bdq_pbl_list_num_entries
;
296 struct qedi_nvm_iscsi_image
*iscsi_image
;
297 dma_addr_t nvm_buf_dma
;
298 void __iomem
*bdq_primary_prod
;
299 void __iomem
*bdq_secondary_prod
;
305 u32 max_active_conns
;
307 struct iscsi_cid_queue cid_que
;
308 struct qedi_endpoint
**ep_tbl
;
309 struct qedi_portid_tbl lcl_port_tbl
;
311 /* Rx fast path intr context */
312 struct qed_sb_info
*sb_array
;
313 struct qedi_fastpath
*fp_array
;
314 struct qed_iscsi_tid tasks
;
316 #define QEDI_LINK_DOWN 0
317 #define QEDI_LINK_UP 1
320 #define QEDI_RESERVE_TASK_ID 0
321 #define MAX_ISCSI_TASK_ENTRIES 4096
322 #define QEDI_INVALID_TASK_ID (MAX_ISCSI_TASK_ENTRIES + 1)
323 unsigned long task_idx_map
[MAX_ISCSI_TASK_ENTRIES
/ BITS_PER_LONG
];
324 struct qedi_itt_map
*itt_map
;
325 u16 tid_reuse_count
[QEDI_MAX_ISCSI_TASK
];
326 struct qed_pf_params pf_params
;
328 struct workqueue_struct
*tmf_thread
;
329 struct workqueue_struct
*offload_thread
;
333 struct workqueue_struct
*dpc_wq
;
335 spinlock_t task_idx_lock
; /* To protect gbl context */
339 struct qedi_io_log io_trace_buf
[QEDI_IO_TRACE_SIZE
];
340 spinlock_t io_trace_lock
; /* prtect trace Log buf */
342 unsigned int intr_cpu
;
350 atomic_t num_offloads
;
351 #define SYSFS_FLAG_FW_SEL_BOOT 2
354 struct iscsi_boot_kset
*boot_kset
;
356 /* Used for iscsi statistics */
357 struct mutex stats_lock
;
361 struct list_head list
;
362 struct qedi_ctx
*qedi
;
368 struct qedi_percpu_s
{
369 struct task_struct
*iothread
;
370 struct list_head work_list
;
371 spinlock_t p_work_lock
; /* Per cpu worker lock */
374 static inline void *qedi_get_task_mem(struct qed_iscsi_tid
*info
, u32 tid
)
376 return (info
->blocks
[tid
/ info
->num_tids_per_block
] +
377 (tid
% info
->num_tids_per_block
) * info
->size
);
380 #define QEDI_U64_HI(val) ((u32)(((u64)(val)) >> 32))
381 #define QEDI_U64_LO(val) ((u32)(((u64)(val)) & 0xffffffff))
383 #endif /* _QEDI_H_ */