2 * Copyright (c) 2005-2010 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.
23 #include "bfa_defs_svc.h"
25 BFA_TRC_FILE(CNA, IOC);
28 * IOC local definitions
30 #define BFA_IOC_TOV 3000 /* msecs */
31 #define BFA_IOC_HWSEM_TOV 500 /* msecs */
32 #define BFA_IOC_HB_TOV 500 /* msecs */
33 #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
34 #define BFA_IOC_POLL_TOV BFA_TIMER_FREQ
36 #define bfa_ioc_timer_start(__ioc) \
37 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
38 bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
39 #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
41 #define bfa_hb_timer_start(__ioc) \
42 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
43 bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
44 #define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
46 #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
49 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
52 #define bfa_ioc_firmware_lock(__ioc) \
53 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
54 #define bfa_ioc_firmware_unlock(__ioc) \
55 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
56 #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
57 #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
58 #define bfa_ioc_notify_fail(__ioc) \
59 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
60 #define bfa_ioc_sync_start(__ioc) \
61 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
62 #define bfa_ioc_sync_join(__ioc) \
63 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
64 #define bfa_ioc_sync_leave(__ioc) \
65 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
66 #define bfa_ioc_sync_ack(__ioc) \
67 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
68 #define bfa_ioc_sync_complete(__ioc) \
69 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
71 #define bfa_ioc_mbox_cmd_pending(__ioc) \
72 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
73 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
75 bfa_boolean_t bfa_auto_recover = BFA_TRUE;
78 * forward declarations
80 static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
81 static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
82 static void bfa_ioc_timeout(void *ioc);
83 static void bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc);
84 static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
85 static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
86 static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
87 static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
88 static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
89 static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc);
90 static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
91 static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
92 enum bfa_ioc_event_e event);
93 static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
94 static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
95 static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc);
96 static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
97 static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *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_s, enum ioc_event);
118 bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
119 bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
120 bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
121 bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
122 bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
123 bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
124 bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
125 bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
126 bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event);
128 static struct bfa_sm_table_s 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 * IOCPF state machine definitions/declarations
145 #define bfa_iocpf_timer_start(__ioc) \
146 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
147 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
148 #define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
150 #define bfa_iocpf_poll_timer_start(__ioc) \
151 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
152 bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
154 #define bfa_sem_timer_start(__ioc) \
155 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
156 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
157 #define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
160 * Forward declareations for iocpf state machine
162 static void bfa_iocpf_timeout(void *ioc_arg);
163 static void bfa_iocpf_sem_timeout(void *ioc_arg);
164 static void bfa_iocpf_poll_timeout(void *ioc_arg);
167 * IOCPF state machine events
170 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
171 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
172 IOCPF_E_STOP = 3, /* stop on driver detach */
173 IOCPF_E_FWREADY = 4, /* f/w initialization done */
174 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
175 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
176 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
177 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
178 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
179 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
180 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
181 IOCPF_E_SEM_ERROR = 12, /* h/w sem mapping error */
187 enum bfa_iocpf_state {
188 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
189 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
190 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
191 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
192 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
193 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
194 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
195 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
196 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
199 bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
200 bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
201 bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
202 bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
203 bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
204 bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
205 bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
206 bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
208 bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
209 bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
210 bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
211 bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
212 bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
214 bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
216 static struct bfa_sm_table_s iocpf_sm_table[] = {
217 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
218 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
219 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
220 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
221 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
222 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
223 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
224 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
225 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
226 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
227 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
228 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
229 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
230 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
238 * Beginning state. IOC uninit state.
242 bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
247 * IOC is in uninit state.
250 bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
256 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
260 bfa_sm_fault(ioc, event);
264 * Reset entry actions -- initialize state machine
267 bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
269 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
273 * IOC is in reset state.
276 bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
282 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
286 bfa_ioc_disable_comp(ioc);
290 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
294 bfa_sm_fault(ioc, event);
300 bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
302 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
306 * Host IOC function is being enabled, awaiting response from firmware.
307 * Semaphore is acquired.
310 bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
316 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
320 /* !!! fall through !!! */
322 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
323 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
324 if (event != IOC_E_PFFAILED)
325 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
329 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
330 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
334 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
338 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
339 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
346 bfa_sm_fault(ioc, event);
352 bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
354 bfa_ioc_timer_start(ioc);
355 bfa_ioc_send_getattr(ioc);
359 * IOC configuration in progress. Timer is active.
362 bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
367 case IOC_E_FWRSP_GETATTR:
368 bfa_ioc_timer_stop(ioc);
369 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
374 bfa_ioc_timer_stop(ioc);
375 /* !!! fall through !!! */
377 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
378 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
379 if (event != IOC_E_PFFAILED)
380 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
384 bfa_ioc_timer_stop(ioc);
385 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
392 bfa_sm_fault(ioc, event);
397 bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
399 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
401 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
402 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
403 bfa_ioc_hb_monitor(ioc);
404 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
405 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE);
409 bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
418 bfa_hb_timer_stop(ioc);
419 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
424 bfa_hb_timer_stop(ioc);
425 /* !!! fall through !!! */
427 if (ioc->iocpf.auto_recover)
428 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
430 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
432 bfa_ioc_fail_notify(ioc);
434 if (event != IOC_E_PFFAILED)
435 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
439 bfa_sm_fault(ioc, event);
445 bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
447 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
448 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
449 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
450 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_DISABLE);
454 * IOC is being disabled
457 bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
463 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
468 * No state change. Will move to disabled state
469 * after iocpf sm completes failure processing and
470 * moves to disabled state.
472 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
476 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
477 bfa_ioc_disable_comp(ioc);
481 bfa_sm_fault(ioc, event);
486 * IOC disable completion entry.
489 bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
491 bfa_ioc_disable_comp(ioc);
495 bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
501 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
505 ioc->cbfn->disable_cbfn(ioc->bfa);
509 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
510 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
514 bfa_sm_fault(ioc, event);
520 bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
526 * Hardware initialization retry.
529 bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
535 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
541 * Initialization retry failed.
543 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
544 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
545 if (event != IOC_E_PFFAILED)
546 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
550 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
551 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
558 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
562 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
563 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
567 bfa_sm_fault(ioc, event);
573 bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
582 bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
589 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
593 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
597 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
598 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
603 * HB failure notification, ignore.
607 bfa_sm_fault(ioc, event);
612 bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s *ioc)
618 bfa_ioc_sm_hwfail(struct bfa_ioc_s *ioc, enum ioc_event event)
624 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
628 ioc->cbfn->disable_cbfn(ioc->bfa);
632 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
636 bfa_sm_fault(ioc, event);
641 * IOCPF State Machine
645 * Reset entry actions -- initialize state machine
648 bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
650 iocpf->fw_mismatch_notified = BFA_FALSE;
651 iocpf->auto_recover = bfa_auto_recover;
655 * Beginning state. IOC is in reset state.
658 bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
660 struct bfa_ioc_s *ioc = iocpf->ioc;
666 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
673 bfa_sm_fault(ioc, event);
678 * Semaphore should be acquired for version check.
681 bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
683 struct bfi_ioc_image_hdr_s fwhdr;
684 u32 r32, fwstate, pgnum, pgoff, loff = 0;
688 * Spin on init semaphore to serialize.
690 r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
693 r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
697 fwstate = readl(iocpf->ioc->ioc_regs.ioc_fwstate);
698 if (fwstate == BFI_IOC_UNINIT) {
699 writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
703 bfa_ioc_fwver_get(iocpf->ioc, &fwhdr);
705 if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) {
706 writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
713 pgnum = PSS_SMEM_PGNUM(iocpf->ioc->ioc_regs.smem_pg0, loff);
714 pgoff = PSS_SMEM_PGOFF(loff);
715 writel(pgnum, iocpf->ioc->ioc_regs.host_page_num_fn);
717 for (i = 0; i < sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32); i++) {
718 bfa_mem_write(iocpf->ioc->ioc_regs.smem_page_start, loff, 0);
722 bfa_trc(iocpf->ioc, fwstate);
723 bfa_trc(iocpf->ioc, swab32(fwhdr.exec));
724 writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.ioc_fwstate);
725 writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.alt_ioc_fwstate);
728 * Unlock the hw semaphore. Should be here only once per boot.
730 readl(iocpf->ioc->ioc_regs.ioc_sem_reg);
731 writel(1, iocpf->ioc->ioc_regs.ioc_sem_reg);
734 * unlock init semaphore.
736 writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
739 bfa_ioc_hw_sem_get(iocpf->ioc);
743 * Awaiting h/w semaphore to continue with version check.
746 bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
748 struct bfa_ioc_s *ioc = iocpf->ioc;
753 case IOCPF_E_SEMLOCKED:
754 if (bfa_ioc_firmware_lock(ioc)) {
755 if (bfa_ioc_sync_start(ioc)) {
756 bfa_ioc_sync_join(ioc);
757 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
759 bfa_ioc_firmware_unlock(ioc);
760 writel(1, ioc->ioc_regs.ioc_sem_reg);
761 bfa_sem_timer_start(ioc);
764 writel(1, ioc->ioc_regs.ioc_sem_reg);
765 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
769 case IOCPF_E_SEM_ERROR:
770 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
771 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
774 case IOCPF_E_DISABLE:
775 bfa_sem_timer_stop(ioc);
776 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
777 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
781 bfa_sem_timer_stop(ioc);
782 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
786 bfa_sm_fault(ioc, event);
791 * Notify enable completion callback.
794 bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
797 * Call only the first time sm enters fwmismatch state.
799 if (iocpf->fw_mismatch_notified == BFA_FALSE)
800 bfa_ioc_pf_fwmismatch(iocpf->ioc);
802 iocpf->fw_mismatch_notified = BFA_TRUE;
803 bfa_iocpf_timer_start(iocpf->ioc);
807 * Awaiting firmware version match.
810 bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
812 struct bfa_ioc_s *ioc = iocpf->ioc;
817 case IOCPF_E_TIMEOUT:
818 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
821 case IOCPF_E_DISABLE:
822 bfa_iocpf_timer_stop(ioc);
823 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
824 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
828 bfa_iocpf_timer_stop(ioc);
829 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
833 bfa_sm_fault(ioc, event);
838 * Request for semaphore.
841 bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
843 bfa_ioc_hw_sem_get(iocpf->ioc);
847 * Awaiting semaphore for h/w initialzation.
850 bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
852 struct bfa_ioc_s *ioc = iocpf->ioc;
857 case IOCPF_E_SEMLOCKED:
858 if (bfa_ioc_sync_complete(ioc)) {
859 bfa_ioc_sync_join(ioc);
860 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
862 writel(1, ioc->ioc_regs.ioc_sem_reg);
863 bfa_sem_timer_start(ioc);
867 case IOCPF_E_SEM_ERROR:
868 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
869 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
872 case IOCPF_E_DISABLE:
873 bfa_sem_timer_stop(ioc);
874 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
878 bfa_sm_fault(ioc, event);
883 bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
885 iocpf->poll_time = 0;
886 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
890 * Hardware is being initialized. Interrupts are enabled.
891 * Holding hardware semaphore lock.
894 bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
896 struct bfa_ioc_s *ioc = iocpf->ioc;
901 case IOCPF_E_FWREADY:
902 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
905 case IOCPF_E_TIMEOUT:
906 writel(1, ioc->ioc_regs.ioc_sem_reg);
907 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
908 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
911 case IOCPF_E_DISABLE:
912 bfa_iocpf_timer_stop(ioc);
913 bfa_ioc_sync_leave(ioc);
914 writel(1, ioc->ioc_regs.ioc_sem_reg);
915 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
919 bfa_sm_fault(ioc, event);
924 bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
926 bfa_iocpf_timer_start(iocpf->ioc);
928 * Enable Interrupts before sending fw IOC ENABLE cmd.
930 iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
931 bfa_ioc_send_enable(iocpf->ioc);
935 * Host IOC function is being enabled, awaiting response from firmware.
936 * Semaphore is acquired.
939 bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
941 struct bfa_ioc_s *ioc = iocpf->ioc;
946 case IOCPF_E_FWRSP_ENABLE:
947 bfa_iocpf_timer_stop(ioc);
948 writel(1, ioc->ioc_regs.ioc_sem_reg);
949 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
952 case IOCPF_E_INITFAIL:
953 bfa_iocpf_timer_stop(ioc);
955 * !!! fall through !!!
958 case IOCPF_E_TIMEOUT:
959 writel(1, ioc->ioc_regs.ioc_sem_reg);
960 if (event == IOCPF_E_TIMEOUT)
961 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
962 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
965 case IOCPF_E_DISABLE:
966 bfa_iocpf_timer_stop(ioc);
967 writel(1, ioc->ioc_regs.ioc_sem_reg);
968 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
972 bfa_sm_fault(ioc, event);
977 bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
979 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
983 bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
985 struct bfa_ioc_s *ioc = iocpf->ioc;
990 case IOCPF_E_DISABLE:
991 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
994 case IOCPF_E_GETATTRFAIL:
995 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
999 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
1003 bfa_sm_fault(ioc, event);
1008 bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
1010 bfa_iocpf_timer_start(iocpf->ioc);
1011 bfa_ioc_send_disable(iocpf->ioc);
1015 * IOC is being disabled
1018 bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1020 struct bfa_ioc_s *ioc = iocpf->ioc;
1022 bfa_trc(ioc, event);
1025 case IOCPF_E_FWRSP_DISABLE:
1026 bfa_iocpf_timer_stop(ioc);
1027 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1031 bfa_iocpf_timer_stop(ioc);
1033 * !!! fall through !!!
1036 case IOCPF_E_TIMEOUT:
1037 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1038 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1041 case IOCPF_E_FWRSP_ENABLE:
1045 bfa_sm_fault(ioc, event);
1050 bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
1052 bfa_ioc_hw_sem_get(iocpf->ioc);
1056 * IOC hb ack request is being removed.
1059 bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1061 struct bfa_ioc_s *ioc = iocpf->ioc;
1063 bfa_trc(ioc, event);
1066 case IOCPF_E_SEMLOCKED:
1067 bfa_ioc_sync_leave(ioc);
1068 writel(1, ioc->ioc_regs.ioc_sem_reg);
1069 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1072 case IOCPF_E_SEM_ERROR:
1073 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1074 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1081 bfa_sm_fault(ioc, event);
1086 * IOC disable completion entry.
1089 bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
1091 bfa_ioc_mbox_flush(iocpf->ioc);
1092 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
1096 bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1098 struct bfa_ioc_s *ioc = iocpf->ioc;
1100 bfa_trc(ioc, event);
1103 case IOCPF_E_ENABLE:
1104 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1108 bfa_ioc_firmware_unlock(ioc);
1109 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1113 bfa_sm_fault(ioc, event);
1118 bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1120 bfa_ioc_debug_save_ftrc(iocpf->ioc);
1121 bfa_ioc_hw_sem_get(iocpf->ioc);
1125 * Hardware initialization failed.
1128 bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1130 struct bfa_ioc_s *ioc = iocpf->ioc;
1132 bfa_trc(ioc, event);
1135 case IOCPF_E_SEMLOCKED:
1136 bfa_ioc_notify_fail(ioc);
1137 bfa_ioc_sync_leave(ioc);
1138 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1139 writel(1, ioc->ioc_regs.ioc_sem_reg);
1140 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
1143 case IOCPF_E_SEM_ERROR:
1144 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1145 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1148 case IOCPF_E_DISABLE:
1149 bfa_sem_timer_stop(ioc);
1150 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1154 bfa_sem_timer_stop(ioc);
1155 bfa_ioc_firmware_unlock(ioc);
1156 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1163 bfa_sm_fault(ioc, event);
1168 bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1170 bfa_trc(iocpf->ioc, 0);
1174 * Hardware initialization failed.
1177 bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1179 struct bfa_ioc_s *ioc = iocpf->ioc;
1181 bfa_trc(ioc, event);
1184 case IOCPF_E_DISABLE:
1185 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1189 bfa_ioc_firmware_unlock(ioc);
1190 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1194 bfa_sm_fault(ioc, event);
1199 bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1202 * Mark IOC as failed in hardware and stop firmware.
1204 bfa_ioc_lpu_stop(iocpf->ioc);
1207 * Flush any queued up mailbox requests.
1209 bfa_ioc_mbox_flush(iocpf->ioc);
1211 bfa_ioc_hw_sem_get(iocpf->ioc);
1215 bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1217 struct bfa_ioc_s *ioc = iocpf->ioc;
1219 bfa_trc(ioc, event);
1222 case IOCPF_E_SEMLOCKED:
1223 bfa_ioc_sync_ack(ioc);
1224 bfa_ioc_notify_fail(ioc);
1225 if (!iocpf->auto_recover) {
1226 bfa_ioc_sync_leave(ioc);
1227 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1228 writel(1, ioc->ioc_regs.ioc_sem_reg);
1229 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1231 if (bfa_ioc_sync_complete(ioc))
1232 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1234 writel(1, ioc->ioc_regs.ioc_sem_reg);
1235 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1240 case IOCPF_E_SEM_ERROR:
1241 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1242 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1245 case IOCPF_E_DISABLE:
1246 bfa_sem_timer_stop(ioc);
1247 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1254 bfa_sm_fault(ioc, event);
1259 bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1261 bfa_trc(iocpf->ioc, 0);
1265 * IOC is in failed state.
1268 bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1270 struct bfa_ioc_s *ioc = iocpf->ioc;
1272 bfa_trc(ioc, event);
1275 case IOCPF_E_DISABLE:
1276 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1280 bfa_sm_fault(ioc, event);
1285 * BFA IOC private functions
1289 * Notify common modules registered for notification.
1292 bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
1294 struct bfa_ioc_notify_s *notify;
1295 struct list_head *qe;
1297 list_for_each(qe, &ioc->notify_q) {
1298 notify = (struct bfa_ioc_notify_s *)qe;
1299 notify->cbfn(notify->cbarg, event);
1304 bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1306 ioc->cbfn->disable_cbfn(ioc->bfa);
1307 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
1311 bfa_ioc_sem_get(void __iomem *sem_reg)
1315 #define BFA_SEM_SPINCNT 3000
1317 r32 = readl(sem_reg);
1319 while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
1322 r32 = readl(sem_reg);
1332 bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1337 * First read to the semaphore register will return 0, subsequent reads
1338 * will return 1. Semaphore is released by writing 1 to the register
1340 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
1343 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
1347 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
1351 bfa_sem_timer_start(ioc);
1355 * Initialize LPU local memory (aka secondary memory / SRAM)
1358 bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1362 #define PSS_LMEM_INIT_TIME 10000
1364 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1365 pss_ctl &= ~__PSS_LMEM_RESET;
1366 pss_ctl |= __PSS_LMEM_INIT_EN;
1369 * i2c workaround 12.5khz clock
1371 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
1372 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1375 * wait for memory initialization to be complete
1379 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1381 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1384 * If memory initialization is not successful, IOC timeout will catch
1387 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
1388 bfa_trc(ioc, pss_ctl);
1390 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
1391 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1395 bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1400 * Take processor out of reset.
1402 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1403 pss_ctl &= ~__PSS_LPU0_RESET;
1405 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1409 bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1414 * Put processors in reset.
1416 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1417 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1419 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1423 * Get driver and firmware versions.
1426 bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1431 u32 *fwsig = (u32 *) fwhdr;
1433 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1434 pgoff = PSS_SMEM_PGOFF(loff);
1435 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1437 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1440 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
1441 loff += sizeof(u32);
1446 * Returns TRUE if same.
1449 bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1451 struct bfi_ioc_image_hdr_s *drv_fwhdr;
1454 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
1455 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
1457 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1458 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1460 bfa_trc(ioc, fwhdr->md5sum[i]);
1461 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1466 bfa_trc(ioc, fwhdr->md5sum[0]);
1471 * Return true if current running version is valid. Firmware signature and
1472 * execution context (driver/bios) must match.
1474 static bfa_boolean_t
1475 bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
1477 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1479 bfa_ioc_fwver_get(ioc, &fwhdr);
1480 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
1481 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
1483 if (fwhdr.signature != drv_fwhdr->signature) {
1484 bfa_trc(ioc, fwhdr.signature);
1485 bfa_trc(ioc, drv_fwhdr->signature);
1489 if (swab32(fwhdr.bootenv) != boot_env) {
1490 bfa_trc(ioc, fwhdr.bootenv);
1491 bfa_trc(ioc, boot_env);
1495 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1499 * Conditionally flush any pending message from firmware at start.
1502 bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1506 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1508 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1512 bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1514 enum bfi_ioc_state ioc_fwstate;
1515 bfa_boolean_t fwvalid;
1519 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1522 ioc_fwstate = BFI_IOC_UNINIT;
1524 bfa_trc(ioc, ioc_fwstate);
1526 boot_type = BFI_FWBOOT_TYPE_NORMAL;
1527 boot_env = BFI_FWBOOT_ENV_OS;
1530 * check if firmware is valid
1532 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
1533 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
1536 bfa_ioc_boot(ioc, boot_type, boot_env);
1537 bfa_ioc_poll_fwinit(ioc);
1542 * If hardware initialization is in progress (initialized by other IOC),
1543 * just wait for an initialization completion interrupt.
1545 if (ioc_fwstate == BFI_IOC_INITING) {
1546 bfa_ioc_poll_fwinit(ioc);
1551 * If IOC function is disabled and firmware version is same,
1552 * just re-enable IOC.
1554 * If option rom, IOC must not be in operational state. With
1555 * convergence, IOC will be in operational state when 2nd driver
1558 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
1561 * When using MSI-X any pending firmware ready event should
1562 * be flushed. Otherwise MSI-X interrupts are not delivered.
1564 bfa_ioc_msgflush(ioc);
1565 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
1570 * Initialize the h/w for any other states.
1572 bfa_ioc_boot(ioc, boot_type, boot_env);
1573 bfa_ioc_poll_fwinit(ioc);
1577 bfa_ioc_timeout(void *ioc_arg)
1579 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
1582 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1586 bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1588 u32 *msgp = (u32 *) ioc_msg;
1591 bfa_trc(ioc, msgp[0]);
1594 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
1597 * first write msg to mailbox registers
1599 for (i = 0; i < len / sizeof(u32); i++)
1600 writel(cpu_to_le32(msgp[i]),
1601 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1603 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
1604 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1607 * write 1 to mailbox CMD to trigger LPU event
1609 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1610 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
1614 bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1616 struct bfi_ioc_ctrl_req_s enable_req;
1619 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1620 bfa_ioc_portid(ioc));
1621 enable_req.clscode = cpu_to_be16(ioc->clscode);
1622 do_gettimeofday(&tv);
1623 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
1624 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1628 bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1630 struct bfi_ioc_ctrl_req_s disable_req;
1632 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1633 bfa_ioc_portid(ioc));
1634 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1638 bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1640 struct bfi_ioc_getattr_req_s attr_req;
1642 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1643 bfa_ioc_portid(ioc));
1644 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1645 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1649 bfa_ioc_hb_check(void *cbarg)
1651 struct bfa_ioc_s *ioc = cbarg;
1654 hb_count = readl(ioc->ioc_regs.heartbeat);
1655 if (ioc->hb_count == hb_count) {
1656 bfa_ioc_recover(ioc);
1659 ioc->hb_count = hb_count;
1662 bfa_ioc_mbox_poll(ioc);
1663 bfa_hb_timer_start(ioc);
1667 bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1669 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
1670 bfa_hb_timer_start(ioc);
1674 * Initiate a full firmware download.
1677 bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
1687 bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)));
1688 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
1690 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1691 pgoff = PSS_SMEM_PGOFF(loff);
1693 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1695 for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
1697 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1698 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
1699 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
1700 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
1706 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
1707 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
1709 loff += sizeof(u32);
1712 * handle page offset wrap around
1714 loff = PSS_SMEM_PGOFF(loff);
1717 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1721 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1722 ioc->ioc_regs.host_page_num_fn);
1725 * Set boot type and device mode at the end.
1727 asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
1728 ioc->port0_mode, ioc->port1_mode);
1729 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF,
1731 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF,
1733 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF,
1739 * Update BFA configuration from firmware configuration.
1742 bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1744 struct bfi_ioc_attr_s *attr = ioc->attr;
1746 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1747 attr->card_type = be32_to_cpu(attr->card_type);
1748 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
1749 ioc->fcmode = (attr->port_mode == BFI_PORT_MODE_FC);
1751 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1755 * Attach time initialization of mbox logic.
1758 bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1760 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1763 INIT_LIST_HEAD(&mod->cmd_q);
1764 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1765 mod->mbhdlr[mc].cbfn = NULL;
1766 mod->mbhdlr[mc].cbarg = ioc->bfa;
1771 * Mbox poll timer -- restarts any pending mailbox requests.
1774 bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1776 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1777 struct bfa_mbox_cmd_s *cmd;
1781 * If no command pending, do nothing
1783 if (list_empty(&mod->cmd_q))
1787 * If previous command is not yet fetched by firmware, do nothing
1789 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1794 * Enqueue command to firmware.
1796 bfa_q_deq(&mod->cmd_q, &cmd);
1797 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1801 * Cleanup any pending requests.
1804 bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc)
1806 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1807 struct bfa_mbox_cmd_s *cmd;
1809 while (!list_empty(&mod->cmd_q))
1810 bfa_q_deq(&mod->cmd_q, &cmd);
1814 * Read data from SMEM to host through PCI memmap
1816 * @param[in] ioc memory for IOC
1817 * @param[in] tbuf app memory to store data from smem
1818 * @param[in] soff smem offset
1819 * @param[in] sz size of smem in bytes
1822 bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1829 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1830 loff = PSS_SMEM_PGOFF(soff);
1831 bfa_trc(ioc, pgnum);
1836 * Hold semaphore to serialize pll init and fwtrc.
1838 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1840 return BFA_STATUS_FAILED;
1843 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1845 len = sz/sizeof(u32);
1847 for (i = 0; i < len; i++) {
1848 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
1849 buf[i] = be32_to_cpu(r32);
1850 loff += sizeof(u32);
1853 * handle page offset wrap around
1855 loff = PSS_SMEM_PGOFF(loff);
1858 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1861 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1862 ioc->ioc_regs.host_page_num_fn);
1864 * release semaphore.
1866 readl(ioc->ioc_regs.ioc_init_sem_reg);
1867 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
1869 bfa_trc(ioc, pgnum);
1870 return BFA_STATUS_OK;
1874 * Clear SMEM data from host through PCI memmap
1876 * @param[in] ioc memory for IOC
1877 * @param[in] soff smem offset
1878 * @param[in] sz size of smem in bytes
1881 bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1886 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1887 loff = PSS_SMEM_PGOFF(soff);
1888 bfa_trc(ioc, pgnum);
1893 * Hold semaphore to serialize pll init and fwtrc.
1895 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1897 return BFA_STATUS_FAILED;
1900 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1902 len = sz/sizeof(u32); /* len in words */
1904 for (i = 0; i < len; i++) {
1905 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1906 loff += sizeof(u32);
1909 * handle page offset wrap around
1911 loff = PSS_SMEM_PGOFF(loff);
1914 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1917 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1918 ioc->ioc_regs.host_page_num_fn);
1921 * release semaphore.
1923 readl(ioc->ioc_regs.ioc_init_sem_reg);
1924 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
1925 bfa_trc(ioc, pgnum);
1926 return BFA_STATUS_OK;
1930 bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1932 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1935 * Notify driver and common modules registered for notification.
1937 ioc->cbfn->hbfail_cbfn(ioc->bfa);
1938 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
1940 bfa_ioc_debug_save_ftrc(ioc);
1942 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1943 "Heart Beat of IOC has failed\n");
1944 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_HBFAIL);
1949 bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1951 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1953 * Provide enable completion callback.
1955 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
1956 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
1957 "Running firmware version is incompatible "
1958 "with the driver version\n");
1959 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH);
1963 bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1967 * Hold semaphore so that nobody can access the chip during init.
1969 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1971 bfa_ioc_pll_init_asic(ioc);
1973 ioc->pllinit = BFA_TRUE;
1978 bfa_ioc_lmem_init(ioc);
1981 * release semaphore.
1983 readl(ioc->ioc_regs.ioc_init_sem_reg);
1984 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
1986 return BFA_STATUS_OK;
1990 * Interface used by diag module to do firmware boot with memory test
1991 * as the entry vector.
1994 bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
1996 bfa_ioc_stats(ioc, ioc_boots);
1998 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
2002 * Initialize IOC state of all functions on a chip reset.
2004 if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
2005 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate);
2006 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate);
2008 writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate);
2009 writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate);
2012 bfa_ioc_msgflush(ioc);
2013 bfa_ioc_download_fw(ioc, boot_type, boot_env);
2014 bfa_ioc_lpu_start(ioc);
2018 * Enable/disable IOC failure auto recovery.
2021 bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
2023 bfa_auto_recover = auto_recover;
2029 bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
2031 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
2035 bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
2037 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
2039 return ((r32 != BFI_IOC_UNINIT) &&
2040 (r32 != BFI_IOC_INITING) &&
2041 (r32 != BFI_IOC_MEMTEST));
2045 bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
2047 __be32 *msgp = mbmsg;
2051 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
2058 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
2060 r32 = readl(ioc->ioc_regs.lpu_mbox +
2062 msgp[i] = cpu_to_be32(r32);
2066 * turn off mailbox interrupt by clearing mailbox status
2068 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
2069 readl(ioc->ioc_regs.lpu_mbox_cmd);
2075 bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
2077 union bfi_ioc_i2h_msg_u *msg;
2078 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
2080 msg = (union bfi_ioc_i2h_msg_u *) m;
2082 bfa_ioc_stats(ioc, ioc_isrs);
2084 switch (msg->mh.msg_id) {
2085 case BFI_IOC_I2H_HBEAT:
2088 case BFI_IOC_I2H_ENABLE_REPLY:
2089 ioc->port_mode = ioc->port_mode_cfg =
2090 (enum bfa_mode_s)msg->fw_event.port_mode;
2091 ioc->ad_cap_bm = msg->fw_event.cap_bm;
2092 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
2095 case BFI_IOC_I2H_DISABLE_REPLY:
2096 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
2099 case BFI_IOC_I2H_GETATTR_REPLY:
2100 bfa_ioc_getattr_reply(ioc);
2104 bfa_trc(ioc, msg->mh.msg_id);
2110 * IOC attach time initialization and setup.
2112 * @param[in] ioc memory for IOC
2113 * @param[in] bfa driver instance structure
2116 bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
2117 struct bfa_timer_mod_s *timer_mod)
2121 ioc->timer_mod = timer_mod;
2122 ioc->fcmode = BFA_FALSE;
2123 ioc->pllinit = BFA_FALSE;
2124 ioc->dbg_fwsave_once = BFA_TRUE;
2125 ioc->iocpf.ioc = ioc;
2127 bfa_ioc_mbox_attach(ioc);
2128 INIT_LIST_HEAD(&ioc->notify_q);
2130 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
2131 bfa_fsm_send_event(ioc, IOC_E_RESET);
2135 * Driver detach time IOC cleanup.
2138 bfa_ioc_detach(struct bfa_ioc_s *ioc)
2140 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2141 INIT_LIST_HEAD(&ioc->notify_q);
2145 * Setup IOC PCI properties.
2147 * @param[in] pcidev PCI device information for this IOC
2150 bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
2151 enum bfi_pcifn_class clscode)
2153 ioc->clscode = clscode;
2154 ioc->pcidev = *pcidev;
2157 * Initialize IOC and device personality
2159 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
2160 ioc->asic_mode = BFI_ASIC_MODE_FC;
2162 switch (pcidev->device_id) {
2163 case BFA_PCI_DEVICE_ID_FC_8G1P:
2164 case BFA_PCI_DEVICE_ID_FC_8G2P:
2165 ioc->asic_gen = BFI_ASIC_GEN_CB;
2166 ioc->fcmode = BFA_TRUE;
2167 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2168 ioc->ad_cap_bm = BFA_CM_HBA;
2171 case BFA_PCI_DEVICE_ID_CT:
2172 ioc->asic_gen = BFI_ASIC_GEN_CT;
2173 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
2174 ioc->asic_mode = BFI_ASIC_MODE_ETH;
2175 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
2176 ioc->ad_cap_bm = BFA_CM_CNA;
2179 case BFA_PCI_DEVICE_ID_CT_FC:
2180 ioc->asic_gen = BFI_ASIC_GEN_CT;
2181 ioc->fcmode = BFA_TRUE;
2182 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2183 ioc->ad_cap_bm = BFA_CM_HBA;
2186 case BFA_PCI_DEVICE_ID_CT2:
2187 ioc->asic_gen = BFI_ASIC_GEN_CT2;
2188 if (clscode == BFI_PCIFN_CLASS_FC &&
2189 pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
2190 ioc->asic_mode = BFI_ASIC_MODE_FC16;
2191 ioc->fcmode = BFA_TRUE;
2192 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2193 ioc->ad_cap_bm = BFA_CM_HBA;
2195 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
2196 ioc->asic_mode = BFI_ASIC_MODE_ETH;
2197 if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
2199 ioc->port_mode_cfg = BFA_MODE_CNA;
2200 ioc->ad_cap_bm = BFA_CM_CNA;
2203 ioc->port_mode_cfg = BFA_MODE_NIC;
2204 ioc->ad_cap_bm = BFA_CM_NIC;
2214 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2216 if (ioc->asic_gen == BFI_ASIC_GEN_CB)
2217 bfa_ioc_set_cb_hwif(ioc);
2218 else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
2219 bfa_ioc_set_ct_hwif(ioc);
2221 WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
2222 bfa_ioc_set_ct2_hwif(ioc);
2223 bfa_ioc_ct2_poweron(ioc);
2226 bfa_ioc_map_port(ioc);
2227 bfa_ioc_reg_init(ioc);
2231 * Initialize IOC dma memory
2233 * @param[in] dm_kva kernel virtual address of IOC dma memory
2234 * @param[in] dm_pa physical address of IOC dma memory
2237 bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
2240 * dma memory for firmware attribute
2242 ioc->attr_dma.kva = dm_kva;
2243 ioc->attr_dma.pa = dm_pa;
2244 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
2248 bfa_ioc_enable(struct bfa_ioc_s *ioc)
2250 bfa_ioc_stats(ioc, ioc_enables);
2251 ioc->dbg_fwsave_once = BFA_TRUE;
2253 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2257 bfa_ioc_disable(struct bfa_ioc_s *ioc)
2259 bfa_ioc_stats(ioc, ioc_disables);
2260 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2265 * Initialize memory for saving firmware trace. Driver must initialize
2266 * trace memory before call bfa_ioc_enable().
2269 bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2271 ioc->dbg_fwsave = dbg_fwsave;
2272 ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
2276 * Register mailbox message handler functions
2278 * @param[in] ioc IOC instance
2279 * @param[in] mcfuncs message class handler functions
2282 bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2284 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2287 for (mc = 0; mc < BFI_MC_MAX; mc++)
2288 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2292 * Register mailbox message handler function, to be called by common modules
2295 bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2296 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2298 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2300 mod->mbhdlr[mc].cbfn = cbfn;
2301 mod->mbhdlr[mc].cbarg = cbarg;
2305 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2306 * Responsibility of caller to serialize
2308 * @param[in] ioc IOC instance
2309 * @param[i] cmd Mailbox command
2312 bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2314 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2318 * If a previous command is pending, queue new command
2320 if (!list_empty(&mod->cmd_q)) {
2321 list_add_tail(&cmd->qe, &mod->cmd_q);
2326 * If mailbox is busy, queue command for poll timer
2328 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
2330 list_add_tail(&cmd->qe, &mod->cmd_q);
2335 * mailbox is free -- queue command to firmware
2337 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2341 * Handle mailbox interrupts
2344 bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2346 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2347 struct bfi_mbmsg_s m;
2350 if (bfa_ioc_msgget(ioc, &m)) {
2352 * Treat IOC message class as special.
2354 mc = m.mh.msg_class;
2355 if (mc == BFI_MC_IOC) {
2356 bfa_ioc_isr(ioc, &m);
2360 if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2363 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2366 bfa_ioc_lpu_read_stat(ioc);
2369 * Try to send pending mailbox commands
2371 bfa_ioc_mbox_poll(ioc);
2375 bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2377 bfa_ioc_stats(ioc, ioc_hbfails);
2378 ioc->stats.hb_count = ioc->hb_count;
2379 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2383 * return true if IOC is disabled
2386 bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2388 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2389 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
2393 * return true if IOC firmware is different.
2396 bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2398 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2399 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2400 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
2403 #define bfa_ioc_state_disabled(__sm) \
2404 (((__sm) == BFI_IOC_UNINIT) || \
2405 ((__sm) == BFI_IOC_INITING) || \
2406 ((__sm) == BFI_IOC_HWINIT) || \
2407 ((__sm) == BFI_IOC_DISABLED) || \
2408 ((__sm) == BFI_IOC_FAIL) || \
2409 ((__sm) == BFI_IOC_CFG_DISABLED))
2412 * Check if adapter is disabled -- both IOCs should be in a disabled
2416 bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2420 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2423 ioc_state = readl(ioc->ioc_regs.ioc_fwstate);
2424 if (!bfa_ioc_state_disabled(ioc_state))
2427 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
2428 ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate);
2429 if (!bfa_ioc_state_disabled(ioc_state))
2437 * Reset IOC fwstate registers.
2440 bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2442 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2443 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2446 #define BFA_MFG_NAME "Brocade"
2448 bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2449 struct bfa_adapter_attr_s *ad_attr)
2451 struct bfi_ioc_attr_s *ioc_attr;
2453 ioc_attr = ioc->attr;
2455 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2456 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2457 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2458 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
2459 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
2460 sizeof(struct bfa_mfg_vpd_s));
2462 ad_attr->nports = bfa_ioc_get_nports(ioc);
2463 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
2465 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2466 /* For now, model descr uses same model string */
2467 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
2469 ad_attr->card_type = ioc_attr->card_type;
2470 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2472 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2473 ad_attr->prototype = 1;
2475 ad_attr->prototype = 0;
2477 ad_attr->pwwn = ioc->attr->pwwn;
2478 ad_attr->mac = bfa_ioc_get_mac(ioc);
2480 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2481 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2482 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2483 ad_attr->asic_rev = ioc_attr->asic_rev;
2485 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
2487 ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
2488 ad_attr->trunk_capable = (ad_attr->nports > 1) &&
2489 !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
2493 bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2495 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
2496 return BFA_IOC_TYPE_LL;
2498 WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
2500 return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
2501 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
2505 bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2507 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2508 memcpy((void *)serial_num,
2509 (void *)ioc->attr->brcd_serialnum,
2510 BFA_ADAPTER_SERIAL_NUM_LEN);
2514 bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2516 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2517 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
2521 bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2525 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
2531 chip_rev[4] = ioc->attr->asic_rev;
2536 bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2538 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2539 memcpy(optrom_ver, ioc->attr->optrom_version,
2544 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2546 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2547 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
2551 bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2553 struct bfi_ioc_attr_s *ioc_attr;
2556 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
2558 ioc_attr = ioc->attr;
2560 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2561 BFA_MFG_NAME, ioc_attr->card_type);
2565 bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2567 enum bfa_iocpf_state iocpf_st;
2568 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2570 if (ioc_st == BFA_IOC_ENABLING ||
2571 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2573 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2576 case BFA_IOCPF_SEMWAIT:
2577 ioc_st = BFA_IOC_SEMWAIT;
2580 case BFA_IOCPF_HWINIT:
2581 ioc_st = BFA_IOC_HWINIT;
2584 case BFA_IOCPF_FWMISMATCH:
2585 ioc_st = BFA_IOC_FWMISMATCH;
2588 case BFA_IOCPF_FAIL:
2589 ioc_st = BFA_IOC_FAIL;
2592 case BFA_IOCPF_INITFAIL:
2593 ioc_st = BFA_IOC_INITFAIL;
2605 bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2607 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
2609 ioc_attr->state = bfa_ioc_get_state(ioc);
2610 ioc_attr->port_id = ioc->port_id;
2611 ioc_attr->port_mode = ioc->port_mode;
2612 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2613 ioc_attr->cap_bm = ioc->ad_cap_bm;
2615 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
2617 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2619 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2620 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
2621 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
2625 bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2628 * Check the IOC type and return the appropriate MAC
2630 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
2631 return ioc->attr->fcoe_mac;
2633 return ioc->attr->mac;
2637 bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2641 m = ioc->attr->mfg_mac;
2642 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2643 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2645 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2646 bfa_ioc_pcifn(ioc));
2652 * Send AEN notification
2655 bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
2657 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
2658 struct bfa_aen_entry_s *aen_entry;
2659 enum bfa_ioc_type_e ioc_type;
2661 bfad_get_aen_entry(bfad, aen_entry);
2665 ioc_type = bfa_ioc_get_type(ioc);
2667 case BFA_IOC_TYPE_FC:
2668 aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
2670 case BFA_IOC_TYPE_FCoE:
2671 aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
2672 aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
2674 case BFA_IOC_TYPE_LL:
2675 aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
2678 WARN_ON(ioc_type != BFA_IOC_TYPE_FC);
2682 /* Send the AEN notification */
2683 aen_entry->aen_data.ioc.ioc_type = ioc_type;
2684 bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
2685 BFA_AEN_CAT_IOC, event);
2689 * Retrieve saved firmware trace from a prior IOC failure.
2692 bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2696 if (ioc->dbg_fwsave_len == 0)
2697 return BFA_STATUS_ENOFSAVE;
2700 if (tlen > ioc->dbg_fwsave_len)
2701 tlen = ioc->dbg_fwsave_len;
2703 memcpy(trcdata, ioc->dbg_fwsave, tlen);
2705 return BFA_STATUS_OK;
2710 * Retrieve saved firmware trace from a prior IOC failure.
2713 bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2715 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2717 bfa_status_t status;
2719 bfa_trc(ioc, *trclen);
2722 if (tlen > BFA_DBG_FWTRC_LEN)
2723 tlen = BFA_DBG_FWTRC_LEN;
2725 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2731 bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2733 struct bfa_mbox_cmd_s cmd;
2734 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
2736 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2737 bfa_ioc_portid(ioc));
2738 req->clscode = cpu_to_be16(ioc->clscode);
2739 bfa_ioc_mbox_queue(ioc, &cmd);
2743 bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2745 u32 fwsync_iter = 1000;
2747 bfa_ioc_send_fwsync(ioc);
2750 * After sending a fw sync mbox command wait for it to
2751 * take effect. We will not wait for a response because
2752 * 1. fw_sync mbox cmd doesn't have a response.
2753 * 2. Even if we implement that, interrupts might not
2754 * be enabled when we call this function.
2755 * So, just keep checking if any mbox cmd is pending, and
2756 * after waiting for a reasonable amount of time, go ahead.
2757 * It is possible that fw has crashed and the mbox command
2758 * is never acknowledged.
2760 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2765 * Dump firmware smem
2768 bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2769 u32 *offset, int *buflen)
2773 bfa_status_t status;
2774 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
2776 if (*offset >= smem_len) {
2777 *offset = *buflen = 0;
2778 return BFA_STATUS_EINVAL;
2785 * First smem read, sync smem before proceeding
2786 * No need to sync before reading every chunk.
2789 bfa_ioc_fwsync(ioc);
2791 if ((loff + dlen) >= smem_len)
2792 dlen = smem_len - loff;
2794 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2796 if (status != BFA_STATUS_OK) {
2797 *offset = *buflen = 0;
2803 if (*offset >= smem_len)
2812 * Firmware statistics
2815 bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2817 u32 loff = BFI_IOC_FWSTATS_OFF + \
2818 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2820 bfa_status_t status;
2822 if (ioc->stats_busy) {
2823 bfa_trc(ioc, ioc->stats_busy);
2824 return BFA_STATUS_DEVBUSY;
2826 ioc->stats_busy = BFA_TRUE;
2828 tlen = sizeof(struct bfa_fw_stats_s);
2829 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2831 ioc->stats_busy = BFA_FALSE;
2836 bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2838 u32 loff = BFI_IOC_FWSTATS_OFF + \
2839 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2841 bfa_status_t status;
2843 if (ioc->stats_busy) {
2844 bfa_trc(ioc, ioc->stats_busy);
2845 return BFA_STATUS_DEVBUSY;
2847 ioc->stats_busy = BFA_TRUE;
2849 tlen = sizeof(struct bfa_fw_stats_s);
2850 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2852 ioc->stats_busy = BFA_FALSE;
2857 * Save firmware trace if configured.
2860 bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
2864 if (ioc->dbg_fwsave_once) {
2865 ioc->dbg_fwsave_once = BFA_FALSE;
2866 if (ioc->dbg_fwsave_len) {
2867 tlen = ioc->dbg_fwsave_len;
2868 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2874 * Firmware failure detected. Start recovery actions.
2877 bfa_ioc_recover(struct bfa_ioc_s *ioc)
2879 bfa_ioc_stats(ioc, ioc_hbfails);
2880 ioc->stats.hb_count = ioc->hb_count;
2881 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2885 * BFA IOC PF private functions
2888 bfa_iocpf_timeout(void *ioc_arg)
2890 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2893 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2897 bfa_iocpf_sem_timeout(void *ioc_arg)
2899 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2901 bfa_ioc_hw_sem_get(ioc);
2905 bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
2907 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
2909 bfa_trc(ioc, fwstate);
2911 if (fwstate == BFI_IOC_DISABLED) {
2912 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2916 if (ioc->iocpf.poll_time >= BFA_IOC_TOV)
2917 bfa_iocpf_timeout(ioc);
2919 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2920 bfa_iocpf_poll_timer_start(ioc);
2925 bfa_iocpf_poll_timeout(void *ioc_arg)
2927 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2929 bfa_ioc_poll_fwinit(ioc);
2933 * bfa timer function
2936 bfa_timer_beat(struct bfa_timer_mod_s *mod)
2938 struct list_head *qh = &mod->timer_q;
2939 struct list_head *qe, *qe_next;
2940 struct bfa_timer_s *elem;
2941 struct list_head timedout_q;
2943 INIT_LIST_HEAD(&timedout_q);
2945 qe = bfa_q_next(qh);
2948 qe_next = bfa_q_next(qe);
2950 elem = (struct bfa_timer_s *) qe;
2951 if (elem->timeout <= BFA_TIMER_FREQ) {
2953 list_del(&elem->qe);
2954 list_add_tail(&elem->qe, &timedout_q);
2956 elem->timeout -= BFA_TIMER_FREQ;
2959 qe = qe_next; /* go to next elem */
2963 * Pop all the timeout entries
2965 while (!list_empty(&timedout_q)) {
2966 bfa_q_deq(&timedout_q, &elem);
2967 elem->timercb(elem->arg);
2972 * Should be called with lock protection
2975 bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2976 void (*timercb) (void *), void *arg, unsigned int timeout)
2979 WARN_ON(timercb == NULL);
2980 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
2982 timer->timeout = timeout;
2983 timer->timercb = timercb;
2986 list_add_tail(&timer->qe, &mod->timer_q);
2990 * Should be called with lock protection
2993 bfa_timer_stop(struct bfa_timer_s *timer)
2995 WARN_ON(list_empty(&timer->qe));
2997 list_del(&timer->qe);
3001 * ASIC block related
3004 bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
3006 struct bfa_ablk_cfg_inst_s *cfg_inst;
3011 for (i = 0; i < BFA_ABLK_MAX; i++) {
3012 cfg_inst = &cfg->inst[i];
3013 for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
3014 be16 = cfg_inst->pf_cfg[j].pers;
3015 cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
3016 be16 = cfg_inst->pf_cfg[j].num_qpairs;
3017 cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
3018 be16 = cfg_inst->pf_cfg[j].num_vectors;
3019 cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
3020 be32 = cfg_inst->pf_cfg[j].bw;
3021 cfg_inst->pf_cfg[j].bw = be16_to_cpu(be32);
3027 bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
3029 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3030 struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
3031 bfa_ablk_cbfn_t cbfn;
3033 WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
3034 bfa_trc(ablk->ioc, msg->mh.msg_id);
3036 switch (msg->mh.msg_id) {
3037 case BFI_ABLK_I2H_QUERY:
3038 if (rsp->status == BFA_STATUS_OK) {
3039 memcpy(ablk->cfg, ablk->dma_addr.kva,
3040 sizeof(struct bfa_ablk_cfg_s));
3041 bfa_ablk_config_swap(ablk->cfg);
3046 case BFI_ABLK_I2H_ADPT_CONFIG:
3047 case BFI_ABLK_I2H_PORT_CONFIG:
3048 /* update config port mode */
3049 ablk->ioc->port_mode_cfg = rsp->port_mode;
3051 case BFI_ABLK_I2H_PF_DELETE:
3052 case BFI_ABLK_I2H_PF_UPDATE:
3053 case BFI_ABLK_I2H_OPTROM_ENABLE:
3054 case BFI_ABLK_I2H_OPTROM_DISABLE:
3058 case BFI_ABLK_I2H_PF_CREATE:
3059 *(ablk->pcifn) = rsp->pcifn;
3067 ablk->busy = BFA_FALSE;
3071 cbfn(ablk->cbarg, rsp->status);
3076 bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
3078 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3080 bfa_trc(ablk->ioc, event);
3083 case BFA_IOC_E_ENABLED:
3084 WARN_ON(ablk->busy != BFA_FALSE);
3087 case BFA_IOC_E_DISABLED:
3088 case BFA_IOC_E_FAILED:
3089 /* Fail any pending requests */
3093 ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
3095 ablk->busy = BFA_FALSE;
3106 bfa_ablk_meminfo(void)
3108 return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
3112 bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
3114 ablk->dma_addr.kva = dma_kva;
3115 ablk->dma_addr.pa = dma_pa;
3119 bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
3123 bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
3124 bfa_q_qe_init(&ablk->ioc_notify);
3125 bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
3126 list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
3130 bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
3131 bfa_ablk_cbfn_t cbfn, void *cbarg)
3133 struct bfi_ablk_h2i_query_s *m;
3137 if (!bfa_ioc_is_operational(ablk->ioc)) {
3138 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3139 return BFA_STATUS_IOC_FAILURE;
3143 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3144 return BFA_STATUS_DEVBUSY;
3147 ablk->cfg = ablk_cfg;
3149 ablk->cbarg = cbarg;
3150 ablk->busy = BFA_TRUE;
3152 m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
3153 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
3154 bfa_ioc_portid(ablk->ioc));
3155 bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
3156 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3158 return BFA_STATUS_OK;
3162 bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
3163 u8 port, enum bfi_pcifn_class personality, int bw,
3164 bfa_ablk_cbfn_t cbfn, void *cbarg)
3166 struct bfi_ablk_h2i_pf_req_s *m;
3168 if (!bfa_ioc_is_operational(ablk->ioc)) {
3169 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3170 return BFA_STATUS_IOC_FAILURE;
3174 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3175 return BFA_STATUS_DEVBUSY;
3178 ablk->pcifn = pcifn;
3180 ablk->cbarg = cbarg;
3181 ablk->busy = BFA_TRUE;
3183 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3184 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
3185 bfa_ioc_portid(ablk->ioc));
3186 m->pers = cpu_to_be16((u16)personality);
3187 m->bw = cpu_to_be32(bw);
3189 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3191 return BFA_STATUS_OK;
3195 bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
3196 bfa_ablk_cbfn_t cbfn, void *cbarg)
3198 struct bfi_ablk_h2i_pf_req_s *m;
3200 if (!bfa_ioc_is_operational(ablk->ioc)) {
3201 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3202 return BFA_STATUS_IOC_FAILURE;
3206 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3207 return BFA_STATUS_DEVBUSY;
3211 ablk->cbarg = cbarg;
3212 ablk->busy = BFA_TRUE;
3214 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3215 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
3216 bfa_ioc_portid(ablk->ioc));
3217 m->pcifn = (u8)pcifn;
3218 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3220 return BFA_STATUS_OK;
3224 bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
3225 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3227 struct bfi_ablk_h2i_cfg_req_s *m;
3229 if (!bfa_ioc_is_operational(ablk->ioc)) {
3230 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3231 return BFA_STATUS_IOC_FAILURE;
3235 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3236 return BFA_STATUS_DEVBUSY;
3240 ablk->cbarg = cbarg;
3241 ablk->busy = BFA_TRUE;
3243 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3244 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
3245 bfa_ioc_portid(ablk->ioc));
3247 m->max_pf = (u8)max_pf;
3248 m->max_vf = (u8)max_vf;
3249 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3251 return BFA_STATUS_OK;
3255 bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
3256 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3258 struct bfi_ablk_h2i_cfg_req_s *m;
3260 if (!bfa_ioc_is_operational(ablk->ioc)) {
3261 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3262 return BFA_STATUS_IOC_FAILURE;
3266 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3267 return BFA_STATUS_DEVBUSY;
3271 ablk->cbarg = cbarg;
3272 ablk->busy = BFA_TRUE;
3274 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3275 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
3276 bfa_ioc_portid(ablk->ioc));
3279 m->max_pf = (u8)max_pf;
3280 m->max_vf = (u8)max_vf;
3281 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3283 return BFA_STATUS_OK;
3287 bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw,
3288 bfa_ablk_cbfn_t cbfn, void *cbarg)
3290 struct bfi_ablk_h2i_pf_req_s *m;
3292 if (!bfa_ioc_is_operational(ablk->ioc)) {
3293 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3294 return BFA_STATUS_IOC_FAILURE;
3298 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3299 return BFA_STATUS_DEVBUSY;
3303 ablk->cbarg = cbarg;
3304 ablk->busy = BFA_TRUE;
3306 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3307 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
3308 bfa_ioc_portid(ablk->ioc));
3309 m->pcifn = (u8)pcifn;
3310 m->bw = cpu_to_be32(bw);
3311 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3313 return BFA_STATUS_OK;
3317 bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3319 struct bfi_ablk_h2i_optrom_s *m;
3321 if (!bfa_ioc_is_operational(ablk->ioc)) {
3322 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3323 return BFA_STATUS_IOC_FAILURE;
3327 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3328 return BFA_STATUS_DEVBUSY;
3332 ablk->cbarg = cbarg;
3333 ablk->busy = BFA_TRUE;
3335 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3336 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
3337 bfa_ioc_portid(ablk->ioc));
3338 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3340 return BFA_STATUS_OK;
3344 bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3346 struct bfi_ablk_h2i_optrom_s *m;
3348 if (!bfa_ioc_is_operational(ablk->ioc)) {
3349 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3350 return BFA_STATUS_IOC_FAILURE;
3354 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3355 return BFA_STATUS_DEVBUSY;
3359 ablk->cbarg = cbarg;
3360 ablk->busy = BFA_TRUE;
3362 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3363 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
3364 bfa_ioc_portid(ablk->ioc));
3365 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3367 return BFA_STATUS_OK;
3371 * SFP module specific
3374 /* forward declarations */
3375 static void bfa_sfp_getdata_send(struct bfa_sfp_s *sfp);
3376 static void bfa_sfp_media_get(struct bfa_sfp_s *sfp);
3377 static bfa_status_t bfa_sfp_speed_valid(struct bfa_sfp_s *sfp,
3378 enum bfa_port_speed portspeed);
3381 bfa_cb_sfp_show(struct bfa_sfp_s *sfp)
3383 bfa_trc(sfp, sfp->lock);
3385 sfp->cbfn(sfp->cbarg, sfp->status);
3391 bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp)
3393 bfa_trc(sfp, sfp->portspeed);
3395 bfa_sfp_media_get(sfp);
3396 if (sfp->state_query_cbfn)
3397 sfp->state_query_cbfn(sfp->state_query_cbarg,
3402 if (sfp->portspeed) {
3403 sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed);
3404 if (sfp->state_query_cbfn)
3405 sfp->state_query_cbfn(sfp->state_query_cbarg,
3407 sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
3410 sfp->state_query_lock = 0;
3411 sfp->state_query_cbfn = NULL;
3415 * IOC event handler.
3418 bfa_sfp_notify(void *sfp_arg, enum bfa_ioc_event_e event)
3420 struct bfa_sfp_s *sfp = sfp_arg;
3422 bfa_trc(sfp, event);
3423 bfa_trc(sfp, sfp->lock);
3424 bfa_trc(sfp, sfp->state_query_lock);
3427 case BFA_IOC_E_DISABLED:
3428 case BFA_IOC_E_FAILED:
3430 sfp->status = BFA_STATUS_IOC_FAILURE;
3431 bfa_cb_sfp_show(sfp);
3434 if (sfp->state_query_lock) {
3435 sfp->status = BFA_STATUS_IOC_FAILURE;
3436 bfa_cb_sfp_state_query(sfp);
3446 * SFP's State Change Notification post to AEN
3449 bfa_sfp_scn_aen_post(struct bfa_sfp_s *sfp, struct bfi_sfp_scn_s *rsp)
3451 struct bfad_s *bfad = (struct bfad_s *)sfp->ioc->bfa->bfad;
3452 struct bfa_aen_entry_s *aen_entry;
3453 enum bfa_port_aen_event aen_evt = 0;
3455 bfa_trc(sfp, (((u64)rsp->pomlvl) << 16) | (((u64)rsp->sfpid) << 8) |
3458 bfad_get_aen_entry(bfad, aen_entry);
3462 aen_entry->aen_data.port.ioc_type = bfa_ioc_get_type(sfp->ioc);
3463 aen_entry->aen_data.port.pwwn = sfp->ioc->attr->pwwn;
3464 aen_entry->aen_data.port.mac = bfa_ioc_get_mac(sfp->ioc);
3466 switch (rsp->event) {
3467 case BFA_SFP_SCN_INSERTED:
3468 aen_evt = BFA_PORT_AEN_SFP_INSERT;
3470 case BFA_SFP_SCN_REMOVED:
3471 aen_evt = BFA_PORT_AEN_SFP_REMOVE;
3473 case BFA_SFP_SCN_FAILED:
3474 aen_evt = BFA_PORT_AEN_SFP_ACCESS_ERROR;
3476 case BFA_SFP_SCN_UNSUPPORT:
3477 aen_evt = BFA_PORT_AEN_SFP_UNSUPPORT;
3479 case BFA_SFP_SCN_POM:
3480 aen_evt = BFA_PORT_AEN_SFP_POM;
3481 aen_entry->aen_data.port.level = rsp->pomlvl;
3484 bfa_trc(sfp, rsp->event);
3488 /* Send the AEN notification */
3489 bfad_im_post_vendor_event(aen_entry, bfad, ++sfp->ioc->ioc_aen_seq,
3490 BFA_AEN_CAT_PORT, aen_evt);
3497 bfa_sfp_getdata_send(struct bfa_sfp_s *sfp)
3499 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3501 bfa_trc(sfp, req->memtype);
3503 /* build host command */
3504 bfi_h2i_set(req->mh, BFI_MC_SFP, BFI_SFP_H2I_SHOW,
3505 bfa_ioc_portid(sfp->ioc));
3508 bfa_ioc_mbox_queue(sfp->ioc, &sfp->mbcmd);
3512 * SFP is valid, read sfp data
3515 bfa_sfp_getdata(struct bfa_sfp_s *sfp, enum bfi_sfp_mem_e memtype)
3517 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3519 WARN_ON(sfp->lock != 0);
3520 bfa_trc(sfp, sfp->state);
3523 sfp->memtype = memtype;
3524 req->memtype = memtype;
3527 bfa_alen_set(&req->alen, sizeof(struct sfp_mem_s), sfp->dbuf_pa);
3529 bfa_sfp_getdata_send(sfp);
3536 bfa_sfp_scn(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
3538 struct bfi_sfp_scn_s *rsp = (struct bfi_sfp_scn_s *) msg;
3540 switch (rsp->event) {
3541 case BFA_SFP_SCN_INSERTED:
3542 sfp->state = BFA_SFP_STATE_INSERTED;
3543 sfp->data_valid = 0;
3544 bfa_sfp_scn_aen_post(sfp, rsp);
3546 case BFA_SFP_SCN_REMOVED:
3547 sfp->state = BFA_SFP_STATE_REMOVED;
3548 sfp->data_valid = 0;
3549 bfa_sfp_scn_aen_post(sfp, rsp);
3551 case BFA_SFP_SCN_FAILED:
3552 sfp->state = BFA_SFP_STATE_FAILED;
3553 sfp->data_valid = 0;
3554 bfa_sfp_scn_aen_post(sfp, rsp);
3556 case BFA_SFP_SCN_UNSUPPORT:
3557 sfp->state = BFA_SFP_STATE_UNSUPPORT;
3558 bfa_sfp_scn_aen_post(sfp, rsp);
3560 bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
3562 case BFA_SFP_SCN_POM:
3563 bfa_sfp_scn_aen_post(sfp, rsp);
3565 case BFA_SFP_SCN_VALID:
3566 sfp->state = BFA_SFP_STATE_VALID;
3568 bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
3571 bfa_trc(sfp, rsp->event);
3580 bfa_sfp_show_comp(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
3582 struct bfi_sfp_rsp_s *rsp = (struct bfi_sfp_rsp_s *) msg;
3586 * receiving response after ioc failure
3588 bfa_trc(sfp, sfp->lock);
3592 bfa_trc(sfp, rsp->status);
3593 if (rsp->status == BFA_STATUS_OK) {
3594 sfp->data_valid = 1;
3595 if (sfp->state == BFA_SFP_STATE_VALID)
3596 sfp->status = BFA_STATUS_OK;
3597 else if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
3598 sfp->status = BFA_STATUS_SFP_UNSUPP;
3600 bfa_trc(sfp, sfp->state);
3602 sfp->data_valid = 0;
3603 sfp->status = rsp->status;
3604 /* sfpshow shouldn't change sfp state */
3607 bfa_trc(sfp, sfp->memtype);
3608 if (sfp->memtype == BFI_SFP_MEM_DIAGEXT) {
3609 bfa_trc(sfp, sfp->data_valid);
3610 if (sfp->data_valid) {
3611 u32 size = sizeof(struct sfp_mem_s);
3612 u8 *des = (u8 *) &(sfp->sfpmem->srlid_base);
3613 memcpy(des, sfp->dbuf_kva, size);
3616 * Queue completion callback.
3618 bfa_cb_sfp_show(sfp);
3622 bfa_trc(sfp, sfp->state_query_lock);
3623 if (sfp->state_query_lock) {
3624 sfp->state = rsp->state;
3625 /* Complete callback */
3626 bfa_cb_sfp_state_query(sfp);
3631 * SFP query fw sfp state
3634 bfa_sfp_state_query(struct bfa_sfp_s *sfp)
3636 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3638 /* Should not be doing query if not in _INIT state */
3639 WARN_ON(sfp->state != BFA_SFP_STATE_INIT);
3640 WARN_ON(sfp->state_query_lock != 0);
3641 bfa_trc(sfp, sfp->state);
3643 sfp->state_query_lock = 1;
3647 bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
3651 bfa_sfp_media_get(struct bfa_sfp_s *sfp)
3653 enum bfa_defs_sfp_media_e *media = sfp->media;
3655 *media = BFA_SFP_MEDIA_UNKNOWN;
3657 if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
3658 *media = BFA_SFP_MEDIA_UNSUPPORT;
3659 else if (sfp->state == BFA_SFP_STATE_VALID) {
3660 union sfp_xcvr_e10g_code_u e10g;
3661 struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
3662 u16 xmtr_tech = (sfpmem->srlid_base.xcvr[4] & 0x3) << 7 |
3663 (sfpmem->srlid_base.xcvr[5] >> 1);
3665 e10g.b = sfpmem->srlid_base.xcvr[0];
3666 bfa_trc(sfp, e10g.b);
3667 bfa_trc(sfp, xmtr_tech);
3668 /* check fc transmitter tech */
3669 if ((xmtr_tech & SFP_XMTR_TECH_CU) ||
3670 (xmtr_tech & SFP_XMTR_TECH_CP) ||
3671 (xmtr_tech & SFP_XMTR_TECH_CA))
3672 *media = BFA_SFP_MEDIA_CU;
3673 else if ((xmtr_tech & SFP_XMTR_TECH_EL_INTRA) ||
3674 (xmtr_tech & SFP_XMTR_TECH_EL_INTER))
3675 *media = BFA_SFP_MEDIA_EL;
3676 else if ((xmtr_tech & SFP_XMTR_TECH_LL) ||
3677 (xmtr_tech & SFP_XMTR_TECH_LC))
3678 *media = BFA_SFP_MEDIA_LW;
3679 else if ((xmtr_tech & SFP_XMTR_TECH_SL) ||
3680 (xmtr_tech & SFP_XMTR_TECH_SN) ||
3681 (xmtr_tech & SFP_XMTR_TECH_SA))
3682 *media = BFA_SFP_MEDIA_SW;
3683 /* Check 10G Ethernet Compilance code */
3684 else if (e10g.r.e10g_sr)
3685 *media = BFA_SFP_MEDIA_SW;
3686 else if (e10g.r.e10g_lrm && e10g.r.e10g_lr)
3687 *media = BFA_SFP_MEDIA_LW;
3688 else if (e10g.r.e10g_unall)
3689 *media = BFA_SFP_MEDIA_UNKNOWN;
3693 bfa_trc(sfp, sfp->state);
3697 bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed)
3699 struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
3700 struct sfp_xcvr_s *xcvr = (struct sfp_xcvr_s *) sfpmem->srlid_base.xcvr;
3701 union sfp_xcvr_fc3_code_u fc3 = xcvr->fc3;
3702 union sfp_xcvr_e10g_code_u e10g = xcvr->e10g;
3704 if (portspeed == BFA_PORT_SPEED_10GBPS) {
3705 if (e10g.r.e10g_sr || e10g.r.e10g_lr)
3706 return BFA_STATUS_OK;
3708 bfa_trc(sfp, e10g.b);
3709 return BFA_STATUS_UNSUPP_SPEED;
3712 if (((portspeed & BFA_PORT_SPEED_16GBPS) && fc3.r.mb1600) ||
3713 ((portspeed & BFA_PORT_SPEED_8GBPS) && fc3.r.mb800) ||
3714 ((portspeed & BFA_PORT_SPEED_4GBPS) && fc3.r.mb400) ||
3715 ((portspeed & BFA_PORT_SPEED_2GBPS) && fc3.r.mb200) ||
3716 ((portspeed & BFA_PORT_SPEED_1GBPS) && fc3.r.mb100))
3717 return BFA_STATUS_OK;
3719 bfa_trc(sfp, portspeed);
3720 bfa_trc(sfp, fc3.b);
3721 bfa_trc(sfp, e10g.b);
3722 return BFA_STATUS_UNSUPP_SPEED;
3730 bfa_sfp_intr(void *sfparg, struct bfi_mbmsg_s *msg)
3732 struct bfa_sfp_s *sfp = sfparg;
3734 switch (msg->mh.msg_id) {
3735 case BFI_SFP_I2H_SHOW:
3736 bfa_sfp_show_comp(sfp, msg);
3739 case BFI_SFP_I2H_SCN:
3740 bfa_sfp_scn(sfp, msg);
3744 bfa_trc(sfp, msg->mh.msg_id);
3750 * Return DMA memory needed by sfp module.
3753 bfa_sfp_meminfo(void)
3755 return BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3759 * Attach virtual and physical memory for SFP.
3762 bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc, void *dev,
3763 struct bfa_trc_mod_s *trcmod)
3767 sfp->trcmod = trcmod;
3773 sfp->data_valid = 0;
3774 sfp->state = BFA_SFP_STATE_INIT;
3775 sfp->state_query_lock = 0;
3776 sfp->state_query_cbfn = NULL;
3777 sfp->state_query_cbarg = NULL;
3779 sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
3780 sfp->is_elb = BFA_FALSE;
3782 bfa_ioc_mbox_regisr(sfp->ioc, BFI_MC_SFP, bfa_sfp_intr, sfp);
3783 bfa_q_qe_init(&sfp->ioc_notify);
3784 bfa_ioc_notify_init(&sfp->ioc_notify, bfa_sfp_notify, sfp);
3785 list_add_tail(&sfp->ioc_notify.qe, &sfp->ioc->notify_q);
3789 * Claim Memory for SFP
3792 bfa_sfp_memclaim(struct bfa_sfp_s *sfp, u8 *dm_kva, u64 dm_pa)
3794 sfp->dbuf_kva = dm_kva;
3795 sfp->dbuf_pa = dm_pa;
3796 memset(sfp->dbuf_kva, 0, sizeof(struct sfp_mem_s));
3798 dm_kva += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3799 dm_pa += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3803 * Show SFP eeprom content
3805 * @param[in] sfp - bfa sfp module
3807 * @param[out] sfpmem - sfp eeprom data
3811 bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem,
3812 bfa_cb_sfp_t cbfn, void *cbarg)
3815 if (!bfa_ioc_is_operational(sfp->ioc)) {
3817 return BFA_STATUS_IOC_NON_OP;
3822 return BFA_STATUS_DEVBUSY;
3827 sfp->sfpmem = sfpmem;
3829 bfa_sfp_getdata(sfp, BFI_SFP_MEM_DIAGEXT);
3830 return BFA_STATUS_OK;
3834 * Return SFP Media type
3836 * @param[in] sfp - bfa sfp module
3838 * @param[out] media - port speed from user
3842 bfa_sfp_media(struct bfa_sfp_s *sfp, enum bfa_defs_sfp_media_e *media,
3843 bfa_cb_sfp_t cbfn, void *cbarg)
3845 if (!bfa_ioc_is_operational(sfp->ioc)) {
3847 return BFA_STATUS_IOC_NON_OP;
3851 if (sfp->state == BFA_SFP_STATE_INIT) {
3852 if (sfp->state_query_lock) {
3854 return BFA_STATUS_DEVBUSY;
3856 sfp->state_query_cbfn = cbfn;
3857 sfp->state_query_cbarg = cbarg;
3858 bfa_sfp_state_query(sfp);
3859 return BFA_STATUS_SFP_NOT_READY;
3863 bfa_sfp_media_get(sfp);
3864 return BFA_STATUS_OK;
3868 * Check if user set port speed is allowed by the SFP
3870 * @param[in] sfp - bfa sfp module
3871 * @param[in] portspeed - port speed from user
3875 bfa_sfp_speed(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed,
3876 bfa_cb_sfp_t cbfn, void *cbarg)
3878 WARN_ON(portspeed == BFA_PORT_SPEED_UNKNOWN);
3880 if (!bfa_ioc_is_operational(sfp->ioc))
3881 return BFA_STATUS_IOC_NON_OP;
3883 /* For Mezz card, all speed is allowed */
3884 if (bfa_mfg_is_mezz(sfp->ioc->attr->card_type))
3885 return BFA_STATUS_OK;
3887 /* Check SFP state */
3888 sfp->portspeed = portspeed;
3889 if (sfp->state == BFA_SFP_STATE_INIT) {
3890 if (sfp->state_query_lock) {
3892 return BFA_STATUS_DEVBUSY;
3894 sfp->state_query_cbfn = cbfn;
3895 sfp->state_query_cbarg = cbarg;
3896 bfa_sfp_state_query(sfp);
3897 return BFA_STATUS_SFP_NOT_READY;
3901 if (sfp->state == BFA_SFP_STATE_REMOVED ||
3902 sfp->state == BFA_SFP_STATE_FAILED) {
3903 bfa_trc(sfp, sfp->state);
3904 return BFA_STATUS_NO_SFP_DEV;
3907 if (sfp->state == BFA_SFP_STATE_INSERTED) {
3908 bfa_trc(sfp, sfp->state);
3909 return BFA_STATUS_DEVBUSY; /* sfp is reading data */
3912 /* For eloopback, all speed is allowed */
3914 return BFA_STATUS_OK;
3916 return bfa_sfp_speed_valid(sfp, portspeed);
3920 * Flash module specific
3924 * FLASH DMA buffer should be big enough to hold both MFG block and
3925 * asic block(64k) at the same time and also should be 2k aligned to
3926 * avoid write segement to cross sector boundary.
3928 #define BFA_FLASH_SEG_SZ 2048
3929 #define BFA_FLASH_DMA_BUF_SZ \
3930 BFA_ROUNDUP(0x010000 + sizeof(struct bfa_mfg_block_s), BFA_FLASH_SEG_SZ)
3933 bfa_flash_aen_audit_post(struct bfa_ioc_s *ioc, enum bfa_audit_aen_event event,
3936 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
3937 struct bfa_aen_entry_s *aen_entry;
3939 bfad_get_aen_entry(bfad, aen_entry);
3943 aen_entry->aen_data.audit.pwwn = ioc->attr->pwwn;
3944 aen_entry->aen_data.audit.partition_inst = inst;
3945 aen_entry->aen_data.audit.partition_type = type;
3947 /* Send the AEN notification */
3948 bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
3949 BFA_AEN_CAT_AUDIT, event);
3953 bfa_flash_cb(struct bfa_flash_s *flash)
3957 flash->cbfn(flash->cbarg, flash->status);
3961 bfa_flash_notify(void *cbarg, enum bfa_ioc_event_e event)
3963 struct bfa_flash_s *flash = cbarg;
3965 bfa_trc(flash, event);
3967 case BFA_IOC_E_DISABLED:
3968 case BFA_IOC_E_FAILED:
3969 if (flash->op_busy) {
3970 flash->status = BFA_STATUS_IOC_FAILURE;
3971 flash->cbfn(flash->cbarg, flash->status);
3982 * Send flash attribute query request.
3984 * @param[in] cbarg - callback argument
3987 bfa_flash_query_send(void *cbarg)
3989 struct bfa_flash_s *flash = cbarg;
3990 struct bfi_flash_query_req_s *msg =
3991 (struct bfi_flash_query_req_s *) flash->mb.msg;
3993 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ,
3994 bfa_ioc_portid(flash->ioc));
3995 bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr_s),
3997 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4001 * Send flash write request.
4003 * @param[in] cbarg - callback argument
4006 bfa_flash_write_send(struct bfa_flash_s *flash)
4008 struct bfi_flash_write_req_s *msg =
4009 (struct bfi_flash_write_req_s *) flash->mb.msg;
4012 msg->type = be32_to_cpu(flash->type);
4013 msg->instance = flash->instance;
4014 msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
4015 len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
4016 flash->residue : BFA_FLASH_DMA_BUF_SZ;
4017 msg->length = be32_to_cpu(len);
4019 /* indicate if it's the last msg of the whole write operation */
4020 msg->last = (len == flash->residue) ? 1 : 0;
4022 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ,
4023 bfa_ioc_portid(flash->ioc));
4024 bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
4025 memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len);
4026 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4028 flash->residue -= len;
4029 flash->offset += len;
4033 * Send flash read request.
4035 * @param[in] cbarg - callback argument
4038 bfa_flash_read_send(void *cbarg)
4040 struct bfa_flash_s *flash = cbarg;
4041 struct bfi_flash_read_req_s *msg =
4042 (struct bfi_flash_read_req_s *) flash->mb.msg;
4045 msg->type = be32_to_cpu(flash->type);
4046 msg->instance = flash->instance;
4047 msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
4048 len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
4049 flash->residue : BFA_FLASH_DMA_BUF_SZ;
4050 msg->length = be32_to_cpu(len);
4051 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ,
4052 bfa_ioc_portid(flash->ioc));
4053 bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
4054 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4058 * Send flash erase request.
4060 * @param[in] cbarg - callback argument
4063 bfa_flash_erase_send(void *cbarg)
4065 struct bfa_flash_s *flash = cbarg;
4066 struct bfi_flash_erase_req_s *msg =
4067 (struct bfi_flash_erase_req_s *) flash->mb.msg;
4069 msg->type = be32_to_cpu(flash->type);
4070 msg->instance = flash->instance;
4071 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_ERASE_REQ,
4072 bfa_ioc_portid(flash->ioc));
4073 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4077 * Process flash response messages upon receiving interrupts.
4079 * @param[in] flasharg - flash structure
4080 * @param[in] msg - message structure
4083 bfa_flash_intr(void *flasharg, struct bfi_mbmsg_s *msg)
4085 struct bfa_flash_s *flash = flasharg;
4089 struct bfi_flash_query_rsp_s *query;
4090 struct bfi_flash_erase_rsp_s *erase;
4091 struct bfi_flash_write_rsp_s *write;
4092 struct bfi_flash_read_rsp_s *read;
4093 struct bfi_flash_event_s *event;
4094 struct bfi_mbmsg_s *msg;
4098 bfa_trc(flash, msg->mh.msg_id);
4100 if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT) {
4101 /* receiving response after ioc failure */
4102 bfa_trc(flash, 0x9999);
4106 switch (msg->mh.msg_id) {
4107 case BFI_FLASH_I2H_QUERY_RSP:
4108 status = be32_to_cpu(m.query->status);
4109 bfa_trc(flash, status);
4110 if (status == BFA_STATUS_OK) {
4112 struct bfa_flash_attr_s *attr, *f;
4114 attr = (struct bfa_flash_attr_s *) flash->ubuf;
4115 f = (struct bfa_flash_attr_s *) flash->dbuf_kva;
4116 attr->status = be32_to_cpu(f->status);
4117 attr->npart = be32_to_cpu(f->npart);
4118 bfa_trc(flash, attr->status);
4119 bfa_trc(flash, attr->npart);
4120 for (i = 0; i < attr->npart; i++) {
4121 attr->part[i].part_type =
4122 be32_to_cpu(f->part[i].part_type);
4123 attr->part[i].part_instance =
4124 be32_to_cpu(f->part[i].part_instance);
4125 attr->part[i].part_off =
4126 be32_to_cpu(f->part[i].part_off);
4127 attr->part[i].part_size =
4128 be32_to_cpu(f->part[i].part_size);
4129 attr->part[i].part_len =
4130 be32_to_cpu(f->part[i].part_len);
4131 attr->part[i].part_status =
4132 be32_to_cpu(f->part[i].part_status);
4135 flash->status = status;
4136 bfa_flash_cb(flash);
4138 case BFI_FLASH_I2H_ERASE_RSP:
4139 status = be32_to_cpu(m.erase->status);
4140 bfa_trc(flash, status);
4141 flash->status = status;
4142 bfa_flash_cb(flash);
4144 case BFI_FLASH_I2H_WRITE_RSP:
4145 status = be32_to_cpu(m.write->status);
4146 bfa_trc(flash, status);
4147 if (status != BFA_STATUS_OK || flash->residue == 0) {
4148 flash->status = status;
4149 bfa_flash_cb(flash);
4151 bfa_trc(flash, flash->offset);
4152 bfa_flash_write_send(flash);
4155 case BFI_FLASH_I2H_READ_RSP:
4156 status = be32_to_cpu(m.read->status);
4157 bfa_trc(flash, status);
4158 if (status != BFA_STATUS_OK) {
4159 flash->status = status;
4160 bfa_flash_cb(flash);
4162 u32 len = be32_to_cpu(m.read->length);
4163 bfa_trc(flash, flash->offset);
4164 bfa_trc(flash, len);
4165 memcpy(flash->ubuf + flash->offset,
4166 flash->dbuf_kva, len);
4167 flash->residue -= len;
4168 flash->offset += len;
4169 if (flash->residue == 0) {
4170 flash->status = status;
4171 bfa_flash_cb(flash);
4173 bfa_flash_read_send(flash);
4176 case BFI_FLASH_I2H_BOOT_VER_RSP:
4178 case BFI_FLASH_I2H_EVENT:
4179 status = be32_to_cpu(m.event->status);
4180 bfa_trc(flash, status);
4181 if (status == BFA_STATUS_BAD_FWCFG)
4182 bfa_ioc_aen_post(flash->ioc, BFA_IOC_AEN_FWCFG_ERROR);
4183 else if (status == BFA_STATUS_INVALID_VENDOR) {
4185 param = be32_to_cpu(m.event->param);
4186 bfa_trc(flash, param);
4187 bfa_ioc_aen_post(flash->ioc,
4188 BFA_IOC_AEN_INVALID_VENDOR);
4198 * Flash memory info API.
4200 * @param[in] mincfg - minimal cfg variable
4203 bfa_flash_meminfo(bfa_boolean_t mincfg)
4205 /* min driver doesn't need flash */
4208 return BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
4214 * @param[in] flash - flash structure
4215 * @param[in] ioc - ioc structure
4216 * @param[in] dev - device structure
4217 * @param[in] trcmod - trace module
4218 * @param[in] logmod - log module
4221 bfa_flash_attach(struct bfa_flash_s *flash, struct bfa_ioc_s *ioc, void *dev,
4222 struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
4225 flash->trcmod = trcmod;
4227 flash->cbarg = NULL;
4230 bfa_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash);
4231 bfa_q_qe_init(&flash->ioc_notify);
4232 bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash);
4233 list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q);
4235 /* min driver doesn't need flash */
4237 flash->dbuf_kva = NULL;
4243 * Claim memory for flash
4245 * @param[in] flash - flash structure
4246 * @param[in] dm_kva - pointer to virtual memory address
4247 * @param[in] dm_pa - physical memory address
4248 * @param[in] mincfg - minimal cfg variable
4251 bfa_flash_memclaim(struct bfa_flash_s *flash, u8 *dm_kva, u64 dm_pa,
4252 bfa_boolean_t mincfg)
4257 flash->dbuf_kva = dm_kva;
4258 flash->dbuf_pa = dm_pa;
4259 memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ);
4260 dm_kva += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
4261 dm_pa += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
4265 * Get flash attribute.
4267 * @param[in] flash - flash structure
4268 * @param[in] attr - flash attribute structure
4269 * @param[in] cbfn - callback function
4270 * @param[in] cbarg - callback argument
4275 bfa_flash_get_attr(struct bfa_flash_s *flash, struct bfa_flash_attr_s *attr,
4276 bfa_cb_flash_t cbfn, void *cbarg)
4278 bfa_trc(flash, BFI_FLASH_H2I_QUERY_REQ);
4280 if (!bfa_ioc_is_operational(flash->ioc))
4281 return BFA_STATUS_IOC_NON_OP;
4283 if (flash->op_busy) {
4284 bfa_trc(flash, flash->op_busy);
4285 return BFA_STATUS_DEVBUSY;
4290 flash->cbarg = cbarg;
4291 flash->ubuf = (u8 *) attr;
4292 bfa_flash_query_send(flash);
4294 return BFA_STATUS_OK;
4298 * Erase flash partition.
4300 * @param[in] flash - flash structure
4301 * @param[in] type - flash partition type
4302 * @param[in] instance - flash partition instance
4303 * @param[in] cbfn - callback function
4304 * @param[in] cbarg - callback argument
4309 bfa_flash_erase_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
4310 u8 instance, bfa_cb_flash_t cbfn, void *cbarg)
4312 bfa_trc(flash, BFI_FLASH_H2I_ERASE_REQ);
4313 bfa_trc(flash, type);
4314 bfa_trc(flash, instance);
4316 if (!bfa_ioc_is_operational(flash->ioc))
4317 return BFA_STATUS_IOC_NON_OP;
4319 if (flash->op_busy) {
4320 bfa_trc(flash, flash->op_busy);
4321 return BFA_STATUS_DEVBUSY;
4326 flash->cbarg = cbarg;
4328 flash->instance = instance;
4330 bfa_flash_erase_send(flash);
4331 bfa_flash_aen_audit_post(flash->ioc, BFA_AUDIT_AEN_FLASH_ERASE,
4333 return BFA_STATUS_OK;
4337 * Update flash partition.
4339 * @param[in] flash - flash structure
4340 * @param[in] type - flash partition type
4341 * @param[in] instance - flash partition instance
4342 * @param[in] buf - update data buffer
4343 * @param[in] len - data buffer length
4344 * @param[in] offset - offset relative to the partition starting address
4345 * @param[in] cbfn - callback function
4346 * @param[in] cbarg - callback argument
4351 bfa_flash_update_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
4352 u8 instance, void *buf, u32 len, u32 offset,
4353 bfa_cb_flash_t cbfn, void *cbarg)
4355 bfa_trc(flash, BFI_FLASH_H2I_WRITE_REQ);
4356 bfa_trc(flash, type);
4357 bfa_trc(flash, instance);
4358 bfa_trc(flash, len);
4359 bfa_trc(flash, offset);
4361 if (!bfa_ioc_is_operational(flash->ioc))
4362 return BFA_STATUS_IOC_NON_OP;
4365 * 'len' must be in word (4-byte) boundary
4366 * 'offset' must be in sector (16kb) boundary
4368 if (!len || (len & 0x03) || (offset & 0x00003FFF))
4369 return BFA_STATUS_FLASH_BAD_LEN;
4371 if (type == BFA_FLASH_PART_MFG)
4372 return BFA_STATUS_EINVAL;
4374 if (flash->op_busy) {
4375 bfa_trc(flash, flash->op_busy);
4376 return BFA_STATUS_DEVBUSY;
4381 flash->cbarg = cbarg;
4383 flash->instance = instance;
4384 flash->residue = len;
4386 flash->addr_off = offset;
4389 bfa_flash_write_send(flash);
4390 return BFA_STATUS_OK;
4394 * Read flash partition.
4396 * @param[in] flash - flash structure
4397 * @param[in] type - flash partition type
4398 * @param[in] instance - flash partition instance
4399 * @param[in] buf - read data buffer
4400 * @param[in] len - data buffer length
4401 * @param[in] offset - offset relative to the partition starting address
4402 * @param[in] cbfn - callback function
4403 * @param[in] cbarg - callback argument
4408 bfa_flash_read_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
4409 u8 instance, void *buf, u32 len, u32 offset,
4410 bfa_cb_flash_t cbfn, void *cbarg)
4412 bfa_trc(flash, BFI_FLASH_H2I_READ_REQ);
4413 bfa_trc(flash, type);
4414 bfa_trc(flash, instance);
4415 bfa_trc(flash, len);
4416 bfa_trc(flash, offset);
4418 if (!bfa_ioc_is_operational(flash->ioc))
4419 return BFA_STATUS_IOC_NON_OP;
4422 * 'len' must be in word (4-byte) boundary
4423 * 'offset' must be in sector (16kb) boundary
4425 if (!len || (len & 0x03) || (offset & 0x00003FFF))
4426 return BFA_STATUS_FLASH_BAD_LEN;
4428 if (flash->op_busy) {
4429 bfa_trc(flash, flash->op_busy);
4430 return BFA_STATUS_DEVBUSY;
4435 flash->cbarg = cbarg;
4437 flash->instance = instance;
4438 flash->residue = len;
4440 flash->addr_off = offset;
4442 bfa_flash_read_send(flash);
4444 return BFA_STATUS_OK;
4448 * DIAG module specific
4451 #define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */
4452 #define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */
4454 /* IOC event handler */
4456 bfa_diag_notify(void *diag_arg, enum bfa_ioc_event_e event)
4458 struct bfa_diag_s *diag = diag_arg;
4460 bfa_trc(diag, event);
4461 bfa_trc(diag, diag->block);
4462 bfa_trc(diag, diag->fwping.lock);
4463 bfa_trc(diag, diag->tsensor.lock);
4466 case BFA_IOC_E_DISABLED:
4467 case BFA_IOC_E_FAILED:
4468 if (diag->fwping.lock) {
4469 diag->fwping.status = BFA_STATUS_IOC_FAILURE;
4470 diag->fwping.cbfn(diag->fwping.cbarg,
4471 diag->fwping.status);
4472 diag->fwping.lock = 0;
4475 if (diag->tsensor.lock) {
4476 diag->tsensor.status = BFA_STATUS_IOC_FAILURE;
4477 diag->tsensor.cbfn(diag->tsensor.cbarg,
4478 diag->tsensor.status);
4479 diag->tsensor.lock = 0;
4483 if (diag->timer_active) {
4484 bfa_timer_stop(&diag->timer);
4485 diag->timer_active = 0;
4488 diag->status = BFA_STATUS_IOC_FAILURE;
4489 diag->cbfn(diag->cbarg, diag->status);
4500 bfa_diag_memtest_done(void *cbarg)
4502 struct bfa_diag_s *diag = cbarg;
4503 struct bfa_ioc_s *ioc = diag->ioc;
4504 struct bfa_diag_memtest_result *res = diag->result;
4505 u32 loff = BFI_BOOT_MEMTEST_RES_ADDR;
4506 u32 pgnum, pgoff, i;
4508 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
4509 pgoff = PSS_SMEM_PGOFF(loff);
4511 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
4513 for (i = 0; i < (sizeof(struct bfa_diag_memtest_result) /
4514 sizeof(u32)); i++) {
4515 /* read test result from smem */
4516 *((u32 *) res + i) =
4517 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
4518 loff += sizeof(u32);
4521 /* Reset IOC fwstates to BFI_IOC_UNINIT */
4522 bfa_ioc_reset_fwstate(ioc);
4524 res->status = swab32(res->status);
4525 bfa_trc(diag, res->status);
4527 if (res->status == BFI_BOOT_MEMTEST_RES_SIG)
4528 diag->status = BFA_STATUS_OK;
4530 diag->status = BFA_STATUS_MEMTEST_FAILED;
4531 res->addr = swab32(res->addr);
4532 res->exp = swab32(res->exp);
4533 res->act = swab32(res->act);
4534 res->err_status = swab32(res->err_status);
4535 res->err_status1 = swab32(res->err_status1);
4536 res->err_addr = swab32(res->err_addr);
4537 bfa_trc(diag, res->addr);
4538 bfa_trc(diag, res->exp);
4539 bfa_trc(diag, res->act);
4540 bfa_trc(diag, res->err_status);
4541 bfa_trc(diag, res->err_status1);
4542 bfa_trc(diag, res->err_addr);
4544 diag->timer_active = 0;
4545 diag->cbfn(diag->cbarg, diag->status);
4554 * Perform DMA test directly
4557 diag_fwping_send(struct bfa_diag_s *diag)
4559 struct bfi_diag_fwping_req_s *fwping_req;
4562 bfa_trc(diag, diag->fwping.dbuf_pa);
4564 /* fill DMA area with pattern */
4565 for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++)
4566 *((u32 *)diag->fwping.dbuf_kva + i) = diag->fwping.data;
4569 fwping_req = (struct bfi_diag_fwping_req_s *)diag->fwping.mbcmd.msg;
4572 bfa_alen_set(&fwping_req->alen, BFI_DIAG_DMA_BUF_SZ,
4573 diag->fwping.dbuf_pa);
4574 /* Set up dma count */
4575 fwping_req->count = cpu_to_be32(diag->fwping.count);
4576 /* Set up data pattern */
4577 fwping_req->data = diag->fwping.data;
4579 /* build host command */
4580 bfi_h2i_set(fwping_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_FWPING,
4581 bfa_ioc_portid(diag->ioc));
4584 bfa_ioc_mbox_queue(diag->ioc, &diag->fwping.mbcmd);
4588 diag_fwping_comp(struct bfa_diag_s *diag,
4589 struct bfi_diag_fwping_rsp_s *diag_rsp)
4591 u32 rsp_data = diag_rsp->data;
4592 u8 rsp_dma_status = diag_rsp->dma_status;
4594 bfa_trc(diag, rsp_data);
4595 bfa_trc(diag, rsp_dma_status);
4597 if (rsp_dma_status == BFA_STATUS_OK) {
4599 pat = (diag->fwping.count & 0x1) ? ~(diag->fwping.data) :
4601 /* Check mbox data */
4602 if (diag->fwping.data != rsp_data) {
4603 bfa_trc(diag, rsp_data);
4604 diag->fwping.result->dmastatus =
4605 BFA_STATUS_DATACORRUPTED;
4606 diag->fwping.status = BFA_STATUS_DATACORRUPTED;
4607 diag->fwping.cbfn(diag->fwping.cbarg,
4608 diag->fwping.status);
4609 diag->fwping.lock = 0;
4612 /* Check dma pattern */
4613 for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++) {
4614 if (*((u32 *)diag->fwping.dbuf_kva + i) != pat) {
4618 *((u32 *)diag->fwping.dbuf_kva + i));
4619 diag->fwping.result->dmastatus =
4620 BFA_STATUS_DATACORRUPTED;
4621 diag->fwping.status = BFA_STATUS_DATACORRUPTED;
4622 diag->fwping.cbfn(diag->fwping.cbarg,
4623 diag->fwping.status);
4624 diag->fwping.lock = 0;
4628 diag->fwping.result->dmastatus = BFA_STATUS_OK;
4629 diag->fwping.status = BFA_STATUS_OK;
4630 diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
4631 diag->fwping.lock = 0;
4633 diag->fwping.status = BFA_STATUS_HDMA_FAILED;
4634 diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
4635 diag->fwping.lock = 0;
4640 * Temperature Sensor
4644 diag_tempsensor_send(struct bfa_diag_s *diag)
4646 struct bfi_diag_ts_req_s *msg;
4648 msg = (struct bfi_diag_ts_req_s *)diag->tsensor.mbcmd.msg;
4649 bfa_trc(diag, msg->temp);
4650 /* build host command */
4651 bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_TEMPSENSOR,
4652 bfa_ioc_portid(diag->ioc));
4654 bfa_ioc_mbox_queue(diag->ioc, &diag->tsensor.mbcmd);
4658 diag_tempsensor_comp(struct bfa_diag_s *diag, bfi_diag_ts_rsp_t *rsp)
4660 if (!diag->tsensor.lock) {
4661 /* receiving response after ioc failure */
4662 bfa_trc(diag, diag->tsensor.lock);
4667 * ASIC junction tempsensor is a reg read operation
4668 * it will always return OK
4670 diag->tsensor.temp->temp = be16_to_cpu(rsp->temp);
4671 diag->tsensor.temp->ts_junc = rsp->ts_junc;
4672 diag->tsensor.temp->ts_brd = rsp->ts_brd;
4673 diag->tsensor.temp->status = BFA_STATUS_OK;
4676 if (rsp->status == BFA_STATUS_OK) {
4677 diag->tsensor.temp->brd_temp =
4678 be16_to_cpu(rsp->brd_temp);
4680 bfa_trc(diag, rsp->status);
4681 diag->tsensor.temp->brd_temp = 0;
4682 diag->tsensor.temp->status = BFA_STATUS_DEVBUSY;
4685 bfa_trc(diag, rsp->ts_junc);
4686 bfa_trc(diag, rsp->temp);
4687 bfa_trc(diag, rsp->ts_brd);
4688 bfa_trc(diag, rsp->brd_temp);
4689 diag->tsensor.cbfn(diag->tsensor.cbarg, diag->tsensor.status);
4690 diag->tsensor.lock = 0;
4697 diag_ledtest_send(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
4699 struct bfi_diag_ledtest_req_s *msg;
4701 msg = (struct bfi_diag_ledtest_req_s *)diag->ledtest.mbcmd.msg;
4702 /* build host command */
4703 bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LEDTEST,
4704 bfa_ioc_portid(diag->ioc));
4707 * convert the freq from N blinks per 10 sec to
4708 * crossbow ontime value. We do it here because division is need
4711 ledtest->freq = 500 / ledtest->freq;
4713 if (ledtest->freq == 0)
4716 bfa_trc(diag, ledtest->freq);
4717 /* mcpy(&ledtest_req->req, ledtest, sizeof(bfa_diag_ledtest_t)); */
4718 msg->cmd = (u8) ledtest->cmd;
4719 msg->color = (u8) ledtest->color;
4720 msg->portid = bfa_ioc_portid(diag->ioc);
4721 msg->led = ledtest->led;
4722 msg->freq = cpu_to_be16(ledtest->freq);
4725 bfa_ioc_mbox_queue(diag->ioc, &diag->ledtest.mbcmd);
4729 diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s *msg)
4731 bfa_trc(diag, diag->ledtest.lock);
4732 diag->ledtest.lock = BFA_FALSE;
4733 /* no bfa_cb_queue is needed because driver is not waiting */
4740 diag_portbeacon_send(struct bfa_diag_s *diag, bfa_boolean_t beacon, u32 sec)
4742 struct bfi_diag_portbeacon_req_s *msg;
4744 msg = (struct bfi_diag_portbeacon_req_s *)diag->beacon.mbcmd.msg;
4745 /* build host command */
4746 bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_PORTBEACON,
4747 bfa_ioc_portid(diag->ioc));
4748 msg->beacon = beacon;
4749 msg->period = cpu_to_be32(sec);
4751 bfa_ioc_mbox_queue(diag->ioc, &diag->beacon.mbcmd);
4755 diag_portbeacon_comp(struct bfa_diag_s *diag)
4757 bfa_trc(diag, diag->beacon.state);
4758 diag->beacon.state = BFA_FALSE;
4759 if (diag->cbfn_beacon)
4760 diag->cbfn_beacon(diag->dev, BFA_FALSE, diag->beacon.link_e2e);
4764 * Diag hmbox handler
4767 bfa_diag_intr(void *diagarg, struct bfi_mbmsg_s *msg)
4769 struct bfa_diag_s *diag = diagarg;
4771 switch (msg->mh.msg_id) {
4772 case BFI_DIAG_I2H_PORTBEACON:
4773 diag_portbeacon_comp(diag);
4775 case BFI_DIAG_I2H_FWPING:
4776 diag_fwping_comp(diag, (struct bfi_diag_fwping_rsp_s *) msg);
4778 case BFI_DIAG_I2H_TEMPSENSOR:
4779 diag_tempsensor_comp(diag, (bfi_diag_ts_rsp_t *) msg);
4781 case BFI_DIAG_I2H_LEDTEST:
4782 diag_ledtest_comp(diag, (struct bfi_diag_ledtest_rsp_s *) msg);
4785 bfa_trc(diag, msg->mh.msg_id);
4793 * @param[in] *diag - diag data struct
4794 * @param[in] *memtest - mem test params input from upper layer,
4795 * @param[in] pattern - mem test pattern
4796 * @param[in] *result - mem test result
4797 * @param[in] cbfn - mem test callback functioin
4798 * @param[in] cbarg - callback functioin arg
4803 bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest,
4804 u32 pattern, struct bfa_diag_memtest_result *result,
4805 bfa_cb_diag_t cbfn, void *cbarg)
4809 bfa_trc(diag, pattern);
4811 if (!bfa_ioc_adapter_is_disabled(diag->ioc))
4812 return BFA_STATUS_ADAPTER_ENABLED;
4814 /* check to see if there is another destructive diag cmd running */
4816 bfa_trc(diag, diag->block);
4817 return BFA_STATUS_DEVBUSY;
4821 diag->result = result;
4823 diag->cbarg = cbarg;
4825 /* download memtest code and take LPU0 out of reset */
4826 bfa_ioc_boot(diag->ioc, BFI_FWBOOT_TYPE_MEMTEST, BFI_FWBOOT_ENV_OS);
4828 memtest_tov = (bfa_ioc_asic_gen(diag->ioc) == BFI_ASIC_GEN_CT2) ?
4829 CT2_BFA_DIAG_MEMTEST_TOV : BFA_DIAG_MEMTEST_TOV;
4830 bfa_timer_begin(diag->ioc->timer_mod, &diag->timer,
4831 bfa_diag_memtest_done, diag, memtest_tov);
4832 diag->timer_active = 1;
4833 return BFA_STATUS_OK;
4837 * DIAG firmware ping command
4839 * @param[in] *diag - diag data struct
4840 * @param[in] cnt - dma loop count for testing PCIE
4841 * @param[in] data - data pattern to pass in fw
4842 * @param[in] *result - pt to bfa_diag_fwping_result_t data struct
4843 * @param[in] cbfn - callback function
4844 * @param[in] *cbarg - callback functioin arg
4849 bfa_diag_fwping(struct bfa_diag_s *diag, u32 cnt, u32 data,
4850 struct bfa_diag_results_fwping *result, bfa_cb_diag_t cbfn,
4854 bfa_trc(diag, data);
4856 if (!bfa_ioc_is_operational(diag->ioc))
4857 return BFA_STATUS_IOC_NON_OP;
4859 if (bfa_asic_id_ct2(bfa_ioc_devid((diag->ioc))) &&
4860 ((diag->ioc)->clscode == BFI_PCIFN_CLASS_ETH))
4861 return BFA_STATUS_CMD_NOTSUPP;
4863 /* check to see if there is another destructive diag cmd running */
4864 if (diag->block || diag->fwping.lock) {
4865 bfa_trc(diag, diag->block);
4866 bfa_trc(diag, diag->fwping.lock);
4867 return BFA_STATUS_DEVBUSY;
4870 /* Initialization */
4871 diag->fwping.lock = 1;
4872 diag->fwping.cbfn = cbfn;
4873 diag->fwping.cbarg = cbarg;
4874 diag->fwping.result = result;
4875 diag->fwping.data = data;
4876 diag->fwping.count = cnt;
4878 /* Init test results */
4879 diag->fwping.result->data = 0;
4880 diag->fwping.result->status = BFA_STATUS_OK;
4882 /* kick off the first ping */
4883 diag_fwping_send(diag);
4884 return BFA_STATUS_OK;
4888 * Read Temperature Sensor
4890 * @param[in] *diag - diag data struct
4891 * @param[in] *result - pt to bfa_diag_temp_t data struct
4892 * @param[in] cbfn - callback function
4893 * @param[in] *cbarg - callback functioin arg
4898 bfa_diag_tsensor_query(struct bfa_diag_s *diag,
4899 struct bfa_diag_results_tempsensor_s *result,
4900 bfa_cb_diag_t cbfn, void *cbarg)
4902 /* check to see if there is a destructive diag cmd running */
4903 if (diag->block || diag->tsensor.lock) {
4904 bfa_trc(diag, diag->block);
4905 bfa_trc(diag, diag->tsensor.lock);
4906 return BFA_STATUS_DEVBUSY;
4909 if (!bfa_ioc_is_operational(diag->ioc))
4910 return BFA_STATUS_IOC_NON_OP;
4912 /* Init diag mod params */
4913 diag->tsensor.lock = 1;
4914 diag->tsensor.temp = result;
4915 diag->tsensor.cbfn = cbfn;
4916 diag->tsensor.cbarg = cbarg;
4918 /* Send msg to fw */
4919 diag_tempsensor_send(diag);
4921 return BFA_STATUS_OK;
4927 * @param[in] *diag - diag data struct
4928 * @param[in] *ledtest - pt to ledtest data structure
4933 bfa_diag_ledtest(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
4935 bfa_trc(diag, ledtest->cmd);
4937 if (!bfa_ioc_is_operational(diag->ioc))
4938 return BFA_STATUS_IOC_NON_OP;
4940 if (diag->beacon.state)
4941 return BFA_STATUS_BEACON_ON;
4943 if (diag->ledtest.lock)
4944 return BFA_STATUS_LEDTEST_OP;
4946 /* Send msg to fw */
4947 diag->ledtest.lock = BFA_TRUE;
4948 diag_ledtest_send(diag, ledtest);
4950 return BFA_STATUS_OK;
4954 * Port beaconing command
4956 * @param[in] *diag - diag data struct
4957 * @param[in] beacon - port beaconing 1:ON 0:OFF
4958 * @param[in] link_e2e_beacon - link beaconing 1:ON 0:OFF
4959 * @param[in] sec - beaconing duration in seconds
4964 bfa_diag_beacon_port(struct bfa_diag_s *diag, bfa_boolean_t beacon,
4965 bfa_boolean_t link_e2e_beacon, uint32_t sec)
4967 bfa_trc(diag, beacon);
4968 bfa_trc(diag, link_e2e_beacon);
4971 if (!bfa_ioc_is_operational(diag->ioc))
4972 return BFA_STATUS_IOC_NON_OP;
4974 if (diag->ledtest.lock)
4975 return BFA_STATUS_LEDTEST_OP;
4977 if (diag->beacon.state && beacon) /* beacon alread on */
4978 return BFA_STATUS_BEACON_ON;
4980 diag->beacon.state = beacon;
4981 diag->beacon.link_e2e = link_e2e_beacon;
4982 if (diag->cbfn_beacon)
4983 diag->cbfn_beacon(diag->dev, beacon, link_e2e_beacon);
4985 /* Send msg to fw */
4986 diag_portbeacon_send(diag, beacon, sec);
4988 return BFA_STATUS_OK;
4992 * Return DMA memory needed by diag module.
4995 bfa_diag_meminfo(void)
4997 return BFA_ROUNDUP(BFI_DIAG_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5001 * Attach virtual and physical memory for Diag.
5004 bfa_diag_attach(struct bfa_diag_s *diag, struct bfa_ioc_s *ioc, void *dev,
5005 bfa_cb_diag_beacon_t cbfn_beacon, struct bfa_trc_mod_s *trcmod)
5009 diag->trcmod = trcmod;
5014 diag->result = NULL;
5015 diag->cbfn_beacon = cbfn_beacon;
5017 bfa_ioc_mbox_regisr(diag->ioc, BFI_MC_DIAG, bfa_diag_intr, diag);
5018 bfa_q_qe_init(&diag->ioc_notify);
5019 bfa_ioc_notify_init(&diag->ioc_notify, bfa_diag_notify, diag);
5020 list_add_tail(&diag->ioc_notify.qe, &diag->ioc->notify_q);
5024 bfa_diag_memclaim(struct bfa_diag_s *diag, u8 *dm_kva, u64 dm_pa)
5026 diag->fwping.dbuf_kva = dm_kva;
5027 diag->fwping.dbuf_pa = dm_pa;
5028 memset(diag->fwping.dbuf_kva, 0, BFI_DIAG_DMA_BUF_SZ);
5032 * PHY module specific
5034 #define BFA_PHY_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
5035 #define BFA_PHY_LOCK_STATUS 0x018878 /* phy semaphore status reg */
5038 bfa_phy_ntoh32(u32 *obuf, u32 *ibuf, int sz)
5042 for (i = 0; i < m; i++)
5043 obuf[i] = be32_to_cpu(ibuf[i]);
5046 static bfa_boolean_t
5047 bfa_phy_present(struct bfa_phy_s *phy)
5049 return (phy->ioc->attr->card_type == BFA_MFG_TYPE_LIGHTNING);
5053 bfa_phy_notify(void *cbarg, enum bfa_ioc_event_e event)
5055 struct bfa_phy_s *phy = cbarg;
5057 bfa_trc(phy, event);
5060 case BFA_IOC_E_DISABLED:
5061 case BFA_IOC_E_FAILED:
5063 phy->status = BFA_STATUS_IOC_FAILURE;
5064 phy->cbfn(phy->cbarg, phy->status);
5075 * Send phy attribute query request.
5077 * @param[in] cbarg - callback argument
5080 bfa_phy_query_send(void *cbarg)
5082 struct bfa_phy_s *phy = cbarg;
5083 struct bfi_phy_query_req_s *msg =
5084 (struct bfi_phy_query_req_s *) phy->mb.msg;
5086 msg->instance = phy->instance;
5087 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_QUERY_REQ,
5088 bfa_ioc_portid(phy->ioc));
5089 bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_attr_s), phy->dbuf_pa);
5090 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5094 * Send phy write request.
5096 * @param[in] cbarg - callback argument
5099 bfa_phy_write_send(void *cbarg)
5101 struct bfa_phy_s *phy = cbarg;
5102 struct bfi_phy_write_req_s *msg =
5103 (struct bfi_phy_write_req_s *) phy->mb.msg;
5108 msg->instance = phy->instance;
5109 msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
5110 len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
5111 phy->residue : BFA_PHY_DMA_BUF_SZ;
5112 msg->length = cpu_to_be32(len);
5114 /* indicate if it's the last msg of the whole write operation */
5115 msg->last = (len == phy->residue) ? 1 : 0;
5117 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_WRITE_REQ,
5118 bfa_ioc_portid(phy->ioc));
5119 bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
5121 buf = (u16 *) (phy->ubuf + phy->offset);
5122 dbuf = (u16 *)phy->dbuf_kva;
5124 for (i = 0; i < sz; i++)
5125 buf[i] = cpu_to_be16(dbuf[i]);
5127 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5129 phy->residue -= len;
5134 * Send phy read request.
5136 * @param[in] cbarg - callback argument
5139 bfa_phy_read_send(void *cbarg)
5141 struct bfa_phy_s *phy = cbarg;
5142 struct bfi_phy_read_req_s *msg =
5143 (struct bfi_phy_read_req_s *) phy->mb.msg;
5146 msg->instance = phy->instance;
5147 msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
5148 len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
5149 phy->residue : BFA_PHY_DMA_BUF_SZ;
5150 msg->length = cpu_to_be32(len);
5151 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_READ_REQ,
5152 bfa_ioc_portid(phy->ioc));
5153 bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
5154 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5158 * Send phy stats request.
5160 * @param[in] cbarg - callback argument
5163 bfa_phy_stats_send(void *cbarg)
5165 struct bfa_phy_s *phy = cbarg;
5166 struct bfi_phy_stats_req_s *msg =
5167 (struct bfi_phy_stats_req_s *) phy->mb.msg;
5169 msg->instance = phy->instance;
5170 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_STATS_REQ,
5171 bfa_ioc_portid(phy->ioc));
5172 bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_stats_s), phy->dbuf_pa);
5173 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5177 * Flash memory info API.
5179 * @param[in] mincfg - minimal cfg variable
5182 bfa_phy_meminfo(bfa_boolean_t mincfg)
5184 /* min driver doesn't need phy */
5188 return BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5194 * @param[in] phy - phy structure
5195 * @param[in] ioc - ioc structure
5196 * @param[in] dev - device structure
5197 * @param[in] trcmod - trace module
5198 * @param[in] logmod - log module
5201 bfa_phy_attach(struct bfa_phy_s *phy, struct bfa_ioc_s *ioc, void *dev,
5202 struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
5205 phy->trcmod = trcmod;
5210 bfa_ioc_mbox_regisr(phy->ioc, BFI_MC_PHY, bfa_phy_intr, phy);
5211 bfa_q_qe_init(&phy->ioc_notify);
5212 bfa_ioc_notify_init(&phy->ioc_notify, bfa_phy_notify, phy);
5213 list_add_tail(&phy->ioc_notify.qe, &phy->ioc->notify_q);
5215 /* min driver doesn't need phy */
5217 phy->dbuf_kva = NULL;
5223 * Claim memory for phy
5225 * @param[in] phy - phy structure
5226 * @param[in] dm_kva - pointer to virtual memory address
5227 * @param[in] dm_pa - physical memory address
5228 * @param[in] mincfg - minimal cfg variable
5231 bfa_phy_memclaim(struct bfa_phy_s *phy, u8 *dm_kva, u64 dm_pa,
5232 bfa_boolean_t mincfg)
5237 phy->dbuf_kva = dm_kva;
5238 phy->dbuf_pa = dm_pa;
5239 memset(phy->dbuf_kva, 0, BFA_PHY_DMA_BUF_SZ);
5240 dm_kva += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5241 dm_pa += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5245 bfa_phy_busy(struct bfa_ioc_s *ioc)
5249 rb = bfa_ioc_bar0(ioc);
5250 return readl(rb + BFA_PHY_LOCK_STATUS);
5254 * Get phy attribute.
5256 * @param[in] phy - phy structure
5257 * @param[in] attr - phy attribute structure
5258 * @param[in] cbfn - callback function
5259 * @param[in] cbarg - callback argument
5264 bfa_phy_get_attr(struct bfa_phy_s *phy, u8 instance,
5265 struct bfa_phy_attr_s *attr, bfa_cb_phy_t cbfn, void *cbarg)
5267 bfa_trc(phy, BFI_PHY_H2I_QUERY_REQ);
5268 bfa_trc(phy, instance);
5270 if (!bfa_phy_present(phy))
5271 return BFA_STATUS_PHY_NOT_PRESENT;
5273 if (!bfa_ioc_is_operational(phy->ioc))
5274 return BFA_STATUS_IOC_NON_OP;
5276 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5277 bfa_trc(phy, phy->op_busy);
5278 return BFA_STATUS_DEVBUSY;
5284 phy->instance = instance;
5285 phy->ubuf = (uint8_t *) attr;
5286 bfa_phy_query_send(phy);
5288 return BFA_STATUS_OK;
5294 * @param[in] phy - phy structure
5295 * @param[in] instance - phy image instance
5296 * @param[in] stats - pointer to phy stats
5297 * @param[in] cbfn - callback function
5298 * @param[in] cbarg - callback argument
5303 bfa_phy_get_stats(struct bfa_phy_s *phy, u8 instance,
5304 struct bfa_phy_stats_s *stats,
5305 bfa_cb_phy_t cbfn, void *cbarg)
5307 bfa_trc(phy, BFI_PHY_H2I_STATS_REQ);
5308 bfa_trc(phy, instance);
5310 if (!bfa_phy_present(phy))
5311 return BFA_STATUS_PHY_NOT_PRESENT;
5313 if (!bfa_ioc_is_operational(phy->ioc))
5314 return BFA_STATUS_IOC_NON_OP;
5316 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5317 bfa_trc(phy, phy->op_busy);
5318 return BFA_STATUS_DEVBUSY;
5324 phy->instance = instance;
5325 phy->ubuf = (u8 *) stats;
5326 bfa_phy_stats_send(phy);
5328 return BFA_STATUS_OK;
5334 * @param[in] phy - phy structure
5335 * @param[in] instance - phy image instance
5336 * @param[in] buf - update data buffer
5337 * @param[in] len - data buffer length
5338 * @param[in] offset - offset relative to starting address
5339 * @param[in] cbfn - callback function
5340 * @param[in] cbarg - callback argument
5345 bfa_phy_update(struct bfa_phy_s *phy, u8 instance,
5346 void *buf, u32 len, u32 offset,
5347 bfa_cb_phy_t cbfn, void *cbarg)
5349 bfa_trc(phy, BFI_PHY_H2I_WRITE_REQ);
5350 bfa_trc(phy, instance);
5352 bfa_trc(phy, offset);
5354 if (!bfa_phy_present(phy))
5355 return BFA_STATUS_PHY_NOT_PRESENT;
5357 if (!bfa_ioc_is_operational(phy->ioc))
5358 return BFA_STATUS_IOC_NON_OP;
5360 /* 'len' must be in word (4-byte) boundary */
5361 if (!len || (len & 0x03))
5362 return BFA_STATUS_FAILED;
5364 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5365 bfa_trc(phy, phy->op_busy);
5366 return BFA_STATUS_DEVBUSY;
5372 phy->instance = instance;
5375 phy->addr_off = offset;
5378 bfa_phy_write_send(phy);
5379 return BFA_STATUS_OK;
5385 * @param[in] phy - phy structure
5386 * @param[in] instance - phy image instance
5387 * @param[in] buf - read data buffer
5388 * @param[in] len - data buffer length
5389 * @param[in] offset - offset relative to starting address
5390 * @param[in] cbfn - callback function
5391 * @param[in] cbarg - callback argument
5396 bfa_phy_read(struct bfa_phy_s *phy, u8 instance,
5397 void *buf, u32 len, u32 offset,
5398 bfa_cb_phy_t cbfn, void *cbarg)
5400 bfa_trc(phy, BFI_PHY_H2I_READ_REQ);
5401 bfa_trc(phy, instance);
5403 bfa_trc(phy, offset);
5405 if (!bfa_phy_present(phy))
5406 return BFA_STATUS_PHY_NOT_PRESENT;
5408 if (!bfa_ioc_is_operational(phy->ioc))
5409 return BFA_STATUS_IOC_NON_OP;
5411 /* 'len' must be in word (4-byte) boundary */
5412 if (!len || (len & 0x03))
5413 return BFA_STATUS_FAILED;
5415 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5416 bfa_trc(phy, phy->op_busy);
5417 return BFA_STATUS_DEVBUSY;
5423 phy->instance = instance;
5426 phy->addr_off = offset;
5428 bfa_phy_read_send(phy);
5430 return BFA_STATUS_OK;
5434 * Process phy response messages upon receiving interrupts.
5436 * @param[in] phyarg - phy structure
5437 * @param[in] msg - message structure
5440 bfa_phy_intr(void *phyarg, struct bfi_mbmsg_s *msg)
5442 struct bfa_phy_s *phy = phyarg;
5446 struct bfi_phy_query_rsp_s *query;
5447 struct bfi_phy_stats_rsp_s *stats;
5448 struct bfi_phy_write_rsp_s *write;
5449 struct bfi_phy_read_rsp_s *read;
5450 struct bfi_mbmsg_s *msg;
5454 bfa_trc(phy, msg->mh.msg_id);
5456 if (!phy->op_busy) {
5457 /* receiving response after ioc failure */
5458 bfa_trc(phy, 0x9999);
5462 switch (msg->mh.msg_id) {
5463 case BFI_PHY_I2H_QUERY_RSP:
5464 status = be32_to_cpu(m.query->status);
5465 bfa_trc(phy, status);
5467 if (status == BFA_STATUS_OK) {
5468 struct bfa_phy_attr_s *attr =
5469 (struct bfa_phy_attr_s *) phy->ubuf;
5470 bfa_phy_ntoh32((u32 *)attr, (u32 *)phy->dbuf_kva,
5471 sizeof(struct bfa_phy_attr_s));
5472 bfa_trc(phy, attr->status);
5473 bfa_trc(phy, attr->length);
5476 phy->status = status;
5479 phy->cbfn(phy->cbarg, phy->status);
5481 case BFI_PHY_I2H_STATS_RSP:
5482 status = be32_to_cpu(m.stats->status);
5483 bfa_trc(phy, status);
5485 if (status == BFA_STATUS_OK) {
5486 struct bfa_phy_stats_s *stats =
5487 (struct bfa_phy_stats_s *) phy->ubuf;
5488 bfa_phy_ntoh32((u32 *)stats, (u32 *)phy->dbuf_kva,
5489 sizeof(struct bfa_phy_stats_s));
5490 bfa_trc(phy, stats->status);
5493 phy->status = status;
5496 phy->cbfn(phy->cbarg, phy->status);
5498 case BFI_PHY_I2H_WRITE_RSP:
5499 status = be32_to_cpu(m.write->status);
5500 bfa_trc(phy, status);
5502 if (status != BFA_STATUS_OK || phy->residue == 0) {
5503 phy->status = status;
5506 phy->cbfn(phy->cbarg, phy->status);
5508 bfa_trc(phy, phy->offset);
5509 bfa_phy_write_send(phy);
5512 case BFI_PHY_I2H_READ_RSP:
5513 status = be32_to_cpu(m.read->status);
5514 bfa_trc(phy, status);
5516 if (status != BFA_STATUS_OK) {
5517 phy->status = status;
5520 phy->cbfn(phy->cbarg, phy->status);
5522 u32 len = be32_to_cpu(m.read->length);
5523 u16 *buf = (u16 *)(phy->ubuf + phy->offset);
5524 u16 *dbuf = (u16 *)phy->dbuf_kva;
5525 int i, sz = len >> 1;
5527 bfa_trc(phy, phy->offset);
5530 for (i = 0; i < sz; i++)
5531 buf[i] = be16_to_cpu(dbuf[i]);
5533 phy->residue -= len;
5536 if (phy->residue == 0) {
5537 phy->status = status;
5540 phy->cbfn(phy->cbarg, phy->status);
5542 bfa_phy_read_send(phy);
5551 * DCONF module specific
5557 * DCONF state machine events
5559 enum bfa_dconf_event {
5560 BFA_DCONF_SM_INIT = 1, /* dconf Init */
5561 BFA_DCONF_SM_FLASH_COMP = 2, /* read/write to flash */
5562 BFA_DCONF_SM_WR = 3, /* binding change, map */
5563 BFA_DCONF_SM_TIMEOUT = 4, /* Start timer */
5564 BFA_DCONF_SM_EXIT = 5, /* exit dconf module */
5565 BFA_DCONF_SM_IOCDISABLE = 6, /* IOC disable event */
5568 /* forward declaration of DCONF state machine */
5569 static void bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf,
5570 enum bfa_dconf_event event);
5571 static void bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
5572 enum bfa_dconf_event event);
5573 static void bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf,
5574 enum bfa_dconf_event event);
5575 static void bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf,
5576 enum bfa_dconf_event event);
5577 static void bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf,
5578 enum bfa_dconf_event event);
5579 static void bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
5580 enum bfa_dconf_event event);
5581 static void bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
5582 enum bfa_dconf_event event);
5584 static void bfa_dconf_cbfn(void *dconf, bfa_status_t status);
5585 static void bfa_dconf_timer(void *cbarg);
5586 static bfa_status_t bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf);
5587 static void bfa_dconf_init_cb(void *arg, bfa_status_t status);
5590 * Beginning state of dconf module. Waiting for an event to start.
5593 bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5595 bfa_status_t bfa_status;
5596 bfa_trc(dconf->bfa, event);
5599 case BFA_DCONF_SM_INIT:
5600 if (dconf->min_cfg) {
5601 bfa_trc(dconf->bfa, dconf->min_cfg);
5602 bfa_fsm_send_event(&dconf->bfa->iocfc,
5603 IOCFC_E_DCONF_DONE);
5606 bfa_sm_set_state(dconf, bfa_dconf_sm_flash_read);
5607 bfa_timer_start(dconf->bfa, &dconf->timer,
5608 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5609 bfa_status = bfa_flash_read_part(BFA_FLASH(dconf->bfa),
5610 BFA_FLASH_PART_DRV, dconf->instance,
5612 sizeof(struct bfa_dconf_s), 0,
5613 bfa_dconf_init_cb, dconf->bfa);
5614 if (bfa_status != BFA_STATUS_OK) {
5615 bfa_timer_stop(&dconf->timer);
5616 bfa_dconf_init_cb(dconf->bfa, BFA_STATUS_FAILED);
5617 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5621 case BFA_DCONF_SM_EXIT:
5622 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
5623 case BFA_DCONF_SM_IOCDISABLE:
5624 case BFA_DCONF_SM_WR:
5625 case BFA_DCONF_SM_FLASH_COMP:
5628 bfa_sm_fault(dconf->bfa, event);
5633 * Read flash for dconf entries and make a call back to the driver once done.
5636 bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
5637 enum bfa_dconf_event event)
5639 bfa_trc(dconf->bfa, event);
5642 case BFA_DCONF_SM_FLASH_COMP:
5643 bfa_timer_stop(&dconf->timer);
5644 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
5646 case BFA_DCONF_SM_TIMEOUT:
5647 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
5648 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_IOC_FAILED);
5650 case BFA_DCONF_SM_EXIT:
5651 bfa_timer_stop(&dconf->timer);
5652 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5653 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
5655 case BFA_DCONF_SM_IOCDISABLE:
5656 bfa_timer_stop(&dconf->timer);
5657 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5660 bfa_sm_fault(dconf->bfa, event);
5665 * DCONF Module is in ready state. Has completed the initialization.
5668 bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5670 bfa_trc(dconf->bfa, event);
5673 case BFA_DCONF_SM_WR:
5674 bfa_timer_start(dconf->bfa, &dconf->timer,
5675 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5676 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
5678 case BFA_DCONF_SM_EXIT:
5679 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5680 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
5682 case BFA_DCONF_SM_INIT:
5683 case BFA_DCONF_SM_IOCDISABLE:
5686 bfa_sm_fault(dconf->bfa, event);
5691 * entries are dirty, write back to the flash.
5695 bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5697 bfa_trc(dconf->bfa, event);
5700 case BFA_DCONF_SM_TIMEOUT:
5701 bfa_sm_set_state(dconf, bfa_dconf_sm_sync);
5702 bfa_dconf_flash_write(dconf);
5704 case BFA_DCONF_SM_WR:
5705 bfa_timer_stop(&dconf->timer);
5706 bfa_timer_start(dconf->bfa, &dconf->timer,
5707 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5709 case BFA_DCONF_SM_EXIT:
5710 bfa_timer_stop(&dconf->timer);
5711 bfa_timer_start(dconf->bfa, &dconf->timer,
5712 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5713 bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
5714 bfa_dconf_flash_write(dconf);
5716 case BFA_DCONF_SM_FLASH_COMP:
5718 case BFA_DCONF_SM_IOCDISABLE:
5719 bfa_timer_stop(&dconf->timer);
5720 bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
5723 bfa_sm_fault(dconf->bfa, event);
5728 * Sync the dconf entries to the flash.
5731 bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
5732 enum bfa_dconf_event event)
5734 bfa_trc(dconf->bfa, event);
5737 case BFA_DCONF_SM_IOCDISABLE:
5738 case BFA_DCONF_SM_FLASH_COMP:
5739 bfa_timer_stop(&dconf->timer);
5740 case BFA_DCONF_SM_TIMEOUT:
5741 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5742 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
5745 bfa_sm_fault(dconf->bfa, event);
5750 bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5752 bfa_trc(dconf->bfa, event);
5755 case BFA_DCONF_SM_FLASH_COMP:
5756 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
5758 case BFA_DCONF_SM_WR:
5759 bfa_timer_start(dconf->bfa, &dconf->timer,
5760 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5761 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
5763 case BFA_DCONF_SM_EXIT:
5764 bfa_timer_start(dconf->bfa, &dconf->timer,
5765 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5766 bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
5768 case BFA_DCONF_SM_IOCDISABLE:
5769 bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
5772 bfa_sm_fault(dconf->bfa, event);
5777 bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
5778 enum bfa_dconf_event event)
5780 bfa_trc(dconf->bfa, event);
5783 case BFA_DCONF_SM_INIT:
5784 bfa_timer_start(dconf->bfa, &dconf->timer,
5785 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5786 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
5788 case BFA_DCONF_SM_EXIT:
5789 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5790 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
5792 case BFA_DCONF_SM_IOCDISABLE:
5795 bfa_sm_fault(dconf->bfa, event);
5800 * Compute and return memory needed by DRV_CFG module.
5803 bfa_dconf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
5806 struct bfa_mem_kva_s *dconf_kva = BFA_MEM_DCONF_KVA(bfa);
5808 if (cfg->drvcfg.min_cfg)
5809 bfa_mem_kva_setup(meminfo, dconf_kva,
5810 sizeof(struct bfa_dconf_hdr_s));
5812 bfa_mem_kva_setup(meminfo, dconf_kva,
5813 sizeof(struct bfa_dconf_s));
5817 bfa_dconf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5818 struct bfa_pcidev_s *pcidev)
5820 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5824 dconf->instance = bfa->ioc.port_id;
5825 bfa_trc(bfa, dconf->instance);
5827 dconf->dconf = (struct bfa_dconf_s *) bfa_mem_kva_curp(dconf);
5828 if (cfg->drvcfg.min_cfg) {
5829 bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_hdr_s);
5830 dconf->min_cfg = BFA_TRUE;
5832 dconf->min_cfg = BFA_FALSE;
5833 bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_s);
5836 bfa_dconf_read_data_valid(bfa) = BFA_FALSE;
5837 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5841 bfa_dconf_init_cb(void *arg, bfa_status_t status)
5843 struct bfa_s *bfa = arg;
5844 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5846 bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
5847 if (status == BFA_STATUS_OK) {
5848 bfa_dconf_read_data_valid(bfa) = BFA_TRUE;
5849 if (dconf->dconf->hdr.signature != BFI_DCONF_SIGNATURE)
5850 dconf->dconf->hdr.signature = BFI_DCONF_SIGNATURE;
5851 if (dconf->dconf->hdr.version != BFI_DCONF_VERSION)
5852 dconf->dconf->hdr.version = BFI_DCONF_VERSION;
5854 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DCONF_DONE);
5858 bfa_dconf_modinit(struct bfa_s *bfa)
5860 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5861 bfa_sm_send_event(dconf, BFA_DCONF_SM_INIT);
5864 bfa_dconf_start(struct bfa_s *bfa)
5869 bfa_dconf_stop(struct bfa_s *bfa)
5873 static void bfa_dconf_timer(void *cbarg)
5875 struct bfa_dconf_mod_s *dconf = cbarg;
5876 bfa_sm_send_event(dconf, BFA_DCONF_SM_TIMEOUT);
5879 bfa_dconf_iocdisable(struct bfa_s *bfa)
5881 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5882 bfa_sm_send_event(dconf, BFA_DCONF_SM_IOCDISABLE);
5886 bfa_dconf_detach(struct bfa_s *bfa)
5891 bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf)
5893 bfa_status_t bfa_status;
5894 bfa_trc(dconf->bfa, 0);
5896 bfa_status = bfa_flash_update_part(BFA_FLASH(dconf->bfa),
5897 BFA_FLASH_PART_DRV, dconf->instance,
5898 dconf->dconf, sizeof(struct bfa_dconf_s), 0,
5899 bfa_dconf_cbfn, dconf);
5900 if (bfa_status != BFA_STATUS_OK)
5901 WARN_ON(bfa_status);
5902 bfa_trc(dconf->bfa, bfa_status);
5908 bfa_dconf_update(struct bfa_s *bfa)
5910 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5911 bfa_trc(dconf->bfa, 0);
5912 if (bfa_sm_cmp_state(dconf, bfa_dconf_sm_iocdown_dirty))
5913 return BFA_STATUS_FAILED;
5915 if (dconf->min_cfg) {
5916 bfa_trc(dconf->bfa, dconf->min_cfg);
5917 return BFA_STATUS_FAILED;
5920 bfa_sm_send_event(dconf, BFA_DCONF_SM_WR);
5921 return BFA_STATUS_OK;
5925 bfa_dconf_cbfn(void *arg, bfa_status_t status)
5927 struct bfa_dconf_mod_s *dconf = arg;
5929 bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
5933 bfa_dconf_modexit(struct bfa_s *bfa)
5935 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5936 bfa_sm_send_event(dconf, BFA_DCONF_SM_EXIT);