blob: 2c575f5dea048cc95f04c4330d96e6da930a4cbb [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"
Krishna Gudipati11189202011-06-13 15:50:35 -070020#include "bfi_reg.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070021#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 Gudipatia36c61f2010-09-15 11:50:55 -070032#define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
Krishna Gudipati775c7742011-06-13 15:52:12 -070033#define BFA_IOC_POLL_TOV BFA_TIMER_FREQ
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);
Krishna Gudipati775c7742011-06-13 15:52:12 -070082static void bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070083static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
84static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
85static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
86static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070087static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
Krishna Gudipati8b070b42011-06-13 15:52:40 -070088static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070089static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
90static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -070091static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
92 enum bfa_ioc_event_e event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070093static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
94static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -080095static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc);
96static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070097static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -070098
Jing Huang7725ccf2009-09-23 17:46:15 -070099
Jing Huang5fbe25c2010-10-18 17:17:23 -0700100/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101 * IOC state machine definitions/declarations
Jing Huang7725ccf2009-09-23 17:46:15 -0700102 */
103enum ioc_event {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104 IOC_E_RESET = 1, /* IOC reset request */
105 IOC_E_ENABLE = 2, /* IOC enable request */
106 IOC_E_DISABLE = 3, /* IOC disable request */
107 IOC_E_DETACH = 4, /* driver detach cleanup */
108 IOC_E_ENABLED = 5, /* f/w enabled */
109 IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
110 IOC_E_DISABLED = 7, /* f/w disabled */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700111 IOC_E_PFFAILED = 8, /* failure notice by iocpf sm */
112 IOC_E_HBFAIL = 9, /* heartbeat failure */
113 IOC_E_HWERROR = 10, /* hardware error interrupt */
114 IOC_E_TIMEOUT = 11, /* 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
Krishna Gudipati775c7742011-06-13 15:52:12 -0700148#define bfa_iocpf_poll_timer_start(__ioc) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700149 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
Krishna Gudipati775c7742011-06-13 15:52:12 -0700150 bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700151
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);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700162static void bfa_iocpf_poll_timeout(void *ioc_arg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700163
Jing Huang5fbe25c2010-10-18 17:17:23 -0700164/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700165 * IOCPF state machine events
166 */
167enum iocpf_event {
168 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
169 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
170 IOCPF_E_STOP = 3, /* stop on driver detach */
171 IOCPF_E_FWREADY = 4, /* f/w initialization done */
172 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
173 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
174 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
175 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
176 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
177 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
178 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
179};
180
Jing Huang5fbe25c2010-10-18 17:17:23 -0700181/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700182 * IOCPF states
183 */
184enum bfa_iocpf_state {
185 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
186 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
187 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
188 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
189 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
190 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
191 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
192 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
193 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
194};
195
196bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
197bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
198bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
199bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
200bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
201bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
202bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800203bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
204 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700205bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800206bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700207bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
208bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800209bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
210 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700211bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
212
213static struct bfa_sm_table_s iocpf_sm_table[] = {
214 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
215 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
216 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
217 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
218 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
219 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
220 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800221 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700222 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800223 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700224 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
225 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800226 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700227 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
228};
229
Jing Huang5fbe25c2010-10-18 17:17:23 -0700230/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700231 * IOC State Machine
232 */
233
Jing Huang5fbe25c2010-10-18 17:17:23 -0700234/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700235 * Beginning state. IOC uninit state.
236 */
237
238static void
239bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
240{
241}
242
Jing Huang5fbe25c2010-10-18 17:17:23 -0700243/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700244 * IOC is in uninit state.
245 */
246static void
247bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
248{
249 bfa_trc(ioc, event);
250
251 switch (event) {
252 case IOC_E_RESET:
253 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
254 break;
255
256 default:
257 bfa_sm_fault(ioc, event);
258 }
259}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700260/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700261 * Reset entry actions -- initialize state machine
262 */
263static void
264bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
265{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700266 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700267}
268
Jing Huang5fbe25c2010-10-18 17:17:23 -0700269/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700270 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700271 */
272static void
273bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
274{
275 bfa_trc(ioc, event);
276
277 switch (event) {
278 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700279 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
280 break;
281
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700282 case IOC_E_DISABLE:
283 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700284 break;
285
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700286 case IOC_E_DETACH:
287 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700288 break;
289
290 default:
291 bfa_sm_fault(ioc, event);
292 }
293}
294
295
296static void
297bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
298{
Maggie Zhangf7f738122010-12-09 19:08:43 -0800299 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700300}
301
Jing Huang5fbe25c2010-10-18 17:17:23 -0700302/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700303 * Host IOC function is being enabled, awaiting response from firmware.
304 * Semaphore is acquired.
305 */
306static void
307bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
308{
309 bfa_trc(ioc, event);
310
311 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700312 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700313 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
314 break;
315
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800316 case IOC_E_PFFAILED:
317 /* !!! fall through !!! */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700318 case IOC_E_HWERROR:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800319 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700320 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800321 if (event != IOC_E_PFFAILED)
322 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700323 break;
324
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700325 case IOC_E_DISABLE:
326 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
327 break;
328
329 case IOC_E_DETACH:
330 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800331 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700332 break;
333
334 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700335 break;
336
337 default:
338 bfa_sm_fault(ioc, event);
339 }
340}
341
342
343static void
344bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
345{
346 bfa_ioc_timer_start(ioc);
347 bfa_ioc_send_getattr(ioc);
348}
349
Jing Huang5fbe25c2010-10-18 17:17:23 -0700350/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700351 * IOC configuration in progress. Timer is active.
352 */
353static void
354bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
355{
356 bfa_trc(ioc, event);
357
358 switch (event) {
359 case IOC_E_FWRSP_GETATTR:
360 bfa_ioc_timer_stop(ioc);
Jing Huang07b28382010-07-08 19:59:24 -0700361 bfa_ioc_check_attr_wwns(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700362 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
363 break;
364
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700365 break;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800366 case IOC_E_PFFAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700367 case IOC_E_HWERROR:
368 bfa_ioc_timer_stop(ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800369 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700370 case IOC_E_TIMEOUT:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800371 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700372 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800373 if (event != IOC_E_PFFAILED)
374 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700375 break;
376
377 case IOC_E_DISABLE:
378 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700379 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
380 break;
381
382 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700383 break;
384
385 default:
386 bfa_sm_fault(ioc, event);
387 }
388}
389
390
391static void
392bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
393{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700394 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
395
Jing Huang7725ccf2009-09-23 17:46:15 -0700396 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700397 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -0700398 bfa_ioc_hb_monitor(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800399 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700400}
401
402static void
403bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
404{
405 bfa_trc(ioc, event);
406
407 switch (event) {
408 case IOC_E_ENABLE:
409 break;
410
411 case IOC_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800412 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700413 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
414 break;
415
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800416 case IOC_E_PFFAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700417 case IOC_E_HWERROR:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800418 bfa_hb_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700419 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700420 case IOC_E_HBFAIL:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800421 if (ioc->iocpf.auto_recover)
422 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
423 else
424 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
425
Krishna Gudipati775c7742011-06-13 15:52:12 -0700426 bfa_ioc_fail_notify(ioc);
427
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800428 if (event != IOC_E_PFFAILED)
429 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700430 break;
431
432 default:
433 bfa_sm_fault(ioc, event);
434 }
435}
436
437
438static void
439bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
440{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700441 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800442 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
Jing Huang88166242010-12-09 17:11:53 -0800443 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700444}
445
Jing Huang5fbe25c2010-10-18 17:17:23 -0700446/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700447 * IOC is being disabled
448 */
449static void
450bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
451{
452 bfa_trc(ioc, event);
453
454 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700455 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800456 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
457 break;
458
459 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700460 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700461 * No state change. Will move to disabled state
462 * after iocpf sm completes failure processing and
463 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700464 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800465 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700466 break;
467
468 default:
469 bfa_sm_fault(ioc, event);
470 }
471}
472
Jing Huang5fbe25c2010-10-18 17:17:23 -0700473/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700474 * IOC disable completion entry.
475 */
476static void
477bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
478{
479 bfa_ioc_disable_comp(ioc);
480}
481
482static void
483bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
484{
485 bfa_trc(ioc, event);
486
487 switch (event) {
488 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700489 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700490 break;
491
492 case IOC_E_DISABLE:
493 ioc->cbfn->disable_cbfn(ioc->bfa);
494 break;
495
Jing Huang7725ccf2009-09-23 17:46:15 -0700496 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700497 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800498 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700499 break;
500
501 default:
502 bfa_sm_fault(ioc, event);
503 }
504}
505
506
507static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800508bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700509{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800510 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700511}
512
Jing Huang5fbe25c2010-10-18 17:17:23 -0700513/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800514 * Hardware initialization retry.
Jing Huang7725ccf2009-09-23 17:46:15 -0700515 */
516static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800517bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700518{
519 bfa_trc(ioc, event);
520
521 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700522 case IOC_E_ENABLED:
523 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
524 break;
525
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800526 case IOC_E_PFFAILED:
527 case IOC_E_HWERROR:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700528 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800529 * Initialization retry failed.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700530 */
531 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700532 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800533 if (event != IOC_E_PFFAILED)
534 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
535 break;
536
537 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700538 break;
539
Jing Huang7725ccf2009-09-23 17:46:15 -0700540 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700541 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700542 break;
543
544 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700545 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800546 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700547 break;
548
549 default:
550 bfa_sm_fault(ioc, event);
551 }
552}
553
554
555static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700556bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700557{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800558 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700559}
560
Jing Huang5fbe25c2010-10-18 17:17:23 -0700561/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700562 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700563 */
564static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700565bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700566{
567 bfa_trc(ioc, event);
568
569 switch (event) {
570
571 case IOC_E_ENABLE:
572 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
573 break;
574
575 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700576 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700577 break;
578
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800579 case IOC_E_DETACH:
580 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
581 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
582 break;
583
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800584 case IOC_E_HWERROR:
585 /*
586 * HB failure notification, ignore.
587 */
588 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700589 default:
590 bfa_sm_fault(ioc, event);
591 }
592}
593
Jing Huang5fbe25c2010-10-18 17:17:23 -0700594/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700595 * IOCPF State Machine
596 */
597
Jing Huang5fbe25c2010-10-18 17:17:23 -0700598/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700599 * Reset entry actions -- initialize state machine
600 */
601static void
602bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
603{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700604 iocpf->fw_mismatch_notified = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700605 iocpf->auto_recover = bfa_auto_recover;
606}
607
Jing Huang5fbe25c2010-10-18 17:17:23 -0700608/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700609 * Beginning state. IOC is in reset state.
610 */
611static void
612bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
613{
614 struct bfa_ioc_s *ioc = iocpf->ioc;
615
616 bfa_trc(ioc, event);
617
618 switch (event) {
619 case IOCPF_E_ENABLE:
620 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
621 break;
622
623 case IOCPF_E_STOP:
624 break;
625
626 default:
627 bfa_sm_fault(ioc, event);
628 }
629}
630
Jing Huang5fbe25c2010-10-18 17:17:23 -0700631/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700632 * Semaphore should be acquired for version check.
633 */
634static void
635bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
636{
637 bfa_ioc_hw_sem_get(iocpf->ioc);
638}
639
Jing Huang5fbe25c2010-10-18 17:17:23 -0700640/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700641 * Awaiting h/w semaphore to continue with version check.
642 */
643static void
644bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
645{
646 struct bfa_ioc_s *ioc = iocpf->ioc;
647
648 bfa_trc(ioc, event);
649
650 switch (event) {
651 case IOCPF_E_SEMLOCKED:
652 if (bfa_ioc_firmware_lock(ioc)) {
Jing Huang45d7f0c2011-04-13 11:45:53 -0700653 if (bfa_ioc_sync_start(ioc)) {
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800654 bfa_ioc_sync_join(ioc);
655 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
656 } else {
657 bfa_ioc_firmware_unlock(ioc);
658 writel(1, ioc->ioc_regs.ioc_sem_reg);
659 bfa_sem_timer_start(ioc);
660 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700661 } else {
Maggie Zhangf7f738122010-12-09 19:08:43 -0800662 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700663 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
664 }
665 break;
666
667 case IOCPF_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800668 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700669 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800670 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700671 break;
672
673 case IOCPF_E_STOP:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800674 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700675 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
676 break;
677
678 default:
679 bfa_sm_fault(ioc, event);
680 }
681}
682
Jing Huang5fbe25c2010-10-18 17:17:23 -0700683/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700684 * Notify enable completion callback.
685 */
686static void
687bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
688{
689 /*
690 * Call only the first time sm enters fwmismatch state.
691 */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700692 if (iocpf->fw_mismatch_notified == BFA_FALSE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700693 bfa_ioc_pf_fwmismatch(iocpf->ioc);
694
Krishna Gudipati775c7742011-06-13 15:52:12 -0700695 iocpf->fw_mismatch_notified = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700696 bfa_iocpf_timer_start(iocpf->ioc);
697}
698
Jing Huang5fbe25c2010-10-18 17:17:23 -0700699/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700700 * Awaiting firmware version match.
701 */
702static void
703bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
704{
705 struct bfa_ioc_s *ioc = iocpf->ioc;
706
707 bfa_trc(ioc, event);
708
709 switch (event) {
710 case IOCPF_E_TIMEOUT:
711 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
712 break;
713
714 case IOCPF_E_DISABLE:
715 bfa_iocpf_timer_stop(ioc);
716 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800717 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700718 break;
719
720 case IOCPF_E_STOP:
721 bfa_iocpf_timer_stop(ioc);
722 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
723 break;
724
725 default:
726 bfa_sm_fault(ioc, event);
727 }
728}
729
Jing Huang5fbe25c2010-10-18 17:17:23 -0700730/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700731 * Request for semaphore.
732 */
733static void
734bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
735{
736 bfa_ioc_hw_sem_get(iocpf->ioc);
737}
738
Jing Huang5fbe25c2010-10-18 17:17:23 -0700739/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700740 * Awaiting semaphore for h/w initialzation.
741 */
742static void
743bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
744{
745 struct bfa_ioc_s *ioc = iocpf->ioc;
746
747 bfa_trc(ioc, event);
748
749 switch (event) {
750 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800751 if (bfa_ioc_sync_complete(ioc)) {
752 bfa_ioc_sync_join(ioc);
753 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
754 } else {
755 writel(1, ioc->ioc_regs.ioc_sem_reg);
756 bfa_sem_timer_start(ioc);
757 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700758 break;
759
760 case IOCPF_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800761 bfa_sem_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800762 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700763 break;
764
765 default:
766 bfa_sm_fault(ioc, event);
767 }
768}
769
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700770static void
771bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
772{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700773 iocpf->poll_time = 0;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800774 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700775}
776
Jing Huang5fbe25c2010-10-18 17:17:23 -0700777/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700778 * Hardware is being initialized. Interrupts are enabled.
779 * Holding hardware semaphore lock.
780 */
781static void
782bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
783{
784 struct bfa_ioc_s *ioc = iocpf->ioc;
785
786 bfa_trc(ioc, event);
787
788 switch (event) {
789 case IOCPF_E_FWREADY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700790 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
791 break;
792
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700793 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800794 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700795 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800796 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700797 break;
798
799 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700800 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800801 bfa_ioc_sync_leave(ioc);
802 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700803 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
804 break;
805
806 default:
807 bfa_sm_fault(ioc, event);
808 }
809}
810
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811static void
812bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
813{
814 bfa_iocpf_timer_start(iocpf->ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700815 /*
816 * Enable Interrupts before sending fw IOC ENABLE cmd.
817 */
818 iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700819 bfa_ioc_send_enable(iocpf->ioc);
820}
821
Jing Huang5fbe25c2010-10-18 17:17:23 -0700822/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700823 * Host IOC function is being enabled, awaiting response from firmware.
824 * Semaphore is acquired.
825 */
826static void
827bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
828{
829 struct bfa_ioc_s *ioc = iocpf->ioc;
830
831 bfa_trc(ioc, event);
832
833 switch (event) {
834 case IOCPF_E_FWRSP_ENABLE:
835 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800836 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700837 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
838 break;
839
840 case IOCPF_E_INITFAIL:
841 bfa_iocpf_timer_stop(ioc);
842 /*
843 * !!! fall through !!!
844 */
845
846 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800847 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700848 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800849 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800850 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700851 break;
852
853 case IOCPF_E_DISABLE:
854 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800855 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700856 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
857 break;
858
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700859 default:
860 bfa_sm_fault(ioc, event);
861 }
862}
863
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700864static void
865bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
866{
Maggie Zhangf7f738122010-12-09 19:08:43 -0800867 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700868}
869
870static void
871bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
872{
873 struct bfa_ioc_s *ioc = iocpf->ioc;
874
875 bfa_trc(ioc, event);
876
877 switch (event) {
878 case IOCPF_E_DISABLE:
879 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
880 break;
881
882 case IOCPF_E_GETATTRFAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800883 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700884 break;
885
886 case IOCPF_E_FAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800887 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700888 break;
889
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700890 default:
891 bfa_sm_fault(ioc, event);
892 }
893}
894
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700895static void
896bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
897{
898 bfa_iocpf_timer_start(iocpf->ioc);
899 bfa_ioc_send_disable(iocpf->ioc);
900}
901
Jing Huang5fbe25c2010-10-18 17:17:23 -0700902/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700903 * IOC is being disabled
904 */
905static void
906bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
907{
908 struct bfa_ioc_s *ioc = iocpf->ioc;
909
910 bfa_trc(ioc, event);
911
912 switch (event) {
913 case IOCPF_E_FWRSP_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700914 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800915 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700916 break;
917
918 case IOCPF_E_FAIL:
919 bfa_iocpf_timer_stop(ioc);
920 /*
921 * !!! fall through !!!
922 */
923
924 case IOCPF_E_TIMEOUT:
Jing Huang53440262010-10-18 17:12:29 -0700925 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800926 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700927 break;
928
929 case IOCPF_E_FWRSP_ENABLE:
930 break;
931
932 default:
933 bfa_sm_fault(ioc, event);
934 }
935}
936
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800937static void
938bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
939{
940 bfa_ioc_hw_sem_get(iocpf->ioc);
941}
942
Jing Huang8f4bfad2010-12-26 21:50:10 -0800943/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800944 * IOC hb ack request is being removed.
945 */
946static void
947bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
948{
949 struct bfa_ioc_s *ioc = iocpf->ioc;
950
951 bfa_trc(ioc, event);
952
953 switch (event) {
954 case IOCPF_E_SEMLOCKED:
955 bfa_ioc_sync_leave(ioc);
956 writel(1, ioc->ioc_regs.ioc_sem_reg);
957 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
958 break;
959
960 case IOCPF_E_FAIL:
961 break;
962
963 default:
964 bfa_sm_fault(ioc, event);
965 }
966}
967
Jing Huang5fbe25c2010-10-18 17:17:23 -0700968/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700969 * IOC disable completion entry.
970 */
971static void
972bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
973{
Krishna Gudipati8b070b42011-06-13 15:52:40 -0700974 bfa_ioc_mbox_flush(iocpf->ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800975 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700976}
977
978static void
979bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
980{
981 struct bfa_ioc_s *ioc = iocpf->ioc;
982
983 bfa_trc(ioc, event);
984
985 switch (event) {
986 case IOCPF_E_ENABLE:
987 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
988 break;
989
990 case IOCPF_E_STOP:
991 bfa_ioc_firmware_unlock(ioc);
992 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
993 break;
994
995 default:
996 bfa_sm_fault(ioc, event);
997 }
998}
999
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001000static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001001bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1002{
1003 bfa_ioc_hw_sem_get(iocpf->ioc);
1004}
1005
Jing Huang8f4bfad2010-12-26 21:50:10 -08001006/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001007 * Hardware initialization failed.
1008 */
1009static void
1010bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1011{
1012 struct bfa_ioc_s *ioc = iocpf->ioc;
1013
1014 bfa_trc(ioc, event);
1015
1016 switch (event) {
1017 case IOCPF_E_SEMLOCKED:
1018 bfa_ioc_notify_fail(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001019 bfa_ioc_sync_leave(ioc);
1020 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1021 writel(1, ioc->ioc_regs.ioc_sem_reg);
1022 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001023 break;
1024
1025 case IOCPF_E_DISABLE:
1026 bfa_sem_timer_stop(ioc);
1027 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1028 break;
1029
1030 case IOCPF_E_STOP:
1031 bfa_sem_timer_stop(ioc);
1032 bfa_ioc_firmware_unlock(ioc);
1033 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1034 break;
1035
1036 case IOCPF_E_FAIL:
1037 break;
1038
1039 default:
1040 bfa_sm_fault(ioc, event);
1041 }
1042}
1043
1044static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001045bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1046{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001047}
1048
Jing Huang5fbe25c2010-10-18 17:17:23 -07001049/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001050 * Hardware initialization failed.
1051 */
1052static void
1053bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1054{
1055 struct bfa_ioc_s *ioc = iocpf->ioc;
1056
1057 bfa_trc(ioc, event);
1058
1059 switch (event) {
1060 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001061 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1062 break;
1063
1064 case IOCPF_E_STOP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001065 bfa_ioc_firmware_unlock(ioc);
1066 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1067 break;
1068
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001069 default:
1070 bfa_sm_fault(ioc, event);
1071 }
1072}
1073
1074static void
1075bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1076{
Jing Huang8f4bfad2010-12-26 21:50:10 -08001077 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001078 * Mark IOC as failed in hardware and stop firmware.
1079 */
1080 bfa_ioc_lpu_stop(iocpf->ioc);
1081
Jing Huang8f4bfad2010-12-26 21:50:10 -08001082 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001083 * Flush any queued up mailbox requests.
1084 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001085 bfa_ioc_mbox_flush(iocpf->ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001086
1087 bfa_ioc_hw_sem_get(iocpf->ioc);
1088}
1089
1090static void
1091bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1092{
1093 struct bfa_ioc_s *ioc = iocpf->ioc;
1094
1095 bfa_trc(ioc, event);
1096
1097 switch (event) {
1098 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001099 bfa_ioc_sync_ack(ioc);
1100 bfa_ioc_notify_fail(ioc);
1101 if (!iocpf->auto_recover) {
1102 bfa_ioc_sync_leave(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001103 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001104 writel(1, ioc->ioc_regs.ioc_sem_reg);
1105 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1106 } else {
1107 if (bfa_ioc_sync_complete(ioc))
1108 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1109 else {
1110 writel(1, ioc->ioc_regs.ioc_sem_reg);
1111 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1112 }
1113 }
1114 break;
1115
1116 case IOCPF_E_DISABLE:
1117 bfa_sem_timer_stop(ioc);
1118 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1119 break;
1120
1121 case IOCPF_E_FAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001122 break;
1123
1124 default:
1125 bfa_sm_fault(ioc, event);
1126 }
1127}
1128
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001129static void
1130bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1131{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001132}
1133
Jing Huang5fbe25c2010-10-18 17:17:23 -07001134/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001135 * IOC is in failed state.
1136 */
1137static void
1138bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1139{
1140 struct bfa_ioc_s *ioc = iocpf->ioc;
1141
1142 bfa_trc(ioc, event);
1143
1144 switch (event) {
1145 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001146 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1147 break;
1148
Jing Huang7725ccf2009-09-23 17:46:15 -07001149 default:
1150 bfa_sm_fault(ioc, event);
1151 }
1152}
1153
Jing Huang5fbe25c2010-10-18 17:17:23 -07001154/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001155 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001156 */
1157
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001158/*
1159 * Notify common modules registered for notification.
1160 */
1161static void
1162bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
1163{
1164 struct bfa_ioc_notify_s *notify;
1165 struct list_head *qe;
1166
1167 list_for_each(qe, &ioc->notify_q) {
1168 notify = (struct bfa_ioc_notify_s *)qe;
1169 notify->cbfn(notify->cbarg, event);
1170 }
1171}
1172
Jing Huang7725ccf2009-09-23 17:46:15 -07001173static void
1174bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1175{
Jing Huang7725ccf2009-09-23 17:46:15 -07001176 ioc->cbfn->disable_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001177 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001178}
1179
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001180bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001181bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001182{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001183 u32 r32;
1184 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001185#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001186
Jing Huang53440262010-10-18 17:12:29 -07001187 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001188
Krishna Gudipati11189202011-06-13 15:50:35 -07001189 while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001190 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001191 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001192 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001193 }
1194
Krishna Gudipati11189202011-06-13 15:50:35 -07001195 if (!(r32 & 1))
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001196 return BFA_TRUE;
1197
Jing Huangd4b671c2010-12-26 21:46:35 -08001198 WARN_ON(cnt >= BFA_SEM_SPINCNT);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001199 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001200}
1201
Jing Huang7725ccf2009-09-23 17:46:15 -07001202static void
1203bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1204{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001205 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001206
Jing Huang5fbe25c2010-10-18 17:17:23 -07001207 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001208 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001209 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001210 */
Jing Huang53440262010-10-18 17:12:29 -07001211 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati11189202011-06-13 15:50:35 -07001212 if (!(r32 & 1)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001213 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001214 return;
1215 }
1216
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001217 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001218}
1219
Jing Huang5fbe25c2010-10-18 17:17:23 -07001220/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001221 * Initialize LPU local memory (aka secondary memory / SRAM)
1222 */
1223static void
1224bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1225{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001226 u32 pss_ctl;
1227 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001228#define PSS_LMEM_INIT_TIME 10000
1229
Jing Huang53440262010-10-18 17:12:29 -07001230 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001231 pss_ctl &= ~__PSS_LMEM_RESET;
1232 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001233
1234 /*
1235 * i2c workaround 12.5khz clock
1236 */
1237 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001238 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001239
Jing Huang5fbe25c2010-10-18 17:17:23 -07001240 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001241 * wait for memory initialization to be complete
1242 */
1243 i = 0;
1244 do {
Jing Huang53440262010-10-18 17:12:29 -07001245 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001246 i++;
1247 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1248
Jing Huang5fbe25c2010-10-18 17:17:23 -07001249 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001250 * If memory initialization is not successful, IOC timeout will catch
1251 * such failures.
1252 */
Jing Huangd4b671c2010-12-26 21:46:35 -08001253 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
Jing Huang7725ccf2009-09-23 17:46:15 -07001254 bfa_trc(ioc, pss_ctl);
1255
1256 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001257 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001258}
1259
1260static void
1261bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1262{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001263 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001264
Jing Huang5fbe25c2010-10-18 17:17:23 -07001265 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001266 * Take processor out of reset.
1267 */
Jing Huang53440262010-10-18 17:12:29 -07001268 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001269 pss_ctl &= ~__PSS_LPU0_RESET;
1270
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}
1273
1274static void
1275bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1276{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001277 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001278
Jing Huang5fbe25c2010-10-18 17:17:23 -07001279 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001280 * Put processors in reset.
1281 */
Jing Huang53440262010-10-18 17:12:29 -07001282 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001283 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1284
Jing Huang53440262010-10-18 17:12:29 -07001285 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001286}
1287
Jing Huang5fbe25c2010-10-18 17:17:23 -07001288/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001289 * Get driver and firmware versions.
1290 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001291void
Jing Huang7725ccf2009-09-23 17:46:15 -07001292bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1293{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001294 u32 pgnum, pgoff;
1295 u32 loff = 0;
1296 int i;
1297 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001298
Maggie Zhangf7f738122010-12-09 19:08:43 -08001299 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1300 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang53440262010-10-18 17:12:29 -07001301 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001302
1303 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1304 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001305 fwsig[i] =
1306 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001307 loff += sizeof(u32);
1308 }
1309}
1310
Jing Huang5fbe25c2010-10-18 17:17:23 -07001311/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001312 * Returns TRUE if same.
1313 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001314bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001315bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1316{
1317 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001318 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001319
Jing Huang293f82d2010-07-08 19:45:20 -07001320 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001321 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001322
1323 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1324 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1325 bfa_trc(ioc, i);
1326 bfa_trc(ioc, fwhdr->md5sum[i]);
1327 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1328 return BFA_FALSE;
1329 }
1330 }
1331
1332 bfa_trc(ioc, fwhdr->md5sum[0]);
1333 return BFA_TRUE;
1334}
1335
Jing Huang5fbe25c2010-10-18 17:17:23 -07001336/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001337 * Return true if current running version is valid. Firmware signature and
1338 * execution context (driver/bios) must match.
1339 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001340static bfa_boolean_t
1341bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001342{
1343 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1344
Jing Huang7725ccf2009-09-23 17:46:15 -07001345 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001346 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001347 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001348
1349 if (fwhdr.signature != drv_fwhdr->signature) {
1350 bfa_trc(ioc, fwhdr.signature);
1351 bfa_trc(ioc, drv_fwhdr->signature);
1352 return BFA_FALSE;
1353 }
1354
Krishna Gudipati11189202011-06-13 15:50:35 -07001355 if (swab32(fwhdr.bootenv) != boot_env) {
1356 bfa_trc(ioc, fwhdr.bootenv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001357 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001358 return BFA_FALSE;
1359 }
1360
1361 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1362}
1363
Jing Huang5fbe25c2010-10-18 17:17:23 -07001364/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001365 * Conditionally flush any pending message from firmware at start.
1366 */
1367static void
1368bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1369{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001370 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001371
Jing Huang53440262010-10-18 17:12:29 -07001372 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001373 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001374 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001375}
1376
Jing Huang7725ccf2009-09-23 17:46:15 -07001377static void
1378bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1379{
1380 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001381 bfa_boolean_t fwvalid;
1382 u32 boot_type;
1383 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001384
Jing Huang53440262010-10-18 17:12:29 -07001385 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001386
1387 if (force)
1388 ioc_fwstate = BFI_IOC_UNINIT;
1389
1390 bfa_trc(ioc, ioc_fwstate);
1391
Krishna Gudipati11189202011-06-13 15:50:35 -07001392 boot_type = BFI_FWBOOT_TYPE_NORMAL;
1393 boot_env = BFI_FWBOOT_ENV_OS;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001394
Jing Huang5fbe25c2010-10-18 17:17:23 -07001395 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001396 * check if firmware is valid
1397 */
1398 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001399 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001400
1401 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001402 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001403 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001404 return;
1405 }
1406
Jing Huang5fbe25c2010-10-18 17:17:23 -07001407 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001408 * If hardware initialization is in progress (initialized by other IOC),
1409 * just wait for an initialization completion interrupt.
1410 */
1411 if (ioc_fwstate == BFI_IOC_INITING) {
Krishna Gudipati775c7742011-06-13 15:52:12 -07001412 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001413 return;
1414 }
1415
Jing Huang5fbe25c2010-10-18 17:17:23 -07001416 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001417 * If IOC function is disabled and firmware version is same,
1418 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001419 *
1420 * If option rom, IOC must not be in operational state. With
1421 * convergence, IOC will be in operational state when 2nd driver
1422 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001423 */
Jing Huang8f4bfad2010-12-26 21:50:10 -08001424 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001425
Jing Huang5fbe25c2010-10-18 17:17:23 -07001426 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001427 * When using MSI-X any pending firmware ready event should
1428 * be flushed. Otherwise MSI-X interrupts are not delivered.
1429 */
1430 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001431 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001432 return;
1433 }
1434
Jing Huang5fbe25c2010-10-18 17:17:23 -07001435 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001436 * Initialize the h/w for any other states.
1437 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001438 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001439 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001440}
1441
1442static void
1443bfa_ioc_timeout(void *ioc_arg)
1444{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001445 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001446
1447 bfa_trc(ioc, 0);
1448 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1449}
1450
1451void
1452bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1453{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001454 u32 *msgp = (u32 *) ioc_msg;
1455 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001456
1457 bfa_trc(ioc, msgp[0]);
1458 bfa_trc(ioc, len);
1459
Jing Huangd4b671c2010-12-26 21:46:35 -08001460 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
Jing Huang7725ccf2009-09-23 17:46:15 -07001461
1462 /*
1463 * first write msg to mailbox registers
1464 */
1465 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001466 writel(cpu_to_le32(msgp[i]),
1467 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001468
1469 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001470 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001471
1472 /*
1473 * write 1 to mailbox CMD to trigger LPU event
1474 */
Jing Huang53440262010-10-18 17:12:29 -07001475 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1476 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001477}
1478
1479static void
1480bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1481{
1482 struct bfi_ioc_ctrl_req_s enable_req;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001483 struct timeval tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001484
1485 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1486 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001487 enable_req.clscode = cpu_to_be16(ioc->clscode);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001488 do_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001489 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001490 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1491}
1492
1493static void
1494bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1495{
1496 struct bfi_ioc_ctrl_req_s disable_req;
1497
1498 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1499 bfa_ioc_portid(ioc));
1500 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1501}
1502
1503static void
1504bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1505{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001506 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001507
1508 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1509 bfa_ioc_portid(ioc));
1510 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1511 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1512}
1513
1514static void
1515bfa_ioc_hb_check(void *cbarg)
1516{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001517 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001518 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001519
Jing Huang53440262010-10-18 17:12:29 -07001520 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001521 if (ioc->hb_count == hb_count) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001522 bfa_ioc_recover(ioc);
1523 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001524 } else {
1525 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001526 }
1527
1528 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001529 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001530}
1531
1532static void
1533bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1534{
Jing Huang53440262010-10-18 17:12:29 -07001535 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001536 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001537}
1538
Jing Huang5fbe25c2010-10-18 17:17:23 -07001539/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001540 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001541 */
1542static void
1543bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001544 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001545{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001546 u32 *fwimg;
1547 u32 pgnum, pgoff;
1548 u32 loff = 0;
1549 u32 chunkno = 0;
1550 u32 i;
Krishna Gudipati11189202011-06-13 15:50:35 -07001551 u32 asicmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07001552
Jing Huang5fbe25c2010-10-18 17:17:23 -07001553 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001554 * Initialize LMEM first before code download
1555 */
1556 bfa_ioc_lmem_init(ioc);
1557
Krishna Gudipati11189202011-06-13 15:50:35 -07001558 bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)));
1559 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001560
Maggie Zhangf7f738122010-12-09 19:08:43 -08001561 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1562 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001563
Jing Huang53440262010-10-18 17:12:29 -07001564 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001565
Krishna Gudipati11189202011-06-13 15:50:35 -07001566 for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001567
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001568 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1569 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipati11189202011-06-13 15:50:35 -07001570 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001571 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001572 }
1573
Jing Huang5fbe25c2010-10-18 17:17:23 -07001574 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001575 * write smem
1576 */
1577 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001578 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001579
1580 loff += sizeof(u32);
1581
Jing Huang5fbe25c2010-10-18 17:17:23 -07001582 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001583 * handle page offset wrap around
1584 */
1585 loff = PSS_SMEM_PGOFF(loff);
1586 if (loff == 0) {
1587 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001588 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001589 }
1590 }
1591
Maggie Zhangf7f738122010-12-09 19:08:43 -08001592 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1593 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001594
1595 /*
Krishna Gudipati11189202011-06-13 15:50:35 -07001596 * Set boot type and device mode at the end.
1597 */
1598 asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
1599 ioc->port0_mode, ioc->port1_mode);
1600 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF,
1601 swab32(asicmode));
1602 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001603 swab32(boot_type));
Krishna Gudipati11189202011-06-13 15:50:35 -07001604 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001605 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001606}
1607
Jing Huang7725ccf2009-09-23 17:46:15 -07001608
Jing Huang5fbe25c2010-10-18 17:17:23 -07001609/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001610 * Update BFA configuration from firmware configuration.
1611 */
1612static void
1613bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1614{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001615 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001616
Jing Huangba816ea2010-10-18 17:10:50 -07001617 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1618 attr->card_type = be32_to_cpu(attr->card_type);
1619 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Jing Huang7725ccf2009-09-23 17:46:15 -07001620
1621 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1622}
1623
Jing Huang5fbe25c2010-10-18 17:17:23 -07001624/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001625 * Attach time initialization of mbox logic.
1626 */
1627static void
1628bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1629{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001630 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1631 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001632
1633 INIT_LIST_HEAD(&mod->cmd_q);
1634 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1635 mod->mbhdlr[mc].cbfn = NULL;
1636 mod->mbhdlr[mc].cbarg = ioc->bfa;
1637 }
1638}
1639
Jing Huang5fbe25c2010-10-18 17:17:23 -07001640/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001641 * Mbox poll timer -- restarts any pending mailbox requests.
1642 */
1643static void
1644bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1645{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001646 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1647 struct bfa_mbox_cmd_s *cmd;
1648 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001649
Jing Huang5fbe25c2010-10-18 17:17:23 -07001650 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001651 * If no command pending, do nothing
1652 */
1653 if (list_empty(&mod->cmd_q))
1654 return;
1655
Jing Huang5fbe25c2010-10-18 17:17:23 -07001656 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001657 * If previous command is not yet fetched by firmware, do nothing
1658 */
Jing Huang53440262010-10-18 17:12:29 -07001659 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001660 if (stat)
1661 return;
1662
Jing Huang5fbe25c2010-10-18 17:17:23 -07001663 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001664 * Enqueue command to firmware.
1665 */
1666 bfa_q_deq(&mod->cmd_q, &cmd);
1667 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1668}
1669
Jing Huang5fbe25c2010-10-18 17:17:23 -07001670/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001671 * Cleanup any pending requests.
1672 */
1673static void
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001674bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07001675{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001676 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1677 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001678
1679 while (!list_empty(&mod->cmd_q))
1680 bfa_q_deq(&mod->cmd_q, &cmd);
1681}
1682
Jing Huang5fbe25c2010-10-18 17:17:23 -07001683/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001684 * Read data from SMEM to host through PCI memmap
1685 *
1686 * @param[in] ioc memory for IOC
1687 * @param[in] tbuf app memory to store data from smem
1688 * @param[in] soff smem offset
1689 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001690 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001691static bfa_status_t
1692bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1693{
Maggie50444a32010-11-29 18:26:32 -08001694 u32 pgnum, loff;
1695 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001696 int i, len;
1697 u32 *buf = tbuf;
1698
Maggie Zhangf7f738122010-12-09 19:08:43 -08001699 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1700 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001701 bfa_trc(ioc, pgnum);
1702 bfa_trc(ioc, loff);
1703 bfa_trc(ioc, sz);
1704
1705 /*
1706 * Hold semaphore to serialize pll init and fwtrc.
1707 */
1708 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1709 bfa_trc(ioc, 0);
1710 return BFA_STATUS_FAILED;
1711 }
1712
Jing Huang53440262010-10-18 17:12:29 -07001713 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001714
1715 len = sz/sizeof(u32);
1716 bfa_trc(ioc, len);
1717 for (i = 0; i < len; i++) {
1718 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001719 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001720 loff += sizeof(u32);
1721
Jing Huang5fbe25c2010-10-18 17:17:23 -07001722 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001723 * handle page offset wrap around
1724 */
1725 loff = PSS_SMEM_PGOFF(loff);
1726 if (loff == 0) {
1727 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001728 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001729 }
1730 }
Maggie Zhangf7f738122010-12-09 19:08:43 -08001731 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1732 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001733 /*
1734 * release semaphore.
1735 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08001736 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001737
1738 bfa_trc(ioc, pgnum);
1739 return BFA_STATUS_OK;
1740}
1741
Jing Huang5fbe25c2010-10-18 17:17:23 -07001742/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001743 * Clear SMEM data from host through PCI memmap
1744 *
1745 * @param[in] ioc memory for IOC
1746 * @param[in] soff smem offset
1747 * @param[in] sz size of smem in bytes
1748 */
1749static bfa_status_t
1750bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1751{
1752 int i, len;
1753 u32 pgnum, loff;
1754
Maggie Zhangf7f738122010-12-09 19:08:43 -08001755 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1756 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001757 bfa_trc(ioc, pgnum);
1758 bfa_trc(ioc, loff);
1759 bfa_trc(ioc, sz);
1760
1761 /*
1762 * Hold semaphore to serialize pll init and fwtrc.
1763 */
1764 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1765 bfa_trc(ioc, 0);
1766 return BFA_STATUS_FAILED;
1767 }
1768
Jing Huang53440262010-10-18 17:12:29 -07001769 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001770
1771 len = sz/sizeof(u32); /* len in words */
1772 bfa_trc(ioc, len);
1773 for (i = 0; i < len; i++) {
1774 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1775 loff += sizeof(u32);
1776
Jing Huang5fbe25c2010-10-18 17:17:23 -07001777 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001778 * handle page offset wrap around
1779 */
1780 loff = PSS_SMEM_PGOFF(loff);
1781 if (loff == 0) {
1782 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001783 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001784 }
1785 }
Maggie Zhangf7f738122010-12-09 19:08:43 -08001786 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1787 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001788
1789 /*
1790 * release semaphore.
1791 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08001792 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001793 bfa_trc(ioc, pgnum);
1794 return BFA_STATUS_OK;
1795}
1796
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001797static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001798bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1799{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001800 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1801
Jing Huang8f4bfad2010-12-26 21:50:10 -08001802 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001803 * Notify driver and common modules registered for notification.
1804 */
1805 ioc->cbfn->hbfail_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001806 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001807
1808 bfa_ioc_debug_save_ftrc(ioc);
1809
1810 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1811 "Heart Beat of IOC has failed\n");
1812
1813}
1814
1815static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001816bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1817{
1818 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001819 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001820 * Provide enable completion callback.
1821 */
1822 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001823 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001824 "Running firmware version is incompatible "
1825 "with the driver version\n");
1826}
1827
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001828bfa_status_t
1829bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1830{
1831
1832 /*
1833 * Hold semaphore so that nobody can access the chip during init.
1834 */
1835 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1836
1837 bfa_ioc_pll_init_asic(ioc);
1838
1839 ioc->pllinit = BFA_TRUE;
1840 /*
1841 * release semaphore.
1842 */
Maggie Zhangf7f738122010-12-09 19:08:43 -08001843 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001844
1845 return BFA_STATUS_OK;
1846}
Jing Huang7725ccf2009-09-23 17:46:15 -07001847
Jing Huang5fbe25c2010-10-18 17:17:23 -07001848/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001849 * Interface used by diag module to do firmware boot with memory test
1850 * as the entry vector.
1851 */
1852void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001853bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001854{
Jing Huang7725ccf2009-09-23 17:46:15 -07001855 bfa_ioc_stats(ioc, ioc_boots);
1856
1857 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1858 return;
1859
Jing Huang5fbe25c2010-10-18 17:17:23 -07001860 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001861 * Initialize IOC state of all functions on a chip reset.
1862 */
Krishna Gudipati11189202011-06-13 15:50:35 -07001863 if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
1864 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate);
1865 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001866 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -07001867 writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate);
1868 writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001869 }
1870
Jing Huang07b28382010-07-08 19:59:24 -07001871 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001872 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001873 bfa_ioc_lpu_start(ioc);
1874}
1875
Jing Huang5fbe25c2010-10-18 17:17:23 -07001876/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001877 * Enable/disable IOC failure auto recovery.
1878 */
1879void
1880bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
1881{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08001882 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07001883}
1884
1885
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001886
Jing Huang7725ccf2009-09-23 17:46:15 -07001887bfa_boolean_t
1888bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1889{
1890 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
1891}
1892
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001893bfa_boolean_t
1894bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
1895{
Jing Huang53440262010-10-18 17:12:29 -07001896 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001897
1898 return ((r32 != BFI_IOC_UNINIT) &&
1899 (r32 != BFI_IOC_INITING) &&
1900 (r32 != BFI_IOC_MEMTEST));
1901}
1902
Krishna Gudipati11189202011-06-13 15:50:35 -07001903bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001904bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
1905{
Maggie50444a32010-11-29 18:26:32 -08001906 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001907 u32 r32;
1908 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001909
Krishna Gudipati11189202011-06-13 15:50:35 -07001910 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1911 if ((r32 & 1) == 0)
1912 return BFA_FALSE;
1913
Jing Huang5fbe25c2010-10-18 17:17:23 -07001914 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001915 * read the MBOX msg
1916 */
1917 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1918 i++) {
Jing Huang53440262010-10-18 17:12:29 -07001919 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07001920 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07001921 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07001922 }
1923
Jing Huang5fbe25c2010-10-18 17:17:23 -07001924 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001925 * turn off mailbox interrupt by clearing mailbox status
1926 */
Jing Huang53440262010-10-18 17:12:29 -07001927 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1928 readl(ioc->ioc_regs.lpu_mbox_cmd);
Krishna Gudipati11189202011-06-13 15:50:35 -07001929
1930 return BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001931}
1932
1933void
1934bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
1935{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001936 union bfi_ioc_i2h_msg_u *msg;
1937 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07001938
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001939 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07001940
1941 bfa_ioc_stats(ioc, ioc_isrs);
1942
1943 switch (msg->mh.msg_id) {
1944 case BFI_IOC_I2H_HBEAT:
1945 break;
1946
Jing Huang7725ccf2009-09-23 17:46:15 -07001947 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07001948 ioc->port_mode = ioc->port_mode_cfg =
1949 (enum bfa_mode_s)msg->fw_event.port_mode;
1950 ioc->ad_cap_bm = msg->fw_event.cap_bm;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001951 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001952 break;
1953
1954 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001955 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07001956 break;
1957
1958 case BFI_IOC_I2H_GETATTR_REPLY:
1959 bfa_ioc_getattr_reply(ioc);
1960 break;
1961
1962 default:
1963 bfa_trc(ioc, msg->mh.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08001964 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -07001965 }
1966}
1967
Jing Huang5fbe25c2010-10-18 17:17:23 -07001968/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001969 * IOC attach time initialization and setup.
1970 *
1971 * @param[in] ioc memory for IOC
1972 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07001973 */
1974void
1975bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001976 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07001977{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001978 ioc->bfa = bfa;
1979 ioc->cbfn = cbfn;
1980 ioc->timer_mod = timer_mod;
1981 ioc->fcmode = BFA_FALSE;
1982 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001983 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001984 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001985
1986 bfa_ioc_mbox_attach(ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001987 INIT_LIST_HEAD(&ioc->notify_q);
Jing Huang7725ccf2009-09-23 17:46:15 -07001988
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001989 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
1990 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07001991}
1992
Jing Huang5fbe25c2010-10-18 17:17:23 -07001993/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001994 * Driver detach time IOC cleanup.
1995 */
1996void
1997bfa_ioc_detach(struct bfa_ioc_s *ioc)
1998{
1999 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2000}
2001
Jing Huang5fbe25c2010-10-18 17:17:23 -07002002/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002003 * Setup IOC PCI properties.
2004 *
2005 * @param[in] pcidev PCI device information for this IOC
2006 */
2007void
2008bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002009 enum bfi_pcifn_class clscode)
Jing Huang7725ccf2009-09-23 17:46:15 -07002010{
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002011 ioc->clscode = clscode;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002012 ioc->pcidev = *pcidev;
Krishna Gudipati11189202011-06-13 15:50:35 -07002013
2014 /*
2015 * Initialize IOC and device personality
2016 */
2017 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
2018 ioc->asic_mode = BFI_ASIC_MODE_FC;
2019
2020 switch (pcidev->device_id) {
2021 case BFA_PCI_DEVICE_ID_FC_8G1P:
2022 case BFA_PCI_DEVICE_ID_FC_8G2P:
2023 ioc->asic_gen = BFI_ASIC_GEN_CB;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002024 ioc->fcmode = BFA_TRUE;
2025 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2026 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002027 break;
2028
2029 case BFA_PCI_DEVICE_ID_CT:
2030 ioc->asic_gen = BFI_ASIC_GEN_CT;
2031 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
2032 ioc->asic_mode = BFI_ASIC_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002033 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
2034 ioc->ad_cap_bm = BFA_CM_CNA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002035 break;
2036
2037 case BFA_PCI_DEVICE_ID_CT_FC:
2038 ioc->asic_gen = BFI_ASIC_GEN_CT;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002039 ioc->fcmode = BFA_TRUE;
2040 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2041 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002042 break;
2043
2044 case BFA_PCI_DEVICE_ID_CT2:
2045 ioc->asic_gen = BFI_ASIC_GEN_CT2;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002046 if (clscode == BFI_PCIFN_CLASS_FC &&
2047 pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002048 ioc->asic_mode = BFI_ASIC_MODE_FC16;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002049 ioc->fcmode = BFA_TRUE;
2050 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2051 ioc->ad_cap_bm = BFA_CM_HBA;
2052 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -07002053 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002054 ioc->asic_mode = BFI_ASIC_MODE_ETH;
2055 if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
2056 ioc->port_mode =
2057 ioc->port_mode_cfg = BFA_MODE_CNA;
2058 ioc->ad_cap_bm = BFA_CM_CNA;
2059 } else {
2060 ioc->port_mode =
2061 ioc->port_mode_cfg = BFA_MODE_NIC;
2062 ioc->ad_cap_bm = BFA_CM_NIC;
2063 }
Krishna Gudipati11189202011-06-13 15:50:35 -07002064 }
2065 break;
2066
2067 default:
2068 WARN_ON(1);
2069 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002070
Jing Huang5fbe25c2010-10-18 17:17:23 -07002071 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002072 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2073 */
Krishna Gudipati11189202011-06-13 15:50:35 -07002074 if (ioc->asic_gen == BFI_ASIC_GEN_CB)
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002075 bfa_ioc_set_cb_hwif(ioc);
Krishna Gudipati11189202011-06-13 15:50:35 -07002076 else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
2077 bfa_ioc_set_ct_hwif(ioc);
2078 else {
2079 WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
2080 bfa_ioc_set_ct2_hwif(ioc);
2081 bfa_ioc_ct2_poweron(ioc);
2082 }
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002083
Jing Huang7725ccf2009-09-23 17:46:15 -07002084 bfa_ioc_map_port(ioc);
2085 bfa_ioc_reg_init(ioc);
2086}
2087
Jing Huang5fbe25c2010-10-18 17:17:23 -07002088/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002089 * Initialize IOC dma memory
2090 *
2091 * @param[in] dm_kva kernel virtual address of IOC dma memory
2092 * @param[in] dm_pa physical address of IOC dma memory
2093 */
2094void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002095bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002096{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002097 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002098 * dma memory for firmware attribute
2099 */
2100 ioc->attr_dma.kva = dm_kva;
2101 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002102 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002103}
2104
Jing Huang7725ccf2009-09-23 17:46:15 -07002105void
2106bfa_ioc_enable(struct bfa_ioc_s *ioc)
2107{
2108 bfa_ioc_stats(ioc, ioc_enables);
2109 ioc->dbg_fwsave_once = BFA_TRUE;
2110
2111 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2112}
2113
2114void
2115bfa_ioc_disable(struct bfa_ioc_s *ioc)
2116{
2117 bfa_ioc_stats(ioc, ioc_disables);
2118 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2119}
2120
Jing Huang7725ccf2009-09-23 17:46:15 -07002121
Jing Huang5fbe25c2010-10-18 17:17:23 -07002122/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002123 * Initialize memory for saving firmware trace. Driver must initialize
2124 * trace memory before call bfa_ioc_enable().
2125 */
2126void
2127bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2128{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002129 ioc->dbg_fwsave = dbg_fwsave;
Maggie Zhangf7f738122010-12-09 19:08:43 -08002130 ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07002131}
2132
Jing Huang5fbe25c2010-10-18 17:17:23 -07002133/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002134 * Register mailbox message handler functions
2135 *
2136 * @param[in] ioc IOC instance
2137 * @param[in] mcfuncs message class handler functions
2138 */
2139void
2140bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2141{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002142 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2143 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002144
2145 for (mc = 0; mc < BFI_MC_MAX; mc++)
2146 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2147}
2148
Jing Huang5fbe25c2010-10-18 17:17:23 -07002149/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002150 * Register mailbox message handler function, to be called by common modules
2151 */
2152void
2153bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2154 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2155{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002156 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002157
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002158 mod->mbhdlr[mc].cbfn = cbfn;
2159 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002160}
2161
Jing Huang5fbe25c2010-10-18 17:17:23 -07002162/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002163 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2164 * Responsibility of caller to serialize
2165 *
2166 * @param[in] ioc IOC instance
2167 * @param[i] cmd Mailbox command
2168 */
2169void
2170bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2171{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002172 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2173 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002174
Jing Huang5fbe25c2010-10-18 17:17:23 -07002175 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002176 * If a previous command is pending, queue new command
2177 */
2178 if (!list_empty(&mod->cmd_q)) {
2179 list_add_tail(&cmd->qe, &mod->cmd_q);
2180 return;
2181 }
2182
Jing Huang5fbe25c2010-10-18 17:17:23 -07002183 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002184 * If mailbox is busy, queue command for poll timer
2185 */
Jing Huang53440262010-10-18 17:12:29 -07002186 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002187 if (stat) {
2188 list_add_tail(&cmd->qe, &mod->cmd_q);
2189 return;
2190 }
2191
Jing Huang5fbe25c2010-10-18 17:17:23 -07002192 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002193 * mailbox is free -- queue command to firmware
2194 */
2195 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2196}
2197
Jing Huang5fbe25c2010-10-18 17:17:23 -07002198/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002199 * Handle mailbox interrupts
2200 */
2201void
2202bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2203{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002204 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2205 struct bfi_mbmsg_s m;
2206 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002207
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002208 if (bfa_ioc_msgget(ioc, &m)) {
2209 /*
2210 * Treat IOC message class as special.
2211 */
2212 mc = m.mh.msg_class;
2213 if (mc == BFI_MC_IOC) {
2214 bfa_ioc_isr(ioc, &m);
2215 return;
2216 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002217
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002218 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2219 return;
2220
2221 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
Jing Huang7725ccf2009-09-23 17:46:15 -07002222 }
2223
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002224 bfa_ioc_lpu_read_stat(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002225
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002226 /*
2227 * Try to send pending mailbox commands
2228 */
2229 bfa_ioc_mbox_poll(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002230}
2231
2232void
2233bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2234{
2235 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2236}
2237
Jing Huanged969322010-07-08 19:45:56 -07002238void
2239bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2240{
2241 ioc->fcmode = BFA_TRUE;
Jing Huanged969322010-07-08 19:45:56 -07002242}
2243
Jing Huang5fbe25c2010-10-18 17:17:23 -07002244/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002245 * return true if IOC is disabled
2246 */
2247bfa_boolean_t
2248bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2249{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002250 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2251 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002252}
2253
Jing Huang5fbe25c2010-10-18 17:17:23 -07002254/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002255 * return true if IOC firmware is different.
2256 */
2257bfa_boolean_t
2258bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2259{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002260 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2261 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2262 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002263}
2264
2265#define bfa_ioc_state_disabled(__sm) \
2266 (((__sm) == BFI_IOC_UNINIT) || \
2267 ((__sm) == BFI_IOC_INITING) || \
2268 ((__sm) == BFI_IOC_HWINIT) || \
2269 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002270 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002271 ((__sm) == BFI_IOC_CFG_DISABLED))
2272
Jing Huang5fbe25c2010-10-18 17:17:23 -07002273/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002274 * Check if adapter is disabled -- both IOCs should be in a disabled
2275 * state.
2276 */
2277bfa_boolean_t
2278bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2279{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002280 u32 ioc_state;
Jing Huang7725ccf2009-09-23 17:46:15 -07002281
2282 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2283 return BFA_FALSE;
2284
Krishna Gudipati11189202011-06-13 15:50:35 -07002285 ioc_state = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07002286 if (!bfa_ioc_state_disabled(ioc_state))
2287 return BFA_FALSE;
2288
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002289 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002290 ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002291 if (!bfa_ioc_state_disabled(ioc_state))
2292 return BFA_FALSE;
2293 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002294
2295 return BFA_TRUE;
2296}
2297
Jing Huang8f4bfad2010-12-26 21:50:10 -08002298/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002299 * Reset IOC fwstate registers.
2300 */
2301void
2302bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2303{
2304 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2305 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2306}
2307
Jing Huang7725ccf2009-09-23 17:46:15 -07002308#define BFA_MFG_NAME "Brocade"
2309void
2310bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2311 struct bfa_adapter_attr_s *ad_attr)
2312{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002313 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002314
2315 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002316
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002317 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2318 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2319 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2320 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002321 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002322 sizeof(struct bfa_mfg_vpd_s));
2323
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002324 ad_attr->nports = bfa_ioc_get_nports(ioc);
2325 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002326
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002327 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2328 /* For now, model descr uses same model string */
2329 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002330
Jing Huanged969322010-07-08 19:45:56 -07002331 ad_attr->card_type = ioc_attr->card_type;
2332 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2333
Jing Huang7725ccf2009-09-23 17:46:15 -07002334 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2335 ad_attr->prototype = 1;
2336 else
2337 ad_attr->prototype = 0;
2338
Maggie Zhangf7f738122010-12-09 19:08:43 -08002339 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002340 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002341
2342 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2343 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2344 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2345 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002346
2347 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002348
Krishna Gudipati11189202011-06-13 15:50:35 -07002349 ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
2350 ad_attr->trunk_capable = (ad_attr->nports > 1) &&
2351 !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
Jing Huang7725ccf2009-09-23 17:46:15 -07002352}
2353
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002354enum bfa_ioc_type_e
2355bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2356{
Krishna Gudipati11189202011-06-13 15:50:35 -07002357 enum bfi_port_mode mode;
2358
2359 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002360 return BFA_IOC_TYPE_LL;
Krishna Gudipati11189202011-06-13 15:50:35 -07002361
2362 WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
2363
2364 mode = (ioc->port_id == 0) ? ioc->port0_mode : ioc->port1_mode;
2365 return (mode == BFI_PORT_MODE_FC)
2366 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002367}
2368
Jing Huang7725ccf2009-09-23 17:46:15 -07002369void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002370bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2371{
Jing Huang6a18b162010-10-18 17:08:54 -07002372 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2373 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002374 (void *)ioc->attr->brcd_serialnum,
2375 BFA_ADAPTER_SERIAL_NUM_LEN);
2376}
2377
2378void
2379bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2380{
Jing Huang6a18b162010-10-18 17:08:54 -07002381 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2382 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002383}
2384
2385void
2386bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2387{
Jing Huangd4b671c2010-12-26 21:46:35 -08002388 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002389
Jing Huang6a18b162010-10-18 17:08:54 -07002390 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002391
2392 chip_rev[0] = 'R';
2393 chip_rev[1] = 'e';
2394 chip_rev[2] = 'v';
2395 chip_rev[3] = '-';
2396 chip_rev[4] = ioc->attr->asic_rev;
2397 chip_rev[5] = '\0';
2398}
2399
2400void
2401bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2402{
Jing Huang6a18b162010-10-18 17:08:54 -07002403 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2404 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002405 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002406}
2407
2408void
2409bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2410{
Jing Huang6a18b162010-10-18 17:08:54 -07002411 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2412 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002413}
2414
2415void
2416bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2417{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002418 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002419
Jing Huangd4b671c2010-12-26 21:46:35 -08002420 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002421 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002422
2423 ioc_attr = ioc->attr;
2424
Jing Huang5fbe25c2010-10-18 17:17:23 -07002425 /*
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002426 * model name
2427 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002428 if (ioc->asic_gen == BFI_ASIC_GEN_CT2) {
2429 int np = bfa_ioc_get_nports(ioc);
2430 char c;
2431 switch (ioc_attr->card_type) {
2432 case BFA_MFG_TYPE_PROWLER_F:
2433 case BFA_MFG_TYPE_PROWLER_N:
2434 case BFA_MFG_TYPE_PROWLER_C:
2435 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN,
2436 "%s-%u-%u",
2437 BFA_MFG_NAME, ioc_attr->card_type, np);
2438 break;
2439 case BFA_MFG_TYPE_PROWLER_D:
2440 if (ioc_attr->ic == BFA_MFG_IC_FC)
2441 c = 'F';
2442 else
2443 c = 'P';
2444
2445 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN,
2446 "%s-%u-%u%c",
2447 BFA_MFG_NAME, ioc_attr->card_type, np, c);
2448 break;
2449 default:
2450 break;
2451 }
2452 } else
2453 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2454 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002455}
2456
2457enum bfa_ioc_state
2458bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2459{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002460 enum bfa_iocpf_state iocpf_st;
2461 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2462
2463 if (ioc_st == BFA_IOC_ENABLING ||
2464 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2465
2466 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2467
2468 switch (iocpf_st) {
2469 case BFA_IOCPF_SEMWAIT:
2470 ioc_st = BFA_IOC_SEMWAIT;
2471 break;
2472
2473 case BFA_IOCPF_HWINIT:
2474 ioc_st = BFA_IOC_HWINIT;
2475 break;
2476
2477 case BFA_IOCPF_FWMISMATCH:
2478 ioc_st = BFA_IOC_FWMISMATCH;
2479 break;
2480
2481 case BFA_IOCPF_FAIL:
2482 ioc_st = BFA_IOC_FAIL;
2483 break;
2484
2485 case BFA_IOCPF_INITFAIL:
2486 ioc_st = BFA_IOC_INITFAIL;
2487 break;
2488
2489 default:
2490 break;
2491 }
2492 }
2493
2494 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002495}
2496
2497void
Jing Huang7725ccf2009-09-23 17:46:15 -07002498bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2499{
Jing Huang6a18b162010-10-18 17:08:54 -07002500 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002501
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002502 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002503 ioc_attr->port_id = ioc->port_id;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002504 ioc_attr->port_mode = ioc->port_mode;
2505 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2506 ioc_attr->cap_bm = ioc->ad_cap_bm;
Jing Huang7725ccf2009-09-23 17:46:15 -07002507
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002508 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002509
2510 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2511
2512 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2513 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002514 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002515}
2516
Jing Huang7725ccf2009-09-23 17:46:15 -07002517mac_t
2518bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2519{
Jing Huang15b64a82010-07-08 19:48:12 -07002520 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002521 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002522 */
2523 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002524 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002525 else
2526 return ioc->attr->mac;
2527}
2528
Jing Huang15b64a82010-07-08 19:48:12 -07002529mac_t
2530bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2531{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002532 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002533
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002534 m = ioc->attr->mfg_mac;
2535 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2536 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2537 else
2538 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2539 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002540
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002541 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002542}
2543
Jing Huang7725ccf2009-09-23 17:46:15 -07002544bfa_boolean_t
2545bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2546{
Krishna Gudipati11189202011-06-13 15:50:35 -07002547 return ioc->fcmode || bfa_asic_id_cb(ioc->pcidev.device_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07002548}
2549
Jing Huang5fbe25c2010-10-18 17:17:23 -07002550/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002551 * Retrieve saved firmware trace from a prior IOC failure.
2552 */
2553bfa_status_t
2554bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2555{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002556 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002557
2558 if (ioc->dbg_fwsave_len == 0)
2559 return BFA_STATUS_ENOFSAVE;
2560
2561 tlen = *trclen;
2562 if (tlen > ioc->dbg_fwsave_len)
2563 tlen = ioc->dbg_fwsave_len;
2564
Jing Huang6a18b162010-10-18 17:08:54 -07002565 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002566 *trclen = tlen;
2567 return BFA_STATUS_OK;
2568}
2569
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002570
Jing Huang5fbe25c2010-10-18 17:17:23 -07002571/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002572 * Retrieve saved firmware trace from a prior IOC failure.
2573 */
2574bfa_status_t
2575bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2576{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002577 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2578 int tlen;
2579 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002580
2581 bfa_trc(ioc, *trclen);
2582
Jing Huang7725ccf2009-09-23 17:46:15 -07002583 tlen = *trclen;
2584 if (tlen > BFA_DBG_FWTRC_LEN)
2585 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002586
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002587 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2588 *trclen = tlen;
2589 return status;
2590}
Jing Huang7725ccf2009-09-23 17:46:15 -07002591
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002592static void
2593bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2594{
2595 struct bfa_mbox_cmd_s cmd;
2596 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002597
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002598 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2599 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002600 req->clscode = cpu_to_be16(ioc->clscode);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002601 bfa_ioc_mbox_queue(ioc, &cmd);
2602}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002603
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002604static void
2605bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2606{
2607 u32 fwsync_iter = 1000;
2608
2609 bfa_ioc_send_fwsync(ioc);
2610
Jing Huang5fbe25c2010-10-18 17:17:23 -07002611 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002612 * After sending a fw sync mbox command wait for it to
2613 * take effect. We will not wait for a response because
2614 * 1. fw_sync mbox cmd doesn't have a response.
2615 * 2. Even if we implement that, interrupts might not
2616 * be enabled when we call this function.
2617 * So, just keep checking if any mbox cmd is pending, and
2618 * after waiting for a reasonable amount of time, go ahead.
2619 * It is possible that fw has crashed and the mbox command
2620 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002621 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002622 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2623 fwsync_iter--;
2624}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002625
Jing Huang5fbe25c2010-10-18 17:17:23 -07002626/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002627 * Dump firmware smem
2628 */
2629bfa_status_t
2630bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2631 u32 *offset, int *buflen)
2632{
2633 u32 loff;
2634 int dlen;
2635 bfa_status_t status;
2636 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002637
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002638 if (*offset >= smem_len) {
2639 *offset = *buflen = 0;
2640 return BFA_STATUS_EINVAL;
2641 }
2642
2643 loff = *offset;
2644 dlen = *buflen;
2645
Jing Huang5fbe25c2010-10-18 17:17:23 -07002646 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002647 * First smem read, sync smem before proceeding
2648 * No need to sync before reading every chunk.
2649 */
2650 if (loff == 0)
2651 bfa_ioc_fwsync(ioc);
2652
2653 if ((loff + dlen) >= smem_len)
2654 dlen = smem_len - loff;
2655
2656 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2657
2658 if (status != BFA_STATUS_OK) {
2659 *offset = *buflen = 0;
2660 return status;
2661 }
2662
2663 *offset += dlen;
2664
2665 if (*offset >= smem_len)
2666 *offset = 0;
2667
2668 *buflen = dlen;
2669
2670 return status;
2671}
2672
Jing Huang5fbe25c2010-10-18 17:17:23 -07002673/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002674 * Firmware statistics
2675 */
2676bfa_status_t
2677bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2678{
2679 u32 loff = BFI_IOC_FWSTATS_OFF + \
2680 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2681 int tlen;
2682 bfa_status_t status;
2683
2684 if (ioc->stats_busy) {
2685 bfa_trc(ioc, ioc->stats_busy);
2686 return BFA_STATUS_DEVBUSY;
2687 }
2688 ioc->stats_busy = BFA_TRUE;
2689
2690 tlen = sizeof(struct bfa_fw_stats_s);
2691 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2692
2693 ioc->stats_busy = BFA_FALSE;
2694 return status;
2695}
2696
2697bfa_status_t
2698bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2699{
2700 u32 loff = BFI_IOC_FWSTATS_OFF + \
2701 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2702 int tlen;
2703 bfa_status_t status;
2704
2705 if (ioc->stats_busy) {
2706 bfa_trc(ioc, ioc->stats_busy);
2707 return BFA_STATUS_DEVBUSY;
2708 }
2709 ioc->stats_busy = BFA_TRUE;
2710
2711 tlen = sizeof(struct bfa_fw_stats_s);
2712 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2713
2714 ioc->stats_busy = BFA_FALSE;
2715 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002716}
2717
Jing Huang5fbe25c2010-10-18 17:17:23 -07002718/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002719 * Save firmware trace if configured.
2720 */
2721static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002722bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002723{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002724 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002725
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002726 if (ioc->dbg_fwsave_once) {
2727 ioc->dbg_fwsave_once = BFA_FALSE;
2728 if (ioc->dbg_fwsave_len) {
2729 tlen = ioc->dbg_fwsave_len;
2730 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2731 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002732 }
2733}
2734
Jing Huang5fbe25c2010-10-18 17:17:23 -07002735/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002736 * Firmware failure detected. Start recovery actions.
2737 */
2738static void
2739bfa_ioc_recover(struct bfa_ioc_s *ioc)
2740{
Jing Huang7725ccf2009-09-23 17:46:15 -07002741 bfa_ioc_stats(ioc, ioc_hbfails);
2742 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2743}
2744
Jing Huang7725ccf2009-09-23 17:46:15 -07002745static void
Jing Huang07b28382010-07-08 19:59:24 -07002746bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002747{
Jing Huang07b28382010-07-08 19:59:24 -07002748 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2749 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002750}
2751
Jing Huang5fbe25c2010-10-18 17:17:23 -07002752/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002753 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002754 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002755static void
2756bfa_iocpf_timeout(void *ioc_arg)
2757{
2758 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2759
2760 bfa_trc(ioc, 0);
2761 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2762}
2763
2764static void
2765bfa_iocpf_sem_timeout(void *ioc_arg)
2766{
2767 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2768
2769 bfa_ioc_hw_sem_get(ioc);
2770}
2771
Krishna Gudipati775c7742011-06-13 15:52:12 -07002772static void
2773bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
2774{
2775 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
2776
2777 bfa_trc(ioc, fwstate);
2778
2779 if (fwstate == BFI_IOC_DISABLED) {
2780 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2781 return;
2782 }
2783
2784 if (ioc->iocpf.poll_time >= BFA_IOC_TOV)
2785 bfa_iocpf_timeout(ioc);
2786 else {
2787 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2788 bfa_iocpf_poll_timer_start(ioc);
2789 }
2790}
2791
2792static void
2793bfa_iocpf_poll_timeout(void *ioc_arg)
2794{
2795 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2796
2797 bfa_ioc_poll_fwinit(ioc);
2798}
2799
Jing Huang5fbe25c2010-10-18 17:17:23 -07002800/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002801 * bfa timer function
2802 */
2803void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002804bfa_timer_beat(struct bfa_timer_mod_s *mod)
2805{
2806 struct list_head *qh = &mod->timer_q;
2807 struct list_head *qe, *qe_next;
2808 struct bfa_timer_s *elem;
2809 struct list_head timedout_q;
2810
2811 INIT_LIST_HEAD(&timedout_q);
2812
2813 qe = bfa_q_next(qh);
2814
2815 while (qe != qh) {
2816 qe_next = bfa_q_next(qe);
2817
2818 elem = (struct bfa_timer_s *) qe;
2819 if (elem->timeout <= BFA_TIMER_FREQ) {
2820 elem->timeout = 0;
2821 list_del(&elem->qe);
2822 list_add_tail(&elem->qe, &timedout_q);
2823 } else {
2824 elem->timeout -= BFA_TIMER_FREQ;
2825 }
2826
2827 qe = qe_next; /* go to next elem */
2828 }
2829
2830 /*
2831 * Pop all the timeout entries
2832 */
2833 while (!list_empty(&timedout_q)) {
2834 bfa_q_deq(&timedout_q, &elem);
2835 elem->timercb(elem->arg);
2836 }
2837}
2838
Jing Huang5fbe25c2010-10-18 17:17:23 -07002839/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002840 * Should be called with lock protection
2841 */
2842void
2843bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2844 void (*timercb) (void *), void *arg, unsigned int timeout)
2845{
2846
Jing Huangd4b671c2010-12-26 21:46:35 -08002847 WARN_ON(timercb == NULL);
2848 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002849
2850 timer->timeout = timeout;
2851 timer->timercb = timercb;
2852 timer->arg = arg;
2853
2854 list_add_tail(&timer->qe, &mod->timer_q);
2855}
2856
Jing Huang5fbe25c2010-10-18 17:17:23 -07002857/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002858 * Should be called with lock protection
2859 */
2860void
2861bfa_timer_stop(struct bfa_timer_s *timer)
2862{
Jing Huangd4b671c2010-12-26 21:46:35 -08002863 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002864
2865 list_del(&timer->qe);
2866}
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002867
2868/*
2869 * ASIC block related
2870 */
2871static void
2872bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
2873{
2874 struct bfa_ablk_cfg_inst_s *cfg_inst;
2875 int i, j;
2876 u16 be16;
2877 u32 be32;
2878
2879 for (i = 0; i < BFA_ABLK_MAX; i++) {
2880 cfg_inst = &cfg->inst[i];
2881 for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
2882 be16 = cfg_inst->pf_cfg[j].pers;
2883 cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
2884 be16 = cfg_inst->pf_cfg[j].num_qpairs;
2885 cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
2886 be16 = cfg_inst->pf_cfg[j].num_vectors;
2887 cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
2888 be32 = cfg_inst->pf_cfg[j].bw;
2889 cfg_inst->pf_cfg[j].bw = be16_to_cpu(be32);
2890 }
2891 }
2892}
2893
2894static void
2895bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
2896{
2897 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
2898 struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
2899 bfa_ablk_cbfn_t cbfn;
2900
2901 WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
2902 bfa_trc(ablk->ioc, msg->mh.msg_id);
2903
2904 switch (msg->mh.msg_id) {
2905 case BFI_ABLK_I2H_QUERY:
2906 if (rsp->status == BFA_STATUS_OK) {
2907 memcpy(ablk->cfg, ablk->dma_addr.kva,
2908 sizeof(struct bfa_ablk_cfg_s));
2909 bfa_ablk_config_swap(ablk->cfg);
2910 ablk->cfg = NULL;
2911 }
2912 break;
2913
2914 case BFI_ABLK_I2H_ADPT_CONFIG:
2915 case BFI_ABLK_I2H_PORT_CONFIG:
2916 /* update config port mode */
2917 ablk->ioc->port_mode_cfg = rsp->port_mode;
2918
2919 case BFI_ABLK_I2H_PF_DELETE:
2920 case BFI_ABLK_I2H_PF_UPDATE:
2921 case BFI_ABLK_I2H_OPTROM_ENABLE:
2922 case BFI_ABLK_I2H_OPTROM_DISABLE:
2923 /* No-op */
2924 break;
2925
2926 case BFI_ABLK_I2H_PF_CREATE:
2927 *(ablk->pcifn) = rsp->pcifn;
2928 ablk->pcifn = NULL;
2929 break;
2930
2931 default:
2932 WARN_ON(1);
2933 }
2934
2935 ablk->busy = BFA_FALSE;
2936 if (ablk->cbfn) {
2937 cbfn = ablk->cbfn;
2938 ablk->cbfn = NULL;
2939 cbfn(ablk->cbarg, rsp->status);
2940 }
2941}
2942
2943static void
2944bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
2945{
2946 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
2947
2948 bfa_trc(ablk->ioc, event);
2949
2950 switch (event) {
2951 case BFA_IOC_E_ENABLED:
2952 WARN_ON(ablk->busy != BFA_FALSE);
2953 break;
2954
2955 case BFA_IOC_E_DISABLED:
2956 case BFA_IOC_E_FAILED:
2957 /* Fail any pending requests */
2958 ablk->pcifn = NULL;
2959 if (ablk->busy) {
2960 if (ablk->cbfn)
2961 ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
2962 ablk->cbfn = NULL;
2963 ablk->busy = BFA_FALSE;
2964 }
2965 break;
2966
2967 default:
2968 WARN_ON(1);
2969 break;
2970 }
2971}
2972
2973u32
2974bfa_ablk_meminfo(void)
2975{
2976 return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
2977}
2978
2979void
2980bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
2981{
2982 ablk->dma_addr.kva = dma_kva;
2983 ablk->dma_addr.pa = dma_pa;
2984}
2985
2986void
2987bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
2988{
2989 ablk->ioc = ioc;
2990
2991 bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
2992 bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
2993 list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
2994}
2995
2996bfa_status_t
2997bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
2998 bfa_ablk_cbfn_t cbfn, void *cbarg)
2999{
3000 struct bfi_ablk_h2i_query_s *m;
3001
3002 WARN_ON(!ablk_cfg);
3003
3004 if (!bfa_ioc_is_operational(ablk->ioc)) {
3005 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3006 return BFA_STATUS_IOC_FAILURE;
3007 }
3008
3009 if (ablk->busy) {
3010 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3011 return BFA_STATUS_DEVBUSY;
3012 }
3013
3014 ablk->cfg = ablk_cfg;
3015 ablk->cbfn = cbfn;
3016 ablk->cbarg = cbarg;
3017 ablk->busy = BFA_TRUE;
3018
3019 m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
3020 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
3021 bfa_ioc_portid(ablk->ioc));
3022 bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
3023 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3024
3025 return BFA_STATUS_OK;
3026}
3027
3028bfa_status_t
3029bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
3030 u8 port, enum bfi_pcifn_class personality, int bw,
3031 bfa_ablk_cbfn_t cbfn, void *cbarg)
3032{
3033 struct bfi_ablk_h2i_pf_req_s *m;
3034
3035 if (!bfa_ioc_is_operational(ablk->ioc)) {
3036 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3037 return BFA_STATUS_IOC_FAILURE;
3038 }
3039
3040 if (ablk->busy) {
3041 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3042 return BFA_STATUS_DEVBUSY;
3043 }
3044
3045 ablk->pcifn = pcifn;
3046 ablk->cbfn = cbfn;
3047 ablk->cbarg = cbarg;
3048 ablk->busy = BFA_TRUE;
3049
3050 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3051 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
3052 bfa_ioc_portid(ablk->ioc));
3053 m->pers = cpu_to_be16((u16)personality);
3054 m->bw = cpu_to_be32(bw);
3055 m->port = port;
3056 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3057
3058 return BFA_STATUS_OK;
3059}
3060
3061bfa_status_t
3062bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
3063 bfa_ablk_cbfn_t cbfn, void *cbarg)
3064{
3065 struct bfi_ablk_h2i_pf_req_s *m;
3066
3067 if (!bfa_ioc_is_operational(ablk->ioc)) {
3068 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3069 return BFA_STATUS_IOC_FAILURE;
3070 }
3071
3072 if (ablk->busy) {
3073 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3074 return BFA_STATUS_DEVBUSY;
3075 }
3076
3077 ablk->cbfn = cbfn;
3078 ablk->cbarg = cbarg;
3079 ablk->busy = BFA_TRUE;
3080
3081 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3082 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
3083 bfa_ioc_portid(ablk->ioc));
3084 m->pcifn = (u8)pcifn;
3085 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3086
3087 return BFA_STATUS_OK;
3088}
3089
3090bfa_status_t
3091bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
3092 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3093{
3094 struct bfi_ablk_h2i_cfg_req_s *m;
3095
3096 if (!bfa_ioc_is_operational(ablk->ioc)) {
3097 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3098 return BFA_STATUS_IOC_FAILURE;
3099 }
3100
3101 if (ablk->busy) {
3102 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3103 return BFA_STATUS_DEVBUSY;
3104 }
3105
3106 ablk->cbfn = cbfn;
3107 ablk->cbarg = cbarg;
3108 ablk->busy = BFA_TRUE;
3109
3110 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3111 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
3112 bfa_ioc_portid(ablk->ioc));
3113 m->mode = (u8)mode;
3114 m->max_pf = (u8)max_pf;
3115 m->max_vf = (u8)max_vf;
3116 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3117
3118 return BFA_STATUS_OK;
3119}
3120
3121bfa_status_t
3122bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
3123 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3124{
3125 struct bfi_ablk_h2i_cfg_req_s *m;
3126
3127 if (!bfa_ioc_is_operational(ablk->ioc)) {
3128 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3129 return BFA_STATUS_IOC_FAILURE;
3130 }
3131
3132 if (ablk->busy) {
3133 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3134 return BFA_STATUS_DEVBUSY;
3135 }
3136
3137 ablk->cbfn = cbfn;
3138 ablk->cbarg = cbarg;
3139 ablk->busy = BFA_TRUE;
3140
3141 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3142 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
3143 bfa_ioc_portid(ablk->ioc));
3144 m->port = (u8)port;
3145 m->mode = (u8)mode;
3146 m->max_pf = (u8)max_pf;
3147 m->max_vf = (u8)max_vf;
3148 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3149
3150 return BFA_STATUS_OK;
3151}
3152
3153bfa_status_t
3154bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw,
3155 bfa_ablk_cbfn_t cbfn, void *cbarg)
3156{
3157 struct bfi_ablk_h2i_pf_req_s *m;
3158
3159 if (!bfa_ioc_is_operational(ablk->ioc)) {
3160 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3161 return BFA_STATUS_IOC_FAILURE;
3162 }
3163
3164 if (ablk->busy) {
3165 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3166 return BFA_STATUS_DEVBUSY;
3167 }
3168
3169 ablk->cbfn = cbfn;
3170 ablk->cbarg = cbarg;
3171 ablk->busy = BFA_TRUE;
3172
3173 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3174 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
3175 bfa_ioc_portid(ablk->ioc));
3176 m->pcifn = (u8)pcifn;
3177 m->bw = cpu_to_be32(bw);
3178 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3179
3180 return BFA_STATUS_OK;
3181}
3182
3183bfa_status_t
3184bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3185{
3186 struct bfi_ablk_h2i_optrom_s *m;
3187
3188 if (!bfa_ioc_is_operational(ablk->ioc)) {
3189 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3190 return BFA_STATUS_IOC_FAILURE;
3191 }
3192
3193 if (ablk->busy) {
3194 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3195 return BFA_STATUS_DEVBUSY;
3196 }
3197
3198 ablk->cbfn = cbfn;
3199 ablk->cbarg = cbarg;
3200 ablk->busy = BFA_TRUE;
3201
3202 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3203 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
3204 bfa_ioc_portid(ablk->ioc));
3205 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3206
3207 return BFA_STATUS_OK;
3208}
3209
3210bfa_status_t
3211bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3212{
3213 struct bfi_ablk_h2i_optrom_s *m;
3214
3215 if (!bfa_ioc_is_operational(ablk->ioc)) {
3216 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3217 return BFA_STATUS_IOC_FAILURE;
3218 }
3219
3220 if (ablk->busy) {
3221 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3222 return BFA_STATUS_DEVBUSY;
3223 }
3224
3225 ablk->cbfn = cbfn;
3226 ablk->cbarg = cbarg;
3227 ablk->busy = BFA_TRUE;
3228
3229 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3230 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
3231 bfa_ioc_portid(ablk->ioc));
3232 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3233
3234 return BFA_STATUS_OK;
3235}