blob: 6c7e0339dda44d0d7029cd83bd2700950e1c49d2 [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))
Jing Huang45d7f0c2011-04-13 11:45:53 -070059#define bfa_ioc_sync_start(__ioc) \
60 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080061#define bfa_ioc_sync_join(__ioc) \
62 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
63#define bfa_ioc_sync_leave(__ioc) \
64 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
65#define bfa_ioc_sync_ack(__ioc) \
66 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
67#define bfa_ioc_sync_complete(__ioc) \
68 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070069
70#define bfa_ioc_mbox_cmd_pending(__ioc) \
71 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
Jing Huang53440262010-10-18 17:12:29 -070072 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070073
74bfa_boolean_t bfa_auto_recover = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070075
76/*
77 * forward declarations
78 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070079static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070080static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
81static void bfa_ioc_timeout(void *ioc);
82static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
83static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
84static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
85static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070086static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
87static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc);
88static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
89static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
90static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
91static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -080092static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc);
93static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070094static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -070095
Jing Huang7725ccf2009-09-23 17:46:15 -070096
Jing Huang5fbe25c2010-10-18 17:17:23 -070097/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070098 * IOC state machine definitions/declarations
Jing Huang7725ccf2009-09-23 17:46:15 -070099 */
100enum ioc_event {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101 IOC_E_RESET = 1, /* IOC reset request */
102 IOC_E_ENABLE = 2, /* IOC enable request */
103 IOC_E_DISABLE = 3, /* IOC disable request */
104 IOC_E_DETACH = 4, /* driver detach cleanup */
105 IOC_E_ENABLED = 5, /* f/w enabled */
106 IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
107 IOC_E_DISABLED = 7, /* f/w disabled */
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800108 IOC_E_INITFAILED = 8, /* failure notice by iocpf sm */
109 IOC_E_PFFAILED = 9, /* failure notice by iocpf sm */
110 IOC_E_HBFAIL = 10, /* heartbeat failure */
111 IOC_E_HWERROR = 11, /* hardware error interrupt */
112 IOC_E_TIMEOUT = 12, /* timeout */
Jing Huang7725ccf2009-09-23 17:46:15 -0700113};
114
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700115bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700116bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700117bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
118bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
119bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800120bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700121bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700122bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
123bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
124
125static struct bfa_sm_table_s ioc_sm_table[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700126 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Jing Huang7725ccf2009-09-23 17:46:15 -0700127 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700128 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Jing Huang7725ccf2009-09-23 17:46:15 -0700129 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
130 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800131 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700132 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700133 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
134 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
135};
136
Jing Huang5fbe25c2010-10-18 17:17:23 -0700137/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700138 * IOCPF state machine definitions/declarations
139 */
140
141#define bfa_iocpf_timer_start(__ioc) \
142 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
143 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
144#define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
145
146#define bfa_iocpf_recovery_timer_start(__ioc) \
147 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
148 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV_RECOVER)
149
150#define bfa_sem_timer_start(__ioc) \
151 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
152 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
153#define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
154
155/*
156 * Forward declareations for iocpf state machine
157 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700158static void bfa_iocpf_timeout(void *ioc_arg);
159static void bfa_iocpf_sem_timeout(void *ioc_arg);
160
Jing Huang5fbe25c2010-10-18 17:17:23 -0700161/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700162 * IOCPF state machine events
163 */
164enum iocpf_event {
165 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
166 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
167 IOCPF_E_STOP = 3, /* stop on driver detach */
168 IOCPF_E_FWREADY = 4, /* f/w initialization done */
169 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
170 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
171 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
172 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
173 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
174 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
175 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
176};
177
Jing Huang5fbe25c2010-10-18 17:17:23 -0700178/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700179 * IOCPF states
180 */
181enum bfa_iocpf_state {
182 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
183 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
184 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
185 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
186 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
187 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
188 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
189 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
190 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
191};
192
193bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
194bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
195bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
196bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
197bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
198bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
199bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800200bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
201 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700202bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800203bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700204bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
205bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800206bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
207 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700208bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
209
210static struct bfa_sm_table_s iocpf_sm_table[] = {
211 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
212 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
213 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
214 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
215 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
216 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
217 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800218 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700219 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800220 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700221 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
222 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800223 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700224 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
225};
226
Jing Huang5fbe25c2010-10-18 17:17:23 -0700227/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700228 * IOC State Machine
229 */
230
Jing Huang5fbe25c2010-10-18 17:17:23 -0700231/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700232 * Beginning state. IOC uninit state.
233 */
234
235static void
236bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
237{
238}
239
Jing Huang5fbe25c2010-10-18 17:17:23 -0700240/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700241 * IOC is in uninit state.
242 */
243static void
244bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
245{
246 bfa_trc(ioc, event);
247
248 switch (event) {
249 case IOC_E_RESET:
250 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
251 break;
252
253 default:
254 bfa_sm_fault(ioc, event);
255 }
256}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700257/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700258 * Reset entry actions -- initialize state machine
259 */
260static void
261bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
262{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700263 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700264}
265
Jing Huang5fbe25c2010-10-18 17:17:23 -0700266/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700267 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700268 */
269static void
270bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
271{
272 bfa_trc(ioc, event);
273
274 switch (event) {
275 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700276 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
277 break;
278
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700279 case IOC_E_DISABLE:
280 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700281 break;
282
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700283 case IOC_E_DETACH:
284 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700285 break;
286
287 default:
288 bfa_sm_fault(ioc, event);
289 }
290}
291
292
293static void
294bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
295{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800296 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700297}
298
Jing Huang5fbe25c2010-10-18 17:17:23 -0700299/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700300 * Host IOC function is being enabled, awaiting response from firmware.
301 * Semaphore is acquired.
302 */
303static void
304bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
305{
306 bfa_trc(ioc, event);
307
308 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700309 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700310 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
311 break;
312
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800313 case IOC_E_PFFAILED:
314 /* !!! fall through !!! */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700315 case IOC_E_HWERROR:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800316 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
317 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
318 if (event != IOC_E_PFFAILED)
319 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700320 break;
321
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322 case IOC_E_DISABLE:
323 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
324 break;
325
326 case IOC_E_DETACH:
327 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800328 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700329 break;
330
331 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700332 break;
333
334 default:
335 bfa_sm_fault(ioc, event);
336 }
337}
338
339
340static void
341bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
342{
343 bfa_ioc_timer_start(ioc);
344 bfa_ioc_send_getattr(ioc);
345}
346
Jing Huang5fbe25c2010-10-18 17:17:23 -0700347/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700348 * IOC configuration in progress. Timer is active.
349 */
350static void
351bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
352{
353 bfa_trc(ioc, event);
354
355 switch (event) {
356 case IOC_E_FWRSP_GETATTR:
357 bfa_ioc_timer_stop(ioc);
Jing Huang07b28382010-07-08 19:59:24 -0700358 bfa_ioc_check_attr_wwns(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700359 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
360 break;
361
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700362 break;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800363 case IOC_E_PFFAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700364 case IOC_E_HWERROR:
365 bfa_ioc_timer_stop(ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800366 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700367 case IOC_E_TIMEOUT:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800368 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
369 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
370 if (event != IOC_E_PFFAILED)
371 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700372 break;
373
374 case IOC_E_DISABLE:
375 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700376 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
377 break;
378
379 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700380 break;
381
382 default:
383 bfa_sm_fault(ioc, event);
384 }
385}
386
387
388static void
389bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
390{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700391 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
392
Jing Huang7725ccf2009-09-23 17:46:15 -0700393 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
394 bfa_ioc_hb_monitor(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800395 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700396}
397
398static void
399bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
400{
401 bfa_trc(ioc, event);
402
403 switch (event) {
404 case IOC_E_ENABLE:
405 break;
406
407 case IOC_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800408 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700409 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
410 break;
411
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800412 case IOC_E_PFFAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700413 case IOC_E_HWERROR:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800414 bfa_hb_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700415 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700416 case IOC_E_HBFAIL:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800417 bfa_ioc_fail_notify(ioc);
418
419 if (ioc->iocpf.auto_recover)
420 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
421 else
422 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
423
424 if (event != IOC_E_PFFAILED)
425 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700426 break;
427
428 default:
429 bfa_sm_fault(ioc, event);
430 }
431}
432
433
434static void
435bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
436{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700437 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Maggie Zhangf7f73812010-12-09 19:08:43 -0800438 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
Jing Huang88166242010-12-09 17:11:53 -0800439 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700440}
441
Jing Huang5fbe25c2010-10-18 17:17:23 -0700442/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700443 * IOC is being disabled
444 */
445static void
446bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
447{
448 bfa_trc(ioc, event);
449
450 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700451 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800452 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
453 break;
454
455 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700456 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700457 * No state change. Will move to disabled state
458 * after iocpf sm completes failure processing and
459 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700460 */
Maggie Zhangf7f73812010-12-09 19:08:43 -0800461 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700462 break;
463
464 default:
465 bfa_sm_fault(ioc, event);
466 }
467}
468
Jing Huang5fbe25c2010-10-18 17:17:23 -0700469/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700470 * IOC disable completion entry.
471 */
472static void
473bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
474{
475 bfa_ioc_disable_comp(ioc);
476}
477
478static void
479bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
480{
481 bfa_trc(ioc, event);
482
483 switch (event) {
484 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700485 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700486 break;
487
488 case IOC_E_DISABLE:
489 ioc->cbfn->disable_cbfn(ioc->bfa);
490 break;
491
Jing Huang7725ccf2009-09-23 17:46:15 -0700492 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700493 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800494 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700495 break;
496
497 default:
498 bfa_sm_fault(ioc, event);
499 }
500}
501
502
503static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800504bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700505{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800506 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700507}
508
Jing Huang5fbe25c2010-10-18 17:17:23 -0700509/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800510 * Hardware initialization retry.
Jing Huang7725ccf2009-09-23 17:46:15 -0700511 */
512static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800513bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700514{
515 bfa_trc(ioc, event);
516
517 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700518 case IOC_E_ENABLED:
519 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
520 break;
521
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800522 case IOC_E_PFFAILED:
523 case IOC_E_HWERROR:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700524 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800525 * Initialization retry failed.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700526 */
527 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800528 if (event != IOC_E_PFFAILED)
529 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
530 break;
531
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800532 case IOC_E_INITFAILED:
533 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
534 break;
535
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800536 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700537 break;
538
Jing Huang7725ccf2009-09-23 17:46:15 -0700539 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700540 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700541 break;
542
543 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700544 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800545 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700546 break;
547
548 default:
549 bfa_sm_fault(ioc, event);
550 }
551}
552
553
554static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700555bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700556{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800557 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700558}
559
Jing Huang5fbe25c2010-10-18 17:17:23 -0700560/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700561 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700562 */
563static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700564bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700565{
566 bfa_trc(ioc, event);
567
568 switch (event) {
569
570 case IOC_E_ENABLE:
571 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
572 break;
573
574 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700575 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700576 break;
577
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800578 case IOC_E_DETACH:
579 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
580 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
581 break;
582
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800583 case IOC_E_HWERROR:
584 /*
585 * HB failure notification, ignore.
586 */
587 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 default:
589 bfa_sm_fault(ioc, event);
590 }
591}
592
Jing Huang5fbe25c2010-10-18 17:17:23 -0700593/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700594 * IOCPF State Machine
595 */
596
Jing Huang5fbe25c2010-10-18 17:17:23 -0700597/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700598 * Reset entry actions -- initialize state machine
599 */
600static void
601bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
602{
603 iocpf->retry_count = 0;
604 iocpf->auto_recover = bfa_auto_recover;
605}
606
Jing Huang5fbe25c2010-10-18 17:17:23 -0700607/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700608 * Beginning state. IOC is in reset state.
609 */
610static void
611bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
612{
613 struct bfa_ioc_s *ioc = iocpf->ioc;
614
615 bfa_trc(ioc, event);
616
617 switch (event) {
618 case IOCPF_E_ENABLE:
619 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
620 break;
621
622 case IOCPF_E_STOP:
623 break;
624
625 default:
626 bfa_sm_fault(ioc, event);
627 }
628}
629
Jing Huang5fbe25c2010-10-18 17:17:23 -0700630/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700631 * Semaphore should be acquired for version check.
632 */
633static void
634bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
635{
636 bfa_ioc_hw_sem_get(iocpf->ioc);
637}
638
Jing Huang5fbe25c2010-10-18 17:17:23 -0700639/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700640 * Awaiting h/w semaphore to continue with version check.
641 */
642static void
643bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
644{
645 struct bfa_ioc_s *ioc = iocpf->ioc;
646
647 bfa_trc(ioc, event);
648
649 switch (event) {
650 case IOCPF_E_SEMLOCKED:
651 if (bfa_ioc_firmware_lock(ioc)) {
Jing Huang45d7f0c2011-04-13 11:45:53 -0700652 if (bfa_ioc_sync_start(ioc)) {
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800653 iocpf->retry_count = 0;
654 bfa_ioc_sync_join(ioc);
655 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
656 } else {
657 bfa_ioc_firmware_unlock(ioc);
658 writel(1, ioc->ioc_regs.ioc_sem_reg);
659 bfa_sem_timer_start(ioc);
660 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700661 } else {
Maggie Zhangf7f73812010-12-09 19:08:43 -0800662 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700663 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
664 }
665 break;
666
667 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800668 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700669 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800670 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700671 break;
672
673 case IOCPF_E_STOP:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800674 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700675 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
676 break;
677
678 default:
679 bfa_sm_fault(ioc, event);
680 }
681}
682
Jing Huang5fbe25c2010-10-18 17:17:23 -0700683/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700684 * Notify enable completion callback.
685 */
686static void
687bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
688{
689 /*
690 * Call only the first time sm enters fwmismatch state.
691 */
692 if (iocpf->retry_count == 0)
693 bfa_ioc_pf_fwmismatch(iocpf->ioc);
694
695 iocpf->retry_count++;
696 bfa_iocpf_timer_start(iocpf->ioc);
697}
698
Jing Huang5fbe25c2010-10-18 17:17:23 -0700699/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700700 * Awaiting firmware version match.
701 */
702static void
703bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
704{
705 struct bfa_ioc_s *ioc = iocpf->ioc;
706
707 bfa_trc(ioc, event);
708
709 switch (event) {
710 case IOCPF_E_TIMEOUT:
711 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
712 break;
713
714 case IOCPF_E_DISABLE:
715 bfa_iocpf_timer_stop(ioc);
716 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800717 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700718 break;
719
720 case IOCPF_E_STOP:
721 bfa_iocpf_timer_stop(ioc);
722 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
723 break;
724
725 default:
726 bfa_sm_fault(ioc, event);
727 }
728}
729
Jing Huang5fbe25c2010-10-18 17:17:23 -0700730/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700731 * Request for semaphore.
732 */
733static void
734bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
735{
736 bfa_ioc_hw_sem_get(iocpf->ioc);
737}
738
Jing Huang5fbe25c2010-10-18 17:17:23 -0700739/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700740 * Awaiting semaphore for h/w initialzation.
741 */
742static void
743bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
744{
745 struct bfa_ioc_s *ioc = iocpf->ioc;
746
747 bfa_trc(ioc, event);
748
749 switch (event) {
750 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800751 if (bfa_ioc_sync_complete(ioc)) {
752 bfa_ioc_sync_join(ioc);
753 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
754 } else {
755 writel(1, ioc->ioc_regs.ioc_sem_reg);
756 bfa_sem_timer_start(ioc);
757 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700758 break;
759
760 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800761 bfa_sem_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800762 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700763 break;
764
765 default:
766 bfa_sm_fault(ioc, event);
767 }
768}
769
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700770static void
771bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
772{
773 bfa_iocpf_timer_start(iocpf->ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800774 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700775}
776
Jing Huang5fbe25c2010-10-18 17:17:23 -0700777/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700778 * Hardware is being initialized. Interrupts are enabled.
779 * Holding hardware semaphore lock.
780 */
781static void
782bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
783{
784 struct bfa_ioc_s *ioc = iocpf->ioc;
785
786 bfa_trc(ioc, event);
787
788 switch (event) {
789 case IOCPF_E_FWREADY:
790 bfa_iocpf_timer_stop(ioc);
791 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
792 break;
793
794 case IOCPF_E_INITFAIL:
795 bfa_iocpf_timer_stop(ioc);
796 /*
797 * !!! fall through !!!
798 */
799
800 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800801 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700802 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800803 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800804 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700805 break;
806
807 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700808 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800809 bfa_ioc_sync_leave(ioc);
810 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
812 break;
813
814 default:
815 bfa_sm_fault(ioc, event);
816 }
817}
818
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700819static void
820bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
821{
822 bfa_iocpf_timer_start(iocpf->ioc);
823 bfa_ioc_send_enable(iocpf->ioc);
824}
825
Jing Huang5fbe25c2010-10-18 17:17:23 -0700826/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700827 * Host IOC function is being enabled, awaiting response from firmware.
828 * Semaphore is acquired.
829 */
830static void
831bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
832{
833 struct bfa_ioc_s *ioc = iocpf->ioc;
834
835 bfa_trc(ioc, event);
836
837 switch (event) {
838 case IOCPF_E_FWRSP_ENABLE:
839 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800840 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700841 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
842 break;
843
844 case IOCPF_E_INITFAIL:
845 bfa_iocpf_timer_stop(ioc);
846 /*
847 * !!! fall through !!!
848 */
849
850 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800851 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700852 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800853 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800854 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700855 break;
856
857 case IOCPF_E_DISABLE:
858 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800859 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700860 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
861 break;
862
863 case IOCPF_E_FWREADY:
864 bfa_ioc_send_enable(ioc);
865 break;
866
867 default:
868 bfa_sm_fault(ioc, event);
869 }
870}
871
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700872static void
873bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
874{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800875 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700876}
877
878static void
879bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
880{
881 struct bfa_ioc_s *ioc = iocpf->ioc;
882
883 bfa_trc(ioc, event);
884
885 switch (event) {
886 case IOCPF_E_DISABLE:
887 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
888 break;
889
890 case IOCPF_E_GETATTRFAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800891 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700892 break;
893
894 case IOCPF_E_FAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800895 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700896 break;
897
898 case IOCPF_E_FWREADY:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800899 if (bfa_ioc_is_operational(ioc)) {
900 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
901 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
902 } else {
903 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
904 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
905 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700906 break;
907
908 default:
909 bfa_sm_fault(ioc, event);
910 }
911}
912
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700913static void
914bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
915{
916 bfa_iocpf_timer_start(iocpf->ioc);
917 bfa_ioc_send_disable(iocpf->ioc);
918}
919
Jing Huang5fbe25c2010-10-18 17:17:23 -0700920/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700921 * IOC is being disabled
922 */
923static void
924bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
925{
926 struct bfa_ioc_s *ioc = iocpf->ioc;
927
928 bfa_trc(ioc, event);
929
930 switch (event) {
931 case IOCPF_E_FWRSP_DISABLE:
932 case IOCPF_E_FWREADY:
933 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800934 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700935 break;
936
937 case IOCPF_E_FAIL:
938 bfa_iocpf_timer_stop(ioc);
939 /*
940 * !!! fall through !!!
941 */
942
943 case IOCPF_E_TIMEOUT:
Jing Huang53440262010-10-18 17:12:29 -0700944 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800945 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700946 break;
947
948 case IOCPF_E_FWRSP_ENABLE:
949 break;
950
951 default:
952 bfa_sm_fault(ioc, event);
953 }
954}
955
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800956static void
957bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
958{
959 bfa_ioc_hw_sem_get(iocpf->ioc);
960}
961
Jing Huang8f4bfad2010-12-26 21:50:10 -0800962/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800963 * IOC hb ack request is being removed.
964 */
965static void
966bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
967{
968 struct bfa_ioc_s *ioc = iocpf->ioc;
969
970 bfa_trc(ioc, event);
971
972 switch (event) {
973 case IOCPF_E_SEMLOCKED:
974 bfa_ioc_sync_leave(ioc);
975 writel(1, ioc->ioc_regs.ioc_sem_reg);
976 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
977 break;
978
979 case IOCPF_E_FAIL:
980 break;
981
982 default:
983 bfa_sm_fault(ioc, event);
984 }
985}
986
Jing Huang5fbe25c2010-10-18 17:17:23 -0700987/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700988 * IOC disable completion entry.
989 */
990static void
991bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
992{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800993 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700994}
995
996static void
997bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
998{
999 struct bfa_ioc_s *ioc = iocpf->ioc;
1000
1001 bfa_trc(ioc, event);
1002
1003 switch (event) {
1004 case IOCPF_E_ENABLE:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001005 iocpf->retry_count = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001006 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1007 break;
1008
1009 case IOCPF_E_STOP:
1010 bfa_ioc_firmware_unlock(ioc);
1011 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1012 break;
1013
1014 default:
1015 bfa_sm_fault(ioc, event);
1016 }
1017}
1018
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001019static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001020bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1021{
1022 bfa_ioc_hw_sem_get(iocpf->ioc);
1023}
1024
Jing Huang8f4bfad2010-12-26 21:50:10 -08001025/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001026 * Hardware initialization failed.
1027 */
1028static void
1029bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1030{
1031 struct bfa_ioc_s *ioc = iocpf->ioc;
1032
1033 bfa_trc(ioc, event);
1034
1035 switch (event) {
1036 case IOCPF_E_SEMLOCKED:
1037 bfa_ioc_notify_fail(ioc);
1038 bfa_ioc_sync_ack(ioc);
1039 iocpf->retry_count++;
1040 if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) {
1041 bfa_ioc_sync_leave(ioc);
1042 writel(1, ioc->ioc_regs.ioc_sem_reg);
1043 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
1044 } else {
1045 if (bfa_ioc_sync_complete(ioc))
1046 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1047 else {
1048 writel(1, ioc->ioc_regs.ioc_sem_reg);
1049 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1050 }
1051 }
1052 break;
1053
1054 case IOCPF_E_DISABLE:
1055 bfa_sem_timer_stop(ioc);
1056 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1057 break;
1058
1059 case IOCPF_E_STOP:
1060 bfa_sem_timer_stop(ioc);
1061 bfa_ioc_firmware_unlock(ioc);
1062 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1063 break;
1064
1065 case IOCPF_E_FAIL:
1066 break;
1067
1068 default:
1069 bfa_sm_fault(ioc, event);
1070 }
1071}
1072
1073static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001074bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1075{
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001076 bfa_fsm_send_event(iocpf->ioc, IOC_E_INITFAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001077}
1078
Jing Huang5fbe25c2010-10-18 17:17:23 -07001079/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001080 * Hardware initialization failed.
1081 */
1082static void
1083bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1084{
1085 struct bfa_ioc_s *ioc = iocpf->ioc;
1086
1087 bfa_trc(ioc, event);
1088
1089 switch (event) {
1090 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001091 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1092 break;
1093
1094 case IOCPF_E_STOP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001095 bfa_ioc_firmware_unlock(ioc);
1096 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1097 break;
1098
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001099 default:
1100 bfa_sm_fault(ioc, event);
1101 }
1102}
1103
1104static void
1105bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1106{
Jing Huang8f4bfad2010-12-26 21:50:10 -08001107 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001108 * Mark IOC as failed in hardware and stop firmware.
1109 */
1110 bfa_ioc_lpu_stop(iocpf->ioc);
1111
Jing Huang8f4bfad2010-12-26 21:50:10 -08001112 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001113 * Flush any queued up mailbox requests.
1114 */
1115 bfa_ioc_mbox_hbfail(iocpf->ioc);
1116
1117 bfa_ioc_hw_sem_get(iocpf->ioc);
1118}
1119
1120static void
1121bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1122{
1123 struct bfa_ioc_s *ioc = iocpf->ioc;
1124
1125 bfa_trc(ioc, event);
1126
1127 switch (event) {
1128 case IOCPF_E_SEMLOCKED:
1129 iocpf->retry_count = 0;
1130 bfa_ioc_sync_ack(ioc);
1131 bfa_ioc_notify_fail(ioc);
1132 if (!iocpf->auto_recover) {
1133 bfa_ioc_sync_leave(ioc);
1134 writel(1, ioc->ioc_regs.ioc_sem_reg);
1135 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1136 } else {
1137 if (bfa_ioc_sync_complete(ioc))
1138 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1139 else {
1140 writel(1, ioc->ioc_regs.ioc_sem_reg);
1141 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1142 }
1143 }
1144 break;
1145
1146 case IOCPF_E_DISABLE:
1147 bfa_sem_timer_stop(ioc);
1148 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1149 break;
1150
1151 case IOCPF_E_FAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001152 break;
1153
1154 default:
1155 bfa_sm_fault(ioc, event);
1156 }
1157}
1158
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001159static void
1160bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1161{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001162}
1163
Jing Huang5fbe25c2010-10-18 17:17:23 -07001164/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001165 * IOC is in failed state.
1166 */
1167static void
1168bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1169{
1170 struct bfa_ioc_s *ioc = iocpf->ioc;
1171
1172 bfa_trc(ioc, event);
1173
1174 switch (event) {
1175 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001176 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1177 break;
1178
Jing Huang7725ccf2009-09-23 17:46:15 -07001179 default:
1180 bfa_sm_fault(ioc, event);
1181 }
1182}
1183
Jing Huang5fbe25c2010-10-18 17:17:23 -07001184/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001185 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001186 */
1187
1188static void
1189bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1190{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001191 struct list_head *qe;
1192 struct bfa_ioc_hbfail_notify_s *notify;
Jing Huang7725ccf2009-09-23 17:46:15 -07001193
1194 ioc->cbfn->disable_cbfn(ioc->bfa);
1195
Jing Huang5fbe25c2010-10-18 17:17:23 -07001196 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001197 * Notify common modules registered for notification.
1198 */
1199 list_for_each(qe, &ioc->hb_notify_q) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001200 notify = (struct bfa_ioc_hbfail_notify_s *) qe;
Jing Huang7725ccf2009-09-23 17:46:15 -07001201 notify->cbfn(notify->cbarg);
1202 }
1203}
1204
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001205bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001206bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001207{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001208 u32 r32;
1209 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001210#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001211
Jing Huang53440262010-10-18 17:12:29 -07001212 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001213
1214 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001215 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001216 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001217 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001218 }
1219
1220 if (r32 == 0)
1221 return BFA_TRUE;
1222
Jing Huangd4b671c2010-12-26 21:46:35 -08001223 WARN_ON(cnt >= BFA_SEM_SPINCNT);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001224 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001225}
1226
Jing Huang7725ccf2009-09-23 17:46:15 -07001227static void
1228bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1229{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001230 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001231
Jing Huang5fbe25c2010-10-18 17:17:23 -07001232 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001233 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001234 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001235 */
Jing Huang53440262010-10-18 17:12:29 -07001236 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001237 if (r32 == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001238 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001239 return;
1240 }
1241
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001242 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001243}
1244
Jing Huang5fbe25c2010-10-18 17:17:23 -07001245/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001246 * Initialize LPU local memory (aka secondary memory / SRAM)
1247 */
1248static void
1249bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1250{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001251 u32 pss_ctl;
1252 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001253#define PSS_LMEM_INIT_TIME 10000
1254
Jing Huang53440262010-10-18 17:12:29 -07001255 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001256 pss_ctl &= ~__PSS_LMEM_RESET;
1257 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001258
1259 /*
1260 * i2c workaround 12.5khz clock
1261 */
1262 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001263 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001264
Jing Huang5fbe25c2010-10-18 17:17:23 -07001265 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001266 * wait for memory initialization to be complete
1267 */
1268 i = 0;
1269 do {
Jing Huang53440262010-10-18 17:12:29 -07001270 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001271 i++;
1272 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1273
Jing Huang5fbe25c2010-10-18 17:17:23 -07001274 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001275 * If memory initialization is not successful, IOC timeout will catch
1276 * such failures.
1277 */
Jing Huangd4b671c2010-12-26 21:46:35 -08001278 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
Jing Huang7725ccf2009-09-23 17:46:15 -07001279 bfa_trc(ioc, pss_ctl);
1280
1281 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001282 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001283}
1284
1285static void
1286bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1287{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001288 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001289
Jing Huang5fbe25c2010-10-18 17:17:23 -07001290 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001291 * Take processor out of reset.
1292 */
Jing Huang53440262010-10-18 17:12:29 -07001293 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001294 pss_ctl &= ~__PSS_LPU0_RESET;
1295
Jing Huang53440262010-10-18 17:12:29 -07001296 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001297}
1298
1299static void
1300bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1301{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001302 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001303
Jing Huang5fbe25c2010-10-18 17:17:23 -07001304 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001305 * Put processors in reset.
1306 */
Jing Huang53440262010-10-18 17:12:29 -07001307 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001308 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1309
Jing Huang53440262010-10-18 17:12:29 -07001310 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001311}
1312
Jing Huang5fbe25c2010-10-18 17:17:23 -07001313/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001314 * Get driver and firmware versions.
1315 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001316void
Jing Huang7725ccf2009-09-23 17:46:15 -07001317bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1318{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001319 u32 pgnum, pgoff;
1320 u32 loff = 0;
1321 int i;
1322 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001323
Maggie Zhangf7f73812010-12-09 19:08:43 -08001324 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1325 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang53440262010-10-18 17:12:29 -07001326 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001327
1328 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1329 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001330 fwsig[i] =
1331 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001332 loff += sizeof(u32);
1333 }
1334}
1335
Jing Huang5fbe25c2010-10-18 17:17:23 -07001336/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001337 * Returns TRUE if same.
1338 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001339bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001340bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1341{
1342 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001343 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001344
Jing Huang293f82d2010-07-08 19:45:20 -07001345 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001346 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001347
1348 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1349 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1350 bfa_trc(ioc, i);
1351 bfa_trc(ioc, fwhdr->md5sum[i]);
1352 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1353 return BFA_FALSE;
1354 }
1355 }
1356
1357 bfa_trc(ioc, fwhdr->md5sum[0]);
1358 return BFA_TRUE;
1359}
1360
Jing Huang5fbe25c2010-10-18 17:17:23 -07001361/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001362 * Return true if current running version is valid. Firmware signature and
1363 * execution context (driver/bios) must match.
1364 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001365static bfa_boolean_t
1366bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001367{
1368 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1369
Jing Huang7725ccf2009-09-23 17:46:15 -07001370 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001371 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001372 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001373
1374 if (fwhdr.signature != drv_fwhdr->signature) {
1375 bfa_trc(ioc, fwhdr.signature);
1376 bfa_trc(ioc, drv_fwhdr->signature);
1377 return BFA_FALSE;
1378 }
1379
Jing Huang53440262010-10-18 17:12:29 -07001380 if (swab32(fwhdr.param) != boot_env) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001381 bfa_trc(ioc, fwhdr.param);
1382 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001383 return BFA_FALSE;
1384 }
1385
1386 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1387}
1388
Jing Huang5fbe25c2010-10-18 17:17:23 -07001389/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001390 * Conditionally flush any pending message from firmware at start.
1391 */
1392static void
1393bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1394{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001395 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001396
Jing Huang53440262010-10-18 17:12:29 -07001397 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001398 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001399 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001400}
1401
Jing Huang7725ccf2009-09-23 17:46:15 -07001402static void
1403bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1404{
1405 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001406 bfa_boolean_t fwvalid;
1407 u32 boot_type;
1408 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001409
Jing Huang53440262010-10-18 17:12:29 -07001410 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001411
1412 if (force)
1413 ioc_fwstate = BFI_IOC_UNINIT;
1414
1415 bfa_trc(ioc, ioc_fwstate);
1416
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001417 boot_type = BFI_BOOT_TYPE_NORMAL;
1418 boot_env = BFI_BOOT_LOADER_OS;
1419
Jing Huang5fbe25c2010-10-18 17:17:23 -07001420 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001421 * check if firmware is valid
1422 */
1423 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001424 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001425
1426 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001427 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001428 return;
1429 }
1430
Jing Huang5fbe25c2010-10-18 17:17:23 -07001431 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001432 * If hardware initialization is in progress (initialized by other IOC),
1433 * just wait for an initialization completion interrupt.
1434 */
1435 if (ioc_fwstate == BFI_IOC_INITING) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001436 ioc->cbfn->reset_cbfn(ioc->bfa);
1437 return;
1438 }
1439
Jing Huang5fbe25c2010-10-18 17:17:23 -07001440 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001441 * If IOC function is disabled and firmware version is same,
1442 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001443 *
1444 * If option rom, IOC must not be in operational state. With
1445 * convergence, IOC will be in operational state when 2nd driver
1446 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001447 */
Jing Huang8f4bfad2010-12-26 21:50:10 -08001448 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001449
Jing Huang5fbe25c2010-10-18 17:17:23 -07001450 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001451 * When using MSI-X any pending firmware ready event should
1452 * be flushed. Otherwise MSI-X interrupts are not delivered.
1453 */
1454 bfa_ioc_msgflush(ioc);
1455 ioc->cbfn->reset_cbfn(ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001456 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001457 return;
1458 }
1459
Jing Huang5fbe25c2010-10-18 17:17:23 -07001460 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001461 * Initialize the h/w for any other states.
1462 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001463 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001464}
1465
1466static void
1467bfa_ioc_timeout(void *ioc_arg)
1468{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001469 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001470
1471 bfa_trc(ioc, 0);
1472 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1473}
1474
1475void
1476bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1477{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001478 u32 *msgp = (u32 *) ioc_msg;
1479 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001480
1481 bfa_trc(ioc, msgp[0]);
1482 bfa_trc(ioc, len);
1483
Jing Huangd4b671c2010-12-26 21:46:35 -08001484 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
Jing Huang7725ccf2009-09-23 17:46:15 -07001485
1486 /*
1487 * first write msg to mailbox registers
1488 */
1489 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001490 writel(cpu_to_le32(msgp[i]),
1491 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001492
1493 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001494 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001495
1496 /*
1497 * write 1 to mailbox CMD to trigger LPU event
1498 */
Jing Huang53440262010-10-18 17:12:29 -07001499 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1500 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001501}
1502
1503static void
1504bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1505{
1506 struct bfi_ioc_ctrl_req_s enable_req;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001507 struct timeval tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001508
1509 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1510 bfa_ioc_portid(ioc));
1511 enable_req.ioc_class = ioc->ioc_mc;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001512 do_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001513 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001514 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1515}
1516
1517static void
1518bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1519{
1520 struct bfi_ioc_ctrl_req_s disable_req;
1521
1522 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1523 bfa_ioc_portid(ioc));
1524 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1525}
1526
1527static void
1528bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1529{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001530 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001531
1532 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1533 bfa_ioc_portid(ioc));
1534 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1535 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1536}
1537
1538static void
1539bfa_ioc_hb_check(void *cbarg)
1540{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001541 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001542 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001543
Jing Huang53440262010-10-18 17:12:29 -07001544 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001545 if (ioc->hb_count == hb_count) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001546 bfa_ioc_recover(ioc);
1547 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001548 } else {
1549 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001550 }
1551
1552 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001553 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001554}
1555
1556static void
1557bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1558{
Jing Huang53440262010-10-18 17:12:29 -07001559 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001560 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001561}
1562
Jing Huang5fbe25c2010-10-18 17:17:23 -07001563/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001564 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001565 */
1566static void
1567bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001568 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001569{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001570 u32 *fwimg;
1571 u32 pgnum, pgoff;
1572 u32 loff = 0;
1573 u32 chunkno = 0;
1574 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001575
Jing Huang5fbe25c2010-10-18 17:17:23 -07001576 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001577 * Initialize LMEM first before code download
1578 */
1579 bfa_ioc_lmem_init(ioc);
1580
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001581 bfa_trc(ioc, bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
1582 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001583
Maggie Zhangf7f73812010-12-09 19:08:43 -08001584 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1585 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001586
Jing Huang53440262010-10-18 17:12:29 -07001587 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001588
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001589 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001590
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001591 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1592 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001593 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001594 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001595 }
1596
Jing Huang5fbe25c2010-10-18 17:17:23 -07001597 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001598 * write smem
1599 */
1600 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001601 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001602
1603 loff += sizeof(u32);
1604
Jing Huang5fbe25c2010-10-18 17:17:23 -07001605 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001606 * handle page offset wrap around
1607 */
1608 loff = PSS_SMEM_PGOFF(loff);
1609 if (loff == 0) {
1610 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001611 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001612 }
1613 }
1614
Maggie Zhangf7f73812010-12-09 19:08:43 -08001615 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1616 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001617
1618 /*
1619 * Set boot type and boot param at the end.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001620 */
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001621 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001622 swab32(boot_type));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001623 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001624 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001625}
1626
Jing Huang7725ccf2009-09-23 17:46:15 -07001627
Jing Huang5fbe25c2010-10-18 17:17:23 -07001628/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001629 * Update BFA configuration from firmware configuration.
1630 */
1631static void
1632bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1633{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001634 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001635
Jing Huangba816ea2010-10-18 17:10:50 -07001636 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1637 attr->card_type = be32_to_cpu(attr->card_type);
1638 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Jing Huang7725ccf2009-09-23 17:46:15 -07001639
1640 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1641}
1642
Jing Huang5fbe25c2010-10-18 17:17:23 -07001643/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001644 * Attach time initialization of mbox logic.
1645 */
1646static void
1647bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1648{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001649 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1650 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001651
1652 INIT_LIST_HEAD(&mod->cmd_q);
1653 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1654 mod->mbhdlr[mc].cbfn = NULL;
1655 mod->mbhdlr[mc].cbarg = ioc->bfa;
1656 }
1657}
1658
Jing Huang5fbe25c2010-10-18 17:17:23 -07001659/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001660 * Mbox poll timer -- restarts any pending mailbox requests.
1661 */
1662static void
1663bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1664{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001665 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1666 struct bfa_mbox_cmd_s *cmd;
1667 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001668
Jing Huang5fbe25c2010-10-18 17:17:23 -07001669 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001670 * If no command pending, do nothing
1671 */
1672 if (list_empty(&mod->cmd_q))
1673 return;
1674
Jing Huang5fbe25c2010-10-18 17:17:23 -07001675 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001676 * If previous command is not yet fetched by firmware, do nothing
1677 */
Jing Huang53440262010-10-18 17:12:29 -07001678 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001679 if (stat)
1680 return;
1681
Jing Huang5fbe25c2010-10-18 17:17:23 -07001682 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001683 * Enqueue command to firmware.
1684 */
1685 bfa_q_deq(&mod->cmd_q, &cmd);
1686 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1687}
1688
Jing Huang5fbe25c2010-10-18 17:17:23 -07001689/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001690 * Cleanup any pending requests.
1691 */
1692static void
1693bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
1694{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001695 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1696 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001697
1698 while (!list_empty(&mod->cmd_q))
1699 bfa_q_deq(&mod->cmd_q, &cmd);
1700}
1701
Jing Huang5fbe25c2010-10-18 17:17:23 -07001702/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001703 * Read data from SMEM to host through PCI memmap
1704 *
1705 * @param[in] ioc memory for IOC
1706 * @param[in] tbuf app memory to store data from smem
1707 * @param[in] soff smem offset
1708 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001709 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001710static bfa_status_t
1711bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1712{
Maggie50444a32010-11-29 18:26:32 -08001713 u32 pgnum, loff;
1714 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001715 int i, len;
1716 u32 *buf = tbuf;
1717
Maggie Zhangf7f73812010-12-09 19:08:43 -08001718 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1719 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001720 bfa_trc(ioc, pgnum);
1721 bfa_trc(ioc, loff);
1722 bfa_trc(ioc, sz);
1723
1724 /*
1725 * Hold semaphore to serialize pll init and fwtrc.
1726 */
1727 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1728 bfa_trc(ioc, 0);
1729 return BFA_STATUS_FAILED;
1730 }
1731
Jing Huang53440262010-10-18 17:12:29 -07001732 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001733
1734 len = sz/sizeof(u32);
1735 bfa_trc(ioc, len);
1736 for (i = 0; i < len; i++) {
1737 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001738 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001739 loff += sizeof(u32);
1740
Jing Huang5fbe25c2010-10-18 17:17:23 -07001741 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001742 * handle page offset wrap around
1743 */
1744 loff = PSS_SMEM_PGOFF(loff);
1745 if (loff == 0) {
1746 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001747 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001748 }
1749 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001750 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1751 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001752 /*
1753 * release semaphore.
1754 */
Maggie Zhangf7f73812010-12-09 19:08:43 -08001755 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001756
1757 bfa_trc(ioc, pgnum);
1758 return BFA_STATUS_OK;
1759}
1760
Jing Huang5fbe25c2010-10-18 17:17:23 -07001761/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001762 * Clear SMEM data from host through PCI memmap
1763 *
1764 * @param[in] ioc memory for IOC
1765 * @param[in] soff smem offset
1766 * @param[in] sz size of smem in bytes
1767 */
1768static bfa_status_t
1769bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1770{
1771 int i, len;
1772 u32 pgnum, loff;
1773
Maggie Zhangf7f73812010-12-09 19:08:43 -08001774 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1775 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001776 bfa_trc(ioc, pgnum);
1777 bfa_trc(ioc, loff);
1778 bfa_trc(ioc, sz);
1779
1780 /*
1781 * Hold semaphore to serialize pll init and fwtrc.
1782 */
1783 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1784 bfa_trc(ioc, 0);
1785 return BFA_STATUS_FAILED;
1786 }
1787
Jing Huang53440262010-10-18 17:12:29 -07001788 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001789
1790 len = sz/sizeof(u32); /* len in words */
1791 bfa_trc(ioc, len);
1792 for (i = 0; i < len; i++) {
1793 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1794 loff += sizeof(u32);
1795
Jing Huang5fbe25c2010-10-18 17:17:23 -07001796 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001797 * handle page offset wrap around
1798 */
1799 loff = PSS_SMEM_PGOFF(loff);
1800 if (loff == 0) {
1801 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001802 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001803 }
1804 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001805 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1806 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001807
1808 /*
1809 * release semaphore.
1810 */
Maggie Zhangf7f73812010-12-09 19:08:43 -08001811 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001812 bfa_trc(ioc, pgnum);
1813 return BFA_STATUS_OK;
1814}
1815
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001816static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001817bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1818{
1819 struct list_head *qe;
1820 struct bfa_ioc_hbfail_notify_s *notify;
1821 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1822
Jing Huang8f4bfad2010-12-26 21:50:10 -08001823 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001824 * Notify driver and common modules registered for notification.
1825 */
1826 ioc->cbfn->hbfail_cbfn(ioc->bfa);
1827 list_for_each(qe, &ioc->hb_notify_q) {
1828 notify = (struct bfa_ioc_hbfail_notify_s *) qe;
1829 notify->cbfn(notify->cbarg);
1830 }
1831
1832 bfa_ioc_debug_save_ftrc(ioc);
1833
1834 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1835 "Heart Beat of IOC has failed\n");
1836
1837}
1838
1839static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001840bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1841{
1842 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001843 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001844 * Provide enable completion callback.
1845 */
1846 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001847 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001848 "Running firmware version is incompatible "
1849 "with the driver version\n");
1850}
1851
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001852bfa_status_t
1853bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1854{
1855
1856 /*
1857 * Hold semaphore so that nobody can access the chip during init.
1858 */
1859 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1860
1861 bfa_ioc_pll_init_asic(ioc);
1862
1863 ioc->pllinit = BFA_TRUE;
1864 /*
1865 * release semaphore.
1866 */
Maggie Zhangf7f73812010-12-09 19:08:43 -08001867 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001868
1869 return BFA_STATUS_OK;
1870}
Jing Huang7725ccf2009-09-23 17:46:15 -07001871
Jing Huang5fbe25c2010-10-18 17:17:23 -07001872/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001873 * Interface used by diag module to do firmware boot with memory test
1874 * as the entry vector.
1875 */
1876void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001877bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001878{
Jing Huang53440262010-10-18 17:12:29 -07001879 void __iomem *rb;
Jing Huang7725ccf2009-09-23 17:46:15 -07001880
1881 bfa_ioc_stats(ioc, ioc_boots);
1882
1883 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1884 return;
1885
Jing Huang5fbe25c2010-10-18 17:17:23 -07001886 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001887 * Initialize IOC state of all functions on a chip reset.
1888 */
1889 rb = ioc->pcidev.pci_bar_kva;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001890 if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
Jing Huang53440262010-10-18 17:12:29 -07001891 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
1892 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001893 } else {
Jing Huang53440262010-10-18 17:12:29 -07001894 writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
1895 writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001896 }
1897
Jing Huang07b28382010-07-08 19:59:24 -07001898 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001899 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001900
Jing Huang5fbe25c2010-10-18 17:17:23 -07001901 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001902 * Enable interrupts just before starting LPU
1903 */
1904 ioc->cbfn->reset_cbfn(ioc->bfa);
1905 bfa_ioc_lpu_start(ioc);
1906}
1907
Jing Huang5fbe25c2010-10-18 17:17:23 -07001908/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001909 * Enable/disable IOC failure auto recovery.
1910 */
1911void
1912bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
1913{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08001914 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07001915}
1916
1917
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001918
Jing Huang7725ccf2009-09-23 17:46:15 -07001919bfa_boolean_t
1920bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1921{
1922 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
1923}
1924
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001925bfa_boolean_t
1926bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
1927{
Jing Huang53440262010-10-18 17:12:29 -07001928 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001929
1930 return ((r32 != BFI_IOC_UNINIT) &&
1931 (r32 != BFI_IOC_INITING) &&
1932 (r32 != BFI_IOC_MEMTEST));
1933}
1934
Jing Huang7725ccf2009-09-23 17:46:15 -07001935void
1936bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
1937{
Maggie50444a32010-11-29 18:26:32 -08001938 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001939 u32 r32;
1940 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001941
Jing Huang5fbe25c2010-10-18 17:17:23 -07001942 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001943 * read the MBOX msg
1944 */
1945 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1946 i++) {
Jing Huang53440262010-10-18 17:12:29 -07001947 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07001948 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07001949 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07001950 }
1951
Jing Huang5fbe25c2010-10-18 17:17:23 -07001952 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001953 * turn off mailbox interrupt by clearing mailbox status
1954 */
Jing Huang53440262010-10-18 17:12:29 -07001955 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1956 readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001957}
1958
1959void
1960bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
1961{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001962 union bfi_ioc_i2h_msg_u *msg;
1963 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07001964
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001965 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07001966
1967 bfa_ioc_stats(ioc, ioc_isrs);
1968
1969 switch (msg->mh.msg_id) {
1970 case BFI_IOC_I2H_HBEAT:
1971 break;
1972
1973 case BFI_IOC_I2H_READY_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001974 bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001975 break;
1976
1977 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001978 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001979 break;
1980
1981 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001982 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001983 break;
1984
1985 case BFI_IOC_I2H_GETATTR_REPLY:
1986 bfa_ioc_getattr_reply(ioc);
1987 break;
1988
1989 default:
1990 bfa_trc(ioc, msg->mh.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001991 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001992 }
1993}
1994
Jing Huang5fbe25c2010-10-18 17:17:23 -07001995/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001996 * IOC attach time initialization and setup.
1997 *
1998 * @param[in] ioc memory for IOC
1999 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07002000 */
2001void
2002bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002003 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07002004{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002005 ioc->bfa = bfa;
2006 ioc->cbfn = cbfn;
2007 ioc->timer_mod = timer_mod;
2008 ioc->fcmode = BFA_FALSE;
2009 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002010 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002011 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002012
2013 bfa_ioc_mbox_attach(ioc);
2014 INIT_LIST_HEAD(&ioc->hb_notify_q);
2015
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002016 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
2017 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07002018}
2019
Jing Huang5fbe25c2010-10-18 17:17:23 -07002020/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002021 * Driver detach time IOC cleanup.
2022 */
2023void
2024bfa_ioc_detach(struct bfa_ioc_s *ioc)
2025{
2026 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2027}
2028
Jing Huang5fbe25c2010-10-18 17:17:23 -07002029/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002030 * Setup IOC PCI properties.
2031 *
2032 * @param[in] pcidev PCI device information for this IOC
2033 */
2034void
2035bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
2036 enum bfi_mclass mc)
2037{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002038 ioc->ioc_mc = mc;
2039 ioc->pcidev = *pcidev;
2040 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
2041 ioc->cna = ioc->ctdev && !ioc->fcmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07002042
Jing Huang5fbe25c2010-10-18 17:17:23 -07002043 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002044 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2045 */
2046 if (ioc->ctdev)
2047 bfa_ioc_set_ct_hwif(ioc);
2048 else
2049 bfa_ioc_set_cb_hwif(ioc);
2050
Jing Huang7725ccf2009-09-23 17:46:15 -07002051 bfa_ioc_map_port(ioc);
2052 bfa_ioc_reg_init(ioc);
2053}
2054
Jing Huang5fbe25c2010-10-18 17:17:23 -07002055/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002056 * Initialize IOC dma memory
2057 *
2058 * @param[in] dm_kva kernel virtual address of IOC dma memory
2059 * @param[in] dm_pa physical address of IOC dma memory
2060 */
2061void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002062bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002063{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002064 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002065 * dma memory for firmware attribute
2066 */
2067 ioc->attr_dma.kva = dm_kva;
2068 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002069 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002070}
2071
Jing Huang7725ccf2009-09-23 17:46:15 -07002072void
2073bfa_ioc_enable(struct bfa_ioc_s *ioc)
2074{
2075 bfa_ioc_stats(ioc, ioc_enables);
2076 ioc->dbg_fwsave_once = BFA_TRUE;
2077
2078 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2079}
2080
2081void
2082bfa_ioc_disable(struct bfa_ioc_s *ioc)
2083{
2084 bfa_ioc_stats(ioc, ioc_disables);
2085 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2086}
2087
Jing Huang7725ccf2009-09-23 17:46:15 -07002088
Jing Huang5fbe25c2010-10-18 17:17:23 -07002089/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002090 * Initialize memory for saving firmware trace. Driver must initialize
2091 * trace memory before call bfa_ioc_enable().
2092 */
2093void
2094bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2095{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002096 ioc->dbg_fwsave = dbg_fwsave;
Maggie Zhangf7f73812010-12-09 19:08:43 -08002097 ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07002098}
2099
Jing Huang5fbe25c2010-10-18 17:17:23 -07002100/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002101 * Register mailbox message handler functions
2102 *
2103 * @param[in] ioc IOC instance
2104 * @param[in] mcfuncs message class handler functions
2105 */
2106void
2107bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2108{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002109 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2110 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002111
2112 for (mc = 0; mc < BFI_MC_MAX; mc++)
2113 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2114}
2115
Jing Huang5fbe25c2010-10-18 17:17:23 -07002116/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002117 * Register mailbox message handler function, to be called by common modules
2118 */
2119void
2120bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2121 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2122{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002123 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002124
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002125 mod->mbhdlr[mc].cbfn = cbfn;
2126 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002127}
2128
Jing Huang5fbe25c2010-10-18 17:17:23 -07002129/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002130 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2131 * Responsibility of caller to serialize
2132 *
2133 * @param[in] ioc IOC instance
2134 * @param[i] cmd Mailbox command
2135 */
2136void
2137bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2138{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002139 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2140 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002141
Jing Huang5fbe25c2010-10-18 17:17:23 -07002142 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002143 * If a previous command is pending, queue new command
2144 */
2145 if (!list_empty(&mod->cmd_q)) {
2146 list_add_tail(&cmd->qe, &mod->cmd_q);
2147 return;
2148 }
2149
Jing Huang5fbe25c2010-10-18 17:17:23 -07002150 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002151 * If mailbox is busy, queue command for poll timer
2152 */
Jing Huang53440262010-10-18 17:12:29 -07002153 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002154 if (stat) {
2155 list_add_tail(&cmd->qe, &mod->cmd_q);
2156 return;
2157 }
2158
Jing Huang5fbe25c2010-10-18 17:17:23 -07002159 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002160 * mailbox is free -- queue command to firmware
2161 */
2162 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2163}
2164
Jing Huang5fbe25c2010-10-18 17:17:23 -07002165/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002166 * Handle mailbox interrupts
2167 */
2168void
2169bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2170{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002171 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2172 struct bfi_mbmsg_s m;
2173 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002174
2175 bfa_ioc_msgget(ioc, &m);
2176
Jing Huang5fbe25c2010-10-18 17:17:23 -07002177 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002178 * Treat IOC message class as special.
2179 */
2180 mc = m.mh.msg_class;
2181 if (mc == BFI_MC_IOC) {
2182 bfa_ioc_isr(ioc, &m);
2183 return;
2184 }
2185
2186 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2187 return;
2188
2189 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2190}
2191
2192void
2193bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2194{
2195 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2196}
2197
Jing Huanged969322010-07-08 19:45:56 -07002198void
2199bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2200{
2201 ioc->fcmode = BFA_TRUE;
2202 ioc->port_id = bfa_ioc_pcifn(ioc);
2203}
2204
Jing Huang5fbe25c2010-10-18 17:17:23 -07002205/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002206 * return true if IOC is disabled
2207 */
2208bfa_boolean_t
2209bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2210{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002211 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2212 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002213}
2214
Jing Huang5fbe25c2010-10-18 17:17:23 -07002215/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002216 * return true if IOC firmware is different.
2217 */
2218bfa_boolean_t
2219bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2220{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002221 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2222 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2223 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002224}
2225
2226#define bfa_ioc_state_disabled(__sm) \
2227 (((__sm) == BFI_IOC_UNINIT) || \
2228 ((__sm) == BFI_IOC_INITING) || \
2229 ((__sm) == BFI_IOC_HWINIT) || \
2230 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002231 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002232 ((__sm) == BFI_IOC_CFG_DISABLED))
2233
Jing Huang5fbe25c2010-10-18 17:17:23 -07002234/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002235 * Check if adapter is disabled -- both IOCs should be in a disabled
2236 * state.
2237 */
2238bfa_boolean_t
2239bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2240{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002241 u32 ioc_state;
Jing Huang53440262010-10-18 17:12:29 -07002242 void __iomem *rb = ioc->pcidev.pci_bar_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002243
2244 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2245 return BFA_FALSE;
2246
Jing Huang53440262010-10-18 17:12:29 -07002247 ioc_state = readl(rb + BFA_IOC0_STATE_REG);
Jing Huang7725ccf2009-09-23 17:46:15 -07002248 if (!bfa_ioc_state_disabled(ioc_state))
2249 return BFA_FALSE;
2250
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002251 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Jing Huang53440262010-10-18 17:12:29 -07002252 ioc_state = readl(rb + BFA_IOC1_STATE_REG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002253 if (!bfa_ioc_state_disabled(ioc_state))
2254 return BFA_FALSE;
2255 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002256
2257 return BFA_TRUE;
2258}
2259
Jing Huang8f4bfad2010-12-26 21:50:10 -08002260/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002261 * Reset IOC fwstate registers.
2262 */
2263void
2264bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2265{
2266 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2267 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2268}
2269
Jing Huang7725ccf2009-09-23 17:46:15 -07002270#define BFA_MFG_NAME "Brocade"
2271void
2272bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2273 struct bfa_adapter_attr_s *ad_attr)
2274{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002275 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002276
2277 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002278
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002279 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2280 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2281 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2282 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002283 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002284 sizeof(struct bfa_mfg_vpd_s));
2285
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002286 ad_attr->nports = bfa_ioc_get_nports(ioc);
2287 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002288
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002289 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2290 /* For now, model descr uses same model string */
2291 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002292
Jing Huanged969322010-07-08 19:45:56 -07002293 ad_attr->card_type = ioc_attr->card_type;
2294 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2295
Jing Huang7725ccf2009-09-23 17:46:15 -07002296 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2297 ad_attr->prototype = 1;
2298 else
2299 ad_attr->prototype = 0;
2300
Maggie Zhangf7f73812010-12-09 19:08:43 -08002301 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002302 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002303
2304 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2305 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2306 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2307 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002308
2309 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002310
2311 ad_attr->cna_capable = ioc->cna;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002312 ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna &&
2313 !ad_attr->is_mezz;
Jing Huang7725ccf2009-09-23 17:46:15 -07002314}
2315
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002316enum bfa_ioc_type_e
2317bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2318{
2319 if (!ioc->ctdev || ioc->fcmode)
2320 return BFA_IOC_TYPE_FC;
2321 else if (ioc->ioc_mc == BFI_MC_IOCFC)
2322 return BFA_IOC_TYPE_FCoE;
2323 else if (ioc->ioc_mc == BFI_MC_LL)
2324 return BFA_IOC_TYPE_LL;
2325 else {
Jing Huangd4b671c2010-12-26 21:46:35 -08002326 WARN_ON(ioc->ioc_mc != BFI_MC_LL);
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002327 return BFA_IOC_TYPE_LL;
2328 }
2329}
2330
Jing Huang7725ccf2009-09-23 17:46:15 -07002331void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002332bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2333{
Jing Huang6a18b162010-10-18 17:08:54 -07002334 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2335 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002336 (void *)ioc->attr->brcd_serialnum,
2337 BFA_ADAPTER_SERIAL_NUM_LEN);
2338}
2339
2340void
2341bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2342{
Jing Huang6a18b162010-10-18 17:08:54 -07002343 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2344 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002345}
2346
2347void
2348bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2349{
Jing Huangd4b671c2010-12-26 21:46:35 -08002350 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002351
Jing Huang6a18b162010-10-18 17:08:54 -07002352 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002353
2354 chip_rev[0] = 'R';
2355 chip_rev[1] = 'e';
2356 chip_rev[2] = 'v';
2357 chip_rev[3] = '-';
2358 chip_rev[4] = ioc->attr->asic_rev;
2359 chip_rev[5] = '\0';
2360}
2361
2362void
2363bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2364{
Jing Huang6a18b162010-10-18 17:08:54 -07002365 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2366 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002367 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002368}
2369
2370void
2371bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2372{
Jing Huang6a18b162010-10-18 17:08:54 -07002373 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2374 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002375}
2376
2377void
2378bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2379{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002380 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002381
Jing Huangd4b671c2010-12-26 21:46:35 -08002382 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002383 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002384
2385 ioc_attr = ioc->attr;
2386
Jing Huang5fbe25c2010-10-18 17:17:23 -07002387 /*
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002388 * model name
2389 */
Jing Huang6a18b162010-10-18 17:08:54 -07002390 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002391 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002392}
2393
2394enum bfa_ioc_state
2395bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2396{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002397 enum bfa_iocpf_state iocpf_st;
2398 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2399
2400 if (ioc_st == BFA_IOC_ENABLING ||
2401 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2402
2403 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2404
2405 switch (iocpf_st) {
2406 case BFA_IOCPF_SEMWAIT:
2407 ioc_st = BFA_IOC_SEMWAIT;
2408 break;
2409
2410 case BFA_IOCPF_HWINIT:
2411 ioc_st = BFA_IOC_HWINIT;
2412 break;
2413
2414 case BFA_IOCPF_FWMISMATCH:
2415 ioc_st = BFA_IOC_FWMISMATCH;
2416 break;
2417
2418 case BFA_IOCPF_FAIL:
2419 ioc_st = BFA_IOC_FAIL;
2420 break;
2421
2422 case BFA_IOCPF_INITFAIL:
2423 ioc_st = BFA_IOC_INITFAIL;
2424 break;
2425
2426 default:
2427 break;
2428 }
2429 }
2430
2431 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002432}
2433
2434void
Jing Huang7725ccf2009-09-23 17:46:15 -07002435bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2436{
Jing Huang6a18b162010-10-18 17:08:54 -07002437 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002438
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002439 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002440 ioc_attr->port_id = ioc->port_id;
2441
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002442 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002443
2444 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2445
2446 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2447 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002448 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002449}
2450
Jing Huang7725ccf2009-09-23 17:46:15 -07002451mac_t
2452bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2453{
Jing Huang15b64a82010-07-08 19:48:12 -07002454 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002455 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002456 */
2457 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002458 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002459 else
2460 return ioc->attr->mac;
2461}
2462
Jing Huang15b64a82010-07-08 19:48:12 -07002463mac_t
2464bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2465{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002466 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002467
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002468 m = ioc->attr->mfg_mac;
2469 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2470 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2471 else
2472 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2473 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002474
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002475 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002476}
2477
Jing Huang7725ccf2009-09-23 17:46:15 -07002478bfa_boolean_t
2479bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2480{
Jing Huang293f82d2010-07-08 19:45:20 -07002481 return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07002482}
2483
Jing Huang5fbe25c2010-10-18 17:17:23 -07002484/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002485 * Retrieve saved firmware trace from a prior IOC failure.
2486 */
2487bfa_status_t
2488bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2489{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002490 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002491
2492 if (ioc->dbg_fwsave_len == 0)
2493 return BFA_STATUS_ENOFSAVE;
2494
2495 tlen = *trclen;
2496 if (tlen > ioc->dbg_fwsave_len)
2497 tlen = ioc->dbg_fwsave_len;
2498
Jing Huang6a18b162010-10-18 17:08:54 -07002499 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002500 *trclen = tlen;
2501 return BFA_STATUS_OK;
2502}
2503
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002504
Jing Huang5fbe25c2010-10-18 17:17:23 -07002505/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002506 * Retrieve saved firmware trace from a prior IOC failure.
2507 */
2508bfa_status_t
2509bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2510{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002511 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2512 int tlen;
2513 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002514
2515 bfa_trc(ioc, *trclen);
2516
Jing Huang7725ccf2009-09-23 17:46:15 -07002517 tlen = *trclen;
2518 if (tlen > BFA_DBG_FWTRC_LEN)
2519 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002520
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002521 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2522 *trclen = tlen;
2523 return status;
2524}
Jing Huang7725ccf2009-09-23 17:46:15 -07002525
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002526static void
2527bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2528{
2529 struct bfa_mbox_cmd_s cmd;
2530 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002531
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002532 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2533 bfa_ioc_portid(ioc));
2534 req->ioc_class = ioc->ioc_mc;
2535 bfa_ioc_mbox_queue(ioc, &cmd);
2536}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002537
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002538static void
2539bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2540{
2541 u32 fwsync_iter = 1000;
2542
2543 bfa_ioc_send_fwsync(ioc);
2544
Jing Huang5fbe25c2010-10-18 17:17:23 -07002545 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002546 * After sending a fw sync mbox command wait for it to
2547 * take effect. We will not wait for a response because
2548 * 1. fw_sync mbox cmd doesn't have a response.
2549 * 2. Even if we implement that, interrupts might not
2550 * be enabled when we call this function.
2551 * So, just keep checking if any mbox cmd is pending, and
2552 * after waiting for a reasonable amount of time, go ahead.
2553 * It is possible that fw has crashed and the mbox command
2554 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002555 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002556 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2557 fwsync_iter--;
2558}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002559
Jing Huang5fbe25c2010-10-18 17:17:23 -07002560/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002561 * Dump firmware smem
2562 */
2563bfa_status_t
2564bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2565 u32 *offset, int *buflen)
2566{
2567 u32 loff;
2568 int dlen;
2569 bfa_status_t status;
2570 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002571
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002572 if (*offset >= smem_len) {
2573 *offset = *buflen = 0;
2574 return BFA_STATUS_EINVAL;
2575 }
2576
2577 loff = *offset;
2578 dlen = *buflen;
2579
Jing Huang5fbe25c2010-10-18 17:17:23 -07002580 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002581 * First smem read, sync smem before proceeding
2582 * No need to sync before reading every chunk.
2583 */
2584 if (loff == 0)
2585 bfa_ioc_fwsync(ioc);
2586
2587 if ((loff + dlen) >= smem_len)
2588 dlen = smem_len - loff;
2589
2590 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2591
2592 if (status != BFA_STATUS_OK) {
2593 *offset = *buflen = 0;
2594 return status;
2595 }
2596
2597 *offset += dlen;
2598
2599 if (*offset >= smem_len)
2600 *offset = 0;
2601
2602 *buflen = dlen;
2603
2604 return status;
2605}
2606
Jing Huang5fbe25c2010-10-18 17:17:23 -07002607/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002608 * Firmware statistics
2609 */
2610bfa_status_t
2611bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2612{
2613 u32 loff = BFI_IOC_FWSTATS_OFF + \
2614 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2615 int tlen;
2616 bfa_status_t status;
2617
2618 if (ioc->stats_busy) {
2619 bfa_trc(ioc, ioc->stats_busy);
2620 return BFA_STATUS_DEVBUSY;
2621 }
2622 ioc->stats_busy = BFA_TRUE;
2623
2624 tlen = sizeof(struct bfa_fw_stats_s);
2625 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2626
2627 ioc->stats_busy = BFA_FALSE;
2628 return status;
2629}
2630
2631bfa_status_t
2632bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2633{
2634 u32 loff = BFI_IOC_FWSTATS_OFF + \
2635 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2636 int tlen;
2637 bfa_status_t status;
2638
2639 if (ioc->stats_busy) {
2640 bfa_trc(ioc, ioc->stats_busy);
2641 return BFA_STATUS_DEVBUSY;
2642 }
2643 ioc->stats_busy = BFA_TRUE;
2644
2645 tlen = sizeof(struct bfa_fw_stats_s);
2646 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2647
2648 ioc->stats_busy = BFA_FALSE;
2649 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002650}
2651
Jing Huang5fbe25c2010-10-18 17:17:23 -07002652/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002653 * Save firmware trace if configured.
2654 */
2655static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002656bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002657{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002658 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002659
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002660 if (ioc->dbg_fwsave_once) {
2661 ioc->dbg_fwsave_once = BFA_FALSE;
2662 if (ioc->dbg_fwsave_len) {
2663 tlen = ioc->dbg_fwsave_len;
2664 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2665 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002666 }
2667}
2668
Jing Huang5fbe25c2010-10-18 17:17:23 -07002669/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002670 * Firmware failure detected. Start recovery actions.
2671 */
2672static void
2673bfa_ioc_recover(struct bfa_ioc_s *ioc)
2674{
Jing Huang7725ccf2009-09-23 17:46:15 -07002675 bfa_ioc_stats(ioc, ioc_hbfails);
2676 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2677}
2678
Jing Huang7725ccf2009-09-23 17:46:15 -07002679static void
Jing Huang07b28382010-07-08 19:59:24 -07002680bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002681{
Jing Huang07b28382010-07-08 19:59:24 -07002682 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2683 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002684}
2685
Jing Huang5fbe25c2010-10-18 17:17:23 -07002686/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002687 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002688 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002689static void
2690bfa_iocpf_timeout(void *ioc_arg)
2691{
2692 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2693
2694 bfa_trc(ioc, 0);
2695 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2696}
2697
2698static void
2699bfa_iocpf_sem_timeout(void *ioc_arg)
2700{
2701 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2702
2703 bfa_ioc_hw_sem_get(ioc);
2704}
2705
Jing Huang5fbe25c2010-10-18 17:17:23 -07002706/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002707 * bfa timer function
2708 */
2709void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002710bfa_timer_beat(struct bfa_timer_mod_s *mod)
2711{
2712 struct list_head *qh = &mod->timer_q;
2713 struct list_head *qe, *qe_next;
2714 struct bfa_timer_s *elem;
2715 struct list_head timedout_q;
2716
2717 INIT_LIST_HEAD(&timedout_q);
2718
2719 qe = bfa_q_next(qh);
2720
2721 while (qe != qh) {
2722 qe_next = bfa_q_next(qe);
2723
2724 elem = (struct bfa_timer_s *) qe;
2725 if (elem->timeout <= BFA_TIMER_FREQ) {
2726 elem->timeout = 0;
2727 list_del(&elem->qe);
2728 list_add_tail(&elem->qe, &timedout_q);
2729 } else {
2730 elem->timeout -= BFA_TIMER_FREQ;
2731 }
2732
2733 qe = qe_next; /* go to next elem */
2734 }
2735
2736 /*
2737 * Pop all the timeout entries
2738 */
2739 while (!list_empty(&timedout_q)) {
2740 bfa_q_deq(&timedout_q, &elem);
2741 elem->timercb(elem->arg);
2742 }
2743}
2744
Jing Huang5fbe25c2010-10-18 17:17:23 -07002745/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002746 * Should be called with lock protection
2747 */
2748void
2749bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2750 void (*timercb) (void *), void *arg, unsigned int timeout)
2751{
2752
Jing Huangd4b671c2010-12-26 21:46:35 -08002753 WARN_ON(timercb == NULL);
2754 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002755
2756 timer->timeout = timeout;
2757 timer->timercb = timercb;
2758 timer->arg = arg;
2759
2760 list_add_tail(&timer->qe, &mod->timer_q);
2761}
2762
Jing Huang5fbe25c2010-10-18 17:17:23 -07002763/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002764 * Should be called with lock protection
2765 */
2766void
2767bfa_timer_stop(struct bfa_timer_s *timer)
2768{
Jing Huangd4b671c2010-12-26 21:46:35 -08002769 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002770
2771 list_del(&timer->qe);
2772}