blob: 7b4a567ca22ae5989e82c342f02125db2cf7618e [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019#include "bfa_ioc.h"
Krishna Gudipati11189202011-06-13 15:50:35 -070020#include "bfi_reg.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070021#include "bfa_defs.h"
22#include "bfa_defs_svc.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070023
Krishna Gudipati7af074d2010-03-05 19:35:45 -080024BFA_TRC_FILE(CNA, IOC);
Jing Huang7725ccf2009-09-23 17:46:15 -070025
Jing Huang5fbe25c2010-10-18 17:17:23 -070026/*
Jing Huang7725ccf2009-09-23 17:46:15 -070027 * IOC local definitions
28 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070029#define BFA_IOC_TOV 3000 /* msecs */
30#define BFA_IOC_HWSEM_TOV 500 /* msecs */
31#define BFA_IOC_HB_TOV 500 /* msecs */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070032#define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
Krishna Gudipati775c7742011-06-13 15:52:12 -070033#define BFA_IOC_POLL_TOV BFA_TIMER_FREQ
Jing Huang7725ccf2009-09-23 17:46:15 -070034
35#define bfa_ioc_timer_start(__ioc) \
36 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
37 bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
38#define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
39
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070040#define bfa_hb_timer_start(__ioc) \
41 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
42 bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
43#define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
44
Jing Huang7725ccf2009-09-23 17:46:15 -070045#define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
Jing Huang7725ccf2009-09-23 17:46:15 -070046
Jing Huang5fbe25c2010-10-18 17:17:23 -070047/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080048 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
49 */
50
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070051#define bfa_ioc_firmware_lock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080052 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070053#define bfa_ioc_firmware_unlock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080054 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
Krishna Gudipati0a20de42010-03-05 19:34:20 -080055#define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
56#define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080057#define bfa_ioc_notify_fail(__ioc) \
58 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
Jing Huang45d7f0c2011-04-13 11:45:53 -070059#define bfa_ioc_sync_start(__ioc) \
60 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080061#define bfa_ioc_sync_join(__ioc) \
62 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
63#define bfa_ioc_sync_leave(__ioc) \
64 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
65#define bfa_ioc_sync_ack(__ioc) \
66 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
67#define bfa_ioc_sync_complete(__ioc) \
68 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070069
70#define bfa_ioc_mbox_cmd_pending(__ioc) \
71 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
Jing Huang53440262010-10-18 17:12:29 -070072 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070073
74bfa_boolean_t bfa_auto_recover = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070075
76/*
77 * forward declarations
78 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070079static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070080static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
81static void bfa_ioc_timeout(void *ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -070082static void bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070083static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
84static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
85static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
86static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070087static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
Krishna Gudipati8b070b42011-06-13 15:52:40 -070088static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070089static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
90static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -070091static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
92 enum bfa_ioc_event_e event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070093static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
94static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -080095static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc);
96static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070097static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -070098
Jing Huang7725ccf2009-09-23 17:46:15 -070099
Jing Huang5fbe25c2010-10-18 17:17:23 -0700100/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101 * IOC state machine definitions/declarations
Jing Huang7725ccf2009-09-23 17:46:15 -0700102 */
103enum ioc_event {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104 IOC_E_RESET = 1, /* IOC reset request */
105 IOC_E_ENABLE = 2, /* IOC enable request */
106 IOC_E_DISABLE = 3, /* IOC disable request */
107 IOC_E_DETACH = 4, /* driver detach cleanup */
108 IOC_E_ENABLED = 5, /* f/w enabled */
109 IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
110 IOC_E_DISABLED = 7, /* f/w disabled */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700111 IOC_E_PFFAILED = 8, /* failure notice by iocpf sm */
112 IOC_E_HBFAIL = 9, /* heartbeat failure */
113 IOC_E_HWERROR = 10, /* hardware error interrupt */
114 IOC_E_TIMEOUT = 11, /* timeout */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700115 IOC_E_HWFAILED = 12, /* PCI mapping failure notice */
Krishna Gudipatia7141342011-06-24 20:23:19 -0700116 IOC_E_FWRSP_ACQ_ADDR = 13, /* Acquiring address */
Jing Huang7725ccf2009-09-23 17:46:15 -0700117};
118
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700119bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700120bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700121bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
122bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
123bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800124bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700125bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700126bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
127bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700128bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia7141342011-06-24 20:23:19 -0700129bfa_fsm_state_decl(bfa_ioc, acq_addr, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700130
131static struct bfa_sm_table_s ioc_sm_table[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700132 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Jing Huang7725ccf2009-09-23 17:46:15 -0700133 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700134 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Jing Huang7725ccf2009-09-23 17:46:15 -0700135 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
136 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800137 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700138 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700139 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
140 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700141 {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
Krishna Gudipatia7141342011-06-24 20:23:19 -0700142 {BFA_SM(bfa_ioc_sm_acq_addr), BFA_IOC_ACQ_ADDR},
Jing Huang7725ccf2009-09-23 17:46:15 -0700143};
144
Jing Huang5fbe25c2010-10-18 17:17:23 -0700145/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700146 * IOCPF state machine definitions/declarations
147 */
148
149#define bfa_iocpf_timer_start(__ioc) \
150 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
151 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
152#define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
153
Krishna Gudipati775c7742011-06-13 15:52:12 -0700154#define bfa_iocpf_poll_timer_start(__ioc) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700155 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
Krishna Gudipati775c7742011-06-13 15:52:12 -0700156 bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700157
158#define bfa_sem_timer_start(__ioc) \
159 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
160 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
161#define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
162
163/*
164 * Forward declareations for iocpf state machine
165 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700166static void bfa_iocpf_timeout(void *ioc_arg);
167static void bfa_iocpf_sem_timeout(void *ioc_arg);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700168static void bfa_iocpf_poll_timeout(void *ioc_arg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700169
Jing Huang5fbe25c2010-10-18 17:17:23 -0700170/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700171 * IOCPF state machine events
172 */
173enum iocpf_event {
174 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
175 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
176 IOCPF_E_STOP = 3, /* stop on driver detach */
177 IOCPF_E_FWREADY = 4, /* f/w initialization done */
178 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
179 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
180 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
181 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
182 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
183 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
184 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700185 IOCPF_E_SEM_ERROR = 12, /* h/w sem mapping error */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700186};
187
Jing Huang5fbe25c2010-10-18 17:17:23 -0700188/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700189 * IOCPF states
190 */
191enum bfa_iocpf_state {
192 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
193 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
194 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
195 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
196 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
197 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
198 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
199 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
200 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
201};
202
203bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
204bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
205bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
206bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
207bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
208bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
209bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800210bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
211 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700212bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800213bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700214bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
215bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800216bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
217 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700218bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
219
220static struct bfa_sm_table_s iocpf_sm_table[] = {
221 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
222 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
223 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
224 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
225 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
226 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
227 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800228 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700229 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800230 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700231 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
232 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800233 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700234 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
235};
236
Jing Huang5fbe25c2010-10-18 17:17:23 -0700237/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700238 * IOC State Machine
239 */
240
Jing Huang5fbe25c2010-10-18 17:17:23 -0700241/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700242 * Beginning state. IOC uninit state.
243 */
244
245static void
246bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
247{
248}
249
Jing Huang5fbe25c2010-10-18 17:17:23 -0700250/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700251 * IOC is in uninit state.
252 */
253static void
254bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
255{
256 bfa_trc(ioc, event);
257
258 switch (event) {
259 case IOC_E_RESET:
260 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
261 break;
262
263 default:
264 bfa_sm_fault(ioc, event);
265 }
266}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700267/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700268 * Reset entry actions -- initialize state machine
269 */
270static void
271bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
272{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700273 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700274}
275
Jing Huang5fbe25c2010-10-18 17:17:23 -0700276/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700277 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700278 */
279static void
280bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
281{
282 bfa_trc(ioc, event);
283
284 switch (event) {
285 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700286 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
287 break;
288
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700289 case IOC_E_DISABLE:
290 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700291 break;
292
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700293 case IOC_E_DETACH:
294 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700295 break;
296
297 default:
298 bfa_sm_fault(ioc, event);
299 }
300}
301
302
303static void
304bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
305{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800306 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700307}
308
Jing Huang5fbe25c2010-10-18 17:17:23 -0700309/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700310 * Host IOC function is being enabled, awaiting response from firmware.
311 * Semaphore is acquired.
312 */
313static void
314bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
315{
316 bfa_trc(ioc, event);
317
318 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700319 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700320 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
321 break;
322
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800323 case IOC_E_PFFAILED:
324 /* !!! fall through !!! */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700325 case IOC_E_HWERROR:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800326 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700327 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800328 if (event != IOC_E_PFFAILED)
329 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700330 break;
331
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700332 case IOC_E_HWFAILED:
333 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
334 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
335 break;
336
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700337 case IOC_E_DISABLE:
338 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
339 break;
340
341 case IOC_E_DETACH:
342 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800343 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700344 break;
345
346 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700347 break;
348
349 default:
350 bfa_sm_fault(ioc, event);
351 }
352}
353
354
355static void
356bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
357{
358 bfa_ioc_timer_start(ioc);
359 bfa_ioc_send_getattr(ioc);
360}
361
Jing Huang5fbe25c2010-10-18 17:17:23 -0700362/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700363 * IOC configuration in progress. Timer is active.
364 */
365static void
366bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
367{
368 bfa_trc(ioc, event);
369
370 switch (event) {
371 case IOC_E_FWRSP_GETATTR:
372 bfa_ioc_timer_stop(ioc);
Jing Huang07b28382010-07-08 19:59:24 -0700373 bfa_ioc_check_attr_wwns(ioc);
Krishna Gudipatia7141342011-06-24 20:23:19 -0700374 bfa_ioc_hb_monitor(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700375 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
376 break;
377
Krishna Gudipatia7141342011-06-24 20:23:19 -0700378 case IOC_E_FWRSP_ACQ_ADDR:
379 bfa_ioc_timer_stop(ioc);
380 bfa_ioc_hb_monitor(ioc);
381 bfa_fsm_set_state(ioc, bfa_ioc_sm_acq_addr);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700382 break;
Krishna Gudipatia7141342011-06-24 20:23:19 -0700383
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800384 case IOC_E_PFFAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700385 case IOC_E_HWERROR:
386 bfa_ioc_timer_stop(ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800387 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700388 case IOC_E_TIMEOUT:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800389 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700390 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800391 if (event != IOC_E_PFFAILED)
392 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700393 break;
394
395 case IOC_E_DISABLE:
396 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700397 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
398 break;
399
400 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700401 break;
402
403 default:
404 bfa_sm_fault(ioc, event);
405 }
406}
407
Krishna Gudipatia7141342011-06-24 20:23:19 -0700408/*
409 * Acquiring address from fabric (entry function)
410 */
411static void
412bfa_ioc_sm_acq_addr_entry(struct bfa_ioc_s *ioc)
413{
414}
415
416/*
417 * Acquiring address from the fabric
418 */
419static void
420bfa_ioc_sm_acq_addr(struct bfa_ioc_s *ioc, enum ioc_event event)
421{
422 bfa_trc(ioc, event);
423
424 switch (event) {
425 case IOC_E_FWRSP_GETATTR:
426 bfa_ioc_check_attr_wwns(ioc);
427 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
428 break;
429
430 case IOC_E_PFFAILED:
431 case IOC_E_HWERROR:
432 bfa_hb_timer_stop(ioc);
433 case IOC_E_HBFAIL:
434 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
435 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
436 if (event != IOC_E_PFFAILED)
437 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
438 break;
439
440 case IOC_E_DISABLE:
441 bfa_hb_timer_stop(ioc);
442 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
443 break;
444
445 case IOC_E_ENABLE:
446 break;
447
448 default:
449 bfa_sm_fault(ioc, event);
450 }
451}
Jing Huang7725ccf2009-09-23 17:46:15 -0700452
453static void
454bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
455{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700456 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
457
Jing Huang7725ccf2009-09-23 17:46:15 -0700458 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700459 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
Jing Huang88166242010-12-09 17:11:53 -0800460 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700461}
462
463static void
464bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
465{
466 bfa_trc(ioc, event);
467
468 switch (event) {
469 case IOC_E_ENABLE:
470 break;
471
472 case IOC_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800473 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700474 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
475 break;
476
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800477 case IOC_E_PFFAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700478 case IOC_E_HWERROR:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800479 bfa_hb_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700480 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700481 case IOC_E_HBFAIL:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800482 if (ioc->iocpf.auto_recover)
483 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
484 else
485 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
486
Krishna Gudipati775c7742011-06-13 15:52:12 -0700487 bfa_ioc_fail_notify(ioc);
488
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800489 if (event != IOC_E_PFFAILED)
490 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700491 break;
492
493 default:
494 bfa_sm_fault(ioc, event);
495 }
496}
497
498
499static void
500bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
501{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700502 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Maggie Zhangf7f73812010-12-09 19:08:43 -0800503 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
Jing Huang88166242010-12-09 17:11:53 -0800504 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Jing Huang7725ccf2009-09-23 17:46:15 -0700505}
506
Jing Huang5fbe25c2010-10-18 17:17:23 -0700507/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700508 * IOC is being disabled
509 */
510static void
511bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
512{
513 bfa_trc(ioc, event);
514
515 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700516 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800517 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
518 break;
519
520 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700521 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700522 * No state change. Will move to disabled state
523 * after iocpf sm completes failure processing and
524 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700525 */
Maggie Zhangf7f73812010-12-09 19:08:43 -0800526 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700527 break;
528
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700529 case IOC_E_HWFAILED:
530 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
531 bfa_ioc_disable_comp(ioc);
532 break;
533
Jing Huang7725ccf2009-09-23 17:46:15 -0700534 default:
535 bfa_sm_fault(ioc, event);
536 }
537}
538
Jing Huang5fbe25c2010-10-18 17:17:23 -0700539/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700540 * IOC disable completion entry.
541 */
542static void
543bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
544{
545 bfa_ioc_disable_comp(ioc);
546}
547
548static void
549bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
550{
551 bfa_trc(ioc, event);
552
553 switch (event) {
554 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700555 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700556 break;
557
558 case IOC_E_DISABLE:
559 ioc->cbfn->disable_cbfn(ioc->bfa);
560 break;
561
Jing Huang7725ccf2009-09-23 17:46:15 -0700562 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700563 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800564 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700565 break;
566
567 default:
568 bfa_sm_fault(ioc, event);
569 }
570}
571
572
573static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800574bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700575{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800576 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700577}
578
Jing Huang5fbe25c2010-10-18 17:17:23 -0700579/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800580 * Hardware initialization retry.
Jing Huang7725ccf2009-09-23 17:46:15 -0700581 */
582static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800583bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700584{
585 bfa_trc(ioc, event);
586
587 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700588 case IOC_E_ENABLED:
589 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
590 break;
591
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800592 case IOC_E_PFFAILED:
593 case IOC_E_HWERROR:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700594 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800595 * Initialization retry failed.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700596 */
597 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700598 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800599 if (event != IOC_E_PFFAILED)
600 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
601 break;
602
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700603 case IOC_E_HWFAILED:
604 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
605 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
606 break;
607
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800608 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700609 break;
610
Jing Huang7725ccf2009-09-23 17:46:15 -0700611 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700612 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700613 break;
614
615 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700616 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800617 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700618 break;
619
620 default:
621 bfa_sm_fault(ioc, event);
622 }
623}
624
625
626static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700627bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700628{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800629 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700630}
631
Jing Huang5fbe25c2010-10-18 17:17:23 -0700632/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700633 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700634 */
635static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700636bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700637{
638 bfa_trc(ioc, event);
639
640 switch (event) {
641
642 case IOC_E_ENABLE:
643 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
644 break;
645
646 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700647 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700648 break;
649
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800650 case IOC_E_DETACH:
651 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
652 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
653 break;
654
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800655 case IOC_E_HWERROR:
656 /*
657 * HB failure notification, ignore.
658 */
659 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700660 default:
661 bfa_sm_fault(ioc, event);
662 }
663}
664
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700665static void
666bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s *ioc)
667{
668 bfa_trc(ioc, 0);
669}
670
671static void
672bfa_ioc_sm_hwfail(struct bfa_ioc_s *ioc, enum ioc_event event)
673{
674 bfa_trc(ioc, event);
675
676 switch (event) {
677 case IOC_E_ENABLE:
678 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
679 break;
680
681 case IOC_E_DISABLE:
682 ioc->cbfn->disable_cbfn(ioc->bfa);
683 break;
684
685 case IOC_E_DETACH:
686 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
687 break;
688
689 default:
690 bfa_sm_fault(ioc, event);
691 }
692}
693
Jing Huang5fbe25c2010-10-18 17:17:23 -0700694/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700695 * IOCPF State Machine
696 */
697
Jing Huang5fbe25c2010-10-18 17:17:23 -0700698/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700699 * Reset entry actions -- initialize state machine
700 */
701static void
702bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
703{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700704 iocpf->fw_mismatch_notified = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700705 iocpf->auto_recover = bfa_auto_recover;
706}
707
Jing Huang5fbe25c2010-10-18 17:17:23 -0700708/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700709 * Beginning state. IOC is in reset state.
710 */
711static void
712bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
713{
714 struct bfa_ioc_s *ioc = iocpf->ioc;
715
716 bfa_trc(ioc, event);
717
718 switch (event) {
719 case IOCPF_E_ENABLE:
720 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
721 break;
722
723 case IOCPF_E_STOP:
724 break;
725
726 default:
727 bfa_sm_fault(ioc, event);
728 }
729}
730
Jing Huang5fbe25c2010-10-18 17:17:23 -0700731/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700732 * Semaphore should be acquired for version check.
733 */
734static void
735bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
736{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700737 struct bfi_ioc_image_hdr_s fwhdr;
738 u32 fwstate = readl(iocpf->ioc->ioc_regs.ioc_fwstate);
739
740 /* h/w sem init */
741 if (fwstate == BFI_IOC_UNINIT)
742 goto sem_get;
743
744 bfa_ioc_fwver_get(iocpf->ioc, &fwhdr);
745
746 if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL)
747 goto sem_get;
748
749 bfa_trc(iocpf->ioc, fwstate);
750 bfa_trc(iocpf->ioc, fwhdr.exec);
751 writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.ioc_fwstate);
752
753 /*
754 * Try to lock and then unlock the semaphore.
755 */
756 readl(iocpf->ioc->ioc_regs.ioc_sem_reg);
757 writel(1, iocpf->ioc->ioc_regs.ioc_sem_reg);
758sem_get:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700759 bfa_ioc_hw_sem_get(iocpf->ioc);
760}
761
Jing Huang5fbe25c2010-10-18 17:17:23 -0700762/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700763 * Awaiting h/w semaphore to continue with version check.
764 */
765static void
766bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
767{
768 struct bfa_ioc_s *ioc = iocpf->ioc;
769
770 bfa_trc(ioc, event);
771
772 switch (event) {
773 case IOCPF_E_SEMLOCKED:
774 if (bfa_ioc_firmware_lock(ioc)) {
Jing Huang45d7f0c2011-04-13 11:45:53 -0700775 if (bfa_ioc_sync_start(ioc)) {
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800776 bfa_ioc_sync_join(ioc);
777 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
778 } else {
779 bfa_ioc_firmware_unlock(ioc);
780 writel(1, ioc->ioc_regs.ioc_sem_reg);
781 bfa_sem_timer_start(ioc);
782 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700783 } else {
Maggie Zhangf7f73812010-12-09 19:08:43 -0800784 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700785 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
786 }
787 break;
788
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700789 case IOCPF_E_SEM_ERROR:
790 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
791 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
792 break;
793
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700794 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800795 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700796 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800797 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700798 break;
799
800 case IOCPF_E_STOP:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800801 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700802 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
803 break;
804
805 default:
806 bfa_sm_fault(ioc, event);
807 }
808}
809
Jing Huang5fbe25c2010-10-18 17:17:23 -0700810/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811 * Notify enable completion callback.
812 */
813static void
814bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
815{
816 /*
817 * Call only the first time sm enters fwmismatch state.
818 */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700819 if (iocpf->fw_mismatch_notified == BFA_FALSE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700820 bfa_ioc_pf_fwmismatch(iocpf->ioc);
821
Krishna Gudipati775c7742011-06-13 15:52:12 -0700822 iocpf->fw_mismatch_notified = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700823 bfa_iocpf_timer_start(iocpf->ioc);
824}
825
Jing Huang5fbe25c2010-10-18 17:17:23 -0700826/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700827 * Awaiting firmware version match.
828 */
829static void
830bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
831{
832 struct bfa_ioc_s *ioc = iocpf->ioc;
833
834 bfa_trc(ioc, event);
835
836 switch (event) {
837 case IOCPF_E_TIMEOUT:
838 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
839 break;
840
841 case IOCPF_E_DISABLE:
842 bfa_iocpf_timer_stop(ioc);
843 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800844 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700845 break;
846
847 case IOCPF_E_STOP:
848 bfa_iocpf_timer_stop(ioc);
849 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
850 break;
851
852 default:
853 bfa_sm_fault(ioc, event);
854 }
855}
856
Jing Huang5fbe25c2010-10-18 17:17:23 -0700857/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700858 * Request for semaphore.
859 */
860static void
861bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
862{
863 bfa_ioc_hw_sem_get(iocpf->ioc);
864}
865
Jing Huang5fbe25c2010-10-18 17:17:23 -0700866/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700867 * Awaiting semaphore for h/w initialzation.
868 */
869static void
870bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
871{
872 struct bfa_ioc_s *ioc = iocpf->ioc;
873
874 bfa_trc(ioc, event);
875
876 switch (event) {
877 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800878 if (bfa_ioc_sync_complete(ioc)) {
879 bfa_ioc_sync_join(ioc);
880 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
881 } else {
882 writel(1, ioc->ioc_regs.ioc_sem_reg);
883 bfa_sem_timer_start(ioc);
884 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700885 break;
886
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700887 case IOCPF_E_SEM_ERROR:
888 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
889 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
890 break;
891
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700892 case IOCPF_E_DISABLE:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800893 bfa_sem_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800894 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700895 break;
896
897 default:
898 bfa_sm_fault(ioc, event);
899 }
900}
901
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700902static void
903bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
904{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700905 iocpf->poll_time = 0;
Maggie Zhangf7f73812010-12-09 19:08:43 -0800906 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700907}
908
Jing Huang5fbe25c2010-10-18 17:17:23 -0700909/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700910 * Hardware is being initialized. Interrupts are enabled.
911 * Holding hardware semaphore lock.
912 */
913static void
914bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
915{
916 struct bfa_ioc_s *ioc = iocpf->ioc;
917
918 bfa_trc(ioc, event);
919
920 switch (event) {
921 case IOCPF_E_FWREADY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700922 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
923 break;
924
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700925 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800926 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700927 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800928 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700929 break;
930
931 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700932 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800933 bfa_ioc_sync_leave(ioc);
934 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700935 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
936 break;
937
938 default:
939 bfa_sm_fault(ioc, event);
940 }
941}
942
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700943static void
944bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
945{
946 bfa_iocpf_timer_start(iocpf->ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700947 /*
948 * Enable Interrupts before sending fw IOC ENABLE cmd.
949 */
950 iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700951 bfa_ioc_send_enable(iocpf->ioc);
952}
953
Jing Huang5fbe25c2010-10-18 17:17:23 -0700954/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700955 * Host IOC function is being enabled, awaiting response from firmware.
956 * Semaphore is acquired.
957 */
958static void
959bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
960{
961 struct bfa_ioc_s *ioc = iocpf->ioc;
962
963 bfa_trc(ioc, event);
964
965 switch (event) {
966 case IOCPF_E_FWRSP_ENABLE:
967 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800968 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700969 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
970 break;
971
972 case IOCPF_E_INITFAIL:
973 bfa_iocpf_timer_stop(ioc);
974 /*
975 * !!! fall through !!!
976 */
977
978 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f73812010-12-09 19:08:43 -0800979 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700980 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800981 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800982 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700983 break;
984
985 case IOCPF_E_DISABLE:
986 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -0800987 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700988 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
989 break;
990
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991 default:
992 bfa_sm_fault(ioc, event);
993 }
994}
995
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700996static void
997bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
998{
Maggie Zhangf7f73812010-12-09 19:08:43 -0800999 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001000}
1001
1002static void
1003bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1004{
1005 struct bfa_ioc_s *ioc = iocpf->ioc;
1006
1007 bfa_trc(ioc, event);
1008
1009 switch (event) {
1010 case IOCPF_E_DISABLE:
1011 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
1012 break;
1013
1014 case IOCPF_E_GETATTRFAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001015 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001016 break;
1017
1018 case IOCPF_E_FAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001019 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001020 break;
1021
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001022 default:
1023 bfa_sm_fault(ioc, event);
1024 }
1025}
1026
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001027static void
1028bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
1029{
1030 bfa_iocpf_timer_start(iocpf->ioc);
1031 bfa_ioc_send_disable(iocpf->ioc);
1032}
1033
Jing Huang5fbe25c2010-10-18 17:17:23 -07001034/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001035 * IOC is being disabled
1036 */
1037static void
1038bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1039{
1040 struct bfa_ioc_s *ioc = iocpf->ioc;
1041
1042 bfa_trc(ioc, event);
1043
1044 switch (event) {
1045 case IOCPF_E_FWRSP_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001046 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001047 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001048 break;
1049
1050 case IOCPF_E_FAIL:
1051 bfa_iocpf_timer_stop(ioc);
1052 /*
1053 * !!! fall through !!!
1054 */
1055
1056 case IOCPF_E_TIMEOUT:
Jing Huang53440262010-10-18 17:12:29 -07001057 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001058 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001059 break;
1060
1061 case IOCPF_E_FWRSP_ENABLE:
1062 break;
1063
1064 default:
1065 bfa_sm_fault(ioc, event);
1066 }
1067}
1068
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001069static void
1070bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
1071{
1072 bfa_ioc_hw_sem_get(iocpf->ioc);
1073}
1074
Jing Huang8f4bfad2010-12-26 21:50:10 -08001075/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001076 * IOC hb ack request is being removed.
1077 */
1078static void
1079bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1080{
1081 struct bfa_ioc_s *ioc = iocpf->ioc;
1082
1083 bfa_trc(ioc, event);
1084
1085 switch (event) {
1086 case IOCPF_E_SEMLOCKED:
1087 bfa_ioc_sync_leave(ioc);
1088 writel(1, ioc->ioc_regs.ioc_sem_reg);
1089 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1090 break;
1091
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001092 case IOCPF_E_SEM_ERROR:
1093 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1094 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1095 break;
1096
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001097 case IOCPF_E_FAIL:
1098 break;
1099
1100 default:
1101 bfa_sm_fault(ioc, event);
1102 }
1103}
1104
Jing Huang5fbe25c2010-10-18 17:17:23 -07001105/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001106 * IOC disable completion entry.
1107 */
1108static void
1109bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
1110{
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001111 bfa_ioc_mbox_flush(iocpf->ioc);
Maggie Zhangf7f73812010-12-09 19:08:43 -08001112 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001113}
1114
1115static void
1116bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1117{
1118 struct bfa_ioc_s *ioc = iocpf->ioc;
1119
1120 bfa_trc(ioc, event);
1121
1122 switch (event) {
1123 case IOCPF_E_ENABLE:
1124 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1125 break;
1126
1127 case IOCPF_E_STOP:
1128 bfa_ioc_firmware_unlock(ioc);
1129 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1130 break;
1131
1132 default:
1133 bfa_sm_fault(ioc, event);
1134 }
1135}
1136
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001137static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001138bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1139{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001140 bfa_ioc_debug_save_ftrc(iocpf->ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001141 bfa_ioc_hw_sem_get(iocpf->ioc);
1142}
1143
Jing Huang8f4bfad2010-12-26 21:50:10 -08001144/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001145 * Hardware initialization failed.
1146 */
1147static void
1148bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1149{
1150 struct bfa_ioc_s *ioc = iocpf->ioc;
1151
1152 bfa_trc(ioc, event);
1153
1154 switch (event) {
1155 case IOCPF_E_SEMLOCKED:
1156 bfa_ioc_notify_fail(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001157 bfa_ioc_sync_leave(ioc);
1158 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
1159 writel(1, ioc->ioc_regs.ioc_sem_reg);
1160 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001161 break;
1162
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001163 case IOCPF_E_SEM_ERROR:
1164 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1165 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1166 break;
1167
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001168 case IOCPF_E_DISABLE:
1169 bfa_sem_timer_stop(ioc);
1170 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1171 break;
1172
1173 case IOCPF_E_STOP:
1174 bfa_sem_timer_stop(ioc);
1175 bfa_ioc_firmware_unlock(ioc);
1176 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1177 break;
1178
1179 case IOCPF_E_FAIL:
1180 break;
1181
1182 default:
1183 bfa_sm_fault(ioc, event);
1184 }
1185}
1186
1187static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001188bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1189{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001190 bfa_trc(iocpf->ioc, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001191}
1192
Jing Huang5fbe25c2010-10-18 17:17:23 -07001193/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001194 * Hardware initialization failed.
1195 */
1196static void
1197bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1198{
1199 struct bfa_ioc_s *ioc = iocpf->ioc;
1200
1201 bfa_trc(ioc, event);
1202
1203 switch (event) {
1204 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001205 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1206 break;
1207
1208 case IOCPF_E_STOP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001209 bfa_ioc_firmware_unlock(ioc);
1210 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1211 break;
1212
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001213 default:
1214 bfa_sm_fault(ioc, event);
1215 }
1216}
1217
1218static void
1219bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1220{
Jing Huang8f4bfad2010-12-26 21:50:10 -08001221 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001222 * Mark IOC as failed in hardware and stop firmware.
1223 */
1224 bfa_ioc_lpu_stop(iocpf->ioc);
1225
Jing Huang8f4bfad2010-12-26 21:50:10 -08001226 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001227 * Flush any queued up mailbox requests.
1228 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001229 bfa_ioc_mbox_flush(iocpf->ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001230
1231 bfa_ioc_hw_sem_get(iocpf->ioc);
1232}
1233
1234static void
1235bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1236{
1237 struct bfa_ioc_s *ioc = iocpf->ioc;
1238
1239 bfa_trc(ioc, event);
1240
1241 switch (event) {
1242 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001243 bfa_ioc_sync_ack(ioc);
1244 bfa_ioc_notify_fail(ioc);
1245 if (!iocpf->auto_recover) {
1246 bfa_ioc_sync_leave(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001247 writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001248 writel(1, ioc->ioc_regs.ioc_sem_reg);
1249 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1250 } else {
1251 if (bfa_ioc_sync_complete(ioc))
1252 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1253 else {
1254 writel(1, ioc->ioc_regs.ioc_sem_reg);
1255 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1256 }
1257 }
1258 break;
1259
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001260 case IOCPF_E_SEM_ERROR:
1261 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1262 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1263 break;
1264
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001265 case IOCPF_E_DISABLE:
1266 bfa_sem_timer_stop(ioc);
1267 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1268 break;
1269
1270 case IOCPF_E_FAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001271 break;
1272
1273 default:
1274 bfa_sm_fault(ioc, event);
1275 }
1276}
1277
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001278static void
1279bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1280{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001281 bfa_trc(iocpf->ioc, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001282}
1283
Jing Huang5fbe25c2010-10-18 17:17:23 -07001284/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001285 * IOC is in failed state.
1286 */
1287static void
1288bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1289{
1290 struct bfa_ioc_s *ioc = iocpf->ioc;
1291
1292 bfa_trc(ioc, event);
1293
1294 switch (event) {
1295 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001296 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1297 break;
1298
Jing Huang7725ccf2009-09-23 17:46:15 -07001299 default:
1300 bfa_sm_fault(ioc, event);
1301 }
1302}
1303
Jing Huang5fbe25c2010-10-18 17:17:23 -07001304/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001305 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001306 */
1307
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001308/*
1309 * Notify common modules registered for notification.
1310 */
1311static void
1312bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
1313{
1314 struct bfa_ioc_notify_s *notify;
1315 struct list_head *qe;
1316
1317 list_for_each(qe, &ioc->notify_q) {
1318 notify = (struct bfa_ioc_notify_s *)qe;
1319 notify->cbfn(notify->cbarg, event);
1320 }
1321}
1322
Jing Huang7725ccf2009-09-23 17:46:15 -07001323static void
1324bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1325{
Jing Huang7725ccf2009-09-23 17:46:15 -07001326 ioc->cbfn->disable_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001327 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001328}
1329
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001330bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001331bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001332{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001333 u32 r32;
1334 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001335#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001336
Jing Huang53440262010-10-18 17:12:29 -07001337 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001338
Krishna Gudipati11189202011-06-13 15:50:35 -07001339 while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001340 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001341 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001342 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001343 }
1344
Krishna Gudipati11189202011-06-13 15:50:35 -07001345 if (!(r32 & 1))
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001346 return BFA_TRUE;
1347
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001348 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001349}
1350
Jing Huang7725ccf2009-09-23 17:46:15 -07001351static void
1352bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1353{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001354 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001355
Jing Huang5fbe25c2010-10-18 17:17:23 -07001356 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001357 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001358 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001359 */
Jing Huang53440262010-10-18 17:12:29 -07001360 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001361 if (r32 == ~0) {
1362 WARN_ON(r32 == ~0);
1363 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
1364 return;
1365 }
Krishna Gudipati11189202011-06-13 15:50:35 -07001366 if (!(r32 & 1)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001367 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001368 return;
1369 }
1370
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001371 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001372}
1373
Jing Huang5fbe25c2010-10-18 17:17:23 -07001374/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001375 * Initialize LPU local memory (aka secondary memory / SRAM)
1376 */
1377static void
1378bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1379{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001380 u32 pss_ctl;
1381 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001382#define PSS_LMEM_INIT_TIME 10000
1383
Jing Huang53440262010-10-18 17:12:29 -07001384 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001385 pss_ctl &= ~__PSS_LMEM_RESET;
1386 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001387
1388 /*
1389 * i2c workaround 12.5khz clock
1390 */
1391 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001392 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001393
Jing Huang5fbe25c2010-10-18 17:17:23 -07001394 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001395 * wait for memory initialization to be complete
1396 */
1397 i = 0;
1398 do {
Jing Huang53440262010-10-18 17:12:29 -07001399 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001400 i++;
1401 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1402
Jing Huang5fbe25c2010-10-18 17:17:23 -07001403 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001404 * If memory initialization is not successful, IOC timeout will catch
1405 * such failures.
1406 */
Jing Huangd4b671c2010-12-26 21:46:35 -08001407 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
Jing Huang7725ccf2009-09-23 17:46:15 -07001408 bfa_trc(ioc, pss_ctl);
1409
1410 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001411 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001412}
1413
1414static void
1415bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1416{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001417 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001418
Jing Huang5fbe25c2010-10-18 17:17:23 -07001419 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001420 * Take processor out of reset.
1421 */
Jing Huang53440262010-10-18 17:12:29 -07001422 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001423 pss_ctl &= ~__PSS_LPU0_RESET;
1424
Jing Huang53440262010-10-18 17:12:29 -07001425 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001426}
1427
1428static void
1429bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1430{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001431 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001432
Jing Huang5fbe25c2010-10-18 17:17:23 -07001433 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001434 * Put processors in reset.
1435 */
Jing Huang53440262010-10-18 17:12:29 -07001436 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001437 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1438
Jing Huang53440262010-10-18 17:12:29 -07001439 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001440}
1441
Jing Huang5fbe25c2010-10-18 17:17:23 -07001442/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001443 * Get driver and firmware versions.
1444 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001445void
Jing Huang7725ccf2009-09-23 17:46:15 -07001446bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1447{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001448 u32 pgnum, pgoff;
1449 u32 loff = 0;
1450 int i;
1451 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001452
Maggie Zhangf7f73812010-12-09 19:08:43 -08001453 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1454 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang53440262010-10-18 17:12:29 -07001455 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001456
1457 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1458 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001459 fwsig[i] =
1460 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001461 loff += sizeof(u32);
1462 }
1463}
1464
Jing Huang5fbe25c2010-10-18 17:17:23 -07001465/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001466 * Returns TRUE if same.
1467 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001468bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001469bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1470{
1471 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001472 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001473
Jing Huang293f82d2010-07-08 19:45:20 -07001474 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001475 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001476
1477 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
1478 if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) {
1479 bfa_trc(ioc, i);
1480 bfa_trc(ioc, fwhdr->md5sum[i]);
1481 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1482 return BFA_FALSE;
1483 }
1484 }
1485
1486 bfa_trc(ioc, fwhdr->md5sum[0]);
1487 return BFA_TRUE;
1488}
1489
Jing Huang5fbe25c2010-10-18 17:17:23 -07001490/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001491 * Return true if current running version is valid. Firmware signature and
1492 * execution context (driver/bios) must match.
1493 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001494static bfa_boolean_t
1495bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001496{
1497 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1498
Jing Huang7725ccf2009-09-23 17:46:15 -07001499 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001500 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001501 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001502
1503 if (fwhdr.signature != drv_fwhdr->signature) {
1504 bfa_trc(ioc, fwhdr.signature);
1505 bfa_trc(ioc, drv_fwhdr->signature);
1506 return BFA_FALSE;
1507 }
1508
Krishna Gudipati11189202011-06-13 15:50:35 -07001509 if (swab32(fwhdr.bootenv) != boot_env) {
1510 bfa_trc(ioc, fwhdr.bootenv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001511 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001512 return BFA_FALSE;
1513 }
1514
1515 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1516}
1517
Jing Huang5fbe25c2010-10-18 17:17:23 -07001518/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001519 * Conditionally flush any pending message from firmware at start.
1520 */
1521static void
1522bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1523{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001524 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001525
Jing Huang53440262010-10-18 17:12:29 -07001526 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001527 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001528 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001529}
1530
Jing Huang7725ccf2009-09-23 17:46:15 -07001531static void
1532bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1533{
1534 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001535 bfa_boolean_t fwvalid;
1536 u32 boot_type;
1537 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001538
Jing Huang53440262010-10-18 17:12:29 -07001539 ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07001540
1541 if (force)
1542 ioc_fwstate = BFI_IOC_UNINIT;
1543
1544 bfa_trc(ioc, ioc_fwstate);
1545
Krishna Gudipati11189202011-06-13 15:50:35 -07001546 boot_type = BFI_FWBOOT_TYPE_NORMAL;
1547 boot_env = BFI_FWBOOT_ENV_OS;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001548
Jing Huang5fbe25c2010-10-18 17:17:23 -07001549 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001550 * check if firmware is valid
1551 */
1552 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001553 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001554
1555 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001556 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001557 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001558 return;
1559 }
1560
Jing Huang5fbe25c2010-10-18 17:17:23 -07001561 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001562 * If hardware initialization is in progress (initialized by other IOC),
1563 * just wait for an initialization completion interrupt.
1564 */
1565 if (ioc_fwstate == BFI_IOC_INITING) {
Krishna Gudipati775c7742011-06-13 15:52:12 -07001566 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001567 return;
1568 }
1569
Jing Huang5fbe25c2010-10-18 17:17:23 -07001570 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001571 * If IOC function is disabled and firmware version is same,
1572 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001573 *
1574 * If option rom, IOC must not be in operational state. With
1575 * convergence, IOC will be in operational state when 2nd driver
1576 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001577 */
Jing Huang8f4bfad2010-12-26 21:50:10 -08001578 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001579
Jing Huang5fbe25c2010-10-18 17:17:23 -07001580 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001581 * When using MSI-X any pending firmware ready event should
1582 * be flushed. Otherwise MSI-X interrupts are not delivered.
1583 */
1584 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001585 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001586 return;
1587 }
1588
Jing Huang5fbe25c2010-10-18 17:17:23 -07001589 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001590 * Initialize the h/w for any other states.
1591 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001592 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001593 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001594}
1595
1596static void
1597bfa_ioc_timeout(void *ioc_arg)
1598{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001599 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001600
1601 bfa_trc(ioc, 0);
1602 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1603}
1604
1605void
1606bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1607{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001608 u32 *msgp = (u32 *) ioc_msg;
1609 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001610
1611 bfa_trc(ioc, msgp[0]);
1612 bfa_trc(ioc, len);
1613
Jing Huangd4b671c2010-12-26 21:46:35 -08001614 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
Jing Huang7725ccf2009-09-23 17:46:15 -07001615
1616 /*
1617 * first write msg to mailbox registers
1618 */
1619 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001620 writel(cpu_to_le32(msgp[i]),
1621 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001622
1623 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001624 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001625
1626 /*
1627 * write 1 to mailbox CMD to trigger LPU event
1628 */
Jing Huang53440262010-10-18 17:12:29 -07001629 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1630 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001631}
1632
1633static void
1634bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1635{
1636 struct bfi_ioc_ctrl_req_s enable_req;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001637 struct timeval tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001638
1639 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1640 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001641 enable_req.clscode = cpu_to_be16(ioc->clscode);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001642 do_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001643 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001644 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1645}
1646
1647static void
1648bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1649{
1650 struct bfi_ioc_ctrl_req_s disable_req;
1651
1652 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1653 bfa_ioc_portid(ioc));
1654 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1655}
1656
1657static void
1658bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1659{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001660 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001661
1662 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1663 bfa_ioc_portid(ioc));
1664 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1665 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1666}
1667
1668static void
1669bfa_ioc_hb_check(void *cbarg)
1670{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001671 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001672 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001673
Jing Huang53440262010-10-18 17:12:29 -07001674 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001675 if (ioc->hb_count == hb_count) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001676 bfa_ioc_recover(ioc);
1677 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001678 } else {
1679 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001680 }
1681
1682 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001683 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001684}
1685
1686static void
1687bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1688{
Jing Huang53440262010-10-18 17:12:29 -07001689 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001690 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001691}
1692
Jing Huang5fbe25c2010-10-18 17:17:23 -07001693/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001694 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001695 */
1696static void
1697bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001698 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001699{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001700 u32 *fwimg;
1701 u32 pgnum, pgoff;
1702 u32 loff = 0;
1703 u32 chunkno = 0;
1704 u32 i;
Krishna Gudipati11189202011-06-13 15:50:35 -07001705 u32 asicmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07001706
Jing Huang5fbe25c2010-10-18 17:17:23 -07001707 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001708 * Initialize LMEM first before code download
1709 */
1710 bfa_ioc_lmem_init(ioc);
1711
Krishna Gudipati11189202011-06-13 15:50:35 -07001712 bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)));
1713 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001714
Maggie Zhangf7f73812010-12-09 19:08:43 -08001715 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1716 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001717
Jing Huang53440262010-10-18 17:12:29 -07001718 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001719
Krishna Gudipati11189202011-06-13 15:50:35 -07001720 for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001721
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001722 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1723 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipati11189202011-06-13 15:50:35 -07001724 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001725 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001726 }
1727
Jing Huang5fbe25c2010-10-18 17:17:23 -07001728 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001729 * write smem
1730 */
1731 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001732 fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]);
Jing Huang7725ccf2009-09-23 17:46:15 -07001733
1734 loff += sizeof(u32);
1735
Jing Huang5fbe25c2010-10-18 17:17:23 -07001736 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001737 * handle page offset wrap around
1738 */
1739 loff = PSS_SMEM_PGOFF(loff);
1740 if (loff == 0) {
1741 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001742 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001743 }
1744 }
1745
Maggie Zhangf7f73812010-12-09 19:08:43 -08001746 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1747 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001748
1749 /*
Krishna Gudipati11189202011-06-13 15:50:35 -07001750 * Set boot type and device mode at the end.
1751 */
1752 asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
1753 ioc->port0_mode, ioc->port1_mode);
1754 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF,
1755 swab32(asicmode));
1756 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001757 swab32(boot_type));
Krishna Gudipati11189202011-06-13 15:50:35 -07001758 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001759 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001760}
1761
Jing Huang7725ccf2009-09-23 17:46:15 -07001762
Jing Huang5fbe25c2010-10-18 17:17:23 -07001763/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001764 * Update BFA configuration from firmware configuration.
1765 */
1766static void
1767bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1768{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001769 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001770
Jing Huangba816ea2010-10-18 17:10:50 -07001771 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1772 attr->card_type = be32_to_cpu(attr->card_type);
1773 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001774 ioc->fcmode = (attr->port_mode == BFI_PORT_MODE_FC);
Jing Huang7725ccf2009-09-23 17:46:15 -07001775
1776 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1777}
1778
Jing Huang5fbe25c2010-10-18 17:17:23 -07001779/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001780 * Attach time initialization of mbox logic.
1781 */
1782static void
1783bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1784{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001785 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1786 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001787
1788 INIT_LIST_HEAD(&mod->cmd_q);
1789 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1790 mod->mbhdlr[mc].cbfn = NULL;
1791 mod->mbhdlr[mc].cbarg = ioc->bfa;
1792 }
1793}
1794
Jing Huang5fbe25c2010-10-18 17:17:23 -07001795/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001796 * Mbox poll timer -- restarts any pending mailbox requests.
1797 */
1798static void
1799bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1800{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001801 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1802 struct bfa_mbox_cmd_s *cmd;
1803 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001804
Jing Huang5fbe25c2010-10-18 17:17:23 -07001805 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001806 * If no command pending, do nothing
1807 */
1808 if (list_empty(&mod->cmd_q))
1809 return;
1810
Jing Huang5fbe25c2010-10-18 17:17:23 -07001811 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001812 * If previous command is not yet fetched by firmware, do nothing
1813 */
Jing Huang53440262010-10-18 17:12:29 -07001814 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001815 if (stat)
1816 return;
1817
Jing Huang5fbe25c2010-10-18 17:17:23 -07001818 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001819 * Enqueue command to firmware.
1820 */
1821 bfa_q_deq(&mod->cmd_q, &cmd);
1822 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1823}
1824
Jing Huang5fbe25c2010-10-18 17:17:23 -07001825/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001826 * Cleanup any pending requests.
1827 */
1828static void
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001829bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07001830{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001831 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1832 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001833
1834 while (!list_empty(&mod->cmd_q))
1835 bfa_q_deq(&mod->cmd_q, &cmd);
1836}
1837
Jing Huang5fbe25c2010-10-18 17:17:23 -07001838/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001839 * Read data from SMEM to host through PCI memmap
1840 *
1841 * @param[in] ioc memory for IOC
1842 * @param[in] tbuf app memory to store data from smem
1843 * @param[in] soff smem offset
1844 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001845 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001846static bfa_status_t
1847bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1848{
Maggie50444a32010-11-29 18:26:32 -08001849 u32 pgnum, loff;
1850 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001851 int i, len;
1852 u32 *buf = tbuf;
1853
Maggie Zhangf7f73812010-12-09 19:08:43 -08001854 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1855 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001856 bfa_trc(ioc, pgnum);
1857 bfa_trc(ioc, loff);
1858 bfa_trc(ioc, sz);
1859
1860 /*
1861 * Hold semaphore to serialize pll init and fwtrc.
1862 */
1863 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1864 bfa_trc(ioc, 0);
1865 return BFA_STATUS_FAILED;
1866 }
1867
Jing Huang53440262010-10-18 17:12:29 -07001868 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001869
1870 len = sz/sizeof(u32);
1871 bfa_trc(ioc, len);
1872 for (i = 0; i < len; i++) {
1873 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001874 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001875 loff += sizeof(u32);
1876
Jing Huang5fbe25c2010-10-18 17:17:23 -07001877 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001878 * handle page offset wrap around
1879 */
1880 loff = PSS_SMEM_PGOFF(loff);
1881 if (loff == 0) {
1882 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001883 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001884 }
1885 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001886 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1887 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001888 /*
1889 * release semaphore.
1890 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001891 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f73812010-12-09 19:08:43 -08001892 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001893
1894 bfa_trc(ioc, pgnum);
1895 return BFA_STATUS_OK;
1896}
1897
Jing Huang5fbe25c2010-10-18 17:17:23 -07001898/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001899 * Clear SMEM data from host through PCI memmap
1900 *
1901 * @param[in] ioc memory for IOC
1902 * @param[in] soff smem offset
1903 * @param[in] sz size of smem in bytes
1904 */
1905static bfa_status_t
1906bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1907{
1908 int i, len;
1909 u32 pgnum, loff;
1910
Maggie Zhangf7f73812010-12-09 19:08:43 -08001911 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1912 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001913 bfa_trc(ioc, pgnum);
1914 bfa_trc(ioc, loff);
1915 bfa_trc(ioc, sz);
1916
1917 /*
1918 * Hold semaphore to serialize pll init and fwtrc.
1919 */
1920 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1921 bfa_trc(ioc, 0);
1922 return BFA_STATUS_FAILED;
1923 }
1924
Jing Huang53440262010-10-18 17:12:29 -07001925 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001926
1927 len = sz/sizeof(u32); /* len in words */
1928 bfa_trc(ioc, len);
1929 for (i = 0; i < len; i++) {
1930 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1931 loff += sizeof(u32);
1932
Jing Huang5fbe25c2010-10-18 17:17:23 -07001933 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001934 * handle page offset wrap around
1935 */
1936 loff = PSS_SMEM_PGOFF(loff);
1937 if (loff == 0) {
1938 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001939 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001940 }
1941 }
Maggie Zhangf7f73812010-12-09 19:08:43 -08001942 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1943 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001944
1945 /*
1946 * release semaphore.
1947 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001948 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f73812010-12-09 19:08:43 -08001949 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001950 bfa_trc(ioc, pgnum);
1951 return BFA_STATUS_OK;
1952}
1953
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001954static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001955bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1956{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001957 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1958
Jing Huang8f4bfad2010-12-26 21:50:10 -08001959 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001960 * Notify driver and common modules registered for notification.
1961 */
1962 ioc->cbfn->hbfail_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001963 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001964
1965 bfa_ioc_debug_save_ftrc(ioc);
1966
1967 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1968 "Heart Beat of IOC has failed\n");
1969
1970}
1971
1972static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001973bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1974{
1975 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001976 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001977 * Provide enable completion callback.
1978 */
1979 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001980 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001981 "Running firmware version is incompatible "
1982 "with the driver version\n");
1983}
1984
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001985bfa_status_t
1986bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1987{
1988
1989 /*
1990 * Hold semaphore so that nobody can access the chip during init.
1991 */
1992 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1993
1994 bfa_ioc_pll_init_asic(ioc);
1995
1996 ioc->pllinit = BFA_TRUE;
1997 /*
1998 * release semaphore.
1999 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002000 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f73812010-12-09 19:08:43 -08002001 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002002
2003 return BFA_STATUS_OK;
2004}
Jing Huang7725ccf2009-09-23 17:46:15 -07002005
Jing Huang5fbe25c2010-10-18 17:17:23 -07002006/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002007 * Interface used by diag module to do firmware boot with memory test
2008 * as the entry vector.
2009 */
2010void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002011bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07002012{
Jing Huang7725ccf2009-09-23 17:46:15 -07002013 bfa_ioc_stats(ioc, ioc_boots);
2014
2015 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
2016 return;
2017
Jing Huang5fbe25c2010-10-18 17:17:23 -07002018 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002019 * Initialize IOC state of all functions on a chip reset.
2020 */
Krishna Gudipati11189202011-06-13 15:50:35 -07002021 if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
2022 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate);
2023 writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07002024 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -07002025 writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate);
2026 writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07002027 }
2028
Jing Huang07b28382010-07-08 19:59:24 -07002029 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002030 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07002031 bfa_ioc_lpu_start(ioc);
2032}
2033
Jing Huang5fbe25c2010-10-18 17:17:23 -07002034/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002035 * Enable/disable IOC failure auto recovery.
2036 */
2037void
2038bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
2039{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08002040 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07002041}
2042
2043
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002044
Jing Huang7725ccf2009-09-23 17:46:15 -07002045bfa_boolean_t
2046bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
2047{
2048 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
2049}
2050
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002051bfa_boolean_t
2052bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
2053{
Jing Huang53440262010-10-18 17:12:29 -07002054 u32 r32 = readl(ioc->ioc_regs.ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002055
2056 return ((r32 != BFI_IOC_UNINIT) &&
2057 (r32 != BFI_IOC_INITING) &&
2058 (r32 != BFI_IOC_MEMTEST));
2059}
2060
Krishna Gudipati11189202011-06-13 15:50:35 -07002061bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07002062bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
2063{
Maggie50444a32010-11-29 18:26:32 -08002064 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002065 u32 r32;
2066 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07002067
Krishna Gudipati11189202011-06-13 15:50:35 -07002068 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
2069 if ((r32 & 1) == 0)
2070 return BFA_FALSE;
2071
Jing Huang5fbe25c2010-10-18 17:17:23 -07002072 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002073 * read the MBOX msg
2074 */
2075 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
2076 i++) {
Jing Huang53440262010-10-18 17:12:29 -07002077 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07002078 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07002079 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07002080 }
2081
Jing Huang5fbe25c2010-10-18 17:17:23 -07002082 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002083 * turn off mailbox interrupt by clearing mailbox status
2084 */
Jing Huang53440262010-10-18 17:12:29 -07002085 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
2086 readl(ioc->ioc_regs.lpu_mbox_cmd);
Krishna Gudipati11189202011-06-13 15:50:35 -07002087
2088 return BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002089}
2090
2091void
2092bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
2093{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002094 union bfi_ioc_i2h_msg_u *msg;
2095 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07002096
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002097 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002098
2099 bfa_ioc_stats(ioc, ioc_isrs);
2100
2101 switch (msg->mh.msg_id) {
2102 case BFI_IOC_I2H_HBEAT:
2103 break;
2104
Jing Huang7725ccf2009-09-23 17:46:15 -07002105 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002106 ioc->port_mode = ioc->port_mode_cfg =
2107 (enum bfa_mode_s)msg->fw_event.port_mode;
2108 ioc->ad_cap_bm = msg->fw_event.cap_bm;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002109 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07002110 break;
2111
2112 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002113 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07002114 break;
2115
2116 case BFI_IOC_I2H_GETATTR_REPLY:
2117 bfa_ioc_getattr_reply(ioc);
2118 break;
2119
Krishna Gudipatia7141342011-06-24 20:23:19 -07002120 case BFI_IOC_I2H_ACQ_ADDR_REPLY:
2121 bfa_fsm_send_event(ioc, IOC_E_FWRSP_ACQ_ADDR);
2122 break;
2123
Jing Huang7725ccf2009-09-23 17:46:15 -07002124 default:
2125 bfa_trc(ioc, msg->mh.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002126 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -07002127 }
2128}
2129
Jing Huang5fbe25c2010-10-18 17:17:23 -07002130/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002131 * IOC attach time initialization and setup.
2132 *
2133 * @param[in] ioc memory for IOC
2134 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07002135 */
2136void
2137bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002138 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07002139{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002140 ioc->bfa = bfa;
2141 ioc->cbfn = cbfn;
2142 ioc->timer_mod = timer_mod;
2143 ioc->fcmode = BFA_FALSE;
2144 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002145 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002146 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002147
2148 bfa_ioc_mbox_attach(ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002149 INIT_LIST_HEAD(&ioc->notify_q);
Jing Huang7725ccf2009-09-23 17:46:15 -07002150
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002151 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
2152 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07002153}
2154
Jing Huang5fbe25c2010-10-18 17:17:23 -07002155/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002156 * Driver detach time IOC cleanup.
2157 */
2158void
2159bfa_ioc_detach(struct bfa_ioc_s *ioc)
2160{
2161 bfa_fsm_send_event(ioc, IOC_E_DETACH);
2162}
2163
Jing Huang5fbe25c2010-10-18 17:17:23 -07002164/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002165 * Setup IOC PCI properties.
2166 *
2167 * @param[in] pcidev PCI device information for this IOC
2168 */
2169void
2170bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002171 enum bfi_pcifn_class clscode)
Jing Huang7725ccf2009-09-23 17:46:15 -07002172{
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002173 ioc->clscode = clscode;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002174 ioc->pcidev = *pcidev;
Krishna Gudipati11189202011-06-13 15:50:35 -07002175
2176 /*
2177 * Initialize IOC and device personality
2178 */
2179 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
2180 ioc->asic_mode = BFI_ASIC_MODE_FC;
2181
2182 switch (pcidev->device_id) {
2183 case BFA_PCI_DEVICE_ID_FC_8G1P:
2184 case BFA_PCI_DEVICE_ID_FC_8G2P:
2185 ioc->asic_gen = BFI_ASIC_GEN_CB;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002186 ioc->fcmode = BFA_TRUE;
2187 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2188 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002189 break;
2190
2191 case BFA_PCI_DEVICE_ID_CT:
2192 ioc->asic_gen = BFI_ASIC_GEN_CT;
2193 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
2194 ioc->asic_mode = BFI_ASIC_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002195 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
2196 ioc->ad_cap_bm = BFA_CM_CNA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002197 break;
2198
2199 case BFA_PCI_DEVICE_ID_CT_FC:
2200 ioc->asic_gen = BFI_ASIC_GEN_CT;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002201 ioc->fcmode = BFA_TRUE;
2202 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2203 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002204 break;
2205
2206 case BFA_PCI_DEVICE_ID_CT2:
2207 ioc->asic_gen = BFI_ASIC_GEN_CT2;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002208 if (clscode == BFI_PCIFN_CLASS_FC &&
2209 pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002210 ioc->asic_mode = BFI_ASIC_MODE_FC16;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002211 ioc->fcmode = BFA_TRUE;
2212 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2213 ioc->ad_cap_bm = BFA_CM_HBA;
2214 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -07002215 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002216 ioc->asic_mode = BFI_ASIC_MODE_ETH;
2217 if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
2218 ioc->port_mode =
2219 ioc->port_mode_cfg = BFA_MODE_CNA;
2220 ioc->ad_cap_bm = BFA_CM_CNA;
2221 } else {
2222 ioc->port_mode =
2223 ioc->port_mode_cfg = BFA_MODE_NIC;
2224 ioc->ad_cap_bm = BFA_CM_NIC;
2225 }
Krishna Gudipati11189202011-06-13 15:50:35 -07002226 }
2227 break;
2228
2229 default:
2230 WARN_ON(1);
2231 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002232
Jing Huang5fbe25c2010-10-18 17:17:23 -07002233 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002234 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2235 */
Krishna Gudipati11189202011-06-13 15:50:35 -07002236 if (ioc->asic_gen == BFI_ASIC_GEN_CB)
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002237 bfa_ioc_set_cb_hwif(ioc);
Krishna Gudipati11189202011-06-13 15:50:35 -07002238 else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
2239 bfa_ioc_set_ct_hwif(ioc);
2240 else {
2241 WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
2242 bfa_ioc_set_ct2_hwif(ioc);
2243 bfa_ioc_ct2_poweron(ioc);
2244 }
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002245
Jing Huang7725ccf2009-09-23 17:46:15 -07002246 bfa_ioc_map_port(ioc);
2247 bfa_ioc_reg_init(ioc);
2248}
2249
Jing Huang5fbe25c2010-10-18 17:17:23 -07002250/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002251 * Initialize IOC dma memory
2252 *
2253 * @param[in] dm_kva kernel virtual address of IOC dma memory
2254 * @param[in] dm_pa physical address of IOC dma memory
2255 */
2256void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002257bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002258{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002259 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002260 * dma memory for firmware attribute
2261 */
2262 ioc->attr_dma.kva = dm_kva;
2263 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002264 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002265}
2266
Jing Huang7725ccf2009-09-23 17:46:15 -07002267void
2268bfa_ioc_enable(struct bfa_ioc_s *ioc)
2269{
2270 bfa_ioc_stats(ioc, ioc_enables);
2271 ioc->dbg_fwsave_once = BFA_TRUE;
2272
2273 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2274}
2275
2276void
2277bfa_ioc_disable(struct bfa_ioc_s *ioc)
2278{
2279 bfa_ioc_stats(ioc, ioc_disables);
2280 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2281}
2282
Jing Huang7725ccf2009-09-23 17:46:15 -07002283
Jing Huang5fbe25c2010-10-18 17:17:23 -07002284/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002285 * Initialize memory for saving firmware trace. Driver must initialize
2286 * trace memory before call bfa_ioc_enable().
2287 */
2288void
2289bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2290{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002291 ioc->dbg_fwsave = dbg_fwsave;
Maggie Zhangf7f73812010-12-09 19:08:43 -08002292 ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0;
Jing Huang7725ccf2009-09-23 17:46:15 -07002293}
2294
Jing Huang5fbe25c2010-10-18 17:17:23 -07002295/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002296 * Register mailbox message handler functions
2297 *
2298 * @param[in] ioc IOC instance
2299 * @param[in] mcfuncs message class handler functions
2300 */
2301void
2302bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2303{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002304 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2305 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002306
2307 for (mc = 0; mc < BFI_MC_MAX; mc++)
2308 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2309}
2310
Jing Huang5fbe25c2010-10-18 17:17:23 -07002311/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002312 * Register mailbox message handler function, to be called by common modules
2313 */
2314void
2315bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2316 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2317{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002318 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002319
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002320 mod->mbhdlr[mc].cbfn = cbfn;
2321 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002322}
2323
Jing Huang5fbe25c2010-10-18 17:17:23 -07002324/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002325 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2326 * Responsibility of caller to serialize
2327 *
2328 * @param[in] ioc IOC instance
2329 * @param[i] cmd Mailbox command
2330 */
2331void
2332bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2333{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002334 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2335 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002336
Jing Huang5fbe25c2010-10-18 17:17:23 -07002337 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002338 * If a previous command is pending, queue new command
2339 */
2340 if (!list_empty(&mod->cmd_q)) {
2341 list_add_tail(&cmd->qe, &mod->cmd_q);
2342 return;
2343 }
2344
Jing Huang5fbe25c2010-10-18 17:17:23 -07002345 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002346 * If mailbox is busy, queue command for poll timer
2347 */
Jing Huang53440262010-10-18 17:12:29 -07002348 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002349 if (stat) {
2350 list_add_tail(&cmd->qe, &mod->cmd_q);
2351 return;
2352 }
2353
Jing Huang5fbe25c2010-10-18 17:17:23 -07002354 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002355 * mailbox is free -- queue command to firmware
2356 */
2357 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2358}
2359
Jing Huang5fbe25c2010-10-18 17:17:23 -07002360/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002361 * Handle mailbox interrupts
2362 */
2363void
2364bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2365{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002366 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2367 struct bfi_mbmsg_s m;
2368 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002369
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002370 if (bfa_ioc_msgget(ioc, &m)) {
2371 /*
2372 * Treat IOC message class as special.
2373 */
2374 mc = m.mh.msg_class;
2375 if (mc == BFI_MC_IOC) {
2376 bfa_ioc_isr(ioc, &m);
2377 return;
2378 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002379
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002380 if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
2381 return;
2382
2383 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
Jing Huang7725ccf2009-09-23 17:46:15 -07002384 }
2385
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002386 bfa_ioc_lpu_read_stat(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002387
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002388 /*
2389 * Try to send pending mailbox commands
2390 */
2391 bfa_ioc_mbox_poll(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002392}
2393
2394void
2395bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2396{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002397 bfa_ioc_stats(ioc, ioc_hbfails);
2398 ioc->stats.hb_count = ioc->hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07002399 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2400}
2401
Jing Huanged969322010-07-08 19:45:56 -07002402void
2403bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc)
2404{
2405 ioc->fcmode = BFA_TRUE;
Jing Huanged969322010-07-08 19:45:56 -07002406}
2407
Jing Huang5fbe25c2010-10-18 17:17:23 -07002408/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002409 * return true if IOC is disabled
2410 */
2411bfa_boolean_t
2412bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2413{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002414 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2415 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002416}
2417
Jing Huang5fbe25c2010-10-18 17:17:23 -07002418/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07002419 * Return TRUE if IOC is in acquiring address state
2420 */
2421bfa_boolean_t
2422bfa_ioc_is_acq_addr(struct bfa_ioc_s *ioc)
2423{
2424 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_acq_addr);
2425}
2426
2427/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002428 * return true if IOC firmware is different.
2429 */
2430bfa_boolean_t
2431bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2432{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002433 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2434 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2435 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002436}
2437
2438#define bfa_ioc_state_disabled(__sm) \
2439 (((__sm) == BFI_IOC_UNINIT) || \
2440 ((__sm) == BFI_IOC_INITING) || \
2441 ((__sm) == BFI_IOC_HWINIT) || \
2442 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002443 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002444 ((__sm) == BFI_IOC_CFG_DISABLED))
2445
Jing Huang5fbe25c2010-10-18 17:17:23 -07002446/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002447 * Check if adapter is disabled -- both IOCs should be in a disabled
2448 * state.
2449 */
2450bfa_boolean_t
2451bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2452{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002453 u32 ioc_state;
Jing Huang7725ccf2009-09-23 17:46:15 -07002454
2455 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2456 return BFA_FALSE;
2457
Krishna Gudipati11189202011-06-13 15:50:35 -07002458 ioc_state = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07002459 if (!bfa_ioc_state_disabled(ioc_state))
2460 return BFA_FALSE;
2461
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002462 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002463 ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002464 if (!bfa_ioc_state_disabled(ioc_state))
2465 return BFA_FALSE;
2466 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002467
2468 return BFA_TRUE;
2469}
2470
Jing Huang8f4bfad2010-12-26 21:50:10 -08002471/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002472 * Reset IOC fwstate registers.
2473 */
2474void
2475bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2476{
2477 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2478 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2479}
2480
Jing Huang7725ccf2009-09-23 17:46:15 -07002481#define BFA_MFG_NAME "Brocade"
2482void
2483bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2484 struct bfa_adapter_attr_s *ad_attr)
2485{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002486 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002487
2488 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002489
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002490 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2491 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2492 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2493 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002494 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002495 sizeof(struct bfa_mfg_vpd_s));
2496
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002497 ad_attr->nports = bfa_ioc_get_nports(ioc);
2498 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002499
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002500 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2501 /* For now, model descr uses same model string */
2502 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002503
Jing Huanged969322010-07-08 19:45:56 -07002504 ad_attr->card_type = ioc_attr->card_type;
2505 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2506
Jing Huang7725ccf2009-09-23 17:46:15 -07002507 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2508 ad_attr->prototype = 1;
2509 else
2510 ad_attr->prototype = 0;
2511
Maggie Zhangf7f73812010-12-09 19:08:43 -08002512 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002513 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002514
2515 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2516 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2517 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2518 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002519
2520 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002521
Krishna Gudipati11189202011-06-13 15:50:35 -07002522 ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
2523 ad_attr->trunk_capable = (ad_attr->nports > 1) &&
2524 !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
Jing Huang7725ccf2009-09-23 17:46:15 -07002525}
2526
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002527enum bfa_ioc_type_e
2528bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2529{
Krishna Gudipati11189202011-06-13 15:50:35 -07002530 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002531 return BFA_IOC_TYPE_LL;
Krishna Gudipati11189202011-06-13 15:50:35 -07002532
2533 WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
2534
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002535 return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
Krishna Gudipati11189202011-06-13 15:50:35 -07002536 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002537}
2538
Jing Huang7725ccf2009-09-23 17:46:15 -07002539void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002540bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2541{
Jing Huang6a18b162010-10-18 17:08:54 -07002542 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2543 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002544 (void *)ioc->attr->brcd_serialnum,
2545 BFA_ADAPTER_SERIAL_NUM_LEN);
2546}
2547
2548void
2549bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2550{
Jing Huang6a18b162010-10-18 17:08:54 -07002551 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2552 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002553}
2554
2555void
2556bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2557{
Jing Huangd4b671c2010-12-26 21:46:35 -08002558 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002559
Jing Huang6a18b162010-10-18 17:08:54 -07002560 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002561
2562 chip_rev[0] = 'R';
2563 chip_rev[1] = 'e';
2564 chip_rev[2] = 'v';
2565 chip_rev[3] = '-';
2566 chip_rev[4] = ioc->attr->asic_rev;
2567 chip_rev[5] = '\0';
2568}
2569
2570void
2571bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2572{
Jing Huang6a18b162010-10-18 17:08:54 -07002573 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2574 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002575 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002576}
2577
2578void
2579bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2580{
Jing Huang6a18b162010-10-18 17:08:54 -07002581 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2582 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002583}
2584
2585void
2586bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2587{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002588 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002589
Jing Huangd4b671c2010-12-26 21:46:35 -08002590 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002591 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002592
2593 ioc_attr = ioc->attr;
2594
Jing Huang5fbe25c2010-10-18 17:17:23 -07002595 /*
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002596 * model name
2597 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002598 if (ioc->asic_gen == BFI_ASIC_GEN_CT2) {
2599 int np = bfa_ioc_get_nports(ioc);
2600 char c;
2601 switch (ioc_attr->card_type) {
2602 case BFA_MFG_TYPE_PROWLER_F:
2603 case BFA_MFG_TYPE_PROWLER_N:
2604 case BFA_MFG_TYPE_PROWLER_C:
2605 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN,
2606 "%s-%u-%u",
2607 BFA_MFG_NAME, ioc_attr->card_type, np);
2608 break;
2609 case BFA_MFG_TYPE_PROWLER_D:
2610 if (ioc_attr->ic == BFA_MFG_IC_FC)
2611 c = 'F';
2612 else
2613 c = 'P';
2614
2615 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN,
2616 "%s-%u-%u%c",
2617 BFA_MFG_NAME, ioc_attr->card_type, np, c);
2618 break;
2619 default:
2620 break;
2621 }
2622 } else
2623 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
2624 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002625}
2626
2627enum bfa_ioc_state
2628bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2629{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002630 enum bfa_iocpf_state iocpf_st;
2631 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2632
2633 if (ioc_st == BFA_IOC_ENABLING ||
2634 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2635
2636 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2637
2638 switch (iocpf_st) {
2639 case BFA_IOCPF_SEMWAIT:
2640 ioc_st = BFA_IOC_SEMWAIT;
2641 break;
2642
2643 case BFA_IOCPF_HWINIT:
2644 ioc_st = BFA_IOC_HWINIT;
2645 break;
2646
2647 case BFA_IOCPF_FWMISMATCH:
2648 ioc_st = BFA_IOC_FWMISMATCH;
2649 break;
2650
2651 case BFA_IOCPF_FAIL:
2652 ioc_st = BFA_IOC_FAIL;
2653 break;
2654
2655 case BFA_IOCPF_INITFAIL:
2656 ioc_st = BFA_IOC_INITFAIL;
2657 break;
2658
2659 default:
2660 break;
2661 }
2662 }
2663
2664 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002665}
2666
2667void
Jing Huang7725ccf2009-09-23 17:46:15 -07002668bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2669{
Jing Huang6a18b162010-10-18 17:08:54 -07002670 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002671
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002672 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002673 ioc_attr->port_id = ioc->port_id;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002674 ioc_attr->port_mode = ioc->port_mode;
2675 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2676 ioc_attr->cap_bm = ioc->ad_cap_bm;
Jing Huang7725ccf2009-09-23 17:46:15 -07002677
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002678 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002679
2680 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2681
2682 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2683 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002684 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002685}
2686
Jing Huang7725ccf2009-09-23 17:46:15 -07002687mac_t
2688bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2689{
Jing Huang15b64a82010-07-08 19:48:12 -07002690 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002691 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002692 */
2693 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002694 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002695 else
2696 return ioc->attr->mac;
2697}
2698
Jing Huang15b64a82010-07-08 19:48:12 -07002699mac_t
2700bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2701{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002702 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002703
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002704 m = ioc->attr->mfg_mac;
2705 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2706 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2707 else
2708 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2709 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002710
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002711 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002712}
2713
Jing Huang7725ccf2009-09-23 17:46:15 -07002714bfa_boolean_t
2715bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc)
2716{
Krishna Gudipati11189202011-06-13 15:50:35 -07002717 return ioc->fcmode || bfa_asic_id_cb(ioc->pcidev.device_id);
Jing Huang7725ccf2009-09-23 17:46:15 -07002718}
2719
Jing Huang5fbe25c2010-10-18 17:17:23 -07002720/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002721 * Retrieve saved firmware trace from a prior IOC failure.
2722 */
2723bfa_status_t
2724bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2725{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002726 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002727
2728 if (ioc->dbg_fwsave_len == 0)
2729 return BFA_STATUS_ENOFSAVE;
2730
2731 tlen = *trclen;
2732 if (tlen > ioc->dbg_fwsave_len)
2733 tlen = ioc->dbg_fwsave_len;
2734
Jing Huang6a18b162010-10-18 17:08:54 -07002735 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002736 *trclen = tlen;
2737 return BFA_STATUS_OK;
2738}
2739
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002740
Jing Huang5fbe25c2010-10-18 17:17:23 -07002741/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002742 * Retrieve saved firmware trace from a prior IOC failure.
2743 */
2744bfa_status_t
2745bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2746{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002747 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2748 int tlen;
2749 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002750
2751 bfa_trc(ioc, *trclen);
2752
Jing Huang7725ccf2009-09-23 17:46:15 -07002753 tlen = *trclen;
2754 if (tlen > BFA_DBG_FWTRC_LEN)
2755 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002756
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002757 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2758 *trclen = tlen;
2759 return status;
2760}
Jing Huang7725ccf2009-09-23 17:46:15 -07002761
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002762static void
2763bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2764{
2765 struct bfa_mbox_cmd_s cmd;
2766 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002767
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002768 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2769 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002770 req->clscode = cpu_to_be16(ioc->clscode);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002771 bfa_ioc_mbox_queue(ioc, &cmd);
2772}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002773
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002774static void
2775bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2776{
2777 u32 fwsync_iter = 1000;
2778
2779 bfa_ioc_send_fwsync(ioc);
2780
Jing Huang5fbe25c2010-10-18 17:17:23 -07002781 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002782 * After sending a fw sync mbox command wait for it to
2783 * take effect. We will not wait for a response because
2784 * 1. fw_sync mbox cmd doesn't have a response.
2785 * 2. Even if we implement that, interrupts might not
2786 * be enabled when we call this function.
2787 * So, just keep checking if any mbox cmd is pending, and
2788 * after waiting for a reasonable amount of time, go ahead.
2789 * It is possible that fw has crashed and the mbox command
2790 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002791 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002792 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2793 fwsync_iter--;
2794}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002795
Jing Huang5fbe25c2010-10-18 17:17:23 -07002796/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002797 * Dump firmware smem
2798 */
2799bfa_status_t
2800bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2801 u32 *offset, int *buflen)
2802{
2803 u32 loff;
2804 int dlen;
2805 bfa_status_t status;
2806 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002807
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002808 if (*offset >= smem_len) {
2809 *offset = *buflen = 0;
2810 return BFA_STATUS_EINVAL;
2811 }
2812
2813 loff = *offset;
2814 dlen = *buflen;
2815
Jing Huang5fbe25c2010-10-18 17:17:23 -07002816 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002817 * First smem read, sync smem before proceeding
2818 * No need to sync before reading every chunk.
2819 */
2820 if (loff == 0)
2821 bfa_ioc_fwsync(ioc);
2822
2823 if ((loff + dlen) >= smem_len)
2824 dlen = smem_len - loff;
2825
2826 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2827
2828 if (status != BFA_STATUS_OK) {
2829 *offset = *buflen = 0;
2830 return status;
2831 }
2832
2833 *offset += dlen;
2834
2835 if (*offset >= smem_len)
2836 *offset = 0;
2837
2838 *buflen = dlen;
2839
2840 return status;
2841}
2842
Jing Huang5fbe25c2010-10-18 17:17:23 -07002843/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002844 * Firmware statistics
2845 */
2846bfa_status_t
2847bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2848{
2849 u32 loff = BFI_IOC_FWSTATS_OFF + \
2850 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2851 int tlen;
2852 bfa_status_t status;
2853
2854 if (ioc->stats_busy) {
2855 bfa_trc(ioc, ioc->stats_busy);
2856 return BFA_STATUS_DEVBUSY;
2857 }
2858 ioc->stats_busy = BFA_TRUE;
2859
2860 tlen = sizeof(struct bfa_fw_stats_s);
2861 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2862
2863 ioc->stats_busy = BFA_FALSE;
2864 return status;
2865}
2866
2867bfa_status_t
2868bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2869{
2870 u32 loff = BFI_IOC_FWSTATS_OFF + \
2871 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2872 int tlen;
2873 bfa_status_t status;
2874
2875 if (ioc->stats_busy) {
2876 bfa_trc(ioc, ioc->stats_busy);
2877 return BFA_STATUS_DEVBUSY;
2878 }
2879 ioc->stats_busy = BFA_TRUE;
2880
2881 tlen = sizeof(struct bfa_fw_stats_s);
2882 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2883
2884 ioc->stats_busy = BFA_FALSE;
2885 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002886}
2887
Jing Huang5fbe25c2010-10-18 17:17:23 -07002888/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002889 * Save firmware trace if configured.
2890 */
2891static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002892bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002893{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002894 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002895
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002896 if (ioc->dbg_fwsave_once) {
2897 ioc->dbg_fwsave_once = BFA_FALSE;
2898 if (ioc->dbg_fwsave_len) {
2899 tlen = ioc->dbg_fwsave_len;
2900 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2901 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002902 }
2903}
2904
Jing Huang5fbe25c2010-10-18 17:17:23 -07002905/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002906 * Firmware failure detected. Start recovery actions.
2907 */
2908static void
2909bfa_ioc_recover(struct bfa_ioc_s *ioc)
2910{
Jing Huang7725ccf2009-09-23 17:46:15 -07002911 bfa_ioc_stats(ioc, ioc_hbfails);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002912 ioc->stats.hb_count = ioc->hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07002913 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2914}
2915
Jing Huang7725ccf2009-09-23 17:46:15 -07002916static void
Jing Huang07b28382010-07-08 19:59:24 -07002917bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002918{
Jing Huang07b28382010-07-08 19:59:24 -07002919 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2920 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002921}
2922
Jing Huang5fbe25c2010-10-18 17:17:23 -07002923/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002924 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002925 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002926static void
2927bfa_iocpf_timeout(void *ioc_arg)
2928{
2929 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2930
2931 bfa_trc(ioc, 0);
2932 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2933}
2934
2935static void
2936bfa_iocpf_sem_timeout(void *ioc_arg)
2937{
2938 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2939
2940 bfa_ioc_hw_sem_get(ioc);
2941}
2942
Krishna Gudipati775c7742011-06-13 15:52:12 -07002943static void
2944bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
2945{
2946 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
2947
2948 bfa_trc(ioc, fwstate);
2949
2950 if (fwstate == BFI_IOC_DISABLED) {
2951 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2952 return;
2953 }
2954
2955 if (ioc->iocpf.poll_time >= BFA_IOC_TOV)
2956 bfa_iocpf_timeout(ioc);
2957 else {
2958 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2959 bfa_iocpf_poll_timer_start(ioc);
2960 }
2961}
2962
2963static void
2964bfa_iocpf_poll_timeout(void *ioc_arg)
2965{
2966 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2967
2968 bfa_ioc_poll_fwinit(ioc);
2969}
2970
Jing Huang5fbe25c2010-10-18 17:17:23 -07002971/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002972 * bfa timer function
2973 */
2974void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002975bfa_timer_beat(struct bfa_timer_mod_s *mod)
2976{
2977 struct list_head *qh = &mod->timer_q;
2978 struct list_head *qe, *qe_next;
2979 struct bfa_timer_s *elem;
2980 struct list_head timedout_q;
2981
2982 INIT_LIST_HEAD(&timedout_q);
2983
2984 qe = bfa_q_next(qh);
2985
2986 while (qe != qh) {
2987 qe_next = bfa_q_next(qe);
2988
2989 elem = (struct bfa_timer_s *) qe;
2990 if (elem->timeout <= BFA_TIMER_FREQ) {
2991 elem->timeout = 0;
2992 list_del(&elem->qe);
2993 list_add_tail(&elem->qe, &timedout_q);
2994 } else {
2995 elem->timeout -= BFA_TIMER_FREQ;
2996 }
2997
2998 qe = qe_next; /* go to next elem */
2999 }
3000
3001 /*
3002 * Pop all the timeout entries
3003 */
3004 while (!list_empty(&timedout_q)) {
3005 bfa_q_deq(&timedout_q, &elem);
3006 elem->timercb(elem->arg);
3007 }
3008}
3009
Jing Huang5fbe25c2010-10-18 17:17:23 -07003010/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003011 * Should be called with lock protection
3012 */
3013void
3014bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
3015 void (*timercb) (void *), void *arg, unsigned int timeout)
3016{
3017
Jing Huangd4b671c2010-12-26 21:46:35 -08003018 WARN_ON(timercb == NULL);
3019 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003020
3021 timer->timeout = timeout;
3022 timer->timercb = timercb;
3023 timer->arg = arg;
3024
3025 list_add_tail(&timer->qe, &mod->timer_q);
3026}
3027
Jing Huang5fbe25c2010-10-18 17:17:23 -07003028/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003029 * Should be called with lock protection
3030 */
3031void
3032bfa_timer_stop(struct bfa_timer_s *timer)
3033{
Jing Huangd4b671c2010-12-26 21:46:35 -08003034 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003035
3036 list_del(&timer->qe);
3037}
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003038
3039/*
3040 * ASIC block related
3041 */
3042static void
3043bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
3044{
3045 struct bfa_ablk_cfg_inst_s *cfg_inst;
3046 int i, j;
3047 u16 be16;
3048 u32 be32;
3049
3050 for (i = 0; i < BFA_ABLK_MAX; i++) {
3051 cfg_inst = &cfg->inst[i];
3052 for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
3053 be16 = cfg_inst->pf_cfg[j].pers;
3054 cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
3055 be16 = cfg_inst->pf_cfg[j].num_qpairs;
3056 cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
3057 be16 = cfg_inst->pf_cfg[j].num_vectors;
3058 cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
3059 be32 = cfg_inst->pf_cfg[j].bw;
3060 cfg_inst->pf_cfg[j].bw = be16_to_cpu(be32);
3061 }
3062 }
3063}
3064
3065static void
3066bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
3067{
3068 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3069 struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
3070 bfa_ablk_cbfn_t cbfn;
3071
3072 WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
3073 bfa_trc(ablk->ioc, msg->mh.msg_id);
3074
3075 switch (msg->mh.msg_id) {
3076 case BFI_ABLK_I2H_QUERY:
3077 if (rsp->status == BFA_STATUS_OK) {
3078 memcpy(ablk->cfg, ablk->dma_addr.kva,
3079 sizeof(struct bfa_ablk_cfg_s));
3080 bfa_ablk_config_swap(ablk->cfg);
3081 ablk->cfg = NULL;
3082 }
3083 break;
3084
3085 case BFI_ABLK_I2H_ADPT_CONFIG:
3086 case BFI_ABLK_I2H_PORT_CONFIG:
3087 /* update config port mode */
3088 ablk->ioc->port_mode_cfg = rsp->port_mode;
3089
3090 case BFI_ABLK_I2H_PF_DELETE:
3091 case BFI_ABLK_I2H_PF_UPDATE:
3092 case BFI_ABLK_I2H_OPTROM_ENABLE:
3093 case BFI_ABLK_I2H_OPTROM_DISABLE:
3094 /* No-op */
3095 break;
3096
3097 case BFI_ABLK_I2H_PF_CREATE:
3098 *(ablk->pcifn) = rsp->pcifn;
3099 ablk->pcifn = NULL;
3100 break;
3101
3102 default:
3103 WARN_ON(1);
3104 }
3105
3106 ablk->busy = BFA_FALSE;
3107 if (ablk->cbfn) {
3108 cbfn = ablk->cbfn;
3109 ablk->cbfn = NULL;
3110 cbfn(ablk->cbarg, rsp->status);
3111 }
3112}
3113
3114static void
3115bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
3116{
3117 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3118
3119 bfa_trc(ablk->ioc, event);
3120
3121 switch (event) {
3122 case BFA_IOC_E_ENABLED:
3123 WARN_ON(ablk->busy != BFA_FALSE);
3124 break;
3125
3126 case BFA_IOC_E_DISABLED:
3127 case BFA_IOC_E_FAILED:
3128 /* Fail any pending requests */
3129 ablk->pcifn = NULL;
3130 if (ablk->busy) {
3131 if (ablk->cbfn)
3132 ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
3133 ablk->cbfn = NULL;
3134 ablk->busy = BFA_FALSE;
3135 }
3136 break;
3137
3138 default:
3139 WARN_ON(1);
3140 break;
3141 }
3142}
3143
3144u32
3145bfa_ablk_meminfo(void)
3146{
3147 return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
3148}
3149
3150void
3151bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
3152{
3153 ablk->dma_addr.kva = dma_kva;
3154 ablk->dma_addr.pa = dma_pa;
3155}
3156
3157void
3158bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
3159{
3160 ablk->ioc = ioc;
3161
3162 bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
3163 bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
3164 list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
3165}
3166
3167bfa_status_t
3168bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
3169 bfa_ablk_cbfn_t cbfn, void *cbarg)
3170{
3171 struct bfi_ablk_h2i_query_s *m;
3172
3173 WARN_ON(!ablk_cfg);
3174
3175 if (!bfa_ioc_is_operational(ablk->ioc)) {
3176 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3177 return BFA_STATUS_IOC_FAILURE;
3178 }
3179
3180 if (ablk->busy) {
3181 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3182 return BFA_STATUS_DEVBUSY;
3183 }
3184
3185 ablk->cfg = ablk_cfg;
3186 ablk->cbfn = cbfn;
3187 ablk->cbarg = cbarg;
3188 ablk->busy = BFA_TRUE;
3189
3190 m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
3191 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
3192 bfa_ioc_portid(ablk->ioc));
3193 bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
3194 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3195
3196 return BFA_STATUS_OK;
3197}
3198
3199bfa_status_t
3200bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
3201 u8 port, enum bfi_pcifn_class personality, int bw,
3202 bfa_ablk_cbfn_t cbfn, void *cbarg)
3203{
3204 struct bfi_ablk_h2i_pf_req_s *m;
3205
3206 if (!bfa_ioc_is_operational(ablk->ioc)) {
3207 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3208 return BFA_STATUS_IOC_FAILURE;
3209 }
3210
3211 if (ablk->busy) {
3212 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3213 return BFA_STATUS_DEVBUSY;
3214 }
3215
3216 ablk->pcifn = pcifn;
3217 ablk->cbfn = cbfn;
3218 ablk->cbarg = cbarg;
3219 ablk->busy = BFA_TRUE;
3220
3221 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3222 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
3223 bfa_ioc_portid(ablk->ioc));
3224 m->pers = cpu_to_be16((u16)personality);
3225 m->bw = cpu_to_be32(bw);
3226 m->port = port;
3227 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3228
3229 return BFA_STATUS_OK;
3230}
3231
3232bfa_status_t
3233bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
3234 bfa_ablk_cbfn_t cbfn, void *cbarg)
3235{
3236 struct bfi_ablk_h2i_pf_req_s *m;
3237
3238 if (!bfa_ioc_is_operational(ablk->ioc)) {
3239 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3240 return BFA_STATUS_IOC_FAILURE;
3241 }
3242
3243 if (ablk->busy) {
3244 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3245 return BFA_STATUS_DEVBUSY;
3246 }
3247
3248 ablk->cbfn = cbfn;
3249 ablk->cbarg = cbarg;
3250 ablk->busy = BFA_TRUE;
3251
3252 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3253 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
3254 bfa_ioc_portid(ablk->ioc));
3255 m->pcifn = (u8)pcifn;
3256 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3257
3258 return BFA_STATUS_OK;
3259}
3260
3261bfa_status_t
3262bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
3263 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3264{
3265 struct bfi_ablk_h2i_cfg_req_s *m;
3266
3267 if (!bfa_ioc_is_operational(ablk->ioc)) {
3268 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3269 return BFA_STATUS_IOC_FAILURE;
3270 }
3271
3272 if (ablk->busy) {
3273 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3274 return BFA_STATUS_DEVBUSY;
3275 }
3276
3277 ablk->cbfn = cbfn;
3278 ablk->cbarg = cbarg;
3279 ablk->busy = BFA_TRUE;
3280
3281 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3282 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
3283 bfa_ioc_portid(ablk->ioc));
3284 m->mode = (u8)mode;
3285 m->max_pf = (u8)max_pf;
3286 m->max_vf = (u8)max_vf;
3287 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3288
3289 return BFA_STATUS_OK;
3290}
3291
3292bfa_status_t
3293bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
3294 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3295{
3296 struct bfi_ablk_h2i_cfg_req_s *m;
3297
3298 if (!bfa_ioc_is_operational(ablk->ioc)) {
3299 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3300 return BFA_STATUS_IOC_FAILURE;
3301 }
3302
3303 if (ablk->busy) {
3304 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3305 return BFA_STATUS_DEVBUSY;
3306 }
3307
3308 ablk->cbfn = cbfn;
3309 ablk->cbarg = cbarg;
3310 ablk->busy = BFA_TRUE;
3311
3312 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3313 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
3314 bfa_ioc_portid(ablk->ioc));
3315 m->port = (u8)port;
3316 m->mode = (u8)mode;
3317 m->max_pf = (u8)max_pf;
3318 m->max_vf = (u8)max_vf;
3319 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3320
3321 return BFA_STATUS_OK;
3322}
3323
3324bfa_status_t
3325bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw,
3326 bfa_ablk_cbfn_t cbfn, void *cbarg)
3327{
3328 struct bfi_ablk_h2i_pf_req_s *m;
3329
3330 if (!bfa_ioc_is_operational(ablk->ioc)) {
3331 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3332 return BFA_STATUS_IOC_FAILURE;
3333 }
3334
3335 if (ablk->busy) {
3336 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3337 return BFA_STATUS_DEVBUSY;
3338 }
3339
3340 ablk->cbfn = cbfn;
3341 ablk->cbarg = cbarg;
3342 ablk->busy = BFA_TRUE;
3343
3344 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3345 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
3346 bfa_ioc_portid(ablk->ioc));
3347 m->pcifn = (u8)pcifn;
3348 m->bw = cpu_to_be32(bw);
3349 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3350
3351 return BFA_STATUS_OK;
3352}
3353
3354bfa_status_t
3355bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3356{
3357 struct bfi_ablk_h2i_optrom_s *m;
3358
3359 if (!bfa_ioc_is_operational(ablk->ioc)) {
3360 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3361 return BFA_STATUS_IOC_FAILURE;
3362 }
3363
3364 if (ablk->busy) {
3365 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3366 return BFA_STATUS_DEVBUSY;
3367 }
3368
3369 ablk->cbfn = cbfn;
3370 ablk->cbarg = cbarg;
3371 ablk->busy = BFA_TRUE;
3372
3373 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3374 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
3375 bfa_ioc_portid(ablk->ioc));
3376 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3377
3378 return BFA_STATUS_OK;
3379}
3380
3381bfa_status_t
3382bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3383{
3384 struct bfi_ablk_h2i_optrom_s *m;
3385
3386 if (!bfa_ioc_is_operational(ablk->ioc)) {
3387 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3388 return BFA_STATUS_IOC_FAILURE;
3389 }
3390
3391 if (ablk->busy) {
3392 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3393 return BFA_STATUS_DEVBUSY;
3394 }
3395
3396 ablk->cbfn = cbfn;
3397 ablk->cbarg = cbarg;
3398 ablk->busy = BFA_TRUE;
3399
3400 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3401 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
3402 bfa_ioc_portid(ablk->ioc));
3403 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3404
3405 return BFA_STATUS_OK;
3406}