2 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
23 #include "bfa_defs_svc.h"
29 typedef void (*bfa_isr_func_t) (struct bfa_s *bfa, struct bfi_msg_s *m);
30 typedef void (*bfa_cb_cbfn_t) (void *cbarg, bfa_boolean_t complete);
33 * Interrupt message handlers
35 void bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m);
38 * Request and response queue related defines
40 #define BFA_REQQ_NELEMS_MIN (4)
41 #define BFA_RSPQ_NELEMS_MIN (4)
43 #define bfa_reqq_pi(__bfa, __reqq) ((__bfa)->iocfc.req_cq_pi[__reqq])
44 #define bfa_reqq_ci(__bfa, __reqq) \
45 (*(u32 *)((__bfa)->iocfc.req_cq_shadow_ci[__reqq].kva))
47 #define bfa_reqq_full(__bfa, __reqq) \
48 (((bfa_reqq_pi(__bfa, __reqq) + 1) & \
49 ((__bfa)->iocfc.cfg.drvcfg.num_reqq_elems - 1)) == \
50 bfa_reqq_ci(__bfa, __reqq))
52 #define bfa_reqq_next(__bfa, __reqq) \
53 (bfa_reqq_full(__bfa, __reqq) ? NULL : \
54 ((void *)((struct bfi_msg_s *)((__bfa)->iocfc.req_cq_ba[__reqq].kva) \
55 + bfa_reqq_pi((__bfa), (__reqq)))))
57 #define bfa_reqq_produce(__bfa, __reqq, __mh) do { \
58 (__mh).mtag.h2i.qid = (__bfa)->iocfc.hw_qid[__reqq];\
59 (__bfa)->iocfc.req_cq_pi[__reqq]++; \
60 (__bfa)->iocfc.req_cq_pi[__reqq] &= \
61 ((__bfa)->iocfc.cfg.drvcfg.num_reqq_elems - 1); \
62 writel((__bfa)->iocfc.req_cq_pi[__reqq], \
63 (__bfa)->iocfc.bfa_regs.cpe_q_pi[__reqq]); \
67 #define bfa_rspq_pi(__bfa, __rspq) \
68 (*(u32 *)((__bfa)->iocfc.rsp_cq_shadow_pi[__rspq].kva))
70 #define bfa_rspq_ci(__bfa, __rspq) ((__bfa)->iocfc.rsp_cq_ci[__rspq])
71 #define bfa_rspq_elem(__bfa, __rspq, __ci) \
72 (&((struct bfi_msg_s *)((__bfa)->iocfc.rsp_cq_ba[__rspq].kva))[__ci])
74 #define CQ_INCR(__index, __size) do { \
76 (__index) &= ((__size) - 1); \
80 * Queue element to wait for room in request queue. FIFO order is
81 * maintained when fullfilling requests.
83 struct bfa_reqq_wait_s {
85 void (*qresume) (void *cbarg);
90 * Circular queue usage assignments
93 BFA_REQQ_IOC = 0, /* all low-priority IOC msgs */
94 BFA_REQQ_FCXP = 0, /* all FCXP messages */
95 BFA_REQQ_LPS = 0, /* all lport service msgs */
96 BFA_REQQ_PORT = 0, /* all port messages */
97 BFA_REQQ_FLASH = 0, /* for flash module */
98 BFA_REQQ_DIAG = 0, /* for diag module */
99 BFA_REQQ_RPORT = 0, /* all port messages */
100 BFA_REQQ_SBOOT = 0, /* all san boot messages */
101 BFA_REQQ_QOS_LO = 1, /* all low priority IO */
102 BFA_REQQ_QOS_MD = 2, /* all medium priority IO */
103 BFA_REQQ_QOS_HI = 3, /* all high priority IO */
107 bfa_reqq_winit(struct bfa_reqq_wait_s *wqe, void (*qresume) (void *cbarg),
110 wqe->qresume = qresume;
114 #define bfa_reqq(__bfa, __reqq) (&(__bfa)->reqq_waitq[__reqq])
118 * bfa_reqq_wait(struct bfa_s *bfa, int reqq, struct bfa_reqq_wait_s *wqe)
120 #define bfa_reqq_wait(__bfa, __reqq, __wqe) do { \
122 struct list_head *waitq = bfa_reqq(__bfa, __reqq); \
124 WARN_ON(((__reqq) >= BFI_IOC_MAX_CQS)); \
125 WARN_ON(!((__wqe)->qresume && (__wqe)->cbarg)); \
127 list_add_tail(&(__wqe)->qe, waitq); \
130 #define bfa_reqq_wcancel(__wqe) list_del(&(__wqe)->qe)
134 * Generic BFA callback element.
143 #define bfa_cb_queue(__bfa, __hcb_qe, __cbfn, __cbarg) do { \
144 (__hcb_qe)->cbfn = (__cbfn); \
145 (__hcb_qe)->cbarg = (__cbarg); \
146 list_add_tail(&(__hcb_qe)->qe, &(__bfa)->comp_q); \
149 #define bfa_cb_dequeue(__hcb_qe) list_del(&(__hcb_qe)->qe)
151 #define bfa_cb_queue_once(__bfa, __hcb_qe, __cbfn, __cbarg) do { \
152 (__hcb_qe)->cbfn = (__cbfn); \
153 (__hcb_qe)->cbarg = (__cbarg); \
154 if (!(__hcb_qe)->once) { \
155 list_add_tail(&(__hcb_qe)->qe, &(__bfa)->comp_q); \
156 (__hcb_qe)->once = BFA_TRUE; \
160 #define bfa_cb_queue_done(__hcb_qe) do { \
161 (__hcb_qe)->once = BFA_FALSE; \
166 * PCI devices supported by the current BFA
173 extern char bfa_version[];
176 * BFA memory resources
179 BFA_MEM_TYPE_KVA = 1, /* Kernel Virtual Memory *(non-dma-able) */
180 BFA_MEM_TYPE_DMA = 2, /* DMA-able memory */
181 BFA_MEM_TYPE_MAX = BFA_MEM_TYPE_DMA,
184 struct bfa_mem_elem_s {
185 enum bfa_mem_type mem_type; /* see enum bfa_mem_type */
186 u32 mem_len; /* Total Length in Bytes */
187 u8 *kva; /* kernel virtual address */
188 u64 dma; /* dma address if DMA memory */
189 u8 *kva_curp; /* kva allocation cursor */
190 u64 dma_curp; /* dma allocation cursor */
193 struct bfa_meminfo_s {
194 struct bfa_mem_elem_s meminfo[BFA_MEM_TYPE_MAX];
196 #define bfa_meminfo_kva(_m) \
197 ((_m)->meminfo[BFA_MEM_TYPE_KVA - 1].kva_curp)
198 #define bfa_meminfo_dma_virt(_m) \
199 ((_m)->meminfo[BFA_MEM_TYPE_DMA - 1].kva_curp)
200 #define bfa_meminfo_dma_phys(_m) \
201 ((_m)->meminfo[BFA_MEM_TYPE_DMA - 1].dma_curp)
203 struct bfa_iocfc_regs_s {
204 void __iomem *intr_status;
205 void __iomem *intr_mask;
206 void __iomem *cpe_q_pi[BFI_IOC_MAX_CQS];
207 void __iomem *cpe_q_ci[BFI_IOC_MAX_CQS];
208 void __iomem *cpe_q_ctrl[BFI_IOC_MAX_CQS];
209 void __iomem *rme_q_ci[BFI_IOC_MAX_CQS];
210 void __iomem *rme_q_pi[BFI_IOC_MAX_CQS];
211 void __iomem *rme_q_ctrl[BFI_IOC_MAX_CQS];
215 * MSIX vector handlers
217 #define BFA_MSIX_MAX_VECTORS 22
218 typedef void (*bfa_msix_handler_t)(struct bfa_s *bfa, int vec);
221 bfa_msix_handler_t handler[BFA_MSIX_MAX_VECTORS];
225 * Chip specific interfaces
228 void (*hw_reginit)(struct bfa_s *bfa);
229 void (*hw_reqq_ack)(struct bfa_s *bfa, int reqq);
230 void (*hw_rspq_ack)(struct bfa_s *bfa, int rspq);
231 void (*hw_msix_init)(struct bfa_s *bfa, int nvecs);
232 void (*hw_msix_ctrl_install)(struct bfa_s *bfa);
233 void (*hw_msix_queue_install)(struct bfa_s *bfa);
234 void (*hw_msix_uninstall)(struct bfa_s *bfa);
235 void (*hw_isr_mode_set)(struct bfa_s *bfa, bfa_boolean_t msix);
236 void (*hw_msix_getvecs)(struct bfa_s *bfa, u32 *vecmap,
237 u32 *nvecs, u32 *maxvec);
238 void (*hw_msix_get_rme_range) (struct bfa_s *bfa, u32 *start,
243 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
245 struct bfa_faa_cbfn_s {
246 bfa_cb_iocfc_t faa_cbfn;
250 #define BFA_FAA_ENABLED 1
251 #define BFA_FAA_DISABLED 2
256 struct bfa_faa_attr_s {
263 struct bfa_faa_args_s {
264 struct bfa_faa_attr_s *faa_attr;
265 struct bfa_faa_cbfn_s faa_cb;
272 struct bfa_iocfc_cfg_s cfg;
274 u32 req_cq_pi[BFI_IOC_MAX_CQS];
275 u32 rsp_cq_ci[BFI_IOC_MAX_CQS];
276 u8 hw_qid[BFI_IOC_MAX_CQS];
277 struct bfa_cb_qe_s init_hcb_qe;
278 struct bfa_cb_qe_s stop_hcb_qe;
279 struct bfa_cb_qe_s dis_hcb_qe;
280 struct bfa_cb_qe_s stats_hcb_qe;
281 bfa_boolean_t cfgdone;
283 struct bfa_dma_s cfg_info;
284 struct bfi_iocfc_cfg_s *cfginfo;
285 struct bfa_dma_s cfgrsp_dma;
286 struct bfi_iocfc_cfgrsp_s *cfgrsp;
287 struct bfa_dma_s req_cq_ba[BFI_IOC_MAX_CQS];
288 struct bfa_dma_s req_cq_shadow_ci[BFI_IOC_MAX_CQS];
289 struct bfa_dma_s rsp_cq_ba[BFI_IOC_MAX_CQS];
290 struct bfa_dma_s rsp_cq_shadow_pi[BFI_IOC_MAX_CQS];
291 struct bfa_iocfc_regs_s bfa_regs; /* BFA device registers */
292 struct bfa_hwif_s hwif;
293 bfa_cb_iocfc_t updateq_cbfn; /* bios callback function */
294 void *updateq_cbarg; /* bios callback arg */
296 struct bfa_faa_args_s faa_args;
299 #define bfa_fn_lpu(__bfa) \
300 bfi_fn_lpu(bfa_ioc_pcifn(&(__bfa)->ioc), bfa_ioc_portid(&(__bfa)->ioc))
301 #define bfa_msix_init(__bfa, __nvecs) \
302 ((__bfa)->iocfc.hwif.hw_msix_init(__bfa, __nvecs))
303 #define bfa_msix_ctrl_install(__bfa) \
304 ((__bfa)->iocfc.hwif.hw_msix_ctrl_install(__bfa))
305 #define bfa_msix_queue_install(__bfa) \
306 ((__bfa)->iocfc.hwif.hw_msix_queue_install(__bfa))
307 #define bfa_msix_uninstall(__bfa) \
308 ((__bfa)->iocfc.hwif.hw_msix_uninstall(__bfa))
309 #define bfa_isr_rspq_ack(__bfa, __queue) do { \
310 if ((__bfa)->iocfc.hwif.hw_rspq_ack) \
311 (__bfa)->iocfc.hwif.hw_rspq_ack(__bfa, __queue); \
313 #define bfa_isr_reqq_ack(__bfa, __queue) do { \
314 if ((__bfa)->iocfc.hwif.hw_reqq_ack) \
315 (__bfa)->iocfc.hwif.hw_reqq_ack(__bfa, __queue); \
317 #define bfa_isr_mode_set(__bfa, __msix) do { \
318 if ((__bfa)->iocfc.hwif.hw_isr_mode_set) \
319 (__bfa)->iocfc.hwif.hw_isr_mode_set(__bfa, __msix); \
321 #define bfa_msix_getvecs(__bfa, __vecmap, __nvecs, __maxvec) \
322 ((__bfa)->iocfc.hwif.hw_msix_getvecs(__bfa, __vecmap, \
324 #define bfa_msix_get_rme_range(__bfa, __start, __end) \
325 ((__bfa)->iocfc.hwif.hw_msix_get_rme_range(__bfa, __start, __end))
326 #define bfa_msix(__bfa, __vec) \
327 ((__bfa)->msix.handler[__vec](__bfa, __vec))
330 * FC specific IOC functions.
332 void bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
334 void bfa_iocfc_attach(struct bfa_s *bfa, void *bfad,
335 struct bfa_iocfc_cfg_s *cfg,
336 struct bfa_meminfo_s *meminfo,
337 struct bfa_pcidev_s *pcidev);
338 void bfa_iocfc_init(struct bfa_s *bfa);
339 void bfa_iocfc_start(struct bfa_s *bfa);
340 void bfa_iocfc_stop(struct bfa_s *bfa);
341 void bfa_iocfc_isr(void *bfa, struct bfi_mbmsg_s *msg);
342 void bfa_iocfc_set_snsbase(struct bfa_s *bfa, u64 snsbase_pa);
343 bfa_boolean_t bfa_iocfc_is_operational(struct bfa_s *bfa);
344 void bfa_iocfc_reset_queues(struct bfa_s *bfa);
346 void bfa_msix_all(struct bfa_s *bfa, int vec);
347 void bfa_msix_reqq(struct bfa_s *bfa, int vec);
348 void bfa_msix_rspq(struct bfa_s *bfa, int vec);
349 void bfa_msix_lpu_err(struct bfa_s *bfa, int vec);
351 void bfa_hwcb_reginit(struct bfa_s *bfa);
352 void bfa_hwcb_rspq_ack(struct bfa_s *bfa, int rspq);
353 void bfa_hwcb_msix_init(struct bfa_s *bfa, int nvecs);
354 void bfa_hwcb_msix_ctrl_install(struct bfa_s *bfa);
355 void bfa_hwcb_msix_queue_install(struct bfa_s *bfa);
356 void bfa_hwcb_msix_uninstall(struct bfa_s *bfa);
357 void bfa_hwcb_isr_mode_set(struct bfa_s *bfa, bfa_boolean_t msix);
358 void bfa_hwcb_msix_getvecs(struct bfa_s *bfa, u32 *vecmap, u32 *nvecs,
360 void bfa_hwcb_msix_get_rme_range(struct bfa_s *bfa, u32 *start,
362 void bfa_hwct_reginit(struct bfa_s *bfa);
363 void bfa_hwct2_reginit(struct bfa_s *bfa);
364 void bfa_hwct_reqq_ack(struct bfa_s *bfa, int rspq);
365 void bfa_hwct_rspq_ack(struct bfa_s *bfa, int rspq);
366 void bfa_hwct_msix_init(struct bfa_s *bfa, int nvecs);
367 void bfa_hwct_msix_ctrl_install(struct bfa_s *bfa);
368 void bfa_hwct_msix_queue_install(struct bfa_s *bfa);
369 void bfa_hwct_msix_uninstall(struct bfa_s *bfa);
370 void bfa_hwct_isr_mode_set(struct bfa_s *bfa, bfa_boolean_t msix);
371 void bfa_hwct_msix_getvecs(struct bfa_s *bfa, u32 *vecmap, u32 *nvecs,
373 void bfa_hwct_msix_get_rme_range(struct bfa_s *bfa, u32 *start,
375 void bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns);
376 wwn_t bfa_iocfc_get_pwwn(struct bfa_s *bfa);
377 wwn_t bfa_iocfc_get_nwwn(struct bfa_s *bfa);
378 int bfa_iocfc_get_pbc_vports(struct bfa_s *bfa,
379 struct bfi_pbc_vport_s *pbc_vport);
383 *----------------------------------------------------------------------
384 * BFA public interfaces
385 *----------------------------------------------------------------------
387 #define bfa_stats(_mod, _stats) ((_mod)->stats._stats++)
388 #define bfa_ioc_get_stats(__bfa, __ioc_stats) \
389 bfa_ioc_fetch_stats(&(__bfa)->ioc, __ioc_stats)
390 #define bfa_ioc_clear_stats(__bfa) \
391 bfa_ioc_clr_stats(&(__bfa)->ioc)
392 #define bfa_get_nports(__bfa) \
393 bfa_ioc_get_nports(&(__bfa)->ioc)
394 #define bfa_get_adapter_manufacturer(__bfa, __manufacturer) \
395 bfa_ioc_get_adapter_manufacturer(&(__bfa)->ioc, __manufacturer)
396 #define bfa_get_adapter_model(__bfa, __model) \
397 bfa_ioc_get_adapter_model(&(__bfa)->ioc, __model)
398 #define bfa_get_adapter_serial_num(__bfa, __serial_num) \
399 bfa_ioc_get_adapter_serial_num(&(__bfa)->ioc, __serial_num)
400 #define bfa_get_adapter_fw_ver(__bfa, __fw_ver) \
401 bfa_ioc_get_adapter_fw_ver(&(__bfa)->ioc, __fw_ver)
402 #define bfa_get_adapter_optrom_ver(__bfa, __optrom_ver) \
403 bfa_ioc_get_adapter_optrom_ver(&(__bfa)->ioc, __optrom_ver)
404 #define bfa_get_pci_chip_rev(__bfa, __chip_rev) \
405 bfa_ioc_get_pci_chip_rev(&(__bfa)->ioc, __chip_rev)
406 #define bfa_get_ioc_state(__bfa) \
407 bfa_ioc_get_state(&(__bfa)->ioc)
408 #define bfa_get_type(__bfa) \
409 bfa_ioc_get_type(&(__bfa)->ioc)
410 #define bfa_get_mac(__bfa) \
411 bfa_ioc_get_mac(&(__bfa)->ioc)
412 #define bfa_get_mfg_mac(__bfa) \
413 bfa_ioc_get_mfg_mac(&(__bfa)->ioc)
414 #define bfa_get_fw_clock_res(__bfa) \
415 ((__bfa)->iocfc.cfgrsp->fwcfg.fw_tick_res)
417 void bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids);
418 void bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg);
419 void bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg);
420 void bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg,
421 struct bfa_meminfo_s *meminfo);
422 void bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
423 struct bfa_meminfo_s *meminfo,
424 struct bfa_pcidev_s *pcidev);
425 void bfa_detach(struct bfa_s *bfa);
426 void bfa_cb_init(void *bfad, bfa_status_t status);
427 void bfa_cb_updateq(void *bfad, bfa_status_t status);
429 bfa_boolean_t bfa_intx(struct bfa_s *bfa);
430 void bfa_isr_enable(struct bfa_s *bfa);
431 void bfa_isr_disable(struct bfa_s *bfa);
433 void bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q);
434 void bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q);
435 void bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q);
437 typedef void (*bfa_cb_ioc_t) (void *cbarg, enum bfa_status status);
438 void bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr);
441 bfa_status_t bfa_iocfc_israttr_set(struct bfa_s *bfa,
442 struct bfa_iocfc_intr_attr_s *attr);
444 void bfa_iocfc_enable(struct bfa_s *bfa);
445 void bfa_iocfc_disable(struct bfa_s *bfa);
446 #define bfa_timer_start(_bfa, _timer, _timercb, _arg, _timeout) \
447 bfa_timer_begin(&(_bfa)->timer_mod, _timer, _timercb, _arg, _timeout)
449 #endif /* __BFA_H__ */