blob: 931bf9769ff272ba7864c7090635735d5608ffd1 [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 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700115 IOC_E_HWFAILED = 12, /* PCI mapping failure notice */
Jing Huang7725ccf2009-09-23 17:46:15 -0700116};
117
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700118bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700119bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700120bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
121bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
122bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800123bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700124bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700125bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
126bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700127bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700128
129static struct bfa_sm_table_s ioc_sm_table[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Jing Huang7725ccf2009-09-23 17:46:15 -0700131 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700132 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Jing Huang7725ccf2009-09-23 17:46:15 -0700133 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
134 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800135 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700136 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700137 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
138 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700139 {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700140};
141
Jing Huang5fbe25c2010-10-18 17:17:23 -0700142/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700143 * IOCPF state machine definitions/declarations
144 */
145
146#define bfa_iocpf_timer_start(__ioc) \
147 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
148 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
149#define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
150
Krishna Gudipati775c7742011-06-13 15:52:12 -0700151#define bfa_iocpf_poll_timer_start(__ioc) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700152 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
Krishna Gudipati775c7742011-06-13 15:52:12 -0700153 bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700154
155#define bfa_sem_timer_start(__ioc) \
156 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
157 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
158#define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
159
160/*
161 * Forward declareations for iocpf state machine
162 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700163static void bfa_iocpf_timeout(void *ioc_arg);
164static void bfa_iocpf_sem_timeout(void *ioc_arg);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700165static void bfa_iocpf_poll_timeout(void *ioc_arg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700166
Jing Huang5fbe25c2010-10-18 17:17:23 -0700167/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700168 * IOCPF state machine events
169 */
170enum iocpf_event {
171 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
172 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
173 IOCPF_E_STOP = 3, /* stop on driver detach */
174 IOCPF_E_FWREADY = 4, /* f/w initialization done */
175 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
176 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
177 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
178 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
179 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
180 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
181 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700182 IOCPF_E_SEM_ERROR = 12, /* h/w sem mapping error */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700183};
184
Jing Huang5fbe25c2010-10-18 17:17:23 -0700185/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700186 * IOCPF states
187 */
188enum bfa_iocpf_state {
189 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
190 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
191 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
192 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
193 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
194 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
195 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
196 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
197 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
198};
199
200bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
201bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
202bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
203bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
204bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
205bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
206bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800207bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
208 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700209bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800210bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700211bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
212bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800213bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
214 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700215bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
216
217static struct bfa_sm_table_s iocpf_sm_table[] = {
218 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
219 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
220 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
221 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
222 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
223 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
224 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800225 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700226 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800227 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700228 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
229 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800230 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700231 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
232};
233
Jing Huang5fbe25c2010-10-18 17:17:23 -0700234/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700235 * IOC State Machine
236 */
237
Jing Huang5fbe25c2010-10-18 17:17:23 -0700238/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700239 * Beginning state. IOC uninit state.
240 */
241
242static void
243bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
244{
245}
246
Jing Huang5fbe25c2010-10-18 17:17:23 -0700247/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700248 * IOC is in uninit state.
249 */
250static void
251bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
252{
253 bfa_trc(ioc, event);
254
255 switch (event) {
256 case IOC_E_RESET:
257 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
258 break;
259
260 default:
261 bfa_sm_fault(ioc, event);
262 }
263}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700264/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700265 * Reset entry actions -- initialize state machine
266 */
267static void
268bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
269{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700270 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700271}
272
Jing Huang5fbe25c2010-10-18 17:17:23 -0700273/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700274 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700275 */
276static void
277bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
278{
279 bfa_trc(ioc, event);
280
281 switch (event) {
282 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700283 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
284 break;
285
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700286 case IOC_E_DISABLE:
287 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700288 break;
289
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700290 case IOC_E_DETACH:
291 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700292 break;
293
294 default:
295 bfa_sm_fault(ioc, event);
296 }
297}
298
299
300static void
301bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
302{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800303 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700304}
305
Jing Huang5fbe25c2010-10-18 17:17:23 -0700306/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700307 * Host IOC function is being enabled, awaiting response from firmware.
308 * Semaphore is acquired.
309 */
310static void
311bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
312{
313 bfa_trc(ioc, event);
314
315 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700316 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700317 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
318 break;
319
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800320 case IOC_E_PFFAILED:
321 /* !!! fall through !!! */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322 case IOC_E_HWERROR:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800323 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700324 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800325 if (event != IOC_E_PFFAILED)
326 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700327 break;
328
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700329 case IOC_E_HWFAILED:
330 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
331 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
332 break;
333
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700334 case IOC_E_DISABLE:
335 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
336 break;
337
338 case IOC_E_DETACH:
339 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800340 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700341 break;
342
343 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700344 break;
345
346 default:
347 bfa_sm_fault(ioc, event);
348 }
349}
350
351
352static void
353bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
354{
355 bfa_ioc_timer_start(ioc);
356 bfa_ioc_send_getattr(ioc);
357}
358
Jing Huang5fbe25c2010-10-18 17:17:23 -0700359/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700360 * IOC configuration in progress. Timer is active.
361 */
362static void
363bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
364{
365 bfa_trc(ioc, event);
366
367 switch (event) {
368 case IOC_E_FWRSP_GETATTR:
369 bfa_ioc_timer_stop(ioc);
Jing Huang07b28382010-07-08 19:59:24 -0700370 bfa_ioc_check_attr_wwns(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700371 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
372 break;
373
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700374 break;
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800375 case IOC_E_PFFAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700376 case IOC_E_HWERROR:
377 bfa_ioc_timer_stop(ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800378 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700379 case IOC_E_TIMEOUT:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800380 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700381 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800382 if (event != IOC_E_PFFAILED)
383 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700384 break;
385
386 case IOC_E_DISABLE:
387 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700388 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
389 break;
390
391 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700392 break;
393
394 default:
395 bfa_sm_fault(ioc, event);
396 }
397}
398
399
400static void
401bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
402{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700403 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
404
Jing Huang7725ccf2009-09-23 17:46:15 -0700405 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700406 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -0700407 bfa_ioc_hb_monitor(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800408 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700409}
410
411static void
412bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
413{
414 bfa_trc(ioc, event);
415
416 switch (event) {
417 case IOC_E_ENABLE:
418 break;
419
420 case IOC_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800421 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700422 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
423 break;
424
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800425 case IOC_E_PFFAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700426 case IOC_E_HWERROR:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800427 bfa_hb_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700428 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700429 case IOC_E_HBFAIL:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800430 if (ioc->iocpf.auto_recover)
431 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
432 else
433 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
434
Krishna Gudipati775c7742011-06-13 15:52:12 -0700435 bfa_ioc_fail_notify(ioc);
436
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800437 if (event != IOC_E_PFFAILED)
438 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700439 break;
440
441 default:
442 bfa_sm_fault(ioc, event);
443 }
444}
445
446
447static void
448bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
449{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700450 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Maggie Zhangf7f73812010-12-09 19:08:43 -0800451 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
Jing Huang88166242010-12-09 17:11:53 -0800452 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700453}
454
Jing Huang5fbe25c2010-10-18 17:17:23 -0700455/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700456 * IOC is being disabled
457 */
458static void
459bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
460{
461 bfa_trc(ioc, event);
462
463 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700464 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800465 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
466 break;
467
468 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700469 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700470 * No state change. Will move to disabled state
471 * after iocpf sm completes failure processing and
472 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700473 */
Maggie Zhangf7f73812010-12-09 19:08:43 -0800474 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700475 break;
476
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700477 case IOC_E_HWFAILED:
478 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
479 bfa_ioc_disable_comp(ioc);
480 break;
481
Jing Huang7725ccf2009-09-23 17:46:15 -0700482 default:
483 bfa_sm_fault(ioc, event);
484 }
485}
486
Jing Huang5fbe25c2010-10-18 17:17:23 -0700487/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700488 * IOC disable completion entry.
489 */
490static void
491bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
492{
493 bfa_ioc_disable_comp(ioc);
494}
495
496static void
497bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
498{
499 bfa_trc(ioc, event);
500
501 switch (event) {
502 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700503 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700504 break;
505
506 case IOC_E_DISABLE:
507 ioc->cbfn->disable_cbfn(ioc->bfa);
508 break;
509
Jing Huang7725ccf2009-09-23 17:46:15 -0700510 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700511 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800512 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700513 break;
514
515 default:
516 bfa_sm_fault(ioc, event);
517 }
518}
519
520
521static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800522bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700523{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800524 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700525}
526
Jing Huang5fbe25c2010-10-18 17:17:23 -0700527/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800528 * Hardware initialization retry.
Jing Huang7725ccf2009-09-23 17:46:15 -0700529 */
530static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800531bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700532{
533 bfa_trc(ioc, event);
534
535 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700536 case IOC_E_ENABLED:
537 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
538 break;
539
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800540 case IOC_E_PFFAILED:
541 case IOC_E_HWERROR:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700542 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800543 * Initialization retry failed.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700544 */
545 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700546 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800547 if (event != IOC_E_PFFAILED)
548 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
549 break;
550
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700551 case IOC_E_HWFAILED:
552 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
553 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
554 break;
555
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800556 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700557 break;
558
Jing Huang7725ccf2009-09-23 17:46:15 -0700559 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700560 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700561 break;
562
563 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700564 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800565 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700566 break;
567
568 default:
569 bfa_sm_fault(ioc, event);
570 }
571}
572
573
574static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700575bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700576{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800577 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700578}
579
Jing Huang5fbe25c2010-10-18 17:17:23 -0700580/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700581 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700582 */
583static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700584bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700585{
586 bfa_trc(ioc, event);
587
588 switch (event) {
589
590 case IOC_E_ENABLE:
591 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
592 break;
593
594 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700595 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700596 break;
597
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800598 case IOC_E_DETACH:
599 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
600 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
601 break;
602
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800603 case IOC_E_HWERROR:
604 /*
605 * HB failure notification, ignore.
606 */
607 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700608 default:
609 bfa_sm_fault(ioc, event);
610 }
611}
612
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700613static void
614bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s *ioc)
615{
616 bfa_trc(ioc, 0);
617}
618
619static void
620bfa_ioc_sm_hwfail(struct bfa_ioc_s *ioc, enum ioc_event event)
621{
622 bfa_trc(ioc, event);
623
624 switch (event) {
625 case IOC_E_ENABLE:
626 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
627 break;
628
629 case IOC_E_DISABLE:
630 ioc->cbfn->disable_cbfn(ioc->bfa);
631 break;
632
633 case IOC_E_DETACH:
634 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
635 break;
636
637 default:
638 bfa_sm_fault(ioc, event);
639 }
640}
641
Jing Huang5fbe25c2010-10-18 17:17:23 -0700642/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700643 * IOCPF State Machine
644 */
645
Jing Huang5fbe25c2010-10-18 17:17:23 -0700646/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700647 * Reset entry actions -- initialize state machine
648 */
649static void
650bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
651{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700652 iocpf->fw_mismatch_notified = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700653 iocpf->auto_recover = bfa_auto_recover;
654}
655
Jing Huang5fbe25c2010-10-18 17:17:23 -0700656/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700657 * Beginning state. IOC is in reset state.
658 */
659static void
660bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
661{
662 struct bfa_ioc_s *ioc = iocpf->ioc;
663
664 bfa_trc(ioc, event);
665
666 switch (event) {
667 case IOCPF_E_ENABLE:
668 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
669 break;
670
671 case IOCPF_E_STOP:
672 break;
673
674 default:
675 bfa_sm_fault(ioc, event);
676 }
677}
678
Jing Huang5fbe25c2010-10-18 17:17:23 -0700679/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700680 * Semaphore should be acquired for version check.
681 */
682static void
683bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
684{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700685 struct bfi_ioc_image_hdr_s fwhdr;
686 u32 fwstate = readl(iocpf->ioc->ioc_regs.ioc_fwstate);
687
688 /* h/w sem init */
689 if (fwstate == BFI_IOC_UNINIT)
690 goto sem_get;
691
692 bfa_ioc_fwver_get(iocpf->ioc, &fwhdr);
693
694 if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL)
695 goto sem_get;
696
697 bfa_trc(iocpf->ioc, fwstate);
698 bfa_trc(iocpf->ioc, fwhdr.exec);
699 writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.ioc_fwstate);
700
701 /*
702 * Try to lock and then unlock the semaphore.
703 */
704 readl(iocpf->ioc->ioc_regs.ioc_sem_reg);
705 writel(1, iocpf->ioc->ioc_regs.ioc_sem_reg);
706sem_get:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700707 bfa_ioc_hw_sem_get(iocpf->ioc);
708}
709
Jing Huang5fbe25c2010-10-18 17:17:23 -0700710/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700711 * Awaiting h/w semaphore to continue with version check.
712 */
713static void
714bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
715{
716 struct bfa_ioc_s *ioc = iocpf->ioc;
717
718 bfa_trc(ioc, event);
719
720 switch (event) {
721 case IOCPF_E_SEMLOCKED:
722 if (bfa_ioc_firmware_lock(ioc)) {
Jing Huang45d7f0c2011-04-13 11:45:53 -0700723 if (bfa_ioc_sync_start(ioc)) {
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800724 bfa_ioc_sync_join(ioc);
725 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
726 } else {
727 bfa_ioc_firmware_unlock(ioc);
728 writel(1, ioc->ioc_regs.ioc_sem_reg);
729 bfa_sem_timer_start(ioc);
730 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700731 } else {
Maggie Zhangf7f73812010-12-09 19:08:43 -0800732 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700733 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
734 }
735 break;
736
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700737 case IOCPF_E_SEM_ERROR:
738 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
739 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
740 break;
741
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700742 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800743 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700744 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800745 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700746 break;
747
748 case IOCPF_E_STOP:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800749 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700750 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
751 break;
752
753 default:
754 bfa_sm_fault(ioc, event);
755 }
756}
757
Jing Huang5fbe25c2010-10-18 17:17:23 -0700758/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700759 * Notify enable completion callback.
760 */
761static void
762bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
763{
764 /*
765 * Call only the first time sm enters fwmismatch state.
766 */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700767 if (iocpf->fw_mismatch_notified == BFA_FALSE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700768 bfa_ioc_pf_fwmismatch(iocpf->ioc);
769
Krishna Gudipati775c7742011-06-13 15:52:12 -0700770 iocpf->fw_mismatch_notified = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700771 bfa_iocpf_timer_start(iocpf->ioc);
772}
773
Jing Huang5fbe25c2010-10-18 17:17:23 -0700774/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700775 * Awaiting firmware version match.
776 */
777static void
778bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
779{
780 struct bfa_ioc_s *ioc = iocpf->ioc;
781
782 bfa_trc(ioc, event);
783
784 switch (event) {
785 case IOCPF_E_TIMEOUT:
786 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
787 break;
788
789 case IOCPF_E_DISABLE:
790 bfa_iocpf_timer_stop(ioc);
791 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800792 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700793 break;
794
795 case IOCPF_E_STOP:
796 bfa_iocpf_timer_stop(ioc);
797 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
798 break;
799
800 default:
801 bfa_sm_fault(ioc, event);
802 }
803}
804
Jing Huang5fbe25c2010-10-18 17:17:23 -0700805/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700806 * Request for semaphore.
807 */
808static void
809bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
810{
811 bfa_ioc_hw_sem_get(iocpf->ioc);
812}
813
Jing Huang5fbe25c2010-10-18 17:17:23 -0700814/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700815 * Awaiting semaphore for h/w initialzation.
816 */
817static void
818bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
819{
820 struct bfa_ioc_s *ioc = iocpf->ioc;
821
822 bfa_trc(ioc, event);
823
824 switch (event) {
825 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800826 if (bfa_ioc_sync_complete(ioc)) {
827 bfa_ioc_sync_join(ioc);
828 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
829 } else {
830 writel(1, ioc->ioc_regs.ioc_sem_reg);
831 bfa_sem_timer_start(ioc);
832 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700833 break;
834
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700835 case IOCPF_E_SEM_ERROR:
836 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
837 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
838 break;
839
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700840 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800841 bfa_sem_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800842 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700843 break;
844
845 default:
846 bfa_sm_fault(ioc, event);
847 }
848}
849
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700850static void
851bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
852{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700853 iocpf->poll_time = 0;
Maggie Zhangf7f73812010-12-09 19:08:43 -0800854 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700855}
856
Jing Huang5fbe25c2010-10-18 17:17:23 -0700857/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700858 * Hardware is being initialized. Interrupts are enabled.
859 * Holding hardware semaphore lock.
860 */
861static void
862bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
863{
864 struct bfa_ioc_s *ioc = iocpf->ioc;
865
866 bfa_trc(ioc, event);
867
868 switch (event) {
869 case IOCPF_E_FWREADY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700870 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
871 break;
872
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700873 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800874 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700875 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800876 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700877 break;
878
879 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700880 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800881 bfa_ioc_sync_leave(ioc);
882 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700883 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
884 break;
885
886 default:
887 bfa_sm_fault(ioc, event);
888 }
889}
890
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700891static void
892bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
893{
894 bfa_iocpf_timer_start(iocpf->ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700895 /*
896 * Enable Interrupts before sending fw IOC ENABLE cmd.
897 */
898 iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700899 bfa_ioc_send_enable(iocpf->ioc);
900}
901
Jing Huang5fbe25c2010-10-18 17:17:23 -0700902/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700903 * Host IOC function is being enabled, awaiting response from firmware.
904 * Semaphore is acquired.
905 */
906static void
907bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
908{
909 struct bfa_ioc_s *ioc = iocpf->ioc;
910
911 bfa_trc(ioc, event);
912
913 switch (event) {
914 case IOCPF_E_FWRSP_ENABLE:
915 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800916 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700917 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
918 break;
919
920 case IOCPF_E_INITFAIL:
921 bfa_iocpf_timer_stop(ioc);
922 /*
923 * !!! fall through !!!
924 */
925
926 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800927 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700928 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800929 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800930 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700931 break;
932
933 case IOCPF_E_DISABLE:
934 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800935 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700936 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
937 break;
938
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700939 default:
940 bfa_sm_fault(ioc, event);
941 }
942}
943
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700944static void
945bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
946{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800947 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700948}
949
950static void
951bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
952{
953 struct bfa_ioc_s *ioc = iocpf->ioc;
954
955 bfa_trc(ioc, event);
956
957 switch (event) {
958 case IOCPF_E_DISABLE:
959 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
960 break;
961
962 case IOCPF_E_GETATTRFAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800963 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700964 break;
965
966 case IOCPF_E_FAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800967 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700968 break;
969
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700970 default:
971 bfa_sm_fault(ioc, event);
972 }
973}
974
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700975static void
976bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
977{
978 bfa_iocpf_timer_start(iocpf->ioc);
979 bfa_ioc_send_disable(iocpf->ioc);
980}
981
Jing Huang5fbe25c2010-10-18 17:17:23 -0700982/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700983 * IOC is being disabled
984 */
985static void
986bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
987{
988 struct bfa_ioc_s *ioc = iocpf->ioc;
989
990 bfa_trc(ioc, event);
991
992 switch (event) {
993 case IOCPF_E_FWRSP_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700994 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800995 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700996 break;
997
998 case IOCPF_E_FAIL:
999 bfa_iocpf_timer_stop(ioc);
1000 /*
1001 * !!! fall through !!!
1002 */
1003
1004 case IOCPF_E_TIMEOUT:
Jing Huang53440262010-10-18 17:12:29 -07001005 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001006 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001007 break;
1008
1009 case IOCPF_E_FWRSP_ENABLE:
1010 break;
1011
1012 default:
1013 bfa_sm_fault(ioc, event);
1014 }
1015}
1016
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001017static void
1018bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
1019{
1020 bfa_ioc_hw_sem_get(iocpf->ioc);
1021}
1022
Jing Huang8f4bfad2010-12-26 21:50:10 -08001023/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001024 * IOC hb ack request is being removed.
1025 */
1026static void
1027bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1028{
1029 struct bfa_ioc_s *ioc = iocpf->ioc;
1030
1031 bfa_trc(ioc, event);
1032
1033 switch (event) {
1034 case IOCPF_E_SEMLOCKED:
1035 bfa_ioc_sync_leave(ioc);
1036 writel(1, ioc->ioc_regs.ioc_sem_reg);
1037 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1038 break;
1039
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001040 case IOCPF_E_SEM_ERROR:
1041 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1042 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1043 break;
1044
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001045 case IOCPF_E_FAIL:
1046 break;
1047
1048 default:
1049 bfa_sm_fault(ioc, event);
1050 }
1051}
1052
Jing Huang5fbe25c2010-10-18 17:17:23 -07001053/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001054 * IOC disable completion entry.
1055 */
1056static void
1057bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
1058{
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001059 bfa_ioc_mbox_flush(iocpf->ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -08001060 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001061}
1062
1063static void
1064bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1065{
1066 struct bfa_ioc_s *ioc = iocpf->ioc;
1067
1068 bfa_trc(ioc, event);
1069
1070 switch (event) {
1071 case IOCPF_E_ENABLE:
1072 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1073 break;
1074
1075 case IOCPF_E_STOP:
1076 bfa_ioc_firmware_unlock(ioc);
1077 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1078 break;
1079
1080 default:
1081 bfa_sm_fault(ioc, event);
1082 }
1083}
1084
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001085static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001086bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1087{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001088 bfa_ioc_debug_save_ftrc(iocpf->ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001089 bfa_ioc_hw_sem_get(iocpf->ioc);
1090}
1091
Jing Huang8f4bfad2010-12-26 21:50:10 -08001092/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001093 * Hardware initialization failed.
1094 */
1095static void
1096bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1097{
1098 struct bfa_ioc_s *ioc = iocpf->ioc;
1099
1100 bfa_trc(ioc, event);
1101
1102 switch (event) {
1103 case IOCPF_E_SEMLOCKED:
1104 bfa_ioc_notify_fail(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001105 bfa_ioc_sync_leave(ioc);
1106 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1107 writel(1, ioc->ioc_regs.ioc_sem_reg);
1108 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001109 break;
1110
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001111 case IOCPF_E_SEM_ERROR:
1112 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1113 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1114 break;
1115
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001116 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_STOP:
1122 bfa_sem_timer_stop(ioc);
1123 bfa_ioc_firmware_unlock(ioc);
1124 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1125 break;
1126
1127 case IOCPF_E_FAIL:
1128 break;
1129
1130 default:
1131 bfa_sm_fault(ioc, event);
1132 }
1133}
1134
1135static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001136bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1137{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001138 bfa_trc(iocpf->ioc, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001139}
1140
Jing Huang5fbe25c2010-10-18 17:17:23 -07001141/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001142 * Hardware initialization failed.
1143 */
1144static void
1145bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1146{
1147 struct bfa_ioc_s *ioc = iocpf->ioc;
1148
1149 bfa_trc(ioc, event);
1150
1151 switch (event) {
1152 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001153 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1154 break;
1155
1156 case IOCPF_E_STOP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001157 bfa_ioc_firmware_unlock(ioc);
1158 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1159 break;
1160
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001161 default:
1162 bfa_sm_fault(ioc, event);
1163 }
1164}
1165
1166static void
1167bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1168{
Jing Huang8f4bfad2010-12-26 21:50:10 -08001169 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001170 * Mark IOC as failed in hardware and stop firmware.
1171 */
1172 bfa_ioc_lpu_stop(iocpf->ioc);
1173
Jing Huang8f4bfad2010-12-26 21:50:10 -08001174 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001175 * Flush any queued up mailbox requests.
1176 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001177 bfa_ioc_mbox_flush(iocpf->ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001178
1179 bfa_ioc_hw_sem_get(iocpf->ioc);
1180}
1181
1182static void
1183bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1184{
1185 struct bfa_ioc_s *ioc = iocpf->ioc;
1186
1187 bfa_trc(ioc, event);
1188
1189 switch (event) {
1190 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001191 bfa_ioc_sync_ack(ioc);
1192 bfa_ioc_notify_fail(ioc);
1193 if (!iocpf->auto_recover) {
1194 bfa_ioc_sync_leave(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001195 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001196 writel(1, ioc->ioc_regs.ioc_sem_reg);
1197 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1198 } else {
1199 if (bfa_ioc_sync_complete(ioc))
1200 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1201 else {
1202 writel(1, ioc->ioc_regs.ioc_sem_reg);
1203 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1204 }
1205 }
1206 break;
1207
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001208 case IOCPF_E_SEM_ERROR:
1209 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1210 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1211 break;
1212
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001213 case IOCPF_E_DISABLE:
1214 bfa_sem_timer_stop(ioc);
1215 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1216 break;
1217
1218 case IOCPF_E_FAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001219 break;
1220
1221 default:
1222 bfa_sm_fault(ioc, event);
1223 }
1224}
1225
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001226static void
1227bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1228{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001229 bfa_trc(iocpf->ioc, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001230}
1231
Jing Huang5fbe25c2010-10-18 17:17:23 -07001232/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001233 * IOC is in failed state.
1234 */
1235static void
1236bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1237{
1238 struct bfa_ioc_s *ioc = iocpf->ioc;
1239
1240 bfa_trc(ioc, event);
1241
1242 switch (event) {
1243 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001244 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1245 break;
1246
Jing Huang7725ccf2009-09-23 17:46:15 -07001247 default:
1248 bfa_sm_fault(ioc, event);
1249 }
1250}
1251
Jing Huang5fbe25c2010-10-18 17:17:23 -07001252/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001253 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001254 */
1255
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001256/*
1257 * Notify common modules registered for notification.
1258 */
1259static void
1260bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
1261{
1262 struct bfa_ioc_notify_s *notify;
1263 struct list_head *qe;
1264
1265 list_for_each(qe, &ioc->notify_q) {
1266 notify = (struct bfa_ioc_notify_s *)qe;
1267 notify->cbfn(notify->cbarg, event);
1268 }
1269}
1270
Jing Huang7725ccf2009-09-23 17:46:15 -07001271static void
1272bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1273{
Jing Huang7725ccf2009-09-23 17:46:15 -07001274 ioc->cbfn->disable_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001275 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001276}
1277
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001278bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001279bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001280{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001281 u32 r32;
1282 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001283#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001284
Jing Huang53440262010-10-18 17:12:29 -07001285 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001286
Krishna Gudipati11189202011-06-13 15:50:35 -07001287 while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001288 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001289 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001290 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001291 }
1292
Krishna Gudipati11189202011-06-13 15:50:35 -07001293 if (!(r32 & 1))
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001294 return BFA_TRUE;
1295
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001296 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001297}
1298
Jing Huang7725ccf2009-09-23 17:46:15 -07001299static void
1300bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1301{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001302 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001303
Jing Huang5fbe25c2010-10-18 17:17:23 -07001304 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001305 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001306 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001307 */
Jing Huang53440262010-10-18 17:12:29 -07001308 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001309 if (r32 == ~0) {
1310 WARN_ON(r32 == ~0);
1311 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
1312 return;
1313 }
Krishna Gudipati11189202011-06-13 15:50:35 -07001314 if (!(r32 & 1)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001315 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001316 return;
1317 }
1318
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001319 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001320}
1321
Jing Huang5fbe25c2010-10-18 17:17:23 -07001322/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001323 * Initialize LPU local memory (aka secondary memory / SRAM)
1324 */
1325static void
1326bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1327{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001328 u32 pss_ctl;
1329 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001330#define PSS_LMEM_INIT_TIME 10000
1331
Jing Huang53440262010-10-18 17:12:29 -07001332 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001333 pss_ctl &= ~__PSS_LMEM_RESET;
1334 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001335
1336 /*
1337 * i2c workaround 12.5khz clock
1338 */
1339 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001340 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001341
Jing Huang5fbe25c2010-10-18 17:17:23 -07001342 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001343 * wait for memory initialization to be complete
1344 */
1345 i = 0;
1346 do {
Jing Huang53440262010-10-18 17:12:29 -07001347 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001348 i++;
1349 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1350
Jing Huang5fbe25c2010-10-18 17:17:23 -07001351 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001352 * If memory initialization is not successful, IOC timeout will catch
1353 * such failures.
1354 */
Jing Huangd4b671c2010-12-26 21:46:35 -08001355 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
Jing Huang7725ccf2009-09-23 17:46:15 -07001356 bfa_trc(ioc, pss_ctl);
1357
1358 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001359 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001360}
1361
1362static void
1363bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1364{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001365 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001366
Jing Huang5fbe25c2010-10-18 17:17:23 -07001367 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001368 * Take processor out of reset.
1369 */
Jing Huang53440262010-10-18 17:12:29 -07001370 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001371 pss_ctl &= ~__PSS_LPU0_RESET;
1372
Jing Huang53440262010-10-18 17:12:29 -07001373 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001374}
1375
1376static void
1377bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1378{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001379 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001380
Jing Huang5fbe25c2010-10-18 17:17:23 -07001381 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001382 * Put processors in reset.
1383 */
Jing Huang53440262010-10-18 17:12:29 -07001384 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001385 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1386
Jing Huang53440262010-10-18 17:12:29 -07001387 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001388}
1389
Jing Huang5fbe25c2010-10-18 17:17:23 -07001390/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001391 * Get driver and firmware versions.
1392 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001393void
Jing Huang7725ccf2009-09-23 17:46:15 -07001394bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1395{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001396 u32 pgnum, pgoff;
1397 u32 loff = 0;
1398 int i;
1399 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001400
Maggie Zhangf7f73812010-12-09 19:08:43 -08001401 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1402 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang53440262010-10-18 17:12:29 -07001403 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001404
1405 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1406 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001407 fwsig[i] =
1408 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001409 loff += sizeof(u32);
1410 }
1411}
1412
Jing Huang5fbe25c2010-10-18 17:17:23 -07001413/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001414 * Returns TRUE if same.
1415 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001416bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001417bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1418{
1419 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001420 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001421
Jing Huang293f82d2010-07-08 19:45:20 -07001422 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001423 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001424
1425 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1426 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1427 bfa_trc(ioc, i);
1428 bfa_trc(ioc, fwhdr->md5sum[i]);
1429 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1430 return BFA_FALSE;
1431 }
1432 }
1433
1434 bfa_trc(ioc, fwhdr->md5sum[0]);
1435 return BFA_TRUE;
1436}
1437
Jing Huang5fbe25c2010-10-18 17:17:23 -07001438/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001439 * Return true if current running version is valid. Firmware signature and
1440 * execution context (driver/bios) must match.
1441 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001442static bfa_boolean_t
1443bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001444{
1445 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1446
Jing Huang7725ccf2009-09-23 17:46:15 -07001447 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001448 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001449 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001450
1451 if (fwhdr.signature != drv_fwhdr->signature) {
1452 bfa_trc(ioc, fwhdr.signature);
1453 bfa_trc(ioc, drv_fwhdr->signature);
1454 return BFA_FALSE;
1455 }
1456
Krishna Gudipati11189202011-06-13 15:50:35 -07001457 if (swab32(fwhdr.bootenv) != boot_env) {
1458 bfa_trc(ioc, fwhdr.bootenv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001459 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001460 return BFA_FALSE;
1461 }
1462
1463 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1464}
1465
Jing Huang5fbe25c2010-10-18 17:17:23 -07001466/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001467 * Conditionally flush any pending message from firmware at start.
1468 */
1469static void
1470bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1471{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001472 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001473
Jing Huang53440262010-10-18 17:12:29 -07001474 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001475 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001476 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001477}
1478
Jing Huang7725ccf2009-09-23 17:46:15 -07001479static void
1480bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1481{
1482 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001483 bfa_boolean_t fwvalid;
1484 u32 boot_type;
1485 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001486
Jing Huang53440262010-10-18 17:12:29 -07001487 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001488
1489 if (force)
1490 ioc_fwstate = BFI_IOC_UNINIT;
1491
1492 bfa_trc(ioc, ioc_fwstate);
1493
Krishna Gudipati11189202011-06-13 15:50:35 -07001494 boot_type = BFI_FWBOOT_TYPE_NORMAL;
1495 boot_env = BFI_FWBOOT_ENV_OS;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001496
Jing Huang5fbe25c2010-10-18 17:17:23 -07001497 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001498 * check if firmware is valid
1499 */
1500 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001501 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001502
1503 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001504 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001505 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001506 return;
1507 }
1508
Jing Huang5fbe25c2010-10-18 17:17:23 -07001509 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001510 * If hardware initialization is in progress (initialized by other IOC),
1511 * just wait for an initialization completion interrupt.
1512 */
1513 if (ioc_fwstate == BFI_IOC_INITING) {
Krishna Gudipati775c7742011-06-13 15:52:12 -07001514 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001515 return;
1516 }
1517
Jing Huang5fbe25c2010-10-18 17:17:23 -07001518 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001519 * If IOC function is disabled and firmware version is same,
1520 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001521 *
1522 * If option rom, IOC must not be in operational state. With
1523 * convergence, IOC will be in operational state when 2nd driver
1524 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001525 */
Jing Huang8f4bfad2010-12-26 21:50:10 -08001526 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001527
Jing Huang5fbe25c2010-10-18 17:17:23 -07001528 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001529 * When using MSI-X any pending firmware ready event should
1530 * be flushed. Otherwise MSI-X interrupts are not delivered.
1531 */
1532 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001533 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001534 return;
1535 }
1536
Jing Huang5fbe25c2010-10-18 17:17:23 -07001537 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001538 * Initialize the h/w for any other states.
1539 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001540 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001541 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001542}
1543
1544static void
1545bfa_ioc_timeout(void *ioc_arg)
1546{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001547 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001548
1549 bfa_trc(ioc, 0);
1550 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1551}
1552
1553void
1554bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1555{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001556 u32 *msgp = (u32 *) ioc_msg;
1557 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001558
1559 bfa_trc(ioc, msgp[0]);
1560 bfa_trc(ioc, len);
1561
Jing Huangd4b671c2010-12-26 21:46:35 -08001562 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
Jing Huang7725ccf2009-09-23 17:46:15 -07001563
1564 /*
1565 * first write msg to mailbox registers
1566 */
1567 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001568 writel(cpu_to_le32(msgp[i]),
1569 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001570
1571 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001572 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001573
1574 /*
1575 * write 1 to mailbox CMD to trigger LPU event
1576 */
Jing Huang53440262010-10-18 17:12:29 -07001577 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1578 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001579}
1580
1581static void
1582bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1583{
1584 struct bfi_ioc_ctrl_req_s enable_req;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001585 struct timeval tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001586
1587 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1588 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001589 enable_req.clscode = cpu_to_be16(ioc->clscode);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001590 do_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001591 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001592 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1593}
1594
1595static void
1596bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1597{
1598 struct bfi_ioc_ctrl_req_s disable_req;
1599
1600 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1601 bfa_ioc_portid(ioc));
1602 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1603}
1604
1605static void
1606bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1607{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001608 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001609
1610 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1611 bfa_ioc_portid(ioc));
1612 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1613 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1614}
1615
1616static void
1617bfa_ioc_hb_check(void *cbarg)
1618{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001619 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001620 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001621
Jing Huang53440262010-10-18 17:12:29 -07001622 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001623 if (ioc->hb_count == hb_count) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001624 bfa_ioc_recover(ioc);
1625 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001626 } else {
1627 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001628 }
1629
1630 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001631 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001632}
1633
1634static void
1635bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1636{
Jing Huang53440262010-10-18 17:12:29 -07001637 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001638 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001639}
1640
Jing Huang5fbe25c2010-10-18 17:17:23 -07001641/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001642 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001643 */
1644static void
1645bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001646 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001647{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001648 u32 *fwimg;
1649 u32 pgnum, pgoff;
1650 u32 loff = 0;
1651 u32 chunkno = 0;
1652 u32 i;
Krishna Gudipati11189202011-06-13 15:50:35 -07001653 u32 asicmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07001654
Jing Huang5fbe25c2010-10-18 17:17:23 -07001655 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001656 * Initialize LMEM first before code download
1657 */
1658 bfa_ioc_lmem_init(ioc);
1659
Krishna Gudipati11189202011-06-13 15:50:35 -07001660 bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)));
1661 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001662
Maggie Zhangf7f73812010-12-09 19:08:43 -08001663 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1664 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001665
Jing Huang53440262010-10-18 17:12:29 -07001666 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001667
Krishna Gudipati11189202011-06-13 15:50:35 -07001668 for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001669
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001670 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1671 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipati11189202011-06-13 15:50:35 -07001672 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001673 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001674 }
1675
Jing Huang5fbe25c2010-10-18 17:17:23 -07001676 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001677 * write smem
1678 */
1679 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001680 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001681
1682 loff += sizeof(u32);
1683
Jing Huang5fbe25c2010-10-18 17:17:23 -07001684 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001685 * handle page offset wrap around
1686 */
1687 loff = PSS_SMEM_PGOFF(loff);
1688 if (loff == 0) {
1689 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001690 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001691 }
1692 }
1693
Maggie Zhangf7f73812010-12-09 19:08:43 -08001694 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1695 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001696
1697 /*
Krishna Gudipati11189202011-06-13 15:50:35 -07001698 * Set boot type and device mode at the end.
1699 */
1700 asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
1701 ioc->port0_mode, ioc->port1_mode);
1702 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF,
1703 swab32(asicmode));
1704 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001705 swab32(boot_type));
Krishna Gudipati11189202011-06-13 15:50:35 -07001706 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001707 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001708}
1709
Jing Huang7725ccf2009-09-23 17:46:15 -07001710
Jing Huang5fbe25c2010-10-18 17:17:23 -07001711/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001712 * Update BFA configuration from firmware configuration.
1713 */
1714static void
1715bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1716{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001717 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001718
Jing Huangba816ea2010-10-18 17:10:50 -07001719 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1720 attr->card_type = be32_to_cpu(attr->card_type);
1721 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001722 ioc->fcmode = (attr->port_mode == BFI_PORT_MODE_FC);
Jing Huang7725ccf2009-09-23 17:46:15 -07001723
1724 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1725}
1726
Jing Huang5fbe25c2010-10-18 17:17:23 -07001727/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001728 * Attach time initialization of mbox logic.
1729 */
1730static void
1731bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1732{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001733 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1734 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001735
1736 INIT_LIST_HEAD(&mod->cmd_q);
1737 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1738 mod->mbhdlr[mc].cbfn = NULL;
1739 mod->mbhdlr[mc].cbarg = ioc->bfa;
1740 }
1741}
1742
Jing Huang5fbe25c2010-10-18 17:17:23 -07001743/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001744 * Mbox poll timer -- restarts any pending mailbox requests.
1745 */
1746static void
1747bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1748{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001749 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1750 struct bfa_mbox_cmd_s *cmd;
1751 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001752
Jing Huang5fbe25c2010-10-18 17:17:23 -07001753 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001754 * If no command pending, do nothing
1755 */
1756 if (list_empty(&mod->cmd_q))
1757 return;
1758
Jing Huang5fbe25c2010-10-18 17:17:23 -07001759 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001760 * If previous command is not yet fetched by firmware, do nothing
1761 */
Jing Huang53440262010-10-18 17:12:29 -07001762 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001763 if (stat)
1764 return;
1765
Jing Huang5fbe25c2010-10-18 17:17:23 -07001766 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001767 * Enqueue command to firmware.
1768 */
1769 bfa_q_deq(&mod->cmd_q, &cmd);
1770 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1771}
1772
Jing Huang5fbe25c2010-10-18 17:17:23 -07001773/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001774 * Cleanup any pending requests.
1775 */
1776static void
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001777bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07001778{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001779 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1780 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001781
1782 while (!list_empty(&mod->cmd_q))
1783 bfa_q_deq(&mod->cmd_q, &cmd);
1784}
1785
Jing Huang5fbe25c2010-10-18 17:17:23 -07001786/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001787 * Read data from SMEM to host through PCI memmap
1788 *
1789 * @param[in] ioc memory for IOC
1790 * @param[in] tbuf app memory to store data from smem
1791 * @param[in] soff smem offset
1792 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001793 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001794static bfa_status_t
1795bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1796{
Maggie50444a32010-11-29 18:26:32 -08001797 u32 pgnum, loff;
1798 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001799 int i, len;
1800 u32 *buf = tbuf;
1801
Maggie Zhangf7f73812010-12-09 19:08:43 -08001802 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1803 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001804 bfa_trc(ioc, pgnum);
1805 bfa_trc(ioc, loff);
1806 bfa_trc(ioc, sz);
1807
1808 /*
1809 * Hold semaphore to serialize pll init and fwtrc.
1810 */
1811 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1812 bfa_trc(ioc, 0);
1813 return BFA_STATUS_FAILED;
1814 }
1815
Jing Huang53440262010-10-18 17:12:29 -07001816 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001817
1818 len = sz/sizeof(u32);
1819 bfa_trc(ioc, len);
1820 for (i = 0; i < len; i++) {
1821 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001822 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001823 loff += sizeof(u32);
1824
Jing Huang5fbe25c2010-10-18 17:17:23 -07001825 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001826 * handle page offset wrap around
1827 */
1828 loff = PSS_SMEM_PGOFF(loff);
1829 if (loff == 0) {
1830 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001831 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001832 }
1833 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001834 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1835 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001836 /*
1837 * release semaphore.
1838 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001839 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f73812010-12-09 19:08:43 -08001840 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001841
1842 bfa_trc(ioc, pgnum);
1843 return BFA_STATUS_OK;
1844}
1845
Jing Huang5fbe25c2010-10-18 17:17:23 -07001846/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001847 * Clear SMEM data from host through PCI memmap
1848 *
1849 * @param[in] ioc memory for IOC
1850 * @param[in] soff smem offset
1851 * @param[in] sz size of smem in bytes
1852 */
1853static bfa_status_t
1854bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1855{
1856 int i, len;
1857 u32 pgnum, loff;
1858
Maggie Zhangf7f73812010-12-09 19:08:43 -08001859 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1860 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001861 bfa_trc(ioc, pgnum);
1862 bfa_trc(ioc, loff);
1863 bfa_trc(ioc, sz);
1864
1865 /*
1866 * Hold semaphore to serialize pll init and fwtrc.
1867 */
1868 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1869 bfa_trc(ioc, 0);
1870 return BFA_STATUS_FAILED;
1871 }
1872
Jing Huang53440262010-10-18 17:12:29 -07001873 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001874
1875 len = sz/sizeof(u32); /* len in words */
1876 bfa_trc(ioc, len);
1877 for (i = 0; i < len; i++) {
1878 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1879 loff += sizeof(u32);
1880
Jing Huang5fbe25c2010-10-18 17:17:23 -07001881 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001882 * handle page offset wrap around
1883 */
1884 loff = PSS_SMEM_PGOFF(loff);
1885 if (loff == 0) {
1886 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001887 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001888 }
1889 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001890 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1891 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001892
1893 /*
1894 * release semaphore.
1895 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001896 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f73812010-12-09 19:08:43 -08001897 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001898 bfa_trc(ioc, pgnum);
1899 return BFA_STATUS_OK;
1900}
1901
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001902static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001903bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1904{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001905 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1906
Jing Huang8f4bfad2010-12-26 21:50:10 -08001907 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001908 * Notify driver and common modules registered for notification.
1909 */
1910 ioc->cbfn->hbfail_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001911 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001912
1913 bfa_ioc_debug_save_ftrc(ioc);
1914
1915 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1916 "Heart Beat of IOC has failed\n");
1917
1918}
1919
1920static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001921bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1922{
1923 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001924 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001925 * Provide enable completion callback.
1926 */
1927 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001928 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001929 "Running firmware version is incompatible "
1930 "with the driver version\n");
1931}
1932
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001933bfa_status_t
1934bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1935{
1936
1937 /*
1938 * Hold semaphore so that nobody can access the chip during init.
1939 */
1940 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1941
1942 bfa_ioc_pll_init_asic(ioc);
1943
1944 ioc->pllinit = BFA_TRUE;
1945 /*
1946 * release semaphore.
1947 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001948 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f73812010-12-09 19:08:43 -08001949 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001950
1951 return BFA_STATUS_OK;
1952}
Jing Huang7725ccf2009-09-23 17:46:15 -07001953
Jing Huang5fbe25c2010-10-18 17:17:23 -07001954/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001955 * Interface used by diag module to do firmware boot with memory test
1956 * as the entry vector.
1957 */
1958void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001959bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001960{
Jing Huang7725ccf2009-09-23 17:46:15 -07001961 bfa_ioc_stats(ioc, ioc_boots);
1962
1963 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1964 return;
1965
Jing Huang5fbe25c2010-10-18 17:17:23 -07001966 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001967 * Initialize IOC state of all functions on a chip reset.
1968 */
Krishna Gudipati11189202011-06-13 15:50:35 -07001969 if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
1970 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate);
1971 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001972 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -07001973 writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate);
1974 writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001975 }
1976
Jing Huang07b28382010-07-08 19:59:24 -07001977 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001978 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001979 bfa_ioc_lpu_start(ioc);
1980}
1981
Jing Huang5fbe25c2010-10-18 17:17:23 -07001982/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001983 * Enable/disable IOC failure auto recovery.
1984 */
1985void
1986bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
1987{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08001988 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07001989}
1990
1991
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001992
Jing Huang7725ccf2009-09-23 17:46:15 -07001993bfa_boolean_t
1994bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
1995{
1996 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
1997}
1998
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001999bfa_boolean_t
2000bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
2001{
Jing Huang53440262010-10-18 17:12:29 -07002002 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002003
2004 return ((r32 != BFI_IOC_UNINIT) &&
2005 (r32 != BFI_IOC_INITING) &&
2006 (r32 != BFI_IOC_MEMTEST));
2007}
2008
Krishna Gudipati11189202011-06-13 15:50:35 -07002009bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07002010bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
2011{
Maggie50444a32010-11-29 18:26:32 -08002012 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002013 u32 r32;
2014 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07002015
Krishna Gudipati11189202011-06-13 15:50:35 -07002016 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
2017 if ((r32 & 1) == 0)
2018 return BFA_FALSE;
2019
Jing Huang5fbe25c2010-10-18 17:17:23 -07002020 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002021 * read the MBOX msg
2022 */
2023 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
2024 i++) {
Jing Huang53440262010-10-18 17:12:29 -07002025 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07002026 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07002027 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07002028 }
2029
Jing Huang5fbe25c2010-10-18 17:17:23 -07002030 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002031 * turn off mailbox interrupt by clearing mailbox status
2032 */
Jing Huang53440262010-10-18 17:12:29 -07002033 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
2034 readl(ioc->ioc_regs.lpu_mbox_cmd);
Krishna Gudipati11189202011-06-13 15:50:35 -07002035
2036 return BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002037}
2038
2039void
2040bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
2041{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002042 union bfi_ioc_i2h_msg_u *msg;
2043 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07002044
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002045 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002046
2047 bfa_ioc_stats(ioc, ioc_isrs);
2048
2049 switch (msg->mh.msg_id) {
2050 case BFI_IOC_I2H_HBEAT:
2051 break;
2052
Jing Huang7725ccf2009-09-23 17:46:15 -07002053 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002054 ioc->port_mode = ioc->port_mode_cfg =
2055 (enum bfa_mode_s)msg->fw_event.port_mode;
2056 ioc->ad_cap_bm = msg->fw_event.cap_bm;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002057 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07002058 break;
2059
2060 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002061 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07002062 break;
2063
2064 case BFI_IOC_I2H_GETATTR_REPLY:
2065 bfa_ioc_getattr_reply(ioc);
2066 break;
2067
2068 default:
2069 bfa_trc(ioc, msg->mh.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002070 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -07002071 }
2072}
2073
Jing Huang5fbe25c2010-10-18 17:17:23 -07002074/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002075 * IOC attach time initialization and setup.
2076 *
2077 * @param[in] ioc memory for IOC
2078 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07002079 */
2080void
2081bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002082 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07002083{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002084 ioc->bfa = bfa;
2085 ioc->cbfn = cbfn;
2086 ioc->timer_mod = timer_mod;
2087 ioc->fcmode = BFA_FALSE;
2088 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002089 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002090 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002091
2092 bfa_ioc_mbox_attach(ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002093 INIT_LIST_HEAD(&ioc->notify_q);
Jing Huang7725ccf2009-09-23 17:46:15 -07002094
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002095 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
2096 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07002097}
2098
Jing Huang5fbe25c2010-10-18 17:17:23 -07002099/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002100 * Driver detach time IOC cleanup.
2101 */
2102void
2103bfa_ioc_detach(struct bfa_ioc_s *ioc)
2104{
2105 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2106}
2107
Jing Huang5fbe25c2010-10-18 17:17:23 -07002108/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002109 * Setup IOC PCI properties.
2110 *
2111 * @param[in] pcidev PCI device information for this IOC
2112 */
2113void
2114bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002115 enum bfi_pcifn_class clscode)
Jing Huang7725ccf2009-09-23 17:46:15 -07002116{
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002117 ioc->clscode = clscode;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002118 ioc->pcidev = *pcidev;
Krishna Gudipati11189202011-06-13 15:50:35 -07002119
2120 /*
2121 * Initialize IOC and device personality
2122 */
2123 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
2124 ioc->asic_mode = BFI_ASIC_MODE_FC;
2125
2126 switch (pcidev->device_id) {
2127 case BFA_PCI_DEVICE_ID_FC_8G1P:
2128 case BFA_PCI_DEVICE_ID_FC_8G2P:
2129 ioc->asic_gen = BFI_ASIC_GEN_CB;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002130 ioc->fcmode = BFA_TRUE;
2131 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2132 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002133 break;
2134
2135 case BFA_PCI_DEVICE_ID_CT:
2136 ioc->asic_gen = BFI_ASIC_GEN_CT;
2137 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
2138 ioc->asic_mode = BFI_ASIC_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002139 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
2140 ioc->ad_cap_bm = BFA_CM_CNA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002141 break;
2142
2143 case BFA_PCI_DEVICE_ID_CT_FC:
2144 ioc->asic_gen = BFI_ASIC_GEN_CT;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002145 ioc->fcmode = BFA_TRUE;
2146 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2147 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002148 break;
2149
2150 case BFA_PCI_DEVICE_ID_CT2:
2151 ioc->asic_gen = BFI_ASIC_GEN_CT2;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002152 if (clscode == BFI_PCIFN_CLASS_FC &&
2153 pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002154 ioc->asic_mode = BFI_ASIC_MODE_FC16;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002155 ioc->fcmode = BFA_TRUE;
2156 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2157 ioc->ad_cap_bm = BFA_CM_HBA;
2158 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -07002159 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002160 ioc->asic_mode = BFI_ASIC_MODE_ETH;
2161 if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
2162 ioc->port_mode =
2163 ioc->port_mode_cfg = BFA_MODE_CNA;
2164 ioc->ad_cap_bm = BFA_CM_CNA;
2165 } else {
2166 ioc->port_mode =
2167 ioc->port_mode_cfg = BFA_MODE_NIC;
2168 ioc->ad_cap_bm = BFA_CM_NIC;
2169 }
Krishna Gudipati11189202011-06-13 15:50:35 -07002170 }
2171 break;
2172
2173 default:
2174 WARN_ON(1);
2175 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002176
Jing Huang5fbe25c2010-10-18 17:17:23 -07002177 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002178 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2179 */
Krishna Gudipati11189202011-06-13 15:50:35 -07002180 if (ioc->asic_gen == BFI_ASIC_GEN_CB)
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002181 bfa_ioc_set_cb_hwif(ioc);
Krishna Gudipati11189202011-06-13 15:50:35 -07002182 else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
2183 bfa_ioc_set_ct_hwif(ioc);
2184 else {
2185 WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
2186 bfa_ioc_set_ct2_hwif(ioc);
2187 bfa_ioc_ct2_poweron(ioc);
2188 }
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002189
Jing Huang7725ccf2009-09-23 17:46:15 -07002190 bfa_ioc_map_port(ioc);
2191 bfa_ioc_reg_init(ioc);
2192}
2193
Jing Huang5fbe25c2010-10-18 17:17:23 -07002194/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002195 * Initialize IOC dma memory
2196 *
2197 * @param[in] dm_kva kernel virtual address of IOC dma memory
2198 * @param[in] dm_pa physical address of IOC dma memory
2199 */
2200void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002201bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002202{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002203 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002204 * dma memory for firmware attribute
2205 */
2206 ioc->attr_dma.kva = dm_kva;
2207 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002208 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002209}
2210
Jing Huang7725ccf2009-09-23 17:46:15 -07002211void
2212bfa_ioc_enable(struct bfa_ioc_s *ioc)
2213{
2214 bfa_ioc_stats(ioc, ioc_enables);
2215 ioc->dbg_fwsave_once = BFA_TRUE;
2216
2217 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2218}
2219
2220void
2221bfa_ioc_disable(struct bfa_ioc_s *ioc)
2222{
2223 bfa_ioc_stats(ioc, ioc_disables);
2224 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2225}
2226
Jing Huang7725ccf2009-09-23 17:46:15 -07002227
Jing Huang5fbe25c2010-10-18 17:17:23 -07002228/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002229 * Initialize memory for saving firmware trace. Driver must initialize
2230 * trace memory before call bfa_ioc_enable().
2231 */
2232void
2233bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2234{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002235 ioc->dbg_fwsave = dbg_fwsave;
Maggie Zhangf7f73812010-12-09 19:08:43 -08002236 ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07002237}
2238
Jing Huang5fbe25c2010-10-18 17:17:23 -07002239/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002240 * Register mailbox message handler functions
2241 *
2242 * @param[in] ioc IOC instance
2243 * @param[in] mcfuncs message class handler functions
2244 */
2245void
2246bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2247{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002248 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2249 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002250
2251 for (mc = 0; mc < BFI_MC_MAX; mc++)
2252 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2253}
2254
Jing Huang5fbe25c2010-10-18 17:17:23 -07002255/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002256 * Register mailbox message handler function, to be called by common modules
2257 */
2258void
2259bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2260 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2261{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002262 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002263
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002264 mod->mbhdlr[mc].cbfn = cbfn;
2265 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002266}
2267
Jing Huang5fbe25c2010-10-18 17:17:23 -07002268/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002269 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2270 * Responsibility of caller to serialize
2271 *
2272 * @param[in] ioc IOC instance
2273 * @param[i] cmd Mailbox command
2274 */
2275void
2276bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2277{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002278 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2279 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002280
Jing Huang5fbe25c2010-10-18 17:17:23 -07002281 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002282 * If a previous command is pending, queue new command
2283 */
2284 if (!list_empty(&mod->cmd_q)) {
2285 list_add_tail(&cmd->qe, &mod->cmd_q);
2286 return;
2287 }
2288
Jing Huang5fbe25c2010-10-18 17:17:23 -07002289 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002290 * If mailbox is busy, queue command for poll timer
2291 */
Jing Huang53440262010-10-18 17:12:29 -07002292 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002293 if (stat) {
2294 list_add_tail(&cmd->qe, &mod->cmd_q);
2295 return;
2296 }
2297
Jing Huang5fbe25c2010-10-18 17:17:23 -07002298 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002299 * mailbox is free -- queue command to firmware
2300 */
2301 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2302}
2303
Jing Huang5fbe25c2010-10-18 17:17:23 -07002304/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002305 * Handle mailbox interrupts
2306 */
2307void
2308bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2309{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002310 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2311 struct bfi_mbmsg_s m;
2312 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002313
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002314 if (bfa_ioc_msgget(ioc, &m)) {
2315 /*
2316 * Treat IOC message class as special.
2317 */
2318 mc = m.mh.msg_class;
2319 if (mc == BFI_MC_IOC) {
2320 bfa_ioc_isr(ioc, &m);
2321 return;
2322 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002323
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002324 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2325 return;
2326
2327 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
Jing Huang7725ccf2009-09-23 17:46:15 -07002328 }
2329
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002330 bfa_ioc_lpu_read_stat(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002331
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002332 /*
2333 * Try to send pending mailbox commands
2334 */
2335 bfa_ioc_mbox_poll(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002336}
2337
2338void
2339bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2340{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002341 bfa_ioc_stats(ioc, ioc_hbfails);
2342 ioc->stats.hb_count = ioc->hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07002343 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2344}
2345
Jing Huanged969322010-07-08 19:45:56 -07002346void
2347bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2348{
2349 ioc->fcmode = BFA_TRUE;
Jing Huanged969322010-07-08 19:45:56 -07002350}
2351
Jing Huang5fbe25c2010-10-18 17:17:23 -07002352/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002353 * return true if IOC is disabled
2354 */
2355bfa_boolean_t
2356bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2357{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002358 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2359 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002360}
2361
Jing Huang5fbe25c2010-10-18 17:17:23 -07002362/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002363 * return true if IOC firmware is different.
2364 */
2365bfa_boolean_t
2366bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2367{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002368 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2369 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2370 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002371}
2372
2373#define bfa_ioc_state_disabled(__sm) \
2374 (((__sm) == BFI_IOC_UNINIT) || \
2375 ((__sm) == BFI_IOC_INITING) || \
2376 ((__sm) == BFI_IOC_HWINIT) || \
2377 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002378 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002379 ((__sm) == BFI_IOC_CFG_DISABLED))
2380
Jing Huang5fbe25c2010-10-18 17:17:23 -07002381/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002382 * Check if adapter is disabled -- both IOCs should be in a disabled
2383 * state.
2384 */
2385bfa_boolean_t
2386bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2387{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002388 u32 ioc_state;
Jing Huang7725ccf2009-09-23 17:46:15 -07002389
2390 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2391 return BFA_FALSE;
2392
Krishna Gudipati11189202011-06-13 15:50:35 -07002393 ioc_state = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07002394 if (!bfa_ioc_state_disabled(ioc_state))
2395 return BFA_FALSE;
2396
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002397 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002398 ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002399 if (!bfa_ioc_state_disabled(ioc_state))
2400 return BFA_FALSE;
2401 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002402
2403 return BFA_TRUE;
2404}
2405
Jing Huang8f4bfad2010-12-26 21:50:10 -08002406/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002407 * Reset IOC fwstate registers.
2408 */
2409void
2410bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2411{
2412 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2413 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2414}
2415
Jing Huang7725ccf2009-09-23 17:46:15 -07002416#define BFA_MFG_NAME "Brocade"
2417void
2418bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2419 struct bfa_adapter_attr_s *ad_attr)
2420{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002421 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002422
2423 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002424
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002425 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2426 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2427 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2428 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002429 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002430 sizeof(struct bfa_mfg_vpd_s));
2431
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002432 ad_attr->nports = bfa_ioc_get_nports(ioc);
2433 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002434
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002435 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2436 /* For now, model descr uses same model string */
2437 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002438
Jing Huanged969322010-07-08 19:45:56 -07002439 ad_attr->card_type = ioc_attr->card_type;
2440 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2441
Jing Huang7725ccf2009-09-23 17:46:15 -07002442 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2443 ad_attr->prototype = 1;
2444 else
2445 ad_attr->prototype = 0;
2446
Maggie Zhangf7f73812010-12-09 19:08:43 -08002447 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002448 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002449
2450 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2451 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2452 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2453 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002454
2455 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002456
Krishna Gudipati11189202011-06-13 15:50:35 -07002457 ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
2458 ad_attr->trunk_capable = (ad_attr->nports > 1) &&
2459 !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
Jing Huang7725ccf2009-09-23 17:46:15 -07002460}
2461
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002462enum bfa_ioc_type_e
2463bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2464{
Krishna Gudipati11189202011-06-13 15:50:35 -07002465 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002466 return BFA_IOC_TYPE_LL;
Krishna Gudipati11189202011-06-13 15:50:35 -07002467
2468 WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
2469
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002470 return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
Krishna Gudipati11189202011-06-13 15:50:35 -07002471 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002472}
2473
Jing Huang7725ccf2009-09-23 17:46:15 -07002474void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002475bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2476{
Jing Huang6a18b162010-10-18 17:08:54 -07002477 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2478 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002479 (void *)ioc->attr->brcd_serialnum,
2480 BFA_ADAPTER_SERIAL_NUM_LEN);
2481}
2482
2483void
2484bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2485{
Jing Huang6a18b162010-10-18 17:08:54 -07002486 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2487 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002488}
2489
2490void
2491bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2492{
Jing Huangd4b671c2010-12-26 21:46:35 -08002493 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002494
Jing Huang6a18b162010-10-18 17:08:54 -07002495 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002496
2497 chip_rev[0] = 'R';
2498 chip_rev[1] = 'e';
2499 chip_rev[2] = 'v';
2500 chip_rev[3] = '-';
2501 chip_rev[4] = ioc->attr->asic_rev;
2502 chip_rev[5] = '\0';
2503}
2504
2505void
2506bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2507{
Jing Huang6a18b162010-10-18 17:08:54 -07002508 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2509 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002510 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002511}
2512
2513void
2514bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2515{
Jing Huang6a18b162010-10-18 17:08:54 -07002516 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2517 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002518}
2519
2520void
2521bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2522{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002523 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002524
Jing Huangd4b671c2010-12-26 21:46:35 -08002525 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002526 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002527
2528 ioc_attr = ioc->attr;
2529
Jing Huang5fbe25c2010-10-18 17:17:23 -07002530 /*
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002531 * model name
2532 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002533 if (ioc->asic_gen == BFI_ASIC_GEN_CT2) {
2534 int np = bfa_ioc_get_nports(ioc);
2535 char c;
2536 switch (ioc_attr->card_type) {
2537 case BFA_MFG_TYPE_PROWLER_F:
2538 case BFA_MFG_TYPE_PROWLER_N:
2539 case BFA_MFG_TYPE_PROWLER_C:
2540 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN,
2541 "%s-%u-%u",
2542 BFA_MFG_NAME, ioc_attr->card_type, np);
2543 break;
2544 case BFA_MFG_TYPE_PROWLER_D:
2545 if (ioc_attr->ic == BFA_MFG_IC_FC)
2546 c = 'F';
2547 else
2548 c = 'P';
2549
2550 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN,
2551 "%s-%u-%u%c",
2552 BFA_MFG_NAME, ioc_attr->card_type, np, c);
2553 break;
2554 default:
2555 break;
2556 }
2557 } else
2558 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2559 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002560}
2561
2562enum bfa_ioc_state
2563bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2564{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002565 enum bfa_iocpf_state iocpf_st;
2566 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2567
2568 if (ioc_st == BFA_IOC_ENABLING ||
2569 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2570
2571 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2572
2573 switch (iocpf_st) {
2574 case BFA_IOCPF_SEMWAIT:
2575 ioc_st = BFA_IOC_SEMWAIT;
2576 break;
2577
2578 case BFA_IOCPF_HWINIT:
2579 ioc_st = BFA_IOC_HWINIT;
2580 break;
2581
2582 case BFA_IOCPF_FWMISMATCH:
2583 ioc_st = BFA_IOC_FWMISMATCH;
2584 break;
2585
2586 case BFA_IOCPF_FAIL:
2587 ioc_st = BFA_IOC_FAIL;
2588 break;
2589
2590 case BFA_IOCPF_INITFAIL:
2591 ioc_st = BFA_IOC_INITFAIL;
2592 break;
2593
2594 default:
2595 break;
2596 }
2597 }
2598
2599 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002600}
2601
2602void
Jing Huang7725ccf2009-09-23 17:46:15 -07002603bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2604{
Jing Huang6a18b162010-10-18 17:08:54 -07002605 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002606
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002607 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002608 ioc_attr->port_id = ioc->port_id;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002609 ioc_attr->port_mode = ioc->port_mode;
2610 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2611 ioc_attr->cap_bm = ioc->ad_cap_bm;
Jing Huang7725ccf2009-09-23 17:46:15 -07002612
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002613 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002614
2615 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2616
2617 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2618 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002619 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002620}
2621
Jing Huang7725ccf2009-09-23 17:46:15 -07002622mac_t
2623bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2624{
Jing Huang15b64a82010-07-08 19:48:12 -07002625 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002626 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002627 */
2628 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002629 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002630 else
2631 return ioc->attr->mac;
2632}
2633
Jing Huang15b64a82010-07-08 19:48:12 -07002634mac_t
2635bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2636{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002637 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002638
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002639 m = ioc->attr->mfg_mac;
2640 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2641 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2642 else
2643 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2644 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002645
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002646 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002647}
2648
Jing Huang7725ccf2009-09-23 17:46:15 -07002649bfa_boolean_t
2650bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2651{
Krishna Gudipati11189202011-06-13 15:50:35 -07002652 return ioc->fcmode || bfa_asic_id_cb(ioc->pcidev.device_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07002653}
2654
Jing Huang5fbe25c2010-10-18 17:17:23 -07002655/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002656 * Retrieve saved firmware trace from a prior IOC failure.
2657 */
2658bfa_status_t
2659bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2660{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002661 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002662
2663 if (ioc->dbg_fwsave_len == 0)
2664 return BFA_STATUS_ENOFSAVE;
2665
2666 tlen = *trclen;
2667 if (tlen > ioc->dbg_fwsave_len)
2668 tlen = ioc->dbg_fwsave_len;
2669
Jing Huang6a18b162010-10-18 17:08:54 -07002670 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002671 *trclen = tlen;
2672 return BFA_STATUS_OK;
2673}
2674
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002675
Jing Huang5fbe25c2010-10-18 17:17:23 -07002676/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002677 * Retrieve saved firmware trace from a prior IOC failure.
2678 */
2679bfa_status_t
2680bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2681{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002682 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2683 int tlen;
2684 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002685
2686 bfa_trc(ioc, *trclen);
2687
Jing Huang7725ccf2009-09-23 17:46:15 -07002688 tlen = *trclen;
2689 if (tlen > BFA_DBG_FWTRC_LEN)
2690 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002691
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002692 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2693 *trclen = tlen;
2694 return status;
2695}
Jing Huang7725ccf2009-09-23 17:46:15 -07002696
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002697static void
2698bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2699{
2700 struct bfa_mbox_cmd_s cmd;
2701 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002702
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002703 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2704 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002705 req->clscode = cpu_to_be16(ioc->clscode);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002706 bfa_ioc_mbox_queue(ioc, &cmd);
2707}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002708
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002709static void
2710bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2711{
2712 u32 fwsync_iter = 1000;
2713
2714 bfa_ioc_send_fwsync(ioc);
2715
Jing Huang5fbe25c2010-10-18 17:17:23 -07002716 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002717 * After sending a fw sync mbox command wait for it to
2718 * take effect. We will not wait for a response because
2719 * 1. fw_sync mbox cmd doesn't have a response.
2720 * 2. Even if we implement that, interrupts might not
2721 * be enabled when we call this function.
2722 * So, just keep checking if any mbox cmd is pending, and
2723 * after waiting for a reasonable amount of time, go ahead.
2724 * It is possible that fw has crashed and the mbox command
2725 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002726 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002727 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2728 fwsync_iter--;
2729}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002730
Jing Huang5fbe25c2010-10-18 17:17:23 -07002731/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002732 * Dump firmware smem
2733 */
2734bfa_status_t
2735bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2736 u32 *offset, int *buflen)
2737{
2738 u32 loff;
2739 int dlen;
2740 bfa_status_t status;
2741 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002742
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002743 if (*offset >= smem_len) {
2744 *offset = *buflen = 0;
2745 return BFA_STATUS_EINVAL;
2746 }
2747
2748 loff = *offset;
2749 dlen = *buflen;
2750
Jing Huang5fbe25c2010-10-18 17:17:23 -07002751 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002752 * First smem read, sync smem before proceeding
2753 * No need to sync before reading every chunk.
2754 */
2755 if (loff == 0)
2756 bfa_ioc_fwsync(ioc);
2757
2758 if ((loff + dlen) >= smem_len)
2759 dlen = smem_len - loff;
2760
2761 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2762
2763 if (status != BFA_STATUS_OK) {
2764 *offset = *buflen = 0;
2765 return status;
2766 }
2767
2768 *offset += dlen;
2769
2770 if (*offset >= smem_len)
2771 *offset = 0;
2772
2773 *buflen = dlen;
2774
2775 return status;
2776}
2777
Jing Huang5fbe25c2010-10-18 17:17:23 -07002778/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002779 * Firmware statistics
2780 */
2781bfa_status_t
2782bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2783{
2784 u32 loff = BFI_IOC_FWSTATS_OFF + \
2785 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2786 int tlen;
2787 bfa_status_t status;
2788
2789 if (ioc->stats_busy) {
2790 bfa_trc(ioc, ioc->stats_busy);
2791 return BFA_STATUS_DEVBUSY;
2792 }
2793 ioc->stats_busy = BFA_TRUE;
2794
2795 tlen = sizeof(struct bfa_fw_stats_s);
2796 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2797
2798 ioc->stats_busy = BFA_FALSE;
2799 return status;
2800}
2801
2802bfa_status_t
2803bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2804{
2805 u32 loff = BFI_IOC_FWSTATS_OFF + \
2806 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2807 int tlen;
2808 bfa_status_t status;
2809
2810 if (ioc->stats_busy) {
2811 bfa_trc(ioc, ioc->stats_busy);
2812 return BFA_STATUS_DEVBUSY;
2813 }
2814 ioc->stats_busy = BFA_TRUE;
2815
2816 tlen = sizeof(struct bfa_fw_stats_s);
2817 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2818
2819 ioc->stats_busy = BFA_FALSE;
2820 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002821}
2822
Jing Huang5fbe25c2010-10-18 17:17:23 -07002823/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002824 * Save firmware trace if configured.
2825 */
2826static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002827bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002828{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002829 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002830
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002831 if (ioc->dbg_fwsave_once) {
2832 ioc->dbg_fwsave_once = BFA_FALSE;
2833 if (ioc->dbg_fwsave_len) {
2834 tlen = ioc->dbg_fwsave_len;
2835 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2836 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002837 }
2838}
2839
Jing Huang5fbe25c2010-10-18 17:17:23 -07002840/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002841 * Firmware failure detected. Start recovery actions.
2842 */
2843static void
2844bfa_ioc_recover(struct bfa_ioc_s *ioc)
2845{
Jing Huang7725ccf2009-09-23 17:46:15 -07002846 bfa_ioc_stats(ioc, ioc_hbfails);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002847 ioc->stats.hb_count = ioc->hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07002848 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2849}
2850
Jing Huang7725ccf2009-09-23 17:46:15 -07002851static void
Jing Huang07b28382010-07-08 19:59:24 -07002852bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002853{
Jing Huang07b28382010-07-08 19:59:24 -07002854 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2855 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002856}
2857
Jing Huang5fbe25c2010-10-18 17:17:23 -07002858/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002859 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002860 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002861static void
2862bfa_iocpf_timeout(void *ioc_arg)
2863{
2864 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2865
2866 bfa_trc(ioc, 0);
2867 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2868}
2869
2870static void
2871bfa_iocpf_sem_timeout(void *ioc_arg)
2872{
2873 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2874
2875 bfa_ioc_hw_sem_get(ioc);
2876}
2877
Krishna Gudipati775c7742011-06-13 15:52:12 -07002878static void
2879bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
2880{
2881 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
2882
2883 bfa_trc(ioc, fwstate);
2884
2885 if (fwstate == BFI_IOC_DISABLED) {
2886 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2887 return;
2888 }
2889
2890 if (ioc->iocpf.poll_time >= BFA_IOC_TOV)
2891 bfa_iocpf_timeout(ioc);
2892 else {
2893 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2894 bfa_iocpf_poll_timer_start(ioc);
2895 }
2896}
2897
2898static void
2899bfa_iocpf_poll_timeout(void *ioc_arg)
2900{
2901 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2902
2903 bfa_ioc_poll_fwinit(ioc);
2904}
2905
Jing Huang5fbe25c2010-10-18 17:17:23 -07002906/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002907 * bfa timer function
2908 */
2909void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002910bfa_timer_beat(struct bfa_timer_mod_s *mod)
2911{
2912 struct list_head *qh = &mod->timer_q;
2913 struct list_head *qe, *qe_next;
2914 struct bfa_timer_s *elem;
2915 struct list_head timedout_q;
2916
2917 INIT_LIST_HEAD(&timedout_q);
2918
2919 qe = bfa_q_next(qh);
2920
2921 while (qe != qh) {
2922 qe_next = bfa_q_next(qe);
2923
2924 elem = (struct bfa_timer_s *) qe;
2925 if (elem->timeout <= BFA_TIMER_FREQ) {
2926 elem->timeout = 0;
2927 list_del(&elem->qe);
2928 list_add_tail(&elem->qe, &timedout_q);
2929 } else {
2930 elem->timeout -= BFA_TIMER_FREQ;
2931 }
2932
2933 qe = qe_next; /* go to next elem */
2934 }
2935
2936 /*
2937 * Pop all the timeout entries
2938 */
2939 while (!list_empty(&timedout_q)) {
2940 bfa_q_deq(&timedout_q, &elem);
2941 elem->timercb(elem->arg);
2942 }
2943}
2944
Jing Huang5fbe25c2010-10-18 17:17:23 -07002945/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002946 * Should be called with lock protection
2947 */
2948void
2949bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2950 void (*timercb) (void *), void *arg, unsigned int timeout)
2951{
2952
Jing Huangd4b671c2010-12-26 21:46:35 -08002953 WARN_ON(timercb == NULL);
2954 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002955
2956 timer->timeout = timeout;
2957 timer->timercb = timercb;
2958 timer->arg = arg;
2959
2960 list_add_tail(&timer->qe, &mod->timer_q);
2961}
2962
Jing Huang5fbe25c2010-10-18 17:17:23 -07002963/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002964 * Should be called with lock protection
2965 */
2966void
2967bfa_timer_stop(struct bfa_timer_s *timer)
2968{
Jing Huangd4b671c2010-12-26 21:46:35 -08002969 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002970
2971 list_del(&timer->qe);
2972}
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002973
2974/*
2975 * ASIC block related
2976 */
2977static void
2978bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
2979{
2980 struct bfa_ablk_cfg_inst_s *cfg_inst;
2981 int i, j;
2982 u16 be16;
2983 u32 be32;
2984
2985 for (i = 0; i < BFA_ABLK_MAX; i++) {
2986 cfg_inst = &cfg->inst[i];
2987 for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
2988 be16 = cfg_inst->pf_cfg[j].pers;
2989 cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
2990 be16 = cfg_inst->pf_cfg[j].num_qpairs;
2991 cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
2992 be16 = cfg_inst->pf_cfg[j].num_vectors;
2993 cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
2994 be32 = cfg_inst->pf_cfg[j].bw;
2995 cfg_inst->pf_cfg[j].bw = be16_to_cpu(be32);
2996 }
2997 }
2998}
2999
3000static void
3001bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
3002{
3003 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3004 struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
3005 bfa_ablk_cbfn_t cbfn;
3006
3007 WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
3008 bfa_trc(ablk->ioc, msg->mh.msg_id);
3009
3010 switch (msg->mh.msg_id) {
3011 case BFI_ABLK_I2H_QUERY:
3012 if (rsp->status == BFA_STATUS_OK) {
3013 memcpy(ablk->cfg, ablk->dma_addr.kva,
3014 sizeof(struct bfa_ablk_cfg_s));
3015 bfa_ablk_config_swap(ablk->cfg);
3016 ablk->cfg = NULL;
3017 }
3018 break;
3019
3020 case BFI_ABLK_I2H_ADPT_CONFIG:
3021 case BFI_ABLK_I2H_PORT_CONFIG:
3022 /* update config port mode */
3023 ablk->ioc->port_mode_cfg = rsp->port_mode;
3024
3025 case BFI_ABLK_I2H_PF_DELETE:
3026 case BFI_ABLK_I2H_PF_UPDATE:
3027 case BFI_ABLK_I2H_OPTROM_ENABLE:
3028 case BFI_ABLK_I2H_OPTROM_DISABLE:
3029 /* No-op */
3030 break;
3031
3032 case BFI_ABLK_I2H_PF_CREATE:
3033 *(ablk->pcifn) = rsp->pcifn;
3034 ablk->pcifn = NULL;
3035 break;
3036
3037 default:
3038 WARN_ON(1);
3039 }
3040
3041 ablk->busy = BFA_FALSE;
3042 if (ablk->cbfn) {
3043 cbfn = ablk->cbfn;
3044 ablk->cbfn = NULL;
3045 cbfn(ablk->cbarg, rsp->status);
3046 }
3047}
3048
3049static void
3050bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
3051{
3052 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3053
3054 bfa_trc(ablk->ioc, event);
3055
3056 switch (event) {
3057 case BFA_IOC_E_ENABLED:
3058 WARN_ON(ablk->busy != BFA_FALSE);
3059 break;
3060
3061 case BFA_IOC_E_DISABLED:
3062 case BFA_IOC_E_FAILED:
3063 /* Fail any pending requests */
3064 ablk->pcifn = NULL;
3065 if (ablk->busy) {
3066 if (ablk->cbfn)
3067 ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
3068 ablk->cbfn = NULL;
3069 ablk->busy = BFA_FALSE;
3070 }
3071 break;
3072
3073 default:
3074 WARN_ON(1);
3075 break;
3076 }
3077}
3078
3079u32
3080bfa_ablk_meminfo(void)
3081{
3082 return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
3083}
3084
3085void
3086bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
3087{
3088 ablk->dma_addr.kva = dma_kva;
3089 ablk->dma_addr.pa = dma_pa;
3090}
3091
3092void
3093bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
3094{
3095 ablk->ioc = ioc;
3096
3097 bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
3098 bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
3099 list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
3100}
3101
3102bfa_status_t
3103bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
3104 bfa_ablk_cbfn_t cbfn, void *cbarg)
3105{
3106 struct bfi_ablk_h2i_query_s *m;
3107
3108 WARN_ON(!ablk_cfg);
3109
3110 if (!bfa_ioc_is_operational(ablk->ioc)) {
3111 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3112 return BFA_STATUS_IOC_FAILURE;
3113 }
3114
3115 if (ablk->busy) {
3116 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3117 return BFA_STATUS_DEVBUSY;
3118 }
3119
3120 ablk->cfg = ablk_cfg;
3121 ablk->cbfn = cbfn;
3122 ablk->cbarg = cbarg;
3123 ablk->busy = BFA_TRUE;
3124
3125 m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
3126 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
3127 bfa_ioc_portid(ablk->ioc));
3128 bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
3129 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3130
3131 return BFA_STATUS_OK;
3132}
3133
3134bfa_status_t
3135bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
3136 u8 port, enum bfi_pcifn_class personality, int bw,
3137 bfa_ablk_cbfn_t cbfn, void *cbarg)
3138{
3139 struct bfi_ablk_h2i_pf_req_s *m;
3140
3141 if (!bfa_ioc_is_operational(ablk->ioc)) {
3142 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3143 return BFA_STATUS_IOC_FAILURE;
3144 }
3145
3146 if (ablk->busy) {
3147 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3148 return BFA_STATUS_DEVBUSY;
3149 }
3150
3151 ablk->pcifn = pcifn;
3152 ablk->cbfn = cbfn;
3153 ablk->cbarg = cbarg;
3154 ablk->busy = BFA_TRUE;
3155
3156 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3157 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
3158 bfa_ioc_portid(ablk->ioc));
3159 m->pers = cpu_to_be16((u16)personality);
3160 m->bw = cpu_to_be32(bw);
3161 m->port = port;
3162 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3163
3164 return BFA_STATUS_OK;
3165}
3166
3167bfa_status_t
3168bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
3169 bfa_ablk_cbfn_t cbfn, void *cbarg)
3170{
3171 struct bfi_ablk_h2i_pf_req_s *m;
3172
3173 if (!bfa_ioc_is_operational(ablk->ioc)) {
3174 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3175 return BFA_STATUS_IOC_FAILURE;
3176 }
3177
3178 if (ablk->busy) {
3179 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3180 return BFA_STATUS_DEVBUSY;
3181 }
3182
3183 ablk->cbfn = cbfn;
3184 ablk->cbarg = cbarg;
3185 ablk->busy = BFA_TRUE;
3186
3187 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3188 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
3189 bfa_ioc_portid(ablk->ioc));
3190 m->pcifn = (u8)pcifn;
3191 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3192
3193 return BFA_STATUS_OK;
3194}
3195
3196bfa_status_t
3197bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
3198 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3199{
3200 struct bfi_ablk_h2i_cfg_req_s *m;
3201
3202 if (!bfa_ioc_is_operational(ablk->ioc)) {
3203 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3204 return BFA_STATUS_IOC_FAILURE;
3205 }
3206
3207 if (ablk->busy) {
3208 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3209 return BFA_STATUS_DEVBUSY;
3210 }
3211
3212 ablk->cbfn = cbfn;
3213 ablk->cbarg = cbarg;
3214 ablk->busy = BFA_TRUE;
3215
3216 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3217 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
3218 bfa_ioc_portid(ablk->ioc));
3219 m->mode = (u8)mode;
3220 m->max_pf = (u8)max_pf;
3221 m->max_vf = (u8)max_vf;
3222 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3223
3224 return BFA_STATUS_OK;
3225}
3226
3227bfa_status_t
3228bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
3229 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3230{
3231 struct bfi_ablk_h2i_cfg_req_s *m;
3232
3233 if (!bfa_ioc_is_operational(ablk->ioc)) {
3234 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3235 return BFA_STATUS_IOC_FAILURE;
3236 }
3237
3238 if (ablk->busy) {
3239 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3240 return BFA_STATUS_DEVBUSY;
3241 }
3242
3243 ablk->cbfn = cbfn;
3244 ablk->cbarg = cbarg;
3245 ablk->busy = BFA_TRUE;
3246
3247 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3248 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
3249 bfa_ioc_portid(ablk->ioc));
3250 m->port = (u8)port;
3251 m->mode = (u8)mode;
3252 m->max_pf = (u8)max_pf;
3253 m->max_vf = (u8)max_vf;
3254 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3255
3256 return BFA_STATUS_OK;
3257}
3258
3259bfa_status_t
3260bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw,
3261 bfa_ablk_cbfn_t cbfn, void *cbarg)
3262{
3263 struct bfi_ablk_h2i_pf_req_s *m;
3264
3265 if (!bfa_ioc_is_operational(ablk->ioc)) {
3266 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3267 return BFA_STATUS_IOC_FAILURE;
3268 }
3269
3270 if (ablk->busy) {
3271 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3272 return BFA_STATUS_DEVBUSY;
3273 }
3274
3275 ablk->cbfn = cbfn;
3276 ablk->cbarg = cbarg;
3277 ablk->busy = BFA_TRUE;
3278
3279 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3280 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
3281 bfa_ioc_portid(ablk->ioc));
3282 m->pcifn = (u8)pcifn;
3283 m->bw = cpu_to_be32(bw);
3284 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3285
3286 return BFA_STATUS_OK;
3287}
3288
3289bfa_status_t
3290bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3291{
3292 struct bfi_ablk_h2i_optrom_s *m;
3293
3294 if (!bfa_ioc_is_operational(ablk->ioc)) {
3295 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3296 return BFA_STATUS_IOC_FAILURE;
3297 }
3298
3299 if (ablk->busy) {
3300 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3301 return BFA_STATUS_DEVBUSY;
3302 }
3303
3304 ablk->cbfn = cbfn;
3305 ablk->cbarg = cbarg;
3306 ablk->busy = BFA_TRUE;
3307
3308 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3309 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
3310 bfa_ioc_portid(ablk->ioc));
3311 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3312
3313 return BFA_STATUS_OK;
3314}
3315
3316bfa_status_t
3317bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3318{
3319 struct bfi_ablk_h2i_optrom_s *m;
3320
3321 if (!bfa_ioc_is_operational(ablk->ioc)) {
3322 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3323 return BFA_STATUS_IOC_FAILURE;
3324 }
3325
3326 if (ablk->busy) {
3327 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3328 return BFA_STATUS_DEVBUSY;
3329 }
3330
3331 ablk->cbfn = cbfn;
3332 ablk->cbarg = cbarg;
3333 ablk->busy = BFA_TRUE;
3334
3335 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3336 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
3337 bfa_ioc_portid(ablk->ioc));
3338 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3339
3340 return BFA_STATUS_OK;
3341}