xref: /linux/drivers/scsi/bfa/bfad_drv.h (revision ef9226cd56b718c79184a3466d32984a51cb449c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
4  * Copyright (c) 2014- QLogic Corporation.
5  * All rights reserved
6  * www.qlogic.com
7  *
8  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9  */
10 
11 /*
12  * Contains base driver definitions.
13  */
14 
15 /*
16  *  bfa_drv.h Linux driver data structures.
17  */
18 
19 #ifndef __BFAD_DRV_H__
20 #define __BFAD_DRV_H__
21 
22 #include <linux/types.h>
23 #include <linux/pci.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/idr.h>
26 #include <linux/interrupt.h>
27 #include <linux/cdev.h>
28 #include <linux/fs.h>
29 #include <linux/delay.h>
30 #include <linux/vmalloc.h>
31 #include <linux/workqueue.h>
32 #include <linux/bitops.h>
33 #include <scsi/scsi.h>
34 #include <scsi/scsi_host.h>
35 #include <scsi/scsi_tcq.h>
36 #include <scsi/scsi_transport_fc.h>
37 #include <scsi/scsi_transport.h>
38 #include <scsi/scsi_bsg_fc.h>
39 #include <scsi/scsi_devinfo.h>
40 
41 #include "bfa_modules.h"
42 #include "bfa_fcs.h"
43 #include "bfa_defs_fcs.h"
44 
45 #include "bfa_plog.h"
46 #include "bfa_cs.h"
47 
48 #define BFAD_DRIVER_NAME	"bfa"
49 #ifdef BFA_DRIVER_VERSION
50 #define BFAD_DRIVER_VERSION    BFA_DRIVER_VERSION
51 #else
52 #define BFAD_DRIVER_VERSION    "3.2.25.1"
53 #endif
54 
55 #define BFAD_PROTO_NAME FCPI_NAME
56 #define BFAD_IRQ_FLAGS IRQF_SHARED
57 
58 #ifndef FC_PORTSPEED_8GBIT
59 #define FC_PORTSPEED_8GBIT 0x10
60 #endif
61 
62 /*
63  * BFAD flags
64  */
65 #define BFAD_MSIX_ON				0x00000001
66 #define BFAD_HAL_INIT_DONE			0x00000002
67 #define BFAD_DRV_INIT_DONE			0x00000004
68 #define BFAD_CFG_PPORT_DONE			0x00000008
69 #define BFAD_HAL_START_DONE			0x00000010
70 #define BFAD_PORT_ONLINE			0x00000020
71 #define BFAD_RPORT_ONLINE			0x00000040
72 #define BFAD_FCS_INIT_DONE			0x00000080
73 #define BFAD_HAL_INIT_FAIL			0x00000100
74 #define BFAD_FC4_PROBE_DONE			0x00000200
75 #define BFAD_PORT_DELETE			0x00000001
76 #define BFAD_INTX_ON				0x00000400
77 #define BFAD_EEH_BUSY				0x00000800
78 #define BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE	0x00001000
79 /*
80  * BFAD related definition
81  */
82 #define SCSI_SCAN_DELAY		HZ
83 #define BFAD_STOP_TIMEOUT	30
84 #define BFAD_SUSPEND_TIMEOUT	BFAD_STOP_TIMEOUT
85 
86 /*
87  * BFAD configuration parameter default values
88  */
89 #define BFAD_LUN_QUEUE_DEPTH	32
90 #define BFAD_IO_MAX_SGE		SG_ALL
91 #define BFAD_MIN_SECTORS	128 /* 64k   */
92 #define BFAD_MAX_SECTORS	0xFFFF  /* 32 MB */
93 
94 #define bfad_isr_t irq_handler_t
95 
96 #define MAX_MSIX_ENTRY 22
97 
98 struct bfad_msix_s {
99 	struct bfad_s *bfad;
100 	struct msix_entry msix;
101 	char name[32];
102 };
103 
104 /*
105  * Only append to the enums defined here to avoid any versioning
106  * needed between trace utility and driver version
107  */
108 enum {
109 	BFA_TRC_LDRV_BFAD		= 1,
110 	BFA_TRC_LDRV_IM			= 2,
111 	BFA_TRC_LDRV_BSG		= 3,
112 };
113 
114 enum bfad_port_pvb_type {
115 	BFAD_PORT_PHYS_BASE = 0,
116 	BFAD_PORT_PHYS_VPORT = 1,
117 	BFAD_PORT_VF_BASE = 2,
118 	BFAD_PORT_VF_VPORT = 3,
119 };
120 
121 /*
122  * PORT data structure
123  */
124 struct bfad_port_s {
125 	struct list_head list_entry;
126 	struct bfad_s	*bfad;
127 	struct bfa_fcs_lport_s *fcs_port;
128 	u32	roles;
129 	s32		flags;
130 	u32	supported_fc4s;
131 	enum bfad_port_pvb_type pvb_type;
132 	struct bfad_im_port_s *im_port;	/* IM specific data */
133 	/* port debugfs specific data */
134 	struct dentry *port_debugfs_root;
135 };
136 
137 /*
138  * VPORT data structure
139  */
140 struct bfad_vport_s {
141 	struct bfad_port_s     drv_port;
142 	struct bfa_fcs_vport_s fcs_vport;
143 	struct completion *comp_del;
144 	struct list_head list_entry;
145 };
146 
147 /*
148  * VF data structure
149  */
150 struct bfad_vf_s {
151 	bfa_fcs_vf_t    fcs_vf;
152 	struct bfad_port_s    base_port;	/* base port for vf */
153 	struct bfad_s   *bfad;
154 };
155 
156 struct bfad_cfg_param_s {
157 	u32	rport_del_timeout;
158 	u32	ioc_queue_depth;
159 	u32	lun_queue_depth;
160 	u32	io_max_sge;
161 	u32	binding_method;
162 };
163 
164 union bfad_tmp_buf {
165 	/* From struct bfa_adapter_attr_s */
166 	char		manufacturer[BFA_ADAPTER_MFG_NAME_LEN];
167 	char		serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
168 	char		model[BFA_ADAPTER_MODEL_NAME_LEN];
169 	char		fw_ver[BFA_VERSION_LEN];
170 	char		optrom_ver[BFA_VERSION_LEN];
171 
172 	/* From struct bfa_ioc_pci_attr_s */
173 	u8		chip_rev[BFA_IOC_CHIP_REV_LEN];  /*  chip revision */
174 
175 	wwn_t		wwn[BFA_FCS_MAX_LPORTS];
176 };
177 
178 /* BFAD state machine events */
179 enum bfad_sm_event {
180 	BFAD_E_CREATE			= 1,
181 	BFAD_E_KTHREAD_CREATE_FAILED	= 2,
182 	BFAD_E_INIT			= 3,
183 	BFAD_E_INIT_SUCCESS		= 4,
184 	BFAD_E_HAL_INIT_FAILED		= 5,
185 	BFAD_E_INIT_FAILED		= 6,
186 	BFAD_E_FCS_EXIT_COMP		= 7,
187 	BFAD_E_EXIT_COMP		= 8,
188 	BFAD_E_STOP			= 9
189 };
190 
191 struct bfad_s;
192 typedef void (*bfad_sm_t)(struct bfad_s *, enum bfad_sm_event);
193 
194 /*
195  * BFAD (PCI function) data structure
196  */
197 struct bfad_s {
198 	bfad_sm_t	sm;	/* state machine */
199 	struct list_head list_entry;
200 	struct bfa_s	bfa;
201 	struct bfa_fcs_s bfa_fcs;
202 	struct pci_dev *pcidev;
203 	const char *pci_name;
204 	struct bfa_pcidev_s hal_pcidev;
205 	struct bfa_ioc_pci_attr_s pci_attr;
206 	void __iomem   *pci_bar0_kva;
207 	void __iomem   *pci_bar2_kva;
208 	struct completion comp;
209 	struct completion suspend;
210 	struct completion enable_comp;
211 	struct completion disable_comp;
212 	bfa_boolean_t   disable_active;
213 	struct bfad_port_s     pport;	/* physical port of the BFAD */
214 	struct bfa_meminfo_s meminfo;
215 	struct bfa_iocfc_cfg_s   ioc_cfg;
216 	u32	inst_no;	/* BFAD instance number */
217 	u32	bfad_flags;
218 	spinlock_t      bfad_lock;
219 	struct task_struct *bfad_tsk;
220 	struct bfad_cfg_param_s cfg_data;
221 	struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY];
222 	int		nvec;
223 	char	adapter_name[BFA_ADAPTER_SYM_NAME_LEN];
224 	char	port_name[BFA_ADAPTER_SYM_NAME_LEN];
225 	struct timer_list hal_tmo;
226 	unsigned long   hs_start;
227 	struct bfad_im_s *im;		/* IM specific data */
228 	struct bfa_trc_mod_s  *trcmod;
229 	struct bfa_plog_s      plog_buf;
230 	int		ref_count;
231 	union bfad_tmp_buf tmp_buf;
232 	struct fc_host_statistics link_stats;
233 	struct list_head pbc_vport_list;
234 	/* debugfs specific data */
235 	char *regdata;
236 	u32 reglen;
237 	struct dentry *bfad_dentry_files[5];
238 	struct list_head	free_aen_q;
239 	struct list_head	active_aen_q;
240 	struct bfa_aen_entry_s	aen_list[BFA_AEN_MAX_ENTRY];
241 	spinlock_t		bfad_aen_spinlock;
242 	struct list_head	vport_list;
243 };
244 
245 /*
246  * RPORT data structure
247  */
248 struct bfad_rport_s {
249 	struct bfa_fcs_rport_s fcs_rport;
250 };
251 
252 struct bfad_buf_info {
253 	void		*virt;
254 	dma_addr_t      phys;
255 	u32	size;
256 };
257 
258 struct bfad_fcxp {
259 	struct bfad_port_s    *port;
260 	struct bfa_rport_s *bfa_rport;
261 	bfa_status_t    req_status;
262 	u16	tag;
263 	u16	rsp_len;
264 	u16	rsp_maxlen;
265 	u8		use_ireqbuf;
266 	u8		use_irspbuf;
267 	u32	num_req_sgles;
268 	u32	num_rsp_sgles;
269 	struct fchs_s	fchs;
270 	void		*reqbuf_info;
271 	void		*rspbuf_info;
272 	struct bfa_sge_s  *req_sge;
273 	struct bfa_sge_s  *rsp_sge;
274 	fcxp_send_cb_t  send_cbfn;
275 	void		*send_cbarg;
276 	void		*bfa_fcxp;
277 	struct completion comp;
278 };
279 
280 struct bfad_hal_comp {
281 	bfa_status_t    status;
282 	struct completion comp;
283 };
284 
285 #define BFA_LOG(level, bfad, mask, fmt, arg...)				\
286 do {									\
287 	if (((mask) == 4) || (level[1] <= '4'))				\
288 		dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg);	\
289 } while (0)
290 
291 bfa_status_t	bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
292 				  struct bfa_lport_cfg_s *port_cfg,
293 				  struct device *dev);
294 bfa_status_t	bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
295 			       struct bfa_lport_cfg_s *port_cfg);
296 bfa_status_t	bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role);
297 bfa_status_t	bfad_drv_init(struct bfad_s *bfad);
298 bfa_status_t	bfad_start_ops(struct bfad_s *bfad);
299 void		bfad_drv_start(struct bfad_s *bfad);
300 void		bfad_uncfg_pport(struct bfad_s *bfad);
301 void		bfad_stop(struct bfad_s *bfad);
302 void		bfad_fcs_stop(struct bfad_s *bfad);
303 void		bfad_remove_intr(struct bfad_s *bfad);
304 void		bfad_hal_mem_release(struct bfad_s *bfad);
305 void		bfad_hcb_comp(void *arg, bfa_status_t status);
306 
307 int		bfad_setup_intr(struct bfad_s *bfad);
308 void		bfad_remove_intr(struct bfad_s *bfad);
309 void		bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg);
310 bfa_status_t	bfad_hal_mem_alloc(struct bfad_s *bfad);
311 void		bfad_bfa_tmo(struct timer_list *t);
312 void		bfad_init_timer(struct bfad_s *bfad);
313 int		bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
314 void		bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
315 void		bfad_drv_uninit(struct bfad_s *bfad);
316 int		bfad_worker(void *ptr);
317 void		bfad_debugfs_init(struct bfad_port_s *port);
318 void		bfad_debugfs_exit(struct bfad_port_s *port);
319 
320 void bfad_pci_remove(struct pci_dev *pdev);
321 int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid);
322 void bfad_rport_online_wait(struct bfad_s *bfad);
323 int bfad_get_linkup_delay(struct bfad_s *bfad);
324 int bfad_install_msix_handler(struct bfad_s *bfad);
325 
326 extern struct idr bfad_im_port_index;
327 extern struct pci_device_id bfad_id_table[];
328 extern struct list_head bfad_list;
329 extern char	*os_name;
330 extern char	*os_patch;
331 extern char	*host_name;
332 extern int	num_rports;
333 extern int	num_ios;
334 extern int	num_tms;
335 extern int	num_fcxps;
336 extern int	num_ufbufs;
337 extern int	reqq_size;
338 extern int	rspq_size;
339 extern int	num_sgpgs;
340 extern int      rport_del_timeout;
341 extern int      bfa_lun_queue_depth;
342 extern int      bfa_io_max_sge;
343 extern int      bfa_log_level;
344 extern int      ioc_auto_recover;
345 extern int      bfa_linkup_delay;
346 extern int      msix_disable_cb;
347 extern int      msix_disable_ct;
348 extern int      fdmi_enable;
349 extern int      supported_fc4s;
350 extern int	pcie_max_read_reqsz;
351 extern int	max_xfer_size;
352 extern int bfa_debugfs_enable;
353 extern struct mutex bfad_mutex;
354 
355 #endif /* __BFAD_DRV_H__ */
356