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.
24 * IOC local definitions
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_nw_ioc_debug_save_ftrc(struct bfa_ioc
*ioc
);
78 static void bfa_ioc_fail_notify(struct bfa_ioc
*ioc
);
79 static void bfa_ioc_pf_enabled(struct bfa_ioc
*ioc
);
80 static void bfa_ioc_pf_disabled(struct bfa_ioc
*ioc
);
81 static void bfa_ioc_pf_failed(struct bfa_ioc
*ioc
);
82 static void bfa_ioc_pf_hwfailed(struct bfa_ioc
*ioc
);
83 static void bfa_ioc_pf_fwmismatch(struct bfa_ioc
*ioc
);
84 static void bfa_ioc_boot(struct bfa_ioc
*ioc
, u32 boot_type
,
86 static u32
bfa_ioc_smem_pgnum(struct bfa_ioc
*ioc
, u32 fmaddr
);
87 static void bfa_ioc_get_adapter_serial_num(struct bfa_ioc
*ioc
,
89 static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc
*ioc
,
91 static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc
*ioc
,
93 static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc
*ioc
,
95 static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc
*ioc
,
97 static void bfa_ioc_get_adapter_model(struct bfa_ioc
*ioc
, char *model
);
98 static u64
bfa_ioc_get_pwwn(struct bfa_ioc
*ioc
);
101 * IOC state machine definitions/declarations
104 IOC_E_RESET
= 1, /*!< IOC reset request */
105 IOC_E_ENABLE
= 2, /*!< IOC enable request */
106 IOC_E_DISABLE
= 3, /*!< IOC disable request */
107 IOC_E_DETACH
= 4, /*!< driver detach cleanup */
108 IOC_E_ENABLED
= 5, /*!< f/w enabled */
109 IOC_E_FWRSP_GETATTR
= 6, /*!< IOC get attribute response */
110 IOC_E_DISABLED
= 7, /*!< f/w disabled */
111 IOC_E_PFFAILED
= 8, /*!< failure notice by iocpf sm */
112 IOC_E_HBFAIL
= 9, /*!< heartbeat failure */
113 IOC_E_HWERROR
= 10, /*!< hardware error interrupt */
114 IOC_E_TIMEOUT
= 11, /*!< timeout */
115 IOC_E_HWFAILED
= 12, /*!< PCI mapping failure notice */
118 bfa_fsm_state_decl(bfa_ioc
, uninit
, struct bfa_ioc
, enum ioc_event
);
119 bfa_fsm_state_decl(bfa_ioc
, reset
, struct bfa_ioc
, enum ioc_event
);
120 bfa_fsm_state_decl(bfa_ioc
, enabling
, struct bfa_ioc
, enum ioc_event
);
121 bfa_fsm_state_decl(bfa_ioc
, getattr
, struct bfa_ioc
, enum ioc_event
);
122 bfa_fsm_state_decl(bfa_ioc
, op
, struct bfa_ioc
, enum ioc_event
);
123 bfa_fsm_state_decl(bfa_ioc
, fail_retry
, struct bfa_ioc
, enum ioc_event
);
124 bfa_fsm_state_decl(bfa_ioc
, fail
, struct bfa_ioc
, enum ioc_event
);
125 bfa_fsm_state_decl(bfa_ioc
, disabling
, struct bfa_ioc
, enum ioc_event
);
126 bfa_fsm_state_decl(bfa_ioc
, disabled
, struct bfa_ioc
, enum ioc_event
);
127 bfa_fsm_state_decl(bfa_ioc
, hwfail
, struct bfa_ioc
, enum ioc_event
);
129 static struct bfa_sm_table ioc_sm_table
[] = {
130 {BFA_SM(bfa_ioc_sm_uninit
), BFA_IOC_UNINIT
},
131 {BFA_SM(bfa_ioc_sm_reset
), BFA_IOC_RESET
},
132 {BFA_SM(bfa_ioc_sm_enabling
), BFA_IOC_ENABLING
},
133 {BFA_SM(bfa_ioc_sm_getattr
), BFA_IOC_GETATTR
},
134 {BFA_SM(bfa_ioc_sm_op
), BFA_IOC_OPERATIONAL
},
135 {BFA_SM(bfa_ioc_sm_fail_retry
), BFA_IOC_INITFAIL
},
136 {BFA_SM(bfa_ioc_sm_fail
), BFA_IOC_FAIL
},
137 {BFA_SM(bfa_ioc_sm_disabling
), BFA_IOC_DISABLING
},
138 {BFA_SM(bfa_ioc_sm_disabled
), BFA_IOC_DISABLED
},
139 {BFA_SM(bfa_ioc_sm_hwfail
), BFA_IOC_HWFAIL
},
143 * Forward declareations for iocpf state machine
145 static void bfa_iocpf_enable(struct bfa_ioc
*ioc
);
146 static void bfa_iocpf_disable(struct bfa_ioc
*ioc
);
147 static void bfa_iocpf_fail(struct bfa_ioc
*ioc
);
148 static void bfa_iocpf_initfail(struct bfa_ioc
*ioc
);
149 static void bfa_iocpf_getattrfail(struct bfa_ioc
*ioc
);
150 static void bfa_iocpf_stop(struct bfa_ioc
*ioc
);
153 * IOCPF state machine events
156 IOCPF_E_ENABLE
= 1, /*!< IOCPF enable request */
157 IOCPF_E_DISABLE
= 2, /*!< IOCPF disable request */
158 IOCPF_E_STOP
= 3, /*!< stop on driver detach */
159 IOCPF_E_FWREADY
= 4, /*!< f/w initialization done */
160 IOCPF_E_FWRSP_ENABLE
= 5, /*!< enable f/w response */
161 IOCPF_E_FWRSP_DISABLE
= 6, /*!< disable f/w response */
162 IOCPF_E_FAIL
= 7, /*!< failure notice by ioc sm */
163 IOCPF_E_INITFAIL
= 8, /*!< init fail notice by ioc sm */
164 IOCPF_E_GETATTRFAIL
= 9, /*!< init fail notice by ioc sm */
165 IOCPF_E_SEMLOCKED
= 10, /*!< h/w semaphore is locked */
166 IOCPF_E_TIMEOUT
= 11, /*!< f/w response timeout */
167 IOCPF_E_SEM_ERROR
= 12, /*!< h/w sem mapping error */
173 enum bfa_iocpf_state
{
174 BFA_IOCPF_RESET
= 1, /*!< IOC is in reset state */
175 BFA_IOCPF_SEMWAIT
= 2, /*!< Waiting for IOC h/w semaphore */
176 BFA_IOCPF_HWINIT
= 3, /*!< IOC h/w is being initialized */
177 BFA_IOCPF_READY
= 4, /*!< IOCPF is initialized */
178 BFA_IOCPF_INITFAIL
= 5, /*!< IOCPF failed */
179 BFA_IOCPF_FAIL
= 6, /*!< IOCPF failed */
180 BFA_IOCPF_DISABLING
= 7, /*!< IOCPF is being disabled */
181 BFA_IOCPF_DISABLED
= 8, /*!< IOCPF is disabled */
182 BFA_IOCPF_FWMISMATCH
= 9, /*!< IOC f/w different from drivers */
185 bfa_fsm_state_decl(bfa_iocpf
, reset
, struct bfa_iocpf
, enum iocpf_event
);
186 bfa_fsm_state_decl(bfa_iocpf
, fwcheck
, struct bfa_iocpf
, enum iocpf_event
);
187 bfa_fsm_state_decl(bfa_iocpf
, mismatch
, struct bfa_iocpf
, enum iocpf_event
);
188 bfa_fsm_state_decl(bfa_iocpf
, semwait
, struct bfa_iocpf
, enum iocpf_event
);
189 bfa_fsm_state_decl(bfa_iocpf
, hwinit
, struct bfa_iocpf
, enum iocpf_event
);
190 bfa_fsm_state_decl(bfa_iocpf
, enabling
, struct bfa_iocpf
, enum iocpf_event
);
191 bfa_fsm_state_decl(bfa_iocpf
, ready
, struct bfa_iocpf
, enum iocpf_event
);
192 bfa_fsm_state_decl(bfa_iocpf
, initfail_sync
, struct bfa_iocpf
,
194 bfa_fsm_state_decl(bfa_iocpf
, initfail
, struct bfa_iocpf
, enum iocpf_event
);
195 bfa_fsm_state_decl(bfa_iocpf
, fail_sync
, struct bfa_iocpf
, enum iocpf_event
);
196 bfa_fsm_state_decl(bfa_iocpf
, fail
, struct bfa_iocpf
, enum iocpf_event
);
197 bfa_fsm_state_decl(bfa_iocpf
, disabling
, struct bfa_iocpf
, enum iocpf_event
);
198 bfa_fsm_state_decl(bfa_iocpf
, disabling_sync
, struct bfa_iocpf
,
200 bfa_fsm_state_decl(bfa_iocpf
, disabled
, struct bfa_iocpf
, enum iocpf_event
);
202 static struct bfa_sm_table iocpf_sm_table
[] = {
203 {BFA_SM(bfa_iocpf_sm_reset
), BFA_IOCPF_RESET
},
204 {BFA_SM(bfa_iocpf_sm_fwcheck
), BFA_IOCPF_FWMISMATCH
},
205 {BFA_SM(bfa_iocpf_sm_mismatch
), BFA_IOCPF_FWMISMATCH
},
206 {BFA_SM(bfa_iocpf_sm_semwait
), BFA_IOCPF_SEMWAIT
},
207 {BFA_SM(bfa_iocpf_sm_hwinit
), BFA_IOCPF_HWINIT
},
208 {BFA_SM(bfa_iocpf_sm_enabling
), BFA_IOCPF_HWINIT
},
209 {BFA_SM(bfa_iocpf_sm_ready
), BFA_IOCPF_READY
},
210 {BFA_SM(bfa_iocpf_sm_initfail_sync
), BFA_IOCPF_INITFAIL
},
211 {BFA_SM(bfa_iocpf_sm_initfail
), BFA_IOCPF_INITFAIL
},
212 {BFA_SM(bfa_iocpf_sm_fail_sync
), BFA_IOCPF_FAIL
},
213 {BFA_SM(bfa_iocpf_sm_fail
), BFA_IOCPF_FAIL
},
214 {BFA_SM(bfa_iocpf_sm_disabling
), BFA_IOCPF_DISABLING
},
215 {BFA_SM(bfa_iocpf_sm_disabling_sync
), BFA_IOCPF_DISABLING
},
216 {BFA_SM(bfa_iocpf_sm_disabled
), BFA_IOCPF_DISABLED
},
224 * Beginning state. IOC uninit state.
227 bfa_ioc_sm_uninit_entry(struct bfa_ioc
*ioc
)
232 * IOC is in uninit state.
235 bfa_ioc_sm_uninit(struct bfa_ioc
*ioc
, enum ioc_event event
)
239 bfa_fsm_set_state(ioc
, bfa_ioc_sm_reset
);
248 * Reset entry actions -- initialize state machine
251 bfa_ioc_sm_reset_entry(struct bfa_ioc
*ioc
)
253 bfa_fsm_set_state(&ioc
->iocpf
, bfa_iocpf_sm_reset
);
257 * IOC is in reset state.
260 bfa_ioc_sm_reset(struct bfa_ioc
*ioc
, enum ioc_event event
)
264 bfa_fsm_set_state(ioc
, bfa_ioc_sm_enabling
);
268 bfa_ioc_disable_comp(ioc
);
272 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
281 bfa_ioc_sm_enabling_entry(struct bfa_ioc
*ioc
)
283 bfa_iocpf_enable(ioc
);
287 * Host IOC function is being enabled, awaiting response from firmware.
288 * Semaphore is acquired.
291 bfa_ioc_sm_enabling(struct bfa_ioc
*ioc
, enum ioc_event event
)
295 bfa_fsm_set_state(ioc
, bfa_ioc_sm_getattr
);
299 /* !!! fall through !!! */
301 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
302 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
303 if (event
!= IOC_E_PFFAILED
)
304 bfa_iocpf_initfail(ioc
);
308 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
309 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
313 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
317 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
330 * Semaphore should be acquired for version check.
333 bfa_ioc_sm_getattr_entry(struct bfa_ioc
*ioc
)
335 mod_timer(&ioc
->ioc_timer
, jiffies
+
336 msecs_to_jiffies(BFA_IOC_TOV
));
337 bfa_ioc_send_getattr(ioc
);
341 * IOC configuration in progress. Timer is active.
344 bfa_ioc_sm_getattr(struct bfa_ioc
*ioc
, enum ioc_event event
)
347 case IOC_E_FWRSP_GETATTR
:
348 del_timer(&ioc
->ioc_timer
);
349 bfa_ioc_check_attr_wwns(ioc
);
350 bfa_ioc_hb_monitor(ioc
);
351 bfa_fsm_set_state(ioc
, bfa_ioc_sm_op
);
356 del_timer(&ioc
->ioc_timer
);
359 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
360 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
361 if (event
!= IOC_E_PFFAILED
)
362 bfa_iocpf_getattrfail(ioc
);
366 del_timer(&ioc
->ioc_timer
);
367 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
379 bfa_ioc_sm_op_entry(struct bfa_ioc
*ioc
)
381 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_OK
);
382 bfa_ioc_event_notify(ioc
, BFA_IOC_E_ENABLED
);
386 bfa_ioc_sm_op(struct bfa_ioc
*ioc
, enum ioc_event event
)
393 bfa_ioc_hb_stop(ioc
);
394 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
399 bfa_ioc_hb_stop(ioc
);
400 /* !!! fall through !!! */
402 if (ioc
->iocpf
.auto_recover
)
403 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail_retry
);
405 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
407 bfa_ioc_fail_notify(ioc
);
409 if (event
!= IOC_E_PFFAILED
)
419 bfa_ioc_sm_disabling_entry(struct bfa_ioc
*ioc
)
421 bfa_iocpf_disable(ioc
);
425 * IOC is being disabled
428 bfa_ioc_sm_disabling(struct bfa_ioc
*ioc
, enum ioc_event event
)
432 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabled
);
437 * No state change. Will move to disabled state
438 * after iocpf sm completes failure processing and
439 * moves to disabled state.
445 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
446 bfa_ioc_disable_comp(ioc
);
455 * IOC disable completion entry.
458 bfa_ioc_sm_disabled_entry(struct bfa_ioc
*ioc
)
460 bfa_ioc_disable_comp(ioc
);
464 bfa_ioc_sm_disabled(struct bfa_ioc
*ioc
, enum ioc_event event
)
468 bfa_fsm_set_state(ioc
, bfa_ioc_sm_enabling
);
472 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
476 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
486 bfa_ioc_sm_fail_retry_entry(struct bfa_ioc
*ioc
)
491 * Hardware initialization retry.
494 bfa_ioc_sm_fail_retry(struct bfa_ioc
*ioc
, enum ioc_event event
)
498 bfa_fsm_set_state(ioc
, bfa_ioc_sm_getattr
);
504 * Initialization retry failed.
506 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
507 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
508 if (event
!= IOC_E_PFFAILED
)
509 bfa_iocpf_initfail(ioc
);
513 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
514 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
521 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
525 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
535 bfa_ioc_sm_fail_entry(struct bfa_ioc
*ioc
)
543 bfa_ioc_sm_fail(struct bfa_ioc
*ioc
, enum ioc_event event
)
547 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
551 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
555 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
560 /* HB failure notification, ignore. */
569 bfa_ioc_sm_hwfail_entry(struct bfa_ioc
*ioc
)
577 bfa_ioc_sm_hwfail(struct bfa_ioc
*ioc
, enum ioc_event event
)
582 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
586 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
590 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
599 * IOCPF State Machine
603 * Reset entry actions -- initialize state machine
606 bfa_iocpf_sm_reset_entry(struct bfa_iocpf
*iocpf
)
608 iocpf
->fw_mismatch_notified
= false;
609 iocpf
->auto_recover
= bfa_nw_auto_recover
;
613 * Beginning state. IOC is in reset state.
616 bfa_iocpf_sm_reset(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
620 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fwcheck
);
632 * Semaphore should be acquired for version check.
635 bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf
*iocpf
)
637 bfa_ioc_hw_sem_init(iocpf
->ioc
);
638 bfa_ioc_hw_sem_get(iocpf
->ioc
);
642 * Awaiting h/w semaphore to continue with version check.
645 bfa_iocpf_sm_fwcheck(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
647 struct bfa_ioc
*ioc
= iocpf
->ioc
;
650 case IOCPF_E_SEMLOCKED
:
651 if (bfa_ioc_firmware_lock(ioc
)) {
652 if (bfa_ioc_sync_start(ioc
)) {
653 bfa_ioc_sync_join(ioc
);
654 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_hwinit
);
656 bfa_ioc_firmware_unlock(ioc
);
657 bfa_nw_ioc_hw_sem_release(ioc
);
658 mod_timer(&ioc
->sem_timer
, jiffies
+
659 msecs_to_jiffies(BFA_IOC_HWSEM_TOV
));
662 bfa_nw_ioc_hw_sem_release(ioc
);
663 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_mismatch
);
667 case IOCPF_E_SEM_ERROR
:
668 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
669 bfa_ioc_pf_hwfailed(ioc
);
672 case IOCPF_E_DISABLE
:
673 bfa_ioc_hw_sem_get_cancel(ioc
);
674 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
675 bfa_ioc_pf_disabled(ioc
);
679 bfa_ioc_hw_sem_get_cancel(ioc
);
680 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
689 * Notify enable completion callback
692 bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf
*iocpf
)
694 /* Call only the first time sm enters fwmismatch state. */
695 if (!iocpf
->fw_mismatch_notified
)
696 bfa_ioc_pf_fwmismatch(iocpf
->ioc
);
698 iocpf
->fw_mismatch_notified
= true;
699 mod_timer(&(iocpf
->ioc
)->iocpf_timer
, jiffies
+
700 msecs_to_jiffies(BFA_IOC_TOV
));
704 * Awaiting firmware version match.
707 bfa_iocpf_sm_mismatch(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
709 struct bfa_ioc
*ioc
= iocpf
->ioc
;
712 case IOCPF_E_TIMEOUT
:
713 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fwcheck
);
716 case IOCPF_E_DISABLE
:
717 del_timer(&ioc
->iocpf_timer
);
718 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
719 bfa_ioc_pf_disabled(ioc
);
723 del_timer(&ioc
->iocpf_timer
);
724 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
733 * Request for semaphore.
736 bfa_iocpf_sm_semwait_entry(struct bfa_iocpf
*iocpf
)
738 bfa_ioc_hw_sem_get(iocpf
->ioc
);
742 * Awaiting semaphore for h/w initialzation.
745 bfa_iocpf_sm_semwait(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
747 struct bfa_ioc
*ioc
= iocpf
->ioc
;
750 case IOCPF_E_SEMLOCKED
:
751 if (bfa_ioc_sync_complete(ioc
)) {
752 bfa_ioc_sync_join(ioc
);
753 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_hwinit
);
755 bfa_nw_ioc_hw_sem_release(ioc
);
756 mod_timer(&ioc
->sem_timer
, jiffies
+
757 msecs_to_jiffies(BFA_IOC_HWSEM_TOV
));
761 case IOCPF_E_SEM_ERROR
:
762 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
763 bfa_ioc_pf_hwfailed(ioc
);
766 case IOCPF_E_DISABLE
:
767 bfa_ioc_hw_sem_get_cancel(ioc
);
768 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
777 bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf
*iocpf
)
779 iocpf
->poll_time
= 0;
780 bfa_ioc_reset(iocpf
->ioc
, false);
784 * Hardware is being initialized. Interrupts are enabled.
785 * Holding hardware semaphore lock.
788 bfa_iocpf_sm_hwinit(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
790 struct bfa_ioc
*ioc
= iocpf
->ioc
;
793 case IOCPF_E_FWREADY
:
794 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_enabling
);
797 case IOCPF_E_TIMEOUT
:
798 bfa_nw_ioc_hw_sem_release(ioc
);
799 bfa_ioc_pf_failed(ioc
);
800 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail_sync
);
803 case IOCPF_E_DISABLE
:
804 del_timer(&ioc
->iocpf_timer
);
805 bfa_ioc_sync_leave(ioc
);
806 bfa_nw_ioc_hw_sem_release(ioc
);
807 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
816 bfa_iocpf_sm_enabling_entry(struct bfa_iocpf
*iocpf
)
818 mod_timer(&(iocpf
->ioc
)->iocpf_timer
, jiffies
+
819 msecs_to_jiffies(BFA_IOC_TOV
));
821 * Enable Interrupts before sending fw IOC ENABLE cmd.
823 iocpf
->ioc
->cbfn
->reset_cbfn(iocpf
->ioc
->bfa
);
824 bfa_ioc_send_enable(iocpf
->ioc
);
828 * Host IOC function is being enabled, awaiting response from firmware.
829 * Semaphore is acquired.
832 bfa_iocpf_sm_enabling(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
834 struct bfa_ioc
*ioc
= iocpf
->ioc
;
837 case IOCPF_E_FWRSP_ENABLE
:
838 del_timer(&ioc
->iocpf_timer
);
839 bfa_nw_ioc_hw_sem_release(ioc
);
840 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_ready
);
843 case IOCPF_E_INITFAIL
:
844 del_timer(&ioc
->iocpf_timer
);
846 * !!! fall through !!!
848 case IOCPF_E_TIMEOUT
:
849 bfa_nw_ioc_hw_sem_release(ioc
);
850 if (event
== IOCPF_E_TIMEOUT
)
851 bfa_ioc_pf_failed(ioc
);
852 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail_sync
);
855 case IOCPF_E_DISABLE
:
856 del_timer(&ioc
->iocpf_timer
);
857 bfa_nw_ioc_hw_sem_release(ioc
);
858 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling
);
867 bfa_iocpf_sm_ready_entry(struct bfa_iocpf
*iocpf
)
869 bfa_ioc_pf_enabled(iocpf
->ioc
);
873 bfa_iocpf_sm_ready(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
876 case IOCPF_E_DISABLE
:
877 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling
);
880 case IOCPF_E_GETATTRFAIL
:
881 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail_sync
);
885 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail_sync
);
894 bfa_iocpf_sm_disabling_entry(struct bfa_iocpf
*iocpf
)
896 mod_timer(&(iocpf
->ioc
)->iocpf_timer
, jiffies
+
897 msecs_to_jiffies(BFA_IOC_TOV
));
898 bfa_ioc_send_disable(iocpf
->ioc
);
902 * IOC is being disabled
905 bfa_iocpf_sm_disabling(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
907 struct bfa_ioc
*ioc
= iocpf
->ioc
;
910 case IOCPF_E_FWRSP_DISABLE
:
911 del_timer(&ioc
->iocpf_timer
);
912 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
916 del_timer(&ioc
->iocpf_timer
);
918 * !!! fall through !!!
921 case IOCPF_E_TIMEOUT
:
922 writel(BFI_IOC_FAIL
, ioc
->ioc_regs
.ioc_fwstate
);
923 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
926 case IOCPF_E_FWRSP_ENABLE
:
935 bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf
*iocpf
)
937 bfa_ioc_hw_sem_get(iocpf
->ioc
);
941 * IOC hb ack request is being removed.
944 bfa_iocpf_sm_disabling_sync(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
946 struct bfa_ioc
*ioc
= iocpf
->ioc
;
949 case IOCPF_E_SEMLOCKED
:
950 bfa_ioc_sync_leave(ioc
);
951 bfa_nw_ioc_hw_sem_release(ioc
);
952 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
955 case IOCPF_E_SEM_ERROR
:
956 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
957 bfa_ioc_pf_hwfailed(ioc
);
969 * IOC disable completion entry.
972 bfa_iocpf_sm_disabled_entry(struct bfa_iocpf
*iocpf
)
974 bfa_ioc_mbox_flush(iocpf
->ioc
);
975 bfa_ioc_pf_disabled(iocpf
->ioc
);
979 bfa_iocpf_sm_disabled(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
981 struct bfa_ioc
*ioc
= iocpf
->ioc
;
985 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_semwait
);
989 bfa_ioc_firmware_unlock(ioc
);
990 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
999 bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf
*iocpf
)
1001 bfa_nw_ioc_debug_save_ftrc(iocpf
->ioc
);
1002 bfa_ioc_hw_sem_get(iocpf
->ioc
);
1006 * Hardware initialization failed.
1009 bfa_iocpf_sm_initfail_sync(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1011 struct bfa_ioc
*ioc
= iocpf
->ioc
;
1014 case IOCPF_E_SEMLOCKED
:
1015 bfa_ioc_notify_fail(ioc
);
1016 bfa_ioc_sync_leave(ioc
);
1017 writel(BFI_IOC_FAIL
, ioc
->ioc_regs
.ioc_fwstate
);
1018 bfa_nw_ioc_hw_sem_release(ioc
);
1019 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail
);
1022 case IOCPF_E_SEM_ERROR
:
1023 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1024 bfa_ioc_pf_hwfailed(ioc
);
1027 case IOCPF_E_DISABLE
:
1028 bfa_ioc_hw_sem_get_cancel(ioc
);
1029 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1033 bfa_ioc_hw_sem_get_cancel(ioc
);
1034 bfa_ioc_firmware_unlock(ioc
);
1035 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
1042 bfa_sm_fault(event
);
1047 bfa_iocpf_sm_initfail_entry(struct bfa_iocpf
*iocpf
)
1052 * Hardware initialization failed.
1055 bfa_iocpf_sm_initfail(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1057 struct bfa_ioc
*ioc
= iocpf
->ioc
;
1060 case IOCPF_E_DISABLE
:
1061 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
1065 bfa_ioc_firmware_unlock(ioc
);
1066 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
1070 bfa_sm_fault(event
);
1075 bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf
*iocpf
)
1078 * Mark IOC as failed in hardware and stop firmware.
1080 bfa_ioc_lpu_stop(iocpf
->ioc
);
1083 * Flush any queued up mailbox requests.
1085 bfa_ioc_mbox_flush(iocpf
->ioc
);
1086 bfa_ioc_hw_sem_get(iocpf
->ioc
);
1090 * IOC is in failed state.
1093 bfa_iocpf_sm_fail_sync(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1095 struct bfa_ioc
*ioc
= iocpf
->ioc
;
1098 case IOCPF_E_SEMLOCKED
:
1099 bfa_ioc_sync_ack(ioc
);
1100 bfa_ioc_notify_fail(ioc
);
1101 if (!iocpf
->auto_recover
) {
1102 bfa_ioc_sync_leave(ioc
);
1103 writel(BFI_IOC_FAIL
, ioc
->ioc_regs
.ioc_fwstate
);
1104 bfa_nw_ioc_hw_sem_release(ioc
);
1105 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1107 if (bfa_ioc_sync_complete(ioc
))
1108 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_hwinit
);
1110 bfa_nw_ioc_hw_sem_release(ioc
);
1111 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_semwait
);
1116 case IOCPF_E_SEM_ERROR
:
1117 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1118 bfa_ioc_pf_hwfailed(ioc
);
1121 case IOCPF_E_DISABLE
:
1122 bfa_ioc_hw_sem_get_cancel(ioc
);
1123 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1130 bfa_sm_fault(event
);
1135 bfa_iocpf_sm_fail_entry(struct bfa_iocpf
*iocpf
)
1141 * IOC is in failed state.
1144 bfa_iocpf_sm_fail(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1147 case IOCPF_E_DISABLE
:
1148 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
1152 bfa_sm_fault(event
);
1157 * BFA IOC private functions
1161 * Notify common modules registered for notification.
1164 bfa_ioc_event_notify(struct bfa_ioc
*ioc
, enum bfa_ioc_event event
)
1166 struct bfa_ioc_notify
*notify
;
1167 struct list_head
*qe
;
1169 list_for_each(qe
, &ioc
->notify_q
) {
1170 notify
= (struct bfa_ioc_notify
*)qe
;
1171 notify
->cbfn(notify
->cbarg
, event
);
1176 bfa_ioc_disable_comp(struct bfa_ioc
*ioc
)
1178 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
1179 bfa_ioc_event_notify(ioc
, BFA_IOC_E_DISABLED
);
1183 bfa_nw_ioc_sem_get(void __iomem
*sem_reg
)
1187 #define BFA_SEM_SPINCNT 3000
1189 r32
= readl(sem_reg
);
1191 while ((r32
& 1) && (cnt
< BFA_SEM_SPINCNT
)) {
1194 r32
= readl(sem_reg
);
1204 bfa_nw_ioc_sem_release(void __iomem
*sem_reg
)
1211 bfa_ioc_hw_sem_init(struct bfa_ioc
*ioc
)
1213 struct bfi_ioc_image_hdr fwhdr
;
1214 u32 fwstate
= readl(ioc
->ioc_regs
.ioc_fwstate
);
1216 if (fwstate
== BFI_IOC_UNINIT
)
1219 bfa_nw_ioc_fwver_get(ioc
, &fwhdr
);
1221 if (swab32(fwhdr
.exec
) == BFI_FWBOOT_TYPE_NORMAL
)
1224 writel(BFI_IOC_UNINIT
, ioc
->ioc_regs
.ioc_fwstate
);
1227 * Try to lock and then unlock the semaphore.
1229 readl(ioc
->ioc_regs
.ioc_sem_reg
);
1230 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
1234 bfa_ioc_hw_sem_get(struct bfa_ioc
*ioc
)
1239 * First read to the semaphore register will return 0, subsequent reads
1240 * will return 1. Semaphore is released by writing 1 to the register
1242 r32
= readl(ioc
->ioc_regs
.ioc_sem_reg
);
1244 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_SEM_ERROR
);
1248 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_SEMLOCKED
);
1252 mod_timer(&ioc
->sem_timer
, jiffies
+
1253 msecs_to_jiffies(BFA_IOC_HWSEM_TOV
));
1257 bfa_nw_ioc_hw_sem_release(struct bfa_ioc
*ioc
)
1259 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
1263 bfa_ioc_hw_sem_get_cancel(struct bfa_ioc
*ioc
)
1265 del_timer(&ioc
->sem_timer
);
1270 * Initialize LPU local memory (aka secondary memory / SRAM)
1273 bfa_ioc_lmem_init(struct bfa_ioc
*ioc
)
1277 #define PSS_LMEM_INIT_TIME 10000
1279 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1280 pss_ctl
&= ~__PSS_LMEM_RESET
;
1281 pss_ctl
|= __PSS_LMEM_INIT_EN
;
1284 * i2c workaround 12.5khz clock
1286 pss_ctl
|= __PSS_I2C_CLK_DIV(3UL);
1287 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1290 * wait for memory initialization to be complete
1294 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1296 } while (!(pss_ctl
& __PSS_LMEM_INIT_DONE
) && (i
< PSS_LMEM_INIT_TIME
));
1299 * If memory initialization is not successful, IOC timeout will catch
1302 BUG_ON(!(pss_ctl
& __PSS_LMEM_INIT_DONE
));
1304 pss_ctl
&= ~(__PSS_LMEM_INIT_DONE
| __PSS_LMEM_INIT_EN
);
1305 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1309 bfa_ioc_lpu_start(struct bfa_ioc
*ioc
)
1314 * Take processor out of reset.
1316 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1317 pss_ctl
&= ~__PSS_LPU0_RESET
;
1319 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1323 bfa_ioc_lpu_stop(struct bfa_ioc
*ioc
)
1328 * Put processors in reset.
1330 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1331 pss_ctl
|= (__PSS_LPU0_RESET
| __PSS_LPU1_RESET
);
1333 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1337 * Get driver and firmware versions.
1340 bfa_nw_ioc_fwver_get(struct bfa_ioc
*ioc
, struct bfi_ioc_image_hdr
*fwhdr
)
1345 u32
*fwsig
= (u32
*) fwhdr
;
1347 pgnum
= bfa_ioc_smem_pgnum(ioc
, loff
);
1348 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1350 for (i
= 0; i
< (sizeof(struct bfi_ioc_image_hdr
) / sizeof(u32
));
1353 swab32(readl((loff
) + (ioc
->ioc_regs
.smem_page_start
)));
1354 loff
+= sizeof(u32
);
1359 * Returns TRUE if same.
1362 bfa_nw_ioc_fwver_cmp(struct bfa_ioc
*ioc
, struct bfi_ioc_image_hdr
*fwhdr
)
1364 struct bfi_ioc_image_hdr
*drv_fwhdr
;
1367 drv_fwhdr
= (struct bfi_ioc_image_hdr
*)
1368 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc
), 0);
1370 for (i
= 0; i
< BFI_IOC_MD5SUM_SZ
; i
++) {
1371 if (fwhdr
->md5sum
[i
] != drv_fwhdr
->md5sum
[i
])
1379 * Return true if current running version is valid. Firmware signature and
1380 * execution context (driver/bios) must match.
1383 bfa_ioc_fwver_valid(struct bfa_ioc
*ioc
, u32 boot_env
)
1385 struct bfi_ioc_image_hdr fwhdr
, *drv_fwhdr
;
1387 bfa_nw_ioc_fwver_get(ioc
, &fwhdr
);
1388 drv_fwhdr
= (struct bfi_ioc_image_hdr
*)
1389 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc
), 0);
1391 if (fwhdr
.signature
!= drv_fwhdr
->signature
)
1394 if (swab32(fwhdr
.bootenv
) != boot_env
)
1397 return bfa_nw_ioc_fwver_cmp(ioc
, &fwhdr
);
1401 * Conditionally flush any pending message from firmware at start.
1404 bfa_ioc_msgflush(struct bfa_ioc
*ioc
)
1408 r32
= readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
1410 writel(1, ioc
->ioc_regs
.lpu_mbox_cmd
);
1414 * @img ioc_init_logic.jpg
1417 bfa_ioc_hwinit(struct bfa_ioc
*ioc
, bool force
)
1419 enum bfi_ioc_state ioc_fwstate
;
1423 ioc_fwstate
= readl(ioc
->ioc_regs
.ioc_fwstate
);
1426 ioc_fwstate
= BFI_IOC_UNINIT
;
1428 boot_env
= BFI_FWBOOT_ENV_OS
;
1431 * check if firmware is valid
1433 fwvalid
= (ioc_fwstate
== BFI_IOC_UNINIT
) ?
1434 false : bfa_ioc_fwver_valid(ioc
, boot_env
);
1437 bfa_ioc_boot(ioc
, BFI_FWBOOT_TYPE_NORMAL
, boot_env
);
1438 bfa_ioc_poll_fwinit(ioc
);
1443 * If hardware initialization is in progress (initialized by other IOC),
1444 * just wait for an initialization completion interrupt.
1446 if (ioc_fwstate
== BFI_IOC_INITING
) {
1447 bfa_ioc_poll_fwinit(ioc
);
1452 * If IOC function is disabled and firmware version is same,
1453 * just re-enable IOC.
1455 if (ioc_fwstate
== BFI_IOC_DISABLED
|| ioc_fwstate
== BFI_IOC_OP
) {
1457 * When using MSI-X any pending firmware ready event should
1458 * be flushed. Otherwise MSI-X interrupts are not delivered.
1460 bfa_ioc_msgflush(ioc
);
1461 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FWREADY
);
1466 * Initialize the h/w for any other states.
1468 bfa_ioc_boot(ioc
, BFI_FWBOOT_TYPE_NORMAL
, boot_env
);
1469 bfa_ioc_poll_fwinit(ioc
);
1473 bfa_nw_ioc_timeout(void *ioc_arg
)
1475 struct bfa_ioc
*ioc
= (struct bfa_ioc
*) ioc_arg
;
1477 bfa_fsm_send_event(ioc
, IOC_E_TIMEOUT
);
1481 bfa_ioc_mbox_send(struct bfa_ioc
*ioc
, void *ioc_msg
, int len
)
1483 u32
*msgp
= (u32
*) ioc_msg
;
1486 BUG_ON(!(len
<= BFI_IOC_MSGLEN_MAX
));
1489 * first write msg to mailbox registers
1491 for (i
= 0; i
< len
/ sizeof(u32
); i
++)
1492 writel(cpu_to_le32(msgp
[i
]),
1493 ioc
->ioc_regs
.hfn_mbox
+ i
* sizeof(u32
));
1495 for (; i
< BFI_IOC_MSGLEN_MAX
/ sizeof(u32
); i
++)
1496 writel(0, ioc
->ioc_regs
.hfn_mbox
+ i
* sizeof(u32
));
1499 * write 1 to mailbox CMD to trigger LPU event
1501 writel(1, ioc
->ioc_regs
.hfn_mbox_cmd
);
1502 (void) readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
1506 bfa_ioc_send_enable(struct bfa_ioc
*ioc
)
1508 struct bfi_ioc_ctrl_req enable_req
;
1511 bfi_h2i_set(enable_req
.mh
, BFI_MC_IOC
, BFI_IOC_H2I_ENABLE_REQ
,
1512 bfa_ioc_portid(ioc
));
1513 enable_req
.clscode
= htons(ioc
->clscode
);
1514 do_gettimeofday(&tv
);
1515 enable_req
.tv_sec
= ntohl(tv
.tv_sec
);
1516 bfa_ioc_mbox_send(ioc
, &enable_req
, sizeof(struct bfi_ioc_ctrl_req
));
1520 bfa_ioc_send_disable(struct bfa_ioc
*ioc
)
1522 struct bfi_ioc_ctrl_req disable_req
;
1524 bfi_h2i_set(disable_req
.mh
, BFI_MC_IOC
, BFI_IOC_H2I_DISABLE_REQ
,
1525 bfa_ioc_portid(ioc
));
1526 bfa_ioc_mbox_send(ioc
, &disable_req
, sizeof(struct bfi_ioc_ctrl_req
));
1530 bfa_ioc_send_getattr(struct bfa_ioc
*ioc
)
1532 struct bfi_ioc_getattr_req attr_req
;
1534 bfi_h2i_set(attr_req
.mh
, BFI_MC_IOC
, BFI_IOC_H2I_GETATTR_REQ
,
1535 bfa_ioc_portid(ioc
));
1536 bfa_dma_be_addr_set(attr_req
.attr_addr
, ioc
->attr_dma
.pa
);
1537 bfa_ioc_mbox_send(ioc
, &attr_req
, sizeof(attr_req
));
1541 bfa_nw_ioc_hb_check(void *cbarg
)
1543 struct bfa_ioc
*ioc
= cbarg
;
1546 hb_count
= readl(ioc
->ioc_regs
.heartbeat
);
1547 if (ioc
->hb_count
== hb_count
) {
1548 bfa_ioc_recover(ioc
);
1551 ioc
->hb_count
= hb_count
;
1554 bfa_ioc_mbox_poll(ioc
);
1555 mod_timer(&ioc
->hb_timer
, jiffies
+
1556 msecs_to_jiffies(BFA_IOC_HB_TOV
));
1560 bfa_ioc_hb_monitor(struct bfa_ioc
*ioc
)
1562 ioc
->hb_count
= readl(ioc
->ioc_regs
.heartbeat
);
1563 mod_timer(&ioc
->hb_timer
, jiffies
+
1564 msecs_to_jiffies(BFA_IOC_HB_TOV
));
1568 bfa_ioc_hb_stop(struct bfa_ioc
*ioc
)
1570 del_timer(&ioc
->hb_timer
);
1575 * Initiate a full firmware download.
1578 bfa_ioc_download_fw(struct bfa_ioc
*ioc
, u32 boot_type
,
1589 * Initialize LMEM first before code download
1591 bfa_ioc_lmem_init(ioc
);
1593 fwimg
= bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc
), chunkno
);
1595 pgnum
= bfa_ioc_smem_pgnum(ioc
, loff
);
1597 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1599 for (i
= 0; i
< bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc
)); i
++) {
1600 if (BFA_IOC_FLASH_CHUNK_NO(i
) != chunkno
) {
1601 chunkno
= BFA_IOC_FLASH_CHUNK_NO(i
);
1602 fwimg
= bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc
),
1603 BFA_IOC_FLASH_CHUNK_ADDR(chunkno
));
1609 writel((swab32(fwimg
[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i
)])),
1610 ((ioc
->ioc_regs
.smem_page_start
) + (loff
)));
1612 loff
+= sizeof(u32
);
1615 * handle page offset wrap around
1617 loff
= PSS_SMEM_PGOFF(loff
);
1621 ioc
->ioc_regs
.host_page_num_fn
);
1625 writel(bfa_ioc_smem_pgnum(ioc
, 0),
1626 ioc
->ioc_regs
.host_page_num_fn
);
1629 * Set boot type, env and device mode at the end.
1631 asicmode
= BFI_FWBOOT_DEVMODE(ioc
->asic_gen
, ioc
->asic_mode
,
1632 ioc
->port0_mode
, ioc
->port1_mode
);
1633 writel(asicmode
, ((ioc
->ioc_regs
.smem_page_start
)
1634 + BFI_FWBOOT_DEVMODE_OFF
));
1635 writel(boot_type
, ((ioc
->ioc_regs
.smem_page_start
)
1636 + (BFI_FWBOOT_TYPE_OFF
)));
1637 writel(boot_env
, ((ioc
->ioc_regs
.smem_page_start
)
1638 + (BFI_FWBOOT_ENV_OFF
)));
1642 bfa_ioc_reset(struct bfa_ioc
*ioc
, bool force
)
1644 bfa_ioc_hwinit(ioc
, force
);
1648 * BFA ioc enable reply by firmware
1651 bfa_ioc_enable_reply(struct bfa_ioc
*ioc
, enum bfa_mode port_mode
,
1654 struct bfa_iocpf
*iocpf
= &ioc
->iocpf
;
1656 ioc
->port_mode
= ioc
->port_mode_cfg
= port_mode
;
1657 ioc
->ad_cap_bm
= cap_bm
;
1658 bfa_fsm_send_event(iocpf
, IOCPF_E_FWRSP_ENABLE
);
1663 * Update BFA configuration from firmware configuration.
1666 bfa_ioc_getattr_reply(struct bfa_ioc
*ioc
)
1668 struct bfi_ioc_attr
*attr
= ioc
->attr
;
1670 attr
->adapter_prop
= ntohl(attr
->adapter_prop
);
1671 attr
->card_type
= ntohl(attr
->card_type
);
1672 attr
->maxfrsize
= ntohs(attr
->maxfrsize
);
1674 bfa_fsm_send_event(ioc
, IOC_E_FWRSP_GETATTR
);
1678 * Attach time initialization of mbox logic.
1681 bfa_ioc_mbox_attach(struct bfa_ioc
*ioc
)
1683 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
1686 INIT_LIST_HEAD(&mod
->cmd_q
);
1687 for (mc
= 0; mc
< BFI_MC_MAX
; mc
++) {
1688 mod
->mbhdlr
[mc
].cbfn
= NULL
;
1689 mod
->mbhdlr
[mc
].cbarg
= ioc
->bfa
;
1694 * Mbox poll timer -- restarts any pending mailbox requests.
1697 bfa_ioc_mbox_poll(struct bfa_ioc
*ioc
)
1699 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
1700 struct bfa_mbox_cmd
*cmd
;
1701 bfa_mbox_cmd_cbfn_t cbfn
;
1706 * If no command pending, do nothing
1708 if (list_empty(&mod
->cmd_q
))
1712 * If previous command is not yet fetched by firmware, do nothing
1714 stat
= readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
1719 * Enqueue command to firmware.
1721 bfa_q_deq(&mod
->cmd_q
, &cmd
);
1722 bfa_ioc_mbox_send(ioc
, cmd
->msg
, sizeof(cmd
->msg
));
1725 * Give a callback to the client, indicating that the command is sent
1736 * Cleanup any pending requests.
1739 bfa_ioc_mbox_flush(struct bfa_ioc
*ioc
)
1741 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
1742 struct bfa_mbox_cmd
*cmd
;
1744 while (!list_empty(&mod
->cmd_q
))
1745 bfa_q_deq(&mod
->cmd_q
, &cmd
);
1749 * Read data from SMEM to host through PCI memmap
1751 * @param[in] ioc memory for IOC
1752 * @param[in] tbuf app memory to store data from smem
1753 * @param[in] soff smem offset
1754 * @param[in] sz size of smem in bytes
1757 bfa_nw_ioc_smem_read(struct bfa_ioc
*ioc
, void *tbuf
, u32 soff
, u32 sz
)
1759 u32 pgnum
, loff
, r32
;
1763 pgnum
= PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, soff
);
1764 loff
= PSS_SMEM_PGOFF(soff
);
1767 * Hold semaphore to serialize pll init and fwtrc.
1769 if (bfa_nw_ioc_sem_get(ioc
->ioc_regs
.ioc_init_sem_reg
) == 0)
1772 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1774 len
= sz
/sizeof(u32
);
1775 for (i
= 0; i
< len
; i
++) {
1776 r32
= swab32(readl((loff
) + (ioc
->ioc_regs
.smem_page_start
)));
1777 buf
[i
] = be32_to_cpu(r32
);
1778 loff
+= sizeof(u32
);
1781 * handle page offset wrap around
1783 loff
= PSS_SMEM_PGOFF(loff
);
1786 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1790 writel(PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, 0),
1791 ioc
->ioc_regs
.host_page_num_fn
);
1796 readl(ioc
->ioc_regs
.ioc_init_sem_reg
);
1797 writel(1, ioc
->ioc_regs
.ioc_init_sem_reg
);
1802 * Retrieve saved firmware trace from a prior IOC failure.
1805 bfa_nw_ioc_debug_fwtrc(struct bfa_ioc
*ioc
, void *trcdata
, int *trclen
)
1807 u32 loff
= BFI_IOC_TRC_OFF
+ BNA_DBG_FWTRC_LEN
* ioc
->port_id
;
1808 int tlen
, status
= 0;
1811 if (tlen
> BNA_DBG_FWTRC_LEN
)
1812 tlen
= BNA_DBG_FWTRC_LEN
;
1814 status
= bfa_nw_ioc_smem_read(ioc
, trcdata
, loff
, tlen
);
1820 * Save firmware trace if configured.
1823 bfa_nw_ioc_debug_save_ftrc(struct bfa_ioc
*ioc
)
1827 if (ioc
->dbg_fwsave_once
) {
1828 ioc
->dbg_fwsave_once
= 0;
1829 if (ioc
->dbg_fwsave_len
) {
1830 tlen
= ioc
->dbg_fwsave_len
;
1831 bfa_nw_ioc_debug_fwtrc(ioc
, ioc
->dbg_fwsave
, &tlen
);
1837 * Retrieve saved firmware trace from a prior IOC failure.
1840 bfa_nw_ioc_debug_fwsave(struct bfa_ioc
*ioc
, void *trcdata
, int *trclen
)
1844 if (ioc
->dbg_fwsave_len
== 0)
1845 return BFA_STATUS_ENOFSAVE
;
1848 if (tlen
> ioc
->dbg_fwsave_len
)
1849 tlen
= ioc
->dbg_fwsave_len
;
1851 memcpy(trcdata
, ioc
->dbg_fwsave
, tlen
);
1853 return BFA_STATUS_OK
;
1857 bfa_ioc_fail_notify(struct bfa_ioc
*ioc
)
1860 * Notify driver and common modules registered for notification.
1862 ioc
->cbfn
->hbfail_cbfn(ioc
->bfa
);
1863 bfa_ioc_event_notify(ioc
, BFA_IOC_E_FAILED
);
1864 bfa_nw_ioc_debug_save_ftrc(ioc
);
1868 * IOCPF to IOC interface
1871 bfa_ioc_pf_enabled(struct bfa_ioc
*ioc
)
1873 bfa_fsm_send_event(ioc
, IOC_E_ENABLED
);
1877 bfa_ioc_pf_disabled(struct bfa_ioc
*ioc
)
1879 bfa_fsm_send_event(ioc
, IOC_E_DISABLED
);
1883 bfa_ioc_pf_failed(struct bfa_ioc
*ioc
)
1885 bfa_fsm_send_event(ioc
, IOC_E_PFFAILED
);
1889 bfa_ioc_pf_hwfailed(struct bfa_ioc
*ioc
)
1891 bfa_fsm_send_event(ioc
, IOC_E_HWFAILED
);
1895 bfa_ioc_pf_fwmismatch(struct bfa_ioc
*ioc
)
1898 * Provide enable completion callback and AEN notification.
1900 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
1906 static enum bfa_status
1907 bfa_ioc_pll_init(struct bfa_ioc
*ioc
)
1910 * Hold semaphore so that nobody can access the chip during init.
1912 bfa_nw_ioc_sem_get(ioc
->ioc_regs
.ioc_init_sem_reg
);
1914 bfa_ioc_pll_init_asic(ioc
);
1916 ioc
->pllinit
= true;
1918 * release semaphore.
1920 bfa_nw_ioc_sem_release(ioc
->ioc_regs
.ioc_init_sem_reg
);
1922 return BFA_STATUS_OK
;
1926 * Interface used by diag module to do firmware boot with memory test
1927 * as the entry vector.
1930 bfa_ioc_boot(struct bfa_ioc
*ioc
, enum bfi_fwboot_type boot_type
,
1933 bfa_ioc_stats(ioc
, ioc_boots
);
1935 if (bfa_ioc_pll_init(ioc
) != BFA_STATUS_OK
)
1939 * Initialize IOC state of all functions on a chip reset.
1941 if (boot_type
== BFI_FWBOOT_TYPE_MEMTEST
) {
1942 writel(BFI_IOC_MEMTEST
, ioc
->ioc_regs
.ioc_fwstate
);
1943 writel(BFI_IOC_MEMTEST
, ioc
->ioc_regs
.alt_ioc_fwstate
);
1945 writel(BFI_IOC_INITING
, ioc
->ioc_regs
.ioc_fwstate
);
1946 writel(BFI_IOC_INITING
, ioc
->ioc_regs
.alt_ioc_fwstate
);
1949 bfa_ioc_msgflush(ioc
);
1950 bfa_ioc_download_fw(ioc
, boot_type
, boot_env
);
1951 bfa_ioc_lpu_start(ioc
);
1955 * Enable/disable IOC failure auto recovery.
1958 bfa_nw_ioc_auto_recover(bool auto_recover
)
1960 bfa_nw_auto_recover
= auto_recover
;
1964 bfa_ioc_msgget(struct bfa_ioc
*ioc
, void *mbmsg
)
1970 r32
= readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
1977 for (i
= 0; i
< (sizeof(union bfi_ioc_i2h_msg_u
) / sizeof(u32
));
1979 r32
= readl(ioc
->ioc_regs
.lpu_mbox
+
1981 msgp
[i
] = htonl(r32
);
1985 * turn off mailbox interrupt by clearing mailbox status
1987 writel(1, ioc
->ioc_regs
.lpu_mbox_cmd
);
1988 readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
1994 bfa_ioc_isr(struct bfa_ioc
*ioc
, struct bfi_mbmsg
*m
)
1996 union bfi_ioc_i2h_msg_u
*msg
;
1997 struct bfa_iocpf
*iocpf
= &ioc
->iocpf
;
1999 msg
= (union bfi_ioc_i2h_msg_u
*) m
;
2001 bfa_ioc_stats(ioc
, ioc_isrs
);
2003 switch (msg
->mh
.msg_id
) {
2004 case BFI_IOC_I2H_HBEAT
:
2007 case BFI_IOC_I2H_ENABLE_REPLY
:
2008 bfa_ioc_enable_reply(ioc
,
2009 (enum bfa_mode
)msg
->fw_event
.port_mode
,
2010 msg
->fw_event
.cap_bm
);
2013 case BFI_IOC_I2H_DISABLE_REPLY
:
2014 bfa_fsm_send_event(iocpf
, IOCPF_E_FWRSP_DISABLE
);
2017 case BFI_IOC_I2H_GETATTR_REPLY
:
2018 bfa_ioc_getattr_reply(ioc
);
2027 * IOC attach time initialization and setup.
2029 * @param[in] ioc memory for IOC
2030 * @param[in] bfa driver instance structure
2033 bfa_nw_ioc_attach(struct bfa_ioc
*ioc
, void *bfa
, struct bfa_ioc_cbfn
*cbfn
)
2037 ioc
->fcmode
= false;
2038 ioc
->pllinit
= false;
2039 ioc
->dbg_fwsave_once
= true;
2040 ioc
->iocpf
.ioc
= ioc
;
2042 bfa_ioc_mbox_attach(ioc
);
2043 INIT_LIST_HEAD(&ioc
->notify_q
);
2045 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
2046 bfa_fsm_send_event(ioc
, IOC_E_RESET
);
2050 * Driver detach time IOC cleanup.
2053 bfa_nw_ioc_detach(struct bfa_ioc
*ioc
)
2055 bfa_fsm_send_event(ioc
, IOC_E_DETACH
);
2057 /* Done with detach, empty the notify_q. */
2058 INIT_LIST_HEAD(&ioc
->notify_q
);
2062 * Setup IOC PCI properties.
2064 * @param[in] pcidev PCI device information for this IOC
2067 bfa_nw_ioc_pci_init(struct bfa_ioc
*ioc
, struct bfa_pcidev
*pcidev
,
2068 enum bfi_pcifn_class clscode
)
2070 ioc
->clscode
= clscode
;
2071 ioc
->pcidev
= *pcidev
;
2074 * Initialize IOC and device personality
2076 ioc
->port0_mode
= ioc
->port1_mode
= BFI_PORT_MODE_FC
;
2077 ioc
->asic_mode
= BFI_ASIC_MODE_FC
;
2079 switch (pcidev
->device_id
) {
2080 case PCI_DEVICE_ID_BROCADE_CT
:
2081 ioc
->asic_gen
= BFI_ASIC_GEN_CT
;
2082 ioc
->port0_mode
= ioc
->port1_mode
= BFI_PORT_MODE_ETH
;
2083 ioc
->asic_mode
= BFI_ASIC_MODE_ETH
;
2084 ioc
->port_mode
= ioc
->port_mode_cfg
= BFA_MODE_CNA
;
2085 ioc
->ad_cap_bm
= BFA_CM_CNA
;
2088 case BFA_PCI_DEVICE_ID_CT2
:
2089 ioc
->asic_gen
= BFI_ASIC_GEN_CT2
;
2090 if (clscode
== BFI_PCIFN_CLASS_FC
&&
2091 pcidev
->ssid
== BFA_PCI_CT2_SSID_FC
) {
2092 ioc
->asic_mode
= BFI_ASIC_MODE_FC16
;
2094 ioc
->port_mode
= ioc
->port_mode_cfg
= BFA_MODE_HBA
;
2095 ioc
->ad_cap_bm
= BFA_CM_HBA
;
2097 ioc
->port0_mode
= ioc
->port1_mode
= BFI_PORT_MODE_ETH
;
2098 ioc
->asic_mode
= BFI_ASIC_MODE_ETH
;
2099 if (pcidev
->ssid
== BFA_PCI_CT2_SSID_FCoE
) {
2101 ioc
->port_mode_cfg
= BFA_MODE_CNA
;
2102 ioc
->ad_cap_bm
= BFA_CM_CNA
;
2105 ioc
->port_mode_cfg
= BFA_MODE_NIC
;
2106 ioc
->ad_cap_bm
= BFA_CM_NIC
;
2116 * Set asic specific interfaces.
2118 if (ioc
->asic_gen
== BFI_ASIC_GEN_CT
)
2119 bfa_nw_ioc_set_ct_hwif(ioc
);
2121 WARN_ON(ioc
->asic_gen
!= BFI_ASIC_GEN_CT2
);
2122 bfa_nw_ioc_set_ct2_hwif(ioc
);
2123 bfa_nw_ioc_ct2_poweron(ioc
);
2126 bfa_ioc_map_port(ioc
);
2127 bfa_ioc_reg_init(ioc
);
2131 * Initialize IOC dma memory
2133 * @param[in] dm_kva kernel virtual address of IOC dma memory
2134 * @param[in] dm_pa physical address of IOC dma memory
2137 bfa_nw_ioc_mem_claim(struct bfa_ioc
*ioc
, u8
*dm_kva
, u64 dm_pa
)
2140 * dma memory for firmware attribute
2142 ioc
->attr_dma
.kva
= dm_kva
;
2143 ioc
->attr_dma
.pa
= dm_pa
;
2144 ioc
->attr
= (struct bfi_ioc_attr
*) dm_kva
;
2148 * Return size of dma memory required.
2151 bfa_nw_ioc_meminfo(void)
2153 return roundup(sizeof(struct bfi_ioc_attr
), BFA_DMA_ALIGN_SZ
);
2157 bfa_nw_ioc_enable(struct bfa_ioc
*ioc
)
2159 bfa_ioc_stats(ioc
, ioc_enables
);
2160 ioc
->dbg_fwsave_once
= true;
2162 bfa_fsm_send_event(ioc
, IOC_E_ENABLE
);
2166 bfa_nw_ioc_disable(struct bfa_ioc
*ioc
)
2168 bfa_ioc_stats(ioc
, ioc_disables
);
2169 bfa_fsm_send_event(ioc
, IOC_E_DISABLE
);
2173 * Initialize memory for saving firmware trace.
2176 bfa_nw_ioc_debug_memclaim(struct bfa_ioc
*ioc
, void *dbg_fwsave
)
2178 ioc
->dbg_fwsave
= dbg_fwsave
;
2179 ioc
->dbg_fwsave_len
= ioc
->iocpf
.auto_recover
? BNA_DBG_FWTRC_LEN
: 0;
2183 bfa_ioc_smem_pgnum(struct bfa_ioc
*ioc
, u32 fmaddr
)
2185 return PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, fmaddr
);
2189 * Register mailbox message handler function, to be called by common modules
2192 bfa_nw_ioc_mbox_regisr(struct bfa_ioc
*ioc
, enum bfi_mclass mc
,
2193 bfa_ioc_mbox_mcfunc_t cbfn
, void *cbarg
)
2195 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
2197 mod
->mbhdlr
[mc
].cbfn
= cbfn
;
2198 mod
->mbhdlr
[mc
].cbarg
= cbarg
;
2202 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2203 * Responsibility of caller to serialize
2205 * @param[in] ioc IOC instance
2206 * @param[i] cmd Mailbox command
2209 bfa_nw_ioc_mbox_queue(struct bfa_ioc
*ioc
, struct bfa_mbox_cmd
*cmd
,
2210 bfa_mbox_cmd_cbfn_t cbfn
, void *cbarg
)
2212 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
2219 * If a previous command is pending, queue new command
2221 if (!list_empty(&mod
->cmd_q
)) {
2222 list_add_tail(&cmd
->qe
, &mod
->cmd_q
);
2227 * If mailbox is busy, queue command for poll timer
2229 stat
= readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
2231 list_add_tail(&cmd
->qe
, &mod
->cmd_q
);
2236 * mailbox is free -- queue command to firmware
2238 bfa_ioc_mbox_send(ioc
, cmd
->msg
, sizeof(cmd
->msg
));
2244 * Handle mailbox interrupts
2247 bfa_nw_ioc_mbox_isr(struct bfa_ioc
*ioc
)
2249 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
2253 if (bfa_ioc_msgget(ioc
, &m
)) {
2255 * Treat IOC message class as special.
2257 mc
= m
.mh
.msg_class
;
2258 if (mc
== BFI_MC_IOC
) {
2259 bfa_ioc_isr(ioc
, &m
);
2263 if ((mc
>= BFI_MC_MAX
) || (mod
->mbhdlr
[mc
].cbfn
== NULL
))
2266 mod
->mbhdlr
[mc
].cbfn(mod
->mbhdlr
[mc
].cbarg
, &m
);
2269 bfa_ioc_lpu_read_stat(ioc
);
2272 * Try to send pending mailbox commands
2274 bfa_ioc_mbox_poll(ioc
);
2278 bfa_nw_ioc_error_isr(struct bfa_ioc
*ioc
)
2280 bfa_ioc_stats(ioc
, ioc_hbfails
);
2281 bfa_ioc_stats_hb_count(ioc
, ioc
->hb_count
);
2282 bfa_fsm_send_event(ioc
, IOC_E_HWERROR
);
2286 * return true if IOC is disabled
2289 bfa_nw_ioc_is_disabled(struct bfa_ioc
*ioc
)
2291 return bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_disabling
) ||
2292 bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_disabled
);
2296 * return true if IOC is operational
2299 bfa_nw_ioc_is_operational(struct bfa_ioc
*ioc
)
2301 return bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_op
);
2305 * Add to IOC heartbeat failure notification queue. To be used by common
2306 * modules such as cee, port, diag.
2309 bfa_nw_ioc_notify_register(struct bfa_ioc
*ioc
,
2310 struct bfa_ioc_notify
*notify
)
2312 list_add_tail(¬ify
->qe
, &ioc
->notify_q
);
2315 #define BFA_MFG_NAME "Brocade"
2317 bfa_ioc_get_adapter_attr(struct bfa_ioc
*ioc
,
2318 struct bfa_adapter_attr
*ad_attr
)
2320 struct bfi_ioc_attr
*ioc_attr
;
2322 ioc_attr
= ioc
->attr
;
2324 bfa_ioc_get_adapter_serial_num(ioc
, ad_attr
->serial_num
);
2325 bfa_ioc_get_adapter_fw_ver(ioc
, ad_attr
->fw_ver
);
2326 bfa_ioc_get_adapter_optrom_ver(ioc
, ad_attr
->optrom_ver
);
2327 bfa_ioc_get_adapter_manufacturer(ioc
, ad_attr
->manufacturer
);
2328 memcpy(&ad_attr
->vpd
, &ioc_attr
->vpd
,
2329 sizeof(struct bfa_mfg_vpd
));
2331 ad_attr
->nports
= bfa_ioc_get_nports(ioc
);
2332 ad_attr
->max_speed
= bfa_ioc_speed_sup(ioc
);
2334 bfa_ioc_get_adapter_model(ioc
, ad_attr
->model
);
2335 /* For now, model descr uses same model string */
2336 bfa_ioc_get_adapter_model(ioc
, ad_attr
->model_descr
);
2338 ad_attr
->card_type
= ioc_attr
->card_type
;
2339 ad_attr
->is_mezz
= bfa_mfg_is_mezz(ioc_attr
->card_type
);
2341 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr
->adapter_prop
))
2342 ad_attr
->prototype
= 1;
2344 ad_attr
->prototype
= 0;
2346 ad_attr
->pwwn
= bfa_ioc_get_pwwn(ioc
);
2347 ad_attr
->mac
= bfa_nw_ioc_get_mac(ioc
);
2349 ad_attr
->pcie_gen
= ioc_attr
->pcie_gen
;
2350 ad_attr
->pcie_lanes
= ioc_attr
->pcie_lanes
;
2351 ad_attr
->pcie_lanes_orig
= ioc_attr
->pcie_lanes_orig
;
2352 ad_attr
->asic_rev
= ioc_attr
->asic_rev
;
2354 bfa_ioc_get_pci_chip_rev(ioc
, ad_attr
->hw_ver
);
2357 static enum bfa_ioc_type
2358 bfa_ioc_get_type(struct bfa_ioc
*ioc
)
2360 if (ioc
->clscode
== BFI_PCIFN_CLASS_ETH
)
2361 return BFA_IOC_TYPE_LL
;
2363 BUG_ON(!(ioc
->clscode
== BFI_PCIFN_CLASS_FC
));
2365 return (ioc
->attr
->port_mode
== BFI_PORT_MODE_FC
)
2366 ? BFA_IOC_TYPE_FC
: BFA_IOC_TYPE_FCoE
;
2370 bfa_ioc_get_adapter_serial_num(struct bfa_ioc
*ioc
, char *serial_num
)
2372 memset(serial_num
, 0, BFA_ADAPTER_SERIAL_NUM_LEN
);
2374 (void *)ioc
->attr
->brcd_serialnum
,
2375 BFA_ADAPTER_SERIAL_NUM_LEN
);
2379 bfa_ioc_get_adapter_fw_ver(struct bfa_ioc
*ioc
, char *fw_ver
)
2381 memset(fw_ver
, 0, BFA_VERSION_LEN
);
2382 memcpy(fw_ver
, ioc
->attr
->fw_version
, BFA_VERSION_LEN
);
2386 bfa_ioc_get_pci_chip_rev(struct bfa_ioc
*ioc
, char *chip_rev
)
2388 BUG_ON(!(chip_rev
));
2390 memset(chip_rev
, 0, BFA_IOC_CHIP_REV_LEN
);
2396 chip_rev
[4] = ioc
->attr
->asic_rev
;
2401 bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc
*ioc
, char *optrom_ver
)
2403 memset(optrom_ver
, 0, BFA_VERSION_LEN
);
2404 memcpy(optrom_ver
, ioc
->attr
->optrom_version
,
2409 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc
*ioc
, char *manufacturer
)
2411 memset(manufacturer
, 0, BFA_ADAPTER_MFG_NAME_LEN
);
2412 memcpy(manufacturer
, BFA_MFG_NAME
, BFA_ADAPTER_MFG_NAME_LEN
);
2416 bfa_ioc_get_adapter_model(struct bfa_ioc
*ioc
, char *model
)
2418 struct bfi_ioc_attr
*ioc_attr
;
2421 memset(model
, 0, BFA_ADAPTER_MODEL_NAME_LEN
);
2423 ioc_attr
= ioc
->attr
;
2425 snprintf(model
, BFA_ADAPTER_MODEL_NAME_LEN
, "%s-%u",
2426 BFA_MFG_NAME
, ioc_attr
->card_type
);
2429 static enum bfa_ioc_state
2430 bfa_ioc_get_state(struct bfa_ioc
*ioc
)
2432 enum bfa_iocpf_state iocpf_st
;
2433 enum bfa_ioc_state ioc_st
= bfa_sm_to_state(ioc_sm_table
, ioc
->fsm
);
2435 if (ioc_st
== BFA_IOC_ENABLING
||
2436 ioc_st
== BFA_IOC_FAIL
|| ioc_st
== BFA_IOC_INITFAIL
) {
2438 iocpf_st
= bfa_sm_to_state(iocpf_sm_table
, ioc
->iocpf
.fsm
);
2441 case BFA_IOCPF_SEMWAIT
:
2442 ioc_st
= BFA_IOC_SEMWAIT
;
2445 case BFA_IOCPF_HWINIT
:
2446 ioc_st
= BFA_IOC_HWINIT
;
2449 case BFA_IOCPF_FWMISMATCH
:
2450 ioc_st
= BFA_IOC_FWMISMATCH
;
2453 case BFA_IOCPF_FAIL
:
2454 ioc_st
= BFA_IOC_FAIL
;
2457 case BFA_IOCPF_INITFAIL
:
2458 ioc_st
= BFA_IOC_INITFAIL
;
2469 bfa_nw_ioc_get_attr(struct bfa_ioc
*ioc
, struct bfa_ioc_attr
*ioc_attr
)
2471 memset((void *)ioc_attr
, 0, sizeof(struct bfa_ioc_attr
));
2473 ioc_attr
->state
= bfa_ioc_get_state(ioc
);
2474 ioc_attr
->port_id
= ioc
->port_id
;
2475 ioc_attr
->port_mode
= ioc
->port_mode
;
2477 ioc_attr
->port_mode_cfg
= ioc
->port_mode_cfg
;
2478 ioc_attr
->cap_bm
= ioc
->ad_cap_bm
;
2480 ioc_attr
->ioc_type
= bfa_ioc_get_type(ioc
);
2482 bfa_ioc_get_adapter_attr(ioc
, &ioc_attr
->adapter_attr
);
2484 ioc_attr
->pci_attr
.device_id
= ioc
->pcidev
.device_id
;
2485 ioc_attr
->pci_attr
.pcifn
= ioc
->pcidev
.pci_func
;
2486 bfa_ioc_get_pci_chip_rev(ioc
, ioc_attr
->pci_attr
.chip_rev
);
2493 bfa_ioc_get_pwwn(struct bfa_ioc
*ioc
)
2495 return ioc
->attr
->pwwn
;
2499 bfa_nw_ioc_get_mac(struct bfa_ioc
*ioc
)
2501 return ioc
->attr
->mac
;
2505 * Firmware failure detected. Start recovery actions.
2508 bfa_ioc_recover(struct bfa_ioc
*ioc
)
2510 pr_crit("Heart Beat of IOC has failed\n");
2511 bfa_ioc_stats(ioc
, ioc_hbfails
);
2512 bfa_ioc_stats_hb_count(ioc
, ioc
->hb_count
);
2513 bfa_fsm_send_event(ioc
, IOC_E_HBFAIL
);
2517 bfa_ioc_check_attr_wwns(struct bfa_ioc
*ioc
)
2519 if (bfa_ioc_get_type(ioc
) == BFA_IOC_TYPE_LL
)
2524 * @dg hal_iocpf_pvt BFA IOC PF private functions
2529 bfa_iocpf_enable(struct bfa_ioc
*ioc
)
2531 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_ENABLE
);
2535 bfa_iocpf_disable(struct bfa_ioc
*ioc
)
2537 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_DISABLE
);
2541 bfa_iocpf_fail(struct bfa_ioc
*ioc
)
2543 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FAIL
);
2547 bfa_iocpf_initfail(struct bfa_ioc
*ioc
)
2549 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_INITFAIL
);
2553 bfa_iocpf_getattrfail(struct bfa_ioc
*ioc
)
2555 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_GETATTRFAIL
);
2559 bfa_iocpf_stop(struct bfa_ioc
*ioc
)
2561 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_STOP
);
2565 bfa_nw_iocpf_timeout(void *ioc_arg
)
2567 struct bfa_ioc
*ioc
= (struct bfa_ioc
*) ioc_arg
;
2568 enum bfa_iocpf_state iocpf_st
;
2570 iocpf_st
= bfa_sm_to_state(iocpf_sm_table
, ioc
->iocpf
.fsm
);
2572 if (iocpf_st
== BFA_IOCPF_HWINIT
)
2573 bfa_ioc_poll_fwinit(ioc
);
2575 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_TIMEOUT
);
2579 bfa_nw_iocpf_sem_timeout(void *ioc_arg
)
2581 struct bfa_ioc
*ioc
= (struct bfa_ioc
*) ioc_arg
;
2583 bfa_ioc_hw_sem_get(ioc
);
2587 bfa_ioc_poll_fwinit(struct bfa_ioc
*ioc
)
2589 u32 fwstate
= readl(ioc
->ioc_regs
.ioc_fwstate
);
2591 if (fwstate
== BFI_IOC_DISABLED
) {
2592 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FWREADY
);
2596 if (ioc
->iocpf
.poll_time
>= BFA_IOC_TOV
) {
2597 bfa_nw_iocpf_timeout(ioc
);
2599 ioc
->iocpf
.poll_time
+= BFA_IOC_POLL_TOV
;
2600 mod_timer(&ioc
->iocpf_timer
, jiffies
+
2601 msecs_to_jiffies(BFA_IOC_POLL_TOV
));
2606 * Flash module specific
2610 * FLASH DMA buffer should be big enough to hold both MFG block and
2611 * asic block(64k) at the same time and also should be 2k aligned to
2612 * avoid write segement to cross sector boundary.
2614 #define BFA_FLASH_SEG_SZ 2048
2615 #define BFA_FLASH_DMA_BUF_SZ \
2616 roundup(0x010000 + sizeof(struct bfa_mfg_block), BFA_FLASH_SEG_SZ)
2619 bfa_flash_cb(struct bfa_flash
*flash
)
2623 flash
->cbfn(flash
->cbarg
, flash
->status
);
2627 bfa_flash_notify(void *cbarg
, enum bfa_ioc_event event
)
2629 struct bfa_flash
*flash
= cbarg
;
2632 case BFA_IOC_E_DISABLED
:
2633 case BFA_IOC_E_FAILED
:
2634 if (flash
->op_busy
) {
2635 flash
->status
= BFA_STATUS_IOC_FAILURE
;
2636 flash
->cbfn(flash
->cbarg
, flash
->status
);
2646 * Send flash write request.
2648 * @param[in] cbarg - callback argument
2651 bfa_flash_write_send(struct bfa_flash
*flash
)
2653 struct bfi_flash_write_req
*msg
=
2654 (struct bfi_flash_write_req
*) flash
->mb
.msg
;
2657 msg
->type
= be32_to_cpu(flash
->type
);
2658 msg
->instance
= flash
->instance
;
2659 msg
->offset
= be32_to_cpu(flash
->addr_off
+ flash
->offset
);
2660 len
= (flash
->residue
< BFA_FLASH_DMA_BUF_SZ
) ?
2661 flash
->residue
: BFA_FLASH_DMA_BUF_SZ
;
2662 msg
->length
= be32_to_cpu(len
);
2664 /* indicate if it's the last msg of the whole write operation */
2665 msg
->last
= (len
== flash
->residue
) ? 1 : 0;
2667 bfi_h2i_set(msg
->mh
, BFI_MC_FLASH
, BFI_FLASH_H2I_WRITE_REQ
,
2668 bfa_ioc_portid(flash
->ioc
));
2669 bfa_alen_set(&msg
->alen
, len
, flash
->dbuf_pa
);
2670 memcpy(flash
->dbuf_kva
, flash
->ubuf
+ flash
->offset
, len
);
2671 bfa_nw_ioc_mbox_queue(flash
->ioc
, &flash
->mb
, NULL
, NULL
);
2673 flash
->residue
-= len
;
2674 flash
->offset
+= len
;
2678 * Send flash read request.
2680 * @param[in] cbarg - callback argument
2683 bfa_flash_read_send(void *cbarg
)
2685 struct bfa_flash
*flash
= cbarg
;
2686 struct bfi_flash_read_req
*msg
=
2687 (struct bfi_flash_read_req
*) flash
->mb
.msg
;
2690 msg
->type
= be32_to_cpu(flash
->type
);
2691 msg
->instance
= flash
->instance
;
2692 msg
->offset
= be32_to_cpu(flash
->addr_off
+ flash
->offset
);
2693 len
= (flash
->residue
< BFA_FLASH_DMA_BUF_SZ
) ?
2694 flash
->residue
: BFA_FLASH_DMA_BUF_SZ
;
2695 msg
->length
= be32_to_cpu(len
);
2696 bfi_h2i_set(msg
->mh
, BFI_MC_FLASH
, BFI_FLASH_H2I_READ_REQ
,
2697 bfa_ioc_portid(flash
->ioc
));
2698 bfa_alen_set(&msg
->alen
, len
, flash
->dbuf_pa
);
2699 bfa_nw_ioc_mbox_queue(flash
->ioc
, &flash
->mb
, NULL
, NULL
);
2703 * Process flash response messages upon receiving interrupts.
2705 * @param[in] flasharg - flash structure
2706 * @param[in] msg - message structure
2709 bfa_flash_intr(void *flasharg
, struct bfi_mbmsg
*msg
)
2711 struct bfa_flash
*flash
= flasharg
;
2715 struct bfi_flash_query_rsp
*query
;
2716 struct bfi_flash_write_rsp
*write
;
2717 struct bfi_flash_read_rsp
*read
;
2718 struct bfi_mbmsg
*msg
;
2723 /* receiving response after ioc failure */
2724 if (!flash
->op_busy
&& msg
->mh
.msg_id
!= BFI_FLASH_I2H_EVENT
)
2727 switch (msg
->mh
.msg_id
) {
2728 case BFI_FLASH_I2H_QUERY_RSP
:
2729 status
= be32_to_cpu(m
.query
->status
);
2730 if (status
== BFA_STATUS_OK
) {
2732 struct bfa_flash_attr
*attr
, *f
;
2734 attr
= (struct bfa_flash_attr
*) flash
->ubuf
;
2735 f
= (struct bfa_flash_attr
*) flash
->dbuf_kva
;
2736 attr
->status
= be32_to_cpu(f
->status
);
2737 attr
->npart
= be32_to_cpu(f
->npart
);
2738 for (i
= 0; i
< attr
->npart
; i
++) {
2739 attr
->part
[i
].part_type
=
2740 be32_to_cpu(f
->part
[i
].part_type
);
2741 attr
->part
[i
].part_instance
=
2742 be32_to_cpu(f
->part
[i
].part_instance
);
2743 attr
->part
[i
].part_off
=
2744 be32_to_cpu(f
->part
[i
].part_off
);
2745 attr
->part
[i
].part_size
=
2746 be32_to_cpu(f
->part
[i
].part_size
);
2747 attr
->part
[i
].part_len
=
2748 be32_to_cpu(f
->part
[i
].part_len
);
2749 attr
->part
[i
].part_status
=
2750 be32_to_cpu(f
->part
[i
].part_status
);
2753 flash
->status
= status
;
2754 bfa_flash_cb(flash
);
2756 case BFI_FLASH_I2H_WRITE_RSP
:
2757 status
= be32_to_cpu(m
.write
->status
);
2758 if (status
!= BFA_STATUS_OK
|| flash
->residue
== 0) {
2759 flash
->status
= status
;
2760 bfa_flash_cb(flash
);
2762 bfa_flash_write_send(flash
);
2764 case BFI_FLASH_I2H_READ_RSP
:
2765 status
= be32_to_cpu(m
.read
->status
);
2766 if (status
!= BFA_STATUS_OK
) {
2767 flash
->status
= status
;
2768 bfa_flash_cb(flash
);
2770 u32 len
= be32_to_cpu(m
.read
->length
);
2771 memcpy(flash
->ubuf
+ flash
->offset
,
2772 flash
->dbuf_kva
, len
);
2773 flash
->residue
-= len
;
2774 flash
->offset
+= len
;
2775 if (flash
->residue
== 0) {
2776 flash
->status
= status
;
2777 bfa_flash_cb(flash
);
2779 bfa_flash_read_send(flash
);
2782 case BFI_FLASH_I2H_BOOT_VER_RSP
:
2783 case BFI_FLASH_I2H_EVENT
:
2791 * Flash memory info API.
2794 bfa_nw_flash_meminfo(void)
2796 return roundup(BFA_FLASH_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
2802 * @param[in] flash - flash structure
2803 * @param[in] ioc - ioc structure
2804 * @param[in] dev - device structure
2807 bfa_nw_flash_attach(struct bfa_flash
*flash
, struct bfa_ioc
*ioc
, void *dev
)
2811 flash
->cbarg
= NULL
;
2814 bfa_nw_ioc_mbox_regisr(flash
->ioc
, BFI_MC_FLASH
, bfa_flash_intr
, flash
);
2815 bfa_q_qe_init(&flash
->ioc_notify
);
2816 bfa_ioc_notify_init(&flash
->ioc_notify
, bfa_flash_notify
, flash
);
2817 list_add_tail(&flash
->ioc_notify
.qe
, &flash
->ioc
->notify_q
);
2821 * Claim memory for flash
2823 * @param[in] flash - flash structure
2824 * @param[in] dm_kva - pointer to virtual memory address
2825 * @param[in] dm_pa - physical memory address
2828 bfa_nw_flash_memclaim(struct bfa_flash
*flash
, u8
*dm_kva
, u64 dm_pa
)
2830 flash
->dbuf_kva
= dm_kva
;
2831 flash
->dbuf_pa
= dm_pa
;
2832 memset(flash
->dbuf_kva
, 0, BFA_FLASH_DMA_BUF_SZ
);
2833 dm_kva
+= roundup(BFA_FLASH_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
2834 dm_pa
+= roundup(BFA_FLASH_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
2838 * Get flash attribute.
2840 * @param[in] flash - flash structure
2841 * @param[in] attr - flash attribute structure
2842 * @param[in] cbfn - callback function
2843 * @param[in] cbarg - callback argument
2848 bfa_nw_flash_get_attr(struct bfa_flash
*flash
, struct bfa_flash_attr
*attr
,
2849 bfa_cb_flash cbfn
, void *cbarg
)
2851 struct bfi_flash_query_req
*msg
=
2852 (struct bfi_flash_query_req
*) flash
->mb
.msg
;
2854 if (!bfa_nw_ioc_is_operational(flash
->ioc
))
2855 return BFA_STATUS_IOC_NON_OP
;
2858 return BFA_STATUS_DEVBUSY
;
2862 flash
->cbarg
= cbarg
;
2863 flash
->ubuf
= (u8
*) attr
;
2865 bfi_h2i_set(msg
->mh
, BFI_MC_FLASH
, BFI_FLASH_H2I_QUERY_REQ
,
2866 bfa_ioc_portid(flash
->ioc
));
2867 bfa_alen_set(&msg
->alen
, sizeof(struct bfa_flash_attr
), flash
->dbuf_pa
);
2868 bfa_nw_ioc_mbox_queue(flash
->ioc
, &flash
->mb
, NULL
, NULL
);
2870 return BFA_STATUS_OK
;
2874 * Update flash partition.
2876 * @param[in] flash - flash structure
2877 * @param[in] type - flash partition type
2878 * @param[in] instance - flash partition instance
2879 * @param[in] buf - update data buffer
2880 * @param[in] len - data buffer length
2881 * @param[in] offset - offset relative to the partition starting address
2882 * @param[in] cbfn - callback function
2883 * @param[in] cbarg - callback argument
2888 bfa_nw_flash_update_part(struct bfa_flash
*flash
, u32 type
, u8 instance
,
2889 void *buf
, u32 len
, u32 offset
,
2890 bfa_cb_flash cbfn
, void *cbarg
)
2892 if (!bfa_nw_ioc_is_operational(flash
->ioc
))
2893 return BFA_STATUS_IOC_NON_OP
;
2896 * 'len' must be in word (4-byte) boundary
2898 if (!len
|| (len
& 0x03))
2899 return BFA_STATUS_FLASH_BAD_LEN
;
2901 if (type
== BFA_FLASH_PART_MFG
)
2902 return BFA_STATUS_EINVAL
;
2905 return BFA_STATUS_DEVBUSY
;
2909 flash
->cbarg
= cbarg
;
2911 flash
->instance
= instance
;
2912 flash
->residue
= len
;
2914 flash
->addr_off
= offset
;
2917 bfa_flash_write_send(flash
);
2919 return BFA_STATUS_OK
;
2923 * Read flash partition.
2925 * @param[in] flash - flash structure
2926 * @param[in] type - flash partition type
2927 * @param[in] instance - flash partition instance
2928 * @param[in] buf - read data buffer
2929 * @param[in] len - data buffer length
2930 * @param[in] offset - offset relative to the partition starting address
2931 * @param[in] cbfn - callback function
2932 * @param[in] cbarg - callback argument
2937 bfa_nw_flash_read_part(struct bfa_flash
*flash
, u32 type
, u8 instance
,
2938 void *buf
, u32 len
, u32 offset
,
2939 bfa_cb_flash cbfn
, void *cbarg
)
2941 if (!bfa_nw_ioc_is_operational(flash
->ioc
))
2942 return BFA_STATUS_IOC_NON_OP
;
2945 * 'len' must be in word (4-byte) boundary
2947 if (!len
|| (len
& 0x03))
2948 return BFA_STATUS_FLASH_BAD_LEN
;
2951 return BFA_STATUS_DEVBUSY
;
2955 flash
->cbarg
= cbarg
;
2957 flash
->instance
= instance
;
2958 flash
->residue
= len
;
2960 flash
->addr_off
= offset
;
2963 bfa_flash_read_send(flash
);
2965 return BFA_STATUS_OK
;