2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
20 #include <bfa_fwimg_priv.h>
21 #include <cna/bfa_cna_trcmod.h>
22 #include <cs/bfa_debug.h>
23 #include <bfi/bfi_ioc.h>
24 #include <bfi/bfi_ctreg.h>
25 #include <aen/bfa_aen_ioc.h>
26 #include <aen/bfa_aen.h>
27 #include <log/bfa_log_hal.h>
28 #include <defs/bfa_defs_pci.h>
30 BFA_TRC_FILE(CNA, IOC);
33 * IOC local definitions
35 #define BFA_IOC_TOV 2000 /* msecs */
36 #define BFA_IOC_HWSEM_TOV 500 /* msecs */
37 #define BFA_IOC_HB_TOV 500 /* msecs */
38 #define BFA_IOC_HWINIT_MAX 2
39 #define BFA_IOC_FWIMG_MINSZ (16 * 1024)
40 #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
42 #define bfa_ioc_timer_start(__ioc) \
43 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
44 bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
45 #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
47 #define BFA_DBG_FWTRC_ENTS (BFI_IOC_TRC_ENTS)
48 #define BFA_DBG_FWTRC_LEN \
49 (BFA_DBG_FWTRC_ENTS * sizeof(struct bfa_trc_s) + \
50 (sizeof(struct bfa_trc_mod_s) - \
51 BFA_TRC_MAX * sizeof(struct bfa_trc_s)))
52 #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
55 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
58 #define bfa_ioc_firmware_lock(__ioc) \
59 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
60 #define bfa_ioc_firmware_unlock(__ioc) \
61 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
62 #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
63 #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
64 #define bfa_ioc_notify_hbfail(__ioc) \
65 ((__ioc)->ioc_hwif->ioc_notify_hbfail(__ioc))
66 #define bfa_ioc_is_optrom(__ioc) \
67 (bfi_image_get_size(BFA_IOC_FWIMG_TYPE(__ioc)) < BFA_IOC_FWIMG_MINSZ)
69 bfa_boolean_t bfa_auto_recover = BFA_TRUE;
72 * forward declarations
74 static void bfa_ioc_aen_post(struct bfa_ioc_s *bfa,
75 enum bfa_ioc_aen_event event);
76 static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
77 static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc);
78 static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
79 static void bfa_ioc_timeout(void *ioc);
80 static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
81 static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
82 static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
83 static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
84 static void bfa_ioc_hb_stop(struct bfa_ioc_s *ioc);
85 static void bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force);
86 static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
87 static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc);
88 static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
89 static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
90 static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
97 * IOC state machine events
100 IOC_E_ENABLE = 1, /* IOC enable request */
101 IOC_E_DISABLE = 2, /* IOC disable request */
102 IOC_E_TIMEOUT = 3, /* f/w response timeout */
103 IOC_E_FWREADY = 4, /* f/w initialization done */
104 IOC_E_FWRSP_GETATTR = 5, /* IOC get attribute response */
105 IOC_E_FWRSP_ENABLE = 6, /* enable f/w response */
106 IOC_E_FWRSP_DISABLE = 7, /* disable f/w response */
107 IOC_E_HBFAIL = 8, /* heartbeat failure */
108 IOC_E_HWERROR = 9, /* hardware error interrupt */
109 IOC_E_SEMLOCKED = 10, /* h/w semaphore is locked */
110 IOC_E_DETACH = 11, /* driver detach cleanup */
113 bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
114 bfa_fsm_state_decl(bfa_ioc, fwcheck, struct bfa_ioc_s, enum ioc_event);
115 bfa_fsm_state_decl(bfa_ioc, mismatch, struct bfa_ioc_s, enum ioc_event);
116 bfa_fsm_state_decl(bfa_ioc, semwait, struct bfa_ioc_s, enum ioc_event);
117 bfa_fsm_state_decl(bfa_ioc, hwinit, struct bfa_ioc_s, enum ioc_event);
118 bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
119 bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
120 bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
121 bfa_fsm_state_decl(bfa_ioc, initfail, struct bfa_ioc_s, enum ioc_event);
122 bfa_fsm_state_decl(bfa_ioc, hbfail, struct bfa_ioc_s, enum ioc_event);
123 bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
124 bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
126 static struct bfa_sm_table_s ioc_sm_table[] = {
127 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
128 {BFA_SM(bfa_ioc_sm_fwcheck), BFA_IOC_FWMISMATCH},
129 {BFA_SM(bfa_ioc_sm_mismatch), BFA_IOC_FWMISMATCH},
130 {BFA_SM(bfa_ioc_sm_semwait), BFA_IOC_SEMWAIT},
131 {BFA_SM(bfa_ioc_sm_hwinit), BFA_IOC_HWINIT},
132 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_HWINIT},
133 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
134 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
135 {BFA_SM(bfa_ioc_sm_initfail), BFA_IOC_INITFAIL},
136 {BFA_SM(bfa_ioc_sm_hbfail), BFA_IOC_HBFAIL},
137 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
138 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
142 * Reset entry actions -- initialize state machine
145 bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
147 ioc->retry_count = 0;
148 ioc->auto_recover = bfa_auto_recover;
152 * Beginning state. IOC is in reset state.
155 bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
161 bfa_fsm_set_state(ioc, bfa_ioc_sm_fwcheck);
165 bfa_ioc_disable_comp(ioc);
172 bfa_sm_fault(ioc, event);
177 * Semaphore should be acquired for version check.
180 bfa_ioc_sm_fwcheck_entry(struct bfa_ioc_s *ioc)
182 bfa_ioc_hw_sem_get(ioc);
186 * Awaiting h/w semaphore to continue with version check.
189 bfa_ioc_sm_fwcheck(struct bfa_ioc_s *ioc, enum ioc_event event)
194 case IOC_E_SEMLOCKED:
195 if (bfa_ioc_firmware_lock(ioc)) {
196 ioc->retry_count = 0;
197 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
199 bfa_ioc_hw_sem_release(ioc);
200 bfa_fsm_set_state(ioc, bfa_ioc_sm_mismatch);
205 bfa_ioc_disable_comp(ioc);
211 bfa_ioc_hw_sem_get_cancel(ioc);
212 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
219 bfa_sm_fault(ioc, event);
224 * Notify enable completion callback and generate mismatch AEN.
227 bfa_ioc_sm_mismatch_entry(struct bfa_ioc_s *ioc)
230 * Provide enable completion callback and AEN notification only once.
232 if (ioc->retry_count == 0) {
233 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
234 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH);
237 bfa_ioc_timer_start(ioc);
241 * Awaiting firmware version match.
244 bfa_ioc_sm_mismatch(struct bfa_ioc_s *ioc, enum ioc_event event)
250 bfa_fsm_set_state(ioc, bfa_ioc_sm_fwcheck);
254 bfa_ioc_disable_comp(ioc);
260 bfa_ioc_timer_stop(ioc);
261 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
268 bfa_sm_fault(ioc, event);
273 * Request for semaphore.
276 bfa_ioc_sm_semwait_entry(struct bfa_ioc_s *ioc)
278 bfa_ioc_hw_sem_get(ioc);
282 * Awaiting semaphore for h/w initialzation.
285 bfa_ioc_sm_semwait(struct bfa_ioc_s *ioc, enum ioc_event event)
290 case IOC_E_SEMLOCKED:
291 ioc->retry_count = 0;
292 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
296 bfa_ioc_hw_sem_get_cancel(ioc);
297 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
301 bfa_sm_fault(ioc, event);
307 bfa_ioc_sm_hwinit_entry(struct bfa_ioc_s *ioc)
309 bfa_ioc_timer_start(ioc);
310 bfa_ioc_reset(ioc, BFA_FALSE);
314 * Hardware is being initialized. Interrupts are enabled.
315 * Holding hardware semaphore lock.
318 bfa_ioc_sm_hwinit(struct bfa_ioc_s *ioc, enum ioc_event event)
324 bfa_ioc_timer_stop(ioc);
325 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
329 bfa_ioc_timer_stop(ioc);
336 if (ioc->retry_count < BFA_IOC_HWINIT_MAX) {
337 bfa_ioc_timer_start(ioc);
338 bfa_ioc_reset(ioc, BFA_TRUE);
342 bfa_ioc_hw_sem_release(ioc);
343 bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
347 bfa_ioc_hw_sem_release(ioc);
348 bfa_ioc_timer_stop(ioc);
349 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
353 bfa_sm_fault(ioc, event);
359 bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
361 bfa_ioc_timer_start(ioc);
362 bfa_ioc_send_enable(ioc);
366 * Host IOC function is being enabled, awaiting response from firmware.
367 * Semaphore is acquired.
370 bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
375 case IOC_E_FWRSP_ENABLE:
376 bfa_ioc_timer_stop(ioc);
377 bfa_ioc_hw_sem_release(ioc);
378 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
382 bfa_ioc_timer_stop(ioc);
389 if (ioc->retry_count < BFA_IOC_HWINIT_MAX) {
390 bfa_reg_write(ioc->ioc_regs.ioc_fwstate,
392 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwinit);
396 bfa_ioc_hw_sem_release(ioc);
397 bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
401 bfa_ioc_timer_stop(ioc);
402 bfa_ioc_hw_sem_release(ioc);
403 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
407 bfa_ioc_send_enable(ioc);
411 bfa_sm_fault(ioc, event);
417 bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
419 bfa_ioc_timer_start(ioc);
420 bfa_ioc_send_getattr(ioc);
424 * IOC configuration in progress. Timer is active.
427 bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
432 case IOC_E_FWRSP_GETATTR:
433 bfa_ioc_timer_stop(ioc);
434 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
438 bfa_ioc_timer_stop(ioc);
444 bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
448 bfa_ioc_timer_stop(ioc);
449 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
453 bfa_sm_fault(ioc, event);
459 bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
461 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
462 bfa_ioc_hb_monitor(ioc);
463 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE);
467 bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
476 bfa_ioc_hb_stop(ioc);
477 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
483 * Hard error or IOC recovery by other function.
484 * Treat it same as heartbeat failure.
486 bfa_ioc_hb_stop(ioc);
488 * !!! fall through !!!
492 bfa_fsm_set_state(ioc, bfa_ioc_sm_hbfail);
496 bfa_sm_fault(ioc, event);
502 bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
504 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_DISABLE);
505 bfa_ioc_timer_start(ioc);
506 bfa_ioc_send_disable(ioc);
510 * IOC is being disabled
513 bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
518 case IOC_E_FWRSP_DISABLE:
519 bfa_ioc_timer_stop(ioc);
520 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
524 bfa_ioc_timer_stop(ioc);
526 * !!! fall through !!!
530 bfa_reg_write(ioc->ioc_regs.ioc_fwstate, BFI_IOC_FAIL);
531 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
535 bfa_sm_fault(ioc, event);
540 * IOC disable completion entry.
543 bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
545 bfa_ioc_disable_comp(ioc);
549 bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
555 bfa_fsm_set_state(ioc, bfa_ioc_sm_semwait);
559 ioc->cbfn->disable_cbfn(ioc->bfa);
566 bfa_ioc_firmware_unlock(ioc);
567 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
571 bfa_sm_fault(ioc, event);
577 bfa_ioc_sm_initfail_entry(struct bfa_ioc_s *ioc)
579 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
580 bfa_ioc_timer_start(ioc);
584 * Hardware initialization failed.
587 bfa_ioc_sm_initfail(struct bfa_ioc_s *ioc, enum ioc_event event)
593 bfa_ioc_timer_stop(ioc);
594 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
598 bfa_ioc_timer_stop(ioc);
599 bfa_ioc_firmware_unlock(ioc);
600 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
604 bfa_fsm_set_state(ioc, bfa_ioc_sm_semwait);
608 bfa_sm_fault(ioc, event);
614 bfa_ioc_sm_hbfail_entry(struct bfa_ioc_s *ioc)
616 struct list_head *qe;
617 struct bfa_ioc_hbfail_notify_s *notify;
620 * Mark IOC as failed in hardware and stop firmware.
622 bfa_ioc_lpu_stop(ioc);
623 bfa_reg_write(ioc->ioc_regs.ioc_fwstate, BFI_IOC_FAIL);
626 * Notify other functions on HB failure.
628 bfa_ioc_notify_hbfail(ioc);
631 * Notify driver and common modules registered for notification.
633 ioc->cbfn->hbfail_cbfn(ioc->bfa);
634 list_for_each(qe, &ioc->hb_notify_q) {
635 notify = (struct bfa_ioc_hbfail_notify_s *)qe;
636 notify->cbfn(notify->cbarg);
640 * Flush any queued up mailbox requests.
642 bfa_ioc_mbox_hbfail(ioc);
643 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_HBFAIL);
646 * Trigger auto-recovery after a delay.
648 if (ioc->auto_recover) {
649 bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer,
650 bfa_ioc_timeout, ioc, BFA_IOC_TOV_RECOVER);
655 * IOC heartbeat failure.
658 bfa_ioc_sm_hbfail(struct bfa_ioc_s *ioc, enum ioc_event event)
665 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
669 if (ioc->auto_recover)
670 bfa_ioc_timer_stop(ioc);
671 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
675 bfa_fsm_set_state(ioc, bfa_ioc_sm_semwait);
680 * Recovery is already initiated by other function.
686 * HB failure notification, ignore.
691 bfa_sm_fault(ioc, event);
698 * bfa_ioc_pvt BFA IOC private functions
702 bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
704 struct list_head *qe;
705 struct bfa_ioc_hbfail_notify_s *notify;
707 ioc->cbfn->disable_cbfn(ioc->bfa);
710 * Notify common modules registered for notification.
712 list_for_each(qe, &ioc->hb_notify_q) {
713 notify = (struct bfa_ioc_hbfail_notify_s *)qe;
714 notify->cbfn(notify->cbarg);
719 bfa_ioc_sem_timeout(void *ioc_arg)
721 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *)ioc_arg;
723 bfa_ioc_hw_sem_get(ioc);
727 bfa_ioc_sem_get(bfa_os_addr_t sem_reg)
731 #define BFA_SEM_SPINCNT 3000
733 r32 = bfa_reg_read(sem_reg);
735 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
738 r32 = bfa_reg_read(sem_reg);
744 bfa_assert(cnt < BFA_SEM_SPINCNT);
749 bfa_ioc_sem_release(bfa_os_addr_t sem_reg)
751 bfa_reg_write(sem_reg, 1);
755 bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
760 * First read to the semaphore register will return 0, subsequent reads
761 * will return 1. Semaphore is released by writing 1 to the register
763 r32 = bfa_reg_read(ioc->ioc_regs.ioc_sem_reg);
765 bfa_fsm_send_event(ioc, IOC_E_SEMLOCKED);
769 bfa_timer_begin(ioc->timer_mod, &ioc->sem_timer, bfa_ioc_sem_timeout,
770 ioc, BFA_IOC_HWSEM_TOV);
774 bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc)
776 bfa_reg_write(ioc->ioc_regs.ioc_sem_reg, 1);
780 bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc)
782 bfa_timer_stop(&ioc->sem_timer);
786 * Initialize LPU local memory (aka secondary memory / SRAM)
789 bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
793 #define PSS_LMEM_INIT_TIME 10000
795 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
796 pss_ctl &= ~__PSS_LMEM_RESET;
797 pss_ctl |= __PSS_LMEM_INIT_EN;
798 pss_ctl |= __PSS_I2C_CLK_DIV(3UL); /* i2c workaround 12.5khz clock */
799 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
802 * wait for memory initialization to be complete
806 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
808 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
811 * If memory initialization is not successful, IOC timeout will catch
814 bfa_assert(pss_ctl & __PSS_LMEM_INIT_DONE);
815 bfa_trc(ioc, pss_ctl);
817 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
818 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
822 bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
827 * Take processor out of reset.
829 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
830 pss_ctl &= ~__PSS_LPU0_RESET;
832 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
836 bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
841 * Put processors in reset.
843 pss_ctl = bfa_reg_read(ioc->ioc_regs.pss_ctl_reg);
844 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
846 bfa_reg_write(ioc->ioc_regs.pss_ctl_reg, pss_ctl);
850 * Get driver and firmware versions.
853 bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
858 u32 *fwsig = (u32 *) fwhdr;
860 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
861 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
862 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
864 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
866 fwsig[i] = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
872 * Returns TRUE if same.
875 bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
877 struct bfi_ioc_image_hdr_s *drv_fwhdr;
880 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
881 bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
883 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
884 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
886 bfa_trc(ioc, fwhdr->md5sum[i]);
887 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
892 bfa_trc(ioc, fwhdr->md5sum[0]);
897 * Return true if current running version is valid. Firmware signature and
898 * execution context (driver/bios) must match.
901 bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc)
903 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
906 * If bios/efi boot (flash based) -- return true
908 if (bfa_ioc_is_optrom(ioc))
911 bfa_ioc_fwver_get(ioc, &fwhdr);
912 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
913 bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
916 if (fwhdr.signature != drv_fwhdr->signature) {
917 bfa_trc(ioc, fwhdr.signature);
918 bfa_trc(ioc, drv_fwhdr->signature);
922 if (fwhdr.exec != drv_fwhdr->exec) {
923 bfa_trc(ioc, fwhdr.exec);
924 bfa_trc(ioc, drv_fwhdr->exec);
928 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
932 * Conditionally flush any pending message from firmware at start.
935 bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
939 r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd);
941 bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1);
946 bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
948 enum bfi_ioc_state ioc_fwstate;
949 bfa_boolean_t fwvalid;
951 ioc_fwstate = bfa_reg_read(ioc->ioc_regs.ioc_fwstate);
954 ioc_fwstate = BFI_IOC_UNINIT;
956 bfa_trc(ioc, ioc_fwstate);
959 * check if firmware is valid
961 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
962 BFA_FALSE : bfa_ioc_fwver_valid(ioc);
965 bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, ioc->pcidev.device_id);
970 * If hardware initialization is in progress (initialized by other IOC),
971 * just wait for an initialization completion interrupt.
973 if (ioc_fwstate == BFI_IOC_INITING) {
974 bfa_trc(ioc, ioc_fwstate);
975 ioc->cbfn->reset_cbfn(ioc->bfa);
980 * If IOC function is disabled and firmware version is same,
981 * just re-enable IOC.
983 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
984 bfa_trc(ioc, ioc_fwstate);
987 * When using MSI-X any pending firmware ready event should
988 * be flushed. Otherwise MSI-X interrupts are not delivered.
990 bfa_ioc_msgflush(ioc);
991 ioc->cbfn->reset_cbfn(ioc->bfa);
992 bfa_fsm_send_event(ioc, IOC_E_FWREADY);
997 * Initialize the h/w for any other states.
999 bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, ioc->pcidev.device_id);
1003 bfa_ioc_timeout(void *ioc_arg)
1005 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *)ioc_arg;
1008 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1012 bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1014 u32 *msgp = (u32 *) ioc_msg;
1017 bfa_trc(ioc, msgp[0]);
1020 bfa_assert(len <= BFI_IOC_MSGLEN_MAX);
1023 * first write msg to mailbox registers
1025 for (i = 0; i < len / sizeof(u32); i++)
1026 bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32),
1027 bfa_os_wtole(msgp[i]));
1029 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
1030 bfa_reg_write(ioc->ioc_regs.hfn_mbox + i * sizeof(u32), 0);
1033 * write 1 to mailbox CMD to trigger LPU event
1035 bfa_reg_write(ioc->ioc_regs.hfn_mbox_cmd, 1);
1036 (void)bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
1040 bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1042 struct bfi_ioc_ctrl_req_s enable_req;
1044 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1045 bfa_ioc_portid(ioc));
1046 enable_req.ioc_class = ioc->ioc_mc;
1047 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1051 bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1053 struct bfi_ioc_ctrl_req_s disable_req;
1055 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1056 bfa_ioc_portid(ioc));
1057 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1061 bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1063 struct bfi_ioc_getattr_req_s attr_req;
1065 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1066 bfa_ioc_portid(ioc));
1067 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1068 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1072 bfa_ioc_hb_check(void *cbarg)
1074 struct bfa_ioc_s *ioc = cbarg;
1077 hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat);
1078 if (ioc->hb_count == hb_count) {
1079 bfa_log(ioc->logm, BFA_LOG_HAL_HEARTBEAT_FAILURE,
1081 bfa_ioc_recover(ioc);
1084 ioc->hb_count = hb_count;
1087 bfa_ioc_mbox_poll(ioc);
1088 bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer, bfa_ioc_hb_check,
1089 ioc, BFA_IOC_HB_TOV);
1093 bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1095 ioc->hb_count = bfa_reg_read(ioc->ioc_regs.heartbeat);
1096 bfa_timer_begin(ioc->timer_mod, &ioc->ioc_timer, bfa_ioc_hb_check, ioc,
1101 bfa_ioc_hb_stop(struct bfa_ioc_s *ioc)
1103 bfa_timer_stop(&ioc->ioc_timer);
1107 * Initiate a full firmware download.
1110 bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
1120 * Initialize LMEM first before code download
1122 bfa_ioc_lmem_init(ioc);
1125 * Flash based firmware boot
1127 bfa_trc(ioc, bfi_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
1128 if (bfa_ioc_is_optrom(ioc))
1129 boot_type = BFI_BOOT_TYPE_FLASH;
1130 fwimg = bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
1133 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1134 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
1136 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
1138 for (i = 0; i < bfi_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
1140 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1141 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
1142 fwimg = bfi_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
1143 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
1149 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
1150 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
1152 loff += sizeof(u32);
1155 * handle page offset wrap around
1157 loff = PSS_SMEM_PGOFF(loff);
1160 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
1164 bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
1165 bfa_ioc_smem_pgnum(ioc, 0));
1168 * Set boot type and boot param at the end.
1170 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
1171 bfa_os_swap32(boot_type));
1172 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_PARAM_OFF,
1173 bfa_os_swap32(boot_param));
1177 bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1179 bfa_ioc_hwinit(ioc, force);
1183 * Update BFA configuration from firmware configuration.
1186 bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1188 struct bfi_ioc_attr_s *attr = ioc->attr;
1190 attr->adapter_prop = bfa_os_ntohl(attr->adapter_prop);
1191 attr->card_type = bfa_os_ntohl(attr->card_type);
1192 attr->maxfrsize = bfa_os_ntohs(attr->maxfrsize);
1194 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1198 * Attach time initialization of mbox logic.
1201 bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1203 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1206 INIT_LIST_HEAD(&mod->cmd_q);
1207 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1208 mod->mbhdlr[mc].cbfn = NULL;
1209 mod->mbhdlr[mc].cbarg = ioc->bfa;
1214 * Mbox poll timer -- restarts any pending mailbox requests.
1217 bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1219 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1220 struct bfa_mbox_cmd_s *cmd;
1224 * If no command pending, do nothing
1226 if (list_empty(&mod->cmd_q))
1230 * If previous command is not yet fetched by firmware, do nothing
1232 stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
1237 * Enqueue command to firmware.
1239 bfa_q_deq(&mod->cmd_q, &cmd);
1240 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1244 * Cleanup any pending requests.
1247 bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
1249 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1250 struct bfa_mbox_cmd_s *cmd;
1252 while (!list_empty(&mod->cmd_q))
1253 bfa_q_deq(&mod->cmd_q, &cmd);
1261 * Interface used by diag module to do firmware boot with memory test
1262 * as the entry vector.
1265 bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_param)
1269 bfa_ioc_stats(ioc, ioc_boots);
1271 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1275 * Initialize IOC state of all functions on a chip reset.
1277 rb = ioc->pcidev.pci_bar_kva;
1278 if (boot_param == BFI_BOOT_TYPE_MEMTEST) {
1279 bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_MEMTEST);
1280 bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_MEMTEST);
1282 bfa_reg_write((rb + BFA_IOC0_STATE_REG), BFI_IOC_INITING);
1283 bfa_reg_write((rb + BFA_IOC1_STATE_REG), BFI_IOC_INITING);
1286 bfa_ioc_download_fw(ioc, boot_type, boot_param);
1289 * Enable interrupts just before starting LPU
1291 ioc->cbfn->reset_cbfn(ioc->bfa);
1292 bfa_ioc_lpu_start(ioc);
1296 * Enable/disable IOC failure auto recovery.
1299 bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
1301 bfa_auto_recover = auto_recover;
1306 bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1308 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
1312 bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
1321 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1323 r32 = bfa_reg_read(ioc->ioc_regs.lpu_mbox +
1325 msgp[i] = bfa_os_htonl(r32);
1329 * turn off mailbox interrupt by clearing mailbox status
1331 bfa_reg_write(ioc->ioc_regs.lpu_mbox_cmd, 1);
1332 bfa_reg_read(ioc->ioc_regs.lpu_mbox_cmd);
1336 bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
1338 union bfi_ioc_i2h_msg_u *msg;
1340 msg = (union bfi_ioc_i2h_msg_u *)m;
1342 bfa_ioc_stats(ioc, ioc_isrs);
1344 switch (msg->mh.msg_id) {
1345 case BFI_IOC_I2H_HBEAT:
1348 case BFI_IOC_I2H_READY_EVENT:
1349 bfa_fsm_send_event(ioc, IOC_E_FWREADY);
1352 case BFI_IOC_I2H_ENABLE_REPLY:
1353 bfa_fsm_send_event(ioc, IOC_E_FWRSP_ENABLE);
1356 case BFI_IOC_I2H_DISABLE_REPLY:
1357 bfa_fsm_send_event(ioc, IOC_E_FWRSP_DISABLE);
1360 case BFI_IOC_I2H_GETATTR_REPLY:
1361 bfa_ioc_getattr_reply(ioc);
1365 bfa_trc(ioc, msg->mh.msg_id);
1371 * IOC attach time initialization and setup.
1373 * @param[in] ioc memory for IOC
1374 * @param[in] bfa driver instance structure
1375 * @param[in] trcmod kernel trace module
1376 * @param[in] aen kernel aen event module
1377 * @param[in] logm kernel logging module
1380 bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
1381 struct bfa_timer_mod_s *timer_mod, struct bfa_trc_mod_s *trcmod,
1382 struct bfa_aen_s *aen, struct bfa_log_mod_s *logm)
1386 ioc->timer_mod = timer_mod;
1387 ioc->trcmod = trcmod;
1390 ioc->fcmode = BFA_FALSE;
1391 ioc->pllinit = BFA_FALSE;
1392 ioc->dbg_fwsave_once = BFA_TRUE;
1394 bfa_ioc_mbox_attach(ioc);
1395 INIT_LIST_HEAD(&ioc->hb_notify_q);
1397 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
1401 * Driver detach time IOC cleanup.
1404 bfa_ioc_detach(struct bfa_ioc_s *ioc)
1406 bfa_fsm_send_event(ioc, IOC_E_DETACH);
1410 * Setup IOC PCI properties.
1412 * @param[in] pcidev PCI device information for this IOC
1415 bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
1419 ioc->pcidev = *pcidev;
1420 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
1421 ioc->cna = ioc->ctdev && !ioc->fcmode;
1424 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
1427 bfa_ioc_set_ct_hwif(ioc);
1429 bfa_ioc_set_cb_hwif(ioc);
1431 bfa_ioc_map_port(ioc);
1432 bfa_ioc_reg_init(ioc);
1436 * Initialize IOC dma memory
1438 * @param[in] dm_kva kernel virtual address of IOC dma memory
1439 * @param[in] dm_pa physical address of IOC dma memory
1442 bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
1445 * dma memory for firmware attribute
1447 ioc->attr_dma.kva = dm_kva;
1448 ioc->attr_dma.pa = dm_pa;
1449 ioc->attr = (struct bfi_ioc_attr_s *)dm_kva;
1453 * Return size of dma memory required.
1456 bfa_ioc_meminfo(void)
1458 return BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
1462 bfa_ioc_enable(struct bfa_ioc_s *ioc)
1464 bfa_ioc_stats(ioc, ioc_enables);
1465 ioc->dbg_fwsave_once = BFA_TRUE;
1467 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
1471 bfa_ioc_disable(struct bfa_ioc_s *ioc)
1473 bfa_ioc_stats(ioc, ioc_disables);
1474 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
1478 * Returns memory required for saving firmware trace in case of crash.
1479 * Driver must call this interface to allocate memory required for
1480 * automatic saving of firmware trace. Driver should call
1481 * bfa_ioc_debug_memclaim() right after bfa_ioc_attach() to setup this
1485 bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover)
1487 return (auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
1491 * Initialize memory for saving firmware trace. Driver must initialize
1492 * trace memory before call bfa_ioc_enable().
1495 bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
1497 ioc->dbg_fwsave = dbg_fwsave;
1498 ioc->dbg_fwsave_len = bfa_ioc_debug_trcsz(ioc->auto_recover);
1502 bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr)
1504 return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
1508 bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr)
1510 return PSS_SMEM_PGOFF(fmaddr);
1514 * Register mailbox message handler functions
1516 * @param[in] ioc IOC instance
1517 * @param[in] mcfuncs message class handler functions
1520 bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
1522 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1525 for (mc = 0; mc < BFI_MC_MAX; mc++)
1526 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
1530 * Register mailbox message handler function, to be called by common modules
1533 bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
1534 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
1536 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1538 mod->mbhdlr[mc].cbfn = cbfn;
1539 mod->mbhdlr[mc].cbarg = cbarg;
1543 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
1544 * Responsibility of caller to serialize
1546 * @param[in] ioc IOC instance
1547 * @param[i] cmd Mailbox command
1550 bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
1552 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1556 * If a previous command is pending, queue new command
1558 if (!list_empty(&mod->cmd_q)) {
1559 list_add_tail(&cmd->qe, &mod->cmd_q);
1564 * If mailbox is busy, queue command for poll timer
1566 stat = bfa_reg_read(ioc->ioc_regs.hfn_mbox_cmd);
1568 list_add_tail(&cmd->qe, &mod->cmd_q);
1573 * mailbox is free -- queue command to firmware
1575 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1579 * Handle mailbox interrupts
1582 bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
1584 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1585 struct bfi_mbmsg_s m;
1588 bfa_ioc_msgget(ioc, &m);
1591 * Treat IOC message class as special.
1593 mc = m.mh.msg_class;
1594 if (mc == BFI_MC_IOC) {
1595 bfa_ioc_isr(ioc, &m);
1599 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
1602 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
1606 bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
1608 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
1612 bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
1614 ioc->fcmode = BFA_TRUE;
1615 ioc->port_id = bfa_ioc_pcifn(ioc);
1618 #ifndef BFA_BIOS_BUILD
1621 * return true if IOC is disabled
1624 bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
1626 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling)
1627 || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
1631 * return true if IOC firmware is different.
1634 bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
1636 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset)
1637 || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_fwcheck)
1638 || bfa_fsm_cmp_state(ioc, bfa_ioc_sm_mismatch);
1641 #define bfa_ioc_state_disabled(__sm) \
1642 (((__sm) == BFI_IOC_UNINIT) || \
1643 ((__sm) == BFI_IOC_INITING) || \
1644 ((__sm) == BFI_IOC_HWINIT) || \
1645 ((__sm) == BFI_IOC_DISABLED) || \
1646 ((__sm) == BFI_IOC_FAIL) || \
1647 ((__sm) == BFI_IOC_CFG_DISABLED))
1650 * Check if adapter is disabled -- both IOCs should be in a disabled
1654 bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
1657 bfa_os_addr_t rb = ioc->pcidev.pci_bar_kva;
1659 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
1662 ioc_state = bfa_reg_read(rb + BFA_IOC0_STATE_REG);
1663 if (!bfa_ioc_state_disabled(ioc_state))
1666 ioc_state = bfa_reg_read(rb + BFA_IOC1_STATE_REG);
1667 if (!bfa_ioc_state_disabled(ioc_state))
1674 * Add to IOC heartbeat failure notification queue. To be used by common
1678 bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
1679 struct bfa_ioc_hbfail_notify_s *notify)
1681 list_add_tail(¬ify->qe, &ioc->hb_notify_q);
1684 #define BFA_MFG_NAME "Brocade"
1686 bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
1687 struct bfa_adapter_attr_s *ad_attr)
1689 struct bfi_ioc_attr_s *ioc_attr;
1691 ioc_attr = ioc->attr;
1693 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
1694 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
1695 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
1696 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
1697 bfa_os_memcpy(&ad_attr->vpd, &ioc_attr->vpd,
1698 sizeof(struct bfa_mfg_vpd_s));
1700 ad_attr->nports = bfa_ioc_get_nports(ioc);
1701 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
1703 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
1704 /* For now, model descr uses same model string */
1705 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
1707 ad_attr->card_type = ioc_attr->card_type;
1708 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
1710 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
1711 ad_attr->prototype = 1;
1713 ad_attr->prototype = 0;
1715 ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
1716 ad_attr->mac = bfa_ioc_get_mac(ioc);
1718 ad_attr->pcie_gen = ioc_attr->pcie_gen;
1719 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
1720 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
1721 ad_attr->asic_rev = ioc_attr->asic_rev;
1723 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
1725 ad_attr->cna_capable = ioc->cna;
1729 bfa_ioc_get_type(struct bfa_ioc_s *ioc)
1731 if (!ioc->ctdev || ioc->fcmode)
1732 return BFA_IOC_TYPE_FC;
1733 else if (ioc->ioc_mc == BFI_MC_IOCFC)
1734 return BFA_IOC_TYPE_FCoE;
1735 else if (ioc->ioc_mc == BFI_MC_LL)
1736 return BFA_IOC_TYPE_LL;
1738 bfa_assert(ioc->ioc_mc == BFI_MC_LL);
1739 return BFA_IOC_TYPE_LL;
1744 bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
1746 bfa_os_memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
1747 bfa_os_memcpy((void *)serial_num,
1748 (void *)ioc->attr->brcd_serialnum,
1749 BFA_ADAPTER_SERIAL_NUM_LEN);
1753 bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
1755 bfa_os_memset((void *)fw_ver, 0, BFA_VERSION_LEN);
1756 bfa_os_memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
1760 bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
1762 bfa_assert(chip_rev);
1764 bfa_os_memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
1770 chip_rev[4] = ioc->attr->asic_rev;
1775 bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
1777 bfa_os_memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
1778 bfa_os_memcpy(optrom_ver, ioc->attr->optrom_version,
1783 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
1785 bfa_os_memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
1786 bfa_os_memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
1790 bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
1792 struct bfi_ioc_attr_s *ioc_attr;
1797 bfa_os_memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
1799 ioc_attr = ioc->attr;
1801 nports = bfa_ioc_get_nports(ioc);
1802 max_speed = bfa_ioc_speed_sup(ioc);
1807 if (max_speed == 10) {
1808 strcpy(model, "BR-10?0");
1809 model[5] = '0' + nports;
1811 strcpy(model, "Brocade-??5");
1812 model[8] = '0' + max_speed;
1813 model[9] = '0' + nports;
1818 bfa_ioc_get_state(struct bfa_ioc_s *ioc)
1820 return bfa_sm_to_state(ioc_sm_table, ioc->fsm);
1824 bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
1826 bfa_os_memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
1828 ioc_attr->state = bfa_ioc_get_state(ioc);
1829 ioc_attr->port_id = ioc->port_id;
1831 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
1833 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
1835 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
1836 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
1837 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
1844 bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc)
1848 u8 byte[sizeof(wwn_t)];
1852 w.wwn = ioc->attr->mfg_wwn;
1854 if (bfa_ioc_portid(ioc) == 1)
1861 bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc)
1865 u8 byte[sizeof(wwn_t)];
1869 w.wwn = ioc->attr->mfg_wwn;
1871 if (bfa_ioc_portid(ioc) == 1)
1880 bfa_ioc_get_adid(struct bfa_ioc_s *ioc)
1882 return ioc->attr->mfg_wwn;
1886 bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
1890 mac = ioc->attr->mfg_mac;
1891 mac.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
1897 bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
1899 return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
1903 * Send AEN notification
1906 bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
1908 union bfa_aen_data_u aen_data;
1909 struct bfa_log_mod_s *logmod = ioc->logm;
1911 enum bfa_ioc_type_e ioc_type;
1913 bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_IOC, event), inst_num);
1915 memset(&aen_data.ioc.pwwn, 0, sizeof(aen_data.ioc.pwwn));
1916 memset(&aen_data.ioc.mac, 0, sizeof(aen_data.ioc.mac));
1917 ioc_type = bfa_ioc_get_type(ioc);
1919 case BFA_IOC_TYPE_FC:
1920 aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
1922 case BFA_IOC_TYPE_FCoE:
1923 aen_data.ioc.pwwn = bfa_ioc_get_pwwn(ioc);
1924 aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
1926 case BFA_IOC_TYPE_LL:
1927 aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
1930 bfa_assert(ioc_type == BFA_IOC_TYPE_FC);
1933 aen_data.ioc.ioc_type = ioc_type;
1937 * Retrieve saved firmware trace from a prior IOC failure.
1940 bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
1944 if (ioc->dbg_fwsave_len == 0)
1945 return BFA_STATUS_ENOFSAVE;
1948 if (tlen > ioc->dbg_fwsave_len)
1949 tlen = ioc->dbg_fwsave_len;
1951 bfa_os_memcpy(trcdata, ioc->dbg_fwsave, tlen);
1953 return BFA_STATUS_OK;
1957 * Clear saved firmware trace
1960 bfa_ioc_debug_fwsave_clear(struct bfa_ioc_s *ioc)
1962 ioc->dbg_fwsave_once = BFA_TRUE;
1966 * Retrieve saved firmware trace from a prior IOC failure.
1969 bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
1972 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
1974 u32 *tbuf = trcdata, r32;
1976 bfa_trc(ioc, *trclen);
1978 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1979 loff = bfa_ioc_smem_pgoff(ioc, loff);
1982 * Hold semaphore to serialize pll init and fwtrc.
1984 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg))
1985 return BFA_STATUS_FAILED;
1987 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
1990 if (tlen > BFA_DBG_FWTRC_LEN)
1991 tlen = BFA_DBG_FWTRC_LEN;
1992 tlen /= sizeof(u32);
1996 for (i = 0; i < tlen; i++) {
1997 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
1998 tbuf[i] = bfa_os_ntohl(r32);
1999 loff += sizeof(u32);
2002 * handle page offset wrap around
2004 loff = PSS_SMEM_PGOFF(loff);
2007 bfa_reg_write(ioc->ioc_regs.host_page_num_fn, pgnum);
2010 bfa_reg_write(ioc->ioc_regs.host_page_num_fn,
2011 bfa_ioc_smem_pgnum(ioc, 0));
2014 * release semaphore.
2016 bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
2018 bfa_trc(ioc, pgnum);
2020 *trclen = tlen * sizeof(u32);
2021 return BFA_STATUS_OK;
2025 * Save firmware trace if configured.
2028 bfa_ioc_debug_save(struct bfa_ioc_s *ioc)
2032 if (ioc->dbg_fwsave_len) {
2033 tlen = ioc->dbg_fwsave_len;
2034 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2039 * Firmware failure detected. Start recovery actions.
2042 bfa_ioc_recover(struct bfa_ioc_s *ioc)
2044 if (ioc->dbg_fwsave_once) {
2045 ioc->dbg_fwsave_once = BFA_FALSE;
2046 bfa_ioc_debug_save(ioc);
2049 bfa_ioc_stats(ioc, ioc_hbfails);
2050 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2056 bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
2061 bfa_ioc_recover(struct bfa_ioc_s *ioc)