blob: d579036b08b726e5f4b9db5475c3472628ef1527 [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 Huang5fbe25c2010-10-18 17:17:23 -07002402/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002403 * return true if IOC is disabled
2404 */
2405bfa_boolean_t
2406bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2407{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002408 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2409 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002410}
2411
Jing Huang5fbe25c2010-10-18 17:17:23 -07002412/*
Krishna Gudipatia7141342011-06-24 20:23:19 -07002413 * Return TRUE if IOC is in acquiring address state
2414 */
2415bfa_boolean_t
2416bfa_ioc_is_acq_addr(struct bfa_ioc_s *ioc)
2417{
2418 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_acq_addr);
2419}
2420
2421/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002422 * return true if IOC firmware is different.
2423 */
2424bfa_boolean_t
2425bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2426{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002427 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2428 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2429 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002430}
2431
2432#define bfa_ioc_state_disabled(__sm) \
2433 (((__sm) == BFI_IOC_UNINIT) || \
2434 ((__sm) == BFI_IOC_INITING) || \
2435 ((__sm) == BFI_IOC_HWINIT) || \
2436 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002437 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002438 ((__sm) == BFI_IOC_CFG_DISABLED))
2439
Jing Huang5fbe25c2010-10-18 17:17:23 -07002440/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002441 * Check if adapter is disabled -- both IOCs should be in a disabled
2442 * state.
2443 */
2444bfa_boolean_t
2445bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2446{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002447 u32 ioc_state;
Jing Huang7725ccf2009-09-23 17:46:15 -07002448
2449 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2450 return BFA_FALSE;
2451
Krishna Gudipati11189202011-06-13 15:50:35 -07002452 ioc_state = readl(ioc->ioc_regs.ioc_fwstate);
Jing Huang7725ccf2009-09-23 17:46:15 -07002453 if (!bfa_ioc_state_disabled(ioc_state))
2454 return BFA_FALSE;
2455
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002456 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002457 ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002458 if (!bfa_ioc_state_disabled(ioc_state))
2459 return BFA_FALSE;
2460 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002461
2462 return BFA_TRUE;
2463}
2464
Jing Huang8f4bfad2010-12-26 21:50:10 -08002465/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002466 * Reset IOC fwstate registers.
2467 */
2468void
2469bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2470{
2471 writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate);
2472 writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate);
2473}
2474
Jing Huang7725ccf2009-09-23 17:46:15 -07002475#define BFA_MFG_NAME "Brocade"
2476void
2477bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2478 struct bfa_adapter_attr_s *ad_attr)
2479{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002480 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002481
2482 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002483
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002484 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2485 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2486 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2487 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002488 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002489 sizeof(struct bfa_mfg_vpd_s));
2490
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002491 ad_attr->nports = bfa_ioc_get_nports(ioc);
2492 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002493
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002494 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2495 /* For now, model descr uses same model string */
2496 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002497
Jing Huanged969322010-07-08 19:45:56 -07002498 ad_attr->card_type = ioc_attr->card_type;
2499 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2500
Jing Huang7725ccf2009-09-23 17:46:15 -07002501 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2502 ad_attr->prototype = 1;
2503 else
2504 ad_attr->prototype = 0;
2505
Maggie Zhangf7f73812010-12-09 19:08:43 -08002506 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002507 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002508
2509 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2510 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2511 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2512 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002513
2514 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002515
Krishna Gudipati11189202011-06-13 15:50:35 -07002516 ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
2517 ad_attr->trunk_capable = (ad_attr->nports > 1) &&
2518 !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
Jing Huang7725ccf2009-09-23 17:46:15 -07002519}
2520
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002521enum bfa_ioc_type_e
2522bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2523{
Krishna Gudipati11189202011-06-13 15:50:35 -07002524 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002525 return BFA_IOC_TYPE_LL;
Krishna Gudipati11189202011-06-13 15:50:35 -07002526
2527 WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
2528
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002529 return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
Krishna Gudipati11189202011-06-13 15:50:35 -07002530 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002531}
2532
Jing Huang7725ccf2009-09-23 17:46:15 -07002533void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002534bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2535{
Jing Huang6a18b162010-10-18 17:08:54 -07002536 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2537 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002538 (void *)ioc->attr->brcd_serialnum,
2539 BFA_ADAPTER_SERIAL_NUM_LEN);
2540}
2541
2542void
2543bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2544{
Jing Huang6a18b162010-10-18 17:08:54 -07002545 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2546 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002547}
2548
2549void
2550bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2551{
Jing Huangd4b671c2010-12-26 21:46:35 -08002552 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002553
Jing Huang6a18b162010-10-18 17:08:54 -07002554 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002555
2556 chip_rev[0] = 'R';
2557 chip_rev[1] = 'e';
2558 chip_rev[2] = 'v';
2559 chip_rev[3] = '-';
2560 chip_rev[4] = ioc->attr->asic_rev;
2561 chip_rev[5] = '\0';
2562}
2563
2564void
2565bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2566{
Jing Huang6a18b162010-10-18 17:08:54 -07002567 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2568 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002569 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002570}
2571
2572void
2573bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2574{
Jing Huang6a18b162010-10-18 17:08:54 -07002575 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2576 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002577}
2578
2579void
2580bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2581{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002582 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002583
Jing Huangd4b671c2010-12-26 21:46:35 -08002584 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002585 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002586
2587 ioc_attr = ioc->attr;
2588
Krishna Gudipati10a07372011-06-24 20:23:38 -07002589 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002590 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002591}
2592
2593enum bfa_ioc_state
2594bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2595{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002596 enum bfa_iocpf_state iocpf_st;
2597 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2598
2599 if (ioc_st == BFA_IOC_ENABLING ||
2600 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2601
2602 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2603
2604 switch (iocpf_st) {
2605 case BFA_IOCPF_SEMWAIT:
2606 ioc_st = BFA_IOC_SEMWAIT;
2607 break;
2608
2609 case BFA_IOCPF_HWINIT:
2610 ioc_st = BFA_IOC_HWINIT;
2611 break;
2612
2613 case BFA_IOCPF_FWMISMATCH:
2614 ioc_st = BFA_IOC_FWMISMATCH;
2615 break;
2616
2617 case BFA_IOCPF_FAIL:
2618 ioc_st = BFA_IOC_FAIL;
2619 break;
2620
2621 case BFA_IOCPF_INITFAIL:
2622 ioc_st = BFA_IOC_INITFAIL;
2623 break;
2624
2625 default:
2626 break;
2627 }
2628 }
2629
2630 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002631}
2632
2633void
Jing Huang7725ccf2009-09-23 17:46:15 -07002634bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2635{
Jing Huang6a18b162010-10-18 17:08:54 -07002636 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002637
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002638 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002639 ioc_attr->port_id = ioc->port_id;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002640 ioc_attr->port_mode = ioc->port_mode;
2641 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2642 ioc_attr->cap_bm = ioc->ad_cap_bm;
Jing Huang7725ccf2009-09-23 17:46:15 -07002643
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002644 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002645
2646 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2647
2648 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2649 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002650 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002651}
2652
Jing Huang7725ccf2009-09-23 17:46:15 -07002653mac_t
2654bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2655{
Jing Huang15b64a82010-07-08 19:48:12 -07002656 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002657 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002658 */
2659 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002660 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002661 else
2662 return ioc->attr->mac;
2663}
2664
Jing Huang15b64a82010-07-08 19:48:12 -07002665mac_t
2666bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2667{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002668 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002669
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002670 m = ioc->attr->mfg_mac;
2671 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2672 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2673 else
2674 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2675 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002676
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002677 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002678}
2679
Jing Huang5fbe25c2010-10-18 17:17:23 -07002680/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002681 * Retrieve saved firmware trace from a prior IOC failure.
2682 */
2683bfa_status_t
2684bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2685{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002686 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002687
2688 if (ioc->dbg_fwsave_len == 0)
2689 return BFA_STATUS_ENOFSAVE;
2690
2691 tlen = *trclen;
2692 if (tlen > ioc->dbg_fwsave_len)
2693 tlen = ioc->dbg_fwsave_len;
2694
Jing Huang6a18b162010-10-18 17:08:54 -07002695 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002696 *trclen = tlen;
2697 return BFA_STATUS_OK;
2698}
2699
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002700
Jing Huang5fbe25c2010-10-18 17:17:23 -07002701/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002702 * Retrieve saved firmware trace from a prior IOC failure.
2703 */
2704bfa_status_t
2705bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2706{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002707 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2708 int tlen;
2709 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002710
2711 bfa_trc(ioc, *trclen);
2712
Jing Huang7725ccf2009-09-23 17:46:15 -07002713 tlen = *trclen;
2714 if (tlen > BFA_DBG_FWTRC_LEN)
2715 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002716
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002717 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2718 *trclen = tlen;
2719 return status;
2720}
Jing Huang7725ccf2009-09-23 17:46:15 -07002721
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002722static void
2723bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2724{
2725 struct bfa_mbox_cmd_s cmd;
2726 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002727
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002728 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2729 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002730 req->clscode = cpu_to_be16(ioc->clscode);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002731 bfa_ioc_mbox_queue(ioc, &cmd);
2732}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002733
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002734static void
2735bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2736{
2737 u32 fwsync_iter = 1000;
2738
2739 bfa_ioc_send_fwsync(ioc);
2740
Jing Huang5fbe25c2010-10-18 17:17:23 -07002741 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002742 * After sending a fw sync mbox command wait for it to
2743 * take effect. We will not wait for a response because
2744 * 1. fw_sync mbox cmd doesn't have a response.
2745 * 2. Even if we implement that, interrupts might not
2746 * be enabled when we call this function.
2747 * So, just keep checking if any mbox cmd is pending, and
2748 * after waiting for a reasonable amount of time, go ahead.
2749 * It is possible that fw has crashed and the mbox command
2750 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002751 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002752 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2753 fwsync_iter--;
2754}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002755
Jing Huang5fbe25c2010-10-18 17:17:23 -07002756/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002757 * Dump firmware smem
2758 */
2759bfa_status_t
2760bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2761 u32 *offset, int *buflen)
2762{
2763 u32 loff;
2764 int dlen;
2765 bfa_status_t status;
2766 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002767
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002768 if (*offset >= smem_len) {
2769 *offset = *buflen = 0;
2770 return BFA_STATUS_EINVAL;
2771 }
2772
2773 loff = *offset;
2774 dlen = *buflen;
2775
Jing Huang5fbe25c2010-10-18 17:17:23 -07002776 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002777 * First smem read, sync smem before proceeding
2778 * No need to sync before reading every chunk.
2779 */
2780 if (loff == 0)
2781 bfa_ioc_fwsync(ioc);
2782
2783 if ((loff + dlen) >= smem_len)
2784 dlen = smem_len - loff;
2785
2786 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2787
2788 if (status != BFA_STATUS_OK) {
2789 *offset = *buflen = 0;
2790 return status;
2791 }
2792
2793 *offset += dlen;
2794
2795 if (*offset >= smem_len)
2796 *offset = 0;
2797
2798 *buflen = dlen;
2799
2800 return status;
2801}
2802
Jing Huang5fbe25c2010-10-18 17:17:23 -07002803/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002804 * Firmware statistics
2805 */
2806bfa_status_t
2807bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2808{
2809 u32 loff = BFI_IOC_FWSTATS_OFF + \
2810 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2811 int tlen;
2812 bfa_status_t status;
2813
2814 if (ioc->stats_busy) {
2815 bfa_trc(ioc, ioc->stats_busy);
2816 return BFA_STATUS_DEVBUSY;
2817 }
2818 ioc->stats_busy = BFA_TRUE;
2819
2820 tlen = sizeof(struct bfa_fw_stats_s);
2821 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2822
2823 ioc->stats_busy = BFA_FALSE;
2824 return status;
2825}
2826
2827bfa_status_t
2828bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2829{
2830 u32 loff = BFI_IOC_FWSTATS_OFF + \
2831 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2832 int tlen;
2833 bfa_status_t status;
2834
2835 if (ioc->stats_busy) {
2836 bfa_trc(ioc, ioc->stats_busy);
2837 return BFA_STATUS_DEVBUSY;
2838 }
2839 ioc->stats_busy = BFA_TRUE;
2840
2841 tlen = sizeof(struct bfa_fw_stats_s);
2842 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2843
2844 ioc->stats_busy = BFA_FALSE;
2845 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002846}
2847
Jing Huang5fbe25c2010-10-18 17:17:23 -07002848/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002849 * Save firmware trace if configured.
2850 */
2851static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002852bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002853{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002854 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002855
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002856 if (ioc->dbg_fwsave_once) {
2857 ioc->dbg_fwsave_once = BFA_FALSE;
2858 if (ioc->dbg_fwsave_len) {
2859 tlen = ioc->dbg_fwsave_len;
2860 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2861 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002862 }
2863}
2864
Jing Huang5fbe25c2010-10-18 17:17:23 -07002865/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002866 * Firmware failure detected. Start recovery actions.
2867 */
2868static void
2869bfa_ioc_recover(struct bfa_ioc_s *ioc)
2870{
Jing Huang7725ccf2009-09-23 17:46:15 -07002871 bfa_ioc_stats(ioc, ioc_hbfails);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002872 ioc->stats.hb_count = ioc->hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07002873 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2874}
2875
Jing Huang7725ccf2009-09-23 17:46:15 -07002876static void
Jing Huang07b28382010-07-08 19:59:24 -07002877bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002878{
Jing Huang07b28382010-07-08 19:59:24 -07002879 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL)
2880 return;
Jing Huang7725ccf2009-09-23 17:46:15 -07002881}
2882
Jing Huang5fbe25c2010-10-18 17:17:23 -07002883/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002884 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002885 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002886static void
2887bfa_iocpf_timeout(void *ioc_arg)
2888{
2889 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2890
2891 bfa_trc(ioc, 0);
2892 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2893}
2894
2895static void
2896bfa_iocpf_sem_timeout(void *ioc_arg)
2897{
2898 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2899
2900 bfa_ioc_hw_sem_get(ioc);
2901}
2902
Krishna Gudipati775c7742011-06-13 15:52:12 -07002903static void
2904bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
2905{
2906 u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate);
2907
2908 bfa_trc(ioc, fwstate);
2909
2910 if (fwstate == BFI_IOC_DISABLED) {
2911 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2912 return;
2913 }
2914
2915 if (ioc->iocpf.poll_time >= BFA_IOC_TOV)
2916 bfa_iocpf_timeout(ioc);
2917 else {
2918 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2919 bfa_iocpf_poll_timer_start(ioc);
2920 }
2921}
2922
2923static void
2924bfa_iocpf_poll_timeout(void *ioc_arg)
2925{
2926 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2927
2928 bfa_ioc_poll_fwinit(ioc);
2929}
2930
Jing Huang5fbe25c2010-10-18 17:17:23 -07002931/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002932 * bfa timer function
2933 */
2934void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002935bfa_timer_beat(struct bfa_timer_mod_s *mod)
2936{
2937 struct list_head *qh = &mod->timer_q;
2938 struct list_head *qe, *qe_next;
2939 struct bfa_timer_s *elem;
2940 struct list_head timedout_q;
2941
2942 INIT_LIST_HEAD(&timedout_q);
2943
2944 qe = bfa_q_next(qh);
2945
2946 while (qe != qh) {
2947 qe_next = bfa_q_next(qe);
2948
2949 elem = (struct bfa_timer_s *) qe;
2950 if (elem->timeout <= BFA_TIMER_FREQ) {
2951 elem->timeout = 0;
2952 list_del(&elem->qe);
2953 list_add_tail(&elem->qe, &timedout_q);
2954 } else {
2955 elem->timeout -= BFA_TIMER_FREQ;
2956 }
2957
2958 qe = qe_next; /* go to next elem */
2959 }
2960
2961 /*
2962 * Pop all the timeout entries
2963 */
2964 while (!list_empty(&timedout_q)) {
2965 bfa_q_deq(&timedout_q, &elem);
2966 elem->timercb(elem->arg);
2967 }
2968}
2969
Jing Huang5fbe25c2010-10-18 17:17:23 -07002970/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002971 * Should be called with lock protection
2972 */
2973void
2974bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2975 void (*timercb) (void *), void *arg, unsigned int timeout)
2976{
2977
Jing Huangd4b671c2010-12-26 21:46:35 -08002978 WARN_ON(timercb == NULL);
2979 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002980
2981 timer->timeout = timeout;
2982 timer->timercb = timercb;
2983 timer->arg = arg;
2984
2985 list_add_tail(&timer->qe, &mod->timer_q);
2986}
2987
Jing Huang5fbe25c2010-10-18 17:17:23 -07002988/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002989 * Should be called with lock protection
2990 */
2991void
2992bfa_timer_stop(struct bfa_timer_s *timer)
2993{
Jing Huangd4b671c2010-12-26 21:46:35 -08002994 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002995
2996 list_del(&timer->qe);
2997}
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002998
2999/*
3000 * ASIC block related
3001 */
3002static void
3003bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
3004{
3005 struct bfa_ablk_cfg_inst_s *cfg_inst;
3006 int i, j;
3007 u16 be16;
3008 u32 be32;
3009
3010 for (i = 0; i < BFA_ABLK_MAX; i++) {
3011 cfg_inst = &cfg->inst[i];
3012 for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
3013 be16 = cfg_inst->pf_cfg[j].pers;
3014 cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
3015 be16 = cfg_inst->pf_cfg[j].num_qpairs;
3016 cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
3017 be16 = cfg_inst->pf_cfg[j].num_vectors;
3018 cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
3019 be32 = cfg_inst->pf_cfg[j].bw;
3020 cfg_inst->pf_cfg[j].bw = be16_to_cpu(be32);
3021 }
3022 }
3023}
3024
3025static void
3026bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
3027{
3028 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3029 struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
3030 bfa_ablk_cbfn_t cbfn;
3031
3032 WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
3033 bfa_trc(ablk->ioc, msg->mh.msg_id);
3034
3035 switch (msg->mh.msg_id) {
3036 case BFI_ABLK_I2H_QUERY:
3037 if (rsp->status == BFA_STATUS_OK) {
3038 memcpy(ablk->cfg, ablk->dma_addr.kva,
3039 sizeof(struct bfa_ablk_cfg_s));
3040 bfa_ablk_config_swap(ablk->cfg);
3041 ablk->cfg = NULL;
3042 }
3043 break;
3044
3045 case BFI_ABLK_I2H_ADPT_CONFIG:
3046 case BFI_ABLK_I2H_PORT_CONFIG:
3047 /* update config port mode */
3048 ablk->ioc->port_mode_cfg = rsp->port_mode;
3049
3050 case BFI_ABLK_I2H_PF_DELETE:
3051 case BFI_ABLK_I2H_PF_UPDATE:
3052 case BFI_ABLK_I2H_OPTROM_ENABLE:
3053 case BFI_ABLK_I2H_OPTROM_DISABLE:
3054 /* No-op */
3055 break;
3056
3057 case BFI_ABLK_I2H_PF_CREATE:
3058 *(ablk->pcifn) = rsp->pcifn;
3059 ablk->pcifn = NULL;
3060 break;
3061
3062 default:
3063 WARN_ON(1);
3064 }
3065
3066 ablk->busy = BFA_FALSE;
3067 if (ablk->cbfn) {
3068 cbfn = ablk->cbfn;
3069 ablk->cbfn = NULL;
3070 cbfn(ablk->cbarg, rsp->status);
3071 }
3072}
3073
3074static void
3075bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
3076{
3077 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3078
3079 bfa_trc(ablk->ioc, event);
3080
3081 switch (event) {
3082 case BFA_IOC_E_ENABLED:
3083 WARN_ON(ablk->busy != BFA_FALSE);
3084 break;
3085
3086 case BFA_IOC_E_DISABLED:
3087 case BFA_IOC_E_FAILED:
3088 /* Fail any pending requests */
3089 ablk->pcifn = NULL;
3090 if (ablk->busy) {
3091 if (ablk->cbfn)
3092 ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
3093 ablk->cbfn = NULL;
3094 ablk->busy = BFA_FALSE;
3095 }
3096 break;
3097
3098 default:
3099 WARN_ON(1);
3100 break;
3101 }
3102}
3103
3104u32
3105bfa_ablk_meminfo(void)
3106{
3107 return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
3108}
3109
3110void
3111bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
3112{
3113 ablk->dma_addr.kva = dma_kva;
3114 ablk->dma_addr.pa = dma_pa;
3115}
3116
3117void
3118bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
3119{
3120 ablk->ioc = ioc;
3121
3122 bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
3123 bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
3124 list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
3125}
3126
3127bfa_status_t
3128bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
3129 bfa_ablk_cbfn_t cbfn, void *cbarg)
3130{
3131 struct bfi_ablk_h2i_query_s *m;
3132
3133 WARN_ON(!ablk_cfg);
3134
3135 if (!bfa_ioc_is_operational(ablk->ioc)) {
3136 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3137 return BFA_STATUS_IOC_FAILURE;
3138 }
3139
3140 if (ablk->busy) {
3141 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3142 return BFA_STATUS_DEVBUSY;
3143 }
3144
3145 ablk->cfg = ablk_cfg;
3146 ablk->cbfn = cbfn;
3147 ablk->cbarg = cbarg;
3148 ablk->busy = BFA_TRUE;
3149
3150 m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
3151 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
3152 bfa_ioc_portid(ablk->ioc));
3153 bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
3154 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3155
3156 return BFA_STATUS_OK;
3157}
3158
3159bfa_status_t
3160bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
3161 u8 port, enum bfi_pcifn_class personality, int bw,
3162 bfa_ablk_cbfn_t cbfn, void *cbarg)
3163{
3164 struct bfi_ablk_h2i_pf_req_s *m;
3165
3166 if (!bfa_ioc_is_operational(ablk->ioc)) {
3167 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3168 return BFA_STATUS_IOC_FAILURE;
3169 }
3170
3171 if (ablk->busy) {
3172 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3173 return BFA_STATUS_DEVBUSY;
3174 }
3175
3176 ablk->pcifn = pcifn;
3177 ablk->cbfn = cbfn;
3178 ablk->cbarg = cbarg;
3179 ablk->busy = BFA_TRUE;
3180
3181 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3182 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
3183 bfa_ioc_portid(ablk->ioc));
3184 m->pers = cpu_to_be16((u16)personality);
3185 m->bw = cpu_to_be32(bw);
3186 m->port = port;
3187 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3188
3189 return BFA_STATUS_OK;
3190}
3191
3192bfa_status_t
3193bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
3194 bfa_ablk_cbfn_t cbfn, void *cbarg)
3195{
3196 struct bfi_ablk_h2i_pf_req_s *m;
3197
3198 if (!bfa_ioc_is_operational(ablk->ioc)) {
3199 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3200 return BFA_STATUS_IOC_FAILURE;
3201 }
3202
3203 if (ablk->busy) {
3204 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3205 return BFA_STATUS_DEVBUSY;
3206 }
3207
3208 ablk->cbfn = cbfn;
3209 ablk->cbarg = cbarg;
3210 ablk->busy = BFA_TRUE;
3211
3212 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3213 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
3214 bfa_ioc_portid(ablk->ioc));
3215 m->pcifn = (u8)pcifn;
3216 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3217
3218 return BFA_STATUS_OK;
3219}
3220
3221bfa_status_t
3222bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
3223 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3224{
3225 struct bfi_ablk_h2i_cfg_req_s *m;
3226
3227 if (!bfa_ioc_is_operational(ablk->ioc)) {
3228 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3229 return BFA_STATUS_IOC_FAILURE;
3230 }
3231
3232 if (ablk->busy) {
3233 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3234 return BFA_STATUS_DEVBUSY;
3235 }
3236
3237 ablk->cbfn = cbfn;
3238 ablk->cbarg = cbarg;
3239 ablk->busy = BFA_TRUE;
3240
3241 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3242 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
3243 bfa_ioc_portid(ablk->ioc));
3244 m->mode = (u8)mode;
3245 m->max_pf = (u8)max_pf;
3246 m->max_vf = (u8)max_vf;
3247 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3248
3249 return BFA_STATUS_OK;
3250}
3251
3252bfa_status_t
3253bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
3254 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3255{
3256 struct bfi_ablk_h2i_cfg_req_s *m;
3257
3258 if (!bfa_ioc_is_operational(ablk->ioc)) {
3259 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3260 return BFA_STATUS_IOC_FAILURE;
3261 }
3262
3263 if (ablk->busy) {
3264 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3265 return BFA_STATUS_DEVBUSY;
3266 }
3267
3268 ablk->cbfn = cbfn;
3269 ablk->cbarg = cbarg;
3270 ablk->busy = BFA_TRUE;
3271
3272 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3273 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
3274 bfa_ioc_portid(ablk->ioc));
3275 m->port = (u8)port;
3276 m->mode = (u8)mode;
3277 m->max_pf = (u8)max_pf;
3278 m->max_vf = (u8)max_vf;
3279 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3280
3281 return BFA_STATUS_OK;
3282}
3283
3284bfa_status_t
3285bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw,
3286 bfa_ablk_cbfn_t cbfn, void *cbarg)
3287{
3288 struct bfi_ablk_h2i_pf_req_s *m;
3289
3290 if (!bfa_ioc_is_operational(ablk->ioc)) {
3291 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3292 return BFA_STATUS_IOC_FAILURE;
3293 }
3294
3295 if (ablk->busy) {
3296 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3297 return BFA_STATUS_DEVBUSY;
3298 }
3299
3300 ablk->cbfn = cbfn;
3301 ablk->cbarg = cbarg;
3302 ablk->busy = BFA_TRUE;
3303
3304 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3305 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
3306 bfa_ioc_portid(ablk->ioc));
3307 m->pcifn = (u8)pcifn;
3308 m->bw = cpu_to_be32(bw);
3309 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3310
3311 return BFA_STATUS_OK;
3312}
3313
3314bfa_status_t
3315bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3316{
3317 struct bfi_ablk_h2i_optrom_s *m;
3318
3319 if (!bfa_ioc_is_operational(ablk->ioc)) {
3320 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3321 return BFA_STATUS_IOC_FAILURE;
3322 }
3323
3324 if (ablk->busy) {
3325 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3326 return BFA_STATUS_DEVBUSY;
3327 }
3328
3329 ablk->cbfn = cbfn;
3330 ablk->cbarg = cbarg;
3331 ablk->busy = BFA_TRUE;
3332
3333 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3334 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE,
3335 bfa_ioc_portid(ablk->ioc));
3336 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3337
3338 return BFA_STATUS_OK;
3339}
3340
3341bfa_status_t
3342bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3343{
3344 struct bfi_ablk_h2i_optrom_s *m;
3345
3346 if (!bfa_ioc_is_operational(ablk->ioc)) {
3347 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3348 return BFA_STATUS_IOC_FAILURE;
3349 }
3350
3351 if (ablk->busy) {
3352 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3353 return BFA_STATUS_DEVBUSY;
3354 }
3355
3356 ablk->cbfn = cbfn;
3357 ablk->cbarg = cbarg;
3358 ablk->busy = BFA_TRUE;
3359
3360 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3361 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
3362 bfa_ioc_portid(ablk->ioc));
3363 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3364
3365 return BFA_STATUS_OK;
3366}
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003367
3368/*
3369 * SFP module specific
3370 */
3371
3372/* forward declarations */
3373static void bfa_sfp_getdata_send(struct bfa_sfp_s *sfp);
3374static void bfa_sfp_media_get(struct bfa_sfp_s *sfp);
3375static bfa_status_t bfa_sfp_speed_valid(struct bfa_sfp_s *sfp,
3376 enum bfa_port_speed portspeed);
3377
3378static void
3379bfa_cb_sfp_show(struct bfa_sfp_s *sfp)
3380{
3381 bfa_trc(sfp, sfp->lock);
3382 if (sfp->cbfn)
3383 sfp->cbfn(sfp->cbarg, sfp->status);
3384 sfp->lock = 0;
3385 sfp->cbfn = NULL;
3386}
3387
3388static void
3389bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp)
3390{
3391 bfa_trc(sfp, sfp->portspeed);
3392 if (sfp->media) {
3393 bfa_sfp_media_get(sfp);
3394 if (sfp->state_query_cbfn)
3395 sfp->state_query_cbfn(sfp->state_query_cbarg,
3396 sfp->status);
3397 sfp->media = NULL;
3398 }
3399
3400 if (sfp->portspeed) {
3401 sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed);
3402 if (sfp->state_query_cbfn)
3403 sfp->state_query_cbfn(sfp->state_query_cbarg,
3404 sfp->status);
3405 sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
3406 }
3407
3408 sfp->state_query_lock = 0;
3409 sfp->state_query_cbfn = NULL;
3410}
3411
3412/*
3413 * IOC event handler.
3414 */
3415static void
3416bfa_sfp_notify(void *sfp_arg, enum bfa_ioc_event_e event)
3417{
3418 struct bfa_sfp_s *sfp = sfp_arg;
3419
3420 bfa_trc(sfp, event);
3421 bfa_trc(sfp, sfp->lock);
3422 bfa_trc(sfp, sfp->state_query_lock);
3423
3424 switch (event) {
3425 case BFA_IOC_E_DISABLED:
3426 case BFA_IOC_E_FAILED:
3427 if (sfp->lock) {
3428 sfp->status = BFA_STATUS_IOC_FAILURE;
3429 bfa_cb_sfp_show(sfp);
3430 }
3431
3432 if (sfp->state_query_lock) {
3433 sfp->status = BFA_STATUS_IOC_FAILURE;
3434 bfa_cb_sfp_state_query(sfp);
3435 }
3436 break;
3437
3438 default:
3439 break;
3440 }
3441}
3442
3443/*
3444 * SFP get data send
3445 */
3446static void
3447bfa_sfp_getdata_send(struct bfa_sfp_s *sfp)
3448{
3449 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3450
3451 bfa_trc(sfp, req->memtype);
3452
3453 /* build host command */
3454 bfi_h2i_set(req->mh, BFI_MC_SFP, BFI_SFP_H2I_SHOW,
3455 bfa_ioc_portid(sfp->ioc));
3456
3457 /* send mbox cmd */
3458 bfa_ioc_mbox_queue(sfp->ioc, &sfp->mbcmd);
3459}
3460
3461/*
3462 * SFP is valid, read sfp data
3463 */
3464static void
3465bfa_sfp_getdata(struct bfa_sfp_s *sfp, enum bfi_sfp_mem_e memtype)
3466{
3467 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3468
3469 WARN_ON(sfp->lock != 0);
3470 bfa_trc(sfp, sfp->state);
3471
3472 sfp->lock = 1;
3473 sfp->memtype = memtype;
3474 req->memtype = memtype;
3475
3476 /* Setup SG list */
3477 bfa_alen_set(&req->alen, sizeof(struct sfp_mem_s), sfp->dbuf_pa);
3478
3479 bfa_sfp_getdata_send(sfp);
3480}
3481
3482/*
3483 * SFP show complete
3484 */
3485static void
3486bfa_sfp_show_comp(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
3487{
3488 struct bfi_sfp_rsp_s *rsp = (struct bfi_sfp_rsp_s *) msg;
3489
3490 if (!sfp->lock) {
3491 /*
3492 * receiving response after ioc failure
3493 */
3494 bfa_trc(sfp, sfp->lock);
3495 return;
3496 }
3497
3498 bfa_trc(sfp, rsp->status);
3499 if (rsp->status == BFA_STATUS_OK) {
3500 sfp->data_valid = 1;
3501 if (sfp->state == BFA_SFP_STATE_VALID)
3502 sfp->status = BFA_STATUS_OK;
3503 else if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
3504 sfp->status = BFA_STATUS_SFP_UNSUPP;
3505 else
3506 bfa_trc(sfp, sfp->state);
3507 } else {
3508 sfp->data_valid = 0;
3509 sfp->status = rsp->status;
3510 /* sfpshow shouldn't change sfp state */
3511 }
3512
3513 bfa_trc(sfp, sfp->memtype);
3514 if (sfp->memtype == BFI_SFP_MEM_DIAGEXT) {
3515 bfa_trc(sfp, sfp->data_valid);
3516 if (sfp->data_valid) {
3517 u32 size = sizeof(struct sfp_mem_s);
3518 u8 *des = (u8 *) &(sfp->sfpmem->srlid_base);
3519 memcpy(des, sfp->dbuf_kva, size);
3520 }
3521 /*
3522 * Queue completion callback.
3523 */
3524 bfa_cb_sfp_show(sfp);
3525 } else
3526 sfp->lock = 0;
3527
3528 bfa_trc(sfp, sfp->state_query_lock);
3529 if (sfp->state_query_lock) {
3530 sfp->state = rsp->state;
3531 /* Complete callback */
3532 bfa_cb_sfp_state_query(sfp);
3533 }
3534}
3535
3536/*
3537 * SFP query fw sfp state
3538 */
3539static void
3540bfa_sfp_state_query(struct bfa_sfp_s *sfp)
3541{
3542 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3543
3544 /* Should not be doing query if not in _INIT state */
3545 WARN_ON(sfp->state != BFA_SFP_STATE_INIT);
3546 WARN_ON(sfp->state_query_lock != 0);
3547 bfa_trc(sfp, sfp->state);
3548
3549 sfp->state_query_lock = 1;
3550 req->memtype = 0;
3551
3552 if (!sfp->lock)
3553 bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
3554}
3555
3556static void
3557bfa_sfp_media_get(struct bfa_sfp_s *sfp)
3558{
3559 enum bfa_defs_sfp_media_e *media = sfp->media;
3560
3561 *media = BFA_SFP_MEDIA_UNKNOWN;
3562
3563 if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
3564 *media = BFA_SFP_MEDIA_UNSUPPORT;
3565 else if (sfp->state == BFA_SFP_STATE_VALID) {
3566 union sfp_xcvr_e10g_code_u e10g;
3567 struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
3568 u16 xmtr_tech = (sfpmem->srlid_base.xcvr[4] & 0x3) << 7 |
3569 (sfpmem->srlid_base.xcvr[5] >> 1);
3570
3571 e10g.b = sfpmem->srlid_base.xcvr[0];
3572 bfa_trc(sfp, e10g.b);
3573 bfa_trc(sfp, xmtr_tech);
3574 /* check fc transmitter tech */
3575 if ((xmtr_tech & SFP_XMTR_TECH_CU) ||
3576 (xmtr_tech & SFP_XMTR_TECH_CP) ||
3577 (xmtr_tech & SFP_XMTR_TECH_CA))
3578 *media = BFA_SFP_MEDIA_CU;
3579 else if ((xmtr_tech & SFP_XMTR_TECH_EL_INTRA) ||
3580 (xmtr_tech & SFP_XMTR_TECH_EL_INTER))
3581 *media = BFA_SFP_MEDIA_EL;
3582 else if ((xmtr_tech & SFP_XMTR_TECH_LL) ||
3583 (xmtr_tech & SFP_XMTR_TECH_LC))
3584 *media = BFA_SFP_MEDIA_LW;
3585 else if ((xmtr_tech & SFP_XMTR_TECH_SL) ||
3586 (xmtr_tech & SFP_XMTR_TECH_SN) ||
3587 (xmtr_tech & SFP_XMTR_TECH_SA))
3588 *media = BFA_SFP_MEDIA_SW;
3589 /* Check 10G Ethernet Compilance code */
3590 else if (e10g.b & 0x10)
3591 *media = BFA_SFP_MEDIA_SW;
3592 else if (e10g.b & 0x60)
3593 *media = BFA_SFP_MEDIA_LW;
3594 else if (e10g.r.e10g_unall & 0x80)
3595 *media = BFA_SFP_MEDIA_UNKNOWN;
3596 else
3597 bfa_trc(sfp, 0);
3598 } else
3599 bfa_trc(sfp, sfp->state);
3600}
3601
3602static bfa_status_t
3603bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed)
3604{
3605 struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
3606 struct sfp_xcvr_s *xcvr = (struct sfp_xcvr_s *) sfpmem->srlid_base.xcvr;
3607 union sfp_xcvr_fc3_code_u fc3 = xcvr->fc3;
3608 union sfp_xcvr_e10g_code_u e10g = xcvr->e10g;
3609
3610 if (portspeed == BFA_PORT_SPEED_10GBPS) {
3611 if (e10g.r.e10g_sr || e10g.r.e10g_lr)
3612 return BFA_STATUS_OK;
3613 else {
3614 bfa_trc(sfp, e10g.b);
3615 return BFA_STATUS_UNSUPP_SPEED;
3616 }
3617 }
3618 if (((portspeed & BFA_PORT_SPEED_16GBPS) && fc3.r.mb1600) ||
3619 ((portspeed & BFA_PORT_SPEED_8GBPS) && fc3.r.mb800) ||
3620 ((portspeed & BFA_PORT_SPEED_4GBPS) && fc3.r.mb400) ||
3621 ((portspeed & BFA_PORT_SPEED_2GBPS) && fc3.r.mb200) ||
3622 ((portspeed & BFA_PORT_SPEED_1GBPS) && fc3.r.mb100))
3623 return BFA_STATUS_OK;
3624 else {
3625 bfa_trc(sfp, portspeed);
3626 bfa_trc(sfp, fc3.b);
3627 bfa_trc(sfp, e10g.b);
3628 return BFA_STATUS_UNSUPP_SPEED;
3629 }
3630}
3631
3632/*
3633 * SFP hmbox handler
3634 */
3635void
3636bfa_sfp_intr(void *sfparg, struct bfi_mbmsg_s *msg)
3637{
3638 struct bfa_sfp_s *sfp = sfparg;
3639
3640 switch (msg->mh.msg_id) {
3641 case BFI_SFP_I2H_SHOW:
3642 bfa_sfp_show_comp(sfp, msg);
3643 break;
3644
3645 case BFI_SFP_I2H_SCN:
3646 bfa_trc(sfp, msg->mh.msg_id);
3647 break;
3648
3649 default:
3650 bfa_trc(sfp, msg->mh.msg_id);
3651 WARN_ON(1);
3652 }
3653}
3654
3655/*
3656 * Return DMA memory needed by sfp module.
3657 */
3658u32
3659bfa_sfp_meminfo(void)
3660{
3661 return BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3662}
3663
3664/*
3665 * Attach virtual and physical memory for SFP.
3666 */
3667void
3668bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc, void *dev,
3669 struct bfa_trc_mod_s *trcmod)
3670{
3671 sfp->dev = dev;
3672 sfp->ioc = ioc;
3673 sfp->trcmod = trcmod;
3674
3675 sfp->cbfn = NULL;
3676 sfp->cbarg = NULL;
3677 sfp->sfpmem = NULL;
3678 sfp->lock = 0;
3679 sfp->data_valid = 0;
3680 sfp->state = BFA_SFP_STATE_INIT;
3681 sfp->state_query_lock = 0;
3682 sfp->state_query_cbfn = NULL;
3683 sfp->state_query_cbarg = NULL;
3684 sfp->media = NULL;
3685 sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
3686 sfp->is_elb = BFA_FALSE;
3687
3688 bfa_ioc_mbox_regisr(sfp->ioc, BFI_MC_SFP, bfa_sfp_intr, sfp);
3689 bfa_q_qe_init(&sfp->ioc_notify);
3690 bfa_ioc_notify_init(&sfp->ioc_notify, bfa_sfp_notify, sfp);
3691 list_add_tail(&sfp->ioc_notify.qe, &sfp->ioc->notify_q);
3692}
3693
3694/*
3695 * Claim Memory for SFP
3696 */
3697void
3698bfa_sfp_memclaim(struct bfa_sfp_s *sfp, u8 *dm_kva, u64 dm_pa)
3699{
3700 sfp->dbuf_kva = dm_kva;
3701 sfp->dbuf_pa = dm_pa;
3702 memset(sfp->dbuf_kva, 0, sizeof(struct sfp_mem_s));
3703
3704 dm_kva += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3705 dm_pa += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3706}
3707
3708/*
3709 * Show SFP eeprom content
3710 *
3711 * @param[in] sfp - bfa sfp module
3712 *
3713 * @param[out] sfpmem - sfp eeprom data
3714 *
3715 */
3716bfa_status_t
3717bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem,
3718 bfa_cb_sfp_t cbfn, void *cbarg)
3719{
3720
3721 if (!bfa_ioc_is_operational(sfp->ioc)) {
3722 bfa_trc(sfp, 0);
3723 return BFA_STATUS_IOC_NON_OP;
3724 }
3725
3726 if (sfp->lock) {
3727 bfa_trc(sfp, 0);
3728 return BFA_STATUS_DEVBUSY;
3729 }
3730
3731 sfp->cbfn = cbfn;
3732 sfp->cbarg = cbarg;
3733 sfp->sfpmem = sfpmem;
3734
3735 bfa_sfp_getdata(sfp, BFI_SFP_MEM_DIAGEXT);
3736 return BFA_STATUS_OK;
3737}
3738
3739/*
3740 * Return SFP Media type
3741 *
3742 * @param[in] sfp - bfa sfp module
3743 *
3744 * @param[out] media - port speed from user
3745 *
3746 */
3747bfa_status_t
3748bfa_sfp_media(struct bfa_sfp_s *sfp, enum bfa_defs_sfp_media_e *media,
3749 bfa_cb_sfp_t cbfn, void *cbarg)
3750{
3751 if (!bfa_ioc_is_operational(sfp->ioc)) {
3752 bfa_trc(sfp, 0);
3753 return BFA_STATUS_IOC_NON_OP;
3754 }
3755
3756 sfp->media = media;
3757 if (sfp->state == BFA_SFP_STATE_INIT) {
3758 if (sfp->state_query_lock) {
3759 bfa_trc(sfp, 0);
3760 return BFA_STATUS_DEVBUSY;
3761 } else {
3762 sfp->state_query_cbfn = cbfn;
3763 sfp->state_query_cbarg = cbarg;
3764 bfa_sfp_state_query(sfp);
3765 return BFA_STATUS_SFP_NOT_READY;
3766 }
3767 }
3768
3769 bfa_sfp_media_get(sfp);
3770 return BFA_STATUS_OK;
3771}
3772
3773/*
3774 * Check if user set port speed is allowed by the SFP
3775 *
3776 * @param[in] sfp - bfa sfp module
3777 * @param[in] portspeed - port speed from user
3778 *
3779 */
3780bfa_status_t
3781bfa_sfp_speed(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed,
3782 bfa_cb_sfp_t cbfn, void *cbarg)
3783{
3784 WARN_ON(portspeed == BFA_PORT_SPEED_UNKNOWN);
3785
3786 if (!bfa_ioc_is_operational(sfp->ioc))
3787 return BFA_STATUS_IOC_NON_OP;
3788
3789 /* For Mezz card, all speed is allowed */
3790 if (bfa_mfg_is_mezz(sfp->ioc->attr->card_type))
3791 return BFA_STATUS_OK;
3792
3793 /* Check SFP state */
3794 sfp->portspeed = portspeed;
3795 if (sfp->state == BFA_SFP_STATE_INIT) {
3796 if (sfp->state_query_lock) {
3797 bfa_trc(sfp, 0);
3798 return BFA_STATUS_DEVBUSY;
3799 } else {
3800 sfp->state_query_cbfn = cbfn;
3801 sfp->state_query_cbarg = cbarg;
3802 bfa_sfp_state_query(sfp);
3803 return BFA_STATUS_SFP_NOT_READY;
3804 }
3805 }
3806
3807 if (sfp->state == BFA_SFP_STATE_REMOVED ||
3808 sfp->state == BFA_SFP_STATE_FAILED) {
3809 bfa_trc(sfp, sfp->state);
3810 return BFA_STATUS_NO_SFP_DEV;
3811 }
3812
3813 if (sfp->state == BFA_SFP_STATE_INSERTED) {
3814 bfa_trc(sfp, sfp->state);
3815 return BFA_STATUS_DEVBUSY; /* sfp is reading data */
3816 }
3817
3818 /* For eloopback, all speed is allowed */
3819 if (sfp->is_elb)
3820 return BFA_STATUS_OK;
3821
3822 return bfa_sfp_speed_valid(sfp, portspeed);
3823}