blob: 21343c26721dd6b98e6d3beae72fc81a6141e170 [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,
Krishna Gudipati60138062011-06-24 20:25:15 -0700128 BFA_IOCFC_ACT_ENABLE = 4,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700129};
130
131#define DEF_CFG_NUM_FABRICS 1
132#define DEF_CFG_NUM_LPORTS 256
133#define DEF_CFG_NUM_CQS 4
134#define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
135#define DEF_CFG_NUM_TSKIM_REQS 128
136#define DEF_CFG_NUM_FCXP_REQS 64
137#define DEF_CFG_NUM_UF_BUFS 64
138#define DEF_CFG_NUM_RPORTS 1024
139#define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
140#define DEF_CFG_NUM_TINS 256
141
142#define DEF_CFG_NUM_SGPGS 2048
143#define DEF_CFG_NUM_REQQ_ELEMS 256
144#define DEF_CFG_NUM_RSPQ_ELEMS 64
145#define DEF_CFG_NUM_SBOOT_TGTS 16
146#define DEF_CFG_NUM_SBOOT_LUNS 16
147
Jing Huang5fbe25c2010-10-18 17:17:23 -0700148/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700149 * forward declaration for IOC FC functions
150 */
151static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
152static void bfa_iocfc_disable_cbfn(void *bfa_arg);
153static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
154static void bfa_iocfc_reset_cbfn(void *bfa_arg);
155static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
156
Jing Huang5fbe25c2010-10-18 17:17:23 -0700157/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700158 * BFA Interrupt handling functions
159 */
160static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700161bfa_reqq_resume(struct bfa_s *bfa, int qid)
162{
163 struct list_head *waitq, *qe, *qen;
164 struct bfa_reqq_wait_s *wqe;
165
166 waitq = bfa_reqq(bfa, qid);
167 list_for_each_safe(qe, qen, waitq) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700168 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700169 * Callback only as long as there is room in request queue
170 */
171 if (bfa_reqq_full(bfa, qid))
172 break;
173
174 list_del(qe);
175 wqe = (struct bfa_reqq_wait_s *) qe;
176 wqe->qresume(wqe->cbarg);
177 }
178}
179
Krishna Gudipati11189202011-06-13 15:50:35 -0700180static inline void
181bfa_isr_rspq(struct bfa_s *bfa, int qid)
182{
183 struct bfi_msg_s *m;
184 u32 pi, ci;
185 struct list_head *waitq;
186
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700187 bfa_isr_rspq_ack(bfa, qid);
Krishna Gudipati11189202011-06-13 15:50:35 -0700188
189 ci = bfa_rspq_ci(bfa, qid);
190 pi = bfa_rspq_pi(bfa, qid);
191
192 while (ci != pi) {
193 m = bfa_rspq_elem(bfa, qid, ci);
194 WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
195
196 bfa_isrs[m->mhdr.msg_class] (bfa, m);
197 CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
198 }
199
200 /*
201 * update CI
202 */
203 bfa_rspq_ci(bfa, qid) = pi;
204 writel(pi, bfa->iocfc.bfa_regs.rme_q_ci[qid]);
205 mmiowb();
206
207 /*
208 * Resume any pending requests in the corresponding reqq.
209 */
210 waitq = bfa_reqq(bfa, qid);
211 if (!list_empty(waitq))
212 bfa_reqq_resume(bfa, qid);
213}
214
215static inline void
216bfa_isr_reqq(struct bfa_s *bfa, int qid)
217{
218 struct list_head *waitq;
219
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700220 bfa_isr_reqq_ack(bfa, qid);
Krishna Gudipati11189202011-06-13 15:50:35 -0700221
222 /*
223 * Resume any pending requests in the corresponding reqq.
224 */
225 waitq = bfa_reqq(bfa, qid);
226 if (!list_empty(waitq))
227 bfa_reqq_resume(bfa, qid);
228}
229
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700230void
231bfa_msix_all(struct bfa_s *bfa, int vec)
232{
Krishna Gudipati10a07372011-06-24 20:23:38 -0700233 u32 intr, qintr;
234 int queue;
235
236 intr = readl(bfa->iocfc.bfa_regs.intr_status);
237 if (!intr)
238 return;
239
240 /*
241 * RME completion queue interrupt
242 */
243 qintr = intr & __HFN_INT_RME_MASK;
244 if (qintr && bfa->queue_process) {
245 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
246 bfa_isr_rspq(bfa, queue);
247 }
248
249 intr &= ~qintr;
250 if (!intr)
251 return;
252
253 /*
254 * CPE completion queue interrupt
255 */
256 qintr = intr & __HFN_INT_CPE_MASK;
257 if (qintr && bfa->queue_process) {
258 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
259 bfa_isr_reqq(bfa, queue);
260 }
261 intr &= ~qintr;
262 if (!intr)
263 return;
264
265 bfa_msix_lpu_err(bfa, intr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700266}
267
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700268bfa_boolean_t
269bfa_intx(struct bfa_s *bfa)
270{
271 u32 intr, qintr;
272 int queue;
273
Jing Huang53440262010-10-18 17:12:29 -0700274 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700275 if (!intr)
276 return BFA_FALSE;
277
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700278 qintr = intr & (__HFN_INT_RME_MASK | __HFN_INT_CPE_MASK);
279 if (qintr)
280 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
281
Jing Huang5fbe25c2010-10-18 17:17:23 -0700282 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700283 * RME completion queue interrupt
284 */
285 qintr = intr & __HFN_INT_RME_MASK;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700286 if (qintr && bfa->queue_process) {
287 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
288 bfa_isr_rspq(bfa, queue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700289 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700290
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700291 intr &= ~qintr;
292 if (!intr)
293 return BFA_TRUE;
294
Jing Huang5fbe25c2010-10-18 17:17:23 -0700295 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700296 * CPE completion queue interrupt
297 */
298 qintr = intr & __HFN_INT_CPE_MASK;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700299 if (qintr && bfa->queue_process) {
300 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
301 bfa_isr_reqq(bfa, queue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700302 }
303 intr &= ~qintr;
304 if (!intr)
305 return BFA_TRUE;
306
307 bfa_msix_lpu_err(bfa, intr);
308
309 return BFA_TRUE;
310}
311
312void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700313bfa_isr_enable(struct bfa_s *bfa)
314{
Krishna Gudipati11189202011-06-13 15:50:35 -0700315 u32 umsk;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700316 int pci_func = bfa_ioc_pcifn(&bfa->ioc);
317
318 bfa_trc(bfa, pci_func);
319
Krishna Gudipati775c7742011-06-13 15:52:12 -0700320 bfa_msix_ctrl_install(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700321
Krishna Gudipati11189202011-06-13 15:50:35 -0700322 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
323 umsk = __HFN_INT_ERR_MASK_CT2;
324 umsk |= pci_func == 0 ?
325 __HFN_INT_FN0_MASK_CT2 : __HFN_INT_FN1_MASK_CT2;
326 } else {
327 umsk = __HFN_INT_ERR_MASK;
328 umsk |= pci_func == 0 ? __HFN_INT_FN0_MASK : __HFN_INT_FN1_MASK;
329 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700330
Krishna Gudipati11189202011-06-13 15:50:35 -0700331 writel(umsk, bfa->iocfc.bfa_regs.intr_status);
332 writel(~umsk, bfa->iocfc.bfa_regs.intr_mask);
333 bfa->iocfc.intr_mask = ~umsk;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700334 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
335}
336
337void
338bfa_isr_disable(struct bfa_s *bfa)
339{
340 bfa_isr_mode_set(bfa, BFA_FALSE);
Jing Huang53440262010-10-18 17:12:29 -0700341 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700342 bfa_msix_uninstall(bfa);
343}
344
345void
Krishna Gudipati11189202011-06-13 15:50:35 -0700346bfa_msix_reqq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700347{
Krishna Gudipati11189202011-06-13 15:50:35 -0700348 bfa_isr_reqq(bfa, vec - bfa->iocfc.hwif.cpe_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700349}
350
351void
352bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
353{
354 bfa_trc(bfa, m->mhdr.msg_class);
355 bfa_trc(bfa, m->mhdr.msg_id);
356 bfa_trc(bfa, m->mhdr.mtag.i2htok);
Jing Huangd4b671c2010-12-26 21:46:35 -0800357 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700358 bfa_trc_stop(bfa->trcmod);
359}
360
361void
Krishna Gudipati11189202011-06-13 15:50:35 -0700362bfa_msix_rspq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700363{
Krishna Gudipati11189202011-06-13 15:50:35 -0700364 bfa_isr_rspq(bfa, vec - bfa->iocfc.hwif.rme_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700365}
366
367void
368bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
369{
370 u32 intr, curr_value;
Krishna Gudipati11189202011-06-13 15:50:35 -0700371 bfa_boolean_t lpu_isr, halt_isr, pss_isr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700372
Jing Huang53440262010-10-18 17:12:29 -0700373 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374
Krishna Gudipati11189202011-06-13 15:50:35 -0700375 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
376 halt_isr = intr & __HFN_INT_CPQ_HALT_CT2;
377 pss_isr = intr & __HFN_INT_ERR_PSS_CT2;
378 lpu_isr = intr & (__HFN_INT_MBOX_LPU0_CT2 |
379 __HFN_INT_MBOX_LPU1_CT2);
380 intr &= __HFN_INT_ERR_MASK_CT2;
381 } else {
382 halt_isr = intr & __HFN_INT_LL_HALT;
383 pss_isr = intr & __HFN_INT_ERR_PSS;
384 lpu_isr = intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1);
385 intr &= __HFN_INT_ERR_MASK;
386 }
387
388 if (lpu_isr)
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800389 bfa_ioc_mbox_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700390
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700391 if (intr) {
Krishna Gudipati11189202011-06-13 15:50:35 -0700392 if (halt_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700393 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700394 * If LL_HALT bit is set then FW Init Halt LL Port
395 * Register needs to be cleared as well so Interrupt
396 * Status Register will be cleared.
397 */
Jing Huang53440262010-10-18 17:12:29 -0700398 curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700399 curr_value &= ~__FW_INIT_HALT_P;
Jing Huang53440262010-10-18 17:12:29 -0700400 writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700401 }
402
Krishna Gudipati11189202011-06-13 15:50:35 -0700403 if (pss_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700404 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700405 * ERR_PSS bit needs to be cleared as well in case
406 * interrups are shared so driver's interrupt handler is
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300407 * still called even though it is already masked out.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700408 */
Jing Huang53440262010-10-18 17:12:29 -0700409 curr_value = readl(
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700410 bfa->ioc.ioc_regs.pss_err_status_reg);
Jing Huang53440262010-10-18 17:12:29 -0700411 writel(curr_value,
412 bfa->ioc.ioc_regs.pss_err_status_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700413 }
414
Jing Huang53440262010-10-18 17:12:29 -0700415 writel(intr, bfa->iocfc.bfa_regs.intr_status);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800416 bfa_ioc_error_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700417 }
418}
419
Jing Huang5fbe25c2010-10-18 17:17:23 -0700420/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700421 * BFA IOC FC related functions
422 */
423
Jing Huang5fbe25c2010-10-18 17:17:23 -0700424/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -0800425 * BFA IOC private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700426 */
427
Jing Huang5fbe25c2010-10-18 17:17:23 -0700428/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700429 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
430 */
431static void
432bfa_iocfc_send_cfg(void *bfa_arg)
433{
434 struct bfa_s *bfa = bfa_arg;
435 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
436 struct bfi_iocfc_cfg_req_s cfg_req;
437 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
438 struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
439 int i;
440
Jing Huangd4b671c2010-12-26 21:46:35 -0800441 WARN_ON(cfg->fwcfg.num_cqs > BFI_IOC_MAX_CQS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700442 bfa_trc(bfa, cfg->fwcfg.num_cqs);
443
444 bfa_iocfc_reset_queues(bfa);
445
Jing Huang5fbe25c2010-10-18 17:17:23 -0700446 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700447 * initialize IOC configuration info
448 */
Krishna Gudipati10a07372011-06-24 20:23:38 -0700449 cfg_info->single_msix_vec = 0;
450 if (bfa->msix.nvecs == 1)
451 cfg_info->single_msix_vec = 1;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700452 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
453 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700454 cfg_info->num_ioim_reqs = cpu_to_be16(cfg->fwcfg.num_ioim_reqs);
455 cfg_info->num_fwtio_reqs = cpu_to_be16(cfg->fwcfg.num_fwtio_reqs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700456
457 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700458 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700459 * dma map REQ and RSP circular queues and shadow pointers
460 */
461 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
462 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
463 iocfc->req_cq_ba[i].pa);
464 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
465 iocfc->req_cq_shadow_ci[i].pa);
466 cfg_info->req_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700467 cpu_to_be16(cfg->drvcfg.num_reqq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700468
469 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
470 iocfc->rsp_cq_ba[i].pa);
471 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
472 iocfc->rsp_cq_shadow_pi[i].pa);
473 cfg_info->rsp_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700474 cpu_to_be16(cfg->drvcfg.num_rspq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475 }
476
Jing Huang5fbe25c2010-10-18 17:17:23 -0700477 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700478 * Enable interrupt coalescing if it is driver init path
479 * and not ioc disable/enable path.
480 */
481 if (!iocfc->cfgdone)
482 cfg_info->intr_attr.coalesce = BFA_TRUE;
483
484 iocfc->cfgdone = BFA_FALSE;
485
Jing Huang5fbe25c2010-10-18 17:17:23 -0700486 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700487 * dma map IOC configuration itself
488 */
489 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700490 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700491 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
492
493 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
494 sizeof(struct bfi_iocfc_cfg_req_s));
495}
496
497static void
498bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
499 struct bfa_pcidev_s *pcidev)
500{
501 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
502
503 bfa->bfad = bfad;
504 iocfc->bfa = bfa;
505 iocfc->action = BFA_IOCFC_ACT_NONE;
506
Jing Huang6a18b162010-10-18 17:08:54 -0700507 iocfc->cfg = *cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700508
Jing Huang5fbe25c2010-10-18 17:17:23 -0700509 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700510 * Initialize chip specific handlers.
511 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700512 if (bfa_asic_id_ctc(bfa_ioc_devid(&bfa->ioc))) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700513 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
514 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
515 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
516 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -0700517 iocfc->hwif.hw_msix_ctrl_install = bfa_hwct_msix_ctrl_install;
518 iocfc->hwif.hw_msix_queue_install = bfa_hwct_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700519 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
520 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
521 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
522 iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -0700523 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CT;
524 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CT;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700525 } else {
526 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700527 iocfc->hwif.hw_reqq_ack = NULL;
528 iocfc->hwif.hw_rspq_ack = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700529 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -0700530 iocfc->hwif.hw_msix_ctrl_install = bfa_hwcb_msix_ctrl_install;
531 iocfc->hwif.hw_msix_queue_install = bfa_hwcb_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700532 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
533 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
534 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
535 iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -0700536 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CB +
537 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
538 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CB +
539 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
540 }
541
542 if (bfa_asic_id_ct2(bfa_ioc_devid(&bfa->ioc))) {
543 iocfc->hwif.hw_reginit = bfa_hwct2_reginit;
544 iocfc->hwif.hw_isr_mode_set = NULL;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700545 iocfc->hwif.hw_rspq_ack = NULL;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700546 }
547
548 iocfc->hwif.hw_reginit(bfa);
549 bfa->msix.nvecs = 0;
550}
551
552static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700553bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700554{
Krishna Gudipati45070252011-06-24 20:24:29 -0700555 u8 *dm_kva = NULL;
556 u64 dm_pa = 0;
557 int i, per_reqq_sz, per_rspq_sz, dbgsz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700558 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
Krishna Gudipati45070252011-06-24 20:24:29 -0700559 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
560 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
561 struct bfa_mem_dma_s *reqq_dma, *rspq_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700562
Krishna Gudipati45070252011-06-24 20:24:29 -0700563 /* First allocate dma memory for IOC */
564 bfa_ioc_mem_claim(&bfa->ioc, bfa_mem_dma_virt(ioc_dma),
565 bfa_mem_dma_phys(ioc_dma));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700566
Krishna Gudipati45070252011-06-24 20:24:29 -0700567 /* Claim DMA-able memory for the request/response queues */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700568 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -0700569 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700570 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -0700571 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700572
573 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
Krishna Gudipati45070252011-06-24 20:24:29 -0700574 reqq_dma = BFA_MEM_REQQ_DMA(bfa, i);
575 iocfc->req_cq_ba[i].kva = bfa_mem_dma_virt(reqq_dma);
576 iocfc->req_cq_ba[i].pa = bfa_mem_dma_phys(reqq_dma);
577 memset(iocfc->req_cq_ba[i].kva, 0, per_reqq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700578
Krishna Gudipati45070252011-06-24 20:24:29 -0700579 rspq_dma = BFA_MEM_RSPQ_DMA(bfa, i);
580 iocfc->rsp_cq_ba[i].kva = bfa_mem_dma_virt(rspq_dma);
581 iocfc->rsp_cq_ba[i].pa = bfa_mem_dma_phys(rspq_dma);
582 memset(iocfc->rsp_cq_ba[i].kva, 0, per_rspq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700583 }
584
Krishna Gudipati45070252011-06-24 20:24:29 -0700585 /* Claim IOCFC dma memory - for shadow CI/PI */
586 dm_kva = bfa_mem_dma_virt(iocfc_dma);
587 dm_pa = bfa_mem_dma_phys(iocfc_dma);
588
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700589 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
590 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
591 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
592 dm_kva += BFA_CACHELINE_SZ;
593 dm_pa += BFA_CACHELINE_SZ;
594
595 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
596 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
597 dm_kva += BFA_CACHELINE_SZ;
598 dm_pa += BFA_CACHELINE_SZ;
599 }
600
Krishna Gudipati45070252011-06-24 20:24:29 -0700601 /* Claim IOCFC dma memory - for the config info page */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700602 bfa->iocfc.cfg_info.kva = dm_kva;
603 bfa->iocfc.cfg_info.pa = dm_pa;
604 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
605 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
606 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
607
Krishna Gudipati45070252011-06-24 20:24:29 -0700608 /* Claim IOCFC dma memory - for the config response */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700609 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
610 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
611 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
Krishna Gudipati45070252011-06-24 20:24:29 -0700612 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
613 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700614 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
Krishna Gudipati45070252011-06-24 20:24:29 -0700615 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700616
Krishna Gudipati45070252011-06-24 20:24:29 -0700617 /* Claim IOCFC kva memory */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800618 dbgsz = (bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700619 if (dbgsz > 0) {
Krishna Gudipati45070252011-06-24 20:24:29 -0700620 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_mem_kva_curp(iocfc));
621 bfa_mem_kva_curp(iocfc) += dbgsz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700622 }
623}
624
Jing Huang5fbe25c2010-10-18 17:17:23 -0700625/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700626 * Start BFA submodules.
627 */
628static void
629bfa_iocfc_start_submod(struct bfa_s *bfa)
630{
631 int i;
632
Krishna Gudipati775c7742011-06-13 15:52:12 -0700633 bfa->queue_process = BFA_TRUE;
Krishna Gudipati11189202011-06-13 15:50:35 -0700634 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700635 bfa_isr_rspq_ack(bfa, i);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700636
637 for (i = 0; hal_mods[i]; i++)
638 hal_mods[i]->start(bfa);
639}
640
Jing Huang5fbe25c2010-10-18 17:17:23 -0700641/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700642 * Disable BFA submodules.
643 */
644static void
645bfa_iocfc_disable_submod(struct bfa_s *bfa)
646{
647 int i;
648
649 for (i = 0; hal_mods[i]; i++)
650 hal_mods[i]->iocdisable(bfa);
651}
652
653static void
654bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
655{
656 struct bfa_s *bfa = bfa_arg;
657
658 if (complete) {
659 if (bfa->iocfc.cfgdone)
660 bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
661 else
662 bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
663 } else {
664 if (bfa->iocfc.cfgdone)
665 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
666 }
667}
668
669static void
670bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
671{
672 struct bfa_s *bfa = bfa_arg;
673 struct bfad_s *bfad = bfa->bfad;
674
675 if (compl)
676 complete(&bfad->comp);
677 else
678 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
679}
680
681static void
Krishna Gudipati60138062011-06-24 20:25:15 -0700682bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl)
683{
684 struct bfa_s *bfa = bfa_arg;
685 struct bfad_s *bfad = bfa->bfad;
686
687 if (compl)
688 complete(&bfad->enable_comp);
689}
690
691static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700692bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
693{
694 struct bfa_s *bfa = bfa_arg;
695 struct bfad_s *bfad = bfa->bfad;
696
697 if (compl)
698 complete(&bfad->disable_comp);
699}
700
Krishna Gudipati11189202011-06-13 15:50:35 -0700701/**
702 * configure queue registers from firmware response
703 */
704static void
705bfa_iocfc_qreg(struct bfa_s *bfa, struct bfi_iocfc_qreg_s *qreg)
706{
707 int i;
708 struct bfa_iocfc_regs_s *r = &bfa->iocfc.bfa_regs;
709 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
710
711 for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700712 bfa->iocfc.hw_qid[i] = qreg->hw_qid[i];
Krishna Gudipati11189202011-06-13 15:50:35 -0700713 r->cpe_q_ci[i] = kva + be32_to_cpu(qreg->cpe_q_ci_off[i]);
714 r->cpe_q_pi[i] = kva + be32_to_cpu(qreg->cpe_q_pi_off[i]);
715 r->cpe_q_ctrl[i] = kva + be32_to_cpu(qreg->cpe_qctl_off[i]);
716 r->rme_q_ci[i] = kva + be32_to_cpu(qreg->rme_q_ci_off[i]);
717 r->rme_q_pi[i] = kva + be32_to_cpu(qreg->rme_q_pi_off[i]);
718 r->rme_q_ctrl[i] = kva + be32_to_cpu(qreg->rme_qctl_off[i]);
719 }
720}
721
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700722static void
723bfa_iocfc_res_recfg(struct bfa_s *bfa, struct bfa_iocfc_fwcfg_s *fwcfg)
724{
725 bfa_fcxp_res_recfg(bfa, fwcfg->num_fcxp_reqs);
726 bfa_uf_res_recfg(bfa, fwcfg->num_uf_bufs);
727 bfa_rport_res_recfg(bfa, fwcfg->num_rports);
728 bfa_fcp_res_recfg(bfa, fwcfg->num_ioim_reqs);
729 bfa_tskim_res_recfg(bfa, fwcfg->num_tskim_reqs);
730}
731
Jing Huang5fbe25c2010-10-18 17:17:23 -0700732/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700733 * Update BFA configuration from firmware configuration.
734 */
735static void
736bfa_iocfc_cfgrsp(struct bfa_s *bfa)
737{
738 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
739 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
740 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
741
742 fwcfg->num_cqs = fwcfg->num_cqs;
Jing Huangba816ea2010-10-18 17:10:50 -0700743 fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700744 fwcfg->num_fwtio_reqs = be16_to_cpu(fwcfg->num_fwtio_reqs);
Jing Huangba816ea2010-10-18 17:10:50 -0700745 fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
746 fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
747 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
748 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700749
750 iocfc->cfgdone = BFA_TRUE;
751
Jing Huang5fbe25c2010-10-18 17:17:23 -0700752 /*
Krishna Gudipati11189202011-06-13 15:50:35 -0700753 * configure queue register offsets as learnt from firmware
754 */
755 bfa_iocfc_qreg(bfa, &cfgrsp->qreg);
756
757 /*
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700758 * Re-configure resources as learnt from Firmware
759 */
760 bfa_iocfc_res_recfg(bfa, fwcfg);
761
762 /*
Krishna Gudipati775c7742011-06-13 15:52:12 -0700763 * Install MSIX queue handlers
764 */
765 bfa_msix_queue_install(bfa);
766
767 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700768 * Configuration is complete - initialize/start submodules
769 */
770 bfa_fcport_init(bfa);
771
772 if (iocfc->action == BFA_IOCFC_ACT_INIT)
773 bfa_cb_queue(bfa, &iocfc->init_hcb_qe, bfa_iocfc_init_cb, bfa);
Krishna Gudipati60138062011-06-24 20:25:15 -0700774 else {
775 if (bfa->iocfc.action == BFA_IOCFC_ACT_ENABLE)
776 bfa_cb_queue(bfa, &bfa->iocfc.en_hcb_qe,
777 bfa_iocfc_enable_cb, bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700778 bfa_iocfc_start_submod(bfa);
Krishna Gudipati60138062011-06-24 20:25:15 -0700779 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700780}
781void
782bfa_iocfc_reset_queues(struct bfa_s *bfa)
783{
784 int q;
785
786 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
787 bfa_reqq_ci(bfa, q) = 0;
788 bfa_reqq_pi(bfa, q) = 0;
789 bfa_rspq_ci(bfa, q) = 0;
790 bfa_rspq_pi(bfa, q) = 0;
791 }
792}
793
Krishna Gudipatia7141342011-06-24 20:23:19 -0700794/* Fabric Assigned Address specific functions */
795
796/*
797 * Check whether IOC is ready before sending command down
798 */
799static bfa_status_t
800bfa_faa_validate_request(struct bfa_s *bfa)
801{
802 enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
803 u32 card_type = bfa->ioc.attr->card_type;
804
805 if (bfa_ioc_is_operational(&bfa->ioc)) {
806 if ((ioc_type != BFA_IOC_TYPE_FC) || bfa_mfg_is_mezz(card_type))
807 return BFA_STATUS_FEATURE_NOT_SUPPORTED;
808 } else {
809 if (!bfa_ioc_is_acq_addr(&bfa->ioc))
810 return BFA_STATUS_IOC_NON_OP;
811 }
812
813 return BFA_STATUS_OK;
814}
815
816bfa_status_t
817bfa_faa_enable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn, void *cbarg)
818{
819 struct bfi_faa_en_dis_s faa_enable_req;
820 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
821 bfa_status_t status;
822
823 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
824 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
825
826 status = bfa_faa_validate_request(bfa);
827 if (status != BFA_STATUS_OK)
828 return status;
829
830 if (iocfc->faa_args.busy == BFA_TRUE)
831 return BFA_STATUS_DEVBUSY;
832
833 if (iocfc->faa_args.faa_state == BFA_FAA_ENABLED)
834 return BFA_STATUS_FAA_ENABLED;
835
836 if (bfa_fcport_is_trunk_enabled(bfa))
837 return BFA_STATUS_ERROR_TRUNK_ENABLED;
838
839 bfa_fcport_cfg_faa(bfa, BFA_FAA_ENABLED);
840 iocfc->faa_args.busy = BFA_TRUE;
841
842 memset(&faa_enable_req, 0, sizeof(struct bfi_faa_en_dis_s));
843 bfi_h2i_set(faa_enable_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700844 BFI_IOCFC_H2I_FAA_ENABLE_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -0700845
846 bfa_ioc_mbox_send(&bfa->ioc, &faa_enable_req,
847 sizeof(struct bfi_faa_en_dis_s));
848
849 return BFA_STATUS_OK;
850}
851
852bfa_status_t
853bfa_faa_disable(struct bfa_s *bfa, bfa_cb_iocfc_t cbfn,
854 void *cbarg)
855{
856 struct bfi_faa_en_dis_s faa_disable_req;
857 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
858 bfa_status_t status;
859
860 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
861 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
862
863 status = bfa_faa_validate_request(bfa);
864 if (status != BFA_STATUS_OK)
865 return status;
866
867 if (iocfc->faa_args.busy == BFA_TRUE)
868 return BFA_STATUS_DEVBUSY;
869
870 if (iocfc->faa_args.faa_state == BFA_FAA_DISABLED)
871 return BFA_STATUS_FAA_DISABLED;
872
873 bfa_fcport_cfg_faa(bfa, BFA_FAA_DISABLED);
874 iocfc->faa_args.busy = BFA_TRUE;
875
876 memset(&faa_disable_req, 0, sizeof(struct bfi_faa_en_dis_s));
877 bfi_h2i_set(faa_disable_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700878 BFI_IOCFC_H2I_FAA_DISABLE_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -0700879
880 bfa_ioc_mbox_send(&bfa->ioc, &faa_disable_req,
881 sizeof(struct bfi_faa_en_dis_s));
882
883 return BFA_STATUS_OK;
884}
885
886bfa_status_t
887bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
888 bfa_cb_iocfc_t cbfn, void *cbarg)
889{
890 struct bfi_faa_query_s faa_attr_req;
891 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
892 bfa_status_t status;
893
894 iocfc->faa_args.faa_attr = attr;
895 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
896 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
897
898 status = bfa_faa_validate_request(bfa);
899 if (status != BFA_STATUS_OK)
900 return status;
901
902 if (iocfc->faa_args.busy == BFA_TRUE)
903 return BFA_STATUS_DEVBUSY;
904
905 iocfc->faa_args.busy = BFA_TRUE;
906 memset(&faa_attr_req, 0, sizeof(struct bfi_faa_query_s));
907 bfi_h2i_set(faa_attr_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700908 BFI_IOCFC_H2I_FAA_QUERY_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -0700909
910 bfa_ioc_mbox_send(&bfa->ioc, &faa_attr_req,
911 sizeof(struct bfi_faa_query_s));
912
913 return BFA_STATUS_OK;
914}
915
916/*
917 * FAA enable response
918 */
919static void
920bfa_faa_enable_reply(struct bfa_iocfc_s *iocfc,
921 struct bfi_faa_en_dis_rsp_s *rsp)
922{
923 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
924 bfa_status_t status = rsp->status;
925
926 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
927
928 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
929 iocfc->faa_args.busy = BFA_FALSE;
930}
931
932/*
933 * FAA disable response
934 */
935static void
936bfa_faa_disable_reply(struct bfa_iocfc_s *iocfc,
937 struct bfi_faa_en_dis_rsp_s *rsp)
938{
939 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
940 bfa_status_t status = rsp->status;
941
942 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
943
944 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, status);
945 iocfc->faa_args.busy = BFA_FALSE;
946}
947
948/*
949 * FAA query response
950 */
951static void
952bfa_faa_query_reply(struct bfa_iocfc_s *iocfc,
953 bfi_faa_query_rsp_t *rsp)
954{
955 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
956
957 if (iocfc->faa_args.faa_attr) {
958 iocfc->faa_args.faa_attr->faa = rsp->faa;
959 iocfc->faa_args.faa_attr->faa_state = rsp->faa_status;
960 iocfc->faa_args.faa_attr->pwwn_source = rsp->addr_source;
961 }
962
963 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
964
965 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, BFA_STATUS_OK);
966 iocfc->faa_args.busy = BFA_FALSE;
967}
968
Jing Huang5fbe25c2010-10-18 17:17:23 -0700969/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700970 * IOC enable request is complete
971 */
972static void
973bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
974{
975 struct bfa_s *bfa = bfa_arg;
976
Krishna Gudipatia7141342011-06-24 20:23:19 -0700977 if (status == BFA_STATUS_FAA_ACQ_ADDR) {
978 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
979 bfa_iocfc_init_cb, bfa);
980 return;
981 }
982
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700983 if (status != BFA_STATUS_OK) {
984 bfa_isr_disable(bfa);
985 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
986 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
987 bfa_iocfc_init_cb, bfa);
Krishna Gudipati60138062011-06-24 20:25:15 -0700988 else if (bfa->iocfc.action == BFA_IOCFC_ACT_ENABLE)
989 bfa_cb_queue(bfa, &bfa->iocfc.en_hcb_qe,
990 bfa_iocfc_enable_cb, bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991 return;
992 }
993
994 bfa_iocfc_send_cfg(bfa);
995}
996
Jing Huang5fbe25c2010-10-18 17:17:23 -0700997/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700998 * IOC disable request is complete
999 */
1000static void
1001bfa_iocfc_disable_cbfn(void *bfa_arg)
1002{
1003 struct bfa_s *bfa = bfa_arg;
1004
1005 bfa_isr_disable(bfa);
1006 bfa_iocfc_disable_submod(bfa);
1007
1008 if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
1009 bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
1010 bfa);
1011 else {
Jing Huangd4b671c2010-12-26 21:46:35 -08001012 WARN_ON(bfa->iocfc.action != BFA_IOCFC_ACT_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001013 bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
1014 bfa);
1015 }
1016}
1017
Jing Huang5fbe25c2010-10-18 17:17:23 -07001018/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001019 * Notify sub-modules of hardware failure.
1020 */
1021static void
1022bfa_iocfc_hbfail_cbfn(void *bfa_arg)
1023{
1024 struct bfa_s *bfa = bfa_arg;
1025
Krishna Gudipati775c7742011-06-13 15:52:12 -07001026 bfa->queue_process = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001027
1028 bfa_isr_disable(bfa);
1029 bfa_iocfc_disable_submod(bfa);
1030
1031 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
1032 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
1033 bfa);
1034}
1035
Jing Huang5fbe25c2010-10-18 17:17:23 -07001036/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001037 * Actions on chip-reset completion.
1038 */
1039static void
1040bfa_iocfc_reset_cbfn(void *bfa_arg)
1041{
1042 struct bfa_s *bfa = bfa_arg;
1043
1044 bfa_iocfc_reset_queues(bfa);
1045 bfa_isr_enable(bfa);
1046}
1047
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001048
Jing Huang5fbe25c2010-10-18 17:17:23 -07001049/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001050 * Query IOC memory requirement information.
1051 */
1052void
Krishna Gudipati45070252011-06-24 20:24:29 -07001053bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1054 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001055{
Krishna Gudipati45070252011-06-24 20:24:29 -07001056 int q, per_reqq_sz, per_rspq_sz;
1057 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
1058 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
1059 struct bfa_mem_kva_s *iocfc_kva = BFA_MEM_IOCFC_KVA(bfa);
1060 u32 dm_len = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001061
Krishna Gudipati45070252011-06-24 20:24:29 -07001062 /* dma memory setup for IOC */
1063 bfa_mem_dma_setup(meminfo, ioc_dma,
1064 BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ));
1065
1066 /* dma memory setup for REQ/RSP queues */
1067 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
1068 BFA_DMA_ALIGN_SZ);
1069 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
1070 BFA_DMA_ALIGN_SZ);
1071
1072 for (q = 0; q < cfg->fwcfg.num_cqs; q++) {
1073 bfa_mem_dma_setup(meminfo, BFA_MEM_REQQ_DMA(bfa, q),
1074 per_reqq_sz);
1075 bfa_mem_dma_setup(meminfo, BFA_MEM_RSPQ_DMA(bfa, q),
1076 per_rspq_sz);
1077 }
1078
1079 /* IOCFC dma memory - calculate Shadow CI/PI size */
1080 for (q = 0; q < cfg->fwcfg.num_cqs; q++)
1081 dm_len += (2 * BFA_CACHELINE_SZ);
1082
1083 /* IOCFC dma memory - calculate config info / rsp size */
1084 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1085 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
1086 BFA_CACHELINE_SZ);
1087
1088 /* dma memory setup for IOCFC */
1089 bfa_mem_dma_setup(meminfo, iocfc_dma, dm_len);
1090
1091 /* kva memory setup for IOCFC */
1092 bfa_mem_kva_setup(meminfo, iocfc_kva,
1093 ((bfa_auto_recover) ? BFA_DBG_FWTRC_LEN : 0));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001094}
1095
Jing Huang5fbe25c2010-10-18 17:17:23 -07001096/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001097 * Query IOC memory requirement information.
1098 */
1099void
1100bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001101 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001102{
1103 int i;
1104 struct bfa_ioc_s *ioc = &bfa->ioc;
1105
1106 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
1107 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
1108 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
1109 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
1110
1111 ioc->trcmod = bfa->trcmod;
1112 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
1113
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001114 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_PCIFN_CLASS_FC);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001115 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
1116
1117 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
Krishna Gudipati45070252011-06-24 20:24:29 -07001118 bfa_iocfc_mem_claim(bfa, cfg);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001119 INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001120
1121 INIT_LIST_HEAD(&bfa->comp_q);
1122 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
1123 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
1124}
1125
Jing Huang5fbe25c2010-10-18 17:17:23 -07001126/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001127 * Query IOC memory requirement information.
1128 */
1129void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001130bfa_iocfc_init(struct bfa_s *bfa)
1131{
1132 bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
1133 bfa_ioc_enable(&bfa->ioc);
1134}
1135
Jing Huang5fbe25c2010-10-18 17:17:23 -07001136/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137 * IOC start called from bfa_start(). Called to start IOC operations
1138 * at driver instantiation for this instance.
1139 */
1140void
1141bfa_iocfc_start(struct bfa_s *bfa)
1142{
1143 if (bfa->iocfc.cfgdone)
1144 bfa_iocfc_start_submod(bfa);
1145}
1146
Jing Huang5fbe25c2010-10-18 17:17:23 -07001147/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001148 * IOC stop called from bfa_stop(). Called only when driver is unloaded
1149 * for this instance.
1150 */
1151void
1152bfa_iocfc_stop(struct bfa_s *bfa)
1153{
1154 bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
1155
Krishna Gudipati775c7742011-06-13 15:52:12 -07001156 bfa->queue_process = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157 bfa_ioc_disable(&bfa->ioc);
1158}
1159
1160void
1161bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
1162{
1163 struct bfa_s *bfa = bfaarg;
1164 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1165 union bfi_iocfc_i2h_msg_u *msg;
1166
1167 msg = (union bfi_iocfc_i2h_msg_u *) m;
1168 bfa_trc(bfa, msg->mh.msg_id);
1169
1170 switch (msg->mh.msg_id) {
1171 case BFI_IOCFC_I2H_CFG_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001172 bfa_iocfc_cfgrsp(bfa);
1173 break;
1174 case BFI_IOCFC_I2H_UPDATEQ_RSP:
1175 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
1176 break;
Krishna Gudipatia7141342011-06-24 20:23:19 -07001177 case BFI_IOCFC_I2H_FAA_ENABLE_RSP:
1178 bfa_faa_enable_reply(iocfc,
1179 (struct bfi_faa_en_dis_rsp_s *)msg);
1180 break;
1181 case BFI_IOCFC_I2H_FAA_DISABLE_RSP:
1182 bfa_faa_disable_reply(iocfc,
1183 (struct bfi_faa_en_dis_rsp_s *)msg);
1184 break;
1185 case BFI_IOCFC_I2H_FAA_QUERY_RSP:
1186 bfa_faa_query_reply(iocfc, (bfi_faa_query_rsp_t *)msg);
1187 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001188 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001189 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001190 }
1191}
1192
1193void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001194bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
1195{
1196 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1197
1198 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
1199
1200 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
Jing Huangba816ea2010-10-18 17:10:50 -07001201 be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
1202 be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001203
1204 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
Jing Huangba816ea2010-10-18 17:10:50 -07001205 be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
1206 be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001207
1208 attr->config = iocfc->cfg;
1209}
1210
1211bfa_status_t
1212bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
1213{
1214 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1215 struct bfi_iocfc_set_intr_req_s *m;
1216
1217 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
Jing Huangba816ea2010-10-18 17:10:50 -07001218 iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
1219 iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001220
1221 if (!bfa_iocfc_is_operational(bfa))
1222 return BFA_STATUS_OK;
1223
1224 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
1225 if (!m)
1226 return BFA_STATUS_DEVBUSY;
1227
1228 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001229 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001230 m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
1231 m->delay = iocfc->cfginfo->intr_attr.delay;
1232 m->latency = iocfc->cfginfo->intr_attr.latency;
1233
1234 bfa_trc(bfa, attr->delay);
1235 bfa_trc(bfa, attr->latency);
1236
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001237 bfa_reqq_produce(bfa, BFA_REQQ_IOC, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001238 return BFA_STATUS_OK;
1239}
1240
1241void
Krishna Gudipati45070252011-06-24 20:24:29 -07001242bfa_iocfc_set_snsbase(struct bfa_s *bfa, int seg_no, u64 snsbase_pa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001243{
1244 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1245
1246 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
Krishna Gudipati45070252011-06-24 20:24:29 -07001247 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase[seg_no], snsbase_pa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001248}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001249/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001250 * Enable IOC after it is disabled.
1251 */
1252void
1253bfa_iocfc_enable(struct bfa_s *bfa)
1254{
1255 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1256 "IOC Enable");
Krishna Gudipati60138062011-06-24 20:25:15 -07001257 bfa->iocfc.action = BFA_IOCFC_ACT_ENABLE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001258 bfa_ioc_enable(&bfa->ioc);
1259}
1260
1261void
1262bfa_iocfc_disable(struct bfa_s *bfa)
1263{
1264 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1265 "IOC Disable");
1266 bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
1267
Krishna Gudipati775c7742011-06-13 15:52:12 -07001268 bfa->queue_process = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001269 bfa_ioc_disable(&bfa->ioc);
1270}
1271
1272
1273bfa_boolean_t
1274bfa_iocfc_is_operational(struct bfa_s *bfa)
1275{
1276 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
1277}
1278
Jing Huang5fbe25c2010-10-18 17:17:23 -07001279/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001280 * Return boot target port wwns -- read from boot information in flash.
1281 */
1282void
1283bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
1284{
1285 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1286 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1287 int i;
1288
1289 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
1290 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
1291 *nwwns = cfgrsp->pbc_cfg.nbluns;
1292 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
1293 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
1294
1295 return;
1296 }
1297
1298 *nwwns = cfgrsp->bootwwns.nwwns;
1299 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
1300}
1301
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001302int
1303bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
1304{
1305 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1306 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1307
1308 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
1309 return cfgrsp->pbc_cfg.nvports;
1310}
1311
Jing Huang7725ccf2009-09-23 17:46:15 -07001312
Jing Huang5fbe25c2010-10-18 17:17:23 -07001313/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001314 * Use this function query the memory requirement of the BFA library.
1315 * This function needs to be called before bfa_attach() to get the
1316 * memory required of the BFA layer for a given driver configuration.
1317 *
1318 * This call will fail, if the cap is out of range compared to pre-defined
1319 * values within the BFA library
1320 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001321 * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
1322 * its configuration in this structure.
Jing Huang7725ccf2009-09-23 17:46:15 -07001323 * The default values for struct bfa_iocfc_cfg_s can be
1324 * fetched using bfa_cfg_get_default() API.
1325 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001326 * If cap's boundary check fails, the library will use
Jing Huang7725ccf2009-09-23 17:46:15 -07001327 * the default bfa_cap_t values (and log a warning msg).
1328 *
1329 * @param[out] meminfo - pointer to bfa_meminfo_t. This content
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001330 * indicates the memory type (see bfa_mem_type_t) and
Jing Huang7725ccf2009-09-23 17:46:15 -07001331 * amount of memory required.
1332 *
1333 * Driver should allocate the memory, populate the
1334 * starting address for each block and provide the same
1335 * structure as input parameter to bfa_attach() call.
1336 *
Krishna Gudipati45070252011-06-24 20:24:29 -07001337 * @param[in] bfa - pointer to the bfa structure, used while fetching the
1338 * dma, kva memory information of the bfa sub-modules.
1339 *
Jing Huang7725ccf2009-09-23 17:46:15 -07001340 * @return void
1341 *
1342 * Special Considerations: @note
1343 */
1344void
Krishna Gudipati45070252011-06-24 20:24:29 -07001345bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1346 struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001347{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001348 int i;
Krishna Gudipati45070252011-06-24 20:24:29 -07001349 struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
1350 struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001351
Jing Huangd4b671c2010-12-26 21:46:35 -08001352 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001353
Jing Huang6a18b162010-10-18 17:08:54 -07001354 memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001355
Krishna Gudipati45070252011-06-24 20:24:29 -07001356 /* Initialize the DMA & KVA meminfo queues */
1357 INIT_LIST_HEAD(&meminfo->dma_info.qe);
1358 INIT_LIST_HEAD(&meminfo->kva_info.qe);
1359
1360 bfa_iocfc_meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001361
1362 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001363 hal_mods[i]->meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001364
Krishna Gudipati45070252011-06-24 20:24:29 -07001365 /* dma info setup */
1366 bfa_mem_dma_setup(meminfo, port_dma, bfa_port_meminfo());
1367 bfa_mem_dma_setup(meminfo, ablk_dma, bfa_ablk_meminfo());
Jing Huang7725ccf2009-09-23 17:46:15 -07001368}
1369
Jing Huang5fbe25c2010-10-18 17:17:23 -07001370/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001371 * Use this function to do attach the driver instance with the BFA
1372 * library. This function will not trigger any HW initialization
1373 * process (which will be done in bfa_init() call)
1374 *
1375 * This call will fail, if the cap is out of range compared to
1376 * pre-defined values within the BFA library
1377 *
1378 * @param[out] bfa Pointer to bfa_t.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001379 * @param[in] bfad Opaque handle back to the driver's IOC structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001380 * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001381 * that was used in bfa_cfg_get_meminfo().
1382 * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
1383 * use the bfa_cfg_get_meminfo() call to
1384 * find the memory blocks required, allocate the
1385 * required memory and provide the starting addresses.
1386 * @param[in] pcidev pointer to struct bfa_pcidev_s
Jing Huang7725ccf2009-09-23 17:46:15 -07001387 *
1388 * @return
1389 * void
1390 *
1391 * Special Considerations:
1392 *
1393 * @note
1394 *
1395 */
1396void
1397bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1398 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1399{
Krishna Gudipati45070252011-06-24 20:24:29 -07001400 int i;
1401 struct bfa_mem_dma_s *dma_info, *dma_elem;
1402 struct bfa_mem_kva_s *kva_info, *kva_elem;
1403 struct list_head *dm_qe, *km_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001404
1405 bfa->fcs = BFA_FALSE;
1406
Jing Huangd4b671c2010-12-26 21:46:35 -08001407 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001408
Krishna Gudipati45070252011-06-24 20:24:29 -07001409 /* Initialize memory pointers for iterative allocation */
1410 dma_info = &meminfo->dma_info;
1411 dma_info->kva_curp = dma_info->kva;
1412 dma_info->dma_curp = dma_info->dma;
1413
1414 kva_info = &meminfo->kva_info;
1415 kva_info->kva_curp = kva_info->kva;
1416
1417 list_for_each(dm_qe, &dma_info->qe) {
1418 dma_elem = (struct bfa_mem_dma_s *) dm_qe;
1419 dma_elem->kva_curp = dma_elem->kva;
1420 dma_elem->dma_curp = dma_elem->dma;
Jing Huang7725ccf2009-09-23 17:46:15 -07001421 }
1422
Krishna Gudipati45070252011-06-24 20:24:29 -07001423 list_for_each(km_qe, &kva_info->qe) {
1424 kva_elem = (struct bfa_mem_kva_s *) km_qe;
1425 kva_elem->kva_curp = kva_elem->kva;
1426 }
1427
1428 bfa_iocfc_attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001429
1430 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001431 hal_mods[i]->attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001432
Krishna Gudipati45070252011-06-24 20:24:29 -07001433 bfa_com_port_attach(bfa);
1434 bfa_com_ablk_attach(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001435}
1436
Jing Huang5fbe25c2010-10-18 17:17:23 -07001437/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001438 * Use this function to delete a BFA IOC. IOC should be stopped (by
1439 * calling bfa_stop()) before this function call.
1440 *
1441 * @param[in] bfa - pointer to bfa_t.
1442 *
1443 * @return
1444 * void
1445 *
1446 * Special Considerations:
1447 *
1448 * @note
1449 */
1450void
1451bfa_detach(struct bfa_s *bfa)
1452{
1453 int i;
1454
1455 for (i = 0; hal_mods[i]; i++)
1456 hal_mods[i]->detach(bfa);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001457 bfa_ioc_detach(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001458}
1459
1460void
1461bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
1462{
1463 INIT_LIST_HEAD(comp_q);
1464 list_splice_tail_init(&bfa->comp_q, comp_q);
1465}
1466
1467void
1468bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
1469{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001470 struct list_head *qe;
1471 struct list_head *qen;
1472 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001473
1474 list_for_each_safe(qe, qen, comp_q) {
1475 hcb_qe = (struct bfa_cb_qe_s *) qe;
1476 hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
1477 }
1478}
1479
1480void
1481bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
1482{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001483 struct list_head *qe;
1484 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001485
1486 while (!list_empty(comp_q)) {
1487 bfa_q_deq(comp_q, &qe);
1488 hcb_qe = (struct bfa_cb_qe_s *) qe;
1489 hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
1490 }
1491}
1492
Jing Huang7725ccf2009-09-23 17:46:15 -07001493
Jing Huang5fbe25c2010-10-18 17:17:23 -07001494/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001495 * Return the list of PCI vendor/device id lists supported by this
1496 * BFA instance.
1497 */
1498void
1499bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
1500{
1501 static struct bfa_pciid_s __pciids[] = {
1502 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
1503 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
1504 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
Jing Huang293f82d2010-07-08 19:45:20 -07001505 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
Jing Huang7725ccf2009-09-23 17:46:15 -07001506 };
1507
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001508 *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001509 *pciids = __pciids;
1510}
1511
Jing Huang5fbe25c2010-10-18 17:17:23 -07001512/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001513 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
1514 * into BFA layer). The OS driver can then turn back and overwrite entries that
1515 * have been configured by the user.
1516 *
1517 * @param[in] cfg - pointer to bfa_ioc_cfg_t
1518 *
1519 * @return
1520 * void
1521 *
1522 * Special Considerations:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001523 * note
Jing Huang7725ccf2009-09-23 17:46:15 -07001524 */
1525void
1526bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
1527{
1528 cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
1529 cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
1530 cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
1531 cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
1532 cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
1533 cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
1534 cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
1535 cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001536 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001537
1538 cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
1539 cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
1540 cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
1541 cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
1542 cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
1543 cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
1544 cfg->drvcfg.ioc_recover = BFA_FALSE;
1545 cfg->drvcfg.delay_comp = BFA_FALSE;
1546
1547}
1548
1549void
1550bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
1551{
1552 bfa_cfg_get_default(cfg);
1553 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
1554 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
1555 cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
1556 cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
1557 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001558 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001559
1560 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
1561 cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
1562 cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001563 cfg->drvcfg.min_cfg = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001564}