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