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 29f16a1750SMaggie Zhang #include <linux/types.h> 30f16a1750SMaggie Zhang #include <linux/version.h> 31f16a1750SMaggie Zhang #include <linux/pci.h> 32f16a1750SMaggie Zhang #include <linux/dma-mapping.h> 33f16a1750SMaggie Zhang #include <linux/idr.h> 34f16a1750SMaggie Zhang #include <linux/interrupt.h> 35f16a1750SMaggie Zhang #include <linux/cdev.h> 36f16a1750SMaggie Zhang #include <linux/fs.h> 37f16a1750SMaggie Zhang #include <linux/delay.h> 38f16a1750SMaggie Zhang #include <linux/vmalloc.h> 39f16a1750SMaggie Zhang #include <linux/workqueue.h> 40f16a1750SMaggie Zhang #include <linux/bitops.h> 41f16a1750SMaggie Zhang #include <scsi/scsi.h> 42f16a1750SMaggie Zhang #include <scsi/scsi_host.h> 43f16a1750SMaggie Zhang #include <scsi/scsi_tcq.h> 44f16a1750SMaggie Zhang #include <scsi/scsi_transport_fc.h> 45f16a1750SMaggie Zhang #include <scsi/scsi_transport.h> 46b85daafeSKrishna Gudipati #include <scsi/scsi_bsg_fc.h> 477725ccfdSJing Huang 48a36c61f9SKrishna Gudipati #include "bfa_modules.h" 49a36c61f9SKrishna Gudipati #include "bfa_fcs.h" 50a36c61f9SKrishna Gudipati #include "bfa_defs_fcs.h" 517725ccfdSJing Huang 52a36c61f9SKrishna Gudipati #include "bfa_plog.h" 53a36c61f9SKrishna Gudipati #include "bfa_cs.h" 547725ccfdSJing Huang 557725ccfdSJing Huang #define BFAD_DRIVER_NAME "bfa" 567725ccfdSJing Huang #ifdef BFA_DRIVER_VERSION 577725ccfdSJing Huang #define BFAD_DRIVER_VERSION BFA_DRIVER_VERSION 587725ccfdSJing Huang #else 597bb66fc0SKrishna Gudipati #define BFAD_DRIVER_VERSION "3.0.2.0" 607725ccfdSJing Huang #endif 617725ccfdSJing Huang 62a36c61f9SKrishna Gudipati #define BFAD_PROTO_NAME FCPI_NAME 637725ccfdSJing Huang #define BFAD_IRQ_FLAGS IRQF_SHARED 647725ccfdSJing Huang 65a36c61f9SKrishna Gudipati #ifndef FC_PORTSPEED_8GBIT 66a36c61f9SKrishna Gudipati #define FC_PORTSPEED_8GBIT 0x10 67a36c61f9SKrishna Gudipati #endif 68a36c61f9SKrishna Gudipati 697725ccfdSJing Huang /* 707725ccfdSJing Huang * BFAD flags 717725ccfdSJing Huang */ 727725ccfdSJing Huang #define BFAD_MSIX_ON 0x00000001 737725ccfdSJing Huang #define BFAD_HAL_INIT_DONE 0x00000002 747725ccfdSJing Huang #define BFAD_DRV_INIT_DONE 0x00000004 757725ccfdSJing Huang #define BFAD_CFG_PPORT_DONE 0x00000008 767725ccfdSJing Huang #define BFAD_HAL_START_DONE 0x00000010 777725ccfdSJing Huang #define BFAD_PORT_ONLINE 0x00000020 787725ccfdSJing Huang #define BFAD_RPORT_ONLINE 0x00000040 79e6714324SKrishna Gudipati #define BFAD_FCS_INIT_DONE 0x00000080 80e6714324SKrishna Gudipati #define BFAD_HAL_INIT_FAIL 0x00000100 81e6714324SKrishna Gudipati #define BFAD_FC4_PROBE_DONE 0x00000200 827725ccfdSJing Huang #define BFAD_PORT_DELETE 0x00000001 837725ccfdSJing Huang 847725ccfdSJing Huang /* 857725ccfdSJing Huang * BFAD related definition 867725ccfdSJing Huang */ 877725ccfdSJing Huang #define SCSI_SCAN_DELAY HZ 887725ccfdSJing Huang #define BFAD_STOP_TIMEOUT 30 897725ccfdSJing Huang #define BFAD_SUSPEND_TIMEOUT BFAD_STOP_TIMEOUT 907725ccfdSJing Huang 917725ccfdSJing Huang /* 927725ccfdSJing Huang * BFAD configuration parameter default values 937725ccfdSJing Huang */ 947725ccfdSJing Huang #define BFAD_LUN_QUEUE_DEPTH 32 957725ccfdSJing Huang #define BFAD_IO_MAX_SGE SG_ALL 967725ccfdSJing Huang 977725ccfdSJing Huang #define bfad_isr_t irq_handler_t 987725ccfdSJing Huang 997725ccfdSJing Huang #define MAX_MSIX_ENTRY 22 1007725ccfdSJing Huang 1017725ccfdSJing Huang struct bfad_msix_s { 1027725ccfdSJing Huang struct bfad_s *bfad; 1037725ccfdSJing Huang struct msix_entry msix; 104a36c61f9SKrishna Gudipati char name[32]; 105a36c61f9SKrishna Gudipati }; 106a36c61f9SKrishna Gudipati 107a36c61f9SKrishna Gudipati /* 108a36c61f9SKrishna Gudipati * Only append to the enums defined here to avoid any versioning 109a36c61f9SKrishna Gudipati * needed between trace utility and driver version 110a36c61f9SKrishna Gudipati */ 111a36c61f9SKrishna Gudipati enum { 112a36c61f9SKrishna Gudipati BFA_TRC_LDRV_BFAD = 1, 113a36c61f9SKrishna Gudipati BFA_TRC_LDRV_IM = 2, 114b85daafeSKrishna Gudipati BFA_TRC_LDRV_BSG = 3, 1157725ccfdSJing Huang }; 1167725ccfdSJing Huang 1177725ccfdSJing Huang enum bfad_port_pvb_type { 1187725ccfdSJing Huang BFAD_PORT_PHYS_BASE = 0, 1197725ccfdSJing Huang BFAD_PORT_PHYS_VPORT = 1, 1207725ccfdSJing Huang BFAD_PORT_VF_BASE = 2, 1217725ccfdSJing Huang BFAD_PORT_VF_VPORT = 3, 1227725ccfdSJing Huang }; 1237725ccfdSJing Huang 1247725ccfdSJing Huang /* 1257725ccfdSJing Huang * PORT data structure 1267725ccfdSJing Huang */ 1277725ccfdSJing Huang struct bfad_port_s { 1287725ccfdSJing Huang struct list_head list_entry; 1297725ccfdSJing Huang struct bfad_s *bfad; 130a36c61f9SKrishna Gudipati struct bfa_fcs_lport_s *fcs_port; 1317725ccfdSJing Huang u32 roles; 1327725ccfdSJing Huang s32 flags; 1337725ccfdSJing Huang u32 supported_fc4s; 1347725ccfdSJing Huang enum bfad_port_pvb_type pvb_type; 1357725ccfdSJing Huang struct bfad_im_port_s *im_port; /* IM specific data */ 136ab2a9ba1SJing Huang /* port debugfs specific data */ 137ab2a9ba1SJing Huang struct dentry *port_debugfs_root; 1387725ccfdSJing Huang }; 1397725ccfdSJing Huang 1407725ccfdSJing Huang /* 1417725ccfdSJing Huang * VPORT data structure 1427725ccfdSJing Huang */ 1437725ccfdSJing Huang struct bfad_vport_s { 1447725ccfdSJing Huang struct bfad_port_s drv_port; 1457725ccfdSJing Huang struct bfa_fcs_vport_s fcs_vport; 1467725ccfdSJing Huang struct completion *comp_del; 147d9883548SJing Huang struct list_head list_entry; 1487725ccfdSJing Huang }; 1497725ccfdSJing Huang 1507725ccfdSJing Huang /* 1517725ccfdSJing Huang * VF data structure 1527725ccfdSJing Huang */ 1537725ccfdSJing Huang struct bfad_vf_s { 1547725ccfdSJing Huang bfa_fcs_vf_t fcs_vf; 1557725ccfdSJing Huang struct bfad_port_s base_port; /* base port for vf */ 1567725ccfdSJing Huang struct bfad_s *bfad; 1577725ccfdSJing Huang }; 1587725ccfdSJing Huang 1597725ccfdSJing Huang struct bfad_cfg_param_s { 1607725ccfdSJing Huang u32 rport_del_timeout; 1617725ccfdSJing Huang u32 ioc_queue_depth; 1627725ccfdSJing Huang u32 lun_queue_depth; 1637725ccfdSJing Huang u32 io_max_sge; 1647725ccfdSJing Huang u32 binding_method; 1657725ccfdSJing Huang }; 1667725ccfdSJing Huang 167a36c61f9SKrishna Gudipati union bfad_tmp_buf { 168a36c61f9SKrishna Gudipati /* From struct bfa_adapter_attr_s */ 169a36c61f9SKrishna Gudipati char manufacturer[BFA_ADAPTER_MFG_NAME_LEN]; 170a36c61f9SKrishna Gudipati char serial_num[BFA_ADAPTER_SERIAL_NUM_LEN]; 171a36c61f9SKrishna Gudipati char model[BFA_ADAPTER_MODEL_NAME_LEN]; 172a36c61f9SKrishna Gudipati char fw_ver[BFA_VERSION_LEN]; 173a36c61f9SKrishna Gudipati char optrom_ver[BFA_VERSION_LEN]; 174a36c61f9SKrishna Gudipati 175a36c61f9SKrishna Gudipati /* From struct bfa_ioc_pci_attr_s */ 176a36c61f9SKrishna Gudipati u8 chip_rev[BFA_IOC_CHIP_REV_LEN]; /* chip revision */ 177a36c61f9SKrishna Gudipati 178a36c61f9SKrishna Gudipati wwn_t wwn[BFA_FCS_MAX_LPORTS]; 179a36c61f9SKrishna Gudipati }; 180a36c61f9SKrishna Gudipati 1817725ccfdSJing Huang /* 1827725ccfdSJing Huang * BFAD (PCI function) data structure 1837725ccfdSJing Huang */ 1847725ccfdSJing Huang struct bfad_s { 185a36c61f9SKrishna Gudipati bfa_sm_t sm; /* state machine */ 1867725ccfdSJing Huang struct list_head list_entry; 1877725ccfdSJing Huang struct bfa_s bfa; 1887725ccfdSJing Huang struct bfa_fcs_s bfa_fcs; 1897725ccfdSJing Huang struct pci_dev *pcidev; 1907725ccfdSJing Huang const char *pci_name; 1917725ccfdSJing Huang struct bfa_pcidev_s hal_pcidev; 1927725ccfdSJing Huang struct bfa_ioc_pci_attr_s pci_attr; 1937725ccfdSJing Huang void __iomem *pci_bar0_kva; 19411189208SKrishna Gudipati void __iomem *pci_bar2_kva; 1957725ccfdSJing Huang struct completion comp; 1967725ccfdSJing Huang struct completion suspend; 197*60138066SKrishna Gudipati struct completion enable_comp; 1987725ccfdSJing Huang struct completion disable_comp; 1997725ccfdSJing Huang bfa_boolean_t disable_active; 2007725ccfdSJing Huang struct bfad_port_s pport; /* physical port of the BFAD */ 2017725ccfdSJing Huang struct bfa_meminfo_s meminfo; 2027725ccfdSJing Huang struct bfa_iocfc_cfg_s ioc_cfg; 2037725ccfdSJing Huang u32 inst_no; /* BFAD instance number */ 2047725ccfdSJing Huang u32 bfad_flags; 2057725ccfdSJing Huang spinlock_t bfad_lock; 206e6714324SKrishna Gudipati struct task_struct *bfad_tsk; 2077725ccfdSJing Huang struct bfad_cfg_param_s cfg_data; 2087725ccfdSJing Huang struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY]; 2097725ccfdSJing Huang int nvec; 2107725ccfdSJing Huang char adapter_name[BFA_ADAPTER_SYM_NAME_LEN]; 2117725ccfdSJing Huang char port_name[BFA_ADAPTER_SYM_NAME_LEN]; 2127725ccfdSJing Huang struct timer_list hal_tmo; 2137725ccfdSJing Huang unsigned long hs_start; 2147725ccfdSJing Huang struct bfad_im_s *im; /* IM specific data */ 2157725ccfdSJing Huang struct bfa_trc_mod_s *trcmod; 2167725ccfdSJing Huang struct bfa_plog_s plog_buf; 2177725ccfdSJing Huang int ref_count; 218a36c61f9SKrishna Gudipati union bfad_tmp_buf tmp_buf; 2197725ccfdSJing Huang struct fc_host_statistics link_stats; 220a36c61f9SKrishna Gudipati struct list_head pbc_vport_list; 221ab2a9ba1SJing Huang /* debugfs specific data */ 222ab2a9ba1SJing Huang char *regdata; 223ab2a9ba1SJing Huang u32 reglen; 224ab2a9ba1SJing Huang struct dentry *bfad_dentry_files[5]; 225d9883548SJing Huang }; 226d9883548SJing Huang 227a36c61f9SKrishna Gudipati /* BFAD state machine events */ 228a36c61f9SKrishna Gudipati enum bfad_sm_event { 229a36c61f9SKrishna Gudipati BFAD_E_CREATE = 1, 230a36c61f9SKrishna Gudipati BFAD_E_KTHREAD_CREATE_FAILED = 2, 231a36c61f9SKrishna Gudipati BFAD_E_INIT = 3, 232a36c61f9SKrishna Gudipati BFAD_E_INIT_SUCCESS = 4, 233a36c61f9SKrishna Gudipati BFAD_E_INIT_FAILED = 5, 234a36c61f9SKrishna Gudipati BFAD_E_INTR_INIT_FAILED = 6, 235a36c61f9SKrishna Gudipati BFAD_E_FCS_EXIT_COMP = 7, 236a36c61f9SKrishna Gudipati BFAD_E_EXIT_COMP = 8, 237a36c61f9SKrishna Gudipati BFAD_E_STOP = 9 2387725ccfdSJing Huang }; 2397725ccfdSJing Huang 2407725ccfdSJing Huang /* 2417725ccfdSJing Huang * RPORT data structure 2427725ccfdSJing Huang */ 2437725ccfdSJing Huang struct bfad_rport_s { 2447725ccfdSJing Huang struct bfa_fcs_rport_s fcs_rport; 2457725ccfdSJing Huang }; 2467725ccfdSJing Huang 2477725ccfdSJing Huang struct bfad_buf_info { 2487725ccfdSJing Huang void *virt; 2497725ccfdSJing Huang dma_addr_t phys; 2507725ccfdSJing Huang u32 size; 2517725ccfdSJing Huang }; 2527725ccfdSJing Huang 2537725ccfdSJing Huang struct bfad_fcxp { 2547725ccfdSJing Huang struct bfad_port_s *port; 2557725ccfdSJing Huang struct bfa_rport_s *bfa_rport; 2567725ccfdSJing Huang bfa_status_t req_status; 2577725ccfdSJing Huang u16 tag; 2587725ccfdSJing Huang u16 rsp_len; 2597725ccfdSJing Huang u16 rsp_maxlen; 2607725ccfdSJing Huang u8 use_ireqbuf; 2617725ccfdSJing Huang u8 use_irspbuf; 2627725ccfdSJing Huang u32 num_req_sgles; 2637725ccfdSJing Huang u32 num_rsp_sgles; 2647725ccfdSJing Huang struct fchs_s fchs; 2657725ccfdSJing Huang void *reqbuf_info; 2667725ccfdSJing Huang void *rspbuf_info; 2677725ccfdSJing Huang struct bfa_sge_s *req_sge; 2687725ccfdSJing Huang struct bfa_sge_s *rsp_sge; 2697725ccfdSJing Huang fcxp_send_cb_t send_cbfn; 2707725ccfdSJing Huang void *send_cbarg; 2717725ccfdSJing Huang void *bfa_fcxp; 2727725ccfdSJing Huang struct completion comp; 2737725ccfdSJing Huang }; 2747725ccfdSJing Huang 2757725ccfdSJing Huang struct bfad_hal_comp { 2767725ccfdSJing Huang bfa_status_t status; 2777725ccfdSJing Huang struct completion comp; 2787725ccfdSJing Huang }; 2797725ccfdSJing Huang 280f16a1750SMaggie Zhang #define BFA_LOG(level, bfad, mask, fmt, arg...) \ 281a36c61f9SKrishna Gudipati do { \ 282f16a1750SMaggie Zhang if (((mask) == 4) || (level[1] <= '4')) \ 283f16a1750SMaggie Zhang dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg); \ 284a36c61f9SKrishna Gudipati } while (0) 285a36c61f9SKrishna Gudipati 2867725ccfdSJing Huang bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id, 287a36c61f9SKrishna Gudipati struct bfa_lport_cfg_s *port_cfg, 288a36c61f9SKrishna Gudipati struct device *dev); 2897725ccfdSJing Huang bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id, 290a36c61f9SKrishna Gudipati struct bfa_lport_cfg_s *port_cfg); 291a36c61f9SKrishna Gudipati bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role); 2927725ccfdSJing Huang bfa_status_t bfad_drv_init(struct bfad_s *bfad); 293e6714324SKrishna Gudipati bfa_status_t bfad_start_ops(struct bfad_s *bfad); 2947725ccfdSJing Huang void bfad_drv_start(struct bfad_s *bfad); 2957725ccfdSJing Huang void bfad_uncfg_pport(struct bfad_s *bfad); 296a36c61f9SKrishna Gudipati void bfad_stop(struct bfad_s *bfad); 297a36c61f9SKrishna Gudipati void bfad_fcs_stop(struct bfad_s *bfad); 2987725ccfdSJing Huang void bfad_remove_intr(struct bfad_s *bfad); 2997725ccfdSJing Huang void bfad_hal_mem_release(struct bfad_s *bfad); 3007725ccfdSJing Huang void bfad_hcb_comp(void *arg, bfa_status_t status); 3017725ccfdSJing Huang 3027725ccfdSJing Huang int bfad_setup_intr(struct bfad_s *bfad); 3037725ccfdSJing Huang void bfad_remove_intr(struct bfad_s *bfad); 3047725ccfdSJing Huang void bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg); 3057725ccfdSJing Huang bfa_status_t bfad_hal_mem_alloc(struct bfad_s *bfad); 3067725ccfdSJing Huang void bfad_bfa_tmo(unsigned long data); 3077725ccfdSJing Huang void bfad_init_timer(struct bfad_s *bfad); 3087725ccfdSJing Huang int bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad); 3097725ccfdSJing Huang void bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad); 3107725ccfdSJing Huang void bfad_drv_uninit(struct bfad_s *bfad); 311e6714324SKrishna Gudipati int bfad_worker(void *ptr); 312ab2a9ba1SJing Huang void bfad_debugfs_init(struct bfad_port_s *port); 313ab2a9ba1SJing Huang void bfad_debugfs_exit(struct bfad_port_s *port); 314e6714324SKrishna Gudipati 3157725ccfdSJing Huang void bfad_pci_remove(struct pci_dev *pdev); 3167725ccfdSJing Huang int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid); 317f16a1750SMaggie Zhang void bfad_rport_online_wait(struct bfad_s *bfad); 318f16a1750SMaggie Zhang int bfad_get_linkup_delay(struct bfad_s *bfad); 3197725ccfdSJing Huang int bfad_install_msix_handler(struct bfad_s *bfad); 3207725ccfdSJing Huang 3217725ccfdSJing Huang extern struct idr bfad_im_port_index; 322a36c61f9SKrishna Gudipati extern struct pci_device_id bfad_id_table[]; 3237725ccfdSJing Huang extern struct list_head bfad_list; 324a36c61f9SKrishna Gudipati extern char *os_name; 325a36c61f9SKrishna Gudipati extern char *os_patch; 326a36c61f9SKrishna Gudipati extern char *host_name; 327a36c61f9SKrishna Gudipati extern int num_rports; 328a36c61f9SKrishna Gudipati extern int num_ios; 329a36c61f9SKrishna Gudipati extern int num_tms; 330a36c61f9SKrishna Gudipati extern int num_fcxps; 331a36c61f9SKrishna Gudipati extern int num_ufbufs; 332a36c61f9SKrishna Gudipati extern int reqq_size; 333a36c61f9SKrishna Gudipati extern int rspq_size; 334a36c61f9SKrishna Gudipati extern int num_sgpgs; 335a36c61f9SKrishna Gudipati extern int rport_del_timeout; 3367725ccfdSJing Huang extern int bfa_lun_queue_depth; 337a36c61f9SKrishna Gudipati extern int bfa_io_max_sge; 33888166242SJing Huang extern int bfa_log_level; 339a36c61f9SKrishna Gudipati extern int ioc_auto_recover; 3407725ccfdSJing Huang extern int bfa_linkup_delay; 341a36c61f9SKrishna Gudipati extern int msix_disable_cb; 342a36c61f9SKrishna Gudipati extern int msix_disable_ct; 343a36c61f9SKrishna Gudipati extern int fdmi_enable; 344a36c61f9SKrishna Gudipati extern int supported_fc4s; 345a36c61f9SKrishna Gudipati extern int pcie_max_read_reqsz; 346ab2a9ba1SJing Huang extern int bfa_debugfs_enable; 34742b426ecSJing Huang extern struct mutex bfad_mutex; 3487725ccfdSJing Huang 3497725ccfdSJing Huang #endif /* __BFAD_DRV_H__ */ 350