1*52fa7bf9SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */ 27725ccfdSJing Huang /* 3889d0d42SAnil Gurumurthy * Copyright (c) 2005-2014 Brocade Communications Systems, Inc. 4889d0d42SAnil Gurumurthy * Copyright (c) 2014- QLogic Corporation. 57725ccfdSJing Huang * All rights reserved 6889d0d42SAnil Gurumurthy * www.qlogic.com 77725ccfdSJing Huang * 831e1d569SAnil Gurumurthy * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter. 97725ccfdSJing Huang */ 107725ccfdSJing Huang 11acdc79a6SJing Huang /* 127725ccfdSJing Huang * Contains base driver definitions. 137725ccfdSJing Huang */ 147725ccfdSJing Huang 15acdc79a6SJing Huang /* 167725ccfdSJing Huang * bfa_drv.h Linux driver data structures. 177725ccfdSJing Huang */ 187725ccfdSJing Huang 197725ccfdSJing Huang #ifndef __BFAD_DRV_H__ 207725ccfdSJing Huang #define __BFAD_DRV_H__ 217725ccfdSJing Huang 22f16a1750SMaggie Zhang #include <linux/types.h> 23f16a1750SMaggie Zhang #include <linux/pci.h> 24f16a1750SMaggie Zhang #include <linux/dma-mapping.h> 25f16a1750SMaggie Zhang #include <linux/idr.h> 26f16a1750SMaggie Zhang #include <linux/interrupt.h> 27f16a1750SMaggie Zhang #include <linux/cdev.h> 28f16a1750SMaggie Zhang #include <linux/fs.h> 29f16a1750SMaggie Zhang #include <linux/delay.h> 30f16a1750SMaggie Zhang #include <linux/vmalloc.h> 31f16a1750SMaggie Zhang #include <linux/workqueue.h> 32f16a1750SMaggie Zhang #include <linux/bitops.h> 33881c1b3cSKrishna Gudipati #include <linux/aer.h> 34f16a1750SMaggie Zhang #include <scsi/scsi.h> 35f16a1750SMaggie Zhang #include <scsi/scsi_host.h> 36f16a1750SMaggie Zhang #include <scsi/scsi_tcq.h> 37f16a1750SMaggie Zhang #include <scsi/scsi_transport_fc.h> 38f16a1750SMaggie Zhang #include <scsi/scsi_transport.h> 39b85daafeSKrishna Gudipati #include <scsi/scsi_bsg_fc.h> 405b7db7afSKrishna Gudipati #include <scsi/scsi_devinfo.h> 417725ccfdSJing Huang 42a36c61f9SKrishna Gudipati #include "bfa_modules.h" 43a36c61f9SKrishna Gudipati #include "bfa_fcs.h" 44a36c61f9SKrishna Gudipati #include "bfa_defs_fcs.h" 457725ccfdSJing Huang 46a36c61f9SKrishna Gudipati #include "bfa_plog.h" 47a36c61f9SKrishna Gudipati #include "bfa_cs.h" 487725ccfdSJing Huang 497725ccfdSJing Huang #define BFAD_DRIVER_NAME "bfa" 507725ccfdSJing Huang #ifdef BFA_DRIVER_VERSION 517725ccfdSJing Huang #define BFAD_DRIVER_VERSION BFA_DRIVER_VERSION 527725ccfdSJing Huang #else 532d1148f0SBenjamin Poirier #define BFAD_DRIVER_VERSION "3.2.25.1" 547725ccfdSJing Huang #endif 557725ccfdSJing Huang 56a36c61f9SKrishna Gudipati #define BFAD_PROTO_NAME FCPI_NAME 577725ccfdSJing Huang #define BFAD_IRQ_FLAGS IRQF_SHARED 587725ccfdSJing Huang 59a36c61f9SKrishna Gudipati #ifndef FC_PORTSPEED_8GBIT 60a36c61f9SKrishna Gudipati #define FC_PORTSPEED_8GBIT 0x10 61a36c61f9SKrishna Gudipati #endif 62a36c61f9SKrishna Gudipati 637725ccfdSJing Huang /* 647725ccfdSJing Huang * BFAD flags 657725ccfdSJing Huang */ 667725ccfdSJing Huang #define BFAD_MSIX_ON 0x00000001 677725ccfdSJing Huang #define BFAD_HAL_INIT_DONE 0x00000002 687725ccfdSJing Huang #define BFAD_DRV_INIT_DONE 0x00000004 697725ccfdSJing Huang #define BFAD_CFG_PPORT_DONE 0x00000008 707725ccfdSJing Huang #define BFAD_HAL_START_DONE 0x00000010 717725ccfdSJing Huang #define BFAD_PORT_ONLINE 0x00000020 727725ccfdSJing Huang #define BFAD_RPORT_ONLINE 0x00000040 73e6714324SKrishna Gudipati #define BFAD_FCS_INIT_DONE 0x00000080 74e6714324SKrishna Gudipati #define BFAD_HAL_INIT_FAIL 0x00000100 75e6714324SKrishna Gudipati #define BFAD_FC4_PROBE_DONE 0x00000200 767725ccfdSJing Huang #define BFAD_PORT_DELETE 0x00000001 7761e62e21SKrishna Gudipati #define BFAD_INTX_ON 0x00000400 78881c1b3cSKrishna Gudipati #define BFAD_EEH_BUSY 0x00000800 79881c1b3cSKrishna Gudipati #define BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE 0x00001000 807725ccfdSJing Huang /* 817725ccfdSJing Huang * BFAD related definition 827725ccfdSJing Huang */ 837725ccfdSJing Huang #define SCSI_SCAN_DELAY HZ 847725ccfdSJing Huang #define BFAD_STOP_TIMEOUT 30 857725ccfdSJing Huang #define BFAD_SUSPEND_TIMEOUT BFAD_STOP_TIMEOUT 867725ccfdSJing Huang 877725ccfdSJing Huang /* 887725ccfdSJing Huang * BFAD configuration parameter default values 897725ccfdSJing Huang */ 907725ccfdSJing Huang #define BFAD_LUN_QUEUE_DEPTH 32 917725ccfdSJing Huang #define BFAD_IO_MAX_SGE SG_ALL 9261e62e21SKrishna Gudipati #define BFAD_MIN_SECTORS 128 /* 64k */ 9361e62e21SKrishna Gudipati #define BFAD_MAX_SECTORS 0xFFFF /* 32 MB */ 947725ccfdSJing Huang 957725ccfdSJing Huang #define bfad_isr_t irq_handler_t 967725ccfdSJing Huang 977725ccfdSJing Huang #define MAX_MSIX_ENTRY 22 987725ccfdSJing Huang 997725ccfdSJing Huang struct bfad_msix_s { 1007725ccfdSJing Huang struct bfad_s *bfad; 1017725ccfdSJing Huang struct msix_entry msix; 102a36c61f9SKrishna Gudipati char name[32]; 103a36c61f9SKrishna Gudipati }; 104a36c61f9SKrishna Gudipati 105a36c61f9SKrishna Gudipati /* 106a36c61f9SKrishna Gudipati * Only append to the enums defined here to avoid any versioning 107a36c61f9SKrishna Gudipati * needed between trace utility and driver version 108a36c61f9SKrishna Gudipati */ 109a36c61f9SKrishna Gudipati enum { 110a36c61f9SKrishna Gudipati BFA_TRC_LDRV_BFAD = 1, 111a36c61f9SKrishna Gudipati BFA_TRC_LDRV_IM = 2, 112b85daafeSKrishna Gudipati BFA_TRC_LDRV_BSG = 3, 1137725ccfdSJing Huang }; 1147725ccfdSJing Huang 1157725ccfdSJing Huang enum bfad_port_pvb_type { 1167725ccfdSJing Huang BFAD_PORT_PHYS_BASE = 0, 1177725ccfdSJing Huang BFAD_PORT_PHYS_VPORT = 1, 1187725ccfdSJing Huang BFAD_PORT_VF_BASE = 2, 1197725ccfdSJing Huang BFAD_PORT_VF_VPORT = 3, 1207725ccfdSJing Huang }; 1217725ccfdSJing Huang 1227725ccfdSJing Huang /* 1237725ccfdSJing Huang * PORT data structure 1247725ccfdSJing Huang */ 1257725ccfdSJing Huang struct bfad_port_s { 1267725ccfdSJing Huang struct list_head list_entry; 1277725ccfdSJing Huang struct bfad_s *bfad; 128a36c61f9SKrishna Gudipati struct bfa_fcs_lport_s *fcs_port; 1297725ccfdSJing Huang u32 roles; 1307725ccfdSJing Huang s32 flags; 1317725ccfdSJing Huang u32 supported_fc4s; 1327725ccfdSJing Huang enum bfad_port_pvb_type pvb_type; 1337725ccfdSJing Huang struct bfad_im_port_s *im_port; /* IM specific data */ 134ab2a9ba1SJing Huang /* port debugfs specific data */ 135ab2a9ba1SJing Huang struct dentry *port_debugfs_root; 1367725ccfdSJing Huang }; 1377725ccfdSJing Huang 1387725ccfdSJing Huang /* 1397725ccfdSJing Huang * VPORT data structure 1407725ccfdSJing Huang */ 1417725ccfdSJing Huang struct bfad_vport_s { 1427725ccfdSJing Huang struct bfad_port_s drv_port; 1437725ccfdSJing Huang struct bfa_fcs_vport_s fcs_vport; 1447725ccfdSJing Huang struct completion *comp_del; 145d9883548SJing Huang struct list_head list_entry; 1467725ccfdSJing Huang }; 1477725ccfdSJing Huang 1487725ccfdSJing Huang /* 1497725ccfdSJing Huang * VF data structure 1507725ccfdSJing Huang */ 1517725ccfdSJing Huang struct bfad_vf_s { 1527725ccfdSJing Huang bfa_fcs_vf_t fcs_vf; 1537725ccfdSJing Huang struct bfad_port_s base_port; /* base port for vf */ 1547725ccfdSJing Huang struct bfad_s *bfad; 1557725ccfdSJing Huang }; 1567725ccfdSJing Huang 1577725ccfdSJing Huang struct bfad_cfg_param_s { 1587725ccfdSJing Huang u32 rport_del_timeout; 1597725ccfdSJing Huang u32 ioc_queue_depth; 1607725ccfdSJing Huang u32 lun_queue_depth; 1617725ccfdSJing Huang u32 io_max_sge; 1627725ccfdSJing Huang u32 binding_method; 1637725ccfdSJing Huang }; 1647725ccfdSJing Huang 165a36c61f9SKrishna Gudipati union bfad_tmp_buf { 166a36c61f9SKrishna Gudipati /* From struct bfa_adapter_attr_s */ 167a36c61f9SKrishna Gudipati char manufacturer[BFA_ADAPTER_MFG_NAME_LEN]; 168a36c61f9SKrishna Gudipati char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN]; 169a36c61f9SKrishna Gudipati char model[BFA_ADAPTER_MODEL_NAME_LEN]; 170a36c61f9SKrishna Gudipati char fw_ver[BFA_VERSION_LEN]; 171a36c61f9SKrishna Gudipati char optrom_ver[BFA_VERSION_LEN]; 172a36c61f9SKrishna Gudipati 173a36c61f9SKrishna Gudipati /* From struct bfa_ioc_pci_attr_s */ 174a36c61f9SKrishna Gudipati u8 chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */ 175a36c61f9SKrishna Gudipati 176a36c61f9SKrishna Gudipati wwn_t wwn[BFA_FCS_MAX_LPORTS]; 177a36c61f9SKrishna Gudipati }; 178a36c61f9SKrishna Gudipati 1797725ccfdSJing Huang /* 1807725ccfdSJing Huang * BFAD (PCI function) data structure 1817725ccfdSJing Huang */ 1827725ccfdSJing Huang struct bfad_s { 183a36c61f9SKrishna Gudipati bfa_sm_t sm; /* state machine */ 1847725ccfdSJing Huang struct list_head list_entry; 1857725ccfdSJing Huang struct bfa_s bfa; 1867725ccfdSJing Huang struct bfa_fcs_s bfa_fcs; 1877725ccfdSJing Huang struct pci_dev *pcidev; 1887725ccfdSJing Huang const char *pci_name; 1897725ccfdSJing Huang struct bfa_pcidev_s hal_pcidev; 1907725ccfdSJing Huang struct bfa_ioc_pci_attr_s pci_attr; 1917725ccfdSJing Huang void __iomem *pci_bar0_kva; 19211189208SKrishna Gudipati void __iomem *pci_bar2_kva; 1937725ccfdSJing Huang struct completion comp; 1947725ccfdSJing Huang struct completion suspend; 19560138066SKrishna Gudipati struct completion enable_comp; 1967725ccfdSJing Huang struct completion disable_comp; 1977725ccfdSJing Huang bfa_boolean_t disable_active; 1987725ccfdSJing Huang struct bfad_port_s pport; /* physical port of the BFAD */ 1997725ccfdSJing Huang struct bfa_meminfo_s meminfo; 2007725ccfdSJing Huang struct bfa_iocfc_cfg_s ioc_cfg; 2017725ccfdSJing Huang u32 inst_no; /* BFAD instance number */ 2027725ccfdSJing Huang u32 bfad_flags; 2037725ccfdSJing Huang spinlock_t bfad_lock; 204e6714324SKrishna Gudipati struct task_struct *bfad_tsk; 2057725ccfdSJing Huang struct bfad_cfg_param_s cfg_data; 2067725ccfdSJing Huang struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY]; 2077725ccfdSJing Huang int nvec; 2087725ccfdSJing Huang char adapter_name[BFA_ADAPTER_SYM_NAME_LEN]; 2097725ccfdSJing Huang char port_name[BFA_ADAPTER_SYM_NAME_LEN]; 2107725ccfdSJing Huang struct timer_list hal_tmo; 2117725ccfdSJing Huang unsigned long hs_start; 2127725ccfdSJing Huang struct bfad_im_s *im; /* IM specific data */ 2137725ccfdSJing Huang struct bfa_trc_mod_s *trcmod; 2147725ccfdSJing Huang struct bfa_plog_s plog_buf; 2157725ccfdSJing Huang int ref_count; 216a36c61f9SKrishna Gudipati union bfad_tmp_buf tmp_buf; 2177725ccfdSJing Huang struct fc_host_statistics link_stats; 218a36c61f9SKrishna Gudipati struct list_head pbc_vport_list; 219ab2a9ba1SJing Huang /* debugfs specific data */ 220ab2a9ba1SJing Huang char *regdata; 221ab2a9ba1SJing Huang u32 reglen; 222ab2a9ba1SJing Huang struct dentry *bfad_dentry_files[5]; 2237826f304SKrishna Gudipati struct list_head free_aen_q; 2247826f304SKrishna Gudipati struct list_head active_aen_q; 2257826f304SKrishna Gudipati struct bfa_aen_entry_s aen_list[BFA_AEN_MAX_ENTRY]; 2267826f304SKrishna Gudipati spinlock_t bfad_aen_spinlock; 2275b7db7afSKrishna Gudipati struct list_head vport_list; 228d9883548SJing Huang }; 229d9883548SJing Huang 230a36c61f9SKrishna Gudipati /* BFAD state machine events */ 231a36c61f9SKrishna Gudipati enum bfad_sm_event { 232a36c61f9SKrishna Gudipati BFAD_E_CREATE = 1, 233a36c61f9SKrishna Gudipati BFAD_E_KTHREAD_CREATE_FAILED = 2, 234a36c61f9SKrishna Gudipati BFAD_E_INIT = 3, 235a36c61f9SKrishna Gudipati BFAD_E_INIT_SUCCESS = 4, 236da3e0beeSVijaya Mohan Guvva BFAD_E_HAL_INIT_FAILED = 5, 237da3e0beeSVijaya Mohan Guvva BFAD_E_INIT_FAILED = 6, 238a36c61f9SKrishna Gudipati BFAD_E_FCS_EXIT_COMP = 7, 239a36c61f9SKrishna Gudipati BFAD_E_EXIT_COMP = 8, 240a36c61f9SKrishna Gudipati BFAD_E_STOP = 9 2417725ccfdSJing Huang }; 2427725ccfdSJing Huang 2437725ccfdSJing Huang /* 2447725ccfdSJing Huang * RPORT data structure 2457725ccfdSJing Huang */ 2467725ccfdSJing Huang struct bfad_rport_s { 2477725ccfdSJing Huang struct bfa_fcs_rport_s fcs_rport; 2487725ccfdSJing Huang }; 2497725ccfdSJing Huang 2507725ccfdSJing Huang struct bfad_buf_info { 2517725ccfdSJing Huang void *virt; 2527725ccfdSJing Huang dma_addr_t phys; 2537725ccfdSJing Huang u32 size; 2547725ccfdSJing Huang }; 2557725ccfdSJing Huang 2567725ccfdSJing Huang struct bfad_fcxp { 2577725ccfdSJing Huang struct bfad_port_s *port; 2587725ccfdSJing Huang struct bfa_rport_s *bfa_rport; 2597725ccfdSJing Huang bfa_status_t req_status; 2607725ccfdSJing Huang u16 tag; 2617725ccfdSJing Huang u16 rsp_len; 2627725ccfdSJing Huang u16 rsp_maxlen; 2637725ccfdSJing Huang u8 use_ireqbuf; 2647725ccfdSJing Huang u8 use_irspbuf; 2657725ccfdSJing Huang u32 num_req_sgles; 2667725ccfdSJing Huang u32 num_rsp_sgles; 2677725ccfdSJing Huang struct fchs_s fchs; 2687725ccfdSJing Huang void *reqbuf_info; 2697725ccfdSJing Huang void *rspbuf_info; 2707725ccfdSJing Huang struct bfa_sge_s *req_sge; 2717725ccfdSJing Huang struct bfa_sge_s *rsp_sge; 2727725ccfdSJing Huang fcxp_send_cb_t send_cbfn; 2737725ccfdSJing Huang void *send_cbarg; 2747725ccfdSJing Huang void *bfa_fcxp; 2757725ccfdSJing Huang struct completion comp; 2767725ccfdSJing Huang }; 2777725ccfdSJing Huang 2787725ccfdSJing Huang struct bfad_hal_comp { 2797725ccfdSJing Huang bfa_status_t status; 2807725ccfdSJing Huang struct completion comp; 2817725ccfdSJing Huang }; 2827725ccfdSJing Huang 283f16a1750SMaggie Zhang #define BFA_LOG(level, bfad, mask, fmt, arg...) \ 284a36c61f9SKrishna Gudipati do { \ 285f16a1750SMaggie Zhang if (((mask) == 4) || (level[1] <= '4')) \ 286f16a1750SMaggie Zhang dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \ 287a36c61f9SKrishna Gudipati } while (0) 288a36c61f9SKrishna Gudipati 2897725ccfdSJing Huang bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id, 290a36c61f9SKrishna Gudipati struct bfa_lport_cfg_s *port_cfg, 291a36c61f9SKrishna Gudipati struct device *dev); 2927725ccfdSJing Huang bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id, 293a36c61f9SKrishna Gudipati struct bfa_lport_cfg_s *port_cfg); 294a36c61f9SKrishna Gudipati bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role); 2957725ccfdSJing Huang bfa_status_t bfad_drv_init(struct bfad_s *bfad); 296e6714324SKrishna Gudipati bfa_status_t bfad_start_ops(struct bfad_s *bfad); 2977725ccfdSJing Huang void bfad_drv_start(struct bfad_s *bfad); 2987725ccfdSJing Huang void bfad_uncfg_pport(struct bfad_s *bfad); 299a36c61f9SKrishna Gudipati void bfad_stop(struct bfad_s *bfad); 300a36c61f9SKrishna Gudipati void bfad_fcs_stop(struct bfad_s *bfad); 3017725ccfdSJing Huang void bfad_remove_intr(struct bfad_s *bfad); 3027725ccfdSJing Huang void bfad_hal_mem_release(struct bfad_s *bfad); 3037725ccfdSJing Huang void bfad_hcb_comp(void *arg, bfa_status_t status); 3047725ccfdSJing Huang 3057725ccfdSJing Huang int bfad_setup_intr(struct bfad_s *bfad); 3067725ccfdSJing Huang void bfad_remove_intr(struct bfad_s *bfad); 3077725ccfdSJing Huang void bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg); 3087725ccfdSJing Huang bfa_status_t bfad_hal_mem_alloc(struct bfad_s *bfad); 309e99e88a9SKees Cook void bfad_bfa_tmo(struct timer_list *t); 3107725ccfdSJing Huang void bfad_init_timer(struct bfad_s *bfad); 3117725ccfdSJing Huang int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad); 3127725ccfdSJing Huang void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad); 3137725ccfdSJing Huang void bfad_drv_uninit(struct bfad_s *bfad); 314e6714324SKrishna Gudipati int bfad_worker(void *ptr); 315ab2a9ba1SJing Huang void bfad_debugfs_init(struct bfad_port_s *port); 316ab2a9ba1SJing Huang void bfad_debugfs_exit(struct bfad_port_s *port); 317e6714324SKrishna Gudipati 3187725ccfdSJing Huang void bfad_pci_remove(struct pci_dev *pdev); 3197725ccfdSJing Huang int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid); 320f16a1750SMaggie Zhang void bfad_rport_online_wait(struct bfad_s *bfad); 321f16a1750SMaggie Zhang int bfad_get_linkup_delay(struct bfad_s *bfad); 3227725ccfdSJing Huang int bfad_install_msix_handler(struct bfad_s *bfad); 3237725ccfdSJing Huang 3247725ccfdSJing Huang extern struct idr bfad_im_port_index; 325a36c61f9SKrishna Gudipati extern struct pci_device_id bfad_id_table[]; 3267725ccfdSJing Huang extern struct list_head bfad_list; 327a36c61f9SKrishna Gudipati extern char *os_name; 328a36c61f9SKrishna Gudipati extern char *os_patch; 329a36c61f9SKrishna Gudipati extern char *host_name; 330a36c61f9SKrishna Gudipati extern int num_rports; 331a36c61f9SKrishna Gudipati extern int num_ios; 332a36c61f9SKrishna Gudipati extern int num_tms; 333a36c61f9SKrishna Gudipati extern int num_fcxps; 334a36c61f9SKrishna Gudipati extern int num_ufbufs; 335a36c61f9SKrishna Gudipati extern int reqq_size; 336a36c61f9SKrishna Gudipati extern int rspq_size; 337a36c61f9SKrishna Gudipati extern int num_sgpgs; 338a36c61f9SKrishna Gudipati extern int rport_del_timeout; 3397725ccfdSJing Huang extern int bfa_lun_queue_depth; 340a36c61f9SKrishna Gudipati extern int bfa_io_max_sge; 34188166242SJing Huang extern int bfa_log_level; 342a36c61f9SKrishna Gudipati extern int ioc_auto_recover; 3437725ccfdSJing Huang extern int bfa_linkup_delay; 344a36c61f9SKrishna Gudipati extern int msix_disable_cb; 345a36c61f9SKrishna Gudipati extern int msix_disable_ct; 346a36c61f9SKrishna Gudipati extern int fdmi_enable; 347a36c61f9SKrishna Gudipati extern int supported_fc4s; 348a36c61f9SKrishna Gudipati extern int pcie_max_read_reqsz; 34961e62e21SKrishna Gudipati extern int max_xfer_size; 350ab2a9ba1SJing Huang extern int bfa_debugfs_enable; 35142b426ecSJing Huang extern struct mutex bfad_mutex; 3527725ccfdSJing Huang 3537725ccfdSJing Huang #endif /* __BFAD_DRV_H__ */ 354