blob: c1f72c49196f64e6f3e1498ca88802fb68754c23 [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
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019#include "bfa_ioc.h"
20#include "bfi_ctreg.h"
21#include "bfa_defs.h"
22#include "bfa_defs_svc.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 */
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080032#define BFA_IOC_HWINIT_MAX 5
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070033#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_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
Jing Huang7725ccf2009-09-23 17:46:15 -070046
Jing Huang5fbe25c2010-10-18 17:17:23 -070047/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080048 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
49 */
50
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070051#define bfa_ioc_firmware_lock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080052 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070053#define bfa_ioc_firmware_unlock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080054 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
Krishna Gudipati0a20de42010-03-05 19:34:20 -080055#define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
56#define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080057#define bfa_ioc_notify_fail(__ioc) \
58 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
59#define bfa_ioc_sync_join(__ioc) \
60 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
61#define bfa_ioc_sync_leave(__ioc) \
62 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
63#define bfa_ioc_sync_ack(__ioc) \
64 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
65#define bfa_ioc_sync_complete(__ioc) \
66 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070067
68#define bfa_ioc_mbox_cmd_pending(__ioc) \
69 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
Jing Huang53440262010-10-18 17:12:29 -070070 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070071
72bfa_boolean_t bfa_auto_recover = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070073
74/*
75 * forward declarations
76 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070077static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070078static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
79static void bfa_ioc_timeout(void *ioc);
80static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
81static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
82static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
83static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070084static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
85static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc);
86static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
87static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
88static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
89static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -080090static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc);
91static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070092static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -070093
Jing Huang7725ccf2009-09-23 17:46:15 -070094
Jing Huang5fbe25c2010-10-18 17:17:23 -070095/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070096 * IOC state machine definitions/declarations
Jing Huang7725ccf2009-09-23 17:46:15 -070097 */
98enum ioc_event {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070099 IOC_E_RESET = 1, /* IOC reset request */
100 IOC_E_ENABLE = 2, /* IOC enable request */
101 IOC_E_DISABLE = 3, /* IOC disable request */
102 IOC_E_DETACH = 4, /* driver detach cleanup */
103 IOC_E_ENABLED = 5, /* f/w enabled */
104 IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
105 IOC_E_DISABLED = 7, /* f/w disabled */
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800106 IOC_E_INITFAILED = 8, /* failure notice by iocpf sm */
107 IOC_E_PFFAILED = 9, /* failure notice by iocpf sm */
108 IOC_E_HBFAIL = 10, /* heartbeat failure */
109 IOC_E_HWERROR = 11, /* hardware error interrupt */
110 IOC_E_TIMEOUT = 12, /* timeout */
Jing Huang7725ccf2009-09-23 17:46:15 -0700111};
112
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700113bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700114bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700115bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
116bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
117bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800118bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700119bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700120bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
121bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
122
123static struct bfa_sm_table_s ioc_sm_table[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700124 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Jing Huang7725ccf2009-09-23 17:46:15 -0700125 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700126 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Jing Huang7725ccf2009-09-23 17:46:15 -0700127 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
128 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800129 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700131 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
132 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
133};
134
Jing Huang5fbe25c2010-10-18 17:17:23 -0700135/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700136 * IOCPF state machine definitions/declarations
137 */
138
139#define bfa_iocpf_timer_start(__ioc) \
140 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
141 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
142#define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
143
144#define bfa_iocpf_recovery_timer_start(__ioc) \
145 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
146 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV_RECOVER)
147
148#define bfa_sem_timer_start(__ioc) \
149 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
150 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
151#define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
152
153/*
154 * Forward declareations for iocpf state machine
155 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700156static void bfa_iocpf_timeout(void *ioc_arg);
157static void bfa_iocpf_sem_timeout(void *ioc_arg);
158
Jing Huang5fbe25c2010-10-18 17:17:23 -0700159/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700160 * IOCPF state machine events
161 */
162enum iocpf_event {
163 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
164 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
165 IOCPF_E_STOP = 3, /* stop on driver detach */
166 IOCPF_E_FWREADY = 4, /* f/w initialization done */
167 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
168 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
169 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
170 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
171 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
172 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
173 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
174};
175
Jing Huang5fbe25c2010-10-18 17:17:23 -0700176/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700177 * IOCPF states
178 */
179enum bfa_iocpf_state {
180 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
181 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
182 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
183 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
184 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
185 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
186 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
187 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
188 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
189};
190
191bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
192bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
193bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
194bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
195bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
196bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
197bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800198bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
199 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700200bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800201bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700202bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
203bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800204bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
205 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700206bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
207
208static struct bfa_sm_table_s iocpf_sm_table[] = {
209 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
210 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
211 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
212 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
213 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
214 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
215 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800216 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700217 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800218 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700219 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
220 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800221 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700222 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
223};
224
Jing Huang5fbe25c2010-10-18 17:17:23 -0700225/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700226 * IOC State Machine
227 */
228
Jing Huang5fbe25c2010-10-18 17:17:23 -0700229/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700230 * Beginning state. IOC uninit state.
231 */
232
233static void
234bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
235{
236}
237
Jing Huang5fbe25c2010-10-18 17:17:23 -0700238/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700239 * IOC is in uninit state.
240 */
241static void
242bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
243{
244 bfa_trc(ioc, event);
245
246 switch (event) {
247 case IOC_E_RESET:
248 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
249 break;
250
251 default:
252 bfa_sm_fault(ioc, event);
253 }
254}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700255/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700256 * Reset entry actions -- initialize state machine
257 */
258static void
259bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
260{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700261 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700262}
263
Jing Huang5fbe25c2010-10-18 17:17:23 -0700264/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700265 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700266 */
267static void
268bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
269{
270 bfa_trc(ioc, event);
271
272 switch (event) {
273 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700274 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
275 break;
276
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700277 case IOC_E_DISABLE:
278 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700279 break;
280
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700281 case IOC_E_DETACH:
282 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700283 break;
284
285 default:
286 bfa_sm_fault(ioc, event);
287 }
288}
289
290
291static void
292bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
293{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800294 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700295}
296
Jing Huang5fbe25c2010-10-18 17:17:23 -0700297/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700298 * Host IOC function is being enabled, awaiting response from firmware.
299 * Semaphore is acquired.
300 */
301static void
302bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
303{
304 bfa_trc(ioc, event);
305
306 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700307 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700308 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
309 break;
310
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800311 case IOC_E_PFFAILED:
312 /* !!! fall through !!! */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700313 case IOC_E_HWERROR:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800314 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
315 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
316 if (event != IOC_E_PFFAILED)
317 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700318 break;
319
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700320 case IOC_E_DISABLE:
321 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
322 break;
323
324 case IOC_E_DETACH:
325 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800326 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700327 break;
328
329 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700330 break;
331
332 default:
333 bfa_sm_fault(ioc, event);
334 }
335}
336
337
338static void
339bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
340{
341 bfa_ioc_timer_start(ioc);
342 bfa_ioc_send_getattr(ioc);
343}
344
Jing Huang5fbe25c2010-10-18 17:17:23 -0700345/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700346 * IOC configuration in progress. Timer is active.
347 */
348static void
349bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
350{
351 bfa_trc(ioc, event);
352
353 switch (event) {
354 case IOC_E_FWRSP_GETATTR:
355 bfa_ioc_timer_stop(ioc);
Jing Huang07b28382010-07-08 19:59:24 -0700356 bfa_ioc_check_attr_wwns(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700357 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
358 break;
359
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700360 break;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800361 case IOC_E_PFFAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700362 case IOC_E_HWERROR:
363 bfa_ioc_timer_stop(ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800364 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700365 case IOC_E_TIMEOUT:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800366 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
367 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
368 if (event != IOC_E_PFFAILED)
369 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700370 break;
371
372 case IOC_E_DISABLE:
373 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
375 break;
376
377 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700378 break;
379
380 default:
381 bfa_sm_fault(ioc, event);
382 }
383}
384
385
386static void
387bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
388{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700389 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
390
Jing Huang7725ccf2009-09-23 17:46:15 -0700391 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
392 bfa_ioc_hb_monitor(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800393 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700394}
395
396static void
397bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
398{
399 bfa_trc(ioc, event);
400
401 switch (event) {
402 case IOC_E_ENABLE:
403 break;
404
405 case IOC_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800406 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700407 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
408 break;
409
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800410 case IOC_E_PFFAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700411 case IOC_E_HWERROR:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800412 bfa_hb_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700413 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700414 case IOC_E_HBFAIL:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800415 bfa_ioc_fail_notify(ioc);
416
417 if (ioc->iocpf.auto_recover)
418 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
419 else
420 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
421
422 if (event != IOC_E_PFFAILED)
423 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700424 break;
425
426 default:
427 bfa_sm_fault(ioc, event);
428 }
429}
430
431
432static void
433bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
434{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700435 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Maggie Zhangf7f73812010-12-09 19:08:43 -0800436 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
Jing Huang88166242010-12-09 17:11:53 -0800437 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700438}
439
Jing Huang5fbe25c2010-10-18 17:17:23 -0700440/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700441 * IOC is being disabled
442 */
443static void
444bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
445{
446 bfa_trc(ioc, event);
447
448 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700449 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800450 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
451 break;
452
453 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700454 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700455 * No state change. Will move to disabled state
456 * after iocpf sm completes failure processing and
457 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700458 */
Maggie Zhangf7f73812010-12-09 19:08:43 -0800459 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700460 break;
461
462 default:
463 bfa_sm_fault(ioc, event);
464 }
465}
466
Jing Huang5fbe25c2010-10-18 17:17:23 -0700467/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700468 * IOC disable completion entry.
469 */
470static void
471bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
472{
473 bfa_ioc_disable_comp(ioc);
474}
475
476static void
477bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
478{
479 bfa_trc(ioc, event);
480
481 switch (event) {
482 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700483 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700484 break;
485
486 case IOC_E_DISABLE:
487 ioc->cbfn->disable_cbfn(ioc->bfa);
488 break;
489
Jing Huang7725ccf2009-09-23 17:46:15 -0700490 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700491 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800492 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700493 break;
494
495 default:
496 bfa_sm_fault(ioc, event);
497 }
498}
499
500
501static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800502bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700503{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800504 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700505}
506
Jing Huang5fbe25c2010-10-18 17:17:23 -0700507/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800508 * Hardware initialization retry.
Jing Huang7725ccf2009-09-23 17:46:15 -0700509 */
510static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800511bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700512{
513 bfa_trc(ioc, event);
514
515 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700516 case IOC_E_ENABLED:
517 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
518 break;
519
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800520 case IOC_E_PFFAILED:
521 case IOC_E_HWERROR:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700522 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800523 * Initialization retry failed.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700524 */
525 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800526 if (event != IOC_E_PFFAILED)
527 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
528 break;
529
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800530 case IOC_E_INITFAILED:
531 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
532 break;
533
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800534 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700535 break;
536
Jing Huang7725ccf2009-09-23 17:46:15 -0700537 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700538 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700539 break;
540
541 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700542 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800543 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700544 break;
545
546 default:
547 bfa_sm_fault(ioc, event);
548 }
549}
550
551
552static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700553bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700554{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800555 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700556}
557
Jing Huang5fbe25c2010-10-18 17:17:23 -0700558/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700559 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700560 */
561static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700562bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700563{
564 bfa_trc(ioc, event);
565
566 switch (event) {
567
568 case IOC_E_ENABLE:
569 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
570 break;
571
572 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700573 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700574 break;
575
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800576 case IOC_E_DETACH:
577 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
578 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
579 break;
580
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800581 case IOC_E_HWERROR:
582 /*
583 * HB failure notification, ignore.
584 */
585 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700586 default:
587 bfa_sm_fault(ioc, event);
588 }
589}
590
Jing Huang5fbe25c2010-10-18 17:17:23 -0700591/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700592 * IOCPF State Machine
593 */
594
Jing Huang5fbe25c2010-10-18 17:17:23 -0700595/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700596 * Reset entry actions -- initialize state machine
597 */
598static void
599bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
600{
601 iocpf->retry_count = 0;
602 iocpf->auto_recover = bfa_auto_recover;
603}
604
Jing Huang5fbe25c2010-10-18 17:17:23 -0700605/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700606 * Beginning state. IOC is in reset state.
607 */
608static void
609bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
610{
611 struct bfa_ioc_s *ioc = iocpf->ioc;
612
613 bfa_trc(ioc, event);
614
615 switch (event) {
616 case IOCPF_E_ENABLE:
617 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
618 break;
619
620 case IOCPF_E_STOP:
621 break;
622
623 default:
624 bfa_sm_fault(ioc, event);
625 }
626}
627
Jing Huang5fbe25c2010-10-18 17:17:23 -0700628/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700629 * Semaphore should be acquired for version check.
630 */
631static void
632bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
633{
634 bfa_ioc_hw_sem_get(iocpf->ioc);
635}
636
Jing Huang5fbe25c2010-10-18 17:17:23 -0700637/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700638 * Awaiting h/w semaphore to continue with version check.
639 */
640static void
641bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
642{
643 struct bfa_ioc_s *ioc = iocpf->ioc;
644
645 bfa_trc(ioc, event);
646
647 switch (event) {
648 case IOCPF_E_SEMLOCKED:
649 if (bfa_ioc_firmware_lock(ioc)) {
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800650 if (bfa_ioc_sync_complete(ioc)) {
651 iocpf->retry_count = 0;
652 bfa_ioc_sync_join(ioc);
653 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
654 } else {
655 bfa_ioc_firmware_unlock(ioc);
656 writel(1, ioc->ioc_regs.ioc_sem_reg);
657 bfa_sem_timer_start(ioc);
658 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700659 } else {
Maggie Zhangf7f73812010-12-09 19:08:43 -0800660 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700661 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
662 }
663 break;
664
665 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800666 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700667 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800668 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700669 break;
670
671 case IOCPF_E_STOP:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800672 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700673 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
674 break;
675
676 default:
677 bfa_sm_fault(ioc, event);
678 }
679}
680
Jing Huang5fbe25c2010-10-18 17:17:23 -0700681/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700682 * Notify enable completion callback.
683 */
684static void
685bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
686{
687 /*
688 * Call only the first time sm enters fwmismatch state.
689 */
690 if (iocpf->retry_count == 0)
691 bfa_ioc_pf_fwmismatch(iocpf->ioc);
692
693 iocpf->retry_count++;
694 bfa_iocpf_timer_start(iocpf->ioc);
695}
696
Jing Huang5fbe25c2010-10-18 17:17:23 -0700697/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700698 * Awaiting firmware version match.
699 */
700static void
701bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
702{
703 struct bfa_ioc_s *ioc = iocpf->ioc;
704
705 bfa_trc(ioc, event);
706
707 switch (event) {
708 case IOCPF_E_TIMEOUT:
709 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
710 break;
711
712 case IOCPF_E_DISABLE:
713 bfa_iocpf_timer_stop(ioc);
714 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800715 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700716 break;
717
718 case IOCPF_E_STOP:
719 bfa_iocpf_timer_stop(ioc);
720 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
721 break;
722
723 default:
724 bfa_sm_fault(ioc, event);
725 }
726}
727
Jing Huang5fbe25c2010-10-18 17:17:23 -0700728/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700729 * Request for semaphore.
730 */
731static void
732bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
733{
734 bfa_ioc_hw_sem_get(iocpf->ioc);
735}
736
Jing Huang5fbe25c2010-10-18 17:17:23 -0700737/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700738 * Awaiting semaphore for h/w initialzation.
739 */
740static void
741bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
742{
743 struct bfa_ioc_s *ioc = iocpf->ioc;
744
745 bfa_trc(ioc, event);
746
747 switch (event) {
748 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800749 if (bfa_ioc_sync_complete(ioc)) {
750 bfa_ioc_sync_join(ioc);
751 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
752 } else {
753 writel(1, ioc->ioc_regs.ioc_sem_reg);
754 bfa_sem_timer_start(ioc);
755 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700756 break;
757
758 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800759 bfa_sem_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800760 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700761 break;
762
763 default:
764 bfa_sm_fault(ioc, event);
765 }
766}
767
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700768static void
769bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
770{
771 bfa_iocpf_timer_start(iocpf->ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800772 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700773}
774
Jing Huang5fbe25c2010-10-18 17:17:23 -0700775/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700776 * Hardware is being initialized. Interrupts are enabled.
777 * Holding hardware semaphore lock.
778 */
779static void
780bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
781{
782 struct bfa_ioc_s *ioc = iocpf->ioc;
783
784 bfa_trc(ioc, event);
785
786 switch (event) {
787 case IOCPF_E_FWREADY:
788 bfa_iocpf_timer_stop(ioc);
789 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
790 break;
791
792 case IOCPF_E_INITFAIL:
793 bfa_iocpf_timer_stop(ioc);
794 /*
795 * !!! fall through !!!
796 */
797
798 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800799 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700800 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800801 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800802 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700803 break;
804
805 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700806 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800807 bfa_ioc_sync_leave(ioc);
808 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700809 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
810 break;
811
812 default:
813 bfa_sm_fault(ioc, event);
814 }
815}
816
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700817static void
818bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
819{
820 bfa_iocpf_timer_start(iocpf->ioc);
821 bfa_ioc_send_enable(iocpf->ioc);
822}
823
Jing Huang5fbe25c2010-10-18 17:17:23 -0700824/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700825 * Host IOC function is being enabled, awaiting response from firmware.
826 * Semaphore is acquired.
827 */
828static void
829bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
830{
831 struct bfa_ioc_s *ioc = iocpf->ioc;
832
833 bfa_trc(ioc, event);
834
835 switch (event) {
836 case IOCPF_E_FWRSP_ENABLE:
837 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800838 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700839 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
840 break;
841
842 case IOCPF_E_INITFAIL:
843 bfa_iocpf_timer_stop(ioc);
844 /*
845 * !!! fall through !!!
846 */
847
848 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800849 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700850 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800851 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800852 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700853 break;
854
855 case IOCPF_E_DISABLE:
856 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800857 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700858 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
859 break;
860
861 case IOCPF_E_FWREADY:
862 bfa_ioc_send_enable(ioc);
863 break;
864
865 default:
866 bfa_sm_fault(ioc, event);
867 }
868}
869
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700870static void
871bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
872{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800873 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700874}
875
876static void
877bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
878{
879 struct bfa_ioc_s *ioc = iocpf->ioc;
880
881 bfa_trc(ioc, event);
882
883 switch (event) {
884 case IOCPF_E_DISABLE:
885 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
886 break;
887
888 case IOCPF_E_GETATTRFAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800889 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890 break;
891
892 case IOCPF_E_FAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800893 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700894 break;
895
896 case IOCPF_E_FWREADY:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800897 if (bfa_ioc_is_operational(ioc)) {
898 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
899 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
900 } else {
901 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
902 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
903 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700904 break;
905
906 default:
907 bfa_sm_fault(ioc, event);
908 }
909}
910
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700911static void
912bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
913{
914 bfa_iocpf_timer_start(iocpf->ioc);
915 bfa_ioc_send_disable(iocpf->ioc);
916}
917
Jing Huang5fbe25c2010-10-18 17:17:23 -0700918/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700919 * IOC is being disabled
920 */
921static void
922bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
923{
924 struct bfa_ioc_s *ioc = iocpf->ioc;
925
926 bfa_trc(ioc, event);
927
928 switch (event) {
929 case IOCPF_E_FWRSP_DISABLE:
930 case IOCPF_E_FWREADY:
931 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800932 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700933 break;
934
935 case IOCPF_E_FAIL:
936 bfa_iocpf_timer_stop(ioc);
937 /*
938 * !!! fall through !!!
939 */
940
941 case IOCPF_E_TIMEOUT:
Jing Huang53440262010-10-18 17:12:29 -0700942 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800943 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700944 break;
945
946 case IOCPF_E_FWRSP_ENABLE:
947 break;
948
949 default:
950 bfa_sm_fault(ioc, event);
951 }
952}
953
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800954static void
955bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
956{
957 bfa_ioc_hw_sem_get(iocpf->ioc);
958}
959
Jing Huang8f4bfad2010-12-26 21:50:10 -0800960/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800961 * IOC hb ack request is being removed.
962 */
963static void
964bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
965{
966 struct bfa_ioc_s *ioc = iocpf->ioc;
967
968 bfa_trc(ioc, event);
969
970 switch (event) {
971 case IOCPF_E_SEMLOCKED:
972 bfa_ioc_sync_leave(ioc);
973 writel(1, ioc->ioc_regs.ioc_sem_reg);
974 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
975 break;
976
977 case IOCPF_E_FAIL:
978 break;
979
980 default:
981 bfa_sm_fault(ioc, event);
982 }
983}
984
Jing Huang5fbe25c2010-10-18 17:17:23 -0700985/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700986 * IOC disable completion entry.
987 */
988static void
989bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
990{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800991 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700992}
993
994static void
995bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
996{
997 struct bfa_ioc_s *ioc = iocpf->ioc;
998
999 bfa_trc(ioc, event);
1000
1001 switch (event) {
1002 case IOCPF_E_ENABLE:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001003 iocpf->retry_count = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001004 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1005 break;
1006
1007 case IOCPF_E_STOP:
1008 bfa_ioc_firmware_unlock(ioc);
1009 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1010 break;
1011
1012 default:
1013 bfa_sm_fault(ioc, event);
1014 }
1015}
1016
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001017static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001018bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1019{
1020 bfa_ioc_hw_sem_get(iocpf->ioc);
1021}
1022
Jing Huang8f4bfad2010-12-26 21:50:10 -08001023/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001024 * Hardware initialization failed.
1025 */
1026static void
1027bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1028{
1029 struct bfa_ioc_s *ioc = iocpf->ioc;
1030
1031 bfa_trc(ioc, event);
1032
1033 switch (event) {
1034 case IOCPF_E_SEMLOCKED:
1035 bfa_ioc_notify_fail(ioc);
1036 bfa_ioc_sync_ack(ioc);
1037 iocpf->retry_count++;
1038 if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) {
1039 bfa_ioc_sync_leave(ioc);
1040 writel(1, ioc->ioc_regs.ioc_sem_reg);
1041 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
1042 } else {
1043 if (bfa_ioc_sync_complete(ioc))
1044 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1045 else {
1046 writel(1, ioc->ioc_regs.ioc_sem_reg);
1047 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1048 }
1049 }
1050 break;
1051
1052 case IOCPF_E_DISABLE:
1053 bfa_sem_timer_stop(ioc);
1054 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1055 break;
1056
1057 case IOCPF_E_STOP:
1058 bfa_sem_timer_stop(ioc);
1059 bfa_ioc_firmware_unlock(ioc);
1060 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1061 break;
1062
1063 case IOCPF_E_FAIL:
1064 break;
1065
1066 default:
1067 bfa_sm_fault(ioc, event);
1068 }
1069}
1070
1071static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001072bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1073{
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001074 bfa_fsm_send_event(iocpf->ioc, IOC_E_INITFAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001075}
1076
Jing Huang5fbe25c2010-10-18 17:17:23 -07001077/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001078 * Hardware initialization failed.
1079 */
1080static void
1081bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1082{
1083 struct bfa_ioc_s *ioc = iocpf->ioc;
1084
1085 bfa_trc(ioc, event);
1086
1087 switch (event) {
1088 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001089 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1090 break;
1091
1092 case IOCPF_E_STOP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001093 bfa_ioc_firmware_unlock(ioc);
1094 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1095 break;
1096
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001097 default:
1098 bfa_sm_fault(ioc, event);
1099 }
1100}
1101
1102static void
1103bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1104{
Jing Huang8f4bfad2010-12-26 21:50:10 -08001105 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001106 * Mark IOC as failed in hardware and stop firmware.
1107 */
1108 bfa_ioc_lpu_stop(iocpf->ioc);
1109
Jing Huang8f4bfad2010-12-26 21:50:10 -08001110 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001111 * Flush any queued up mailbox requests.
1112 */
1113 bfa_ioc_mbox_hbfail(iocpf->ioc);
1114
1115 bfa_ioc_hw_sem_get(iocpf->ioc);
1116}
1117
1118static void
1119bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1120{
1121 struct bfa_ioc_s *ioc = iocpf->ioc;
1122
1123 bfa_trc(ioc, event);
1124
1125 switch (event) {
1126 case IOCPF_E_SEMLOCKED:
1127 iocpf->retry_count = 0;
1128 bfa_ioc_sync_ack(ioc);
1129 bfa_ioc_notify_fail(ioc);
1130 if (!iocpf->auto_recover) {
1131 bfa_ioc_sync_leave(ioc);
1132 writel(1, ioc->ioc_regs.ioc_sem_reg);
1133 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1134 } else {
1135 if (bfa_ioc_sync_complete(ioc))
1136 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1137 else {
1138 writel(1, ioc->ioc_regs.ioc_sem_reg);
1139 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1140 }
1141 }
1142 break;
1143
1144 case IOCPF_E_DISABLE:
1145 bfa_sem_timer_stop(ioc);
1146 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1147 break;
1148
1149 case IOCPF_E_FAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001150 break;
1151
1152 default:
1153 bfa_sm_fault(ioc, event);
1154 }
1155}
1156
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157static void
1158bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1159{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001160}
1161
Jing Huang5fbe25c2010-10-18 17:17:23 -07001162/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001163 * IOC is in failed state.
1164 */
1165static void
1166bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1167{
1168 struct bfa_ioc_s *ioc = iocpf->ioc;
1169
1170 bfa_trc(ioc, event);
1171
1172 switch (event) {
1173 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001174 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1175 break;
1176
Jing Huang7725ccf2009-09-23 17:46:15 -07001177 default:
1178 bfa_sm_fault(ioc, event);
1179 }
1180}
1181
Jing Huang5fbe25c2010-10-18 17:17:23 -07001182/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001183 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001184 */
1185
1186static void
1187bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1188{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001189 struct list_head *qe;
1190 struct bfa_ioc_hbfail_notify_s *notify;
Jing Huang7725ccf2009-09-23 17:46:15 -07001191
1192 ioc->cbfn->disable_cbfn(ioc->bfa);
1193
Jing Huang5fbe25c2010-10-18 17:17:23 -07001194 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001195 * Notify common modules registered for notification.
1196 */
1197 list_for_each(qe, &ioc->hb_notify_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001198 notify = (struct bfa_ioc_hbfail_notify_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001199 notify->cbfn(notify->cbarg);
1200 }
1201}
1202
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001203bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001204bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001205{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001206 u32 r32;
1207 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001208#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001209
Jing Huang53440262010-10-18 17:12:29 -07001210 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001211
1212 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001213 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001214 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001215 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001216 }
1217
1218 if (r32 == 0)
1219 return BFA_TRUE;
1220
Jing Huangd4b671c2010-12-26 21:46:35 -08001221 WARN_ON(cnt >= BFA_SEM_SPINCNT);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001222 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001223}
1224
Jing Huang7725ccf2009-09-23 17:46:15 -07001225static void
1226bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1227{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001228 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001229
Jing Huang5fbe25c2010-10-18 17:17:23 -07001230 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001231 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001232 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001233 */
Jing Huang53440262010-10-18 17:12:29 -07001234 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001235 if (r32 == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001236 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001237 return;
1238 }
1239
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001240 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001241}
1242
Jing Huang5fbe25c2010-10-18 17:17:23 -07001243/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001244 * Initialize LPU local memory (aka secondary memory / SRAM)
1245 */
1246static void
1247bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1248{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001249 u32 pss_ctl;
1250 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001251#define PSS_LMEM_INIT_TIME 10000
1252
Jing Huang53440262010-10-18 17:12:29 -07001253 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001254 pss_ctl &= ~__PSS_LMEM_RESET;
1255 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001256
1257 /*
1258 * i2c workaround 12.5khz clock
1259 */
1260 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001261 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001262
Jing Huang5fbe25c2010-10-18 17:17:23 -07001263 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001264 * wait for memory initialization to be complete
1265 */
1266 i = 0;
1267 do {
Jing Huang53440262010-10-18 17:12:29 -07001268 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001269 i++;
1270 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1271
Jing Huang5fbe25c2010-10-18 17:17:23 -07001272 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001273 * If memory initialization is not successful, IOC timeout will catch
1274 * such failures.
1275 */
Jing Huangd4b671c2010-12-26 21:46:35 -08001276 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
Jing Huang7725ccf2009-09-23 17:46:15 -07001277 bfa_trc(ioc, pss_ctl);
1278
1279 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001280 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001281}
1282
1283static void
1284bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1285{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001286 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001287
Jing Huang5fbe25c2010-10-18 17:17:23 -07001288 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001289 * Take processor out of reset.
1290 */
Jing Huang53440262010-10-18 17:12:29 -07001291 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001292 pss_ctl &= ~__PSS_LPU0_RESET;
1293
Jing Huang53440262010-10-18 17:12:29 -07001294 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001295}
1296
1297static void
1298bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1299{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001300 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001301
Jing Huang5fbe25c2010-10-18 17:17:23 -07001302 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001303 * Put processors in reset.
1304 */
Jing Huang53440262010-10-18 17:12:29 -07001305 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001306 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1307
Jing Huang53440262010-10-18 17:12:29 -07001308 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001309}
1310
Jing Huang5fbe25c2010-10-18 17:17:23 -07001311/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001312 * Get driver and firmware versions.
1313 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001314void
Jing Huang7725ccf2009-09-23 17:46:15 -07001315bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1316{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001317 u32 pgnum, pgoff;
1318 u32 loff = 0;
1319 int i;
1320 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001321
Maggie Zhangf7f73812010-12-09 19:08:43 -08001322 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1323 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang53440262010-10-18 17:12:29 -07001324 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001325
1326 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1327 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001328 fwsig[i] =
1329 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001330 loff += sizeof(u32);
1331 }
1332}
1333
Jing Huang5fbe25c2010-10-18 17:17:23 -07001334/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001335 * Returns TRUE if same.
1336 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001337bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001338bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1339{
1340 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001341 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001342
Jing Huang293f82d2010-07-08 19:45:20 -07001343 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001344 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001345
1346 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1347 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1348 bfa_trc(ioc, i);
1349 bfa_trc(ioc, fwhdr->md5sum[i]);
1350 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1351 return BFA_FALSE;
1352 }
1353 }
1354
1355 bfa_trc(ioc, fwhdr->md5sum[0]);
1356 return BFA_TRUE;
1357}
1358
Jing Huang5fbe25c2010-10-18 17:17:23 -07001359/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001360 * Return true if current running version is valid. Firmware signature and
1361 * execution context (driver/bios) must match.
1362 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001363static bfa_boolean_t
1364bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001365{
1366 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1367
Jing Huang7725ccf2009-09-23 17:46:15 -07001368 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001369 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001370 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001371
1372 if (fwhdr.signature != drv_fwhdr->signature) {
1373 bfa_trc(ioc, fwhdr.signature);
1374 bfa_trc(ioc, drv_fwhdr->signature);
1375 return BFA_FALSE;
1376 }
1377
Jing Huang53440262010-10-18 17:12:29 -07001378 if (swab32(fwhdr.param) != boot_env) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001379 bfa_trc(ioc, fwhdr.param);
1380 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001381 return BFA_FALSE;
1382 }
1383
1384 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1385}
1386
Jing Huang5fbe25c2010-10-18 17:17:23 -07001387/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001388 * Conditionally flush any pending message from firmware at start.
1389 */
1390static void
1391bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1392{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001393 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001394
Jing Huang53440262010-10-18 17:12:29 -07001395 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001396 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001397 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001398}
1399
Jing Huang7725ccf2009-09-23 17:46:15 -07001400static void
1401bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1402{
1403 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001404 bfa_boolean_t fwvalid;
1405 u32 boot_type;
1406 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001407
Jing Huang53440262010-10-18 17:12:29 -07001408 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001409
1410 if (force)
1411 ioc_fwstate = BFI_IOC_UNINIT;
1412
1413 bfa_trc(ioc, ioc_fwstate);
1414
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001415 boot_type = BFI_BOOT_TYPE_NORMAL;
1416 boot_env = BFI_BOOT_LOADER_OS;
1417
Jing Huang5fbe25c2010-10-18 17:17:23 -07001418 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001419 * check if firmware is valid
1420 */
1421 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001422 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001423
1424 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001425 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001426 return;
1427 }
1428
Jing Huang5fbe25c2010-10-18 17:17:23 -07001429 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001430 * If hardware initialization is in progress (initialized by other IOC),
1431 * just wait for an initialization completion interrupt.
1432 */
1433 if (ioc_fwstate == BFI_IOC_INITING) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001434 ioc->cbfn->reset_cbfn(ioc->bfa);
1435 return;
1436 }
1437
Jing Huang5fbe25c2010-10-18 17:17:23 -07001438 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001439 * If IOC function is disabled and firmware version is same,
1440 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001441 *
1442 * If option rom, IOC must not be in operational state. With
1443 * convergence, IOC will be in operational state when 2nd driver
1444 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001445 */
Jing Huang8f4bfad2010-12-26 21:50:10 -08001446 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001447
Jing Huang5fbe25c2010-10-18 17:17:23 -07001448 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001449 * When using MSI-X any pending firmware ready event should
1450 * be flushed. Otherwise MSI-X interrupts are not delivered.
1451 */
1452 bfa_ioc_msgflush(ioc);
1453 ioc->cbfn->reset_cbfn(ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001454 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001455 return;
1456 }
1457
Jing Huang5fbe25c2010-10-18 17:17:23 -07001458 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001459 * Initialize the h/w for any other states.
1460 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001461 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001462}
1463
1464static void
1465bfa_ioc_timeout(void *ioc_arg)
1466{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001467 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001468
1469 bfa_trc(ioc, 0);
1470 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1471}
1472
1473void
1474bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1475{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001476 u32 *msgp = (u32 *) ioc_msg;
1477 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001478
1479 bfa_trc(ioc, msgp[0]);
1480 bfa_trc(ioc, len);
1481
Jing Huangd4b671c2010-12-26 21:46:35 -08001482 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
Jing Huang7725ccf2009-09-23 17:46:15 -07001483
1484 /*
1485 * first write msg to mailbox registers
1486 */
1487 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001488 writel(cpu_to_le32(msgp[i]),
1489 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001490
1491 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001492 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001493
1494 /*
1495 * write 1 to mailbox CMD to trigger LPU event
1496 */
Jing Huang53440262010-10-18 17:12:29 -07001497 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1498 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001499}
1500
1501static void
1502bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1503{
1504 struct bfi_ioc_ctrl_req_s enable_req;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001505 struct timeval tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001506
1507 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1508 bfa_ioc_portid(ioc));
1509 enable_req.ioc_class = ioc->ioc_mc;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001510 do_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001511 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001512 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1513}
1514
1515static void
1516bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1517{
1518 struct bfi_ioc_ctrl_req_s disable_req;
1519
1520 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1521 bfa_ioc_portid(ioc));
1522 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1523}
1524
1525static void
1526bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1527{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001528 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001529
1530 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1531 bfa_ioc_portid(ioc));
1532 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1533 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1534}
1535
1536static void
1537bfa_ioc_hb_check(void *cbarg)
1538{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001539 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001540 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001541
Jing Huang53440262010-10-18 17:12:29 -07001542 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001543 if (ioc->hb_count == hb_count) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001544 bfa_ioc_recover(ioc);
1545 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001546 } else {
1547 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001548 }
1549
1550 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001551 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001552}
1553
1554static void
1555bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1556{
Jing Huang53440262010-10-18 17:12:29 -07001557 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001558 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001559}
1560
Jing Huang5fbe25c2010-10-18 17:17:23 -07001561/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001562 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001563 */
1564static void
1565bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001566 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001567{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001568 u32 *fwimg;
1569 u32 pgnum, pgoff;
1570 u32 loff = 0;
1571 u32 chunkno = 0;
1572 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001573
Jing Huang5fbe25c2010-10-18 17:17:23 -07001574 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001575 * Initialize LMEM first before code download
1576 */
1577 bfa_ioc_lmem_init(ioc);
1578
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001579 bfa_trc(ioc, bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
1580 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001581
Maggie Zhangf7f73812010-12-09 19:08:43 -08001582 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1583 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001584
Jing Huang53440262010-10-18 17:12:29 -07001585 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001586
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001587 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001588
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001589 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1590 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001591 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001592 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001593 }
1594
Jing Huang5fbe25c2010-10-18 17:17:23 -07001595 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001596 * write smem
1597 */
1598 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001599 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001600
1601 loff += sizeof(u32);
1602
Jing Huang5fbe25c2010-10-18 17:17:23 -07001603 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001604 * handle page offset wrap around
1605 */
1606 loff = PSS_SMEM_PGOFF(loff);
1607 if (loff == 0) {
1608 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001609 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001610 }
1611 }
1612
Maggie Zhangf7f73812010-12-09 19:08:43 -08001613 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1614 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001615
1616 /*
1617 * Set boot type and boot param at the end.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001618 */
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001619 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001620 swab32(boot_type));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001621 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001622 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001623}
1624
Jing Huang7725ccf2009-09-23 17:46:15 -07001625
Jing Huang5fbe25c2010-10-18 17:17:23 -07001626/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001627 * Update BFA configuration from firmware configuration.
1628 */
1629static void
1630bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1631{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001632 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001633
Jing Huangba816ea2010-10-18 17:10:50 -07001634 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1635 attr->card_type = be32_to_cpu(attr->card_type);
1636 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Jing Huang7725ccf2009-09-23 17:46:15 -07001637
1638 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1639}
1640
Jing Huang5fbe25c2010-10-18 17:17:23 -07001641/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001642 * Attach time initialization of mbox logic.
1643 */
1644static void
1645bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1646{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001647 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1648 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001649
1650 INIT_LIST_HEAD(&mod->cmd_q);
1651 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1652 mod->mbhdlr[mc].cbfn = NULL;
1653 mod->mbhdlr[mc].cbarg = ioc->bfa;
1654 }
1655}
1656
Jing Huang5fbe25c2010-10-18 17:17:23 -07001657/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001658 * Mbox poll timer -- restarts any pending mailbox requests.
1659 */
1660static void
1661bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1662{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001663 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1664 struct bfa_mbox_cmd_s *cmd;
1665 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001666
Jing Huang5fbe25c2010-10-18 17:17:23 -07001667 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001668 * If no command pending, do nothing
1669 */
1670 if (list_empty(&mod->cmd_q))
1671 return;
1672
Jing Huang5fbe25c2010-10-18 17:17:23 -07001673 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001674 * If previous command is not yet fetched by firmware, do nothing
1675 */
Jing Huang53440262010-10-18 17:12:29 -07001676 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001677 if (stat)
1678 return;
1679
Jing Huang5fbe25c2010-10-18 17:17:23 -07001680 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001681 * Enqueue command to firmware.
1682 */
1683 bfa_q_deq(&mod->cmd_q, &cmd);
1684 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1685}
1686
Jing Huang5fbe25c2010-10-18 17:17:23 -07001687/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001688 * Cleanup any pending requests.
1689 */
1690static void
1691bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
1692{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001693 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1694 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001695
1696 while (!list_empty(&mod->cmd_q))
1697 bfa_q_deq(&mod->cmd_q, &cmd);
1698}
1699
Jing Huang5fbe25c2010-10-18 17:17:23 -07001700/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001701 * Read data from SMEM to host through PCI memmap
1702 *
1703 * @param[in] ioc memory for IOC
1704 * @param[in] tbuf app memory to store data from smem
1705 * @param[in] soff smem offset
1706 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001707 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001708static bfa_status_t
1709bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1710{
Maggie50444a32010-11-29 18:26:32 -08001711 u32 pgnum, loff;
1712 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001713 int i, len;
1714 u32 *buf = tbuf;
1715
Maggie Zhangf7f73812010-12-09 19:08:43 -08001716 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1717 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001718 bfa_trc(ioc, pgnum);
1719 bfa_trc(ioc, loff);
1720 bfa_trc(ioc, sz);
1721
1722 /*
1723 * Hold semaphore to serialize pll init and fwtrc.
1724 */
1725 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1726 bfa_trc(ioc, 0);
1727 return BFA_STATUS_FAILED;
1728 }
1729
Jing Huang53440262010-10-18 17:12:29 -07001730 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001731
1732 len = sz/sizeof(u32);
1733 bfa_trc(ioc, len);
1734 for (i = 0; i < len; i++) {
1735 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001736 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001737 loff += sizeof(u32);
1738
Jing Huang5fbe25c2010-10-18 17:17:23 -07001739 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001740 * handle page offset wrap around
1741 */
1742 loff = PSS_SMEM_PGOFF(loff);
1743 if (loff == 0) {
1744 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001745 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001746 }
1747 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001748 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1749 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001750 /*
1751 * release semaphore.
1752 */
Maggie Zhangf7f73812010-12-09 19:08:43 -08001753 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001754
1755 bfa_trc(ioc, pgnum);
1756 return BFA_STATUS_OK;
1757}
1758
Jing Huang5fbe25c2010-10-18 17:17:23 -07001759/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001760 * Clear SMEM data from host through PCI memmap
1761 *
1762 * @param[in] ioc memory for IOC
1763 * @param[in] soff smem offset
1764 * @param[in] sz size of smem in bytes
1765 */
1766static bfa_status_t
1767bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1768{
1769 int i, len;
1770 u32 pgnum, loff;
1771
Maggie Zhangf7f73812010-12-09 19:08:43 -08001772 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1773 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001774 bfa_trc(ioc, pgnum);
1775 bfa_trc(ioc, loff);
1776 bfa_trc(ioc, sz);
1777
1778 /*
1779 * Hold semaphore to serialize pll init and fwtrc.
1780 */
1781 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1782 bfa_trc(ioc, 0);
1783 return BFA_STATUS_FAILED;
1784 }
1785
Jing Huang53440262010-10-18 17:12:29 -07001786 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001787
1788 len = sz/sizeof(u32); /* len in words */
1789 bfa_trc(ioc, len);
1790 for (i = 0; i < len; i++) {
1791 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1792 loff += sizeof(u32);
1793
Jing Huang5fbe25c2010-10-18 17:17:23 -07001794 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001795 * handle page offset wrap around
1796 */
1797 loff = PSS_SMEM_PGOFF(loff);
1798 if (loff == 0) {
1799 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001800 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001801 }
1802 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001803 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1804 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001805
1806 /*
1807 * release semaphore.
1808 */
Maggie Zhangf7f73812010-12-09 19:08:43 -08001809 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001810 bfa_trc(ioc, pgnum);
1811 return BFA_STATUS_OK;
1812}
1813
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001814static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001815bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1816{
1817 struct list_head *qe;
1818 struct bfa_ioc_hbfail_notify_s *notify;
1819 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1820
Jing Huang8f4bfad2010-12-26 21:50:10 -08001821 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001822 * Notify driver and common modules registered for notification.
1823 */
1824 ioc->cbfn->hbfail_cbfn(ioc->bfa);
1825 list_for_each(qe, &ioc->hb_notify_q) {
1826 notify = (struct bfa_ioc_hbfail_notify_s *) qe;
1827 notify->cbfn(notify->cbarg);
1828 }
1829
1830 bfa_ioc_debug_save_ftrc(ioc);
1831
1832 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1833 "Heart Beat of IOC has failed\n");
1834
1835}
1836
1837static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001838bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1839{
1840 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001841 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001842 * Provide enable completion callback.
1843 */
1844 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001845 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001846 "Running firmware version is incompatible "
1847 "with the driver version\n");
1848}
1849
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001850bfa_status_t
1851bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1852{
1853
1854 /*
1855 * Hold semaphore so that nobody can access the chip during init.
1856 */
1857 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1858
1859 bfa_ioc_pll_init_asic(ioc);
1860
1861 ioc->pllinit = BFA_TRUE;
1862 /*
1863 * release semaphore.
1864 */
Maggie Zhangf7f73812010-12-09 19:08:43 -08001865 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001866
1867 return BFA_STATUS_OK;
1868}
Jing Huang7725ccf2009-09-23 17:46:15 -07001869
Jing Huang5fbe25c2010-10-18 17:17:23 -07001870/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001871 * Interface used by diag module to do firmware boot with memory test
1872 * as the entry vector.
1873 */
1874void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001875bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001876{
Jing Huang53440262010-10-18 17:12:29 -07001877 void __iomem *rb;
Jing Huang7725ccf2009-09-23 17:46:15 -07001878
1879 bfa_ioc_stats(ioc, ioc_boots);
1880
1881 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1882 return;
1883
Jing Huang5fbe25c2010-10-18 17:17:23 -07001884 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001885 * Initialize IOC state of all functions on a chip reset.
1886 */
1887 rb = ioc->pcidev.pci_bar_kva;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001888 if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
Jing Huang53440262010-10-18 17:12:29 -07001889 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
1890 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001891 } else {
Jing Huang53440262010-10-18 17:12:29 -07001892 writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
1893 writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001894 }
1895
Jing Huang07b28382010-07-08 19:59:24 -07001896 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001897 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001898
Jing Huang5fbe25c2010-10-18 17:17:23 -07001899 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001900 * Enable interrupts just before starting LPU
1901 */
1902 ioc->cbfn->reset_cbfn(ioc->bfa);
1903 bfa_ioc_lpu_start(ioc);
1904}
1905
Jing Huang5fbe25c2010-10-18 17:17:23 -07001906/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001907 * Enable/disable IOC failure auto recovery.
1908 */
1909void
1910bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
1911{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08001912 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07001913}
1914
1915
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001916
Jing Huang7725ccf2009-09-23 17:46:15 -07001917bfa_boolean_t
1918bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1919{
1920 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
1921}
1922
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001923bfa_boolean_t
1924bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
1925{
Jing Huang53440262010-10-18 17:12:29 -07001926 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001927
1928 return ((r32 != BFI_IOC_UNINIT) &&
1929 (r32 != BFI_IOC_INITING) &&
1930 (r32 != BFI_IOC_MEMTEST));
1931}
1932
Jing Huang7725ccf2009-09-23 17:46:15 -07001933void
1934bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
1935{
Maggie50444a32010-11-29 18:26:32 -08001936 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001937 u32 r32;
1938 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001939
Jing Huang5fbe25c2010-10-18 17:17:23 -07001940 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001941 * read the MBOX msg
1942 */
1943 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1944 i++) {
Jing Huang53440262010-10-18 17:12:29 -07001945 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07001946 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07001947 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07001948 }
1949
Jing Huang5fbe25c2010-10-18 17:17:23 -07001950 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001951 * turn off mailbox interrupt by clearing mailbox status
1952 */
Jing Huang53440262010-10-18 17:12:29 -07001953 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1954 readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001955}
1956
1957void
1958bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
1959{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001960 union bfi_ioc_i2h_msg_u *msg;
1961 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07001962
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001963 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07001964
1965 bfa_ioc_stats(ioc, ioc_isrs);
1966
1967 switch (msg->mh.msg_id) {
1968 case BFI_IOC_I2H_HBEAT:
1969 break;
1970
1971 case BFI_IOC_I2H_READY_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001972 bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001973 break;
1974
1975 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001976 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001977 break;
1978
1979 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001980 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001981 break;
1982
1983 case BFI_IOC_I2H_GETATTR_REPLY:
1984 bfa_ioc_getattr_reply(ioc);
1985 break;
1986
1987 default:
1988 bfa_trc(ioc, msg->mh.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001989 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001990 }
1991}
1992
Jing Huang5fbe25c2010-10-18 17:17:23 -07001993/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001994 * IOC attach time initialization and setup.
1995 *
1996 * @param[in] ioc memory for IOC
1997 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001998 */
1999void
2000bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002001 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07002002{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002003 ioc->bfa = bfa;
2004 ioc->cbfn = cbfn;
2005 ioc->timer_mod = timer_mod;
2006 ioc->fcmode = BFA_FALSE;
2007 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002008 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002009 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002010
2011 bfa_ioc_mbox_attach(ioc);
2012 INIT_LIST_HEAD(&ioc->hb_notify_q);
2013
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002014 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
2015 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07002016}
2017
Jing Huang5fbe25c2010-10-18 17:17:23 -07002018/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002019 * Driver detach time IOC cleanup.
2020 */
2021void
2022bfa_ioc_detach(struct bfa_ioc_s *ioc)
2023{
2024 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2025}
2026
Jing Huang5fbe25c2010-10-18 17:17:23 -07002027/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002028 * Setup IOC PCI properties.
2029 *
2030 * @param[in] pcidev PCI device information for this IOC
2031 */
2032void
2033bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
2034 enum bfi_mclass mc)
2035{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002036 ioc->ioc_mc = mc;
2037 ioc->pcidev = *pcidev;
2038 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
2039 ioc->cna = ioc->ctdev && !ioc->fcmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07002040
Jing Huang5fbe25c2010-10-18 17:17:23 -07002041 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002042 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2043 */
2044 if (ioc->ctdev)
2045 bfa_ioc_set_ct_hwif(ioc);
2046 else
2047 bfa_ioc_set_cb_hwif(ioc);
2048
Jing Huang7725ccf2009-09-23 17:46:15 -07002049 bfa_ioc_map_port(ioc);
2050 bfa_ioc_reg_init(ioc);
2051}
2052
Jing Huang5fbe25c2010-10-18 17:17:23 -07002053/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002054 * Initialize IOC dma memory
2055 *
2056 * @param[in] dm_kva kernel virtual address of IOC dma memory
2057 * @param[in] dm_pa physical address of IOC dma memory
2058 */
2059void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002060bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002061{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002062 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002063 * dma memory for firmware attribute
2064 */
2065 ioc->attr_dma.kva = dm_kva;
2066 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002067 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002068}
2069
Jing Huang7725ccf2009-09-23 17:46:15 -07002070void
2071bfa_ioc_enable(struct bfa_ioc_s *ioc)
2072{
2073 bfa_ioc_stats(ioc, ioc_enables);
2074 ioc->dbg_fwsave_once = BFA_TRUE;
2075
2076 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2077}
2078
2079void
2080bfa_ioc_disable(struct bfa_ioc_s *ioc)
2081{
2082 bfa_ioc_stats(ioc, ioc_disables);
2083 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2084}
2085
Jing Huang7725ccf2009-09-23 17:46:15 -07002086
Jing Huang5fbe25c2010-10-18 17:17:23 -07002087/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002088 * Initialize memory for saving firmware trace. Driver must initialize
2089 * trace memory before call bfa_ioc_enable().
2090 */
2091void
2092bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2093{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002094 ioc->dbg_fwsave = dbg_fwsave;
Maggie Zhangf7f73812010-12-09 19:08:43 -08002095 ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07002096}
2097
Jing Huang5fbe25c2010-10-18 17:17:23 -07002098/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002099 * Register mailbox message handler functions
2100 *
2101 * @param[in] ioc IOC instance
2102 * @param[in] mcfuncs message class handler functions
2103 */
2104void
2105bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2106{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002107 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2108 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002109
2110 for (mc = 0; mc < BFI_MC_MAX; mc++)
2111 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2112}
2113
Jing Huang5fbe25c2010-10-18 17:17:23 -07002114/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002115 * Register mailbox message handler function, to be called by common modules
2116 */
2117void
2118bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2119 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2120{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002121 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002122
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002123 mod->mbhdlr[mc].cbfn = cbfn;
2124 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002125}
2126
Jing Huang5fbe25c2010-10-18 17:17:23 -07002127/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002128 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2129 * Responsibility of caller to serialize
2130 *
2131 * @param[in] ioc IOC instance
2132 * @param[i] cmd Mailbox command
2133 */
2134void
2135bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2136{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002137 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2138 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002139
Jing Huang5fbe25c2010-10-18 17:17:23 -07002140 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002141 * If a previous command is pending, queue new command
2142 */
2143 if (!list_empty(&mod->cmd_q)) {
2144 list_add_tail(&cmd->qe, &mod->cmd_q);
2145 return;
2146 }
2147
Jing Huang5fbe25c2010-10-18 17:17:23 -07002148 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002149 * If mailbox is busy, queue command for poll timer
2150 */
Jing Huang53440262010-10-18 17:12:29 -07002151 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002152 if (stat) {
2153 list_add_tail(&cmd->qe, &mod->cmd_q);
2154 return;
2155 }
2156
Jing Huang5fbe25c2010-10-18 17:17:23 -07002157 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002158 * mailbox is free -- queue command to firmware
2159 */
2160 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2161}
2162
Jing Huang5fbe25c2010-10-18 17:17:23 -07002163/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002164 * Handle mailbox interrupts
2165 */
2166void
2167bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2168{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002169 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2170 struct bfi_mbmsg_s m;
2171 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002172
2173 bfa_ioc_msgget(ioc, &m);
2174
Jing Huang5fbe25c2010-10-18 17:17:23 -07002175 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002176 * Treat IOC message class as special.
2177 */
2178 mc = m.mh.msg_class;
2179 if (mc == BFI_MC_IOC) {
2180 bfa_ioc_isr(ioc, &m);
2181 return;
2182 }
2183
2184 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2185 return;
2186
2187 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2188}
2189
2190void
2191bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2192{
2193 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2194}
2195
Jing Huanged969322010-07-08 19:45:56 -07002196void
2197bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2198{
2199 ioc->fcmode = BFA_TRUE;
2200 ioc->port_id = bfa_ioc_pcifn(ioc);
2201}
2202
Jing Huang5fbe25c2010-10-18 17:17:23 -07002203/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002204 * return true if IOC is disabled
2205 */
2206bfa_boolean_t
2207bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2208{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002209 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2210 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002211}
2212
Jing Huang5fbe25c2010-10-18 17:17:23 -07002213/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002214 * return true if IOC firmware is different.
2215 */
2216bfa_boolean_t
2217bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2218{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002219 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2220 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2221 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002222}
2223
2224#define bfa_ioc_state_disabled(__sm) \
2225 (((__sm) == BFI_IOC_UNINIT) || \
2226 ((__sm) == BFI_IOC_INITING) || \
2227 ((__sm) == BFI_IOC_HWINIT) || \
2228 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002229 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002230 ((__sm) == BFI_IOC_CFG_DISABLED))
2231
Jing Huang5fbe25c2010-10-18 17:17:23 -07002232/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002233 * Check if adapter is disabled -- both IOCs should be in a disabled
2234 * state.
2235 */
2236bfa_boolean_t
2237bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2238{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002239 u32 ioc_state;
Jing Huang53440262010-10-18 17:12:29 -07002240 void __iomem *rb = ioc->pcidev.pci_bar_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002241
2242 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2243 return BFA_FALSE;
2244
Jing Huang53440262010-10-18 17:12:29 -07002245 ioc_state = readl(rb + BFA_IOC0_STATE_REG);
Jing Huang7725ccf2009-09-23 17:46:15 -07002246 if (!bfa_ioc_state_disabled(ioc_state))
2247 return BFA_FALSE;
2248
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002249 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Jing Huang53440262010-10-18 17:12:29 -07002250 ioc_state = readl(rb + BFA_IOC1_STATE_REG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002251 if (!bfa_ioc_state_disabled(ioc_state))
2252 return BFA_FALSE;
2253 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002254
2255 return BFA_TRUE;
2256}
2257
Jing Huang8f4bfad2010-12-26 21:50:10 -08002258/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002259 * Reset IOC fwstate registers.
2260 */
2261void
2262bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2263{
2264 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2265 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2266}
2267
Jing Huang7725ccf2009-09-23 17:46:15 -07002268#define BFA_MFG_NAME "Brocade"
2269void
2270bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2271 struct bfa_adapter_attr_s *ad_attr)
2272{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002273 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002274
2275 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002276
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002277 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2278 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2279 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2280 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002281 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002282 sizeof(struct bfa_mfg_vpd_s));
2283
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002284 ad_attr->nports = bfa_ioc_get_nports(ioc);
2285 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002286
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002287 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2288 /* For now, model descr uses same model string */
2289 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002290
Jing Huanged969322010-07-08 19:45:56 -07002291 ad_attr->card_type = ioc_attr->card_type;
2292 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2293
Jing Huang7725ccf2009-09-23 17:46:15 -07002294 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2295 ad_attr->prototype = 1;
2296 else
2297 ad_attr->prototype = 0;
2298
Maggie Zhangf7f73812010-12-09 19:08:43 -08002299 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002300 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002301
2302 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2303 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2304 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2305 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002306
2307 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002308
2309 ad_attr->cna_capable = ioc->cna;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002310 ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna &&
2311 !ad_attr->is_mezz;
Jing Huang7725ccf2009-09-23 17:46:15 -07002312}
2313
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002314enum bfa_ioc_type_e
2315bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2316{
2317 if (!ioc->ctdev || ioc->fcmode)
2318 return BFA_IOC_TYPE_FC;
2319 else if (ioc->ioc_mc == BFI_MC_IOCFC)
2320 return BFA_IOC_TYPE_FCoE;
2321 else if (ioc->ioc_mc == BFI_MC_LL)
2322 return BFA_IOC_TYPE_LL;
2323 else {
Jing Huangd4b671c2010-12-26 21:46:35 -08002324 WARN_ON(ioc->ioc_mc != BFI_MC_LL);
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002325 return BFA_IOC_TYPE_LL;
2326 }
2327}
2328
Jing Huang7725ccf2009-09-23 17:46:15 -07002329void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002330bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2331{
Jing Huang6a18b162010-10-18 17:08:54 -07002332 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2333 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002334 (void *)ioc->attr->brcd_serialnum,
2335 BFA_ADAPTER_SERIAL_NUM_LEN);
2336}
2337
2338void
2339bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2340{
Jing Huang6a18b162010-10-18 17:08:54 -07002341 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2342 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002343}
2344
2345void
2346bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2347{
Jing Huangd4b671c2010-12-26 21:46:35 -08002348 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002349
Jing Huang6a18b162010-10-18 17:08:54 -07002350 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002351
2352 chip_rev[0] = 'R';
2353 chip_rev[1] = 'e';
2354 chip_rev[2] = 'v';
2355 chip_rev[3] = '-';
2356 chip_rev[4] = ioc->attr->asic_rev;
2357 chip_rev[5] = '\0';
2358}
2359
2360void
2361bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2362{
Jing Huang6a18b162010-10-18 17:08:54 -07002363 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2364 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002365 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002366}
2367
2368void
2369bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2370{
Jing Huang6a18b162010-10-18 17:08:54 -07002371 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2372 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002373}
2374
2375void
2376bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2377{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002378 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002379
Jing Huangd4b671c2010-12-26 21:46:35 -08002380 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002381 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002382
2383 ioc_attr = ioc->attr;
2384
Jing Huang5fbe25c2010-10-18 17:17:23 -07002385 /*
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002386 * model name
2387 */
Jing Huang6a18b162010-10-18 17:08:54 -07002388 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002389 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002390}
2391
2392enum bfa_ioc_state
2393bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2394{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002395 enum bfa_iocpf_state iocpf_st;
2396 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2397
2398 if (ioc_st == BFA_IOC_ENABLING ||
2399 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2400
2401 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2402
2403 switch (iocpf_st) {
2404 case BFA_IOCPF_SEMWAIT:
2405 ioc_st = BFA_IOC_SEMWAIT;
2406 break;
2407
2408 case BFA_IOCPF_HWINIT:
2409 ioc_st = BFA_IOC_HWINIT;
2410 break;
2411
2412 case BFA_IOCPF_FWMISMATCH:
2413 ioc_st = BFA_IOC_FWMISMATCH;
2414 break;
2415
2416 case BFA_IOCPF_FAIL:
2417 ioc_st = BFA_IOC_FAIL;
2418 break;
2419
2420 case BFA_IOCPF_INITFAIL:
2421 ioc_st = BFA_IOC_INITFAIL;
2422 break;
2423
2424 default:
2425 break;
2426 }
2427 }
2428
2429 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002430}
2431
2432void
Jing Huang7725ccf2009-09-23 17:46:15 -07002433bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2434{
Jing Huang6a18b162010-10-18 17:08:54 -07002435 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002436
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002437 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002438 ioc_attr->port_id = ioc->port_id;
2439
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002440 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002441
2442 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2443
2444 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2445 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002446 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002447}
2448
Jing Huang7725ccf2009-09-23 17:46:15 -07002449mac_t
2450bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2451{
Jing Huang15b64a82010-07-08 19:48:12 -07002452 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002453 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002454 */
2455 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002456 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002457 else
2458 return ioc->attr->mac;
2459}
2460
Jing Huang15b64a82010-07-08 19:48:12 -07002461mac_t
2462bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2463{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002464 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002465
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002466 m = ioc->attr->mfg_mac;
2467 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2468 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2469 else
2470 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2471 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002472
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002473 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002474}
2475
Jing Huang7725ccf2009-09-23 17:46:15 -07002476bfa_boolean_t
2477bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2478{
Jing Huang293f82d2010-07-08 19:45:20 -07002479 return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07002480}
2481
Jing Huang5fbe25c2010-10-18 17:17:23 -07002482/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002483 * Retrieve saved firmware trace from a prior IOC failure.
2484 */
2485bfa_status_t
2486bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2487{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002488 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002489
2490 if (ioc->dbg_fwsave_len == 0)
2491 return BFA_STATUS_ENOFSAVE;
2492
2493 tlen = *trclen;
2494 if (tlen > ioc->dbg_fwsave_len)
2495 tlen = ioc->dbg_fwsave_len;
2496
Jing Huang6a18b162010-10-18 17:08:54 -07002497 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002498 *trclen = tlen;
2499 return BFA_STATUS_OK;
2500}
2501
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002502
Jing Huang5fbe25c2010-10-18 17:17:23 -07002503/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002504 * Retrieve saved firmware trace from a prior IOC failure.
2505 */
2506bfa_status_t
2507bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2508{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002509 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2510 int tlen;
2511 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002512
2513 bfa_trc(ioc, *trclen);
2514
Jing Huang7725ccf2009-09-23 17:46:15 -07002515 tlen = *trclen;
2516 if (tlen > BFA_DBG_FWTRC_LEN)
2517 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002518
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002519 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2520 *trclen = tlen;
2521 return status;
2522}
Jing Huang7725ccf2009-09-23 17:46:15 -07002523
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002524static void
2525bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2526{
2527 struct bfa_mbox_cmd_s cmd;
2528 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002529
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002530 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2531 bfa_ioc_portid(ioc));
2532 req->ioc_class = ioc->ioc_mc;
2533 bfa_ioc_mbox_queue(ioc, &cmd);
2534}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002535
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002536static void
2537bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2538{
2539 u32 fwsync_iter = 1000;
2540
2541 bfa_ioc_send_fwsync(ioc);
2542
Jing Huang5fbe25c2010-10-18 17:17:23 -07002543 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002544 * After sending a fw sync mbox command wait for it to
2545 * take effect. We will not wait for a response because
2546 * 1. fw_sync mbox cmd doesn't have a response.
2547 * 2. Even if we implement that, interrupts might not
2548 * be enabled when we call this function.
2549 * So, just keep checking if any mbox cmd is pending, and
2550 * after waiting for a reasonable amount of time, go ahead.
2551 * It is possible that fw has crashed and the mbox command
2552 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002553 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002554 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2555 fwsync_iter--;
2556}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002557
Jing Huang5fbe25c2010-10-18 17:17:23 -07002558/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002559 * Dump firmware smem
2560 */
2561bfa_status_t
2562bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2563 u32 *offset, int *buflen)
2564{
2565 u32 loff;
2566 int dlen;
2567 bfa_status_t status;
2568 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002569
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002570 if (*offset >= smem_len) {
2571 *offset = *buflen = 0;
2572 return BFA_STATUS_EINVAL;
2573 }
2574
2575 loff = *offset;
2576 dlen = *buflen;
2577
Jing Huang5fbe25c2010-10-18 17:17:23 -07002578 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002579 * First smem read, sync smem before proceeding
2580 * No need to sync before reading every chunk.
2581 */
2582 if (loff == 0)
2583 bfa_ioc_fwsync(ioc);
2584
2585 if ((loff + dlen) >= smem_len)
2586 dlen = smem_len - loff;
2587
2588 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2589
2590 if (status != BFA_STATUS_OK) {
2591 *offset = *buflen = 0;
2592 return status;
2593 }
2594
2595 *offset += dlen;
2596
2597 if (*offset >= smem_len)
2598 *offset = 0;
2599
2600 *buflen = dlen;
2601
2602 return status;
2603}
2604
Jing Huang5fbe25c2010-10-18 17:17:23 -07002605/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002606 * Firmware statistics
2607 */
2608bfa_status_t
2609bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2610{
2611 u32 loff = BFI_IOC_FWSTATS_OFF + \
2612 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2613 int tlen;
2614 bfa_status_t status;
2615
2616 if (ioc->stats_busy) {
2617 bfa_trc(ioc, ioc->stats_busy);
2618 return BFA_STATUS_DEVBUSY;
2619 }
2620 ioc->stats_busy = BFA_TRUE;
2621
2622 tlen = sizeof(struct bfa_fw_stats_s);
2623 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2624
2625 ioc->stats_busy = BFA_FALSE;
2626 return status;
2627}
2628
2629bfa_status_t
2630bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2631{
2632 u32 loff = BFI_IOC_FWSTATS_OFF + \
2633 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2634 int tlen;
2635 bfa_status_t status;
2636
2637 if (ioc->stats_busy) {
2638 bfa_trc(ioc, ioc->stats_busy);
2639 return BFA_STATUS_DEVBUSY;
2640 }
2641 ioc->stats_busy = BFA_TRUE;
2642
2643 tlen = sizeof(struct bfa_fw_stats_s);
2644 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2645
2646 ioc->stats_busy = BFA_FALSE;
2647 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002648}
2649
Jing Huang5fbe25c2010-10-18 17:17:23 -07002650/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002651 * Save firmware trace if configured.
2652 */
2653static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002654bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002655{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002656 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002657
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002658 if (ioc->dbg_fwsave_once) {
2659 ioc->dbg_fwsave_once = BFA_FALSE;
2660 if (ioc->dbg_fwsave_len) {
2661 tlen = ioc->dbg_fwsave_len;
2662 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2663 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002664 }
2665}
2666
Jing Huang5fbe25c2010-10-18 17:17:23 -07002667/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002668 * Firmware failure detected. Start recovery actions.
2669 */
2670static void
2671bfa_ioc_recover(struct bfa_ioc_s *ioc)
2672{
Jing Huang7725ccf2009-09-23 17:46:15 -07002673 bfa_ioc_stats(ioc, ioc_hbfails);
2674 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2675}
2676
Jing Huang7725ccf2009-09-23 17:46:15 -07002677static void
Jing Huang07b28382010-07-08 19:59:24 -07002678bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002679{
Jing Huang07b28382010-07-08 19:59:24 -07002680 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2681 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002682}
2683
Jing Huang5fbe25c2010-10-18 17:17:23 -07002684/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002685 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002686 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002687static void
2688bfa_iocpf_timeout(void *ioc_arg)
2689{
2690 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2691
2692 bfa_trc(ioc, 0);
2693 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2694}
2695
2696static void
2697bfa_iocpf_sem_timeout(void *ioc_arg)
2698{
2699 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2700
2701 bfa_ioc_hw_sem_get(ioc);
2702}
2703
Jing Huang5fbe25c2010-10-18 17:17:23 -07002704/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002705 * bfa timer function
2706 */
2707void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002708bfa_timer_beat(struct bfa_timer_mod_s *mod)
2709{
2710 struct list_head *qh = &mod->timer_q;
2711 struct list_head *qe, *qe_next;
2712 struct bfa_timer_s *elem;
2713 struct list_head timedout_q;
2714
2715 INIT_LIST_HEAD(&timedout_q);
2716
2717 qe = bfa_q_next(qh);
2718
2719 while (qe != qh) {
2720 qe_next = bfa_q_next(qe);
2721
2722 elem = (struct bfa_timer_s *) qe;
2723 if (elem->timeout <= BFA_TIMER_FREQ) {
2724 elem->timeout = 0;
2725 list_del(&elem->qe);
2726 list_add_tail(&elem->qe, &timedout_q);
2727 } else {
2728 elem->timeout -= BFA_TIMER_FREQ;
2729 }
2730
2731 qe = qe_next; /* go to next elem */
2732 }
2733
2734 /*
2735 * Pop all the timeout entries
2736 */
2737 while (!list_empty(&timedout_q)) {
2738 bfa_q_deq(&timedout_q, &elem);
2739 elem->timercb(elem->arg);
2740 }
2741}
2742
Jing Huang5fbe25c2010-10-18 17:17:23 -07002743/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002744 * Should be called with lock protection
2745 */
2746void
2747bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2748 void (*timercb) (void *), void *arg, unsigned int timeout)
2749{
2750
Jing Huangd4b671c2010-12-26 21:46:35 -08002751 WARN_ON(timercb == NULL);
2752 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002753
2754 timer->timeout = timeout;
2755 timer->timercb = timercb;
2756 timer->arg = arg;
2757
2758 list_add_tail(&timer->qe, &mod->timer_q);
2759}
2760
Jing Huang5fbe25c2010-10-18 17:17:23 -07002761/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002762 * Should be called with lock protection
2763 */
2764void
2765bfa_timer_stop(struct bfa_timer_s *timer)
2766{
Jing Huangd4b671c2010-12-26 21:46:35 -08002767 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002768
2769 list_del(&timer->qe);
2770}