xref: /linux/drivers/scsi/fnic/fnic.h (revision 3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2008 Cisco Systems, Inc.  All rights reserved.
4  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
5  */
6 #ifndef _FNIC_H_
7 #define _FNIC_H_
8 
9 #include <linux/interrupt.h>
10 #include <linux/netdevice.h>
11 #include <linux/workqueue.h>
12 #include <linux/bitops.h>
13 #include <scsi/scsi_cmnd.h>
14 #include <scsi/scsi_transport.h>
15 #include <scsi/scsi_transport_fc.h>
16 #include <scsi/fc_frame.h>
17 #include "fnic_io.h"
18 #include "fnic_res.h"
19 #include "fnic_trace.h"
20 #include "fnic_stats.h"
21 #include "vnic_dev.h"
22 #include "vnic_wq.h"
23 #include "vnic_rq.h"
24 #include "vnic_cq.h"
25 #include "vnic_wq_copy.h"
26 #include "vnic_intr.h"
27 #include "vnic_stats.h"
28 #include "vnic_scsi.h"
29 #include "fnic_fdls.h"
30 #include "fnic_nvme.h"
31 
32 #define DRV_NAME		"fnic"
33 #define DRV_DESCRIPTION		"Cisco FCoE HBA Driver"
34 #define DRV_VERSION		"1.9.0.0"
35 #define PFX			DRV_NAME ": "
36 #define DFX                     DRV_NAME "%d: "
37 
38 #define FABRIC_LOGO_MAX_RETRY 3
39 #define DESC_CLEAN_LOW_WATERMARK 8
40 #define FNIC_UCSM_DFLT_THROTTLE_CNT_BLD	16 /* UCSM default throttle count */
41 #define FNIC_MIN_IO_REQ			256 /* Min IO throttle count */
42 #define FNIC_MAX_IO_REQ		1024 /* scsi_cmnd tag map entries */
43 #define FNIC_DFLT_IO_REQ        256 /* Default scsi_cmnd tag map entries */
44 #define FNIC_DFLT_QUEUE_DEPTH	256
45 #define	FNIC_STATS_RATE_LIMIT	4 /* limit rate at which stats are pulled up */
46 #define LUN0_DELAY_TIME			9
47 #define FNIC_ROLE_CONFIG_MASK   (0xFF0)
48 
49 /*
50  * Tag bits used for special requests.
51  */
52 #define FNIC_TAG_ABORT		BIT(30)		/* tag bit indicating abort */
53 #define FNIC_TAG_DEV_RST	BIT(29)		/* indicates device reset */
54 #define FNIC_TAG_MASK		(BIT(24) - 1)	/* mask for lookup */
55 #define FNIC_NO_TAG             -1
56 
57 /*
58  * Command flags to identify the type of command and for other future
59  * use.
60  */
61 #define FNIC_NO_FLAGS                   0
62 #define FNIC_IO_INITIALIZED             BIT(0)
63 #define FNIC_IO_ISSUED                  BIT(1)
64 #define FNIC_IO_DONE                    BIT(2)
65 #define FNIC_IO_REQ_NULL                BIT(3)
66 #define FNIC_IO_ABTS_PENDING            BIT(4)
67 #define FNIC_IO_ABORTED                 BIT(5)
68 #define FNIC_IO_ABTS_ISSUED             BIT(6)
69 #define FNIC_IO_TERM_ISSUED             BIT(7)
70 #define FNIC_IO_INTERNAL_TERM_ISSUED    BIT(8)
71 #define FNIC_IO_ABT_TERM_DONE           BIT(9)
72 #define FNIC_IO_ABT_TERM_REQ_NULL       BIT(10)
73 #define FNIC_IO_ABT_TERM_TIMED_OUT      BIT(11)
74 #define FNIC_DEVICE_RESET               BIT(12)  /* Device reset request */
75 #define FNIC_DEV_RST_ISSUED             BIT(13)
76 #define FNIC_DEV_RST_TIMED_OUT          BIT(14)
77 #define FNIC_DEV_RST_ABTS_ISSUED        BIT(15)
78 #define FNIC_DEV_RST_TERM_ISSUED        BIT(16)
79 #define FNIC_DEV_RST_DONE               BIT(17)
80 #define FNIC_DEV_RST_REQ_NULL           BIT(18)
81 #define FNIC_DEV_RST_ABTS_DONE          BIT(19)
82 #define FNIC_DEV_RST_TERM_DONE          BIT(20)
83 #define FNIC_DEV_RST_ABTS_PENDING       BIT(21)
84 #define FNIC_NVME_ADMIN_IO_TIMER_PENDING BIT(22)
85 #define FNIC_NVME_ADMIN_IO              BIT(23)
86 
87 #define FNIC_FW_RESET_TIMEOUT        60000	/* mSec   */
88 #define FNIC_FCOE_MAX_CMD_LEN        16
89 /* Retry supported by rport (returned by PRLI service parameters) */
90 #define FNIC_FC_RP_FLAGS_RETRY            0x1
91 
92 /* Cisco vendor id */
93 #define PCI_VENDOR_ID_CISCO						0x1137
94 #define PCI_DEVICE_ID_CISCO_VIC_FC				0x0045	/* fc vnic */
95 
96 /* sereno pcie switch */
97 #define PCI_DEVICE_ID_CISCO_SERENO             0x004e
98 #define PCI_DEVICE_ID_CISCO_CRUZ               0x007a	/* Cruz */
99 #define PCI_DEVICE_ID_CISCO_BODEGA             0x0131	/* Bodega */
100 #define PCI_DEVICE_ID_CISCO_BEVERLY            0x025f	/* Beverly */
101 
102 /* Sereno */
103 #define PCI_SUBDEVICE_ID_CISCO_VASONA			0x004f	/* vasona mezz */
104 #define PCI_SUBDEVICE_ID_CISCO_COTATI			0x0084	/* cotati mlom */
105 #define PCI_SUBDEVICE_ID_CISCO_LEXINGTON		0x0085	/* lexington pcie */
106 #define PCI_SUBDEVICE_ID_CISCO_ICEHOUSE			0x00cd	/* Icehouse */
107 #define PCI_SUBDEVICE_ID_CISCO_KIRKWOODLAKE		0x00ce	/* KirkwoodLake pcie */
108 #define PCI_SUBDEVICE_ID_CISCO_SUSANVILLE		0x012e	/* Susanville MLOM */
109 #define PCI_SUBDEVICE_ID_CISCO_TORRANCE			0x0139	/* Torrance MLOM */
110 
111 /* Cruz */
112 #define PCI_SUBDEVICE_ID_CISCO_CALISTOGA		0x012c	/* Calistoga MLOM */
113 #define PCI_SUBDEVICE_ID_CISCO_MOUNTAINVIEW		0x0137	/* Cruz Mezz */
114 /* Cruz MountTian SIOC */
115 #define PCI_SUBDEVICE_ID_CISCO_MOUNTTIAN		0x014b
116 #define PCI_SUBDEVICE_ID_CISCO_CLEARLAKE		0x014d	/* ClearLake pcie */
117 /* Cruz MountTian2 SIOC */
118 #define PCI_SUBDEVICE_ID_CISCO_MOUNTTIAN2		0x0157
119 #define PCI_SUBDEVICE_ID_CISCO_CLAREMONT		0x015d	/* Claremont MLOM */
120 
121 /* Bodega */
122 /* VIC 1457 PCIe mLOM */
123 #define PCI_SUBDEVICE_ID_CISCO_BRADBURY         0x0218
124 #define PCI_SUBDEVICE_ID_CISCO_BRENTWOOD        0x0217	/* VIC 1455 PCIe */
125 /* VIC 1487 PCIe mLOM */
126 #define PCI_SUBDEVICE_ID_CISCO_BURLINGAME       0x021a
127 #define PCI_SUBDEVICE_ID_CISCO_BAYSIDE          0x0219	/* VIC 1485 PCIe */
128 /* VIC 1440 Mezz mLOM */
129 #define PCI_SUBDEVICE_ID_CISCO_BAKERSFIELD      0x0215
130 #define PCI_SUBDEVICE_ID_CISCO_BOONVILLE        0x0216	/* VIC 1480 Mezz */
131 #define PCI_SUBDEVICE_ID_CISCO_BENICIA          0x024a	/* VIC 1495 */
132 #define PCI_SUBDEVICE_ID_CISCO_BEAUMONT         0x024b	/* VIC 1497 */
133 #define PCI_SUBDEVICE_ID_CISCO_BRISBANE         0x02af	/* VIC 1467 */
134 #define PCI_SUBDEVICE_ID_CISCO_BENTON           0x02b0	/* VIC 1477 */
135 #define PCI_SUBDEVICE_ID_CISCO_TWIN_RIVER       0x02cf	/* VIC 14425 */
136 #define PCI_SUBDEVICE_ID_CISCO_TWIN_PEAK        0x02d0	/* VIC 14825 */
137 
138 /* Beverly */
139 #define PCI_SUBDEVICE_ID_CISCO_BERN             0x02de	/* VIC 15420 */
140 #define PCI_SUBDEVICE_ID_CISCO_STOCKHOLM        0x02dd	/* VIC 15428 */
141 #define PCI_SUBDEVICE_ID_CISCO_KRAKOW           0x02dc	/* VIC 15411 */
142 #define PCI_SUBDEVICE_ID_CISCO_LUCERNE          0x02db	/* VIC 15231 */
143 #define PCI_SUBDEVICE_ID_CISCO_TURKU            0x02e8	/* VIC 15238 */
144 #define PCI_SUBDEVICE_ID_CISCO_TURKU_PLUS       0x02f3	/* VIC 15237 */
145 #define PCI_SUBDEVICE_ID_CISCO_ZURICH           0x02df	/* VIC 15230 */
146 #define PCI_SUBDEVICE_ID_CISCO_RIGA             0x02e0	/* VIC 15427 */
147 #define PCI_SUBDEVICE_ID_CISCO_GENEVA           0x02e1	/* VIC 15422 */
148 #define PCI_SUBDEVICE_ID_CISCO_HELSINKI         0x02e4	/* VIC 15235 */
149 #define PCI_SUBDEVICE_ID_CISCO_GOTHENBURG       0x02f2	/* VIC 15425 */
150 
151 #define IS_FNIC_FCP_INITIATOR(fnic) (fnic->role == FNIC_ROLE_FCP_INITIATOR)
152 #define IS_FNIC_NVME_INITIATOR(fnic) (fnic->role == FNIC_ROLE_NVME_INITIATOR)
153 
154 struct fnic_pcie_device {
155 	u32 device;
156 	u8 *desc;
157 	u32 subsystem_device;
158 	u8 *subsys_desc;
159 };
160 
161 /*
162  * fnic private data per SCSI command.
163  * These fields are locked by the hashed io_req_lock.
164  */
165 struct fnic_cmd_priv {
166 	struct fnic_io_req *io_req;
167 	enum fnic_ioreq_state state;
168 	u32 flags;
169 	u16 abts_status;
170 	u16 lr_status;
171 };
172 
173 static inline struct fnic_cmd_priv *fnic_priv(struct scsi_cmnd *cmd)
174 {
175 	return scsi_cmd_priv(cmd);
176 }
177 
178 static inline u64 fnic_flags_and_state(struct scsi_cmnd *cmd)
179 {
180 	struct fnic_cmd_priv *fcmd = fnic_priv(cmd);
181 
182 	return ((u64)fcmd->flags << 32) | fcmd->state;
183 }
184 
185 #define FCPIO_INVALID_CODE 0x100 /* hdr_status value unused by firmware */
186 
187 #define FNIC_LUN_RESET_TIMEOUT	     10000	/* mSec */
188 #define FNIC_HOST_RESET_TIMEOUT	     10000	/* mSec */
189 #define FNIC_RMDEVICE_TIMEOUT        1000       /* mSec */
190 #define FNIC_HOST_RESET_SETTLE_TIME  30         /* Sec */
191 #define FNIC_ABT_TERM_DELAY_TIMEOUT  500        /* mSec */
192 
193 #define FNIC_MAX_FCP_TARGET     256
194 #define FNIC_PCI_OFFSET		2
195 /**
196  * state_flags to identify host state along along with fnic's state
197  **/
198 #define __FNIC_FLAGS_FWRESET		BIT(0) /* fwreset in progress */
199 #define __FNIC_FLAGS_BLOCK_IO		BIT(1) /* IOs are blocked */
200 
201 #define FNIC_FLAGS_NONE			(0)
202 #define FNIC_FLAGS_FWRESET		(__FNIC_FLAGS_FWRESET | \
203 					__FNIC_FLAGS_BLOCK_IO)
204 
205 #define FNIC_FLAGS_IO_BLOCKED		(__FNIC_FLAGS_BLOCK_IO)
206 
207 #define fnic_set_state_flags(fnicp, st_flags)	\
208 	__fnic_set_state_flags(fnicp, st_flags, 0)
209 
210 #define fnic_clear_state_flags(fnicp, st_flags)  \
211 	__fnic_set_state_flags(fnicp, st_flags, 1)
212 
213 enum reset_states {
214 	NOT_IN_PROGRESS = 0,
215 	IN_PROGRESS,
216 	RESET_ERROR
217 };
218 
219 enum rscn_type {
220 	NOT_PC_RSCN = 0,
221 	PC_RSCN
222 };
223 
224 enum pc_rscn_handling_status {
225 	PC_RSCN_HANDLING_NOT_IN_PROGRESS = 0,
226 	PC_RSCN_HANDLING_IN_PROGRESS
227 };
228 
229 enum pc_rscn_handling_feature {
230 	PC_RSCN_HANDLING_FEATURE_OFF = 0,
231 	PC_RSCN_HANDLING_FEATURE_ON
232 };
233 
234 extern unsigned int fnic_fdmi_support;
235 extern unsigned int fnic_log_level;
236 extern unsigned int io_completions;
237 extern struct workqueue_struct *fnic_event_queue;
238 
239 extern unsigned int pc_rscn_handling_feature_flag;
240 extern spinlock_t reset_fnic_list_lock;
241 extern struct list_head reset_fnic_list;
242 extern struct workqueue_struct *reset_fnic_work_queue;
243 extern struct work_struct reset_fnic_work;
244 extern struct workqueue_struct *fnic_cmpl_queue;
245 
246 #define FNIC_MAIN_LOGGING 0x01
247 #define FNIC_FCS_LOGGING 0x02
248 #define FNIC_SCSI_LOGGING 0x04
249 #define FNIC_ISR_LOGGING 0x08
250 #define FNIC_FDLS_LOGGING 0x10
251 #define FNIC_NVME_LOGGING 0x20
252 #define FNIC_FIP_LOGGING 0x40
253 
254 #define FNIC_CHECK_LOGGING(LEVEL, CMD)				\
255 do {								\
256 	if (unlikely(fnic_log_level & LEVEL))			\
257 		do {						\
258 			CMD;					\
259 		} while (0);					\
260 } while (0)
261 
262 #define fnic_printk(kern_level, fnic, fmt, ...)                      \
263 	(IS_FNIC_FCP_INITIATOR(fnic) ?                                   \
264 	shost_printk(kern_level, fnic->host, "fnic<%d>: %s: %d: " fmt,   \
265 				fnic->fnic_num, __func__, __LINE__, ##__VA_ARGS__) : \
266 	printk(kern_level "fnic<%d>: %s: %d: " fmt, fnic->fnic_num,      \
267 				__func__, __LINE__, ##__VA_ARGS__))
268 
269 #define FNIC_MAIN_DBG(kern_level, fnic, fmt, args...)				\
270 		FNIC_CHECK_LOGGING(FNIC_MAIN_LOGGING,						\
271 				fnic_printk(kern_level, fnic, fmt, ##args);)
272 
273 #define FNIC_FCS_DBG(kern_level, fnic, fmt, args...)				\
274 		FNIC_CHECK_LOGGING(FNIC_FCS_LOGGING,						\
275 				fnic_printk(kern_level, fnic, fmt, ##args);)
276 
277 #define FNIC_FIP_DBG(kern_level, fnic, fmt, args...)				\
278 		FNIC_CHECK_LOGGING(FNIC_FIP_LOGGING,						\
279 				fnic_printk(kern_level, fnic, fmt, ##args);)
280 
281 #define FNIC_SCSI_DBG(kern_level, fnic, fmt, args...)				\
282 		FNIC_CHECK_LOGGING(FNIC_SCSI_LOGGING,						\
283 				fnic_printk(kern_level, fnic, fmt, ##args);)
284 
285 #define FNIC_ISR_DBG(kern_level, fnic, fmt, args...)				\
286 		FNIC_CHECK_LOGGING(FNIC_ISR_LOGGING,						\
287 				fnic_printk(kern_level, fnic, fmt, ##args);)
288 
289 #define FNIC_NVME_DBG(kern_level, fnic, fmt, args...)				\
290 		FNIC_CHECK_LOGGING(FNIC_NVME_LOGGING,						\
291 				fnic_printk(kern_level, fnic, fmt, ##args);)
292 
293 #define FNIC_MAIN_NOTE(kern_level, fnic, fmt, args...)				\
294 			fnic_printk(kern_level, fnic, fmt, ##args)
295 
296 #define FNIC_WQ_COPY_MAX 64
297 #define FNIC_WQ_MAX 1
298 #define FNIC_RQ_MAX 1
299 #define FNIC_CQ_MAX (FNIC_WQ_COPY_MAX + FNIC_WQ_MAX + FNIC_RQ_MAX)
300 #define FNIC_DFLT_IO_COMPLETIONS 256
301 
302 #define FNIC_MQ_CQ_INDEX        2
303 
304 extern const char *fnic_state_str[];
305 
306 enum fnic_intx_intr_index {
307 	FNIC_INTX_WQ_RQ_COPYWQ,
308 	FNIC_INTX_DUMMY,
309 	FNIC_INTX_NOTIFY,
310 	FNIC_INTX_ERR,
311 	FNIC_INTX_INTR_MAX,
312 };
313 
314 enum fnic_msix_intr_index {
315 	FNIC_MSIX_RQ,
316 	FNIC_MSIX_WQ,
317 	FNIC_MSIX_WQ_COPY,
318 	FNIC_MSIX_ERR_NOTIFY = FNIC_MSIX_WQ_COPY + FNIC_WQ_COPY_MAX,
319 	FNIC_MSIX_INTR_MAX,
320 };
321 
322 struct fnic_msix_entry {
323 	int requested;
324 	char devname[IFNAMSIZ + 11];
325 	irqreturn_t (*isr)(int, void *);
326 	void *devid;
327 	int irq_num;
328 };
329 
330 enum fnic_state {
331 	FNIC_IN_FC_MODE = 0,
332 	FNIC_IN_FC_TRANS_ETH_MODE,
333 	FNIC_IN_ETH_MODE,
334 	FNIC_IN_ETH_TRANS_FC_MODE,
335 };
336 
337 enum fnic_role_e {
338 	FNIC_ROLE_FCP_INITIATOR = 0,
339 	FNIC_ROLE_NVME_INITIATOR,
340 };
341 
342 enum fnic_evt {
343 	FNIC_EVT_START_VLAN_DISC = 1,
344 	FNIC_EVT_START_FCF_DISC = 2,
345 	FNIC_EVT_MAX,
346 };
347 
348 struct fnic_frame_list {
349 	/*
350 	 * Link to frame lists
351 	 */
352 	struct list_head links;
353 	void *fp;
354 	int frame_len;
355 	int rx_ethhdr_stripped;
356 };
357 
358 struct fnic_tag_t {
359 	struct list_head free_list;
360 	int tag_id;
361 };
362 
363 struct fnic_event {
364 	struct list_head list;
365 	struct fnic *fnic;
366 	enum fnic_evt event;
367 };
368 
369 struct fnic_cpy_wq {
370 	unsigned long hw_lock_flags;
371 	u16 active_ioreq_count;
372 	u16 ioreq_table_size;
373 	____cacheline_aligned struct fnic_io_req **io_req_table;
374 };
375 
376 /* Per-instance private data structure */
377 struct fnic {
378 	int fnic_num;
379 	enum fnic_role_e role;
380 	struct fnic_iport_s iport;
381 	struct Scsi_Host *host;
382 	struct vnic_dev_bar bar0;
383 
384 	struct fnic_msix_entry msix[FNIC_MSIX_INTR_MAX];
385 
386 	struct vnic_stats *stats;
387 	unsigned long stats_time;	/* time of stats update */
388 	unsigned long stats_reset_time; /* time of stats reset */
389 	struct vnic_nic_cfg *nic_cfg;
390 	char name[IFNAMSIZ];
391 	struct timer_list notify_timer; /* used for MSI interrupts */
392 
393 	unsigned int fnic_max_tag_id;
394 	unsigned int err_intr_offset;
395 	unsigned int link_intr_offset;
396 
397 	unsigned int wq_count;
398 	unsigned int cq_count;
399 
400 	struct completion reset_completion_wait;
401 	struct mutex sgreset_mutex;
402 	spinlock_t sgreset_lock; /* lock for sgreset */
403 	struct scsi_cmnd *sgreset_sc;
404 	struct dentry *fnic_stats_debugfs_host;
405 	struct dentry *fnic_stats_debugfs_file;
406 	struct dentry *fnic_reset_debugfs_file;
407 	unsigned int reset_stats;
408 	atomic64_t io_cmpl_skip;
409 	struct fnic_stats fnic_stats;
410 
411 	u32 vlan_hw_insert:1;	        /* let hw insert the tag */
412 	u32 in_remove:1;                /* fnic device in removal */
413 	u32 stop_rx_link_events:1;      /* stop proc. rx frames, link events */
414 
415 	struct completion *fw_reset_done;
416 	u32 reset_in_progress;
417 	atomic_t in_flight;		/* io counter */
418 	bool internal_reset_inprogress;
419 	u32 _reserved;			/* fill hole */
420 	unsigned long state_flags;	/* protected by host lock */
421 	enum fnic_state state;
422 	spinlock_t fnic_lock;
423 	unsigned long lock_flags;
424 
425 	u16 vlan_id;	                /* VLAN tag including priority */
426 	u8 data_src_addr[ETH_ALEN];
427 	u64 fcp_input_bytes;		/* internal statistic */
428 	u64 fcp_output_bytes;		/* internal statistic */
429 	u32 link_down_cnt;
430 	u32 soft_reset_count;
431 	int link_status;
432 
433 	struct list_head list;
434 	struct list_head links;
435 	struct pci_dev *pdev;
436 	struct vnic_fc_config config;
437 	struct vnic_dev *vdev;
438 	unsigned int raw_wq_count;
439 	unsigned int wq_copy_count;
440 	unsigned int rq_count;
441 	int fw_ack_index[FNIC_WQ_COPY_MAX];
442 	unsigned short fw_ack_recd[FNIC_WQ_COPY_MAX];
443 	unsigned short wq_copy_desc_low[FNIC_WQ_COPY_MAX];
444 	unsigned int intr_count;
445 	u32 __iomem *legacy_pba;
446 	struct fnic_host_tag *tags;
447 	mempool_t *io_req_pool;
448 	mempool_t *io_sgl_pool[FNIC_SGL_NUM_CACHES];
449 
450 	unsigned int copy_wq_base;
451 	struct work_struct link_work;
452 	struct work_struct frame_work;
453 	struct work_struct flush_work;
454 	struct list_head frame_queue;
455 	struct list_head tx_queue;
456 	mempool_t *frame_pool;
457 	mempool_t *frame_elem_pool;
458 	mempool_t *frame_recv_pool;
459 	struct work_struct tport_work;
460 	struct list_head tport_event_list;
461 
462 	char subsys_desc[14];
463 	int subsys_desc_len;
464 	int pc_rscn_handling_status;
465 
466 	/*** FIP related data members  -- start ***/
467 	void (*set_vlan)(struct fnic *, u16 vlan);
468 	struct work_struct      fip_frame_work;
469 	struct work_struct		fip_timer_work;
470 	struct list_head		fip_frame_queue;
471 	struct timer_list       fip_timer;
472 	spinlock_t              vlans_lock;
473 	struct timer_list retry_fip_timer;
474 	struct timer_list fcs_ka_timer;
475 	struct timer_list enode_ka_timer;
476 	struct timer_list vn_ka_timer;
477 	struct list_head vlan_list;
478 	/*** FIP related data members  -- end ***/
479 
480 	/* NVME data members */
481 	struct dentry *fnic_nvmef_debugfs_host;
482 	struct dentry *fnic_nvmef_debugfs_file;
483 	struct sbitmap nvfnic_tag_map;
484 	struct work_struct nvme_io_cmpl_work;
485 	atomic_t nvme_io_event_queued;
486 	struct llist_head nvme_io_event_llist;
487 	struct completion *nvme_lport_unreg_done;
488 
489 	/* copy work queue cache line section */
490 	____cacheline_aligned struct vnic_wq_copy hw_copy_wq[FNIC_WQ_COPY_MAX];
491 	____cacheline_aligned struct fnic_cpy_wq sw_copy_wq[FNIC_WQ_COPY_MAX];
492 
493 	/* completion queue cache line section */
494 	____cacheline_aligned struct vnic_cq cq[FNIC_CQ_MAX];
495 
496 	spinlock_t wq_copy_lock[FNIC_WQ_COPY_MAX];
497 
498 	/* work queue cache line section */
499 	____cacheline_aligned struct vnic_wq wq[FNIC_WQ_MAX];
500 	spinlock_t wq_lock[FNIC_WQ_MAX];
501 
502 	/* receive queue cache line section */
503 	____cacheline_aligned struct vnic_rq rq[FNIC_RQ_MAX];
504 
505 	/* interrupt resource cache line section */
506 	____cacheline_aligned struct vnic_intr intr[FNIC_MSIX_INTR_MAX];
507 };
508 
509 extern struct workqueue_struct *fnic_event_queue;
510 extern struct workqueue_struct *fnic_fip_queue;
511 extern const struct attribute_group *fnic_host_groups[];
512 
513 void fnic_clear_intr_mode(struct fnic *fnic);
514 int fnic_set_intr_mode(struct fnic *fnic);
515 int fnic_set_intr_mode_msix(struct fnic *fnic);
516 void fnic_free_intr(struct fnic *fnic);
517 int fnic_request_intr(struct fnic *fnic);
518 
519 void fnic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf);
520 void fnic_handle_frame(struct work_struct *work);
521 void fnic_tport_event_handler(struct work_struct *work);
522 void fnic_handle_link(struct work_struct *work);
523 void fnic_handle_event(struct work_struct *work);
524 void fdls_reclaim_oxid_handler(struct work_struct *work);
525 void fdls_schedule_oxid_free(struct fnic_iport_s *iport, uint16_t *active_oxid);
526 void fdls_schedule_oxid_free_retry_work(struct work_struct *work);
527 int fnic_rq_cmpl_handler(struct fnic *fnic, int);
528 int fnic_alloc_rq_frame(struct vnic_rq *rq);
529 void fnic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf);
530 void fnic_flush_tx(struct work_struct *work);
531 void fnic_update_mac_locked(struct fnic *, u8 *new);
532 
533 enum scsi_qc_status fnic_queuecommand(struct Scsi_Host *shost,
534 				      struct scsi_cmnd *sc);
535 int fnic_abort_cmd(struct scsi_cmnd *);
536 int fnic_device_reset(struct scsi_cmnd *);
537 int fnic_eh_host_reset_handler(struct scsi_cmnd *sc);
538 int fnic_host_reset(struct Scsi_Host *shost);
539 void fnic_reset(struct Scsi_Host *shost);
540 int fnic_issue_fc_host_lip(struct Scsi_Host *shost);
541 void fnic_get_host_port_state(struct Scsi_Host *shost);
542 void fnic_fcpio_reset(struct fnic *fnic);
543 int fnic_wq_copy_cmpl_handler(struct fnic *fnic, int copy_work_to_do, unsigned int cq_index);
544 int fnic_wq_cmpl_handler(struct fnic *fnic, int);
545 int fnic_flogi_reg_handler(struct fnic *fnic, u32);
546 void fnic_wq_copy_cleanup_handler(struct vnic_wq_copy *wq,
547 				  struct fcpio_host_req *desc);
548 int fnic_fw_reset_handler(struct fnic *fnic);
549 void fnic_terminate_rport_io(struct fc_rport *);
550 const char *fnic_state_to_str(unsigned int state);
551 void fnic_mq_map_queues_cpus(struct Scsi_Host *host);
552 void fnic_log_q_error(struct fnic *fnic);
553 void fnic_handle_link_event(struct fnic *fnic);
554 int fnic_stats_debugfs_init(struct fnic *fnic);
555 void fnic_stats_debugfs_remove(struct fnic *fnic);
556 void fnic_nvmef_debugfs_init(struct fnic *fnic);
557 void fnic_nvmef_debugfs_remove(struct fnic *fnic);
558 int nvfnic_get_nvmef_info(struct fnic *fnic, struct fnic_nvmef_info *info);
559 int fnic_is_abts_pending(struct fnic *, struct scsi_cmnd *);
560 
561 void fnic_handle_fip_frame(struct work_struct *work);
562 void fnic_reset_work_handler(struct work_struct *work);
563 void fnic_handle_fip_event(struct fnic *fnic);
564 void fnic_fcoe_reset_vlans(struct fnic *fnic);
565 extern void fnic_handle_fip_timer(struct timer_list *t);
566 
567 static inline int
568 fnic_chk_state_flags_locked(struct fnic *fnic, unsigned long st_flags)
569 {
570 	return ((fnic->state_flags & st_flags) == st_flags);
571 }
572 void __fnic_set_state_flags(struct fnic *, unsigned long, unsigned long);
573 void fnic_dump_fchost_stats(struct Scsi_Host *, struct fc_host_statistics *);
574 void fnic_free_txq(struct fnic *fnic);
575 void fnic_free_rxq(struct fnic *fnic);
576 int fnic_get_desc_by_devid(struct pci_dev *pdev, char **desc,
577 						   char **subsys_desc);
578 void fnic_fdls_link_status_change(struct fnic *fnic, int linkup);
579 void fnic_delete_fcp_tports(struct fnic *fnic);
580 void fnic_flush_tport_event_list(struct fnic *fnic);
581 int fnic_count_ioreqs_wq(struct fnic *fnic, u32 hwq, u32 portid);
582 unsigned int fnic_count_ioreqs(struct fnic *fnic, u32 portid);
583 unsigned int fnic_count_all_ioreqs(struct fnic *fnic);
584 unsigned int fnic_count_lun_ioreqs_wq(struct fnic *fnic, u32 hwq,
585 						  struct scsi_device *device);
586 unsigned int fnic_count_lun_ioreqs(struct fnic *fnic,
587 					   struct scsi_device *device);
588 void fnic_scsi_unload(struct fnic *fnic);
589 void fnic_scsi_unload_cleanup(struct fnic *fnic);
590 int fnic_get_debug_info(struct stats_debug_info *info,
591 			struct fnic *fnic);
592 int free_wq_copy_descs(struct fnic *fnic, struct vnic_wq_copy *wq,
593 			unsigned int hwq);
594 
595 struct fnic_scsi_iter_data {
596 	struct fnic *fnic;
597 	void *data1;
598 	void *data2;
599 	bool (*fn)(struct fnic *fnic, struct scsi_cmnd *sc,
600 			void *data1, void *data2);
601 };
602 
603 static inline bool
604 fnic_io_iter_handler(struct scsi_cmnd *sc, void *iter_data)
605 {
606 	struct fnic_scsi_iter_data *iter = iter_data;
607 
608 	return iter->fn(iter->fnic, sc, iter->data1, iter->data2);
609 }
610 
611 static inline void
612 fnic_scsi_io_iter(struct fnic *fnic,
613 		bool (*fn)(struct fnic *fnic, struct scsi_cmnd *sc,
614 				void *data1, void *data2),
615 		void *data1, void *data2)
616 {
617 	struct fnic_scsi_iter_data iter_data = {
618 		.fn = fn,
619 		.fnic = fnic,
620 		.data1 = data1,
621 		.data2 = data2,
622 	};
623 	scsi_host_busy_iter(fnic->host, fnic_io_iter_handler, &iter_data);
624 }
625 
626 #ifdef FNIC_DEBUG
627 static inline void
628 fnic_debug_dump(struct fnic *fnic, uint8_t *u8arr, int len)
629 {
630 	int i;
631 
632 	for (i = 0; i < len; i = i+8) {
633 		FNIC_FCS_DBG(KERN_INFO, fnic,
634 		    "%d: %02x %02x %02x %02x %02x %02x %02x %02x", i / 8,
635 		    u8arr[i + 0], u8arr[i + 1], u8arr[i + 2], u8arr[i + 3],
636 		    u8arr[i + 4], u8arr[i + 5], u8arr[i + 6], u8arr[i + 7]);
637 	}
638 }
639 
640 static inline void
641 fnic_debug_dump_fc_frame(struct fnic *fnic, struct fc_frame_header *fchdr,
642 				int len, char *pfx)
643 {
644 	uint32_t s_id, d_id;
645 
646 	s_id = ntoh24(fchdr->fh_s_id);
647 	d_id = ntoh24(fchdr->fh_d_id);
648 	FNIC_FCS_DBG(KERN_INFO, fnic,
649 		"%s packet contents: sid/did/type/oxid = 0x%x/0x%x/0x%x/0x%x (len = %d)\n",
650 		pfx, s_id, d_id, fchdr->fh_type,
651 		FNIC_STD_GET_OX_ID(fchdr), len);
652 
653 	fnic_debug_dump(fnic, (uint8_t *)fchdr, len);
654 
655 }
656 #else /* FNIC_DEBUG */
657 static inline void
658 fnic_debug_dump(struct fnic *fnic, uint8_t *u8arr, int len) {}
659 static inline void
660 fnic_debug_dump_fc_frame(struct fnic *fnic, struct fc_frame_header *fchdr,
661 				uint32_t len, char *pfx) {}
662 #endif /* FNIC_DEBUG */
663 #endif /* _FNIC_H_ */
664