blob: f157a37150d7d59499346e27d99f6edd7033b5d7 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05002 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
Jing Huang7725ccf2009-09-23 17:46:15 -07004 * All rights reserved
Anil Gurumurthy889d0d42015-11-26 03:54:45 -05005 * www.qlogic.com
Jing Huang7725ccf2009-09-23 17:46:15 -07006 *
7 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 */
18
Maggie Zhangf16a1752010-12-09 19:12:32 -080019#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070020#include "bfa_modules.h"
Krishna Gudipati11189202011-06-13 15:50:35 -070021#include "bfi_reg.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070022
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070023BFA_TRC_FILE(HAL, CORE);
Jing Huang7725ccf2009-09-23 17:46:15 -070024
Jing Huang5fbe25c2010-10-18 17:17:23 -070025/*
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080026 * BFA module list terminated by NULL
27 */
28static struct bfa_module_s *hal_mods[] = {
Krishna Gudipati3d7fc662011-06-24 20:28:17 -070029 &hal_mod_fcdiag,
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080030 &hal_mod_sgpg,
31 &hal_mod_fcport,
32 &hal_mod_fcxp,
33 &hal_mod_lps,
34 &hal_mod_uf,
35 &hal_mod_rport,
Krishna Gudipatie2187d72011-06-13 15:53:58 -070036 &hal_mod_fcp,
Krishna Gudipati45c5dc12011-07-20 17:03:46 -070037 &hal_mod_dconf,
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080038 NULL
39};
40
41/*
42 * Message handlers for various modules.
43 */
44static bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
45 bfa_isr_unhandled, /* NONE */
46 bfa_isr_unhandled, /* BFI_MC_IOC */
Krishna Gudipati3d7fc662011-06-24 20:28:17 -070047 bfa_fcdiag_intr, /* BFI_MC_DIAG */
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080048 bfa_isr_unhandled, /* BFI_MC_FLASH */
49 bfa_isr_unhandled, /* BFI_MC_CEE */
50 bfa_fcport_isr, /* BFI_MC_FCPORT */
51 bfa_isr_unhandled, /* BFI_MC_IOCFC */
52 bfa_isr_unhandled, /* BFI_MC_LL */
53 bfa_uf_isr, /* BFI_MC_UF */
54 bfa_fcxp_isr, /* BFI_MC_FCXP */
55 bfa_lps_isr, /* BFI_MC_LPS */
56 bfa_rport_isr, /* BFI_MC_RPORT */
Krishna Gudipatie2187d72011-06-13 15:53:58 -070057 bfa_itn_isr, /* BFI_MC_ITN */
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080058 bfa_isr_unhandled, /* BFI_MC_IOIM_READ */
59 bfa_isr_unhandled, /* BFI_MC_IOIM_WRITE */
60 bfa_isr_unhandled, /* BFI_MC_IOIM_IO */
61 bfa_ioim_isr, /* BFI_MC_IOIM */
62 bfa_ioim_good_comp_isr, /* BFI_MC_IOIM_IOCOM */
63 bfa_tskim_isr, /* BFI_MC_TSKIM */
64 bfa_isr_unhandled, /* BFI_MC_SBOOT */
65 bfa_isr_unhandled, /* BFI_MC_IPFC */
66 bfa_isr_unhandled, /* BFI_MC_PORT */
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 bfa_isr_unhandled, /* --------- */
77};
78/*
79 * Message handlers for mailbox command classes
80 */
81static bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = {
82 NULL,
83 NULL, /* BFI_MC_IOC */
84 NULL, /* BFI_MC_DIAG */
85 NULL, /* BFI_MC_FLASH */
86 NULL, /* BFI_MC_CEE */
87 NULL, /* BFI_MC_PORT */
88 bfa_iocfc_isr, /* BFI_MC_IOCFC */
89 NULL,
90};
91
92
93
94static void
Krishna Gudipati45070252011-06-24 20:24:29 -070095bfa_com_port_attach(struct bfa_s *bfa)
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080096{
97 struct bfa_port_s *port = &bfa->modules.port;
Krishna Gudipati45070252011-06-24 20:24:29 -070098 struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
Maggie Zhangb77ee1f2010-12-09 19:09:26 -080099
Maggie Zhangb77ee1f2010-12-09 19:09:26 -0800100 bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod);
Krishna Gudipati45070252011-06-24 20:24:29 -0700101 bfa_port_mem_claim(port, port_dma->kva_curp, port_dma->dma_curp);
Maggie Zhangb77ee1f2010-12-09 19:09:26 -0800102}
103
104/*
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700105 * ablk module attach
106 */
107static void
Krishna Gudipati45070252011-06-24 20:24:29 -0700108bfa_com_ablk_attach(struct bfa_s *bfa)
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700109{
110 struct bfa_ablk_s *ablk = &bfa->modules.ablk;
Krishna Gudipati45070252011-06-24 20:24:29 -0700111 struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700112
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700113 bfa_ablk_attach(ablk, &bfa->ioc);
Krishna Gudipati45070252011-06-24 20:24:29 -0700114 bfa_ablk_memclaim(ablk, ablk_dma->kva_curp, ablk_dma->dma_curp);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700115}
116
Krishna Gudipati148d6102011-06-24 20:25:36 -0700117static void
118bfa_com_cee_attach(struct bfa_s *bfa)
119{
120 struct bfa_cee_s *cee = &bfa->modules.cee;
121 struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
122
123 cee->trcmod = bfa->trcmod;
124 bfa_cee_attach(cee, &bfa->ioc, bfa);
125 bfa_cee_mem_claim(cee, cee_dma->kva_curp, cee_dma->dma_curp);
126}
127
Krishna Gudipati51e569a2011-06-24 20:26:25 -0700128static void
129bfa_com_sfp_attach(struct bfa_s *bfa)
130{
131 struct bfa_sfp_s *sfp = BFA_SFP_MOD(bfa);
132 struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
133
134 bfa_sfp_attach(sfp, &bfa->ioc, bfa, bfa->trcmod);
135 bfa_sfp_memclaim(sfp, sfp_dma->kva_curp, sfp_dma->dma_curp);
136}
137
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -0700138static void
139bfa_com_flash_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
140{
141 struct bfa_flash_s *flash = BFA_FLASH(bfa);
142 struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
143
144 bfa_flash_attach(flash, &bfa->ioc, bfa, bfa->trcmod, mincfg);
145 bfa_flash_memclaim(flash, flash_dma->kva_curp,
146 flash_dma->dma_curp, mincfg);
147}
148
Krishna Gudipati3d7fc662011-06-24 20:28:17 -0700149static void
150bfa_com_diag_attach(struct bfa_s *bfa)
151{
152 struct bfa_diag_s *diag = BFA_DIAG_MOD(bfa);
153 struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
154
155 bfa_diag_attach(diag, &bfa->ioc, bfa, bfa_fcport_beacon, bfa->trcmod);
156 bfa_diag_memclaim(diag, diag_dma->kva_curp, diag_dma->dma_curp);
157}
158
Krishna Gudipati3350d982011-06-24 20:28:37 -0700159static void
160bfa_com_phy_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
161{
162 struct bfa_phy_s *phy = BFA_PHY(bfa);
163 struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
164
165 bfa_phy_attach(phy, &bfa->ioc, bfa, bfa->trcmod, mincfg);
166 bfa_phy_memclaim(phy, phy_dma->kva_curp, phy_dma->dma_curp, mincfg);
167}
168
Krishna Gudipatie6826c92012-09-21 17:27:14 -0700169static void
170bfa_com_fru_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
171{
172 struct bfa_fru_s *fru = BFA_FRU(bfa);
173 struct bfa_mem_dma_s *fru_dma = BFA_MEM_FRU_DMA(bfa);
174
175 bfa_fru_attach(fru, &bfa->ioc, bfa, bfa->trcmod, mincfg);
176 bfa_fru_memclaim(fru, fru_dma->kva_curp, fru_dma->dma_curp, mincfg);
177}
178
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -0700179/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700180 * BFA IOC FC related definitions
181 */
182
Jing Huang5fbe25c2010-10-18 17:17:23 -0700183/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700184 * IOC local definitions
185 */
186#define BFA_IOCFC_TOV 5000 /* msecs */
187
188enum {
189 BFA_IOCFC_ACT_NONE = 0,
190 BFA_IOCFC_ACT_INIT = 1,
191 BFA_IOCFC_ACT_STOP = 2,
192 BFA_IOCFC_ACT_DISABLE = 3,
Krishna Gudipati60138062011-06-24 20:25:15 -0700193 BFA_IOCFC_ACT_ENABLE = 4,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700194};
195
196#define DEF_CFG_NUM_FABRICS 1
197#define DEF_CFG_NUM_LPORTS 256
198#define DEF_CFG_NUM_CQS 4
199#define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
200#define DEF_CFG_NUM_TSKIM_REQS 128
201#define DEF_CFG_NUM_FCXP_REQS 64
202#define DEF_CFG_NUM_UF_BUFS 64
203#define DEF_CFG_NUM_RPORTS 1024
204#define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
205#define DEF_CFG_NUM_TINS 256
206
207#define DEF_CFG_NUM_SGPGS 2048
208#define DEF_CFG_NUM_REQQ_ELEMS 256
209#define DEF_CFG_NUM_RSPQ_ELEMS 64
210#define DEF_CFG_NUM_SBOOT_TGTS 16
211#define DEF_CFG_NUM_SBOOT_LUNS 16
212
Jing Huang5fbe25c2010-10-18 17:17:23 -0700213/*
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700214 * IOCFC state machine definitions/declarations
215 */
216bfa_fsm_state_decl(bfa_iocfc, stopped, struct bfa_iocfc_s, enum iocfc_event);
217bfa_fsm_state_decl(bfa_iocfc, initing, struct bfa_iocfc_s, enum iocfc_event);
218bfa_fsm_state_decl(bfa_iocfc, dconf_read, struct bfa_iocfc_s, enum iocfc_event);
219bfa_fsm_state_decl(bfa_iocfc, init_cfg_wait,
220 struct bfa_iocfc_s, enum iocfc_event);
221bfa_fsm_state_decl(bfa_iocfc, init_cfg_done,
222 struct bfa_iocfc_s, enum iocfc_event);
223bfa_fsm_state_decl(bfa_iocfc, operational,
224 struct bfa_iocfc_s, enum iocfc_event);
225bfa_fsm_state_decl(bfa_iocfc, dconf_write,
226 struct bfa_iocfc_s, enum iocfc_event);
227bfa_fsm_state_decl(bfa_iocfc, stopping, struct bfa_iocfc_s, enum iocfc_event);
228bfa_fsm_state_decl(bfa_iocfc, enabling, struct bfa_iocfc_s, enum iocfc_event);
229bfa_fsm_state_decl(bfa_iocfc, cfg_wait, struct bfa_iocfc_s, enum iocfc_event);
230bfa_fsm_state_decl(bfa_iocfc, disabling, struct bfa_iocfc_s, enum iocfc_event);
231bfa_fsm_state_decl(bfa_iocfc, disabled, struct bfa_iocfc_s, enum iocfc_event);
232bfa_fsm_state_decl(bfa_iocfc, failed, struct bfa_iocfc_s, enum iocfc_event);
233bfa_fsm_state_decl(bfa_iocfc, init_failed,
234 struct bfa_iocfc_s, enum iocfc_event);
235
236/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700237 * forward declaration for IOC FC functions
238 */
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700239static void bfa_iocfc_start_submod(struct bfa_s *bfa);
240static void bfa_iocfc_disable_submod(struct bfa_s *bfa);
241static void bfa_iocfc_send_cfg(void *bfa_arg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700242static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
243static void bfa_iocfc_disable_cbfn(void *bfa_arg);
244static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
245static void bfa_iocfc_reset_cbfn(void *bfa_arg);
246static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700247static void bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete);
248static void bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl);
249static void bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl);
250static void bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl);
251
252static void
253bfa_iocfc_sm_stopped_entry(struct bfa_iocfc_s *iocfc)
254{
255}
256
257static void
258bfa_iocfc_sm_stopped(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
259{
260 bfa_trc(iocfc->bfa, event);
261
262 switch (event) {
263 case IOCFC_E_INIT:
264 case IOCFC_E_ENABLE:
265 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_initing);
266 break;
267 default:
268 bfa_sm_fault(iocfc->bfa, event);
269 break;
270 }
271}
272
273static void
274bfa_iocfc_sm_initing_entry(struct bfa_iocfc_s *iocfc)
275{
276 bfa_ioc_enable(&iocfc->bfa->ioc);
277}
278
279static void
280bfa_iocfc_sm_initing(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
281{
282 bfa_trc(iocfc->bfa, event);
283
284 switch (event) {
285 case IOCFC_E_IOC_ENABLED:
286 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
287 break;
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700288
289 case IOCFC_E_DISABLE:
290 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
291 break;
292
293 case IOCFC_E_STOP:
294 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
295 break;
296
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700297 case IOCFC_E_IOC_FAILED:
298 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
299 break;
300 default:
301 bfa_sm_fault(iocfc->bfa, event);
302 break;
303 }
304}
305
306static void
307bfa_iocfc_sm_dconf_read_entry(struct bfa_iocfc_s *iocfc)
308{
309 bfa_dconf_modinit(iocfc->bfa);
310}
311
312static void
313bfa_iocfc_sm_dconf_read(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
314{
315 bfa_trc(iocfc->bfa, event);
316
317 switch (event) {
318 case IOCFC_E_DCONF_DONE:
319 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_wait);
320 break;
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700321
322 case IOCFC_E_DISABLE:
323 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
324 break;
325
326 case IOCFC_E_STOP:
327 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
328 break;
329
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700330 case IOCFC_E_IOC_FAILED:
331 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
332 break;
333 default:
334 bfa_sm_fault(iocfc->bfa, event);
335 break;
336 }
337}
338
339static void
340bfa_iocfc_sm_init_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
341{
342 bfa_iocfc_send_cfg(iocfc->bfa);
343}
344
345static void
346bfa_iocfc_sm_init_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
347{
348 bfa_trc(iocfc->bfa, event);
349
350 switch (event) {
351 case IOCFC_E_CFG_DONE:
352 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_done);
353 break;
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700354
355 case IOCFC_E_DISABLE:
356 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
357 break;
358
359 case IOCFC_E_STOP:
360 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
361 break;
362
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700363 case IOCFC_E_IOC_FAILED:
364 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
365 break;
366 default:
367 bfa_sm_fault(iocfc->bfa, event);
368 break;
369 }
370}
371
372static void
373bfa_iocfc_sm_init_cfg_done_entry(struct bfa_iocfc_s *iocfc)
374{
375 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
376 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
377 bfa_iocfc_init_cb, iocfc->bfa);
378}
379
380static void
381bfa_iocfc_sm_init_cfg_done(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
382{
383 bfa_trc(iocfc->bfa, event);
384
385 switch (event) {
386 case IOCFC_E_START:
387 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
388 break;
389 case IOCFC_E_STOP:
390 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
391 break;
392 case IOCFC_E_DISABLE:
393 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
394 break;
395 case IOCFC_E_IOC_FAILED:
396 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
397 break;
398 default:
399 bfa_sm_fault(iocfc->bfa, event);
400 break;
401 }
402}
403
404static void
405bfa_iocfc_sm_operational_entry(struct bfa_iocfc_s *iocfc)
406{
407 bfa_fcport_init(iocfc->bfa);
408 bfa_iocfc_start_submod(iocfc->bfa);
409}
410
411static void
412bfa_iocfc_sm_operational(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
413{
414 bfa_trc(iocfc->bfa, event);
415
416 switch (event) {
417 case IOCFC_E_STOP:
418 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
419 break;
420 case IOCFC_E_DISABLE:
421 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
422 break;
423 case IOCFC_E_IOC_FAILED:
424 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
425 break;
426 default:
427 bfa_sm_fault(iocfc->bfa, event);
428 break;
429 }
430}
431
432static void
433bfa_iocfc_sm_dconf_write_entry(struct bfa_iocfc_s *iocfc)
434{
435 bfa_dconf_modexit(iocfc->bfa);
436}
437
438static void
439bfa_iocfc_sm_dconf_write(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
440{
441 bfa_trc(iocfc->bfa, event);
442
443 switch (event) {
444 case IOCFC_E_DCONF_DONE:
445 case IOCFC_E_IOC_FAILED:
446 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
447 break;
448 default:
449 bfa_sm_fault(iocfc->bfa, event);
450 break;
451 }
452}
453
454static void
455bfa_iocfc_sm_stopping_entry(struct bfa_iocfc_s *iocfc)
456{
457 bfa_ioc_disable(&iocfc->bfa->ioc);
458}
459
460static void
461bfa_iocfc_sm_stopping(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
462{
463 bfa_trc(iocfc->bfa, event);
464
465 switch (event) {
466 case IOCFC_E_IOC_DISABLED:
467 bfa_isr_disable(iocfc->bfa);
468 bfa_iocfc_disable_submod(iocfc->bfa);
469 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
470 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
471 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.stop_hcb_qe,
472 bfa_iocfc_stop_cb, iocfc->bfa);
473 break;
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700474
475 case IOCFC_E_IOC_ENABLED:
476 case IOCFC_E_DCONF_DONE:
477 case IOCFC_E_CFG_DONE:
478 break;
479
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700480 default:
481 bfa_sm_fault(iocfc->bfa, event);
482 break;
483 }
484}
485
486static void
487bfa_iocfc_sm_enabling_entry(struct bfa_iocfc_s *iocfc)
488{
489 bfa_ioc_enable(&iocfc->bfa->ioc);
490}
491
492static void
493bfa_iocfc_sm_enabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
494{
495 bfa_trc(iocfc->bfa, event);
496
497 switch (event) {
498 case IOCFC_E_IOC_ENABLED:
499 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
500 break;
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700501
502 case IOCFC_E_DISABLE:
503 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
504 break;
505
506 case IOCFC_E_STOP:
507 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
508 break;
509
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700510 case IOCFC_E_IOC_FAILED:
511 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
512
513 if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
514 break;
515
516 iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
517 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
518 bfa_iocfc_enable_cb, iocfc->bfa);
519 iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
520 break;
521 default:
522 bfa_sm_fault(iocfc->bfa, event);
523 break;
524 }
525}
526
527static void
528bfa_iocfc_sm_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
529{
530 bfa_iocfc_send_cfg(iocfc->bfa);
531}
532
533static void
534bfa_iocfc_sm_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
535{
536 bfa_trc(iocfc->bfa, event);
537
538 switch (event) {
539 case IOCFC_E_CFG_DONE:
540 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
541 if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
542 break;
543
544 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
545 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
546 bfa_iocfc_enable_cb, iocfc->bfa);
547 iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
548 break;
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700549 case IOCFC_E_DISABLE:
550 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
551 break;
552
553 case IOCFC_E_STOP:
554 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
555 break;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700556 case IOCFC_E_IOC_FAILED:
557 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
558 if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
559 break;
560
561 iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
562 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
563 bfa_iocfc_enable_cb, iocfc->bfa);
564 iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
565 break;
566 default:
567 bfa_sm_fault(iocfc->bfa, event);
568 break;
569 }
570}
571
572static void
573bfa_iocfc_sm_disabling_entry(struct bfa_iocfc_s *iocfc)
574{
575 bfa_ioc_disable(&iocfc->bfa->ioc);
576}
577
578static void
579bfa_iocfc_sm_disabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
580{
581 bfa_trc(iocfc->bfa, event);
582
583 switch (event) {
584 case IOCFC_E_IOC_DISABLED:
585 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabled);
586 break;
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700587 case IOCFC_E_IOC_ENABLED:
588 case IOCFC_E_DCONF_DONE:
589 case IOCFC_E_CFG_DONE:
590 break;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700591 default:
592 bfa_sm_fault(iocfc->bfa, event);
593 break;
594 }
595}
596
597static void
598bfa_iocfc_sm_disabled_entry(struct bfa_iocfc_s *iocfc)
599{
600 bfa_isr_disable(iocfc->bfa);
601 bfa_iocfc_disable_submod(iocfc->bfa);
602 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
603 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
604 bfa_iocfc_disable_cb, iocfc->bfa);
605}
606
607static void
608bfa_iocfc_sm_disabled(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
609{
610 bfa_trc(iocfc->bfa, event);
611
612 switch (event) {
613 case IOCFC_E_STOP:
614 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
615 break;
616 case IOCFC_E_ENABLE:
617 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_enabling);
618 break;
619 default:
620 bfa_sm_fault(iocfc->bfa, event);
621 break;
622 }
623}
624
625static void
626bfa_iocfc_sm_failed_entry(struct bfa_iocfc_s *iocfc)
627{
628 bfa_isr_disable(iocfc->bfa);
629 bfa_iocfc_disable_submod(iocfc->bfa);
630}
631
632static void
633bfa_iocfc_sm_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
634{
635 bfa_trc(iocfc->bfa, event);
636
637 switch (event) {
638 case IOCFC_E_STOP:
639 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
640 break;
641 case IOCFC_E_DISABLE:
642 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
643 break;
644 case IOCFC_E_IOC_ENABLED:
645 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
646 break;
647 case IOCFC_E_IOC_FAILED:
648 break;
649 default:
650 bfa_sm_fault(iocfc->bfa, event);
651 break;
652 }
653}
654
655static void
656bfa_iocfc_sm_init_failed_entry(struct bfa_iocfc_s *iocfc)
657{
658 bfa_isr_disable(iocfc->bfa);
659 iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
660 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
661 bfa_iocfc_init_cb, iocfc->bfa);
662}
663
664static void
665bfa_iocfc_sm_init_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
666{
667 bfa_trc(iocfc->bfa, event);
668
669 switch (event) {
670 case IOCFC_E_STOP:
671 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
672 break;
673 case IOCFC_E_DISABLE:
674 bfa_ioc_disable(&iocfc->bfa->ioc);
675 break;
676 case IOCFC_E_IOC_ENABLED:
677 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
678 break;
679 case IOCFC_E_IOC_DISABLED:
680 bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
681 iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
682 bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
683 bfa_iocfc_disable_cb, iocfc->bfa);
684 break;
685 case IOCFC_E_IOC_FAILED:
686 break;
687 default:
688 bfa_sm_fault(iocfc->bfa, event);
689 break;
690 }
691}
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700692
Jing Huang5fbe25c2010-10-18 17:17:23 -0700693/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700694 * BFA Interrupt handling functions
695 */
696static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700697bfa_reqq_resume(struct bfa_s *bfa, int qid)
698{
699 struct list_head *waitq, *qe, *qen;
700 struct bfa_reqq_wait_s *wqe;
701
702 waitq = bfa_reqq(bfa, qid);
703 list_for_each_safe(qe, qen, waitq) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700704 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700705 * Callback only as long as there is room in request queue
706 */
707 if (bfa_reqq_full(bfa, qid))
708 break;
709
710 list_del(qe);
711 wqe = (struct bfa_reqq_wait_s *) qe;
712 wqe->qresume(wqe->cbarg);
713 }
714}
715
Krishna Gudipati1f670962012-03-13 17:38:15 -0700716bfa_boolean_t
Krishna Gudipati11189202011-06-13 15:50:35 -0700717bfa_isr_rspq(struct bfa_s *bfa, int qid)
718{
719 struct bfi_msg_s *m;
720 u32 pi, ci;
721 struct list_head *waitq;
Krishna Gudipati1f670962012-03-13 17:38:15 -0700722 bfa_boolean_t ret;
Krishna Gudipati11189202011-06-13 15:50:35 -0700723
Krishna Gudipati11189202011-06-13 15:50:35 -0700724 ci = bfa_rspq_ci(bfa, qid);
725 pi = bfa_rspq_pi(bfa, qid);
726
Krishna Gudipati1f670962012-03-13 17:38:15 -0700727 ret = (ci != pi);
728
Krishna Gudipati11189202011-06-13 15:50:35 -0700729 while (ci != pi) {
730 m = bfa_rspq_elem(bfa, qid, ci);
731 WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
732
733 bfa_isrs[m->mhdr.msg_class] (bfa, m);
734 CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
735 }
736
737 /*
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700738 * acknowledge RME completions and update CI
Krishna Gudipati11189202011-06-13 15:50:35 -0700739 */
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700740 bfa_isr_rspq_ack(bfa, qid, ci);
Krishna Gudipati11189202011-06-13 15:50:35 -0700741
742 /*
743 * Resume any pending requests in the corresponding reqq.
744 */
745 waitq = bfa_reqq(bfa, qid);
746 if (!list_empty(waitq))
747 bfa_reqq_resume(bfa, qid);
Krishna Gudipati1f670962012-03-13 17:38:15 -0700748
749 return ret;
Krishna Gudipati11189202011-06-13 15:50:35 -0700750}
751
752static inline void
753bfa_isr_reqq(struct bfa_s *bfa, int qid)
754{
755 struct list_head *waitq;
756
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700757 bfa_isr_reqq_ack(bfa, qid);
Krishna Gudipati11189202011-06-13 15:50:35 -0700758
759 /*
760 * Resume any pending requests in the corresponding reqq.
761 */
762 waitq = bfa_reqq(bfa, qid);
763 if (!list_empty(waitq))
764 bfa_reqq_resume(bfa, qid);
765}
766
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700767void
768bfa_msix_all(struct bfa_s *bfa, int vec)
769{
Krishna Gudipati10a07372011-06-24 20:23:38 -0700770 u32 intr, qintr;
771 int queue;
772
773 intr = readl(bfa->iocfc.bfa_regs.intr_status);
774 if (!intr)
775 return;
776
777 /*
778 * RME completion queue interrupt
779 */
780 qintr = intr & __HFN_INT_RME_MASK;
781 if (qintr && bfa->queue_process) {
782 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
783 bfa_isr_rspq(bfa, queue);
784 }
785
786 intr &= ~qintr;
787 if (!intr)
788 return;
789
790 /*
791 * CPE completion queue interrupt
792 */
793 qintr = intr & __HFN_INT_CPE_MASK;
794 if (qintr && bfa->queue_process) {
795 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
796 bfa_isr_reqq(bfa, queue);
797 }
798 intr &= ~qintr;
799 if (!intr)
800 return;
801
802 bfa_msix_lpu_err(bfa, intr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700803}
804
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700805bfa_boolean_t
806bfa_intx(struct bfa_s *bfa)
807{
808 u32 intr, qintr;
809 int queue;
Krishna Gudipati1f670962012-03-13 17:38:15 -0700810 bfa_boolean_t rspq_comp = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811
Jing Huang53440262010-10-18 17:12:29 -0700812 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700813
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700814 qintr = intr & (__HFN_INT_RME_MASK | __HFN_INT_CPE_MASK);
815 if (qintr)
816 writel(qintr, bfa->iocfc.bfa_regs.intr_status);
817
Jing Huang5fbe25c2010-10-18 17:17:23 -0700818 /*
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700819 * Unconditional RME completion queue interrupt
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700820 */
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700821 if (bfa->queue_process) {
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700822 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
Krishna Gudipati1f670962012-03-13 17:38:15 -0700823 if (bfa_isr_rspq(bfa, queue))
824 rspq_comp = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700825 }
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700826
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700827 if (!intr)
Krishna Gudipati1f670962012-03-13 17:38:15 -0700828 return (qintr | rspq_comp) ? BFA_TRUE : BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700829
Jing Huang5fbe25c2010-10-18 17:17:23 -0700830 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700831 * CPE completion queue interrupt
832 */
833 qintr = intr & __HFN_INT_CPE_MASK;
Krishna Gudipati3fd45982011-06-24 20:24:08 -0700834 if (qintr && bfa->queue_process) {
835 for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
836 bfa_isr_reqq(bfa, queue);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700837 }
838 intr &= ~qintr;
839 if (!intr)
840 return BFA_TRUE;
841
Krishna Gudipati9aec0242012-08-22 19:52:18 -0700842 if (bfa->intr_enabled)
843 bfa_msix_lpu_err(bfa, intr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700844
845 return BFA_TRUE;
846}
847
848void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849bfa_isr_enable(struct bfa_s *bfa)
850{
Krishna Gudipati11189202011-06-13 15:50:35 -0700851 u32 umsk;
Krishna Gudipati1a1297c2012-09-21 17:26:50 -0700852 int port_id = bfa_ioc_portid(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700853
Krishna Gudipati1a1297c2012-09-21 17:26:50 -0700854 bfa_trc(bfa, bfa_ioc_pcifn(&bfa->ioc));
855 bfa_trc(bfa, port_id);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700856
Krishna Gudipati775c7742011-06-13 15:52:12 -0700857 bfa_msix_ctrl_install(bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700858
Krishna Gudipati11189202011-06-13 15:50:35 -0700859 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
860 umsk = __HFN_INT_ERR_MASK_CT2;
Krishna Gudipati1a1297c2012-09-21 17:26:50 -0700861 umsk |= port_id == 0 ?
Krishna Gudipati11189202011-06-13 15:50:35 -0700862 __HFN_INT_FN0_MASK_CT2 : __HFN_INT_FN1_MASK_CT2;
863 } else {
864 umsk = __HFN_INT_ERR_MASK;
Krishna Gudipati1a1297c2012-09-21 17:26:50 -0700865 umsk |= port_id == 0 ? __HFN_INT_FN0_MASK : __HFN_INT_FN1_MASK;
Krishna Gudipati11189202011-06-13 15:50:35 -0700866 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700867
Krishna Gudipati11189202011-06-13 15:50:35 -0700868 writel(umsk, bfa->iocfc.bfa_regs.intr_status);
869 writel(~umsk, bfa->iocfc.bfa_regs.intr_mask);
870 bfa->iocfc.intr_mask = ~umsk;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700871 bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
Krishna Gudipati9aec0242012-08-22 19:52:18 -0700872
873 /*
874 * Set the flag indicating successful enabling of interrupts
875 */
876 bfa->intr_enabled = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700877}
878
879void
880bfa_isr_disable(struct bfa_s *bfa)
881{
Krishna Gudipati9aec0242012-08-22 19:52:18 -0700882 bfa->intr_enabled = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700883 bfa_isr_mode_set(bfa, BFA_FALSE);
Jing Huang53440262010-10-18 17:12:29 -0700884 writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700885 bfa_msix_uninstall(bfa);
886}
887
888void
Krishna Gudipati11189202011-06-13 15:50:35 -0700889bfa_msix_reqq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890{
Krishna Gudipati11189202011-06-13 15:50:35 -0700891 bfa_isr_reqq(bfa, vec - bfa->iocfc.hwif.cpe_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700892}
893
894void
895bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
896{
897 bfa_trc(bfa, m->mhdr.msg_class);
898 bfa_trc(bfa, m->mhdr.msg_id);
899 bfa_trc(bfa, m->mhdr.mtag.i2htok);
Jing Huangd4b671c2010-12-26 21:46:35 -0800900 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700901 bfa_trc_stop(bfa->trcmod);
902}
903
904void
Krishna Gudipati11189202011-06-13 15:50:35 -0700905bfa_msix_rspq(struct bfa_s *bfa, int vec)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700906{
Krishna Gudipati11189202011-06-13 15:50:35 -0700907 bfa_isr_rspq(bfa, vec - bfa->iocfc.hwif.rme_vec_q0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700908}
909
910void
911bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
912{
913 u32 intr, curr_value;
Krishna Gudipati11189202011-06-13 15:50:35 -0700914 bfa_boolean_t lpu_isr, halt_isr, pss_isr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700915
Jing Huang53440262010-10-18 17:12:29 -0700916 intr = readl(bfa->iocfc.bfa_regs.intr_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700917
Krishna Gudipati11189202011-06-13 15:50:35 -0700918 if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
919 halt_isr = intr & __HFN_INT_CPQ_HALT_CT2;
920 pss_isr = intr & __HFN_INT_ERR_PSS_CT2;
921 lpu_isr = intr & (__HFN_INT_MBOX_LPU0_CT2 |
922 __HFN_INT_MBOX_LPU1_CT2);
923 intr &= __HFN_INT_ERR_MASK_CT2;
924 } else {
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -0700925 halt_isr = bfa_asic_id_ct(bfa->ioc.pcidev.device_id) ?
926 (intr & __HFN_INT_LL_HALT) : 0;
Krishna Gudipati11189202011-06-13 15:50:35 -0700927 pss_isr = intr & __HFN_INT_ERR_PSS;
928 lpu_isr = intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1);
929 intr &= __HFN_INT_ERR_MASK;
930 }
931
932 if (lpu_isr)
Maggie Zhangda99dcc2010-12-09 19:13:20 -0800933 bfa_ioc_mbox_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700934
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700935 if (intr) {
Krishna Gudipati11189202011-06-13 15:50:35 -0700936 if (halt_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700937 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700938 * If LL_HALT bit is set then FW Init Halt LL Port
939 * Register needs to be cleared as well so Interrupt
940 * Status Register will be cleared.
941 */
Jing Huang53440262010-10-18 17:12:29 -0700942 curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700943 curr_value &= ~__FW_INIT_HALT_P;
Jing Huang53440262010-10-18 17:12:29 -0700944 writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700945 }
946
Krishna Gudipati11189202011-06-13 15:50:35 -0700947 if (pss_isr) {
Jing Huang5fbe25c2010-10-18 17:17:23 -0700948 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700949 * ERR_PSS bit needs to be cleared as well in case
950 * interrups are shared so driver's interrupt handler is
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300951 * still called even though it is already masked out.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700952 */
Jing Huang53440262010-10-18 17:12:29 -0700953 curr_value = readl(
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700954 bfa->ioc.ioc_regs.pss_err_status_reg);
Jing Huang53440262010-10-18 17:12:29 -0700955 writel(curr_value,
956 bfa->ioc.ioc_regs.pss_err_status_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700957 }
958
Jing Huang53440262010-10-18 17:12:29 -0700959 writel(intr, bfa->iocfc.bfa_regs.intr_status);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800960 bfa_ioc_error_isr(&bfa->ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700961 }
962}
963
Jing Huang5fbe25c2010-10-18 17:17:23 -0700964/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700965 * BFA IOC FC related functions
966 */
967
Jing Huang5fbe25c2010-10-18 17:17:23 -0700968/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -0800969 * BFA IOC private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700970 */
971
Jing Huang5fbe25c2010-10-18 17:17:23 -0700972/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700973 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
974 */
975static void
976bfa_iocfc_send_cfg(void *bfa_arg)
977{
978 struct bfa_s *bfa = bfa_arg;
979 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
980 struct bfi_iocfc_cfg_req_s cfg_req;
981 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
982 struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
983 int i;
984
Jing Huangd4b671c2010-12-26 21:46:35 -0800985 WARN_ON(cfg->fwcfg.num_cqs > BFI_IOC_MAX_CQS);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700986 bfa_trc(bfa, cfg->fwcfg.num_cqs);
987
988 bfa_iocfc_reset_queues(bfa);
989
Jing Huang5fbe25c2010-10-18 17:17:23 -0700990 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991 * initialize IOC configuration info
992 */
Krishna Gudipati10a07372011-06-24 20:23:38 -0700993 cfg_info->single_msix_vec = 0;
994 if (bfa->msix.nvecs == 1)
995 cfg_info->single_msix_vec = 1;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700996 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
997 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
Krishna Gudipati7ace27a2012-09-21 17:26:41 -0700998 cfg_info->num_ioim_reqs = cpu_to_be16(bfa_fcpim_get_throttle_cfg(bfa,
999 cfg->fwcfg.num_ioim_reqs));
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001000 cfg_info->num_fwtio_reqs = cpu_to_be16(cfg->fwcfg.num_fwtio_reqs);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001001
1002 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
Jing Huang5fbe25c2010-10-18 17:17:23 -07001003 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001004 * dma map REQ and RSP circular queues and shadow pointers
1005 */
1006 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
1007 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
1008 iocfc->req_cq_ba[i].pa);
1009 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
1010 iocfc->req_cq_shadow_ci[i].pa);
1011 cfg_info->req_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -07001012 cpu_to_be16(cfg->drvcfg.num_reqq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001013
1014 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
1015 iocfc->rsp_cq_ba[i].pa);
1016 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
1017 iocfc->rsp_cq_shadow_pi[i].pa);
1018 cfg_info->rsp_cq_elems[i] =
Jing Huangba816ea2010-10-18 17:10:50 -07001019 cpu_to_be16(cfg->drvcfg.num_rspq_elems);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001020 }
1021
Jing Huang5fbe25c2010-10-18 17:17:23 -07001022 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001023 * Enable interrupt coalescing if it is driver init path
1024 * and not ioc disable/enable path.
1025 */
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001026 if (bfa_fsm_cmp_state(iocfc, bfa_iocfc_sm_init_cfg_wait))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001027 cfg_info->intr_attr.coalesce = BFA_TRUE;
1028
Jing Huang5fbe25c2010-10-18 17:17:23 -07001029 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001030 * dma map IOC configuration itself
1031 */
1032 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001033 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001034 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
1035
1036 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
1037 sizeof(struct bfi_iocfc_cfg_req_s));
1038}
1039
1040static void
1041bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1042 struct bfa_pcidev_s *pcidev)
1043{
1044 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1045
1046 bfa->bfad = bfad;
1047 iocfc->bfa = bfa;
Jing Huang6a18b162010-10-18 17:08:54 -07001048 iocfc->cfg = *cfg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001049
Jing Huang5fbe25c2010-10-18 17:17:23 -07001050 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001051 * Initialize chip specific handlers.
1052 */
Krishna Gudipati11189202011-06-13 15:50:35 -07001053 if (bfa_asic_id_ctc(bfa_ioc_devid(&bfa->ioc))) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001054 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
1055 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
1056 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
1057 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -07001058 iocfc->hwif.hw_msix_ctrl_install = bfa_hwct_msix_ctrl_install;
1059 iocfc->hwif.hw_msix_queue_install = bfa_hwct_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001060 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
1061 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
1062 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
1063 iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -07001064 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CT;
1065 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CT;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001066 } else {
1067 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001068 iocfc->hwif.hw_reqq_ack = NULL;
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -07001069 iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001070 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
Krishna Gudipati775c7742011-06-13 15:52:12 -07001071 iocfc->hwif.hw_msix_ctrl_install = bfa_hwcb_msix_ctrl_install;
1072 iocfc->hwif.hw_msix_queue_install = bfa_hwcb_msix_queue_install;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001073 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
1074 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
1075 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
1076 iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
Krishna Gudipati11189202011-06-13 15:50:35 -07001077 iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CB +
1078 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
1079 iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CB +
1080 bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
1081 }
1082
1083 if (bfa_asic_id_ct2(bfa_ioc_devid(&bfa->ioc))) {
1084 iocfc->hwif.hw_reginit = bfa_hwct2_reginit;
1085 iocfc->hwif.hw_isr_mode_set = NULL;
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -07001086 iocfc->hwif.hw_rspq_ack = bfa_hwct2_rspq_ack;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001087 }
1088
1089 iocfc->hwif.hw_reginit(bfa);
1090 bfa->msix.nvecs = 0;
1091}
1092
1093static void
Krishna Gudipati45070252011-06-24 20:24:29 -07001094bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001095{
Krishna Gudipati45070252011-06-24 20:24:29 -07001096 u8 *dm_kva = NULL;
1097 u64 dm_pa = 0;
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001098 int i, per_reqq_sz, per_rspq_sz;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001099 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
Krishna Gudipati45070252011-06-24 20:24:29 -07001100 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
1101 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
1102 struct bfa_mem_dma_s *reqq_dma, *rspq_dma;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001103
Krishna Gudipati45070252011-06-24 20:24:29 -07001104 /* First allocate dma memory for IOC */
1105 bfa_ioc_mem_claim(&bfa->ioc, bfa_mem_dma_virt(ioc_dma),
1106 bfa_mem_dma_phys(ioc_dma));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001107
Krishna Gudipati45070252011-06-24 20:24:29 -07001108 /* Claim DMA-able memory for the request/response queues */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001109 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -07001110 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001111 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
Krishna Gudipati45070252011-06-24 20:24:29 -07001112 BFA_DMA_ALIGN_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001113
1114 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
Krishna Gudipati45070252011-06-24 20:24:29 -07001115 reqq_dma = BFA_MEM_REQQ_DMA(bfa, i);
1116 iocfc->req_cq_ba[i].kva = bfa_mem_dma_virt(reqq_dma);
1117 iocfc->req_cq_ba[i].pa = bfa_mem_dma_phys(reqq_dma);
1118 memset(iocfc->req_cq_ba[i].kva, 0, per_reqq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001119
Krishna Gudipati45070252011-06-24 20:24:29 -07001120 rspq_dma = BFA_MEM_RSPQ_DMA(bfa, i);
1121 iocfc->rsp_cq_ba[i].kva = bfa_mem_dma_virt(rspq_dma);
1122 iocfc->rsp_cq_ba[i].pa = bfa_mem_dma_phys(rspq_dma);
1123 memset(iocfc->rsp_cq_ba[i].kva, 0, per_rspq_sz);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001124 }
1125
Krishna Gudipati45070252011-06-24 20:24:29 -07001126 /* Claim IOCFC dma memory - for shadow CI/PI */
1127 dm_kva = bfa_mem_dma_virt(iocfc_dma);
1128 dm_pa = bfa_mem_dma_phys(iocfc_dma);
1129
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001130 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
1131 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
1132 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
1133 dm_kva += BFA_CACHELINE_SZ;
1134 dm_pa += BFA_CACHELINE_SZ;
1135
1136 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
1137 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
1138 dm_kva += BFA_CACHELINE_SZ;
1139 dm_pa += BFA_CACHELINE_SZ;
1140 }
1141
Krishna Gudipati45070252011-06-24 20:24:29 -07001142 /* Claim IOCFC dma memory - for the config info page */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001143 bfa->iocfc.cfg_info.kva = dm_kva;
1144 bfa->iocfc.cfg_info.pa = dm_pa;
1145 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
1146 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1147 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1148
Krishna Gudipati45070252011-06-24 20:24:29 -07001149 /* Claim IOCFC dma memory - for the config response */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001150 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
1151 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
1152 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
Krishna Gudipati45070252011-06-24 20:24:29 -07001153 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
1154 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001155 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
Krishna Gudipati45070252011-06-24 20:24:29 -07001156 BFA_CACHELINE_SZ);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157
Krishna Gudipati45070252011-06-24 20:24:29 -07001158 /* Claim IOCFC kva memory */
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001159 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_mem_kva_curp(iocfc));
1160 bfa_mem_kva_curp(iocfc) += BFA_DBG_FWTRC_LEN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001161}
1162
Jing Huang5fbe25c2010-10-18 17:17:23 -07001163/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001164 * Start BFA submodules.
1165 */
1166static void
1167bfa_iocfc_start_submod(struct bfa_s *bfa)
1168{
1169 int i;
1170
Krishna Gudipati775c7742011-06-13 15:52:12 -07001171 bfa->queue_process = BFA_TRUE;
Krishna Gudipati11189202011-06-13 15:50:35 -07001172 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
Krishna Gudipatica6e0ea2011-07-20 17:00:45 -07001173 bfa_isr_rspq_ack(bfa, i, bfa_rspq_ci(bfa, i));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001174
1175 for (i = 0; hal_mods[i]; i++)
1176 hal_mods[i]->start(bfa);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001177
1178 bfa->iocfc.submod_enabled = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001179}
1180
Jing Huang5fbe25c2010-10-18 17:17:23 -07001181/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001182 * Disable BFA submodules.
1183 */
1184static void
1185bfa_iocfc_disable_submod(struct bfa_s *bfa)
1186{
1187 int i;
1188
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001189 if (bfa->iocfc.submod_enabled == BFA_FALSE)
1190 return;
1191
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001192 for (i = 0; hal_mods[i]; i++)
1193 hal_mods[i]->iocdisable(bfa);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001194
1195 bfa->iocfc.submod_enabled = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001196}
1197
1198static void
1199bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
1200{
1201 struct bfa_s *bfa = bfa_arg;
1202
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001203 if (complete)
1204 bfa_cb_init(bfa->bfad, bfa->iocfc.op_status);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001205}
1206
1207static void
1208bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
1209{
1210 struct bfa_s *bfa = bfa_arg;
1211 struct bfad_s *bfad = bfa->bfad;
1212
1213 if (compl)
1214 complete(&bfad->comp);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001215}
1216
1217static void
Krishna Gudipati60138062011-06-24 20:25:15 -07001218bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl)
1219{
1220 struct bfa_s *bfa = bfa_arg;
1221 struct bfad_s *bfad = bfa->bfad;
1222
1223 if (compl)
1224 complete(&bfad->enable_comp);
1225}
1226
1227static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001228bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
1229{
1230 struct bfa_s *bfa = bfa_arg;
1231 struct bfad_s *bfad = bfa->bfad;
1232
1233 if (compl)
1234 complete(&bfad->disable_comp);
1235}
1236
Krishna Gudipati11189202011-06-13 15:50:35 -07001237/**
1238 * configure queue registers from firmware response
1239 */
1240static void
1241bfa_iocfc_qreg(struct bfa_s *bfa, struct bfi_iocfc_qreg_s *qreg)
1242{
1243 int i;
1244 struct bfa_iocfc_regs_s *r = &bfa->iocfc.bfa_regs;
1245 void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
1246
1247 for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001248 bfa->iocfc.hw_qid[i] = qreg->hw_qid[i];
Krishna Gudipati11189202011-06-13 15:50:35 -07001249 r->cpe_q_ci[i] = kva + be32_to_cpu(qreg->cpe_q_ci_off[i]);
1250 r->cpe_q_pi[i] = kva + be32_to_cpu(qreg->cpe_q_pi_off[i]);
1251 r->cpe_q_ctrl[i] = kva + be32_to_cpu(qreg->cpe_qctl_off[i]);
1252 r->rme_q_ci[i] = kva + be32_to_cpu(qreg->rme_q_ci_off[i]);
1253 r->rme_q_pi[i] = kva + be32_to_cpu(qreg->rme_q_pi_off[i]);
1254 r->rme_q_ctrl[i] = kva + be32_to_cpu(qreg->rme_qctl_off[i]);
1255 }
1256}
1257
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001258static void
1259bfa_iocfc_res_recfg(struct bfa_s *bfa, struct bfa_iocfc_fwcfg_s *fwcfg)
1260{
Krishna Gudipati7ace27a2012-09-21 17:26:41 -07001261 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1262 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
1263
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001264 bfa_fcxp_res_recfg(bfa, fwcfg->num_fcxp_reqs);
1265 bfa_uf_res_recfg(bfa, fwcfg->num_uf_bufs);
1266 bfa_rport_res_recfg(bfa, fwcfg->num_rports);
Krishna Gudipati7ace27a2012-09-21 17:26:41 -07001267 bfa_fcp_res_recfg(bfa, cpu_to_be16(cfg_info->num_ioim_reqs),
1268 fwcfg->num_ioim_reqs);
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001269 bfa_tskim_res_recfg(bfa, fwcfg->num_tskim_reqs);
1270}
1271
Jing Huang5fbe25c2010-10-18 17:17:23 -07001272/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001273 * Update BFA configuration from firmware configuration.
1274 */
1275static void
1276bfa_iocfc_cfgrsp(struct bfa_s *bfa)
1277{
1278 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1279 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1280 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
1281
1282 fwcfg->num_cqs = fwcfg->num_cqs;
Jing Huangba816ea2010-10-18 17:10:50 -07001283 fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001284 fwcfg->num_fwtio_reqs = be16_to_cpu(fwcfg->num_fwtio_reqs);
Jing Huangba816ea2010-10-18 17:10:50 -07001285 fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
1286 fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
1287 fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
1288 fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001289
Jing Huang5fbe25c2010-10-18 17:17:23 -07001290 /*
Krishna Gudipati11189202011-06-13 15:50:35 -07001291 * configure queue register offsets as learnt from firmware
1292 */
1293 bfa_iocfc_qreg(bfa, &cfgrsp->qreg);
1294
1295 /*
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001296 * Re-configure resources as learnt from Firmware
1297 */
1298 bfa_iocfc_res_recfg(bfa, fwcfg);
1299
1300 /*
Krishna Gudipati775c7742011-06-13 15:52:12 -07001301 * Install MSIX queue handlers
1302 */
1303 bfa_msix_queue_install(bfa);
1304
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001305 if (bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn != 0) {
1306 bfa->ioc.attr->pwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn;
1307 bfa->ioc.attr->nwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_nwwn;
1308 bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
Krishna Gudipati60138062011-06-24 20:25:15 -07001309 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001310}
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001311
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001312void
1313bfa_iocfc_reset_queues(struct bfa_s *bfa)
1314{
1315 int q;
1316
1317 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
1318 bfa_reqq_ci(bfa, q) = 0;
1319 bfa_reqq_pi(bfa, q) = 0;
1320 bfa_rspq_ci(bfa, q) = 0;
1321 bfa_rspq_pi(bfa, q) = 0;
1322 }
1323}
1324
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001325/*
1326 * Process FAA pwwn msg from fw.
1327 */
1328static void
1329bfa_iocfc_process_faa_addr(struct bfa_s *bfa, struct bfi_faa_addr_msg_s *msg)
1330{
1331 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1332 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1333
1334 cfgrsp->pbc_cfg.pbc_pwwn = msg->pwwn;
1335 cfgrsp->pbc_cfg.pbc_nwwn = msg->nwwn;
1336
1337 bfa->ioc.attr->pwwn = msg->pwwn;
1338 bfa->ioc.attr->nwwn = msg->nwwn;
1339 bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
1340}
1341
Krishna Gudipatia7141342011-06-24 20:23:19 -07001342/* Fabric Assigned Address specific functions */
1343
1344/*
1345 * Check whether IOC is ready before sending command down
1346 */
1347static bfa_status_t
1348bfa_faa_validate_request(struct bfa_s *bfa)
1349{
1350 enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
1351 u32 card_type = bfa->ioc.attr->card_type;
1352
1353 if (bfa_ioc_is_operational(&bfa->ioc)) {
1354 if ((ioc_type != BFA_IOC_TYPE_FC) || bfa_mfg_is_mezz(card_type))
1355 return BFA_STATUS_FEATURE_NOT_SUPPORTED;
1356 } else {
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001357 return BFA_STATUS_IOC_NON_OP;
Krishna Gudipatia7141342011-06-24 20:23:19 -07001358 }
1359
1360 return BFA_STATUS_OK;
1361}
1362
1363bfa_status_t
Krishna Gudipatia7141342011-06-24 20:23:19 -07001364bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
1365 bfa_cb_iocfc_t cbfn, void *cbarg)
1366{
1367 struct bfi_faa_query_s faa_attr_req;
1368 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1369 bfa_status_t status;
1370
Krishna Gudipatia7141342011-06-24 20:23:19 -07001371 status = bfa_faa_validate_request(bfa);
1372 if (status != BFA_STATUS_OK)
1373 return status;
1374
1375 if (iocfc->faa_args.busy == BFA_TRUE)
1376 return BFA_STATUS_DEVBUSY;
1377
Vijaya Mohan Guvva7593e522013-11-21 01:37:46 -08001378 iocfc->faa_args.faa_attr = attr;
1379 iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
1380 iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
1381
Krishna Gudipatia7141342011-06-24 20:23:19 -07001382 iocfc->faa_args.busy = BFA_TRUE;
1383 memset(&faa_attr_req, 0, sizeof(struct bfi_faa_query_s));
1384 bfi_h2i_set(faa_attr_req.mh, BFI_MC_IOCFC,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001385 BFI_IOCFC_H2I_FAA_QUERY_REQ, bfa_fn_lpu(bfa));
Krishna Gudipatia7141342011-06-24 20:23:19 -07001386
1387 bfa_ioc_mbox_send(&bfa->ioc, &faa_attr_req,
1388 sizeof(struct bfi_faa_query_s));
1389
1390 return BFA_STATUS_OK;
1391}
1392
1393/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07001394 * FAA query response
1395 */
1396static void
1397bfa_faa_query_reply(struct bfa_iocfc_s *iocfc,
1398 bfi_faa_query_rsp_t *rsp)
1399{
1400 void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
1401
1402 if (iocfc->faa_args.faa_attr) {
1403 iocfc->faa_args.faa_attr->faa = rsp->faa;
1404 iocfc->faa_args.faa_attr->faa_state = rsp->faa_status;
1405 iocfc->faa_args.faa_attr->pwwn_source = rsp->addr_source;
1406 }
1407
1408 WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
1409
1410 iocfc->faa_args.faa_cb.faa_cbfn(cbarg, BFA_STATUS_OK);
1411 iocfc->faa_args.busy = BFA_FALSE;
1412}
1413
Jing Huang5fbe25c2010-10-18 17:17:23 -07001414/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001415 * IOC enable request is complete
1416 */
1417static void
1418bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
1419{
1420 struct bfa_s *bfa = bfa_arg;
1421
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001422 if (status == BFA_STATUS_OK)
1423 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_ENABLED);
1424 else
1425 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001426}
1427
Jing Huang5fbe25c2010-10-18 17:17:23 -07001428/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001429 * IOC disable request is complete
1430 */
1431static void
1432bfa_iocfc_disable_cbfn(void *bfa_arg)
1433{
1434 struct bfa_s *bfa = bfa_arg;
1435
Vijaya Mohan Guvvaea3837a2013-05-13 02:33:30 -07001436 bfa->queue_process = BFA_FALSE;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001437 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001438}
1439
Jing Huang5fbe25c2010-10-18 17:17:23 -07001440/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001441 * Notify sub-modules of hardware failure.
1442 */
1443static void
1444bfa_iocfc_hbfail_cbfn(void *bfa_arg)
1445{
1446 struct bfa_s *bfa = bfa_arg;
1447
Krishna Gudipati775c7742011-06-13 15:52:12 -07001448 bfa->queue_process = BFA_FALSE;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001449 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001450}
1451
Jing Huang5fbe25c2010-10-18 17:17:23 -07001452/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001453 * Actions on chip-reset completion.
1454 */
1455static void
1456bfa_iocfc_reset_cbfn(void *bfa_arg)
1457{
1458 struct bfa_s *bfa = bfa_arg;
1459
1460 bfa_iocfc_reset_queues(bfa);
1461 bfa_isr_enable(bfa);
1462}
1463
Jing Huang5fbe25c2010-10-18 17:17:23 -07001464/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001465 * Query IOC memory requirement information.
1466 */
1467void
Krishna Gudipati45070252011-06-24 20:24:29 -07001468bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1469 struct bfa_s *bfa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001470{
Krishna Gudipati45070252011-06-24 20:24:29 -07001471 int q, per_reqq_sz, per_rspq_sz;
1472 struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
1473 struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
1474 struct bfa_mem_kva_s *iocfc_kva = BFA_MEM_IOCFC_KVA(bfa);
1475 u32 dm_len = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001476
Krishna Gudipati45070252011-06-24 20:24:29 -07001477 /* dma memory setup for IOC */
1478 bfa_mem_dma_setup(meminfo, ioc_dma,
1479 BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ));
1480
1481 /* dma memory setup for REQ/RSP queues */
1482 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
1483 BFA_DMA_ALIGN_SZ);
1484 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
1485 BFA_DMA_ALIGN_SZ);
1486
1487 for (q = 0; q < cfg->fwcfg.num_cqs; q++) {
1488 bfa_mem_dma_setup(meminfo, BFA_MEM_REQQ_DMA(bfa, q),
1489 per_reqq_sz);
1490 bfa_mem_dma_setup(meminfo, BFA_MEM_RSPQ_DMA(bfa, q),
1491 per_rspq_sz);
1492 }
1493
1494 /* IOCFC dma memory - calculate Shadow CI/PI size */
1495 for (q = 0; q < cfg->fwcfg.num_cqs; q++)
1496 dm_len += (2 * BFA_CACHELINE_SZ);
1497
1498 /* IOCFC dma memory - calculate config info / rsp size */
1499 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
1500 dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
1501 BFA_CACHELINE_SZ);
1502
1503 /* dma memory setup for IOCFC */
1504 bfa_mem_dma_setup(meminfo, iocfc_dma, dm_len);
1505
1506 /* kva memory setup for IOCFC */
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001507 bfa_mem_kva_setup(meminfo, iocfc_kva, BFA_DBG_FWTRC_LEN);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001508}
1509
Jing Huang5fbe25c2010-10-18 17:17:23 -07001510/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001511 * Query IOC memory requirement information.
1512 */
1513void
1514bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
Krishna Gudipati45070252011-06-24 20:24:29 -07001515 struct bfa_pcidev_s *pcidev)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001516{
1517 int i;
1518 struct bfa_ioc_s *ioc = &bfa->ioc;
1519
1520 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
1521 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
1522 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
1523 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
1524
1525 ioc->trcmod = bfa->trcmod;
1526 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
1527
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001528 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_PCIFN_CLASS_FC);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001529 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
1530
1531 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
Krishna Gudipati45070252011-06-24 20:24:29 -07001532 bfa_iocfc_mem_claim(bfa, cfg);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001533 INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001534
1535 INIT_LIST_HEAD(&bfa->comp_q);
1536 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
1537 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001538
1539 bfa->iocfc.cb_reqd = BFA_FALSE;
1540 bfa->iocfc.op_status = BFA_STATUS_OK;
1541 bfa->iocfc.submod_enabled = BFA_FALSE;
1542
1543 bfa_fsm_set_state(&bfa->iocfc, bfa_iocfc_sm_stopped);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001544}
1545
Jing Huang5fbe25c2010-10-18 17:17:23 -07001546/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001547 * Query IOC memory requirement information.
1548 */
1549void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001550bfa_iocfc_init(struct bfa_s *bfa)
1551{
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001552 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_INIT);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001553}
1554
Jing Huang5fbe25c2010-10-18 17:17:23 -07001555/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001556 * IOC start called from bfa_start(). Called to start IOC operations
1557 * at driver instantiation for this instance.
1558 */
1559void
1560bfa_iocfc_start(struct bfa_s *bfa)
1561{
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001562 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_START);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001563}
1564
Jing Huang5fbe25c2010-10-18 17:17:23 -07001565/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001566 * IOC stop called from bfa_stop(). Called only when driver is unloaded
1567 * for this instance.
1568 */
1569void
1570bfa_iocfc_stop(struct bfa_s *bfa)
1571{
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001572 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001573}
1574
1575void
1576bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
1577{
1578 struct bfa_s *bfa = bfaarg;
1579 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1580 union bfi_iocfc_i2h_msg_u *msg;
1581
1582 msg = (union bfi_iocfc_i2h_msg_u *) m;
1583 bfa_trc(bfa, msg->mh.msg_id);
1584
1585 switch (msg->mh.msg_id) {
1586 case BFI_IOCFC_I2H_CFG_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001587 bfa_iocfc_cfgrsp(bfa);
1588 break;
1589 case BFI_IOCFC_I2H_UPDATEQ_RSP:
1590 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
1591 break;
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001592 case BFI_IOCFC_I2H_ADDR_MSG:
1593 bfa_iocfc_process_faa_addr(bfa,
1594 (struct bfi_faa_addr_msg_s *)msg);
Krishna Gudipatia7141342011-06-24 20:23:19 -07001595 break;
1596 case BFI_IOCFC_I2H_FAA_QUERY_RSP:
1597 bfa_faa_query_reply(iocfc, (bfi_faa_query_rsp_t *)msg);
1598 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001599 default:
Jing Huangd4b671c2010-12-26 21:46:35 -08001600 WARN_ON(1);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001601 }
1602}
1603
1604void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001605bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
1606{
1607 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1608
1609 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
1610
1611 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
Jing Huangba816ea2010-10-18 17:10:50 -07001612 be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
1613 be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001614
1615 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
Jing Huangba816ea2010-10-18 17:10:50 -07001616 be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
1617 be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001618
1619 attr->config = iocfc->cfg;
1620}
1621
1622bfa_status_t
1623bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
1624{
1625 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1626 struct bfi_iocfc_set_intr_req_s *m;
1627
1628 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
Jing Huangba816ea2010-10-18 17:10:50 -07001629 iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
1630 iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001631
1632 if (!bfa_iocfc_is_operational(bfa))
1633 return BFA_STATUS_OK;
1634
1635 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
1636 if (!m)
1637 return BFA_STATUS_DEVBUSY;
1638
1639 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001640 bfa_fn_lpu(bfa));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001641 m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
1642 m->delay = iocfc->cfginfo->intr_attr.delay;
1643 m->latency = iocfc->cfginfo->intr_attr.latency;
1644
1645 bfa_trc(bfa, attr->delay);
1646 bfa_trc(bfa, attr->latency);
1647
Krishna Gudipati3fd45982011-06-24 20:24:08 -07001648 bfa_reqq_produce(bfa, BFA_REQQ_IOC, m->mh);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001649 return BFA_STATUS_OK;
1650}
1651
1652void
Krishna Gudipati45070252011-06-24 20:24:29 -07001653bfa_iocfc_set_snsbase(struct bfa_s *bfa, int seg_no, u64 snsbase_pa)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001654{
1655 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1656
1657 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
Krishna Gudipati45070252011-06-24 20:24:29 -07001658 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase[seg_no], snsbase_pa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001659}
Jing Huang5fbe25c2010-10-18 17:17:23 -07001660/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001661 * Enable IOC after it is disabled.
1662 */
1663void
1664bfa_iocfc_enable(struct bfa_s *bfa)
1665{
1666 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1667 "IOC Enable");
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001668 bfa->iocfc.cb_reqd = BFA_TRUE;
1669 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_ENABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001670}
1671
1672void
1673bfa_iocfc_disable(struct bfa_s *bfa)
1674{
1675 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
1676 "IOC Disable");
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001677
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001678 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DISABLE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001679}
1680
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001681bfa_boolean_t
1682bfa_iocfc_is_operational(struct bfa_s *bfa)
1683{
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07001684 return bfa_ioc_is_operational(&bfa->ioc) &&
1685 bfa_fsm_cmp_state(&bfa->iocfc, bfa_iocfc_sm_operational);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001686}
1687
Jing Huang5fbe25c2010-10-18 17:17:23 -07001688/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001689 * Return boot target port wwns -- read from boot information in flash.
1690 */
1691void
1692bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
1693{
1694 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1695 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1696 int i;
1697
1698 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
1699 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
1700 *nwwns = cfgrsp->pbc_cfg.nbluns;
1701 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
1702 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
1703
1704 return;
1705 }
1706
1707 *nwwns = cfgrsp->bootwwns.nwwns;
1708 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
1709}
1710
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001711int
1712bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
1713{
1714 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
1715 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
1716
1717 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
1718 return cfgrsp->pbc_cfg.nvports;
1719}
1720
Jing Huang7725ccf2009-09-23 17:46:15 -07001721
Jing Huang5fbe25c2010-10-18 17:17:23 -07001722/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001723 * Use this function query the memory requirement of the BFA library.
1724 * This function needs to be called before bfa_attach() to get the
1725 * memory required of the BFA layer for a given driver configuration.
1726 *
1727 * This call will fail, if the cap is out of range compared to pre-defined
1728 * values within the BFA library
1729 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001730 * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
1731 * its configuration in this structure.
Jing Huang7725ccf2009-09-23 17:46:15 -07001732 * The default values for struct bfa_iocfc_cfg_s can be
1733 * fetched using bfa_cfg_get_default() API.
1734 *
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001735 * If cap's boundary check fails, the library will use
Jing Huang7725ccf2009-09-23 17:46:15 -07001736 * the default bfa_cap_t values (and log a warning msg).
1737 *
1738 * @param[out] meminfo - pointer to bfa_meminfo_t. This content
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001739 * indicates the memory type (see bfa_mem_type_t) and
Jing Huang7725ccf2009-09-23 17:46:15 -07001740 * amount of memory required.
1741 *
1742 * Driver should allocate the memory, populate the
1743 * starting address for each block and provide the same
1744 * structure as input parameter to bfa_attach() call.
1745 *
Krishna Gudipati45070252011-06-24 20:24:29 -07001746 * @param[in] bfa - pointer to the bfa structure, used while fetching the
1747 * dma, kva memory information of the bfa sub-modules.
1748 *
Jing Huang7725ccf2009-09-23 17:46:15 -07001749 * @return void
1750 *
1751 * Special Considerations: @note
1752 */
1753void
Krishna Gudipati45070252011-06-24 20:24:29 -07001754bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
1755 struct bfa_s *bfa)
Jing Huang7725ccf2009-09-23 17:46:15 -07001756{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001757 int i;
Krishna Gudipati45070252011-06-24 20:24:29 -07001758 struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
1759 struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
Krishna Gudipati148d6102011-06-24 20:25:36 -07001760 struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
Krishna Gudipati51e569a2011-06-24 20:26:25 -07001761 struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07001762 struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07001763 struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
Krishna Gudipati3350d982011-06-24 20:28:37 -07001764 struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
Krishna Gudipatie6826c92012-09-21 17:27:14 -07001765 struct bfa_mem_dma_s *fru_dma = BFA_MEM_FRU_DMA(bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001766
Jing Huangd4b671c2010-12-26 21:46:35 -08001767 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001768
Jing Huang6a18b162010-10-18 17:08:54 -07001769 memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07001770
Krishna Gudipati45070252011-06-24 20:24:29 -07001771 /* Initialize the DMA & KVA meminfo queues */
1772 INIT_LIST_HEAD(&meminfo->dma_info.qe);
1773 INIT_LIST_HEAD(&meminfo->kva_info.qe);
1774
1775 bfa_iocfc_meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001776
1777 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001778 hal_mods[i]->meminfo(cfg, meminfo, bfa);
Jing Huang7725ccf2009-09-23 17:46:15 -07001779
Krishna Gudipati45070252011-06-24 20:24:29 -07001780 /* dma info setup */
1781 bfa_mem_dma_setup(meminfo, port_dma, bfa_port_meminfo());
1782 bfa_mem_dma_setup(meminfo, ablk_dma, bfa_ablk_meminfo());
Krishna Gudipati148d6102011-06-24 20:25:36 -07001783 bfa_mem_dma_setup(meminfo, cee_dma, bfa_cee_meminfo());
Krishna Gudipati51e569a2011-06-24 20:26:25 -07001784 bfa_mem_dma_setup(meminfo, sfp_dma, bfa_sfp_meminfo());
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07001785 bfa_mem_dma_setup(meminfo, flash_dma,
1786 bfa_flash_meminfo(cfg->drvcfg.min_cfg));
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07001787 bfa_mem_dma_setup(meminfo, diag_dma, bfa_diag_meminfo());
Krishna Gudipati3350d982011-06-24 20:28:37 -07001788 bfa_mem_dma_setup(meminfo, phy_dma,
1789 bfa_phy_meminfo(cfg->drvcfg.min_cfg));
Krishna Gudipatie6826c92012-09-21 17:27:14 -07001790 bfa_mem_dma_setup(meminfo, fru_dma,
1791 bfa_fru_meminfo(cfg->drvcfg.min_cfg));
Jing Huang7725ccf2009-09-23 17:46:15 -07001792}
1793
Jing Huang5fbe25c2010-10-18 17:17:23 -07001794/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001795 * Use this function to do attach the driver instance with the BFA
1796 * library. This function will not trigger any HW initialization
1797 * process (which will be done in bfa_init() call)
1798 *
1799 * This call will fail, if the cap is out of range compared to
1800 * pre-defined values within the BFA library
1801 *
1802 * @param[out] bfa Pointer to bfa_t.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001803 * @param[in] bfad Opaque handle back to the driver's IOC structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001804 * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001805 * that was used in bfa_cfg_get_meminfo().
1806 * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
1807 * use the bfa_cfg_get_meminfo() call to
1808 * find the memory blocks required, allocate the
1809 * required memory and provide the starting addresses.
1810 * @param[in] pcidev pointer to struct bfa_pcidev_s
Jing Huang7725ccf2009-09-23 17:46:15 -07001811 *
1812 * @return
1813 * void
1814 *
1815 * Special Considerations:
1816 *
1817 * @note
1818 *
1819 */
1820void
1821bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
1822 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
1823{
Krishna Gudipati45070252011-06-24 20:24:29 -07001824 int i;
1825 struct bfa_mem_dma_s *dma_info, *dma_elem;
1826 struct bfa_mem_kva_s *kva_info, *kva_elem;
1827 struct list_head *dm_qe, *km_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001828
1829 bfa->fcs = BFA_FALSE;
1830
Jing Huangd4b671c2010-12-26 21:46:35 -08001831 WARN_ON((cfg == NULL) || (meminfo == NULL));
Jing Huang7725ccf2009-09-23 17:46:15 -07001832
Krishna Gudipati45070252011-06-24 20:24:29 -07001833 /* Initialize memory pointers for iterative allocation */
1834 dma_info = &meminfo->dma_info;
1835 dma_info->kva_curp = dma_info->kva;
1836 dma_info->dma_curp = dma_info->dma;
1837
1838 kva_info = &meminfo->kva_info;
1839 kva_info->kva_curp = kva_info->kva;
1840
1841 list_for_each(dm_qe, &dma_info->qe) {
1842 dma_elem = (struct bfa_mem_dma_s *) dm_qe;
1843 dma_elem->kva_curp = dma_elem->kva;
1844 dma_elem->dma_curp = dma_elem->dma;
Jing Huang7725ccf2009-09-23 17:46:15 -07001845 }
1846
Krishna Gudipati45070252011-06-24 20:24:29 -07001847 list_for_each(km_qe, &kva_info->qe) {
1848 kva_elem = (struct bfa_mem_kva_s *) km_qe;
1849 kva_elem->kva_curp = kva_elem->kva;
1850 }
1851
1852 bfa_iocfc_attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001853
1854 for (i = 0; hal_mods[i]; i++)
Krishna Gudipati45070252011-06-24 20:24:29 -07001855 hal_mods[i]->attach(bfa, bfad, cfg, pcidev);
Jing Huang7725ccf2009-09-23 17:46:15 -07001856
Krishna Gudipati45070252011-06-24 20:24:29 -07001857 bfa_com_port_attach(bfa);
1858 bfa_com_ablk_attach(bfa);
Krishna Gudipati148d6102011-06-24 20:25:36 -07001859 bfa_com_cee_attach(bfa);
Krishna Gudipati51e569a2011-06-24 20:26:25 -07001860 bfa_com_sfp_attach(bfa);
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07001861 bfa_com_flash_attach(bfa, cfg->drvcfg.min_cfg);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07001862 bfa_com_diag_attach(bfa);
Krishna Gudipati3350d982011-06-24 20:28:37 -07001863 bfa_com_phy_attach(bfa, cfg->drvcfg.min_cfg);
Krishna Gudipatie6826c92012-09-21 17:27:14 -07001864 bfa_com_fru_attach(bfa, cfg->drvcfg.min_cfg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001865}
1866
Jing Huang5fbe25c2010-10-18 17:17:23 -07001867/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001868 * Use this function to delete a BFA IOC. IOC should be stopped (by
1869 * calling bfa_stop()) before this function call.
1870 *
1871 * @param[in] bfa - pointer to bfa_t.
1872 *
1873 * @return
1874 * void
1875 *
1876 * Special Considerations:
1877 *
1878 * @note
1879 */
1880void
1881bfa_detach(struct bfa_s *bfa)
1882{
1883 int i;
1884
1885 for (i = 0; hal_mods[i]; i++)
1886 hal_mods[i]->detach(bfa);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001887 bfa_ioc_detach(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001888}
1889
1890void
1891bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
1892{
1893 INIT_LIST_HEAD(comp_q);
1894 list_splice_tail_init(&bfa->comp_q, comp_q);
1895}
1896
1897void
1898bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
1899{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001900 struct list_head *qe;
1901 struct list_head *qen;
1902 struct bfa_cb_qe_s *hcb_qe;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07001903 bfa_cb_cbfn_status_t cbfn;
Jing Huang7725ccf2009-09-23 17:46:15 -07001904
1905 list_for_each_safe(qe, qen, comp_q) {
1906 hcb_qe = (struct bfa_cb_qe_s *) qe;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07001907 if (hcb_qe->pre_rmv) {
1908 /* qe is invalid after return, dequeue before cbfn() */
1909 list_del(qe);
1910 cbfn = (bfa_cb_cbfn_status_t)(hcb_qe->cbfn);
1911 cbfn(hcb_qe->cbarg, hcb_qe->fw_status);
1912 } else
1913 hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001914 }
1915}
1916
1917void
1918bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
1919{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001920 struct list_head *qe;
1921 struct bfa_cb_qe_s *hcb_qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001922
1923 while (!list_empty(comp_q)) {
1924 bfa_q_deq(comp_q, &qe);
1925 hcb_qe = (struct bfa_cb_qe_s *) qe;
Krishna Gudipati37ea0552011-07-20 17:02:11 -07001926 WARN_ON(hcb_qe->pre_rmv);
Jing Huang7725ccf2009-09-23 17:46:15 -07001927 hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
1928 }
1929}
1930
Jing Huang5fbe25c2010-10-18 17:17:23 -07001931/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001932 * Return the list of PCI vendor/device id lists supported by this
1933 * BFA instance.
1934 */
1935void
1936bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
1937{
1938 static struct bfa_pciid_s __pciids[] = {
1939 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
1940 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
1941 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
Jing Huang293f82d2010-07-08 19:45:20 -07001942 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
Jing Huang7725ccf2009-09-23 17:46:15 -07001943 };
1944
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001945 *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001946 *pciids = __pciids;
1947}
1948
Jing Huang5fbe25c2010-10-18 17:17:23 -07001949/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001950 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
1951 * into BFA layer). The OS driver can then turn back and overwrite entries that
1952 * have been configured by the user.
1953 *
1954 * @param[in] cfg - pointer to bfa_ioc_cfg_t
1955 *
1956 * @return
1957 * void
1958 *
1959 * Special Considerations:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001960 * note
Jing Huang7725ccf2009-09-23 17:46:15 -07001961 */
1962void
1963bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
1964{
1965 cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
1966 cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
1967 cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
1968 cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
1969 cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
1970 cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
1971 cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
1972 cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001973 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001974
1975 cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
1976 cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
1977 cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
1978 cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
1979 cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
1980 cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
1981 cfg->drvcfg.ioc_recover = BFA_FALSE;
1982 cfg->drvcfg.delay_comp = BFA_FALSE;
1983
1984}
1985
1986void
1987bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
1988{
1989 bfa_cfg_get_default(cfg);
1990 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
1991 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
1992 cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
1993 cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
1994 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
Krishna Gudipatie2187d72011-06-13 15:53:58 -07001995 cfg->fwcfg.num_fwtio_reqs = 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07001996
1997 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
1998 cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
1999 cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002000 cfg->drvcfg.min_cfg = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002001}