blob: 002907c694af625c371646658dd26d762c8ec697 [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
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070070bfa_reqq_resume(struct bfa_s *bfa, int qid)
71{
72 struct list_head *waitq, *qe, *qen;
73 struct bfa_reqq_wait_s *wqe;
74
75 waitq = bfa_reqq(bfa, qid);
76 list_for_each_safe(qe, qen, waitq) {
Jing Huang5fbe25c2010-10-18 17:17:23 -070077 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070078 * Callback only as long as there is room in request queue
79 */
80 if (bfa_reqq_full(bfa, qid))
81 break;
82
83 list_del(qe);
84 wqe = (struct bfa_reqq_wait_s *) qe;
85 wqe->qresume(wqe->cbarg);
86 }
87}
88
89void
90bfa_msix_all(struct bfa_s *bfa, int vec)
91{
92 bfa_intx(bfa);
93}
94
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070095bfa_boolean_t
96bfa_intx(struct bfa_s *bfa)
97{
98 u32 intr, qintr;
99 int queue;
100
Jing Huang53440262010-10-18 17:12:29 -0700101 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700102 if (!intr)
103 return BFA_FALSE;
104
Jing Huang5fbe25c2010-10-18 17:17:23 -0700105 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700106 * RME completion queue interrupt
107 */
108 qintr = intr & __HFN_INT_RME_MASK;
Jing Huang53440262010-10-18 17:12:29 -0700109 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700110
111 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
112 if (intr & (__HFN_INT_RME_Q0 << queue))
113 bfa_msix_rspq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
114 }
115 intr &= ~qintr;
116 if (!intr)
117 return BFA_TRUE;
118
Jing Huang5fbe25c2010-10-18 17:17:23 -0700119 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700120 * CPE completion queue interrupt
121 */
122 qintr = intr & __HFN_INT_CPE_MASK;
Jing Huang53440262010-10-18 17:12:29 -0700123 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700124
125 for (queue = 0; queue < BFI_IOC_MAX_CQS_ASIC; queue++) {
126 if (intr & (__HFN_INT_CPE_Q0 << queue))
127 bfa_msix_reqq(bfa, queue & (BFI_IOC_MAX_CQS - 1));
128 }
129 intr &= ~qintr;
130 if (!intr)
131 return BFA_TRUE;
132
133 bfa_msix_lpu_err(bfa, intr);
134
135 return BFA_TRUE;
136}
137
138void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700139bfa_isr_enable(struct bfa_s *bfa)
140{
141 u32 intr_unmask;
142 int pci_func = bfa_ioc_pcifn(&bfa->ioc);
143
144 bfa_trc(bfa, pci_func);
145
146 bfa_msix_install(bfa);
147 intr_unmask = (__HFN_INT_ERR_EMC | __HFN_INT_ERR_LPU0 |
148 __HFN_INT_ERR_LPU1 | __HFN_INT_ERR_PSS |
149 __HFN_INT_LL_HALT);
150
151 if (pci_func == 0)
152 intr_unmask |= (__HFN_INT_CPE_Q0 | __HFN_INT_CPE_Q1 |
153 __HFN_INT_CPE_Q2 | __HFN_INT_CPE_Q3 |
154 __HFN_INT_RME_Q0 | __HFN_INT_RME_Q1 |
155 __HFN_INT_RME_Q2 | __HFN_INT_RME_Q3 |
156 __HFN_INT_MBOX_LPU0);
157 else
158 intr_unmask |= (__HFN_INT_CPE_Q4 | __HFN_INT_CPE_Q5 |
159 __HFN_INT_CPE_Q6 | __HFN_INT_CPE_Q7 |
160 __HFN_INT_RME_Q4 | __HFN_INT_RME_Q5 |
161 __HFN_INT_RME_Q6 | __HFN_INT_RME_Q7 |
162 __HFN_INT_MBOX_LPU1);
163
Jing Huang53440262010-10-18 17:12:29 -0700164 writel(intr_unmask, bfa->iocfc.bfa_regs.intr_status);
165 writel(~intr_unmask, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700166 bfa->iocfc.intr_mask = ~intr_unmask;
167 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
168}
169
170void
171bfa_isr_disable(struct bfa_s *bfa)
172{
173 bfa_isr_mode_set(bfa, BFA_FALSE);
Jing Huang53440262010-10-18 17:12:29 -0700174 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700175 bfa_msix_uninstall(bfa);
176}
177
178void
179bfa_msix_reqq(struct bfa_s *bfa, int qid)
180{
181 struct list_head *waitq;
182
183 qid &= (BFI_IOC_MAX_CQS - 1);
184
185 bfa->iocfc.hwif.hw_reqq_ack(bfa, qid);
186
Jing Huang5fbe25c2010-10-18 17:17:23 -0700187 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700188 * Resume any pending requests in the corresponding reqq.
189 */
190 waitq = bfa_reqq(bfa, qid);
191 if (!list_empty(waitq))
192 bfa_reqq_resume(bfa, qid);
193}
194
195void
196bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
197{
198 bfa_trc(bfa, m->mhdr.msg_class);
199 bfa_trc(bfa, m->mhdr.msg_id);
200 bfa_trc(bfa, m->mhdr.mtag.i2htok);
201 bfa_assert(0);
202 bfa_trc_stop(bfa->trcmod);
203}
204
205void
206bfa_msix_rspq(struct bfa_s *bfa, int qid)
207{
208 struct bfi_msg_s *m;
209 u32 pi, ci;
210 struct list_head *waitq;
211
212 bfa_trc_fp(bfa, qid);
213
214 qid &= (BFI_IOC_MAX_CQS - 1);
215
216 bfa->iocfc.hwif.hw_rspq_ack(bfa, qid);
217
218 ci = bfa_rspq_ci(bfa, qid);
219 pi = bfa_rspq_pi(bfa, qid);
220
221 bfa_trc_fp(bfa, ci);
222 bfa_trc_fp(bfa, pi);
223
224 if (bfa->rme_process) {
225 while (ci != pi) {
226 m = bfa_rspq_elem(bfa, qid, ci);
227 bfa_assert_fp(m->mhdr.msg_class < BFI_MC_MAX);
228
229 bfa_isrs[m->mhdr.msg_class] (bfa, m);
230
231 CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
232 }
233 }
234
Jing Huang5fbe25c2010-10-18 17:17:23 -0700235 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700236 * update CI
237 */
238 bfa_rspq_ci(bfa, qid) = pi;
Jing Huang53440262010-10-18 17:12:29 -0700239 writel(pi, bfa->iocfc.bfa_regs.rme_q_ci[qid]);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700240 mmiowb();
241
Jing Huang5fbe25c2010-10-18 17:17:23 -0700242 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700243 * Resume any pending requests in the corresponding reqq.
244 */
245 waitq = bfa_reqq(bfa, qid);
246 if (!list_empty(waitq))
247 bfa_reqq_resume(bfa, qid);
248}
249
250void
251bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
252{
253 u32 intr, curr_value;
254
Jing Huang53440262010-10-18 17:12:29 -0700255 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700256
257 if (intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1))
Maggie Zhangf7f738122010-12-09 19:08:43 -0800258 bfa_ioc_mbox_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700259
260 intr &= (__HFN_INT_ERR_EMC | __HFN_INT_ERR_LPU0 |
261 __HFN_INT_ERR_LPU1 | __HFN_INT_ERR_PSS | __HFN_INT_LL_HALT);
262
263 if (intr) {
264 if (intr & __HFN_INT_LL_HALT) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700265 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700266 * If LL_HALT bit is set then FW Init Halt LL Port
267 * Register needs to be cleared as well so Interrupt
268 * Status Register will be cleared.
269 */
Jing Huang53440262010-10-18 17:12:29 -0700270 curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700271 curr_value &= ~__FW_INIT_HALT_P;
Jing Huang53440262010-10-18 17:12:29 -0700272 writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700273 }
274
275 if (intr & __HFN_INT_ERR_PSS) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700276 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700277 * ERR_PSS bit needs to be cleared as well in case
278 * interrups are shared so driver's interrupt handler is
279 * still called eventhough it is already masked out.
280 */
Jing Huang53440262010-10-18 17:12:29 -0700281 curr_value = readl(
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700282 bfa->ioc.ioc_regs.pss_err_status_reg);
283 curr_value &= __PSS_ERR_STATUS_SET;
Jing Huang53440262010-10-18 17:12:29 -0700284 writel(curr_value,
285 bfa->ioc.ioc_regs.pss_err_status_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700286 }
287
Jing Huang53440262010-10-18 17:12:29 -0700288 writel(intr, bfa->iocfc.bfa_regs.intr_status);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800289 bfa_ioc_error_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700290 }
291}
292
Jing Huang5fbe25c2010-10-18 17:17:23 -0700293/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700294 * BFA IOC FC related functions
295 */
296
Jing Huang5fbe25c2010-10-18 17:17:23 -0700297/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -0800298 * BFA IOC private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700299 */
300
301static void
302bfa_iocfc_cqs_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
303{
304 int i, per_reqq_sz, per_rspq_sz;
305
306 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
307 BFA_DMA_ALIGN_SZ);
308 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
309 BFA_DMA_ALIGN_SZ);
310
311 /*
312 * Calculate CQ size
313 */
314 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
315 *dm_len = *dm_len + per_reqq_sz;
316 *dm_len = *dm_len + per_rspq_sz;
317 }
318
319 /*
320 * Calculate Shadow CI/PI size
321 */
322 for (i = 0; i < cfg->fwcfg.num_cqs; i++)
323 *dm_len += (2 * BFA_CACHELINE_SZ);
324}
325
326static void
327bfa_iocfc_fw_cfg_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
328{
329 *dm_len +=
330 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
331 *dm_len +=
332 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
333 BFA_CACHELINE_SZ);
334}
335
Jing Huang5fbe25c2010-10-18 17:17:23 -0700336/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700337 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
338 */
339static void
340bfa_iocfc_send_cfg(void *bfa_arg)
341{
342 struct bfa_s *bfa = bfa_arg;
343 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
344 struct bfi_iocfc_cfg_req_s cfg_req;
345 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
346 struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
347 int i;
348
349 bfa_assert(cfg->fwcfg.num_cqs <= BFI_IOC_MAX_CQS);
350 bfa_trc(bfa, cfg->fwcfg.num_cqs);
351
352 bfa_iocfc_reset_queues(bfa);
353
Jing Huang5fbe25c2010-10-18 17:17:23 -0700354 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700355 * initialize IOC configuration info
356 */
357 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
358 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
359
360 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700361 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700362 * dma map REQ and RSP circular queues and shadow pointers
363 */
364 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
365 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
366 iocfc->req_cq_ba[i].pa);
367 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
368 iocfc->req_cq_shadow_ci[i].pa);
369 cfg_info->req_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700370 cpu_to_be16(cfg->drvcfg.num_reqq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700371
372 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
373 iocfc->rsp_cq_ba[i].pa);
374 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
375 iocfc->rsp_cq_shadow_pi[i].pa);
376 cfg_info->rsp_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700377 cpu_to_be16(cfg->drvcfg.num_rspq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700378 }
379
Jing Huang5fbe25c2010-10-18 17:17:23 -0700380 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700381 * Enable interrupt coalescing if it is driver init path
382 * and not ioc disable/enable path.
383 */
384 if (!iocfc->cfgdone)
385 cfg_info->intr_attr.coalesce = BFA_TRUE;
386
387 iocfc->cfgdone = BFA_FALSE;
388
Jing Huang5fbe25c2010-10-18 17:17:23 -0700389 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700390 * dma map IOC configuration itself
391 */
392 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
393 bfa_lpuid(bfa));
394 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
395
396 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
397 sizeof(struct bfi_iocfc_cfg_req_s));
398}
399
400static void
401bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
402 struct bfa_pcidev_s *pcidev)
403{
404 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
405
406 bfa->bfad = bfad;
407 iocfc->bfa = bfa;
408 iocfc->action = BFA_IOCFC_ACT_NONE;
409
Jing Huang6a18b162010-10-18 17:08:54 -0700410 iocfc->cfg = *cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700411
Jing Huang5fbe25c2010-10-18 17:17:23 -0700412 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700413 * Initialize chip specific handlers.
414 */
415 if (bfa_asic_id_ct(bfa_ioc_devid(&bfa->ioc))) {
416 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
417 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
418 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
419 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
420 iocfc->hwif.hw_msix_install = bfa_hwct_msix_install;
421 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
422 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
423 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
424 iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
425 } else {
426 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
427 iocfc->hwif.hw_reqq_ack = bfa_hwcb_reqq_ack;
428 iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
429 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
430 iocfc->hwif.hw_msix_install = bfa_hwcb_msix_install;
431 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
432 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
433 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
434 iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
435 }
436
437 iocfc->hwif.hw_reginit(bfa);
438 bfa->msix.nvecs = 0;
439}
440
441static void
442bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg,
443 struct bfa_meminfo_s *meminfo)
444{
445 u8 *dm_kva;
446 u64 dm_pa;
447 int i, per_reqq_sz, per_rspq_sz;
448 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
449 int dbgsz;
450
451 dm_kva = bfa_meminfo_dma_virt(meminfo);
452 dm_pa = bfa_meminfo_dma_phys(meminfo);
453
454 /*
455 * First allocate dma memory for IOC.
456 */
457 bfa_ioc_mem_claim(&bfa->ioc, dm_kva, dm_pa);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800458 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
459 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700460
461 /*
462 * Claim DMA-able memory for the request/response queues and for shadow
463 * ci/pi registers
464 */
465 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
466 BFA_DMA_ALIGN_SZ);
467 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
468 BFA_DMA_ALIGN_SZ);
469
470 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
471 iocfc->req_cq_ba[i].kva = dm_kva;
472 iocfc->req_cq_ba[i].pa = dm_pa;
Jing Huang6a18b162010-10-18 17:08:54 -0700473 memset(dm_kva, 0, per_reqq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700474 dm_kva += per_reqq_sz;
475 dm_pa += per_reqq_sz;
476
477 iocfc->rsp_cq_ba[i].kva = dm_kva;
478 iocfc->rsp_cq_ba[i].pa = dm_pa;
Jing Huang6a18b162010-10-18 17:08:54 -0700479 memset(dm_kva, 0, per_rspq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700480 dm_kva += per_rspq_sz;
481 dm_pa += per_rspq_sz;
482 }
483
484 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
485 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
486 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
487 dm_kva += BFA_CACHELINE_SZ;
488 dm_pa += BFA_CACHELINE_SZ;
489
490 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
491 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
492 dm_kva += BFA_CACHELINE_SZ;
493 dm_pa += BFA_CACHELINE_SZ;
494 }
495
496 /*
497 * Claim DMA-able memory for the config info page
498 */
499 bfa->iocfc.cfg_info.kva = dm_kva;
500 bfa->iocfc.cfg_info.pa = dm_pa;
501 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
502 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
503 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
504
505 /*
506 * Claim DMA-able memory for the config response
507 */
508 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
509 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
510 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
511
512 dm_kva +=
513 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
514 BFA_CACHELINE_SZ);
515 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
516 BFA_CACHELINE_SZ);
517
518
519 bfa_meminfo_dma_virt(meminfo) = dm_kva;
520 bfa_meminfo_dma_phys(meminfo) = dm_pa;
521
Maggie Zhangf7f738122010-12-09 19:08:43 -0800522 dbgsz = (bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700523 if (dbgsz > 0) {
524 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_meminfo_kva(meminfo));
525 bfa_meminfo_kva(meminfo) += dbgsz;
526 }
527}
528
Jing Huang5fbe25c2010-10-18 17:17:23 -0700529/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700530 * Start BFA submodules.
531 */
532static void
533bfa_iocfc_start_submod(struct bfa_s *bfa)
534{
535 int i;
536
537 bfa->rme_process = BFA_TRUE;
538
539 for (i = 0; hal_mods[i]; i++)
540 hal_mods[i]->start(bfa);
541}
542
Jing Huang5fbe25c2010-10-18 17:17:23 -0700543/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700544 * Disable BFA submodules.
545 */
546static void
547bfa_iocfc_disable_submod(struct bfa_s *bfa)
548{
549 int i;
550
551 for (i = 0; hal_mods[i]; i++)
552 hal_mods[i]->iocdisable(bfa);
553}
554
555static void
556bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
557{
558 struct bfa_s *bfa = bfa_arg;
559
560 if (complete) {
561 if (bfa->iocfc.cfgdone)
562 bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
563 else
564 bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
565 } else {
566 if (bfa->iocfc.cfgdone)
567 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
568 }
569}
570
571static void
572bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
573{
574 struct bfa_s *bfa = bfa_arg;
575 struct bfad_s *bfad = bfa->bfad;
576
577 if (compl)
578 complete(&bfad->comp);
579 else
580 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
581}
582
583static void
584bfa_iocfc_disable_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->disable_comp);
591}
592
Jing Huang5fbe25c2010-10-18 17:17:23 -0700593/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700594 * Update BFA configuration from firmware configuration.
595 */
596static void
597bfa_iocfc_cfgrsp(struct bfa_s *bfa)
598{
599 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
600 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
601 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
602
603 fwcfg->num_cqs = fwcfg->num_cqs;
Jing Huangba816ea2010-10-18 17:10:50 -0700604 fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
605 fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
606 fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
607 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
608 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700609
610 iocfc->cfgdone = BFA_TRUE;
611
Jing Huang5fbe25c2010-10-18 17:17:23 -0700612 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700613 * Configuration is complete - initialize/start submodules
614 */
615 bfa_fcport_init(bfa);
616
617 if (iocfc->action == BFA_IOCFC_ACT_INIT)
618 bfa_cb_queue(bfa, &iocfc->init_hcb_qe, bfa_iocfc_init_cb, bfa);
619 else
620 bfa_iocfc_start_submod(bfa);
621}
622void
623bfa_iocfc_reset_queues(struct bfa_s *bfa)
624{
625 int q;
626
627 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
628 bfa_reqq_ci(bfa, q) = 0;
629 bfa_reqq_pi(bfa, q) = 0;
630 bfa_rspq_ci(bfa, q) = 0;
631 bfa_rspq_pi(bfa, q) = 0;
632 }
633}
634
Jing Huang5fbe25c2010-10-18 17:17:23 -0700635/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700636 * IOC enable request is complete
637 */
638static void
639bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
640{
641 struct bfa_s *bfa = bfa_arg;
642
643 if (status != BFA_STATUS_OK) {
644 bfa_isr_disable(bfa);
645 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
646 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
647 bfa_iocfc_init_cb, bfa);
648 return;
649 }
650
651 bfa_iocfc_send_cfg(bfa);
652}
653
Jing Huang5fbe25c2010-10-18 17:17:23 -0700654/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700655 * IOC disable request is complete
656 */
657static void
658bfa_iocfc_disable_cbfn(void *bfa_arg)
659{
660 struct bfa_s *bfa = bfa_arg;
661
662 bfa_isr_disable(bfa);
663 bfa_iocfc_disable_submod(bfa);
664
665 if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
666 bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
667 bfa);
668 else {
669 bfa_assert(bfa->iocfc.action == BFA_IOCFC_ACT_DISABLE);
670 bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
671 bfa);
672 }
673}
674
Jing Huang5fbe25c2010-10-18 17:17:23 -0700675/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700676 * Notify sub-modules of hardware failure.
677 */
678static void
679bfa_iocfc_hbfail_cbfn(void *bfa_arg)
680{
681 struct bfa_s *bfa = bfa_arg;
682
683 bfa->rme_process = BFA_FALSE;
684
685 bfa_isr_disable(bfa);
686 bfa_iocfc_disable_submod(bfa);
687
688 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
689 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
690 bfa);
691}
692
Jing Huang5fbe25c2010-10-18 17:17:23 -0700693/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700694 * Actions on chip-reset completion.
695 */
696static void
697bfa_iocfc_reset_cbfn(void *bfa_arg)
698{
699 struct bfa_s *bfa = bfa_arg;
700
701 bfa_iocfc_reset_queues(bfa);
702 bfa_isr_enable(bfa);
703}
704
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700705
Jing Huang5fbe25c2010-10-18 17:17:23 -0700706/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700707 * Query IOC memory requirement information.
708 */
709void
710bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
711 u32 *dm_len)
712{
713 /* dma memory for IOC */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800714 *dm_len += BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700715
716 bfa_iocfc_fw_cfg_sz(cfg, dm_len);
717 bfa_iocfc_cqs_sz(cfg, dm_len);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800718 *km_len += (bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700719}
720
Jing Huang5fbe25c2010-10-18 17:17:23 -0700721/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700722 * Query IOC memory requirement information.
723 */
724void
725bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
726 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
727{
728 int i;
729 struct bfa_ioc_s *ioc = &bfa->ioc;
730
731 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
732 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
733 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
734 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
735
736 ioc->trcmod = bfa->trcmod;
737 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
738
Jing Huang5fbe25c2010-10-18 17:17:23 -0700739 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700740 * Set FC mode for BFA_PCI_DEVICE_ID_CT_FC.
741 */
742 if (pcidev->device_id == BFA_PCI_DEVICE_ID_CT_FC)
743 bfa_ioc_set_fcmode(&bfa->ioc);
744
745 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_MC_IOCFC);
746 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
747
748 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
749 bfa_iocfc_mem_claim(bfa, cfg, meminfo);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800750 INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700751
752 INIT_LIST_HEAD(&bfa->comp_q);
753 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
754 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
755}
756
Jing Huang5fbe25c2010-10-18 17:17:23 -0700757/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700758 * Query IOC memory requirement information.
759 */
760void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700761bfa_iocfc_init(struct bfa_s *bfa)
762{
763 bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
764 bfa_ioc_enable(&bfa->ioc);
765}
766
Jing Huang5fbe25c2010-10-18 17:17:23 -0700767/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700768 * IOC start called from bfa_start(). Called to start IOC operations
769 * at driver instantiation for this instance.
770 */
771void
772bfa_iocfc_start(struct bfa_s *bfa)
773{
774 if (bfa->iocfc.cfgdone)
775 bfa_iocfc_start_submod(bfa);
776}
777
Jing Huang5fbe25c2010-10-18 17:17:23 -0700778/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700779 * IOC stop called from bfa_stop(). Called only when driver is unloaded
780 * for this instance.
781 */
782void
783bfa_iocfc_stop(struct bfa_s *bfa)
784{
785 bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
786
787 bfa->rme_process = BFA_FALSE;
788 bfa_ioc_disable(&bfa->ioc);
789}
790
791void
792bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
793{
794 struct bfa_s *bfa = bfaarg;
795 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
796 union bfi_iocfc_i2h_msg_u *msg;
797
798 msg = (union bfi_iocfc_i2h_msg_u *) m;
799 bfa_trc(bfa, msg->mh.msg_id);
800
801 switch (msg->mh.msg_id) {
802 case BFI_IOCFC_I2H_CFG_REPLY:
803 iocfc->cfg_reply = &msg->cfg_reply;
804 bfa_iocfc_cfgrsp(bfa);
805 break;
806 case BFI_IOCFC_I2H_UPDATEQ_RSP:
807 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
808 break;
809 default:
810 bfa_assert(0);
811 }
812}
813
814void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700815bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
816{
817 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
818
819 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
820
821 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
Jing Huangba816ea2010-10-18 17:10:50 -0700822 be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
823 be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700824
825 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
Jing Huangba816ea2010-10-18 17:10:50 -0700826 be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
827 be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700828
829 attr->config = iocfc->cfg;
830}
831
832bfa_status_t
833bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
834{
835 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
836 struct bfi_iocfc_set_intr_req_s *m;
837
838 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
Jing Huangba816ea2010-10-18 17:10:50 -0700839 iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
840 iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700841
842 if (!bfa_iocfc_is_operational(bfa))
843 return BFA_STATUS_OK;
844
845 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
846 if (!m)
847 return BFA_STATUS_DEVBUSY;
848
849 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
850 bfa_lpuid(bfa));
851 m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
852 m->delay = iocfc->cfginfo->intr_attr.delay;
853 m->latency = iocfc->cfginfo->intr_attr.latency;
854
855 bfa_trc(bfa, attr->delay);
856 bfa_trc(bfa, attr->latency);
857
858 bfa_reqq_produce(bfa, BFA_REQQ_IOC);
859 return BFA_STATUS_OK;
860}
861
862void
863bfa_iocfc_set_snsbase(struct bfa_s *bfa, u64 snsbase_pa)
864{
865 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
866
867 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
868 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase, snsbase_pa);
869}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700870/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700871 * Enable IOC after it is disabled.
872 */
873void
874bfa_iocfc_enable(struct bfa_s *bfa)
875{
876 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
877 "IOC Enable");
878 bfa_ioc_enable(&bfa->ioc);
879}
880
881void
882bfa_iocfc_disable(struct bfa_s *bfa)
883{
884 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
885 "IOC Disable");
886 bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
887
888 bfa->rme_process = BFA_FALSE;
889 bfa_ioc_disable(&bfa->ioc);
890}
891
892
893bfa_boolean_t
894bfa_iocfc_is_operational(struct bfa_s *bfa)
895{
896 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
897}
898
Jing Huang5fbe25c2010-10-18 17:17:23 -0700899/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700900 * Return boot target port wwns -- read from boot information in flash.
901 */
902void
903bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
904{
905 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
906 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
907 int i;
908
909 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
910 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
911 *nwwns = cfgrsp->pbc_cfg.nbluns;
912 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
913 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
914
915 return;
916 }
917
918 *nwwns = cfgrsp->bootwwns.nwwns;
919 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
920}
921
922void
923bfa_iocfc_get_pbc_boot_cfg(struct bfa_s *bfa, struct bfa_boot_pbc_s *pbcfg)
924{
925 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
926 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
927
928 pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
929 pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
930 pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
931 memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
932}
933
934int
935bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
936{
937 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
938 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
939
940 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
941 return cfgrsp->pbc_cfg.nvports;
942}
943
Jing Huang7725ccf2009-09-23 17:46:15 -0700944
Jing Huang5fbe25c2010-10-18 17:17:23 -0700945/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700946 * Use this function query the memory requirement of the BFA library.
947 * This function needs to be called before bfa_attach() to get the
948 * memory required of the BFA layer for a given driver configuration.
949 *
950 * This call will fail, if the cap is out of range compared to pre-defined
951 * values within the BFA library
952 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700953 * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
954 * its configuration in this structure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700955 * The default values for struct bfa_iocfc_cfg_s can be
956 * fetched using bfa_cfg_get_default() API.
957 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700958 * If cap's boundary check fails, the library will use
Jing Huang7725ccf2009-09-23 17:46:15 -0700959 * the default bfa_cap_t values (and log a warning msg).
960 *
961 * @param[out] meminfo - pointer to bfa_meminfo_t. This content
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700962 * indicates the memory type (see bfa_mem_type_t) and
Jing Huang7725ccf2009-09-23 17:46:15 -0700963 * amount of memory required.
964 *
965 * Driver should allocate the memory, populate the
966 * starting address for each block and provide the same
967 * structure as input parameter to bfa_attach() call.
968 *
969 * @return void
970 *
971 * Special Considerations: @note
972 */
973void
974bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo)
975{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976 int i;
977 u32 km_len = 0, dm_len = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -0700978
979 bfa_assert((cfg != NULL) && (meminfo != NULL));
980
Jing Huang6a18b162010-10-18 17:08:54 -0700981 memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -0700982 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_type =
983 BFA_MEM_TYPE_KVA;
984 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_type =
985 BFA_MEM_TYPE_DMA;
986
987 bfa_iocfc_meminfo(cfg, &km_len, &dm_len);
988
989 for (i = 0; hal_mods[i]; i++)
990 hal_mods[i]->meminfo(cfg, &km_len, &dm_len);
991
Krishna Gudipati7873ca42010-05-21 14:39:45 -0700992 dm_len += bfa_port_meminfo();
Jing Huang7725ccf2009-09-23 17:46:15 -0700993
994 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_len = km_len;
995 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len;
996}
997
Jing Huang5fbe25c2010-10-18 17:17:23 -0700998/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700999 * Use this function to do attach the driver instance with the BFA
1000 * library. This function will not trigger any HW initialization
1001 * process (which will be done in bfa_init() call)
1002 *
1003 * This call will fail, if the cap is out of range compared to
1004 * pre-defined values within the BFA library
1005 *
1006 * @param[out] bfa Pointer to bfa_t.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001007 * @param[in] bfad Opaque handle back to the driver's IOC structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001008 * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001009 * that was used in bfa_cfg_get_meminfo().
1010 * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
1011 * use the bfa_cfg_get_meminfo() call to
1012 * find the memory blocks required, allocate the
1013 * required memory and provide the starting addresses.
1014 * @param[in] pcidev pointer to struct bfa_pcidev_s
Jing Huang7725ccf2009-09-23 17:46:15 -07001015 *
1016 * @return
1017 * void
1018 *
1019 * Special Considerations:
1020 *
1021 * @note
1022 *
1023 */
1024void
1025bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1026 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1027{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001028 int i;
1029 struct bfa_mem_elem_s *melem;
Jing Huang7725ccf2009-09-23 17:46:15 -07001030
1031 bfa->fcs = BFA_FALSE;
1032
1033 bfa_assert((cfg != NULL) && (meminfo != NULL));
1034
Jing Huang5fbe25c2010-10-18 17:17:23 -07001035 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001036 * initialize all memory pointers for iterative allocation
1037 */
1038 for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
1039 melem = meminfo->meminfo + i;
1040 melem->kva_curp = melem->kva;
1041 melem->dma_curp = melem->dma;
1042 }
1043
1044 bfa_iocfc_attach(bfa, bfad, cfg, meminfo, pcidev);
1045
1046 for (i = 0; hal_mods[i]; i++)
1047 hal_mods[i]->attach(bfa, bfad, cfg, meminfo, pcidev);
1048
Krishna Gudipati7873ca42010-05-21 14:39:45 -07001049 bfa_com_port_attach(bfa, meminfo);
Jing Huang7725ccf2009-09-23 17:46:15 -07001050}
1051
Jing Huang5fbe25c2010-10-18 17:17:23 -07001052/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001053 * Use this function to delete a BFA IOC. IOC should be stopped (by
1054 * calling bfa_stop()) before this function call.
1055 *
1056 * @param[in] bfa - pointer to bfa_t.
1057 *
1058 * @return
1059 * void
1060 *
1061 * Special Considerations:
1062 *
1063 * @note
1064 */
1065void
1066bfa_detach(struct bfa_s *bfa)
1067{
1068 int i;
1069
1070 for (i = 0; hal_mods[i]; i++)
1071 hal_mods[i]->detach(bfa);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001072 bfa_ioc_detach(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001073}
1074
1075void
1076bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
1077{
1078 INIT_LIST_HEAD(comp_q);
1079 list_splice_tail_init(&bfa->comp_q, comp_q);
1080}
1081
1082void
1083bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
1084{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001085 struct list_head *qe;
1086 struct list_head *qen;
1087 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001088
1089 list_for_each_safe(qe, qen, comp_q) {
1090 hcb_qe = (struct bfa_cb_qe_s *) qe;
1091 hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
1092 }
1093}
1094
1095void
1096bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
1097{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001098 struct list_head *qe;
1099 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001100
1101 while (!list_empty(comp_q)) {
1102 bfa_q_deq(comp_q, &qe);
1103 hcb_qe = (struct bfa_cb_qe_s *) qe;
1104 hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
1105 }
1106}
1107
Jing Huang7725ccf2009-09-23 17:46:15 -07001108
Jing Huang5fbe25c2010-10-18 17:17:23 -07001109/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001110 * Return the list of PCI vendor/device id lists supported by this
1111 * BFA instance.
1112 */
1113void
1114bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
1115{
1116 static struct bfa_pciid_s __pciids[] = {
1117 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
1118 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
1119 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
Jing Huang293f82d2010-07-08 19:45:20 -07001120 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
Jing Huang7725ccf2009-09-23 17:46:15 -07001121 };
1122
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001123 *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001124 *pciids = __pciids;
1125}
1126
Jing Huang5fbe25c2010-10-18 17:17:23 -07001127/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001128 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
1129 * into BFA layer). The OS driver can then turn back and overwrite entries that
1130 * have been configured by the user.
1131 *
1132 * @param[in] cfg - pointer to bfa_ioc_cfg_t
1133 *
1134 * @return
1135 * void
1136 *
1137 * Special Considerations:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001138 * note
Jing Huang7725ccf2009-09-23 17:46:15 -07001139 */
1140void
1141bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
1142{
1143 cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
1144 cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
1145 cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
1146 cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
1147 cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
1148 cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
1149 cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
1150 cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
1151
1152 cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
1153 cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
1154 cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
1155 cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
1156 cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
1157 cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
1158 cfg->drvcfg.ioc_recover = BFA_FALSE;
1159 cfg->drvcfg.delay_comp = BFA_FALSE;
1160
1161}
1162
1163void
1164bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
1165{
1166 bfa_cfg_get_default(cfg);
1167 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
1168 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
1169 cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
1170 cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
1171 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
1172
1173 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
1174 cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
1175 cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176 cfg->drvcfg.min_cfg = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001177}