blob: 90e0f81ae425d5ef593933a7a046e1d6b76caca9 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * 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
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070018#include "bfa_modules.h"
19#include "bfi_ctreg.h"
20#include "bfad_drv.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070021
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070022BFA_TRC_FILE(HAL, CORE);
Jing Huang7725ccf2009-09-23 17:46:15 -070023
Jing Huang5fbe25c2010-10-18 17:17:23 -070024/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070025 * BFA IOC FC related definitions
26 */
27
Jing Huang5fbe25c2010-10-18 17:17:23 -070028/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070029 * IOC local definitions
30 */
31#define BFA_IOCFC_TOV 5000 /* msecs */
32
33enum {
34 BFA_IOCFC_ACT_NONE = 0,
35 BFA_IOCFC_ACT_INIT = 1,
36 BFA_IOCFC_ACT_STOP = 2,
37 BFA_IOCFC_ACT_DISABLE = 3,
38};
39
40#define DEF_CFG_NUM_FABRICS 1
41#define DEF_CFG_NUM_LPORTS 256
42#define DEF_CFG_NUM_CQS 4
43#define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
44#define DEF_CFG_NUM_TSKIM_REQS 128
45#define DEF_CFG_NUM_FCXP_REQS 64
46#define DEF_CFG_NUM_UF_BUFS 64
47#define DEF_CFG_NUM_RPORTS 1024
48#define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
49#define DEF_CFG_NUM_TINS 256
50
51#define DEF_CFG_NUM_SGPGS 2048
52#define DEF_CFG_NUM_REQQ_ELEMS 256
53#define DEF_CFG_NUM_RSPQ_ELEMS 64
54#define DEF_CFG_NUM_SBOOT_TGTS 16
55#define DEF_CFG_NUM_SBOOT_LUNS 16
56
Jing Huang5fbe25c2010-10-18 17:17:23 -070057/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070058 * forward declaration for IOC FC functions
59 */
60static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
61static void bfa_iocfc_disable_cbfn(void *bfa_arg);
62static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
63static void bfa_iocfc_reset_cbfn(void *bfa_arg);
64static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
65
Jing Huang5fbe25c2010-10-18 17:17:23 -070066/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070067 * BFA Interrupt handling functions
68 */
69static void
70bfa_msix_errint(struct bfa_s *bfa, u32 intr)
71{
72 bfa_ioc_error_isr(&bfa->ioc);
73}
74
75static void
76bfa_msix_lpu(struct bfa_s *bfa)
77{
78 bfa_ioc_mbox_isr(&bfa->ioc);
79}
80
81static void
82bfa_reqq_resume(struct bfa_s *bfa, int qid)
83{
84 struct list_head *waitq, *qe, *qen;
85 struct bfa_reqq_wait_s *wqe;
86
87 waitq = bfa_reqq(bfa, qid);
88 list_for_each_safe(qe, qen, waitq) {
Jing Huang5fbe25c2010-10-18 17:17:23 -070089 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070090 * Callback only as long as there is room in request queue
91 */
92 if (bfa_reqq_full(bfa, qid))
93 break;
94
95 list_del(qe);
96 wqe = (struct bfa_reqq_wait_s *) qe;
97 wqe->qresume(wqe->cbarg);
98 }
99}
100
101void
102bfa_msix_all(struct bfa_s *bfa, int vec)
103{
104 bfa_intx(bfa);
105}
106
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700107bfa_boolean_t
108bfa_intx(struct bfa_s *bfa)
109{
110 u32 intr, qintr;
111 int queue;
112
Jing Huang53440262010-10-18 17:12:29 -0700113 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700114 if (!intr)
115 return BFA_FALSE;
116
Jing Huang5fbe25c2010-10-18 17:17:23 -0700117 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700118 * RME completion queue interrupt
119 */
120 qintr = intr & __HFN_INT_RME_MASK;
Jing Huang53440262010-10-18 17:12:29 -0700121 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700122
123 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
124 if (intr & (__HFN_INT_RME_Q0 << queue))
125 bfa_msix_rspq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
126 }
127 intr &= ~qintr;
128 if (!intr)
129 return BFA_TRUE;
130
Jing Huang5fbe25c2010-10-18 17:17:23 -0700131 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700132 * CPE completion queue interrupt
133 */
134 qintr = intr & __HFN_INT_CPE_MASK;
Jing Huang53440262010-10-18 17:12:29 -0700135 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700136
137 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
138 if (intr & (__HFN_INT_CPE_Q0 << queue))
139 bfa_msix_reqq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
140 }
141 intr &= ~qintr;
142 if (!intr)
143 return BFA_TRUE;
144
145 bfa_msix_lpu_err(bfa, intr);
146
147 return BFA_TRUE;
148}
149
150void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700151bfa_isr_enable(struct bfa_s *bfa)
152{
153 u32 intr_unmask;
154 int pci_func = bfa_ioc_pcifn(&bfa->ioc);
155
156 bfa_trc(bfa, pci_func);
157
158 bfa_msix_install(bfa);
159 intr_unmask = (__HFN_INT_ERR_EMC | __HFN_INT_ERR_LPU0 |
160 __HFN_INT_ERR_LPU1 | __HFN_INT_ERR_PSS |
161 __HFN_INT_LL_HALT);
162
163 if (pci_func == 0)
164 intr_unmask |= (__HFN_INT_CPE_Q0 | __HFN_INT_CPE_Q1 |
165 __HFN_INT_CPE_Q2 | __HFN_INT_CPE_Q3 |
166 __HFN_INT_RME_Q0 | __HFN_INT_RME_Q1 |
167 __HFN_INT_RME_Q2 | __HFN_INT_RME_Q3 |
168 __HFN_INT_MBOX_LPU0);
169 else
170 intr_unmask |= (__HFN_INT_CPE_Q4 | __HFN_INT_CPE_Q5 |
171 __HFN_INT_CPE_Q6 | __HFN_INT_CPE_Q7 |
172 __HFN_INT_RME_Q4 | __HFN_INT_RME_Q5 |
173 __HFN_INT_RME_Q6 | __HFN_INT_RME_Q7 |
174 __HFN_INT_MBOX_LPU1);
175
Jing Huang53440262010-10-18 17:12:29 -0700176 writel(intr_unmask, bfa->iocfc.bfa_regs.intr_status);
177 writel(~intr_unmask, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700178 bfa->iocfc.intr_mask = ~intr_unmask;
179 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
180}
181
182void
183bfa_isr_disable(struct bfa_s *bfa)
184{
185 bfa_isr_mode_set(bfa, BFA_FALSE);
Jing Huang53440262010-10-18 17:12:29 -0700186 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700187 bfa_msix_uninstall(bfa);
188}
189
190void
191bfa_msix_reqq(struct bfa_s *bfa, int qid)
192{
193 struct list_head *waitq;
194
195 qid &= (BFI_IOC_MAX_CQS - 1);
196
197 bfa->iocfc.hwif.hw_reqq_ack(bfa, qid);
198
Jing Huang5fbe25c2010-10-18 17:17:23 -0700199 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700200 * Resume any pending requests in the corresponding reqq.
201 */
202 waitq = bfa_reqq(bfa, qid);
203 if (!list_empty(waitq))
204 bfa_reqq_resume(bfa, qid);
205}
206
207void
208bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
209{
210 bfa_trc(bfa, m->mhdr.msg_class);
211 bfa_trc(bfa, m->mhdr.msg_id);
212 bfa_trc(bfa, m->mhdr.mtag.i2htok);
213 bfa_assert(0);
214 bfa_trc_stop(bfa->trcmod);
215}
216
217void
218bfa_msix_rspq(struct bfa_s *bfa, int qid)
219{
220 struct bfi_msg_s *m;
221 u32 pi, ci;
222 struct list_head *waitq;
223
224 bfa_trc_fp(bfa, qid);
225
226 qid &= (BFI_IOC_MAX_CQS - 1);
227
228 bfa->iocfc.hwif.hw_rspq_ack(bfa, qid);
229
230 ci = bfa_rspq_ci(bfa, qid);
231 pi = bfa_rspq_pi(bfa, qid);
232
233 bfa_trc_fp(bfa, ci);
234 bfa_trc_fp(bfa, pi);
235
236 if (bfa->rme_process) {
237 while (ci != pi) {
238 m = bfa_rspq_elem(bfa, qid, ci);
239 bfa_assert_fp(m->mhdr.msg_class < BFI_MC_MAX);
240
241 bfa_isrs[m->mhdr.msg_class] (bfa, m);
242
243 CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
244 }
245 }
246
Jing Huang5fbe25c2010-10-18 17:17:23 -0700247 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700248 * update CI
249 */
250 bfa_rspq_ci(bfa, qid) = pi;
Jing Huang53440262010-10-18 17:12:29 -0700251 writel(pi, bfa->iocfc.bfa_regs.rme_q_ci[qid]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700252 mmiowb();
253
Jing Huang5fbe25c2010-10-18 17:17:23 -0700254 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700255 * Resume any pending requests in the corresponding reqq.
256 */
257 waitq = bfa_reqq(bfa, qid);
258 if (!list_empty(waitq))
259 bfa_reqq_resume(bfa, qid);
260}
261
262void
263bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
264{
265 u32 intr, curr_value;
266
Jing Huang53440262010-10-18 17:12:29 -0700267 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700268
269 if (intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1))
270 bfa_msix_lpu(bfa);
271
272 intr &= (__HFN_INT_ERR_EMC | __HFN_INT_ERR_LPU0 |
273 __HFN_INT_ERR_LPU1 | __HFN_INT_ERR_PSS | __HFN_INT_LL_HALT);
274
275 if (intr) {
276 if (intr & __HFN_INT_LL_HALT) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700277 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700278 * If LL_HALT bit is set then FW Init Halt LL Port
279 * Register needs to be cleared as well so Interrupt
280 * Status Register will be cleared.
281 */
Jing Huang53440262010-10-18 17:12:29 -0700282 curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700283 curr_value &= ~__FW_INIT_HALT_P;
Jing Huang53440262010-10-18 17:12:29 -0700284 writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700285 }
286
287 if (intr & __HFN_INT_ERR_PSS) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700288 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700289 * ERR_PSS bit needs to be cleared as well in case
290 * interrups are shared so driver's interrupt handler is
291 * still called eventhough it is already masked out.
292 */
Jing Huang53440262010-10-18 17:12:29 -0700293 curr_value = readl(
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700294 bfa->ioc.ioc_regs.pss_err_status_reg);
295 curr_value &= __PSS_ERR_STATUS_SET;
Jing Huang53440262010-10-18 17:12:29 -0700296 writel(curr_value,
297 bfa->ioc.ioc_regs.pss_err_status_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700298 }
299
Jing Huang53440262010-10-18 17:12:29 -0700300 writel(intr, bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700301 bfa_msix_errint(bfa, intr);
302 }
303}
304
Jing Huang5fbe25c2010-10-18 17:17:23 -0700305/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700306 * BFA IOC FC related functions
307 */
308
Jing Huang5fbe25c2010-10-18 17:17:23 -0700309/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -0800310 * BFA IOC private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700311 */
312
313static void
314bfa_iocfc_cqs_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
315{
316 int i, per_reqq_sz, per_rspq_sz;
317
318 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
319 BFA_DMA_ALIGN_SZ);
320 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
321 BFA_DMA_ALIGN_SZ);
322
323 /*
324 * Calculate CQ size
325 */
326 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
327 *dm_len = *dm_len + per_reqq_sz;
328 *dm_len = *dm_len + per_rspq_sz;
329 }
330
331 /*
332 * Calculate Shadow CI/PI size
333 */
334 for (i = 0; i < cfg->fwcfg.num_cqs; i++)
335 *dm_len += (2 * BFA_CACHELINE_SZ);
336}
337
338static void
339bfa_iocfc_fw_cfg_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
340{
341 *dm_len +=
342 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
343 *dm_len +=
344 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
345 BFA_CACHELINE_SZ);
346}
347
Jing Huang5fbe25c2010-10-18 17:17:23 -0700348/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700349 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
350 */
351static void
352bfa_iocfc_send_cfg(void *bfa_arg)
353{
354 struct bfa_s *bfa = bfa_arg;
355 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
356 struct bfi_iocfc_cfg_req_s cfg_req;
357 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
358 struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
359 int i;
360
361 bfa_assert(cfg->fwcfg.num_cqs <= BFI_IOC_MAX_CQS);
362 bfa_trc(bfa, cfg->fwcfg.num_cqs);
363
364 bfa_iocfc_reset_queues(bfa);
365
Jing Huang5fbe25c2010-10-18 17:17:23 -0700366 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700367 * initialize IOC configuration info
368 */
369 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
370 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
371
372 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700373 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374 * dma map REQ and RSP circular queues and shadow pointers
375 */
376 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
377 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
378 iocfc->req_cq_ba[i].pa);
379 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
380 iocfc->req_cq_shadow_ci[i].pa);
381 cfg_info->req_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700382 cpu_to_be16(cfg->drvcfg.num_reqq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700383
384 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
385 iocfc->rsp_cq_ba[i].pa);
386 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
387 iocfc->rsp_cq_shadow_pi[i].pa);
388 cfg_info->rsp_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700389 cpu_to_be16(cfg->drvcfg.num_rspq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700390 }
391
Jing Huang5fbe25c2010-10-18 17:17:23 -0700392 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700393 * Enable interrupt coalescing if it is driver init path
394 * and not ioc disable/enable path.
395 */
396 if (!iocfc->cfgdone)
397 cfg_info->intr_attr.coalesce = BFA_TRUE;
398
399 iocfc->cfgdone = BFA_FALSE;
400
Jing Huang5fbe25c2010-10-18 17:17:23 -0700401 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700402 * dma map IOC configuration itself
403 */
404 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
405 bfa_lpuid(bfa));
406 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
407
408 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
409 sizeof(struct bfi_iocfc_cfg_req_s));
410}
411
412static void
413bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
414 struct bfa_pcidev_s *pcidev)
415{
416 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
417
418 bfa->bfad = bfad;
419 iocfc->bfa = bfa;
420 iocfc->action = BFA_IOCFC_ACT_NONE;
421
Jing Huang6a18b162010-10-18 17:08:54 -0700422 iocfc->cfg = *cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700423
Jing Huang5fbe25c2010-10-18 17:17:23 -0700424 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700425 * Initialize chip specific handlers.
426 */
427 if (bfa_asic_id_ct(bfa_ioc_devid(&bfa->ioc))) {
428 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
429 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
430 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
431 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
432 iocfc->hwif.hw_msix_install = bfa_hwct_msix_install;
433 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
434 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
435 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
436 iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
437 } else {
438 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
439 iocfc->hwif.hw_reqq_ack = bfa_hwcb_reqq_ack;
440 iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
441 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
442 iocfc->hwif.hw_msix_install = bfa_hwcb_msix_install;
443 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
444 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
445 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
446 iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
447 }
448
449 iocfc->hwif.hw_reginit(bfa);
450 bfa->msix.nvecs = 0;
451}
452
453static void
454bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg,
455 struct bfa_meminfo_s *meminfo)
456{
457 u8 *dm_kva;
458 u64 dm_pa;
459 int i, per_reqq_sz, per_rspq_sz;
460 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
461 int dbgsz;
462
463 dm_kva = bfa_meminfo_dma_virt(meminfo);
464 dm_pa = bfa_meminfo_dma_phys(meminfo);
465
466 /*
467 * First allocate dma memory for IOC.
468 */
469 bfa_ioc_mem_claim(&bfa->ioc, dm_kva, dm_pa);
470 dm_kva += bfa_ioc_meminfo();
471 dm_pa += bfa_ioc_meminfo();
472
473 /*
474 * Claim DMA-able memory for the request/response queues and for shadow
475 * ci/pi registers
476 */
477 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
478 BFA_DMA_ALIGN_SZ);
479 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
480 BFA_DMA_ALIGN_SZ);
481
482 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
483 iocfc->req_cq_ba[i].kva = dm_kva;
484 iocfc->req_cq_ba[i].pa = dm_pa;
Jing Huang6a18b162010-10-18 17:08:54 -0700485 memset(dm_kva, 0, per_reqq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700486 dm_kva += per_reqq_sz;
487 dm_pa += per_reqq_sz;
488
489 iocfc->rsp_cq_ba[i].kva = dm_kva;
490 iocfc->rsp_cq_ba[i].pa = dm_pa;
Jing Huang6a18b162010-10-18 17:08:54 -0700491 memset(dm_kva, 0, per_rspq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700492 dm_kva += per_rspq_sz;
493 dm_pa += per_rspq_sz;
494 }
495
496 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
497 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
498 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
499 dm_kva += BFA_CACHELINE_SZ;
500 dm_pa += BFA_CACHELINE_SZ;
501
502 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
503 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
504 dm_kva += BFA_CACHELINE_SZ;
505 dm_pa += BFA_CACHELINE_SZ;
506 }
507
508 /*
509 * Claim DMA-able memory for the config info page
510 */
511 bfa->iocfc.cfg_info.kva = dm_kva;
512 bfa->iocfc.cfg_info.pa = dm_pa;
513 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
514 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
515 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
516
517 /*
518 * Claim DMA-able memory for the config response
519 */
520 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
521 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
522 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
523
524 dm_kva +=
525 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
526 BFA_CACHELINE_SZ);
527 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
528 BFA_CACHELINE_SZ);
529
530
531 bfa_meminfo_dma_virt(meminfo) = dm_kva;
532 bfa_meminfo_dma_phys(meminfo) = dm_pa;
533
534 dbgsz = bfa_ioc_debug_trcsz(bfa_auto_recover);
535 if (dbgsz > 0) {
536 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_meminfo_kva(meminfo));
537 bfa_meminfo_kva(meminfo) += dbgsz;
538 }
539}
540
Jing Huang5fbe25c2010-10-18 17:17:23 -0700541/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700542 * Start BFA submodules.
543 */
544static void
545bfa_iocfc_start_submod(struct bfa_s *bfa)
546{
547 int i;
548
549 bfa->rme_process = BFA_TRUE;
550
551 for (i = 0; hal_mods[i]; i++)
552 hal_mods[i]->start(bfa);
553}
554
Jing Huang5fbe25c2010-10-18 17:17:23 -0700555/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700556 * Disable BFA submodules.
557 */
558static void
559bfa_iocfc_disable_submod(struct bfa_s *bfa)
560{
561 int i;
562
563 for (i = 0; hal_mods[i]; i++)
564 hal_mods[i]->iocdisable(bfa);
565}
566
567static void
568bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
569{
570 struct bfa_s *bfa = bfa_arg;
571
572 if (complete) {
573 if (bfa->iocfc.cfgdone)
574 bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
575 else
576 bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
577 } else {
578 if (bfa->iocfc.cfgdone)
579 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
580 }
581}
582
583static void
584bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
585{
586 struct bfa_s *bfa = bfa_arg;
587 struct bfad_s *bfad = bfa->bfad;
588
589 if (compl)
590 complete(&bfad->comp);
591 else
592 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
593}
594
595static void
596bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
597{
598 struct bfa_s *bfa = bfa_arg;
599 struct bfad_s *bfad = bfa->bfad;
600
601 if (compl)
602 complete(&bfad->disable_comp);
603}
604
Jing Huang5fbe25c2010-10-18 17:17:23 -0700605/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700606 * Update BFA configuration from firmware configuration.
607 */
608static void
609bfa_iocfc_cfgrsp(struct bfa_s *bfa)
610{
611 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
612 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
613 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
614
615 fwcfg->num_cqs = fwcfg->num_cqs;
Jing Huangba816ea2010-10-18 17:10:50 -0700616 fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
617 fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
618 fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
619 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
620 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700621
622 iocfc->cfgdone = BFA_TRUE;
623
Jing Huang5fbe25c2010-10-18 17:17:23 -0700624 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700625 * Configuration is complete - initialize/start submodules
626 */
627 bfa_fcport_init(bfa);
628
629 if (iocfc->action == BFA_IOCFC_ACT_INIT)
630 bfa_cb_queue(bfa, &iocfc->init_hcb_qe, bfa_iocfc_init_cb, bfa);
631 else
632 bfa_iocfc_start_submod(bfa);
633}
634void
635bfa_iocfc_reset_queues(struct bfa_s *bfa)
636{
637 int q;
638
639 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
640 bfa_reqq_ci(bfa, q) = 0;
641 bfa_reqq_pi(bfa, q) = 0;
642 bfa_rspq_ci(bfa, q) = 0;
643 bfa_rspq_pi(bfa, q) = 0;
644 }
645}
646
Jing Huang5fbe25c2010-10-18 17:17:23 -0700647/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700648 * IOC enable request is complete
649 */
650static void
651bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
652{
653 struct bfa_s *bfa = bfa_arg;
654
655 if (status != BFA_STATUS_OK) {
656 bfa_isr_disable(bfa);
657 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
658 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
659 bfa_iocfc_init_cb, bfa);
660 return;
661 }
662
663 bfa_iocfc_send_cfg(bfa);
664}
665
Jing Huang5fbe25c2010-10-18 17:17:23 -0700666/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700667 * IOC disable request is complete
668 */
669static void
670bfa_iocfc_disable_cbfn(void *bfa_arg)
671{
672 struct bfa_s *bfa = bfa_arg;
673
674 bfa_isr_disable(bfa);
675 bfa_iocfc_disable_submod(bfa);
676
677 if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
678 bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
679 bfa);
680 else {
681 bfa_assert(bfa->iocfc.action == BFA_IOCFC_ACT_DISABLE);
682 bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
683 bfa);
684 }
685}
686
Jing Huang5fbe25c2010-10-18 17:17:23 -0700687/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700688 * Notify sub-modules of hardware failure.
689 */
690static void
691bfa_iocfc_hbfail_cbfn(void *bfa_arg)
692{
693 struct bfa_s *bfa = bfa_arg;
694
695 bfa->rme_process = BFA_FALSE;
696
697 bfa_isr_disable(bfa);
698 bfa_iocfc_disable_submod(bfa);
699
700 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
701 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
702 bfa);
703}
704
Jing Huang5fbe25c2010-10-18 17:17:23 -0700705/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700706 * Actions on chip-reset completion.
707 */
708static void
709bfa_iocfc_reset_cbfn(void *bfa_arg)
710{
711 struct bfa_s *bfa = bfa_arg;
712
713 bfa_iocfc_reset_queues(bfa);
714 bfa_isr_enable(bfa);
715}
716
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700717
Jing Huang5fbe25c2010-10-18 17:17:23 -0700718/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700719 * Query IOC memory requirement information.
720 */
721void
722bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
723 u32 *dm_len)
724{
725 /* dma memory for IOC */
726 *dm_len += bfa_ioc_meminfo();
727
728 bfa_iocfc_fw_cfg_sz(cfg, dm_len);
729 bfa_iocfc_cqs_sz(cfg, dm_len);
730 *km_len += bfa_ioc_debug_trcsz(bfa_auto_recover);
731}
732
Jing Huang5fbe25c2010-10-18 17:17:23 -0700733/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700734 * Query IOC memory requirement information.
735 */
736void
737bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
738 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
739{
740 int i;
741 struct bfa_ioc_s *ioc = &bfa->ioc;
742
743 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
744 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
745 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
746 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
747
748 ioc->trcmod = bfa->trcmod;
749 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
750
Jing Huang5fbe25c2010-10-18 17:17:23 -0700751 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700752 * Set FC mode for BFA_PCI_DEVICE_ID_CT_FC.
753 */
754 if (pcidev->device_id == BFA_PCI_DEVICE_ID_CT_FC)
755 bfa_ioc_set_fcmode(&bfa->ioc);
756
757 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_MC_IOCFC);
758 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
759
760 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
761 bfa_iocfc_mem_claim(bfa, cfg, meminfo);
762 bfa_timer_init(&bfa->timer_mod);
763
764 INIT_LIST_HEAD(&bfa->comp_q);
765 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
766 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
767}
768
Jing Huang5fbe25c2010-10-18 17:17:23 -0700769/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700770 * Query IOC memory requirement information.
771 */
772void
773bfa_iocfc_detach(struct bfa_s *bfa)
774{
775 bfa_ioc_detach(&bfa->ioc);
776}
777
Jing Huang5fbe25c2010-10-18 17:17:23 -0700778/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700779 * Query IOC memory requirement information.
780 */
781void
782bfa_iocfc_init(struct bfa_s *bfa)
783{
784 bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
785 bfa_ioc_enable(&bfa->ioc);
786}
787
Jing Huang5fbe25c2010-10-18 17:17:23 -0700788/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700789 * IOC start called from bfa_start(). Called to start IOC operations
790 * at driver instantiation for this instance.
791 */
792void
793bfa_iocfc_start(struct bfa_s *bfa)
794{
795 if (bfa->iocfc.cfgdone)
796 bfa_iocfc_start_submod(bfa);
797}
798
Jing Huang5fbe25c2010-10-18 17:17:23 -0700799/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700800 * IOC stop called from bfa_stop(). Called only when driver is unloaded
801 * for this instance.
802 */
803void
804bfa_iocfc_stop(struct bfa_s *bfa)
805{
806 bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
807
808 bfa->rme_process = BFA_FALSE;
809 bfa_ioc_disable(&bfa->ioc);
810}
811
812void
813bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
814{
815 struct bfa_s *bfa = bfaarg;
816 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
817 union bfi_iocfc_i2h_msg_u *msg;
818
819 msg = (union bfi_iocfc_i2h_msg_u *) m;
820 bfa_trc(bfa, msg->mh.msg_id);
821
822 switch (msg->mh.msg_id) {
823 case BFI_IOCFC_I2H_CFG_REPLY:
824 iocfc->cfg_reply = &msg->cfg_reply;
825 bfa_iocfc_cfgrsp(bfa);
826 break;
827 case BFI_IOCFC_I2H_UPDATEQ_RSP:
828 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
829 break;
830 default:
831 bfa_assert(0);
832 }
833}
834
835void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700836bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
837{
838 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
839
840 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
841
842 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
Jing Huangba816ea2010-10-18 17:10:50 -0700843 be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
844 be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700845
846 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
Jing Huangba816ea2010-10-18 17:10:50 -0700847 be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
848 be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849
850 attr->config = iocfc->cfg;
851}
852
853bfa_status_t
854bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
855{
856 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
857 struct bfi_iocfc_set_intr_req_s *m;
858
859 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
Jing Huangba816ea2010-10-18 17:10:50 -0700860 iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
861 iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700862
863 if (!bfa_iocfc_is_operational(bfa))
864 return BFA_STATUS_OK;
865
866 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
867 if (!m)
868 return BFA_STATUS_DEVBUSY;
869
870 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
871 bfa_lpuid(bfa));
872 m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
873 m->delay = iocfc->cfginfo->intr_attr.delay;
874 m->latency = iocfc->cfginfo->intr_attr.latency;
875
876 bfa_trc(bfa, attr->delay);
877 bfa_trc(bfa, attr->latency);
878
879 bfa_reqq_produce(bfa, BFA_REQQ_IOC);
880 return BFA_STATUS_OK;
881}
882
883void
884bfa_iocfc_set_snsbase(struct bfa_s *bfa, u64 snsbase_pa)
885{
886 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
887
888 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
889 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase, snsbase_pa);
890}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700891/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700892 * Enable IOC after it is disabled.
893 */
894void
895bfa_iocfc_enable(struct bfa_s *bfa)
896{
897 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
898 "IOC Enable");
899 bfa_ioc_enable(&bfa->ioc);
900}
901
902void
903bfa_iocfc_disable(struct bfa_s *bfa)
904{
905 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
906 "IOC Disable");
907 bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
908
909 bfa->rme_process = BFA_FALSE;
910 bfa_ioc_disable(&bfa->ioc);
911}
912
913
914bfa_boolean_t
915bfa_iocfc_is_operational(struct bfa_s *bfa)
916{
917 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
918}
919
Jing Huang5fbe25c2010-10-18 17:17:23 -0700920/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700921 * Return boot target port wwns -- read from boot information in flash.
922 */
923void
924bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
925{
926 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
927 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
928 int i;
929
930 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
931 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
932 *nwwns = cfgrsp->pbc_cfg.nbluns;
933 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
934 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
935
936 return;
937 }
938
939 *nwwns = cfgrsp->bootwwns.nwwns;
940 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
941}
942
943void
944bfa_iocfc_get_pbc_boot_cfg(struct bfa_s *bfa, struct bfa_boot_pbc_s *pbcfg)
945{
946 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
947 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
948
949 pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
950 pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
951 pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
952 memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
953}
954
955int
956bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
957{
958 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
959 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
960
961 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
962 return cfgrsp->pbc_cfg.nvports;
963}
964
Jing Huang7725ccf2009-09-23 17:46:15 -0700965
Jing Huang5fbe25c2010-10-18 17:17:23 -0700966/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700967 * Use this function query the memory requirement of the BFA library.
968 * This function needs to be called before bfa_attach() to get the
969 * memory required of the BFA layer for a given driver configuration.
970 *
971 * This call will fail, if the cap is out of range compared to pre-defined
972 * values within the BFA library
973 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700974 * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
975 * its configuration in this structure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700976 * The default values for struct bfa_iocfc_cfg_s can be
977 * fetched using bfa_cfg_get_default() API.
978 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700979 * If cap's boundary check fails, the library will use
Jing Huang7725ccf2009-09-23 17:46:15 -0700980 * the default bfa_cap_t values (and log a warning msg).
981 *
982 * @param[out] meminfo - pointer to bfa_meminfo_t. This content
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700983 * indicates the memory type (see bfa_mem_type_t) and
Jing Huang7725ccf2009-09-23 17:46:15 -0700984 * amount of memory required.
985 *
986 * Driver should allocate the memory, populate the
987 * starting address for each block and provide the same
988 * structure as input parameter to bfa_attach() call.
989 *
990 * @return void
991 *
992 * Special Considerations: @note
993 */
994void
995bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo)
996{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700997 int i;
998 u32 km_len = 0, dm_len = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -0700999
1000 bfa_assert((cfg != NULL) && (meminfo != NULL));
1001
Jing Huang6a18b162010-10-18 17:08:54 -07001002 memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001003 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_type =
1004 BFA_MEM_TYPE_KVA;
1005 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_type =
1006 BFA_MEM_TYPE_DMA;
1007
1008 bfa_iocfc_meminfo(cfg, &km_len, &dm_len);
1009
1010 for (i = 0; hal_mods[i]; i++)
1011 hal_mods[i]->meminfo(cfg, &km_len, &dm_len);
1012
Krishna Gudipati7873ca42010-05-21 14:39:45 -07001013 dm_len += bfa_port_meminfo();
Jing Huang7725ccf2009-09-23 17:46:15 -07001014
1015 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_len = km_len;
1016 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len;
1017}
1018
Jing Huang5fbe25c2010-10-18 17:17:23 -07001019/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001020 * Use this function to do attach the driver instance with the BFA
1021 * library. This function will not trigger any HW initialization
1022 * process (which will be done in bfa_init() call)
1023 *
1024 * This call will fail, if the cap is out of range compared to
1025 * pre-defined values within the BFA library
1026 *
1027 * @param[out] bfa Pointer to bfa_t.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001028 * @param[in] bfad Opaque handle back to the driver's IOC structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001029 * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001030 * that was used in bfa_cfg_get_meminfo().
1031 * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
1032 * use the bfa_cfg_get_meminfo() call to
1033 * find the memory blocks required, allocate the
1034 * required memory and provide the starting addresses.
1035 * @param[in] pcidev pointer to struct bfa_pcidev_s
Jing Huang7725ccf2009-09-23 17:46:15 -07001036 *
1037 * @return
1038 * void
1039 *
1040 * Special Considerations:
1041 *
1042 * @note
1043 *
1044 */
1045void
1046bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1047 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1048{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001049 int i;
1050 struct bfa_mem_elem_s *melem;
Jing Huang7725ccf2009-09-23 17:46:15 -07001051
1052 bfa->fcs = BFA_FALSE;
1053
1054 bfa_assert((cfg != NULL) && (meminfo != NULL));
1055
Jing Huang5fbe25c2010-10-18 17:17:23 -07001056 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001057 * initialize all memory pointers for iterative allocation
1058 */
1059 for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
1060 melem = meminfo->meminfo + i;
1061 melem->kva_curp = melem->kva;
1062 melem->dma_curp = melem->dma;
1063 }
1064
1065 bfa_iocfc_attach(bfa, bfad, cfg, meminfo, pcidev);
1066
1067 for (i = 0; hal_mods[i]; i++)
1068 hal_mods[i]->attach(bfa, bfad, cfg, meminfo, pcidev);
1069
Krishna Gudipati7873ca42010-05-21 14:39:45 -07001070 bfa_com_port_attach(bfa, meminfo);
Jing Huang7725ccf2009-09-23 17:46:15 -07001071}
1072
Jing Huang5fbe25c2010-10-18 17:17:23 -07001073/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001074 * Use this function to delete a BFA IOC. IOC should be stopped (by
1075 * calling bfa_stop()) before this function call.
1076 *
1077 * @param[in] bfa - pointer to bfa_t.
1078 *
1079 * @return
1080 * void
1081 *
1082 * Special Considerations:
1083 *
1084 * @note
1085 */
1086void
1087bfa_detach(struct bfa_s *bfa)
1088{
1089 int i;
1090
1091 for (i = 0; hal_mods[i]; i++)
1092 hal_mods[i]->detach(bfa);
1093
1094 bfa_iocfc_detach(bfa);
1095}
1096
1097
1098void
1099bfa_init_trc(struct bfa_s *bfa, struct bfa_trc_mod_s *trcmod)
1100{
1101 bfa->trcmod = trcmod;
1102}
1103
Jing Huang7725ccf2009-09-23 17:46:15 -07001104void
1105bfa_init_plog(struct bfa_s *bfa, struct bfa_plog_s *plog)
1106{
1107 bfa->plog = plog;
1108}
1109
Jing Huang5fbe25c2010-10-18 17:17:23 -07001110/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001111 * Initialize IOC.
1112 *
1113 * This function will return immediately, when the IOC initialization is
1114 * completed, the bfa_cb_init() will be called.
1115 *
1116 * @param[in] bfa instance
1117 *
1118 * @return void
1119 *
1120 * Special Considerations:
1121 *
1122 * @note
1123 * When this function returns, the driver should register the interrupt service
1124 * routine(s) and enable the device interrupts. If this is not done,
1125 * bfa_cb_init() will never get called
1126 */
1127void
1128bfa_init(struct bfa_s *bfa)
1129{
1130 bfa_iocfc_init(bfa);
1131}
1132
Jing Huang5fbe25c2010-10-18 17:17:23 -07001133/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001134 * Use this function initiate the IOC configuration setup. This function
1135 * will return immediately.
1136 *
1137 * @param[in] bfa instance
1138 *
1139 * @return None
1140 */
1141void
1142bfa_start(struct bfa_s *bfa)
1143{
1144 bfa_iocfc_start(bfa);
1145}
1146
Jing Huang5fbe25c2010-10-18 17:17:23 -07001147/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001148 * Use this function quiese the IOC. This function will return immediately,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001149 * when the IOC is actually stopped, the bfad->comp will be set.
Jing Huang7725ccf2009-09-23 17:46:15 -07001150 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001151 * @param[in]bfa - pointer to bfa_t.
Jing Huang7725ccf2009-09-23 17:46:15 -07001152 *
1153 * @return None
1154 *
1155 * Special Considerations:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001156 * bfad->comp can be set before or after bfa_stop() returns.
Jing Huang7725ccf2009-09-23 17:46:15 -07001157 *
1158 * @note
1159 * In case of any failure, we could handle it automatically by doing a
1160 * reset and then succeed the bfa_stop() call.
1161 */
1162void
1163bfa_stop(struct bfa_s *bfa)
1164{
1165 bfa_iocfc_stop(bfa);
1166}
1167
1168void
1169bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
1170{
1171 INIT_LIST_HEAD(comp_q);
1172 list_splice_tail_init(&bfa->comp_q, comp_q);
1173}
1174
1175void
1176bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
1177{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001178 struct list_head *qe;
1179 struct list_head *qen;
1180 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001181
1182 list_for_each_safe(qe, qen, comp_q) {
1183 hcb_qe = (struct bfa_cb_qe_s *) qe;
1184 hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
1185 }
1186}
1187
1188void
1189bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
1190{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001191 struct list_head *qe;
1192 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001193
1194 while (!list_empty(comp_q)) {
1195 bfa_q_deq(comp_q, &qe);
1196 hcb_qe = (struct bfa_cb_qe_s *) qe;
1197 hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
1198 }
1199}
1200
1201void
1202bfa_attach_fcs(struct bfa_s *bfa)
1203{
1204 bfa->fcs = BFA_TRUE;
1205}
1206
Jing Huang5fbe25c2010-10-18 17:17:23 -07001207/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001208 * Periodic timer heart beat from driver
1209 */
1210void
1211bfa_timer_tick(struct bfa_s *bfa)
1212{
1213 bfa_timer_beat(&bfa->timer_mod);
1214}
1215
Jing Huang5fbe25c2010-10-18 17:17:23 -07001216/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001217 * Return the list of PCI vendor/device id lists supported by this
1218 * BFA instance.
1219 */
1220void
1221bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
1222{
1223 static struct bfa_pciid_s __pciids[] = {
1224 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
1225 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
1226 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
Jing Huang293f82d2010-07-08 19:45:20 -07001227 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
Jing Huang7725ccf2009-09-23 17:46:15 -07001228 };
1229
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001230 *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001231 *pciids = __pciids;
1232}
1233
Jing Huang5fbe25c2010-10-18 17:17:23 -07001234/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001235 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
1236 * into BFA layer). The OS driver can then turn back and overwrite entries that
1237 * have been configured by the user.
1238 *
1239 * @param[in] cfg - pointer to bfa_ioc_cfg_t
1240 *
1241 * @return
1242 * void
1243 *
1244 * Special Considerations:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001245 * note
Jing Huang7725ccf2009-09-23 17:46:15 -07001246 */
1247void
1248bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
1249{
1250 cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
1251 cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
1252 cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
1253 cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
1254 cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
1255 cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
1256 cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
1257 cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
1258
1259 cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
1260 cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
1261 cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
1262 cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
1263 cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
1264 cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
1265 cfg->drvcfg.ioc_recover = BFA_FALSE;
1266 cfg->drvcfg.delay_comp = BFA_FALSE;
1267
1268}
1269
1270void
1271bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
1272{
1273 bfa_cfg_get_default(cfg);
1274 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
1275 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
1276 cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
1277 cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
1278 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
1279
1280 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
1281 cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
1282 cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001283 cfg->drvcfg.min_cfg = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001284}
1285
1286void
1287bfa_get_attr(struct bfa_s *bfa, struct bfa_ioc_attr_s *ioc_attr)
1288{
1289 bfa_ioc_get_attr(&bfa->ioc, ioc_attr);
1290}
1291
Jing Huang5fbe25c2010-10-18 17:17:23 -07001292/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001293 * Retrieve firmware trace information on IOC failure.
1294 */
1295bfa_status_t
1296bfa_debug_fwsave(struct bfa_s *bfa, void *trcdata, int *trclen)
1297{
1298 return bfa_ioc_debug_fwsave(&bfa->ioc, trcdata, trclen);
1299}
1300
Jing Huang5fbe25c2010-10-18 17:17:23 -07001301/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001302 * Fetch firmware trace data.
Jing Huang7725ccf2009-09-23 17:46:15 -07001303 *
1304 * @param[in] bfa BFA instance
1305 * @param[out] trcdata Firmware trace buffer
1306 * @param[in,out] trclen Firmware trace buffer len
1307 *
1308 * @retval BFA_STATUS_OK Firmware trace is fetched.
1309 * @retval BFA_STATUS_INPROGRESS Firmware trace fetch is in progress.
1310 */
1311bfa_status_t
1312bfa_debug_fwtrc(struct bfa_s *bfa, void *trcdata, int *trclen)
1313{
1314 return bfa_ioc_debug_fwtrc(&bfa->ioc, trcdata, trclen);
1315}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001316
Jing Huang5fbe25c2010-10-18 17:17:23 -07001317/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001318 * Dump firmware memory.
1319 *
1320 * @param[in] bfa BFA instance
1321 * @param[out] buf buffer for dump
1322 * @param[in,out] offset smem offset to start read
1323 * @param[in,out] buflen length of buffer
1324 *
1325 * @retval BFA_STATUS_OK Firmware memory is dumped.
1326 * @retval BFA_STATUS_INPROGRESS Firmware memory dump is in progress.
1327 */
1328bfa_status_t
1329bfa_debug_fwcore(struct bfa_s *bfa, void *buf, u32 *offset, int *buflen)
1330{
1331 return bfa_ioc_debug_fwcore(&bfa->ioc, buf, offset, buflen);
1332}