blob: d215168ab8b58ae7ea52e197eae3a55d72595368 [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);
Krishna Gudipatid37779f2011-06-13 15:42:10 -070090static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
91 enum bfa_ioc_event_e event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070092static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
93static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -080094static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc);
95static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070096static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -070097
Jing Huang7725ccf2009-09-23 17:46:15 -070098
Jing Huang5fbe25c2010-10-18 17:17:23 -070099/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700100 * IOC state machine definitions/declarations
Jing Huang7725ccf2009-09-23 17:46:15 -0700101 */
102enum ioc_event {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700103 IOC_E_RESET = 1, /* IOC reset request */
104 IOC_E_ENABLE = 2, /* IOC enable request */
105 IOC_E_DISABLE = 3, /* IOC disable request */
106 IOC_E_DETACH = 4, /* driver detach cleanup */
107 IOC_E_ENABLED = 5, /* f/w enabled */
108 IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
109 IOC_E_DISABLED = 7, /* f/w disabled */
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800110 IOC_E_INITFAILED = 8, /* failure notice by iocpf sm */
111 IOC_E_PFFAILED = 9, /* failure notice by iocpf sm */
112 IOC_E_HBFAIL = 10, /* heartbeat failure */
113 IOC_E_HWERROR = 11, /* hardware error interrupt */
114 IOC_E_TIMEOUT = 12, /* timeout */
Jing Huang7725ccf2009-09-23 17:46:15 -0700115};
116
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700117bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700118bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700119bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
120bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
121bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800122bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700123bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700124bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
125bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
126
127static struct bfa_sm_table_s ioc_sm_table[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700128 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Jing Huang7725ccf2009-09-23 17:46:15 -0700129 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Jing Huang7725ccf2009-09-23 17:46:15 -0700131 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
132 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800133 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700134 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700135 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
136 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
137};
138
Jing Huang5fbe25c2010-10-18 17:17:23 -0700139/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700140 * IOCPF state machine definitions/declarations
141 */
142
143#define bfa_iocpf_timer_start(__ioc) \
144 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
145 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
146#define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
147
148#define bfa_iocpf_recovery_timer_start(__ioc) \
149 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
150 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV_RECOVER)
151
152#define bfa_sem_timer_start(__ioc) \
153 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
154 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
155#define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
156
157/*
158 * Forward declareations for iocpf state machine
159 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700160static void bfa_iocpf_timeout(void *ioc_arg);
161static void bfa_iocpf_sem_timeout(void *ioc_arg);
162
Jing Huang5fbe25c2010-10-18 17:17:23 -0700163/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700164 * IOCPF state machine events
165 */
166enum iocpf_event {
167 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
168 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
169 IOCPF_E_STOP = 3, /* stop on driver detach */
170 IOCPF_E_FWREADY = 4, /* f/w initialization done */
171 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
172 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
173 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
174 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
175 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
176 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
177 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
178};
179
Jing Huang5fbe25c2010-10-18 17:17:23 -0700180/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700181 * IOCPF states
182 */
183enum bfa_iocpf_state {
184 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
185 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
186 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
187 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
188 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
189 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
190 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
191 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
192 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
193};
194
195bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
196bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
197bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
198bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
199bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
200bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
201bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800202bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
203 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700204bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800205bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700206bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
207bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800208bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
209 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700210bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
211
212static struct bfa_sm_table_s iocpf_sm_table[] = {
213 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
214 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
215 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
216 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
217 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
218 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
219 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800220 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700221 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800222 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700223 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
224 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800225 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700226 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
227};
228
Jing Huang5fbe25c2010-10-18 17:17:23 -0700229/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700230 * IOC State Machine
231 */
232
Jing Huang5fbe25c2010-10-18 17:17:23 -0700233/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700234 * Beginning state. IOC uninit state.
235 */
236
237static void
238bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
239{
240}
241
Jing Huang5fbe25c2010-10-18 17:17:23 -0700242/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700243 * IOC is in uninit state.
244 */
245static void
246bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
247{
248 bfa_trc(ioc, event);
249
250 switch (event) {
251 case IOC_E_RESET:
252 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
253 break;
254
255 default:
256 bfa_sm_fault(ioc, event);
257 }
258}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700259/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700260 * Reset entry actions -- initialize state machine
261 */
262static void
263bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
264{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700265 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700266}
267
Jing Huang5fbe25c2010-10-18 17:17:23 -0700268/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700269 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700270 */
271static void
272bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
273{
274 bfa_trc(ioc, event);
275
276 switch (event) {
277 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700278 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
279 break;
280
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700281 case IOC_E_DISABLE:
282 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700283 break;
284
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700285 case IOC_E_DETACH:
286 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700287 break;
288
289 default:
290 bfa_sm_fault(ioc, event);
291 }
292}
293
294
295static void
296bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
297{
Maggie Zhangf7f738122010-12-09 19:08:43 -0800298 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700299}
300
Jing Huang5fbe25c2010-10-18 17:17:23 -0700301/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700302 * Host IOC function is being enabled, awaiting response from firmware.
303 * Semaphore is acquired.
304 */
305static void
306bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
307{
308 bfa_trc(ioc, event);
309
310 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700311 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700312 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
313 break;
314
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800315 case IOC_E_PFFAILED:
316 /* !!! fall through !!! */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700317 case IOC_E_HWERROR:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800318 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
319 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
320 if (event != IOC_E_PFFAILED)
321 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700322 break;
323
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700324 case IOC_E_DISABLE:
325 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
326 break;
327
328 case IOC_E_DETACH:
329 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800330 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700331 break;
332
333 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700334 break;
335
336 default:
337 bfa_sm_fault(ioc, event);
338 }
339}
340
341
342static void
343bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
344{
345 bfa_ioc_timer_start(ioc);
346 bfa_ioc_send_getattr(ioc);
347}
348
Jing Huang5fbe25c2010-10-18 17:17:23 -0700349/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700350 * IOC configuration in progress. Timer is active.
351 */
352static void
353bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
354{
355 bfa_trc(ioc, event);
356
357 switch (event) {
358 case IOC_E_FWRSP_GETATTR:
359 bfa_ioc_timer_stop(ioc);
Jing Huang07b28382010-07-08 19:59:24 -0700360 bfa_ioc_check_attr_wwns(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700361 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
362 break;
363
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700364 break;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800365 case IOC_E_PFFAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700366 case IOC_E_HWERROR:
367 bfa_ioc_timer_stop(ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800368 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700369 case IOC_E_TIMEOUT:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800370 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
371 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
372 if (event != IOC_E_PFFAILED)
373 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700374 break;
375
376 case IOC_E_DISABLE:
377 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700378 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
379 break;
380
381 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700382 break;
383
384 default:
385 bfa_sm_fault(ioc, event);
386 }
387}
388
389
390static void
391bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
392{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700393 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
394
Jing Huang7725ccf2009-09-23 17:46:15 -0700395 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700396 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -0700397 bfa_ioc_hb_monitor(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800398 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700399}
400
401static void
402bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
403{
404 bfa_trc(ioc, event);
405
406 switch (event) {
407 case IOC_E_ENABLE:
408 break;
409
410 case IOC_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800411 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700412 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
413 break;
414
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800415 case IOC_E_PFFAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700416 case IOC_E_HWERROR:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800417 bfa_hb_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700418 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700419 case IOC_E_HBFAIL:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800420 bfa_ioc_fail_notify(ioc);
421
422 if (ioc->iocpf.auto_recover)
423 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
424 else
425 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
426
427 if (event != IOC_E_PFFAILED)
428 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700429 break;
430
431 default:
432 bfa_sm_fault(ioc, event);
433 }
434}
435
436
437static void
438bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
439{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700440 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800441 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
Jing Huang88166242010-12-09 17:11:53 -0800442 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700443}
444
Jing Huang5fbe25c2010-10-18 17:17:23 -0700445/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700446 * IOC is being disabled
447 */
448static void
449bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
450{
451 bfa_trc(ioc, event);
452
453 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700454 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800455 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
456 break;
457
458 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700459 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700460 * No state change. Will move to disabled state
461 * after iocpf sm completes failure processing and
462 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700463 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800464 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700465 break;
466
467 default:
468 bfa_sm_fault(ioc, event);
469 }
470}
471
Jing Huang5fbe25c2010-10-18 17:17:23 -0700472/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700473 * IOC disable completion entry.
474 */
475static void
476bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
477{
478 bfa_ioc_disable_comp(ioc);
479}
480
481static void
482bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
483{
484 bfa_trc(ioc, event);
485
486 switch (event) {
487 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700488 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700489 break;
490
491 case IOC_E_DISABLE:
492 ioc->cbfn->disable_cbfn(ioc->bfa);
493 break;
494
Jing Huang7725ccf2009-09-23 17:46:15 -0700495 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700496 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800497 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700498 break;
499
500 default:
501 bfa_sm_fault(ioc, event);
502 }
503}
504
505
506static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800507bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700508{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800509 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700510}
511
Jing Huang5fbe25c2010-10-18 17:17:23 -0700512/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800513 * Hardware initialization retry.
Jing Huang7725ccf2009-09-23 17:46:15 -0700514 */
515static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800516bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700517{
518 bfa_trc(ioc, event);
519
520 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700521 case IOC_E_ENABLED:
522 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
523 break;
524
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800525 case IOC_E_PFFAILED:
526 case IOC_E_HWERROR:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700527 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800528 * Initialization retry failed.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700529 */
530 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800531 if (event != IOC_E_PFFAILED)
532 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
533 break;
534
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800535 case IOC_E_INITFAILED:
536 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
537 break;
538
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800539 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700540 break;
541
Jing Huang7725ccf2009-09-23 17:46:15 -0700542 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700543 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700544 break;
545
546 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700547 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800548 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700549 break;
550
551 default:
552 bfa_sm_fault(ioc, event);
553 }
554}
555
556
557static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700558bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700559{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800560 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700561}
562
Jing Huang5fbe25c2010-10-18 17:17:23 -0700563/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700564 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700565 */
566static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700567bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700568{
569 bfa_trc(ioc, event);
570
571 switch (event) {
572
573 case IOC_E_ENABLE:
574 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
575 break;
576
577 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700578 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700579 break;
580
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800581 case IOC_E_DETACH:
582 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
583 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
584 break;
585
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800586 case IOC_E_HWERROR:
587 /*
588 * HB failure notification, ignore.
589 */
590 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700591 default:
592 bfa_sm_fault(ioc, event);
593 }
594}
595
Jing Huang5fbe25c2010-10-18 17:17:23 -0700596/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700597 * IOCPF State Machine
598 */
599
Jing Huang5fbe25c2010-10-18 17:17:23 -0700600/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700601 * Reset entry actions -- initialize state machine
602 */
603static void
604bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
605{
606 iocpf->retry_count = 0;
607 iocpf->auto_recover = bfa_auto_recover;
608}
609
Jing Huang5fbe25c2010-10-18 17:17:23 -0700610/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700611 * Beginning state. IOC is in reset state.
612 */
613static void
614bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
615{
616 struct bfa_ioc_s *ioc = iocpf->ioc;
617
618 bfa_trc(ioc, event);
619
620 switch (event) {
621 case IOCPF_E_ENABLE:
622 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
623 break;
624
625 case IOCPF_E_STOP:
626 break;
627
628 default:
629 bfa_sm_fault(ioc, event);
630 }
631}
632
Jing Huang5fbe25c2010-10-18 17:17:23 -0700633/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700634 * Semaphore should be acquired for version check.
635 */
636static void
637bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
638{
639 bfa_ioc_hw_sem_get(iocpf->ioc);
640}
641
Jing Huang5fbe25c2010-10-18 17:17:23 -0700642/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700643 * Awaiting h/w semaphore to continue with version check.
644 */
645static void
646bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
647{
648 struct bfa_ioc_s *ioc = iocpf->ioc;
649
650 bfa_trc(ioc, event);
651
652 switch (event) {
653 case IOCPF_E_SEMLOCKED:
654 if (bfa_ioc_firmware_lock(ioc)) {
Jing Huang45d7f0c2011-04-13 11:45:53 -0700655 if (bfa_ioc_sync_start(ioc)) {
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800656 iocpf->retry_count = 0;
657 bfa_ioc_sync_join(ioc);
658 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
659 } else {
660 bfa_ioc_firmware_unlock(ioc);
661 writel(1, ioc->ioc_regs.ioc_sem_reg);
662 bfa_sem_timer_start(ioc);
663 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700664 } else {
Maggie Zhangf7f738122010-12-09 19:08:43 -0800665 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700666 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
667 }
668 break;
669
670 case IOCPF_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800671 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700672 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800673 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700674 break;
675
676 case IOCPF_E_STOP:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800677 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700678 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
679 break;
680
681 default:
682 bfa_sm_fault(ioc, event);
683 }
684}
685
Jing Huang5fbe25c2010-10-18 17:17:23 -0700686/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700687 * Notify enable completion callback.
688 */
689static void
690bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
691{
692 /*
693 * Call only the first time sm enters fwmismatch state.
694 */
695 if (iocpf->retry_count == 0)
696 bfa_ioc_pf_fwmismatch(iocpf->ioc);
697
698 iocpf->retry_count++;
699 bfa_iocpf_timer_start(iocpf->ioc);
700}
701
Jing Huang5fbe25c2010-10-18 17:17:23 -0700702/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700703 * Awaiting firmware version match.
704 */
705static void
706bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
707{
708 struct bfa_ioc_s *ioc = iocpf->ioc;
709
710 bfa_trc(ioc, event);
711
712 switch (event) {
713 case IOCPF_E_TIMEOUT:
714 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
715 break;
716
717 case IOCPF_E_DISABLE:
718 bfa_iocpf_timer_stop(ioc);
719 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800720 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700721 break;
722
723 case IOCPF_E_STOP:
724 bfa_iocpf_timer_stop(ioc);
725 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
726 break;
727
728 default:
729 bfa_sm_fault(ioc, event);
730 }
731}
732
Jing Huang5fbe25c2010-10-18 17:17:23 -0700733/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700734 * Request for semaphore.
735 */
736static void
737bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
738{
739 bfa_ioc_hw_sem_get(iocpf->ioc);
740}
741
Jing Huang5fbe25c2010-10-18 17:17:23 -0700742/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700743 * Awaiting semaphore for h/w initialzation.
744 */
745static void
746bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
747{
748 struct bfa_ioc_s *ioc = iocpf->ioc;
749
750 bfa_trc(ioc, event);
751
752 switch (event) {
753 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800754 if (bfa_ioc_sync_complete(ioc)) {
755 bfa_ioc_sync_join(ioc);
756 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
757 } else {
758 writel(1, ioc->ioc_regs.ioc_sem_reg);
759 bfa_sem_timer_start(ioc);
760 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700761 break;
762
763 case IOCPF_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800764 bfa_sem_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800765 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700766 break;
767
768 default:
769 bfa_sm_fault(ioc, event);
770 }
771}
772
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700773static void
774bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
775{
776 bfa_iocpf_timer_start(iocpf->ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800777 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700778}
779
Jing Huang5fbe25c2010-10-18 17:17:23 -0700780/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700781 * Hardware is being initialized. Interrupts are enabled.
782 * Holding hardware semaphore lock.
783 */
784static void
785bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
786{
787 struct bfa_ioc_s *ioc = iocpf->ioc;
788
789 bfa_trc(ioc, event);
790
791 switch (event) {
792 case IOCPF_E_FWREADY:
793 bfa_iocpf_timer_stop(ioc);
794 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
795 break;
796
797 case IOCPF_E_INITFAIL:
798 bfa_iocpf_timer_stop(ioc);
799 /*
800 * !!! fall through !!!
801 */
802
803 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800804 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700805 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800806 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800807 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700808 break;
809
810 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800812 bfa_ioc_sync_leave(ioc);
813 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700814 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
815 break;
816
817 default:
818 bfa_sm_fault(ioc, event);
819 }
820}
821
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700822static void
823bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
824{
825 bfa_iocpf_timer_start(iocpf->ioc);
826 bfa_ioc_send_enable(iocpf->ioc);
827}
828
Jing Huang5fbe25c2010-10-18 17:17:23 -0700829/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700830 * Host IOC function is being enabled, awaiting response from firmware.
831 * Semaphore is acquired.
832 */
833static void
834bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
835{
836 struct bfa_ioc_s *ioc = iocpf->ioc;
837
838 bfa_trc(ioc, event);
839
840 switch (event) {
841 case IOCPF_E_FWRSP_ENABLE:
842 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800843 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700844 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
845 break;
846
847 case IOCPF_E_INITFAIL:
848 bfa_iocpf_timer_stop(ioc);
849 /*
850 * !!! fall through !!!
851 */
852
853 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800854 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700855 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800856 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800857 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700858 break;
859
860 case IOCPF_E_DISABLE:
861 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800862 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700863 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
864 break;
865
866 case IOCPF_E_FWREADY:
867 bfa_ioc_send_enable(ioc);
868 break;
869
870 default:
871 bfa_sm_fault(ioc, event);
872 }
873}
874
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700875static void
876bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
877{
Maggie Zhangf7f738122010-12-09 19:08:43 -0800878 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700879}
880
881static void
882bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
883{
884 struct bfa_ioc_s *ioc = iocpf->ioc;
885
886 bfa_trc(ioc, event);
887
888 switch (event) {
889 case IOCPF_E_DISABLE:
890 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
891 break;
892
893 case IOCPF_E_GETATTRFAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800894 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700895 break;
896
897 case IOCPF_E_FAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800898 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700899 break;
900
901 case IOCPF_E_FWREADY:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800902 if (bfa_ioc_is_operational(ioc)) {
903 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
904 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
905 } else {
906 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
907 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
908 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700909 break;
910
911 default:
912 bfa_sm_fault(ioc, event);
913 }
914}
915
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700916static void
917bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
918{
919 bfa_iocpf_timer_start(iocpf->ioc);
920 bfa_ioc_send_disable(iocpf->ioc);
921}
922
Jing Huang5fbe25c2010-10-18 17:17:23 -0700923/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700924 * IOC is being disabled
925 */
926static void
927bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
928{
929 struct bfa_ioc_s *ioc = iocpf->ioc;
930
931 bfa_trc(ioc, event);
932
933 switch (event) {
934 case IOCPF_E_FWRSP_DISABLE:
935 case IOCPF_E_FWREADY:
936 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800937 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700938 break;
939
940 case IOCPF_E_FAIL:
941 bfa_iocpf_timer_stop(ioc);
942 /*
943 * !!! fall through !!!
944 */
945
946 case IOCPF_E_TIMEOUT:
Jing Huang53440262010-10-18 17:12:29 -0700947 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800948 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700949 break;
950
951 case IOCPF_E_FWRSP_ENABLE:
952 break;
953
954 default:
955 bfa_sm_fault(ioc, event);
956 }
957}
958
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800959static void
960bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
961{
962 bfa_ioc_hw_sem_get(iocpf->ioc);
963}
964
Jing Huang8f4bfad2010-12-26 21:50:10 -0800965/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800966 * IOC hb ack request is being removed.
967 */
968static void
969bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
970{
971 struct bfa_ioc_s *ioc = iocpf->ioc;
972
973 bfa_trc(ioc, event);
974
975 switch (event) {
976 case IOCPF_E_SEMLOCKED:
977 bfa_ioc_sync_leave(ioc);
978 writel(1, ioc->ioc_regs.ioc_sem_reg);
979 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
980 break;
981
982 case IOCPF_E_FAIL:
983 break;
984
985 default:
986 bfa_sm_fault(ioc, event);
987 }
988}
989
Jing Huang5fbe25c2010-10-18 17:17:23 -0700990/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991 * IOC disable completion entry.
992 */
993static void
994bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
995{
Maggie Zhangf7f738122010-12-09 19:08:43 -0800996 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700997}
998
999static void
1000bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1001{
1002 struct bfa_ioc_s *ioc = iocpf->ioc;
1003
1004 bfa_trc(ioc, event);
1005
1006 switch (event) {
1007 case IOCPF_E_ENABLE:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001008 iocpf->retry_count = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001009 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1010 break;
1011
1012 case IOCPF_E_STOP:
1013 bfa_ioc_firmware_unlock(ioc);
1014 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1015 break;
1016
1017 default:
1018 bfa_sm_fault(ioc, event);
1019 }
1020}
1021
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001022static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001023bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1024{
1025 bfa_ioc_hw_sem_get(iocpf->ioc);
1026}
1027
Jing Huang8f4bfad2010-12-26 21:50:10 -08001028/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001029 * Hardware initialization failed.
1030 */
1031static void
1032bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1033{
1034 struct bfa_ioc_s *ioc = iocpf->ioc;
1035
1036 bfa_trc(ioc, event);
1037
1038 switch (event) {
1039 case IOCPF_E_SEMLOCKED:
1040 bfa_ioc_notify_fail(ioc);
1041 bfa_ioc_sync_ack(ioc);
1042 iocpf->retry_count++;
1043 if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) {
1044 bfa_ioc_sync_leave(ioc);
1045 writel(1, ioc->ioc_regs.ioc_sem_reg);
1046 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
1047 } else {
1048 if (bfa_ioc_sync_complete(ioc))
1049 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1050 else {
1051 writel(1, ioc->ioc_regs.ioc_sem_reg);
1052 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1053 }
1054 }
1055 break;
1056
1057 case IOCPF_E_DISABLE:
1058 bfa_sem_timer_stop(ioc);
1059 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1060 break;
1061
1062 case IOCPF_E_STOP:
1063 bfa_sem_timer_stop(ioc);
1064 bfa_ioc_firmware_unlock(ioc);
1065 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1066 break;
1067
1068 case IOCPF_E_FAIL:
1069 break;
1070
1071 default:
1072 bfa_sm_fault(ioc, event);
1073 }
1074}
1075
1076static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001077bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1078{
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001079 bfa_fsm_send_event(iocpf->ioc, IOC_E_INITFAILED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001080}
1081
Jing Huang5fbe25c2010-10-18 17:17:23 -07001082/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001083 * Hardware initialization failed.
1084 */
1085static void
1086bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1087{
1088 struct bfa_ioc_s *ioc = iocpf->ioc;
1089
1090 bfa_trc(ioc, event);
1091
1092 switch (event) {
1093 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001094 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1095 break;
1096
1097 case IOCPF_E_STOP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001098 bfa_ioc_firmware_unlock(ioc);
1099 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1100 break;
1101
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001102 default:
1103 bfa_sm_fault(ioc, event);
1104 }
1105}
1106
1107static void
1108bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1109{
Jing Huang8f4bfad2010-12-26 21:50:10 -08001110 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001111 * Mark IOC as failed in hardware and stop firmware.
1112 */
1113 bfa_ioc_lpu_stop(iocpf->ioc);
1114
Jing Huang8f4bfad2010-12-26 21:50:10 -08001115 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001116 * Flush any queued up mailbox requests.
1117 */
1118 bfa_ioc_mbox_hbfail(iocpf->ioc);
1119
1120 bfa_ioc_hw_sem_get(iocpf->ioc);
1121}
1122
1123static void
1124bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1125{
1126 struct bfa_ioc_s *ioc = iocpf->ioc;
1127
1128 bfa_trc(ioc, event);
1129
1130 switch (event) {
1131 case IOCPF_E_SEMLOCKED:
1132 iocpf->retry_count = 0;
1133 bfa_ioc_sync_ack(ioc);
1134 bfa_ioc_notify_fail(ioc);
1135 if (!iocpf->auto_recover) {
1136 bfa_ioc_sync_leave(ioc);
1137 writel(1, ioc->ioc_regs.ioc_sem_reg);
1138 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1139 } else {
1140 if (bfa_ioc_sync_complete(ioc))
1141 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1142 else {
1143 writel(1, ioc->ioc_regs.ioc_sem_reg);
1144 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1145 }
1146 }
1147 break;
1148
1149 case IOCPF_E_DISABLE:
1150 bfa_sem_timer_stop(ioc);
1151 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1152 break;
1153
1154 case IOCPF_E_FAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001155 break;
1156
1157 default:
1158 bfa_sm_fault(ioc, event);
1159 }
1160}
1161
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001162static void
1163bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1164{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001165}
1166
Jing Huang5fbe25c2010-10-18 17:17:23 -07001167/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001168 * IOC is in failed state.
1169 */
1170static void
1171bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1172{
1173 struct bfa_ioc_s *ioc = iocpf->ioc;
1174
1175 bfa_trc(ioc, event);
1176
1177 switch (event) {
1178 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001179 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1180 break;
1181
Jing Huang7725ccf2009-09-23 17:46:15 -07001182 default:
1183 bfa_sm_fault(ioc, event);
1184 }
1185}
1186
Jing Huang5fbe25c2010-10-18 17:17:23 -07001187/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001188 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001189 */
1190
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001191/*
1192 * Notify common modules registered for notification.
1193 */
1194static void
1195bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
1196{
1197 struct bfa_ioc_notify_s *notify;
1198 struct list_head *qe;
1199
1200 list_for_each(qe, &ioc->notify_q) {
1201 notify = (struct bfa_ioc_notify_s *)qe;
1202 notify->cbfn(notify->cbarg, event);
1203 }
1204}
1205
Jing Huang7725ccf2009-09-23 17:46:15 -07001206static void
1207bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1208{
Jing Huang7725ccf2009-09-23 17:46:15 -07001209 ioc->cbfn->disable_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001210 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001211}
1212
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001213bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001214bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001215{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001216 u32 r32;
1217 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001218#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001219
Jing Huang53440262010-10-18 17:12:29 -07001220 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001221
1222 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001223 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001224 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001225 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001226 }
1227
1228 if (r32 == 0)
1229 return BFA_TRUE;
1230
Jing Huangd4b671c2010-12-26 21:46:35 -08001231 WARN_ON(cnt >= BFA_SEM_SPINCNT);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001232 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001233}
1234
Jing Huang7725ccf2009-09-23 17:46:15 -07001235static void
1236bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1237{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001238 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001239
Jing Huang5fbe25c2010-10-18 17:17:23 -07001240 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001241 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001242 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001243 */
Jing Huang53440262010-10-18 17:12:29 -07001244 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001245 if (r32 == 0) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001246 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001247 return;
1248 }
1249
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001250 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001251}
1252
Jing Huang5fbe25c2010-10-18 17:17:23 -07001253/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001254 * Initialize LPU local memory (aka secondary memory / SRAM)
1255 */
1256static void
1257bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1258{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001259 u32 pss_ctl;
1260 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001261#define PSS_LMEM_INIT_TIME 10000
1262
Jing Huang53440262010-10-18 17:12:29 -07001263 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001264 pss_ctl &= ~__PSS_LMEM_RESET;
1265 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001266
1267 /*
1268 * i2c workaround 12.5khz clock
1269 */
1270 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001271 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001272
Jing Huang5fbe25c2010-10-18 17:17:23 -07001273 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001274 * wait for memory initialization to be complete
1275 */
1276 i = 0;
1277 do {
Jing Huang53440262010-10-18 17:12:29 -07001278 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001279 i++;
1280 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1281
Jing Huang5fbe25c2010-10-18 17:17:23 -07001282 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001283 * If memory initialization is not successful, IOC timeout will catch
1284 * such failures.
1285 */
Jing Huangd4b671c2010-12-26 21:46:35 -08001286 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
Jing Huang7725ccf2009-09-23 17:46:15 -07001287 bfa_trc(ioc, pss_ctl);
1288
1289 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001290 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001291}
1292
1293static void
1294bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1295{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001296 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001297
Jing Huang5fbe25c2010-10-18 17:17:23 -07001298 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001299 * Take processor out of reset.
1300 */
Jing Huang53440262010-10-18 17:12:29 -07001301 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001302 pss_ctl &= ~__PSS_LPU0_RESET;
1303
Jing Huang53440262010-10-18 17:12:29 -07001304 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001305}
1306
1307static void
1308bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1309{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001310 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001311
Jing Huang5fbe25c2010-10-18 17:17:23 -07001312 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001313 * Put processors in reset.
1314 */
Jing Huang53440262010-10-18 17:12:29 -07001315 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001316 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1317
Jing Huang53440262010-10-18 17:12:29 -07001318 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001319}
1320
Jing Huang5fbe25c2010-10-18 17:17:23 -07001321/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001322 * Get driver and firmware versions.
1323 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001324void
Jing Huang7725ccf2009-09-23 17:46:15 -07001325bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1326{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001327 u32 pgnum, pgoff;
1328 u32 loff = 0;
1329 int i;
1330 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001331
Maggie Zhangf7f738122010-12-09 19:08:43 -08001332 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1333 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang53440262010-10-18 17:12:29 -07001334 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001335
1336 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1337 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001338 fwsig[i] =
1339 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001340 loff += sizeof(u32);
1341 }
1342}
1343
Jing Huang5fbe25c2010-10-18 17:17:23 -07001344/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001345 * Returns TRUE if same.
1346 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001347bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001348bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1349{
1350 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001351 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001352
Jing Huang293f82d2010-07-08 19:45:20 -07001353 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001354 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001355
1356 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1357 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1358 bfa_trc(ioc, i);
1359 bfa_trc(ioc, fwhdr->md5sum[i]);
1360 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1361 return BFA_FALSE;
1362 }
1363 }
1364
1365 bfa_trc(ioc, fwhdr->md5sum[0]);
1366 return BFA_TRUE;
1367}
1368
Jing Huang5fbe25c2010-10-18 17:17:23 -07001369/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001370 * Return true if current running version is valid. Firmware signature and
1371 * execution context (driver/bios) must match.
1372 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001373static bfa_boolean_t
1374bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001375{
1376 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1377
Jing Huang7725ccf2009-09-23 17:46:15 -07001378 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001379 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001380 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001381
1382 if (fwhdr.signature != drv_fwhdr->signature) {
1383 bfa_trc(ioc, fwhdr.signature);
1384 bfa_trc(ioc, drv_fwhdr->signature);
1385 return BFA_FALSE;
1386 }
1387
Jing Huang53440262010-10-18 17:12:29 -07001388 if (swab32(fwhdr.param) != boot_env) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001389 bfa_trc(ioc, fwhdr.param);
1390 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001391 return BFA_FALSE;
1392 }
1393
1394 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1395}
1396
Jing Huang5fbe25c2010-10-18 17:17:23 -07001397/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001398 * Conditionally flush any pending message from firmware at start.
1399 */
1400static void
1401bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1402{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001403 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001404
Jing Huang53440262010-10-18 17:12:29 -07001405 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001406 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001407 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001408}
1409
Jing Huang7725ccf2009-09-23 17:46:15 -07001410static void
1411bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1412{
1413 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001414 bfa_boolean_t fwvalid;
1415 u32 boot_type;
1416 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001417
Jing Huang53440262010-10-18 17:12:29 -07001418 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001419
1420 if (force)
1421 ioc_fwstate = BFI_IOC_UNINIT;
1422
1423 bfa_trc(ioc, ioc_fwstate);
1424
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001425 boot_type = BFI_BOOT_TYPE_NORMAL;
1426 boot_env = BFI_BOOT_LOADER_OS;
1427
Jing Huang5fbe25c2010-10-18 17:17:23 -07001428 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001429 * check if firmware is valid
1430 */
1431 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001432 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001433
1434 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001435 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001436 return;
1437 }
1438
Jing Huang5fbe25c2010-10-18 17:17:23 -07001439 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001440 * If hardware initialization is in progress (initialized by other IOC),
1441 * just wait for an initialization completion interrupt.
1442 */
1443 if (ioc_fwstate == BFI_IOC_INITING) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001444 ioc->cbfn->reset_cbfn(ioc->bfa);
1445 return;
1446 }
1447
Jing Huang5fbe25c2010-10-18 17:17:23 -07001448 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001449 * If IOC function is disabled and firmware version is same,
1450 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001451 *
1452 * If option rom, IOC must not be in operational state. With
1453 * convergence, IOC will be in operational state when 2nd driver
1454 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001455 */
Jing Huang8f4bfad2010-12-26 21:50:10 -08001456 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001457
Jing Huang5fbe25c2010-10-18 17:17:23 -07001458 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001459 * When using MSI-X any pending firmware ready event should
1460 * be flushed. Otherwise MSI-X interrupts are not delivered.
1461 */
1462 bfa_ioc_msgflush(ioc);
1463 ioc->cbfn->reset_cbfn(ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001464 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001465 return;
1466 }
1467
Jing Huang5fbe25c2010-10-18 17:17:23 -07001468 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001469 * Initialize the h/w for any other states.
1470 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001471 bfa_ioc_boot(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001472}
1473
1474static void
1475bfa_ioc_timeout(void *ioc_arg)
1476{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001477 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001478
1479 bfa_trc(ioc, 0);
1480 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1481}
1482
1483void
1484bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1485{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001486 u32 *msgp = (u32 *) ioc_msg;
1487 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001488
1489 bfa_trc(ioc, msgp[0]);
1490 bfa_trc(ioc, len);
1491
Jing Huangd4b671c2010-12-26 21:46:35 -08001492 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
Jing Huang7725ccf2009-09-23 17:46:15 -07001493
1494 /*
1495 * first write msg to mailbox registers
1496 */
1497 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001498 writel(cpu_to_le32(msgp[i]),
1499 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001500
1501 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001502 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001503
1504 /*
1505 * write 1 to mailbox CMD to trigger LPU event
1506 */
Jing Huang53440262010-10-18 17:12:29 -07001507 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1508 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001509}
1510
1511static void
1512bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1513{
1514 struct bfi_ioc_ctrl_req_s enable_req;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001515 struct timeval tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001516
1517 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1518 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001519 enable_req.clscode = cpu_to_be16(ioc->clscode);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001520 do_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001521 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001522 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1523}
1524
1525static void
1526bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1527{
1528 struct bfi_ioc_ctrl_req_s disable_req;
1529
1530 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1531 bfa_ioc_portid(ioc));
1532 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1533}
1534
1535static void
1536bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1537{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001538 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001539
1540 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1541 bfa_ioc_portid(ioc));
1542 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1543 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1544}
1545
1546static void
1547bfa_ioc_hb_check(void *cbarg)
1548{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001549 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001550 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001551
Jing Huang53440262010-10-18 17:12:29 -07001552 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001553 if (ioc->hb_count == hb_count) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001554 bfa_ioc_recover(ioc);
1555 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001556 } else {
1557 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001558 }
1559
1560 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001561 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001562}
1563
1564static void
1565bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1566{
Jing Huang53440262010-10-18 17:12:29 -07001567 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001568 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001569}
1570
Jing Huang5fbe25c2010-10-18 17:17:23 -07001571/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001572 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001573 */
1574static void
1575bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001576 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001577{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001578 u32 *fwimg;
1579 u32 pgnum, pgoff;
1580 u32 loff = 0;
1581 u32 chunkno = 0;
1582 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001583
Jing Huang5fbe25c2010-10-18 17:17:23 -07001584 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001585 * Initialize LMEM first before code download
1586 */
1587 bfa_ioc_lmem_init(ioc);
1588
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001589 bfa_trc(ioc, bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)));
1590 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001591
Maggie Zhangf7f738122010-12-09 19:08:43 -08001592 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1593 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001594
Jing Huang53440262010-10-18 17:12:29 -07001595 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001596
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001597 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001598
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001599 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1600 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001601 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001602 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001603 }
1604
Jing Huang5fbe25c2010-10-18 17:17:23 -07001605 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001606 * write smem
1607 */
1608 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001609 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001610
1611 loff += sizeof(u32);
1612
Jing Huang5fbe25c2010-10-18 17:17:23 -07001613 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001614 * handle page offset wrap around
1615 */
1616 loff = PSS_SMEM_PGOFF(loff);
1617 if (loff == 0) {
1618 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001619 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001620 }
1621 }
1622
Maggie Zhangf7f738122010-12-09 19:08:43 -08001623 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1624 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001625
1626 /*
1627 * Set boot type and boot param at the end.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001628 */
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001629 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001630 swab32(boot_type));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001631 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001632 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001633}
1634
Jing Huang7725ccf2009-09-23 17:46:15 -07001635
Jing Huang5fbe25c2010-10-18 17:17:23 -07001636/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001637 * Update BFA configuration from firmware configuration.
1638 */
1639static void
1640bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1641{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001642 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001643
Jing Huangba816ea2010-10-18 17:10:50 -07001644 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1645 attr->card_type = be32_to_cpu(attr->card_type);
1646 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Jing Huang7725ccf2009-09-23 17:46:15 -07001647
1648 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1649}
1650
Jing Huang5fbe25c2010-10-18 17:17:23 -07001651/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001652 * Attach time initialization of mbox logic.
1653 */
1654static void
1655bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1656{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001657 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1658 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001659
1660 INIT_LIST_HEAD(&mod->cmd_q);
1661 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1662 mod->mbhdlr[mc].cbfn = NULL;
1663 mod->mbhdlr[mc].cbarg = ioc->bfa;
1664 }
1665}
1666
Jing Huang5fbe25c2010-10-18 17:17:23 -07001667/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001668 * Mbox poll timer -- restarts any pending mailbox requests.
1669 */
1670static void
1671bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1672{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001673 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1674 struct bfa_mbox_cmd_s *cmd;
1675 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001676
Jing Huang5fbe25c2010-10-18 17:17:23 -07001677 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001678 * If no command pending, do nothing
1679 */
1680 if (list_empty(&mod->cmd_q))
1681 return;
1682
Jing Huang5fbe25c2010-10-18 17:17:23 -07001683 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001684 * If previous command is not yet fetched by firmware, do nothing
1685 */
Jing Huang53440262010-10-18 17:12:29 -07001686 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001687 if (stat)
1688 return;
1689
Jing Huang5fbe25c2010-10-18 17:17:23 -07001690 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001691 * Enqueue command to firmware.
1692 */
1693 bfa_q_deq(&mod->cmd_q, &cmd);
1694 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1695}
1696
Jing Huang5fbe25c2010-10-18 17:17:23 -07001697/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001698 * Cleanup any pending requests.
1699 */
1700static void
1701bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc)
1702{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001703 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1704 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001705
1706 while (!list_empty(&mod->cmd_q))
1707 bfa_q_deq(&mod->cmd_q, &cmd);
1708}
1709
Jing Huang5fbe25c2010-10-18 17:17:23 -07001710/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001711 * Read data from SMEM to host through PCI memmap
1712 *
1713 * @param[in] ioc memory for IOC
1714 * @param[in] tbuf app memory to store data from smem
1715 * @param[in] soff smem offset
1716 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001717 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001718static bfa_status_t
1719bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1720{
Maggie50444a32010-11-29 18:26:32 -08001721 u32 pgnum, loff;
1722 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001723 int i, len;
1724 u32 *buf = tbuf;
1725
Maggie Zhangf7f738122010-12-09 19:08:43 -08001726 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1727 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001728 bfa_trc(ioc, pgnum);
1729 bfa_trc(ioc, loff);
1730 bfa_trc(ioc, sz);
1731
1732 /*
1733 * Hold semaphore to serialize pll init and fwtrc.
1734 */
1735 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1736 bfa_trc(ioc, 0);
1737 return BFA_STATUS_FAILED;
1738 }
1739
Jing Huang53440262010-10-18 17:12:29 -07001740 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001741
1742 len = sz/sizeof(u32);
1743 bfa_trc(ioc, len);
1744 for (i = 0; i < len; i++) {
1745 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001746 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001747 loff += sizeof(u32);
1748
Jing Huang5fbe25c2010-10-18 17:17:23 -07001749 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001750 * handle page offset wrap around
1751 */
1752 loff = PSS_SMEM_PGOFF(loff);
1753 if (loff == 0) {
1754 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001755 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001756 }
1757 }
Maggie Zhangf7f738122010-12-09 19:08:43 -08001758 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1759 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001760 /*
1761 * release semaphore.
1762 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08001763 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001764
1765 bfa_trc(ioc, pgnum);
1766 return BFA_STATUS_OK;
1767}
1768
Jing Huang5fbe25c2010-10-18 17:17:23 -07001769/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001770 * Clear SMEM data from host through PCI memmap
1771 *
1772 * @param[in] ioc memory for IOC
1773 * @param[in] soff smem offset
1774 * @param[in] sz size of smem in bytes
1775 */
1776static bfa_status_t
1777bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1778{
1779 int i, len;
1780 u32 pgnum, loff;
1781
Maggie Zhangf7f738122010-12-09 19:08:43 -08001782 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1783 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001784 bfa_trc(ioc, pgnum);
1785 bfa_trc(ioc, loff);
1786 bfa_trc(ioc, sz);
1787
1788 /*
1789 * Hold semaphore to serialize pll init and fwtrc.
1790 */
1791 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1792 bfa_trc(ioc, 0);
1793 return BFA_STATUS_FAILED;
1794 }
1795
Jing Huang53440262010-10-18 17:12:29 -07001796 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001797
1798 len = sz/sizeof(u32); /* len in words */
1799 bfa_trc(ioc, len);
1800 for (i = 0; i < len; i++) {
1801 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1802 loff += sizeof(u32);
1803
Jing Huang5fbe25c2010-10-18 17:17:23 -07001804 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001805 * handle page offset wrap around
1806 */
1807 loff = PSS_SMEM_PGOFF(loff);
1808 if (loff == 0) {
1809 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001810 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001811 }
1812 }
Maggie Zhangf7f738122010-12-09 19:08:43 -08001813 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1814 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001815
1816 /*
1817 * release semaphore.
1818 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08001819 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001820 bfa_trc(ioc, pgnum);
1821 return BFA_STATUS_OK;
1822}
1823
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001824static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001825bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1826{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001827 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1828
Jing Huang8f4bfad2010-12-26 21:50:10 -08001829 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001830 * Notify driver and common modules registered for notification.
1831 */
1832 ioc->cbfn->hbfail_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001833 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001834
1835 bfa_ioc_debug_save_ftrc(ioc);
1836
1837 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1838 "Heart Beat of IOC has failed\n");
1839
1840}
1841
1842static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001843bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1844{
1845 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001846 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001847 * Provide enable completion callback.
1848 */
1849 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001850 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001851 "Running firmware version is incompatible "
1852 "with the driver version\n");
1853}
1854
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001855bfa_status_t
1856bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1857{
1858
1859 /*
1860 * Hold semaphore so that nobody can access the chip during init.
1861 */
1862 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1863
1864 bfa_ioc_pll_init_asic(ioc);
1865
1866 ioc->pllinit = BFA_TRUE;
1867 /*
1868 * release semaphore.
1869 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08001870 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001871
1872 return BFA_STATUS_OK;
1873}
Jing Huang7725ccf2009-09-23 17:46:15 -07001874
Jing Huang5fbe25c2010-10-18 17:17:23 -07001875/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001876 * Interface used by diag module to do firmware boot with memory test
1877 * as the entry vector.
1878 */
1879void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001880bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001881{
Jing Huang53440262010-10-18 17:12:29 -07001882 void __iomem *rb;
Jing Huang7725ccf2009-09-23 17:46:15 -07001883
1884 bfa_ioc_stats(ioc, ioc_boots);
1885
1886 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1887 return;
1888
Jing Huang5fbe25c2010-10-18 17:17:23 -07001889 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001890 * Initialize IOC state of all functions on a chip reset.
1891 */
1892 rb = ioc->pcidev.pci_bar_kva;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001893 if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
Jing Huang53440262010-10-18 17:12:29 -07001894 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
1895 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001896 } else {
Jing Huang53440262010-10-18 17:12:29 -07001897 writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
1898 writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
Jing Huang7725ccf2009-09-23 17:46:15 -07001899 }
1900
Jing Huang07b28382010-07-08 19:59:24 -07001901 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001902 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001903
Jing Huang5fbe25c2010-10-18 17:17:23 -07001904 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001905 * Enable interrupts just before starting LPU
1906 */
1907 ioc->cbfn->reset_cbfn(ioc->bfa);
1908 bfa_ioc_lpu_start(ioc);
1909}
1910
Jing Huang5fbe25c2010-10-18 17:17:23 -07001911/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001912 * Enable/disable IOC failure auto recovery.
1913 */
1914void
1915bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
1916{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08001917 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07001918}
1919
1920
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001921
Jing Huang7725ccf2009-09-23 17:46:15 -07001922bfa_boolean_t
1923bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1924{
1925 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
1926}
1927
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001928bfa_boolean_t
1929bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
1930{
Jing Huang53440262010-10-18 17:12:29 -07001931 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001932
1933 return ((r32 != BFI_IOC_UNINIT) &&
1934 (r32 != BFI_IOC_INITING) &&
1935 (r32 != BFI_IOC_MEMTEST));
1936}
1937
Jing Huang7725ccf2009-09-23 17:46:15 -07001938void
1939bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
1940{
Maggie50444a32010-11-29 18:26:32 -08001941 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001942 u32 r32;
1943 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001944
Jing Huang5fbe25c2010-10-18 17:17:23 -07001945 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001946 * read the MBOX msg
1947 */
1948 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1949 i++) {
Jing Huang53440262010-10-18 17:12:29 -07001950 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07001951 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07001952 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07001953 }
1954
Jing Huang5fbe25c2010-10-18 17:17:23 -07001955 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001956 * turn off mailbox interrupt by clearing mailbox status
1957 */
Jing Huang53440262010-10-18 17:12:29 -07001958 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1959 readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001960}
1961
1962void
1963bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
1964{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001965 union bfi_ioc_i2h_msg_u *msg;
1966 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07001967
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001968 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07001969
1970 bfa_ioc_stats(ioc, ioc_isrs);
1971
1972 switch (msg->mh.msg_id) {
1973 case BFI_IOC_I2H_HBEAT:
1974 break;
1975
1976 case BFI_IOC_I2H_READY_EVENT:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001977 bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001978 break;
1979
1980 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001981 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001982 break;
1983
1984 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001985 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001986 break;
1987
1988 case BFI_IOC_I2H_GETATTR_REPLY:
1989 bfa_ioc_getattr_reply(ioc);
1990 break;
1991
1992 default:
1993 bfa_trc(ioc, msg->mh.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001994 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001995 }
1996}
1997
Jing Huang5fbe25c2010-10-18 17:17:23 -07001998/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001999 * IOC attach time initialization and setup.
2000 *
2001 * @param[in] ioc memory for IOC
2002 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07002003 */
2004void
2005bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002006 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07002007{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002008 ioc->bfa = bfa;
2009 ioc->cbfn = cbfn;
2010 ioc->timer_mod = timer_mod;
2011 ioc->fcmode = BFA_FALSE;
2012 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002013 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002014 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002015
2016 bfa_ioc_mbox_attach(ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002017 INIT_LIST_HEAD(&ioc->notify_q);
Jing Huang7725ccf2009-09-23 17:46:15 -07002018
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002019 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
2020 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07002021}
2022
Jing Huang5fbe25c2010-10-18 17:17:23 -07002023/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002024 * Driver detach time IOC cleanup.
2025 */
2026void
2027bfa_ioc_detach(struct bfa_ioc_s *ioc)
2028{
2029 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2030}
2031
Jing Huang5fbe25c2010-10-18 17:17:23 -07002032/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002033 * Setup IOC PCI properties.
2034 *
2035 * @param[in] pcidev PCI device information for this IOC
2036 */
2037void
2038bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002039 enum bfi_pcifn_class clscode)
Jing Huang7725ccf2009-09-23 17:46:15 -07002040{
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002041 ioc->clscode = clscode;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002042 ioc->pcidev = *pcidev;
2043 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
2044 ioc->cna = ioc->ctdev && !ioc->fcmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07002045
Jing Huang5fbe25c2010-10-18 17:17:23 -07002046 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002047 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2048 */
2049 if (ioc->ctdev)
2050 bfa_ioc_set_ct_hwif(ioc);
2051 else
2052 bfa_ioc_set_cb_hwif(ioc);
2053
Jing Huang7725ccf2009-09-23 17:46:15 -07002054 bfa_ioc_map_port(ioc);
2055 bfa_ioc_reg_init(ioc);
2056}
2057
Jing Huang5fbe25c2010-10-18 17:17:23 -07002058/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002059 * Initialize IOC dma memory
2060 *
2061 * @param[in] dm_kva kernel virtual address of IOC dma memory
2062 * @param[in] dm_pa physical address of IOC dma memory
2063 */
2064void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002065bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002066{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002067 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002068 * dma memory for firmware attribute
2069 */
2070 ioc->attr_dma.kva = dm_kva;
2071 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002072 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002073}
2074
Jing Huang7725ccf2009-09-23 17:46:15 -07002075void
2076bfa_ioc_enable(struct bfa_ioc_s *ioc)
2077{
2078 bfa_ioc_stats(ioc, ioc_enables);
2079 ioc->dbg_fwsave_once = BFA_TRUE;
2080
2081 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2082}
2083
2084void
2085bfa_ioc_disable(struct bfa_ioc_s *ioc)
2086{
2087 bfa_ioc_stats(ioc, ioc_disables);
2088 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2089}
2090
Jing Huang7725ccf2009-09-23 17:46:15 -07002091
Jing Huang5fbe25c2010-10-18 17:17:23 -07002092/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002093 * Initialize memory for saving firmware trace. Driver must initialize
2094 * trace memory before call bfa_ioc_enable().
2095 */
2096void
2097bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2098{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002099 ioc->dbg_fwsave = dbg_fwsave;
Maggie Zhangf7f738122010-12-09 19:08:43 -08002100 ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07002101}
2102
Jing Huang5fbe25c2010-10-18 17:17:23 -07002103/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002104 * Register mailbox message handler functions
2105 *
2106 * @param[in] ioc IOC instance
2107 * @param[in] mcfuncs message class handler functions
2108 */
2109void
2110bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2111{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002112 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2113 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002114
2115 for (mc = 0; mc < BFI_MC_MAX; mc++)
2116 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2117}
2118
Jing Huang5fbe25c2010-10-18 17:17:23 -07002119/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002120 * Register mailbox message handler function, to be called by common modules
2121 */
2122void
2123bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2124 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2125{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002126 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002127
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002128 mod->mbhdlr[mc].cbfn = cbfn;
2129 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002130}
2131
Jing Huang5fbe25c2010-10-18 17:17:23 -07002132/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002133 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2134 * Responsibility of caller to serialize
2135 *
2136 * @param[in] ioc IOC instance
2137 * @param[i] cmd Mailbox command
2138 */
2139void
2140bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2141{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002142 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2143 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002144
Jing Huang5fbe25c2010-10-18 17:17:23 -07002145 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002146 * If a previous command is pending, queue new command
2147 */
2148 if (!list_empty(&mod->cmd_q)) {
2149 list_add_tail(&cmd->qe, &mod->cmd_q);
2150 return;
2151 }
2152
Jing Huang5fbe25c2010-10-18 17:17:23 -07002153 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002154 * If mailbox is busy, queue command for poll timer
2155 */
Jing Huang53440262010-10-18 17:12:29 -07002156 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002157 if (stat) {
2158 list_add_tail(&cmd->qe, &mod->cmd_q);
2159 return;
2160 }
2161
Jing Huang5fbe25c2010-10-18 17:17:23 -07002162 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002163 * mailbox is free -- queue command to firmware
2164 */
2165 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2166}
2167
Jing Huang5fbe25c2010-10-18 17:17:23 -07002168/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002169 * Handle mailbox interrupts
2170 */
2171void
2172bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2173{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002174 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2175 struct bfi_mbmsg_s m;
2176 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002177
2178 bfa_ioc_msgget(ioc, &m);
2179
Jing Huang5fbe25c2010-10-18 17:17:23 -07002180 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002181 * Treat IOC message class as special.
2182 */
2183 mc = m.mh.msg_class;
2184 if (mc == BFI_MC_IOC) {
2185 bfa_ioc_isr(ioc, &m);
2186 return;
2187 }
2188
2189 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2190 return;
2191
2192 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2193}
2194
2195void
2196bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2197{
2198 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2199}
2200
Jing Huanged969322010-07-08 19:45:56 -07002201void
2202bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2203{
2204 ioc->fcmode = BFA_TRUE;
2205 ioc->port_id = bfa_ioc_pcifn(ioc);
2206}
2207
Jing Huang5fbe25c2010-10-18 17:17:23 -07002208/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002209 * return true if IOC is disabled
2210 */
2211bfa_boolean_t
2212bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2213{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002214 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2215 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002216}
2217
Jing Huang5fbe25c2010-10-18 17:17:23 -07002218/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002219 * return true if IOC firmware is different.
2220 */
2221bfa_boolean_t
2222bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2223{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002224 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2225 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2226 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002227}
2228
2229#define bfa_ioc_state_disabled(__sm) \
2230 (((__sm) == BFI_IOC_UNINIT) || \
2231 ((__sm) == BFI_IOC_INITING) || \
2232 ((__sm) == BFI_IOC_HWINIT) || \
2233 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002234 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002235 ((__sm) == BFI_IOC_CFG_DISABLED))
2236
Jing Huang5fbe25c2010-10-18 17:17:23 -07002237/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002238 * Check if adapter is disabled -- both IOCs should be in a disabled
2239 * state.
2240 */
2241bfa_boolean_t
2242bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2243{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002244 u32 ioc_state;
Jing Huang53440262010-10-18 17:12:29 -07002245 void __iomem *rb = ioc->pcidev.pci_bar_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002246
2247 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2248 return BFA_FALSE;
2249
Jing Huang53440262010-10-18 17:12:29 -07002250 ioc_state = readl(rb + BFA_IOC0_STATE_REG);
Jing Huang7725ccf2009-09-23 17:46:15 -07002251 if (!bfa_ioc_state_disabled(ioc_state))
2252 return BFA_FALSE;
2253
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002254 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Jing Huang53440262010-10-18 17:12:29 -07002255 ioc_state = readl(rb + BFA_IOC1_STATE_REG);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002256 if (!bfa_ioc_state_disabled(ioc_state))
2257 return BFA_FALSE;
2258 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002259
2260 return BFA_TRUE;
2261}
2262
Jing Huang8f4bfad2010-12-26 21:50:10 -08002263/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002264 * Reset IOC fwstate registers.
2265 */
2266void
2267bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2268{
2269 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2270 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2271}
2272
Jing Huang7725ccf2009-09-23 17:46:15 -07002273#define BFA_MFG_NAME "Brocade"
2274void
2275bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2276 struct bfa_adapter_attr_s *ad_attr)
2277{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002278 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002279
2280 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002281
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002282 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2283 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2284 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2285 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002286 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002287 sizeof(struct bfa_mfg_vpd_s));
2288
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002289 ad_attr->nports = bfa_ioc_get_nports(ioc);
2290 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002291
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002292 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2293 /* For now, model descr uses same model string */
2294 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002295
Jing Huanged969322010-07-08 19:45:56 -07002296 ad_attr->card_type = ioc_attr->card_type;
2297 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2298
Jing Huang7725ccf2009-09-23 17:46:15 -07002299 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2300 ad_attr->prototype = 1;
2301 else
2302 ad_attr->prototype = 0;
2303
Maggie Zhangf7f738122010-12-09 19:08:43 -08002304 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002305 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002306
2307 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2308 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2309 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2310 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002311
2312 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002313
2314 ad_attr->cna_capable = ioc->cna;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002315 ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna &&
2316 !ad_attr->is_mezz;
Jing Huang7725ccf2009-09-23 17:46:15 -07002317}
2318
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002319enum bfa_ioc_type_e
2320bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2321{
2322 if (!ioc->ctdev || ioc->fcmode)
2323 return BFA_IOC_TYPE_FC;
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002324 else if (ioc->clscode == BFI_PCIFN_CLASS_FC)
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002325 return BFA_IOC_TYPE_FCoE;
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002326 else {
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002327 WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_ETH);
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002328 return BFA_IOC_TYPE_LL;
2329 }
2330}
2331
Jing Huang7725ccf2009-09-23 17:46:15 -07002332void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002333bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2334{
Jing Huang6a18b162010-10-18 17:08:54 -07002335 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2336 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002337 (void *)ioc->attr->brcd_serialnum,
2338 BFA_ADAPTER_SERIAL_NUM_LEN);
2339}
2340
2341void
2342bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2343{
Jing Huang6a18b162010-10-18 17:08:54 -07002344 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2345 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002346}
2347
2348void
2349bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2350{
Jing Huangd4b671c2010-12-26 21:46:35 -08002351 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002352
Jing Huang6a18b162010-10-18 17:08:54 -07002353 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002354
2355 chip_rev[0] = 'R';
2356 chip_rev[1] = 'e';
2357 chip_rev[2] = 'v';
2358 chip_rev[3] = '-';
2359 chip_rev[4] = ioc->attr->asic_rev;
2360 chip_rev[5] = '\0';
2361}
2362
2363void
2364bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2365{
Jing Huang6a18b162010-10-18 17:08:54 -07002366 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2367 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002368 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002369}
2370
2371void
2372bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2373{
Jing Huang6a18b162010-10-18 17:08:54 -07002374 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2375 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002376}
2377
2378void
2379bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2380{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002381 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002382
Jing Huangd4b671c2010-12-26 21:46:35 -08002383 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002384 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002385
2386 ioc_attr = ioc->attr;
2387
Jing Huang5fbe25c2010-10-18 17:17:23 -07002388 /*
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002389 * model name
2390 */
Jing Huang6a18b162010-10-18 17:08:54 -07002391 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002392 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002393}
2394
2395enum bfa_ioc_state
2396bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2397{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002398 enum bfa_iocpf_state iocpf_st;
2399 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2400
2401 if (ioc_st == BFA_IOC_ENABLING ||
2402 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2403
2404 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2405
2406 switch (iocpf_st) {
2407 case BFA_IOCPF_SEMWAIT:
2408 ioc_st = BFA_IOC_SEMWAIT;
2409 break;
2410
2411 case BFA_IOCPF_HWINIT:
2412 ioc_st = BFA_IOC_HWINIT;
2413 break;
2414
2415 case BFA_IOCPF_FWMISMATCH:
2416 ioc_st = BFA_IOC_FWMISMATCH;
2417 break;
2418
2419 case BFA_IOCPF_FAIL:
2420 ioc_st = BFA_IOC_FAIL;
2421 break;
2422
2423 case BFA_IOCPF_INITFAIL:
2424 ioc_st = BFA_IOC_INITFAIL;
2425 break;
2426
2427 default:
2428 break;
2429 }
2430 }
2431
2432 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002433}
2434
2435void
Jing Huang7725ccf2009-09-23 17:46:15 -07002436bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2437{
Jing Huang6a18b162010-10-18 17:08:54 -07002438 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002439
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002440 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002441 ioc_attr->port_id = ioc->port_id;
2442
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002443 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002444
2445 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2446
2447 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2448 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002449 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002450}
2451
Jing Huang7725ccf2009-09-23 17:46:15 -07002452mac_t
2453bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2454{
Jing Huang15b64a82010-07-08 19:48:12 -07002455 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002456 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002457 */
2458 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002459 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002460 else
2461 return ioc->attr->mac;
2462}
2463
Jing Huang15b64a82010-07-08 19:48:12 -07002464mac_t
2465bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2466{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002467 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002468
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002469 m = ioc->attr->mfg_mac;
2470 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2471 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2472 else
2473 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2474 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002475
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002476 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002477}
2478
Jing Huang7725ccf2009-09-23 17:46:15 -07002479bfa_boolean_t
2480bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2481{
Jing Huang293f82d2010-07-08 19:45:20 -07002482 return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07002483}
2484
Jing Huang5fbe25c2010-10-18 17:17:23 -07002485/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002486 * Retrieve saved firmware trace from a prior IOC failure.
2487 */
2488bfa_status_t
2489bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2490{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002491 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002492
2493 if (ioc->dbg_fwsave_len == 0)
2494 return BFA_STATUS_ENOFSAVE;
2495
2496 tlen = *trclen;
2497 if (tlen > ioc->dbg_fwsave_len)
2498 tlen = ioc->dbg_fwsave_len;
2499
Jing Huang6a18b162010-10-18 17:08:54 -07002500 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002501 *trclen = tlen;
2502 return BFA_STATUS_OK;
2503}
2504
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002505
Jing Huang5fbe25c2010-10-18 17:17:23 -07002506/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002507 * Retrieve saved firmware trace from a prior IOC failure.
2508 */
2509bfa_status_t
2510bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2511{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002512 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2513 int tlen;
2514 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002515
2516 bfa_trc(ioc, *trclen);
2517
Jing Huang7725ccf2009-09-23 17:46:15 -07002518 tlen = *trclen;
2519 if (tlen > BFA_DBG_FWTRC_LEN)
2520 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002521
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002522 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2523 *trclen = tlen;
2524 return status;
2525}
Jing Huang7725ccf2009-09-23 17:46:15 -07002526
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002527static void
2528bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2529{
2530 struct bfa_mbox_cmd_s cmd;
2531 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002532
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002533 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2534 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002535 req->clscode = cpu_to_be16(ioc->clscode);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002536 bfa_ioc_mbox_queue(ioc, &cmd);
2537}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002538
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002539static void
2540bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2541{
2542 u32 fwsync_iter = 1000;
2543
2544 bfa_ioc_send_fwsync(ioc);
2545
Jing Huang5fbe25c2010-10-18 17:17:23 -07002546 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002547 * After sending a fw sync mbox command wait for it to
2548 * take effect. We will not wait for a response because
2549 * 1. fw_sync mbox cmd doesn't have a response.
2550 * 2. Even if we implement that, interrupts might not
2551 * be enabled when we call this function.
2552 * So, just keep checking if any mbox cmd is pending, and
2553 * after waiting for a reasonable amount of time, go ahead.
2554 * It is possible that fw has crashed and the mbox command
2555 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002556 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002557 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2558 fwsync_iter--;
2559}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002560
Jing Huang5fbe25c2010-10-18 17:17:23 -07002561/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002562 * Dump firmware smem
2563 */
2564bfa_status_t
2565bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2566 u32 *offset, int *buflen)
2567{
2568 u32 loff;
2569 int dlen;
2570 bfa_status_t status;
2571 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002572
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002573 if (*offset >= smem_len) {
2574 *offset = *buflen = 0;
2575 return BFA_STATUS_EINVAL;
2576 }
2577
2578 loff = *offset;
2579 dlen = *buflen;
2580
Jing Huang5fbe25c2010-10-18 17:17:23 -07002581 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002582 * First smem read, sync smem before proceeding
2583 * No need to sync before reading every chunk.
2584 */
2585 if (loff == 0)
2586 bfa_ioc_fwsync(ioc);
2587
2588 if ((loff + dlen) >= smem_len)
2589 dlen = smem_len - loff;
2590
2591 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2592
2593 if (status != BFA_STATUS_OK) {
2594 *offset = *buflen = 0;
2595 return status;
2596 }
2597
2598 *offset += dlen;
2599
2600 if (*offset >= smem_len)
2601 *offset = 0;
2602
2603 *buflen = dlen;
2604
2605 return status;
2606}
2607
Jing Huang5fbe25c2010-10-18 17:17:23 -07002608/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002609 * Firmware statistics
2610 */
2611bfa_status_t
2612bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2613{
2614 u32 loff = BFI_IOC_FWSTATS_OFF + \
2615 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2616 int tlen;
2617 bfa_status_t status;
2618
2619 if (ioc->stats_busy) {
2620 bfa_trc(ioc, ioc->stats_busy);
2621 return BFA_STATUS_DEVBUSY;
2622 }
2623 ioc->stats_busy = BFA_TRUE;
2624
2625 tlen = sizeof(struct bfa_fw_stats_s);
2626 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2627
2628 ioc->stats_busy = BFA_FALSE;
2629 return status;
2630}
2631
2632bfa_status_t
2633bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2634{
2635 u32 loff = BFI_IOC_FWSTATS_OFF + \
2636 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2637 int tlen;
2638 bfa_status_t status;
2639
2640 if (ioc->stats_busy) {
2641 bfa_trc(ioc, ioc->stats_busy);
2642 return BFA_STATUS_DEVBUSY;
2643 }
2644 ioc->stats_busy = BFA_TRUE;
2645
2646 tlen = sizeof(struct bfa_fw_stats_s);
2647 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2648
2649 ioc->stats_busy = BFA_FALSE;
2650 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002651}
2652
Jing Huang5fbe25c2010-10-18 17:17:23 -07002653/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002654 * Save firmware trace if configured.
2655 */
2656static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002657bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002658{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002659 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002660
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002661 if (ioc->dbg_fwsave_once) {
2662 ioc->dbg_fwsave_once = BFA_FALSE;
2663 if (ioc->dbg_fwsave_len) {
2664 tlen = ioc->dbg_fwsave_len;
2665 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2666 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002667 }
2668}
2669
Jing Huang5fbe25c2010-10-18 17:17:23 -07002670/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002671 * Firmware failure detected. Start recovery actions.
2672 */
2673static void
2674bfa_ioc_recover(struct bfa_ioc_s *ioc)
2675{
Jing Huang7725ccf2009-09-23 17:46:15 -07002676 bfa_ioc_stats(ioc, ioc_hbfails);
2677 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2678}
2679
Jing Huang7725ccf2009-09-23 17:46:15 -07002680static void
Jing Huang07b28382010-07-08 19:59:24 -07002681bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002682{
Jing Huang07b28382010-07-08 19:59:24 -07002683 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2684 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002685}
2686
Jing Huang5fbe25c2010-10-18 17:17:23 -07002687/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002688 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002689 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002690static void
2691bfa_iocpf_timeout(void *ioc_arg)
2692{
2693 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2694
2695 bfa_trc(ioc, 0);
2696 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2697}
2698
2699static void
2700bfa_iocpf_sem_timeout(void *ioc_arg)
2701{
2702 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2703
2704 bfa_ioc_hw_sem_get(ioc);
2705}
2706
Jing Huang5fbe25c2010-10-18 17:17:23 -07002707/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002708 * bfa timer function
2709 */
2710void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002711bfa_timer_beat(struct bfa_timer_mod_s *mod)
2712{
2713 struct list_head *qh = &mod->timer_q;
2714 struct list_head *qe, *qe_next;
2715 struct bfa_timer_s *elem;
2716 struct list_head timedout_q;
2717
2718 INIT_LIST_HEAD(&timedout_q);
2719
2720 qe = bfa_q_next(qh);
2721
2722 while (qe != qh) {
2723 qe_next = bfa_q_next(qe);
2724
2725 elem = (struct bfa_timer_s *) qe;
2726 if (elem->timeout <= BFA_TIMER_FREQ) {
2727 elem->timeout = 0;
2728 list_del(&elem->qe);
2729 list_add_tail(&elem->qe, &timedout_q);
2730 } else {
2731 elem->timeout -= BFA_TIMER_FREQ;
2732 }
2733
2734 qe = qe_next; /* go to next elem */
2735 }
2736
2737 /*
2738 * Pop all the timeout entries
2739 */
2740 while (!list_empty(&timedout_q)) {
2741 bfa_q_deq(&timedout_q, &elem);
2742 elem->timercb(elem->arg);
2743 }
2744}
2745
Jing Huang5fbe25c2010-10-18 17:17:23 -07002746/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002747 * Should be called with lock protection
2748 */
2749void
2750bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2751 void (*timercb) (void *), void *arg, unsigned int timeout)
2752{
2753
Jing Huangd4b671c2010-12-26 21:46:35 -08002754 WARN_ON(timercb == NULL);
2755 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002756
2757 timer->timeout = timeout;
2758 timer->timercb = timercb;
2759 timer->arg = arg;
2760
2761 list_add_tail(&timer->qe, &mod->timer_q);
2762}
2763
Jing Huang5fbe25c2010-10-18 17:17:23 -07002764/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002765 * Should be called with lock protection
2766 */
2767void
2768bfa_timer_stop(struct bfa_timer_s *timer)
2769{
Jing Huangd4b671c2010-12-26 21:46:35 -08002770 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002771
2772 list_del(&timer->qe);
2773}