blob: 1633a50187f7eb5bdda9d81af684c01847ae1778 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
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 */
30struct 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 */
41struct 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
54static 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)
64static 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
71struct 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;
77 bfa_os_addr_t app_pll_fast_ctl_reg;
78 bfa_os_addr_t app_pll_slow_ctl_reg;
79 bfa_os_addr_t ioc_sem_reg;
80 bfa_os_addr_t ioc_usage_sem_reg;
Krishna Gudipati0a20de42010-03-05 19:34:20 -080081 bfa_os_addr_t ioc_init_sem_reg;
Jing Huang7725ccf2009-09-23 17:46:15 -070082 bfa_os_addr_t ioc_usage_reg;
83 bfa_os_addr_t host_page_num_fn;
84 bfa_os_addr_t heartbeat;
85 bfa_os_addr_t ioc_fwstate;
86 bfa_os_addr_t ll_halt;
Krishna Gudipati0a20de42010-03-05 19:34:20 -080087 bfa_os_addr_t err_set;
Jing Huang7725ccf2009-09-23 17:46:15 -070088 bfa_os_addr_t shirq_isr_next;
89 bfa_os_addr_t shirq_msk_next;
90 bfa_os_addr_t smem_page_start;
91 u32 smem_pg0;
92};
93
94#define bfa_reg_read(_raddr) bfa_os_reg_read(_raddr)
95#define bfa_reg_write(_raddr, _val) bfa_os_reg_write(_raddr, _val)
96#define bfa_mem_read(_raddr, _off) bfa_os_mem_read(_raddr, _off)
97#define bfa_mem_write(_raddr, _off, _val) \
98 bfa_os_mem_write(_raddr, _off, _val)
99/**
100 * IOC Mailbox structures
101 */
102struct bfa_mbox_cmd_s {
103 struct list_head qe;
104 u32 msg[BFI_IOC_MSGSZ];
105};
106
107/**
108 * IOC mailbox module
109 */
110typedef void (*bfa_ioc_mbox_mcfunc_t)(void *cbarg, struct bfi_mbmsg_s *m);
111struct bfa_ioc_mbox_mod_s {
112 struct list_head cmd_q; /* pending mbox queue */
113 int nmclass; /* number of handlers */
114 struct {
115 bfa_ioc_mbox_mcfunc_t cbfn; /* message handlers */
116 void *cbarg;
117 } mbhdlr[BFI_MC_MAX];
118};
119
120/**
121 * IOC callback function interfaces
122 */
123typedef void (*bfa_ioc_enable_cbfn_t)(void *bfa, enum bfa_status status);
124typedef void (*bfa_ioc_disable_cbfn_t)(void *bfa);
125typedef void (*bfa_ioc_hbfail_cbfn_t)(void *bfa);
126typedef void (*bfa_ioc_reset_cbfn_t)(void *bfa);
127struct bfa_ioc_cbfn_s {
128 bfa_ioc_enable_cbfn_t enable_cbfn;
129 bfa_ioc_disable_cbfn_t disable_cbfn;
130 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
131 bfa_ioc_reset_cbfn_t reset_cbfn;
132};
133
134/**
135 * Heartbeat failure notification queue element.
136 */
137struct bfa_ioc_hbfail_notify_s {
138 struct list_head qe;
139 bfa_ioc_hbfail_cbfn_t cbfn;
140 void *cbarg;
141};
142
143/**
144 * Initialize a heartbeat failure notification structure
145 */
146#define bfa_ioc_hbfail_init(__notify, __cbfn, __cbarg) do { \
147 (__notify)->cbfn = (__cbfn); \
148 (__notify)->cbarg = (__cbarg); \
149} while (0)
150
151struct bfa_ioc_s {
152 bfa_fsm_t fsm;
153 struct bfa_s *bfa;
154 struct bfa_pcidev_s pcidev;
155 struct bfa_timer_mod_s *timer_mod;
156 struct bfa_timer_s ioc_timer;
157 struct bfa_timer_s sem_timer;
158 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -0700159 u32 retry_count;
160 struct list_head hb_notify_q;
161 void *dbg_fwsave;
162 int dbg_fwsave_len;
163 bfa_boolean_t dbg_fwsave_once;
164 enum bfi_mclass ioc_mc;
165 struct bfa_ioc_regs_s ioc_regs;
166 struct bfa_trc_mod_s *trcmod;
167 struct bfa_aen_s *aen;
168 struct bfa_log_mod_s *logm;
169 struct bfa_ioc_drv_stats_s stats;
170 bfa_boolean_t auto_recover;
171 bfa_boolean_t fcmode;
172 bfa_boolean_t ctdev;
173 bfa_boolean_t cna;
174 bfa_boolean_t pllinit;
175 u8 port_id;
176
177 struct bfa_dma_s attr_dma;
178 struct bfi_ioc_attr_s *attr;
179 struct bfa_ioc_cbfn_s *cbfn;
180 struct bfa_ioc_mbox_mod_s mbox_mod;
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800181 struct bfa_ioc_hwif_s *ioc_hwif;
182};
183
184struct bfa_ioc_hwif_s {
185 bfa_status_t (*ioc_pll_init) (struct bfa_ioc_s *ioc);
186 bfa_boolean_t (*ioc_firmware_lock) (struct bfa_ioc_s *ioc);
187 void (*ioc_firmware_unlock) (struct bfa_ioc_s *ioc);
188 u32 * (*ioc_fwimg_get_chunk) (struct bfa_ioc_s *ioc,
189 u32 off);
190 u32 (*ioc_fwimg_get_size) (struct bfa_ioc_s *ioc);
191 void (*ioc_reg_init) (struct bfa_ioc_s *ioc);
192 void (*ioc_map_port) (struct bfa_ioc_s *ioc);
193 void (*ioc_isr_mode_set) (struct bfa_ioc_s *ioc,
194 bfa_boolean_t msix);
195 void (*ioc_notify_hbfail) (struct bfa_ioc_s *ioc);
196 void (*ioc_ownership_reset) (struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700197};
198
Jing Huangf8ceafd2009-09-25 12:29:54 -0700199#define bfa_ioc_pcifn(__ioc) ((__ioc)->pcidev.pci_func)
200#define bfa_ioc_devid(__ioc) ((__ioc)->pcidev.device_id)
201#define bfa_ioc_bar0(__ioc) ((__ioc)->pcidev.pci_bar_kva)
Jing Huang7725ccf2009-09-23 17:46:15 -0700202#define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
203#define bfa_ioc_fetch_stats(__ioc, __stats) \
Jing Huangf8ceafd2009-09-25 12:29:54 -0700204 (((__stats)->drv_stats) = (__ioc)->stats)
Jing Huang7725ccf2009-09-23 17:46:15 -0700205#define bfa_ioc_clr_stats(__ioc) \
206 bfa_os_memset(&(__ioc)->stats, 0, sizeof((__ioc)->stats))
Jing Huangf8ceafd2009-09-25 12:29:54 -0700207#define bfa_ioc_maxfrsize(__ioc) ((__ioc)->attr->maxfrsize)
208#define bfa_ioc_rx_bbcredit(__ioc) ((__ioc)->attr->rx_bbcredit)
Jing Huang7725ccf2009-09-23 17:46:15 -0700209#define bfa_ioc_speed_sup(__ioc) \
210 BFI_ADAPTER_GETP(SPEED, (__ioc)->attr->adapter_prop)
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800211#define bfa_ioc_get_nports(__ioc) \
212 BFI_ADAPTER_GETP(NPORTS, (__ioc)->attr->adapter_prop)
213
214#define bfa_ioc_stats(_ioc, _stats) ((_ioc)->stats._stats++)
215#define BFA_IOC_FWIMG_MINSZ (16 * 1024)
216
217#define BFA_IOC_FLASH_CHUNK_NO(off) (off / BFI_FLASH_CHUNK_SZ_WORDS)
218#define BFA_IOC_FLASH_OFFSET_IN_CHUNK(off) (off % BFI_FLASH_CHUNK_SZ_WORDS)
219#define BFA_IOC_FLASH_CHUNK_ADDR(chunkno) (chunkno * BFI_FLASH_CHUNK_SZ_WORDS)
Jing Huang7725ccf2009-09-23 17:46:15 -0700220
221/**
222 * IOC mailbox interface
223 */
224void bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd);
225void bfa_ioc_mbox_register(struct bfa_ioc_s *ioc,
226 bfa_ioc_mbox_mcfunc_t *mcfuncs);
227void bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc);
228void bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len);
229void bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg);
230void bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
231 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg);
232
233/**
234 * IOC interfaces
235 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800236#define bfa_ioc_pll_init(__ioc) ((__ioc)->ioc_hwif->ioc_pll_init(__ioc))
237#define bfa_ioc_isr_mode_set(__ioc, __msix) \
238 ((__ioc)->ioc_hwif->ioc_isr_mode_set(__ioc, __msix))
239#define bfa_ioc_ownership_reset(__ioc) \
240 ((__ioc)->ioc_hwif->ioc_ownership_reset(__ioc))
241
242void bfa_ioc_set_ct_hwif(struct bfa_ioc_s *ioc);
243void bfa_ioc_set_cb_hwif(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700244void bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa,
245 struct bfa_ioc_cbfn_s *cbfn, struct bfa_timer_mod_s *timer_mod,
246 struct bfa_trc_mod_s *trcmod,
247 struct bfa_aen_s *aen, struct bfa_log_mod_s *logm);
248void bfa_ioc_detach(struct bfa_ioc_s *ioc);
249void bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
250 enum bfi_mclass mc);
251u32 bfa_ioc_meminfo(void);
252void bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa);
253void bfa_ioc_enable(struct bfa_ioc_s *ioc);
254void bfa_ioc_disable(struct bfa_ioc_s *ioc);
255bfa_boolean_t bfa_ioc_intx_claim(struct bfa_ioc_s *ioc);
256
257void bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param);
258void bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *msg);
259void bfa_ioc_error_isr(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700260bfa_boolean_t bfa_ioc_is_operational(struct bfa_ioc_s *ioc);
261bfa_boolean_t bfa_ioc_is_disabled(struct bfa_ioc_s *ioc);
262bfa_boolean_t bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc);
263bfa_boolean_t bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc);
264void bfa_ioc_cfg_complete(struct bfa_ioc_s *ioc);
265void bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr);
266void bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
267 struct bfa_adapter_attr_s *ad_attr);
268int bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover);
269void bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave);
270bfa_status_t bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata,
271 int *trclen);
272bfa_status_t bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata,
273 int *trclen);
274u32 bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr);
275u32 bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr);
276void bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc);
277bfa_boolean_t bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc);
278void bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
279 struct bfa_ioc_hbfail_notify_s *notify);
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800280bfa_boolean_t bfa_ioc_sem_get(bfa_os_addr_t sem_reg);
281void bfa_ioc_sem_release(bfa_os_addr_t sem_reg);
282void bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc);
283void bfa_ioc_fwver_get(struct bfa_ioc_s *ioc,
284 struct bfi_ioc_image_hdr_s *fwhdr);
285bfa_boolean_t bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc,
286 struct bfi_ioc_image_hdr_s *fwhdr);
Jing Huang7725ccf2009-09-23 17:46:15 -0700287
288/*
289 * bfa mfg wwn API functions
290 */
291wwn_t bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc);
292wwn_t bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc);
293wwn_t bfa_ioc_get_wwn_naa5(struct bfa_ioc_s *ioc, u16 inst);
294mac_t bfa_ioc_get_mac(struct bfa_ioc_s *ioc);
295u64 bfa_ioc_get_adid(struct bfa_ioc_s *ioc);
296
297#endif /* __BFA_IOC_H__ */
298