blob: e02d6071a9c43280236bcb8d381a44eeaa1d126a [file] [log] [blame]
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001/*
2 * Linux network driver for Brocade Converged Network Adapter.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License (GPL) Version 2 as
6 * published by the Free Software Foundation
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13/*
14 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
15 * All rights reserved
16 * www.brocade.com
17 */
18
19#include "bfa_ioc.h"
Rasesh Modya9602492011-08-02 12:36:06 +000020#include "bfi_reg.h"
Rasesh Mody8b230ed2010-08-23 20:24:12 -070021#include "bfa_defs.h"
22
23/**
24 * IOC local definitions
25 */
26
Rasesh Mody8b230ed2010-08-23 20:24:12 -070027/**
28 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
29 */
30
31#define bfa_ioc_firmware_lock(__ioc) \
32 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
33#define bfa_ioc_firmware_unlock(__ioc) \
34 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
35#define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
36#define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
Rasesh Mody1d32f762010-12-23 21:45:09 +000037#define bfa_ioc_notify_fail(__ioc) \
38 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
Rasesh Mody79ea6c82011-04-14 08:05:18 +000039#define bfa_ioc_sync_start(__ioc) \
40 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
Rasesh Mody1d32f762010-12-23 21:45:09 +000041#define bfa_ioc_sync_join(__ioc) \
42 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
43#define bfa_ioc_sync_leave(__ioc) \
44 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
45#define bfa_ioc_sync_ack(__ioc) \
46 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
47#define bfa_ioc_sync_complete(__ioc) \
48 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
Rasesh Mody8b230ed2010-08-23 20:24:12 -070049
Rasesh Mody8b230ed2010-08-23 20:24:12 -070050#define bfa_ioc_mbox_cmd_pending(__ioc) \
51 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
52 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
53
Rasesh Modyb7ee31c52010-10-05 15:46:05 +000054static bool bfa_nw_auto_recover = true;
Rasesh Mody8b230ed2010-08-23 20:24:12 -070055
56/*
57 * forward declarations
58 */
Rasesh Modyd4e16d42011-07-22 08:07:47 +000059static void bfa_ioc_hw_sem_init(struct bfa_ioc *ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070060static void bfa_ioc_hw_sem_get(struct bfa_ioc *ioc);
61static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc);
62static void bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force);
Rasesh Mody078086f2011-08-08 16:21:39 +000063static void bfa_ioc_poll_fwinit(struct bfa_ioc *ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070064static void bfa_ioc_send_enable(struct bfa_ioc *ioc);
65static void bfa_ioc_send_disable(struct bfa_ioc *ioc);
66static void bfa_ioc_send_getattr(struct bfa_ioc *ioc);
67static void bfa_ioc_hb_monitor(struct bfa_ioc *ioc);
68static void bfa_ioc_hb_stop(struct bfa_ioc *ioc);
69static void bfa_ioc_reset(struct bfa_ioc *ioc, bool force);
70static void bfa_ioc_mbox_poll(struct bfa_ioc *ioc);
Rasesh Modyfdad4002011-07-22 08:07:45 +000071static void bfa_ioc_mbox_flush(struct bfa_ioc *ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070072static void bfa_ioc_recover(struct bfa_ioc *ioc);
73static void bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc);
Rasesh Modybd5a92e2011-07-22 08:07:42 +000074static void bfa_ioc_event_notify(struct bfa_ioc *, enum bfa_ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070075static void bfa_ioc_disable_comp(struct bfa_ioc *ioc);
76static void bfa_ioc_lpu_stop(struct bfa_ioc *ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +000077static void bfa_ioc_fail_notify(struct bfa_ioc *ioc);
78static void bfa_ioc_pf_enabled(struct bfa_ioc *ioc);
79static void bfa_ioc_pf_disabled(struct bfa_ioc *ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +000080static void bfa_ioc_pf_failed(struct bfa_ioc *ioc);
Rasesh Mody078086f2011-08-08 16:21:39 +000081static void bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +000082static void bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc);
Rasesh Mody8a891422010-08-25 23:00:27 -070083static void bfa_ioc_boot(struct bfa_ioc *ioc, u32 boot_type,
84 u32 boot_param);
85static u32 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr);
Rasesh Mody8a891422010-08-25 23:00:27 -070086static void bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc,
87 char *serial_num);
88static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc,
89 char *fw_ver);
90static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc,
91 char *chip_rev);
92static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc,
93 char *optrom_ver);
94static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc,
95 char *manufacturer);
96static void bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model);
97static u64 bfa_ioc_get_pwwn(struct bfa_ioc *ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070098
99/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000100 * IOC state machine definitions/declarations
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700101 */
102enum ioc_event {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000103 IOC_E_RESET = 1, /*!< IOC reset request */
104 IOC_E_ENABLE = 2, /*!< IOC enable request */
105 IOC_E_DISABLE = 3, /*!< IOC disable request */
106 IOC_E_DETACH = 4, /*!< driver detach cleanup */
107 IOC_E_ENABLED = 5, /*!< f/w enabled */
108 IOC_E_FWRSP_GETATTR = 6, /*!< IOC get attribute response */
109 IOC_E_DISABLED = 7, /*!< f/w disabled */
Rasesh Mody078086f2011-08-08 16:21:39 +0000110 IOC_E_PFFAILED = 8, /*!< failure notice by iocpf sm */
111 IOC_E_HBFAIL = 9, /*!< heartbeat failure */
112 IOC_E_HWERROR = 10, /*!< hardware error interrupt */
113 IOC_E_TIMEOUT = 11, /*!< timeout */
114 IOC_E_HWFAILED = 12, /*!< PCI mapping failure notice */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700115};
116
Rasesh Mody1d32f762010-12-23 21:45:09 +0000117bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc, enum ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700118bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc, enum ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700119bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc, enum ioc_event);
120bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc, enum ioc_event);
121bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc, enum ioc_event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000122bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc, enum ioc_event);
123bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc, enum ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700124bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc, enum ioc_event);
125bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc, enum ioc_event);
Rasesh Mody078086f2011-08-08 16:21:39 +0000126bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc, enum ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700127
128static struct bfa_sm_table ioc_sm_table[] = {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000129 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700130 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Rasesh Mody1d32f762010-12-23 21:45:09 +0000131 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700132 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
133 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
Rasesh Mody1d32f762010-12-23 21:45:09 +0000134 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
135 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700136 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
137 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
Rasesh Mody078086f2011-08-08 16:21:39 +0000138 {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700139};
140
Rasesh Mody1d32f762010-12-23 21:45:09 +0000141/*
142 * Forward declareations for iocpf state machine
143 */
144static void bfa_iocpf_enable(struct bfa_ioc *ioc);
145static void bfa_iocpf_disable(struct bfa_ioc *ioc);
146static void bfa_iocpf_fail(struct bfa_ioc *ioc);
147static void bfa_iocpf_initfail(struct bfa_ioc *ioc);
148static void bfa_iocpf_getattrfail(struct bfa_ioc *ioc);
149static void bfa_iocpf_stop(struct bfa_ioc *ioc);
150
151/**
152 * IOCPF state machine events
153 */
154enum iocpf_event {
155 IOCPF_E_ENABLE = 1, /*!< IOCPF enable request */
156 IOCPF_E_DISABLE = 2, /*!< IOCPF disable request */
157 IOCPF_E_STOP = 3, /*!< stop on driver detach */
Rasesh Mody0120b992011-07-22 08:07:41 +0000158 IOCPF_E_FWREADY = 4, /*!< f/w initialization done */
Rasesh Mody1d32f762010-12-23 21:45:09 +0000159 IOCPF_E_FWRSP_ENABLE = 5, /*!< enable f/w response */
160 IOCPF_E_FWRSP_DISABLE = 6, /*!< disable f/w response */
161 IOCPF_E_FAIL = 7, /*!< failure notice by ioc sm */
162 IOCPF_E_INITFAIL = 8, /*!< init fail notice by ioc sm */
163 IOCPF_E_GETATTRFAIL = 9, /*!< init fail notice by ioc sm */
164 IOCPF_E_SEMLOCKED = 10, /*!< h/w semaphore is locked */
165 IOCPF_E_TIMEOUT = 11, /*!< f/w response timeout */
Rasesh Mody078086f2011-08-08 16:21:39 +0000166 IOCPF_E_SEM_ERROR = 12, /*!< h/w sem mapping error */
Rasesh Mody1d32f762010-12-23 21:45:09 +0000167};
168
169/**
170 * IOCPF states
171 */
172enum bfa_iocpf_state {
173 BFA_IOCPF_RESET = 1, /*!< IOC is in reset state */
174 BFA_IOCPF_SEMWAIT = 2, /*!< Waiting for IOC h/w semaphore */
175 BFA_IOCPF_HWINIT = 3, /*!< IOC h/w is being initialized */
176 BFA_IOCPF_READY = 4, /*!< IOCPF is initialized */
177 BFA_IOCPF_INITFAIL = 5, /*!< IOCPF failed */
178 BFA_IOCPF_FAIL = 6, /*!< IOCPF failed */
179 BFA_IOCPF_DISABLING = 7, /*!< IOCPF is being disabled */
180 BFA_IOCPF_DISABLED = 8, /*!< IOCPF is disabled */
181 BFA_IOCPF_FWMISMATCH = 9, /*!< IOC f/w different from drivers */
182};
183
184bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf, enum iocpf_event);
185bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf, enum iocpf_event);
186bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf, enum iocpf_event);
187bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf, enum iocpf_event);
188bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf, enum iocpf_event);
189bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf, enum iocpf_event);
190bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf, enum iocpf_event);
191bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf,
192 enum iocpf_event);
193bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf, enum iocpf_event);
194bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf, enum iocpf_event);
195bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf, enum iocpf_event);
196bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf, enum iocpf_event);
197bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf,
198 enum iocpf_event);
199bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf, enum iocpf_event);
200
201static struct bfa_sm_table iocpf_sm_table[] = {
202 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
203 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
204 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
205 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
206 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
207 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
208 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
209 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
210 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
211 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
212 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
213 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
214 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
215 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
216};
217
218/**
219 * IOC State Machine
220 */
221
222/**
223 * Beginning state. IOC uninit state.
224 */
225static void
226bfa_ioc_sm_uninit_entry(struct bfa_ioc *ioc)
227{
228}
229
230/**
231 * IOC is in uninit state.
232 */
233static void
234bfa_ioc_sm_uninit(struct bfa_ioc *ioc, enum ioc_event event)
235{
236 switch (event) {
237 case IOC_E_RESET:
238 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
239 break;
240
241 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000242 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000243 }
244}
245
246/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700247 * Reset entry actions -- initialize state machine
248 */
249static void
250bfa_ioc_sm_reset_entry(struct bfa_ioc *ioc)
251{
Rasesh Mody1d32f762010-12-23 21:45:09 +0000252 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700253}
254
255/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000256 * IOC is in reset state.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700257 */
258static void
259bfa_ioc_sm_reset(struct bfa_ioc *ioc, enum ioc_event event)
260{
261 switch (event) {
262 case IOC_E_ENABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000263 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700264 break;
265
266 case IOC_E_DISABLE:
267 bfa_ioc_disable_comp(ioc);
268 break;
269
270 case IOC_E_DETACH:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000271 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
272 break;
273
274 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000275 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000276 }
277}
278
279static void
280bfa_ioc_sm_enabling_entry(struct bfa_ioc *ioc)
281{
282 bfa_iocpf_enable(ioc);
283}
284
285/**
286 * Host IOC function is being enabled, awaiting response from firmware.
287 * Semaphore is acquired.
288 */
289static void
290bfa_ioc_sm_enabling(struct bfa_ioc *ioc, enum ioc_event event)
291{
292 switch (event) {
293 case IOC_E_ENABLED:
294 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
295 break;
296
Rasesh Modyf374b362011-07-22 08:07:46 +0000297 case IOC_E_PFFAILED:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000298 /* !!! fall through !!! */
299 case IOC_E_HWERROR:
300 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Rasesh Mody078086f2011-08-08 16:21:39 +0000301 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Rasesh Modyf374b362011-07-22 08:07:46 +0000302 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000303 bfa_iocpf_initfail(ioc);
304 break;
305
Rasesh Mody078086f2011-08-08 16:21:39 +0000306 case IOC_E_HWFAILED:
307 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
308 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
309 break;
310
Rasesh Mody1d32f762010-12-23 21:45:09 +0000311 case IOC_E_DISABLE:
312 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
313 break;
314
315 case IOC_E_DETACH:
316 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
317 bfa_iocpf_stop(ioc);
318 break;
319
320 case IOC_E_ENABLE:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700321 break;
322
323 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000324 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700325 }
326}
327
328/**
329 * Semaphore should be acquired for version check.
330 */
331static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700332bfa_ioc_sm_getattr_entry(struct bfa_ioc *ioc)
333{
Rasesh Mody1d32f762010-12-23 21:45:09 +0000334 mod_timer(&ioc->ioc_timer, jiffies +
335 msecs_to_jiffies(BFA_IOC_TOV));
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700336 bfa_ioc_send_getattr(ioc);
337}
338
339/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700340 * IOC configuration in progress. Timer is active.
341 */
342static void
343bfa_ioc_sm_getattr(struct bfa_ioc *ioc, enum ioc_event event)
344{
345 switch (event) {
346 case IOC_E_FWRSP_GETATTR:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000347 del_timer(&ioc->ioc_timer);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700348 bfa_ioc_check_attr_wwns(ioc);
Rasesh Mody078086f2011-08-08 16:21:39 +0000349 bfa_ioc_hb_monitor(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700350 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
351 break;
352
Rasesh Modyf374b362011-07-22 08:07:46 +0000353 case IOC_E_PFFAILED:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700354 case IOC_E_HWERROR:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000355 del_timer(&ioc->ioc_timer);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700356 /* fall through */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700357 case IOC_E_TIMEOUT:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000358 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Rasesh Mody078086f2011-08-08 16:21:39 +0000359 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Rasesh Modyf374b362011-07-22 08:07:46 +0000360 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000361 bfa_iocpf_getattrfail(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700362 break;
363
364 case IOC_E_DISABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000365 del_timer(&ioc->ioc_timer);
366 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
367 break;
368
369 case IOC_E_ENABLE:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700370 break;
371
372 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000373 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700374 }
375}
376
377static void
378bfa_ioc_sm_op_entry(struct bfa_ioc *ioc)
379{
380 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
Rasesh Mody078086f2011-08-08 16:21:39 +0000381 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700382}
383
384static void
385bfa_ioc_sm_op(struct bfa_ioc *ioc, enum ioc_event event)
386{
387 switch (event) {
388 case IOC_E_ENABLE:
389 break;
390
391 case IOC_E_DISABLE:
392 bfa_ioc_hb_stop(ioc);
393 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
394 break;
395
Rasesh Modyf374b362011-07-22 08:07:46 +0000396 case IOC_E_PFFAILED:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700397 case IOC_E_HWERROR:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700398 bfa_ioc_hb_stop(ioc);
399 /* !!! fall through !!! */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700400 case IOC_E_HBFAIL:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000401 if (ioc->iocpf.auto_recover)
402 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
403 else
404 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
405
Rasesh Mody078086f2011-08-08 16:21:39 +0000406 bfa_ioc_fail_notify(ioc);
407
Rasesh Modyf374b362011-07-22 08:07:46 +0000408 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000409 bfa_iocpf_fail(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700410 break;
411
412 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000413 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700414 }
415}
416
417static void
418bfa_ioc_sm_disabling_entry(struct bfa_ioc *ioc)
419{
Rasesh Mody1d32f762010-12-23 21:45:09 +0000420 bfa_iocpf_disable(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700421}
422
423/**
Rasesh Modyaafd5c22011-09-27 10:39:09 +0000424 * IOC is being disabled
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700425 */
426static void
427bfa_ioc_sm_disabling(struct bfa_ioc *ioc, enum ioc_event event)
428{
429 switch (event) {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000430 case IOC_E_DISABLED:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700431 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
432 break;
433
434 case IOC_E_HWERROR:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700435 /*
Rasesh Mody1d32f762010-12-23 21:45:09 +0000436 * No state change. Will move to disabled state
437 * after iocpf sm completes failure processing and
438 * moves to disabled state.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700439 */
Rasesh Mody1d32f762010-12-23 21:45:09 +0000440 bfa_iocpf_fail(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700441 break;
442
Rasesh Mody078086f2011-08-08 16:21:39 +0000443 case IOC_E_HWFAILED:
444 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
445 bfa_ioc_disable_comp(ioc);
446 break;
447
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700448 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000449 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700450 }
451}
452
453/**
Rasesh Modyaafd5c22011-09-27 10:39:09 +0000454 * IOC disable completion entry.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700455 */
456static void
457bfa_ioc_sm_disabled_entry(struct bfa_ioc *ioc)
458{
459 bfa_ioc_disable_comp(ioc);
460}
461
462static void
463bfa_ioc_sm_disabled(struct bfa_ioc *ioc, enum ioc_event event)
464{
465 switch (event) {
466 case IOC_E_ENABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000467 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700468 break;
469
470 case IOC_E_DISABLE:
471 ioc->cbfn->disable_cbfn(ioc->bfa);
472 break;
473
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700474 case IOC_E_DETACH:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000475 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
476 bfa_iocpf_stop(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700477 break;
478
479 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000480 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700481 }
482}
483
484static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000485bfa_ioc_sm_fail_retry_entry(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700486{
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700487}
488
489/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000490 * Hardware initialization retry.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700491 */
492static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000493bfa_ioc_sm_fail_retry(struct bfa_ioc *ioc, enum ioc_event event)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700494{
495 switch (event) {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000496 case IOC_E_ENABLED:
497 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
498 break;
499
Rasesh Modyf374b362011-07-22 08:07:46 +0000500 case IOC_E_PFFAILED:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000501 case IOC_E_HWERROR:
502 /**
503 * Initialization retry failed.
504 */
505 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Rasesh Mody078086f2011-08-08 16:21:39 +0000506 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Rasesh Modyf374b362011-07-22 08:07:46 +0000507 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000508 bfa_iocpf_initfail(ioc);
509 break;
510
Rasesh Mody078086f2011-08-08 16:21:39 +0000511 case IOC_E_HWFAILED:
512 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
513 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000514 break;
515
516 case IOC_E_ENABLE:
517 break;
518
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700519 case IOC_E_DISABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000520 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700521 break;
522
523 case IOC_E_DETACH:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000524 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
525 bfa_iocpf_stop(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700526 break;
527
528 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000529 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700530 }
531}
532
533static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000534bfa_ioc_sm_fail_entry(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700535{
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700536}
537
538/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000539 * IOC failure.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700540 */
541static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000542bfa_ioc_sm_fail(struct bfa_ioc *ioc, enum ioc_event event)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700543{
544 switch (event) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700545 case IOC_E_ENABLE:
546 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
547 break;
548
549 case IOC_E_DISABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000550 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700551 break;
552
Rasesh Mody1d32f762010-12-23 21:45:09 +0000553 case IOC_E_DETACH:
554 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
555 bfa_iocpf_stop(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700556 break;
557
558 case IOC_E_HWERROR:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000559 /* HB failure notification, ignore. */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700560 break;
Rasesh Mody1d32f762010-12-23 21:45:09 +0000561
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700562 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000563 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700564 }
565}
566
Rasesh Mody078086f2011-08-08 16:21:39 +0000567static void
568bfa_ioc_sm_hwfail_entry(struct bfa_ioc *ioc)
569{
570}
571
572/**
573 * IOC failure.
574 */
575static void
576bfa_ioc_sm_hwfail(struct bfa_ioc *ioc, enum ioc_event event)
577{
578 switch (event) {
579
580 case IOC_E_ENABLE:
581 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
582 break;
583
584 case IOC_E_DISABLE:
585 ioc->cbfn->disable_cbfn(ioc->bfa);
586 break;
587
588 case IOC_E_DETACH:
589 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
590 break;
591
592 default:
593 bfa_sm_fault(event);
594 }
595}
596
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700597/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000598 * IOCPF State Machine
599 */
600
601/**
602 * Reset entry actions -- initialize state machine
603 */
604static void
605bfa_iocpf_sm_reset_entry(struct bfa_iocpf *iocpf)
606{
Rasesh Mody078086f2011-08-08 16:21:39 +0000607 iocpf->fw_mismatch_notified = false;
Rasesh Mody1d32f762010-12-23 21:45:09 +0000608 iocpf->auto_recover = bfa_nw_auto_recover;
609}
610
611/**
612 * Beginning state. IOC is in reset state.
613 */
614static void
615bfa_iocpf_sm_reset(struct bfa_iocpf *iocpf, enum iocpf_event event)
616{
617 switch (event) {
618 case IOCPF_E_ENABLE:
619 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
620 break;
621
622 case IOCPF_E_STOP:
623 break;
624
625 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000626 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000627 }
628}
629
630/**
631 * Semaphore should be acquired for version check.
632 */
633static void
634bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf *iocpf)
635{
Rasesh Modyd4e16d42011-07-22 08:07:47 +0000636 bfa_ioc_hw_sem_init(iocpf->ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000637 bfa_ioc_hw_sem_get(iocpf->ioc);
638}
639
640/**
641 * Awaiting h/w semaphore to continue with version check.
642 */
643static void
644bfa_iocpf_sm_fwcheck(struct bfa_iocpf *iocpf, enum iocpf_event event)
645{
646 struct bfa_ioc *ioc = iocpf->ioc;
647
648 switch (event) {
649 case IOCPF_E_SEMLOCKED:
650 if (bfa_ioc_firmware_lock(ioc)) {
Rasesh Mody79ea6c82011-04-14 08:05:18 +0000651 if (bfa_ioc_sync_start(ioc)) {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000652 bfa_ioc_sync_join(ioc);
653 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
654 } else {
655 bfa_ioc_firmware_unlock(ioc);
656 bfa_nw_ioc_hw_sem_release(ioc);
657 mod_timer(&ioc->sem_timer, jiffies +
658 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
659 }
660 } else {
661 bfa_nw_ioc_hw_sem_release(ioc);
662 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
663 }
664 break;
665
Rasesh Mody078086f2011-08-08 16:21:39 +0000666 case IOCPF_E_SEM_ERROR:
667 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
668 bfa_ioc_pf_hwfailed(ioc);
669 break;
670
Rasesh Mody1d32f762010-12-23 21:45:09 +0000671 case IOCPF_E_DISABLE:
672 bfa_ioc_hw_sem_get_cancel(ioc);
673 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
674 bfa_ioc_pf_disabled(ioc);
675 break;
676
677 case IOCPF_E_STOP:
678 bfa_ioc_hw_sem_get_cancel(ioc);
679 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
680 break;
681
682 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000683 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000684 }
685}
686
687/**
688 * Notify enable completion callback
689 */
690static void
691bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf *iocpf)
692{
693 /* Call only the first time sm enters fwmismatch state. */
Rasesh Mody078086f2011-08-08 16:21:39 +0000694 if (iocpf->fw_mismatch_notified == false)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000695 bfa_ioc_pf_fwmismatch(iocpf->ioc);
696
Rasesh Mody078086f2011-08-08 16:21:39 +0000697 iocpf->fw_mismatch_notified = true;
Rasesh Mody1d32f762010-12-23 21:45:09 +0000698 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
699 msecs_to_jiffies(BFA_IOC_TOV));
700}
701
702/**
703 * Awaiting firmware version match.
704 */
705static void
706bfa_iocpf_sm_mismatch(struct bfa_iocpf *iocpf, enum iocpf_event event)
707{
708 struct bfa_ioc *ioc = iocpf->ioc;
709
710 switch (event) {
711 case IOCPF_E_TIMEOUT:
712 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
713 break;
714
715 case IOCPF_E_DISABLE:
716 del_timer(&ioc->iocpf_timer);
717 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
718 bfa_ioc_pf_disabled(ioc);
719 break;
720
721 case IOCPF_E_STOP:
722 del_timer(&ioc->iocpf_timer);
723 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
724 break;
725
726 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000727 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000728 }
729}
730
731/**
732 * Request for semaphore.
733 */
734static void
735bfa_iocpf_sm_semwait_entry(struct bfa_iocpf *iocpf)
736{
737 bfa_ioc_hw_sem_get(iocpf->ioc);
738}
739
740/**
741 * Awaiting semaphore for h/w initialzation.
742 */
743static void
744bfa_iocpf_sm_semwait(struct bfa_iocpf *iocpf, enum iocpf_event event)
745{
746 struct bfa_ioc *ioc = iocpf->ioc;
747
748 switch (event) {
749 case IOCPF_E_SEMLOCKED:
750 if (bfa_ioc_sync_complete(ioc)) {
751 bfa_ioc_sync_join(ioc);
752 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
753 } else {
754 bfa_nw_ioc_hw_sem_release(ioc);
755 mod_timer(&ioc->sem_timer, jiffies +
756 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
757 }
758 break;
759
Rasesh Mody078086f2011-08-08 16:21:39 +0000760 case IOCPF_E_SEM_ERROR:
761 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
762 bfa_ioc_pf_hwfailed(ioc);
763 break;
764
Rasesh Mody1d32f762010-12-23 21:45:09 +0000765 case IOCPF_E_DISABLE:
766 bfa_ioc_hw_sem_get_cancel(ioc);
767 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
768 break;
769
770 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000771 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000772 }
773}
774
775static void
776bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf *iocpf)
777{
Rasesh Mody078086f2011-08-08 16:21:39 +0000778 iocpf->poll_time = 0;
Rasesh Modyaafd5c22011-09-27 10:39:09 +0000779 bfa_ioc_reset(iocpf->ioc, false);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000780}
781
782/**
783 * Hardware is being initialized. Interrupts are enabled.
784 * Holding hardware semaphore lock.
785 */
786static void
787bfa_iocpf_sm_hwinit(struct bfa_iocpf *iocpf, enum iocpf_event event)
788{
789 struct bfa_ioc *ioc = iocpf->ioc;
790
791 switch (event) {
792 case IOCPF_E_FWREADY:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000793 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
794 break;
795
Rasesh Mody1d32f762010-12-23 21:45:09 +0000796 case IOCPF_E_TIMEOUT:
797 bfa_nw_ioc_hw_sem_release(ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000798 bfa_ioc_pf_failed(ioc);
799 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
800 break;
801
802 case IOCPF_E_DISABLE:
803 del_timer(&ioc->iocpf_timer);
804 bfa_ioc_sync_leave(ioc);
805 bfa_nw_ioc_hw_sem_release(ioc);
806 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
807 break;
808
809 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000810 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000811 }
812}
813
814static void
815bfa_iocpf_sm_enabling_entry(struct bfa_iocpf *iocpf)
816{
817 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
818 msecs_to_jiffies(BFA_IOC_TOV));
Rasesh Mody078086f2011-08-08 16:21:39 +0000819 /**
820 * Enable Interrupts before sending fw IOC ENABLE cmd.
821 */
822 iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000823 bfa_ioc_send_enable(iocpf->ioc);
824}
825
826/**
827 * Host IOC function is being enabled, awaiting response from firmware.
828 * Semaphore is acquired.
829 */
830static void
831bfa_iocpf_sm_enabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
832{
833 struct bfa_ioc *ioc = iocpf->ioc;
834
835 switch (event) {
836 case IOCPF_E_FWRSP_ENABLE:
837 del_timer(&ioc->iocpf_timer);
838 bfa_nw_ioc_hw_sem_release(ioc);
839 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
840 break;
841
842 case IOCPF_E_INITFAIL:
843 del_timer(&ioc->iocpf_timer);
844 /*
845 * !!! fall through !!!
846 */
847 case IOCPF_E_TIMEOUT:
848 bfa_nw_ioc_hw_sem_release(ioc);
849 if (event == IOCPF_E_TIMEOUT)
850 bfa_ioc_pf_failed(ioc);
851 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
852 break;
853
854 case IOCPF_E_DISABLE:
855 del_timer(&ioc->iocpf_timer);
856 bfa_nw_ioc_hw_sem_release(ioc);
857 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
858 break;
859
Rasesh Mody1d32f762010-12-23 21:45:09 +0000860 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000861 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000862 }
863}
864
Rasesh Mody1d32f762010-12-23 21:45:09 +0000865static void
866bfa_iocpf_sm_ready_entry(struct bfa_iocpf *iocpf)
867{
868 bfa_ioc_pf_enabled(iocpf->ioc);
869}
870
871static void
872bfa_iocpf_sm_ready(struct bfa_iocpf *iocpf, enum iocpf_event event)
873{
Rasesh Mody1d32f762010-12-23 21:45:09 +0000874 switch (event) {
875 case IOCPF_E_DISABLE:
876 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
877 break;
878
879 case IOCPF_E_GETATTRFAIL:
880 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
881 break;
882
883 case IOCPF_E_FAIL:
884 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
885 break;
886
Rasesh Mody1d32f762010-12-23 21:45:09 +0000887 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000888 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000889 }
890}
891
892static void
893bfa_iocpf_sm_disabling_entry(struct bfa_iocpf *iocpf)
894{
895 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
896 msecs_to_jiffies(BFA_IOC_TOV));
897 bfa_ioc_send_disable(iocpf->ioc);
898}
899
900/**
901 * IOC is being disabled
902 */
903static void
904bfa_iocpf_sm_disabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
905{
906 struct bfa_ioc *ioc = iocpf->ioc;
907
908 switch (event) {
909 case IOCPF_E_FWRSP_DISABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000910 del_timer(&ioc->iocpf_timer);
911 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
912 break;
913
914 case IOCPF_E_FAIL:
915 del_timer(&ioc->iocpf_timer);
916 /*
917 * !!! fall through !!!
918 */
919
920 case IOCPF_E_TIMEOUT:
921 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
922 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
923 break;
924
925 case IOCPF_E_FWRSP_ENABLE:
926 break;
927
928 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000929 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000930 }
931}
932
933static void
934bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf *iocpf)
935{
936 bfa_ioc_hw_sem_get(iocpf->ioc);
937}
938
939/**
940 * IOC hb ack request is being removed.
941 */
942static void
943bfa_iocpf_sm_disabling_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
944{
945 struct bfa_ioc *ioc = iocpf->ioc;
946
947 switch (event) {
948 case IOCPF_E_SEMLOCKED:
949 bfa_ioc_sync_leave(ioc);
950 bfa_nw_ioc_hw_sem_release(ioc);
951 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
952 break;
953
Rasesh Mody078086f2011-08-08 16:21:39 +0000954 case IOCPF_E_SEM_ERROR:
955 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
956 bfa_ioc_pf_hwfailed(ioc);
957 break;
958
Rasesh Mody1d32f762010-12-23 21:45:09 +0000959 case IOCPF_E_FAIL:
960 break;
961
962 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000963 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000964 }
965}
966
967/**
968 * IOC disable completion entry.
969 */
970static void
971bfa_iocpf_sm_disabled_entry(struct bfa_iocpf *iocpf)
972{
Rasesh Modyfdad4002011-07-22 08:07:45 +0000973 bfa_ioc_mbox_flush(iocpf->ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000974 bfa_ioc_pf_disabled(iocpf->ioc);
975}
976
977static void
978bfa_iocpf_sm_disabled(struct bfa_iocpf *iocpf, enum iocpf_event event)
979{
980 struct bfa_ioc *ioc = iocpf->ioc;
981
982 switch (event) {
983 case IOCPF_E_ENABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000984 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
985 break;
986
987 case IOCPF_E_STOP:
988 bfa_ioc_firmware_unlock(ioc);
989 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
990 break;
991
992 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000993 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000994 }
995}
996
997static void
998bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf *iocpf)
999{
1000 bfa_ioc_hw_sem_get(iocpf->ioc);
1001}
1002
1003/**
1004 * Hardware initialization failed.
1005 */
1006static void
1007bfa_iocpf_sm_initfail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
1008{
1009 struct bfa_ioc *ioc = iocpf->ioc;
1010
1011 switch (event) {
1012 case IOCPF_E_SEMLOCKED:
1013 bfa_ioc_notify_fail(ioc);
Rasesh Mody078086f2011-08-08 16:21:39 +00001014 bfa_ioc_sync_leave(ioc);
1015 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1016 bfa_nw_ioc_hw_sem_release(ioc);
1017 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
1018 break;
1019
1020 case IOCPF_E_SEM_ERROR:
1021 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1022 bfa_ioc_pf_hwfailed(ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001023 break;
1024
1025 case IOCPF_E_DISABLE:
1026 bfa_ioc_hw_sem_get_cancel(ioc);
1027 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1028 break;
1029
1030 case IOCPF_E_STOP:
1031 bfa_ioc_hw_sem_get_cancel(ioc);
1032 bfa_ioc_firmware_unlock(ioc);
1033 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1034 break;
1035
1036 case IOCPF_E_FAIL:
1037 break;
1038
1039 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001040 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001041 }
1042}
1043
1044static void
1045bfa_iocpf_sm_initfail_entry(struct bfa_iocpf *iocpf)
1046{
Rasesh Mody1d32f762010-12-23 21:45:09 +00001047}
1048
1049/**
1050 * Hardware initialization failed.
1051 */
1052static void
1053bfa_iocpf_sm_initfail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1054{
1055 struct bfa_ioc *ioc = iocpf->ioc;
1056
1057 switch (event) {
1058 case IOCPF_E_DISABLE:
1059 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1060 break;
1061
1062 case IOCPF_E_STOP:
1063 bfa_ioc_firmware_unlock(ioc);
1064 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1065 break;
1066
1067 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001068 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001069 }
1070}
1071
1072static void
1073bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf *iocpf)
1074{
1075 /**
1076 * Mark IOC as failed in hardware and stop firmware.
1077 */
1078 bfa_ioc_lpu_stop(iocpf->ioc);
1079
1080 /**
1081 * Flush any queued up mailbox requests.
1082 */
Rasesh Modyfdad4002011-07-22 08:07:45 +00001083 bfa_ioc_mbox_flush(iocpf->ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001084 bfa_ioc_hw_sem_get(iocpf->ioc);
1085}
1086
1087/**
1088 * IOC is in failed state.
1089 */
1090static void
1091bfa_iocpf_sm_fail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
1092{
1093 struct bfa_ioc *ioc = iocpf->ioc;
1094
1095 switch (event) {
1096 case IOCPF_E_SEMLOCKED:
Rasesh Mody1d32f762010-12-23 21:45:09 +00001097 bfa_ioc_sync_ack(ioc);
1098 bfa_ioc_notify_fail(ioc);
1099 if (!iocpf->auto_recover) {
1100 bfa_ioc_sync_leave(ioc);
Rasesh Mody078086f2011-08-08 16:21:39 +00001101 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001102 bfa_nw_ioc_hw_sem_release(ioc);
1103 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1104 } else {
1105 if (bfa_ioc_sync_complete(ioc))
1106 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1107 else {
1108 bfa_nw_ioc_hw_sem_release(ioc);
1109 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1110 }
1111 }
1112 break;
1113
Rasesh Mody078086f2011-08-08 16:21:39 +00001114 case IOCPF_E_SEM_ERROR:
1115 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1116 bfa_ioc_pf_hwfailed(ioc);
1117 break;
1118
Rasesh Mody1d32f762010-12-23 21:45:09 +00001119 case IOCPF_E_DISABLE:
1120 bfa_ioc_hw_sem_get_cancel(ioc);
1121 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1122 break;
1123
1124 case IOCPF_E_FAIL:
1125 break;
1126
1127 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001128 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001129 }
1130}
1131
1132static void
1133bfa_iocpf_sm_fail_entry(struct bfa_iocpf *iocpf)
1134{
1135}
1136
1137/**
1138 * @brief
1139 * IOC is in failed state.
1140 */
1141static void
1142bfa_iocpf_sm_fail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1143{
1144 switch (event) {
1145 case IOCPF_E_DISABLE:
1146 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1147 break;
1148
1149 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001150 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001151 }
1152}
1153
1154/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001155 * BFA IOC private functions
1156 */
1157
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001158/**
1159 * Notify common modules registered for notification.
1160 */
1161static void
1162bfa_ioc_event_notify(struct bfa_ioc *ioc, enum bfa_ioc_event event)
1163{
1164 struct bfa_ioc_notify *notify;
1165 struct list_head *qe;
1166
1167 list_for_each(qe, &ioc->notify_q) {
1168 notify = (struct bfa_ioc_notify *)qe;
1169 notify->cbfn(notify->cbarg, event);
1170 }
1171}
1172
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001173static void
1174bfa_ioc_disable_comp(struct bfa_ioc *ioc)
1175{
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001176 ioc->cbfn->disable_cbfn(ioc->bfa);
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001177 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001178}
1179
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001180bool
Rasesh Mody8a891422010-08-25 23:00:27 -07001181bfa_nw_ioc_sem_get(void __iomem *sem_reg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001182{
1183 u32 r32;
1184 int cnt = 0;
1185#define BFA_SEM_SPINCNT 3000
1186
1187 r32 = readl(sem_reg);
1188
Rasesh Mody078086f2011-08-08 16:21:39 +00001189 while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001190 cnt++;
1191 udelay(2);
1192 r32 = readl(sem_reg);
1193 }
1194
Rasesh Mody078086f2011-08-08 16:21:39 +00001195 if (!(r32 & 1))
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001196 return true;
1197
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001198 return false;
1199}
1200
1201void
Rasesh Mody8a891422010-08-25 23:00:27 -07001202bfa_nw_ioc_sem_release(void __iomem *sem_reg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001203{
Rasesh Mody1d51a132011-09-16 15:06:46 +00001204 readl(sem_reg);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001205 writel(1, sem_reg);
1206}
1207
1208static void
Rasesh Modyd4e16d42011-07-22 08:07:47 +00001209bfa_ioc_hw_sem_init(struct bfa_ioc *ioc)
1210{
1211 struct bfi_ioc_image_hdr fwhdr;
1212 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1213
1214 if (fwstate == BFI_IOC_UNINIT)
1215 return;
1216
1217 bfa_nw_ioc_fwver_get(ioc, &fwhdr);
1218
1219 if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL)
1220 return;
1221
1222 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
1223
1224 /*
1225 * Try to lock and then unlock the semaphore.
1226 */
1227 readl(ioc->ioc_regs.ioc_sem_reg);
1228 writel(1, ioc->ioc_regs.ioc_sem_reg);
1229}
1230
1231static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001232bfa_ioc_hw_sem_get(struct bfa_ioc *ioc)
1233{
1234 u32 r32;
1235
1236 /**
1237 * First read to the semaphore register will return 0, subsequent reads
1238 * will return 1. Semaphore is released by writing 1 to the register
1239 */
1240 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Rasesh Mody078086f2011-08-08 16:21:39 +00001241 if (r32 == ~0) {
1242 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
1243 return;
1244 }
1245 if (!(r32 & 1)) {
Rasesh Mody1d32f762010-12-23 21:45:09 +00001246 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001247 return;
1248 }
1249
1250 mod_timer(&ioc->sem_timer, jiffies +
1251 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
1252}
1253
1254void
Rasesh Mody8a891422010-08-25 23:00:27 -07001255bfa_nw_ioc_hw_sem_release(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001256{
1257 writel(1, ioc->ioc_regs.ioc_sem_reg);
1258}
1259
1260static void
1261bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc)
1262{
1263 del_timer(&ioc->sem_timer);
1264}
1265
1266/**
1267 * @brief
1268 * Initialize LPU local memory (aka secondary memory / SRAM)
1269 */
1270static void
1271bfa_ioc_lmem_init(struct bfa_ioc *ioc)
1272{
1273 u32 pss_ctl;
1274 int i;
1275#define PSS_LMEM_INIT_TIME 10000
1276
1277 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1278 pss_ctl &= ~__PSS_LMEM_RESET;
1279 pss_ctl |= __PSS_LMEM_INIT_EN;
1280
1281 /*
1282 * i2c workaround 12.5khz clock
1283 */
1284 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
1285 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1286
1287 /**
1288 * wait for memory initialization to be complete
1289 */
1290 i = 0;
1291 do {
1292 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1293 i++;
1294 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1295
1296 /**
1297 * If memory initialization is not successful, IOC timeout will catch
1298 * such failures.
1299 */
1300 BUG_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
1301
1302 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
1303 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1304}
1305
1306static void
1307bfa_ioc_lpu_start(struct bfa_ioc *ioc)
1308{
1309 u32 pss_ctl;
1310
1311 /**
1312 * Take processor out of reset.
1313 */
1314 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1315 pss_ctl &= ~__PSS_LPU0_RESET;
1316
1317 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1318}
1319
1320static void
1321bfa_ioc_lpu_stop(struct bfa_ioc *ioc)
1322{
1323 u32 pss_ctl;
1324
1325 /**
1326 * Put processors in reset.
1327 */
1328 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1329 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1330
1331 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1332}
1333
1334/**
1335 * Get driver and firmware versions.
1336 */
1337void
Rasesh Mody8a891422010-08-25 23:00:27 -07001338bfa_nw_ioc_fwver_get(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001339{
David S. Miller58598542011-04-17 16:51:36 -07001340 u32 pgnum;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001341 u32 loff = 0;
1342 int i;
1343 u32 *fwsig = (u32 *) fwhdr;
1344
1345 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001346 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1347
1348 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32));
1349 i++) {
1350 fwsig[i] =
1351 swab32(readl((loff) + (ioc->ioc_regs.smem_page_start)));
1352 loff += sizeof(u32);
1353 }
1354}
1355
1356/**
1357 * Returns TRUE if same.
1358 */
1359bool
Rasesh Mody8a891422010-08-25 23:00:27 -07001360bfa_nw_ioc_fwver_cmp(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001361{
1362 struct bfi_ioc_image_hdr *drv_fwhdr;
1363 int i;
1364
1365 drv_fwhdr = (struct bfi_ioc_image_hdr *)
Rasesh Mody078086f2011-08-08 16:21:39 +00001366 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001367
1368 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1369 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i])
1370 return false;
1371 }
1372
1373 return true;
1374}
1375
1376/**
1377 * Return true if current running version is valid. Firmware signature and
1378 * execution context (driver/bios) must match.
1379 */
1380static bool
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001381bfa_ioc_fwver_valid(struct bfa_ioc *ioc, u32 boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001382{
1383 struct bfi_ioc_image_hdr fwhdr, *drv_fwhdr;
1384
Rasesh Mody8a891422010-08-25 23:00:27 -07001385 bfa_nw_ioc_fwver_get(ioc, &fwhdr);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001386 drv_fwhdr = (struct bfi_ioc_image_hdr *)
Rasesh Mody078086f2011-08-08 16:21:39 +00001387 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001388
1389 if (fwhdr.signature != drv_fwhdr->signature)
1390 return false;
1391
Rasesh Mody078086f2011-08-08 16:21:39 +00001392 if (swab32(fwhdr.bootenv) != boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001393 return false;
1394
Rasesh Mody8a891422010-08-25 23:00:27 -07001395 return bfa_nw_ioc_fwver_cmp(ioc, &fwhdr);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001396}
1397
1398/**
1399 * Conditionally flush any pending message from firmware at start.
1400 */
1401static void
1402bfa_ioc_msgflush(struct bfa_ioc *ioc)
1403{
1404 u32 r32;
1405
1406 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1407 if (r32)
1408 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1409}
1410
1411/**
1412 * @img ioc_init_logic.jpg
1413 */
1414static void
1415bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force)
1416{
1417 enum bfi_ioc_state ioc_fwstate;
1418 bool fwvalid;
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001419 u32 boot_env;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001420
1421 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1422
1423 if (force)
1424 ioc_fwstate = BFI_IOC_UNINIT;
1425
Rasesh Mody078086f2011-08-08 16:21:39 +00001426 boot_env = BFI_FWBOOT_ENV_OS;
1427
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001428 /**
1429 * check if firmware is valid
1430 */
1431 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001432 false : bfa_ioc_fwver_valid(ioc, boot_env);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001433
1434 if (!fwvalid) {
Rasesh Mody078086f2011-08-08 16:21:39 +00001435 bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env);
1436 bfa_ioc_poll_fwinit(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001437 return;
1438 }
1439
1440 /**
1441 * If hardware initialization is in progress (initialized by other IOC),
1442 * just wait for an initialization completion interrupt.
1443 */
1444 if (ioc_fwstate == BFI_IOC_INITING) {
Rasesh Mody078086f2011-08-08 16:21:39 +00001445 bfa_ioc_poll_fwinit(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001446 return;
1447 }
1448
1449 /**
1450 * If IOC function is disabled and firmware version is same,
1451 * just re-enable IOC.
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001452 */
Rasesh Mody2c7d3822010-12-23 21:45:06 +00001453 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001454 /**
1455 * When using MSI-X any pending firmware ready event should
1456 * be flushed. Otherwise MSI-X interrupts are not delivered.
1457 */
1458 bfa_ioc_msgflush(ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001459 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001460 return;
1461 }
1462
1463 /**
1464 * Initialize the h/w for any other states.
1465 */
Rasesh Mody078086f2011-08-08 16:21:39 +00001466 bfa_ioc_boot(ioc, BFI_FWBOOT_TYPE_NORMAL, boot_env);
1467 bfa_ioc_poll_fwinit(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001468}
1469
1470void
Rasesh Mody8a891422010-08-25 23:00:27 -07001471bfa_nw_ioc_timeout(void *ioc_arg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001472{
1473 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
1474
1475 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1476}
1477
Rasesh Mody8a891422010-08-25 23:00:27 -07001478static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001479bfa_ioc_mbox_send(struct bfa_ioc *ioc, void *ioc_msg, int len)
1480{
1481 u32 *msgp = (u32 *) ioc_msg;
1482 u32 i;
1483
1484 BUG_ON(!(len <= BFI_IOC_MSGLEN_MAX));
1485
1486 /*
1487 * first write msg to mailbox registers
1488 */
1489 for (i = 0; i < len / sizeof(u32); i++)
1490 writel(cpu_to_le32(msgp[i]),
1491 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1492
1493 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
1494 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1495
1496 /*
1497 * write 1 to mailbox CMD to trigger LPU event
1498 */
1499 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1500 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
1501}
1502
1503static void
1504bfa_ioc_send_enable(struct bfa_ioc *ioc)
1505{
1506 struct bfi_ioc_ctrl_req enable_req;
1507 struct timeval tv;
1508
1509 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1510 bfa_ioc_portid(ioc));
Rasesh Mody078086f2011-08-08 16:21:39 +00001511 enable_req.clscode = htons(ioc->clscode);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001512 do_gettimeofday(&tv);
1513 enable_req.tv_sec = ntohl(tv.tv_sec);
1514 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req));
1515}
1516
1517static void
1518bfa_ioc_send_disable(struct bfa_ioc *ioc)
1519{
1520 struct bfi_ioc_ctrl_req disable_req;
1521
1522 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1523 bfa_ioc_portid(ioc));
1524 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req));
1525}
1526
1527static void
1528bfa_ioc_send_getattr(struct bfa_ioc *ioc)
1529{
1530 struct bfi_ioc_getattr_req attr_req;
1531
1532 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1533 bfa_ioc_portid(ioc));
1534 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1535 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1536}
1537
1538void
Rasesh Mody8a891422010-08-25 23:00:27 -07001539bfa_nw_ioc_hb_check(void *cbarg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001540{
1541 struct bfa_ioc *ioc = cbarg;
1542 u32 hb_count;
1543
1544 hb_count = readl(ioc->ioc_regs.heartbeat);
1545 if (ioc->hb_count == hb_count) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001546 bfa_ioc_recover(ioc);
1547 return;
1548 } else {
1549 ioc->hb_count = hb_count;
1550 }
1551
1552 bfa_ioc_mbox_poll(ioc);
1553 mod_timer(&ioc->hb_timer, jiffies +
1554 msecs_to_jiffies(BFA_IOC_HB_TOV));
1555}
1556
1557static void
1558bfa_ioc_hb_monitor(struct bfa_ioc *ioc)
1559{
1560 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
1561 mod_timer(&ioc->hb_timer, jiffies +
1562 msecs_to_jiffies(BFA_IOC_HB_TOV));
1563}
1564
1565static void
1566bfa_ioc_hb_stop(struct bfa_ioc *ioc)
1567{
1568 del_timer(&ioc->hb_timer);
1569}
1570
1571/**
1572 * @brief
1573 * Initiate a full firmware download.
1574 */
1575static void
1576bfa_ioc_download_fw(struct bfa_ioc *ioc, u32 boot_type,
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001577 u32 boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001578{
1579 u32 *fwimg;
David S. Miller58598542011-04-17 16:51:36 -07001580 u32 pgnum;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001581 u32 loff = 0;
1582 u32 chunkno = 0;
1583 u32 i;
Rasesh Mody078086f2011-08-08 16:21:39 +00001584 u32 asicmode;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001585
1586 /**
1587 * Initialize LMEM first before code download
1588 */
1589 bfa_ioc_lmem_init(ioc);
1590
Rasesh Mody078086f2011-08-08 16:21:39 +00001591 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001592
1593 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001594
1595 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1596
Rasesh Mody078086f2011-08-08 16:21:39 +00001597 for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001598 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1599 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Rasesh Mody078086f2011-08-08 16:21:39 +00001600 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001601 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
1602 }
1603
1604 /**
1605 * write smem
1606 */
1607 writel((swab32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)])),
1608 ((ioc->ioc_regs.smem_page_start) + (loff)));
1609
1610 loff += sizeof(u32);
1611
1612 /**
1613 * handle page offset wrap around
1614 */
1615 loff = PSS_SMEM_PGOFF(loff);
1616 if (loff == 0) {
1617 pgnum++;
1618 writel(pgnum,
1619 ioc->ioc_regs.host_page_num_fn);
1620 }
1621 }
1622
1623 writel(bfa_ioc_smem_pgnum(ioc, 0),
1624 ioc->ioc_regs.host_page_num_fn);
1625
1626 /*
Rasesh Mody078086f2011-08-08 16:21:39 +00001627 * Set boot type, env and device mode at the end.
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001628 */
Rasesh Mody078086f2011-08-08 16:21:39 +00001629 asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
1630 ioc->port0_mode, ioc->port1_mode);
1631 writel(asicmode, ((ioc->ioc_regs.smem_page_start)
1632 + BFI_FWBOOT_DEVMODE_OFF));
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001633 writel(boot_type, ((ioc->ioc_regs.smem_page_start)
Rasesh Mody078086f2011-08-08 16:21:39 +00001634 + (BFI_FWBOOT_TYPE_OFF)));
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001635 writel(boot_env, ((ioc->ioc_regs.smem_page_start)
Rasesh Mody078086f2011-08-08 16:21:39 +00001636 + (BFI_FWBOOT_ENV_OFF)));
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001637}
1638
1639static void
1640bfa_ioc_reset(struct bfa_ioc *ioc, bool force)
1641{
1642 bfa_ioc_hwinit(ioc, force);
1643}
1644
1645/**
Rasesh Mody078086f2011-08-08 16:21:39 +00001646 * BFA ioc enable reply by firmware
1647 */
1648static void
1649bfa_ioc_enable_reply(struct bfa_ioc *ioc, enum bfa_mode port_mode,
1650 u8 cap_bm)
1651{
1652 struct bfa_iocpf *iocpf = &ioc->iocpf;
1653
1654 ioc->port_mode = ioc->port_mode_cfg = port_mode;
1655 ioc->ad_cap_bm = cap_bm;
1656 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
1657}
1658
1659/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001660 * @brief
1661 * Update BFA configuration from firmware configuration.
1662 */
1663static void
1664bfa_ioc_getattr_reply(struct bfa_ioc *ioc)
1665{
1666 struct bfi_ioc_attr *attr = ioc->attr;
1667
1668 attr->adapter_prop = ntohl(attr->adapter_prop);
1669 attr->card_type = ntohl(attr->card_type);
1670 attr->maxfrsize = ntohs(attr->maxfrsize);
1671
1672 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1673}
1674
1675/**
1676 * Attach time initialization of mbox logic.
1677 */
1678static void
1679bfa_ioc_mbox_attach(struct bfa_ioc *ioc)
1680{
1681 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1682 int mc;
1683
1684 INIT_LIST_HEAD(&mod->cmd_q);
1685 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1686 mod->mbhdlr[mc].cbfn = NULL;
1687 mod->mbhdlr[mc].cbarg = ioc->bfa;
1688 }
1689}
1690
1691/**
1692 * Mbox poll timer -- restarts any pending mailbox requests.
1693 */
1694static void
1695bfa_ioc_mbox_poll(struct bfa_ioc *ioc)
1696{
1697 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1698 struct bfa_mbox_cmd *cmd;
Rasesh Mody078086f2011-08-08 16:21:39 +00001699 bfa_mbox_cmd_cbfn_t cbfn;
1700 void *cbarg;
1701 u32 stat;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001702
1703 /**
1704 * If no command pending, do nothing
1705 */
1706 if (list_empty(&mod->cmd_q))
1707 return;
1708
1709 /**
1710 * If previous command is not yet fetched by firmware, do nothing
1711 */
1712 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1713 if (stat)
1714 return;
1715
1716 /**
1717 * Enqueue command to firmware.
1718 */
1719 bfa_q_deq(&mod->cmd_q, &cmd);
1720 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
Rasesh Mody078086f2011-08-08 16:21:39 +00001721
1722 /**
1723 * Give a callback to the client, indicating that the command is sent
1724 */
1725 if (cmd->cbfn) {
1726 cbfn = cmd->cbfn;
1727 cbarg = cmd->cbarg;
1728 cmd->cbfn = NULL;
1729 cbfn(cbarg);
1730 }
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001731}
1732
1733/**
1734 * Cleanup any pending requests.
1735 */
1736static void
Rasesh Modyfdad4002011-07-22 08:07:45 +00001737bfa_ioc_mbox_flush(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001738{
1739 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1740 struct bfa_mbox_cmd *cmd;
1741
1742 while (!list_empty(&mod->cmd_q))
1743 bfa_q_deq(&mod->cmd_q, &cmd);
1744}
1745
Rasesh Mody1d32f762010-12-23 21:45:09 +00001746static void
1747bfa_ioc_fail_notify(struct bfa_ioc *ioc)
1748{
Rasesh Mody1d32f762010-12-23 21:45:09 +00001749 /**
1750 * Notify driver and common modules registered for notification.
1751 */
1752 ioc->cbfn->hbfail_cbfn(ioc->bfa);
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001753 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001754}
1755
Rasesh Modyaafd5c22011-09-27 10:39:09 +00001756/**
1757 * IOCPF to IOC interface
1758 */
Rasesh Mody1d32f762010-12-23 21:45:09 +00001759static void
1760bfa_ioc_pf_enabled(struct bfa_ioc *ioc)
1761{
1762 bfa_fsm_send_event(ioc, IOC_E_ENABLED);
1763}
1764
1765static void
1766bfa_ioc_pf_disabled(struct bfa_ioc *ioc)
1767{
1768 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
1769}
1770
1771static void
Rasesh Mody1d32f762010-12-23 21:45:09 +00001772bfa_ioc_pf_failed(struct bfa_ioc *ioc)
1773{
Rasesh Modyf374b362011-07-22 08:07:46 +00001774 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001775}
1776
1777static void
Rasesh Mody078086f2011-08-08 16:21:39 +00001778bfa_ioc_pf_hwfailed(struct bfa_ioc *ioc)
1779{
1780 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1781}
1782
1783static void
Rasesh Mody1d32f762010-12-23 21:45:09 +00001784bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc)
1785{
1786 /**
1787 * Provide enable completion callback and AEN notification.
1788 */
1789 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
1790}
1791
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001792/**
1793 * IOC public
1794 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001795static enum bfa_status
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001796bfa_ioc_pll_init(struct bfa_ioc *ioc)
1797{
1798 /*
1799 * Hold semaphore so that nobody can access the chip during init.
1800 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001801 bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001802
1803 bfa_ioc_pll_init_asic(ioc);
1804
1805 ioc->pllinit = true;
1806 /*
1807 * release semaphore.
1808 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001809 bfa_nw_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001810
1811 return BFA_STATUS_OK;
1812}
1813
1814/**
1815 * Interface used by diag module to do firmware boot with memory test
1816 * as the entry vector.
1817 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001818static void
Rasesh Mody078086f2011-08-08 16:21:39 +00001819bfa_ioc_boot(struct bfa_ioc *ioc, enum bfi_fwboot_type boot_type,
1820 u32 boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001821{
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001822 bfa_ioc_stats(ioc, ioc_boots);
1823
1824 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1825 return;
1826
1827 /**
1828 * Initialize IOC state of all functions on a chip reset.
1829 */
Rasesh Mody078086f2011-08-08 16:21:39 +00001830 if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
1831 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate);
1832 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001833 } else {
Rasesh Mody078086f2011-08-08 16:21:39 +00001834 writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate);
1835 writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001836 }
1837
1838 bfa_ioc_msgflush(ioc);
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001839 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001840 bfa_ioc_lpu_start(ioc);
1841}
1842
1843/**
1844 * Enable/disable IOC failure auto recovery.
1845 */
1846void
Rasesh Mody8a891422010-08-25 23:00:27 -07001847bfa_nw_ioc_auto_recover(bool auto_recover)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001848{
Rasesh Mody8a891422010-08-25 23:00:27 -07001849 bfa_nw_auto_recover = auto_recover;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001850}
1851
Rasesh Mody078086f2011-08-08 16:21:39 +00001852static bool
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001853bfa_ioc_msgget(struct bfa_ioc *ioc, void *mbmsg)
1854{
1855 u32 *msgp = mbmsg;
1856 u32 r32;
1857 int i;
1858
Rasesh Mody078086f2011-08-08 16:21:39 +00001859 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1860 if ((r32 & 1) == 0)
1861 return false;
1862
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001863 /**
1864 * read the MBOX msg
1865 */
1866 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1867 i++) {
1868 r32 = readl(ioc->ioc_regs.lpu_mbox +
1869 i * sizeof(u32));
1870 msgp[i] = htonl(r32);
1871 }
1872
1873 /**
1874 * turn off mailbox interrupt by clearing mailbox status
1875 */
1876 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1877 readl(ioc->ioc_regs.lpu_mbox_cmd);
Rasesh Mody078086f2011-08-08 16:21:39 +00001878
1879 return true;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001880}
1881
Rasesh Mody8a891422010-08-25 23:00:27 -07001882static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001883bfa_ioc_isr(struct bfa_ioc *ioc, struct bfi_mbmsg *m)
1884{
1885 union bfi_ioc_i2h_msg_u *msg;
Rasesh Mody1d32f762010-12-23 21:45:09 +00001886 struct bfa_iocpf *iocpf = &ioc->iocpf;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001887
1888 msg = (union bfi_ioc_i2h_msg_u *) m;
1889
1890 bfa_ioc_stats(ioc, ioc_isrs);
1891
1892 switch (msg->mh.msg_id) {
1893 case BFI_IOC_I2H_HBEAT:
1894 break;
1895
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001896 case BFI_IOC_I2H_ENABLE_REPLY:
Rasesh Mody078086f2011-08-08 16:21:39 +00001897 bfa_ioc_enable_reply(ioc,
1898 (enum bfa_mode)msg->fw_event.port_mode,
1899 msg->fw_event.cap_bm);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001900 break;
1901
1902 case BFI_IOC_I2H_DISABLE_REPLY:
Rasesh Mody1d32f762010-12-23 21:45:09 +00001903 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001904 break;
1905
1906 case BFI_IOC_I2H_GETATTR_REPLY:
1907 bfa_ioc_getattr_reply(ioc);
1908 break;
1909
1910 default:
1911 BUG_ON(1);
1912 }
1913}
1914
1915/**
1916 * IOC attach time initialization and setup.
1917 *
1918 * @param[in] ioc memory for IOC
1919 * @param[in] bfa driver instance structure
1920 */
1921void
Rasesh Mody8a891422010-08-25 23:00:27 -07001922bfa_nw_ioc_attach(struct bfa_ioc *ioc, void *bfa, struct bfa_ioc_cbfn *cbfn)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001923{
1924 ioc->bfa = bfa;
1925 ioc->cbfn = cbfn;
1926 ioc->fcmode = false;
1927 ioc->pllinit = false;
1928 ioc->dbg_fwsave_once = true;
Rasesh Mody1d32f762010-12-23 21:45:09 +00001929 ioc->iocpf.ioc = ioc;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001930
1931 bfa_ioc_mbox_attach(ioc);
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001932 INIT_LIST_HEAD(&ioc->notify_q);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001933
Rasesh Mody1d32f762010-12-23 21:45:09 +00001934 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
1935 bfa_fsm_send_event(ioc, IOC_E_RESET);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001936}
1937
1938/**
1939 * Driver detach time IOC cleanup.
1940 */
1941void
Rasesh Mody8a891422010-08-25 23:00:27 -07001942bfa_nw_ioc_detach(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001943{
1944 bfa_fsm_send_event(ioc, IOC_E_DETACH);
Rasesh Mody078086f2011-08-08 16:21:39 +00001945
1946 /* Done with detach, empty the notify_q. */
1947 INIT_LIST_HEAD(&ioc->notify_q);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001948}
1949
1950/**
1951 * Setup IOC PCI properties.
1952 *
1953 * @param[in] pcidev PCI device information for this IOC
1954 */
1955void
Rasesh Mody8a891422010-08-25 23:00:27 -07001956bfa_nw_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
Rasesh Mody078086f2011-08-08 16:21:39 +00001957 enum bfi_pcifn_class clscode)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001958{
Rasesh Mody078086f2011-08-08 16:21:39 +00001959 ioc->clscode = clscode;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001960 ioc->pcidev = *pcidev;
Rasesh Mody078086f2011-08-08 16:21:39 +00001961
1962 /**
1963 * Initialize IOC and device personality
1964 */
1965 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
1966 ioc->asic_mode = BFI_ASIC_MODE_FC;
1967
1968 switch (pcidev->device_id) {
1969 case PCI_DEVICE_ID_BROCADE_CT:
1970 ioc->asic_gen = BFI_ASIC_GEN_CT;
1971 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
1972 ioc->asic_mode = BFI_ASIC_MODE_ETH;
1973 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
1974 ioc->ad_cap_bm = BFA_CM_CNA;
1975 break;
1976
Rasesh Mody586b2812011-09-27 10:39:08 +00001977 case BFA_PCI_DEVICE_ID_CT2:
1978 ioc->asic_gen = BFI_ASIC_GEN_CT2;
1979 if (clscode == BFI_PCIFN_CLASS_FC &&
1980 pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
1981 ioc->asic_mode = BFI_ASIC_MODE_FC16;
1982 ioc->fcmode = true;
1983 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
1984 ioc->ad_cap_bm = BFA_CM_HBA;
1985 } else {
1986 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
1987 ioc->asic_mode = BFI_ASIC_MODE_ETH;
1988 if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
1989 ioc->port_mode =
1990 ioc->port_mode_cfg = BFA_MODE_CNA;
1991 ioc->ad_cap_bm = BFA_CM_CNA;
1992 } else {
1993 ioc->port_mode =
1994 ioc->port_mode_cfg = BFA_MODE_NIC;
1995 ioc->ad_cap_bm = BFA_CM_NIC;
1996 }
1997 }
1998 break;
1999
Rasesh Mody078086f2011-08-08 16:21:39 +00002000 default:
2001 BUG_ON(1);
2002 }
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002003
Rasesh Modybe3a84d2011-09-27 10:39:05 +00002004 /**
2005 * Set asic specific interfaces.
2006 */
2007 if (ioc->asic_gen == BFI_ASIC_GEN_CT)
2008 bfa_nw_ioc_set_ct_hwif(ioc);
2009 else
2010 bfa_nw_ioc_set_ct2_hwif(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002011
2012 bfa_ioc_map_port(ioc);
2013 bfa_ioc_reg_init(ioc);
2014}
2015
2016/**
2017 * Initialize IOC dma memory
2018 *
2019 * @param[in] dm_kva kernel virtual address of IOC dma memory
2020 * @param[in] dm_pa physical address of IOC dma memory
2021 */
2022void
Rasesh Mody8a891422010-08-25 23:00:27 -07002023bfa_nw_ioc_mem_claim(struct bfa_ioc *ioc, u8 *dm_kva, u64 dm_pa)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002024{
2025 /**
2026 * dma memory for firmware attribute
2027 */
2028 ioc->attr_dma.kva = dm_kva;
2029 ioc->attr_dma.pa = dm_pa;
2030 ioc->attr = (struct bfi_ioc_attr *) dm_kva;
2031}
2032
2033/**
2034 * Return size of dma memory required.
2035 */
2036u32
Rasesh Mody8a891422010-08-25 23:00:27 -07002037bfa_nw_ioc_meminfo(void)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002038{
2039 return roundup(sizeof(struct bfi_ioc_attr), BFA_DMA_ALIGN_SZ);
2040}
2041
2042void
Rasesh Mody8a891422010-08-25 23:00:27 -07002043bfa_nw_ioc_enable(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002044{
2045 bfa_ioc_stats(ioc, ioc_enables);
2046 ioc->dbg_fwsave_once = true;
2047
2048 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2049}
2050
2051void
Rasesh Mody8a891422010-08-25 23:00:27 -07002052bfa_nw_ioc_disable(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002053{
2054 bfa_ioc_stats(ioc, ioc_disables);
2055 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2056}
2057
Rasesh Mody8a891422010-08-25 23:00:27 -07002058static u32
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002059bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr)
2060{
2061 return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
2062}
2063
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002064/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002065 * Register mailbox message handler function, to be called by common modules
2066 */
2067void
Rasesh Mody8a891422010-08-25 23:00:27 -07002068bfa_nw_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002069 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2070{
2071 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
2072
2073 mod->mbhdlr[mc].cbfn = cbfn;
2074 mod->mbhdlr[mc].cbarg = cbarg;
2075}
2076
2077/**
2078 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2079 * Responsibility of caller to serialize
2080 *
2081 * @param[in] ioc IOC instance
2082 * @param[i] cmd Mailbox command
2083 */
Rasesh Modyaf027a32011-08-08 16:21:35 +00002084bool
2085bfa_nw_ioc_mbox_queue(struct bfa_ioc *ioc, struct bfa_mbox_cmd *cmd,
2086 bfa_mbox_cmd_cbfn_t cbfn, void *cbarg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002087{
2088 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
2089 u32 stat;
2090
Rasesh Modyaf027a32011-08-08 16:21:35 +00002091 cmd->cbfn = cbfn;
2092 cmd->cbarg = cbarg;
2093
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002094 /**
2095 * If a previous command is pending, queue new command
2096 */
2097 if (!list_empty(&mod->cmd_q)) {
2098 list_add_tail(&cmd->qe, &mod->cmd_q);
Rasesh Modyaf027a32011-08-08 16:21:35 +00002099 return true;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002100 }
2101
2102 /**
2103 * If mailbox is busy, queue command for poll timer
2104 */
2105 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
2106 if (stat) {
2107 list_add_tail(&cmd->qe, &mod->cmd_q);
Rasesh Modyaf027a32011-08-08 16:21:35 +00002108 return true;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002109 }
2110
2111 /**
2112 * mailbox is free -- queue command to firmware
2113 */
2114 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
Rasesh Modybd5a92e2011-07-22 08:07:42 +00002115
Rasesh Modyaf027a32011-08-08 16:21:35 +00002116 return false;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002117}
2118
2119/**
2120 * Handle mailbox interrupts
2121 */
2122void
Rasesh Mody8a891422010-08-25 23:00:27 -07002123bfa_nw_ioc_mbox_isr(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002124{
2125 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
2126 struct bfi_mbmsg m;
2127 int mc;
2128
Rasesh Mody078086f2011-08-08 16:21:39 +00002129 if (bfa_ioc_msgget(ioc, &m)) {
2130 /**
2131 * Treat IOC message class as special.
2132 */
2133 mc = m.mh.msg_class;
2134 if (mc == BFI_MC_IOC) {
2135 bfa_ioc_isr(ioc, &m);
2136 return;
2137 }
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002138
Rasesh Mody078086f2011-08-08 16:21:39 +00002139 if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2140 return;
2141
2142 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002143 }
2144
Rasesh Mody078086f2011-08-08 16:21:39 +00002145 bfa_ioc_lpu_read_stat(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002146
Rasesh Mody078086f2011-08-08 16:21:39 +00002147 /**
2148 * Try to send pending mailbox commands
2149 */
2150 bfa_ioc_mbox_poll(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002151}
2152
2153void
Rasesh Mody8a891422010-08-25 23:00:27 -07002154bfa_nw_ioc_error_isr(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002155{
Rasesh Mody9b08a4f2011-07-22 08:07:48 +00002156 bfa_ioc_stats(ioc, ioc_hbfails);
2157 bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002158 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2159}
2160
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002161/**
Rasesh Modybd5a92e2011-07-22 08:07:42 +00002162 * return true if IOC is disabled
2163 */
2164bool
2165bfa_nw_ioc_is_disabled(struct bfa_ioc *ioc)
2166{
2167 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2168 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
2169}
2170
2171/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002172 * Add to IOC heartbeat failure notification queue. To be used by common
2173 * modules such as cee, port, diag.
2174 */
2175void
Rasesh Modybd5a92e2011-07-22 08:07:42 +00002176bfa_nw_ioc_notify_register(struct bfa_ioc *ioc,
2177 struct bfa_ioc_notify *notify)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002178{
Rasesh Modybd5a92e2011-07-22 08:07:42 +00002179 list_add_tail(&notify->qe, &ioc->notify_q);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002180}
2181
2182#define BFA_MFG_NAME "Brocade"
Rasesh Mody8a891422010-08-25 23:00:27 -07002183static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002184bfa_ioc_get_adapter_attr(struct bfa_ioc *ioc,
2185 struct bfa_adapter_attr *ad_attr)
2186{
2187 struct bfi_ioc_attr *ioc_attr;
2188
2189 ioc_attr = ioc->attr;
2190
2191 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2192 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2193 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2194 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
2195 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
2196 sizeof(struct bfa_mfg_vpd));
2197
2198 ad_attr->nports = bfa_ioc_get_nports(ioc);
2199 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
2200
2201 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2202 /* For now, model descr uses same model string */
2203 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
2204
2205 ad_attr->card_type = ioc_attr->card_type;
2206 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2207
2208 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2209 ad_attr->prototype = 1;
2210 else
2211 ad_attr->prototype = 0;
2212
2213 ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
Rasesh Mody8a891422010-08-25 23:00:27 -07002214 ad_attr->mac = bfa_nw_ioc_get_mac(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002215
2216 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2217 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2218 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2219 ad_attr->asic_rev = ioc_attr->asic_rev;
2220
2221 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002222}
2223
Rasesh Mody8a891422010-08-25 23:00:27 -07002224static enum bfa_ioc_type
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002225bfa_ioc_get_type(struct bfa_ioc *ioc)
2226{
Rasesh Mody078086f2011-08-08 16:21:39 +00002227 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002228 return BFA_IOC_TYPE_LL;
Rasesh Mody078086f2011-08-08 16:21:39 +00002229
2230 BUG_ON(!(ioc->clscode == BFI_PCIFN_CLASS_FC));
2231
2232 return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
2233 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002234}
2235
Rasesh Mody8a891422010-08-25 23:00:27 -07002236static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002237bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc, char *serial_num)
2238{
2239 memset(serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2240 memcpy(serial_num,
2241 (void *)ioc->attr->brcd_serialnum,
2242 BFA_ADAPTER_SERIAL_NUM_LEN);
2243}
2244
Rasesh Mody8a891422010-08-25 23:00:27 -07002245static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002246bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc, char *fw_ver)
2247{
2248 memset(fw_ver, 0, BFA_VERSION_LEN);
2249 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
2250}
2251
Rasesh Mody8a891422010-08-25 23:00:27 -07002252static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002253bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc, char *chip_rev)
2254{
2255 BUG_ON(!(chip_rev));
2256
2257 memset(chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
2258
2259 chip_rev[0] = 'R';
2260 chip_rev[1] = 'e';
2261 chip_rev[2] = 'v';
2262 chip_rev[3] = '-';
2263 chip_rev[4] = ioc->attr->asic_rev;
2264 chip_rev[5] = '\0';
2265}
2266
Rasesh Mody8a891422010-08-25 23:00:27 -07002267static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002268bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver)
2269{
2270 memset(optrom_ver, 0, BFA_VERSION_LEN);
2271 memcpy(optrom_ver, ioc->attr->optrom_version,
2272 BFA_VERSION_LEN);
2273}
2274
Rasesh Mody8a891422010-08-25 23:00:27 -07002275static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002276bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer)
2277{
2278 memset(manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2279 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
2280}
2281
Rasesh Mody8a891422010-08-25 23:00:27 -07002282static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002283bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model)
2284{
2285 struct bfi_ioc_attr *ioc_attr;
2286
2287 BUG_ON(!(model));
2288 memset(model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
2289
2290 ioc_attr = ioc->attr;
2291
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002292 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2293 BFA_MFG_NAME, ioc_attr->card_type);
2294}
2295
Rasesh Mody8a891422010-08-25 23:00:27 -07002296static enum bfa_ioc_state
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002297bfa_ioc_get_state(struct bfa_ioc *ioc)
2298{
Rasesh Mody1d32f762010-12-23 21:45:09 +00002299 enum bfa_iocpf_state iocpf_st;
2300 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2301
2302 if (ioc_st == BFA_IOC_ENABLING ||
2303 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2304
2305 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2306
2307 switch (iocpf_st) {
2308 case BFA_IOCPF_SEMWAIT:
2309 ioc_st = BFA_IOC_SEMWAIT;
2310 break;
2311
2312 case BFA_IOCPF_HWINIT:
2313 ioc_st = BFA_IOC_HWINIT;
2314 break;
2315
2316 case BFA_IOCPF_FWMISMATCH:
2317 ioc_st = BFA_IOC_FWMISMATCH;
2318 break;
2319
2320 case BFA_IOCPF_FAIL:
2321 ioc_st = BFA_IOC_FAIL;
2322 break;
2323
2324 case BFA_IOCPF_INITFAIL:
2325 ioc_st = BFA_IOC_INITFAIL;
2326 break;
2327
2328 default:
2329 break;
2330 }
2331 }
2332 return ioc_st;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002333}
2334
2335void
Rasesh Mody8a891422010-08-25 23:00:27 -07002336bfa_nw_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002337{
2338 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr));
2339
2340 ioc_attr->state = bfa_ioc_get_state(ioc);
2341 ioc_attr->port_id = ioc->port_id;
Rasesh Mody078086f2011-08-08 16:21:39 +00002342 ioc_attr->port_mode = ioc->port_mode;
2343
2344 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2345 ioc_attr->cap_bm = ioc->ad_cap_bm;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002346
2347 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
2348
2349 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2350
2351 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2352 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
2353 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
2354}
2355
2356/**
2357 * WWN public
2358 */
Rasesh Mody8a891422010-08-25 23:00:27 -07002359static u64
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002360bfa_ioc_get_pwwn(struct bfa_ioc *ioc)
2361{
2362 return ioc->attr->pwwn;
2363}
2364
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002365mac_t
Rasesh Mody8a891422010-08-25 23:00:27 -07002366bfa_nw_ioc_get_mac(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002367{
Rasesh Mody2c7d3822010-12-23 21:45:06 +00002368 return ioc->attr->mac;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002369}
2370
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002371/**
2372 * Firmware failure detected. Start recovery actions.
2373 */
2374static void
2375bfa_ioc_recover(struct bfa_ioc *ioc)
2376{
Rasesh Mody1e581482011-04-04 08:29:59 +00002377 pr_crit("Heart Beat of IOC has failed\n");
2378 bfa_ioc_stats(ioc, ioc_hbfails);
Rasesh Mody9b08a4f2011-07-22 08:07:48 +00002379 bfa_ioc_stats_hb_count(ioc, ioc->hb_count);
Rasesh Mody1e581482011-04-04 08:29:59 +00002380 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002381}
2382
2383static void
2384bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc)
2385{
2386 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2387 return;
Rasesh Mody1d32f762010-12-23 21:45:09 +00002388}
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002389
Rasesh Mody1d32f762010-12-23 21:45:09 +00002390/**
2391 * @dg hal_iocpf_pvt BFA IOC PF private functions
2392 * @{
2393 */
2394
2395static void
2396bfa_iocpf_enable(struct bfa_ioc *ioc)
2397{
2398 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
2399}
2400
2401static void
2402bfa_iocpf_disable(struct bfa_ioc *ioc)
2403{
2404 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
2405}
2406
2407static void
2408bfa_iocpf_fail(struct bfa_ioc *ioc)
2409{
2410 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
2411}
2412
2413static void
2414bfa_iocpf_initfail(struct bfa_ioc *ioc)
2415{
2416 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
2417}
2418
2419static void
2420bfa_iocpf_getattrfail(struct bfa_ioc *ioc)
2421{
2422 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
2423}
2424
2425static void
2426bfa_iocpf_stop(struct bfa_ioc *ioc)
2427{
2428 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
2429}
2430
2431void
2432bfa_nw_iocpf_timeout(void *ioc_arg)
2433{
2434 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
Rasesh Mody078086f2011-08-08 16:21:39 +00002435 enum bfa_iocpf_state iocpf_st;
Rasesh Mody1d32f762010-12-23 21:45:09 +00002436
Rasesh Mody078086f2011-08-08 16:21:39 +00002437 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2438
2439 if (iocpf_st == BFA_IOCPF_HWINIT)
2440 bfa_ioc_poll_fwinit(ioc);
2441 else
2442 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
Rasesh Mody1d32f762010-12-23 21:45:09 +00002443}
2444
2445void
2446bfa_nw_iocpf_sem_timeout(void *ioc_arg)
2447{
2448 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
2449
2450 bfa_ioc_hw_sem_get(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002451}
Rasesh Mody078086f2011-08-08 16:21:39 +00002452
2453static void
2454bfa_ioc_poll_fwinit(struct bfa_ioc *ioc)
2455{
2456 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
2457
2458 if (fwstate == BFI_IOC_DISABLED) {
2459 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2460 return;
2461 }
2462
2463 if (ioc->iocpf.poll_time >= BFA_IOC_TOV) {
2464 bfa_nw_iocpf_timeout(ioc);
2465 } else {
2466 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2467 mod_timer(&ioc->iocpf_timer, jiffies +
2468 msecs_to_jiffies(BFA_IOC_POLL_TOV));
2469 }
2470}