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