Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Linux network driver for QLogic BR-series Converged Network Adapter.
0004  */
0005 /*
0006  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
0007  * Copyright (c) 2014-2015 QLogic Corporation
0008  * All rights reserved
0009  * www.qlogic.com
0010  */
0011 
0012 #ifndef __BFA_IOC_H__
0013 #define __BFA_IOC_H__
0014 
0015 #include "bfa_cs.h"
0016 #include "bfi.h"
0017 #include "cna.h"
0018 
0019 #define BFA_IOC_TOV     3000    /* msecs */
0020 #define BFA_IOC_HWSEM_TOV   500 /* msecs */
0021 #define BFA_IOC_HB_TOV      500 /* msecs */
0022 #define BFA_IOC_POLL_TOV    200 /* msecs */
0023 #define BNA_DBG_FWTRC_LEN      (BFI_IOC_TRC_ENTS * BFI_IOC_TRC_ENT_SZ + \
0024                 BFI_IOC_TRC_HDR_SZ)
0025 
0026 /* PCI device information required by IOC */
0027 struct bfa_pcidev {
0028     int pci_slot;
0029     u8  pci_func;
0030     u16 device_id;
0031     u16 ssid;
0032     void    __iomem *pci_bar_kva;
0033 };
0034 
0035 /* Structure used to remember the DMA-able memory block's KVA and Physical
0036  * Address
0037  */
0038 struct bfa_dma {
0039     void    *kva;   /* ! Kernel virtual address */
0040     u64 pa; /* ! Physical address       */
0041 };
0042 
0043 #define BFA_DMA_ALIGN_SZ    256
0044 
0045 /* smem size for Crossbow and Catapult */
0046 #define BFI_SMEM_CB_SIZE    0x200000U   /* ! 2MB for crossbow   */
0047 #define BFI_SMEM_CT_SIZE    0x280000U   /* ! 2.5MB for catapult */
0048 
0049 /* BFA dma address assignment macro. (big endian format) */
0050 #define bfa_dma_be_addr_set(dma_addr, pa)   \
0051         __bfa_dma_be_addr_set(&dma_addr, (u64)pa)
0052 static inline void
0053 __bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa)
0054 {
0055     dma_addr->a32.addr_lo = (u32) htonl(pa);
0056     dma_addr->a32.addr_hi = (u32) htonl(upper_32_bits(pa));
0057 }
0058 
0059 #define bfa_alen_set(__alen, __len, __pa)   \
0060     __bfa_alen_set(__alen, __len, (u64)__pa)
0061 
0062 static inline void
0063 __bfa_alen_set(struct bfi_alen *alen, u32 len, u64 pa)
0064 {
0065     alen->al_len = cpu_to_be32(len);
0066     bfa_dma_be_addr_set(alen->al_addr, pa);
0067 }
0068 
0069 struct bfa_ioc_regs {
0070     void __iomem *hfn_mbox_cmd;
0071     void __iomem *hfn_mbox;
0072     void __iomem *lpu_mbox_cmd;
0073     void __iomem *lpu_mbox;
0074     void __iomem *lpu_read_stat;
0075     void __iomem *pss_ctl_reg;
0076     void __iomem *pss_err_status_reg;
0077     void __iomem *app_pll_fast_ctl_reg;
0078     void __iomem *app_pll_slow_ctl_reg;
0079     void __iomem *ioc_sem_reg;
0080     void __iomem *ioc_usage_sem_reg;
0081     void __iomem *ioc_init_sem_reg;
0082     void __iomem *ioc_usage_reg;
0083     void __iomem *host_page_num_fn;
0084     void __iomem *heartbeat;
0085     void __iomem *ioc_fwstate;
0086     void __iomem *alt_ioc_fwstate;
0087     void __iomem *ll_halt;
0088     void __iomem *alt_ll_halt;
0089     void __iomem *err_set;
0090     void __iomem *ioc_fail_sync;
0091     void __iomem *shirq_isr_next;
0092     void __iomem *shirq_msk_next;
0093     void __iomem *smem_page_start;
0094     u32 smem_pg0;
0095 };
0096 
0097 /* IOC Mailbox structures */
0098 typedef void (*bfa_mbox_cmd_cbfn_t)(void *cbarg);
0099 struct bfa_mbox_cmd {
0100     struct list_head    qe;
0101     bfa_mbox_cmd_cbfn_t     cbfn;
0102     void            *cbarg;
0103     u32     msg[BFI_IOC_MSGSZ];
0104 };
0105 
0106 /* IOC mailbox module */
0107 typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg *m);
0108 struct bfa_ioc_mbox_mod {
0109     struct list_head    cmd_q;      /*!< pending mbox queue */
0110     int         nmclass;    /*!< number of handlers */
0111     struct {
0112         bfa_ioc_mbox_mcfunc_t   cbfn;   /*!< message handlers   */
0113         void            *cbarg;
0114     } mbhdlr[BFI_MC_MAX];
0115 };
0116 
0117 /* IOC callback function interfaces */
0118 typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
0119 typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
0120 typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
0121 typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
0122 struct bfa_ioc_cbfn {
0123     bfa_ioc_enable_cbfn_t   enable_cbfn;
0124     bfa_ioc_disable_cbfn_t  disable_cbfn;
0125     bfa_ioc_hbfail_cbfn_t   hbfail_cbfn;
0126     bfa_ioc_reset_cbfn_t    reset_cbfn;
0127 };
0128 
0129 /* IOC event notification mechanism. */
0130 enum bfa_ioc_event {
0131     BFA_IOC_E_ENABLED   = 1,
0132     BFA_IOC_E_DISABLED  = 2,
0133     BFA_IOC_E_FAILED    = 3,
0134 };
0135 
0136 typedef void (*bfa_ioc_notify_cbfn_t)(void *, enum bfa_ioc_event);
0137 
0138 struct bfa_ioc_notify {
0139     struct list_head    qe;
0140     bfa_ioc_notify_cbfn_t   cbfn;
0141     void            *cbarg;
0142 };
0143 
0144 /* Initialize a IOC event notification structure */
0145 #define bfa_ioc_notify_init(__notify, __cbfn, __cbarg) do { \
0146     (__notify)->cbfn = (__cbfn);                \
0147     (__notify)->cbarg = (__cbarg);              \
0148 } while (0)
0149 
0150 struct bfa_iocpf {
0151     bfa_fsm_t       fsm;
0152     struct bfa_ioc      *ioc;
0153     bool            fw_mismatch_notified;
0154     bool            auto_recover;
0155     u32         poll_time;
0156 };
0157 
0158 struct bfa_ioc {
0159     bfa_fsm_t       fsm;
0160     struct bfa      *bfa;
0161     struct bfa_pcidev   pcidev;
0162     struct timer_list   ioc_timer;
0163     struct timer_list   iocpf_timer;
0164     struct timer_list   sem_timer;
0165     struct timer_list   hb_timer;
0166     u32         hb_count;
0167     struct list_head    notify_q;
0168     void            *dbg_fwsave;
0169     int         dbg_fwsave_len;
0170     bool            dbg_fwsave_once;
0171     enum bfi_pcifn_class    clscode;
0172     struct bfa_ioc_regs ioc_regs;
0173     struct bfa_ioc_drv_stats stats;
0174     bool            fcmode;
0175     bool            pllinit;
0176     bool            stats_busy; /*!< outstanding stats */
0177     u8          port_id;
0178 
0179     struct bfa_dma      attr_dma;
0180     struct bfi_ioc_attr *attr;
0181     struct bfa_ioc_cbfn *cbfn;
0182     struct bfa_ioc_mbox_mod mbox_mod;
0183     const struct bfa_ioc_hwif *ioc_hwif;
0184     struct bfa_iocpf    iocpf;
0185     enum bfi_asic_gen   asic_gen;
0186     enum bfi_asic_mode  asic_mode;
0187     enum bfi_port_mode  port0_mode;
0188     enum bfi_port_mode  port1_mode;
0189     enum bfa_mode       port_mode;
0190     u8          ad_cap_bm;  /*!< adapter cap bit mask */
0191     u8          port_mode_cfg;  /*!< config port mode */
0192 };
0193 
0194 struct bfa_ioc_hwif {
0195     enum bfa_status (*ioc_pll_init) (void __iomem *rb,
0196                         enum bfi_asic_mode m);
0197     bool        (*ioc_firmware_lock)    (struct bfa_ioc *ioc);
0198     void        (*ioc_firmware_unlock)  (struct bfa_ioc *ioc);
0199     void        (*ioc_reg_init) (struct bfa_ioc *ioc);
0200     void        (*ioc_map_port) (struct bfa_ioc *ioc);
0201     void        (*ioc_isr_mode_set) (struct bfa_ioc *ioc,
0202                     bool msix);
0203     void        (*ioc_notify_fail)  (struct bfa_ioc *ioc);
0204     void        (*ioc_ownership_reset)  (struct bfa_ioc *ioc);
0205     bool        (*ioc_sync_start)       (struct bfa_ioc *ioc);
0206     void        (*ioc_sync_join)    (struct bfa_ioc *ioc);
0207     void        (*ioc_sync_leave)   (struct bfa_ioc *ioc);
0208     void        (*ioc_sync_ack)     (struct bfa_ioc *ioc);
0209     bool        (*ioc_sync_complete)    (struct bfa_ioc *ioc);
0210     bool        (*ioc_lpu_read_stat)    (struct bfa_ioc *ioc);
0211     void        (*ioc_set_fwstate)  (struct bfa_ioc *ioc,
0212                     enum bfi_ioc_state fwstate);
0213     enum bfi_ioc_state (*ioc_get_fwstate) (struct bfa_ioc *ioc);
0214     void        (*ioc_set_alt_fwstate)  (struct bfa_ioc *ioc,
0215                     enum bfi_ioc_state fwstate);
0216     enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc *ioc);
0217 
0218 };
0219 
0220 #define bfa_ioc_pcifn(__ioc)        ((__ioc)->pcidev.pci_func)
0221 #define bfa_ioc_devid(__ioc)        ((__ioc)->pcidev.device_id)
0222 #define bfa_ioc_bar0(__ioc)     ((__ioc)->pcidev.pci_bar_kva)
0223 #define bfa_ioc_portid(__ioc)       ((__ioc)->port_id)
0224 #define bfa_ioc_asic_gen(__ioc)     ((__ioc)->asic_gen)
0225 #define bfa_ioc_is_default(__ioc)   \
0226     (bfa_ioc_pcifn(__ioc) == bfa_ioc_portid(__ioc))
0227 #define bfa_ioc_speed_sup(__ioc)    \
0228     BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
0229 #define bfa_ioc_get_nports(__ioc)   \
0230     BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
0231 
0232 #define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
0233 #define bfa_ioc_stats_hb_count(_ioc, _hb_count) \
0234     ((_ioc)->stats.hb_count = (_hb_count))
0235 #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
0236 #define BFA_IOC_FW_SMEM_SIZE(__ioc)                 \
0237     ((bfa_ioc_asic_gen(__ioc) == BFI_ASIC_GEN_CB)           \
0238     ? BFI_SMEM_CB_SIZE : BFI_SMEM_CT_SIZE)
0239 #define BFA_IOC_FLASH_CHUNK_NO(off)     (off / BFI_FLASH_CHUNK_SZ_WORDS)
0240 #define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off)  (off % BFI_FLASH_CHUNK_SZ_WORDS)
0241 #define BFA_IOC_FLASH_CHUNK_ADDR(chunkno)  (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
0242 
0243 /* IOC mailbox interface */
0244 bool bfa_nw_ioc_mbox_queue(struct bfa_ioc *ioc,
0245             struct bfa_mbox_cmd *cmd,
0246             bfa_mbox_cmd_cbfn_t cbfn, void *cbarg);
0247 void bfa_nw_ioc_mbox_isr(struct bfa_ioc *ioc);
0248 void bfa_nw_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
0249         bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
0250 
0251 /* IOC interfaces */
0252 
0253 #define bfa_ioc_pll_init_asic(__ioc) \
0254     ((__ioc)->ioc_hwif->ioc_pll_init((__ioc)->pcidev.pci_bar_kva, \
0255                (__ioc)->asic_mode))
0256 
0257 #define bfa_ioc_lpu_read_stat(__ioc) do {               \
0258         if ((__ioc)->ioc_hwif->ioc_lpu_read_stat)       \
0259             ((__ioc)->ioc_hwif->ioc_lpu_read_stat(__ioc));  \
0260 } while (0)
0261 
0262 void bfa_nw_ioc_set_ct_hwif(struct bfa_ioc *ioc);
0263 void bfa_nw_ioc_set_ct2_hwif(struct bfa_ioc *ioc);
0264 void bfa_nw_ioc_ct2_poweron(struct bfa_ioc *ioc);
0265 
0266 void bfa_nw_ioc_attach(struct bfa_ioc *ioc, void *bfa,
0267         struct bfa_ioc_cbfn *cbfn);
0268 void bfa_nw_ioc_auto_recover(bool auto_recover);
0269 void bfa_nw_ioc_detach(struct bfa_ioc *ioc);
0270 void bfa_nw_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
0271         enum bfi_pcifn_class clscode);
0272 u32 bfa_nw_ioc_meminfo(void);
0273 void bfa_nw_ioc_mem_claim(struct bfa_ioc *ioc,  u8 *dm_kva, u64 dm_pa);
0274 void bfa_nw_ioc_enable(struct bfa_ioc *ioc);
0275 void bfa_nw_ioc_disable(struct bfa_ioc *ioc);
0276 
0277 void bfa_nw_ioc_error_isr(struct bfa_ioc *ioc);
0278 bool bfa_nw_ioc_is_disabled(struct bfa_ioc *ioc);
0279 bool bfa_nw_ioc_is_operational(struct bfa_ioc *ioc);
0280 void bfa_nw_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr);
0281 enum bfa_status bfa_nw_ioc_fwsig_invalidate(struct bfa_ioc *ioc);
0282 void bfa_nw_ioc_notify_register(struct bfa_ioc *ioc,
0283     struct bfa_ioc_notify *notify);
0284 bool bfa_nw_ioc_sem_get(void __iomem *sem_reg);
0285 void bfa_nw_ioc_sem_release(void __iomem *sem_reg);
0286 void bfa_nw_ioc_hw_sem_release(struct bfa_ioc *ioc);
0287 void bfa_nw_ioc_fwver_get(struct bfa_ioc *ioc,
0288             struct bfi_ioc_image_hdr *fwhdr);
0289 bool bfa_nw_ioc_fwver_cmp(struct bfa_ioc *ioc,
0290             struct bfi_ioc_image_hdr *fwhdr);
0291 void bfa_nw_ioc_get_mac(struct bfa_ioc *ioc, u8 *mac);
0292 void bfa_nw_ioc_debug_memclaim(struct bfa_ioc *ioc, void *dbg_fwsave);
0293 int bfa_nw_ioc_debug_fwtrc(struct bfa_ioc *ioc, void *trcdata, int *trclen);
0294 int bfa_nw_ioc_debug_fwsave(struct bfa_ioc *ioc, void *trcdata, int *trclen);
0295 
0296 /*
0297  * Timeout APIs
0298  */
0299 void bfa_nw_ioc_timeout(struct bfa_ioc *ioc);
0300 void bfa_nw_ioc_hb_check(struct bfa_ioc *ioc);
0301 void bfa_nw_iocpf_timeout(struct bfa_ioc *ioc);
0302 void bfa_nw_iocpf_sem_timeout(struct bfa_ioc *ioc);
0303 
0304 /*
0305  * F/W Image Size & Chunk
0306  */
0307 u32 *bfa_cb_image_get_chunk(enum bfi_asic_gen asic_gen, u32 off);
0308 u32 bfa_cb_image_get_size(enum bfi_asic_gen asic_gen);
0309 
0310 /*
0311  *  Flash module specific
0312  */
0313 typedef void    (*bfa_cb_flash) (void *cbarg, enum bfa_status status);
0314 
0315 struct bfa_flash {
0316     struct bfa_ioc *ioc;        /* back pointer to ioc */
0317     u32     type;       /* partition type */
0318     u8      instance;   /* partition instance */
0319     u8      rsv[3];
0320     u32     op_busy;    /*  operation busy flag */
0321     u32     residue;    /*  residual length */
0322     u32     offset;     /*  offset */
0323     enum bfa_status status;     /*  status */
0324     u8      *dbuf_kva;  /*  dma buf virtual address */
0325     u64     dbuf_pa;    /*  dma buf physical address */
0326     bfa_cb_flash    cbfn;       /*  user callback function */
0327     void        *cbarg;     /*  user callback arg */
0328     u8      *ubuf;      /*  user supplied buffer */
0329     u32     addr_off;   /*  partition address offset */
0330     struct bfa_mbox_cmd mb;     /*  mailbox */
0331     struct bfa_ioc_notify ioc_notify; /*  ioc event notify */
0332 };
0333 
0334 enum bfa_status bfa_nw_flash_get_attr(struct bfa_flash *flash,
0335             struct bfa_flash_attr *attr,
0336             bfa_cb_flash cbfn, void *cbarg);
0337 enum bfa_status bfa_nw_flash_update_part(struct bfa_flash *flash,
0338             u32 type, u8 instance, void *buf, u32 len, u32 offset,
0339             bfa_cb_flash cbfn, void *cbarg);
0340 enum bfa_status bfa_nw_flash_read_part(struct bfa_flash *flash,
0341             u32 type, u8 instance, void *buf, u32 len, u32 offset,
0342             bfa_cb_flash cbfn, void *cbarg);
0343 u32 bfa_nw_flash_meminfo(void);
0344 void    bfa_nw_flash_attach(struct bfa_flash *flash,
0345                 struct bfa_ioc *ioc, void *dev);
0346 void    bfa_nw_flash_memclaim(struct bfa_flash *flash, u8 *dm_kva, u64 dm_pa);
0347 
0348 #endif /* __BFA_IOC_H__ */