blob: 2e5c0adef899974558515446618b603bffd85daa [file] [log] [blame]
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001/*
2 * Linux network driver for Brocade Converged Network Adapter.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13/*
14 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
17 */
18
19#ifndef __BFA_IOC_H__
20#define __BFA_IOC_H__
21
22#include "bfa_sm.h"
23#include "bfi.h"
24#include "cna.h"
25
26#define BFA_IOC_TOV 3000 /* msecs */
27#define BFA_IOC_HWSEM_TOV 500 /* msecs */
28#define BFA_IOC_HB_TOV 500 /* msecs */
29#define BFA_IOC_HWINIT_MAX 2
30#define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
31
32/**
33 * Generic Scatter Gather Element used by driver
34 */
35struct bfa_sge {
36 u32 sg_len;
37 void *sg_addr;
38};
39
40/**
41 * PCI device information required by IOC
42 */
43struct bfa_pcidev {
44 int pci_slot;
45 u8 pci_func;
46 u16 device_id;
47 void __iomem *pci_bar_kva;
48};
49
50/**
51 * Structure used to remember the DMA-able memory block's KVA and Physical
52 * Address
53 */
54struct bfa_dma {
55 void *kva; /* ! Kernel virtual address */
56 u64 pa; /* ! Physical address */
57};
58
59#define BFA_DMA_ALIGN_SZ 256
60
61/**
62 * smem size for Crossbow and Catapult
63 */
64#define BFI_SMEM_CB_SIZE 0x200000U /* ! 2MB for crossbow */
65#define BFI_SMEM_CT_SIZE 0x280000U /* ! 2.5MB for catapult */
66
67/**
68 * @brief BFA dma address assignment macro
69 */
70#define bfa_dma_addr_set(dma_addr, pa) \
71 __bfa_dma_addr_set(&dma_addr, (u64)pa)
72
73static inline void
74__bfa_dma_addr_set(union bfi_addr_u *dma_addr, u64 pa)
75{
76 dma_addr->a32.addr_lo = (u32) pa;
77 dma_addr->a32.addr_hi = (u32) (upper_32_bits(pa));
78}
79
80/**
81 * @brief BFA dma address assignment macro. (big endian format)
82 */
83#define bfa_dma_be_addr_set(dma_addr, pa) \
84 __bfa_dma_be_addr_set(&dma_addr, (u64)pa)
85static inline void
86__bfa_dma_be_addr_set(union bfi_addr_u *dma_addr, u64 pa)
87{
88 dma_addr->a32.addr_lo = (u32) htonl(pa);
89 dma_addr->a32.addr_hi = (u32) htonl(upper_32_bits(pa));
90}
91
92struct bfa_ioc_regs {
93 void __iomem *hfn_mbox_cmd;
94 void __iomem *hfn_mbox;
95 void __iomem *lpu_mbox_cmd;
96 void __iomem *lpu_mbox;
97 void __iomem *pss_ctl_reg;
98 void __iomem *pss_err_status_reg;
99 void __iomem *app_pll_fast_ctl_reg;
100 void __iomem *app_pll_slow_ctl_reg;
101 void __iomem *ioc_sem_reg;
102 void __iomem *ioc_usage_sem_reg;
103 void __iomem *ioc_init_sem_reg;
104 void __iomem *ioc_usage_reg;
105 void __iomem *host_page_num_fn;
106 void __iomem *heartbeat;
107 void __iomem *ioc_fwstate;
108 void __iomem *ll_halt;
109 void __iomem *err_set;
110 void __iomem *shirq_isr_next;
111 void __iomem *shirq_msk_next;
112 void __iomem *smem_page_start;
113 u32 smem_pg0;
114};
115
116/**
117 * IOC Mailbox structures
118 */
119struct bfa_mbox_cmd {
120 struct list_head qe;
121 u32 msg[BFI_IOC_MSGSZ];
122};
123
124/**
125 * IOC mailbox module
126 */
127typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg *m);
128struct bfa_ioc_mbox_mod {
129 struct list_head cmd_q; /*!< pending mbox queue */
130 int nmclass; /*!< number of handlers */
131 struct {
132 bfa_ioc_mbox_mcfunc_t cbfn; /*!< message handlers */
133 void *cbarg;
134 } mbhdlr[BFI_MC_MAX];
135};
136
137/**
138 * IOC callback function interfaces
139 */
140typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
141typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
142typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
143typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
144struct bfa_ioc_cbfn {
145 bfa_ioc_enable_cbfn_t enable_cbfn;
146 bfa_ioc_disable_cbfn_t disable_cbfn;
147 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
148 bfa_ioc_reset_cbfn_t reset_cbfn;
149};
150
151/**
152 * Heartbeat failure notification queue element.
153 */
154struct bfa_ioc_hbfail_notify {
155 struct list_head qe;
156 bfa_ioc_hbfail_cbfn_t cbfn;
157 void *cbarg;
158};
159
160/**
161 * Initialize a heartbeat failure notification structure
162 */
163#define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
164 (__notify)->cbfn = (__cbfn); \
165 (__notify)->cbarg = (__cbarg); \
166} while (0)
167
168struct bfa_ioc {
169 bfa_fsm_t fsm;
170 struct bfa *bfa;
171 struct bfa_pcidev pcidev;
172 struct bfa_timer_mod *timer_mod;
173 struct timer_list ioc_timer;
174 struct timer_list sem_timer;
175 struct timer_list hb_timer;
176 u32 hb_count;
177 u32 retry_count;
178 struct list_head hb_notify_q;
179 void *dbg_fwsave;
180 int dbg_fwsave_len;
181 bool dbg_fwsave_once;
182 enum bfi_mclass ioc_mc;
183 struct bfa_ioc_regs ioc_regs;
184 struct bfa_ioc_drv_stats stats;
185 bool auto_recover;
186 bool fcmode;
187 bool ctdev;
188 bool cna;
189 bool pllinit;
190 bool stats_busy; /*!< outstanding stats */
191 u8 port_id;
192
193 struct bfa_dma attr_dma;
194 struct bfi_ioc_attr *attr;
195 struct bfa_ioc_cbfn *cbfn;
196 struct bfa_ioc_mbox_mod mbox_mod;
197 struct bfa_ioc_hwif *ioc_hwif;
198};
199
200struct bfa_ioc_hwif {
201 enum bfa_status (*ioc_pll_init) (void __iomem *rb, bool fcmode);
202 bool (*ioc_firmware_lock) (struct bfa_ioc *ioc);
203 void (*ioc_firmware_unlock) (struct bfa_ioc *ioc);
204 void (*ioc_reg_init) (struct bfa_ioc *ioc);
205 void (*ioc_map_port) (struct bfa_ioc *ioc);
206 void (*ioc_isr_mode_set) (struct bfa_ioc *ioc,
207 bool msix);
208 void (*ioc_notify_hbfail) (struct bfa_ioc *ioc);
209 void (*ioc_ownership_reset) (struct bfa_ioc *ioc);
210};
211
212#define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
213#define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
214#define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
215#define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
216#define bfa_ioc_fetch_stats(__ioc, __stats) \
217 (((__stats)->drv_stats) = (__ioc)->stats)
218#define bfa_ioc_clr_stats(__ioc) \
219 memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
220#define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
221#define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
222#define bfa_ioc_speed_sup(__ioc) \
223 BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
224#define bfa_ioc_get_nports(__ioc) \
225 BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
226
227#define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
228#define BFA_IOC_FWIMG_MINSZ (16 * 1024)
229#define BFA_IOC_FWIMG_TYPE(__ioc) \
230 (((__ioc)->ctdev) ? \
231 (((__ioc)->fcmode) ? BFI_IMAGE_CT_FC : BFI_IMAGE_CT_CNA) : \
232 BFI_IMAGE_CB_FC)
233#define BFA_IOC_FW_SMEM_SIZE(__ioc) \
234 (((__ioc)->ctdev) ? BFI_SMEM_CT_SIZE : BFI_SMEM_CB_SIZE)
235#define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS)
236#define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
237#define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
238
239/**
240 * IOC mailbox interface
241 */
242void bfa_ioc_mbox_queue(struct bfa_ioc *ioc, struct bfa_mbox_cmd *cmd);
243void bfa_ioc_mbox_register(struct bfa_ioc *ioc,
244 bfa_ioc_mbox_mcfunc_t *mcfuncs);
245void bfa_ioc_mbox_isr(struct bfa_ioc *ioc);
246void bfa_ioc_mbox_send(struct bfa_ioc *ioc, void *ioc_msg, int len);
247void bfa_ioc_msgget(struct bfa_ioc *ioc, void *mbmsg);
248void bfa_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
249 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
250
251/**
252 * IOC interfaces
253 */
254
255#define bfa_ioc_pll_init_asic(__ioc) \
256 ((__ioc)->ioc_hwif->ioc_pll_init((__ioc)->pcidev.pci_bar_kva, \
257 (__ioc)->fcmode))
258
259enum bfa_status bfa_ioc_pll_init(struct bfa_ioc *ioc);
260enum bfa_status bfa_ioc_cb_pll_init(void __iomem *rb, bool fcmode);
261enum bfa_status bfa_ioc_ct_pll_init(void __iomem *rb, bool fcmode);
262
263#define bfa_ioc_isr_mode_set(__ioc, __msix) \
264 ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix))
265#define bfa_ioc_ownership_reset(__ioc) \
266 ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc))
267
268void bfa_ioc_set_ct_hwif(struct bfa_ioc *ioc);
269
270void bfa_ioc_attach(struct bfa_ioc *ioc, void *bfa,
271 struct bfa_ioc_cbfn *cbfn);
272void bfa_ioc_auto_recover(bool auto_recover);
273void bfa_ioc_detach(struct bfa_ioc *ioc);
274void bfa_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
275 enum bfi_mclass mc);
276u32 bfa_ioc_meminfo(void);
277void bfa_ioc_mem_claim(struct bfa_ioc *ioc, u8 *dm_kva, u64 dm_pa);
278void bfa_ioc_enable(struct bfa_ioc *ioc);
279void bfa_ioc_disable(struct bfa_ioc *ioc);
280bool bfa_ioc_intx_claim(struct bfa_ioc *ioc);
281
282void bfa_ioc_boot(struct bfa_ioc *ioc, u32 boot_type,
283 u32 boot_param);
284void bfa_ioc_isr(struct bfa_ioc *ioc, struct bfi_mbmsg *msg);
285void bfa_ioc_error_isr(struct bfa_ioc *ioc);
286bool bfa_ioc_is_operational(struct bfa_ioc *ioc);
287bool bfa_ioc_is_initialized(struct bfa_ioc *ioc);
288bool bfa_ioc_is_disabled(struct bfa_ioc *ioc);
289bool bfa_ioc_fw_mismatch(struct bfa_ioc *ioc);
290bool bfa_ioc_adapter_is_disabled(struct bfa_ioc *ioc);
291void bfa_ioc_cfg_complete(struct bfa_ioc *ioc);
292enum bfa_ioc_type bfa_ioc_get_type(struct bfa_ioc *ioc);
293void bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc, char *serial_num);
294void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc, char *fw_ver);
295void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver);
296void bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model);
297void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc,
298 char *manufacturer);
299void bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc, char *chip_rev);
300enum bfa_ioc_state bfa_ioc_get_state(struct bfa_ioc *ioc);
301
302void bfa_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr);
303void bfa_ioc_get_adapter_attr(struct bfa_ioc *ioc,
304 struct bfa_adapter_attr *ad_attr);
305u32 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr);
306u32 bfa_ioc_smem_pgoff(struct bfa_ioc *ioc, u32 fmaddr);
307void bfa_ioc_set_fcmode(struct bfa_ioc *ioc);
308bool bfa_ioc_get_fcmode(struct bfa_ioc *ioc);
309void bfa_ioc_hbfail_register(struct bfa_ioc *ioc,
310 struct bfa_ioc_hbfail_notify *notify);
311bool bfa_ioc_sem_get(void __iomem *sem_reg);
312void bfa_ioc_sem_release(void __iomem *sem_reg);
313void bfa_ioc_hw_sem_release(struct bfa_ioc *ioc);
314void bfa_ioc_fwver_get(struct bfa_ioc *ioc,
315 struct bfi_ioc_image_hdr *fwhdr);
316bool bfa_ioc_fwver_cmp(struct bfa_ioc *ioc,
317 struct bfi_ioc_image_hdr *fwhdr);
318
319/*
320 * Timeout APIs
321 */
322void bfa_ioc_timeout(void *ioc);
323void bfa_ioc_hb_check(void *ioc);
324void bfa_ioc_sem_timeout(void *ioc);
325
326/*
327 * bfa mfg wwn API functions
328 */
329u64 bfa_ioc_get_pwwn(struct bfa_ioc *ioc);
330u64 bfa_ioc_get_nwwn(struct bfa_ioc *ioc);
331mac_t bfa_ioc_get_mac(struct bfa_ioc *ioc);
332u64 bfa_ioc_get_mfg_pwwn(struct bfa_ioc *ioc);
333u64 bfa_ioc_get_mfg_nwwn(struct bfa_ioc *ioc);
334mac_t bfa_ioc_get_mfg_mac(struct bfa_ioc *ioc);
335u64 bfa_ioc_get_adid(struct bfa_ioc *ioc);
336
337/*
338 * F/W Image Size & Chunk
339 */
340u32 *bfa_cb_image_get_chunk(int type, u32 off);
341u32 bfa_cb_image_get_size(int type);
342
343#endif /* __BFA_IOC_H__ */