blob: 3f41d290142d2fecd1338259aa3f1da1ea268262 [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
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
11 *
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.
16 */
17
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070018#include "bfa_ioc.h"
19#include "bfi_ctreg.h"
20#include "bfa_defs.h"
21#include "bfa_defs_svc.h"
22#include "bfad_drv.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070023
Krishna Gudipati7af074d2010-03-05 19:35:45 -080024BFA_TRC_FILE(CNA, IOC);
Jing Huang7725ccf2009-09-23 17:46:15 -070025
Jing Huang5fbe25c2010-10-18 17:17:23 -070026/*
Jing Huang7725ccf2009-09-23 17:46:15 -070027 * IOC local definitions
28 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070029#define BFA_IOC_TOV 3000 /* msecs */
30#define BFA_IOC_HWSEM_TOV 500 /* msecs */
31#define BFA_IOC_HB_TOV 500 /* msecs */
32#define BFA_IOC_HWINIT_MAX 2
33#define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
Jing Huang7725ccf2009-09-23 17:46:15 -070034
35#define bfa_ioc_timer_start(__ioc) \
36 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
37 bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
38#define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
39
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070040#define bfa_hb_timer_start(__ioc) \
41 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
42 bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
43#define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
44
Jing Huang7725ccf2009-09-23 17:46:15 -070045#define BFA_DBG_FWTRC_ENTS (BFI_IOC_TRC_ENTS)
46#define BFA_DBG_FWTRC_LEN \
47 (BFA_DBG_FWTRC_ENTS * sizeof(struct bfa_trc_s) + \
48 (sizeof(struct bfa_trc_mod_s) - \
49 BFA_TRC_MAX * sizeof(struct bfa_trc_s)))
50#define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
Jing Huang7725ccf2009-09-23 17:46:15 -070051
Jing Huang5fbe25c2010-10-18 17:17:23 -070052/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080053 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
54 */
55
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070056#define bfa_ioc_firmware_lock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080057 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070058#define bfa_ioc_firmware_unlock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080059 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
Krishna Gudipati0a20de42010-03-05 19:34:20 -080060#define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
61#define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070062#define bfa_ioc_notify_hbfail(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080063 ((__ioc)->ioc_hwif->ioc_notify_hbfail(__ioc))
64
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070065#ifdef BFA_IOC_IS_UEFI
66#define bfa_ioc_is_bios_optrom(__ioc) (0)
67#define bfa_ioc_is_uefi(__ioc) BFA_IOC_IS_UEFI
68#else
69#define bfa_ioc_is_bios_optrom(__ioc) \
70 (bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(__ioc)) < BFA_IOC_FWIMG_MINSZ)
71#define bfa_ioc_is_uefi(__ioc) (0)
72#endif
73
74#define bfa_ioc_mbox_cmd_pending(__ioc) \
75 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
Jing Huang53440262010-10-18 17:12:29 -070076 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070077
78bfa_boolean_t bfa_auto_recover = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070079
80/*
81 * forward declarations
82 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070083static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
84static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc);
85static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
86static void bfa_ioc_timeout(void *ioc);
87static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
88static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
89static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
90static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
91static void bfa_ioc_hb_stop(struct bfa_ioc_s *ioc);
92static void bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force);
93static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
94static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc);
95static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
96static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
97static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
98static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
99static void bfa_ioc_pf_enabled(struct bfa_ioc_s *ioc);
100static void bfa_ioc_pf_disabled(struct bfa_ioc_s *ioc);
101static void bfa_ioc_pf_failed(struct bfa_ioc_s *ioc);
102static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700103
Jing Huang7725ccf2009-09-23 17:46:15 -0700104
Jing Huang5fbe25c2010-10-18 17:17:23 -0700105/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700106 * IOC state machine definitions/declarations
Jing Huang7725ccf2009-09-23 17:46:15 -0700107 */
108enum ioc_event {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700109 IOC_E_RESET = 1, /* IOC reset request */
110 IOC_E_ENABLE = 2, /* IOC enable request */
111 IOC_E_DISABLE = 3, /* IOC disable request */
112 IOC_E_DETACH = 4, /* driver detach cleanup */
113 IOC_E_ENABLED = 5, /* f/w enabled */
114 IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
115 IOC_E_DISABLED = 7, /* f/w disabled */
116 IOC_E_FAILED = 8, /* failure notice by iocpf sm */
117 IOC_E_HBFAIL = 9, /* heartbeat failure */
118 IOC_E_HWERROR = 10, /* hardware error interrupt */
119 IOC_E_TIMEOUT = 11, /* timeout */
Jing Huang7725ccf2009-09-23 17:46:15 -0700120};
121
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700122bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700123bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700124bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
125bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
126bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
127bfa_fsm_state_decl(bfa_ioc, initfail, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700128bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700129bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
130bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
131
132static struct bfa_sm_table_s ioc_sm_table[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700133 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Jing Huang7725ccf2009-09-23 17:46:15 -0700134 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700135 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Jing Huang7725ccf2009-09-23 17:46:15 -0700136 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
137 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
138 {BFA_SM(bfa_ioc_sm_initfail), BFA_IOC_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700139 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700140 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
141 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
142};
143
Jing Huang5fbe25c2010-10-18 17:17:23 -0700144/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700145 * IOCPF state machine definitions/declarations
146 */
147
148#define bfa_iocpf_timer_start(__ioc) \
149 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
150 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
151#define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
152
153#define bfa_iocpf_recovery_timer_start(__ioc) \
154 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
155 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV_RECOVER)
156
157#define bfa_sem_timer_start(__ioc) \
158 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
159 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
160#define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
161
162/*
163 * Forward declareations for iocpf state machine
164 */
165static void bfa_iocpf_enable(struct bfa_ioc_s *ioc);
166static void bfa_iocpf_disable(struct bfa_ioc_s *ioc);
167static void bfa_iocpf_fail(struct bfa_ioc_s *ioc);
168static void bfa_iocpf_initfail(struct bfa_ioc_s *ioc);
169static void bfa_iocpf_getattrfail(struct bfa_ioc_s *ioc);
170static void bfa_iocpf_stop(struct bfa_ioc_s *ioc);
171static void bfa_iocpf_timeout(void *ioc_arg);
172static void bfa_iocpf_sem_timeout(void *ioc_arg);
173
Jing Huang5fbe25c2010-10-18 17:17:23 -0700174/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700175 * IOCPF state machine events
176 */
177enum iocpf_event {
178 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
179 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
180 IOCPF_E_STOP = 3, /* stop on driver detach */
181 IOCPF_E_FWREADY = 4, /* f/w initialization done */
182 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
183 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
184 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
185 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
186 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
187 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
188 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
189};
190
Jing Huang5fbe25c2010-10-18 17:17:23 -0700191/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700192 * IOCPF states
193 */
194enum bfa_iocpf_state {
195 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
196 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
197 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
198 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
199 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
200 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
201 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
202 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
203 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
204};
205
206bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
207bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
208bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
209bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
210bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
211bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
212bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
213bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
214bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
215bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
216bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
217
218static struct bfa_sm_table_s iocpf_sm_table[] = {
219 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
220 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
221 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
222 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
223 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
224 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
225 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
226 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
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_disabled), BFA_IOCPF_DISABLED},
230};
231
Jing Huang5fbe25c2010-10-18 17:17:23 -0700232/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700233 * IOC State Machine
234 */
235
Jing Huang5fbe25c2010-10-18 17:17:23 -0700236/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700237 * Beginning state. IOC uninit state.
238 */
239
240static void
241bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
242{
243}
244
Jing Huang5fbe25c2010-10-18 17:17:23 -0700245/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700246 * IOC is in uninit state.
247 */
248static void
249bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
250{
251 bfa_trc(ioc, event);
252
253 switch (event) {
254 case IOC_E_RESET:
255 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
256 break;
257
258 default:
259 bfa_sm_fault(ioc, event);
260 }
261}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700262/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700263 * Reset entry actions -- initialize state machine
264 */
265static void
266bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
267{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700268 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700269}
270
Jing Huang5fbe25c2010-10-18 17:17:23 -0700271/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700272 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700273 */
274static void
275bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
276{
277 bfa_trc(ioc, event);
278
279 switch (event) {
280 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700281 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
282 break;
283
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700284 case IOC_E_DISABLE:
285 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700286 break;
287
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700288 case IOC_E_DETACH:
289 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700290 break;
291
292 default:
293 bfa_sm_fault(ioc, event);
294 }
295}
296
297
298static void
299bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
300{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700301 bfa_iocpf_enable(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700302}
303
Jing Huang5fbe25c2010-10-18 17:17:23 -0700304/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700305 * Host IOC function is being enabled, awaiting response from firmware.
306 * Semaphore is acquired.
307 */
308static void
309bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
310{
311 bfa_trc(ioc, event);
312
313 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700314 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700315 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
316 break;
317
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700318 case IOC_E_FAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700319 bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
320 break;
321
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322 case IOC_E_HWERROR:
323 bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
324 bfa_iocpf_initfail(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700325 break;
326
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700327 case IOC_E_DISABLE:
328 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
329 break;
330
331 case IOC_E_DETACH:
332 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
333 bfa_iocpf_stop(ioc);
334 break;
335
336 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700337 break;
338
339 default:
340 bfa_sm_fault(ioc, event);
341 }
342}
343
344
345static void
346bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
347{
348 bfa_ioc_timer_start(ioc);
349 bfa_ioc_send_getattr(ioc);
350}
351
Jing Huang5fbe25c2010-10-18 17:17:23 -0700352/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700353 * IOC configuration in progress. Timer is active.
354 */
355static void
356bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
357{
358 bfa_trc(ioc, event);
359
360 switch (event) {
361 case IOC_E_FWRSP_GETATTR:
362 bfa_ioc_timer_stop(ioc);
Jing Huang07b28382010-07-08 19:59:24 -0700363 bfa_ioc_check_attr_wwns(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700364 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
365 break;
366
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700367 case IOC_E_FAILED:
368 bfa_ioc_timer_stop(ioc);
369 bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
370 break;
371
Jing Huang7725ccf2009-09-23 17:46:15 -0700372 case IOC_E_HWERROR:
373 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374 /* fall through */
Jing Huang7725ccf2009-09-23 17:46:15 -0700375
376 case IOC_E_TIMEOUT:
377 bfa_fsm_set_state(ioc, bfa_ioc_sm_initfail);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700378 bfa_iocpf_getattrfail(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700379 break;
380
381 case IOC_E_DISABLE:
382 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700383 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
384 break;
385
386 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700387 break;
388
389 default:
390 bfa_sm_fault(ioc, event);
391 }
392}
393
394
395static void
396bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
397{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700398 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
399
Jing Huang7725ccf2009-09-23 17:46:15 -0700400 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
401 bfa_ioc_hb_monitor(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800402 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700403}
404
405static void
406bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
407{
408 bfa_trc(ioc, event);
409
410 switch (event) {
411 case IOC_E_ENABLE:
412 break;
413
414 case IOC_E_DISABLE:
415 bfa_ioc_hb_stop(ioc);
416 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
417 break;
418
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700419 case IOC_E_FAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700420 bfa_ioc_hb_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700421 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
422 break;
423
424 case IOC_E_HWERROR:
425 bfa_ioc_hb_stop(ioc);
426 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700427
428 case IOC_E_HBFAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700429 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
430 bfa_iocpf_fail(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700431 break;
432
433 default:
434 bfa_sm_fault(ioc, event);
435 }
436}
437
438
439static void
440bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
441{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700442 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
443 bfa_iocpf_disable(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800444 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700445}
446
Jing Huang5fbe25c2010-10-18 17:17:23 -0700447/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700448 * IOC is being disabled
449 */
450static void
451bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
452{
453 bfa_trc(ioc, event);
454
455 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700456 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800457 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
458 break;
459
460 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700461 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700462 * No state change. Will move to disabled state
463 * after iocpf sm completes failure processing and
464 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700465 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700466 bfa_iocpf_fail(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700467 break;
468
469 default:
470 bfa_sm_fault(ioc, event);
471 }
472}
473
Jing Huang5fbe25c2010-10-18 17:17:23 -0700474/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700475 * IOC disable completion entry.
476 */
477static void
478bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
479{
480 bfa_ioc_disable_comp(ioc);
481}
482
483static void
484bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
485{
486 bfa_trc(ioc, event);
487
488 switch (event) {
489 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700490 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700491 break;
492
493 case IOC_E_DISABLE:
494 ioc->cbfn->disable_cbfn(ioc->bfa);
495 break;
496
Jing Huang7725ccf2009-09-23 17:46:15 -0700497 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700498 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
499 bfa_iocpf_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700500 break;
501
502 default:
503 bfa_sm_fault(ioc, event);
504 }
505}
506
507
508static void
509bfa_ioc_sm_initfail_entry(struct bfa_ioc_s *ioc)
510{
511 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700512}
513
Jing Huang5fbe25c2010-10-18 17:17:23 -0700514/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700515 * Hardware initialization failed.
516 */
517static void
518bfa_ioc_sm_initfail(struct bfa_ioc_s *ioc, enum ioc_event event)
519{
520 bfa_trc(ioc, event);
521
522 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700523 case IOC_E_ENABLED:
524 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
525 break;
526
527 case IOC_E_FAILED:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700528 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700529 * Initialization failure during iocpf init retry.
530 */
531 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
532 break;
533
Jing Huang7725ccf2009-09-23 17:46:15 -0700534 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700535 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700536 break;
537
538 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700539 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
540 bfa_iocpf_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700541 break;
542
543 default:
544 bfa_sm_fault(ioc, event);
545 }
546}
547
548
549static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700550bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700551{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700552 struct list_head *qe;
553 struct bfa_ioc_hbfail_notify_s *notify;
554 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang7725ccf2009-09-23 17:46:15 -0700555
Jing Huang5fbe25c2010-10-18 17:17:23 -0700556 /*
Jing Huang7725ccf2009-09-23 17:46:15 -0700557 * Notify driver and common modules registered for notification.
558 */
559 ioc->cbfn->hbfail_cbfn(ioc->bfa);
560 list_for_each(qe, &ioc->hb_notify_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700561 notify = (struct bfa_ioc_hbfail_notify_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -0700562 notify->cbfn(notify->cbarg);
563 }
564
Jing Huang88166242010-12-09 17:11:53 -0800565 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700566 "Heart Beat of IOC has failed\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700567}
568
Jing Huang5fbe25c2010-10-18 17:17:23 -0700569/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700570 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700571 */
572static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700573bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700574{
575 bfa_trc(ioc, event);
576
577 switch (event) {
578
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700579 case IOC_E_FAILED:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700580 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700581 * Initialization failure during iocpf recovery.
582 * !!! Fall through !!!
583 */
Jing Huang7725ccf2009-09-23 17:46:15 -0700584 case IOC_E_ENABLE:
585 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
586 break;
587
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 case IOC_E_ENABLED:
589 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
590 break;
591
Jing Huang7725ccf2009-09-23 17:46:15 -0700592 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700593 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700594 break;
595
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800596 case IOC_E_HWERROR:
597 /*
598 * HB failure notification, ignore.
599 */
600 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700601 default:
602 bfa_sm_fault(ioc, event);
603 }
604}
605
606
607
Jing Huang5fbe25c2010-10-18 17:17:23 -0700608/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700609 * IOCPF State Machine
610 */
611
612
Jing Huang5fbe25c2010-10-18 17:17:23 -0700613/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700614 * Reset entry actions -- initialize state machine
615 */
616static void
617bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
618{
619 iocpf->retry_count = 0;
620 iocpf->auto_recover = bfa_auto_recover;
621}
622
Jing Huang5fbe25c2010-10-18 17:17:23 -0700623/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700624 * Beginning state. IOC is in reset state.
625 */
626static void
627bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
628{
629 struct bfa_ioc_s *ioc = iocpf->ioc;
630
631 bfa_trc(ioc, event);
632
633 switch (event) {
634 case IOCPF_E_ENABLE:
635 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
636 break;
637
638 case IOCPF_E_STOP:
639 break;
640
641 default:
642 bfa_sm_fault(ioc, event);
643 }
644}
645
Jing Huang5fbe25c2010-10-18 17:17:23 -0700646/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700647 * Semaphore should be acquired for version check.
648 */
649static void
650bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
651{
652 bfa_ioc_hw_sem_get(iocpf->ioc);
653}
654
Jing Huang5fbe25c2010-10-18 17:17:23 -0700655/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700656 * Awaiting h/w semaphore to continue with version check.
657 */
658static void
659bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
660{
661 struct bfa_ioc_s *ioc = iocpf->ioc;
662
663 bfa_trc(ioc, event);
664
665 switch (event) {
666 case IOCPF_E_SEMLOCKED:
667 if (bfa_ioc_firmware_lock(ioc)) {
668 iocpf->retry_count = 0;
669 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
670 } else {
671 bfa_ioc_hw_sem_release(ioc);
672 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
673 }
674 break;
675
676 case IOCPF_E_DISABLE:
677 bfa_ioc_hw_sem_get_cancel(ioc);
678 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
679 bfa_ioc_pf_disabled(ioc);
680 break;
681
682 case IOCPF_E_STOP:
683 bfa_ioc_hw_sem_get_cancel(ioc);
684 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
685 break;
686
687 default:
688 bfa_sm_fault(ioc, event);
689 }
690}
691
Jing Huang5fbe25c2010-10-18 17:17:23 -0700692/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700693 * Notify enable completion callback.
694 */
695static void
696bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
697{
698 /*
699 * Call only the first time sm enters fwmismatch state.
700 */
701 if (iocpf->retry_count == 0)
702 bfa_ioc_pf_fwmismatch(iocpf->ioc);
703
704 iocpf->retry_count++;
705 bfa_iocpf_timer_start(iocpf->ioc);
706}
707
Jing Huang5fbe25c2010-10-18 17:17:23 -0700708/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700709 * Awaiting firmware version match.
710 */
711static void
712bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
713{
714 struct bfa_ioc_s *ioc = iocpf->ioc;
715
716 bfa_trc(ioc, event);
717
718 switch (event) {
719 case IOCPF_E_TIMEOUT:
720 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
721 break;
722
723 case IOCPF_E_DISABLE:
724 bfa_iocpf_timer_stop(ioc);
725 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
726 bfa_ioc_pf_disabled(ioc);
727 break;
728
729 case IOCPF_E_STOP:
730 bfa_iocpf_timer_stop(ioc);
731 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
732 break;
733
734 default:
735 bfa_sm_fault(ioc, event);
736 }
737}
738
Jing Huang5fbe25c2010-10-18 17:17:23 -0700739/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700740 * Request for semaphore.
741 */
742static void
743bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
744{
745 bfa_ioc_hw_sem_get(iocpf->ioc);
746}
747
Jing Huang5fbe25c2010-10-18 17:17:23 -0700748/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700749 * Awaiting semaphore for h/w initialzation.
750 */
751static void
752bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
753{
754 struct bfa_ioc_s *ioc = iocpf->ioc;
755
756 bfa_trc(ioc, event);
757
758 switch (event) {
759 case IOCPF_E_SEMLOCKED:
760 iocpf->retry_count = 0;
761 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
762 break;
763
764 case IOCPF_E_DISABLE:
765 bfa_ioc_hw_sem_get_cancel(ioc);
766 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
767 break;
768
769 default:
770 bfa_sm_fault(ioc, event);
771 }
772}
773
774
775static void
776bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
777{
778 bfa_iocpf_timer_start(iocpf->ioc);
779 bfa_ioc_reset(iocpf->ioc, BFA_FALSE);
780}
781
Jing Huang5fbe25c2010-10-18 17:17:23 -0700782/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700783 * Hardware is being initialized. Interrupts are enabled.
784 * Holding hardware semaphore lock.
785 */
786static void
787bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
788{
789 struct bfa_ioc_s *ioc = iocpf->ioc;
790
791 bfa_trc(ioc, event);
792
793 switch (event) {
794 case IOCPF_E_FWREADY:
795 bfa_iocpf_timer_stop(ioc);
796 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
797 break;
798
799 case IOCPF_E_INITFAIL:
800 bfa_iocpf_timer_stop(ioc);
801 /*
802 * !!! fall through !!!
803 */
804
805 case IOCPF_E_TIMEOUT:
806 iocpf->retry_count++;
807 if (iocpf->retry_count < BFA_IOC_HWINIT_MAX) {
808 bfa_iocpf_timer_start(ioc);
809 bfa_ioc_reset(ioc, BFA_TRUE);
810 break;
811 }
812
813 bfa_ioc_hw_sem_release(ioc);
814 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
815
816 if (event == IOCPF_E_TIMEOUT)
817 bfa_ioc_pf_failed(ioc);
818 break;
819
820 case IOCPF_E_DISABLE:
821 bfa_ioc_hw_sem_release(ioc);
822 bfa_iocpf_timer_stop(ioc);
823 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
824 break;
825
826 default:
827 bfa_sm_fault(ioc, event);
828 }
829}
830
831
832static void
833bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
834{
835 bfa_iocpf_timer_start(iocpf->ioc);
836 bfa_ioc_send_enable(iocpf->ioc);
837}
838
Jing Huang5fbe25c2010-10-18 17:17:23 -0700839/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700840 * Host IOC function is being enabled, awaiting response from firmware.
841 * Semaphore is acquired.
842 */
843static void
844bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
845{
846 struct bfa_ioc_s *ioc = iocpf->ioc;
847
848 bfa_trc(ioc, event);
849
850 switch (event) {
851 case IOCPF_E_FWRSP_ENABLE:
852 bfa_iocpf_timer_stop(ioc);
853 bfa_ioc_hw_sem_release(ioc);
854 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
855 break;
856
857 case IOCPF_E_INITFAIL:
858 bfa_iocpf_timer_stop(ioc);
859 /*
860 * !!! fall through !!!
861 */
862
863 case IOCPF_E_TIMEOUT:
864 iocpf->retry_count++;
865 if (iocpf->retry_count < BFA_IOC_HWINIT_MAX) {
Jing Huang53440262010-10-18 17:12:29 -0700866 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700867 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
868 break;
869 }
870
871 bfa_ioc_hw_sem_release(ioc);
872 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
873
874 if (event == IOCPF_E_TIMEOUT)
875 bfa_ioc_pf_failed(ioc);
876 break;
877
878 case IOCPF_E_DISABLE:
879 bfa_iocpf_timer_stop(ioc);
880 bfa_ioc_hw_sem_release(ioc);
881 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
882 break;
883
884 case IOCPF_E_FWREADY:
885 bfa_ioc_send_enable(ioc);
886 break;
887
888 default:
889 bfa_sm_fault(ioc, event);
890 }
891}
892
893
894
895static void
896bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
897{
898 bfa_ioc_pf_enabled(iocpf->ioc);
899}
900
901static void
902bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
903{
904 struct bfa_ioc_s *ioc = iocpf->ioc;
905
906 bfa_trc(ioc, event);
907
908 switch (event) {
909 case IOCPF_E_DISABLE:
910 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
911 break;
912
913 case IOCPF_E_GETATTRFAIL:
914 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
915 break;
916
917 case IOCPF_E_FAIL:
918 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
919 break;
920
921 case IOCPF_E_FWREADY:
922 if (bfa_ioc_is_operational(ioc))
923 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
924 else
925 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
926
927 bfa_ioc_pf_failed(ioc);
928 break;
929
930 default:
931 bfa_sm_fault(ioc, event);
932 }
933}
934
935
936static void
937bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
938{
939 bfa_iocpf_timer_start(iocpf->ioc);
940 bfa_ioc_send_disable(iocpf->ioc);
941}
942
Jing Huang5fbe25c2010-10-18 17:17:23 -0700943/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700944 * IOC is being disabled
945 */
946static void
947bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
948{
949 struct bfa_ioc_s *ioc = iocpf->ioc;
950
951 bfa_trc(ioc, event);
952
953 switch (event) {
954 case IOCPF_E_FWRSP_DISABLE:
955 case IOCPF_E_FWREADY:
956 bfa_iocpf_timer_stop(ioc);
957 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
958 break;
959
960 case IOCPF_E_FAIL:
961 bfa_iocpf_timer_stop(ioc);
962 /*
963 * !!! fall through !!!
964 */
965
966 case IOCPF_E_TIMEOUT:
Jing Huang53440262010-10-18 17:12:29 -0700967 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700968 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
969 break;
970
971 case IOCPF_E_FWRSP_ENABLE:
972 break;
973
974 default:
975 bfa_sm_fault(ioc, event);
976 }
977}
978
Jing Huang5fbe25c2010-10-18 17:17:23 -0700979/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700980 * IOC disable completion entry.
981 */
982static void
983bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
984{
985 bfa_ioc_pf_disabled(iocpf->ioc);
986}
987
988static void
989bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
990{
991 struct bfa_ioc_s *ioc = iocpf->ioc;
992
993 bfa_trc(ioc, event);
994
995 switch (event) {
996 case IOCPF_E_ENABLE:
997 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
998 break;
999
1000 case IOCPF_E_STOP:
1001 bfa_ioc_firmware_unlock(ioc);
1002 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1003 break;
1004
1005 default:
1006 bfa_sm_fault(ioc, event);
1007 }
1008}
1009
1010
1011static void
1012bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1013{
1014 bfa_iocpf_timer_start(iocpf->ioc);
1015}
1016
Jing Huang5fbe25c2010-10-18 17:17:23 -07001017/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001018 * Hardware initialization failed.
1019 */
1020static void
1021bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1022{
1023 struct bfa_ioc_s *ioc = iocpf->ioc;
1024
1025 bfa_trc(ioc, event);
1026
1027 switch (event) {
1028 case IOCPF_E_DISABLE:
1029 bfa_iocpf_timer_stop(ioc);
1030 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1031 break;
1032
1033 case IOCPF_E_STOP:
1034 bfa_iocpf_timer_stop(ioc);
1035 bfa_ioc_firmware_unlock(ioc);
1036 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1037 break;
1038
1039 case IOCPF_E_TIMEOUT:
1040 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1041 break;
1042
1043 default:
1044 bfa_sm_fault(ioc, event);
1045 }
1046}
1047
1048
1049static void
1050bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1051{
Jing Huang5fbe25c2010-10-18 17:17:23 -07001052 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001053 * Mark IOC as failed in hardware and stop firmware.
1054 */
1055 bfa_ioc_lpu_stop(iocpf->ioc);
Jing Huang53440262010-10-18 17:12:29 -07001056 writel(BFI_IOC_FAIL, iocpf->ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001057
Jing Huang5fbe25c2010-10-18 17:17:23 -07001058 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001059 * Notify other functions on HB failure.
1060 */
1061 bfa_ioc_notify_hbfail(iocpf->ioc);
1062
Jing Huang5fbe25c2010-10-18 17:17:23 -07001063 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001064 * Flush any queued up mailbox requests.
1065 */
1066 bfa_ioc_mbox_hbfail(iocpf->ioc);
1067
1068 if (iocpf->auto_recover)
1069 bfa_iocpf_recovery_timer_start(iocpf->ioc);
1070}
1071
Jing Huang5fbe25c2010-10-18 17:17:23 -07001072/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001073 * IOC is in failed state.
1074 */
1075static void
1076bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1077{
1078 struct bfa_ioc_s *ioc = iocpf->ioc;
1079
1080 bfa_trc(ioc, event);
1081
1082 switch (event) {
1083 case IOCPF_E_DISABLE:
1084 if (iocpf->auto_recover)
1085 bfa_iocpf_timer_stop(ioc);
1086 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1087 break;
1088
1089 case IOCPF_E_TIMEOUT:
1090 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1091 break;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001092
Jing Huang7725ccf2009-09-23 17:46:15 -07001093 default:
1094 bfa_sm_fault(ioc, event);
1095 }
1096}
1097
1098
1099
Jing Huang5fbe25c2010-10-18 17:17:23 -07001100/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001101 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001102 */
1103
1104static void
1105bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1106{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001107 struct list_head *qe;
1108 struct bfa_ioc_hbfail_notify_s *notify;
Jing Huang7725ccf2009-09-23 17:46:15 -07001109
1110 ioc->cbfn->disable_cbfn(ioc->bfa);
1111
Jing Huang5fbe25c2010-10-18 17:17:23 -07001112 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001113 * Notify common modules registered for notification.
1114 */
1115 list_for_each(qe, &ioc->hb_notify_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001116 notify = (struct bfa_ioc_hbfail_notify_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001117 notify->cbfn(notify->cbarg);
1118 }
1119}
1120
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001121bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001122bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001123{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001124 u32 r32;
1125 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001126#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001127
Jing Huang53440262010-10-18 17:12:29 -07001128 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001129
1130 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001131 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001132 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001133 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001134 }
1135
1136 if (r32 == 0)
1137 return BFA_TRUE;
1138
Jing Huang7725ccf2009-09-23 17:46:15 -07001139 bfa_assert(cnt < BFA_SEM_SPINCNT);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001140 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001141}
1142
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001143void
Jing Huang53440262010-10-18 17:12:29 -07001144bfa_ioc_sem_release(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001145{
Jing Huang53440262010-10-18 17:12:29 -07001146 writel(1, sem_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001147}
1148
1149static void
1150bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1151{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001152 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001153
Jing Huang5fbe25c2010-10-18 17:17:23 -07001154 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001155 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001156 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001157 */
Jing Huang53440262010-10-18 17:12:29 -07001158 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001159 if (r32 == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001160 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001161 return;
1162 }
1163
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001164 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001165}
1166
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001167void
Jing Huang7725ccf2009-09-23 17:46:15 -07001168bfa_ioc_hw_sem_release(struct bfa_ioc_s *ioc)
1169{
Jing Huang53440262010-10-18 17:12:29 -07001170 writel(1, ioc->ioc_regs.ioc_sem_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001171}
1172
1173static void
1174bfa_ioc_hw_sem_get_cancel(struct bfa_ioc_s *ioc)
1175{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176 bfa_sem_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001177}
1178
Jing Huang5fbe25c2010-10-18 17:17:23 -07001179/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001180 * Initialize LPU local memory (aka secondary memory / SRAM)
1181 */
1182static void
1183bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1184{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001185 u32 pss_ctl;
1186 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001187#define PSS_LMEM_INIT_TIME 10000
1188
Jing Huang53440262010-10-18 17:12:29 -07001189 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001190 pss_ctl &= ~__PSS_LMEM_RESET;
1191 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001192
1193 /*
1194 * i2c workaround 12.5khz clock
1195 */
1196 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001197 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001198
Jing Huang5fbe25c2010-10-18 17:17:23 -07001199 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001200 * wait for memory initialization to be complete
1201 */
1202 i = 0;
1203 do {
Jing Huang53440262010-10-18 17:12:29 -07001204 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001205 i++;
1206 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1207
Jing Huang5fbe25c2010-10-18 17:17:23 -07001208 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001209 * If memory initialization is not successful, IOC timeout will catch
1210 * such failures.
1211 */
1212 bfa_assert(pss_ctl & __PSS_LMEM_INIT_DONE);
1213 bfa_trc(ioc, pss_ctl);
1214
1215 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001216 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001217}
1218
1219static void
1220bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1221{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001222 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001223
Jing Huang5fbe25c2010-10-18 17:17:23 -07001224 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001225 * Take processor out of reset.
1226 */
Jing Huang53440262010-10-18 17:12:29 -07001227 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001228 pss_ctl &= ~__PSS_LPU0_RESET;
1229
Jing Huang53440262010-10-18 17:12:29 -07001230 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001231}
1232
1233static void
1234bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1235{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001236 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001237
Jing Huang5fbe25c2010-10-18 17:17:23 -07001238 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001239 * Put processors in reset.
1240 */
Jing Huang53440262010-10-18 17:12:29 -07001241 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001242 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1243
Jing Huang53440262010-10-18 17:12:29 -07001244 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001245}
1246
Jing Huang5fbe25c2010-10-18 17:17:23 -07001247/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001248 * Get driver and firmware versions.
1249 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001250void
Jing Huang7725ccf2009-09-23 17:46:15 -07001251bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1252{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001253 u32 pgnum, pgoff;
1254 u32 loff = 0;
1255 int i;
1256 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001257
1258 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1259 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
Jing Huang53440262010-10-18 17:12:29 -07001260 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001261
1262 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1263 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001264 fwsig[i] =
1265 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001266 loff += sizeof(u32);
1267 }
1268}
1269
Jing Huang5fbe25c2010-10-18 17:17:23 -07001270/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001271 * Returns TRUE if same.
1272 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001273bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001274bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1275{
1276 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001277 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001278
Jing Huang293f82d2010-07-08 19:45:20 -07001279 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001280 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001281
1282 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1283 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1284 bfa_trc(ioc, i);
1285 bfa_trc(ioc, fwhdr->md5sum[i]);
1286 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1287 return BFA_FALSE;
1288 }
1289 }
1290
1291 bfa_trc(ioc, fwhdr->md5sum[0]);
1292 return BFA_TRUE;
1293}
1294
Jing Huang5fbe25c2010-10-18 17:17:23 -07001295/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001296 * Return true if current running version is valid. Firmware signature and
1297 * execution context (driver/bios) must match.
1298 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001299static bfa_boolean_t
1300bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001301{
1302 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1303
Jing Huang5fbe25c2010-10-18 17:17:23 -07001304 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001305 * If bios/efi boot (flash based) -- return true
1306 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001307 if (bfa_ioc_is_bios_optrom(ioc))
Jing Huang7725ccf2009-09-23 17:46:15 -07001308 return BFA_TRUE;
1309
1310 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001311 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001312 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001313
1314 if (fwhdr.signature != drv_fwhdr->signature) {
1315 bfa_trc(ioc, fwhdr.signature);
1316 bfa_trc(ioc, drv_fwhdr->signature);
1317 return BFA_FALSE;
1318 }
1319
Jing Huang53440262010-10-18 17:12:29 -07001320 if (swab32(fwhdr.param) != boot_env) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001321 bfa_trc(ioc, fwhdr.param);
1322 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001323 return BFA_FALSE;
1324 }
1325
1326 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1327}
1328
Jing Huang5fbe25c2010-10-18 17:17:23 -07001329/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001330 * Conditionally flush any pending message from firmware at start.
1331 */
1332static void
1333bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1334{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001335 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001336
Jing Huang53440262010-10-18 17:12:29 -07001337 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001338 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001339 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001340}
1341
1342
1343static void
1344bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1345{
1346 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001347 bfa_boolean_t fwvalid;
1348 u32 boot_type;
1349 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001350
Jing Huang53440262010-10-18 17:12:29 -07001351 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001352
1353 if (force)
1354 ioc_fwstate = BFI_IOC_UNINIT;
1355
1356 bfa_trc(ioc, ioc_fwstate);
1357
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001358 boot_type = BFI_BOOT_TYPE_NORMAL;
1359 boot_env = BFI_BOOT_LOADER_OS;
1360
Jing Huang5fbe25c2010-10-18 17:17:23 -07001361 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001362 * Flash based firmware boot BIOS env.
1363 */
1364 if (bfa_ioc_is_bios_optrom(ioc)) {
1365 boot_type = BFI_BOOT_TYPE_FLASH;
1366 boot_env = BFI_BOOT_LOADER_BIOS;
1367 }
1368
Jing Huang5fbe25c2010-10-18 17:17:23 -07001369 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001370 * Flash based firmware boot UEFI env.
1371 */
1372 if (bfa_ioc_is_uefi(ioc)) {
1373 boot_type = BFI_BOOT_TYPE_FLASH;
1374 boot_env = BFI_BOOT_LOADER_UEFI;
1375 }
1376
Jing Huang5fbe25c2010-10-18 17:17:23 -07001377 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001378 * check if firmware is valid
1379 */
1380 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001381 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001382
1383 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001384 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001385 return;
1386 }
1387
Jing Huang5fbe25c2010-10-18 17:17:23 -07001388 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001389 * If hardware initialization is in progress (initialized by other IOC),
1390 * just wait for an initialization completion interrupt.
1391 */
1392 if (ioc_fwstate == BFI_IOC_INITING) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001393 ioc->cbfn->reset_cbfn(ioc->bfa);
1394 return;
1395 }
1396
Jing Huang5fbe25c2010-10-18 17:17:23 -07001397 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001398 * If IOC function is disabled and firmware version is same,
1399 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001400 *
1401 * If option rom, IOC must not be in operational state. With
1402 * convergence, IOC will be in operational state when 2nd driver
1403 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001404 */
Jing Huang07b28382010-07-08 19:59:24 -07001405 if (ioc_fwstate == BFI_IOC_DISABLED ||
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001406 (!bfa_ioc_is_bios_optrom(ioc) && ioc_fwstate == BFI_IOC_OP)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001407
Jing Huang5fbe25c2010-10-18 17:17:23 -07001408 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001409 * When using MSI-X any pending firmware ready event should
1410 * be flushed. Otherwise MSI-X interrupts are not delivered.
1411 */
1412 bfa_ioc_msgflush(ioc);
1413 ioc->cbfn->reset_cbfn(ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001414 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001415 return;
1416 }
1417
Jing Huang5fbe25c2010-10-18 17:17:23 -07001418 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001419 * Initialize the h/w for any other states.
1420 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001421 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001422}
1423
1424static void
1425bfa_ioc_timeout(void *ioc_arg)
1426{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001427 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001428
1429 bfa_trc(ioc, 0);
1430 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1431}
1432
1433void
1434bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1435{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001436 u32 *msgp = (u32 *) ioc_msg;
1437 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001438
1439 bfa_trc(ioc, msgp[0]);
1440 bfa_trc(ioc, len);
1441
1442 bfa_assert(len <= BFI_IOC_MSGLEN_MAX);
1443
1444 /*
1445 * first write msg to mailbox registers
1446 */
1447 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001448 writel(cpu_to_le32(msgp[i]),
1449 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001450
1451 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001452 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001453
1454 /*
1455 * write 1 to mailbox CMD to trigger LPU event
1456 */
Jing Huang53440262010-10-18 17:12:29 -07001457 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1458 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001459}
1460
1461static void
1462bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1463{
1464 struct bfi_ioc_ctrl_req_s enable_req;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001465 struct bfa_timeval_s tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001466
1467 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1468 bfa_ioc_portid(ioc));
1469 enable_req.ioc_class = ioc->ioc_mc;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001470 bfa_os_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001471 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001472 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1473}
1474
1475static void
1476bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1477{
1478 struct bfi_ioc_ctrl_req_s disable_req;
1479
1480 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1481 bfa_ioc_portid(ioc));
1482 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1483}
1484
1485static void
1486bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1487{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001488 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001489
1490 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1491 bfa_ioc_portid(ioc));
1492 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1493 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1494}
1495
1496static void
1497bfa_ioc_hb_check(void *cbarg)
1498{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001499 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001500 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001501
Jing Huang53440262010-10-18 17:12:29 -07001502 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001503 if (ioc->hb_count == hb_count) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001504 printk(KERN_CRIT "Firmware heartbeat failure at %d", hb_count);
Jing Huang7725ccf2009-09-23 17:46:15 -07001505 bfa_ioc_recover(ioc);
1506 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001507 } else {
1508 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001509 }
1510
1511 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001512 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001513}
1514
1515static void
1516bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1517{
Jing Huang53440262010-10-18 17:12:29 -07001518 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001519 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001520}
1521
1522static void
1523bfa_ioc_hb_stop(struct bfa_ioc_s *ioc)
1524{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001525 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001526}
1527
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001528
Jing Huang5fbe25c2010-10-18 17:17:23 -07001529/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001530 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001531 */
1532static void
1533bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001534 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001535{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001536 u32 *fwimg;
1537 u32 pgnum, pgoff;
1538 u32 loff = 0;
1539 u32 chunkno = 0;
1540 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001541
Jing Huang5fbe25c2010-10-18 17:17:23 -07001542 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001543 * Initialize LMEM first before code download
1544 */
1545 bfa_ioc_lmem_init(ioc);
1546
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001547 bfa_trc(ioc, bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
1548 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001549
1550 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
1551 pgoff = bfa_ioc_smem_pgoff(ioc, loff);
1552
Jing Huang53440262010-10-18 17:12:29 -07001553 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001554
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001555 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001556
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001557 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1558 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001559 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001560 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001561 }
1562
Jing Huang5fbe25c2010-10-18 17:17:23 -07001563 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001564 * write smem
1565 */
1566 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001567 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001568
1569 loff += sizeof(u32);
1570
Jing Huang5fbe25c2010-10-18 17:17:23 -07001571 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001572 * handle page offset wrap around
1573 */
1574 loff = PSS_SMEM_PGOFF(loff);
1575 if (loff == 0) {
1576 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001577 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001578 }
1579 }
1580
Jing Huang53440262010-10-18 17:12:29 -07001581 writel(bfa_ioc_smem_pgnum(ioc, 0), ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001582
1583 /*
1584 * Set boot type and boot param at the end.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001585 */
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001586 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001587 swab32(boot_type));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001588 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001589 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001590}
1591
1592static void
1593bfa_ioc_reset(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1594{
1595 bfa_ioc_hwinit(ioc, force);
1596}
1597
Jing Huang5fbe25c2010-10-18 17:17:23 -07001598/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001599 * Update BFA configuration from firmware configuration.
1600 */
1601static void
1602bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1603{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001604 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001605
Jing Huangba816ea2010-10-18 17:10:50 -07001606 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1607 attr->card_type = be32_to_cpu(attr->card_type);
1608 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Jing Huang7725ccf2009-09-23 17:46:15 -07001609
1610 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1611}
1612
Jing Huang5fbe25c2010-10-18 17:17:23 -07001613/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001614 * Attach time initialization of mbox logic.
1615 */
1616static void
1617bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1618{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001619 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1620 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001621
1622 INIT_LIST_HEAD(&mod->cmd_q);
1623 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1624 mod->mbhdlr[mc].cbfn = NULL;
1625 mod->mbhdlr[mc].cbarg = ioc->bfa;
1626 }
1627}
1628
Jing Huang5fbe25c2010-10-18 17:17:23 -07001629/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001630 * Mbox poll timer -- restarts any pending mailbox requests.
1631 */
1632static void
1633bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1634{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001635 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1636 struct bfa_mbox_cmd_s *cmd;
1637 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001638
Jing Huang5fbe25c2010-10-18 17:17:23 -07001639 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001640 * If no command pending, do nothing
1641 */
1642 if (list_empty(&mod->cmd_q))
1643 return;
1644
Jing Huang5fbe25c2010-10-18 17:17:23 -07001645 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001646 * If previous command is not yet fetched by firmware, do nothing
1647 */
Jing Huang53440262010-10-18 17:12:29 -07001648 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001649 if (stat)
1650 return;
1651
Jing Huang5fbe25c2010-10-18 17:17:23 -07001652 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001653 * Enqueue command to firmware.
1654 */
1655 bfa_q_deq(&mod->cmd_q, &cmd);
1656 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1657}
1658
Jing Huang5fbe25c2010-10-18 17:17:23 -07001659/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001660 * Cleanup any pending requests.
1661 */
1662static void
1663bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
1664{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001665 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1666 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001667
1668 while (!list_empty(&mod->cmd_q))
1669 bfa_q_deq(&mod->cmd_q, &cmd);
1670}
1671
Jing Huang5fbe25c2010-10-18 17:17:23 -07001672/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001673 * Read data from SMEM to host through PCI memmap
1674 *
1675 * @param[in] ioc memory for IOC
1676 * @param[in] tbuf app memory to store data from smem
1677 * @param[in] soff smem offset
1678 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001679 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001680static bfa_status_t
1681bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1682{
Maggie50444a32010-11-29 18:26:32 -08001683 u32 pgnum, loff;
1684 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001685 int i, len;
1686 u32 *buf = tbuf;
1687
1688 pgnum = bfa_ioc_smem_pgnum(ioc, soff);
1689 loff = bfa_ioc_smem_pgoff(ioc, soff);
1690 bfa_trc(ioc, pgnum);
1691 bfa_trc(ioc, loff);
1692 bfa_trc(ioc, sz);
1693
1694 /*
1695 * Hold semaphore to serialize pll init and fwtrc.
1696 */
1697 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1698 bfa_trc(ioc, 0);
1699 return BFA_STATUS_FAILED;
1700 }
1701
Jing Huang53440262010-10-18 17:12:29 -07001702 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001703
1704 len = sz/sizeof(u32);
1705 bfa_trc(ioc, len);
1706 for (i = 0; i < len; i++) {
1707 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001708 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001709 loff += sizeof(u32);
1710
Jing Huang5fbe25c2010-10-18 17:17:23 -07001711 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001712 * handle page offset wrap around
1713 */
1714 loff = PSS_SMEM_PGOFF(loff);
1715 if (loff == 0) {
1716 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001717 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001718 }
1719 }
Jing Huang53440262010-10-18 17:12:29 -07001720 writel(bfa_ioc_smem_pgnum(ioc, 0), ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001721 /*
1722 * release semaphore.
1723 */
1724 bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
1725
1726 bfa_trc(ioc, pgnum);
1727 return BFA_STATUS_OK;
1728}
1729
Jing Huang5fbe25c2010-10-18 17:17:23 -07001730/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001731 * Clear SMEM data from host through PCI memmap
1732 *
1733 * @param[in] ioc memory for IOC
1734 * @param[in] soff smem offset
1735 * @param[in] sz size of smem in bytes
1736 */
1737static bfa_status_t
1738bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1739{
1740 int i, len;
1741 u32 pgnum, loff;
1742
1743 pgnum = bfa_ioc_smem_pgnum(ioc, soff);
1744 loff = bfa_ioc_smem_pgoff(ioc, soff);
1745 bfa_trc(ioc, pgnum);
1746 bfa_trc(ioc, loff);
1747 bfa_trc(ioc, sz);
1748
1749 /*
1750 * Hold semaphore to serialize pll init and fwtrc.
1751 */
1752 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1753 bfa_trc(ioc, 0);
1754 return BFA_STATUS_FAILED;
1755 }
1756
Jing Huang53440262010-10-18 17:12:29 -07001757 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001758
1759 len = sz/sizeof(u32); /* len in words */
1760 bfa_trc(ioc, len);
1761 for (i = 0; i < len; i++) {
1762 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1763 loff += sizeof(u32);
1764
Jing Huang5fbe25c2010-10-18 17:17:23 -07001765 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001766 * handle page offset wrap around
1767 */
1768 loff = PSS_SMEM_PGOFF(loff);
1769 if (loff == 0) {
1770 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001771 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001772 }
1773 }
Jing Huang53440262010-10-18 17:12:29 -07001774 writel(bfa_ioc_smem_pgnum(ioc, 0), ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001775
1776 /*
1777 * release semaphore.
1778 */
1779 bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
1780 bfa_trc(ioc, pgnum);
1781 return BFA_STATUS_OK;
1782}
1783
Jing Huang5fbe25c2010-10-18 17:17:23 -07001784/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001785 * hal iocpf to ioc interface
1786 */
1787static void
1788bfa_ioc_pf_enabled(struct bfa_ioc_s *ioc)
1789{
1790 bfa_fsm_send_event(ioc, IOC_E_ENABLED);
1791}
1792
1793static void
1794bfa_ioc_pf_disabled(struct bfa_ioc_s *ioc)
1795{
1796 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
1797}
1798
1799static void
1800bfa_ioc_pf_failed(struct bfa_ioc_s *ioc)
1801{
1802 bfa_fsm_send_event(ioc, IOC_E_FAILED);
1803}
1804
1805static void
1806bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1807{
1808 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001809 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001810 * Provide enable completion callback.
1811 */
1812 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001813 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001814 "Running firmware version is incompatible "
1815 "with the driver version\n");
1816}
1817
1818
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001819bfa_status_t
1820bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1821{
1822
1823 /*
1824 * Hold semaphore so that nobody can access the chip during init.
1825 */
1826 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1827
1828 bfa_ioc_pll_init_asic(ioc);
1829
1830 ioc->pllinit = BFA_TRUE;
1831 /*
1832 * release semaphore.
1833 */
1834 bfa_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
1835
1836 return BFA_STATUS_OK;
1837}
Jing Huang7725ccf2009-09-23 17:46:15 -07001838
Jing Huang5fbe25c2010-10-18 17:17:23 -07001839/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001840 * Interface used by diag module to do firmware boot with memory test
1841 * as the entry vector.
1842 */
1843void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001844bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001845{
Jing Huang53440262010-10-18 17:12:29 -07001846 void __iomem *rb;
Jing Huang7725ccf2009-09-23 17:46:15 -07001847
1848 bfa_ioc_stats(ioc, ioc_boots);
1849
1850 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1851 return;
1852
Jing Huang5fbe25c2010-10-18 17:17:23 -07001853 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001854 * Initialize IOC state of all functions on a chip reset.
1855 */
1856 rb = ioc->pcidev.pci_bar_kva;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001857 if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
Jing Huang53440262010-10-18 17:12:29 -07001858 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
1859 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001860 } else {
Jing Huang53440262010-10-18 17:12:29 -07001861 writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
1862 writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001863 }
1864
Jing Huang07b28382010-07-08 19:59:24 -07001865 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001866 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001867
Jing Huang5fbe25c2010-10-18 17:17:23 -07001868 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001869 * Enable interrupts just before starting LPU
1870 */
1871 ioc->cbfn->reset_cbfn(ioc->bfa);
1872 bfa_ioc_lpu_start(ioc);
1873}
1874
Jing Huang5fbe25c2010-10-18 17:17:23 -07001875/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001876 * Enable/disable IOC failure auto recovery.
1877 */
1878void
1879bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
1880{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08001881 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07001882}
1883
1884
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001885
Jing Huang7725ccf2009-09-23 17:46:15 -07001886bfa_boolean_t
1887bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1888{
1889 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
1890}
1891
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001892bfa_boolean_t
1893bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
1894{
Jing Huang53440262010-10-18 17:12:29 -07001895 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001896
1897 return ((r32 != BFI_IOC_UNINIT) &&
1898 (r32 != BFI_IOC_INITING) &&
1899 (r32 != BFI_IOC_MEMTEST));
1900}
1901
Jing Huang7725ccf2009-09-23 17:46:15 -07001902void
1903bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
1904{
Maggie50444a32010-11-29 18:26:32 -08001905 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001906 u32 r32;
1907 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001908
Jing Huang5fbe25c2010-10-18 17:17:23 -07001909 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001910 * read the MBOX msg
1911 */
1912 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1913 i++) {
Jing Huang53440262010-10-18 17:12:29 -07001914 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07001915 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07001916 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07001917 }
1918
Jing Huang5fbe25c2010-10-18 17:17:23 -07001919 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001920 * turn off mailbox interrupt by clearing mailbox status
1921 */
Jing Huang53440262010-10-18 17:12:29 -07001922 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1923 readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001924}
1925
1926void
1927bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
1928{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001929 union bfi_ioc_i2h_msg_u *msg;
1930 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07001931
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001932 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07001933
1934 bfa_ioc_stats(ioc, ioc_isrs);
1935
1936 switch (msg->mh.msg_id) {
1937 case BFI_IOC_I2H_HBEAT:
1938 break;
1939
1940 case BFI_IOC_I2H_READY_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001941 bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001942 break;
1943
1944 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001945 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001946 break;
1947
1948 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001949 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001950 break;
1951
1952 case BFI_IOC_I2H_GETATTR_REPLY:
1953 bfa_ioc_getattr_reply(ioc);
1954 break;
1955
1956 default:
1957 bfa_trc(ioc, msg->mh.msg_id);
1958 bfa_assert(0);
1959 }
1960}
1961
Jing Huang5fbe25c2010-10-18 17:17:23 -07001962/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001963 * IOC attach time initialization and setup.
1964 *
1965 * @param[in] ioc memory for IOC
1966 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001967 */
1968void
1969bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001970 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07001971{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001972 ioc->bfa = bfa;
1973 ioc->cbfn = cbfn;
1974 ioc->timer_mod = timer_mod;
1975 ioc->fcmode = BFA_FALSE;
1976 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001977 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001978 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001979
1980 bfa_ioc_mbox_attach(ioc);
1981 INIT_LIST_HEAD(&ioc->hb_notify_q);
1982
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001983 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
1984 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07001985}
1986
Jing Huang5fbe25c2010-10-18 17:17:23 -07001987/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001988 * Driver detach time IOC cleanup.
1989 */
1990void
1991bfa_ioc_detach(struct bfa_ioc_s *ioc)
1992{
1993 bfa_fsm_send_event(ioc, IOC_E_DETACH);
1994}
1995
Jing Huang5fbe25c2010-10-18 17:17:23 -07001996/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001997 * Setup IOC PCI properties.
1998 *
1999 * @param[in] pcidev PCI device information for this IOC
2000 */
2001void
2002bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
2003 enum bfi_mclass mc)
2004{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002005 ioc->ioc_mc = mc;
2006 ioc->pcidev = *pcidev;
2007 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
2008 ioc->cna = ioc->ctdev && !ioc->fcmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07002009
Jing Huang5fbe25c2010-10-18 17:17:23 -07002010 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002011 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2012 */
2013 if (ioc->ctdev)
2014 bfa_ioc_set_ct_hwif(ioc);
2015 else
2016 bfa_ioc_set_cb_hwif(ioc);
2017
Jing Huang7725ccf2009-09-23 17:46:15 -07002018 bfa_ioc_map_port(ioc);
2019 bfa_ioc_reg_init(ioc);
2020}
2021
Jing Huang5fbe25c2010-10-18 17:17:23 -07002022/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002023 * Initialize IOC dma memory
2024 *
2025 * @param[in] dm_kva kernel virtual address of IOC dma memory
2026 * @param[in] dm_pa physical address of IOC dma memory
2027 */
2028void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002029bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002030{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002031 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002032 * dma memory for firmware attribute
2033 */
2034 ioc->attr_dma.kva = dm_kva;
2035 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002036 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002037}
2038
Jing Huang5fbe25c2010-10-18 17:17:23 -07002039/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002040 * Return size of dma memory required.
2041 */
2042u32
2043bfa_ioc_meminfo(void)
2044{
2045 return BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ);
2046}
2047
2048void
2049bfa_ioc_enable(struct bfa_ioc_s *ioc)
2050{
2051 bfa_ioc_stats(ioc, ioc_enables);
2052 ioc->dbg_fwsave_once = BFA_TRUE;
2053
2054 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2055}
2056
2057void
2058bfa_ioc_disable(struct bfa_ioc_s *ioc)
2059{
2060 bfa_ioc_stats(ioc, ioc_disables);
2061 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2062}
2063
Jing Huang5fbe25c2010-10-18 17:17:23 -07002064/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002065 * Returns memory required for saving firmware trace in case of crash.
2066 * Driver must call this interface to allocate memory required for
2067 * automatic saving of firmware trace. Driver should call
2068 * bfa_ioc_debug_memclaim() right after bfa_ioc_attach() to setup this
2069 * trace memory.
2070 */
2071int
2072bfa_ioc_debug_trcsz(bfa_boolean_t auto_recover)
2073{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002074 return (auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07002075}
2076
Jing Huang5fbe25c2010-10-18 17:17:23 -07002077/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002078 * Initialize memory for saving firmware trace. Driver must initialize
2079 * trace memory before call bfa_ioc_enable().
2080 */
2081void
2082bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2083{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002084 ioc->dbg_fwsave = dbg_fwsave;
2085 ioc->dbg_fwsave_len = bfa_ioc_debug_trcsz(ioc->iocpf.auto_recover);
Jing Huang7725ccf2009-09-23 17:46:15 -07002086}
2087
2088u32
2089bfa_ioc_smem_pgnum(struct bfa_ioc_s *ioc, u32 fmaddr)
2090{
2091 return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
2092}
2093
2094u32
2095bfa_ioc_smem_pgoff(struct bfa_ioc_s *ioc, u32 fmaddr)
2096{
2097 return PSS_SMEM_PGOFF(fmaddr);
2098}
2099
Jing Huang5fbe25c2010-10-18 17:17:23 -07002100/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002101 * Register mailbox message handler functions
2102 *
2103 * @param[in] ioc IOC instance
2104 * @param[in] mcfuncs message class handler functions
2105 */
2106void
2107bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2108{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002109 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2110 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002111
2112 for (mc = 0; mc < BFI_MC_MAX; mc++)
2113 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2114}
2115
Jing Huang5fbe25c2010-10-18 17:17:23 -07002116/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002117 * Register mailbox message handler function, to be called by common modules
2118 */
2119void
2120bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2121 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2122{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002123 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002124
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002125 mod->mbhdlr[mc].cbfn = cbfn;
2126 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002127}
2128
Jing Huang5fbe25c2010-10-18 17:17:23 -07002129/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002130 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2131 * Responsibility of caller to serialize
2132 *
2133 * @param[in] ioc IOC instance
2134 * @param[i] cmd Mailbox command
2135 */
2136void
2137bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2138{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002139 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2140 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002141
Jing Huang5fbe25c2010-10-18 17:17:23 -07002142 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002143 * If a previous command is pending, queue new command
2144 */
2145 if (!list_empty(&mod->cmd_q)) {
2146 list_add_tail(&cmd->qe, &mod->cmd_q);
2147 return;
2148 }
2149
Jing Huang5fbe25c2010-10-18 17:17:23 -07002150 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002151 * If mailbox is busy, queue command for poll timer
2152 */
Jing Huang53440262010-10-18 17:12:29 -07002153 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002154 if (stat) {
2155 list_add_tail(&cmd->qe, &mod->cmd_q);
2156 return;
2157 }
2158
Jing Huang5fbe25c2010-10-18 17:17:23 -07002159 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002160 * mailbox is free -- queue command to firmware
2161 */
2162 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2163}
2164
Jing Huang5fbe25c2010-10-18 17:17:23 -07002165/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002166 * Handle mailbox interrupts
2167 */
2168void
2169bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2170{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002171 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2172 struct bfi_mbmsg_s m;
2173 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002174
2175 bfa_ioc_msgget(ioc, &m);
2176
Jing Huang5fbe25c2010-10-18 17:17:23 -07002177 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002178 * Treat IOC message class as special.
2179 */
2180 mc = m.mh.msg_class;
2181 if (mc == BFI_MC_IOC) {
2182 bfa_ioc_isr(ioc, &m);
2183 return;
2184 }
2185
2186 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2187 return;
2188
2189 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2190}
2191
2192void
2193bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2194{
2195 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2196}
2197
Jing Huanged969322010-07-08 19:45:56 -07002198void
2199bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2200{
2201 ioc->fcmode = BFA_TRUE;
2202 ioc->port_id = bfa_ioc_pcifn(ioc);
2203}
2204
Jing Huang5fbe25c2010-10-18 17:17:23 -07002205/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002206 * return true if IOC is disabled
2207 */
2208bfa_boolean_t
2209bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2210{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002211 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2212 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002213}
2214
Jing Huang5fbe25c2010-10-18 17:17:23 -07002215/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002216 * return true if IOC firmware is different.
2217 */
2218bfa_boolean_t
2219bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2220{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002221 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2222 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2223 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002224}
2225
2226#define bfa_ioc_state_disabled(__sm) \
2227 (((__sm) == BFI_IOC_UNINIT) || \
2228 ((__sm) == BFI_IOC_INITING) || \
2229 ((__sm) == BFI_IOC_HWINIT) || \
2230 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002231 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002232 ((__sm) == BFI_IOC_CFG_DISABLED))
2233
Jing Huang5fbe25c2010-10-18 17:17:23 -07002234/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002235 * Check if adapter is disabled -- both IOCs should be in a disabled
2236 * state.
2237 */
2238bfa_boolean_t
2239bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2240{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002241 u32 ioc_state;
Jing Huang53440262010-10-18 17:12:29 -07002242 void __iomem *rb = ioc->pcidev.pci_bar_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002243
2244 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2245 return BFA_FALSE;
2246
Jing Huang53440262010-10-18 17:12:29 -07002247 ioc_state = readl(rb + BFA_IOC0_STATE_REG);
Jing Huang7725ccf2009-09-23 17:46:15 -07002248 if (!bfa_ioc_state_disabled(ioc_state))
2249 return BFA_FALSE;
2250
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002251 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Jing Huang53440262010-10-18 17:12:29 -07002252 ioc_state = readl(rb + BFA_IOC1_STATE_REG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002253 if (!bfa_ioc_state_disabled(ioc_state))
2254 return BFA_FALSE;
2255 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002256
2257 return BFA_TRUE;
2258}
2259
Jing Huang5fbe25c2010-10-18 17:17:23 -07002260/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002261 * Add to IOC heartbeat failure notification queue. To be used by common
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002262 * modules such as cee, port, diag.
Jing Huang7725ccf2009-09-23 17:46:15 -07002263 */
2264void
2265bfa_ioc_hbfail_register(struct bfa_ioc_s *ioc,
2266 struct bfa_ioc_hbfail_notify_s *notify)
2267{
2268 list_add_tail(&notify->qe, &ioc->hb_notify_q);
2269}
2270
2271#define BFA_MFG_NAME "Brocade"
2272void
2273bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2274 struct bfa_adapter_attr_s *ad_attr)
2275{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002276 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002277
2278 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002279
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002280 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2281 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2282 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2283 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002284 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002285 sizeof(struct bfa_mfg_vpd_s));
2286
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002287 ad_attr->nports = bfa_ioc_get_nports(ioc);
2288 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002289
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002290 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2291 /* For now, model descr uses same model string */
2292 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002293
Jing Huanged969322010-07-08 19:45:56 -07002294 ad_attr->card_type = ioc_attr->card_type;
2295 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2296
Jing Huang7725ccf2009-09-23 17:46:15 -07002297 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2298 ad_attr->prototype = 1;
2299 else
2300 ad_attr->prototype = 0;
2301
Jing Huang7725ccf2009-09-23 17:46:15 -07002302 ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002303 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002304
2305 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2306 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2307 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2308 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002309
2310 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002311
2312 ad_attr->cna_capable = ioc->cna;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002313 ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna;
Jing Huang7725ccf2009-09-23 17:46:15 -07002314}
2315
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002316enum bfa_ioc_type_e
2317bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2318{
2319 if (!ioc->ctdev || ioc->fcmode)
2320 return BFA_IOC_TYPE_FC;
2321 else if (ioc->ioc_mc == BFI_MC_IOCFC)
2322 return BFA_IOC_TYPE_FCoE;
2323 else if (ioc->ioc_mc == BFI_MC_LL)
2324 return BFA_IOC_TYPE_LL;
2325 else {
2326 bfa_assert(ioc->ioc_mc == BFI_MC_LL);
2327 return BFA_IOC_TYPE_LL;
2328 }
2329}
2330
Jing Huang7725ccf2009-09-23 17:46:15 -07002331void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002332bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2333{
Jing Huang6a18b162010-10-18 17:08:54 -07002334 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2335 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002336 (void *)ioc->attr->brcd_serialnum,
2337 BFA_ADAPTER_SERIAL_NUM_LEN);
2338}
2339
2340void
2341bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2342{
Jing Huang6a18b162010-10-18 17:08:54 -07002343 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2344 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002345}
2346
2347void
2348bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2349{
2350 bfa_assert(chip_rev);
2351
Jing Huang6a18b162010-10-18 17:08:54 -07002352 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002353
2354 chip_rev[0] = 'R';
2355 chip_rev[1] = 'e';
2356 chip_rev[2] = 'v';
2357 chip_rev[3] = '-';
2358 chip_rev[4] = ioc->attr->asic_rev;
2359 chip_rev[5] = '\0';
2360}
2361
2362void
2363bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2364{
Jing Huang6a18b162010-10-18 17:08:54 -07002365 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2366 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002367 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002368}
2369
2370void
2371bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2372{
Jing Huang6a18b162010-10-18 17:08:54 -07002373 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2374 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002375}
2376
2377void
2378bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2379{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002380 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002381
2382 bfa_assert(model);
Jing Huang6a18b162010-10-18 17:08:54 -07002383 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002384
2385 ioc_attr = ioc->attr;
2386
Jing Huang5fbe25c2010-10-18 17:17:23 -07002387 /*
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002388 * model name
2389 */
Jing Huang6a18b162010-10-18 17:08:54 -07002390 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002391 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002392}
2393
2394enum bfa_ioc_state
2395bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2396{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002397 enum bfa_iocpf_state iocpf_st;
2398 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2399
2400 if (ioc_st == BFA_IOC_ENABLING ||
2401 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2402
2403 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2404
2405 switch (iocpf_st) {
2406 case BFA_IOCPF_SEMWAIT:
2407 ioc_st = BFA_IOC_SEMWAIT;
2408 break;
2409
2410 case BFA_IOCPF_HWINIT:
2411 ioc_st = BFA_IOC_HWINIT;
2412 break;
2413
2414 case BFA_IOCPF_FWMISMATCH:
2415 ioc_st = BFA_IOC_FWMISMATCH;
2416 break;
2417
2418 case BFA_IOCPF_FAIL:
2419 ioc_st = BFA_IOC_FAIL;
2420 break;
2421
2422 case BFA_IOCPF_INITFAIL:
2423 ioc_st = BFA_IOC_INITFAIL;
2424 break;
2425
2426 default:
2427 break;
2428 }
2429 }
2430
2431 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002432}
2433
2434void
Jing Huang7725ccf2009-09-23 17:46:15 -07002435bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2436{
Jing Huang6a18b162010-10-18 17:08:54 -07002437 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002438
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002439 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002440 ioc_attr->port_id = ioc->port_id;
2441
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002442 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002443
2444 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2445
2446 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2447 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002448 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002449}
2450
Jing Huang7725ccf2009-09-23 17:46:15 -07002451wwn_t
2452bfa_ioc_get_pwwn(struct bfa_ioc_s *ioc)
2453{
Jing Huang15b64a82010-07-08 19:48:12 -07002454 return ioc->attr->pwwn;
Jing Huang7725ccf2009-09-23 17:46:15 -07002455}
2456
2457wwn_t
2458bfa_ioc_get_nwwn(struct bfa_ioc_s *ioc)
2459{
Jing Huang15b64a82010-07-08 19:48:12 -07002460 return ioc->attr->nwwn;
Jing Huang7725ccf2009-09-23 17:46:15 -07002461}
2462
Jing Huang7725ccf2009-09-23 17:46:15 -07002463u64
2464bfa_ioc_get_adid(struct bfa_ioc_s *ioc)
2465{
Jing Huang15b64a82010-07-08 19:48:12 -07002466 return ioc->attr->mfg_pwwn;
Jing Huang7725ccf2009-09-23 17:46:15 -07002467}
2468
2469mac_t
2470bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2471{
Jing Huang15b64a82010-07-08 19:48:12 -07002472 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002473 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002474 */
2475 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002476 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002477 else
2478 return ioc->attr->mac;
2479}
2480
2481wwn_t
2482bfa_ioc_get_mfg_pwwn(struct bfa_ioc_s *ioc)
2483{
2484 return ioc->attr->mfg_pwwn;
2485}
2486
2487wwn_t
2488bfa_ioc_get_mfg_nwwn(struct bfa_ioc_s *ioc)
2489{
2490 return ioc->attr->mfg_nwwn;
2491}
2492
2493mac_t
2494bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2495{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002496 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002497
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002498 m = ioc->attr->mfg_mac;
2499 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2500 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2501 else
2502 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2503 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002504
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002505 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002506}
2507
Jing Huang7725ccf2009-09-23 17:46:15 -07002508bfa_boolean_t
2509bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2510{
Jing Huang293f82d2010-07-08 19:45:20 -07002511 return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07002512}
2513
Jing Huang5fbe25c2010-10-18 17:17:23 -07002514/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002515 * Retrieve saved firmware trace from a prior IOC failure.
2516 */
2517bfa_status_t
2518bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2519{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002520 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002521
2522 if (ioc->dbg_fwsave_len == 0)
2523 return BFA_STATUS_ENOFSAVE;
2524
2525 tlen = *trclen;
2526 if (tlen > ioc->dbg_fwsave_len)
2527 tlen = ioc->dbg_fwsave_len;
2528
Jing Huang6a18b162010-10-18 17:08:54 -07002529 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002530 *trclen = tlen;
2531 return BFA_STATUS_OK;
2532}
2533
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002534
Jing Huang5fbe25c2010-10-18 17:17:23 -07002535/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002536 * Retrieve saved firmware trace from a prior IOC failure.
2537 */
2538bfa_status_t
2539bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2540{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002541 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2542 int tlen;
2543 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002544
2545 bfa_trc(ioc, *trclen);
2546
Jing Huang7725ccf2009-09-23 17:46:15 -07002547 tlen = *trclen;
2548 if (tlen > BFA_DBG_FWTRC_LEN)
2549 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002550
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002551 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2552 *trclen = tlen;
2553 return status;
2554}
Jing Huang7725ccf2009-09-23 17:46:15 -07002555
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002556static void
2557bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2558{
2559 struct bfa_mbox_cmd_s cmd;
2560 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002561
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002562 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2563 bfa_ioc_portid(ioc));
2564 req->ioc_class = ioc->ioc_mc;
2565 bfa_ioc_mbox_queue(ioc, &cmd);
2566}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002567
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002568static void
2569bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2570{
2571 u32 fwsync_iter = 1000;
2572
2573 bfa_ioc_send_fwsync(ioc);
2574
Jing Huang5fbe25c2010-10-18 17:17:23 -07002575 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002576 * After sending a fw sync mbox command wait for it to
2577 * take effect. We will not wait for a response because
2578 * 1. fw_sync mbox cmd doesn't have a response.
2579 * 2. Even if we implement that, interrupts might not
2580 * be enabled when we call this function.
2581 * So, just keep checking if any mbox cmd is pending, and
2582 * after waiting for a reasonable amount of time, go ahead.
2583 * It is possible that fw has crashed and the mbox command
2584 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002585 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002586 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2587 fwsync_iter--;
2588}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002589
Jing Huang5fbe25c2010-10-18 17:17:23 -07002590/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002591 * Dump firmware smem
2592 */
2593bfa_status_t
2594bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2595 u32 *offset, int *buflen)
2596{
2597 u32 loff;
2598 int dlen;
2599 bfa_status_t status;
2600 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002601
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002602 if (*offset >= smem_len) {
2603 *offset = *buflen = 0;
2604 return BFA_STATUS_EINVAL;
2605 }
2606
2607 loff = *offset;
2608 dlen = *buflen;
2609
Jing Huang5fbe25c2010-10-18 17:17:23 -07002610 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002611 * First smem read, sync smem before proceeding
2612 * No need to sync before reading every chunk.
2613 */
2614 if (loff == 0)
2615 bfa_ioc_fwsync(ioc);
2616
2617 if ((loff + dlen) >= smem_len)
2618 dlen = smem_len - loff;
2619
2620 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2621
2622 if (status != BFA_STATUS_OK) {
2623 *offset = *buflen = 0;
2624 return status;
2625 }
2626
2627 *offset += dlen;
2628
2629 if (*offset >= smem_len)
2630 *offset = 0;
2631
2632 *buflen = dlen;
2633
2634 return status;
2635}
2636
Jing Huang5fbe25c2010-10-18 17:17:23 -07002637/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002638 * Firmware statistics
2639 */
2640bfa_status_t
2641bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2642{
2643 u32 loff = BFI_IOC_FWSTATS_OFF + \
2644 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2645 int tlen;
2646 bfa_status_t status;
2647
2648 if (ioc->stats_busy) {
2649 bfa_trc(ioc, ioc->stats_busy);
2650 return BFA_STATUS_DEVBUSY;
2651 }
2652 ioc->stats_busy = BFA_TRUE;
2653
2654 tlen = sizeof(struct bfa_fw_stats_s);
2655 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2656
2657 ioc->stats_busy = BFA_FALSE;
2658 return status;
2659}
2660
2661bfa_status_t
2662bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2663{
2664 u32 loff = BFI_IOC_FWSTATS_OFF + \
2665 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2666 int tlen;
2667 bfa_status_t status;
2668
2669 if (ioc->stats_busy) {
2670 bfa_trc(ioc, ioc->stats_busy);
2671 return BFA_STATUS_DEVBUSY;
2672 }
2673 ioc->stats_busy = BFA_TRUE;
2674
2675 tlen = sizeof(struct bfa_fw_stats_s);
2676 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2677
2678 ioc->stats_busy = BFA_FALSE;
2679 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002680}
2681
Jing Huang5fbe25c2010-10-18 17:17:23 -07002682/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002683 * Save firmware trace if configured.
2684 */
2685static void
2686bfa_ioc_debug_save(struct bfa_ioc_s *ioc)
2687{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002688 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002689
2690 if (ioc->dbg_fwsave_len) {
2691 tlen = ioc->dbg_fwsave_len;
2692 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2693 }
2694}
2695
Jing Huang5fbe25c2010-10-18 17:17:23 -07002696/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002697 * Firmware failure detected. Start recovery actions.
2698 */
2699static void
2700bfa_ioc_recover(struct bfa_ioc_s *ioc)
2701{
2702 if (ioc->dbg_fwsave_once) {
2703 ioc->dbg_fwsave_once = BFA_FALSE;
2704 bfa_ioc_debug_save(ioc);
2705 }
2706
2707 bfa_ioc_stats(ioc, ioc_hbfails);
2708 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2709}
2710
Jing Huang7725ccf2009-09-23 17:46:15 -07002711static void
Jing Huang07b28382010-07-08 19:59:24 -07002712bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002713{
Jing Huang07b28382010-07-08 19:59:24 -07002714 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2715 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002716}
2717
Jing Huang5fbe25c2010-10-18 17:17:23 -07002718/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002719 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002720 */
2721
2722static void
2723bfa_iocpf_enable(struct bfa_ioc_s *ioc)
2724{
2725 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
2726}
2727
2728static void
2729bfa_iocpf_disable(struct bfa_ioc_s *ioc)
2730{
2731 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
2732}
2733
2734static void
2735bfa_iocpf_fail(struct bfa_ioc_s *ioc)
2736{
2737 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
2738}
2739
2740static void
2741bfa_iocpf_initfail(struct bfa_ioc_s *ioc)
2742{
2743 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
2744}
2745
2746static void
2747bfa_iocpf_getattrfail(struct bfa_ioc_s *ioc)
2748{
2749 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
2750}
2751
2752static void
2753bfa_iocpf_stop(struct bfa_ioc_s *ioc)
2754{
2755 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
2756}
2757
2758static void
2759bfa_iocpf_timeout(void *ioc_arg)
2760{
2761 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2762
2763 bfa_trc(ioc, 0);
2764 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2765}
2766
2767static void
2768bfa_iocpf_sem_timeout(void *ioc_arg)
2769{
2770 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2771
2772 bfa_ioc_hw_sem_get(ioc);
2773}
2774
Jing Huang5fbe25c2010-10-18 17:17:23 -07002775/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002776 * bfa timer function
2777 */
2778void
2779bfa_timer_init(struct bfa_timer_mod_s *mod)
2780{
2781 INIT_LIST_HEAD(&mod->timer_q);
2782}
2783
2784void
2785bfa_timer_beat(struct bfa_timer_mod_s *mod)
2786{
2787 struct list_head *qh = &mod->timer_q;
2788 struct list_head *qe, *qe_next;
2789 struct bfa_timer_s *elem;
2790 struct list_head timedout_q;
2791
2792 INIT_LIST_HEAD(&timedout_q);
2793
2794 qe = bfa_q_next(qh);
2795
2796 while (qe != qh) {
2797 qe_next = bfa_q_next(qe);
2798
2799 elem = (struct bfa_timer_s *) qe;
2800 if (elem->timeout <= BFA_TIMER_FREQ) {
2801 elem->timeout = 0;
2802 list_del(&elem->qe);
2803 list_add_tail(&elem->qe, &timedout_q);
2804 } else {
2805 elem->timeout -= BFA_TIMER_FREQ;
2806 }
2807
2808 qe = qe_next; /* go to next elem */
2809 }
2810
2811 /*
2812 * Pop all the timeout entries
2813 */
2814 while (!list_empty(&timedout_q)) {
2815 bfa_q_deq(&timedout_q, &elem);
2816 elem->timercb(elem->arg);
2817 }
2818}
2819
Jing Huang5fbe25c2010-10-18 17:17:23 -07002820/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002821 * Should be called with lock protection
2822 */
2823void
2824bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2825 void (*timercb) (void *), void *arg, unsigned int timeout)
2826{
2827
2828 bfa_assert(timercb != NULL);
2829 bfa_assert(!bfa_q_is_on_q(&mod->timer_q, timer));
2830
2831 timer->timeout = timeout;
2832 timer->timercb = timercb;
2833 timer->arg = arg;
2834
2835 list_add_tail(&timer->qe, &mod->timer_q);
2836}
2837
Jing Huang5fbe25c2010-10-18 17:17:23 -07002838/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002839 * Should be called with lock protection
2840 */
2841void
2842bfa_timer_stop(struct bfa_timer_s *timer)
2843{
2844 bfa_assert(!list_empty(&timer->qe));
2845
2846 list_del(&timer->qe);
2847}