Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2009 Brocade Communications Systems, Inc. |
| 3 | * All rights reserved |
| 4 | * www.brocade.com |
| 5 | * |
| 6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 10 | * published by the Free Software Foundation |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #ifndef __BFA_IOC_H__ |
| 19 | #define __BFA_IOC_H__ |
| 20 | |
| 21 | #include <cs/bfa_sm.h> |
| 22 | #include <bfi/bfi.h> |
| 23 | #include <bfi/bfi_ioc.h> |
| 24 | #include <bfi/bfi_boot.h> |
| 25 | #include <bfa_timer.h> |
| 26 | |
| 27 | /** |
| 28 | * PCI device information required by IOC |
| 29 | */ |
| 30 | struct bfa_pcidev_s { |
| 31 | int pci_slot; |
| 32 | u8 pci_func; |
| 33 | u16 device_id; |
| 34 | bfa_os_addr_t pci_bar_kva; |
| 35 | }; |
| 36 | |
| 37 | /** |
| 38 | * Structure used to remember the DMA-able memory block's KVA and Physical |
| 39 | * Address |
| 40 | */ |
| 41 | struct bfa_dma_s { |
| 42 | void *kva; /*! Kernel virtual address */ |
| 43 | u64 pa; /*! Physical address */ |
| 44 | }; |
| 45 | |
| 46 | #define BFA_DMA_ALIGN_SZ 256 |
| 47 | #define BFA_ROUNDUP(_l, _s) (((_l) + ((_s) - 1)) & ~((_s) - 1)) |
| 48 | |
| 49 | |
| 50 | |
| 51 | #define bfa_dma_addr_set(dma_addr, pa) \ |
| 52 | __bfa_dma_addr_set(&dma_addr, (u64)pa) |
| 53 | |
| 54 | static inline void |
| 55 | __bfa_dma_addr_set(union bfi_addr_u *dma_addr, u64 pa) |
| 56 | { |
| 57 | dma_addr->a32.addr_lo = (u32) pa; |
| 58 | dma_addr->a32.addr_hi = (u32) (bfa_os_u32(pa)); |
| 59 | } |
| 60 | |
| 61 | |
| 62 | #define bfa_dma_be_addr_set(dma_addr, pa) \ |
| 63 | __bfa_dma_be_addr_set(&dma_addr, (u64)pa) |
| 64 | static inline void |
| 65 | __bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa) |
| 66 | { |
| 67 | dma_addr->a32.addr_lo = (u32) bfa_os_htonl(pa); |
| 68 | dma_addr->a32.addr_hi = (u32) bfa_os_htonl(bfa_os_u32(pa)); |
| 69 | } |
| 70 | |
| 71 | struct bfa_ioc_regs_s { |
| 72 | bfa_os_addr_t hfn_mbox_cmd; |
| 73 | bfa_os_addr_t hfn_mbox; |
| 74 | bfa_os_addr_t lpu_mbox_cmd; |
| 75 | bfa_os_addr_t lpu_mbox; |
| 76 | bfa_os_addr_t pss_ctl_reg; |
Krishna Gudipati | 8b651b4 | 2010-03-05 19:34:44 -0800 | [diff] [blame] | 77 | bfa_os_addr_t pss_err_status_reg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 78 | bfa_os_addr_t app_pll_fast_ctl_reg; |
| 79 | bfa_os_addr_t app_pll_slow_ctl_reg; |
| 80 | bfa_os_addr_t ioc_sem_reg; |
| 81 | bfa_os_addr_t ioc_usage_sem_reg; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 82 | bfa_os_addr_t ioc_init_sem_reg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 83 | bfa_os_addr_t ioc_usage_reg; |
| 84 | bfa_os_addr_t host_page_num_fn; |
| 85 | bfa_os_addr_t heartbeat; |
| 86 | bfa_os_addr_t ioc_fwstate; |
| 87 | bfa_os_addr_t ll_halt; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 88 | bfa_os_addr_t err_set; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 89 | bfa_os_addr_t shirq_isr_next; |
| 90 | bfa_os_addr_t shirq_msk_next; |
| 91 | bfa_os_addr_t smem_page_start; |
| 92 | u32 smem_pg0; |
| 93 | }; |
| 94 | |
| 95 | #define bfa_reg_read(_raddr) bfa_os_reg_read(_raddr) |
| 96 | #define bfa_reg_write(_raddr, _val) bfa_os_reg_write(_raddr, _val) |
| 97 | #define bfa_mem_read(_raddr, _off) bfa_os_mem_read(_raddr, _off) |
| 98 | #define bfa_mem_write(_raddr, _off, _val) \ |
| 99 | bfa_os_mem_write(_raddr, _off, _val) |
| 100 | /** |
| 101 | * IOC Mailbox structures |
| 102 | */ |
| 103 | struct bfa_mbox_cmd_s { |
| 104 | struct list_head qe; |
| 105 | u32 msg[BFI_IOC_MSGSZ]; |
| 106 | }; |
| 107 | |
| 108 | /** |
| 109 | * IOC mailbox module |
| 110 | */ |
| 111 | typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m); |
| 112 | struct bfa_ioc_mbox_mod_s { |
| 113 | struct list_head cmd_q; /* pending mbox queue */ |
| 114 | int nmclass; /* number of handlers */ |
| 115 | struct { |
| 116 | bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */ |
| 117 | void *cbarg; |
| 118 | } mbhdlr[BFI_MC_MAX]; |
| 119 | }; |
| 120 | |
| 121 | /** |
| 122 | * IOC callback function interfaces |
| 123 | */ |
| 124 | typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status); |
| 125 | typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa); |
| 126 | typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa); |
| 127 | typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa); |
| 128 | struct bfa_ioc_cbfn_s { |
| 129 | bfa_ioc_enable_cbfn_t enable_cbfn; |
| 130 | bfa_ioc_disable_cbfn_t disable_cbfn; |
| 131 | bfa_ioc_hbfail_cbfn_t hbfail_cbfn; |
| 132 | bfa_ioc_reset_cbfn_t reset_cbfn; |
| 133 | }; |
| 134 | |
| 135 | /** |
| 136 | * Heartbeat failure notification queue element. |
| 137 | */ |
| 138 | struct bfa_ioc_hbfail_notify_s { |
| 139 | struct list_head qe; |
| 140 | bfa_ioc_hbfail_cbfn_t cbfn; |
| 141 | void *cbarg; |
| 142 | }; |
| 143 | |
| 144 | /** |
| 145 | * Initialize a heartbeat failure notification structure |
| 146 | */ |
| 147 | #define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \ |
| 148 | (__notify)->cbfn = (__cbfn); \ |
| 149 | (__notify)->cbarg = (__cbarg); \ |
| 150 | } while (0) |
| 151 | |
| 152 | struct bfa_ioc_s { |
| 153 | bfa_fsm_t fsm; |
| 154 | struct bfa_s *bfa; |
| 155 | struct bfa_pcidev_s pcidev; |
| 156 | struct bfa_timer_mod_s *timer_mod; |
| 157 | struct bfa_timer_s ioc_timer; |
| 158 | struct bfa_timer_s sem_timer; |
| 159 | u32 hb_count; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 160 | u32 retry_count; |
| 161 | struct list_head hb_notify_q; |
| 162 | void *dbg_fwsave; |
| 163 | int dbg_fwsave_len; |
| 164 | bfa_boolean_t dbg_fwsave_once; |
| 165 | enum bfi_mclass ioc_mc; |
| 166 | struct bfa_ioc_regs_s ioc_regs; |
| 167 | struct bfa_trc_mod_s *trcmod; |
| 168 | struct bfa_aen_s *aen; |
| 169 | struct bfa_log_mod_s *logm; |
| 170 | struct bfa_ioc_drv_stats_s stats; |
| 171 | bfa_boolean_t auto_recover; |
| 172 | bfa_boolean_t fcmode; |
| 173 | bfa_boolean_t ctdev; |
| 174 | bfa_boolean_t cna; |
| 175 | bfa_boolean_t pllinit; |
| 176 | u8 port_id; |
| 177 | |
| 178 | struct bfa_dma_s attr_dma; |
| 179 | struct bfi_ioc_attr_s *attr; |
| 180 | struct bfa_ioc_cbfn_s *cbfn; |
| 181 | struct bfa_ioc_mbox_mod_s mbox_mod; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 182 | struct bfa_ioc_hwif_s *ioc_hwif; |
| 183 | }; |
| 184 | |
| 185 | struct bfa_ioc_hwif_s { |
| 186 | bfa_status_t (*ioc_pll_init) (struct bfa_ioc_s *ioc); |
| 187 | bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc); |
| 188 | void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 189 | void (*ioc_reg_init) (struct bfa_ioc_s *ioc); |
| 190 | void (*ioc_map_port) (struct bfa_ioc_s *ioc); |
| 191 | void (*ioc_isr_mode_set) (struct bfa_ioc_s *ioc, |
| 192 | bfa_boolean_t msix); |
| 193 | void (*ioc_notify_hbfail) (struct bfa_ioc_s *ioc); |
| 194 | void (*ioc_ownership_reset) (struct bfa_ioc_s *ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 197 | #define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func) |
| 198 | #define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id) |
| 199 | #define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 200 | #define bfa_ioc_portid(__ioc) ((__ioc)->port_id) |
| 201 | #define bfa_ioc_fetch_stats(__ioc, __stats) \ |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 202 | (((__stats)->drv_stats) = (__ioc)->stats) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 203 | #define bfa_ioc_clr_stats(__ioc) \ |
| 204 | bfa_os_memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats)) |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 205 | #define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize) |
| 206 | #define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 207 | #define bfa_ioc_speed_sup(__ioc) \ |
| 208 | BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 209 | #define bfa_ioc_get_nports(__ioc) \ |
| 210 | BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop) |
| 211 | |
| 212 | #define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++) |
| 213 | #define BFA_IOC_FWIMG_MINSZ (16 * 1024) |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame^] | 214 | #define BFA_IOC_FWIMG_TYPE(__ioc) \ |
| 215 | (((__ioc)->ctdev) ? \ |
| 216 | (((__ioc)->fcmode) ? BFI_IMAGE_CT_FC : BFI_IMAGE_CT_CNA) : \ |
| 217 | BFI_IMAGE_CB_FC) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 218 | |
| 219 | #define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS) |
| 220 | #define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS) |
| 221 | #define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 222 | |
| 223 | /** |
| 224 | * IOC mailbox interface |
| 225 | */ |
| 226 | void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd); |
| 227 | void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, |
| 228 | bfa_ioc_mbox_mcfunc_t *mcfuncs); |
| 229 | void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc); |
| 230 | void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len); |
| 231 | void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg); |
| 232 | void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc, |
| 233 | bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg); |
| 234 | |
| 235 | /** |
| 236 | * IOC interfaces |
| 237 | */ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 238 | #define bfa_ioc_pll_init(__ioc) ((__ioc)->ioc_hwif->ioc_pll_init(__ioc)) |
| 239 | #define bfa_ioc_isr_mode_set(__ioc, __msix) \ |
| 240 | ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix)) |
| 241 | #define bfa_ioc_ownership_reset(__ioc) \ |
| 242 | ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc)) |
| 243 | |
| 244 | void bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc); |
| 245 | void bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 246 | void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, |
| 247 | struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod, |
| 248 | struct bfa_trc_mod_s *trcmod, |
| 249 | struct bfa_aen_s *aen, struct bfa_log_mod_s *logm); |
| 250 | void bfa_ioc_detach(struct bfa_ioc_s *ioc); |
| 251 | void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev, |
| 252 | enum bfi_mclass mc); |
| 253 | u32 bfa_ioc_meminfo(void); |
| 254 | void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa); |
| 255 | void bfa_ioc_enable(struct bfa_ioc_s *ioc); |
| 256 | void bfa_ioc_disable(struct bfa_ioc_s *ioc); |
| 257 | bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc); |
| 258 | |
| 259 | void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param); |
| 260 | void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg); |
| 261 | void bfa_ioc_error_isr(struct bfa_ioc_s *ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 262 | bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc); |
| 263 | bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc); |
| 264 | bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc); |
| 265 | bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc); |
| 266 | void bfa_ioc_cfg_complete(struct bfa_ioc_s *ioc); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 267 | enum bfa_ioc_type_e bfa_ioc_get_type(struct bfa_ioc_s *ioc); |
| 268 | void bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num); |
| 269 | void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver); |
| 270 | void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver); |
| 271 | void bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model); |
| 272 | void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, |
| 273 | char *manufacturer); |
| 274 | void bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev); |
| 275 | enum bfa_ioc_state bfa_ioc_get_state(struct bfa_ioc_s *ioc); |
| 276 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 277 | void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr); |
| 278 | void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc, |
| 279 | struct bfa_adapter_attr_s *ad_attr); |
| 280 | int bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover); |
| 281 | void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave); |
| 282 | bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, |
| 283 | int *trclen); |
Krishna Gudipati | 738c9e6 | 2010-03-05 19:36:19 -0800 | [diff] [blame] | 284 | void bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 285 | bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, |
| 286 | int *trclen); |
| 287 | u32 bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr); |
| 288 | u32 bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr); |
| 289 | void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc); |
| 290 | bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc); |
| 291 | void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc, |
| 292 | struct bfa_ioc_hbfail_notify_s *notify); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 293 | bfa_boolean_t bfa_ioc_sem_get(bfa_os_addr_t sem_reg); |
| 294 | void bfa_ioc_sem_release(bfa_os_addr_t sem_reg); |
| 295 | void bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc); |
| 296 | void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, |
| 297 | struct bfi_ioc_image_hdr_s *fwhdr); |
| 298 | bfa_boolean_t bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, |
| 299 | struct bfi_ioc_image_hdr_s *fwhdr); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 300 | |
| 301 | /* |
| 302 | * bfa mfg wwn API functions |
| 303 | */ |
| 304 | wwn_t bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc); |
| 305 | wwn_t bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc); |
| 306 | wwn_t bfa_ioc_get_wwn_naa5(struct bfa_ioc_s *ioc, u16 inst); |
| 307 | mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc); |
| 308 | u64 bfa_ioc_get_adid(struct bfa_ioc_s *ioc); |
| 309 | |
| 310 | #endif /* __BFA_IOC_H__ */ |
| 311 | |