blob: c3b62a3753f967b7670feef83988e8f3603e4004 [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"
20#include "cna.h"
21#include "bfi.h"
22#include "bfi_ctreg.h"
23#include "bfa_defs.h"
24
25/**
26 * IOC local definitions
27 */
28
Rasesh Mody8b230ed2010-08-23 20:24:12 -070029/**
30 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
31 */
32
33#define bfa_ioc_firmware_lock(__ioc) \
34 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
35#define bfa_ioc_firmware_unlock(__ioc) \
36 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
37#define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
38#define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
Rasesh Mody1d32f762010-12-23 21:45:09 +000039#define bfa_ioc_notify_fail(__ioc) \
40 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
Rasesh Mody79ea6c82011-04-14 08:05:18 +000041#define bfa_ioc_sync_start(__ioc) \
42 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
Rasesh Mody1d32f762010-12-23 21:45:09 +000043#define bfa_ioc_sync_join(__ioc) \
44 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
45#define bfa_ioc_sync_leave(__ioc) \
46 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
47#define bfa_ioc_sync_ack(__ioc) \
48 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
49#define bfa_ioc_sync_complete(__ioc) \
50 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
Rasesh Mody8b230ed2010-08-23 20:24:12 -070051
Rasesh Mody8b230ed2010-08-23 20:24:12 -070052#define bfa_ioc_mbox_cmd_pending(__ioc) \
53 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
54 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
55
Rasesh Modyb7ee31c52010-10-05 15:46:05 +000056static bool bfa_nw_auto_recover = true;
Rasesh Mody8b230ed2010-08-23 20:24:12 -070057
58/*
59 * forward declarations
60 */
Rasesh Modyd4e16d42011-07-22 08:07:47 +000061static void bfa_ioc_hw_sem_init(struct bfa_ioc *ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070062static void bfa_ioc_hw_sem_get(struct bfa_ioc *ioc);
63static void bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc);
64static void bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force);
65static void bfa_ioc_send_enable(struct bfa_ioc *ioc);
66static void bfa_ioc_send_disable(struct bfa_ioc *ioc);
67static void bfa_ioc_send_getattr(struct bfa_ioc *ioc);
68static void bfa_ioc_hb_monitor(struct bfa_ioc *ioc);
69static void bfa_ioc_hb_stop(struct bfa_ioc *ioc);
70static void bfa_ioc_reset(struct bfa_ioc *ioc, bool force);
71static void bfa_ioc_mbox_poll(struct bfa_ioc *ioc);
Rasesh Modyfdad4002011-07-22 08:07:45 +000072static void bfa_ioc_mbox_flush(struct bfa_ioc *ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070073static void bfa_ioc_recover(struct bfa_ioc *ioc);
74static void bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc);
Rasesh Modybd5a92e2011-07-22 08:07:42 +000075static void bfa_ioc_event_notify(struct bfa_ioc *, enum bfa_ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070076static void bfa_ioc_disable_comp(struct bfa_ioc *ioc);
77static void bfa_ioc_lpu_stop(struct bfa_ioc *ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +000078static void bfa_ioc_fail_notify(struct bfa_ioc *ioc);
79static void bfa_ioc_pf_enabled(struct bfa_ioc *ioc);
80static void bfa_ioc_pf_disabled(struct bfa_ioc *ioc);
81static void bfa_ioc_pf_initfailed(struct bfa_ioc *ioc);
82static void bfa_ioc_pf_failed(struct bfa_ioc *ioc);
83static void bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc);
Rasesh Mody8a891422010-08-25 23:00:27 -070084static void bfa_ioc_boot(struct bfa_ioc *ioc, u32 boot_type,
85 u32 boot_param);
86static u32 bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr);
Rasesh Mody8a891422010-08-25 23:00:27 -070087static void bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc,
88 char *serial_num);
89static void bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc,
90 char *fw_ver);
91static void bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc,
92 char *chip_rev);
93static void bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc,
94 char *optrom_ver);
95static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc,
96 char *manufacturer);
97static void bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model);
98static u64 bfa_ioc_get_pwwn(struct bfa_ioc *ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -070099
100/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000101 * IOC state machine definitions/declarations
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700102 */
103enum ioc_event {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000104 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 */
111 IOC_E_INITFAILED = 8, /*!< failure notice by iocpf sm */
Rasesh Modyf374b362011-07-22 08:07:46 +0000112 IOC_E_PFFAILED = 9, /*!< failure notice by iocpf sm */
Rasesh Mody1d32f762010-12-23 21:45:09 +0000113 IOC_E_HBFAIL = 10, /*!< heartbeat failure */
114 IOC_E_HWERROR = 11, /*!< hardware error interrupt */
115 IOC_E_TIMEOUT = 12, /*!< timeout */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700116};
117
Rasesh Mody1d32f762010-12-23 21:45:09 +0000118bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc, enum ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700119bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc, enum ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700120bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc, enum ioc_event);
121bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc, enum ioc_event);
122bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc, enum ioc_event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000123bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc, enum ioc_event);
124bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc, enum ioc_event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700125bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc, enum ioc_event);
126bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc, enum ioc_event);
127
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},
138};
139
140/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000141 * IOCPF state machine definitions/declarations
142 */
143
144/*
145 * Forward declareations for iocpf state machine
146 */
147static void bfa_iocpf_enable(struct bfa_ioc *ioc);
148static void bfa_iocpf_disable(struct bfa_ioc *ioc);
149static void bfa_iocpf_fail(struct bfa_ioc *ioc);
150static void bfa_iocpf_initfail(struct bfa_ioc *ioc);
151static void bfa_iocpf_getattrfail(struct bfa_ioc *ioc);
152static void bfa_iocpf_stop(struct bfa_ioc *ioc);
153
154/**
155 * IOCPF state machine events
156 */
157enum iocpf_event {
158 IOCPF_E_ENABLE = 1, /*!< IOCPF enable request */
159 IOCPF_E_DISABLE = 2, /*!< IOCPF disable request */
160 IOCPF_E_STOP = 3, /*!< stop on driver detach */
Rasesh Mody0120b992011-07-22 08:07:41 +0000161 IOCPF_E_FWREADY = 4, /*!< f/w initialization done */
Rasesh Mody1d32f762010-12-23 21:45:09 +0000162 IOCPF_E_FWRSP_ENABLE = 5, /*!< enable f/w response */
163 IOCPF_E_FWRSP_DISABLE = 6, /*!< disable f/w response */
164 IOCPF_E_FAIL = 7, /*!< failure notice by ioc sm */
165 IOCPF_E_INITFAIL = 8, /*!< init fail notice by ioc sm */
166 IOCPF_E_GETATTRFAIL = 9, /*!< init fail notice by ioc sm */
167 IOCPF_E_SEMLOCKED = 10, /*!< h/w semaphore is locked */
168 IOCPF_E_TIMEOUT = 11, /*!< f/w response timeout */
169};
170
171/**
172 * IOCPF states
173 */
174enum bfa_iocpf_state {
175 BFA_IOCPF_RESET = 1, /*!< IOC is in reset state */
176 BFA_IOCPF_SEMWAIT = 2, /*!< Waiting for IOC h/w semaphore */
177 BFA_IOCPF_HWINIT = 3, /*!< IOC h/w is being initialized */
178 BFA_IOCPF_READY = 4, /*!< IOCPF is initialized */
179 BFA_IOCPF_INITFAIL = 5, /*!< IOCPF failed */
180 BFA_IOCPF_FAIL = 6, /*!< IOCPF failed */
181 BFA_IOCPF_DISABLING = 7, /*!< IOCPF is being disabled */
182 BFA_IOCPF_DISABLED = 8, /*!< IOCPF is disabled */
183 BFA_IOCPF_FWMISMATCH = 9, /*!< IOC f/w different from drivers */
184};
185
186bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf, enum iocpf_event);
187bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf, enum iocpf_event);
188bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf, enum iocpf_event);
189bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf, enum iocpf_event);
190bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf, enum iocpf_event);
191bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf, enum iocpf_event);
192bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf, enum iocpf_event);
193bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf,
194 enum iocpf_event);
195bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf, enum iocpf_event);
196bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf, enum iocpf_event);
197bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf, enum iocpf_event);
198bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf, enum iocpf_event);
199bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf,
200 enum iocpf_event);
201bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf, enum iocpf_event);
202
203static struct bfa_sm_table iocpf_sm_table[] = {
204 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
205 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
206 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
207 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
208 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
209 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
210 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
211 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
212 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
213 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
214 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
215 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
216 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
217 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
218};
219
220/**
221 * IOC State Machine
222 */
223
224/**
225 * Beginning state. IOC uninit state.
226 */
227static void
228bfa_ioc_sm_uninit_entry(struct bfa_ioc *ioc)
229{
230}
231
232/**
233 * IOC is in uninit state.
234 */
235static void
236bfa_ioc_sm_uninit(struct bfa_ioc *ioc, enum ioc_event event)
237{
238 switch (event) {
239 case IOC_E_RESET:
240 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
241 break;
242
243 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000244 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000245 }
246}
247
248/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700249 * Reset entry actions -- initialize state machine
250 */
251static void
252bfa_ioc_sm_reset_entry(struct bfa_ioc *ioc)
253{
Rasesh Mody1d32f762010-12-23 21:45:09 +0000254 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700255}
256
257/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000258 * IOC is in reset state.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700259 */
260static void
261bfa_ioc_sm_reset(struct bfa_ioc *ioc, enum ioc_event event)
262{
263 switch (event) {
264 case IOC_E_ENABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000265 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700266 break;
267
268 case IOC_E_DISABLE:
269 bfa_ioc_disable_comp(ioc);
270 break;
271
272 case IOC_E_DETACH:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000273 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
274 break;
275
276 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000277 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000278 }
279}
280
281static void
282bfa_ioc_sm_enabling_entry(struct bfa_ioc *ioc)
283{
284 bfa_iocpf_enable(ioc);
285}
286
287/**
288 * Host IOC function is being enabled, awaiting response from firmware.
289 * Semaphore is acquired.
290 */
291static void
292bfa_ioc_sm_enabling(struct bfa_ioc *ioc, enum ioc_event event)
293{
294 switch (event) {
295 case IOC_E_ENABLED:
296 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
297 break;
298
Rasesh Modyf374b362011-07-22 08:07:46 +0000299 case IOC_E_PFFAILED:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000300 /* !!! fall through !!! */
301 case IOC_E_HWERROR:
302 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
303 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
Rasesh Modyf374b362011-07-22 08:07:46 +0000304 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000305 bfa_iocpf_initfail(ioc);
306 break;
307
308 case IOC_E_DISABLE:
309 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
310 break;
311
312 case IOC_E_DETACH:
313 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
314 bfa_iocpf_stop(ioc);
315 break;
316
317 case IOC_E_ENABLE:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700318 break;
319
320 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000321 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700322 }
323}
324
325/**
326 * Semaphore should be acquired for version check.
327 */
328static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700329bfa_ioc_sm_getattr_entry(struct bfa_ioc *ioc)
330{
Rasesh Mody1d32f762010-12-23 21:45:09 +0000331 mod_timer(&ioc->ioc_timer, jiffies +
332 msecs_to_jiffies(BFA_IOC_TOV));
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700333 bfa_ioc_send_getattr(ioc);
334}
335
336/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700337 * IOC configuration in progress. Timer is active.
338 */
339static void
340bfa_ioc_sm_getattr(struct bfa_ioc *ioc, enum ioc_event event)
341{
342 switch (event) {
343 case IOC_E_FWRSP_GETATTR:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000344 del_timer(&ioc->ioc_timer);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700345 bfa_ioc_check_attr_wwns(ioc);
346 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
347 break;
348
Rasesh Modyf374b362011-07-22 08:07:46 +0000349 case IOC_E_PFFAILED:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700350 case IOC_E_HWERROR:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000351 del_timer(&ioc->ioc_timer);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700352 /* fall through */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700353 case IOC_E_TIMEOUT:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000354 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
355 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
Rasesh Modyf374b362011-07-22 08:07:46 +0000356 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000357 bfa_iocpf_getattrfail(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700358 break;
359
360 case IOC_E_DISABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000361 del_timer(&ioc->ioc_timer);
362 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
363 break;
364
365 case IOC_E_ENABLE:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700366 break;
367
368 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000369 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700370 }
371}
372
373static void
374bfa_ioc_sm_op_entry(struct bfa_ioc *ioc)
375{
376 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
377 bfa_ioc_hb_monitor(ioc);
378}
379
380static void
381bfa_ioc_sm_op(struct bfa_ioc *ioc, enum ioc_event event)
382{
383 switch (event) {
384 case IOC_E_ENABLE:
385 break;
386
387 case IOC_E_DISABLE:
388 bfa_ioc_hb_stop(ioc);
389 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
390 break;
391
Rasesh Modyf374b362011-07-22 08:07:46 +0000392 case IOC_E_PFFAILED:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700393 case IOC_E_HWERROR:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700394 bfa_ioc_hb_stop(ioc);
395 /* !!! fall through !!! */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700396 case IOC_E_HBFAIL:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000397 bfa_ioc_fail_notify(ioc);
398 if (ioc->iocpf.auto_recover)
399 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
400 else
401 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
402
Rasesh Modyf374b362011-07-22 08:07:46 +0000403 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000404 bfa_iocpf_fail(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700405 break;
406
407 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000408 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700409 }
410}
411
412static void
413bfa_ioc_sm_disabling_entry(struct bfa_ioc *ioc)
414{
Rasesh Mody1d32f762010-12-23 21:45:09 +0000415 bfa_iocpf_disable(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700416}
417
418/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000419 * IOC is being desabled
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700420 */
421static void
422bfa_ioc_sm_disabling(struct bfa_ioc *ioc, enum ioc_event event)
423{
424 switch (event) {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000425 case IOC_E_DISABLED:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700426 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
427 break;
428
429 case IOC_E_HWERROR:
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700430 /*
Rasesh Mody1d32f762010-12-23 21:45:09 +0000431 * No state change. Will move to disabled state
432 * after iocpf sm completes failure processing and
433 * moves to disabled state.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700434 */
Rasesh Mody1d32f762010-12-23 21:45:09 +0000435 bfa_iocpf_fail(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700436 break;
437
438 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000439 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700440 }
441}
442
443/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000444 * IOC desable completion entry.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700445 */
446static void
447bfa_ioc_sm_disabled_entry(struct bfa_ioc *ioc)
448{
449 bfa_ioc_disable_comp(ioc);
450}
451
452static void
453bfa_ioc_sm_disabled(struct bfa_ioc *ioc, enum ioc_event event)
454{
455 switch (event) {
456 case IOC_E_ENABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000457 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700458 break;
459
460 case IOC_E_DISABLE:
461 ioc->cbfn->disable_cbfn(ioc->bfa);
462 break;
463
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700464 case IOC_E_DETACH:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000465 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
466 bfa_iocpf_stop(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700467 break;
468
469 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000470 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700471 }
472}
473
474static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000475bfa_ioc_sm_fail_retry_entry(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700476{
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700477}
478
479/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000480 * Hardware initialization retry.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700481 */
482static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000483bfa_ioc_sm_fail_retry(struct bfa_ioc *ioc, enum ioc_event event)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700484{
485 switch (event) {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000486 case IOC_E_ENABLED:
487 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
488 break;
489
Rasesh Modyf374b362011-07-22 08:07:46 +0000490 case IOC_E_PFFAILED:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000491 case IOC_E_HWERROR:
492 /**
493 * Initialization retry failed.
494 */
495 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Rasesh Modyf374b362011-07-22 08:07:46 +0000496 if (event != IOC_E_PFFAILED)
Rasesh Mody1d32f762010-12-23 21:45:09 +0000497 bfa_iocpf_initfail(ioc);
498 break;
499
500 case IOC_E_INITFAILED:
501 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
502 break;
503
504 case IOC_E_ENABLE:
505 break;
506
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700507 case IOC_E_DISABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000508 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700509 break;
510
511 case IOC_E_DETACH:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000512 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
513 bfa_iocpf_stop(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700514 break;
515
516 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000517 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700518 }
519}
520
521static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000522bfa_ioc_sm_fail_entry(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700523{
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700524}
525
526/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000527 * IOC failure.
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700528 */
529static void
Rasesh Mody1d32f762010-12-23 21:45:09 +0000530bfa_ioc_sm_fail(struct bfa_ioc *ioc, enum ioc_event event)
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700531{
532 switch (event) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700533 case IOC_E_ENABLE:
534 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
535 break;
536
537 case IOC_E_DISABLE:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000538 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700539 break;
540
Rasesh Mody1d32f762010-12-23 21:45:09 +0000541 case IOC_E_DETACH:
542 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
543 bfa_iocpf_stop(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700544 break;
545
546 case IOC_E_HWERROR:
Rasesh Mody1d32f762010-12-23 21:45:09 +0000547 /* HB failure notification, ignore. */
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700548 break;
Rasesh Mody1d32f762010-12-23 21:45:09 +0000549
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700550 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000551 bfa_sm_fault(event);
Rasesh Mody8b230ed2010-08-23 20:24:12 -0700552 }
553}
554
555/**
Rasesh Mody1d32f762010-12-23 21:45:09 +0000556 * IOCPF State Machine
557 */
558
559/**
560 * Reset entry actions -- initialize state machine
561 */
562static void
563bfa_iocpf_sm_reset_entry(struct bfa_iocpf *iocpf)
564{
565 iocpf->retry_count = 0;
566 iocpf->auto_recover = bfa_nw_auto_recover;
567}
568
569/**
570 * Beginning state. IOC is in reset state.
571 */
572static void
573bfa_iocpf_sm_reset(struct bfa_iocpf *iocpf, enum iocpf_event event)
574{
575 switch (event) {
576 case IOCPF_E_ENABLE:
577 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
578 break;
579
580 case IOCPF_E_STOP:
581 break;
582
583 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000584 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000585 }
586}
587
588/**
589 * Semaphore should be acquired for version check.
590 */
591static void
592bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf *iocpf)
593{
Rasesh Modyd4e16d42011-07-22 08:07:47 +0000594 bfa_ioc_hw_sem_init(iocpf->ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000595 bfa_ioc_hw_sem_get(iocpf->ioc);
596}
597
598/**
599 * Awaiting h/w semaphore to continue with version check.
600 */
601static void
602bfa_iocpf_sm_fwcheck(struct bfa_iocpf *iocpf, enum iocpf_event event)
603{
604 struct bfa_ioc *ioc = iocpf->ioc;
605
606 switch (event) {
607 case IOCPF_E_SEMLOCKED:
608 if (bfa_ioc_firmware_lock(ioc)) {
Rasesh Mody79ea6c82011-04-14 08:05:18 +0000609 if (bfa_ioc_sync_start(ioc)) {
Rasesh Mody1d32f762010-12-23 21:45:09 +0000610 iocpf->retry_count = 0;
611 bfa_ioc_sync_join(ioc);
612 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
613 } else {
614 bfa_ioc_firmware_unlock(ioc);
615 bfa_nw_ioc_hw_sem_release(ioc);
616 mod_timer(&ioc->sem_timer, jiffies +
617 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
618 }
619 } else {
620 bfa_nw_ioc_hw_sem_release(ioc);
621 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
622 }
623 break;
624
625 case IOCPF_E_DISABLE:
626 bfa_ioc_hw_sem_get_cancel(ioc);
627 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
628 bfa_ioc_pf_disabled(ioc);
629 break;
630
631 case IOCPF_E_STOP:
632 bfa_ioc_hw_sem_get_cancel(ioc);
633 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
634 break;
635
636 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000637 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000638 }
639}
640
641/**
642 * Notify enable completion callback
643 */
644static void
645bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf *iocpf)
646{
647 /* Call only the first time sm enters fwmismatch state. */
648 if (iocpf->retry_count == 0)
649 bfa_ioc_pf_fwmismatch(iocpf->ioc);
650
651 iocpf->retry_count++;
652 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
653 msecs_to_jiffies(BFA_IOC_TOV));
654}
655
656/**
657 * Awaiting firmware version match.
658 */
659static void
660bfa_iocpf_sm_mismatch(struct bfa_iocpf *iocpf, enum iocpf_event event)
661{
662 struct bfa_ioc *ioc = iocpf->ioc;
663
664 switch (event) {
665 case IOCPF_E_TIMEOUT:
666 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
667 break;
668
669 case IOCPF_E_DISABLE:
670 del_timer(&ioc->iocpf_timer);
671 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
672 bfa_ioc_pf_disabled(ioc);
673 break;
674
675 case IOCPF_E_STOP:
676 del_timer(&ioc->iocpf_timer);
677 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
678 break;
679
680 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000681 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000682 }
683}
684
685/**
686 * Request for semaphore.
687 */
688static void
689bfa_iocpf_sm_semwait_entry(struct bfa_iocpf *iocpf)
690{
691 bfa_ioc_hw_sem_get(iocpf->ioc);
692}
693
694/**
695 * Awaiting semaphore for h/w initialzation.
696 */
697static void
698bfa_iocpf_sm_semwait(struct bfa_iocpf *iocpf, enum iocpf_event event)
699{
700 struct bfa_ioc *ioc = iocpf->ioc;
701
702 switch (event) {
703 case IOCPF_E_SEMLOCKED:
704 if (bfa_ioc_sync_complete(ioc)) {
705 bfa_ioc_sync_join(ioc);
706 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
707 } else {
708 bfa_nw_ioc_hw_sem_release(ioc);
709 mod_timer(&ioc->sem_timer, jiffies +
710 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
711 }
712 break;
713
714 case IOCPF_E_DISABLE:
715 bfa_ioc_hw_sem_get_cancel(ioc);
716 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
717 break;
718
719 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000720 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000721 }
722}
723
724static void
725bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf *iocpf)
726{
727 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
728 msecs_to_jiffies(BFA_IOC_TOV));
729 bfa_ioc_reset(iocpf->ioc, 0);
730}
731
732/**
733 * Hardware is being initialized. Interrupts are enabled.
734 * Holding hardware semaphore lock.
735 */
736static void
737bfa_iocpf_sm_hwinit(struct bfa_iocpf *iocpf, enum iocpf_event event)
738{
739 struct bfa_ioc *ioc = iocpf->ioc;
740
741 switch (event) {
742 case IOCPF_E_FWREADY:
743 del_timer(&ioc->iocpf_timer);
744 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
745 break;
746
747 case IOCPF_E_INITFAIL:
748 del_timer(&ioc->iocpf_timer);
749 /*
750 * !!! fall through !!!
751 */
752
753 case IOCPF_E_TIMEOUT:
754 bfa_nw_ioc_hw_sem_release(ioc);
755 if (event == IOCPF_E_TIMEOUT)
756 bfa_ioc_pf_failed(ioc);
757 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
758 break;
759
760 case IOCPF_E_DISABLE:
761 del_timer(&ioc->iocpf_timer);
762 bfa_ioc_sync_leave(ioc);
763 bfa_nw_ioc_hw_sem_release(ioc);
764 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
765 break;
766
767 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000768 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000769 }
770}
771
772static void
773bfa_iocpf_sm_enabling_entry(struct bfa_iocpf *iocpf)
774{
775 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
776 msecs_to_jiffies(BFA_IOC_TOV));
777 bfa_ioc_send_enable(iocpf->ioc);
778}
779
780/**
781 * Host IOC function is being enabled, awaiting response from firmware.
782 * Semaphore is acquired.
783 */
784static void
785bfa_iocpf_sm_enabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
786{
787 struct bfa_ioc *ioc = iocpf->ioc;
788
789 switch (event) {
790 case IOCPF_E_FWRSP_ENABLE:
791 del_timer(&ioc->iocpf_timer);
792 bfa_nw_ioc_hw_sem_release(ioc);
793 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
794 break;
795
796 case IOCPF_E_INITFAIL:
797 del_timer(&ioc->iocpf_timer);
798 /*
799 * !!! fall through !!!
800 */
801 case IOCPF_E_TIMEOUT:
802 bfa_nw_ioc_hw_sem_release(ioc);
803 if (event == IOCPF_E_TIMEOUT)
804 bfa_ioc_pf_failed(ioc);
805 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
806 break;
807
808 case IOCPF_E_DISABLE:
809 del_timer(&ioc->iocpf_timer);
810 bfa_nw_ioc_hw_sem_release(ioc);
811 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
812 break;
813
814 case IOCPF_E_FWREADY:
815 bfa_ioc_send_enable(ioc);
816 break;
817
818 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000819 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000820 }
821}
822
823static bool
824bfa_nw_ioc_is_operational(struct bfa_ioc *ioc)
825{
826 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
827}
828
829static void
830bfa_iocpf_sm_ready_entry(struct bfa_iocpf *iocpf)
831{
832 bfa_ioc_pf_enabled(iocpf->ioc);
833}
834
835static void
836bfa_iocpf_sm_ready(struct bfa_iocpf *iocpf, enum iocpf_event event)
837{
838 struct bfa_ioc *ioc = iocpf->ioc;
839
840 switch (event) {
841 case IOCPF_E_DISABLE:
842 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
843 break;
844
845 case IOCPF_E_GETATTRFAIL:
846 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
847 break;
848
849 case IOCPF_E_FAIL:
850 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
851 break;
852
853 case IOCPF_E_FWREADY:
854 bfa_ioc_pf_failed(ioc);
855 if (bfa_nw_ioc_is_operational(ioc))
856 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
857 else
858 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
859 break;
860
861 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000862 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000863 }
864}
865
866static void
867bfa_iocpf_sm_disabling_entry(struct bfa_iocpf *iocpf)
868{
869 mod_timer(&(iocpf->ioc)->iocpf_timer, jiffies +
870 msecs_to_jiffies(BFA_IOC_TOV));
871 bfa_ioc_send_disable(iocpf->ioc);
872}
873
874/**
875 * IOC is being disabled
876 */
877static void
878bfa_iocpf_sm_disabling(struct bfa_iocpf *iocpf, enum iocpf_event event)
879{
880 struct bfa_ioc *ioc = iocpf->ioc;
881
882 switch (event) {
883 case IOCPF_E_FWRSP_DISABLE:
884 case IOCPF_E_FWREADY:
885 del_timer(&ioc->iocpf_timer);
886 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
887 break;
888
889 case IOCPF_E_FAIL:
890 del_timer(&ioc->iocpf_timer);
891 /*
892 * !!! fall through !!!
893 */
894
895 case IOCPF_E_TIMEOUT:
896 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
897 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
898 break;
899
900 case IOCPF_E_FWRSP_ENABLE:
901 break;
902
903 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000904 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000905 }
906}
907
908static void
909bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf *iocpf)
910{
911 bfa_ioc_hw_sem_get(iocpf->ioc);
912}
913
914/**
915 * IOC hb ack request is being removed.
916 */
917static void
918bfa_iocpf_sm_disabling_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
919{
920 struct bfa_ioc *ioc = iocpf->ioc;
921
922 switch (event) {
923 case IOCPF_E_SEMLOCKED:
924 bfa_ioc_sync_leave(ioc);
925 bfa_nw_ioc_hw_sem_release(ioc);
926 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
927 break;
928
929 case IOCPF_E_FAIL:
930 break;
931
932 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000933 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000934 }
935}
936
937/**
938 * IOC disable completion entry.
939 */
940static void
941bfa_iocpf_sm_disabled_entry(struct bfa_iocpf *iocpf)
942{
Rasesh Modyfdad4002011-07-22 08:07:45 +0000943 bfa_ioc_mbox_flush(iocpf->ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000944 bfa_ioc_pf_disabled(iocpf->ioc);
945}
946
947static void
948bfa_iocpf_sm_disabled(struct bfa_iocpf *iocpf, enum iocpf_event event)
949{
950 struct bfa_ioc *ioc = iocpf->ioc;
951
952 switch (event) {
953 case IOCPF_E_ENABLE:
954 iocpf->retry_count = 0;
955 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
956 break;
957
958 case IOCPF_E_STOP:
959 bfa_ioc_firmware_unlock(ioc);
960 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
961 break;
962
963 default:
Rasesh Modyac51f602011-07-22 08:07:43 +0000964 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +0000965 }
966}
967
968static void
969bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf *iocpf)
970{
971 bfa_ioc_hw_sem_get(iocpf->ioc);
972}
973
974/**
975 * Hardware initialization failed.
976 */
977static void
978bfa_iocpf_sm_initfail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
979{
980 struct bfa_ioc *ioc = iocpf->ioc;
981
982 switch (event) {
983 case IOCPF_E_SEMLOCKED:
984 bfa_ioc_notify_fail(ioc);
985 bfa_ioc_sync_ack(ioc);
986 iocpf->retry_count++;
987 if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) {
988 bfa_ioc_sync_leave(ioc);
989 bfa_nw_ioc_hw_sem_release(ioc);
990 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
991 } else {
992 if (bfa_ioc_sync_complete(ioc))
993 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
994 else {
995 bfa_nw_ioc_hw_sem_release(ioc);
996 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
997 }
998 }
999 break;
1000
1001 case IOCPF_E_DISABLE:
1002 bfa_ioc_hw_sem_get_cancel(ioc);
1003 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1004 break;
1005
1006 case IOCPF_E_STOP:
1007 bfa_ioc_hw_sem_get_cancel(ioc);
1008 bfa_ioc_firmware_unlock(ioc);
1009 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1010 break;
1011
1012 case IOCPF_E_FAIL:
1013 break;
1014
1015 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001016 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001017 }
1018}
1019
1020static void
1021bfa_iocpf_sm_initfail_entry(struct bfa_iocpf *iocpf)
1022{
1023 bfa_ioc_pf_initfailed(iocpf->ioc);
1024}
1025
1026/**
1027 * Hardware initialization failed.
1028 */
1029static void
1030bfa_iocpf_sm_initfail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1031{
1032 struct bfa_ioc *ioc = iocpf->ioc;
1033
1034 switch (event) {
1035 case IOCPF_E_DISABLE:
1036 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1037 break;
1038
1039 case IOCPF_E_STOP:
1040 bfa_ioc_firmware_unlock(ioc);
1041 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1042 break;
1043
1044 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001045 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001046 }
1047}
1048
1049static void
1050bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf *iocpf)
1051{
1052 /**
1053 * Mark IOC as failed in hardware and stop firmware.
1054 */
1055 bfa_ioc_lpu_stop(iocpf->ioc);
1056
1057 /**
1058 * Flush any queued up mailbox requests.
1059 */
Rasesh Modyfdad4002011-07-22 08:07:45 +00001060 bfa_ioc_mbox_flush(iocpf->ioc);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001061 bfa_ioc_hw_sem_get(iocpf->ioc);
1062}
1063
1064/**
1065 * IOC is in failed state.
1066 */
1067static void
1068bfa_iocpf_sm_fail_sync(struct bfa_iocpf *iocpf, enum iocpf_event event)
1069{
1070 struct bfa_ioc *ioc = iocpf->ioc;
1071
1072 switch (event) {
1073 case IOCPF_E_SEMLOCKED:
1074 iocpf->retry_count = 0;
1075 bfa_ioc_sync_ack(ioc);
1076 bfa_ioc_notify_fail(ioc);
1077 if (!iocpf->auto_recover) {
1078 bfa_ioc_sync_leave(ioc);
1079 bfa_nw_ioc_hw_sem_release(ioc);
1080 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1081 } else {
1082 if (bfa_ioc_sync_complete(ioc))
1083 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1084 else {
1085 bfa_nw_ioc_hw_sem_release(ioc);
1086 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1087 }
1088 }
1089 break;
1090
1091 case IOCPF_E_DISABLE:
1092 bfa_ioc_hw_sem_get_cancel(ioc);
1093 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1094 break;
1095
1096 case IOCPF_E_FAIL:
1097 break;
1098
1099 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001100 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001101 }
1102}
1103
1104static void
1105bfa_iocpf_sm_fail_entry(struct bfa_iocpf *iocpf)
1106{
1107}
1108
1109/**
1110 * @brief
1111 * IOC is in failed state.
1112 */
1113static void
1114bfa_iocpf_sm_fail(struct bfa_iocpf *iocpf, enum iocpf_event event)
1115{
1116 switch (event) {
1117 case IOCPF_E_DISABLE:
1118 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1119 break;
1120
1121 default:
Rasesh Modyac51f602011-07-22 08:07:43 +00001122 bfa_sm_fault(event);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001123 }
1124}
1125
1126/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001127 * BFA IOC private functions
1128 */
1129
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001130/**
1131 * Notify common modules registered for notification.
1132 */
1133static void
1134bfa_ioc_event_notify(struct bfa_ioc *ioc, enum bfa_ioc_event event)
1135{
1136 struct bfa_ioc_notify *notify;
1137 struct list_head *qe;
1138
1139 list_for_each(qe, &ioc->notify_q) {
1140 notify = (struct bfa_ioc_notify *)qe;
1141 notify->cbfn(notify->cbarg, event);
1142 }
1143}
1144
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001145static void
1146bfa_ioc_disable_comp(struct bfa_ioc *ioc)
1147{
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001148 ioc->cbfn->disable_cbfn(ioc->bfa);
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001149 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001150}
1151
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001152bool
Rasesh Mody8a891422010-08-25 23:00:27 -07001153bfa_nw_ioc_sem_get(void __iomem *sem_reg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001154{
1155 u32 r32;
1156 int cnt = 0;
1157#define BFA_SEM_SPINCNT 3000
1158
1159 r32 = readl(sem_reg);
1160
1161 while (r32 && (cnt < BFA_SEM_SPINCNT)) {
1162 cnt++;
1163 udelay(2);
1164 r32 = readl(sem_reg);
1165 }
1166
1167 if (r32 == 0)
1168 return true;
1169
1170 BUG_ON(!(cnt < BFA_SEM_SPINCNT));
1171 return false;
1172}
1173
1174void
Rasesh Mody8a891422010-08-25 23:00:27 -07001175bfa_nw_ioc_sem_release(void __iomem *sem_reg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001176{
1177 writel(1, sem_reg);
1178}
1179
1180static void
Rasesh Modyd4e16d42011-07-22 08:07:47 +00001181bfa_ioc_hw_sem_init(struct bfa_ioc *ioc)
1182{
1183 struct bfi_ioc_image_hdr fwhdr;
1184 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1185
1186 if (fwstate == BFI_IOC_UNINIT)
1187 return;
1188
1189 bfa_nw_ioc_fwver_get(ioc, &fwhdr);
1190
1191 if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL)
1192 return;
1193
1194 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
1195
1196 /*
1197 * Try to lock and then unlock the semaphore.
1198 */
1199 readl(ioc->ioc_regs.ioc_sem_reg);
1200 writel(1, ioc->ioc_regs.ioc_sem_reg);
1201}
1202
1203static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001204bfa_ioc_hw_sem_get(struct bfa_ioc *ioc)
1205{
1206 u32 r32;
1207
1208 /**
1209 * First read to the semaphore register will return 0, subsequent reads
1210 * will return 1. Semaphore is released by writing 1 to the register
1211 */
1212 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
1213 if (r32 == 0) {
Rasesh Mody1d32f762010-12-23 21:45:09 +00001214 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001215 return;
1216 }
1217
1218 mod_timer(&ioc->sem_timer, jiffies +
1219 msecs_to_jiffies(BFA_IOC_HWSEM_TOV));
1220}
1221
1222void
Rasesh Mody8a891422010-08-25 23:00:27 -07001223bfa_nw_ioc_hw_sem_release(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001224{
1225 writel(1, ioc->ioc_regs.ioc_sem_reg);
1226}
1227
1228static void
1229bfa_ioc_hw_sem_get_cancel(struct bfa_ioc *ioc)
1230{
1231 del_timer(&ioc->sem_timer);
1232}
1233
1234/**
1235 * @brief
1236 * Initialize LPU local memory (aka secondary memory / SRAM)
1237 */
1238static void
1239bfa_ioc_lmem_init(struct bfa_ioc *ioc)
1240{
1241 u32 pss_ctl;
1242 int i;
1243#define PSS_LMEM_INIT_TIME 10000
1244
1245 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1246 pss_ctl &= ~__PSS_LMEM_RESET;
1247 pss_ctl |= __PSS_LMEM_INIT_EN;
1248
1249 /*
1250 * i2c workaround 12.5khz clock
1251 */
1252 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
1253 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1254
1255 /**
1256 * wait for memory initialization to be complete
1257 */
1258 i = 0;
1259 do {
1260 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1261 i++;
1262 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1263
1264 /**
1265 * If memory initialization is not successful, IOC timeout will catch
1266 * such failures.
1267 */
1268 BUG_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
1269
1270 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
1271 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1272}
1273
1274static void
1275bfa_ioc_lpu_start(struct bfa_ioc *ioc)
1276{
1277 u32 pss_ctl;
1278
1279 /**
1280 * Take processor out of reset.
1281 */
1282 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1283 pss_ctl &= ~__PSS_LPU0_RESET;
1284
1285 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1286}
1287
1288static void
1289bfa_ioc_lpu_stop(struct bfa_ioc *ioc)
1290{
1291 u32 pss_ctl;
1292
1293 /**
1294 * Put processors in reset.
1295 */
1296 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
1297 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1298
1299 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
1300}
1301
1302/**
1303 * Get driver and firmware versions.
1304 */
1305void
Rasesh Mody8a891422010-08-25 23:00:27 -07001306bfa_nw_ioc_fwver_get(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001307{
David S. Miller58598542011-04-17 16:51:36 -07001308 u32 pgnum;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001309 u32 loff = 0;
1310 int i;
1311 u32 *fwsig = (u32 *) fwhdr;
1312
1313 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001314 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1315
1316 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr) / sizeof(u32));
1317 i++) {
1318 fwsig[i] =
1319 swab32(readl((loff) + (ioc->ioc_regs.smem_page_start)));
1320 loff += sizeof(u32);
1321 }
1322}
1323
1324/**
1325 * Returns TRUE if same.
1326 */
1327bool
Rasesh Mody8a891422010-08-25 23:00:27 -07001328bfa_nw_ioc_fwver_cmp(struct bfa_ioc *ioc, struct bfi_ioc_image_hdr *fwhdr)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001329{
1330 struct bfi_ioc_image_hdr *drv_fwhdr;
1331 int i;
1332
1333 drv_fwhdr = (struct bfi_ioc_image_hdr *)
1334 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
1335
1336 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1337 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i])
1338 return false;
1339 }
1340
1341 return true;
1342}
1343
1344/**
1345 * Return true if current running version is valid. Firmware signature and
1346 * execution context (driver/bios) must match.
1347 */
1348static bool
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001349bfa_ioc_fwver_valid(struct bfa_ioc *ioc, u32 boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001350{
1351 struct bfi_ioc_image_hdr fwhdr, *drv_fwhdr;
1352
Rasesh Mody8a891422010-08-25 23:00:27 -07001353 bfa_nw_ioc_fwver_get(ioc, &fwhdr);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001354 drv_fwhdr = (struct bfi_ioc_image_hdr *)
1355 bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0);
1356
1357 if (fwhdr.signature != drv_fwhdr->signature)
1358 return false;
1359
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001360 if (swab32(fwhdr.param) != boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001361 return false;
1362
Rasesh Mody8a891422010-08-25 23:00:27 -07001363 return bfa_nw_ioc_fwver_cmp(ioc, &fwhdr);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001364}
1365
1366/**
1367 * Conditionally flush any pending message from firmware at start.
1368 */
1369static void
1370bfa_ioc_msgflush(struct bfa_ioc *ioc)
1371{
1372 u32 r32;
1373
1374 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
1375 if (r32)
1376 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1377}
1378
1379/**
1380 * @img ioc_init_logic.jpg
1381 */
1382static void
1383bfa_ioc_hwinit(struct bfa_ioc *ioc, bool force)
1384{
1385 enum bfi_ioc_state ioc_fwstate;
1386 bool fwvalid;
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001387 u32 boot_env;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001388
1389 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
1390
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001391 boot_env = BFI_BOOT_LOADER_OS;
1392
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001393 if (force)
1394 ioc_fwstate = BFI_IOC_UNINIT;
1395
1396 /**
1397 * check if firmware is valid
1398 */
1399 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001400 false : bfa_ioc_fwver_valid(ioc, boot_env);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001401
1402 if (!fwvalid) {
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001403 bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, boot_env);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001404 return;
1405 }
1406
1407 /**
1408 * If hardware initialization is in progress (initialized by other IOC),
1409 * just wait for an initialization completion interrupt.
1410 */
1411 if (ioc_fwstate == BFI_IOC_INITING) {
1412 ioc->cbfn->reset_cbfn(ioc->bfa);
1413 return;
1414 }
1415
1416 /**
1417 * If IOC function is disabled and firmware version is same,
1418 * just re-enable IOC.
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001419 */
Rasesh Mody2c7d3822010-12-23 21:45:06 +00001420 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001421 /**
1422 * When using MSI-X any pending firmware ready event should
1423 * be flushed. Otherwise MSI-X interrupts are not delivered.
1424 */
1425 bfa_ioc_msgflush(ioc);
1426 ioc->cbfn->reset_cbfn(ioc->bfa);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001427 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001428 return;
1429 }
1430
1431 /**
1432 * Initialize the h/w for any other states.
1433 */
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001434 bfa_ioc_boot(ioc, BFI_BOOT_TYPE_NORMAL, boot_env);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001435}
1436
1437void
Rasesh Mody8a891422010-08-25 23:00:27 -07001438bfa_nw_ioc_timeout(void *ioc_arg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001439{
1440 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
1441
1442 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1443}
1444
Rasesh Mody8a891422010-08-25 23:00:27 -07001445static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001446bfa_ioc_mbox_send(struct bfa_ioc *ioc, void *ioc_msg, int len)
1447{
1448 u32 *msgp = (u32 *) ioc_msg;
1449 u32 i;
1450
1451 BUG_ON(!(len <= BFI_IOC_MSGLEN_MAX));
1452
1453 /*
1454 * first write msg to mailbox registers
1455 */
1456 for (i = 0; i < len / sizeof(u32); i++)
1457 writel(cpu_to_le32(msgp[i]),
1458 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1459
1460 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
1461 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
1462
1463 /*
1464 * write 1 to mailbox CMD to trigger LPU event
1465 */
1466 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1467 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
1468}
1469
1470static void
1471bfa_ioc_send_enable(struct bfa_ioc *ioc)
1472{
1473 struct bfi_ioc_ctrl_req enable_req;
1474 struct timeval tv;
1475
1476 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1477 bfa_ioc_portid(ioc));
1478 enable_req.ioc_class = ioc->ioc_mc;
1479 do_gettimeofday(&tv);
1480 enable_req.tv_sec = ntohl(tv.tv_sec);
1481 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req));
1482}
1483
1484static void
1485bfa_ioc_send_disable(struct bfa_ioc *ioc)
1486{
1487 struct bfi_ioc_ctrl_req disable_req;
1488
1489 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1490 bfa_ioc_portid(ioc));
1491 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req));
1492}
1493
1494static void
1495bfa_ioc_send_getattr(struct bfa_ioc *ioc)
1496{
1497 struct bfi_ioc_getattr_req attr_req;
1498
1499 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1500 bfa_ioc_portid(ioc));
1501 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1502 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1503}
1504
1505void
Rasesh Mody8a891422010-08-25 23:00:27 -07001506bfa_nw_ioc_hb_check(void *cbarg)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001507{
1508 struct bfa_ioc *ioc = cbarg;
1509 u32 hb_count;
1510
1511 hb_count = readl(ioc->ioc_regs.heartbeat);
1512 if (ioc->hb_count == hb_count) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001513 bfa_ioc_recover(ioc);
1514 return;
1515 } else {
1516 ioc->hb_count = hb_count;
1517 }
1518
1519 bfa_ioc_mbox_poll(ioc);
1520 mod_timer(&ioc->hb_timer, jiffies +
1521 msecs_to_jiffies(BFA_IOC_HB_TOV));
1522}
1523
1524static void
1525bfa_ioc_hb_monitor(struct bfa_ioc *ioc)
1526{
1527 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
1528 mod_timer(&ioc->hb_timer, jiffies +
1529 msecs_to_jiffies(BFA_IOC_HB_TOV));
1530}
1531
1532static void
1533bfa_ioc_hb_stop(struct bfa_ioc *ioc)
1534{
1535 del_timer(&ioc->hb_timer);
1536}
1537
1538/**
1539 * @brief
1540 * Initiate a full firmware download.
1541 */
1542static void
1543bfa_ioc_download_fw(struct bfa_ioc *ioc, u32 boot_type,
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001544 u32 boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001545{
1546 u32 *fwimg;
David S. Miller58598542011-04-17 16:51:36 -07001547 u32 pgnum;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001548 u32 loff = 0;
1549 u32 chunkno = 0;
1550 u32 i;
1551
1552 /**
1553 * Initialize LMEM first before code download
1554 */
1555 bfa_ioc_lmem_init(ioc);
1556
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001557 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno);
1558
1559 pgnum = bfa_ioc_smem_pgnum(ioc, loff);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001560
1561 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
1562
1563 for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) {
1564 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1565 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
1566 fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc),
1567 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
1568 }
1569
1570 /**
1571 * write smem
1572 */
1573 writel((swab32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)])),
1574 ((ioc->ioc_regs.smem_page_start) + (loff)));
1575
1576 loff += sizeof(u32);
1577
1578 /**
1579 * handle page offset wrap around
1580 */
1581 loff = PSS_SMEM_PGOFF(loff);
1582 if (loff == 0) {
1583 pgnum++;
1584 writel(pgnum,
1585 ioc->ioc_regs.host_page_num_fn);
1586 }
1587 }
1588
1589 writel(bfa_ioc_smem_pgnum(ioc, 0),
1590 ioc->ioc_regs.host_page_num_fn);
1591
1592 /*
1593 * Set boot type and boot param at the end.
1594 */
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001595 writel(boot_type, ((ioc->ioc_regs.smem_page_start)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001596 + (BFI_BOOT_TYPE_OFF)));
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001597 writel(boot_env, ((ioc->ioc_regs.smem_page_start)
1598 + (BFI_BOOT_LOADER_OFF)));
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001599}
1600
1601static void
1602bfa_ioc_reset(struct bfa_ioc *ioc, bool force)
1603{
1604 bfa_ioc_hwinit(ioc, force);
1605}
1606
1607/**
1608 * @brief
1609 * Update BFA configuration from firmware configuration.
1610 */
1611static void
1612bfa_ioc_getattr_reply(struct bfa_ioc *ioc)
1613{
1614 struct bfi_ioc_attr *attr = ioc->attr;
1615
1616 attr->adapter_prop = ntohl(attr->adapter_prop);
1617 attr->card_type = ntohl(attr->card_type);
1618 attr->maxfrsize = ntohs(attr->maxfrsize);
1619
1620 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1621}
1622
1623/**
1624 * Attach time initialization of mbox logic.
1625 */
1626static void
1627bfa_ioc_mbox_attach(struct bfa_ioc *ioc)
1628{
1629 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1630 int mc;
1631
1632 INIT_LIST_HEAD(&mod->cmd_q);
1633 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1634 mod->mbhdlr[mc].cbfn = NULL;
1635 mod->mbhdlr[mc].cbarg = ioc->bfa;
1636 }
1637}
1638
1639/**
1640 * Mbox poll timer -- restarts any pending mailbox requests.
1641 */
1642static void
1643bfa_ioc_mbox_poll(struct bfa_ioc *ioc)
1644{
1645 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1646 struct bfa_mbox_cmd *cmd;
1647 u32 stat;
1648
1649 /**
1650 * If no command pending, do nothing
1651 */
1652 if (list_empty(&mod->cmd_q))
1653 return;
1654
1655 /**
1656 * If previous command is not yet fetched by firmware, do nothing
1657 */
1658 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1659 if (stat)
1660 return;
1661
1662 /**
1663 * Enqueue command to firmware.
1664 */
1665 bfa_q_deq(&mod->cmd_q, &cmd);
1666 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1667}
1668
1669/**
1670 * Cleanup any pending requests.
1671 */
1672static void
Rasesh Modyfdad4002011-07-22 08:07:45 +00001673bfa_ioc_mbox_flush(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001674{
1675 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1676 struct bfa_mbox_cmd *cmd;
1677
1678 while (!list_empty(&mod->cmd_q))
1679 bfa_q_deq(&mod->cmd_q, &cmd);
1680}
1681
Rasesh Mody1d32f762010-12-23 21:45:09 +00001682static void
1683bfa_ioc_fail_notify(struct bfa_ioc *ioc)
1684{
Rasesh Mody1d32f762010-12-23 21:45:09 +00001685 /**
1686 * Notify driver and common modules registered for notification.
1687 */
1688 ioc->cbfn->hbfail_cbfn(ioc->bfa);
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001689 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001690}
1691
1692static void
1693bfa_ioc_pf_enabled(struct bfa_ioc *ioc)
1694{
1695 bfa_fsm_send_event(ioc, IOC_E_ENABLED);
1696}
1697
1698static void
1699bfa_ioc_pf_disabled(struct bfa_ioc *ioc)
1700{
1701 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
1702}
1703
1704static void
1705bfa_ioc_pf_initfailed(struct bfa_ioc *ioc)
1706{
1707 bfa_fsm_send_event(ioc, IOC_E_INITFAILED);
1708}
1709
1710static void
1711bfa_ioc_pf_failed(struct bfa_ioc *ioc)
1712{
Rasesh Modyf374b362011-07-22 08:07:46 +00001713 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Rasesh Mody1d32f762010-12-23 21:45:09 +00001714}
1715
1716static void
1717bfa_ioc_pf_fwmismatch(struct bfa_ioc *ioc)
1718{
1719 /**
1720 * Provide enable completion callback and AEN notification.
1721 */
1722 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
1723}
1724
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001725/**
1726 * IOC public
1727 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001728static enum bfa_status
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001729bfa_ioc_pll_init(struct bfa_ioc *ioc)
1730{
1731 /*
1732 * Hold semaphore so that nobody can access the chip during init.
1733 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001734 bfa_nw_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001735
1736 bfa_ioc_pll_init_asic(ioc);
1737
1738 ioc->pllinit = true;
1739 /*
1740 * release semaphore.
1741 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001742 bfa_nw_ioc_sem_release(ioc->ioc_regs.ioc_init_sem_reg);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001743
1744 return BFA_STATUS_OK;
1745}
1746
1747/**
1748 * Interface used by diag module to do firmware boot with memory test
1749 * as the entry vector.
1750 */
Rasesh Mody8a891422010-08-25 23:00:27 -07001751static void
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001752bfa_ioc_boot(struct bfa_ioc *ioc, u32 boot_type, u32 boot_env)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001753{
1754 void __iomem *rb;
1755
1756 bfa_ioc_stats(ioc, ioc_boots);
1757
1758 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
1759 return;
1760
1761 /**
1762 * Initialize IOC state of all functions on a chip reset.
1763 */
1764 rb = ioc->pcidev.pci_bar_kva;
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001765 if (boot_type == BFI_BOOT_TYPE_MEMTEST) {
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001766 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG));
1767 writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG));
1768 } else {
1769 writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG));
1770 writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG));
1771 }
1772
1773 bfa_ioc_msgflush(ioc);
Rasesh Mody79ea6c82011-04-14 08:05:18 +00001774 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001775
1776 /**
1777 * Enable interrupts just before starting LPU
1778 */
1779 ioc->cbfn->reset_cbfn(ioc->bfa);
1780 bfa_ioc_lpu_start(ioc);
1781}
1782
1783/**
1784 * Enable/disable IOC failure auto recovery.
1785 */
1786void
Rasesh Mody8a891422010-08-25 23:00:27 -07001787bfa_nw_ioc_auto_recover(bool auto_recover)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001788{
Rasesh Mody8a891422010-08-25 23:00:27 -07001789 bfa_nw_auto_recover = auto_recover;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001790}
1791
Rasesh Mody8a891422010-08-25 23:00:27 -07001792static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001793bfa_ioc_msgget(struct bfa_ioc *ioc, void *mbmsg)
1794{
1795 u32 *msgp = mbmsg;
1796 u32 r32;
1797 int i;
1798
1799 /**
1800 * read the MBOX msg
1801 */
1802 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
1803 i++) {
1804 r32 = readl(ioc->ioc_regs.lpu_mbox +
1805 i * sizeof(u32));
1806 msgp[i] = htonl(r32);
1807 }
1808
1809 /**
1810 * turn off mailbox interrupt by clearing mailbox status
1811 */
1812 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
1813 readl(ioc->ioc_regs.lpu_mbox_cmd);
1814}
1815
Rasesh Mody8a891422010-08-25 23:00:27 -07001816static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001817bfa_ioc_isr(struct bfa_ioc *ioc, struct bfi_mbmsg *m)
1818{
1819 union bfi_ioc_i2h_msg_u *msg;
Rasesh Mody1d32f762010-12-23 21:45:09 +00001820 struct bfa_iocpf *iocpf = &ioc->iocpf;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001821
1822 msg = (union bfi_ioc_i2h_msg_u *) m;
1823
1824 bfa_ioc_stats(ioc, ioc_isrs);
1825
1826 switch (msg->mh.msg_id) {
1827 case BFI_IOC_I2H_HBEAT:
1828 break;
1829
1830 case BFI_IOC_I2H_READY_EVENT:
Rasesh Mody1d32f762010-12-23 21:45:09 +00001831 bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001832 break;
1833
1834 case BFI_IOC_I2H_ENABLE_REPLY:
Rasesh Mody1d32f762010-12-23 21:45:09 +00001835 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001836 break;
1837
1838 case BFI_IOC_I2H_DISABLE_REPLY:
Rasesh Mody1d32f762010-12-23 21:45:09 +00001839 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001840 break;
1841
1842 case BFI_IOC_I2H_GETATTR_REPLY:
1843 bfa_ioc_getattr_reply(ioc);
1844 break;
1845
1846 default:
1847 BUG_ON(1);
1848 }
1849}
1850
1851/**
1852 * IOC attach time initialization and setup.
1853 *
1854 * @param[in] ioc memory for IOC
1855 * @param[in] bfa driver instance structure
1856 */
1857void
Rasesh Mody8a891422010-08-25 23:00:27 -07001858bfa_nw_ioc_attach(struct bfa_ioc *ioc, void *bfa, struct bfa_ioc_cbfn *cbfn)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001859{
1860 ioc->bfa = bfa;
1861 ioc->cbfn = cbfn;
1862 ioc->fcmode = false;
1863 ioc->pllinit = false;
1864 ioc->dbg_fwsave_once = true;
Rasesh Mody1d32f762010-12-23 21:45:09 +00001865 ioc->iocpf.ioc = ioc;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001866
1867 bfa_ioc_mbox_attach(ioc);
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001868 INIT_LIST_HEAD(&ioc->notify_q);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001869
Rasesh Mody1d32f762010-12-23 21:45:09 +00001870 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
1871 bfa_fsm_send_event(ioc, IOC_E_RESET);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001872}
1873
1874/**
1875 * Driver detach time IOC cleanup.
1876 */
1877void
Rasesh Mody8a891422010-08-25 23:00:27 -07001878bfa_nw_ioc_detach(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001879{
1880 bfa_fsm_send_event(ioc, IOC_E_DETACH);
1881}
1882
1883/**
1884 * Setup IOC PCI properties.
1885 *
1886 * @param[in] pcidev PCI device information for this IOC
1887 */
1888void
Rasesh Mody8a891422010-08-25 23:00:27 -07001889bfa_nw_ioc_pci_init(struct bfa_ioc *ioc, struct bfa_pcidev *pcidev,
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001890 enum bfi_mclass mc)
1891{
1892 ioc->ioc_mc = mc;
1893 ioc->pcidev = *pcidev;
1894 ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id);
1895 ioc->cna = ioc->ctdev && !ioc->fcmode;
1896
Rasesh Mody8a891422010-08-25 23:00:27 -07001897 bfa_nw_ioc_set_ct_hwif(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001898
1899 bfa_ioc_map_port(ioc);
1900 bfa_ioc_reg_init(ioc);
1901}
1902
1903/**
1904 * Initialize IOC dma memory
1905 *
1906 * @param[in] dm_kva kernel virtual address of IOC dma memory
1907 * @param[in] dm_pa physical address of IOC dma memory
1908 */
1909void
Rasesh Mody8a891422010-08-25 23:00:27 -07001910bfa_nw_ioc_mem_claim(struct bfa_ioc *ioc, u8 *dm_kva, u64 dm_pa)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001911{
1912 /**
1913 * dma memory for firmware attribute
1914 */
1915 ioc->attr_dma.kva = dm_kva;
1916 ioc->attr_dma.pa = dm_pa;
1917 ioc->attr = (struct bfi_ioc_attr *) dm_kva;
1918}
1919
1920/**
1921 * Return size of dma memory required.
1922 */
1923u32
Rasesh Mody8a891422010-08-25 23:00:27 -07001924bfa_nw_ioc_meminfo(void)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001925{
1926 return roundup(sizeof(struct bfi_ioc_attr), BFA_DMA_ALIGN_SZ);
1927}
1928
1929void
Rasesh Mody8a891422010-08-25 23:00:27 -07001930bfa_nw_ioc_enable(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001931{
1932 bfa_ioc_stats(ioc, ioc_enables);
1933 ioc->dbg_fwsave_once = true;
1934
1935 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
1936}
1937
1938void
Rasesh Mody8a891422010-08-25 23:00:27 -07001939bfa_nw_ioc_disable(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001940{
1941 bfa_ioc_stats(ioc, ioc_disables);
1942 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
1943}
1944
Rasesh Mody8a891422010-08-25 23:00:27 -07001945static u32
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001946bfa_ioc_smem_pgnum(struct bfa_ioc *ioc, u32 fmaddr)
1947{
1948 return PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, fmaddr);
1949}
1950
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001951/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001952 * Register mailbox message handler function, to be called by common modules
1953 */
1954void
Rasesh Mody8a891422010-08-25 23:00:27 -07001955bfa_nw_ioc_mbox_regisr(struct bfa_ioc *ioc, enum bfi_mclass mc,
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001956 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
1957{
1958 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1959
1960 mod->mbhdlr[mc].cbfn = cbfn;
1961 mod->mbhdlr[mc].cbarg = cbarg;
1962}
1963
1964/**
1965 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
1966 * Responsibility of caller to serialize
1967 *
1968 * @param[in] ioc IOC instance
1969 * @param[i] cmd Mailbox command
1970 */
1971void
Rasesh Mody8a891422010-08-25 23:00:27 -07001972bfa_nw_ioc_mbox_queue(struct bfa_ioc *ioc, struct bfa_mbox_cmd *cmd)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07001973{
1974 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
1975 u32 stat;
1976
1977 /**
1978 * If a previous command is pending, queue new command
1979 */
1980 if (!list_empty(&mod->cmd_q)) {
1981 list_add_tail(&cmd->qe, &mod->cmd_q);
1982 return;
1983 }
1984
1985 /**
1986 * If mailbox is busy, queue command for poll timer
1987 */
1988 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
1989 if (stat) {
1990 list_add_tail(&cmd->qe, &mod->cmd_q);
1991 return;
1992 }
1993
1994 /**
1995 * mailbox is free -- queue command to firmware
1996 */
1997 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
Rasesh Modybd5a92e2011-07-22 08:07:42 +00001998
1999 return;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002000}
2001
2002/**
2003 * Handle mailbox interrupts
2004 */
2005void
Rasesh Mody8a891422010-08-25 23:00:27 -07002006bfa_nw_ioc_mbox_isr(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002007{
2008 struct bfa_ioc_mbox_mod *mod = &ioc->mbox_mod;
2009 struct bfi_mbmsg m;
2010 int mc;
2011
2012 bfa_ioc_msgget(ioc, &m);
2013
2014 /**
2015 * Treat IOC message class as special.
2016 */
2017 mc = m.mh.msg_class;
2018 if (mc == BFI_MC_IOC) {
2019 bfa_ioc_isr(ioc, &m);
2020 return;
2021 }
2022
Dan Carpenter07465562010-09-19 11:25:54 -07002023 if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002024 return;
2025
2026 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
2027}
2028
2029void
Rasesh Mody8a891422010-08-25 23:00:27 -07002030bfa_nw_ioc_error_isr(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002031{
2032 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2033}
2034
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002035/**
Rasesh Modybd5a92e2011-07-22 08:07:42 +00002036 * return true if IOC is disabled
2037 */
2038bool
2039bfa_nw_ioc_is_disabled(struct bfa_ioc *ioc)
2040{
2041 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2042 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
2043}
2044
2045/**
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002046 * Add to IOC heartbeat failure notification queue. To be used by common
2047 * modules such as cee, port, diag.
2048 */
2049void
Rasesh Modybd5a92e2011-07-22 08:07:42 +00002050bfa_nw_ioc_notify_register(struct bfa_ioc *ioc,
2051 struct bfa_ioc_notify *notify)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002052{
Rasesh Modybd5a92e2011-07-22 08:07:42 +00002053 list_add_tail(&notify->qe, &ioc->notify_q);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002054}
2055
2056#define BFA_MFG_NAME "Brocade"
Rasesh Mody8a891422010-08-25 23:00:27 -07002057static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002058bfa_ioc_get_adapter_attr(struct bfa_ioc *ioc,
2059 struct bfa_adapter_attr *ad_attr)
2060{
2061 struct bfi_ioc_attr *ioc_attr;
2062
2063 ioc_attr = ioc->attr;
2064
2065 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2066 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2067 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2068 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
2069 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
2070 sizeof(struct bfa_mfg_vpd));
2071
2072 ad_attr->nports = bfa_ioc_get_nports(ioc);
2073 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
2074
2075 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2076 /* For now, model descr uses same model string */
2077 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
2078
2079 ad_attr->card_type = ioc_attr->card_type;
2080 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2081
2082 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2083 ad_attr->prototype = 1;
2084 else
2085 ad_attr->prototype = 0;
2086
2087 ad_attr->pwwn = bfa_ioc_get_pwwn(ioc);
Rasesh Mody8a891422010-08-25 23:00:27 -07002088 ad_attr->mac = bfa_nw_ioc_get_mac(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002089
2090 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2091 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2092 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2093 ad_attr->asic_rev = ioc_attr->asic_rev;
2094
2095 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
2096
2097 ad_attr->cna_capable = ioc->cna;
2098 ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna;
2099}
2100
Rasesh Mody8a891422010-08-25 23:00:27 -07002101static enum bfa_ioc_type
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002102bfa_ioc_get_type(struct bfa_ioc *ioc)
2103{
2104 if (!ioc->ctdev || ioc->fcmode)
2105 return BFA_IOC_TYPE_FC;
2106 else if (ioc->ioc_mc == BFI_MC_IOCFC)
2107 return BFA_IOC_TYPE_FCoE;
2108 else if (ioc->ioc_mc == BFI_MC_LL)
2109 return BFA_IOC_TYPE_LL;
2110 else {
2111 BUG_ON(!(ioc->ioc_mc == BFI_MC_LL));
2112 return BFA_IOC_TYPE_LL;
2113 }
2114}
2115
Rasesh Mody8a891422010-08-25 23:00:27 -07002116static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002117bfa_ioc_get_adapter_serial_num(struct bfa_ioc *ioc, char *serial_num)
2118{
2119 memset(serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2120 memcpy(serial_num,
2121 (void *)ioc->attr->brcd_serialnum,
2122 BFA_ADAPTER_SERIAL_NUM_LEN);
2123}
2124
Rasesh Mody8a891422010-08-25 23:00:27 -07002125static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002126bfa_ioc_get_adapter_fw_ver(struct bfa_ioc *ioc, char *fw_ver)
2127{
2128 memset(fw_ver, 0, BFA_VERSION_LEN);
2129 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
2130}
2131
Rasesh Mody8a891422010-08-25 23:00:27 -07002132static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002133bfa_ioc_get_pci_chip_rev(struct bfa_ioc *ioc, char *chip_rev)
2134{
2135 BUG_ON(!(chip_rev));
2136
2137 memset(chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
2138
2139 chip_rev[0] = 'R';
2140 chip_rev[1] = 'e';
2141 chip_rev[2] = 'v';
2142 chip_rev[3] = '-';
2143 chip_rev[4] = ioc->attr->asic_rev;
2144 chip_rev[5] = '\0';
2145}
2146
Rasesh Mody8a891422010-08-25 23:00:27 -07002147static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002148bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver)
2149{
2150 memset(optrom_ver, 0, BFA_VERSION_LEN);
2151 memcpy(optrom_ver, ioc->attr->optrom_version,
2152 BFA_VERSION_LEN);
2153}
2154
Rasesh Mody8a891422010-08-25 23:00:27 -07002155static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002156bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer)
2157{
2158 memset(manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2159 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
2160}
2161
Rasesh Mody8a891422010-08-25 23:00:27 -07002162static void
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002163bfa_ioc_get_adapter_model(struct bfa_ioc *ioc, char *model)
2164{
2165 struct bfi_ioc_attr *ioc_attr;
2166
2167 BUG_ON(!(model));
2168 memset(model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
2169
2170 ioc_attr = ioc->attr;
2171
2172 /**
2173 * model name
2174 */
2175 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2176 BFA_MFG_NAME, ioc_attr->card_type);
2177}
2178
Rasesh Mody8a891422010-08-25 23:00:27 -07002179static enum bfa_ioc_state
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002180bfa_ioc_get_state(struct bfa_ioc *ioc)
2181{
Rasesh Mody1d32f762010-12-23 21:45:09 +00002182 enum bfa_iocpf_state iocpf_st;
2183 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2184
2185 if (ioc_st == BFA_IOC_ENABLING ||
2186 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2187
2188 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2189
2190 switch (iocpf_st) {
2191 case BFA_IOCPF_SEMWAIT:
2192 ioc_st = BFA_IOC_SEMWAIT;
2193 break;
2194
2195 case BFA_IOCPF_HWINIT:
2196 ioc_st = BFA_IOC_HWINIT;
2197 break;
2198
2199 case BFA_IOCPF_FWMISMATCH:
2200 ioc_st = BFA_IOC_FWMISMATCH;
2201 break;
2202
2203 case BFA_IOCPF_FAIL:
2204 ioc_st = BFA_IOC_FAIL;
2205 break;
2206
2207 case BFA_IOCPF_INITFAIL:
2208 ioc_st = BFA_IOC_INITFAIL;
2209 break;
2210
2211 default:
2212 break;
2213 }
2214 }
2215 return ioc_st;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002216}
2217
2218void
Rasesh Mody8a891422010-08-25 23:00:27 -07002219bfa_nw_ioc_get_attr(struct bfa_ioc *ioc, struct bfa_ioc_attr *ioc_attr)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002220{
2221 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr));
2222
2223 ioc_attr->state = bfa_ioc_get_state(ioc);
2224 ioc_attr->port_id = ioc->port_id;
2225
2226 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
2227
2228 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2229
2230 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2231 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
2232 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
2233}
2234
2235/**
2236 * WWN public
2237 */
Rasesh Mody8a891422010-08-25 23:00:27 -07002238static u64
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002239bfa_ioc_get_pwwn(struct bfa_ioc *ioc)
2240{
2241 return ioc->attr->pwwn;
2242}
2243
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002244mac_t
Rasesh Mody8a891422010-08-25 23:00:27 -07002245bfa_nw_ioc_get_mac(struct bfa_ioc *ioc)
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002246{
Rasesh Mody2c7d3822010-12-23 21:45:06 +00002247 return ioc->attr->mac;
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002248}
2249
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002250/**
2251 * Firmware failure detected. Start recovery actions.
2252 */
2253static void
2254bfa_ioc_recover(struct bfa_ioc *ioc)
2255{
Rasesh Mody1e581482011-04-04 08:29:59 +00002256 pr_crit("Heart Beat of IOC has failed\n");
2257 bfa_ioc_stats(ioc, ioc_hbfails);
2258 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002259}
2260
2261static void
2262bfa_ioc_check_attr_wwns(struct bfa_ioc *ioc)
2263{
2264 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2265 return;
Rasesh Mody1d32f762010-12-23 21:45:09 +00002266}
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002267
Rasesh Mody1d32f762010-12-23 21:45:09 +00002268/**
2269 * @dg hal_iocpf_pvt BFA IOC PF private functions
2270 * @{
2271 */
2272
2273static void
2274bfa_iocpf_enable(struct bfa_ioc *ioc)
2275{
2276 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
2277}
2278
2279static void
2280bfa_iocpf_disable(struct bfa_ioc *ioc)
2281{
2282 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
2283}
2284
2285static void
2286bfa_iocpf_fail(struct bfa_ioc *ioc)
2287{
2288 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
2289}
2290
2291static void
2292bfa_iocpf_initfail(struct bfa_ioc *ioc)
2293{
2294 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
2295}
2296
2297static void
2298bfa_iocpf_getattrfail(struct bfa_ioc *ioc)
2299{
2300 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
2301}
2302
2303static void
2304bfa_iocpf_stop(struct bfa_ioc *ioc)
2305{
2306 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
2307}
2308
2309void
2310bfa_nw_iocpf_timeout(void *ioc_arg)
2311{
2312 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
2313
2314 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2315}
2316
2317void
2318bfa_nw_iocpf_sem_timeout(void *ioc_arg)
2319{
2320 struct bfa_ioc *ioc = (struct bfa_ioc *) ioc_arg;
2321
2322 bfa_ioc_hw_sem_get(ioc);
Rasesh Mody8b230ed2010-08-23 20:24:12 -07002323}