blob: a4129c929f2480aa11183a595c40e26c7855f6b0 [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[] = {
Krishna Gudipati3d7fc662011-06-24 20:28:17 -070028 &hal_mod_fcdiag,
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080029 &hal_mod_sgpg,
30 &hal_mod_fcport,
31 &hal_mod_fcxp,
32 &hal_mod_lps,
33 &hal_mod_uf,
34 &hal_mod_rport,
Krishna Gudipatie2187d72011-06-13 15:53:58 -070035 &hal_mod_fcp,
Krishna Gudipati45c5dc12011-07-20 17:03:46 -070036 &hal_mod_dconf,
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080037 NULL
38};
39
40/*
41 * Message handlers for various modules.
42 */
43static bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
44 bfa_isr_unhandled, /* NONE */
45 bfa_isr_unhandled, /* BFI_MC_IOC */
Krishna Gudipati3d7fc662011-06-24 20:28:17 -070046 bfa_fcdiag_intr, /* BFI_MC_DIAG */
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080047 bfa_isr_unhandled, /* BFI_MC_FLASH */
48 bfa_isr_unhandled, /* BFI_MC_CEE */
49 bfa_fcport_isr, /* BFI_MC_FCPORT */
50 bfa_isr_unhandled, /* BFI_MC_IOCFC */
51 bfa_isr_unhandled, /* BFI_MC_LL */
52 bfa_uf_isr, /* BFI_MC_UF */
53 bfa_fcxp_isr, /* BFI_MC_FCXP */
54 bfa_lps_isr, /* BFI_MC_LPS */
55 bfa_rport_isr, /* BFI_MC_RPORT */
Krishna Gudipatie2187d72011-06-13 15:53:58 -070056 bfa_itn_isr, /* BFI_MC_ITN */
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080057 bfa_isr_unhandled, /* BFI_MC_IOIM_READ */
58 bfa_isr_unhandled, /* BFI_MC_IOIM_WRITE */
59 bfa_isr_unhandled, /* BFI_MC_IOIM_IO */
60 bfa_ioim_isr, /* BFI_MC_IOIM */
61 bfa_ioim_good_comp_isr, /* BFI_MC_IOIM_IOCOM */
62 bfa_tskim_isr, /* BFI_MC_TSKIM */
63 bfa_isr_unhandled, /* BFI_MC_SBOOT */
64 bfa_isr_unhandled, /* BFI_MC_IPFC */
65 bfa_isr_unhandled, /* BFI_MC_PORT */
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 bfa_isr_unhandled, /* --------- */
75 bfa_isr_unhandled, /* --------- */
76};
77/*
78 * Message handlers for mailbox command classes
79 */
80static bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = {
81 NULL,
82 NULL, /* BFI_MC_IOC */
83 NULL, /* BFI_MC_DIAG */
84 NULL, /* BFI_MC_FLASH */
85 NULL, /* BFI_MC_CEE */
86 NULL, /* BFI_MC_PORT */
87 bfa_iocfc_isr, /* BFI_MC_IOCFC */
88 NULL,
89};
90
91
92
93static void
Krishna Gudipati45070252011-06-24 20:24:29 -070094bfa_com_port_attach(struct bfa_s *bfa)
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080095{
96 struct bfa_port_s *port = &bfa->modules.port;
Krishna Gudipati45070252011-06-24 20:24:29 -070097 struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080098
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080099 bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod);
Krishna Gudipati45070252011-06-24 20:24:29 -0700100 bfa_port_mem_claim(port, port_dma->kva_curp, port_dma->dma_curp);
Maggie Zhangb77ee1f2010-12-09 19:09:26 -0800101}
102
103/*
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700104 * ablk module attach
105 */
106static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700107bfa_com_ablk_attach(struct bfa_s *bfa)
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700108{
109 struct bfa_ablk_s *ablk = &bfa->modules.ablk;
Krishna Gudipati45070252011-06-24 20:24:29 -0700110 struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700111
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700112 bfa_ablk_attach(ablk, &bfa->ioc);
Krishna Gudipati45070252011-06-24 20:24:29 -0700113 bfa_ablk_memclaim(ablk, ablk_dma->kva_curp, ablk_dma->dma_curp);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700114}
115
Krishna Gudipati148d6102011-06-24 20:25:36 -0700116static void
117bfa_com_cee_attach(struct bfa_s *bfa)
118{
119 struct bfa_cee_s *cee = &bfa->modules.cee;
120 struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
121
122 cee->trcmod = bfa->trcmod;
123 bfa_cee_attach(cee, &bfa->ioc, bfa);
124 bfa_cee_mem_claim(cee, cee_dma->kva_curp, cee_dma->dma_curp);
125}
126
Krishna Gudipati51e569a2011-06-24 20:26:25 -0700127static void
128bfa_com_sfp_attach(struct bfa_s *bfa)
129{
130 struct bfa_sfp_s *sfp = BFA_SFP_MOD(bfa);
131 struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
132
133 bfa_sfp_attach(sfp, &bfa->ioc, bfa, bfa->trcmod);
134 bfa_sfp_memclaim(sfp, sfp_dma->kva_curp, sfp_dma->dma_curp);
135}
136
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -0700137static void
138bfa_com_flash_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
139{
140 struct bfa_flash_s *flash = BFA_FLASH(bfa);
141 struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
142
143 bfa_flash_attach(flash, &bfa->ioc, bfa, bfa->trcmod, mincfg);
144 bfa_flash_memclaim(flash, flash_dma->kva_curp,
145 flash_dma->dma_curp, mincfg);
146}
147
Krishna Gudipati3d7fc662011-06-24 20:28:17 -0700148static void
149bfa_com_diag_attach(struct bfa_s *bfa)
150{
151 struct bfa_diag_s *diag = BFA_DIAG_MOD(bfa);
152 struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
153
154 bfa_diag_attach(diag, &bfa->ioc, bfa, bfa_fcport_beacon, bfa->trcmod);
155 bfa_diag_memclaim(diag, diag_dma->kva_curp, diag_dma->dma_curp);
156}
157
Krishna Gudipati3350d982011-06-24 20:28:37 -0700158static void
159bfa_com_phy_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
160{
161 struct bfa_phy_s *phy = BFA_PHY(bfa);
162 struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
163
164 bfa_phy_attach(phy, &bfa->ioc, bfa, bfa->trcmod, mincfg);
165 bfa_phy_memclaim(phy, phy_dma->kva_curp, phy_dma->dma_curp, mincfg);
166}
167
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700168/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700169 * BFA IOC FC related definitions
170 */
171
Jing Huang5fbe25c2010-10-18 17:17:23 -0700172/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700173 * IOC local definitions
174 */
175#define BFA_IOCFC_TOV 5000 /* msecs */
176
177enum {
178 BFA_IOCFC_ACT_NONE = 0,
179 BFA_IOCFC_ACT_INIT = 1,
180 BFA_IOCFC_ACT_STOP = 2,
181 BFA_IOCFC_ACT_DISABLE = 3,
Krishna Gudipati60138062011-06-24 20:25:15 -0700182 BFA_IOCFC_ACT_ENABLE = 4,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700183};
184
185#define DEF_CFG_NUM_FABRICS 1
186#define DEF_CFG_NUM_LPORTS 256
187#define DEF_CFG_NUM_CQS 4
188#define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
189#define DEF_CFG_NUM_TSKIM_REQS 128
190#define DEF_CFG_NUM_FCXP_REQS 64
191#define DEF_CFG_NUM_UF_BUFS 64
192#define DEF_CFG_NUM_RPORTS 1024
193#define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
194#define DEF_CFG_NUM_TINS 256
195
196#define DEF_CFG_NUM_SGPGS 2048
197#define DEF_CFG_NUM_REQQ_ELEMS 256
198#define DEF_CFG_NUM_RSPQ_ELEMS 64
199#define DEF_CFG_NUM_SBOOT_TGTS 16
200#define DEF_CFG_NUM_SBOOT_LUNS 16
201
Jing Huang5fbe25c2010-10-18 17:17:23 -0700202/*
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700203 * IOCFC state machine definitions/declarations
204 */
205bfa_fsm_state_decl(bfa_iocfc, stopped, struct bfa_iocfc_s, enum iocfc_event);
206bfa_fsm_state_decl(bfa_iocfc, initing, struct bfa_iocfc_s, enum iocfc_event);
207bfa_fsm_state_decl(bfa_iocfc, dconf_read, struct bfa_iocfc_s, enum iocfc_event);
208bfa_fsm_state_decl(bfa_iocfc, init_cfg_wait,
209 struct bfa_iocfc_s, enum iocfc_event);
210bfa_fsm_state_decl(bfa_iocfc, init_cfg_done,
211 struct bfa_iocfc_s, enum iocfc_event);
212bfa_fsm_state_decl(bfa_iocfc, operational,
213 struct bfa_iocfc_s, enum iocfc_event);
214bfa_fsm_state_decl(bfa_iocfc, dconf_write,
215 struct bfa_iocfc_s, enum iocfc_event);
216bfa_fsm_state_decl(bfa_iocfc, stopping, struct bfa_iocfc_s, enum iocfc_event);
217bfa_fsm_state_decl(bfa_iocfc, enabling, struct bfa_iocfc_s, enum iocfc_event);
218bfa_fsm_state_decl(bfa_iocfc, cfg_wait, struct bfa_iocfc_s, enum iocfc_event);
219bfa_fsm_state_decl(bfa_iocfc, disabling, struct bfa_iocfc_s, enum iocfc_event);
220bfa_fsm_state_decl(bfa_iocfc, disabled, struct bfa_iocfc_s, enum iocfc_event);
221bfa_fsm_state_decl(bfa_iocfc, failed, struct bfa_iocfc_s, enum iocfc_event);
222bfa_fsm_state_decl(bfa_iocfc, init_failed,
223 struct bfa_iocfc_s, enum iocfc_event);
224
225/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700226 * forward declaration for IOC FC functions
227 */
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700228static void bfa_iocfc_start_submod(struct bfa_s *bfa);
229static void bfa_iocfc_disable_submod(struct bfa_s *bfa);
230static void bfa_iocfc_send_cfg(void *bfa_arg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700231static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
232static void bfa_iocfc_disable_cbfn(void *bfa_arg);
233static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
234static void bfa_iocfc_reset_cbfn(void *bfa_arg);
235static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700236static void bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete);
237static void bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl);
238static void bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl);
239static void bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl);
240
241static void
242bfa_iocfc_sm_stopped_entry(struct bfa_iocfc_s *iocfc)
243{
244}
245
246static void
247bfa_iocfc_sm_stopped(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
248{
249 bfa_trc(iocfc->bfa, event);
250
251 switch (event) {
252 case IOCFC_E_INIT:
253 case IOCFC_E_ENABLE:
254 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_initing);
255 break;
256 default:
257 bfa_sm_fault(iocfc->bfa, event);
258 break;
259 }
260}
261
262static void
263bfa_iocfc_sm_initing_entry(struct bfa_iocfc_s *iocfc)
264{
265 bfa_ioc_enable(&iocfc->bfa->ioc);
266}
267
268static void
269bfa_iocfc_sm_initing(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
270{
271 bfa_trc(iocfc->bfa, event);
272
273 switch (event) {
274 case IOCFC_E_IOC_ENABLED:
275 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
276 break;
277 case IOCFC_E_IOC_FAILED:
278 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
279 break;
280 default:
281 bfa_sm_fault(iocfc->bfa, event);
282 break;
283 }
284}
285
286static void
287bfa_iocfc_sm_dconf_read_entry(struct bfa_iocfc_s *iocfc)
288{
289 bfa_dconf_modinit(iocfc->bfa);
290}
291
292static void
293bfa_iocfc_sm_dconf_read(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
294{
295 bfa_trc(iocfc->bfa, event);
296
297 switch (event) {
298 case IOCFC_E_DCONF_DONE:
299 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_wait);
300 break;
301 case IOCFC_E_IOC_FAILED:
302 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
303 break;
304 default:
305 bfa_sm_fault(iocfc->bfa, event);
306 break;
307 }
308}
309
310static void
311bfa_iocfc_sm_init_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
312{
313 bfa_iocfc_send_cfg(iocfc->bfa);
314}
315
316static void
317bfa_iocfc_sm_init_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
318{
319 bfa_trc(iocfc->bfa, event);
320
321 switch (event) {
322 case IOCFC_E_CFG_DONE:
323 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_done);
324 break;
325 case IOCFC_E_IOC_FAILED:
326 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
327 break;
328 default:
329 bfa_sm_fault(iocfc->bfa, event);
330 break;
331 }
332}
333
334static void
335bfa_iocfc_sm_init_cfg_done_entry(struct bfa_iocfc_s *iocfc)
336{
337 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
338 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
339 bfa_iocfc_init_cb, iocfc->bfa);
340}
341
342static void
343bfa_iocfc_sm_init_cfg_done(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
344{
345 bfa_trc(iocfc->bfa, event);
346
347 switch (event) {
348 case IOCFC_E_START:
349 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
350 break;
351 case IOCFC_E_STOP:
352 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
353 break;
354 case IOCFC_E_DISABLE:
355 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
356 break;
357 case IOCFC_E_IOC_FAILED:
358 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
359 break;
360 default:
361 bfa_sm_fault(iocfc->bfa, event);
362 break;
363 }
364}
365
366static void
367bfa_iocfc_sm_operational_entry(struct bfa_iocfc_s *iocfc)
368{
369 bfa_fcport_init(iocfc->bfa);
370 bfa_iocfc_start_submod(iocfc->bfa);
371}
372
373static void
374bfa_iocfc_sm_operational(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
375{
376 bfa_trc(iocfc->bfa, event);
377
378 switch (event) {
379 case IOCFC_E_STOP:
380 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
381 break;
382 case IOCFC_E_DISABLE:
383 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
384 break;
385 case IOCFC_E_IOC_FAILED:
386 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
387 break;
388 default:
389 bfa_sm_fault(iocfc->bfa, event);
390 break;
391 }
392}
393
394static void
395bfa_iocfc_sm_dconf_write_entry(struct bfa_iocfc_s *iocfc)
396{
397 bfa_dconf_modexit(iocfc->bfa);
398}
399
400static void
401bfa_iocfc_sm_dconf_write(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
402{
403 bfa_trc(iocfc->bfa, event);
404
405 switch (event) {
406 case IOCFC_E_DCONF_DONE:
407 case IOCFC_E_IOC_FAILED:
408 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
409 break;
410 default:
411 bfa_sm_fault(iocfc->bfa, event);
412 break;
413 }
414}
415
416static void
417bfa_iocfc_sm_stopping_entry(struct bfa_iocfc_s *iocfc)
418{
419 bfa_ioc_disable(&iocfc->bfa->ioc);
420}
421
422static void
423bfa_iocfc_sm_stopping(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
424{
425 bfa_trc(iocfc->bfa, event);
426
427 switch (event) {
428 case IOCFC_E_IOC_DISABLED:
429 bfa_isr_disable(iocfc->bfa);
430 bfa_iocfc_disable_submod(iocfc->bfa);
431 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
432 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
433 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.stop_hcb_qe,
434 bfa_iocfc_stop_cb, iocfc->bfa);
435 break;
436 default:
437 bfa_sm_fault(iocfc->bfa, event);
438 break;
439 }
440}
441
442static void
443bfa_iocfc_sm_enabling_entry(struct bfa_iocfc_s *iocfc)
444{
445 bfa_ioc_enable(&iocfc->bfa->ioc);
446}
447
448static void
449bfa_iocfc_sm_enabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
450{
451 bfa_trc(iocfc->bfa, event);
452
453 switch (event) {
454 case IOCFC_E_IOC_ENABLED:
455 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
456 break;
457 case IOCFC_E_IOC_FAILED:
458 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
459
460 if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
461 break;
462
463 iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
464 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
465 bfa_iocfc_enable_cb, iocfc->bfa);
466 iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
467 break;
468 default:
469 bfa_sm_fault(iocfc->bfa, event);
470 break;
471 }
472}
473
474static void
475bfa_iocfc_sm_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
476{
477 bfa_iocfc_send_cfg(iocfc->bfa);
478}
479
480static void
481bfa_iocfc_sm_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
482{
483 bfa_trc(iocfc->bfa, event);
484
485 switch (event) {
486 case IOCFC_E_CFG_DONE:
487 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
488 if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
489 break;
490
491 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
492 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
493 bfa_iocfc_enable_cb, iocfc->bfa);
494 iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
495 break;
496 case IOCFC_E_IOC_FAILED:
497 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
498 if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
499 break;
500
501 iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
502 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
503 bfa_iocfc_enable_cb, iocfc->bfa);
504 iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
505 break;
506 default:
507 bfa_sm_fault(iocfc->bfa, event);
508 break;
509 }
510}
511
512static void
513bfa_iocfc_sm_disabling_entry(struct bfa_iocfc_s *iocfc)
514{
515 bfa_ioc_disable(&iocfc->bfa->ioc);
516}
517
518static void
519bfa_iocfc_sm_disabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
520{
521 bfa_trc(iocfc->bfa, event);
522
523 switch (event) {
524 case IOCFC_E_IOC_DISABLED:
525 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabled);
526 break;
527 default:
528 bfa_sm_fault(iocfc->bfa, event);
529 break;
530 }
531}
532
533static void
534bfa_iocfc_sm_disabled_entry(struct bfa_iocfc_s *iocfc)
535{
536 bfa_isr_disable(iocfc->bfa);
537 bfa_iocfc_disable_submod(iocfc->bfa);
538 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
539 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
540 bfa_iocfc_disable_cb, iocfc->bfa);
541}
542
543static void
544bfa_iocfc_sm_disabled(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
545{
546 bfa_trc(iocfc->bfa, event);
547
548 switch (event) {
549 case IOCFC_E_STOP:
550 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
551 break;
552 case IOCFC_E_ENABLE:
553 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_enabling);
554 break;
555 default:
556 bfa_sm_fault(iocfc->bfa, event);
557 break;
558 }
559}
560
561static void
562bfa_iocfc_sm_failed_entry(struct bfa_iocfc_s *iocfc)
563{
564 bfa_isr_disable(iocfc->bfa);
565 bfa_iocfc_disable_submod(iocfc->bfa);
566}
567
568static void
569bfa_iocfc_sm_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
570{
571 bfa_trc(iocfc->bfa, event);
572
573 switch (event) {
574 case IOCFC_E_STOP:
575 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
576 break;
577 case IOCFC_E_DISABLE:
578 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
579 break;
580 case IOCFC_E_IOC_ENABLED:
581 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
582 break;
583 case IOCFC_E_IOC_FAILED:
584 break;
585 default:
586 bfa_sm_fault(iocfc->bfa, event);
587 break;
588 }
589}
590
591static void
592bfa_iocfc_sm_init_failed_entry(struct bfa_iocfc_s *iocfc)
593{
594 bfa_isr_disable(iocfc->bfa);
595 iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
596 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
597 bfa_iocfc_init_cb, iocfc->bfa);
598}
599
600static void
601bfa_iocfc_sm_init_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
602{
603 bfa_trc(iocfc->bfa, event);
604
605 switch (event) {
606 case IOCFC_E_STOP:
607 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
608 break;
609 case IOCFC_E_DISABLE:
610 bfa_ioc_disable(&iocfc->bfa->ioc);
611 break;
612 case IOCFC_E_IOC_ENABLED:
613 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
614 break;
615 case IOCFC_E_IOC_DISABLED:
616 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
617 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
618 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
619 bfa_iocfc_disable_cb, iocfc->bfa);
620 break;
621 case IOCFC_E_IOC_FAILED:
622 break;
623 default:
624 bfa_sm_fault(iocfc->bfa, event);
625 break;
626 }
627}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700628
Jing Huang5fbe25c2010-10-18 17:17:23 -0700629/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700630 * BFA Interrupt handling functions
631 */
632static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700633bfa_reqq_resume(struct bfa_s *bfa, int qid)
634{
635 struct list_head *waitq, *qe, *qen;
636 struct bfa_reqq_wait_s *wqe;
637
638 waitq = bfa_reqq(bfa, qid);
639 list_for_each_safe(qe, qen, waitq) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700640 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700641 * Callback only as long as there is room in request queue
642 */
643 if (bfa_reqq_full(bfa, qid))
644 break;
645
646 list_del(qe);
647 wqe = (struct bfa_reqq_wait_s *) qe;
648 wqe->qresume(wqe->cbarg);
649 }
650}
651
Krishna Gudipati1f670962012-03-13 17:38:15 -0700652bfa_boolean_t
Krishna Gudipati11189202011-06-13 15:50:35 -0700653bfa_isr_rspq(struct bfa_s *bfa, int qid)
654{
655 struct bfi_msg_s *m;
656 u32 pi, ci;
657 struct list_head *waitq;
Krishna Gudipati1f670962012-03-13 17:38:15 -0700658 bfa_boolean_t ret;
Krishna Gudipati11189202011-06-13 15:50:35 -0700659
Krishna Gudipati11189202011-06-13 15:50:35 -0700660 ci = bfa_rspq_ci(bfa, qid);
661 pi = bfa_rspq_pi(bfa, qid);
662
Krishna Gudipati1f670962012-03-13 17:38:15 -0700663 ret = (ci != pi);
664
Krishna Gudipati11189202011-06-13 15:50:35 -0700665 while (ci != pi) {
666 m = bfa_rspq_elem(bfa, qid, ci);
667 WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
668
669 bfa_isrs[m->mhdr.msg_class] (bfa, m);
670 CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
671 }
672
673 /*
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700674 * acknowledge RME completions and update CI
Krishna Gudipati11189202011-06-13 15:50:35 -0700675 */
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700676 bfa_isr_rspq_ack(bfa, qid, ci);
Krishna Gudipati11189202011-06-13 15:50:35 -0700677
678 /*
679 * Resume any pending requests in the corresponding reqq.
680 */
681 waitq = bfa_reqq(bfa, qid);
682 if (!list_empty(waitq))
683 bfa_reqq_resume(bfa, qid);
Krishna Gudipati1f670962012-03-13 17:38:15 -0700684
685 return ret;
Krishna Gudipati11189202011-06-13 15:50:35 -0700686}
687
688static inline void
689bfa_isr_reqq(struct bfa_s *bfa, int qid)
690{
691 struct list_head *waitq;
692
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700693 bfa_isr_reqq_ack(bfa, qid);
Krishna Gudipati11189202011-06-13 15:50:35 -0700694
695 /*
696 * Resume any pending requests in the corresponding reqq.
697 */
698 waitq = bfa_reqq(bfa, qid);
699 if (!list_empty(waitq))
700 bfa_reqq_resume(bfa, qid);
701}
702
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700703void
704bfa_msix_all(struct bfa_s *bfa, int vec)
705{
Krishna Gudipati10a07372011-06-24 20:23:38 -0700706 u32 intr, qintr;
707 int queue;
708
709 intr = readl(bfa->iocfc.bfa_regs.intr_status);
710 if (!intr)
711 return;
712
713 /*
714 * RME completion queue interrupt
715 */
716 qintr = intr & __HFN_INT_RME_MASK;
717 if (qintr && bfa->queue_process) {
718 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
719 bfa_isr_rspq(bfa, queue);
720 }
721
722 intr &= ~qintr;
723 if (!intr)
724 return;
725
726 /*
727 * CPE completion queue interrupt
728 */
729 qintr = intr & __HFN_INT_CPE_MASK;
730 if (qintr && bfa->queue_process) {
731 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
732 bfa_isr_reqq(bfa, queue);
733 }
734 intr &= ~qintr;
735 if (!intr)
736 return;
737
738 bfa_msix_lpu_err(bfa, intr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700739}
740
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700741bfa_boolean_t
742bfa_intx(struct bfa_s *bfa)
743{
744 u32 intr, qintr;
745 int queue;
Krishna Gudipati1f670962012-03-13 17:38:15 -0700746 bfa_boolean_t rspq_comp = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700747
Jing Huang53440262010-10-18 17:12:29 -0700748 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700749
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700750 qintr = intr & (__HFN_INT_RME_MASK | __HFN_INT_CPE_MASK);
751 if (qintr)
752 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
753
Jing Huang5fbe25c2010-10-18 17:17:23 -0700754 /*
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700755 * Unconditional RME completion queue interrupt
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700756 */
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700757 if (bfa->queue_process) {
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700758 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
Krishna Gudipati1f670962012-03-13 17:38:15 -0700759 if (bfa_isr_rspq(bfa, queue))
760 rspq_comp = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700761 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700762
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700763 if (!intr)
Krishna Gudipati1f670962012-03-13 17:38:15 -0700764 return (qintr | rspq_comp) ? BFA_TRUE : BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700765
Jing Huang5fbe25c2010-10-18 17:17:23 -0700766 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700767 * CPE completion queue interrupt
768 */
769 qintr = intr & __HFN_INT_CPE_MASK;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700770 if (qintr && bfa->queue_process) {
771 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
772 bfa_isr_reqq(bfa, queue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700773 }
774 intr &= ~qintr;
775 if (!intr)
776 return BFA_TRUE;
777
778 bfa_msix_lpu_err(bfa, intr);
779
780 return BFA_TRUE;
781}
782
783void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700784bfa_isr_enable(struct bfa_s *bfa)
785{
Krishna Gudipati11189202011-06-13 15:50:35 -0700786 u32 umsk;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700787 int pci_func = bfa_ioc_pcifn(&bfa->ioc);
788
789 bfa_trc(bfa, pci_func);
790
Krishna Gudipati775c7742011-06-13 15:52:12 -0700791 bfa_msix_ctrl_install(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700792
Krishna Gudipati11189202011-06-13 15:50:35 -0700793 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
794 umsk = __HFN_INT_ERR_MASK_CT2;
795 umsk |= pci_func == 0 ?
796 __HFN_INT_FN0_MASK_CT2 : __HFN_INT_FN1_MASK_CT2;
797 } else {
798 umsk = __HFN_INT_ERR_MASK;
799 umsk |= pci_func == 0 ? __HFN_INT_FN0_MASK : __HFN_INT_FN1_MASK;
800 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700801
Krishna Gudipati11189202011-06-13 15:50:35 -0700802 writel(umsk, bfa->iocfc.bfa_regs.intr_status);
803 writel(~umsk, bfa->iocfc.bfa_regs.intr_mask);
804 bfa->iocfc.intr_mask = ~umsk;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700805 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
806}
807
808void
809bfa_isr_disable(struct bfa_s *bfa)
810{
811 bfa_isr_mode_set(bfa, BFA_FALSE);
Jing Huang53440262010-10-18 17:12:29 -0700812 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700813 bfa_msix_uninstall(bfa);
814}
815
816void
Krishna Gudipati11189202011-06-13 15:50:35 -0700817bfa_msix_reqq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700818{
Krishna Gudipati11189202011-06-13 15:50:35 -0700819 bfa_isr_reqq(bfa, vec - bfa->iocfc.hwif.cpe_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700820}
821
822void
823bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
824{
825 bfa_trc(bfa, m->mhdr.msg_class);
826 bfa_trc(bfa, m->mhdr.msg_id);
827 bfa_trc(bfa, m->mhdr.mtag.i2htok);
Jing Huangd4b671c2010-12-26 21:46:35 -0800828 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700829 bfa_trc_stop(bfa->trcmod);
830}
831
832void
Krishna Gudipati11189202011-06-13 15:50:35 -0700833bfa_msix_rspq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700834{
Krishna Gudipati11189202011-06-13 15:50:35 -0700835 bfa_isr_rspq(bfa, vec - bfa->iocfc.hwif.rme_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700836}
837
838void
839bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
840{
841 u32 intr, curr_value;
Krishna Gudipati11189202011-06-13 15:50:35 -0700842 bfa_boolean_t lpu_isr, halt_isr, pss_isr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843
Jing Huang53440262010-10-18 17:12:29 -0700844 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700845
Krishna Gudipati11189202011-06-13 15:50:35 -0700846 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
847 halt_isr = intr & __HFN_INT_CPQ_HALT_CT2;
848 pss_isr = intr & __HFN_INT_ERR_PSS_CT2;
849 lpu_isr = intr & (__HFN_INT_MBOX_LPU0_CT2 |
850 __HFN_INT_MBOX_LPU1_CT2);
851 intr &= __HFN_INT_ERR_MASK_CT2;
852 } else {
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700853 halt_isr = bfa_asic_id_ct(bfa->ioc.pcidev.device_id) ?
854 (intr & __HFN_INT_LL_HALT) : 0;
Krishna Gudipati11189202011-06-13 15:50:35 -0700855 pss_isr = intr & __HFN_INT_ERR_PSS;
856 lpu_isr = intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1);
857 intr &= __HFN_INT_ERR_MASK;
858 }
859
860 if (lpu_isr)
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800861 bfa_ioc_mbox_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700862
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700863 if (intr) {
Krishna Gudipati11189202011-06-13 15:50:35 -0700864 if (halt_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700865 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700866 * If LL_HALT bit is set then FW Init Halt LL Port
867 * Register needs to be cleared as well so Interrupt
868 * Status Register will be cleared.
869 */
Jing Huang53440262010-10-18 17:12:29 -0700870 curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700871 curr_value &= ~__FW_INIT_HALT_P;
Jing Huang53440262010-10-18 17:12:29 -0700872 writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700873 }
874
Krishna Gudipati11189202011-06-13 15:50:35 -0700875 if (pss_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700876 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700877 * ERR_PSS bit needs to be cleared as well in case
878 * interrups are shared so driver's interrupt handler is
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300879 * still called even though it is already masked out.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700880 */
Jing Huang53440262010-10-18 17:12:29 -0700881 curr_value = readl(
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700882 bfa->ioc.ioc_regs.pss_err_status_reg);
Jing Huang53440262010-10-18 17:12:29 -0700883 writel(curr_value,
884 bfa->ioc.ioc_regs.pss_err_status_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700885 }
886
Jing Huang53440262010-10-18 17:12:29 -0700887 writel(intr, bfa->iocfc.bfa_regs.intr_status);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800888 bfa_ioc_error_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700889 }
890}
891
Jing Huang5fbe25c2010-10-18 17:17:23 -0700892/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700893 * BFA IOC FC related functions
894 */
895
Jing Huang5fbe25c2010-10-18 17:17:23 -0700896/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -0800897 * BFA IOC private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700898 */
899
Jing Huang5fbe25c2010-10-18 17:17:23 -0700900/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700901 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
902 */
903static void
904bfa_iocfc_send_cfg(void *bfa_arg)
905{
906 struct bfa_s *bfa = bfa_arg;
907 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
908 struct bfi_iocfc_cfg_req_s cfg_req;
909 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
910 struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
911 int i;
912
Jing Huangd4b671c2010-12-26 21:46:35 -0800913 WARN_ON(cfg->fwcfg.num_cqs > BFI_IOC_MAX_CQS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700914 bfa_trc(bfa, cfg->fwcfg.num_cqs);
915
916 bfa_iocfc_reset_queues(bfa);
917
Jing Huang5fbe25c2010-10-18 17:17:23 -0700918 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700919 * initialize IOC configuration info
920 */
Krishna Gudipati10a07372011-06-24 20:23:38 -0700921 cfg_info->single_msix_vec = 0;
922 if (bfa->msix.nvecs == 1)
923 cfg_info->single_msix_vec = 1;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700924 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
925 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
Krishna Gudipatie2187d72011-06-13 15:53:58 -0700926 cfg_info->num_ioim_reqs = cpu_to_be16(cfg->fwcfg.num_ioim_reqs);
927 cfg_info->num_fwtio_reqs = cpu_to_be16(cfg->fwcfg.num_fwtio_reqs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700928
929 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
Jing Huang5fbe25c2010-10-18 17:17:23 -0700930 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700931 * dma map REQ and RSP circular queues and shadow pointers
932 */
933 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
934 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
935 iocfc->req_cq_ba[i].pa);
936 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
937 iocfc->req_cq_shadow_ci[i].pa);
938 cfg_info->req_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700939 cpu_to_be16(cfg->drvcfg.num_reqq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700940
941 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
942 iocfc->rsp_cq_ba[i].pa);
943 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
944 iocfc->rsp_cq_shadow_pi[i].pa);
945 cfg_info->rsp_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -0700946 cpu_to_be16(cfg->drvcfg.num_rspq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700947 }
948
Jing Huang5fbe25c2010-10-18 17:17:23 -0700949 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700950 * Enable interrupt coalescing if it is driver init path
951 * and not ioc disable/enable path.
952 */
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700953 if (bfa_fsm_cmp_state(iocfc, bfa_iocfc_sm_init_cfg_wait))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700954 cfg_info->intr_attr.coalesce = BFA_TRUE;
955
Jing Huang5fbe25c2010-10-18 17:17:23 -0700956 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700957 * dma map IOC configuration itself
958 */
959 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700960 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700961 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
962
963 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
964 sizeof(struct bfi_iocfc_cfg_req_s));
965}
966
967static void
968bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
969 struct bfa_pcidev_s *pcidev)
970{
971 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
972
973 bfa->bfad = bfad;
974 iocfc->bfa = bfa;
Jing Huang6a18b162010-10-18 17:08:54 -0700975 iocfc->cfg = *cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976
Jing Huang5fbe25c2010-10-18 17:17:23 -0700977 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700978 * Initialize chip specific handlers.
979 */
Krishna Gudipati11189202011-06-13 15:50:35 -0700980 if (bfa_asic_id_ctc(bfa_ioc_devid(&bfa->ioc))) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700981 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
982 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
983 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
984 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -0700985 iocfc->hwif.hw_msix_ctrl_install = bfa_hwct_msix_ctrl_install;
986 iocfc->hwif.hw_msix_queue_install = bfa_hwct_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700987 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
988 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
989 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
990 iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -0700991 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CT;
992 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CT;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700993 } else {
994 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700995 iocfc->hwif.hw_reqq_ack = NULL;
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700996 iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700997 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -0700998 iocfc->hwif.hw_msix_ctrl_install = bfa_hwcb_msix_ctrl_install;
999 iocfc->hwif.hw_msix_queue_install = bfa_hwcb_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001000 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
1001 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
1002 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
1003 iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -07001004 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CB +
1005 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
1006 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CB +
1007 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
1008 }
1009
1010 if (bfa_asic_id_ct2(bfa_ioc_devid(&bfa->ioc))) {
1011 iocfc->hwif.hw_reginit = bfa_hwct2_reginit;
1012 iocfc->hwif.hw_isr_mode_set = NULL;
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -07001013 iocfc->hwif.hw_rspq_ack = bfa_hwct2_rspq_ack;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001014 }
1015
1016 iocfc->hwif.hw_reginit(bfa);
1017 bfa->msix.nvecs = 0;
1018}
1019
1020static void
Krishna Gudipati45070252011-06-24 20:24:29 -07001021bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001022{
Krishna Gudipati45070252011-06-24 20:24:29 -07001023 u8 *dm_kva = NULL;
1024 u64 dm_pa = 0;
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001025 int i, per_reqq_sz, per_rspq_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001026 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
Krishna Gudipati45070252011-06-24 20:24:29 -07001027 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
1028 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
1029 struct bfa_mem_dma_s *reqq_dma, *rspq_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001030
Krishna Gudipati45070252011-06-24 20:24:29 -07001031 /* First allocate dma memory for IOC */
1032 bfa_ioc_mem_claim(&bfa->ioc, bfa_mem_dma_virt(ioc_dma),
1033 bfa_mem_dma_phys(ioc_dma));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001034
Krishna Gudipati45070252011-06-24 20:24:29 -07001035 /* Claim DMA-able memory for the request/response queues */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001036 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -07001037 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001038 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -07001039 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001040
1041 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
Krishna Gudipati45070252011-06-24 20:24:29 -07001042 reqq_dma = BFA_MEM_REQQ_DMA(bfa, i);
1043 iocfc->req_cq_ba[i].kva = bfa_mem_dma_virt(reqq_dma);
1044 iocfc->req_cq_ba[i].pa = bfa_mem_dma_phys(reqq_dma);
1045 memset(iocfc->req_cq_ba[i].kva, 0, per_reqq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001046
Krishna Gudipati45070252011-06-24 20:24:29 -07001047 rspq_dma = BFA_MEM_RSPQ_DMA(bfa, i);
1048 iocfc->rsp_cq_ba[i].kva = bfa_mem_dma_virt(rspq_dma);
1049 iocfc->rsp_cq_ba[i].pa = bfa_mem_dma_phys(rspq_dma);
1050 memset(iocfc->rsp_cq_ba[i].kva, 0, per_rspq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001051 }
1052
Krishna Gudipati45070252011-06-24 20:24:29 -07001053 /* Claim IOCFC dma memory - for shadow CI/PI */
1054 dm_kva = bfa_mem_dma_virt(iocfc_dma);
1055 dm_pa = bfa_mem_dma_phys(iocfc_dma);
1056
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001057 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
1058 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
1059 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
1060 dm_kva += BFA_CACHELINE_SZ;
1061 dm_pa += BFA_CACHELINE_SZ;
1062
1063 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
1064 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
1065 dm_kva += BFA_CACHELINE_SZ;
1066 dm_pa += BFA_CACHELINE_SZ;
1067 }
1068
Krishna Gudipati45070252011-06-24 20:24:29 -07001069 /* Claim IOCFC dma memory - for the config info page */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001070 bfa->iocfc.cfg_info.kva = dm_kva;
1071 bfa->iocfc.cfg_info.pa = dm_pa;
1072 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
1073 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1074 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1075
Krishna Gudipati45070252011-06-24 20:24:29 -07001076 /* Claim IOCFC dma memory - for the config response */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001077 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
1078 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
1079 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
Krishna Gudipati45070252011-06-24 20:24:29 -07001080 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
1081 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001082 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
Krishna Gudipati45070252011-06-24 20:24:29 -07001083 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001084
Krishna Gudipati45070252011-06-24 20:24:29 -07001085 /* Claim IOCFC kva memory */
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001086 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_mem_kva_curp(iocfc));
1087 bfa_mem_kva_curp(iocfc) += BFA_DBG_FWTRC_LEN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001088}
1089
Jing Huang5fbe25c2010-10-18 17:17:23 -07001090/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001091 * Start BFA submodules.
1092 */
1093static void
1094bfa_iocfc_start_submod(struct bfa_s *bfa)
1095{
1096 int i;
1097
Krishna Gudipati775c7742011-06-13 15:52:12 -07001098 bfa->queue_process = BFA_TRUE;
Krishna Gudipati11189202011-06-13 15:50:35 -07001099 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -07001100 bfa_isr_rspq_ack(bfa, i, bfa_rspq_ci(bfa, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001101
1102 for (i = 0; hal_mods[i]; i++)
1103 hal_mods[i]->start(bfa);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001104
1105 bfa->iocfc.submod_enabled = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001106}
1107
Jing Huang5fbe25c2010-10-18 17:17:23 -07001108/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001109 * Disable BFA submodules.
1110 */
1111static void
1112bfa_iocfc_disable_submod(struct bfa_s *bfa)
1113{
1114 int i;
1115
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001116 if (bfa->iocfc.submod_enabled == BFA_FALSE)
1117 return;
1118
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001119 for (i = 0; hal_mods[i]; i++)
1120 hal_mods[i]->iocdisable(bfa);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001121
1122 bfa->iocfc.submod_enabled = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001123}
1124
1125static void
1126bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
1127{
1128 struct bfa_s *bfa = bfa_arg;
1129
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001130 if (complete)
1131 bfa_cb_init(bfa->bfad, bfa->iocfc.op_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001132}
1133
1134static void
1135bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
1136{
1137 struct bfa_s *bfa = bfa_arg;
1138 struct bfad_s *bfad = bfa->bfad;
1139
1140 if (compl)
1141 complete(&bfad->comp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001142}
1143
1144static void
Krishna Gudipati60138062011-06-24 20:25:15 -07001145bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl)
1146{
1147 struct bfa_s *bfa = bfa_arg;
1148 struct bfad_s *bfad = bfa->bfad;
1149
1150 if (compl)
1151 complete(&bfad->enable_comp);
1152}
1153
1154static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001155bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
1156{
1157 struct bfa_s *bfa = bfa_arg;
1158 struct bfad_s *bfad = bfa->bfad;
1159
1160 if (compl)
1161 complete(&bfad->disable_comp);
1162}
1163
Krishna Gudipati11189202011-06-13 15:50:35 -07001164/**
1165 * configure queue registers from firmware response
1166 */
1167static void
1168bfa_iocfc_qreg(struct bfa_s *bfa, struct bfi_iocfc_qreg_s *qreg)
1169{
1170 int i;
1171 struct bfa_iocfc_regs_s *r = &bfa->iocfc.bfa_regs;
1172 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
1173
1174 for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001175 bfa->iocfc.hw_qid[i] = qreg->hw_qid[i];
Krishna Gudipati11189202011-06-13 15:50:35 -07001176 r->cpe_q_ci[i] = kva + be32_to_cpu(qreg->cpe_q_ci_off[i]);
1177 r->cpe_q_pi[i] = kva + be32_to_cpu(qreg->cpe_q_pi_off[i]);
1178 r->cpe_q_ctrl[i] = kva + be32_to_cpu(qreg->cpe_qctl_off[i]);
1179 r->rme_q_ci[i] = kva + be32_to_cpu(qreg->rme_q_ci_off[i]);
1180 r->rme_q_pi[i] = kva + be32_to_cpu(qreg->rme_q_pi_off[i]);
1181 r->rme_q_ctrl[i] = kva + be32_to_cpu(qreg->rme_qctl_off[i]);
1182 }
1183}
1184
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001185static void
1186bfa_iocfc_res_recfg(struct bfa_s *bfa, struct bfa_iocfc_fwcfg_s *fwcfg)
1187{
1188 bfa_fcxp_res_recfg(bfa, fwcfg->num_fcxp_reqs);
1189 bfa_uf_res_recfg(bfa, fwcfg->num_uf_bufs);
1190 bfa_rport_res_recfg(bfa, fwcfg->num_rports);
1191 bfa_fcp_res_recfg(bfa, fwcfg->num_ioim_reqs);
1192 bfa_tskim_res_recfg(bfa, fwcfg->num_tskim_reqs);
1193}
1194
Jing Huang5fbe25c2010-10-18 17:17:23 -07001195/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001196 * Update BFA configuration from firmware configuration.
1197 */
1198static void
1199bfa_iocfc_cfgrsp(struct bfa_s *bfa)
1200{
1201 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1202 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1203 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
1204
1205 fwcfg->num_cqs = fwcfg->num_cqs;
Jing Huangba816ea2010-10-18 17:10:50 -07001206 fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001207 fwcfg->num_fwtio_reqs = be16_to_cpu(fwcfg->num_fwtio_reqs);
Jing Huangba816ea2010-10-18 17:10:50 -07001208 fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
1209 fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
1210 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
1211 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001212
Jing Huang5fbe25c2010-10-18 17:17:23 -07001213 /*
Krishna Gudipati11189202011-06-13 15:50:35 -07001214 * configure queue register offsets as learnt from firmware
1215 */
1216 bfa_iocfc_qreg(bfa, &cfgrsp->qreg);
1217
1218 /*
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001219 * Re-configure resources as learnt from Firmware
1220 */
1221 bfa_iocfc_res_recfg(bfa, fwcfg);
1222
1223 /*
Krishna Gudipati775c7742011-06-13 15:52:12 -07001224 * Install MSIX queue handlers
1225 */
1226 bfa_msix_queue_install(bfa);
1227
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001228 if (bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn != 0) {
1229 bfa->ioc.attr->pwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn;
1230 bfa->ioc.attr->nwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_nwwn;
1231 bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
Krishna Gudipati60138062011-06-24 20:25:15 -07001232 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001233}
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001234
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001235void
1236bfa_iocfc_reset_queues(struct bfa_s *bfa)
1237{
1238 int q;
1239
1240 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
1241 bfa_reqq_ci(bfa, q) = 0;
1242 bfa_reqq_pi(bfa, q) = 0;
1243 bfa_rspq_ci(bfa, q) = 0;
1244 bfa_rspq_pi(bfa, q) = 0;
1245 }
1246}
1247
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001248/*
1249 * Process FAA pwwn msg from fw.
1250 */
1251static void
1252bfa_iocfc_process_faa_addr(struct bfa_s *bfa, struct bfi_faa_addr_msg_s *msg)
1253{
1254 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1255 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1256
1257 cfgrsp->pbc_cfg.pbc_pwwn = msg->pwwn;
1258 cfgrsp->pbc_cfg.pbc_nwwn = msg->nwwn;
1259
1260 bfa->ioc.attr->pwwn = msg->pwwn;
1261 bfa->ioc.attr->nwwn = msg->nwwn;
1262 bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
1263}
1264
Krishna Gudipatia7141342011-06-24 20:23:19 -07001265/* Fabric Assigned Address specific functions */
1266
1267/*
1268 * Check whether IOC is ready before sending command down
1269 */
1270static bfa_status_t
1271bfa_faa_validate_request(struct bfa_s *bfa)
1272{
1273 enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
1274 u32 card_type = bfa->ioc.attr->card_type;
1275
1276 if (bfa_ioc_is_operational(&bfa->ioc)) {
1277 if ((ioc_type != BFA_IOC_TYPE_FC) || bfa_mfg_is_mezz(card_type))
1278 return BFA_STATUS_FEATURE_NOT_SUPPORTED;
1279 } else {
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001280 return BFA_STATUS_IOC_NON_OP;
Krishna Gudipatia7141342011-06-24 20:23:19 -07001281 }
1282
1283 return BFA_STATUS_OK;
1284}
1285
1286bfa_status_t
Krishna Gudipatia7141342011-06-24 20:23:19 -07001287bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
1288 bfa_cb_iocfc_t cbfn, void *cbarg)
1289{
1290 struct bfi_faa_query_s faa_attr_req;
1291 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1292 bfa_status_t status;
1293
1294 iocfc->faa_args.faa_attr = attr;
1295 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
1296 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
1297
1298 status = bfa_faa_validate_request(bfa);
1299 if (status != BFA_STATUS_OK)
1300 return status;
1301
1302 if (iocfc->faa_args.busy == BFA_TRUE)
1303 return BFA_STATUS_DEVBUSY;
1304
1305 iocfc->faa_args.busy = BFA_TRUE;
1306 memset(&faa_attr_req, 0, sizeof(struct bfi_faa_query_s));
1307 bfi_h2i_set(faa_attr_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001308 BFI_IOCFC_H2I_FAA_QUERY_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -07001309
1310 bfa_ioc_mbox_send(&bfa->ioc, &faa_attr_req,
1311 sizeof(struct bfi_faa_query_s));
1312
1313 return BFA_STATUS_OK;
1314}
1315
1316/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07001317 * FAA query response
1318 */
1319static void
1320bfa_faa_query_reply(struct bfa_iocfc_s *iocfc,
1321 bfi_faa_query_rsp_t *rsp)
1322{
1323 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
1324
1325 if (iocfc->faa_args.faa_attr) {
1326 iocfc->faa_args.faa_attr->faa = rsp->faa;
1327 iocfc->faa_args.faa_attr->faa_state = rsp->faa_status;
1328 iocfc->faa_args.faa_attr->pwwn_source = rsp->addr_source;
1329 }
1330
1331 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
1332
1333 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, BFA_STATUS_OK);
1334 iocfc->faa_args.busy = BFA_FALSE;
1335}
1336
Jing Huang5fbe25c2010-10-18 17:17:23 -07001337/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001338 * IOC enable request is complete
1339 */
1340static void
1341bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
1342{
1343 struct bfa_s *bfa = bfa_arg;
1344
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001345 if (status == BFA_STATUS_OK)
1346 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_ENABLED);
1347 else
1348 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001349}
1350
Jing Huang5fbe25c2010-10-18 17:17:23 -07001351/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001352 * IOC disable request is complete
1353 */
1354static void
1355bfa_iocfc_disable_cbfn(void *bfa_arg)
1356{
1357 struct bfa_s *bfa = bfa_arg;
1358
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001359 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001360}
1361
Jing Huang5fbe25c2010-10-18 17:17:23 -07001362/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001363 * Notify sub-modules of hardware failure.
1364 */
1365static void
1366bfa_iocfc_hbfail_cbfn(void *bfa_arg)
1367{
1368 struct bfa_s *bfa = bfa_arg;
1369
Krishna Gudipati775c7742011-06-13 15:52:12 -07001370 bfa->queue_process = BFA_FALSE;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001371 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001372}
1373
Jing Huang5fbe25c2010-10-18 17:17:23 -07001374/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001375 * Actions on chip-reset completion.
1376 */
1377static void
1378bfa_iocfc_reset_cbfn(void *bfa_arg)
1379{
1380 struct bfa_s *bfa = bfa_arg;
1381
1382 bfa_iocfc_reset_queues(bfa);
1383 bfa_isr_enable(bfa);
1384}
1385
Jing Huang5fbe25c2010-10-18 17:17:23 -07001386/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001387 * Query IOC memory requirement information.
1388 */
1389void
Krishna Gudipati45070252011-06-24 20:24:29 -07001390bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1391 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001392{
Krishna Gudipati45070252011-06-24 20:24:29 -07001393 int q, per_reqq_sz, per_rspq_sz;
1394 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
1395 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
1396 struct bfa_mem_kva_s *iocfc_kva = BFA_MEM_IOCFC_KVA(bfa);
1397 u32 dm_len = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001398
Krishna Gudipati45070252011-06-24 20:24:29 -07001399 /* dma memory setup for IOC */
1400 bfa_mem_dma_setup(meminfo, ioc_dma,
1401 BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ));
1402
1403 /* dma memory setup for REQ/RSP queues */
1404 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
1405 BFA_DMA_ALIGN_SZ);
1406 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
1407 BFA_DMA_ALIGN_SZ);
1408
1409 for (q = 0; q < cfg->fwcfg.num_cqs; q++) {
1410 bfa_mem_dma_setup(meminfo, BFA_MEM_REQQ_DMA(bfa, q),
1411 per_reqq_sz);
1412 bfa_mem_dma_setup(meminfo, BFA_MEM_RSPQ_DMA(bfa, q),
1413 per_rspq_sz);
1414 }
1415
1416 /* IOCFC dma memory - calculate Shadow CI/PI size */
1417 for (q = 0; q < cfg->fwcfg.num_cqs; q++)
1418 dm_len += (2 * BFA_CACHELINE_SZ);
1419
1420 /* IOCFC dma memory - calculate config info / rsp size */
1421 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1422 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
1423 BFA_CACHELINE_SZ);
1424
1425 /* dma memory setup for IOCFC */
1426 bfa_mem_dma_setup(meminfo, iocfc_dma, dm_len);
1427
1428 /* kva memory setup for IOCFC */
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001429 bfa_mem_kva_setup(meminfo, iocfc_kva, BFA_DBG_FWTRC_LEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001430}
1431
Jing Huang5fbe25c2010-10-18 17:17:23 -07001432/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001433 * Query IOC memory requirement information.
1434 */
1435void
1436bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001437 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001438{
1439 int i;
1440 struct bfa_ioc_s *ioc = &bfa->ioc;
1441
1442 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
1443 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
1444 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
1445 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
1446
1447 ioc->trcmod = bfa->trcmod;
1448 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
1449
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001450 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_PCIFN_CLASS_FC);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001451 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
1452
1453 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
Krishna Gudipati45070252011-06-24 20:24:29 -07001454 bfa_iocfc_mem_claim(bfa, cfg);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001455 INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001456
1457 INIT_LIST_HEAD(&bfa->comp_q);
1458 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
1459 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001460
1461 bfa->iocfc.cb_reqd = BFA_FALSE;
1462 bfa->iocfc.op_status = BFA_STATUS_OK;
1463 bfa->iocfc.submod_enabled = BFA_FALSE;
1464
1465 bfa_fsm_set_state(&bfa->iocfc, bfa_iocfc_sm_stopped);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001466}
1467
Jing Huang5fbe25c2010-10-18 17:17:23 -07001468/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001469 * Query IOC memory requirement information.
1470 */
1471void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001472bfa_iocfc_init(struct bfa_s *bfa)
1473{
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001474 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_INIT);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001475}
1476
Jing Huang5fbe25c2010-10-18 17:17:23 -07001477/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001478 * IOC start called from bfa_start(). Called to start IOC operations
1479 * at driver instantiation for this instance.
1480 */
1481void
1482bfa_iocfc_start(struct bfa_s *bfa)
1483{
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001484 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_START);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001485}
1486
Jing Huang5fbe25c2010-10-18 17:17:23 -07001487/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001488 * IOC stop called from bfa_stop(). Called only when driver is unloaded
1489 * for this instance.
1490 */
1491void
1492bfa_iocfc_stop(struct bfa_s *bfa)
1493{
Krishna Gudipati775c7742011-06-13 15:52:12 -07001494 bfa->queue_process = BFA_FALSE;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001495 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001496}
1497
1498void
1499bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
1500{
1501 struct bfa_s *bfa = bfaarg;
1502 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1503 union bfi_iocfc_i2h_msg_u *msg;
1504
1505 msg = (union bfi_iocfc_i2h_msg_u *) m;
1506 bfa_trc(bfa, msg->mh.msg_id);
1507
1508 switch (msg->mh.msg_id) {
1509 case BFI_IOCFC_I2H_CFG_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001510 bfa_iocfc_cfgrsp(bfa);
1511 break;
1512 case BFI_IOCFC_I2H_UPDATEQ_RSP:
1513 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
1514 break;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001515 case BFI_IOCFC_I2H_ADDR_MSG:
1516 bfa_iocfc_process_faa_addr(bfa,
1517 (struct bfi_faa_addr_msg_s *)msg);
Krishna Gudipatia7141342011-06-24 20:23:19 -07001518 break;
1519 case BFI_IOCFC_I2H_FAA_QUERY_RSP:
1520 bfa_faa_query_reply(iocfc, (bfi_faa_query_rsp_t *)msg);
1521 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001522 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001523 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001524 }
1525}
1526
1527void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001528bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
1529{
1530 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1531
1532 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
1533
1534 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
Jing Huangba816ea2010-10-18 17:10:50 -07001535 be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
1536 be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001537
1538 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
Jing Huangba816ea2010-10-18 17:10:50 -07001539 be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
1540 be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001541
1542 attr->config = iocfc->cfg;
1543}
1544
1545bfa_status_t
1546bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
1547{
1548 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1549 struct bfi_iocfc_set_intr_req_s *m;
1550
1551 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
Jing Huangba816ea2010-10-18 17:10:50 -07001552 iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
1553 iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001554
1555 if (!bfa_iocfc_is_operational(bfa))
1556 return BFA_STATUS_OK;
1557
1558 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
1559 if (!m)
1560 return BFA_STATUS_DEVBUSY;
1561
1562 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001563 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001564 m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
1565 m->delay = iocfc->cfginfo->intr_attr.delay;
1566 m->latency = iocfc->cfginfo->intr_attr.latency;
1567
1568 bfa_trc(bfa, attr->delay);
1569 bfa_trc(bfa, attr->latency);
1570
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001571 bfa_reqq_produce(bfa, BFA_REQQ_IOC, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001572 return BFA_STATUS_OK;
1573}
1574
1575void
Krishna Gudipati45070252011-06-24 20:24:29 -07001576bfa_iocfc_set_snsbase(struct bfa_s *bfa, int seg_no, u64 snsbase_pa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001577{
1578 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1579
1580 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
Krishna Gudipati45070252011-06-24 20:24:29 -07001581 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase[seg_no], snsbase_pa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001582}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001583/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001584 * Enable IOC after it is disabled.
1585 */
1586void
1587bfa_iocfc_enable(struct bfa_s *bfa)
1588{
1589 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1590 "IOC Enable");
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001591 bfa->iocfc.cb_reqd = BFA_TRUE;
1592 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001593}
1594
1595void
1596bfa_iocfc_disable(struct bfa_s *bfa)
1597{
1598 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1599 "IOC Disable");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001600
Krishna Gudipati775c7742011-06-13 15:52:12 -07001601 bfa->queue_process = BFA_FALSE;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001602 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001603}
1604
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001605bfa_boolean_t
1606bfa_iocfc_is_operational(struct bfa_s *bfa)
1607{
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001608 return bfa_ioc_is_operational(&bfa->ioc) &&
1609 bfa_fsm_cmp_state(&bfa->iocfc, bfa_iocfc_sm_operational);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001610}
1611
Jing Huang5fbe25c2010-10-18 17:17:23 -07001612/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001613 * Return boot target port wwns -- read from boot information in flash.
1614 */
1615void
1616bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
1617{
1618 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1619 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1620 int i;
1621
1622 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
1623 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
1624 *nwwns = cfgrsp->pbc_cfg.nbluns;
1625 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
1626 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
1627
1628 return;
1629 }
1630
1631 *nwwns = cfgrsp->bootwwns.nwwns;
1632 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
1633}
1634
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001635int
1636bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
1637{
1638 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1639 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1640
1641 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
1642 return cfgrsp->pbc_cfg.nvports;
1643}
1644
Jing Huang7725ccf2009-09-23 17:46:15 -07001645
Jing Huang5fbe25c2010-10-18 17:17:23 -07001646/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001647 * Use this function query the memory requirement of the BFA library.
1648 * This function needs to be called before bfa_attach() to get the
1649 * memory required of the BFA layer for a given driver configuration.
1650 *
1651 * This call will fail, if the cap is out of range compared to pre-defined
1652 * values within the BFA library
1653 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001654 * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
1655 * its configuration in this structure.
Jing Huang7725ccf2009-09-23 17:46:15 -07001656 * The default values for struct bfa_iocfc_cfg_s can be
1657 * fetched using bfa_cfg_get_default() API.
1658 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001659 * If cap's boundary check fails, the library will use
Jing Huang7725ccf2009-09-23 17:46:15 -07001660 * the default bfa_cap_t values (and log a warning msg).
1661 *
1662 * @param[out] meminfo - pointer to bfa_meminfo_t. This content
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001663 * indicates the memory type (see bfa_mem_type_t) and
Jing Huang7725ccf2009-09-23 17:46:15 -07001664 * amount of memory required.
1665 *
1666 * Driver should allocate the memory, populate the
1667 * starting address for each block and provide the same
1668 * structure as input parameter to bfa_attach() call.
1669 *
Krishna Gudipati45070252011-06-24 20:24:29 -07001670 * @param[in] bfa - pointer to the bfa structure, used while fetching the
1671 * dma, kva memory information of the bfa sub-modules.
1672 *
Jing Huang7725ccf2009-09-23 17:46:15 -07001673 * @return void
1674 *
1675 * Special Considerations: @note
1676 */
1677void
Krishna Gudipati45070252011-06-24 20:24:29 -07001678bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1679 struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001680{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001681 int i;
Krishna Gudipati45070252011-06-24 20:24:29 -07001682 struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
1683 struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
Krishna Gudipati148d6102011-06-24 20:25:36 -07001684 struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
Krishna Gudipati51e569a2011-06-24 20:26:25 -07001685 struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07001686 struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07001687 struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
Krishna Gudipati3350d982011-06-24 20:28:37 -07001688 struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001689
Jing Huangd4b671c2010-12-26 21:46:35 -08001690 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001691
Jing Huang6a18b162010-10-18 17:08:54 -07001692 memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001693
Krishna Gudipati45070252011-06-24 20:24:29 -07001694 /* Initialize the DMA & KVA meminfo queues */
1695 INIT_LIST_HEAD(&meminfo->dma_info.qe);
1696 INIT_LIST_HEAD(&meminfo->kva_info.qe);
1697
1698 bfa_iocfc_meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001699
1700 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001701 hal_mods[i]->meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001702
Krishna Gudipati45070252011-06-24 20:24:29 -07001703 /* dma info setup */
1704 bfa_mem_dma_setup(meminfo, port_dma, bfa_port_meminfo());
1705 bfa_mem_dma_setup(meminfo, ablk_dma, bfa_ablk_meminfo());
Krishna Gudipati148d6102011-06-24 20:25:36 -07001706 bfa_mem_dma_setup(meminfo, cee_dma, bfa_cee_meminfo());
Krishna Gudipati51e569a2011-06-24 20:26:25 -07001707 bfa_mem_dma_setup(meminfo, sfp_dma, bfa_sfp_meminfo());
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07001708 bfa_mem_dma_setup(meminfo, flash_dma,
1709 bfa_flash_meminfo(cfg->drvcfg.min_cfg));
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07001710 bfa_mem_dma_setup(meminfo, diag_dma, bfa_diag_meminfo());
Krishna Gudipati3350d982011-06-24 20:28:37 -07001711 bfa_mem_dma_setup(meminfo, phy_dma,
1712 bfa_phy_meminfo(cfg->drvcfg.min_cfg));
Jing Huang7725ccf2009-09-23 17:46:15 -07001713}
1714
Jing Huang5fbe25c2010-10-18 17:17:23 -07001715/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001716 * Use this function to do attach the driver instance with the BFA
1717 * library. This function will not trigger any HW initialization
1718 * process (which will be done in bfa_init() call)
1719 *
1720 * This call will fail, if the cap is out of range compared to
1721 * pre-defined values within the BFA library
1722 *
1723 * @param[out] bfa Pointer to bfa_t.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001724 * @param[in] bfad Opaque handle back to the driver's IOC structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001725 * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001726 * that was used in bfa_cfg_get_meminfo().
1727 * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
1728 * use the bfa_cfg_get_meminfo() call to
1729 * find the memory blocks required, allocate the
1730 * required memory and provide the starting addresses.
1731 * @param[in] pcidev pointer to struct bfa_pcidev_s
Jing Huang7725ccf2009-09-23 17:46:15 -07001732 *
1733 * @return
1734 * void
1735 *
1736 * Special Considerations:
1737 *
1738 * @note
1739 *
1740 */
1741void
1742bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1743 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1744{
Krishna Gudipati45070252011-06-24 20:24:29 -07001745 int i;
1746 struct bfa_mem_dma_s *dma_info, *dma_elem;
1747 struct bfa_mem_kva_s *kva_info, *kva_elem;
1748 struct list_head *dm_qe, *km_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001749
1750 bfa->fcs = BFA_FALSE;
1751
Jing Huangd4b671c2010-12-26 21:46:35 -08001752 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001753
Krishna Gudipati45070252011-06-24 20:24:29 -07001754 /* Initialize memory pointers for iterative allocation */
1755 dma_info = &meminfo->dma_info;
1756 dma_info->kva_curp = dma_info->kva;
1757 dma_info->dma_curp = dma_info->dma;
1758
1759 kva_info = &meminfo->kva_info;
1760 kva_info->kva_curp = kva_info->kva;
1761
1762 list_for_each(dm_qe, &dma_info->qe) {
1763 dma_elem = (struct bfa_mem_dma_s *) dm_qe;
1764 dma_elem->kva_curp = dma_elem->kva;
1765 dma_elem->dma_curp = dma_elem->dma;
Jing Huang7725ccf2009-09-23 17:46:15 -07001766 }
1767
Krishna Gudipati45070252011-06-24 20:24:29 -07001768 list_for_each(km_qe, &kva_info->qe) {
1769 kva_elem = (struct bfa_mem_kva_s *) km_qe;
1770 kva_elem->kva_curp = kva_elem->kva;
1771 }
1772
1773 bfa_iocfc_attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001774
1775 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001776 hal_mods[i]->attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001777
Krishna Gudipati45070252011-06-24 20:24:29 -07001778 bfa_com_port_attach(bfa);
1779 bfa_com_ablk_attach(bfa);
Krishna Gudipati148d6102011-06-24 20:25:36 -07001780 bfa_com_cee_attach(bfa);
Krishna Gudipati51e569a2011-06-24 20:26:25 -07001781 bfa_com_sfp_attach(bfa);
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07001782 bfa_com_flash_attach(bfa, cfg->drvcfg.min_cfg);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07001783 bfa_com_diag_attach(bfa);
Krishna Gudipati3350d982011-06-24 20:28:37 -07001784 bfa_com_phy_attach(bfa, cfg->drvcfg.min_cfg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001785}
1786
Jing Huang5fbe25c2010-10-18 17:17:23 -07001787/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001788 * Use this function to delete a BFA IOC. IOC should be stopped (by
1789 * calling bfa_stop()) before this function call.
1790 *
1791 * @param[in] bfa - pointer to bfa_t.
1792 *
1793 * @return
1794 * void
1795 *
1796 * Special Considerations:
1797 *
1798 * @note
1799 */
1800void
1801bfa_detach(struct bfa_s *bfa)
1802{
1803 int i;
1804
1805 for (i = 0; hal_mods[i]; i++)
1806 hal_mods[i]->detach(bfa);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001807 bfa_ioc_detach(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001808}
1809
1810void
1811bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
1812{
1813 INIT_LIST_HEAD(comp_q);
1814 list_splice_tail_init(&bfa->comp_q, comp_q);
1815}
1816
1817void
1818bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
1819{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001820 struct list_head *qe;
1821 struct list_head *qen;
1822 struct bfa_cb_qe_s *hcb_qe;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07001823 bfa_cb_cbfn_status_t cbfn;
Jing Huang7725ccf2009-09-23 17:46:15 -07001824
1825 list_for_each_safe(qe, qen, comp_q) {
1826 hcb_qe = (struct bfa_cb_qe_s *) qe;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07001827 if (hcb_qe->pre_rmv) {
1828 /* qe is invalid after return, dequeue before cbfn() */
1829 list_del(qe);
1830 cbfn = (bfa_cb_cbfn_status_t)(hcb_qe->cbfn);
1831 cbfn(hcb_qe->cbarg, hcb_qe->fw_status);
1832 } else
1833 hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001834 }
1835}
1836
1837void
1838bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
1839{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001840 struct list_head *qe;
1841 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001842
1843 while (!list_empty(comp_q)) {
1844 bfa_q_deq(comp_q, &qe);
1845 hcb_qe = (struct bfa_cb_qe_s *) qe;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07001846 WARN_ON(hcb_qe->pre_rmv);
Jing Huang7725ccf2009-09-23 17:46:15 -07001847 hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
1848 }
1849}
1850
Jing Huang5fbe25c2010-10-18 17:17:23 -07001851/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001852 * Return the list of PCI vendor/device id lists supported by this
1853 * BFA instance.
1854 */
1855void
1856bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
1857{
1858 static struct bfa_pciid_s __pciids[] = {
1859 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
1860 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
1861 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
Jing Huang293f82d2010-07-08 19:45:20 -07001862 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
Jing Huang7725ccf2009-09-23 17:46:15 -07001863 };
1864
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001865 *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001866 *pciids = __pciids;
1867}
1868
Jing Huang5fbe25c2010-10-18 17:17:23 -07001869/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001870 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
1871 * into BFA layer). The OS driver can then turn back and overwrite entries that
1872 * have been configured by the user.
1873 *
1874 * @param[in] cfg - pointer to bfa_ioc_cfg_t
1875 *
1876 * @return
1877 * void
1878 *
1879 * Special Considerations:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001880 * note
Jing Huang7725ccf2009-09-23 17:46:15 -07001881 */
1882void
1883bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
1884{
1885 cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
1886 cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
1887 cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
1888 cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
1889 cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
1890 cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
1891 cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
1892 cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001893 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001894
1895 cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
1896 cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
1897 cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
1898 cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
1899 cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
1900 cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
1901 cfg->drvcfg.ioc_recover = BFA_FALSE;
1902 cfg->drvcfg.delay_comp = BFA_FALSE;
1903
1904}
1905
1906void
1907bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
1908{
1909 bfa_cfg_get_default(cfg);
1910 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
1911 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
1912 cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
1913 cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
1914 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001915 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001916
1917 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
1918 cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
1919 cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001920 cfg->drvcfg.min_cfg = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001921}