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_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
,
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
,
88 static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc
*ioc
,
90 static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc
*ioc
,
92 static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc
*ioc
,
94 static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc
*ioc
,
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
);
100 * IOC state machine definitions/declarations
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
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 */
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
,
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
,
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
},
223 * Beginning state. IOC uninit state.
226 bfa_ioc_sm_uninit_entry(struct bfa_ioc
*ioc
)
231 * IOC is in uninit state.
234 bfa_ioc_sm_uninit(struct bfa_ioc
*ioc
, enum ioc_event event
)
238 bfa_fsm_set_state(ioc
, bfa_ioc_sm_reset
);
247 * Reset entry actions -- initialize state machine
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.
259 bfa_ioc_sm_reset(struct bfa_ioc
*ioc
, enum ioc_event event
)
263 bfa_fsm_set_state(ioc
, bfa_ioc_sm_enabling
);
267 bfa_ioc_disable_comp(ioc
);
271 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
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.
290 bfa_ioc_sm_enabling(struct bfa_ioc
*ioc
, enum ioc_event event
)
294 bfa_fsm_set_state(ioc
, bfa_ioc_sm_getattr
);
298 /* !!! fall through !!! */
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
);
307 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
308 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
312 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
316 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
329 * Semaphore should be acquired for version check.
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.
343 bfa_ioc_sm_getattr(struct bfa_ioc
*ioc
, enum ioc_event 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
);
355 del_timer(&ioc
->ioc_timer
);
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
);
365 del_timer(&ioc
->ioc_timer
);
366 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
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
);
385 bfa_ioc_sm_op(struct bfa_ioc
*ioc
, enum ioc_event event
)
392 bfa_ioc_hb_stop(ioc
);
393 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
398 bfa_ioc_hb_stop(ioc
);
399 /* !!! fall through !!! */
401 if (ioc
->iocpf
.auto_recover
)
402 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail_retry
);
404 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
406 bfa_ioc_fail_notify(ioc
);
408 if (event
!= IOC_E_PFFAILED
)
418 bfa_ioc_sm_disabling_entry(struct bfa_ioc
*ioc
)
420 bfa_iocpf_disable(ioc
);
424 * IOC is being disabled
427 bfa_ioc_sm_disabling(struct bfa_ioc
*ioc
, enum ioc_event event
)
431 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabled
);
436 * No state change. Will move to disabled state
437 * after iocpf sm completes failure processing and
438 * moves to disabled state.
444 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
445 bfa_ioc_disable_comp(ioc
);
454 * IOC disable completion entry.
457 bfa_ioc_sm_disabled_entry(struct bfa_ioc
*ioc
)
459 bfa_ioc_disable_comp(ioc
);
463 bfa_ioc_sm_disabled(struct bfa_ioc
*ioc
, enum ioc_event event
)
467 bfa_fsm_set_state(ioc
, bfa_ioc_sm_enabling
);
471 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
475 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
485 bfa_ioc_sm_fail_retry_entry(struct bfa_ioc
*ioc
)
490 * Hardware initialization retry.
493 bfa_ioc_sm_fail_retry(struct bfa_ioc
*ioc
, enum ioc_event event
)
497 bfa_fsm_set_state(ioc
, bfa_ioc_sm_getattr
);
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
);
512 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
513 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
520 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
524 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
534 bfa_ioc_sm_fail_entry(struct bfa_ioc
*ioc
)
542 bfa_ioc_sm_fail(struct bfa_ioc
*ioc
, enum ioc_event event
)
546 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
550 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
554 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
559 /* HB failure notification, ignore. */
568 bfa_ioc_sm_hwfail_entry(struct bfa_ioc
*ioc
)
576 bfa_ioc_sm_hwfail(struct bfa_ioc
*ioc
, enum ioc_event event
)
581 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
585 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
589 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
598 * IOCPF State Machine
602 * Reset entry actions -- initialize state machine
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.
615 bfa_iocpf_sm_reset(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
619 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fwcheck
);
631 * Semaphore should be acquired for version check.
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.
644 bfa_iocpf_sm_fwcheck(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
646 struct bfa_ioc
*ioc
= iocpf
->ioc
;
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
);
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
));
661 bfa_nw_ioc_hw_sem_release(ioc
);
662 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_mismatch
);
666 case IOCPF_E_SEM_ERROR
:
667 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
668 bfa_ioc_pf_hwfailed(ioc
);
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
);
678 bfa_ioc_hw_sem_get_cancel(ioc
);
679 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
688 * Notify enable completion callback
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.
706 bfa_iocpf_sm_mismatch(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
708 struct bfa_ioc
*ioc
= iocpf
->ioc
;
711 case IOCPF_E_TIMEOUT
:
712 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fwcheck
);
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
);
722 del_timer(&ioc
->iocpf_timer
);
723 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
732 * Request for semaphore.
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.
744 bfa_iocpf_sm_semwait(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
746 struct bfa_ioc
*ioc
= iocpf
->ioc
;
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
);
754 bfa_nw_ioc_hw_sem_release(ioc
);
755 mod_timer(&ioc
->sem_timer
, jiffies
+
756 msecs_to_jiffies(BFA_IOC_HWSEM_TOV
));
760 case IOCPF_E_SEM_ERROR
:
761 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
762 bfa_ioc_pf_hwfailed(ioc
);
765 case IOCPF_E_DISABLE
:
766 bfa_ioc_hw_sem_get_cancel(ioc
);
767 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
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.
787 bfa_iocpf_sm_hwinit(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
789 struct bfa_ioc
*ioc
= iocpf
->ioc
;
792 case IOCPF_E_FWREADY
:
793 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_enabling
);
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
);
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
);
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.
831 bfa_iocpf_sm_enabling(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
833 struct bfa_ioc
*ioc
= iocpf
->ioc
;
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
);
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
);
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
);
866 bfa_iocpf_sm_ready_entry(struct bfa_iocpf
*iocpf
)
868 bfa_ioc_pf_enabled(iocpf
->ioc
);
872 bfa_iocpf_sm_ready(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
875 case IOCPF_E_DISABLE
:
876 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling
);
879 case IOCPF_E_GETATTRFAIL
:
880 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail_sync
);
884 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail_sync
);
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
904 bfa_iocpf_sm_disabling(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
906 struct bfa_ioc
*ioc
= iocpf
->ioc
;
909 case IOCPF_E_FWRSP_DISABLE
:
910 del_timer(&ioc
->iocpf_timer
);
911 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
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
);
925 case IOCPF_E_FWRSP_ENABLE
:
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.
943 bfa_iocpf_sm_disabling_sync(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
945 struct bfa_ioc
*ioc
= iocpf
->ioc
;
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
);
954 case IOCPF_E_SEM_ERROR
:
955 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
956 bfa_ioc_pf_hwfailed(ioc
);
968 * IOC disable completion entry.
971 bfa_iocpf_sm_disabled_entry(struct bfa_iocpf
*iocpf
)
973 bfa_ioc_mbox_flush(iocpf
->ioc
);
974 bfa_ioc_pf_disabled(iocpf
->ioc
);
978 bfa_iocpf_sm_disabled(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
980 struct bfa_ioc
*ioc
= iocpf
->ioc
;
984 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_semwait
);
988 bfa_ioc_firmware_unlock(ioc
);
989 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
998 bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf
*iocpf
)
1000 bfa_ioc_hw_sem_get(iocpf
->ioc
);
1004 * Hardware initialization failed.
1007 bfa_iocpf_sm_initfail_sync(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1009 struct bfa_ioc
*ioc
= iocpf
->ioc
;
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
);
1020 case IOCPF_E_SEM_ERROR
:
1021 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1022 bfa_ioc_pf_hwfailed(ioc
);
1025 case IOCPF_E_DISABLE
:
1026 bfa_ioc_hw_sem_get_cancel(ioc
);
1027 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1031 bfa_ioc_hw_sem_get_cancel(ioc
);
1032 bfa_ioc_firmware_unlock(ioc
);
1033 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
1040 bfa_sm_fault(event
);
1045 bfa_iocpf_sm_initfail_entry(struct bfa_iocpf
*iocpf
)
1050 * Hardware initialization failed.
1053 bfa_iocpf_sm_initfail(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1055 struct bfa_ioc
*ioc
= iocpf
->ioc
;
1058 case IOCPF_E_DISABLE
:
1059 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
1063 bfa_ioc_firmware_unlock(ioc
);
1064 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
1068 bfa_sm_fault(event
);
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.
1091 bfa_iocpf_sm_fail_sync(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1093 struct bfa_ioc
*ioc
= iocpf
->ioc
;
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
);
1105 if (bfa_ioc_sync_complete(ioc
))
1106 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_hwinit
);
1108 bfa_nw_ioc_hw_sem_release(ioc
);
1109 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_semwait
);
1114 case IOCPF_E_SEM_ERROR
:
1115 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1116 bfa_ioc_pf_hwfailed(ioc
);
1119 case IOCPF_E_DISABLE
:
1120 bfa_ioc_hw_sem_get_cancel(ioc
);
1121 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1128 bfa_sm_fault(event
);
1133 bfa_iocpf_sm_fail_entry(struct bfa_iocpf
*iocpf
)
1139 * IOC is in failed state.
1142 bfa_iocpf_sm_fail(struct bfa_iocpf
*iocpf
, enum iocpf_event event
)
1145 case IOCPF_E_DISABLE
:
1146 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
1150 bfa_sm_fault(event
);
1155 * BFA IOC private functions
1159 * Notify common modules registered for notification.
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
);
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
);
1181 bfa_nw_ioc_sem_get(void __iomem
*sem_reg
)
1185 #define BFA_SEM_SPINCNT 3000
1187 r32
= readl(sem_reg
);
1189 while ((r32
& 1) && (cnt
< BFA_SEM_SPINCNT
)) {
1192 r32
= readl(sem_reg
);
1202 bfa_nw_ioc_sem_release(void __iomem
*sem_reg
)
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
)
1217 bfa_nw_ioc_fwver_get(ioc
, &fwhdr
);
1219 if (swab32(fwhdr
.exec
) == BFI_FWBOOT_TYPE_NORMAL
)
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
);
1232 bfa_ioc_hw_sem_get(struct bfa_ioc
*ioc
)
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
);
1242 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_SEM_ERROR
);
1246 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_SEMLOCKED
);
1250 mod_timer(&ioc
->sem_timer
, jiffies
+
1251 msecs_to_jiffies(BFA_IOC_HWSEM_TOV
));
1255 bfa_nw_ioc_hw_sem_release(struct bfa_ioc
*ioc
)
1257 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
1261 bfa_ioc_hw_sem_get_cancel(struct bfa_ioc
*ioc
)
1263 del_timer(&ioc
->sem_timer
);
1268 * Initialize LPU local memory (aka secondary memory / SRAM)
1271 bfa_ioc_lmem_init(struct bfa_ioc
*ioc
)
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
1292 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1294 } while (!(pss_ctl
& __PSS_LMEM_INIT_DONE
) && (i
< PSS_LMEM_INIT_TIME
));
1297 * If memory initialization is not successful, IOC timeout will catch
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
);
1307 bfa_ioc_lpu_start(struct bfa_ioc
*ioc
)
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
);
1321 bfa_ioc_lpu_stop(struct bfa_ioc
*ioc
)
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.
1338 bfa_nw_ioc_fwver_get(struct bfa_ioc
*ioc
, struct bfi_ioc_image_hdr
*fwhdr
)
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
));
1351 swab32(readl((loff
) + (ioc
->ioc_regs
.smem_page_start
)));
1352 loff
+= sizeof(u32
);
1357 * Returns TRUE if same.
1360 bfa_nw_ioc_fwver_cmp(struct bfa_ioc
*ioc
, struct bfi_ioc_image_hdr
*fwhdr
)
1362 struct bfi_ioc_image_hdr
*drv_fwhdr
;
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
])
1377 * Return true if current running version is valid. Firmware signature and
1378 * execution context (driver/bios) must match.
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
)
1392 if (swab32(fwhdr
.bootenv
) != boot_env
)
1395 return bfa_nw_ioc_fwver_cmp(ioc
, &fwhdr
);
1399 * Conditionally flush any pending message from firmware at start.
1402 bfa_ioc_msgflush(struct bfa_ioc
*ioc
)
1406 r32
= readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
1408 writel(1, ioc
->ioc_regs
.lpu_mbox_cmd
);
1412 * @img ioc_init_logic.jpg
1415 bfa_ioc_hwinit(struct bfa_ioc
*ioc
, bool force
)
1417 enum bfi_ioc_state ioc_fwstate
;
1421 ioc_fwstate
= readl(ioc
->ioc_regs
.ioc_fwstate
);
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
);
1435 bfa_ioc_boot(ioc
, BFI_FWBOOT_TYPE_NORMAL
, boot_env
);
1436 bfa_ioc_poll_fwinit(ioc
);
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
);
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
);
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
);
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
);
1479 bfa_ioc_mbox_send(struct bfa_ioc
*ioc
, void *ioc_msg
, int len
)
1481 u32
*msgp
= (u32
*) ioc_msg
;
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
);
1504 bfa_ioc_send_enable(struct bfa_ioc
*ioc
)
1506 struct bfi_ioc_ctrl_req enable_req
;
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
));
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
));
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
));
1539 bfa_nw_ioc_hb_check(void *cbarg
)
1541 struct bfa_ioc
*ioc
= cbarg
;
1544 hb_count
= readl(ioc
->ioc_regs
.heartbeat
);
1545 if (ioc
->hb_count
== hb_count
) {
1546 bfa_ioc_recover(ioc
);
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
));
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
));
1566 bfa_ioc_hb_stop(struct bfa_ioc
*ioc
)
1568 del_timer(&ioc
->hb_timer
);
1573 * Initiate a full firmware download.
1576 bfa_ioc_download_fw(struct bfa_ioc
*ioc
, u32 boot_type
,
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
));
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
);
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
)));
1640 bfa_ioc_reset(struct bfa_ioc
*ioc
, bool force
)
1642 bfa_ioc_hwinit(ioc
, force
);
1646 * BFA ioc enable reply by firmware
1649 bfa_ioc_enable_reply(struct bfa_ioc
*ioc
, enum bfa_mode port_mode
,
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
);
1661 * Update BFA configuration from firmware configuration.
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.
1679 bfa_ioc_mbox_attach(struct bfa_ioc
*ioc
)
1681 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
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.
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
;
1704 * If no command pending, do nothing
1706 if (list_empty(&mod
->cmd_q
))
1710 * If previous command is not yet fetched by firmware, do nothing
1712 stat
= readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
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
1734 * Cleanup any pending requests.
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
);
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
1760 bfa_ioc_pf_enabled(struct bfa_ioc
*ioc
)
1762 bfa_fsm_send_event(ioc
, IOC_E_ENABLED
);
1766 bfa_ioc_pf_disabled(struct bfa_ioc
*ioc
)
1768 bfa_fsm_send_event(ioc
, IOC_E_DISABLED
);
1772 bfa_ioc_pf_failed(struct bfa_ioc
*ioc
)
1774 bfa_fsm_send_event(ioc
, IOC_E_PFFAILED
);
1778 bfa_ioc_pf_hwfailed(struct bfa_ioc
*ioc
)
1780 bfa_fsm_send_event(ioc
, IOC_E_HWFAILED
);
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
);
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.
1819 bfa_ioc_boot(struct bfa_ioc
*ioc
, enum bfi_fwboot_type boot_type
,
1822 bfa_ioc_stats(ioc
, ioc_boots
);
1824 if (bfa_ioc_pll_init(ioc
) != BFA_STATUS_OK
)
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
);
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.
1847 bfa_nw_ioc_auto_recover(bool auto_recover
)
1849 bfa_nw_auto_recover
= auto_recover
;
1853 bfa_ioc_msgget(struct bfa_ioc
*ioc
, void *mbmsg
)
1859 r32
= readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
1866 for (i
= 0; i
< (sizeof(union bfi_ioc_i2h_msg_u
) / sizeof(u32
));
1868 r32
= readl(ioc
->ioc_regs
.lpu_mbox
+
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
);
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
:
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
);
1902 case BFI_IOC_I2H_DISABLE_REPLY
:
1903 bfa_fsm_send_event(iocpf
, IOCPF_E_FWRSP_DISABLE
);
1906 case BFI_IOC_I2H_GETATTR_REPLY
:
1907 bfa_ioc_getattr_reply(ioc
);
1916 * IOC attach time initialization and setup.
1918 * @param[in] ioc memory for IOC
1919 * @param[in] bfa driver instance structure
1922 bfa_nw_ioc_attach(struct bfa_ioc
*ioc
, void *bfa
, struct bfa_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.
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
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
;
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
;
1983 ioc
->port_mode
= ioc
->port_mode_cfg
= BFA_MODE_HBA
;
1984 ioc
->ad_cap_bm
= BFA_CM_HBA
;
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
) {
1990 ioc
->port_mode_cfg
= BFA_MODE_CNA
;
1991 ioc
->ad_cap_bm
= BFA_CM_CNA
;
1994 ioc
->port_mode_cfg
= BFA_MODE_NIC
;
1995 ioc
->ad_cap_bm
= BFA_CM_NIC
;
2005 * Set asic specific interfaces.
2007 if (ioc
->asic_gen
== BFI_ASIC_GEN_CT
)
2008 bfa_nw_ioc_set_ct_hwif(ioc
);
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
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
);
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
);
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
);
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
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
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
;
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
);
2106 * If mailbox is busy, queue command for poll timer
2108 stat
= readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
2110 list_add_tail(&cmd
->qe
, &mod
->cmd_q
);
2115 * mailbox is free -- queue command to firmware
2117 bfa_ioc_mbox_send(ioc
, cmd
->msg
, sizeof(cmd
->msg
));
2123 * Handle mailbox interrupts
2126 bfa_nw_ioc_mbox_isr(struct bfa_ioc
*ioc
)
2128 struct bfa_ioc_mbox_mod
*mod
= &ioc
->mbox_mod
;
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
);
2142 if ((mc
>= BFI_MC_MAX
) || (mod
->mbhdlr
[mc
].cbfn
== NULL
))
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
);
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
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.
2179 bfa_nw_ioc_notify_register(struct bfa_ioc
*ioc
,
2180 struct bfa_ioc_notify
*notify
)
2182 list_add_tail(¬ify
->qe
, &ioc
->notify_q
);
2185 #define BFA_MFG_NAME "Brocade"
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;
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
;
2240 bfa_ioc_get_adapter_serial_num(struct bfa_ioc
*ioc
, char *serial_num
)
2242 memset(serial_num
, 0, BFA_ADAPTER_SERIAL_NUM_LEN
);
2244 (void *)ioc
->attr
->brcd_serialnum
,
2245 BFA_ADAPTER_SERIAL_NUM_LEN
);
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
);
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
);
2266 chip_rev
[4] = ioc
->attr
->asic_rev
;
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
,
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
);
2286 bfa_ioc_get_adapter_model(struct bfa_ioc
*ioc
, char *model
)
2288 struct bfi_ioc_attr
*ioc_attr
;
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
);
2311 case BFA_IOCPF_SEMWAIT
:
2312 ioc_st
= BFA_IOC_SEMWAIT
;
2315 case BFA_IOCPF_HWINIT
:
2316 ioc_st
= BFA_IOC_HWINIT
;
2319 case BFA_IOCPF_FWMISMATCH
:
2320 ioc_st
= BFA_IOC_FWMISMATCH
;
2323 case BFA_IOCPF_FAIL
:
2324 ioc_st
= BFA_IOC_FAIL
;
2327 case BFA_IOCPF_INITFAIL
:
2328 ioc_st
= BFA_IOC_INITFAIL
;
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
);
2363 bfa_ioc_get_pwwn(struct bfa_ioc
*ioc
)
2365 return ioc
->attr
->pwwn
;
2369 bfa_nw_ioc_get_mac(struct bfa_ioc
*ioc
)
2371 return ioc
->attr
->mac
;
2375 * Firmware failure detected. Start recovery actions.
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
);
2387 bfa_ioc_check_attr_wwns(struct bfa_ioc
*ioc
)
2389 if (bfa_ioc_get_type(ioc
) == BFA_IOC_TYPE_LL
)
2394 * @dg hal_iocpf_pvt BFA IOC PF private functions
2399 bfa_iocpf_enable(struct bfa_ioc
*ioc
)
2401 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_ENABLE
);
2405 bfa_iocpf_disable(struct bfa_ioc
*ioc
)
2407 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_DISABLE
);
2411 bfa_iocpf_fail(struct bfa_ioc
*ioc
)
2413 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FAIL
);
2417 bfa_iocpf_initfail(struct bfa_ioc
*ioc
)
2419 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_INITFAIL
);
2423 bfa_iocpf_getattrfail(struct bfa_ioc
*ioc
)
2425 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_GETATTRFAIL
);
2429 bfa_iocpf_stop(struct bfa_ioc
*ioc
)
2431 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_STOP
);
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
);
2445 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_TIMEOUT
);
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
);
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
);
2466 if (ioc
->iocpf
.poll_time
>= BFA_IOC_TOV
) {
2467 bfa_nw_iocpf_timeout(ioc
);
2469 ioc
->iocpf
.poll_time
+= BFA_IOC_POLL_TOV
;
2470 mod_timer(&ioc
->iocpf_timer
, jiffies
+
2471 msecs_to_jiffies(BFA_IOC_POLL_TOV
));