Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
0004  * Copyright (c) 2014- QLogic Corporation.
0005  * All rights reserved
0006  * www.qlogic.com
0007  *
0008  * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
0009  */
0010 
0011 /*
0012  * Contains base driver definitions.
0013  */
0014 
0015 /*
0016  *  bfa_drv.h Linux driver data structures.
0017  */
0018 
0019 #ifndef __BFAD_DRV_H__
0020 #define __BFAD_DRV_H__
0021 
0022 #include <linux/types.h>
0023 #include <linux/pci.h>
0024 #include <linux/dma-mapping.h>
0025 #include <linux/idr.h>
0026 #include <linux/interrupt.h>
0027 #include <linux/cdev.h>
0028 #include <linux/fs.h>
0029 #include <linux/delay.h>
0030 #include <linux/vmalloc.h>
0031 #include <linux/workqueue.h>
0032 #include <linux/bitops.h>
0033 #include <linux/aer.h>
0034 #include <scsi/scsi.h>
0035 #include <scsi/scsi_host.h>
0036 #include <scsi/scsi_tcq.h>
0037 #include <scsi/scsi_transport_fc.h>
0038 #include <scsi/scsi_transport.h>
0039 #include <scsi/scsi_bsg_fc.h>
0040 #include <scsi/scsi_devinfo.h>
0041 
0042 #include "bfa_modules.h"
0043 #include "bfa_fcs.h"
0044 #include "bfa_defs_fcs.h"
0045 
0046 #include "bfa_plog.h"
0047 #include "bfa_cs.h"
0048 
0049 #define BFAD_DRIVER_NAME    "bfa"
0050 #ifdef BFA_DRIVER_VERSION
0051 #define BFAD_DRIVER_VERSION    BFA_DRIVER_VERSION
0052 #else
0053 #define BFAD_DRIVER_VERSION    "3.2.25.1"
0054 #endif
0055 
0056 #define BFAD_PROTO_NAME FCPI_NAME
0057 #define BFAD_IRQ_FLAGS IRQF_SHARED
0058 
0059 #ifndef FC_PORTSPEED_8GBIT
0060 #define FC_PORTSPEED_8GBIT 0x10
0061 #endif
0062 
0063 /*
0064  * BFAD flags
0065  */
0066 #define BFAD_MSIX_ON                0x00000001
0067 #define BFAD_HAL_INIT_DONE          0x00000002
0068 #define BFAD_DRV_INIT_DONE          0x00000004
0069 #define BFAD_CFG_PPORT_DONE         0x00000008
0070 #define BFAD_HAL_START_DONE         0x00000010
0071 #define BFAD_PORT_ONLINE            0x00000020
0072 #define BFAD_RPORT_ONLINE           0x00000040
0073 #define BFAD_FCS_INIT_DONE          0x00000080
0074 #define BFAD_HAL_INIT_FAIL          0x00000100
0075 #define BFAD_FC4_PROBE_DONE         0x00000200
0076 #define BFAD_PORT_DELETE            0x00000001
0077 #define BFAD_INTX_ON                0x00000400
0078 #define BFAD_EEH_BUSY               0x00000800
0079 #define BFAD_EEH_PCI_CHANNEL_IO_PERM_FAILURE    0x00001000
0080 /*
0081  * BFAD related definition
0082  */
0083 #define SCSI_SCAN_DELAY     HZ
0084 #define BFAD_STOP_TIMEOUT   30
0085 #define BFAD_SUSPEND_TIMEOUT    BFAD_STOP_TIMEOUT
0086 
0087 /*
0088  * BFAD configuration parameter default values
0089  */
0090 #define BFAD_LUN_QUEUE_DEPTH    32
0091 #define BFAD_IO_MAX_SGE     SG_ALL
0092 #define BFAD_MIN_SECTORS    128 /* 64k   */
0093 #define BFAD_MAX_SECTORS    0xFFFF  /* 32 MB */
0094 
0095 #define bfad_isr_t irq_handler_t
0096 
0097 #define MAX_MSIX_ENTRY 22
0098 
0099 struct bfad_msix_s {
0100     struct bfad_s *bfad;
0101     struct msix_entry msix;
0102     char name[32];
0103 };
0104 
0105 /*
0106  * Only append to the enums defined here to avoid any versioning
0107  * needed between trace utility and driver version
0108  */
0109 enum {
0110     BFA_TRC_LDRV_BFAD       = 1,
0111     BFA_TRC_LDRV_IM         = 2,
0112     BFA_TRC_LDRV_BSG        = 3,
0113 };
0114 
0115 enum bfad_port_pvb_type {
0116     BFAD_PORT_PHYS_BASE = 0,
0117     BFAD_PORT_PHYS_VPORT = 1,
0118     BFAD_PORT_VF_BASE = 2,
0119     BFAD_PORT_VF_VPORT = 3,
0120 };
0121 
0122 /*
0123  * PORT data structure
0124  */
0125 struct bfad_port_s {
0126     struct list_head list_entry;
0127     struct bfad_s   *bfad;
0128     struct bfa_fcs_lport_s *fcs_port;
0129     u32 roles;
0130     s32     flags;
0131     u32 supported_fc4s;
0132     enum bfad_port_pvb_type pvb_type;
0133     struct bfad_im_port_s *im_port; /* IM specific data */
0134     /* port debugfs specific data */
0135     struct dentry *port_debugfs_root;
0136 };
0137 
0138 /*
0139  * VPORT data structure
0140  */
0141 struct bfad_vport_s {
0142     struct bfad_port_s     drv_port;
0143     struct bfa_fcs_vport_s fcs_vport;
0144     struct completion *comp_del;
0145     struct list_head list_entry;
0146 };
0147 
0148 /*
0149  * VF data structure
0150  */
0151 struct bfad_vf_s {
0152     bfa_fcs_vf_t    fcs_vf;
0153     struct bfad_port_s    base_port;    /* base port for vf */
0154     struct bfad_s   *bfad;
0155 };
0156 
0157 struct bfad_cfg_param_s {
0158     u32 rport_del_timeout;
0159     u32 ioc_queue_depth;
0160     u32 lun_queue_depth;
0161     u32 io_max_sge;
0162     u32 binding_method;
0163 };
0164 
0165 union bfad_tmp_buf {
0166     /* From struct bfa_adapter_attr_s */
0167     char        manufacturer[BFA_ADAPTER_MFG_NAME_LEN];
0168     char        serial_num[BFA_ADAPTER_SERIAL_NUM_LEN];
0169     char        model[BFA_ADAPTER_MODEL_NAME_LEN];
0170     char        fw_ver[BFA_VERSION_LEN];
0171     char        optrom_ver[BFA_VERSION_LEN];
0172 
0173     /* From struct bfa_ioc_pci_attr_s */
0174     u8      chip_rev[BFA_IOC_CHIP_REV_LEN];  /*  chip revision */
0175 
0176     wwn_t       wwn[BFA_FCS_MAX_LPORTS];
0177 };
0178 
0179 /*
0180  * BFAD (PCI function) data structure
0181  */
0182 struct bfad_s {
0183     bfa_sm_t    sm; /* state machine */
0184     struct list_head list_entry;
0185     struct bfa_s    bfa;
0186     struct bfa_fcs_s bfa_fcs;
0187     struct pci_dev *pcidev;
0188     const char *pci_name;
0189     struct bfa_pcidev_s hal_pcidev;
0190     struct bfa_ioc_pci_attr_s pci_attr;
0191     void __iomem   *pci_bar0_kva;
0192     void __iomem   *pci_bar2_kva;
0193     struct completion comp;
0194     struct completion suspend;
0195     struct completion enable_comp;
0196     struct completion disable_comp;
0197     bfa_boolean_t   disable_active;
0198     struct bfad_port_s     pport;   /* physical port of the BFAD */
0199     struct bfa_meminfo_s meminfo;
0200     struct bfa_iocfc_cfg_s   ioc_cfg;
0201     u32 inst_no;    /* BFAD instance number */
0202     u32 bfad_flags;
0203     spinlock_t      bfad_lock;
0204     struct task_struct *bfad_tsk;
0205     struct bfad_cfg_param_s cfg_data;
0206     struct bfad_msix_s msix_tab[MAX_MSIX_ENTRY];
0207     int     nvec;
0208     char    adapter_name[BFA_ADAPTER_SYM_NAME_LEN];
0209     char    port_name[BFA_ADAPTER_SYM_NAME_LEN];
0210     struct timer_list hal_tmo;
0211     unsigned long   hs_start;
0212     struct bfad_im_s *im;       /* IM specific data */
0213     struct bfa_trc_mod_s  *trcmod;
0214     struct bfa_plog_s      plog_buf;
0215     int     ref_count;
0216     union bfad_tmp_buf tmp_buf;
0217     struct fc_host_statistics link_stats;
0218     struct list_head pbc_vport_list;
0219     /* debugfs specific data */
0220     char *regdata;
0221     u32 reglen;
0222     struct dentry *bfad_dentry_files[5];
0223     struct list_head    free_aen_q;
0224     struct list_head    active_aen_q;
0225     struct bfa_aen_entry_s  aen_list[BFA_AEN_MAX_ENTRY];
0226     spinlock_t      bfad_aen_spinlock;
0227     struct list_head    vport_list;
0228 };
0229 
0230 /* BFAD state machine events */
0231 enum bfad_sm_event {
0232     BFAD_E_CREATE           = 1,
0233     BFAD_E_KTHREAD_CREATE_FAILED    = 2,
0234     BFAD_E_INIT         = 3,
0235     BFAD_E_INIT_SUCCESS     = 4,
0236     BFAD_E_HAL_INIT_FAILED      = 5,
0237     BFAD_E_INIT_FAILED      = 6,
0238     BFAD_E_FCS_EXIT_COMP        = 7,
0239     BFAD_E_EXIT_COMP        = 8,
0240     BFAD_E_STOP         = 9
0241 };
0242 
0243 /*
0244  * RPORT data structure
0245  */
0246 struct bfad_rport_s {
0247     struct bfa_fcs_rport_s fcs_rport;
0248 };
0249 
0250 struct bfad_buf_info {
0251     void        *virt;
0252     dma_addr_t      phys;
0253     u32 size;
0254 };
0255 
0256 struct bfad_fcxp {
0257     struct bfad_port_s    *port;
0258     struct bfa_rport_s *bfa_rport;
0259     bfa_status_t    req_status;
0260     u16 tag;
0261     u16 rsp_len;
0262     u16 rsp_maxlen;
0263     u8      use_ireqbuf;
0264     u8      use_irspbuf;
0265     u32 num_req_sgles;
0266     u32 num_rsp_sgles;
0267     struct fchs_s   fchs;
0268     void        *reqbuf_info;
0269     void        *rspbuf_info;
0270     struct bfa_sge_s  *req_sge;
0271     struct bfa_sge_s  *rsp_sge;
0272     fcxp_send_cb_t  send_cbfn;
0273     void        *send_cbarg;
0274     void        *bfa_fcxp;
0275     struct completion comp;
0276 };
0277 
0278 struct bfad_hal_comp {
0279     bfa_status_t    status;
0280     struct completion comp;
0281 };
0282 
0283 #define BFA_LOG(level, bfad, mask, fmt, arg...)             \
0284 do {                                    \
0285     if (((mask) == 4) || (level[1] <= '4'))             \
0286         dev_printk(level, &((bfad)->pcidev)->dev, fmt, ##arg);  \
0287 } while (0)
0288 
0289 bfa_status_t    bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
0290                   struct bfa_lport_cfg_s *port_cfg,
0291                   struct device *dev);
0292 bfa_status_t    bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
0293                    struct bfa_lport_cfg_s *port_cfg);
0294 bfa_status_t    bfad_cfg_pport(struct bfad_s *bfad, enum bfa_lport_role role);
0295 bfa_status_t    bfad_drv_init(struct bfad_s *bfad);
0296 bfa_status_t    bfad_start_ops(struct bfad_s *bfad);
0297 void        bfad_drv_start(struct bfad_s *bfad);
0298 void        bfad_uncfg_pport(struct bfad_s *bfad);
0299 void        bfad_stop(struct bfad_s *bfad);
0300 void        bfad_fcs_stop(struct bfad_s *bfad);
0301 void        bfad_remove_intr(struct bfad_s *bfad);
0302 void        bfad_hal_mem_release(struct bfad_s *bfad);
0303 void        bfad_hcb_comp(void *arg, bfa_status_t status);
0304 
0305 int     bfad_setup_intr(struct bfad_s *bfad);
0306 void        bfad_remove_intr(struct bfad_s *bfad);
0307 void        bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg);
0308 bfa_status_t    bfad_hal_mem_alloc(struct bfad_s *bfad);
0309 void        bfad_bfa_tmo(struct timer_list *t);
0310 void        bfad_init_timer(struct bfad_s *bfad);
0311 int     bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad);
0312 void        bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad);
0313 void        bfad_drv_uninit(struct bfad_s *bfad);
0314 int     bfad_worker(void *ptr);
0315 void        bfad_debugfs_init(struct bfad_port_s *port);
0316 void        bfad_debugfs_exit(struct bfad_port_s *port);
0317 
0318 void bfad_pci_remove(struct pci_dev *pdev);
0319 int bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid);
0320 void bfad_rport_online_wait(struct bfad_s *bfad);
0321 int bfad_get_linkup_delay(struct bfad_s *bfad);
0322 int bfad_install_msix_handler(struct bfad_s *bfad);
0323 
0324 extern struct idr bfad_im_port_index;
0325 extern struct pci_device_id bfad_id_table[];
0326 extern struct list_head bfad_list;
0327 extern char *os_name;
0328 extern char *os_patch;
0329 extern char *host_name;
0330 extern int  num_rports;
0331 extern int  num_ios;
0332 extern int  num_tms;
0333 extern int  num_fcxps;
0334 extern int  num_ufbufs;
0335 extern int  reqq_size;
0336 extern int  rspq_size;
0337 extern int  num_sgpgs;
0338 extern int      rport_del_timeout;
0339 extern int      bfa_lun_queue_depth;
0340 extern int      bfa_io_max_sge;
0341 extern int      bfa_log_level;
0342 extern int      ioc_auto_recover;
0343 extern int      bfa_linkup_delay;
0344 extern int      msix_disable_cb;
0345 extern int      msix_disable_ct;
0346 extern int      fdmi_enable;
0347 extern int      supported_fc4s;
0348 extern int  pcie_max_read_reqsz;
0349 extern int  max_xfer_size;
0350 extern int bfa_debugfs_enable;
0351 extern struct mutex bfad_mutex;
0352 
0353 #endif /* __BFAD_DRV_H__ */