152fa7bf9SThomas 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> 33f16a1750SMaggie Zhang #include <scsi/scsi.h> 34f16a1750SMaggie Zhang #include <scsi/scsi_host.h> 35f16a1750SMaggie Zhang #include <scsi/scsi_tcq.h> 36f16a1750SMaggie Zhang #include <scsi/scsi_transport_fc.h> 37f16a1750SMaggie Zhang #include <scsi/scsi_transport.h> 38b85daafeSKrishna Gudipati #include <scsi/scsi_bsg_fc.h> 395b7db7afSKrishna Gudipati #include <scsi/scsi_devinfo.h> 407725ccfdSJing Huang 41a36c61f9SKrishna Gudipati #include "bfa_modules.h" 42a36c61f9SKrishna Gudipati #include "bfa_fcs.h" 43a36c61f9SKrishna Gudipati #include "bfa_defs_fcs.h" 447725ccfdSJing Huang 45a36c61f9SKrishna Gudipati #include "bfa_plog.h" 46a36c61f9SKrishna Gudipati #include "bfa_cs.h" 477725ccfdSJing Huang 487725ccfdSJing Huang #define BFAD_DRIVER_NAME "bfa" 497725ccfdSJing Huang #ifdef BFA_DRIVER_VERSION 507725ccfdSJing Huang #define BFAD_DRIVER_VERSION BFA_DRIVER_VERSION 517725ccfdSJing Huang #else 522d1148f0SBenjamin Poirier #define BFAD_DRIVER_VERSION "3.2.25.1" 537725ccfdSJing Huang #endif 547725ccfdSJing Huang 55a36c61f9SKrishna Gudipati #define BFAD_PROTO_NAME FCPI_NAME 567725ccfdSJing Huang #define BFAD_IRQ_FLAGS IRQF_SHARED 577725ccfdSJing Huang 58a36c61f9SKrishna Gudipati #ifndef FC_PORTSPEED_8GBIT 59a36c61f9SKrishna Gudipati #define FC_PORTSPEED_8GBIT 0x10 60a36c61f9SKrishna Gudipati #endif 61a36c61f9SKrishna Gudipati 627725ccfdSJing Huang /* 637725ccfdSJing Huang * BFAD flags 647725ccfdSJing Huang */ 657725ccfdSJing Huang #define BFAD_MSIX_ON 0x00000001 667725ccfdSJing Huang #define BFAD_HAL_INIT_DONE 0x00000002 677725ccfdSJing Huang #define BFAD_DRV_INIT_DONE 0x00000004 687725ccfdSJing Huang #define BFAD_CFG_PPORT_DONE 0x00000008 697725ccfdSJing Huang #define BFAD_HAL_START_DONE 0x00000010 707725ccfdSJing Huang #define BFAD_PORT_ONLINE 0x00000020 717725ccfdSJing Huang #define BFAD_RPORT_ONLINE 0x00000040 72e6714324SKrishna Gudipati #define BFAD_FCS_INIT_DONE 0x00000080 73e6714324SKrishna Gudipati #define BFAD_HAL_INIT_FAIL 0x00000100 74e6714324SKrishna Gudipati #define BFAD_FC4_PROBE_DONE 0x00000200 757725ccfdSJing Huang #define BFAD_PORT_DELETE 0x00000001 7661e62e21SKrishna Gudipati #define BFAD_INTX_ON 0x00000400 77881c1b3cSKrishna Gudipati #define BFAD_EEH_BUSY 0x00000800 78881c1b3cSKrishna Gudipati #define BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE 0x00001000 797725ccfdSJing Huang /* 807725ccfdSJing Huang * BFAD related definition 817725ccfdSJing Huang */ 827725ccfdSJing Huang #define SCSI_SCAN_DELAY HZ 837725ccfdSJing Huang #define BFAD_STOP_TIMEOUT 30 847725ccfdSJing Huang #define BFAD_SUSPEND_TIMEOUT BFAD_STOP_TIMEOUT 857725ccfdSJing Huang 867725ccfdSJing Huang /* 877725ccfdSJing Huang * BFAD configuration parameter default values 887725ccfdSJing Huang */ 897725ccfdSJing Huang #define BFAD_LUN_QUEUE_DEPTH 32 907725ccfdSJing Huang #define BFAD_IO_MAX_SGE SG_ALL 9161e62e21SKrishna Gudipati #define BFAD_MIN_SECTORS 128 /* 64k */ 9261e62e21SKrishna Gudipati #define BFAD_MAX_SECTORS 0xFFFF /* 32 MB */ 937725ccfdSJing Huang 947725ccfdSJing Huang #define bfad_isr_t irq_handler_t 957725ccfdSJing Huang 967725ccfdSJing Huang #define MAX_MSIX_ENTRY 22 977725ccfdSJing Huang 987725ccfdSJing Huang struct bfad_msix_s { 997725ccfdSJing Huang struct bfad_s *bfad; 1007725ccfdSJing Huang struct msix_entry msix; 101a36c61f9SKrishna Gudipati char name[32]; 102a36c61f9SKrishna Gudipati }; 103a36c61f9SKrishna Gudipati 104a36c61f9SKrishna Gudipati /* 105a36c61f9SKrishna Gudipati * Only append to the enums defined here to avoid any versioning 106a36c61f9SKrishna Gudipati * needed between trace utility and driver version 107a36c61f9SKrishna Gudipati */ 108a36c61f9SKrishna Gudipati enum { 109a36c61f9SKrishna Gudipati BFA_TRC_LDRV_BFAD = 1, 110a36c61f9SKrishna Gudipati BFA_TRC_LDRV_IM = 2, 111b85daafeSKrishna Gudipati BFA_TRC_LDRV_BSG = 3, 1127725ccfdSJing Huang }; 1137725ccfdSJing Huang 1147725ccfdSJing Huang enum bfad_port_pvb_type { 1157725ccfdSJing Huang BFAD_PORT_PHYS_BASE = 0, 1167725ccfdSJing Huang BFAD_PORT_PHYS_VPORT = 1, 1177725ccfdSJing Huang BFAD_PORT_VF_BASE = 2, 1187725ccfdSJing Huang BFAD_PORT_VF_VPORT = 3, 1197725ccfdSJing Huang }; 1207725ccfdSJing Huang 1217725ccfdSJing Huang /* 1227725ccfdSJing Huang * PORT data structure 1237725ccfdSJing Huang */ 1247725ccfdSJing Huang struct bfad_port_s { 1257725ccfdSJing Huang struct list_head list_entry; 1267725ccfdSJing Huang struct bfad_s *bfad; 127a36c61f9SKrishna Gudipati struct bfa_fcs_lport_s *fcs_port; 1287725ccfdSJing Huang u32 roles; 1297725ccfdSJing Huang s32 flags; 1307725ccfdSJing Huang u32 supported_fc4s; 1317725ccfdSJing Huang enum bfad_port_pvb_type pvb_type; 1327725ccfdSJing Huang struct bfad_im_port_s *im_port; /* IM specific data */ 133ab2a9ba1SJing Huang /* port debugfs specific data */ 134ab2a9ba1SJing Huang struct dentry *port_debugfs_root; 1357725ccfdSJing Huang }; 1367725ccfdSJing Huang 1377725ccfdSJing Huang /* 1387725ccfdSJing Huang * VPORT data structure 1397725ccfdSJing Huang */ 1407725ccfdSJing Huang struct bfad_vport_s { 1417725ccfdSJing Huang struct bfad_port_s drv_port; 1427725ccfdSJing Huang struct bfa_fcs_vport_s fcs_vport; 1437725ccfdSJing Huang struct completion *comp_del; 144d9883548SJing Huang struct list_head list_entry; 1457725ccfdSJing Huang }; 1467725ccfdSJing Huang 1477725ccfdSJing Huang /* 1487725ccfdSJing Huang * VF data structure 1497725ccfdSJing Huang */ 1507725ccfdSJing Huang struct bfad_vf_s { 1517725ccfdSJing Huang bfa_fcs_vf_t fcs_vf; 1527725ccfdSJing Huang struct bfad_port_s base_port; /* base port for vf */ 1537725ccfdSJing Huang struct bfad_s *bfad; 1547725ccfdSJing Huang }; 1557725ccfdSJing Huang 1567725ccfdSJing Huang struct bfad_cfg_param_s { 1577725ccfdSJing Huang u32 rport_del_timeout; 1587725ccfdSJing Huang u32 ioc_queue_depth; 1597725ccfdSJing Huang u32 lun_queue_depth; 1607725ccfdSJing Huang u32 io_max_sge; 1617725ccfdSJing Huang u32 binding_method; 1627725ccfdSJing Huang }; 1637725ccfdSJing Huang 164a36c61f9SKrishna Gudipati union bfad_tmp_buf { 165a36c61f9SKrishna Gudipati /* From struct bfa_adapter_attr_s */ 166a36c61f9SKrishna Gudipati char manufacturer[BFA_ADAPTER_MFG_NAME_LEN]; 167a36c61f9SKrishna Gudipati char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN]; 168a36c61f9SKrishna Gudipati char model[BFA_ADAPTER_MODEL_NAME_LEN]; 169a36c61f9SKrishna Gudipati char fw_ver[BFA_VERSION_LEN]; 170a36c61f9SKrishna Gudipati char optrom_ver[BFA_VERSION_LEN]; 171a36c61f9SKrishna Gudipati 172a36c61f9SKrishna Gudipati /* From struct bfa_ioc_pci_attr_s */ 173a36c61f9SKrishna Gudipati u8 chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */ 174a36c61f9SKrishna Gudipati 175a36c61f9SKrishna Gudipati wwn_t wwn[BFA_FCS_MAX_LPORTS]; 176a36c61f9SKrishna Gudipati }; 177a36c61f9SKrishna Gudipati 178*37126399SArnd Bergmann /* BFAD state machine events */ 179*37126399SArnd Bergmann enum bfad_sm_event { 180*37126399SArnd Bergmann BFAD_E_CREATE = 1, 181*37126399SArnd Bergmann BFAD_E_KTHREAD_CREATE_FAILED = 2, 182*37126399SArnd Bergmann BFAD_E_INIT = 3, 183*37126399SArnd Bergmann BFAD_E_INIT_SUCCESS = 4, 184*37126399SArnd Bergmann BFAD_E_HAL_INIT_FAILED = 5, 185*37126399SArnd Bergmann BFAD_E_INIT_FAILED = 6, 186*37126399SArnd Bergmann BFAD_E_FCS_EXIT_COMP = 7, 187*37126399SArnd Bergmann BFAD_E_EXIT_COMP = 8, 188*37126399SArnd Bergmann BFAD_E_STOP = 9 189*37126399SArnd Bergmann }; 190*37126399SArnd Bergmann 191*37126399SArnd Bergmann struct bfad_s; 192*37126399SArnd Bergmann typedef void (*bfad_sm_t)(struct bfad_s *, enum bfad_sm_event); 193*37126399SArnd Bergmann 1947725ccfdSJing Huang /* 1957725ccfdSJing Huang * BFAD (PCI function) data structure 1967725ccfdSJing Huang */ 1977725ccfdSJing Huang struct bfad_s { 198*37126399SArnd Bergmann bfad_sm_t sm; /* state machine */ 1997725ccfdSJing Huang struct list_head list_entry; 2007725ccfdSJing Huang struct bfa_s bfa; 2017725ccfdSJing Huang struct bfa_fcs_s bfa_fcs; 2027725ccfdSJing Huang struct pci_dev *pcidev; 2037725ccfdSJing Huang const char *pci_name; 2047725ccfdSJing Huang struct bfa_pcidev_s hal_pcidev; 2057725ccfdSJing Huang struct bfa_ioc_pci_attr_s pci_attr; 2067725ccfdSJing Huang void __iomem *pci_bar0_kva; 20711189208SKrishna Gudipati void __iomem *pci_bar2_kva; 2087725ccfdSJing Huang struct completion comp; 2097725ccfdSJing Huang struct completion suspend; 21060138066SKrishna Gudipati struct completion enable_comp; 2117725ccfdSJing Huang struct completion disable_comp; 2127725ccfdSJing Huang bfa_boolean_t disable_active; 2137725ccfdSJing Huang struct bfad_port_s pport; /* physical port of the BFAD */ 2147725ccfdSJing Huang struct bfa_meminfo_s meminfo; 2157725ccfdSJing Huang struct bfa_iocfc_cfg_s ioc_cfg; 2167725ccfdSJing Huang u32 inst_no; /* BFAD instance number */ 2177725ccfdSJing Huang u32 bfad_flags; 2187725ccfdSJing Huang spinlock_t bfad_lock; 219e6714324SKrishna Gudipati struct task_struct *bfad_tsk; 2207725ccfdSJing Huang struct bfad_cfg_param_s cfg_data; 2217725ccfdSJing Huang struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY]; 2227725ccfdSJing Huang int nvec; 2237725ccfdSJing Huang char adapter_name[BFA_ADAPTER_SYM_NAME_LEN]; 2247725ccfdSJing Huang char port_name[BFA_ADAPTER_SYM_NAME_LEN]; 2257725ccfdSJing Huang struct timer_list hal_tmo; 2267725ccfdSJing Huang unsigned long hs_start; 2277725ccfdSJing Huang struct bfad_im_s *im; /* IM specific data */ 2287725ccfdSJing Huang struct bfa_trc_mod_s *trcmod; 2297725ccfdSJing Huang struct bfa_plog_s plog_buf; 2307725ccfdSJing Huang int ref_count; 231a36c61f9SKrishna Gudipati union bfad_tmp_buf tmp_buf; 2327725ccfdSJing Huang struct fc_host_statistics link_stats; 233a36c61f9SKrishna Gudipati struct list_head pbc_vport_list; 234ab2a9ba1SJing Huang /* debugfs specific data */ 235ab2a9ba1SJing Huang char *regdata; 236ab2a9ba1SJing Huang u32 reglen; 237ab2a9ba1SJing Huang struct dentry *bfad_dentry_files[5]; 2387826f304SKrishna Gudipati struct list_head free_aen_q; 2397826f304SKrishna Gudipati struct list_head active_aen_q; 2407826f304SKrishna Gudipati struct bfa_aen_entry_s aen_list[BFA_AEN_MAX_ENTRY]; 2417826f304SKrishna Gudipati spinlock_t bfad_aen_spinlock; 2425b7db7afSKrishna Gudipati struct list_head vport_list; 243d9883548SJing Huang }; 244d9883548SJing Huang 2457725ccfdSJing Huang /* 2467725ccfdSJing Huang * RPORT data structure 2477725ccfdSJing Huang */ 2487725ccfdSJing Huang struct bfad_rport_s { 2497725ccfdSJing Huang struct bfa_fcs_rport_s fcs_rport; 2507725ccfdSJing Huang }; 2517725ccfdSJing Huang 2527725ccfdSJing Huang struct bfad_buf_info { 2537725ccfdSJing Huang void *virt; 2547725ccfdSJing Huang dma_addr_t phys; 2557725ccfdSJing Huang u32 size; 2567725ccfdSJing Huang }; 2577725ccfdSJing Huang 2587725ccfdSJing Huang struct bfad_fcxp { 2597725ccfdSJing Huang struct bfad_port_s *port; 2607725ccfdSJing Huang struct bfa_rport_s *bfa_rport; 2617725ccfdSJing Huang bfa_status_t req_status; 2627725ccfdSJing Huang u16 tag; 2637725ccfdSJing Huang u16 rsp_len; 2647725ccfdSJing Huang u16 rsp_maxlen; 2657725ccfdSJing Huang u8 use_ireqbuf; 2667725ccfdSJing Huang u8 use_irspbuf; 2677725ccfdSJing Huang u32 num_req_sgles; 2687725ccfdSJing Huang u32 num_rsp_sgles; 2697725ccfdSJing Huang struct fchs_s fchs; 2707725ccfdSJing Huang void *reqbuf_info; 2717725ccfdSJing Huang void *rspbuf_info; 2727725ccfdSJing Huang struct bfa_sge_s *req_sge; 2737725ccfdSJing Huang struct bfa_sge_s *rsp_sge; 2747725ccfdSJing Huang fcxp_send_cb_t send_cbfn; 2757725ccfdSJing Huang void *send_cbarg; 2767725ccfdSJing Huang void *bfa_fcxp; 2777725ccfdSJing Huang struct completion comp; 2787725ccfdSJing Huang }; 2797725ccfdSJing Huang 2807725ccfdSJing Huang struct bfad_hal_comp { 2817725ccfdSJing Huang bfa_status_t status; 2827725ccfdSJing Huang struct completion comp; 2837725ccfdSJing Huang }; 2847725ccfdSJing Huang 285f16a1750SMaggie Zhang #define BFA_LOG(level, bfad, mask, fmt, arg...) \ 286a36c61f9SKrishna Gudipati do { \ 287f16a1750SMaggie Zhang if (((mask) == 4) || (level[1] <= '4')) \ 288f16a1750SMaggie Zhang dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \ 289a36c61f9SKrishna Gudipati } while (0) 290a36c61f9SKrishna Gudipati 2917725ccfdSJing Huang bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id, 292a36c61f9SKrishna Gudipati struct bfa_lport_cfg_s *port_cfg, 293a36c61f9SKrishna Gudipati struct device *dev); 2947725ccfdSJing Huang bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id, 295a36c61f9SKrishna Gudipati struct bfa_lport_cfg_s *port_cfg); 296a36c61f9SKrishna Gudipati bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role); 2977725ccfdSJing Huang bfa_status_t bfad_drv_init(struct bfad_s *bfad); 298e6714324SKrishna Gudipati bfa_status_t bfad_start_ops(struct bfad_s *bfad); 2997725ccfdSJing Huang void bfad_drv_start(struct bfad_s *bfad); 3007725ccfdSJing Huang void bfad_uncfg_pport(struct bfad_s *bfad); 301a36c61f9SKrishna Gudipati void bfad_stop(struct bfad_s *bfad); 302a36c61f9SKrishna Gudipati void bfad_fcs_stop(struct bfad_s *bfad); 3037725ccfdSJing Huang void bfad_remove_intr(struct bfad_s *bfad); 3047725ccfdSJing Huang void bfad_hal_mem_release(struct bfad_s *bfad); 3057725ccfdSJing Huang void bfad_hcb_comp(void *arg, bfa_status_t status); 3067725ccfdSJing Huang 3077725ccfdSJing Huang int bfad_setup_intr(struct bfad_s *bfad); 3087725ccfdSJing Huang void bfad_remove_intr(struct bfad_s *bfad); 3097725ccfdSJing Huang void bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg); 3107725ccfdSJing Huang bfa_status_t bfad_hal_mem_alloc(struct bfad_s *bfad); 311e99e88a9SKees Cook void bfad_bfa_tmo(struct timer_list *t); 3127725ccfdSJing Huang void bfad_init_timer(struct bfad_s *bfad); 3137725ccfdSJing Huang int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad); 3147725ccfdSJing Huang void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad); 3157725ccfdSJing Huang void bfad_drv_uninit(struct bfad_s *bfad); 316e6714324SKrishna Gudipati int bfad_worker(void *ptr); 317ab2a9ba1SJing Huang void bfad_debugfs_init(struct bfad_port_s *port); 318ab2a9ba1SJing Huang void bfad_debugfs_exit(struct bfad_port_s *port); 319e6714324SKrishna Gudipati 3207725ccfdSJing Huang void bfad_pci_remove(struct pci_dev *pdev); 3217725ccfdSJing Huang int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid); 322f16a1750SMaggie Zhang void bfad_rport_online_wait(struct bfad_s *bfad); 323f16a1750SMaggie Zhang int bfad_get_linkup_delay(struct bfad_s *bfad); 3247725ccfdSJing Huang int bfad_install_msix_handler(struct bfad_s *bfad); 3257725ccfdSJing Huang 3267725ccfdSJing Huang extern struct idr bfad_im_port_index; 327a36c61f9SKrishna Gudipati extern struct pci_device_id bfad_id_table[]; 3287725ccfdSJing Huang extern struct list_head bfad_list; 329a36c61f9SKrishna Gudipati extern char *os_name; 330a36c61f9SKrishna Gudipati extern char *os_patch; 331a36c61f9SKrishna Gudipati extern char *host_name; 332a36c61f9SKrishna Gudipati extern int num_rports; 333a36c61f9SKrishna Gudipati extern int num_ios; 334a36c61f9SKrishna Gudipati extern int num_tms; 335a36c61f9SKrishna Gudipati extern int num_fcxps; 336a36c61f9SKrishna Gudipati extern int num_ufbufs; 337a36c61f9SKrishna Gudipati extern int reqq_size; 338a36c61f9SKrishna Gudipati extern int rspq_size; 339a36c61f9SKrishna Gudipati extern int num_sgpgs; 340a36c61f9SKrishna Gudipati extern int rport_del_timeout; 3417725ccfdSJing Huang extern int bfa_lun_queue_depth; 342a36c61f9SKrishna Gudipati extern int bfa_io_max_sge; 34388166242SJing Huang extern int bfa_log_level; 344a36c61f9SKrishna Gudipati extern int ioc_auto_recover; 3457725ccfdSJing Huang extern int bfa_linkup_delay; 346a36c61f9SKrishna Gudipati extern int msix_disable_cb; 347a36c61f9SKrishna Gudipati extern int msix_disable_ct; 348a36c61f9SKrishna Gudipati extern int fdmi_enable; 349a36c61f9SKrishna Gudipati extern int supported_fc4s; 350a36c61f9SKrishna Gudipati extern int pcie_max_read_reqsz; 35161e62e21SKrishna Gudipati extern int max_xfer_size; 352ab2a9ba1SJing Huang extern int bfa_debugfs_enable; 35342b426ecSJing Huang extern struct mutex bfad_mutex; 3547725ccfdSJing Huang 3557725ccfdSJing Huang #endif /* __BFAD_DRV_H__ */ 356