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