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.
22 #include "bfi_ctreg.h"
26 * IOC local definitions
30 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
33 #define bfa_ioc_firmware_lock(__ioc) \
34 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
35 #define bfa_ioc_firmware_unlock(__ioc) \
36 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
37 #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
38 #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
39 #define bfa_ioc_notify_fail(__ioc) \
40 ((__ioc)->ioc_hwif->ioc_notify_fail(__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_get(struct bfa_ioc *ioc);
60 static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc);
61 static void bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force);
62 static void bfa_ioc_send_enable(struct bfa_ioc *ioc);
63 static void bfa_ioc_send_disable(struct bfa_ioc *ioc);
64 static void bfa_ioc_send_getattr(struct bfa_ioc *ioc);
65 static void bfa_ioc_hb_monitor(struct bfa_ioc *ioc);
66 static void bfa_ioc_hb_stop(struct bfa_ioc *ioc);
67 static void bfa_ioc_reset(struct bfa_ioc *ioc, bool force);
68 static void bfa_ioc_mbox_poll(struct bfa_ioc *ioc);
69 static void bfa_ioc_mbox_hbfail(struct bfa_ioc *ioc);
70 static void bfa_ioc_recover(struct bfa_ioc *ioc);
71 static void bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc);
72 static void bfa_ioc_disable_comp(struct bfa_ioc *ioc);
73 static void bfa_ioc_lpu_stop(struct bfa_ioc *ioc);
74 static void bfa_ioc_fail_notify(struct bfa_ioc *ioc);
75 static void bfa_ioc_pf_enabled(struct bfa_ioc *ioc);
76 static void bfa_ioc_pf_disabled(struct bfa_ioc *ioc);
77 static void bfa_ioc_pf_initfailed(struct bfa_ioc *ioc);
78 static void bfa_ioc_pf_failed(struct bfa_ioc *ioc);
79 static void bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc);
80 static void bfa_ioc_boot(struct bfa_ioc *ioc, u32 boot_type,
82 static u32 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr);
83 static u32 bfa_ioc_smem_pgoff(struct bfa_ioc *ioc, u32 fmaddr);
84 static void bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc,
86 static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc,
88 static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc,
90 static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc,
92 static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc,
94 static void bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model);
95 static u64 bfa_ioc_get_pwwn(struct bfa_ioc *ioc);
98 * IOC state machine definitions/declarations
101 IOC_E_RESET = 1, /*!< IOC reset request */
102 IOC_E_ENABLE = 2, /*!< IOC enable request */
103 IOC_E_DISABLE = 3, /*!< IOC disable request */
104 IOC_E_DETACH = 4, /*!< driver detach cleanup */
105 IOC_E_ENABLED = 5, /*!< f/w enabled */
106 IOC_E_FWRSP_GETATTR = 6, /*!< IOC get attribute response */
107 IOC_E_DISABLED = 7, /*!< f/w disabled */
108 IOC_E_INITFAILED = 8, /*!< failure notice by iocpf sm */
109 IOC_E_PFAILED = 9, /*!< failure notice by iocpf sm */
110 IOC_E_HBFAIL = 10, /*!< heartbeat failure */
111 IOC_E_HWERROR = 11, /*!< hardware error interrupt */
112 IOC_E_TIMEOUT = 12, /*!< timeout */
115 bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc, enum ioc_event);
116 bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc, enum ioc_event);
117 bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc, enum ioc_event);
118 bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc, enum ioc_event);
119 bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc, enum ioc_event);
120 bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc, enum ioc_event);
121 bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc, enum ioc_event);
122 bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc, enum ioc_event);
123 bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc, enum ioc_event);
125 static struct bfa_sm_table ioc_sm_table[] = {
126 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
127 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
128 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
129 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
130 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
131 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
132 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
133 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
134 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
138 * IOCPF state machine definitions/declarations
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 */
171 enum bfa_iocpf_state {
172 BFA_IOCPF_RESET = 1, /*!< IOC is in reset state */
173 BFA_IOCPF_SEMWAIT = 2, /*!< Waiting for IOC h/w semaphore */
174 BFA_IOCPF_HWINIT = 3, /*!< IOC h/w is being initialized */
175 BFA_IOCPF_READY = 4, /*!< IOCPF is initialized */
176 BFA_IOCPF_INITFAIL = 5, /*!< IOCPF failed */
177 BFA_IOCPF_FAIL = 6, /*!< IOCPF failed */
178 BFA_IOCPF_DISABLING = 7, /*!< IOCPF is being disabled */
179 BFA_IOCPF_DISABLED = 8, /*!< IOCPF is disabled */
180 BFA_IOCPF_FWMISMATCH = 9, /*!< IOC f/w different from drivers */
183 bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf, enum iocpf_event);
184 bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf, enum iocpf_event);
185 bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf, enum iocpf_event);
186 bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf, enum iocpf_event);
187 bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf, enum iocpf_event);
188 bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf, enum iocpf_event);
189 bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf, enum iocpf_event);
190 bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf,
192 bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf, enum iocpf_event);
193 bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf, enum iocpf_event);
194 bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf, enum iocpf_event);
195 bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf, enum iocpf_event);
196 bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf,
198 bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf, enum iocpf_event);
200 static struct bfa_sm_table iocpf_sm_table[] = {
201 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
202 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
203 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
204 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
205 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
206 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
207 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
208 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
209 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
210 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
211 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
212 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
213 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
214 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
222 * Beginning state. IOC uninit state.
225 bfa_ioc_sm_uninit_entry(struct bfa_ioc *ioc)
230 * IOC is in uninit state.
233 bfa_ioc_sm_uninit(struct bfa_ioc *ioc, enum ioc_event event)
237 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
241 bfa_sm_fault(ioc, event);
246 * Reset entry actions -- initialize state machine
249 bfa_ioc_sm_reset_entry(struct bfa_ioc *ioc)
251 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
255 * IOC is in reset state.
258 bfa_ioc_sm_reset(struct bfa_ioc *ioc, enum ioc_event event)
262 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
266 bfa_ioc_disable_comp(ioc);
270 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
274 bfa_sm_fault(ioc, event);
279 bfa_ioc_sm_enabling_entry(struct bfa_ioc *ioc)
281 bfa_iocpf_enable(ioc);
285 * Host IOC function is being enabled, awaiting response from firmware.
286 * Semaphore is acquired.
289 bfa_ioc_sm_enabling(struct bfa_ioc *ioc, enum ioc_event event)
293 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
297 /* !!! fall through !!! */
299 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
300 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
301 if (event != IOC_E_PFAILED)
302 bfa_iocpf_initfail(ioc);
306 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
310 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
318 bfa_sm_fault(ioc, event);
323 * Semaphore should be acquired for version check.
326 bfa_ioc_sm_getattr_entry(struct bfa_ioc *ioc)
328 mod_timer(&ioc->ioc_timer, jiffies +
329 msecs_to_jiffies(BFA_IOC_TOV));
330 bfa_ioc_send_getattr(ioc);
334 * IOC configuration in progress. Timer is active.
337 bfa_ioc_sm_getattr(struct bfa_ioc *ioc, enum ioc_event event)
340 case IOC_E_FWRSP_GETATTR:
341 del_timer(&ioc->ioc_timer);
342 bfa_ioc_check_attr_wwns(ioc);
343 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
348 del_timer(&ioc->ioc_timer);
351 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
352 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
353 if (event != IOC_E_PFAILED)
354 bfa_iocpf_getattrfail(ioc);
358 del_timer(&ioc->ioc_timer);
359 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
366 bfa_sm_fault(ioc, event);
371 bfa_ioc_sm_op_entry(struct bfa_ioc *ioc)
373 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
374 bfa_ioc_hb_monitor(ioc);
378 bfa_ioc_sm_op(struct bfa_ioc *ioc, enum ioc_event event)
385 bfa_ioc_hb_stop(ioc);
386 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
391 bfa_ioc_hb_stop(ioc);
392 /* !!! fall through !!! */
394 bfa_ioc_fail_notify(ioc);
395 if (ioc->iocpf.auto_recover)
396 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
398 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
400 if (event != IOC_E_PFAILED)
405 bfa_sm_fault(ioc, event);
410 bfa_ioc_sm_disabling_entry(struct bfa_ioc *ioc)
412 bfa_iocpf_disable(ioc);
416 * IOC is being desabled
419 bfa_ioc_sm_disabling(struct bfa_ioc *ioc, enum ioc_event event)
423 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
428 * No state change. Will move to disabled state
429 * after iocpf sm completes failure processing and
430 * moves to disabled state.
436 bfa_sm_fault(ioc, event);
441 * IOC desable completion entry.
444 bfa_ioc_sm_disabled_entry(struct bfa_ioc *ioc)
446 bfa_ioc_disable_comp(ioc);
450 bfa_ioc_sm_disabled(struct bfa_ioc *ioc, enum ioc_event event)
454 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
458 ioc->cbfn->disable_cbfn(ioc->bfa);
462 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
467 bfa_sm_fault(ioc, event);
472 bfa_ioc_sm_fail_retry_entry(struct bfa_ioc *ioc)
477 * Hardware initialization retry.
480 bfa_ioc_sm_fail_retry(struct bfa_ioc *ioc, enum ioc_event event)
484 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
490 * Initialization retry failed.
492 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
493 if (event != IOC_E_PFAILED)
494 bfa_iocpf_initfail(ioc);
497 case IOC_E_INITFAILED:
498 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
505 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
509 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
514 bfa_sm_fault(ioc, event);
519 bfa_ioc_sm_fail_entry(struct bfa_ioc *ioc)
527 bfa_ioc_sm_fail(struct bfa_ioc *ioc, enum ioc_event event)
531 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
535 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
539 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
544 /* HB failure notification, ignore. */
548 bfa_sm_fault(ioc, event);
553 * IOCPF State Machine
557 * Reset entry actions -- initialize state machine
560 bfa_iocpf_sm_reset_entry(struct bfa_iocpf *iocpf)
562 iocpf->retry_count = 0;
563 iocpf->auto_recover = bfa_nw_auto_recover;
567 * Beginning state. IOC is in reset state.
570 bfa_iocpf_sm_reset(struct bfa_iocpf *iocpf, enum iocpf_event event)
574 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
581 bfa_sm_fault(iocpf->ioc, event);
586 * Semaphore should be acquired for version check.
589 bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf *iocpf)
591 bfa_ioc_hw_sem_get(iocpf->ioc);
595 * Awaiting h/w semaphore to continue with version check.
598 bfa_iocpf_sm_fwcheck(struct bfa_iocpf *iocpf, enum iocpf_event event)
600 struct bfa_ioc *ioc = iocpf->ioc;
603 case IOCPF_E_SEMLOCKED:
604 if (bfa_ioc_firmware_lock(ioc)) {
605 if (bfa_ioc_sync_complete(ioc)) {
606 iocpf->retry_count = 0;
607 bfa_ioc_sync_join(ioc);
608 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
610 bfa_ioc_firmware_unlock(ioc);
611 bfa_nw_ioc_hw_sem_release(ioc);
612 mod_timer(&ioc->sem_timer, jiffies +
613 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
616 bfa_nw_ioc_hw_sem_release(ioc);
617 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
621 case IOCPF_E_DISABLE:
622 bfa_ioc_hw_sem_get_cancel(ioc);
623 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
624 bfa_ioc_pf_disabled(ioc);
628 bfa_ioc_hw_sem_get_cancel(ioc);
629 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
633 bfa_sm_fault(ioc, event);
638 * Notify enable completion callback
641 bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf *iocpf)
643 /* Call only the first time sm enters fwmismatch state. */
644 if (iocpf->retry_count == 0)
645 bfa_ioc_pf_fwmismatch(iocpf->ioc);
647 iocpf->retry_count++;
648 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
649 msecs_to_jiffies(BFA_IOC_TOV));
653 * Awaiting firmware version match.
656 bfa_iocpf_sm_mismatch(struct bfa_iocpf *iocpf, enum iocpf_event event)
658 struct bfa_ioc *ioc = iocpf->ioc;
661 case IOCPF_E_TIMEOUT:
662 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
665 case IOCPF_E_DISABLE:
666 del_timer(&ioc->iocpf_timer);
667 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
668 bfa_ioc_pf_disabled(ioc);
672 del_timer(&ioc->iocpf_timer);
673 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
677 bfa_sm_fault(ioc, event);
682 * Request for semaphore.
685 bfa_iocpf_sm_semwait_entry(struct bfa_iocpf *iocpf)
687 bfa_ioc_hw_sem_get(iocpf->ioc);
691 * Awaiting semaphore for h/w initialzation.
694 bfa_iocpf_sm_semwait(struct bfa_iocpf *iocpf, enum iocpf_event event)
696 struct bfa_ioc *ioc = iocpf->ioc;
699 case IOCPF_E_SEMLOCKED:
700 if (bfa_ioc_sync_complete(ioc)) {
701 bfa_ioc_sync_join(ioc);
702 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
704 bfa_nw_ioc_hw_sem_release(ioc);
705 mod_timer(&ioc->sem_timer, jiffies +
706 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
710 case IOCPF_E_DISABLE:
711 bfa_ioc_hw_sem_get_cancel(ioc);
712 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
716 bfa_sm_fault(ioc, event);
721 bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf *iocpf)
723 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
724 msecs_to_jiffies(BFA_IOC_TOV));
725 bfa_ioc_reset(iocpf->ioc, 0);
729 * Hardware is being initialized. Interrupts are enabled.
730 * Holding hardware semaphore lock.
733 bfa_iocpf_sm_hwinit(struct bfa_iocpf *iocpf, enum iocpf_event event)
735 struct bfa_ioc *ioc = iocpf->ioc;
738 case IOCPF_E_FWREADY:
739 del_timer(&ioc->iocpf_timer);
740 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
743 case IOCPF_E_INITFAIL:
744 del_timer(&ioc->iocpf_timer);
746 * !!! fall through !!!
749 case IOCPF_E_TIMEOUT:
750 bfa_nw_ioc_hw_sem_release(ioc);
751 if (event == IOCPF_E_TIMEOUT)
752 bfa_ioc_pf_failed(ioc);
753 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
756 case IOCPF_E_DISABLE:
757 del_timer(&ioc->iocpf_timer);
758 bfa_ioc_sync_leave(ioc);
759 bfa_nw_ioc_hw_sem_release(ioc);
760 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
764 bfa_sm_fault(ioc, event);
769 bfa_iocpf_sm_enabling_entry(struct bfa_iocpf *iocpf)
771 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
772 msecs_to_jiffies(BFA_IOC_TOV));
773 bfa_ioc_send_enable(iocpf->ioc);
777 * Host IOC function is being enabled, awaiting response from firmware.
778 * Semaphore is acquired.
781 bfa_iocpf_sm_enabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
783 struct bfa_ioc *ioc = iocpf->ioc;
786 case IOCPF_E_FWRSP_ENABLE:
787 del_timer(&ioc->iocpf_timer);
788 bfa_nw_ioc_hw_sem_release(ioc);
789 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
792 case IOCPF_E_INITFAIL:
793 del_timer(&ioc->iocpf_timer);
795 * !!! fall through !!!
797 case IOCPF_E_TIMEOUT:
798 bfa_nw_ioc_hw_sem_release(ioc);
799 if (event == IOCPF_E_TIMEOUT)
800 bfa_ioc_pf_failed(ioc);
801 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
804 case IOCPF_E_DISABLE:
805 del_timer(&ioc->iocpf_timer);
806 bfa_nw_ioc_hw_sem_release(ioc);
807 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
810 case IOCPF_E_FWREADY:
811 bfa_ioc_send_enable(ioc);
815 bfa_sm_fault(ioc, event);
820 bfa_nw_ioc_is_operational(struct bfa_ioc *ioc)
822 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
826 bfa_iocpf_sm_ready_entry(struct bfa_iocpf *iocpf)
828 bfa_ioc_pf_enabled(iocpf->ioc);
832 bfa_iocpf_sm_ready(struct bfa_iocpf *iocpf, enum iocpf_event event)
834 struct bfa_ioc *ioc = iocpf->ioc;
837 case IOCPF_E_DISABLE:
838 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
841 case IOCPF_E_GETATTRFAIL:
842 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
846 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
849 case IOCPF_E_FWREADY:
850 bfa_ioc_pf_failed(ioc);
851 if (bfa_nw_ioc_is_operational(ioc))
852 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
854 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
858 bfa_sm_fault(ioc, event);
863 bfa_iocpf_sm_disabling_entry(struct bfa_iocpf *iocpf)
865 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
866 msecs_to_jiffies(BFA_IOC_TOV));
867 bfa_ioc_send_disable(iocpf->ioc);
871 * IOC is being disabled
874 bfa_iocpf_sm_disabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
876 struct bfa_ioc *ioc = iocpf->ioc;
879 case IOCPF_E_FWRSP_DISABLE:
880 case IOCPF_E_FWREADY:
881 del_timer(&ioc->iocpf_timer);
882 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
886 del_timer(&ioc->iocpf_timer);
888 * !!! fall through !!!
891 case IOCPF_E_TIMEOUT:
892 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
893 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
896 case IOCPF_E_FWRSP_ENABLE:
900 bfa_sm_fault(ioc, event);
905 bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf *iocpf)
907 bfa_ioc_hw_sem_get(iocpf->ioc);
911 * IOC hb ack request is being removed.
914 bfa_iocpf_sm_disabling_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
916 struct bfa_ioc *ioc = iocpf->ioc;
919 case IOCPF_E_SEMLOCKED:
920 bfa_ioc_sync_leave(ioc);
921 bfa_nw_ioc_hw_sem_release(ioc);
922 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
929 bfa_sm_fault(ioc, event);
934 * IOC disable completion entry.
937 bfa_iocpf_sm_disabled_entry(struct bfa_iocpf *iocpf)
939 bfa_ioc_pf_disabled(iocpf->ioc);
943 bfa_iocpf_sm_disabled(struct bfa_iocpf *iocpf, enum iocpf_event event)
945 struct bfa_ioc *ioc = iocpf->ioc;
949 iocpf->retry_count = 0;
950 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
954 bfa_ioc_firmware_unlock(ioc);
955 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
959 bfa_sm_fault(ioc, event);
964 bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf *iocpf)
966 bfa_ioc_hw_sem_get(iocpf->ioc);
970 * Hardware initialization failed.
973 bfa_iocpf_sm_initfail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
975 struct bfa_ioc *ioc = iocpf->ioc;
978 case IOCPF_E_SEMLOCKED:
979 bfa_ioc_notify_fail(ioc);
980 bfa_ioc_sync_ack(ioc);
981 iocpf->retry_count++;
982 if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) {
983 bfa_ioc_sync_leave(ioc);
984 bfa_nw_ioc_hw_sem_release(ioc);
985 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
987 if (bfa_ioc_sync_complete(ioc))
988 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
990 bfa_nw_ioc_hw_sem_release(ioc);
991 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
996 case IOCPF_E_DISABLE:
997 bfa_ioc_hw_sem_get_cancel(ioc);
998 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1002 bfa_ioc_hw_sem_get_cancel(ioc);
1003 bfa_ioc_firmware_unlock(ioc);
1004 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1011 bfa_sm_fault(ioc, event);
1016 bfa_iocpf_sm_initfail_entry(struct bfa_iocpf *iocpf)
1018 bfa_ioc_pf_initfailed(iocpf->ioc);
1022 * Hardware initialization failed.
1025 bfa_iocpf_sm_initfail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1027 struct bfa_ioc *ioc = iocpf->ioc;
1030 case IOCPF_E_DISABLE:
1031 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1035 bfa_ioc_firmware_unlock(ioc);
1036 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1040 bfa_sm_fault(ioc, event);
1045 bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf *iocpf)
1048 * Mark IOC as failed in hardware and stop firmware.
1050 bfa_ioc_lpu_stop(iocpf->ioc);
1053 * Flush any queued up mailbox requests.
1055 bfa_ioc_mbox_hbfail(iocpf->ioc);
1056 bfa_ioc_hw_sem_get(iocpf->ioc);
1060 * IOC is in failed state.
1063 bfa_iocpf_sm_fail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
1065 struct bfa_ioc *ioc = iocpf->ioc;
1068 case IOCPF_E_SEMLOCKED:
1069 iocpf->retry_count = 0;
1070 bfa_ioc_sync_ack(ioc);
1071 bfa_ioc_notify_fail(ioc);
1072 if (!iocpf->auto_recover) {
1073 bfa_ioc_sync_leave(ioc);
1074 bfa_nw_ioc_hw_sem_release(ioc);
1075 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1077 if (bfa_ioc_sync_complete(ioc))
1078 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1080 bfa_nw_ioc_hw_sem_release(ioc);
1081 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1086 case IOCPF_E_DISABLE:
1087 bfa_ioc_hw_sem_get_cancel(ioc);
1088 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1095 bfa_sm_fault(ioc, event);
1100 bfa_iocpf_sm_fail_entry(struct bfa_iocpf *iocpf)
1106 * IOC is in failed state.
1109 bfa_iocpf_sm_fail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1112 case IOCPF_E_DISABLE:
1113 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1117 bfa_sm_fault(iocpf->ioc, event);
1122 * BFA IOC private functions
1126 bfa_ioc_disable_comp(struct bfa_ioc *ioc)
1128 struct list_head *qe;
1129 struct bfa_ioc_hbfail_notify *notify;
1131 ioc->cbfn->disable_cbfn(ioc->bfa);
1134 * Notify common modules registered for notification.
1136 list_for_each(qe, &ioc->hb_notify_q) {
1137 notify = (struct bfa_ioc_hbfail_notify *) qe;
1138 notify->cbfn(notify->cbarg);
1143 bfa_nw_ioc_sem_get(void __iomem *sem_reg)
1147 #define BFA_SEM_SPINCNT 3000
1149 r32 = readl(sem_reg);
1151 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
1154 r32 = readl(sem_reg);
1160 BUG_ON(!(cnt < BFA_SEM_SPINCNT));
1165 bfa_nw_ioc_sem_release(void __iomem *sem_reg)
1171 bfa_ioc_hw_sem_get(struct bfa_ioc *ioc)
1176 * First read to the semaphore register will return 0, subsequent reads
1177 * will return 1. Semaphore is released by writing 1 to the register
1179 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
1181 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
1185 mod_timer(&ioc->sem_timer, jiffies +
1186 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
1190 bfa_nw_ioc_hw_sem_release(struct bfa_ioc *ioc)
1192 writel(1, ioc->ioc_regs.ioc_sem_reg);
1196 bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc)
1198 del_timer(&ioc->sem_timer);
1203 * Initialize LPU local memory (aka secondary memory / SRAM)
1206 bfa_ioc_lmem_init(struct bfa_ioc *ioc)
1210 #define PSS_LMEM_INIT_TIME 10000
1212 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1213 pss_ctl &= ~__PSS_LMEM_RESET;
1214 pss_ctl |= __PSS_LMEM_INIT_EN;
1217 * i2c workaround 12.5khz clock
1219 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
1220 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1223 * wait for memory initialization to be complete
1227 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1229 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1232 * If memory initialization is not successful, IOC timeout will catch
1235 BUG_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
1237 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
1238 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1242 bfa_ioc_lpu_start(struct bfa_ioc *ioc)
1247 * Take processor out of reset.
1249 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1250 pss_ctl &= ~__PSS_LPU0_RESET;
1252 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1256 bfa_ioc_lpu_stop(struct bfa_ioc *ioc)
1261 * Put processors in reset.
1263 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1264 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1266 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1270 * Get driver and firmware versions.
1273 bfa_nw_ioc_fwver_get(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
1278 u32 *fwsig = (u32 *) fwhdr;
1280 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1281 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
1282 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1284 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32));
1287 swab32(readl((loff) + (ioc->ioc_regs.smem_page_start)));
1288 loff += sizeof(u32);
1293 * Returns TRUE if same.
1296 bfa_nw_ioc_fwver_cmp(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
1298 struct bfi_ioc_image_hdr *drv_fwhdr;
1301 drv_fwhdr = (struct bfi_ioc_image_hdr *)
1302 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
1304 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1305 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i])
1313 * Return true if current running version is valid. Firmware signature and
1314 * execution context (driver/bios) must match.
1317 bfa_ioc_fwver_valid(struct bfa_ioc *ioc)
1319 struct bfi_ioc_image_hdr fwhdr, *drv_fwhdr;
1321 bfa_nw_ioc_fwver_get(ioc, &fwhdr);
1322 drv_fwhdr = (struct bfi_ioc_image_hdr *)
1323 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
1325 if (fwhdr.signature != drv_fwhdr->signature)
1328 if (fwhdr.exec != drv_fwhdr->exec)
1331 return bfa_nw_ioc_fwver_cmp(ioc, &fwhdr);
1335 * Conditionally flush any pending message from firmware at start.
1338 bfa_ioc_msgflush(struct bfa_ioc *ioc)
1342 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1344 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1348 * @img ioc_init_logic.jpg
1351 bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force)
1353 enum bfi_ioc_state ioc_fwstate;
1356 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1359 ioc_fwstate = BFI_IOC_UNINIT;
1362 * check if firmware is valid
1364 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
1365 false : bfa_ioc_fwver_valid(ioc);
1368 bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, ioc->pcidev.device_id);
1373 * If hardware initialization is in progress (initialized by other IOC),
1374 * just wait for an initialization completion interrupt.
1376 if (ioc_fwstate == BFI_IOC_INITING) {
1377 ioc->cbfn->reset_cbfn(ioc->bfa);
1382 * If IOC function is disabled and firmware version is same,
1383 * just re-enable IOC.
1385 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
1387 * When using MSI-X any pending firmware ready event should
1388 * be flushed. Otherwise MSI-X interrupts are not delivered.
1390 bfa_ioc_msgflush(ioc);
1391 ioc->cbfn->reset_cbfn(ioc->bfa);
1392 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
1397 * Initialize the h/w for any other states.
1399 bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, ioc->pcidev.device_id);
1403 bfa_nw_ioc_timeout(void *ioc_arg)
1405 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
1407 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1411 bfa_ioc_mbox_send(struct bfa_ioc *ioc, void *ioc_msg, int len)
1413 u32 *msgp = (u32 *) ioc_msg;
1416 BUG_ON(!(len <= BFI_IOC_MSGLEN_MAX));
1419 * first write msg to mailbox registers
1421 for (i = 0; i < len / sizeof(u32); i++)
1422 writel(cpu_to_le32(msgp[i]),
1423 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1425 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
1426 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1429 * write 1 to mailbox CMD to trigger LPU event
1431 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1432 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
1436 bfa_ioc_send_enable(struct bfa_ioc *ioc)
1438 struct bfi_ioc_ctrl_req enable_req;
1441 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1442 bfa_ioc_portid(ioc));
1443 enable_req.ioc_class = ioc->ioc_mc;
1444 do_gettimeofday(&tv);
1445 enable_req.tv_sec = ntohl(tv.tv_sec);
1446 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req));
1450 bfa_ioc_send_disable(struct bfa_ioc *ioc)
1452 struct bfi_ioc_ctrl_req disable_req;
1454 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1455 bfa_ioc_portid(ioc));
1456 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req));
1460 bfa_ioc_send_getattr(struct bfa_ioc *ioc)
1462 struct bfi_ioc_getattr_req attr_req;
1464 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1465 bfa_ioc_portid(ioc));
1466 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1467 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1471 bfa_nw_ioc_hb_check(void *cbarg)
1473 struct bfa_ioc *ioc = cbarg;
1476 hb_count = readl(ioc->ioc_regs.heartbeat);
1477 if (ioc->hb_count == hb_count) {
1478 bfa_ioc_recover(ioc);
1481 ioc->hb_count = hb_count;
1484 bfa_ioc_mbox_poll(ioc);
1485 mod_timer(&ioc->hb_timer, jiffies +
1486 msecs_to_jiffies(BFA_IOC_HB_TOV));
1490 bfa_ioc_hb_monitor(struct bfa_ioc *ioc)
1492 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
1493 mod_timer(&ioc->hb_timer, jiffies +
1494 msecs_to_jiffies(BFA_IOC_HB_TOV));
1498 bfa_ioc_hb_stop(struct bfa_ioc *ioc)
1500 del_timer(&ioc->hb_timer);
1505 * Initiate a full firmware download.
1508 bfa_ioc_download_fw(struct bfa_ioc *ioc, u32 boot_type,
1518 * Initialize LMEM first before code download
1520 bfa_ioc_lmem_init(ioc);
1522 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
1524 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1525 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
1527 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1529 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
1530 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1531 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
1532 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
1533 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
1539 writel((swab32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)])),
1540 ((ioc->ioc_regs.smem_page_start) + (loff)));
1542 loff += sizeof(u32);
1545 * handle page offset wrap around
1547 loff = PSS_SMEM_PGOFF(loff);
1551 ioc->ioc_regs.host_page_num_fn);
1555 writel(bfa_ioc_smem_pgnum(ioc, 0),
1556 ioc->ioc_regs.host_page_num_fn);
1559 * Set boot type and boot param at the end.
1561 writel((swab32(swab32(boot_type))), ((ioc->ioc_regs.smem_page_start)
1562 + (BFI_BOOT_TYPE_OFF)));
1563 writel((swab32(swab32(boot_param))), ((ioc->ioc_regs.smem_page_start)
1564 + (BFI_BOOT_PARAM_OFF)));
1568 bfa_ioc_reset(struct bfa_ioc *ioc, bool force)
1570 bfa_ioc_hwinit(ioc, force);
1575 * Update BFA configuration from firmware configuration.
1578 bfa_ioc_getattr_reply(struct bfa_ioc *ioc)
1580 struct bfi_ioc_attr *attr = ioc->attr;
1582 attr->adapter_prop = ntohl(attr->adapter_prop);
1583 attr->card_type = ntohl(attr->card_type);
1584 attr->maxfrsize = ntohs(attr->maxfrsize);
1586 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1590 * Attach time initialization of mbox logic.
1593 bfa_ioc_mbox_attach(struct bfa_ioc *ioc)
1595 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1598 INIT_LIST_HEAD(&mod->cmd_q);
1599 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1600 mod->mbhdlr[mc].cbfn = NULL;
1601 mod->mbhdlr[mc].cbarg = ioc->bfa;
1606 * Mbox poll timer -- restarts any pending mailbox requests.
1609 bfa_ioc_mbox_poll(struct bfa_ioc *ioc)
1611 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1612 struct bfa_mbox_cmd *cmd;
1616 * If no command pending, do nothing
1618 if (list_empty(&mod->cmd_q))
1622 * If previous command is not yet fetched by firmware, do nothing
1624 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1629 * Enqueue command to firmware.
1631 bfa_q_deq(&mod->cmd_q, &cmd);
1632 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1636 * Cleanup any pending requests.
1639 bfa_ioc_mbox_hbfail(struct bfa_ioc *ioc)
1641 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1642 struct bfa_mbox_cmd *cmd;
1644 while (!list_empty(&mod->cmd_q))
1645 bfa_q_deq(&mod->cmd_q, &cmd);
1649 bfa_ioc_fail_notify(struct bfa_ioc *ioc)
1651 struct list_head *qe;
1652 struct bfa_ioc_hbfail_notify *notify;
1655 * Notify driver and common modules registered for notification.
1657 ioc->cbfn->hbfail_cbfn(ioc->bfa);
1658 list_for_each(qe, &ioc->hb_notify_q) {
1659 notify = (struct bfa_ioc_hbfail_notify *) qe;
1660 notify->cbfn(notify->cbarg);
1665 bfa_ioc_pf_enabled(struct bfa_ioc *ioc)
1667 bfa_fsm_send_event(ioc, IOC_E_ENABLED);
1671 bfa_ioc_pf_disabled(struct bfa_ioc *ioc)
1673 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
1677 bfa_ioc_pf_initfailed(struct bfa_ioc *ioc)
1679 bfa_fsm_send_event(ioc, IOC_E_INITFAILED);
1683 bfa_ioc_pf_failed(struct bfa_ioc *ioc)
1685 bfa_fsm_send_event(ioc, IOC_E_PFAILED);
1689 bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc)
1692 * Provide enable completion callback and AEN notification.
1694 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
1700 static enum bfa_status
1701 bfa_ioc_pll_init(struct bfa_ioc *ioc)
1704 * Hold semaphore so that nobody can access the chip during init.
1706 bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1708 bfa_ioc_pll_init_asic(ioc);
1710 ioc->pllinit = true;
1712 * release semaphore.
1714 bfa_nw_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
1716 return BFA_STATUS_OK;
1720 * Interface used by diag module to do firmware boot with memory test
1721 * as the entry vector.
1724 bfa_ioc_boot(struct bfa_ioc *ioc, u32 boot_type, u32 boot_param)
1728 bfa_ioc_stats(ioc, ioc_boots);
1730 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1734 * Initialize IOC state of all functions on a chip reset.
1736 rb = ioc->pcidev.pci_bar_kva;
1737 if (boot_param == BFI_BOOT_TYPE_MEMTEST) {
1738 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
1739 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
1741 writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
1742 writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
1745 bfa_ioc_msgflush(ioc);
1746 bfa_ioc_download_fw(ioc, boot_type, boot_param);
1749 * Enable interrupts just before starting LPU
1751 ioc->cbfn->reset_cbfn(ioc->bfa);
1752 bfa_ioc_lpu_start(ioc);
1756 * Enable/disable IOC failure auto recovery.
1759 bfa_nw_ioc_auto_recover(bool auto_recover)
1761 bfa_nw_auto_recover = auto_recover;
1765 bfa_ioc_msgget(struct bfa_ioc *ioc, void *mbmsg)
1774 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1776 r32 = readl(ioc->ioc_regs.lpu_mbox +
1778 msgp[i] = htonl(r32);
1782 * turn off mailbox interrupt by clearing mailbox status
1784 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1785 readl(ioc->ioc_regs.lpu_mbox_cmd);
1789 bfa_ioc_isr(struct bfa_ioc *ioc, struct bfi_mbmsg *m)
1791 union bfi_ioc_i2h_msg_u *msg;
1792 struct bfa_iocpf *iocpf = &ioc->iocpf;
1794 msg = (union bfi_ioc_i2h_msg_u *) m;
1796 bfa_ioc_stats(ioc, ioc_isrs);
1798 switch (msg->mh.msg_id) {
1799 case BFI_IOC_I2H_HBEAT:
1802 case BFI_IOC_I2H_READY_EVENT:
1803 bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
1806 case BFI_IOC_I2H_ENABLE_REPLY:
1807 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
1810 case BFI_IOC_I2H_DISABLE_REPLY:
1811 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
1814 case BFI_IOC_I2H_GETATTR_REPLY:
1815 bfa_ioc_getattr_reply(ioc);
1824 * IOC attach time initialization and setup.
1826 * @param[in] ioc memory for IOC
1827 * @param[in] bfa driver instance structure
1830 bfa_nw_ioc_attach(struct bfa_ioc *ioc, void *bfa, struct bfa_ioc_cbfn *cbfn)
1834 ioc->fcmode = false;
1835 ioc->pllinit = false;
1836 ioc->dbg_fwsave_once = true;
1837 ioc->iocpf.ioc = ioc;
1839 bfa_ioc_mbox_attach(ioc);
1840 INIT_LIST_HEAD(&ioc->hb_notify_q);
1842 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
1843 bfa_fsm_send_event(ioc, IOC_E_RESET);
1847 * Driver detach time IOC cleanup.
1850 bfa_nw_ioc_detach(struct bfa_ioc *ioc)
1852 bfa_fsm_send_event(ioc, IOC_E_DETACH);
1856 * Setup IOC PCI properties.
1858 * @param[in] pcidev PCI device information for this IOC
1861 bfa_nw_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
1865 ioc->pcidev = *pcidev;
1866 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
1867 ioc->cna = ioc->ctdev && !ioc->fcmode;
1869 bfa_nw_ioc_set_ct_hwif(ioc);
1871 bfa_ioc_map_port(ioc);
1872 bfa_ioc_reg_init(ioc);
1876 * Initialize IOC dma memory
1878 * @param[in] dm_kva kernel virtual address of IOC dma memory
1879 * @param[in] dm_pa physical address of IOC dma memory
1882 bfa_nw_ioc_mem_claim(struct bfa_ioc *ioc, u8 *dm_kva, u64 dm_pa)
1885 * dma memory for firmware attribute
1887 ioc->attr_dma.kva = dm_kva;
1888 ioc->attr_dma.pa = dm_pa;
1889 ioc->attr = (struct bfi_ioc_attr *) dm_kva;
1893 * Return size of dma memory required.
1896 bfa_nw_ioc_meminfo(void)
1898 return roundup(sizeof(struct bfi_ioc_attr), BFA_DMA_ALIGN_SZ);
1902 bfa_nw_ioc_enable(struct bfa_ioc *ioc)
1904 bfa_ioc_stats(ioc, ioc_enables);
1905 ioc->dbg_fwsave_once = true;
1907 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
1911 bfa_nw_ioc_disable(struct bfa_ioc *ioc)
1913 bfa_ioc_stats(ioc, ioc_disables);
1914 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
1918 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr)
1920 return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
1924 bfa_ioc_smem_pgoff(struct bfa_ioc *ioc, u32 fmaddr)
1926 return PSS_SMEM_PGOFF(fmaddr);
1930 * Register mailbox message handler function, to be called by common modules
1933 bfa_nw_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
1934 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
1936 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1938 mod->mbhdlr[mc].cbfn = cbfn;
1939 mod->mbhdlr[mc].cbarg = cbarg;
1943 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
1944 * Responsibility of caller to serialize
1946 * @param[in] ioc IOC instance
1947 * @param[i] cmd Mailbox command
1950 bfa_nw_ioc_mbox_queue(struct bfa_ioc *ioc, struct bfa_mbox_cmd *cmd)
1952 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1956 * If a previous command is pending, queue new command
1958 if (!list_empty(&mod->cmd_q)) {
1959 list_add_tail(&cmd->qe, &mod->cmd_q);
1964 * If mailbox is busy, queue command for poll timer
1966 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1968 list_add_tail(&cmd->qe, &mod->cmd_q);
1973 * mailbox is free -- queue command to firmware
1975 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1979 * Handle mailbox interrupts
1982 bfa_nw_ioc_mbox_isr(struct bfa_ioc *ioc)
1984 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1988 bfa_ioc_msgget(ioc, &m);
1991 * Treat IOC message class as special.
1993 mc = m.mh.msg_class;
1994 if (mc == BFI_MC_IOC) {
1995 bfa_ioc_isr(ioc, &m);
1999 if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2002 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2006 bfa_nw_ioc_error_isr(struct bfa_ioc *ioc)
2008 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2012 * Add to IOC heartbeat failure notification queue. To be used by common
2013 * modules such as cee, port, diag.
2016 bfa_nw_ioc_hbfail_register(struct bfa_ioc *ioc,
2017 struct bfa_ioc_hbfail_notify *notify)
2019 list_add_tail(¬ify->qe, &ioc->hb_notify_q);
2022 #define BFA_MFG_NAME "Brocade"
2024 bfa_ioc_get_adapter_attr(struct bfa_ioc *ioc,
2025 struct bfa_adapter_attr *ad_attr)
2027 struct bfi_ioc_attr *ioc_attr;
2029 ioc_attr = ioc->attr;
2031 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2032 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2033 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2034 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
2035 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
2036 sizeof(struct bfa_mfg_vpd));
2038 ad_attr->nports = bfa_ioc_get_nports(ioc);
2039 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
2041 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2042 /* For now, model descr uses same model string */
2043 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
2045 ad_attr->card_type = ioc_attr->card_type;
2046 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2048 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2049 ad_attr->prototype = 1;
2051 ad_attr->prototype = 0;
2053 ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
2054 ad_attr->mac = bfa_nw_ioc_get_mac(ioc);
2056 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2057 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2058 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2059 ad_attr->asic_rev = ioc_attr->asic_rev;
2061 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
2063 ad_attr->cna_capable = ioc->cna;
2064 ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna;
2067 static enum bfa_ioc_type
2068 bfa_ioc_get_type(struct bfa_ioc *ioc)
2070 if (!ioc->ctdev || ioc->fcmode)
2071 return BFA_IOC_TYPE_FC;
2072 else if (ioc->ioc_mc == BFI_MC_IOCFC)
2073 return BFA_IOC_TYPE_FCoE;
2074 else if (ioc->ioc_mc == BFI_MC_LL)
2075 return BFA_IOC_TYPE_LL;
2077 BUG_ON(!(ioc->ioc_mc == BFI_MC_LL));
2078 return BFA_IOC_TYPE_LL;
2083 bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc, char *serial_num)
2085 memset(serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2087 (void *)ioc->attr->brcd_serialnum,
2088 BFA_ADAPTER_SERIAL_NUM_LEN);
2092 bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc, char *fw_ver)
2094 memset(fw_ver, 0, BFA_VERSION_LEN);
2095 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
2099 bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc, char *chip_rev)
2101 BUG_ON(!(chip_rev));
2103 memset(chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
2109 chip_rev[4] = ioc->attr->asic_rev;
2114 bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver)
2116 memset(optrom_ver, 0, BFA_VERSION_LEN);
2117 memcpy(optrom_ver, ioc->attr->optrom_version,
2122 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer)
2124 memset(manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2125 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
2129 bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model)
2131 struct bfi_ioc_attr *ioc_attr;
2134 memset(model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
2136 ioc_attr = ioc->attr;
2141 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2142 BFA_MFG_NAME, ioc_attr->card_type);
2145 static enum bfa_ioc_state
2146 bfa_ioc_get_state(struct bfa_ioc *ioc)
2148 enum bfa_iocpf_state iocpf_st;
2149 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2151 if (ioc_st == BFA_IOC_ENABLING ||
2152 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2154 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2157 case BFA_IOCPF_SEMWAIT:
2158 ioc_st = BFA_IOC_SEMWAIT;
2161 case BFA_IOCPF_HWINIT:
2162 ioc_st = BFA_IOC_HWINIT;
2165 case BFA_IOCPF_FWMISMATCH:
2166 ioc_st = BFA_IOC_FWMISMATCH;
2169 case BFA_IOCPF_FAIL:
2170 ioc_st = BFA_IOC_FAIL;
2173 case BFA_IOCPF_INITFAIL:
2174 ioc_st = BFA_IOC_INITFAIL;
2185 bfa_nw_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr)
2187 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr));
2189 ioc_attr->state = bfa_ioc_get_state(ioc);
2190 ioc_attr->port_id = ioc->port_id;
2192 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
2194 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2196 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2197 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
2198 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
2205 bfa_ioc_get_pwwn(struct bfa_ioc *ioc)
2207 return ioc->attr->pwwn;
2211 bfa_nw_ioc_get_mac(struct bfa_ioc *ioc)
2213 return ioc->attr->mac;
2217 * Firmware failure detected. Start recovery actions.
2220 bfa_ioc_recover(struct bfa_ioc *ioc)
2224 bdf = (ioc->pcidev.pci_slot << 8 | ioc->pcidev.pci_func << 3 |
2225 ioc->pcidev.device_id);
2227 pr_crit("Firmware heartbeat failure at %d", bdf);
2232 bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc)
2234 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2239 * @dg hal_iocpf_pvt BFA IOC PF private functions
2244 bfa_iocpf_enable(struct bfa_ioc *ioc)
2246 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
2250 bfa_iocpf_disable(struct bfa_ioc *ioc)
2252 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
2256 bfa_iocpf_fail(struct bfa_ioc *ioc)
2258 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
2262 bfa_iocpf_initfail(struct bfa_ioc *ioc)
2264 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
2268 bfa_iocpf_getattrfail(struct bfa_ioc *ioc)
2270 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
2274 bfa_iocpf_stop(struct bfa_ioc *ioc)
2276 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
2280 bfa_nw_iocpf_timeout(void *ioc_arg)
2282 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
2284 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2288 bfa_nw_iocpf_sem_timeout(void *ioc_arg)
2290 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
2292 bfa_ioc_hw_sem_get(ioc);