xref: /linux/drivers/scsi/bfa/bfad_drv.h (revision 8816624222b12e5d7e291e9d1973fc42b994eb6b)
17725ccfdSJing Huang /*
2a36c61f9SKrishna Gudipati  * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
37725ccfdSJing Huang  * All rights reserved
47725ccfdSJing Huang  * www.brocade.com
57725ccfdSJing Huang  *
67725ccfdSJing Huang  * Linux driver for Brocade Fibre Channel Host Bus Adapter.
77725ccfdSJing Huang  *
87725ccfdSJing Huang  * This program is free software; you can redistribute it and/or modify it
97725ccfdSJing Huang  * under the terms of the GNU General Public License (GPL) Version 2 as
107725ccfdSJing Huang  * published by the Free Software Foundation
117725ccfdSJing Huang  *
127725ccfdSJing Huang  * This program is distributed in the hope that it will be useful, but
137725ccfdSJing Huang  * WITHOUT ANY WARRANTY; without even the implied warranty of
147725ccfdSJing Huang  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
157725ccfdSJing Huang  * General Public License for more details.
167725ccfdSJing Huang  */
177725ccfdSJing Huang 
18acdc79a6SJing Huang /*
197725ccfdSJing Huang  * Contains base driver definitions.
207725ccfdSJing Huang  */
217725ccfdSJing Huang 
22acdc79a6SJing Huang /*
237725ccfdSJing Huang  *  bfa_drv.h Linux driver data structures.
247725ccfdSJing Huang  */
257725ccfdSJing Huang 
267725ccfdSJing Huang #ifndef __BFAD_DRV_H__
277725ccfdSJing Huang #define __BFAD_DRV_H__
287725ccfdSJing Huang 
297725ccfdSJing Huang #include "bfa_os_inc.h"
307725ccfdSJing Huang 
31a36c61f9SKrishna Gudipati #include "bfa_modules.h"
32a36c61f9SKrishna Gudipati #include "bfa_fcs.h"
33a36c61f9SKrishna Gudipati #include "bfa_defs_fcs.h"
347725ccfdSJing Huang 
35a36c61f9SKrishna Gudipati #include "bfa_plog.h"
36a36c61f9SKrishna Gudipati #include "bfa_cs.h"
377725ccfdSJing Huang 
387725ccfdSJing Huang #define BFAD_DRIVER_NAME	"bfa"
397725ccfdSJing Huang #ifdef BFA_DRIVER_VERSION
407725ccfdSJing Huang #define BFAD_DRIVER_VERSION    BFA_DRIVER_VERSION
417725ccfdSJing Huang #else
42a36c61f9SKrishna Gudipati #define BFAD_DRIVER_VERSION    "2.3.2.0"
437725ccfdSJing Huang #endif
447725ccfdSJing Huang 
45a36c61f9SKrishna Gudipati #define BFAD_PROTO_NAME FCPI_NAME
467725ccfdSJing Huang #define BFAD_IRQ_FLAGS IRQF_SHARED
477725ccfdSJing Huang 
48a36c61f9SKrishna Gudipati #ifndef FC_PORTSPEED_8GBIT
49a36c61f9SKrishna Gudipati #define FC_PORTSPEED_8GBIT 0x10
50a36c61f9SKrishna Gudipati #endif
51a36c61f9SKrishna Gudipati 
527725ccfdSJing Huang /*
537725ccfdSJing Huang  * BFAD flags
547725ccfdSJing Huang  */
557725ccfdSJing Huang #define BFAD_MSIX_ON				0x00000001
567725ccfdSJing Huang #define BFAD_HAL_INIT_DONE			0x00000002
577725ccfdSJing Huang #define BFAD_DRV_INIT_DONE			0x00000004
587725ccfdSJing Huang #define BFAD_CFG_PPORT_DONE			0x00000008
597725ccfdSJing Huang #define BFAD_HAL_START_DONE			0x00000010
607725ccfdSJing Huang #define BFAD_PORT_ONLINE			0x00000020
617725ccfdSJing Huang #define BFAD_RPORT_ONLINE			0x00000040
62e6714324SKrishna Gudipati #define BFAD_FCS_INIT_DONE			0x00000080
63e6714324SKrishna Gudipati #define BFAD_HAL_INIT_FAIL			0x00000100
64e6714324SKrishna Gudipati #define BFAD_FC4_PROBE_DONE			0x00000200
657725ccfdSJing Huang #define BFAD_PORT_DELETE			0x00000001
667725ccfdSJing Huang 
677725ccfdSJing Huang /*
687725ccfdSJing Huang  * BFAD related definition
697725ccfdSJing Huang  */
707725ccfdSJing Huang #define SCSI_SCAN_DELAY		HZ
717725ccfdSJing Huang #define BFAD_STOP_TIMEOUT	30
727725ccfdSJing Huang #define BFAD_SUSPEND_TIMEOUT	BFAD_STOP_TIMEOUT
737725ccfdSJing Huang 
747725ccfdSJing Huang /*
757725ccfdSJing Huang  * BFAD configuration parameter default values
767725ccfdSJing Huang  */
777725ccfdSJing Huang #define BFAD_LUN_QUEUE_DEPTH	32
787725ccfdSJing Huang #define BFAD_IO_MAX_SGE		SG_ALL
797725ccfdSJing Huang 
807725ccfdSJing Huang #define bfad_isr_t irq_handler_t
817725ccfdSJing Huang 
827725ccfdSJing Huang #define MAX_MSIX_ENTRY 22
837725ccfdSJing Huang 
847725ccfdSJing Huang struct bfad_msix_s {
857725ccfdSJing Huang 	struct bfad_s *bfad;
867725ccfdSJing Huang 	struct msix_entry msix;
87a36c61f9SKrishna Gudipati 	char name[32];
88a36c61f9SKrishna Gudipati };
89a36c61f9SKrishna Gudipati 
90a36c61f9SKrishna Gudipati /*
91a36c61f9SKrishna Gudipati  * Only append to the enums defined here to avoid any versioning
92a36c61f9SKrishna Gudipati  * needed between trace utility and driver version
93a36c61f9SKrishna Gudipati  */
94a36c61f9SKrishna Gudipati enum {
95a36c61f9SKrishna Gudipati 	BFA_TRC_LDRV_BFAD		= 1,
96a36c61f9SKrishna Gudipati 	BFA_TRC_LDRV_IM			= 2,
977725ccfdSJing Huang };
987725ccfdSJing Huang 
997725ccfdSJing Huang enum bfad_port_pvb_type {
1007725ccfdSJing Huang 	BFAD_PORT_PHYS_BASE = 0,
1017725ccfdSJing Huang 	BFAD_PORT_PHYS_VPORT = 1,
1027725ccfdSJing Huang 	BFAD_PORT_VF_BASE = 2,
1037725ccfdSJing Huang 	BFAD_PORT_VF_VPORT = 3,
1047725ccfdSJing Huang };
1057725ccfdSJing Huang 
1067725ccfdSJing Huang /*
1077725ccfdSJing Huang  * PORT data structure
1087725ccfdSJing Huang  */
1097725ccfdSJing Huang struct bfad_port_s {
1107725ccfdSJing Huang 	struct list_head list_entry;
1117725ccfdSJing Huang 	struct bfad_s	*bfad;
112a36c61f9SKrishna Gudipati 	struct bfa_fcs_lport_s *fcs_port;
1137725ccfdSJing Huang 	u32	roles;
1147725ccfdSJing Huang 	s32		flags;
1157725ccfdSJing Huang 	u32	supported_fc4s;
1167725ccfdSJing Huang 	enum bfad_port_pvb_type pvb_type;
1177725ccfdSJing Huang 	struct bfad_im_port_s *im_port;	/* IM specific data */
118ab2a9ba1SJing Huang 	/* port debugfs specific data */
119ab2a9ba1SJing Huang 	struct dentry *port_debugfs_root;
1207725ccfdSJing Huang };
1217725ccfdSJing Huang 
1227725ccfdSJing Huang /*
1237725ccfdSJing Huang  * VPORT data structure
1247725ccfdSJing Huang  */
1257725ccfdSJing Huang struct bfad_vport_s {
1267725ccfdSJing Huang 	struct bfad_port_s     drv_port;
1277725ccfdSJing Huang 	struct bfa_fcs_vport_s fcs_vport;
1287725ccfdSJing Huang 	struct completion *comp_del;
129d9883548SJing Huang 	struct list_head list_entry;
1307725ccfdSJing Huang };
1317725ccfdSJing Huang 
1327725ccfdSJing Huang /*
1337725ccfdSJing Huang  * VF data structure
1347725ccfdSJing Huang  */
1357725ccfdSJing Huang struct bfad_vf_s {
1367725ccfdSJing Huang 	bfa_fcs_vf_t    fcs_vf;
1377725ccfdSJing Huang 	struct bfad_port_s    base_port;	/* base port for vf */
1387725ccfdSJing Huang 	struct bfad_s   *bfad;
1397725ccfdSJing Huang };
1407725ccfdSJing Huang 
1417725ccfdSJing Huang struct bfad_cfg_param_s {
1427725ccfdSJing Huang 	u32	rport_del_timeout;
1437725ccfdSJing Huang 	u32	ioc_queue_depth;
1447725ccfdSJing Huang 	u32	lun_queue_depth;
1457725ccfdSJing Huang 	u32	io_max_sge;
1467725ccfdSJing Huang 	u32	binding_method;
1477725ccfdSJing Huang };
1487725ccfdSJing Huang 
149a36c61f9SKrishna Gudipati union bfad_tmp_buf {
150a36c61f9SKrishna Gudipati 	/* From struct bfa_adapter_attr_s */
151a36c61f9SKrishna Gudipati 	char		manufacturer[BFA_ADAPTER_MFG_NAME_LEN];
152a36c61f9SKrishna Gudipati 	char		serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
153a36c61f9SKrishna Gudipati 	char		model[BFA_ADAPTER_MODEL_NAME_LEN];
154a36c61f9SKrishna Gudipati 	char		fw_ver[BFA_VERSION_LEN];
155a36c61f9SKrishna Gudipati 	char		optrom_ver[BFA_VERSION_LEN];
156a36c61f9SKrishna Gudipati 
157a36c61f9SKrishna Gudipati 	/* From struct bfa_ioc_pci_attr_s */
158a36c61f9SKrishna Gudipati 	u8		chip_rev[BFA_IOC_CHIP_REV_LEN];  /*  chip revision */
159a36c61f9SKrishna Gudipati 
160a36c61f9SKrishna Gudipati 	wwn_t		wwn[BFA_FCS_MAX_LPORTS];
161a36c61f9SKrishna Gudipati };
162a36c61f9SKrishna Gudipati 
1637725ccfdSJing Huang /*
1647725ccfdSJing Huang  * BFAD (PCI function) data structure
1657725ccfdSJing Huang  */
1667725ccfdSJing Huang struct bfad_s {
167a36c61f9SKrishna Gudipati 	bfa_sm_t	sm;	/* state machine */
1687725ccfdSJing Huang 	struct list_head list_entry;
1697725ccfdSJing Huang 	struct bfa_s	bfa;
1707725ccfdSJing Huang 	struct bfa_fcs_s bfa_fcs;
1717725ccfdSJing Huang 	struct pci_dev *pcidev;
1727725ccfdSJing Huang 	const char *pci_name;
1737725ccfdSJing Huang 	struct bfa_pcidev_s hal_pcidev;
1747725ccfdSJing Huang 	struct bfa_ioc_pci_attr_s pci_attr;
1757725ccfdSJing Huang 	void __iomem   *pci_bar0_kva;
1767725ccfdSJing Huang 	struct completion comp;
1777725ccfdSJing Huang 	struct completion suspend;
1787725ccfdSJing Huang 	struct completion disable_comp;
1797725ccfdSJing Huang 	bfa_boolean_t   disable_active;
1807725ccfdSJing Huang 	struct bfad_port_s     pport;	/* physical port of the BFAD */
1817725ccfdSJing Huang 	struct bfa_meminfo_s meminfo;
1827725ccfdSJing Huang 	struct bfa_iocfc_cfg_s   ioc_cfg;
1837725ccfdSJing Huang 	u32	inst_no;	/* BFAD instance number */
1847725ccfdSJing Huang 	u32	bfad_flags;
1857725ccfdSJing Huang 	spinlock_t      bfad_lock;
186e6714324SKrishna Gudipati 	struct task_struct *bfad_tsk;
1877725ccfdSJing Huang 	struct bfad_cfg_param_s cfg_data;
1887725ccfdSJing Huang 	struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY];
1897725ccfdSJing Huang 	int		nvec;
1907725ccfdSJing Huang 	char	adapter_name[BFA_ADAPTER_SYM_NAME_LEN];
1917725ccfdSJing Huang 	char	port_name[BFA_ADAPTER_SYM_NAME_LEN];
1927725ccfdSJing Huang 	struct timer_list hal_tmo;
1937725ccfdSJing Huang 	unsigned long   hs_start;
1947725ccfdSJing Huang 	struct bfad_im_s *im;		/* IM specific data */
1957725ccfdSJing Huang 	struct bfa_trc_mod_s  *trcmod;
1967725ccfdSJing Huang 	struct bfa_plog_s      plog_buf;
1977725ccfdSJing Huang 	int		ref_count;
198a36c61f9SKrishna Gudipati 	union bfad_tmp_buf tmp_buf;
1997725ccfdSJing Huang 	struct fc_host_statistics link_stats;
200a36c61f9SKrishna Gudipati 	struct list_head pbc_vport_list;
201ab2a9ba1SJing Huang 	/* debugfs specific data */
202ab2a9ba1SJing Huang 	char *regdata;
203ab2a9ba1SJing Huang 	u32 reglen;
204ab2a9ba1SJing Huang 	struct dentry *bfad_dentry_files[5];
205d9883548SJing Huang };
206d9883548SJing Huang 
207a36c61f9SKrishna Gudipati /* BFAD state machine events */
208a36c61f9SKrishna Gudipati enum bfad_sm_event {
209a36c61f9SKrishna Gudipati 	BFAD_E_CREATE			= 1,
210a36c61f9SKrishna Gudipati 	BFAD_E_KTHREAD_CREATE_FAILED	= 2,
211a36c61f9SKrishna Gudipati 	BFAD_E_INIT			= 3,
212a36c61f9SKrishna Gudipati 	BFAD_E_INIT_SUCCESS		= 4,
213a36c61f9SKrishna Gudipati 	BFAD_E_INIT_FAILED		= 5,
214a36c61f9SKrishna Gudipati 	BFAD_E_INTR_INIT_FAILED		= 6,
215a36c61f9SKrishna Gudipati 	BFAD_E_FCS_EXIT_COMP		= 7,
216a36c61f9SKrishna Gudipati 	BFAD_E_EXIT_COMP		= 8,
217a36c61f9SKrishna Gudipati 	BFAD_E_STOP			= 9
2187725ccfdSJing Huang };
2197725ccfdSJing Huang 
2207725ccfdSJing Huang /*
2217725ccfdSJing Huang  * RPORT data structure
2227725ccfdSJing Huang  */
2237725ccfdSJing Huang struct bfad_rport_s {
2247725ccfdSJing Huang 	struct bfa_fcs_rport_s fcs_rport;
2257725ccfdSJing Huang };
2267725ccfdSJing Huang 
2277725ccfdSJing Huang struct bfad_buf_info {
2287725ccfdSJing Huang 	void		*virt;
2297725ccfdSJing Huang 	dma_addr_t      phys;
2307725ccfdSJing Huang 	u32	size;
2317725ccfdSJing Huang };
2327725ccfdSJing Huang 
2337725ccfdSJing Huang struct bfad_fcxp {
2347725ccfdSJing Huang 	struct bfad_port_s    *port;
2357725ccfdSJing Huang 	struct bfa_rport_s *bfa_rport;
2367725ccfdSJing Huang 	bfa_status_t    req_status;
2377725ccfdSJing Huang 	u16	tag;
2387725ccfdSJing Huang 	u16	rsp_len;
2397725ccfdSJing Huang 	u16	rsp_maxlen;
2407725ccfdSJing Huang 	u8		use_ireqbuf;
2417725ccfdSJing Huang 	u8		use_irspbuf;
2427725ccfdSJing Huang 	u32	num_req_sgles;
2437725ccfdSJing Huang 	u32	num_rsp_sgles;
2447725ccfdSJing Huang 	struct fchs_s	fchs;
2457725ccfdSJing Huang 	void		*reqbuf_info;
2467725ccfdSJing Huang 	void		*rspbuf_info;
2477725ccfdSJing Huang 	struct bfa_sge_s  *req_sge;
2487725ccfdSJing Huang 	struct bfa_sge_s  *rsp_sge;
2497725ccfdSJing Huang 	fcxp_send_cb_t  send_cbfn;
2507725ccfdSJing Huang 	void		*send_cbarg;
2517725ccfdSJing Huang 	void		*bfa_fcxp;
2527725ccfdSJing Huang 	struct completion comp;
2537725ccfdSJing Huang };
2547725ccfdSJing Huang 
2557725ccfdSJing Huang struct bfad_hal_comp {
2567725ccfdSJing Huang 	bfa_status_t    status;
2577725ccfdSJing Huang 	struct completion comp;
2587725ccfdSJing Huang };
2597725ccfdSJing Huang 
2607725ccfdSJing Huang /*
2617725ccfdSJing Huang  * Macro to obtain the immediate lower power
2627725ccfdSJing Huang  * of two for the integer.
2637725ccfdSJing Huang  */
2647725ccfdSJing Huang #define nextLowerInt(x)                         \
2657725ccfdSJing Huang do {                                            \
266a36c61f9SKrishna Gudipati 	int i;                                  \
2677725ccfdSJing Huang 	(*x)--;					\
268a36c61f9SKrishna Gudipati 	for (i = 1; i < (sizeof(int)*8); i <<= 1) \
269a36c61f9SKrishna Gudipati 		(*x) = (*x) | (*x) >> i;	\
2707725ccfdSJing Huang 	(*x)++;					\
2717725ccfdSJing Huang 	(*x) = (*x) >> 1;			\
2727725ccfdSJing Huang } while (0)
2737725ccfdSJing Huang 
2747725ccfdSJing Huang 
275a36c61f9SKrishna Gudipati #define list_remove_head(list, entry, type, member)		\
276a36c61f9SKrishna Gudipati do {								\
277a36c61f9SKrishna Gudipati 	entry = NULL;                                           \
278a36c61f9SKrishna Gudipati 	if (!list_empty(list)) {                                \
279a36c61f9SKrishna Gudipati 		entry = list_entry((list)->next, type, member);	\
280a36c61f9SKrishna Gudipati 		list_del_init(&entry->member);			\
281a36c61f9SKrishna Gudipati 	}							\
282a36c61f9SKrishna Gudipati } while (0)
283a36c61f9SKrishna Gudipati 
284a36c61f9SKrishna Gudipati #define list_get_first(list, type, member)				\
285a36c61f9SKrishna Gudipati ((list_empty(list)) ? NULL :						\
286a36c61f9SKrishna Gudipati 	list_entry((list)->next, type, member))
287a36c61f9SKrishna Gudipati 
2887725ccfdSJing Huang bfa_status_t	bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
289a36c61f9SKrishna Gudipati 				  struct bfa_lport_cfg_s *port_cfg,
290a36c61f9SKrishna Gudipati 				  struct device *dev);
2917725ccfdSJing Huang bfa_status_t	bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
292a36c61f9SKrishna Gudipati 			       struct bfa_lport_cfg_s *port_cfg);
293a36c61f9SKrishna Gudipati bfa_status_t	bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role);
2947725ccfdSJing Huang bfa_status_t	bfad_drv_init(struct bfad_s *bfad);
295e6714324SKrishna Gudipati bfa_status_t	bfad_start_ops(struct bfad_s *bfad);
2967725ccfdSJing Huang void		bfad_drv_start(struct bfad_s *bfad);
2977725ccfdSJing Huang void		bfad_uncfg_pport(struct bfad_s *bfad);
298a36c61f9SKrishna Gudipati void		bfad_stop(struct bfad_s *bfad);
299a36c61f9SKrishna Gudipati void		bfad_fcs_stop(struct bfad_s *bfad);
3007725ccfdSJing Huang void		bfad_remove_intr(struct bfad_s *bfad);
3017725ccfdSJing Huang void		bfad_hal_mem_release(struct bfad_s *bfad);
3027725ccfdSJing Huang void		bfad_hcb_comp(void *arg, bfa_status_t status);
3037725ccfdSJing Huang 
3047725ccfdSJing Huang int		bfad_setup_intr(struct bfad_s *bfad);
3057725ccfdSJing Huang void		bfad_remove_intr(struct bfad_s *bfad);
3067725ccfdSJing Huang void		bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg);
3077725ccfdSJing Huang bfa_status_t	bfad_hal_mem_alloc(struct bfad_s *bfad);
3087725ccfdSJing Huang void		bfad_bfa_tmo(unsigned long data);
3097725ccfdSJing Huang void		bfad_init_timer(struct bfad_s *bfad);
3107725ccfdSJing Huang int		bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
3117725ccfdSJing Huang void		bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
3127725ccfdSJing Huang void		bfad_drv_uninit(struct bfad_s *bfad);
313e6714324SKrishna Gudipati int		bfad_worker(void *ptr);
314ab2a9ba1SJing Huang void		bfad_debugfs_init(struct bfad_port_s *port);
315ab2a9ba1SJing Huang void		bfad_debugfs_exit(struct bfad_port_s *port);
316e6714324SKrishna Gudipati 
3177725ccfdSJing Huang void bfad_pci_remove(struct pci_dev *pdev);
3187725ccfdSJing Huang int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid);
3197725ccfdSJing Huang void bfad_os_rport_online_wait(struct bfad_s *bfad);
3207725ccfdSJing Huang int bfad_os_get_linkup_delay(struct bfad_s *bfad);
3217725ccfdSJing Huang int bfad_install_msix_handler(struct bfad_s *bfad);
3227725ccfdSJing Huang 
3237725ccfdSJing Huang extern struct idr bfad_im_port_index;
324a36c61f9SKrishna Gudipati extern struct pci_device_id bfad_id_table[];
3257725ccfdSJing Huang extern struct list_head bfad_list;
326a36c61f9SKrishna Gudipati extern char	*os_name;
327a36c61f9SKrishna Gudipati extern char	*os_patch;
328a36c61f9SKrishna Gudipati extern char	*host_name;
329a36c61f9SKrishna Gudipati extern int	num_rports;
330a36c61f9SKrishna Gudipati extern int	num_ios;
331a36c61f9SKrishna Gudipati extern int	num_tms;
332a36c61f9SKrishna Gudipati extern int	num_fcxps;
333a36c61f9SKrishna Gudipati extern int	num_ufbufs;
334a36c61f9SKrishna Gudipati extern int	reqq_size;
335a36c61f9SKrishna Gudipati extern int	rspq_size;
336a36c61f9SKrishna Gudipati extern int	num_sgpgs;
337a36c61f9SKrishna Gudipati extern int      rport_del_timeout;
3387725ccfdSJing Huang extern int      bfa_lun_queue_depth;
339a36c61f9SKrishna Gudipati extern int      bfa_io_max_sge;
340*88166242SJing Huang extern int      bfa_log_level;
341a36c61f9SKrishna Gudipati extern int      ioc_auto_recover;
3427725ccfdSJing Huang extern int      bfa_linkup_delay;
343a36c61f9SKrishna Gudipati extern int      msix_disable_cb;
344a36c61f9SKrishna Gudipati extern int      msix_disable_ct;
345a36c61f9SKrishna Gudipati extern int      fdmi_enable;
346a36c61f9SKrishna Gudipati extern int      supported_fc4s;
347a36c61f9SKrishna Gudipati extern int	pcie_max_read_reqsz;
348ab2a9ba1SJing Huang extern int bfa_debugfs_enable;
34942b426ecSJing Huang extern struct mutex bfad_mutex;
3507725ccfdSJing Huang 
3517725ccfdSJing Huang #endif /* __BFAD_DRV_H__ */
352