usb: Netlogic: Use CPU_XLR in place of NLM_XLR
[zen-stable.git] / drivers / net / ethernet / brocade / bna / bfa_ioc.c
blobb0307a00a109e06ca876e25d42c44773b51250be
1 /*
2 * Linux network driver for Brocade Converged Network Adapter.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
14 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
19 #include "bfa_ioc.h"
20 #include "bfi_reg.h"
21 #include "bfa_defs.h"
23 /**
24 * IOC local definitions
27 /**
28 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
31 #define bfa_ioc_firmware_lock(__ioc) \
32 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
33 #define bfa_ioc_firmware_unlock(__ioc) \
34 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
35 #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
36 #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
37 #define bfa_ioc_notify_fail(__ioc) \
38 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
39 #define bfa_ioc_sync_start(__ioc) \
40 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
41 #define bfa_ioc_sync_join(__ioc) \
42 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
43 #define bfa_ioc_sync_leave(__ioc) \
44 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
45 #define bfa_ioc_sync_ack(__ioc) \
46 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
47 #define bfa_ioc_sync_complete(__ioc) \
48 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
50 #define bfa_ioc_mbox_cmd_pending(__ioc) \
51 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
52 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
54 static bool bfa_nw_auto_recover = true;
57 * forward declarations
59 static void bfa_ioc_hw_sem_init(struct bfa_ioc *ioc);
60 static void bfa_ioc_hw_sem_get(struct bfa_ioc *ioc);
61 static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc);
62 static void bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force);
63 static void bfa_ioc_poll_fwinit(struct bfa_ioc *ioc);
64 static void bfa_ioc_send_enable(struct bfa_ioc *ioc);
65 static void bfa_ioc_send_disable(struct bfa_ioc *ioc);
66 static void bfa_ioc_send_getattr(struct bfa_ioc *ioc);
67 static void bfa_ioc_hb_monitor(struct bfa_ioc *ioc);
68 static void bfa_ioc_hb_stop(struct bfa_ioc *ioc);
69 static void bfa_ioc_reset(struct bfa_ioc *ioc, bool force);
70 static void bfa_ioc_mbox_poll(struct bfa_ioc *ioc);
71 static void bfa_ioc_mbox_flush(struct bfa_ioc *ioc);
72 static void bfa_ioc_recover(struct bfa_ioc *ioc);
73 static void bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc);
74 static void bfa_ioc_event_notify(struct bfa_ioc *, enum bfa_ioc_event);
75 static void bfa_ioc_disable_comp(struct bfa_ioc *ioc);
76 static void bfa_ioc_lpu_stop(struct bfa_ioc *ioc);
77 static void bfa_ioc_fail_notify(struct bfa_ioc *ioc);
78 static void bfa_ioc_pf_enabled(struct bfa_ioc *ioc);
79 static void bfa_ioc_pf_disabled(struct bfa_ioc *ioc);
80 static void bfa_ioc_pf_failed(struct bfa_ioc *ioc);
81 static void bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc);
82 static void bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc);
83 static void bfa_ioc_boot(struct bfa_ioc *ioc, u32 boot_type,
84 u32 boot_param);
85 static u32 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr);
86 static void bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc,
87 char *serial_num);
88 static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc,
89 char *fw_ver);
90 static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc,
91 char *chip_rev);
92 static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc,
93 char *optrom_ver);
94 static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc,
95 char *manufacturer);
96 static void bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model);
97 static u64 bfa_ioc_get_pwwn(struct bfa_ioc *ioc);
99 /**
100 * IOC state machine definitions/declarations
102 enum ioc_event {
103 IOC_E_RESET = 1, /*!< IOC reset request */
104 IOC_E_ENABLE = 2, /*!< IOC enable request */
105 IOC_E_DISABLE = 3, /*!< IOC disable request */
106 IOC_E_DETACH = 4, /*!< driver detach cleanup */
107 IOC_E_ENABLED = 5, /*!< f/w enabled */
108 IOC_E_FWRSP_GETATTR = 6, /*!< IOC get attribute response */
109 IOC_E_DISABLED = 7, /*!< f/w disabled */
110 IOC_E_PFFAILED = 8, /*!< failure notice by iocpf sm */
111 IOC_E_HBFAIL = 9, /*!< heartbeat failure */
112 IOC_E_HWERROR = 10, /*!< hardware error interrupt */
113 IOC_E_TIMEOUT = 11, /*!< timeout */
114 IOC_E_HWFAILED = 12, /*!< PCI mapping failure notice */
117 bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc, enum ioc_event);
118 bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc, enum ioc_event);
119 bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc, enum ioc_event);
120 bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc, enum ioc_event);
121 bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc, enum ioc_event);
122 bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc, enum ioc_event);
123 bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc, enum ioc_event);
124 bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc, enum ioc_event);
125 bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc, enum ioc_event);
126 bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc, enum ioc_event);
128 static struct bfa_sm_table ioc_sm_table[] = {
129 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
130 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
131 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
132 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
133 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
134 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
135 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
136 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
137 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
138 {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
142 * Forward declareations for iocpf state machine
144 static void bfa_iocpf_enable(struct bfa_ioc *ioc);
145 static void bfa_iocpf_disable(struct bfa_ioc *ioc);
146 static void bfa_iocpf_fail(struct bfa_ioc *ioc);
147 static void bfa_iocpf_initfail(struct bfa_ioc *ioc);
148 static void bfa_iocpf_getattrfail(struct bfa_ioc *ioc);
149 static void bfa_iocpf_stop(struct bfa_ioc *ioc);
152 * IOCPF state machine events
154 enum iocpf_event {
155 IOCPF_E_ENABLE = 1, /*!< IOCPF enable request */
156 IOCPF_E_DISABLE = 2, /*!< IOCPF disable request */
157 IOCPF_E_STOP = 3, /*!< stop on driver detach */
158 IOCPF_E_FWREADY = 4, /*!< f/w initialization done */
159 IOCPF_E_FWRSP_ENABLE = 5, /*!< enable f/w response */
160 IOCPF_E_FWRSP_DISABLE = 6, /*!< disable f/w response */
161 IOCPF_E_FAIL = 7, /*!< failure notice by ioc sm */
162 IOCPF_E_INITFAIL = 8, /*!< init fail notice by ioc sm */
163 IOCPF_E_GETATTRFAIL = 9, /*!< init fail notice by ioc sm */
164 IOCPF_E_SEMLOCKED = 10, /*!< h/w semaphore is locked */
165 IOCPF_E_TIMEOUT = 11, /*!< f/w response timeout */
166 IOCPF_E_SEM_ERROR = 12, /*!< h/w sem mapping error */
170 * IOCPF states
172 enum bfa_iocpf_state {
173 BFA_IOCPF_RESET = 1, /*!< IOC is in reset state */
174 BFA_IOCPF_SEMWAIT = 2, /*!< Waiting for IOC h/w semaphore */
175 BFA_IOCPF_HWINIT = 3, /*!< IOC h/w is being initialized */
176 BFA_IOCPF_READY = 4, /*!< IOCPF is initialized */
177 BFA_IOCPF_INITFAIL = 5, /*!< IOCPF failed */
178 BFA_IOCPF_FAIL = 6, /*!< IOCPF failed */
179 BFA_IOCPF_DISABLING = 7, /*!< IOCPF is being disabled */
180 BFA_IOCPF_DISABLED = 8, /*!< IOCPF is disabled */
181 BFA_IOCPF_FWMISMATCH = 9, /*!< IOC f/w different from drivers */
184 bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf, enum iocpf_event);
185 bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf, enum iocpf_event);
186 bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf, enum iocpf_event);
187 bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf, enum iocpf_event);
188 bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf, enum iocpf_event);
189 bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf, enum iocpf_event);
190 bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf, enum iocpf_event);
191 bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf,
192 enum iocpf_event);
193 bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf, enum iocpf_event);
194 bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf, enum iocpf_event);
195 bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf, enum iocpf_event);
196 bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf, enum iocpf_event);
197 bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf,
198 enum iocpf_event);
199 bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf, enum iocpf_event);
201 static struct bfa_sm_table iocpf_sm_table[] = {
202 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
203 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
204 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
205 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
206 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
207 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
208 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
209 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
210 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
211 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
212 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
213 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
214 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
215 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
219 * IOC State Machine
223 * Beginning state. IOC uninit state.
225 static void
226 bfa_ioc_sm_uninit_entry(struct bfa_ioc *ioc)
231 * IOC is in uninit state.
233 static void
234 bfa_ioc_sm_uninit(struct bfa_ioc *ioc, enum ioc_event event)
236 switch (event) {
237 case IOC_E_RESET:
238 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
239 break;
241 default:
242 bfa_sm_fault(event);
247 * Reset entry actions -- initialize state machine
249 static void
250 bfa_ioc_sm_reset_entry(struct bfa_ioc *ioc)
252 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
256 * IOC is in reset state.
258 static void
259 bfa_ioc_sm_reset(struct bfa_ioc *ioc, enum ioc_event event)
261 switch (event) {
262 case IOC_E_ENABLE:
263 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
264 break;
266 case IOC_E_DISABLE:
267 bfa_ioc_disable_comp(ioc);
268 break;
270 case IOC_E_DETACH:
271 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
272 break;
274 default:
275 bfa_sm_fault(event);
279 static void
280 bfa_ioc_sm_enabling_entry(struct bfa_ioc *ioc)
282 bfa_iocpf_enable(ioc);
286 * Host IOC function is being enabled, awaiting response from firmware.
287 * Semaphore is acquired.
289 static void
290 bfa_ioc_sm_enabling(struct bfa_ioc *ioc, enum ioc_event event)
292 switch (event) {
293 case IOC_E_ENABLED:
294 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
295 break;
297 case IOC_E_PFFAILED:
298 /* !!! fall through !!! */
299 case IOC_E_HWERROR:
300 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
301 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
302 if (event != IOC_E_PFFAILED)
303 bfa_iocpf_initfail(ioc);
304 break;
306 case IOC_E_HWFAILED:
307 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
308 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
309 break;
311 case IOC_E_DISABLE:
312 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
313 break;
315 case IOC_E_DETACH:
316 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
317 bfa_iocpf_stop(ioc);
318 break;
320 case IOC_E_ENABLE:
321 break;
323 default:
324 bfa_sm_fault(event);
329 * Semaphore should be acquired for version check.
331 static void
332 bfa_ioc_sm_getattr_entry(struct bfa_ioc *ioc)
334 mod_timer(&ioc->ioc_timer, jiffies +
335 msecs_to_jiffies(BFA_IOC_TOV));
336 bfa_ioc_send_getattr(ioc);
340 * IOC configuration in progress. Timer is active.
342 static void
343 bfa_ioc_sm_getattr(struct bfa_ioc *ioc, enum ioc_event event)
345 switch (event) {
346 case IOC_E_FWRSP_GETATTR:
347 del_timer(&ioc->ioc_timer);
348 bfa_ioc_check_attr_wwns(ioc);
349 bfa_ioc_hb_monitor(ioc);
350 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
351 break;
353 case IOC_E_PFFAILED:
354 case IOC_E_HWERROR:
355 del_timer(&ioc->ioc_timer);
356 /* fall through */
357 case IOC_E_TIMEOUT:
358 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
359 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
360 if (event != IOC_E_PFFAILED)
361 bfa_iocpf_getattrfail(ioc);
362 break;
364 case IOC_E_DISABLE:
365 del_timer(&ioc->ioc_timer);
366 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
367 break;
369 case IOC_E_ENABLE:
370 break;
372 default:
373 bfa_sm_fault(event);
377 static void
378 bfa_ioc_sm_op_entry(struct bfa_ioc *ioc)
380 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
381 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
384 static void
385 bfa_ioc_sm_op(struct bfa_ioc *ioc, enum ioc_event event)
387 switch (event) {
388 case IOC_E_ENABLE:
389 break;
391 case IOC_E_DISABLE:
392 bfa_ioc_hb_stop(ioc);
393 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
394 break;
396 case IOC_E_PFFAILED:
397 case IOC_E_HWERROR:
398 bfa_ioc_hb_stop(ioc);
399 /* !!! fall through !!! */
400 case IOC_E_HBFAIL:
401 if (ioc->iocpf.auto_recover)
402 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
403 else
404 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
406 bfa_ioc_fail_notify(ioc);
408 if (event != IOC_E_PFFAILED)
409 bfa_iocpf_fail(ioc);
410 break;
412 default:
413 bfa_sm_fault(event);
417 static void
418 bfa_ioc_sm_disabling_entry(struct bfa_ioc *ioc)
420 bfa_iocpf_disable(ioc);
424 * IOC is being disabled
426 static void
427 bfa_ioc_sm_disabling(struct bfa_ioc *ioc, enum ioc_event event)
429 switch (event) {
430 case IOC_E_DISABLED:
431 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
432 break;
434 case IOC_E_HWERROR:
436 * No state change. Will move to disabled state
437 * after iocpf sm completes failure processing and
438 * moves to disabled state.
440 bfa_iocpf_fail(ioc);
441 break;
443 case IOC_E_HWFAILED:
444 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
445 bfa_ioc_disable_comp(ioc);
446 break;
448 default:
449 bfa_sm_fault(event);
454 * IOC disable completion entry.
456 static void
457 bfa_ioc_sm_disabled_entry(struct bfa_ioc *ioc)
459 bfa_ioc_disable_comp(ioc);
462 static void
463 bfa_ioc_sm_disabled(struct bfa_ioc *ioc, enum ioc_event event)
465 switch (event) {
466 case IOC_E_ENABLE:
467 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
468 break;
470 case IOC_E_DISABLE:
471 ioc->cbfn->disable_cbfn(ioc->bfa);
472 break;
474 case IOC_E_DETACH:
475 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
476 bfa_iocpf_stop(ioc);
477 break;
479 default:
480 bfa_sm_fault(event);
484 static void
485 bfa_ioc_sm_fail_retry_entry(struct bfa_ioc *ioc)
490 * Hardware initialization retry.
492 static void
493 bfa_ioc_sm_fail_retry(struct bfa_ioc *ioc, enum ioc_event event)
495 switch (event) {
496 case IOC_E_ENABLED:
497 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
498 break;
500 case IOC_E_PFFAILED:
501 case IOC_E_HWERROR:
503 * Initialization retry failed.
505 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
506 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
507 if (event != IOC_E_PFFAILED)
508 bfa_iocpf_initfail(ioc);
509 break;
511 case IOC_E_HWFAILED:
512 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
513 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
514 break;
516 case IOC_E_ENABLE:
517 break;
519 case IOC_E_DISABLE:
520 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
521 break;
523 case IOC_E_DETACH:
524 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
525 bfa_iocpf_stop(ioc);
526 break;
528 default:
529 bfa_sm_fault(event);
533 static void
534 bfa_ioc_sm_fail_entry(struct bfa_ioc *ioc)
539 * IOC failure.
541 static void
542 bfa_ioc_sm_fail(struct bfa_ioc *ioc, enum ioc_event event)
544 switch (event) {
545 case IOC_E_ENABLE:
546 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
547 break;
549 case IOC_E_DISABLE:
550 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
551 break;
553 case IOC_E_DETACH:
554 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
555 bfa_iocpf_stop(ioc);
556 break;
558 case IOC_E_HWERROR:
559 /* HB failure notification, ignore. */
560 break;
562 default:
563 bfa_sm_fault(event);
567 static void
568 bfa_ioc_sm_hwfail_entry(struct bfa_ioc *ioc)
573 * IOC failure.
575 static void
576 bfa_ioc_sm_hwfail(struct bfa_ioc *ioc, enum ioc_event event)
578 switch (event) {
580 case IOC_E_ENABLE:
581 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
582 break;
584 case IOC_E_DISABLE:
585 ioc->cbfn->disable_cbfn(ioc->bfa);
586 break;
588 case IOC_E_DETACH:
589 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
590 break;
592 default:
593 bfa_sm_fault(event);
598 * IOCPF State Machine
602 * Reset entry actions -- initialize state machine
604 static void
605 bfa_iocpf_sm_reset_entry(struct bfa_iocpf *iocpf)
607 iocpf->fw_mismatch_notified = false;
608 iocpf->auto_recover = bfa_nw_auto_recover;
612 * Beginning state. IOC is in reset state.
614 static void
615 bfa_iocpf_sm_reset(struct bfa_iocpf *iocpf, enum iocpf_event event)
617 switch (event) {
618 case IOCPF_E_ENABLE:
619 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
620 break;
622 case IOCPF_E_STOP:
623 break;
625 default:
626 bfa_sm_fault(event);
631 * Semaphore should be acquired for version check.
633 static void
634 bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf *iocpf)
636 bfa_ioc_hw_sem_init(iocpf->ioc);
637 bfa_ioc_hw_sem_get(iocpf->ioc);
641 * Awaiting h/w semaphore to continue with version check.
643 static void
644 bfa_iocpf_sm_fwcheck(struct bfa_iocpf *iocpf, enum iocpf_event event)
646 struct bfa_ioc *ioc = iocpf->ioc;
648 switch (event) {
649 case IOCPF_E_SEMLOCKED:
650 if (bfa_ioc_firmware_lock(ioc)) {
651 if (bfa_ioc_sync_start(ioc)) {
652 bfa_ioc_sync_join(ioc);
653 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
654 } else {
655 bfa_ioc_firmware_unlock(ioc);
656 bfa_nw_ioc_hw_sem_release(ioc);
657 mod_timer(&ioc->sem_timer, jiffies +
658 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
660 } else {
661 bfa_nw_ioc_hw_sem_release(ioc);
662 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
664 break;
666 case IOCPF_E_SEM_ERROR:
667 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
668 bfa_ioc_pf_hwfailed(ioc);
669 break;
671 case IOCPF_E_DISABLE:
672 bfa_ioc_hw_sem_get_cancel(ioc);
673 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
674 bfa_ioc_pf_disabled(ioc);
675 break;
677 case IOCPF_E_STOP:
678 bfa_ioc_hw_sem_get_cancel(ioc);
679 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
680 break;
682 default:
683 bfa_sm_fault(event);
688 * Notify enable completion callback
690 static void
691 bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf *iocpf)
693 /* Call only the first time sm enters fwmismatch state. */
694 if (iocpf->fw_mismatch_notified == false)
695 bfa_ioc_pf_fwmismatch(iocpf->ioc);
697 iocpf->fw_mismatch_notified = true;
698 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
699 msecs_to_jiffies(BFA_IOC_TOV));
703 * Awaiting firmware version match.
705 static void
706 bfa_iocpf_sm_mismatch(struct bfa_iocpf *iocpf, enum iocpf_event event)
708 struct bfa_ioc *ioc = iocpf->ioc;
710 switch (event) {
711 case IOCPF_E_TIMEOUT:
712 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
713 break;
715 case IOCPF_E_DISABLE:
716 del_timer(&ioc->iocpf_timer);
717 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
718 bfa_ioc_pf_disabled(ioc);
719 break;
721 case IOCPF_E_STOP:
722 del_timer(&ioc->iocpf_timer);
723 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
724 break;
726 default:
727 bfa_sm_fault(event);
732 * Request for semaphore.
734 static void
735 bfa_iocpf_sm_semwait_entry(struct bfa_iocpf *iocpf)
737 bfa_ioc_hw_sem_get(iocpf->ioc);
741 * Awaiting semaphore for h/w initialzation.
743 static void
744 bfa_iocpf_sm_semwait(struct bfa_iocpf *iocpf, enum iocpf_event event)
746 struct bfa_ioc *ioc = iocpf->ioc;
748 switch (event) {
749 case IOCPF_E_SEMLOCKED:
750 if (bfa_ioc_sync_complete(ioc)) {
751 bfa_ioc_sync_join(ioc);
752 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
753 } else {
754 bfa_nw_ioc_hw_sem_release(ioc);
755 mod_timer(&ioc->sem_timer, jiffies +
756 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
758 break;
760 case IOCPF_E_SEM_ERROR:
761 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
762 bfa_ioc_pf_hwfailed(ioc);
763 break;
765 case IOCPF_E_DISABLE:
766 bfa_ioc_hw_sem_get_cancel(ioc);
767 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
768 break;
770 default:
771 bfa_sm_fault(event);
775 static void
776 bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf *iocpf)
778 iocpf->poll_time = 0;
779 bfa_ioc_reset(iocpf->ioc, false);
783 * Hardware is being initialized. Interrupts are enabled.
784 * Holding hardware semaphore lock.
786 static void
787 bfa_iocpf_sm_hwinit(struct bfa_iocpf *iocpf, enum iocpf_event event)
789 struct bfa_ioc *ioc = iocpf->ioc;
791 switch (event) {
792 case IOCPF_E_FWREADY:
793 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
794 break;
796 case IOCPF_E_TIMEOUT:
797 bfa_nw_ioc_hw_sem_release(ioc);
798 bfa_ioc_pf_failed(ioc);
799 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
800 break;
802 case IOCPF_E_DISABLE:
803 del_timer(&ioc->iocpf_timer);
804 bfa_ioc_sync_leave(ioc);
805 bfa_nw_ioc_hw_sem_release(ioc);
806 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
807 break;
809 default:
810 bfa_sm_fault(event);
814 static void
815 bfa_iocpf_sm_enabling_entry(struct bfa_iocpf *iocpf)
817 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
818 msecs_to_jiffies(BFA_IOC_TOV));
820 * Enable Interrupts before sending fw IOC ENABLE cmd.
822 iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
823 bfa_ioc_send_enable(iocpf->ioc);
827 * Host IOC function is being enabled, awaiting response from firmware.
828 * Semaphore is acquired.
830 static void
831 bfa_iocpf_sm_enabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
833 struct bfa_ioc *ioc = iocpf->ioc;
835 switch (event) {
836 case IOCPF_E_FWRSP_ENABLE:
837 del_timer(&ioc->iocpf_timer);
838 bfa_nw_ioc_hw_sem_release(ioc);
839 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
840 break;
842 case IOCPF_E_INITFAIL:
843 del_timer(&ioc->iocpf_timer);
845 * !!! fall through !!!
847 case IOCPF_E_TIMEOUT:
848 bfa_nw_ioc_hw_sem_release(ioc);
849 if (event == IOCPF_E_TIMEOUT)
850 bfa_ioc_pf_failed(ioc);
851 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
852 break;
854 case IOCPF_E_DISABLE:
855 del_timer(&ioc->iocpf_timer);
856 bfa_nw_ioc_hw_sem_release(ioc);
857 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
858 break;
860 default:
861 bfa_sm_fault(event);
865 static void
866 bfa_iocpf_sm_ready_entry(struct bfa_iocpf *iocpf)
868 bfa_ioc_pf_enabled(iocpf->ioc);
871 static void
872 bfa_iocpf_sm_ready(struct bfa_iocpf *iocpf, enum iocpf_event event)
874 switch (event) {
875 case IOCPF_E_DISABLE:
876 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
877 break;
879 case IOCPF_E_GETATTRFAIL:
880 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
881 break;
883 case IOCPF_E_FAIL:
884 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
885 break;
887 default:
888 bfa_sm_fault(event);
892 static void
893 bfa_iocpf_sm_disabling_entry(struct bfa_iocpf *iocpf)
895 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
896 msecs_to_jiffies(BFA_IOC_TOV));
897 bfa_ioc_send_disable(iocpf->ioc);
901 * IOC is being disabled
903 static void
904 bfa_iocpf_sm_disabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
906 struct bfa_ioc *ioc = iocpf->ioc;
908 switch (event) {
909 case IOCPF_E_FWRSP_DISABLE:
910 del_timer(&ioc->iocpf_timer);
911 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
912 break;
914 case IOCPF_E_FAIL:
915 del_timer(&ioc->iocpf_timer);
917 * !!! fall through !!!
920 case IOCPF_E_TIMEOUT:
921 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
922 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
923 break;
925 case IOCPF_E_FWRSP_ENABLE:
926 break;
928 default:
929 bfa_sm_fault(event);
933 static void
934 bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf *iocpf)
936 bfa_ioc_hw_sem_get(iocpf->ioc);
940 * IOC hb ack request is being removed.
942 static void
943 bfa_iocpf_sm_disabling_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
945 struct bfa_ioc *ioc = iocpf->ioc;
947 switch (event) {
948 case IOCPF_E_SEMLOCKED:
949 bfa_ioc_sync_leave(ioc);
950 bfa_nw_ioc_hw_sem_release(ioc);
951 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
952 break;
954 case IOCPF_E_SEM_ERROR:
955 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
956 bfa_ioc_pf_hwfailed(ioc);
957 break;
959 case IOCPF_E_FAIL:
960 break;
962 default:
963 bfa_sm_fault(event);
968 * IOC disable completion entry.
970 static void
971 bfa_iocpf_sm_disabled_entry(struct bfa_iocpf *iocpf)
973 bfa_ioc_mbox_flush(iocpf->ioc);
974 bfa_ioc_pf_disabled(iocpf->ioc);
977 static void
978 bfa_iocpf_sm_disabled(struct bfa_iocpf *iocpf, enum iocpf_event event)
980 struct bfa_ioc *ioc = iocpf->ioc;
982 switch (event) {
983 case IOCPF_E_ENABLE:
984 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
985 break;
987 case IOCPF_E_STOP:
988 bfa_ioc_firmware_unlock(ioc);
989 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
990 break;
992 default:
993 bfa_sm_fault(event);
997 static void
998 bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf *iocpf)
1000 bfa_ioc_hw_sem_get(iocpf->ioc);
1004 * Hardware initialization failed.
1006 static void
1007 bfa_iocpf_sm_initfail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
1009 struct bfa_ioc *ioc = iocpf->ioc;
1011 switch (event) {
1012 case IOCPF_E_SEMLOCKED:
1013 bfa_ioc_notify_fail(ioc);
1014 bfa_ioc_sync_leave(ioc);
1015 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1016 bfa_nw_ioc_hw_sem_release(ioc);
1017 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
1018 break;
1020 case IOCPF_E_SEM_ERROR:
1021 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1022 bfa_ioc_pf_hwfailed(ioc);
1023 break;
1025 case IOCPF_E_DISABLE:
1026 bfa_ioc_hw_sem_get_cancel(ioc);
1027 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1028 break;
1030 case IOCPF_E_STOP:
1031 bfa_ioc_hw_sem_get_cancel(ioc);
1032 bfa_ioc_firmware_unlock(ioc);
1033 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1034 break;
1036 case IOCPF_E_FAIL:
1037 break;
1039 default:
1040 bfa_sm_fault(event);
1044 static void
1045 bfa_iocpf_sm_initfail_entry(struct bfa_iocpf *iocpf)
1050 * Hardware initialization failed.
1052 static void
1053 bfa_iocpf_sm_initfail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1055 struct bfa_ioc *ioc = iocpf->ioc;
1057 switch (event) {
1058 case IOCPF_E_DISABLE:
1059 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1060 break;
1062 case IOCPF_E_STOP:
1063 bfa_ioc_firmware_unlock(ioc);
1064 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1065 break;
1067 default:
1068 bfa_sm_fault(event);
1072 static void
1073 bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf *iocpf)
1076 * Mark IOC as failed in hardware and stop firmware.
1078 bfa_ioc_lpu_stop(iocpf->ioc);
1081 * Flush any queued up mailbox requests.
1083 bfa_ioc_mbox_flush(iocpf->ioc);
1084 bfa_ioc_hw_sem_get(iocpf->ioc);
1088 * IOC is in failed state.
1090 static void
1091 bfa_iocpf_sm_fail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
1093 struct bfa_ioc *ioc = iocpf->ioc;
1095 switch (event) {
1096 case IOCPF_E_SEMLOCKED:
1097 bfa_ioc_sync_ack(ioc);
1098 bfa_ioc_notify_fail(ioc);
1099 if (!iocpf->auto_recover) {
1100 bfa_ioc_sync_leave(ioc);
1101 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1102 bfa_nw_ioc_hw_sem_release(ioc);
1103 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1104 } else {
1105 if (bfa_ioc_sync_complete(ioc))
1106 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1107 else {
1108 bfa_nw_ioc_hw_sem_release(ioc);
1109 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1112 break;
1114 case IOCPF_E_SEM_ERROR:
1115 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1116 bfa_ioc_pf_hwfailed(ioc);
1117 break;
1119 case IOCPF_E_DISABLE:
1120 bfa_ioc_hw_sem_get_cancel(ioc);
1121 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1122 break;
1124 case IOCPF_E_FAIL:
1125 break;
1127 default:
1128 bfa_sm_fault(event);
1132 static void
1133 bfa_iocpf_sm_fail_entry(struct bfa_iocpf *iocpf)
1138 * @brief
1139 * IOC is in failed state.
1141 static void
1142 bfa_iocpf_sm_fail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1144 switch (event) {
1145 case IOCPF_E_DISABLE:
1146 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1147 break;
1149 default:
1150 bfa_sm_fault(event);
1155 * BFA IOC private functions
1159 * Notify common modules registered for notification.
1161 static void
1162 bfa_ioc_event_notify(struct bfa_ioc *ioc, enum bfa_ioc_event event)
1164 struct bfa_ioc_notify *notify;
1165 struct list_head *qe;
1167 list_for_each(qe, &ioc->notify_q) {
1168 notify = (struct bfa_ioc_notify *)qe;
1169 notify->cbfn(notify->cbarg, event);
1173 static void
1174 bfa_ioc_disable_comp(struct bfa_ioc *ioc)
1176 ioc->cbfn->disable_cbfn(ioc->bfa);
1177 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
1180 bool
1181 bfa_nw_ioc_sem_get(void __iomem *sem_reg)
1183 u32 r32;
1184 int cnt = 0;
1185 #define BFA_SEM_SPINCNT 3000
1187 r32 = readl(sem_reg);
1189 while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
1190 cnt++;
1191 udelay(2);
1192 r32 = readl(sem_reg);
1195 if (!(r32 & 1))
1196 return true;
1198 return false;
1201 void
1202 bfa_nw_ioc_sem_release(void __iomem *sem_reg)
1204 readl(sem_reg);
1205 writel(1, sem_reg);
1208 static void
1209 bfa_ioc_hw_sem_init(struct bfa_ioc *ioc)
1211 struct bfi_ioc_image_hdr fwhdr;
1212 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1214 if (fwstate == BFI_IOC_UNINIT)
1215 return;
1217 bfa_nw_ioc_fwver_get(ioc, &fwhdr);
1219 if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL)
1220 return;
1222 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
1225 * Try to lock and then unlock the semaphore.
1227 readl(ioc->ioc_regs.ioc_sem_reg);
1228 writel(1, ioc->ioc_regs.ioc_sem_reg);
1231 static void
1232 bfa_ioc_hw_sem_get(struct bfa_ioc *ioc)
1234 u32 r32;
1237 * First read to the semaphore register will return 0, subsequent reads
1238 * will return 1. Semaphore is released by writing 1 to the register
1240 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
1241 if (r32 == ~0) {
1242 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
1243 return;
1245 if (!(r32 & 1)) {
1246 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
1247 return;
1250 mod_timer(&ioc->sem_timer, jiffies +
1251 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
1254 void
1255 bfa_nw_ioc_hw_sem_release(struct bfa_ioc *ioc)
1257 writel(1, ioc->ioc_regs.ioc_sem_reg);
1260 static void
1261 bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc)
1263 del_timer(&ioc->sem_timer);
1267 * @brief
1268 * Initialize LPU local memory (aka secondary memory / SRAM)
1270 static void
1271 bfa_ioc_lmem_init(struct bfa_ioc *ioc)
1273 u32 pss_ctl;
1274 int i;
1275 #define PSS_LMEM_INIT_TIME 10000
1277 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1278 pss_ctl &= ~__PSS_LMEM_RESET;
1279 pss_ctl |= __PSS_LMEM_INIT_EN;
1282 * i2c workaround 12.5khz clock
1284 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
1285 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1288 * wait for memory initialization to be complete
1290 i = 0;
1291 do {
1292 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1293 i++;
1294 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1297 * If memory initialization is not successful, IOC timeout will catch
1298 * such failures.
1300 BUG_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
1302 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
1303 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1306 static void
1307 bfa_ioc_lpu_start(struct bfa_ioc *ioc)
1309 u32 pss_ctl;
1312 * Take processor out of reset.
1314 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1315 pss_ctl &= ~__PSS_LPU0_RESET;
1317 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1320 static void
1321 bfa_ioc_lpu_stop(struct bfa_ioc *ioc)
1323 u32 pss_ctl;
1326 * Put processors in reset.
1328 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1329 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1331 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1335 * Get driver and firmware versions.
1337 void
1338 bfa_nw_ioc_fwver_get(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
1340 u32 pgnum;
1341 u32 loff = 0;
1342 int i;
1343 u32 *fwsig = (u32 *) fwhdr;
1345 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1346 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1348 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32));
1349 i++) {
1350 fwsig[i] =
1351 swab32(readl((loff) + (ioc->ioc_regs.smem_page_start)));
1352 loff += sizeof(u32);
1357 * Returns TRUE if same.
1359 bool
1360 bfa_nw_ioc_fwver_cmp(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
1362 struct bfi_ioc_image_hdr *drv_fwhdr;
1363 int i;
1365 drv_fwhdr = (struct bfi_ioc_image_hdr *)
1366 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
1368 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1369 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i])
1370 return false;
1373 return true;
1377 * Return true if current running version is valid. Firmware signature and
1378 * execution context (driver/bios) must match.
1380 static bool
1381 bfa_ioc_fwver_valid(struct bfa_ioc *ioc, u32 boot_env)
1383 struct bfi_ioc_image_hdr fwhdr, *drv_fwhdr;
1385 bfa_nw_ioc_fwver_get(ioc, &fwhdr);
1386 drv_fwhdr = (struct bfi_ioc_image_hdr *)
1387 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
1389 if (fwhdr.signature != drv_fwhdr->signature)
1390 return false;
1392 if (swab32(fwhdr.bootenv) != boot_env)
1393 return false;
1395 return bfa_nw_ioc_fwver_cmp(ioc, &fwhdr);
1399 * Conditionally flush any pending message from firmware at start.
1401 static void
1402 bfa_ioc_msgflush(struct bfa_ioc *ioc)
1404 u32 r32;
1406 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1407 if (r32)
1408 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1412 * @img ioc_init_logic.jpg
1414 static void
1415 bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force)
1417 enum bfi_ioc_state ioc_fwstate;
1418 bool fwvalid;
1419 u32 boot_env;
1421 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1423 if (force)
1424 ioc_fwstate = BFI_IOC_UNINIT;
1426 boot_env = BFI_FWBOOT_ENV_OS;
1429 * check if firmware is valid
1431 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
1432 false : bfa_ioc_fwver_valid(ioc, boot_env);
1434 if (!fwvalid) {
1435 bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env);
1436 bfa_ioc_poll_fwinit(ioc);
1437 return;
1441 * If hardware initialization is in progress (initialized by other IOC),
1442 * just wait for an initialization completion interrupt.
1444 if (ioc_fwstate == BFI_IOC_INITING) {
1445 bfa_ioc_poll_fwinit(ioc);
1446 return;
1450 * If IOC function is disabled and firmware version is same,
1451 * just re-enable IOC.
1453 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
1455 * When using MSI-X any pending firmware ready event should
1456 * be flushed. Otherwise MSI-X interrupts are not delivered.
1458 bfa_ioc_msgflush(ioc);
1459 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
1460 return;
1464 * Initialize the h/w for any other states.
1466 bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env);
1467 bfa_ioc_poll_fwinit(ioc);
1470 void
1471 bfa_nw_ioc_timeout(void *ioc_arg)
1473 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
1475 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1478 static void
1479 bfa_ioc_mbox_send(struct bfa_ioc *ioc, void *ioc_msg, int len)
1481 u32 *msgp = (u32 *) ioc_msg;
1482 u32 i;
1484 BUG_ON(!(len <= BFI_IOC_MSGLEN_MAX));
1487 * first write msg to mailbox registers
1489 for (i = 0; i < len / sizeof(u32); i++)
1490 writel(cpu_to_le32(msgp[i]),
1491 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1493 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
1494 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1497 * write 1 to mailbox CMD to trigger LPU event
1499 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1500 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
1503 static void
1504 bfa_ioc_send_enable(struct bfa_ioc *ioc)
1506 struct bfi_ioc_ctrl_req enable_req;
1507 struct timeval tv;
1509 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1510 bfa_ioc_portid(ioc));
1511 enable_req.clscode = htons(ioc->clscode);
1512 do_gettimeofday(&tv);
1513 enable_req.tv_sec = ntohl(tv.tv_sec);
1514 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req));
1517 static void
1518 bfa_ioc_send_disable(struct bfa_ioc *ioc)
1520 struct bfi_ioc_ctrl_req disable_req;
1522 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1523 bfa_ioc_portid(ioc));
1524 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req));
1527 static void
1528 bfa_ioc_send_getattr(struct bfa_ioc *ioc)
1530 struct bfi_ioc_getattr_req attr_req;
1532 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1533 bfa_ioc_portid(ioc));
1534 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1535 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1538 void
1539 bfa_nw_ioc_hb_check(void *cbarg)
1541 struct bfa_ioc *ioc = cbarg;
1542 u32 hb_count;
1544 hb_count = readl(ioc->ioc_regs.heartbeat);
1545 if (ioc->hb_count == hb_count) {
1546 bfa_ioc_recover(ioc);
1547 return;
1548 } else {
1549 ioc->hb_count = hb_count;
1552 bfa_ioc_mbox_poll(ioc);
1553 mod_timer(&ioc->hb_timer, jiffies +
1554 msecs_to_jiffies(BFA_IOC_HB_TOV));
1557 static void
1558 bfa_ioc_hb_monitor(struct bfa_ioc *ioc)
1560 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
1561 mod_timer(&ioc->hb_timer, jiffies +
1562 msecs_to_jiffies(BFA_IOC_HB_TOV));
1565 static void
1566 bfa_ioc_hb_stop(struct bfa_ioc *ioc)
1568 del_timer(&ioc->hb_timer);
1572 * @brief
1573 * Initiate a full firmware download.
1575 static void
1576 bfa_ioc_download_fw(struct bfa_ioc *ioc, u32 boot_type,
1577 u32 boot_env)
1579 u32 *fwimg;
1580 u32 pgnum;
1581 u32 loff = 0;
1582 u32 chunkno = 0;
1583 u32 i;
1584 u32 asicmode;
1587 * Initialize LMEM first before code download
1589 bfa_ioc_lmem_init(ioc);
1591 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
1593 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1595 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1597 for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
1598 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1599 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
1600 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
1601 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
1605 * write smem
1607 writel((swab32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)])),
1608 ((ioc->ioc_regs.smem_page_start) + (loff)));
1610 loff += sizeof(u32);
1613 * handle page offset wrap around
1615 loff = PSS_SMEM_PGOFF(loff);
1616 if (loff == 0) {
1617 pgnum++;
1618 writel(pgnum,
1619 ioc->ioc_regs.host_page_num_fn);
1623 writel(bfa_ioc_smem_pgnum(ioc, 0),
1624 ioc->ioc_regs.host_page_num_fn);
1627 * Set boot type, env and device mode at the end.
1629 asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
1630 ioc->port0_mode, ioc->port1_mode);
1631 writel(asicmode, ((ioc->ioc_regs.smem_page_start)
1632 + BFI_FWBOOT_DEVMODE_OFF));
1633 writel(boot_type, ((ioc->ioc_regs.smem_page_start)
1634 + (BFI_FWBOOT_TYPE_OFF)));
1635 writel(boot_env, ((ioc->ioc_regs.smem_page_start)
1636 + (BFI_FWBOOT_ENV_OFF)));
1639 static void
1640 bfa_ioc_reset(struct bfa_ioc *ioc, bool force)
1642 bfa_ioc_hwinit(ioc, force);
1646 * BFA ioc enable reply by firmware
1648 static void
1649 bfa_ioc_enable_reply(struct bfa_ioc *ioc, enum bfa_mode port_mode,
1650 u8 cap_bm)
1652 struct bfa_iocpf *iocpf = &ioc->iocpf;
1654 ioc->port_mode = ioc->port_mode_cfg = port_mode;
1655 ioc->ad_cap_bm = cap_bm;
1656 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
1660 * @brief
1661 * Update BFA configuration from firmware configuration.
1663 static void
1664 bfa_ioc_getattr_reply(struct bfa_ioc *ioc)
1666 struct bfi_ioc_attr *attr = ioc->attr;
1668 attr->adapter_prop = ntohl(attr->adapter_prop);
1669 attr->card_type = ntohl(attr->card_type);
1670 attr->maxfrsize = ntohs(attr->maxfrsize);
1672 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1676 * Attach time initialization of mbox logic.
1678 static void
1679 bfa_ioc_mbox_attach(struct bfa_ioc *ioc)
1681 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1682 int mc;
1684 INIT_LIST_HEAD(&mod->cmd_q);
1685 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1686 mod->mbhdlr[mc].cbfn = NULL;
1687 mod->mbhdlr[mc].cbarg = ioc->bfa;
1692 * Mbox poll timer -- restarts any pending mailbox requests.
1694 static void
1695 bfa_ioc_mbox_poll(struct bfa_ioc *ioc)
1697 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1698 struct bfa_mbox_cmd *cmd;
1699 bfa_mbox_cmd_cbfn_t cbfn;
1700 void *cbarg;
1701 u32 stat;
1704 * If no command pending, do nothing
1706 if (list_empty(&mod->cmd_q))
1707 return;
1710 * If previous command is not yet fetched by firmware, do nothing
1712 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1713 if (stat)
1714 return;
1717 * Enqueue command to firmware.
1719 bfa_q_deq(&mod->cmd_q, &cmd);
1720 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1723 * Give a callback to the client, indicating that the command is sent
1725 if (cmd->cbfn) {
1726 cbfn = cmd->cbfn;
1727 cbarg = cmd->cbarg;
1728 cmd->cbfn = NULL;
1729 cbfn(cbarg);
1734 * Cleanup any pending requests.
1736 static void
1737 bfa_ioc_mbox_flush(struct bfa_ioc *ioc)
1739 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1740 struct bfa_mbox_cmd *cmd;
1742 while (!list_empty(&mod->cmd_q))
1743 bfa_q_deq(&mod->cmd_q, &cmd);
1746 static void
1747 bfa_ioc_fail_notify(struct bfa_ioc *ioc)
1750 * Notify driver and common modules registered for notification.
1752 ioc->cbfn->hbfail_cbfn(ioc->bfa);
1753 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
1757 * IOCPF to IOC interface
1759 static void
1760 bfa_ioc_pf_enabled(struct bfa_ioc *ioc)
1762 bfa_fsm_send_event(ioc, IOC_E_ENABLED);
1765 static void
1766 bfa_ioc_pf_disabled(struct bfa_ioc *ioc)
1768 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
1771 static void
1772 bfa_ioc_pf_failed(struct bfa_ioc *ioc)
1774 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
1777 static void
1778 bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc)
1780 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1783 static void
1784 bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc)
1787 * Provide enable completion callback and AEN notification.
1789 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
1793 * IOC public
1795 static enum bfa_status
1796 bfa_ioc_pll_init(struct bfa_ioc *ioc)
1799 * Hold semaphore so that nobody can access the chip during init.
1801 bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1803 bfa_ioc_pll_init_asic(ioc);
1805 ioc->pllinit = true;
1807 * release semaphore.
1809 bfa_nw_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
1811 return BFA_STATUS_OK;
1815 * Interface used by diag module to do firmware boot with memory test
1816 * as the entry vector.
1818 static void
1819 bfa_ioc_boot(struct bfa_ioc *ioc, enum bfi_fwboot_type boot_type,
1820 u32 boot_env)
1822 bfa_ioc_stats(ioc, ioc_boots);
1824 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1825 return;
1828 * Initialize IOC state of all functions on a chip reset.
1830 if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
1831 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate);
1832 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate);
1833 } else {
1834 writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate);
1835 writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate);
1838 bfa_ioc_msgflush(ioc);
1839 bfa_ioc_download_fw(ioc, boot_type, boot_env);
1840 bfa_ioc_lpu_start(ioc);
1844 * Enable/disable IOC failure auto recovery.
1846 void
1847 bfa_nw_ioc_auto_recover(bool auto_recover)
1849 bfa_nw_auto_recover = auto_recover;
1852 static bool
1853 bfa_ioc_msgget(struct bfa_ioc *ioc, void *mbmsg)
1855 u32 *msgp = mbmsg;
1856 u32 r32;
1857 int i;
1859 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1860 if ((r32 & 1) == 0)
1861 return false;
1864 * read the MBOX msg
1866 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1867 i++) {
1868 r32 = readl(ioc->ioc_regs.lpu_mbox +
1869 i * sizeof(u32));
1870 msgp[i] = htonl(r32);
1874 * turn off mailbox interrupt by clearing mailbox status
1876 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1877 readl(ioc->ioc_regs.lpu_mbox_cmd);
1879 return true;
1882 static void
1883 bfa_ioc_isr(struct bfa_ioc *ioc, struct bfi_mbmsg *m)
1885 union bfi_ioc_i2h_msg_u *msg;
1886 struct bfa_iocpf *iocpf = &ioc->iocpf;
1888 msg = (union bfi_ioc_i2h_msg_u *) m;
1890 bfa_ioc_stats(ioc, ioc_isrs);
1892 switch (msg->mh.msg_id) {
1893 case BFI_IOC_I2H_HBEAT:
1894 break;
1896 case BFI_IOC_I2H_ENABLE_REPLY:
1897 bfa_ioc_enable_reply(ioc,
1898 (enum bfa_mode)msg->fw_event.port_mode,
1899 msg->fw_event.cap_bm);
1900 break;
1902 case BFI_IOC_I2H_DISABLE_REPLY:
1903 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
1904 break;
1906 case BFI_IOC_I2H_GETATTR_REPLY:
1907 bfa_ioc_getattr_reply(ioc);
1908 break;
1910 default:
1911 BUG_ON(1);
1916 * IOC attach time initialization and setup.
1918 * @param[in] ioc memory for IOC
1919 * @param[in] bfa driver instance structure
1921 void
1922 bfa_nw_ioc_attach(struct bfa_ioc *ioc, void *bfa, struct bfa_ioc_cbfn *cbfn)
1924 ioc->bfa = bfa;
1925 ioc->cbfn = cbfn;
1926 ioc->fcmode = false;
1927 ioc->pllinit = false;
1928 ioc->dbg_fwsave_once = true;
1929 ioc->iocpf.ioc = ioc;
1931 bfa_ioc_mbox_attach(ioc);
1932 INIT_LIST_HEAD(&ioc->notify_q);
1934 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
1935 bfa_fsm_send_event(ioc, IOC_E_RESET);
1939 * Driver detach time IOC cleanup.
1941 void
1942 bfa_nw_ioc_detach(struct bfa_ioc *ioc)
1944 bfa_fsm_send_event(ioc, IOC_E_DETACH);
1946 /* Done with detach, empty the notify_q. */
1947 INIT_LIST_HEAD(&ioc->notify_q);
1951 * Setup IOC PCI properties.
1953 * @param[in] pcidev PCI device information for this IOC
1955 void
1956 bfa_nw_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
1957 enum bfi_pcifn_class clscode)
1959 ioc->clscode = clscode;
1960 ioc->pcidev = *pcidev;
1963 * Initialize IOC and device personality
1965 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
1966 ioc->asic_mode = BFI_ASIC_MODE_FC;
1968 switch (pcidev->device_id) {
1969 case PCI_DEVICE_ID_BROCADE_CT:
1970 ioc->asic_gen = BFI_ASIC_GEN_CT;
1971 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
1972 ioc->asic_mode = BFI_ASIC_MODE_ETH;
1973 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
1974 ioc->ad_cap_bm = BFA_CM_CNA;
1975 break;
1977 case BFA_PCI_DEVICE_ID_CT2:
1978 ioc->asic_gen = BFI_ASIC_GEN_CT2;
1979 if (clscode == BFI_PCIFN_CLASS_FC &&
1980 pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
1981 ioc->asic_mode = BFI_ASIC_MODE_FC16;
1982 ioc->fcmode = true;
1983 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
1984 ioc->ad_cap_bm = BFA_CM_HBA;
1985 } else {
1986 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
1987 ioc->asic_mode = BFI_ASIC_MODE_ETH;
1988 if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
1989 ioc->port_mode =
1990 ioc->port_mode_cfg = BFA_MODE_CNA;
1991 ioc->ad_cap_bm = BFA_CM_CNA;
1992 } else {
1993 ioc->port_mode =
1994 ioc->port_mode_cfg = BFA_MODE_NIC;
1995 ioc->ad_cap_bm = BFA_CM_NIC;
1998 break;
2000 default:
2001 BUG_ON(1);
2005 * Set asic specific interfaces.
2007 if (ioc->asic_gen == BFI_ASIC_GEN_CT)
2008 bfa_nw_ioc_set_ct_hwif(ioc);
2009 else {
2010 WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
2011 bfa_nw_ioc_set_ct2_hwif(ioc);
2012 bfa_nw_ioc_ct2_poweron(ioc);
2015 bfa_ioc_map_port(ioc);
2016 bfa_ioc_reg_init(ioc);
2020 * Initialize IOC dma memory
2022 * @param[in] dm_kva kernel virtual address of IOC dma memory
2023 * @param[in] dm_pa physical address of IOC dma memory
2025 void
2026 bfa_nw_ioc_mem_claim(struct bfa_ioc *ioc, u8 *dm_kva, u64 dm_pa)
2029 * dma memory for firmware attribute
2031 ioc->attr_dma.kva = dm_kva;
2032 ioc->attr_dma.pa = dm_pa;
2033 ioc->attr = (struct bfi_ioc_attr *) dm_kva;
2037 * Return size of dma memory required.
2040 bfa_nw_ioc_meminfo(void)
2042 return roundup(sizeof(struct bfi_ioc_attr), BFA_DMA_ALIGN_SZ);
2045 void
2046 bfa_nw_ioc_enable(struct bfa_ioc *ioc)
2048 bfa_ioc_stats(ioc, ioc_enables);
2049 ioc->dbg_fwsave_once = true;
2051 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2054 void
2055 bfa_nw_ioc_disable(struct bfa_ioc *ioc)
2057 bfa_ioc_stats(ioc, ioc_disables);
2058 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2061 static u32
2062 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr)
2064 return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
2068 * Register mailbox message handler function, to be called by common modules
2070 void
2071 bfa_nw_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
2072 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2074 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
2076 mod->mbhdlr[mc].cbfn = cbfn;
2077 mod->mbhdlr[mc].cbarg = cbarg;
2081 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2082 * Responsibility of caller to serialize
2084 * @param[in] ioc IOC instance
2085 * @param[i] cmd Mailbox command
2087 bool
2088 bfa_nw_ioc_mbox_queue(struct bfa_ioc *ioc, struct bfa_mbox_cmd *cmd,
2089 bfa_mbox_cmd_cbfn_t cbfn, void *cbarg)
2091 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
2092 u32 stat;
2094 cmd->cbfn = cbfn;
2095 cmd->cbarg = cbarg;
2098 * If a previous command is pending, queue new command
2100 if (!list_empty(&mod->cmd_q)) {
2101 list_add_tail(&cmd->qe, &mod->cmd_q);
2102 return true;
2106 * If mailbox is busy, queue command for poll timer
2108 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
2109 if (stat) {
2110 list_add_tail(&cmd->qe, &mod->cmd_q);
2111 return true;
2115 * mailbox is free -- queue command to firmware
2117 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2119 return false;
2123 * Handle mailbox interrupts
2125 void
2126 bfa_nw_ioc_mbox_isr(struct bfa_ioc *ioc)
2128 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
2129 struct bfi_mbmsg m;
2130 int mc;
2132 if (bfa_ioc_msgget(ioc, &m)) {
2134 * Treat IOC message class as special.
2136 mc = m.mh.msg_class;
2137 if (mc == BFI_MC_IOC) {
2138 bfa_ioc_isr(ioc, &m);
2139 return;
2142 if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2143 return;
2145 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2148 bfa_ioc_lpu_read_stat(ioc);
2151 * Try to send pending mailbox commands
2153 bfa_ioc_mbox_poll(ioc);
2156 void
2157 bfa_nw_ioc_error_isr(struct bfa_ioc *ioc)
2159 bfa_ioc_stats(ioc, ioc_hbfails);
2160 bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
2161 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2165 * return true if IOC is disabled
2167 bool
2168 bfa_nw_ioc_is_disabled(struct bfa_ioc *ioc)
2170 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2171 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
2175 * Add to IOC heartbeat failure notification queue. To be used by common
2176 * modules such as cee, port, diag.
2178 void
2179 bfa_nw_ioc_notify_register(struct bfa_ioc *ioc,
2180 struct bfa_ioc_notify *notify)
2182 list_add_tail(&notify->qe, &ioc->notify_q);
2185 #define BFA_MFG_NAME "Brocade"
2186 static void
2187 bfa_ioc_get_adapter_attr(struct bfa_ioc *ioc,
2188 struct bfa_adapter_attr *ad_attr)
2190 struct bfi_ioc_attr *ioc_attr;
2192 ioc_attr = ioc->attr;
2194 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2195 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2196 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2197 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
2198 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
2199 sizeof(struct bfa_mfg_vpd));
2201 ad_attr->nports = bfa_ioc_get_nports(ioc);
2202 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
2204 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2205 /* For now, model descr uses same model string */
2206 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
2208 ad_attr->card_type = ioc_attr->card_type;
2209 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2211 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2212 ad_attr->prototype = 1;
2213 else
2214 ad_attr->prototype = 0;
2216 ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
2217 ad_attr->mac = bfa_nw_ioc_get_mac(ioc);
2219 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2220 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2221 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2222 ad_attr->asic_rev = ioc_attr->asic_rev;
2224 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
2227 static enum bfa_ioc_type
2228 bfa_ioc_get_type(struct bfa_ioc *ioc)
2230 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
2231 return BFA_IOC_TYPE_LL;
2233 BUG_ON(!(ioc->clscode == BFI_PCIFN_CLASS_FC));
2235 return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
2236 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
2239 static void
2240 bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc, char *serial_num)
2242 memset(serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2243 memcpy(serial_num,
2244 (void *)ioc->attr->brcd_serialnum,
2245 BFA_ADAPTER_SERIAL_NUM_LEN);
2248 static void
2249 bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc, char *fw_ver)
2251 memset(fw_ver, 0, BFA_VERSION_LEN);
2252 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
2255 static void
2256 bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc, char *chip_rev)
2258 BUG_ON(!(chip_rev));
2260 memset(chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
2262 chip_rev[0] = 'R';
2263 chip_rev[1] = 'e';
2264 chip_rev[2] = 'v';
2265 chip_rev[3] = '-';
2266 chip_rev[4] = ioc->attr->asic_rev;
2267 chip_rev[5] = '\0';
2270 static void
2271 bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver)
2273 memset(optrom_ver, 0, BFA_VERSION_LEN);
2274 memcpy(optrom_ver, ioc->attr->optrom_version,
2275 BFA_VERSION_LEN);
2278 static void
2279 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer)
2281 memset(manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2282 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
2285 static void
2286 bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model)
2288 struct bfi_ioc_attr *ioc_attr;
2290 BUG_ON(!(model));
2291 memset(model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
2293 ioc_attr = ioc->attr;
2295 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2296 BFA_MFG_NAME, ioc_attr->card_type);
2299 static enum bfa_ioc_state
2300 bfa_ioc_get_state(struct bfa_ioc *ioc)
2302 enum bfa_iocpf_state iocpf_st;
2303 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2305 if (ioc_st == BFA_IOC_ENABLING ||
2306 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2308 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2310 switch (iocpf_st) {
2311 case BFA_IOCPF_SEMWAIT:
2312 ioc_st = BFA_IOC_SEMWAIT;
2313 break;
2315 case BFA_IOCPF_HWINIT:
2316 ioc_st = BFA_IOC_HWINIT;
2317 break;
2319 case BFA_IOCPF_FWMISMATCH:
2320 ioc_st = BFA_IOC_FWMISMATCH;
2321 break;
2323 case BFA_IOCPF_FAIL:
2324 ioc_st = BFA_IOC_FAIL;
2325 break;
2327 case BFA_IOCPF_INITFAIL:
2328 ioc_st = BFA_IOC_INITFAIL;
2329 break;
2331 default:
2332 break;
2335 return ioc_st;
2338 void
2339 bfa_nw_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr)
2341 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr));
2343 ioc_attr->state = bfa_ioc_get_state(ioc);
2344 ioc_attr->port_id = ioc->port_id;
2345 ioc_attr->port_mode = ioc->port_mode;
2347 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2348 ioc_attr->cap_bm = ioc->ad_cap_bm;
2350 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
2352 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2354 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2355 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
2356 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
2360 * WWN public
2362 static u64
2363 bfa_ioc_get_pwwn(struct bfa_ioc *ioc)
2365 return ioc->attr->pwwn;
2368 mac_t
2369 bfa_nw_ioc_get_mac(struct bfa_ioc *ioc)
2371 return ioc->attr->mac;
2375 * Firmware failure detected. Start recovery actions.
2377 static void
2378 bfa_ioc_recover(struct bfa_ioc *ioc)
2380 pr_crit("Heart Beat of IOC has failed\n");
2381 bfa_ioc_stats(ioc, ioc_hbfails);
2382 bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
2383 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2386 static void
2387 bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc)
2389 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2390 return;
2394 * @dg hal_iocpf_pvt BFA IOC PF private functions
2395 * @{
2398 static void
2399 bfa_iocpf_enable(struct bfa_ioc *ioc)
2401 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
2404 static void
2405 bfa_iocpf_disable(struct bfa_ioc *ioc)
2407 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
2410 static void
2411 bfa_iocpf_fail(struct bfa_ioc *ioc)
2413 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
2416 static void
2417 bfa_iocpf_initfail(struct bfa_ioc *ioc)
2419 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
2422 static void
2423 bfa_iocpf_getattrfail(struct bfa_ioc *ioc)
2425 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
2428 static void
2429 bfa_iocpf_stop(struct bfa_ioc *ioc)
2431 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
2434 void
2435 bfa_nw_iocpf_timeout(void *ioc_arg)
2437 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
2438 enum bfa_iocpf_state iocpf_st;
2440 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2442 if (iocpf_st == BFA_IOCPF_HWINIT)
2443 bfa_ioc_poll_fwinit(ioc);
2444 else
2445 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2448 void
2449 bfa_nw_iocpf_sem_timeout(void *ioc_arg)
2451 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
2453 bfa_ioc_hw_sem_get(ioc);
2456 static void
2457 bfa_ioc_poll_fwinit(struct bfa_ioc *ioc)
2459 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
2461 if (fwstate == BFI_IOC_DISABLED) {
2462 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2463 return;
2466 if (ioc->iocpf.poll_time >= BFA_IOC_TOV) {
2467 bfa_nw_iocpf_timeout(ioc);
2468 } else {
2469 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2470 mod_timer(&ioc->iocpf_timer, jiffies +
2471 msecs_to_jiffies(BFA_IOC_POLL_TOV));