blob: 602dc3508ed81289142768380dc8dbfcc709725b [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
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019#include "bfa_modules.h"
Krishna Gudipati11189202011-06-13 15:50:35 -070020#include "bfi_reg.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/*
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080025 * BFA module list terminated by NULL
26 */
27static struct bfa_module_s *hal_mods[] = {
28 &hal_mod_sgpg,
29 &hal_mod_fcport,
30 &hal_mod_fcxp,
31 &hal_mod_lps,
32 &hal_mod_uf,
33 &hal_mod_rport,
Krishna Gudipatie2187d72011-06-13 15:53:58 -070034 &hal_mod_fcp,
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080035 NULL
36};
37
38/*
39 * Message handlers for various modules.
40 */
41static bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
42 bfa_isr_unhandled, /* NONE */
43 bfa_isr_unhandled, /* BFI_MC_IOC */
44 bfa_isr_unhandled, /* BFI_MC_DIAG */
45 bfa_isr_unhandled, /* BFI_MC_FLASH */
46 bfa_isr_unhandled, /* BFI_MC_CEE */
47 bfa_fcport_isr, /* BFI_MC_FCPORT */
48 bfa_isr_unhandled, /* BFI_MC_IOCFC */
49 bfa_isr_unhandled, /* BFI_MC_LL */
50 bfa_uf_isr, /* BFI_MC_UF */
51 bfa_fcxp_isr, /* BFI_MC_FCXP */
52 bfa_lps_isr, /* BFI_MC_LPS */
53 bfa_rport_isr, /* BFI_MC_RPORT */
Krishna Gudipatie2187d72011-06-13 15:53:58 -070054 bfa_itn_isr, /* BFI_MC_ITN */
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080055 bfa_isr_unhandled, /* BFI_MC_IOIM_READ */
56 bfa_isr_unhandled, /* BFI_MC_IOIM_WRITE */
57 bfa_isr_unhandled, /* BFI_MC_IOIM_IO */
58 bfa_ioim_isr, /* BFI_MC_IOIM */
59 bfa_ioim_good_comp_isr, /* BFI_MC_IOIM_IOCOM */
60 bfa_tskim_isr, /* BFI_MC_TSKIM */
61 bfa_isr_unhandled, /* BFI_MC_SBOOT */
62 bfa_isr_unhandled, /* BFI_MC_IPFC */
63 bfa_isr_unhandled, /* BFI_MC_PORT */
64 bfa_isr_unhandled, /* --------- */
65 bfa_isr_unhandled, /* --------- */
66 bfa_isr_unhandled, /* --------- */
67 bfa_isr_unhandled, /* --------- */
68 bfa_isr_unhandled, /* --------- */
69 bfa_isr_unhandled, /* --------- */
70 bfa_isr_unhandled, /* --------- */
71 bfa_isr_unhandled, /* --------- */
72 bfa_isr_unhandled, /* --------- */
73 bfa_isr_unhandled, /* --------- */
74};
75/*
76 * Message handlers for mailbox command classes
77 */
78static bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = {
79 NULL,
80 NULL, /* BFI_MC_IOC */
81 NULL, /* BFI_MC_DIAG */
82 NULL, /* BFI_MC_FLASH */
83 NULL, /* BFI_MC_CEE */
84 NULL, /* BFI_MC_PORT */
85 bfa_iocfc_isr, /* BFI_MC_IOCFC */
86 NULL,
87};
88
89
90
91static void
Krishna Gudipati45070252011-06-24 20:24:29 -070092bfa_com_port_attach(struct bfa_s *bfa)
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080093{
94 struct bfa_port_s *port = &bfa->modules.port;
Krishna Gudipati45070252011-06-24 20:24:29 -070095 struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080096
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080097 bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod);
Krishna Gudipati45070252011-06-24 20:24:29 -070098 bfa_port_mem_claim(port, port_dma->kva_curp, port_dma->dma_curp);
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080099}
100
101/*
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700102 * ablk module attach
103 */
104static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700105bfa_com_ablk_attach(struct bfa_s *bfa)
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700106{
107 struct bfa_ablk_s *ablk = &bfa->modules.ablk;
Krishna Gudipati45070252011-06-24 20:24:29 -0700108 struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700109
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700110 bfa_ablk_attach(ablk, &bfa->ioc);
Krishna Gudipati45070252011-06-24 20:24:29 -0700111 bfa_ablk_memclaim(ablk, ablk_dma->kva_curp, ablk_dma->dma_curp);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700112}
113
114/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700115 * BFA IOC FC related definitions
116 */
117
Jing Huang5fbe25c2010-10-18 17:17:23 -0700118/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700119 * IOC local definitions
120 */
121#define BFA_IOCFC_TOV 5000 /* msecs */
122
123enum {
124 BFA_IOCFC_ACT_NONE = 0,
125 BFA_IOCFC_ACT_INIT = 1,
126 BFA_IOCFC_ACT_STOP = 2,
127 BFA_IOCFC_ACT_DISABLE = 3,
128};
129
130#define DEF_CFG_NUM_FABRICS 1
131#define DEF_CFG_NUM_LPORTS 256
132#define DEF_CFG_NUM_CQS 4
133#define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
134#define DEF_CFG_NUM_TSKIM_REQS 128
135#define DEF_CFG_NUM_FCXP_REQS 64
136#define DEF_CFG_NUM_UF_BUFS 64
137#define DEF_CFG_NUM_RPORTS 1024
138#define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
139#define DEF_CFG_NUM_TINS 256
140
141#define DEF_CFG_NUM_SGPGS 2048
142#define DEF_CFG_NUM_REQQ_ELEMS 256
143#define DEF_CFG_NUM_RSPQ_ELEMS 64
144#define DEF_CFG_NUM_SBOOT_TGTS 16
145#define DEF_CFG_NUM_SBOOT_LUNS 16
146
Jing Huang5fbe25c2010-10-18 17:17:23 -0700147/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700148 * forward declaration for IOC FC functions
149 */
150static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
151static void bfa_iocfc_disable_cbfn(void *bfa_arg);
152static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
153static void bfa_iocfc_reset_cbfn(void *bfa_arg);
154static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
155
Jing Huang5fbe25c2010-10-18 17:17:23 -0700156/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700157 * BFA Interrupt handling functions
158 */
159static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700160bfa_reqq_resume(struct bfa_s *bfa, int qid)
161{
162 struct list_head *waitq, *qe, *qen;
163 struct bfa_reqq_wait_s *wqe;
164
165 waitq = bfa_reqq(bfa, qid);
166 list_for_each_safe(qe, qen, waitq) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700167 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700168 * Callback only as long as there is room in request queue
169 */
170 if (bfa_reqq_full(bfa, qid))
171 break;
172
173 list_del(qe);
174 wqe = (struct bfa_reqq_wait_s *) qe;
175 wqe->qresume(wqe->cbarg);
176 }
177}
178
Krishna Gudipati11189202011-06-13 15:50:35 -0700179static inline void
180bfa_isr_rspq(struct bfa_s *bfa, int qid)
181{
182 struct bfi_msg_s *m;
183 u32 pi, ci;
184 struct list_head *waitq;
185
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700186 bfa_isr_rspq_ack(bfa, qid);
Krishna Gudipati11189202011-06-13 15:50:35 -0700187
188 ci = bfa_rspq_ci(bfa, qid);
189 pi = bfa_rspq_pi(bfa, qid);
190
191 while (ci != pi) {
192 m = bfa_rspq_elem(bfa, qid, ci);
193 WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
194
195 bfa_isrs[m->mhdr.msg_class] (bfa, m);
196 CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
197 }
198
199 /*
200 * update CI
201 */
202 bfa_rspq_ci(bfa, qid) = pi;
203 writel(pi, bfa->iocfc.bfa_regs.rme_q_ci[qid]);
204 mmiowb();
205
206 /*
207 * Resume any pending requests in the corresponding reqq.
208 */
209 waitq = bfa_reqq(bfa, qid);
210 if (!list_empty(waitq))
211 bfa_reqq_resume(bfa, qid);
212}
213
214static inline void
215bfa_isr_reqq(struct bfa_s *bfa, int qid)
216{
217 struct list_head *waitq;
218
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700219 bfa_isr_reqq_ack(bfa, qid);
Krishna Gudipati11189202011-06-13 15:50:35 -0700220
221 /*
222 * Resume any pending requests in the corresponding reqq.
223 */
224 waitq = bfa_reqq(bfa, qid);
225 if (!list_empty(waitq))
226 bfa_reqq_resume(bfa, qid);
227}
228
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700229void
230bfa_msix_all(struct bfa_s *bfa, int vec)
231{
Krishna Gudipati10a07372011-06-24 20:23:38 -0700232 u32 intr, qintr;
233 int queue;
234
235 intr = readl(bfa->iocfc.bfa_regs.intr_status);
236 if (!intr)
237 return;
238
239 /*
240 * RME completion queue interrupt
241 */
242 qintr = intr & __HFN_INT_RME_MASK;
243 if (qintr && bfa->queue_process) {
244 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
245 bfa_isr_rspq(bfa, queue);
246 }
247
248 intr &= ~qintr;
249 if (!intr)
250 return;
251
252 /*
253 * CPE completion queue interrupt
254 */
255 qintr = intr & __HFN_INT_CPE_MASK;
256 if (qintr && bfa->queue_process) {
257 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
258 bfa_isr_reqq(bfa, queue);
259 }
260 intr &= ~qintr;
261 if (!intr)
262 return;
263
264 bfa_msix_lpu_err(bfa, intr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700265}
266
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700267bfa_boolean_t
268bfa_intx(struct bfa_s *bfa)
269{
270 u32 intr, qintr;
271 int queue;
272
Jing Huang53440262010-10-18 17:12:29 -0700273 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700274 if (!intr)
275 return BFA_FALSE;
276
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700277 qintr = intr & (__HFN_INT_RME_MASK | __HFN_INT_CPE_MASK);
278 if (qintr)
279 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
280
Jing Huang5fbe25c2010-10-18 17:17:23 -0700281 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700282 * RME completion queue interrupt
283 */
284 qintr = intr & __HFN_INT_RME_MASK;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700285 if (qintr && bfa->queue_process) {
286 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
287 bfa_isr_rspq(bfa, queue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700288 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700289
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700290 intr &= ~qintr;
291 if (!intr)
292 return BFA_TRUE;
293
Jing Huang5fbe25c2010-10-18 17:17:23 -0700294 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700295 * CPE completion queue interrupt
296 */
297 qintr = intr & __HFN_INT_CPE_MASK;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700298 if (qintr && bfa->queue_process) {
299 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
300 bfa_isr_reqq(bfa, queue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700301 }
302 intr &= ~qintr;
303 if (!intr)
304 return BFA_TRUE;
305
306 bfa_msix_lpu_err(bfa, intr);
307
308 return BFA_TRUE;
309}
310
311void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700312bfa_isr_enable(struct bfa_s *bfa)
313{
Krishna Gudipati11189202011-06-13 15:50:35 -0700314 u32 umsk;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700315 int pci_func = bfa_ioc_pcifn(&bfa->ioc);
316
317 bfa_trc(bfa, pci_func);
318
Krishna Gudipati775c7742011-06-13 15:52:12 -0700319 bfa_msix_ctrl_install(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700320
Krishna Gudipati11189202011-06-13 15:50:35 -0700321 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
322 umsk = __HFN_INT_ERR_MASK_CT2;
323 umsk |= pci_func == 0 ?
324 __HFN_INT_FN0_MASK_CT2 : __HFN_INT_FN1_MASK_CT2;
325 } else {
326 umsk = __HFN_INT_ERR_MASK;
327 umsk |= pci_func == 0 ? __HFN_INT_FN0_MASK : __HFN_INT_FN1_MASK;
328 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700329
Krishna Gudipati11189202011-06-13 15:50:35 -0700330 writel(umsk, bfa->iocfc.bfa_regs.intr_status);
331 writel(~umsk, bfa->iocfc.bfa_regs.intr_mask);
332 bfa->iocfc.intr_mask = ~umsk;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700333 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
334}
335
336void
337bfa_isr_disable(struct bfa_s *bfa)
338{
339 bfa_isr_mode_set(bfa, BFA_FALSE);
Jing Huang53440262010-10-18 17:12:29 -0700340 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700341 bfa_msix_uninstall(bfa);
342}
343
344void
Krishna Gudipati11189202011-06-13 15:50:35 -0700345bfa_msix_reqq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700346{
Krishna Gudipati11189202011-06-13 15:50:35 -0700347 bfa_isr_reqq(bfa, vec - bfa->iocfc.hwif.cpe_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700348}
349
350void
351bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
352{
353 bfa_trc(bfa, m->mhdr.msg_class);
354 bfa_trc(bfa, m->mhdr.msg_id);
355 bfa_trc(bfa, m->mhdr.mtag.i2htok);
Jing Huangd4b671c2010-12-26 21:46:35 -0800356 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700357 bfa_trc_stop(bfa->trcmod);
358}
359
360void
Krishna Gudipati11189202011-06-13 15:50:35 -0700361bfa_msix_rspq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700362{
Krishna Gudipati11189202011-06-13 15:50:35 -0700363 bfa_isr_rspq(bfa, vec - bfa->iocfc.hwif.rme_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700364}
365
366void
367bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
368{
369 u32 intr, curr_value;
Krishna Gudipati11189202011-06-13 15:50:35 -0700370 bfa_boolean_t lpu_isr, halt_isr, pss_isr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700371
Jing Huang53440262010-10-18 17:12:29 -0700372 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700373
Krishna Gudipati11189202011-06-13 15:50:35 -0700374 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
375 halt_isr = intr & __HFN_INT_CPQ_HALT_CT2;
376 pss_isr = intr & __HFN_INT_ERR_PSS_CT2;
377 lpu_isr = intr & (__HFN_INT_MBOX_LPU0_CT2 |
378 __HFN_INT_MBOX_LPU1_CT2);
379 intr &= __HFN_INT_ERR_MASK_CT2;
380 } else {
381 halt_isr = intr & __HFN_INT_LL_HALT;
382 pss_isr = intr & __HFN_INT_ERR_PSS;
383 lpu_isr = intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1);
384 intr &= __HFN_INT_ERR_MASK;
385 }
386
387 if (lpu_isr)
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800388 bfa_ioc_mbox_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700389
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700390 if (intr) {
Krishna Gudipati11189202011-06-13 15:50:35 -0700391 if (halt_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700392 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700393 * If LL_HALT bit is set then FW Init Halt LL Port
394 * Register needs to be cleared as well so Interrupt
395 * Status Register will be cleared.
396 */
Jing Huang53440262010-10-18 17:12:29 -0700397 curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700398 curr_value &= ~__FW_INIT_HALT_P;
Jing Huang53440262010-10-18 17:12:29 -0700399 writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700400 }
401
Krishna Gudipati11189202011-06-13 15:50:35 -0700402 if (pss_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700403 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700404 * ERR_PSS bit needs to be cleared as well in case
405 * interrups are shared so driver's interrupt handler is
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300406 * still called even though it is already masked out.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700407 */
Jing Huang53440262010-10-18 17:12:29 -0700408 curr_value = readl(
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700409 bfa->ioc.ioc_regs.pss_err_status_reg);
Jing Huang53440262010-10-18 17:12:29 -0700410 writel(curr_value,
411 bfa->ioc.ioc_regs.pss_err_status_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700412 }
413
Jing Huang53440262010-10-18 17:12:29 -0700414 writel(intr, bfa->iocfc.bfa_regs.intr_status);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800415 bfa_ioc_error_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700416 }
417}
418
Jing Huang5fbe25c2010-10-18 17:17:23 -0700419/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700420 * BFA IOC FC related functions
421 */
422
Jing Huang5fbe25c2010-10-18 17:17:23 -0700423/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -0800424 * BFA IOC private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700425 */
426
Jing Huang5fbe25c2010-10-18 17:17:23 -0700427/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700428 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
429 */
430static void
431bfa_iocfc_send_cfg(void *bfa_arg)
432{
433 struct bfa_s *bfa = bfa_arg;
434 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
435 struct bfi_iocfc_cfg_req_s cfg_req;
436 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
437 struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
438 int i;
439
Jing Huangd4b671c2010-12-26 21:46:35 -0800440 WARN_ON(cfg->fwcfg.num_cqs > BFI_IOC_MAX_CQS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700441 bfa_trc(bfa, cfg->fwcfg.num_cqs);
442
443 bfa_iocfc_reset_queues(bfa);
444
Jing Huang5fbe25c2010-10-18 17:17:23 -0700445 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700446 * initialize IOC configuration info
447 */
Krishna Gudipati10a07372011-06-24 20:23:38 -0700448 cfg_info->single_msix_vec = 0;
449 if (bfa->msix.nvecs == 1)
450 cfg_info->single_msix_vec = 1;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700451 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
452 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700453 cfg_info->num_ioim_reqs = cpu_to_be16(cfg->fwcfg.num_ioim_reqs);
454 cfg_info->num_fwtio_reqs = cpu_to_be16(cfg->fwcfg.num_fwtio_reqs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700455
456 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700457 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700458 * dma map REQ and RSP circular queues and shadow pointers
459 */
460 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
461 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
462 iocfc->req_cq_ba[i].pa);
463 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
464 iocfc->req_cq_shadow_ci[i].pa);
465 cfg_info->req_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700466 cpu_to_be16(cfg->drvcfg.num_reqq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700467
468 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
469 iocfc->rsp_cq_ba[i].pa);
470 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
471 iocfc->rsp_cq_shadow_pi[i].pa);
472 cfg_info->rsp_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700473 cpu_to_be16(cfg->drvcfg.num_rspq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700474 }
475
Jing Huang5fbe25c2010-10-18 17:17:23 -0700476 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700477 * Enable interrupt coalescing if it is driver init path
478 * and not ioc disable/enable path.
479 */
480 if (!iocfc->cfgdone)
481 cfg_info->intr_attr.coalesce = BFA_TRUE;
482
483 iocfc->cfgdone = BFA_FALSE;
484
Jing Huang5fbe25c2010-10-18 17:17:23 -0700485 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700486 * dma map IOC configuration itself
487 */
488 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700489 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700490 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
491
492 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
493 sizeof(struct bfi_iocfc_cfg_req_s));
494}
495
496static void
497bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
498 struct bfa_pcidev_s *pcidev)
499{
500 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
501
502 bfa->bfad = bfad;
503 iocfc->bfa = bfa;
504 iocfc->action = BFA_IOCFC_ACT_NONE;
505
Jing Huang6a18b162010-10-18 17:08:54 -0700506 iocfc->cfg = *cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700507
Jing Huang5fbe25c2010-10-18 17:17:23 -0700508 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700509 * Initialize chip specific handlers.
510 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700511 if (bfa_asic_id_ctc(bfa_ioc_devid(&bfa->ioc))) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700512 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
513 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
514 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
515 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -0700516 iocfc->hwif.hw_msix_ctrl_install = bfa_hwct_msix_ctrl_install;
517 iocfc->hwif.hw_msix_queue_install = bfa_hwct_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700518 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
519 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
520 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
521 iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -0700522 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CT;
523 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CT;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700524 } else {
525 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700526 iocfc->hwif.hw_reqq_ack = NULL;
527 iocfc->hwif.hw_rspq_ack = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700528 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -0700529 iocfc->hwif.hw_msix_ctrl_install = bfa_hwcb_msix_ctrl_install;
530 iocfc->hwif.hw_msix_queue_install = bfa_hwcb_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700531 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
532 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
533 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
534 iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -0700535 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CB +
536 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
537 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CB +
538 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
539 }
540
541 if (bfa_asic_id_ct2(bfa_ioc_devid(&bfa->ioc))) {
542 iocfc->hwif.hw_reginit = bfa_hwct2_reginit;
543 iocfc->hwif.hw_isr_mode_set = NULL;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700544 iocfc->hwif.hw_rspq_ack = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700545 }
546
547 iocfc->hwif.hw_reginit(bfa);
548 bfa->msix.nvecs = 0;
549}
550
551static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700552bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700553{
Krishna Gudipati45070252011-06-24 20:24:29 -0700554 u8 *dm_kva = NULL;
555 u64 dm_pa = 0;
556 int i, per_reqq_sz, per_rspq_sz, dbgsz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700557 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
Krishna Gudipati45070252011-06-24 20:24:29 -0700558 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
559 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
560 struct bfa_mem_dma_s *reqq_dma, *rspq_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700561
Krishna Gudipati45070252011-06-24 20:24:29 -0700562 /* First allocate dma memory for IOC */
563 bfa_ioc_mem_claim(&bfa->ioc, bfa_mem_dma_virt(ioc_dma),
564 bfa_mem_dma_phys(ioc_dma));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700565
Krishna Gudipati45070252011-06-24 20:24:29 -0700566 /* Claim DMA-able memory for the request/response queues */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700567 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -0700568 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700569 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -0700570 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700571
572 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
Krishna Gudipati45070252011-06-24 20:24:29 -0700573 reqq_dma = BFA_MEM_REQQ_DMA(bfa, i);
574 iocfc->req_cq_ba[i].kva = bfa_mem_dma_virt(reqq_dma);
575 iocfc->req_cq_ba[i].pa = bfa_mem_dma_phys(reqq_dma);
576 memset(iocfc->req_cq_ba[i].kva, 0, per_reqq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700577
Krishna Gudipati45070252011-06-24 20:24:29 -0700578 rspq_dma = BFA_MEM_RSPQ_DMA(bfa, i);
579 iocfc->rsp_cq_ba[i].kva = bfa_mem_dma_virt(rspq_dma);
580 iocfc->rsp_cq_ba[i].pa = bfa_mem_dma_phys(rspq_dma);
581 memset(iocfc->rsp_cq_ba[i].kva, 0, per_rspq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700582 }
583
Krishna Gudipati45070252011-06-24 20:24:29 -0700584 /* Claim IOCFC dma memory - for shadow CI/PI */
585 dm_kva = bfa_mem_dma_virt(iocfc_dma);
586 dm_pa = bfa_mem_dma_phys(iocfc_dma);
587
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
589 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
590 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
591 dm_kva += BFA_CACHELINE_SZ;
592 dm_pa += BFA_CACHELINE_SZ;
593
594 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
595 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
596 dm_kva += BFA_CACHELINE_SZ;
597 dm_pa += BFA_CACHELINE_SZ;
598 }
599
Krishna Gudipati45070252011-06-24 20:24:29 -0700600 /* Claim IOCFC dma memory - for the config info page */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700601 bfa->iocfc.cfg_info.kva = dm_kva;
602 bfa->iocfc.cfg_info.pa = dm_pa;
603 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
604 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
605 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
606
Krishna Gudipati45070252011-06-24 20:24:29 -0700607 /* Claim IOCFC dma memory - for the config response */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700608 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
609 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
610 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
Krishna Gudipati45070252011-06-24 20:24:29 -0700611 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
612 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700613 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
Krishna Gudipati45070252011-06-24 20:24:29 -0700614 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700615
Krishna Gudipati45070252011-06-24 20:24:29 -0700616 /* Claim IOCFC kva memory */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800617 dbgsz = (bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700618 if (dbgsz > 0) {
Krishna Gudipati45070252011-06-24 20:24:29 -0700619 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_mem_kva_curp(iocfc));
620 bfa_mem_kva_curp(iocfc) += dbgsz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700621 }
622}
623
Jing Huang5fbe25c2010-10-18 17:17:23 -0700624/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700625 * Start BFA submodules.
626 */
627static void
628bfa_iocfc_start_submod(struct bfa_s *bfa)
629{
630 int i;
631
Krishna Gudipati775c7742011-06-13 15:52:12 -0700632 bfa->queue_process = BFA_TRUE;
Krishna Gudipati11189202011-06-13 15:50:35 -0700633 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700634 bfa_isr_rspq_ack(bfa, i);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700635
636 for (i = 0; hal_mods[i]; i++)
637 hal_mods[i]->start(bfa);
638}
639
Jing Huang5fbe25c2010-10-18 17:17:23 -0700640/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700641 * Disable BFA submodules.
642 */
643static void
644bfa_iocfc_disable_submod(struct bfa_s *bfa)
645{
646 int i;
647
648 for (i = 0; hal_mods[i]; i++)
649 hal_mods[i]->iocdisable(bfa);
650}
651
652static void
653bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
654{
655 struct bfa_s *bfa = bfa_arg;
656
657 if (complete) {
658 if (bfa->iocfc.cfgdone)
659 bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
660 else
661 bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
662 } else {
663 if (bfa->iocfc.cfgdone)
664 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
665 }
666}
667
668static void
669bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
670{
671 struct bfa_s *bfa = bfa_arg;
672 struct bfad_s *bfad = bfa->bfad;
673
674 if (compl)
675 complete(&bfad->comp);
676 else
677 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
678}
679
680static void
681bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
682{
683 struct bfa_s *bfa = bfa_arg;
684 struct bfad_s *bfad = bfa->bfad;
685
686 if (compl)
687 complete(&bfad->disable_comp);
688}
689
Krishna Gudipati11189202011-06-13 15:50:35 -0700690/**
691 * configure queue registers from firmware response
692 */
693static void
694bfa_iocfc_qreg(struct bfa_s *bfa, struct bfi_iocfc_qreg_s *qreg)
695{
696 int i;
697 struct bfa_iocfc_regs_s *r = &bfa->iocfc.bfa_regs;
698 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
699
700 for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700701 bfa->iocfc.hw_qid[i] = qreg->hw_qid[i];
Krishna Gudipati11189202011-06-13 15:50:35 -0700702 r->cpe_q_ci[i] = kva + be32_to_cpu(qreg->cpe_q_ci_off[i]);
703 r->cpe_q_pi[i] = kva + be32_to_cpu(qreg->cpe_q_pi_off[i]);
704 r->cpe_q_ctrl[i] = kva + be32_to_cpu(qreg->cpe_qctl_off[i]);
705 r->rme_q_ci[i] = kva + be32_to_cpu(qreg->rme_q_ci_off[i]);
706 r->rme_q_pi[i] = kva + be32_to_cpu(qreg->rme_q_pi_off[i]);
707 r->rme_q_ctrl[i] = kva + be32_to_cpu(qreg->rme_qctl_off[i]);
708 }
709}
710
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700711static void
712bfa_iocfc_res_recfg(struct bfa_s *bfa, struct bfa_iocfc_fwcfg_s *fwcfg)
713{
714 bfa_fcxp_res_recfg(bfa, fwcfg->num_fcxp_reqs);
715 bfa_uf_res_recfg(bfa, fwcfg->num_uf_bufs);
716 bfa_rport_res_recfg(bfa, fwcfg->num_rports);
717 bfa_fcp_res_recfg(bfa, fwcfg->num_ioim_reqs);
718 bfa_tskim_res_recfg(bfa, fwcfg->num_tskim_reqs);
719}
720
Jing Huang5fbe25c2010-10-18 17:17:23 -0700721/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700722 * Update BFA configuration from firmware configuration.
723 */
724static void
725bfa_iocfc_cfgrsp(struct bfa_s *bfa)
726{
727 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
728 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
729 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
730
731 fwcfg->num_cqs = fwcfg->num_cqs;
Jing Huangba816ea2010-10-18 17:10:50 -0700732 fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700733 fwcfg->num_fwtio_reqs = be16_to_cpu(fwcfg->num_fwtio_reqs);
Jing Huangba816ea2010-10-18 17:10:50 -0700734 fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
735 fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
736 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
737 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700738
739 iocfc->cfgdone = BFA_TRUE;
740
Jing Huang5fbe25c2010-10-18 17:17:23 -0700741 /*
Krishna Gudipati11189202011-06-13 15:50:35 -0700742 * configure queue register offsets as learnt from firmware
743 */
744 bfa_iocfc_qreg(bfa, &cfgrsp->qreg);
745
746 /*
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700747 * Re-configure resources as learnt from Firmware
748 */
749 bfa_iocfc_res_recfg(bfa, fwcfg);
750
751 /*
Krishna Gudipati775c7742011-06-13 15:52:12 -0700752 * Install MSIX queue handlers
753 */
754 bfa_msix_queue_install(bfa);
755
756 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700757 * Configuration is complete - initialize/start submodules
758 */
759 bfa_fcport_init(bfa);
760
761 if (iocfc->action == BFA_IOCFC_ACT_INIT)
762 bfa_cb_queue(bfa, &iocfc->init_hcb_qe, bfa_iocfc_init_cb, bfa);
763 else
764 bfa_iocfc_start_submod(bfa);
765}
766void
767bfa_iocfc_reset_queues(struct bfa_s *bfa)
768{
769 int q;
770
771 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
772 bfa_reqq_ci(bfa, q) = 0;
773 bfa_reqq_pi(bfa, q) = 0;
774 bfa_rspq_ci(bfa, q) = 0;
775 bfa_rspq_pi(bfa, q) = 0;
776 }
777}
778
Krishna Gudipatia7141342011-06-24 20:23:19 -0700779/* Fabric Assigned Address specific functions */
780
781/*
782 * Check whether IOC is ready before sending command down
783 */
784static bfa_status_t
785bfa_faa_validate_request(struct bfa_s *bfa)
786{
787 enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
788 u32 card_type = bfa->ioc.attr->card_type;
789
790 if (bfa_ioc_is_operational(&bfa->ioc)) {
791 if ((ioc_type != BFA_IOC_TYPE_FC) || bfa_mfg_is_mezz(card_type))
792 return BFA_STATUS_FEATURE_NOT_SUPPORTED;
793 } else {
794 if (!bfa_ioc_is_acq_addr(&bfa->ioc))
795 return BFA_STATUS_IOC_NON_OP;
796 }
797
798 return BFA_STATUS_OK;
799}
800
801bfa_status_t
802bfa_faa_enable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn, void *cbarg)
803{
804 struct bfi_faa_en_dis_s faa_enable_req;
805 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
806 bfa_status_t status;
807
808 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
809 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
810
811 status = bfa_faa_validate_request(bfa);
812 if (status != BFA_STATUS_OK)
813 return status;
814
815 if (iocfc->faa_args.busy == BFA_TRUE)
816 return BFA_STATUS_DEVBUSY;
817
818 if (iocfc->faa_args.faa_state == BFA_FAA_ENABLED)
819 return BFA_STATUS_FAA_ENABLED;
820
821 if (bfa_fcport_is_trunk_enabled(bfa))
822 return BFA_STATUS_ERROR_TRUNK_ENABLED;
823
824 bfa_fcport_cfg_faa(bfa, BFA_FAA_ENABLED);
825 iocfc->faa_args.busy = BFA_TRUE;
826
827 memset(&faa_enable_req, 0, sizeof(struct bfi_faa_en_dis_s));
828 bfi_h2i_set(faa_enable_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700829 BFI_IOCFC_H2I_FAA_ENABLE_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -0700830
831 bfa_ioc_mbox_send(&bfa->ioc, &faa_enable_req,
832 sizeof(struct bfi_faa_en_dis_s));
833
834 return BFA_STATUS_OK;
835}
836
837bfa_status_t
838bfa_faa_disable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn,
839 void *cbarg)
840{
841 struct bfi_faa_en_dis_s faa_disable_req;
842 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
843 bfa_status_t status;
844
845 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
846 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
847
848 status = bfa_faa_validate_request(bfa);
849 if (status != BFA_STATUS_OK)
850 return status;
851
852 if (iocfc->faa_args.busy == BFA_TRUE)
853 return BFA_STATUS_DEVBUSY;
854
855 if (iocfc->faa_args.faa_state == BFA_FAA_DISABLED)
856 return BFA_STATUS_FAA_DISABLED;
857
858 bfa_fcport_cfg_faa(bfa, BFA_FAA_DISABLED);
859 iocfc->faa_args.busy = BFA_TRUE;
860
861 memset(&faa_disable_req, 0, sizeof(struct bfi_faa_en_dis_s));
862 bfi_h2i_set(faa_disable_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700863 BFI_IOCFC_H2I_FAA_DISABLE_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -0700864
865 bfa_ioc_mbox_send(&bfa->ioc, &faa_disable_req,
866 sizeof(struct bfi_faa_en_dis_s));
867
868 return BFA_STATUS_OK;
869}
870
871bfa_status_t
872bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
873 bfa_cb_iocfc_t cbfn, void *cbarg)
874{
875 struct bfi_faa_query_s faa_attr_req;
876 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
877 bfa_status_t status;
878
879 iocfc->faa_args.faa_attr = attr;
880 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
881 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
882
883 status = bfa_faa_validate_request(bfa);
884 if (status != BFA_STATUS_OK)
885 return status;
886
887 if (iocfc->faa_args.busy == BFA_TRUE)
888 return BFA_STATUS_DEVBUSY;
889
890 iocfc->faa_args.busy = BFA_TRUE;
891 memset(&faa_attr_req, 0, sizeof(struct bfi_faa_query_s));
892 bfi_h2i_set(faa_attr_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700893 BFI_IOCFC_H2I_FAA_QUERY_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -0700894
895 bfa_ioc_mbox_send(&bfa->ioc, &faa_attr_req,
896 sizeof(struct bfi_faa_query_s));
897
898 return BFA_STATUS_OK;
899}
900
901/*
902 * FAA enable response
903 */
904static void
905bfa_faa_enable_reply(struct bfa_iocfc_s *iocfc,
906 struct bfi_faa_en_dis_rsp_s *rsp)
907{
908 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
909 bfa_status_t status = rsp->status;
910
911 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
912
913 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
914 iocfc->faa_args.busy = BFA_FALSE;
915}
916
917/*
918 * FAA disable response
919 */
920static void
921bfa_faa_disable_reply(struct bfa_iocfc_s *iocfc,
922 struct bfi_faa_en_dis_rsp_s *rsp)
923{
924 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
925 bfa_status_t status = rsp->status;
926
927 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
928
929 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
930 iocfc->faa_args.busy = BFA_FALSE;
931}
932
933/*
934 * FAA query response
935 */
936static void
937bfa_faa_query_reply(struct bfa_iocfc_s *iocfc,
938 bfi_faa_query_rsp_t *rsp)
939{
940 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
941
942 if (iocfc->faa_args.faa_attr) {
943 iocfc->faa_args.faa_attr->faa = rsp->faa;
944 iocfc->faa_args.faa_attr->faa_state = rsp->faa_status;
945 iocfc->faa_args.faa_attr->pwwn_source = rsp->addr_source;
946 }
947
948 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
949
950 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, BFA_STATUS_OK);
951 iocfc->faa_args.busy = BFA_FALSE;
952}
953
Jing Huang5fbe25c2010-10-18 17:17:23 -0700954/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700955 * IOC enable request is complete
956 */
957static void
958bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
959{
960 struct bfa_s *bfa = bfa_arg;
961
Krishna Gudipatia7141342011-06-24 20:23:19 -0700962 if (status == BFA_STATUS_FAA_ACQ_ADDR) {
963 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
964 bfa_iocfc_init_cb, bfa);
965 return;
966 }
967
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700968 if (status != BFA_STATUS_OK) {
969 bfa_isr_disable(bfa);
970 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
971 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
972 bfa_iocfc_init_cb, bfa);
973 return;
974 }
975
976 bfa_iocfc_send_cfg(bfa);
977}
978
Jing Huang5fbe25c2010-10-18 17:17:23 -0700979/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700980 * IOC disable request is complete
981 */
982static void
983bfa_iocfc_disable_cbfn(void *bfa_arg)
984{
985 struct bfa_s *bfa = bfa_arg;
986
987 bfa_isr_disable(bfa);
988 bfa_iocfc_disable_submod(bfa);
989
990 if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
991 bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
992 bfa);
993 else {
Jing Huangd4b671c2010-12-26 21:46:35 -0800994 WARN_ON(bfa->iocfc.action != BFA_IOCFC_ACT_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700995 bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
996 bfa);
997 }
998}
999
Jing Huang5fbe25c2010-10-18 17:17:23 -07001000/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001001 * Notify sub-modules of hardware failure.
1002 */
1003static void
1004bfa_iocfc_hbfail_cbfn(void *bfa_arg)
1005{
1006 struct bfa_s *bfa = bfa_arg;
1007
Krishna Gudipati775c7742011-06-13 15:52:12 -07001008 bfa->queue_process = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001009
1010 bfa_isr_disable(bfa);
1011 bfa_iocfc_disable_submod(bfa);
1012
1013 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
1014 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
1015 bfa);
1016}
1017
Jing Huang5fbe25c2010-10-18 17:17:23 -07001018/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001019 * Actions on chip-reset completion.
1020 */
1021static void
1022bfa_iocfc_reset_cbfn(void *bfa_arg)
1023{
1024 struct bfa_s *bfa = bfa_arg;
1025
1026 bfa_iocfc_reset_queues(bfa);
1027 bfa_isr_enable(bfa);
1028}
1029
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001030
Jing Huang5fbe25c2010-10-18 17:17:23 -07001031/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001032 * Query IOC memory requirement information.
1033 */
1034void
Krishna Gudipati45070252011-06-24 20:24:29 -07001035bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1036 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001037{
Krishna Gudipati45070252011-06-24 20:24:29 -07001038 int q, per_reqq_sz, per_rspq_sz;
1039 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
1040 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
1041 struct bfa_mem_kva_s *iocfc_kva = BFA_MEM_IOCFC_KVA(bfa);
1042 u32 dm_len = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001043
Krishna Gudipati45070252011-06-24 20:24:29 -07001044 /* dma memory setup for IOC */
1045 bfa_mem_dma_setup(meminfo, ioc_dma,
1046 BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ));
1047
1048 /* dma memory setup for REQ/RSP queues */
1049 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
1050 BFA_DMA_ALIGN_SZ);
1051 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
1052 BFA_DMA_ALIGN_SZ);
1053
1054 for (q = 0; q < cfg->fwcfg.num_cqs; q++) {
1055 bfa_mem_dma_setup(meminfo, BFA_MEM_REQQ_DMA(bfa, q),
1056 per_reqq_sz);
1057 bfa_mem_dma_setup(meminfo, BFA_MEM_RSPQ_DMA(bfa, q),
1058 per_rspq_sz);
1059 }
1060
1061 /* IOCFC dma memory - calculate Shadow CI/PI size */
1062 for (q = 0; q < cfg->fwcfg.num_cqs; q++)
1063 dm_len += (2 * BFA_CACHELINE_SZ);
1064
1065 /* IOCFC dma memory - calculate config info / rsp size */
1066 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1067 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
1068 BFA_CACHELINE_SZ);
1069
1070 /* dma memory setup for IOCFC */
1071 bfa_mem_dma_setup(meminfo, iocfc_dma, dm_len);
1072
1073 /* kva memory setup for IOCFC */
1074 bfa_mem_kva_setup(meminfo, iocfc_kva,
1075 ((bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001076}
1077
Jing Huang5fbe25c2010-10-18 17:17:23 -07001078/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001079 * Query IOC memory requirement information.
1080 */
1081void
1082bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001083 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001084{
1085 int i;
1086 struct bfa_ioc_s *ioc = &bfa->ioc;
1087
1088 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
1089 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
1090 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
1091 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
1092
1093 ioc->trcmod = bfa->trcmod;
1094 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
1095
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001096 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_PCIFN_CLASS_FC);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001097 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
1098
1099 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
Krishna Gudipati45070252011-06-24 20:24:29 -07001100 bfa_iocfc_mem_claim(bfa, cfg);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001101 INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001102
1103 INIT_LIST_HEAD(&bfa->comp_q);
1104 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
1105 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
1106}
1107
Jing Huang5fbe25c2010-10-18 17:17:23 -07001108/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001109 * Query IOC memory requirement information.
1110 */
1111void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001112bfa_iocfc_init(struct bfa_s *bfa)
1113{
1114 bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
1115 bfa_ioc_enable(&bfa->ioc);
1116}
1117
Jing Huang5fbe25c2010-10-18 17:17:23 -07001118/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001119 * IOC start called from bfa_start(). Called to start IOC operations
1120 * at driver instantiation for this instance.
1121 */
1122void
1123bfa_iocfc_start(struct bfa_s *bfa)
1124{
1125 if (bfa->iocfc.cfgdone)
1126 bfa_iocfc_start_submod(bfa);
1127}
1128
Jing Huang5fbe25c2010-10-18 17:17:23 -07001129/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001130 * IOC stop called from bfa_stop(). Called only when driver is unloaded
1131 * for this instance.
1132 */
1133void
1134bfa_iocfc_stop(struct bfa_s *bfa)
1135{
1136 bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
1137
Krishna Gudipati775c7742011-06-13 15:52:12 -07001138 bfa->queue_process = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001139 bfa_ioc_disable(&bfa->ioc);
1140}
1141
1142void
1143bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
1144{
1145 struct bfa_s *bfa = bfaarg;
1146 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1147 union bfi_iocfc_i2h_msg_u *msg;
1148
1149 msg = (union bfi_iocfc_i2h_msg_u *) m;
1150 bfa_trc(bfa, msg->mh.msg_id);
1151
1152 switch (msg->mh.msg_id) {
1153 case BFI_IOCFC_I2H_CFG_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001154 bfa_iocfc_cfgrsp(bfa);
1155 break;
1156 case BFI_IOCFC_I2H_UPDATEQ_RSP:
1157 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
1158 break;
Krishna Gudipatia7141342011-06-24 20:23:19 -07001159 case BFI_IOCFC_I2H_FAA_ENABLE_RSP:
1160 bfa_faa_enable_reply(iocfc,
1161 (struct bfi_faa_en_dis_rsp_s *)msg);
1162 break;
1163 case BFI_IOCFC_I2H_FAA_DISABLE_RSP:
1164 bfa_faa_disable_reply(iocfc,
1165 (struct bfi_faa_en_dis_rsp_s *)msg);
1166 break;
1167 case BFI_IOCFC_I2H_FAA_QUERY_RSP:
1168 bfa_faa_query_reply(iocfc, (bfi_faa_query_rsp_t *)msg);
1169 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001170 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001171 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001172 }
1173}
1174
1175void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
1177{
1178 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1179
1180 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
1181
1182 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
Jing Huangba816ea2010-10-18 17:10:50 -07001183 be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
1184 be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001185
1186 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
Jing Huangba816ea2010-10-18 17:10:50 -07001187 be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
1188 be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001189
1190 attr->config = iocfc->cfg;
1191}
1192
1193bfa_status_t
1194bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
1195{
1196 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1197 struct bfi_iocfc_set_intr_req_s *m;
1198
1199 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
Jing Huangba816ea2010-10-18 17:10:50 -07001200 iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
1201 iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001202
1203 if (!bfa_iocfc_is_operational(bfa))
1204 return BFA_STATUS_OK;
1205
1206 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
1207 if (!m)
1208 return BFA_STATUS_DEVBUSY;
1209
1210 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001211 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001212 m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
1213 m->delay = iocfc->cfginfo->intr_attr.delay;
1214 m->latency = iocfc->cfginfo->intr_attr.latency;
1215
1216 bfa_trc(bfa, attr->delay);
1217 bfa_trc(bfa, attr->latency);
1218
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001219 bfa_reqq_produce(bfa, BFA_REQQ_IOC, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001220 return BFA_STATUS_OK;
1221}
1222
1223void
Krishna Gudipati45070252011-06-24 20:24:29 -07001224bfa_iocfc_set_snsbase(struct bfa_s *bfa, int seg_no, u64 snsbase_pa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001225{
1226 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1227
1228 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
Krishna Gudipati45070252011-06-24 20:24:29 -07001229 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase[seg_no], snsbase_pa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001230}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001231/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001232 * Enable IOC after it is disabled.
1233 */
1234void
1235bfa_iocfc_enable(struct bfa_s *bfa)
1236{
1237 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1238 "IOC Enable");
1239 bfa_ioc_enable(&bfa->ioc);
1240}
1241
1242void
1243bfa_iocfc_disable(struct bfa_s *bfa)
1244{
1245 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1246 "IOC Disable");
1247 bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
1248
Krishna Gudipati775c7742011-06-13 15:52:12 -07001249 bfa->queue_process = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001250 bfa_ioc_disable(&bfa->ioc);
1251}
1252
1253
1254bfa_boolean_t
1255bfa_iocfc_is_operational(struct bfa_s *bfa)
1256{
1257 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
1258}
1259
Jing Huang5fbe25c2010-10-18 17:17:23 -07001260/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001261 * Return boot target port wwns -- read from boot information in flash.
1262 */
1263void
1264bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
1265{
1266 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1267 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1268 int i;
1269
1270 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
1271 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
1272 *nwwns = cfgrsp->pbc_cfg.nbluns;
1273 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
1274 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
1275
1276 return;
1277 }
1278
1279 *nwwns = cfgrsp->bootwwns.nwwns;
1280 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
1281}
1282
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001283int
1284bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
1285{
1286 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1287 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1288
1289 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
1290 return cfgrsp->pbc_cfg.nvports;
1291}
1292
Jing Huang7725ccf2009-09-23 17:46:15 -07001293
Jing Huang5fbe25c2010-10-18 17:17:23 -07001294/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001295 * Use this function query the memory requirement of the BFA library.
1296 * This function needs to be called before bfa_attach() to get the
1297 * memory required of the BFA layer for a given driver configuration.
1298 *
1299 * This call will fail, if the cap is out of range compared to pre-defined
1300 * values within the BFA library
1301 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001302 * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
1303 * its configuration in this structure.
Jing Huang7725ccf2009-09-23 17:46:15 -07001304 * The default values for struct bfa_iocfc_cfg_s can be
1305 * fetched using bfa_cfg_get_default() API.
1306 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001307 * If cap's boundary check fails, the library will use
Jing Huang7725ccf2009-09-23 17:46:15 -07001308 * the default bfa_cap_t values (and log a warning msg).
1309 *
1310 * @param[out] meminfo - pointer to bfa_meminfo_t. This content
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001311 * indicates the memory type (see bfa_mem_type_t) and
Jing Huang7725ccf2009-09-23 17:46:15 -07001312 * amount of memory required.
1313 *
1314 * Driver should allocate the memory, populate the
1315 * starting address for each block and provide the same
1316 * structure as input parameter to bfa_attach() call.
1317 *
Krishna Gudipati45070252011-06-24 20:24:29 -07001318 * @param[in] bfa - pointer to the bfa structure, used while fetching the
1319 * dma, kva memory information of the bfa sub-modules.
1320 *
Jing Huang7725ccf2009-09-23 17:46:15 -07001321 * @return void
1322 *
1323 * Special Considerations: @note
1324 */
1325void
Krishna Gudipati45070252011-06-24 20:24:29 -07001326bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1327 struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001328{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001329 int i;
Krishna Gudipati45070252011-06-24 20:24:29 -07001330 struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
1331 struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001332
Jing Huangd4b671c2010-12-26 21:46:35 -08001333 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001334
Jing Huang6a18b162010-10-18 17:08:54 -07001335 memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001336
Krishna Gudipati45070252011-06-24 20:24:29 -07001337 /* Initialize the DMA & KVA meminfo queues */
1338 INIT_LIST_HEAD(&meminfo->dma_info.qe);
1339 INIT_LIST_HEAD(&meminfo->kva_info.qe);
1340
1341 bfa_iocfc_meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001342
1343 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001344 hal_mods[i]->meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001345
Krishna Gudipati45070252011-06-24 20:24:29 -07001346 /* dma info setup */
1347 bfa_mem_dma_setup(meminfo, port_dma, bfa_port_meminfo());
1348 bfa_mem_dma_setup(meminfo, ablk_dma, bfa_ablk_meminfo());
Jing Huang7725ccf2009-09-23 17:46:15 -07001349}
1350
Jing Huang5fbe25c2010-10-18 17:17:23 -07001351/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001352 * Use this function to do attach the driver instance with the BFA
1353 * library. This function will not trigger any HW initialization
1354 * process (which will be done in bfa_init() call)
1355 *
1356 * This call will fail, if the cap is out of range compared to
1357 * pre-defined values within the BFA library
1358 *
1359 * @param[out] bfa Pointer to bfa_t.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001360 * @param[in] bfad Opaque handle back to the driver's IOC structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001361 * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001362 * that was used in bfa_cfg_get_meminfo().
1363 * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
1364 * use the bfa_cfg_get_meminfo() call to
1365 * find the memory blocks required, allocate the
1366 * required memory and provide the starting addresses.
1367 * @param[in] pcidev pointer to struct bfa_pcidev_s
Jing Huang7725ccf2009-09-23 17:46:15 -07001368 *
1369 * @return
1370 * void
1371 *
1372 * Special Considerations:
1373 *
1374 * @note
1375 *
1376 */
1377void
1378bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1379 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1380{
Krishna Gudipati45070252011-06-24 20:24:29 -07001381 int i;
1382 struct bfa_mem_dma_s *dma_info, *dma_elem;
1383 struct bfa_mem_kva_s *kva_info, *kva_elem;
1384 struct list_head *dm_qe, *km_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001385
1386 bfa->fcs = BFA_FALSE;
1387
Jing Huangd4b671c2010-12-26 21:46:35 -08001388 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001389
Krishna Gudipati45070252011-06-24 20:24:29 -07001390 /* Initialize memory pointers for iterative allocation */
1391 dma_info = &meminfo->dma_info;
1392 dma_info->kva_curp = dma_info->kva;
1393 dma_info->dma_curp = dma_info->dma;
1394
1395 kva_info = &meminfo->kva_info;
1396 kva_info->kva_curp = kva_info->kva;
1397
1398 list_for_each(dm_qe, &dma_info->qe) {
1399 dma_elem = (struct bfa_mem_dma_s *) dm_qe;
1400 dma_elem->kva_curp = dma_elem->kva;
1401 dma_elem->dma_curp = dma_elem->dma;
Jing Huang7725ccf2009-09-23 17:46:15 -07001402 }
1403
Krishna Gudipati45070252011-06-24 20:24:29 -07001404 list_for_each(km_qe, &kva_info->qe) {
1405 kva_elem = (struct bfa_mem_kva_s *) km_qe;
1406 kva_elem->kva_curp = kva_elem->kva;
1407 }
1408
1409 bfa_iocfc_attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001410
1411 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001412 hal_mods[i]->attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001413
Krishna Gudipati45070252011-06-24 20:24:29 -07001414 bfa_com_port_attach(bfa);
1415 bfa_com_ablk_attach(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001416}
1417
Jing Huang5fbe25c2010-10-18 17:17:23 -07001418/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001419 * Use this function to delete a BFA IOC. IOC should be stopped (by
1420 * calling bfa_stop()) before this function call.
1421 *
1422 * @param[in] bfa - pointer to bfa_t.
1423 *
1424 * @return
1425 * void
1426 *
1427 * Special Considerations:
1428 *
1429 * @note
1430 */
1431void
1432bfa_detach(struct bfa_s *bfa)
1433{
1434 int i;
1435
1436 for (i = 0; hal_mods[i]; i++)
1437 hal_mods[i]->detach(bfa);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001438 bfa_ioc_detach(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001439}
1440
1441void
1442bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
1443{
1444 INIT_LIST_HEAD(comp_q);
1445 list_splice_tail_init(&bfa->comp_q, comp_q);
1446}
1447
1448void
1449bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
1450{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001451 struct list_head *qe;
1452 struct list_head *qen;
1453 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001454
1455 list_for_each_safe(qe, qen, comp_q) {
1456 hcb_qe = (struct bfa_cb_qe_s *) qe;
1457 hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
1458 }
1459}
1460
1461void
1462bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
1463{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 struct list_head *qe;
1465 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001466
1467 while (!list_empty(comp_q)) {
1468 bfa_q_deq(comp_q, &qe);
1469 hcb_qe = (struct bfa_cb_qe_s *) qe;
1470 hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
1471 }
1472}
1473
Jing Huang7725ccf2009-09-23 17:46:15 -07001474
Jing Huang5fbe25c2010-10-18 17:17:23 -07001475/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001476 * Return the list of PCI vendor/device id lists supported by this
1477 * BFA instance.
1478 */
1479void
1480bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
1481{
1482 static struct bfa_pciid_s __pciids[] = {
1483 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
1484 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
1485 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
Jing Huang293f82d2010-07-08 19:45:20 -07001486 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
Jing Huang7725ccf2009-09-23 17:46:15 -07001487 };
1488
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001489 *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001490 *pciids = __pciids;
1491}
1492
Jing Huang5fbe25c2010-10-18 17:17:23 -07001493/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001494 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
1495 * into BFA layer). The OS driver can then turn back and overwrite entries that
1496 * have been configured by the user.
1497 *
1498 * @param[in] cfg - pointer to bfa_ioc_cfg_t
1499 *
1500 * @return
1501 * void
1502 *
1503 * Special Considerations:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001504 * note
Jing Huang7725ccf2009-09-23 17:46:15 -07001505 */
1506void
1507bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
1508{
1509 cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
1510 cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
1511 cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
1512 cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
1513 cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
1514 cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
1515 cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
1516 cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001517 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001518
1519 cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
1520 cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
1521 cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
1522 cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
1523 cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
1524 cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
1525 cfg->drvcfg.ioc_recover = BFA_FALSE;
1526 cfg->drvcfg.delay_comp = BFA_FALSE;
1527
1528}
1529
1530void
1531bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
1532{
1533 bfa_cfg_get_default(cfg);
1534 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
1535 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
1536 cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
1537 cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
1538 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001539 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001540
1541 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
1542 cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
1543 cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001544 cfg->drvcfg.min_cfg = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001545}