blob: 8928b68551c373a9efdfd2f3c46286a75a2d0c45 [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 Gudipati7826f302011-07-20 16:59:13 -070019#include "bfad_im.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070020#include "bfa_ioc.h"
Krishna Gudipati11189202011-06-13 15:50:35 -070021#include "bfi_reg.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070022#include "bfa_defs.h"
23#include "bfa_defs_svc.h"
Jing Huang7725ccf2009-09-23 17:46:15 -070024
Krishna Gudipati7af074d2010-03-05 19:35:45 -080025BFA_TRC_FILE(CNA, IOC);
Jing Huang7725ccf2009-09-23 17:46:15 -070026
Jing Huang5fbe25c2010-10-18 17:17:23 -070027/*
Jing Huang7725ccf2009-09-23 17:46:15 -070028 * IOC local definitions
29 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070030#define BFA_IOC_TOV 3000 /* msecs */
31#define BFA_IOC_HWSEM_TOV 500 /* msecs */
32#define BFA_IOC_HB_TOV 500 /* msecs */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070033#define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
Krishna Gudipati775c7742011-06-13 15:52:12 -070034#define BFA_IOC_POLL_TOV BFA_TIMER_FREQ
Jing Huang7725ccf2009-09-23 17:46:15 -070035
36#define bfa_ioc_timer_start(__ioc) \
37 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
38 bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
39#define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
40
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070041#define bfa_hb_timer_start(__ioc) \
42 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
43 bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
44#define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
45
Jing Huang7725ccf2009-09-23 17:46:15 -070046#define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
Jing Huang7725ccf2009-09-23 17:46:15 -070047
Jing Huang5fbe25c2010-10-18 17:17:23 -070048/*
Krishna Gudipati0a20de42010-03-05 19:34:20 -080049 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
50 */
51
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070052#define bfa_ioc_firmware_lock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080053 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070054#define bfa_ioc_firmware_unlock(__ioc) \
Krishna Gudipati0a20de42010-03-05 19:34:20 -080055 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
Krishna Gudipati0a20de42010-03-05 19:34:20 -080056#define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
57#define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080058#define bfa_ioc_notify_fail(__ioc) \
59 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
Jing Huang45d7f0c2011-04-13 11:45:53 -070060#define bfa_ioc_sync_start(__ioc) \
61 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
Krishna Gudipatif1d584d2010-12-13 16:17:11 -080062#define bfa_ioc_sync_join(__ioc) \
63 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
64#define bfa_ioc_sync_leave(__ioc) \
65 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
66#define bfa_ioc_sync_ack(__ioc) \
67 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
68#define bfa_ioc_sync_complete(__ioc) \
69 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -070070#define bfa_ioc_set_cur_ioc_fwstate(__ioc, __fwstate) \
71 ((__ioc)->ioc_hwif->ioc_set_fwstate(__ioc, __fwstate))
72#define bfa_ioc_get_cur_ioc_fwstate(__ioc) \
73 ((__ioc)->ioc_hwif->ioc_get_fwstate(__ioc))
74#define bfa_ioc_set_alt_ioc_fwstate(__ioc, __fwstate) \
75 ((__ioc)->ioc_hwif->ioc_set_alt_fwstate(__ioc, __fwstate))
76#define bfa_ioc_get_alt_ioc_fwstate(__ioc) \
77 ((__ioc)->ioc_hwif->ioc_get_alt_fwstate(__ioc))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070078
79#define bfa_ioc_mbox_cmd_pending(__ioc) \
80 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
Jing Huang53440262010-10-18 17:12:29 -070081 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070082
83bfa_boolean_t bfa_auto_recover = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -070084
85/*
86 * forward declarations
87 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070088static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070089static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force);
90static void bfa_ioc_timeout(void *ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -070091static void bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070092static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc);
93static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc);
94static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc);
95static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070096static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc);
Krishna Gudipati8b070b42011-06-13 15:52:40 -070097static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070098static void bfa_ioc_recover(struct bfa_ioc_s *ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -070099static void bfa_ioc_event_notify(struct bfa_ioc_s *ioc ,
100 enum bfa_ioc_event_e event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc);
102static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800103static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700104static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700105
Jing Huang5fbe25c2010-10-18 17:17:23 -0700106/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700107 * IOC state machine definitions/declarations
Jing Huang7725ccf2009-09-23 17:46:15 -0700108 */
109enum ioc_event {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700110 IOC_E_RESET = 1, /* IOC reset request */
111 IOC_E_ENABLE = 2, /* IOC enable request */
112 IOC_E_DISABLE = 3, /* IOC disable request */
113 IOC_E_DETACH = 4, /* driver detach cleanup */
114 IOC_E_ENABLED = 5, /* f/w enabled */
115 IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */
116 IOC_E_DISABLED = 7, /* f/w disabled */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700117 IOC_E_PFFAILED = 8, /* failure notice by iocpf sm */
118 IOC_E_HBFAIL = 9, /* heartbeat failure */
119 IOC_E_HWERROR = 10, /* hardware error interrupt */
120 IOC_E_TIMEOUT = 11, /* timeout */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700121 IOC_E_HWFAILED = 12, /* PCI mapping failure notice */
Jing Huang7725ccf2009-09-23 17:46:15 -0700122};
123
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700124bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700125bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700126bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event);
127bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event);
128bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800129bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700131bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event);
132bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700133bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event);
Jing Huang7725ccf2009-09-23 17:46:15 -0700134
135static struct bfa_sm_table_s ioc_sm_table[] = {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700136 {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT},
Jing Huang7725ccf2009-09-23 17:46:15 -0700137 {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700138 {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING},
Jing Huang7725ccf2009-09-23 17:46:15 -0700139 {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR},
140 {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL},
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800141 {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700142 {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700143 {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING},
144 {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED},
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700145 {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL},
Jing Huang7725ccf2009-09-23 17:46:15 -0700146};
147
Jing Huang5fbe25c2010-10-18 17:17:23 -0700148/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700149 * IOCPF state machine definitions/declarations
150 */
151
152#define bfa_iocpf_timer_start(__ioc) \
153 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
154 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
155#define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
156
Krishna Gudipati775c7742011-06-13 15:52:12 -0700157#define bfa_iocpf_poll_timer_start(__ioc) \
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700158 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
Krishna Gudipati775c7742011-06-13 15:52:12 -0700159 bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700160
161#define bfa_sem_timer_start(__ioc) \
162 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
163 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
164#define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
165
166/*
167 * Forward declareations for iocpf state machine
168 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700169static void bfa_iocpf_timeout(void *ioc_arg);
170static void bfa_iocpf_sem_timeout(void *ioc_arg);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700171static void bfa_iocpf_poll_timeout(void *ioc_arg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700172
Jing Huang5fbe25c2010-10-18 17:17:23 -0700173/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700174 * IOCPF state machine events
175 */
176enum iocpf_event {
177 IOCPF_E_ENABLE = 1, /* IOCPF enable request */
178 IOCPF_E_DISABLE = 2, /* IOCPF disable request */
179 IOCPF_E_STOP = 3, /* stop on driver detach */
180 IOCPF_E_FWREADY = 4, /* f/w initialization done */
181 IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */
182 IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */
183 IOCPF_E_FAIL = 7, /* failure notice by ioc sm */
184 IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */
185 IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */
186 IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */
187 IOCPF_E_TIMEOUT = 11, /* f/w response timeout */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700188 IOCPF_E_SEM_ERROR = 12, /* h/w sem mapping error */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700189};
190
Jing Huang5fbe25c2010-10-18 17:17:23 -0700191/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700192 * IOCPF states
193 */
194enum bfa_iocpf_state {
195 BFA_IOCPF_RESET = 1, /* IOC is in reset state */
196 BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */
197 BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */
198 BFA_IOCPF_READY = 4, /* IOCPF is initialized */
199 BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */
200 BFA_IOCPF_FAIL = 6, /* IOCPF failed */
201 BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */
202 BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */
203 BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */
204};
205
206bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event);
207bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event);
208bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event);
209bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event);
210bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event);
211bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event);
212bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800213bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s,
214 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700215bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800216bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700217bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event);
218bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800219bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s,
220 enum iocpf_event);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700221bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event);
222
223static struct bfa_sm_table_s iocpf_sm_table[] = {
224 {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET},
225 {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH},
226 {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH},
227 {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT},
228 {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT},
229 {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT},
230 {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800231 {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700232 {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800233 {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700234 {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL},
235 {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING},
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800236 {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING},
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700237 {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED},
238};
239
Jing Huang5fbe25c2010-10-18 17:17:23 -0700240/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700241 * IOC State Machine
242 */
243
Jing Huang5fbe25c2010-10-18 17:17:23 -0700244/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700245 * Beginning state. IOC uninit state.
246 */
247
248static void
249bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc)
250{
251}
252
Jing Huang5fbe25c2010-10-18 17:17:23 -0700253/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700254 * IOC is in uninit state.
255 */
256static void
257bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event)
258{
259 bfa_trc(ioc, event);
260
261 switch (event) {
262 case IOC_E_RESET:
263 bfa_fsm_set_state(ioc, bfa_ioc_sm_reset);
264 break;
265
266 default:
267 bfa_sm_fault(ioc, event);
268 }
269}
Jing Huang5fbe25c2010-10-18 17:17:23 -0700270/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700271 * Reset entry actions -- initialize state machine
272 */
273static void
274bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc)
275{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700276 bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset);
Jing Huang7725ccf2009-09-23 17:46:15 -0700277}
278
Jing Huang5fbe25c2010-10-18 17:17:23 -0700279/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700280 * IOC is in reset state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700281 */
282static void
283bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event)
284{
285 bfa_trc(ioc, event);
286
287 switch (event) {
288 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700289 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
290 break;
291
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700292 case IOC_E_DISABLE:
293 bfa_ioc_disable_comp(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700294 break;
295
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700296 case IOC_E_DETACH:
297 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Jing Huang7725ccf2009-09-23 17:46:15 -0700298 break;
299
300 default:
301 bfa_sm_fault(ioc, event);
302 }
303}
304
305
306static void
307bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc)
308{
Maggie Zhangf7f738122010-12-09 19:08:43 -0800309 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700310}
311
Jing Huang5fbe25c2010-10-18 17:17:23 -0700312/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700313 * Host IOC function is being enabled, awaiting response from firmware.
314 * Semaphore is acquired.
315 */
316static void
317bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event)
318{
319 bfa_trc(ioc, event);
320
321 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700322 case IOC_E_ENABLED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700323 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
324 break;
325
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800326 case IOC_E_PFFAILED:
327 /* !!! fall through !!! */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700328 case IOC_E_HWERROR:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800329 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700330 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800331 if (event != IOC_E_PFFAILED)
332 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700333 break;
334
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700335 case IOC_E_HWFAILED:
336 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
337 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
338 break;
339
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700340 case IOC_E_DISABLE:
341 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
342 break;
343
344 case IOC_E_DETACH:
345 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800346 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700347 break;
348
349 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700350 break;
351
352 default:
353 bfa_sm_fault(ioc, event);
354 }
355}
356
357
358static void
359bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc)
360{
361 bfa_ioc_timer_start(ioc);
362 bfa_ioc_send_getattr(ioc);
363}
364
Jing Huang5fbe25c2010-10-18 17:17:23 -0700365/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700366 * IOC configuration in progress. Timer is active.
367 */
368static void
369bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event)
370{
371 bfa_trc(ioc, event);
372
373 switch (event) {
374 case IOC_E_FWRSP_GETATTR:
375 bfa_ioc_timer_stop(ioc);
376 bfa_fsm_set_state(ioc, bfa_ioc_sm_op);
377 break;
378
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800379 case IOC_E_PFFAILED:
Jing Huang7725ccf2009-09-23 17:46:15 -0700380 case IOC_E_HWERROR:
381 bfa_ioc_timer_stop(ioc);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800382 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700383 case IOC_E_TIMEOUT:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800384 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700385 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800386 if (event != IOC_E_PFFAILED)
387 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700388 break;
389
390 case IOC_E_DISABLE:
391 bfa_ioc_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700392 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
393 break;
394
395 case IOC_E_ENABLE:
Jing Huang7725ccf2009-09-23 17:46:15 -0700396 break;
397
398 default:
399 bfa_sm_fault(ioc, event);
400 }
401}
402
Jing Huang7725ccf2009-09-23 17:46:15 -0700403static void
404bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc)
405{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700406 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
407
Jing Huang7725ccf2009-09-23 17:46:15 -0700408 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK);
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700409 bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -0700410 bfa_ioc_hb_monitor(ioc);
Jing Huang88166242010-12-09 17:11:53 -0800411 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700412 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700413}
414
415static void
416bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event)
417{
418 bfa_trc(ioc, event);
419
420 switch (event) {
421 case IOC_E_ENABLE:
422 break;
423
424 case IOC_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800425 bfa_hb_timer_stop(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700426 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
427 break;
428
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800429 case IOC_E_PFFAILED:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700430 case IOC_E_HWERROR:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800431 bfa_hb_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700432 /* !!! fall through !!! */
Jing Huang7725ccf2009-09-23 17:46:15 -0700433 case IOC_E_HBFAIL:
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800434 if (ioc->iocpf.auto_recover)
435 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry);
436 else
437 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
438
Krishna Gudipati775c7742011-06-13 15:52:12 -0700439 bfa_ioc_fail_notify(ioc);
440
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800441 if (event != IOC_E_PFFAILED)
442 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700443 break;
444
445 default:
446 bfa_sm_fault(ioc, event);
447 }
448}
449
450
451static void
452bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc)
453{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700454 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800455 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE);
Jing Huang88166242010-12-09 17:11:53 -0800456 BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n");
Krishna Gudipati7826f302011-07-20 16:59:13 -0700457 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -0700458}
459
Jing Huang5fbe25c2010-10-18 17:17:23 -0700460/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700461 * IOC is being disabled
462 */
463static void
464bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event)
465{
466 bfa_trc(ioc, event);
467
468 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700469 case IOC_E_DISABLED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800470 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled);
471 break;
472
473 case IOC_E_HWERROR:
Jing Huang7725ccf2009-09-23 17:46:15 -0700474 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700475 * No state change. Will move to disabled state
476 * after iocpf sm completes failure processing and
477 * moves to disabled state.
Jing Huang7725ccf2009-09-23 17:46:15 -0700478 */
Maggie Zhangf7f738122010-12-09 19:08:43 -0800479 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL);
Jing Huang7725ccf2009-09-23 17:46:15 -0700480 break;
481
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700482 case IOC_E_HWFAILED:
483 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
484 bfa_ioc_disable_comp(ioc);
485 break;
486
Jing Huang7725ccf2009-09-23 17:46:15 -0700487 default:
488 bfa_sm_fault(ioc, event);
489 }
490}
491
Jing Huang5fbe25c2010-10-18 17:17:23 -0700492/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700493 * IOC disable completion entry.
494 */
495static void
496bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc)
497{
498 bfa_ioc_disable_comp(ioc);
499}
500
501static void
502bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event)
503{
504 bfa_trc(ioc, event);
505
506 switch (event) {
507 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700508 bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700509 break;
510
511 case IOC_E_DISABLE:
512 ioc->cbfn->disable_cbfn(ioc->bfa);
513 break;
514
Jing Huang7725ccf2009-09-23 17:46:15 -0700515 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700516 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800517 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700518 break;
519
520 default:
521 bfa_sm_fault(ioc, event);
522 }
523}
524
525
526static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800527bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700528{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800529 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700530}
531
Jing Huang5fbe25c2010-10-18 17:17:23 -0700532/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800533 * Hardware initialization retry.
Jing Huang7725ccf2009-09-23 17:46:15 -0700534 */
535static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800536bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700537{
538 bfa_trc(ioc, event);
539
540 switch (event) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700541 case IOC_E_ENABLED:
542 bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr);
543 break;
544
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800545 case IOC_E_PFFAILED:
546 case IOC_E_HWERROR:
Jing Huang5fbe25c2010-10-18 17:17:23 -0700547 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800548 * Initialization retry failed.
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700549 */
550 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700551 bfa_fsm_set_state(ioc, bfa_ioc_sm_fail);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800552 if (event != IOC_E_PFFAILED)
553 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL);
554 break;
555
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700556 case IOC_E_HWFAILED:
557 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
558 bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail);
559 break;
560
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800561 case IOC_E_ENABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700562 break;
563
Jing Huang7725ccf2009-09-23 17:46:15 -0700564 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700565 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700566 break;
567
568 case IOC_E_DETACH:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700569 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800570 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
Jing Huang7725ccf2009-09-23 17:46:15 -0700571 break;
572
573 default:
574 bfa_sm_fault(ioc, event);
575 }
576}
577
578
579static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700580bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -0700581{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800582 bfa_trc(ioc, 0);
Jing Huang7725ccf2009-09-23 17:46:15 -0700583}
584
Jing Huang5fbe25c2010-10-18 17:17:23 -0700585/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700586 * IOC failure.
Jing Huang7725ccf2009-09-23 17:46:15 -0700587 */
588static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700589bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700590{
591 bfa_trc(ioc, event);
592
593 switch (event) {
594
595 case IOC_E_ENABLE:
596 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
597 break;
598
599 case IOC_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700600 bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling);
Jing Huang7725ccf2009-09-23 17:46:15 -0700601 break;
602
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800603 case IOC_E_DETACH:
604 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
605 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP);
606 break;
607
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800608 case IOC_E_HWERROR:
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700609 case IOC_E_HWFAILED:
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800610 /*
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700611 * HB failure / HW error notification, ignore.
Krishna Gudipati0a20de42010-03-05 19:34:20 -0800612 */
613 break;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700614 default:
615 bfa_sm_fault(ioc, event);
616 }
617}
618
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700619static void
620bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s *ioc)
621{
622 bfa_trc(ioc, 0);
623}
624
625static void
626bfa_ioc_sm_hwfail(struct bfa_ioc_s *ioc, enum ioc_event event)
627{
628 bfa_trc(ioc, event);
629
630 switch (event) {
631 case IOC_E_ENABLE:
632 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
633 break;
634
635 case IOC_E_DISABLE:
636 ioc->cbfn->disable_cbfn(ioc->bfa);
637 break;
638
639 case IOC_E_DETACH:
640 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
641 break;
642
Krishna Gudipati881c1b32012-08-22 19:52:02 -0700643 case IOC_E_HWERROR:
644 /* Ignore - already in hwfail state */
645 break;
646
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700647 default:
648 bfa_sm_fault(ioc, event);
649 }
650}
651
Jing Huang5fbe25c2010-10-18 17:17:23 -0700652/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700653 * IOCPF State Machine
654 */
655
Jing Huang5fbe25c2010-10-18 17:17:23 -0700656/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700657 * Reset entry actions -- initialize state machine
658 */
659static void
660bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf)
661{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700662 iocpf->fw_mismatch_notified = BFA_FALSE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700663 iocpf->auto_recover = bfa_auto_recover;
664}
665
Jing Huang5fbe25c2010-10-18 17:17:23 -0700666/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700667 * Beginning state. IOC is in reset state.
668 */
669static void
670bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
671{
672 struct bfa_ioc_s *ioc = iocpf->ioc;
673
674 bfa_trc(ioc, event);
675
676 switch (event) {
677 case IOCPF_E_ENABLE:
678 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
679 break;
680
681 case IOCPF_E_STOP:
682 break;
683
684 default:
685 bfa_sm_fault(ioc, event);
686 }
687}
688
Jing Huang5fbe25c2010-10-18 17:17:23 -0700689/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700690 * Semaphore should be acquired for version check.
691 */
692static void
693bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf)
694{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700695 struct bfi_ioc_image_hdr_s fwhdr;
Krishna Gudipati89196782012-03-13 17:38:56 -0700696 u32 r32, fwstate, pgnum, pgoff, loff = 0;
697 int i;
698
699 /*
700 * Spin on init semaphore to serialize.
701 */
702 r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
703 while (r32 & 0x1) {
704 udelay(20);
705 r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg);
706 }
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700707
708 /* h/w sem init */
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -0700709 fwstate = bfa_ioc_get_cur_ioc_fwstate(iocpf->ioc);
Krishna Gudipati89196782012-03-13 17:38:56 -0700710 if (fwstate == BFI_IOC_UNINIT) {
711 writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700712 goto sem_get;
Krishna Gudipati89196782012-03-13 17:38:56 -0700713 }
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700714
715 bfa_ioc_fwver_get(iocpf->ioc, &fwhdr);
716
Krishna Gudipati89196782012-03-13 17:38:56 -0700717 if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) {
718 writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700719 goto sem_get;
Krishna Gudipati89196782012-03-13 17:38:56 -0700720 }
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700721
722 /*
Krishna Gudipati89196782012-03-13 17:38:56 -0700723 * Clear fwver hdr
724 */
725 pgnum = PSS_SMEM_PGNUM(iocpf->ioc->ioc_regs.smem_pg0, loff);
726 pgoff = PSS_SMEM_PGOFF(loff);
727 writel(pgnum, iocpf->ioc->ioc_regs.host_page_num_fn);
728
729 for (i = 0; i < sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32); i++) {
730 bfa_mem_write(iocpf->ioc->ioc_regs.smem_page_start, loff, 0);
731 loff += sizeof(u32);
732 }
733
734 bfa_trc(iocpf->ioc, fwstate);
735 bfa_trc(iocpf->ioc, swab32(fwhdr.exec));
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -0700736 bfa_ioc_set_cur_ioc_fwstate(iocpf->ioc, BFI_IOC_UNINIT);
737 bfa_ioc_set_alt_ioc_fwstate(iocpf->ioc, BFI_IOC_UNINIT);
Krishna Gudipati89196782012-03-13 17:38:56 -0700738
739 /*
740 * Unlock the hw semaphore. Should be here only once per boot.
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700741 */
Krishna Gudipati7ac83b12012-09-21 17:24:21 -0700742 bfa_ioc_ownership_reset(iocpf->ioc);
Krishna Gudipati89196782012-03-13 17:38:56 -0700743
744 /*
745 * unlock init semaphore.
746 */
747 writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg);
748
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700749sem_get:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700750 bfa_ioc_hw_sem_get(iocpf->ioc);
751}
752
Jing Huang5fbe25c2010-10-18 17:17:23 -0700753/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700754 * Awaiting h/w semaphore to continue with version check.
755 */
756static void
757bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
758{
759 struct bfa_ioc_s *ioc = iocpf->ioc;
760
761 bfa_trc(ioc, event);
762
763 switch (event) {
764 case IOCPF_E_SEMLOCKED:
765 if (bfa_ioc_firmware_lock(ioc)) {
Jing Huang45d7f0c2011-04-13 11:45:53 -0700766 if (bfa_ioc_sync_start(ioc)) {
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800767 bfa_ioc_sync_join(ioc);
768 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
769 } else {
770 bfa_ioc_firmware_unlock(ioc);
771 writel(1, ioc->ioc_regs.ioc_sem_reg);
772 bfa_sem_timer_start(ioc);
773 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700774 } else {
Maggie Zhangf7f738122010-12-09 19:08:43 -0800775 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700776 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch);
777 }
778 break;
779
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700780 case IOCPF_E_SEM_ERROR:
781 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
782 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
783 break;
784
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700785 case IOCPF_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800786 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700787 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800788 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700789 break;
790
791 case IOCPF_E_STOP:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800792 bfa_sem_timer_stop(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700793 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
794 break;
795
796 default:
797 bfa_sm_fault(ioc, event);
798 }
799}
800
Jing Huang5fbe25c2010-10-18 17:17:23 -0700801/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700802 * Notify enable completion callback.
803 */
804static void
805bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf)
806{
807 /*
808 * Call only the first time sm enters fwmismatch state.
809 */
Krishna Gudipati775c7742011-06-13 15:52:12 -0700810 if (iocpf->fw_mismatch_notified == BFA_FALSE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700811 bfa_ioc_pf_fwmismatch(iocpf->ioc);
812
Krishna Gudipati775c7742011-06-13 15:52:12 -0700813 iocpf->fw_mismatch_notified = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700814 bfa_iocpf_timer_start(iocpf->ioc);
815}
816
Jing Huang5fbe25c2010-10-18 17:17:23 -0700817/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700818 * Awaiting firmware version match.
819 */
820static void
821bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
822{
823 struct bfa_ioc_s *ioc = iocpf->ioc;
824
825 bfa_trc(ioc, event);
826
827 switch (event) {
828 case IOCPF_E_TIMEOUT:
829 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck);
830 break;
831
832 case IOCPF_E_DISABLE:
833 bfa_iocpf_timer_stop(ioc);
834 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800835 bfa_fsm_send_event(ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700836 break;
837
838 case IOCPF_E_STOP:
839 bfa_iocpf_timer_stop(ioc);
840 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
841 break;
842
843 default:
844 bfa_sm_fault(ioc, event);
845 }
846}
847
Jing Huang5fbe25c2010-10-18 17:17:23 -0700848/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700849 * Request for semaphore.
850 */
851static void
852bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf)
853{
854 bfa_ioc_hw_sem_get(iocpf->ioc);
855}
856
Jing Huang5fbe25c2010-10-18 17:17:23 -0700857/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700858 * Awaiting semaphore for h/w initialzation.
859 */
860static void
861bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
862{
863 struct bfa_ioc_s *ioc = iocpf->ioc;
864
865 bfa_trc(ioc, event);
866
867 switch (event) {
868 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800869 if (bfa_ioc_sync_complete(ioc)) {
870 bfa_ioc_sync_join(ioc);
871 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
872 } else {
873 writel(1, ioc->ioc_regs.ioc_sem_reg);
874 bfa_sem_timer_start(ioc);
875 }
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700876 break;
877
Krishna Gudipati5a0adae2011-06-24 20:22:56 -0700878 case IOCPF_E_SEM_ERROR:
879 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
880 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
881 break;
882
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700883 case IOCPF_E_DISABLE:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800884 bfa_sem_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800885 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700886 break;
887
888 default:
889 bfa_sm_fault(ioc, event);
890 }
891}
892
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700893static void
894bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf)
895{
Krishna Gudipati775c7742011-06-13 15:52:12 -0700896 iocpf->poll_time = 0;
Maggie Zhangf7f738122010-12-09 19:08:43 -0800897 bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700898}
899
Jing Huang5fbe25c2010-10-18 17:17:23 -0700900/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700901 * Hardware is being initialized. Interrupts are enabled.
902 * Holding hardware semaphore lock.
903 */
904static void
905bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
906{
907 struct bfa_ioc_s *ioc = iocpf->ioc;
908
909 bfa_trc(ioc, event);
910
911 switch (event) {
912 case IOCPF_E_FWREADY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700913 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling);
914 break;
915
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700916 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800917 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700918 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800919 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700920 break;
921
922 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700923 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800924 bfa_ioc_sync_leave(ioc);
925 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700926 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
927 break;
928
929 default:
930 bfa_sm_fault(ioc, event);
931 }
932}
933
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700934static void
935bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf)
936{
937 bfa_iocpf_timer_start(iocpf->ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -0700938 /*
939 * Enable Interrupts before sending fw IOC ENABLE cmd.
940 */
941 iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700942 bfa_ioc_send_enable(iocpf->ioc);
943}
944
Jing Huang5fbe25c2010-10-18 17:17:23 -0700945/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700946 * Host IOC function is being enabled, awaiting response from firmware.
947 * Semaphore is acquired.
948 */
949static void
950bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
951{
952 struct bfa_ioc_s *ioc = iocpf->ioc;
953
954 bfa_trc(ioc, event);
955
956 switch (event) {
957 case IOCPF_E_FWRSP_ENABLE:
958 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800959 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700960 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready);
961 break;
962
963 case IOCPF_E_INITFAIL:
964 bfa_iocpf_timer_stop(ioc);
965 /*
966 * !!! fall through !!!
967 */
968
969 case IOCPF_E_TIMEOUT:
Maggie Zhangf7f738122010-12-09 19:08:43 -0800970 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700971 if (event == IOCPF_E_TIMEOUT)
Krishna Gudipati4e78efe2010-12-13 16:16:09 -0800972 bfa_fsm_send_event(ioc, IOC_E_PFFAILED);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -0800973 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700974 break;
975
976 case IOCPF_E_DISABLE:
977 bfa_iocpf_timer_stop(ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -0800978 writel(1, ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700979 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
980 break;
981
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700982 default:
983 bfa_sm_fault(ioc, event);
984 }
985}
986
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700987static void
988bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf)
989{
Maggie Zhangf7f738122010-12-09 19:08:43 -0800990 bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700991}
992
993static void
994bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
995{
996 struct bfa_ioc_s *ioc = iocpf->ioc;
997
998 bfa_trc(ioc, event);
999
1000 switch (event) {
1001 case IOCPF_E_DISABLE:
1002 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling);
1003 break;
1004
1005 case IOCPF_E_GETATTRFAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001006 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001007 break;
1008
1009 case IOCPF_E_FAIL:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001010 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001011 break;
1012
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001013 default:
1014 bfa_sm_fault(ioc, event);
1015 }
1016}
1017
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001018static void
1019bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf)
1020{
1021 bfa_iocpf_timer_start(iocpf->ioc);
1022 bfa_ioc_send_disable(iocpf->ioc);
1023}
1024
Jing Huang5fbe25c2010-10-18 17:17:23 -07001025/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001026 * IOC is being disabled
1027 */
1028static void
1029bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1030{
1031 struct bfa_ioc_s *ioc = iocpf->ioc;
1032
1033 bfa_trc(ioc, event);
1034
1035 switch (event) {
1036 case IOCPF_E_FWRSP_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001037 bfa_iocpf_timer_stop(ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001038 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001039 break;
1040
1041 case IOCPF_E_FAIL:
1042 bfa_iocpf_timer_stop(ioc);
1043 /*
1044 * !!! fall through !!!
1045 */
1046
1047 case IOCPF_E_TIMEOUT:
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07001048 bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001049 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001050 break;
1051
1052 case IOCPF_E_FWRSP_ENABLE:
1053 break;
1054
1055 default:
1056 bfa_sm_fault(ioc, event);
1057 }
1058}
1059
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001060static void
1061bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf)
1062{
1063 bfa_ioc_hw_sem_get(iocpf->ioc);
1064}
1065
Jing Huang8f4bfad2010-12-26 21:50:10 -08001066/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001067 * IOC hb ack request is being removed.
1068 */
1069static void
1070bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1071{
1072 struct bfa_ioc_s *ioc = iocpf->ioc;
1073
1074 bfa_trc(ioc, event);
1075
1076 switch (event) {
1077 case IOCPF_E_SEMLOCKED:
1078 bfa_ioc_sync_leave(ioc);
1079 writel(1, ioc->ioc_regs.ioc_sem_reg);
1080 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1081 break;
1082
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001083 case IOCPF_E_SEM_ERROR:
1084 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1085 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1086 break;
1087
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001088 case IOCPF_E_FAIL:
1089 break;
1090
1091 default:
1092 bfa_sm_fault(ioc, event);
1093 }
1094}
1095
Jing Huang5fbe25c2010-10-18 17:17:23 -07001096/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001097 * IOC disable completion entry.
1098 */
1099static void
1100bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf)
1101{
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001102 bfa_ioc_mbox_flush(iocpf->ioc);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001103 bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001104}
1105
1106static void
1107bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1108{
1109 struct bfa_ioc_s *ioc = iocpf->ioc;
1110
1111 bfa_trc(ioc, event);
1112
1113 switch (event) {
1114 case IOCPF_E_ENABLE:
1115 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1116 break;
1117
1118 case IOCPF_E_STOP:
1119 bfa_ioc_firmware_unlock(ioc);
1120 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1121 break;
1122
1123 default:
1124 bfa_sm_fault(ioc, event);
1125 }
1126}
1127
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001128static void
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001129bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf)
1130{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001131 bfa_ioc_debug_save_ftrc(iocpf->ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001132 bfa_ioc_hw_sem_get(iocpf->ioc);
1133}
1134
Jing Huang8f4bfad2010-12-26 21:50:10 -08001135/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001136 * Hardware initialization failed.
1137 */
1138static void
1139bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1140{
1141 struct bfa_ioc_s *ioc = iocpf->ioc;
1142
1143 bfa_trc(ioc, event);
1144
1145 switch (event) {
1146 case IOCPF_E_SEMLOCKED:
1147 bfa_ioc_notify_fail(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001148 bfa_ioc_sync_leave(ioc);
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07001149 bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
Krishna Gudipati775c7742011-06-13 15:52:12 -07001150 writel(1, ioc->ioc_regs.ioc_sem_reg);
1151 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001152 break;
1153
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001154 case IOCPF_E_SEM_ERROR:
1155 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1156 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1157 break;
1158
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001159 case IOCPF_E_DISABLE:
1160 bfa_sem_timer_stop(ioc);
1161 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1162 break;
1163
1164 case IOCPF_E_STOP:
1165 bfa_sem_timer_stop(ioc);
1166 bfa_ioc_firmware_unlock(ioc);
1167 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1168 break;
1169
1170 case IOCPF_E_FAIL:
1171 break;
1172
1173 default:
1174 bfa_sm_fault(ioc, event);
1175 }
1176}
1177
1178static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001179bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf)
1180{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001181 bfa_trc(iocpf->ioc, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001182}
1183
Jing Huang5fbe25c2010-10-18 17:17:23 -07001184/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001185 * Hardware initialization failed.
1186 */
1187static void
1188bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1189{
1190 struct bfa_ioc_s *ioc = iocpf->ioc;
1191
1192 bfa_trc(ioc, event);
1193
1194 switch (event) {
1195 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001196 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1197 break;
1198
1199 case IOCPF_E_STOP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001200 bfa_ioc_firmware_unlock(ioc);
1201 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset);
1202 break;
1203
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001204 default:
1205 bfa_sm_fault(ioc, event);
1206 }
1207}
1208
1209static void
1210bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf)
1211{
Jing Huang8f4bfad2010-12-26 21:50:10 -08001212 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001213 * Mark IOC as failed in hardware and stop firmware.
1214 */
1215 bfa_ioc_lpu_stop(iocpf->ioc);
1216
Jing Huang8f4bfad2010-12-26 21:50:10 -08001217 /*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001218 * Flush any queued up mailbox requests.
1219 */
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001220 bfa_ioc_mbox_flush(iocpf->ioc);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001221
1222 bfa_ioc_hw_sem_get(iocpf->ioc);
1223}
1224
1225static void
1226bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1227{
1228 struct bfa_ioc_s *ioc = iocpf->ioc;
1229
1230 bfa_trc(ioc, event);
1231
1232 switch (event) {
1233 case IOCPF_E_SEMLOCKED:
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001234 bfa_ioc_sync_ack(ioc);
1235 bfa_ioc_notify_fail(ioc);
1236 if (!iocpf->auto_recover) {
1237 bfa_ioc_sync_leave(ioc);
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07001238 bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_FAIL);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001239 writel(1, ioc->ioc_regs.ioc_sem_reg);
1240 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1241 } else {
1242 if (bfa_ioc_sync_complete(ioc))
1243 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit);
1244 else {
1245 writel(1, ioc->ioc_regs.ioc_sem_reg);
1246 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait);
1247 }
1248 }
1249 break;
1250
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001251 case IOCPF_E_SEM_ERROR:
1252 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail);
1253 bfa_fsm_send_event(ioc, IOC_E_HWFAILED);
1254 break;
1255
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08001256 case IOCPF_E_DISABLE:
1257 bfa_sem_timer_stop(ioc);
1258 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync);
1259 break;
1260
1261 case IOCPF_E_FAIL:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001262 break;
1263
1264 default:
1265 bfa_sm_fault(ioc, event);
1266 }
1267}
1268
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001269static void
1270bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf)
1271{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001272 bfa_trc(iocpf->ioc, 0);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001273}
1274
Jing Huang5fbe25c2010-10-18 17:17:23 -07001275/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001276 * IOC is in failed state.
1277 */
1278static void
1279bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event)
1280{
1281 struct bfa_ioc_s *ioc = iocpf->ioc;
1282
1283 bfa_trc(ioc, event);
1284
1285 switch (event) {
1286 case IOCPF_E_DISABLE:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001287 bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled);
1288 break;
1289
Jing Huang7725ccf2009-09-23 17:46:15 -07001290 default:
1291 bfa_sm_fault(ioc, event);
1292 }
1293}
1294
Jing Huang5fbe25c2010-10-18 17:17:23 -07001295/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08001296 * BFA IOC private functions
Jing Huang7725ccf2009-09-23 17:46:15 -07001297 */
1298
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001299/*
1300 * Notify common modules registered for notification.
1301 */
1302static void
1303bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event)
1304{
1305 struct bfa_ioc_notify_s *notify;
1306 struct list_head *qe;
1307
1308 list_for_each(qe, &ioc->notify_q) {
1309 notify = (struct bfa_ioc_notify_s *)qe;
1310 notify->cbfn(notify->cbarg, event);
1311 }
1312}
1313
Jing Huang7725ccf2009-09-23 17:46:15 -07001314static void
1315bfa_ioc_disable_comp(struct bfa_ioc_s *ioc)
1316{
Jing Huang7725ccf2009-09-23 17:46:15 -07001317 ioc->cbfn->disable_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001318 bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001319}
1320
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001321bfa_boolean_t
Jing Huang53440262010-10-18 17:12:29 -07001322bfa_ioc_sem_get(void __iomem *sem_reg)
Jing Huang7725ccf2009-09-23 17:46:15 -07001323{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001324 u32 r32;
1325 int cnt = 0;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001326#define BFA_SEM_SPINCNT 3000
Jing Huang7725ccf2009-09-23 17:46:15 -07001327
Jing Huang53440262010-10-18 17:12:29 -07001328 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001329
Krishna Gudipati11189202011-06-13 15:50:35 -07001330 while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001331 cnt++;
Jing Huang6a18b162010-10-18 17:08:54 -07001332 udelay(2);
Jing Huang53440262010-10-18 17:12:29 -07001333 r32 = readl(sem_reg);
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001334 }
1335
Krishna Gudipati11189202011-06-13 15:50:35 -07001336 if (!(r32 & 1))
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001337 return BFA_TRUE;
1338
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001339 return BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07001340}
1341
Jing Huang7725ccf2009-09-23 17:46:15 -07001342static void
1343bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc)
1344{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001345 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001346
Jing Huang5fbe25c2010-10-18 17:17:23 -07001347 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001348 * First read to the semaphore register will return 0, subsequent reads
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001349 * will return 1. Semaphore is released by writing 1 to the register
Jing Huang7725ccf2009-09-23 17:46:15 -07001350 */
Jing Huang53440262010-10-18 17:12:29 -07001351 r32 = readl(ioc->ioc_regs.ioc_sem_reg);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001352 if (r32 == ~0) {
1353 WARN_ON(r32 == ~0);
1354 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR);
1355 return;
1356 }
Krishna Gudipati11189202011-06-13 15:50:35 -07001357 if (!(r32 & 1)) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001358 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED);
Jing Huang7725ccf2009-09-23 17:46:15 -07001359 return;
1360 }
1361
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001362 bfa_sem_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001363}
1364
Jing Huang5fbe25c2010-10-18 17:17:23 -07001365/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001366 * Initialize LPU local memory (aka secondary memory / SRAM)
1367 */
1368static void
1369bfa_ioc_lmem_init(struct bfa_ioc_s *ioc)
1370{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001371 u32 pss_ctl;
1372 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001373#define PSS_LMEM_INIT_TIME 10000
1374
Jing Huang53440262010-10-18 17:12:29 -07001375 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001376 pss_ctl &= ~__PSS_LMEM_RESET;
1377 pss_ctl |= __PSS_LMEM_INIT_EN;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001378
1379 /*
1380 * i2c workaround 12.5khz clock
1381 */
1382 pss_ctl |= __PSS_I2C_CLK_DIV(3UL);
Jing Huang53440262010-10-18 17:12:29 -07001383 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001384
Jing Huang5fbe25c2010-10-18 17:17:23 -07001385 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001386 * wait for memory initialization to be complete
1387 */
1388 i = 0;
1389 do {
Jing Huang53440262010-10-18 17:12:29 -07001390 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001391 i++;
1392 } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME));
1393
Jing Huang5fbe25c2010-10-18 17:17:23 -07001394 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001395 * If memory initialization is not successful, IOC timeout will catch
1396 * such failures.
1397 */
Jing Huangd4b671c2010-12-26 21:46:35 -08001398 WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE));
Jing Huang7725ccf2009-09-23 17:46:15 -07001399 bfa_trc(ioc, pss_ctl);
1400
1401 pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN);
Jing Huang53440262010-10-18 17:12:29 -07001402 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001403}
1404
1405static void
1406bfa_ioc_lpu_start(struct bfa_ioc_s *ioc)
1407{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001408 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001409
Jing Huang5fbe25c2010-10-18 17:17:23 -07001410 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001411 * Take processor out of reset.
1412 */
Jing Huang53440262010-10-18 17:12:29 -07001413 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001414 pss_ctl &= ~__PSS_LPU0_RESET;
1415
Jing Huang53440262010-10-18 17:12:29 -07001416 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001417}
1418
1419static void
1420bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc)
1421{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001422 u32 pss_ctl;
Jing Huang7725ccf2009-09-23 17:46:15 -07001423
Jing Huang5fbe25c2010-10-18 17:17:23 -07001424 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001425 * Put processors in reset.
1426 */
Jing Huang53440262010-10-18 17:12:29 -07001427 pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001428 pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET);
1429
Jing Huang53440262010-10-18 17:12:29 -07001430 writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg);
Jing Huang7725ccf2009-09-23 17:46:15 -07001431}
1432
Jing Huang5fbe25c2010-10-18 17:17:23 -07001433/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001434 * Get driver and firmware versions.
1435 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001436void
Jing Huang7725ccf2009-09-23 17:46:15 -07001437bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1438{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001439 u32 pgnum, pgoff;
1440 u32 loff = 0;
1441 int i;
1442 u32 *fwsig = (u32 *) fwhdr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001443
Maggie Zhangf7f738122010-12-09 19:08:43 -08001444 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1445 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang53440262010-10-18 17:12:29 -07001446 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001447
1448 for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32));
1449 i++) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001450 fwsig[i] =
1451 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001452 loff += sizeof(u32);
1453 }
1454}
1455
Jing Huang5fbe25c2010-10-18 17:17:23 -07001456/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001457 * Returns TRUE if same.
1458 */
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001459bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07001460bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr)
1461{
1462 struct bfi_ioc_image_hdr_s *drv_fwhdr;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001463 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001464
Jing Huang293f82d2010-07-08 19:45:20 -07001465 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001466 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001467
1468 for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) {
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001469 if (fwhdr->md5sum[i] != cpu_to_le32(drv_fwhdr->md5sum[i])) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001470 bfa_trc(ioc, i);
1471 bfa_trc(ioc, fwhdr->md5sum[i]);
1472 bfa_trc(ioc, drv_fwhdr->md5sum[i]);
1473 return BFA_FALSE;
1474 }
1475 }
1476
1477 bfa_trc(ioc, fwhdr->md5sum[0]);
1478 return BFA_TRUE;
1479}
1480
Jing Huang5fbe25c2010-10-18 17:17:23 -07001481/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001482 * Return true if current running version is valid. Firmware signature and
1483 * execution context (driver/bios) must match.
1484 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001485static bfa_boolean_t
1486bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001487{
1488 struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr;
1489
Jing Huang7725ccf2009-09-23 17:46:15 -07001490 bfa_ioc_fwver_get(ioc, &fwhdr);
Jing Huang293f82d2010-07-08 19:45:20 -07001491 drv_fwhdr = (struct bfi_ioc_image_hdr_s *)
Krishna Gudipati11189202011-06-13 15:50:35 -07001492 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0);
Jing Huang7725ccf2009-09-23 17:46:15 -07001493
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001494 if (fwhdr.signature != cpu_to_le32(drv_fwhdr->signature)) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001495 bfa_trc(ioc, fwhdr.signature);
1496 bfa_trc(ioc, drv_fwhdr->signature);
1497 return BFA_FALSE;
1498 }
1499
Krishna Gudipati11189202011-06-13 15:50:35 -07001500 if (swab32(fwhdr.bootenv) != boot_env) {
1501 bfa_trc(ioc, fwhdr.bootenv);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001502 bfa_trc(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001503 return BFA_FALSE;
1504 }
1505
1506 return bfa_ioc_fwver_cmp(ioc, &fwhdr);
1507}
1508
Jing Huang5fbe25c2010-10-18 17:17:23 -07001509/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001510 * Conditionally flush any pending message from firmware at start.
1511 */
1512static void
1513bfa_ioc_msgflush(struct bfa_ioc_s *ioc)
1514{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001515 u32 r32;
Jing Huang7725ccf2009-09-23 17:46:15 -07001516
Jing Huang53440262010-10-18 17:12:29 -07001517 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001518 if (r32)
Jing Huang53440262010-10-18 17:12:29 -07001519 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001520}
1521
Jing Huang7725ccf2009-09-23 17:46:15 -07001522static void
1523bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force)
1524{
1525 enum bfi_ioc_state ioc_fwstate;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001526 bfa_boolean_t fwvalid;
1527 u32 boot_type;
1528 u32 boot_env;
Jing Huang7725ccf2009-09-23 17:46:15 -07001529
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07001530 ioc_fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001531
1532 if (force)
1533 ioc_fwstate = BFI_IOC_UNINIT;
1534
1535 bfa_trc(ioc, ioc_fwstate);
1536
Krishna Gudipati11189202011-06-13 15:50:35 -07001537 boot_type = BFI_FWBOOT_TYPE_NORMAL;
1538 boot_env = BFI_FWBOOT_ENV_OS;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001539
Jing Huang5fbe25c2010-10-18 17:17:23 -07001540 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001541 * check if firmware is valid
1542 */
1543 fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ?
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001544 BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07001545
1546 if (!fwvalid) {
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001547 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001548 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001549 return;
1550 }
1551
Jing Huang5fbe25c2010-10-18 17:17:23 -07001552 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001553 * If hardware initialization is in progress (initialized by other IOC),
1554 * just wait for an initialization completion interrupt.
1555 */
1556 if (ioc_fwstate == BFI_IOC_INITING) {
Krishna Gudipati775c7742011-06-13 15:52:12 -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 IOC function is disabled and firmware version is same,
1563 * just re-enable IOC.
Jing Huang07b28382010-07-08 19:59:24 -07001564 *
1565 * If option rom, IOC must not be in operational state. With
1566 * convergence, IOC will be in operational state when 2nd driver
1567 * is loaded.
Jing Huang7725ccf2009-09-23 17:46:15 -07001568 */
Jing Huang8f4bfad2010-12-26 21:50:10 -08001569 if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001570
Jing Huang5fbe25c2010-10-18 17:17:23 -07001571 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001572 * When using MSI-X any pending firmware ready event should
1573 * be flushed. Otherwise MSI-X interrupts are not delivered.
1574 */
1575 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001576 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
Jing Huang7725ccf2009-09-23 17:46:15 -07001577 return;
1578 }
1579
Jing Huang5fbe25c2010-10-18 17:17:23 -07001580 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001581 * Initialize the h/w for any other states.
1582 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001583 bfa_ioc_boot(ioc, boot_type, boot_env);
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001584 bfa_ioc_poll_fwinit(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001585}
1586
1587static void
1588bfa_ioc_timeout(void *ioc_arg)
1589{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001590 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
Jing Huang7725ccf2009-09-23 17:46:15 -07001591
1592 bfa_trc(ioc, 0);
1593 bfa_fsm_send_event(ioc, IOC_E_TIMEOUT);
1594}
1595
1596void
1597bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len)
1598{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001599 u32 *msgp = (u32 *) ioc_msg;
1600 u32 i;
Jing Huang7725ccf2009-09-23 17:46:15 -07001601
1602 bfa_trc(ioc, msgp[0]);
1603 bfa_trc(ioc, len);
1604
Jing Huangd4b671c2010-12-26 21:46:35 -08001605 WARN_ON(len > BFI_IOC_MSGLEN_MAX);
Jing Huang7725ccf2009-09-23 17:46:15 -07001606
1607 /*
1608 * first write msg to mailbox registers
1609 */
1610 for (i = 0; i < len / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001611 writel(cpu_to_le32(msgp[i]),
1612 ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001613
1614 for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++)
Jing Huang53440262010-10-18 17:12:29 -07001615 writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32));
Jing Huang7725ccf2009-09-23 17:46:15 -07001616
1617 /*
1618 * write 1 to mailbox CMD to trigger LPU event
1619 */
Jing Huang53440262010-10-18 17:12:29 -07001620 writel(1, ioc->ioc_regs.hfn_mbox_cmd);
1621 (void) readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001622}
1623
1624static void
1625bfa_ioc_send_enable(struct bfa_ioc_s *ioc)
1626{
1627 struct bfi_ioc_ctrl_req_s enable_req;
Maggie Zhangf16a1752010-12-09 19:12:32 -08001628 struct timeval tv;
Jing Huang7725ccf2009-09-23 17:46:15 -07001629
1630 bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ,
1631 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001632 enable_req.clscode = cpu_to_be16(ioc->clscode);
Maggie Zhangf16a1752010-12-09 19:12:32 -08001633 do_gettimeofday(&tv);
Jing Huangba816ea2010-10-18 17:10:50 -07001634 enable_req.tv_sec = be32_to_cpu(tv.tv_sec);
Jing Huang7725ccf2009-09-23 17:46:15 -07001635 bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1636}
1637
1638static void
1639bfa_ioc_send_disable(struct bfa_ioc_s *ioc)
1640{
1641 struct bfi_ioc_ctrl_req_s disable_req;
1642
1643 bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ,
1644 bfa_ioc_portid(ioc));
1645 bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s));
1646}
1647
1648static void
1649bfa_ioc_send_getattr(struct bfa_ioc_s *ioc)
1650{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001651 struct bfi_ioc_getattr_req_s attr_req;
Jing Huang7725ccf2009-09-23 17:46:15 -07001652
1653 bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ,
1654 bfa_ioc_portid(ioc));
1655 bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa);
1656 bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req));
1657}
1658
1659static void
1660bfa_ioc_hb_check(void *cbarg)
1661{
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001662 struct bfa_ioc_s *ioc = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001663 u32 hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001664
Jing Huang53440262010-10-18 17:12:29 -07001665 hb_count = readl(ioc->ioc_regs.heartbeat);
Jing Huang7725ccf2009-09-23 17:46:15 -07001666 if (ioc->hb_count == hb_count) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001667 bfa_ioc_recover(ioc);
1668 return;
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001669 } else {
1670 ioc->hb_count = hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07001671 }
1672
1673 bfa_ioc_mbox_poll(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001674 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001675}
1676
1677static void
1678bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc)
1679{
Jing Huang53440262010-10-18 17:12:29 -07001680 ioc->hb_count = readl(ioc->ioc_regs.heartbeat);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001681 bfa_hb_timer_start(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07001682}
1683
Jing Huang5fbe25c2010-10-18 17:17:23 -07001684/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001685 * Initiate a full firmware download.
Jing Huang7725ccf2009-09-23 17:46:15 -07001686 */
1687static void
1688bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001689 u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07001690{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001691 u32 *fwimg;
1692 u32 pgnum, pgoff;
1693 u32 loff = 0;
1694 u32 chunkno = 0;
1695 u32 i;
Krishna Gudipati11189202011-06-13 15:50:35 -07001696 u32 asicmode;
Jing Huang7725ccf2009-09-23 17:46:15 -07001697
Krishna Gudipati11189202011-06-13 15:50:35 -07001698 bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)));
1699 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno);
Jing Huang7725ccf2009-09-23 17:46:15 -07001700
Maggie Zhangf7f738122010-12-09 19:08:43 -08001701 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
1702 pgoff = PSS_SMEM_PGOFF(loff);
Jing Huang7725ccf2009-09-23 17:46:15 -07001703
Jing Huang53440262010-10-18 17:12:29 -07001704 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001705
Krishna Gudipati11189202011-06-13 15:50:35 -07001706 for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) {
Jing Huang7725ccf2009-09-23 17:46:15 -07001707
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001708 if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) {
1709 chunkno = BFA_IOC_FLASH_CHUNK_NO(i);
Krishna Gudipati11189202011-06-13 15:50:35 -07001710 fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc),
Krishna Gudipati0a20de42010-03-05 19:34:20 -08001711 BFA_IOC_FLASH_CHUNK_ADDR(chunkno));
Jing Huang7725ccf2009-09-23 17:46:15 -07001712 }
1713
Jing Huang5fbe25c2010-10-18 17:17:23 -07001714 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001715 * write smem
1716 */
1717 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff,
Krishna Gudipati881c1b32012-08-22 19:52:02 -07001718 cpu_to_le32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]));
Jing Huang7725ccf2009-09-23 17:46:15 -07001719
1720 loff += sizeof(u32);
1721
Jing Huang5fbe25c2010-10-18 17:17:23 -07001722 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001723 * handle page offset wrap around
1724 */
1725 loff = PSS_SMEM_PGOFF(loff);
1726 if (loff == 0) {
1727 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001728 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Jing Huang7725ccf2009-09-23 17:46:15 -07001729 }
1730 }
1731
Maggie Zhangf7f738122010-12-09 19:08:43 -08001732 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1733 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipati13cc20c2010-03-05 19:37:29 -08001734
1735 /*
Krishna Gudipati11189202011-06-13 15:50:35 -07001736 * Set boot type and device mode at the end.
1737 */
1738 asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode,
1739 ioc->port0_mode, ioc->port1_mode);
1740 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF,
1741 swab32(asicmode));
1742 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001743 swab32(boot_type));
Krishna Gudipati11189202011-06-13 15:50:35 -07001744 bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF,
Jing Huang53440262010-10-18 17:12:29 -07001745 swab32(boot_env));
Jing Huang7725ccf2009-09-23 17:46:15 -07001746}
1747
Jing Huang7725ccf2009-09-23 17:46:15 -07001748
Jing Huang5fbe25c2010-10-18 17:17:23 -07001749/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001750 * Update BFA configuration from firmware configuration.
1751 */
1752static void
1753bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc)
1754{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001755 struct bfi_ioc_attr_s *attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07001756
Jing Huangba816ea2010-10-18 17:10:50 -07001757 attr->adapter_prop = be32_to_cpu(attr->adapter_prop);
1758 attr->card_type = be32_to_cpu(attr->card_type);
1759 attr->maxfrsize = be16_to_cpu(attr->maxfrsize);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001760 ioc->fcmode = (attr->port_mode == BFI_PORT_MODE_FC);
Krishna Gudipatiea5d7c92012-09-21 17:25:02 -07001761 attr->mfg_year = be16_to_cpu(attr->mfg_year);
Jing Huang7725ccf2009-09-23 17:46:15 -07001762
1763 bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR);
1764}
1765
Jing Huang5fbe25c2010-10-18 17:17:23 -07001766/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001767 * Attach time initialization of mbox logic.
1768 */
1769static void
1770bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc)
1771{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001772 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1773 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07001774
1775 INIT_LIST_HEAD(&mod->cmd_q);
1776 for (mc = 0; mc < BFI_MC_MAX; mc++) {
1777 mod->mbhdlr[mc].cbfn = NULL;
1778 mod->mbhdlr[mc].cbarg = ioc->bfa;
1779 }
1780}
1781
Jing Huang5fbe25c2010-10-18 17:17:23 -07001782/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001783 * Mbox poll timer -- restarts any pending mailbox requests.
1784 */
1785static void
1786bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc)
1787{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001788 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1789 struct bfa_mbox_cmd_s *cmd;
1790 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07001791
Jing Huang5fbe25c2010-10-18 17:17:23 -07001792 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001793 * If no command pending, do nothing
1794 */
1795 if (list_empty(&mod->cmd_q))
1796 return;
1797
Jing Huang5fbe25c2010-10-18 17:17:23 -07001798 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001799 * If previous command is not yet fetched by firmware, do nothing
1800 */
Jing Huang53440262010-10-18 17:12:29 -07001801 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07001802 if (stat)
1803 return;
1804
Jing Huang5fbe25c2010-10-18 17:17:23 -07001805 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07001806 * Enqueue command to firmware.
1807 */
1808 bfa_q_deq(&mod->cmd_q, &cmd);
1809 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
1810}
1811
Jing Huang5fbe25c2010-10-18 17:17:23 -07001812/*
Jing Huang7725ccf2009-09-23 17:46:15 -07001813 * Cleanup any pending requests.
1814 */
1815static void
Krishna Gudipati8b070b42011-06-13 15:52:40 -07001816bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07001817{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001818 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
1819 struct bfa_mbox_cmd_s *cmd;
Jing Huang7725ccf2009-09-23 17:46:15 -07001820
1821 while (!list_empty(&mod->cmd_q))
1822 bfa_q_deq(&mod->cmd_q, &cmd);
1823}
1824
Jing Huang5fbe25c2010-10-18 17:17:23 -07001825/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001826 * Read data from SMEM to host through PCI memmap
1827 *
1828 * @param[in] ioc memory for IOC
1829 * @param[in] tbuf app memory to store data from smem
1830 * @param[in] soff smem offset
1831 * @param[in] sz size of smem in bytes
Jing Huang7725ccf2009-09-23 17:46:15 -07001832 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001833static bfa_status_t
1834bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz)
1835{
Maggie50444a32010-11-29 18:26:32 -08001836 u32 pgnum, loff;
1837 __be32 r32;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001838 int i, len;
1839 u32 *buf = tbuf;
1840
Maggie Zhangf7f738122010-12-09 19:08:43 -08001841 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1842 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001843 bfa_trc(ioc, pgnum);
1844 bfa_trc(ioc, loff);
1845 bfa_trc(ioc, sz);
1846
1847 /*
1848 * Hold semaphore to serialize pll init and fwtrc.
1849 */
1850 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1851 bfa_trc(ioc, 0);
1852 return BFA_STATUS_FAILED;
1853 }
1854
Jing Huang53440262010-10-18 17:12:29 -07001855 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001856
1857 len = sz/sizeof(u32);
1858 bfa_trc(ioc, len);
1859 for (i = 0; i < len; i++) {
1860 r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
Jing Huangba816ea2010-10-18 17:10:50 -07001861 buf[i] = be32_to_cpu(r32);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001862 loff += sizeof(u32);
1863
Jing Huang5fbe25c2010-10-18 17:17:23 -07001864 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001865 * handle page offset wrap around
1866 */
1867 loff = PSS_SMEM_PGOFF(loff);
1868 if (loff == 0) {
1869 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001870 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001871 }
1872 }
Maggie Zhangf7f738122010-12-09 19:08:43 -08001873 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1874 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001875 /*
1876 * release semaphore.
1877 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001878 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001879 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001880
1881 bfa_trc(ioc, pgnum);
1882 return BFA_STATUS_OK;
1883}
1884
Jing Huang5fbe25c2010-10-18 17:17:23 -07001885/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001886 * Clear SMEM data from host through PCI memmap
1887 *
1888 * @param[in] ioc memory for IOC
1889 * @param[in] soff smem offset
1890 * @param[in] sz size of smem in bytes
1891 */
1892static bfa_status_t
1893bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz)
1894{
1895 int i, len;
1896 u32 pgnum, loff;
1897
Maggie Zhangf7f738122010-12-09 19:08:43 -08001898 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff);
1899 loff = PSS_SMEM_PGOFF(soff);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001900 bfa_trc(ioc, pgnum);
1901 bfa_trc(ioc, loff);
1902 bfa_trc(ioc, sz);
1903
1904 /*
1905 * Hold semaphore to serialize pll init and fwtrc.
1906 */
1907 if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) {
1908 bfa_trc(ioc, 0);
1909 return BFA_STATUS_FAILED;
1910 }
1911
Jing Huang53440262010-10-18 17:12:29 -07001912 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001913
1914 len = sz/sizeof(u32); /* len in words */
1915 bfa_trc(ioc, len);
1916 for (i = 0; i < len; i++) {
1917 bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0);
1918 loff += sizeof(u32);
1919
Jing Huang5fbe25c2010-10-18 17:17:23 -07001920 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001921 * handle page offset wrap around
1922 */
1923 loff = PSS_SMEM_PGOFF(loff);
1924 if (loff == 0) {
1925 pgnum++;
Jing Huang53440262010-10-18 17:12:29 -07001926 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001927 }
1928 }
Maggie Zhangf7f738122010-12-09 19:08:43 -08001929 writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0),
1930 ioc->ioc_regs.host_page_num_fn);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001931
1932 /*
1933 * release semaphore.
1934 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001935 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001936 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001937 bfa_trc(ioc, pgnum);
1938 return BFA_STATUS_OK;
1939}
1940
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001941static void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001942bfa_ioc_fail_notify(struct bfa_ioc_s *ioc)
1943{
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001944 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
1945
Jing Huang8f4bfad2010-12-26 21:50:10 -08001946 /*
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001947 * Notify driver and common modules registered for notification.
1948 */
1949 ioc->cbfn->hbfail_cbfn(ioc->bfa);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07001950 bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001951
1952 bfa_ioc_debug_save_ftrc(ioc);
1953
1954 BFA_LOG(KERN_CRIT, bfad, bfa_log_level,
1955 "Heart Beat of IOC has failed\n");
Krishna Gudipati7826f302011-07-20 16:59:13 -07001956 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_HBFAIL);
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08001957
1958}
1959
1960static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001961bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc)
1962{
1963 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
Jing Huang5fbe25c2010-10-18 17:17:23 -07001964 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001965 * Provide enable completion callback.
1966 */
1967 ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE);
Jing Huang88166242010-12-09 17:11:53 -08001968 BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001969 "Running firmware version is incompatible "
1970 "with the driver version\n");
Krishna Gudipati7826f302011-07-20 16:59:13 -07001971 bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001972}
1973
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001974bfa_status_t
1975bfa_ioc_pll_init(struct bfa_ioc_s *ioc)
1976{
1977
1978 /*
1979 * Hold semaphore so that nobody can access the chip during init.
1980 */
1981 bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg);
1982
1983 bfa_ioc_pll_init_asic(ioc);
1984
1985 ioc->pllinit = BFA_TRUE;
Krishna Gudipati89196782012-03-13 17:38:56 -07001986
1987 /*
1988 * Initialize LMEM
1989 */
1990 bfa_ioc_lmem_init(ioc);
1991
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001992 /*
1993 * release semaphore.
1994 */
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07001995 readl(ioc->ioc_regs.ioc_init_sem_reg);
Maggie Zhangf7f738122010-12-09 19:08:43 -08001996 writel(1, ioc->ioc_regs.ioc_init_sem_reg);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07001997
1998 return BFA_STATUS_OK;
1999}
Jing Huang7725ccf2009-09-23 17:46:15 -07002000
Jing Huang5fbe25c2010-10-18 17:17:23 -07002001/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002002 * Interface used by diag module to do firmware boot with memory test
2003 * as the entry vector.
2004 */
2005void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002006bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env)
Jing Huang7725ccf2009-09-23 17:46:15 -07002007{
Jing Huang7725ccf2009-09-23 17:46:15 -07002008 bfa_ioc_stats(ioc, ioc_boots);
2009
2010 if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK)
2011 return;
2012
Jing Huang5fbe25c2010-10-18 17:17:23 -07002013 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002014 * Initialize IOC state of all functions on a chip reset.
2015 */
Krishna Gudipati11189202011-06-13 15:50:35 -07002016 if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) {
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07002017 bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
2018 bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_MEMTEST);
Jing Huang7725ccf2009-09-23 17:46:15 -07002019 } else {
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07002020 bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_INITING);
2021 bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_INITING);
Jing Huang7725ccf2009-09-23 17:46:15 -07002022 }
2023
Jing Huang07b28382010-07-08 19:59:24 -07002024 bfa_ioc_msgflush(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002025 bfa_ioc_download_fw(ioc, boot_type, boot_env);
Jing Huang7725ccf2009-09-23 17:46:15 -07002026 bfa_ioc_lpu_start(ioc);
2027}
2028
Jing Huang5fbe25c2010-10-18 17:17:23 -07002029/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002030 * Enable/disable IOC failure auto recovery.
2031 */
2032void
2033bfa_ioc_auto_recover(bfa_boolean_t auto_recover)
2034{
Krishna Gudipati2f9b8852010-03-03 17:42:51 -08002035 bfa_auto_recover = auto_recover;
Jing Huang7725ccf2009-09-23 17:46:15 -07002036}
2037
2038
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002039
Jing Huang7725ccf2009-09-23 17:46:15 -07002040bfa_boolean_t
2041bfa_ioc_is_operational(struct bfa_ioc_s *ioc)
2042{
2043 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op);
2044}
2045
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002046bfa_boolean_t
2047bfa_ioc_is_initialized(struct bfa_ioc_s *ioc)
2048{
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07002049 u32 r32 = bfa_ioc_get_cur_ioc_fwstate(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002050
2051 return ((r32 != BFI_IOC_UNINIT) &&
2052 (r32 != BFI_IOC_INITING) &&
2053 (r32 != BFI_IOC_MEMTEST));
2054}
2055
Krishna Gudipati11189202011-06-13 15:50:35 -07002056bfa_boolean_t
Jing Huang7725ccf2009-09-23 17:46:15 -07002057bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg)
2058{
Maggie50444a32010-11-29 18:26:32 -08002059 __be32 *msgp = mbmsg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002060 u32 r32;
2061 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -07002062
Krishna Gudipati11189202011-06-13 15:50:35 -07002063 r32 = readl(ioc->ioc_regs.lpu_mbox_cmd);
2064 if ((r32 & 1) == 0)
2065 return BFA_FALSE;
2066
Jing Huang5fbe25c2010-10-18 17:17:23 -07002067 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002068 * read the MBOX msg
2069 */
2070 for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32));
2071 i++) {
Jing Huang53440262010-10-18 17:12:29 -07002072 r32 = readl(ioc->ioc_regs.lpu_mbox +
Jing Huang7725ccf2009-09-23 17:46:15 -07002073 i * sizeof(u32));
Jing Huangba816ea2010-10-18 17:10:50 -07002074 msgp[i] = cpu_to_be32(r32);
Jing Huang7725ccf2009-09-23 17:46:15 -07002075 }
2076
Jing Huang5fbe25c2010-10-18 17:17:23 -07002077 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002078 * turn off mailbox interrupt by clearing mailbox status
2079 */
Jing Huang53440262010-10-18 17:12:29 -07002080 writel(1, ioc->ioc_regs.lpu_mbox_cmd);
2081 readl(ioc->ioc_regs.lpu_mbox_cmd);
Krishna Gudipati11189202011-06-13 15:50:35 -07002082
2083 return BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002084}
2085
2086void
2087bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m)
2088{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002089 union bfi_ioc_i2h_msg_u *msg;
2090 struct bfa_iocpf_s *iocpf = &ioc->iocpf;
Jing Huang7725ccf2009-09-23 17:46:15 -07002091
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002092 msg = (union bfi_ioc_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002093
2094 bfa_ioc_stats(ioc, ioc_isrs);
2095
2096 switch (msg->mh.msg_id) {
2097 case BFI_IOC_I2H_HBEAT:
2098 break;
2099
Jing Huang7725ccf2009-09-23 17:46:15 -07002100 case BFI_IOC_I2H_ENABLE_REPLY:
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002101 ioc->port_mode = ioc->port_mode_cfg =
2102 (enum bfa_mode_s)msg->fw_event.port_mode;
2103 ioc->ad_cap_bm = msg->fw_event.cap_bm;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002104 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07002105 break;
2106
2107 case BFI_IOC_I2H_DISABLE_REPLY:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002108 bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE);
Jing Huang7725ccf2009-09-23 17:46:15 -07002109 break;
2110
2111 case BFI_IOC_I2H_GETATTR_REPLY:
2112 bfa_ioc_getattr_reply(ioc);
2113 break;
2114
2115 default:
2116 bfa_trc(ioc, msg->mh.msg_id);
Jing Huangd4b671c2010-12-26 21:46:35 -08002117 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -07002118 }
2119}
2120
Jing Huang5fbe25c2010-10-18 17:17:23 -07002121/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002122 * IOC attach time initialization and setup.
2123 *
2124 * @param[in] ioc memory for IOC
2125 * @param[in] bfa driver instance structure
Jing Huang7725ccf2009-09-23 17:46:15 -07002126 */
2127void
2128bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002129 struct bfa_timer_mod_s *timer_mod)
Jing Huang7725ccf2009-09-23 17:46:15 -07002130{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002131 ioc->bfa = bfa;
2132 ioc->cbfn = cbfn;
2133 ioc->timer_mod = timer_mod;
2134 ioc->fcmode = BFA_FALSE;
2135 ioc->pllinit = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -07002136 ioc->dbg_fwsave_once = BFA_TRUE;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002137 ioc->iocpf.ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002138
2139 bfa_ioc_mbox_attach(ioc);
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002140 INIT_LIST_HEAD(&ioc->notify_q);
Jing Huang7725ccf2009-09-23 17:46:15 -07002141
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002142 bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit);
2143 bfa_fsm_send_event(ioc, IOC_E_RESET);
Jing Huang7725ccf2009-09-23 17:46:15 -07002144}
2145
Jing Huang5fbe25c2010-10-18 17:17:23 -07002146/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002147 * Driver detach time IOC cleanup.
2148 */
2149void
2150bfa_ioc_detach(struct bfa_ioc_s *ioc)
2151{
2152 bfa_fsm_send_event(ioc, IOC_E_DETACH);
Krishna Gudipati3350d982011-06-24 20:28:37 -07002153 INIT_LIST_HEAD(&ioc->notify_q);
Jing Huang7725ccf2009-09-23 17:46:15 -07002154}
2155
Jing Huang5fbe25c2010-10-18 17:17:23 -07002156/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002157 * Setup IOC PCI properties.
2158 *
2159 * @param[in] pcidev PCI device information for this IOC
2160 */
2161void
2162bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev,
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002163 enum bfi_pcifn_class clscode)
Jing Huang7725ccf2009-09-23 17:46:15 -07002164{
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002165 ioc->clscode = clscode;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002166 ioc->pcidev = *pcidev;
Krishna Gudipati11189202011-06-13 15:50:35 -07002167
2168 /*
2169 * Initialize IOC and device personality
2170 */
2171 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC;
2172 ioc->asic_mode = BFI_ASIC_MODE_FC;
2173
2174 switch (pcidev->device_id) {
2175 case BFA_PCI_DEVICE_ID_FC_8G1P:
2176 case BFA_PCI_DEVICE_ID_FC_8G2P:
2177 ioc->asic_gen = BFI_ASIC_GEN_CB;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002178 ioc->fcmode = BFA_TRUE;
2179 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2180 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002181 break;
2182
2183 case BFA_PCI_DEVICE_ID_CT:
2184 ioc->asic_gen = BFI_ASIC_GEN_CT;
2185 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
2186 ioc->asic_mode = BFI_ASIC_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002187 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA;
2188 ioc->ad_cap_bm = BFA_CM_CNA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002189 break;
2190
2191 case BFA_PCI_DEVICE_ID_CT_FC:
2192 ioc->asic_gen = BFI_ASIC_GEN_CT;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002193 ioc->fcmode = BFA_TRUE;
2194 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2195 ioc->ad_cap_bm = BFA_CM_HBA;
Krishna Gudipati11189202011-06-13 15:50:35 -07002196 break;
2197
2198 case BFA_PCI_DEVICE_ID_CT2:
2199 ioc->asic_gen = BFI_ASIC_GEN_CT2;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002200 if (clscode == BFI_PCIFN_CLASS_FC &&
2201 pcidev->ssid == BFA_PCI_CT2_SSID_FC) {
Krishna Gudipati11189202011-06-13 15:50:35 -07002202 ioc->asic_mode = BFI_ASIC_MODE_FC16;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002203 ioc->fcmode = BFA_TRUE;
2204 ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA;
2205 ioc->ad_cap_bm = BFA_CM_HBA;
2206 } else {
Krishna Gudipati11189202011-06-13 15:50:35 -07002207 ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002208 ioc->asic_mode = BFI_ASIC_MODE_ETH;
2209 if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) {
2210 ioc->port_mode =
2211 ioc->port_mode_cfg = BFA_MODE_CNA;
2212 ioc->ad_cap_bm = BFA_CM_CNA;
2213 } else {
2214 ioc->port_mode =
2215 ioc->port_mode_cfg = BFA_MODE_NIC;
2216 ioc->ad_cap_bm = BFA_CM_NIC;
2217 }
Krishna Gudipati11189202011-06-13 15:50:35 -07002218 }
2219 break;
2220
2221 default:
2222 WARN_ON(1);
2223 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002224
Jing Huang5fbe25c2010-10-18 17:17:23 -07002225 /*
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002226 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2227 */
Krishna Gudipati11189202011-06-13 15:50:35 -07002228 if (ioc->asic_gen == BFI_ASIC_GEN_CB)
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002229 bfa_ioc_set_cb_hwif(ioc);
Krishna Gudipati11189202011-06-13 15:50:35 -07002230 else if (ioc->asic_gen == BFI_ASIC_GEN_CT)
2231 bfa_ioc_set_ct_hwif(ioc);
2232 else {
2233 WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2);
2234 bfa_ioc_set_ct2_hwif(ioc);
2235 bfa_ioc_ct2_poweron(ioc);
2236 }
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002237
Jing Huang7725ccf2009-09-23 17:46:15 -07002238 bfa_ioc_map_port(ioc);
2239 bfa_ioc_reg_init(ioc);
2240}
2241
Jing Huang5fbe25c2010-10-18 17:17:23 -07002242/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002243 * Initialize IOC dma memory
2244 *
2245 * @param[in] dm_kva kernel virtual address of IOC dma memory
2246 * @param[in] dm_pa physical address of IOC dma memory
2247 */
2248void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002249bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa)
Jing Huang7725ccf2009-09-23 17:46:15 -07002250{
Jing Huang5fbe25c2010-10-18 17:17:23 -07002251 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002252 * dma memory for firmware attribute
2253 */
2254 ioc->attr_dma.kva = dm_kva;
2255 ioc->attr_dma.pa = dm_pa;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002256 ioc->attr = (struct bfi_ioc_attr_s *) dm_kva;
Jing Huang7725ccf2009-09-23 17:46:15 -07002257}
2258
Jing Huang7725ccf2009-09-23 17:46:15 -07002259void
2260bfa_ioc_enable(struct bfa_ioc_s *ioc)
2261{
2262 bfa_ioc_stats(ioc, ioc_enables);
2263 ioc->dbg_fwsave_once = BFA_TRUE;
2264
2265 bfa_fsm_send_event(ioc, IOC_E_ENABLE);
2266}
2267
2268void
2269bfa_ioc_disable(struct bfa_ioc_s *ioc)
2270{
2271 bfa_ioc_stats(ioc, ioc_disables);
2272 bfa_fsm_send_event(ioc, IOC_E_DISABLE);
2273}
2274
Krishna Gudipati881c1b32012-08-22 19:52:02 -07002275void
2276bfa_ioc_suspend(struct bfa_ioc_s *ioc)
2277{
2278 ioc->dbg_fwsave_once = BFA_TRUE;
2279 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2280}
Jing Huang7725ccf2009-09-23 17:46:15 -07002281
Jing Huang5fbe25c2010-10-18 17:17:23 -07002282/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002283 * Initialize memory for saving firmware trace. Driver must initialize
2284 * trace memory before call bfa_ioc_enable().
2285 */
2286void
2287bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave)
2288{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002289 ioc->dbg_fwsave = dbg_fwsave;
Krishna Gudipati881c1b32012-08-22 19:52:02 -07002290 ioc->dbg_fwsave_len = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002291}
2292
Jing Huang5fbe25c2010-10-18 17:17:23 -07002293/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002294 * Register mailbox message handler functions
2295 *
2296 * @param[in] ioc IOC instance
2297 * @param[in] mcfuncs message class handler functions
2298 */
2299void
2300bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs)
2301{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002302 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2303 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002304
2305 for (mc = 0; mc < BFI_MC_MAX; mc++)
2306 mod->mbhdlr[mc].cbfn = mcfuncs[mc];
2307}
2308
Jing Huang5fbe25c2010-10-18 17:17:23 -07002309/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002310 * Register mailbox message handler function, to be called by common modules
2311 */
2312void
2313bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc,
2314 bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg)
2315{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002316 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
Jing Huang7725ccf2009-09-23 17:46:15 -07002317
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002318 mod->mbhdlr[mc].cbfn = cbfn;
2319 mod->mbhdlr[mc].cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002320}
2321
Jing Huang5fbe25c2010-10-18 17:17:23 -07002322/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002323 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2324 * Responsibility of caller to serialize
2325 *
2326 * @param[in] ioc IOC instance
2327 * @param[i] cmd Mailbox command
2328 */
2329void
2330bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd)
2331{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002332 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2333 u32 stat;
Jing Huang7725ccf2009-09-23 17:46:15 -07002334
Jing Huang5fbe25c2010-10-18 17:17:23 -07002335 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002336 * If a previous command is pending, queue new command
2337 */
2338 if (!list_empty(&mod->cmd_q)) {
2339 list_add_tail(&cmd->qe, &mod->cmd_q);
2340 return;
2341 }
2342
Jing Huang5fbe25c2010-10-18 17:17:23 -07002343 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002344 * If mailbox is busy, queue command for poll timer
2345 */
Jing Huang53440262010-10-18 17:12:29 -07002346 stat = readl(ioc->ioc_regs.hfn_mbox_cmd);
Jing Huang7725ccf2009-09-23 17:46:15 -07002347 if (stat) {
2348 list_add_tail(&cmd->qe, &mod->cmd_q);
2349 return;
2350 }
2351
Jing Huang5fbe25c2010-10-18 17:17:23 -07002352 /*
Jing Huang7725ccf2009-09-23 17:46:15 -07002353 * mailbox is free -- queue command to firmware
2354 */
2355 bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg));
2356}
2357
Jing Huang5fbe25c2010-10-18 17:17:23 -07002358/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002359 * Handle mailbox interrupts
2360 */
2361void
2362bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc)
2363{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002364 struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod;
2365 struct bfi_mbmsg_s m;
2366 int mc;
Jing Huang7725ccf2009-09-23 17:46:15 -07002367
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002368 if (bfa_ioc_msgget(ioc, &m)) {
2369 /*
2370 * Treat IOC message class as special.
2371 */
2372 mc = m.mh.msg_class;
2373 if (mc == BFI_MC_IOC) {
2374 bfa_ioc_isr(ioc, &m);
2375 return;
2376 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002377
Dan Carpenterfffa6922012-06-27 11:59:36 +03002378 if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL))
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002379 return;
2380
2381 mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m);
Jing Huang7725ccf2009-09-23 17:46:15 -07002382 }
2383
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002384 bfa_ioc_lpu_read_stat(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002385
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002386 /*
2387 * Try to send pending mailbox commands
2388 */
2389 bfa_ioc_mbox_poll(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002390}
2391
2392void
2393bfa_ioc_error_isr(struct bfa_ioc_s *ioc)
2394{
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002395 bfa_ioc_stats(ioc, ioc_hbfails);
2396 ioc->stats.hb_count = ioc->hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07002397 bfa_fsm_send_event(ioc, IOC_E_HWERROR);
2398}
2399
Jing Huang5fbe25c2010-10-18 17:17:23 -07002400/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002401 * return true if IOC is disabled
2402 */
2403bfa_boolean_t
2404bfa_ioc_is_disabled(struct bfa_ioc_s *ioc)
2405{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002406 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) ||
2407 bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled);
Jing Huang7725ccf2009-09-23 17:46:15 -07002408}
2409
Jing Huang5fbe25c2010-10-18 17:17:23 -07002410/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002411 * return true if IOC firmware is different.
2412 */
2413bfa_boolean_t
2414bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc)
2415{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002416 return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) ||
2417 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) ||
2418 bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch);
Jing Huang7725ccf2009-09-23 17:46:15 -07002419}
2420
2421#define bfa_ioc_state_disabled(__sm) \
2422 (((__sm) == BFI_IOC_UNINIT) || \
2423 ((__sm) == BFI_IOC_INITING) || \
2424 ((__sm) == BFI_IOC_HWINIT) || \
2425 ((__sm) == BFI_IOC_DISABLED) || \
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002426 ((__sm) == BFI_IOC_FAIL) || \
Jing Huang7725ccf2009-09-23 17:46:15 -07002427 ((__sm) == BFI_IOC_CFG_DISABLED))
2428
Jing Huang5fbe25c2010-10-18 17:17:23 -07002429/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002430 * Check if adapter is disabled -- both IOCs should be in a disabled
2431 * state.
2432 */
2433bfa_boolean_t
2434bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc)
2435{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002436 u32 ioc_state;
Jing Huang7725ccf2009-09-23 17:46:15 -07002437
2438 if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled))
2439 return BFA_FALSE;
2440
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07002441 ioc_state = bfa_ioc_get_cur_ioc_fwstate(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002442 if (!bfa_ioc_state_disabled(ioc_state))
2443 return BFA_FALSE;
2444
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002445 if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) {
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07002446 ioc_state = bfa_ioc_get_cur_ioc_fwstate(ioc);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002447 if (!bfa_ioc_state_disabled(ioc_state))
2448 return BFA_FALSE;
2449 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002450
2451 return BFA_TRUE;
2452}
2453
Jing Huang8f4bfad2010-12-26 21:50:10 -08002454/*
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002455 * Reset IOC fwstate registers.
2456 */
2457void
2458bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc)
2459{
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07002460 bfa_ioc_set_cur_ioc_fwstate(ioc, BFI_IOC_UNINIT);
2461 bfa_ioc_set_alt_ioc_fwstate(ioc, BFI_IOC_UNINIT);
Krishna Gudipatif1d584d2010-12-13 16:17:11 -08002462}
2463
Jing Huang7725ccf2009-09-23 17:46:15 -07002464#define BFA_MFG_NAME "Brocade"
2465void
2466bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc,
2467 struct bfa_adapter_attr_s *ad_attr)
2468{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002469 struct bfi_ioc_attr_s *ioc_attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002470
2471 ioc_attr = ioc->attr;
Jing Huang7725ccf2009-09-23 17:46:15 -07002472
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002473 bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num);
2474 bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver);
2475 bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver);
2476 bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer);
Jing Huang6a18b162010-10-18 17:08:54 -07002477 memcpy(&ad_attr->vpd, &ioc_attr->vpd,
Jing Huang7725ccf2009-09-23 17:46:15 -07002478 sizeof(struct bfa_mfg_vpd_s));
2479
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002480 ad_attr->nports = bfa_ioc_get_nports(ioc);
2481 ad_attr->max_speed = bfa_ioc_speed_sup(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002482
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002483 bfa_ioc_get_adapter_model(ioc, ad_attr->model);
2484 /* For now, model descr uses same model string */
2485 bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr);
Jing Huang7725ccf2009-09-23 17:46:15 -07002486
Jing Huanged969322010-07-08 19:45:56 -07002487 ad_attr->card_type = ioc_attr->card_type;
2488 ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type);
2489
Jing Huang7725ccf2009-09-23 17:46:15 -07002490 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop))
2491 ad_attr->prototype = 1;
2492 else
2493 ad_attr->prototype = 0;
2494
Maggie Zhangf7f738122010-12-09 19:08:43 -08002495 ad_attr->pwwn = ioc->attr->pwwn;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002496 ad_attr->mac = bfa_ioc_get_mac(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002497
2498 ad_attr->pcie_gen = ioc_attr->pcie_gen;
2499 ad_attr->pcie_lanes = ioc_attr->pcie_lanes;
2500 ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig;
2501 ad_attr->asic_rev = ioc_attr->asic_rev;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002502
2503 bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver);
Jing Huang7725ccf2009-09-23 17:46:15 -07002504
Krishna Gudipati11189202011-06-13 15:50:35 -07002505 ad_attr->cna_capable = bfa_ioc_is_cna(ioc);
2506 ad_attr->trunk_capable = (ad_attr->nports > 1) &&
2507 !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz;
Krishna Gudipatiea5d7c92012-09-21 17:25:02 -07002508 ad_attr->mfg_day = ioc_attr->mfg_day;
2509 ad_attr->mfg_month = ioc_attr->mfg_month;
2510 ad_attr->mfg_year = ioc_attr->mfg_year;
Jing Huang7725ccf2009-09-23 17:46:15 -07002511}
2512
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002513enum bfa_ioc_type_e
2514bfa_ioc_get_type(struct bfa_ioc_s *ioc)
2515{
Krishna Gudipati11189202011-06-13 15:50:35 -07002516 if (ioc->clscode == BFI_PCIFN_CLASS_ETH)
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002517 return BFA_IOC_TYPE_LL;
Krishna Gudipati11189202011-06-13 15:50:35 -07002518
2519 WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC);
2520
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002521 return (ioc->attr->port_mode == BFI_PORT_MODE_FC)
Krishna Gudipati11189202011-06-13 15:50:35 -07002522 ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE;
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002523}
2524
Jing Huang7725ccf2009-09-23 17:46:15 -07002525void
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002526bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num)
2527{
Jing Huang6a18b162010-10-18 17:08:54 -07002528 memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN);
2529 memcpy((void *)serial_num,
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002530 (void *)ioc->attr->brcd_serialnum,
2531 BFA_ADAPTER_SERIAL_NUM_LEN);
2532}
2533
2534void
2535bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver)
2536{
Jing Huang6a18b162010-10-18 17:08:54 -07002537 memset((void *)fw_ver, 0, BFA_VERSION_LEN);
2538 memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002539}
2540
2541void
2542bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev)
2543{
Jing Huangd4b671c2010-12-26 21:46:35 -08002544 WARN_ON(!chip_rev);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002545
Jing Huang6a18b162010-10-18 17:08:54 -07002546 memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002547
2548 chip_rev[0] = 'R';
2549 chip_rev[1] = 'e';
2550 chip_rev[2] = 'v';
2551 chip_rev[3] = '-';
2552 chip_rev[4] = ioc->attr->asic_rev;
2553 chip_rev[5] = '\0';
2554}
2555
2556void
2557bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver)
2558{
Jing Huang6a18b162010-10-18 17:08:54 -07002559 memset((void *)optrom_ver, 0, BFA_VERSION_LEN);
2560 memcpy(optrom_ver, ioc->attr->optrom_version,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002561 BFA_VERSION_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002562}
2563
2564void
2565bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
2566{
Jing Huang6a18b162010-10-18 17:08:54 -07002567 memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
2568 memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002569}
2570
2571void
2572bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model)
2573{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002574 struct bfi_ioc_attr_s *ioc_attr;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002575
Jing Huangd4b671c2010-12-26 21:46:35 -08002576 WARN_ON(!model);
Jing Huang6a18b162010-10-18 17:08:54 -07002577 memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002578
2579 ioc_attr = ioc->attr;
2580
Krishna Gudipati10a07372011-06-24 20:23:38 -07002581 snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u",
Krishna Gudipati8b070b42011-06-13 15:52:40 -07002582 BFA_MFG_NAME, ioc_attr->card_type);
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002583}
2584
2585enum bfa_ioc_state
2586bfa_ioc_get_state(struct bfa_ioc_s *ioc)
2587{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002588 enum bfa_iocpf_state iocpf_st;
2589 enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm);
2590
2591 if (ioc_st == BFA_IOC_ENABLING ||
2592 ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) {
2593
2594 iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm);
2595
2596 switch (iocpf_st) {
2597 case BFA_IOCPF_SEMWAIT:
2598 ioc_st = BFA_IOC_SEMWAIT;
2599 break;
2600
2601 case BFA_IOCPF_HWINIT:
2602 ioc_st = BFA_IOC_HWINIT;
2603 break;
2604
2605 case BFA_IOCPF_FWMISMATCH:
2606 ioc_st = BFA_IOC_FWMISMATCH;
2607 break;
2608
2609 case BFA_IOCPF_FAIL:
2610 ioc_st = BFA_IOC_FAIL;
2611 break;
2612
2613 case BFA_IOCPF_INITFAIL:
2614 ioc_st = BFA_IOC_INITFAIL;
2615 break;
2616
2617 default:
2618 break;
2619 }
2620 }
2621
2622 return ioc_st;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002623}
2624
2625void
Jing Huang7725ccf2009-09-23 17:46:15 -07002626bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr)
2627{
Jing Huang6a18b162010-10-18 17:08:54 -07002628 memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s));
Jing Huang7725ccf2009-09-23 17:46:15 -07002629
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002630 ioc_attr->state = bfa_ioc_get_state(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002631 ioc_attr->port_id = ioc->port_id;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07002632 ioc_attr->port_mode = ioc->port_mode;
2633 ioc_attr->port_mode_cfg = ioc->port_mode_cfg;
2634 ioc_attr->cap_bm = ioc->ad_cap_bm;
Jing Huang7725ccf2009-09-23 17:46:15 -07002635
Krishna Gudipati2993cc72010-03-05 19:36:47 -08002636 ioc_attr->ioc_type = bfa_ioc_get_type(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002637
2638 bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr);
2639
2640 ioc_attr->pci_attr.device_id = ioc->pcidev.device_id;
2641 ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func;
Krishna Gudipati0a4b1fc2010-03-05 19:37:57 -08002642 bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev);
Jing Huang7725ccf2009-09-23 17:46:15 -07002643}
2644
Jing Huang7725ccf2009-09-23 17:46:15 -07002645mac_t
2646bfa_ioc_get_mac(struct bfa_ioc_s *ioc)
2647{
Jing Huang15b64a82010-07-08 19:48:12 -07002648 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002649 * Check the IOC type and return the appropriate MAC
Jing Huang15b64a82010-07-08 19:48:12 -07002650 */
2651 if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE)
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002652 return ioc->attr->fcoe_mac;
Jing Huang15b64a82010-07-08 19:48:12 -07002653 else
2654 return ioc->attr->mac;
2655}
2656
Jing Huang15b64a82010-07-08 19:48:12 -07002657mac_t
2658bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc)
2659{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002660 mac_t m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002661
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002662 m = ioc->attr->mfg_mac;
2663 if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type))
2664 m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc);
2665 else
2666 bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]),
2667 bfa_ioc_pcifn(ioc));
Jing Huang7725ccf2009-09-23 17:46:15 -07002668
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002669 return m;
Jing Huang7725ccf2009-09-23 17:46:15 -07002670}
2671
Jing Huang5fbe25c2010-10-18 17:17:23 -07002672/*
Krishna Gudipati7826f302011-07-20 16:59:13 -07002673 * Send AEN notification
2674 */
2675void
2676bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event)
2677{
2678 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
2679 struct bfa_aen_entry_s *aen_entry;
2680 enum bfa_ioc_type_e ioc_type;
2681
2682 bfad_get_aen_entry(bfad, aen_entry);
2683 if (!aen_entry)
2684 return;
2685
2686 ioc_type = bfa_ioc_get_type(ioc);
2687 switch (ioc_type) {
2688 case BFA_IOC_TYPE_FC:
2689 aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
2690 break;
2691 case BFA_IOC_TYPE_FCoE:
2692 aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn;
2693 aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
2694 break;
2695 case BFA_IOC_TYPE_LL:
2696 aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc);
2697 break;
2698 default:
2699 WARN_ON(ioc_type != BFA_IOC_TYPE_FC);
2700 break;
2701 }
2702
2703 /* Send the AEN notification */
2704 aen_entry->aen_data.ioc.ioc_type = ioc_type;
2705 bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
2706 BFA_AEN_CAT_IOC, event);
2707}
2708
2709/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002710 * Retrieve saved firmware trace from a prior IOC failure.
2711 */
2712bfa_status_t
2713bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2714{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002715 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002716
2717 if (ioc->dbg_fwsave_len == 0)
2718 return BFA_STATUS_ENOFSAVE;
2719
2720 tlen = *trclen;
2721 if (tlen > ioc->dbg_fwsave_len)
2722 tlen = ioc->dbg_fwsave_len;
2723
Jing Huang6a18b162010-10-18 17:08:54 -07002724 memcpy(trcdata, ioc->dbg_fwsave, tlen);
Jing Huang7725ccf2009-09-23 17:46:15 -07002725 *trclen = tlen;
2726 return BFA_STATUS_OK;
2727}
2728
Krishna Gudipati738c9e62010-03-05 19:36:19 -08002729
Jing Huang5fbe25c2010-10-18 17:17:23 -07002730/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002731 * Retrieve saved firmware trace from a prior IOC failure.
2732 */
2733bfa_status_t
2734bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen)
2735{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002736 u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc));
2737 int tlen;
2738 bfa_status_t status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002739
2740 bfa_trc(ioc, *trclen);
2741
Jing Huang7725ccf2009-09-23 17:46:15 -07002742 tlen = *trclen;
2743 if (tlen > BFA_DBG_FWTRC_LEN)
2744 tlen = BFA_DBG_FWTRC_LEN;
Jing Huang7725ccf2009-09-23 17:46:15 -07002745
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002746 status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen);
2747 *trclen = tlen;
2748 return status;
2749}
Jing Huang7725ccf2009-09-23 17:46:15 -07002750
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002751static void
2752bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc)
2753{
2754 struct bfa_mbox_cmd_s cmd;
2755 struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -07002756
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002757 bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC,
2758 bfa_ioc_portid(ioc));
Krishna Gudipatid37779f2011-06-13 15:42:10 -07002759 req->clscode = cpu_to_be16(ioc->clscode);
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002760 bfa_ioc_mbox_queue(ioc, &cmd);
2761}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002762
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002763static void
2764bfa_ioc_fwsync(struct bfa_ioc_s *ioc)
2765{
2766 u32 fwsync_iter = 1000;
2767
2768 bfa_ioc_send_fwsync(ioc);
2769
Jing Huang5fbe25c2010-10-18 17:17:23 -07002770 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002771 * After sending a fw sync mbox command wait for it to
2772 * take effect. We will not wait for a response because
2773 * 1. fw_sync mbox cmd doesn't have a response.
2774 * 2. Even if we implement that, interrupts might not
2775 * be enabled when we call this function.
2776 * So, just keep checking if any mbox cmd is pending, and
2777 * after waiting for a reasonable amount of time, go ahead.
2778 * It is possible that fw has crashed and the mbox command
2779 * is never acknowledged.
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002780 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002781 while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0)
2782 fwsync_iter--;
2783}
Krishna Gudipati0a20de42010-03-05 19:34:20 -08002784
Jing Huang5fbe25c2010-10-18 17:17:23 -07002785/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002786 * Dump firmware smem
2787 */
2788bfa_status_t
2789bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf,
2790 u32 *offset, int *buflen)
2791{
2792 u32 loff;
2793 int dlen;
2794 bfa_status_t status;
2795 u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -07002796
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002797 if (*offset >= smem_len) {
2798 *offset = *buflen = 0;
2799 return BFA_STATUS_EINVAL;
2800 }
2801
2802 loff = *offset;
2803 dlen = *buflen;
2804
Jing Huang5fbe25c2010-10-18 17:17:23 -07002805 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002806 * First smem read, sync smem before proceeding
2807 * No need to sync before reading every chunk.
2808 */
2809 if (loff == 0)
2810 bfa_ioc_fwsync(ioc);
2811
2812 if ((loff + dlen) >= smem_len)
2813 dlen = smem_len - loff;
2814
2815 status = bfa_ioc_smem_read(ioc, buf, loff, dlen);
2816
2817 if (status != BFA_STATUS_OK) {
2818 *offset = *buflen = 0;
2819 return status;
2820 }
2821
2822 *offset += dlen;
2823
2824 if (*offset >= smem_len)
2825 *offset = 0;
2826
2827 *buflen = dlen;
2828
2829 return status;
2830}
2831
Jing Huang5fbe25c2010-10-18 17:17:23 -07002832/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002833 * Firmware statistics
2834 */
2835bfa_status_t
2836bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats)
2837{
2838 u32 loff = BFI_IOC_FWSTATS_OFF + \
2839 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2840 int tlen;
2841 bfa_status_t status;
2842
2843 if (ioc->stats_busy) {
2844 bfa_trc(ioc, ioc->stats_busy);
2845 return BFA_STATUS_DEVBUSY;
2846 }
2847 ioc->stats_busy = BFA_TRUE;
2848
2849 tlen = sizeof(struct bfa_fw_stats_s);
2850 status = bfa_ioc_smem_read(ioc, stats, loff, tlen);
2851
2852 ioc->stats_busy = BFA_FALSE;
2853 return status;
2854}
2855
2856bfa_status_t
2857bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc)
2858{
2859 u32 loff = BFI_IOC_FWSTATS_OFF + \
2860 BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc));
2861 int tlen;
2862 bfa_status_t status;
2863
2864 if (ioc->stats_busy) {
2865 bfa_trc(ioc, ioc->stats_busy);
2866 return BFA_STATUS_DEVBUSY;
2867 }
2868 ioc->stats_busy = BFA_TRUE;
2869
2870 tlen = sizeof(struct bfa_fw_stats_s);
2871 status = bfa_ioc_smem_clr(ioc, loff, tlen);
2872
2873 ioc->stats_busy = BFA_FALSE;
2874 return status;
Jing Huang7725ccf2009-09-23 17:46:15 -07002875}
2876
Jing Huang5fbe25c2010-10-18 17:17:23 -07002877/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002878 * Save firmware trace if configured.
2879 */
Krishna Gudipati881c1b32012-08-22 19:52:02 -07002880void
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002881bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc)
Jing Huang7725ccf2009-09-23 17:46:15 -07002882{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002883 int tlen;
Jing Huang7725ccf2009-09-23 17:46:15 -07002884
Krishna Gudipati4e78efe2010-12-13 16:16:09 -08002885 if (ioc->dbg_fwsave_once) {
2886 ioc->dbg_fwsave_once = BFA_FALSE;
2887 if (ioc->dbg_fwsave_len) {
2888 tlen = ioc->dbg_fwsave_len;
2889 bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen);
2890 }
Jing Huang7725ccf2009-09-23 17:46:15 -07002891 }
2892}
2893
Jing Huang5fbe25c2010-10-18 17:17:23 -07002894/*
Jing Huang7725ccf2009-09-23 17:46:15 -07002895 * Firmware failure detected. Start recovery actions.
2896 */
2897static void
2898bfa_ioc_recover(struct bfa_ioc_s *ioc)
2899{
Jing Huang7725ccf2009-09-23 17:46:15 -07002900 bfa_ioc_stats(ioc, ioc_hbfails);
Krishna Gudipati5a0adae2011-06-24 20:22:56 -07002901 ioc->stats.hb_count = ioc->hb_count;
Jing Huang7725ccf2009-09-23 17:46:15 -07002902 bfa_fsm_send_event(ioc, IOC_E_HBFAIL);
2903}
2904
Jing Huang5fbe25c2010-10-18 17:17:23 -07002905/*
Maggie Zhangdf0f1932010-12-09 19:07:46 -08002906 * BFA IOC PF private functions
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002907 */
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002908static void
2909bfa_iocpf_timeout(void *ioc_arg)
2910{
2911 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2912
2913 bfa_trc(ioc, 0);
2914 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT);
2915}
2916
2917static void
2918bfa_iocpf_sem_timeout(void *ioc_arg)
2919{
2920 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2921
2922 bfa_ioc_hw_sem_get(ioc);
2923}
2924
Krishna Gudipati775c7742011-06-13 15:52:12 -07002925static void
2926bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc)
2927{
Vijaya Mohan Guvvac679b592013-05-13 02:33:26 -07002928 u32 fwstate = bfa_ioc_get_cur_ioc_fwstate(ioc);
Krishna Gudipati775c7742011-06-13 15:52:12 -07002929
2930 bfa_trc(ioc, fwstate);
2931
2932 if (fwstate == BFI_IOC_DISABLED) {
2933 bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY);
2934 return;
2935 }
2936
Krishna Gudipati7ac83b12012-09-21 17:24:21 -07002937 if (ioc->iocpf.poll_time >= (3 * BFA_IOC_TOV))
Krishna Gudipati775c7742011-06-13 15:52:12 -07002938 bfa_iocpf_timeout(ioc);
2939 else {
2940 ioc->iocpf.poll_time += BFA_IOC_POLL_TOV;
2941 bfa_iocpf_poll_timer_start(ioc);
2942 }
2943}
2944
2945static void
2946bfa_iocpf_poll_timeout(void *ioc_arg)
2947{
2948 struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg;
2949
2950 bfa_ioc_poll_fwinit(ioc);
2951}
2952
Jing Huang5fbe25c2010-10-18 17:17:23 -07002953/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002954 * bfa timer function
2955 */
2956void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002957bfa_timer_beat(struct bfa_timer_mod_s *mod)
2958{
2959 struct list_head *qh = &mod->timer_q;
2960 struct list_head *qe, *qe_next;
2961 struct bfa_timer_s *elem;
2962 struct list_head timedout_q;
2963
2964 INIT_LIST_HEAD(&timedout_q);
2965
2966 qe = bfa_q_next(qh);
2967
2968 while (qe != qh) {
2969 qe_next = bfa_q_next(qe);
2970
2971 elem = (struct bfa_timer_s *) qe;
2972 if (elem->timeout <= BFA_TIMER_FREQ) {
2973 elem->timeout = 0;
2974 list_del(&elem->qe);
2975 list_add_tail(&elem->qe, &timedout_q);
2976 } else {
2977 elem->timeout -= BFA_TIMER_FREQ;
2978 }
2979
2980 qe = qe_next; /* go to next elem */
2981 }
2982
2983 /*
2984 * Pop all the timeout entries
2985 */
2986 while (!list_empty(&timedout_q)) {
2987 bfa_q_deq(&timedout_q, &elem);
2988 elem->timercb(elem->arg);
2989 }
2990}
2991
Jing Huang5fbe25c2010-10-18 17:17:23 -07002992/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002993 * Should be called with lock protection
2994 */
2995void
2996bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer,
2997 void (*timercb) (void *), void *arg, unsigned int timeout)
2998{
2999
Jing Huangd4b671c2010-12-26 21:46:35 -08003000 WARN_ON(timercb == NULL);
3001 WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003002
3003 timer->timeout = timeout;
3004 timer->timercb = timercb;
3005 timer->arg = arg;
3006
3007 list_add_tail(&timer->qe, &mod->timer_q);
3008}
3009
Jing Huang5fbe25c2010-10-18 17:17:23 -07003010/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003011 * Should be called with lock protection
3012 */
3013void
3014bfa_timer_stop(struct bfa_timer_s *timer)
3015{
Jing Huangd4b671c2010-12-26 21:46:35 -08003016 WARN_ON(list_empty(&timer->qe));
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07003017
3018 list_del(&timer->qe);
3019}
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003020
3021/*
3022 * ASIC block related
3023 */
3024static void
3025bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg)
3026{
3027 struct bfa_ablk_cfg_inst_s *cfg_inst;
3028 int i, j;
3029 u16 be16;
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003030
3031 for (i = 0; i < BFA_ABLK_MAX; i++) {
3032 cfg_inst = &cfg->inst[i];
3033 for (j = 0; j < BFA_ABLK_MAX_PFS; j++) {
3034 be16 = cfg_inst->pf_cfg[j].pers;
3035 cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16);
3036 be16 = cfg_inst->pf_cfg[j].num_qpairs;
3037 cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16);
3038 be16 = cfg_inst->pf_cfg[j].num_vectors;
3039 cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16);
Krishna Gudipati1a1297c2012-09-21 17:26:50 -07003040 be16 = cfg_inst->pf_cfg[j].bw_min;
3041 cfg_inst->pf_cfg[j].bw_min = be16_to_cpu(be16);
3042 be16 = cfg_inst->pf_cfg[j].bw_max;
3043 cfg_inst->pf_cfg[j].bw_max = be16_to_cpu(be16);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003044 }
3045 }
3046}
3047
3048static void
3049bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg)
3050{
3051 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3052 struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg;
3053 bfa_ablk_cbfn_t cbfn;
3054
3055 WARN_ON(msg->mh.msg_class != BFI_MC_ABLK);
3056 bfa_trc(ablk->ioc, msg->mh.msg_id);
3057
3058 switch (msg->mh.msg_id) {
3059 case BFI_ABLK_I2H_QUERY:
3060 if (rsp->status == BFA_STATUS_OK) {
3061 memcpy(ablk->cfg, ablk->dma_addr.kva,
3062 sizeof(struct bfa_ablk_cfg_s));
3063 bfa_ablk_config_swap(ablk->cfg);
3064 ablk->cfg = NULL;
3065 }
3066 break;
3067
3068 case BFI_ABLK_I2H_ADPT_CONFIG:
3069 case BFI_ABLK_I2H_PORT_CONFIG:
3070 /* update config port mode */
3071 ablk->ioc->port_mode_cfg = rsp->port_mode;
3072
3073 case BFI_ABLK_I2H_PF_DELETE:
3074 case BFI_ABLK_I2H_PF_UPDATE:
3075 case BFI_ABLK_I2H_OPTROM_ENABLE:
3076 case BFI_ABLK_I2H_OPTROM_DISABLE:
3077 /* No-op */
3078 break;
3079
3080 case BFI_ABLK_I2H_PF_CREATE:
3081 *(ablk->pcifn) = rsp->pcifn;
3082 ablk->pcifn = NULL;
3083 break;
3084
3085 default:
3086 WARN_ON(1);
3087 }
3088
3089 ablk->busy = BFA_FALSE;
3090 if (ablk->cbfn) {
3091 cbfn = ablk->cbfn;
3092 ablk->cbfn = NULL;
3093 cbfn(ablk->cbarg, rsp->status);
3094 }
3095}
3096
3097static void
3098bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event)
3099{
3100 struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg;
3101
3102 bfa_trc(ablk->ioc, event);
3103
3104 switch (event) {
3105 case BFA_IOC_E_ENABLED:
3106 WARN_ON(ablk->busy != BFA_FALSE);
3107 break;
3108
3109 case BFA_IOC_E_DISABLED:
3110 case BFA_IOC_E_FAILED:
3111 /* Fail any pending requests */
3112 ablk->pcifn = NULL;
3113 if (ablk->busy) {
3114 if (ablk->cbfn)
3115 ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED);
3116 ablk->cbfn = NULL;
3117 ablk->busy = BFA_FALSE;
3118 }
3119 break;
3120
3121 default:
3122 WARN_ON(1);
3123 break;
3124 }
3125}
3126
3127u32
3128bfa_ablk_meminfo(void)
3129{
3130 return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ);
3131}
3132
3133void
3134bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa)
3135{
3136 ablk->dma_addr.kva = dma_kva;
3137 ablk->dma_addr.pa = dma_pa;
3138}
3139
3140void
3141bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc)
3142{
3143 ablk->ioc = ioc;
3144
3145 bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk);
Krishna Gudipati3350d982011-06-24 20:28:37 -07003146 bfa_q_qe_init(&ablk->ioc_notify);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003147 bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk);
3148 list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q);
3149}
3150
3151bfa_status_t
3152bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg,
3153 bfa_ablk_cbfn_t cbfn, void *cbarg)
3154{
3155 struct bfi_ablk_h2i_query_s *m;
3156
3157 WARN_ON(!ablk_cfg);
3158
3159 if (!bfa_ioc_is_operational(ablk->ioc)) {
3160 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3161 return BFA_STATUS_IOC_FAILURE;
3162 }
3163
3164 if (ablk->busy) {
3165 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3166 return BFA_STATUS_DEVBUSY;
3167 }
3168
3169 ablk->cfg = ablk_cfg;
3170 ablk->cbfn = cbfn;
3171 ablk->cbarg = cbarg;
3172 ablk->busy = BFA_TRUE;
3173
3174 m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg;
3175 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY,
3176 bfa_ioc_portid(ablk->ioc));
3177 bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa);
3178 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3179
3180 return BFA_STATUS_OK;
3181}
3182
3183bfa_status_t
3184bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn,
Krishna Gudipati1a1297c2012-09-21 17:26:50 -07003185 u8 port, enum bfi_pcifn_class personality,
3186 u16 bw_min, u16 bw_max,
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003187 bfa_ablk_cbfn_t cbfn, void *cbarg)
3188{
3189 struct bfi_ablk_h2i_pf_req_s *m;
3190
3191 if (!bfa_ioc_is_operational(ablk->ioc)) {
3192 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3193 return BFA_STATUS_IOC_FAILURE;
3194 }
3195
3196 if (ablk->busy) {
3197 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3198 return BFA_STATUS_DEVBUSY;
3199 }
3200
3201 ablk->pcifn = pcifn;
3202 ablk->cbfn = cbfn;
3203 ablk->cbarg = cbarg;
3204 ablk->busy = BFA_TRUE;
3205
3206 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3207 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE,
3208 bfa_ioc_portid(ablk->ioc));
3209 m->pers = cpu_to_be16((u16)personality);
Krishna Gudipati1a1297c2012-09-21 17:26:50 -07003210 m->bw_min = cpu_to_be16(bw_min);
3211 m->bw_max = cpu_to_be16(bw_max);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003212 m->port = port;
3213 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3214
3215 return BFA_STATUS_OK;
3216}
3217
3218bfa_status_t
3219bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn,
3220 bfa_ablk_cbfn_t cbfn, void *cbarg)
3221{
3222 struct bfi_ablk_h2i_pf_req_s *m;
3223
3224 if (!bfa_ioc_is_operational(ablk->ioc)) {
3225 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3226 return BFA_STATUS_IOC_FAILURE;
3227 }
3228
3229 if (ablk->busy) {
3230 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3231 return BFA_STATUS_DEVBUSY;
3232 }
3233
3234 ablk->cbfn = cbfn;
3235 ablk->cbarg = cbarg;
3236 ablk->busy = BFA_TRUE;
3237
3238 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3239 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE,
3240 bfa_ioc_portid(ablk->ioc));
3241 m->pcifn = (u8)pcifn;
3242 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3243
3244 return BFA_STATUS_OK;
3245}
3246
3247bfa_status_t
3248bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode,
3249 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3250{
3251 struct bfi_ablk_h2i_cfg_req_s *m;
3252
3253 if (!bfa_ioc_is_operational(ablk->ioc)) {
3254 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3255 return BFA_STATUS_IOC_FAILURE;
3256 }
3257
3258 if (ablk->busy) {
3259 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3260 return BFA_STATUS_DEVBUSY;
3261 }
3262
3263 ablk->cbfn = cbfn;
3264 ablk->cbarg = cbarg;
3265 ablk->busy = BFA_TRUE;
3266
3267 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3268 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG,
3269 bfa_ioc_portid(ablk->ioc));
3270 m->mode = (u8)mode;
3271 m->max_pf = (u8)max_pf;
3272 m->max_vf = (u8)max_vf;
3273 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3274
3275 return BFA_STATUS_OK;
3276}
3277
3278bfa_status_t
3279bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode,
3280 int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg)
3281{
3282 struct bfi_ablk_h2i_cfg_req_s *m;
3283
3284 if (!bfa_ioc_is_operational(ablk->ioc)) {
3285 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3286 return BFA_STATUS_IOC_FAILURE;
3287 }
3288
3289 if (ablk->busy) {
3290 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3291 return BFA_STATUS_DEVBUSY;
3292 }
3293
3294 ablk->cbfn = cbfn;
3295 ablk->cbarg = cbarg;
3296 ablk->busy = BFA_TRUE;
3297
3298 m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg;
3299 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG,
3300 bfa_ioc_portid(ablk->ioc));
3301 m->port = (u8)port;
3302 m->mode = (u8)mode;
3303 m->max_pf = (u8)max_pf;
3304 m->max_vf = (u8)max_vf;
3305 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3306
3307 return BFA_STATUS_OK;
3308}
3309
3310bfa_status_t
Krishna Gudipati1a1297c2012-09-21 17:26:50 -07003311bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, u16 bw_min,
3312 u16 bw_max, bfa_ablk_cbfn_t cbfn, void *cbarg)
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003313{
3314 struct bfi_ablk_h2i_pf_req_s *m;
3315
3316 if (!bfa_ioc_is_operational(ablk->ioc)) {
3317 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3318 return BFA_STATUS_IOC_FAILURE;
3319 }
3320
3321 if (ablk->busy) {
3322 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3323 return BFA_STATUS_DEVBUSY;
3324 }
3325
3326 ablk->cbfn = cbfn;
3327 ablk->cbarg = cbarg;
3328 ablk->busy = BFA_TRUE;
3329
3330 m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg;
3331 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE,
3332 bfa_ioc_portid(ablk->ioc));
3333 m->pcifn = (u8)pcifn;
Krishna Gudipati1a1297c2012-09-21 17:26:50 -07003334 m->bw_min = cpu_to_be16(bw_min);
3335 m->bw_max = cpu_to_be16(bw_max);
Krishna Gudipati1a4d8e12011-06-24 20:22:28 -07003336 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3337
3338 return BFA_STATUS_OK;
3339}
3340
3341bfa_status_t
3342bfa_ablk_optrom_en(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_ENABLE,
3362 bfa_ioc_portid(ablk->ioc));
3363 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3364
3365 return BFA_STATUS_OK;
3366}
3367
3368bfa_status_t
3369bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg)
3370{
3371 struct bfi_ablk_h2i_optrom_s *m;
3372
3373 if (!bfa_ioc_is_operational(ablk->ioc)) {
3374 bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE);
3375 return BFA_STATUS_IOC_FAILURE;
3376 }
3377
3378 if (ablk->busy) {
3379 bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY);
3380 return BFA_STATUS_DEVBUSY;
3381 }
3382
3383 ablk->cbfn = cbfn;
3384 ablk->cbarg = cbarg;
3385 ablk->busy = BFA_TRUE;
3386
3387 m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg;
3388 bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE,
3389 bfa_ioc_portid(ablk->ioc));
3390 bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb);
3391
3392 return BFA_STATUS_OK;
3393}
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003394
3395/*
3396 * SFP module specific
3397 */
3398
3399/* forward declarations */
3400static void bfa_sfp_getdata_send(struct bfa_sfp_s *sfp);
3401static void bfa_sfp_media_get(struct bfa_sfp_s *sfp);
3402static bfa_status_t bfa_sfp_speed_valid(struct bfa_sfp_s *sfp,
3403 enum bfa_port_speed portspeed);
3404
3405static void
3406bfa_cb_sfp_show(struct bfa_sfp_s *sfp)
3407{
3408 bfa_trc(sfp, sfp->lock);
3409 if (sfp->cbfn)
3410 sfp->cbfn(sfp->cbarg, sfp->status);
3411 sfp->lock = 0;
3412 sfp->cbfn = NULL;
3413}
3414
3415static void
3416bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp)
3417{
3418 bfa_trc(sfp, sfp->portspeed);
3419 if (sfp->media) {
3420 bfa_sfp_media_get(sfp);
3421 if (sfp->state_query_cbfn)
3422 sfp->state_query_cbfn(sfp->state_query_cbarg,
3423 sfp->status);
3424 sfp->media = NULL;
3425 }
3426
3427 if (sfp->portspeed) {
3428 sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed);
3429 if (sfp->state_query_cbfn)
3430 sfp->state_query_cbfn(sfp->state_query_cbarg,
3431 sfp->status);
3432 sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
3433 }
3434
3435 sfp->state_query_lock = 0;
3436 sfp->state_query_cbfn = NULL;
3437}
3438
3439/*
3440 * IOC event handler.
3441 */
3442static void
3443bfa_sfp_notify(void *sfp_arg, enum bfa_ioc_event_e event)
3444{
3445 struct bfa_sfp_s *sfp = sfp_arg;
3446
3447 bfa_trc(sfp, event);
3448 bfa_trc(sfp, sfp->lock);
3449 bfa_trc(sfp, sfp->state_query_lock);
3450
3451 switch (event) {
3452 case BFA_IOC_E_DISABLED:
3453 case BFA_IOC_E_FAILED:
3454 if (sfp->lock) {
3455 sfp->status = BFA_STATUS_IOC_FAILURE;
3456 bfa_cb_sfp_show(sfp);
3457 }
3458
3459 if (sfp->state_query_lock) {
3460 sfp->status = BFA_STATUS_IOC_FAILURE;
3461 bfa_cb_sfp_state_query(sfp);
3462 }
3463 break;
3464
3465 default:
3466 break;
3467 }
3468}
3469
3470/*
Krishna Gudipati7826f302011-07-20 16:59:13 -07003471 * SFP's State Change Notification post to AEN
3472 */
3473static void
3474bfa_sfp_scn_aen_post(struct bfa_sfp_s *sfp, struct bfi_sfp_scn_s *rsp)
3475{
3476 struct bfad_s *bfad = (struct bfad_s *)sfp->ioc->bfa->bfad;
3477 struct bfa_aen_entry_s *aen_entry;
3478 enum bfa_port_aen_event aen_evt = 0;
3479
3480 bfa_trc(sfp, (((u64)rsp->pomlvl) << 16) | (((u64)rsp->sfpid) << 8) |
3481 ((u64)rsp->event));
3482
3483 bfad_get_aen_entry(bfad, aen_entry);
3484 if (!aen_entry)
3485 return;
3486
3487 aen_entry->aen_data.port.ioc_type = bfa_ioc_get_type(sfp->ioc);
3488 aen_entry->aen_data.port.pwwn = sfp->ioc->attr->pwwn;
3489 aen_entry->aen_data.port.mac = bfa_ioc_get_mac(sfp->ioc);
3490
3491 switch (rsp->event) {
3492 case BFA_SFP_SCN_INSERTED:
3493 aen_evt = BFA_PORT_AEN_SFP_INSERT;
3494 break;
3495 case BFA_SFP_SCN_REMOVED:
3496 aen_evt = BFA_PORT_AEN_SFP_REMOVE;
3497 break;
3498 case BFA_SFP_SCN_FAILED:
3499 aen_evt = BFA_PORT_AEN_SFP_ACCESS_ERROR;
3500 break;
3501 case BFA_SFP_SCN_UNSUPPORT:
3502 aen_evt = BFA_PORT_AEN_SFP_UNSUPPORT;
3503 break;
3504 case BFA_SFP_SCN_POM:
3505 aen_evt = BFA_PORT_AEN_SFP_POM;
3506 aen_entry->aen_data.port.level = rsp->pomlvl;
3507 break;
3508 default:
3509 bfa_trc(sfp, rsp->event);
3510 WARN_ON(1);
3511 }
3512
3513 /* Send the AEN notification */
3514 bfad_im_post_vendor_event(aen_entry, bfad, ++sfp->ioc->ioc_aen_seq,
3515 BFA_AEN_CAT_PORT, aen_evt);
3516}
3517
3518/*
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003519 * SFP get data send
3520 */
3521static void
3522bfa_sfp_getdata_send(struct bfa_sfp_s *sfp)
3523{
3524 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3525
3526 bfa_trc(sfp, req->memtype);
3527
3528 /* build host command */
3529 bfi_h2i_set(req->mh, BFI_MC_SFP, BFI_SFP_H2I_SHOW,
3530 bfa_ioc_portid(sfp->ioc));
3531
3532 /* send mbox cmd */
3533 bfa_ioc_mbox_queue(sfp->ioc, &sfp->mbcmd);
3534}
3535
3536/*
3537 * SFP is valid, read sfp data
3538 */
3539static void
3540bfa_sfp_getdata(struct bfa_sfp_s *sfp, enum bfi_sfp_mem_e memtype)
3541{
3542 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3543
3544 WARN_ON(sfp->lock != 0);
3545 bfa_trc(sfp, sfp->state);
3546
3547 sfp->lock = 1;
3548 sfp->memtype = memtype;
3549 req->memtype = memtype;
3550
3551 /* Setup SG list */
3552 bfa_alen_set(&req->alen, sizeof(struct sfp_mem_s), sfp->dbuf_pa);
3553
3554 bfa_sfp_getdata_send(sfp);
3555}
3556
3557/*
Krishna Gudipati7826f302011-07-20 16:59:13 -07003558 * SFP scn handler
3559 */
3560static void
3561bfa_sfp_scn(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
3562{
3563 struct bfi_sfp_scn_s *rsp = (struct bfi_sfp_scn_s *) msg;
3564
3565 switch (rsp->event) {
3566 case BFA_SFP_SCN_INSERTED:
3567 sfp->state = BFA_SFP_STATE_INSERTED;
3568 sfp->data_valid = 0;
3569 bfa_sfp_scn_aen_post(sfp, rsp);
3570 break;
3571 case BFA_SFP_SCN_REMOVED:
3572 sfp->state = BFA_SFP_STATE_REMOVED;
3573 sfp->data_valid = 0;
3574 bfa_sfp_scn_aen_post(sfp, rsp);
3575 break;
3576 case BFA_SFP_SCN_FAILED:
3577 sfp->state = BFA_SFP_STATE_FAILED;
3578 sfp->data_valid = 0;
3579 bfa_sfp_scn_aen_post(sfp, rsp);
3580 break;
3581 case BFA_SFP_SCN_UNSUPPORT:
3582 sfp->state = BFA_SFP_STATE_UNSUPPORT;
3583 bfa_sfp_scn_aen_post(sfp, rsp);
3584 if (!sfp->lock)
3585 bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
3586 break;
3587 case BFA_SFP_SCN_POM:
3588 bfa_sfp_scn_aen_post(sfp, rsp);
3589 break;
3590 case BFA_SFP_SCN_VALID:
3591 sfp->state = BFA_SFP_STATE_VALID;
3592 if (!sfp->lock)
3593 bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
3594 break;
3595 default:
3596 bfa_trc(sfp, rsp->event);
3597 WARN_ON(1);
3598 }
3599}
3600
3601/*
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003602 * SFP show complete
3603 */
3604static void
3605bfa_sfp_show_comp(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg)
3606{
3607 struct bfi_sfp_rsp_s *rsp = (struct bfi_sfp_rsp_s *) msg;
3608
3609 if (!sfp->lock) {
3610 /*
3611 * receiving response after ioc failure
3612 */
3613 bfa_trc(sfp, sfp->lock);
3614 return;
3615 }
3616
3617 bfa_trc(sfp, rsp->status);
3618 if (rsp->status == BFA_STATUS_OK) {
3619 sfp->data_valid = 1;
3620 if (sfp->state == BFA_SFP_STATE_VALID)
3621 sfp->status = BFA_STATUS_OK;
3622 else if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
3623 sfp->status = BFA_STATUS_SFP_UNSUPP;
3624 else
3625 bfa_trc(sfp, sfp->state);
3626 } else {
3627 sfp->data_valid = 0;
3628 sfp->status = rsp->status;
3629 /* sfpshow shouldn't change sfp state */
3630 }
3631
3632 bfa_trc(sfp, sfp->memtype);
3633 if (sfp->memtype == BFI_SFP_MEM_DIAGEXT) {
3634 bfa_trc(sfp, sfp->data_valid);
3635 if (sfp->data_valid) {
3636 u32 size = sizeof(struct sfp_mem_s);
3637 u8 *des = (u8 *) &(sfp->sfpmem->srlid_base);
3638 memcpy(des, sfp->dbuf_kva, size);
3639 }
3640 /*
3641 * Queue completion callback.
3642 */
3643 bfa_cb_sfp_show(sfp);
3644 } else
3645 sfp->lock = 0;
3646
3647 bfa_trc(sfp, sfp->state_query_lock);
3648 if (sfp->state_query_lock) {
3649 sfp->state = rsp->state;
3650 /* Complete callback */
3651 bfa_cb_sfp_state_query(sfp);
3652 }
3653}
3654
3655/*
3656 * SFP query fw sfp state
3657 */
3658static void
3659bfa_sfp_state_query(struct bfa_sfp_s *sfp)
3660{
3661 struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg;
3662
3663 /* Should not be doing query if not in _INIT state */
3664 WARN_ON(sfp->state != BFA_SFP_STATE_INIT);
3665 WARN_ON(sfp->state_query_lock != 0);
3666 bfa_trc(sfp, sfp->state);
3667
3668 sfp->state_query_lock = 1;
3669 req->memtype = 0;
3670
3671 if (!sfp->lock)
3672 bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL);
3673}
3674
3675static void
3676bfa_sfp_media_get(struct bfa_sfp_s *sfp)
3677{
3678 enum bfa_defs_sfp_media_e *media = sfp->media;
3679
3680 *media = BFA_SFP_MEDIA_UNKNOWN;
3681
3682 if (sfp->state == BFA_SFP_STATE_UNSUPPORT)
3683 *media = BFA_SFP_MEDIA_UNSUPPORT;
3684 else if (sfp->state == BFA_SFP_STATE_VALID) {
3685 union sfp_xcvr_e10g_code_u e10g;
3686 struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
3687 u16 xmtr_tech = (sfpmem->srlid_base.xcvr[4] & 0x3) << 7 |
3688 (sfpmem->srlid_base.xcvr[5] >> 1);
3689
3690 e10g.b = sfpmem->srlid_base.xcvr[0];
3691 bfa_trc(sfp, e10g.b);
3692 bfa_trc(sfp, xmtr_tech);
3693 /* check fc transmitter tech */
3694 if ((xmtr_tech & SFP_XMTR_TECH_CU) ||
3695 (xmtr_tech & SFP_XMTR_TECH_CP) ||
3696 (xmtr_tech & SFP_XMTR_TECH_CA))
3697 *media = BFA_SFP_MEDIA_CU;
3698 else if ((xmtr_tech & SFP_XMTR_TECH_EL_INTRA) ||
3699 (xmtr_tech & SFP_XMTR_TECH_EL_INTER))
3700 *media = BFA_SFP_MEDIA_EL;
3701 else if ((xmtr_tech & SFP_XMTR_TECH_LL) ||
3702 (xmtr_tech & SFP_XMTR_TECH_LC))
3703 *media = BFA_SFP_MEDIA_LW;
3704 else if ((xmtr_tech & SFP_XMTR_TECH_SL) ||
3705 (xmtr_tech & SFP_XMTR_TECH_SN) ||
3706 (xmtr_tech & SFP_XMTR_TECH_SA))
3707 *media = BFA_SFP_MEDIA_SW;
3708 /* Check 10G Ethernet Compilance code */
Jing Huang98cdfb42011-11-16 12:29:26 -08003709 else if (e10g.r.e10g_sr)
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003710 *media = BFA_SFP_MEDIA_SW;
Jing Huang98cdfb42011-11-16 12:29:26 -08003711 else if (e10g.r.e10g_lrm && e10g.r.e10g_lr)
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003712 *media = BFA_SFP_MEDIA_LW;
Jing Huang98cdfb42011-11-16 12:29:26 -08003713 else if (e10g.r.e10g_unall)
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003714 *media = BFA_SFP_MEDIA_UNKNOWN;
3715 else
3716 bfa_trc(sfp, 0);
3717 } else
3718 bfa_trc(sfp, sfp->state);
3719}
3720
3721static bfa_status_t
3722bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed)
3723{
3724 struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva;
3725 struct sfp_xcvr_s *xcvr = (struct sfp_xcvr_s *) sfpmem->srlid_base.xcvr;
3726 union sfp_xcvr_fc3_code_u fc3 = xcvr->fc3;
3727 union sfp_xcvr_e10g_code_u e10g = xcvr->e10g;
3728
3729 if (portspeed == BFA_PORT_SPEED_10GBPS) {
3730 if (e10g.r.e10g_sr || e10g.r.e10g_lr)
3731 return BFA_STATUS_OK;
3732 else {
3733 bfa_trc(sfp, e10g.b);
3734 return BFA_STATUS_UNSUPP_SPEED;
3735 }
3736 }
3737 if (((portspeed & BFA_PORT_SPEED_16GBPS) && fc3.r.mb1600) ||
3738 ((portspeed & BFA_PORT_SPEED_8GBPS) && fc3.r.mb800) ||
3739 ((portspeed & BFA_PORT_SPEED_4GBPS) && fc3.r.mb400) ||
3740 ((portspeed & BFA_PORT_SPEED_2GBPS) && fc3.r.mb200) ||
3741 ((portspeed & BFA_PORT_SPEED_1GBPS) && fc3.r.mb100))
3742 return BFA_STATUS_OK;
3743 else {
3744 bfa_trc(sfp, portspeed);
3745 bfa_trc(sfp, fc3.b);
3746 bfa_trc(sfp, e10g.b);
3747 return BFA_STATUS_UNSUPP_SPEED;
3748 }
3749}
3750
3751/*
3752 * SFP hmbox handler
3753 */
3754void
3755bfa_sfp_intr(void *sfparg, struct bfi_mbmsg_s *msg)
3756{
3757 struct bfa_sfp_s *sfp = sfparg;
3758
3759 switch (msg->mh.msg_id) {
3760 case BFI_SFP_I2H_SHOW:
3761 bfa_sfp_show_comp(sfp, msg);
3762 break;
3763
3764 case BFI_SFP_I2H_SCN:
Krishna Gudipati7826f302011-07-20 16:59:13 -07003765 bfa_sfp_scn(sfp, msg);
Krishna Gudipati51e569a2011-06-24 20:26:25 -07003766 break;
3767
3768 default:
3769 bfa_trc(sfp, msg->mh.msg_id);
3770 WARN_ON(1);
3771 }
3772}
3773
3774/*
3775 * Return DMA memory needed by sfp module.
3776 */
3777u32
3778bfa_sfp_meminfo(void)
3779{
3780 return BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3781}
3782
3783/*
3784 * Attach virtual and physical memory for SFP.
3785 */
3786void
3787bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc, void *dev,
3788 struct bfa_trc_mod_s *trcmod)
3789{
3790 sfp->dev = dev;
3791 sfp->ioc = ioc;
3792 sfp->trcmod = trcmod;
3793
3794 sfp->cbfn = NULL;
3795 sfp->cbarg = NULL;
3796 sfp->sfpmem = NULL;
3797 sfp->lock = 0;
3798 sfp->data_valid = 0;
3799 sfp->state = BFA_SFP_STATE_INIT;
3800 sfp->state_query_lock = 0;
3801 sfp->state_query_cbfn = NULL;
3802 sfp->state_query_cbarg = NULL;
3803 sfp->media = NULL;
3804 sfp->portspeed = BFA_PORT_SPEED_UNKNOWN;
3805 sfp->is_elb = BFA_FALSE;
3806
3807 bfa_ioc_mbox_regisr(sfp->ioc, BFI_MC_SFP, bfa_sfp_intr, sfp);
3808 bfa_q_qe_init(&sfp->ioc_notify);
3809 bfa_ioc_notify_init(&sfp->ioc_notify, bfa_sfp_notify, sfp);
3810 list_add_tail(&sfp->ioc_notify.qe, &sfp->ioc->notify_q);
3811}
3812
3813/*
3814 * Claim Memory for SFP
3815 */
3816void
3817bfa_sfp_memclaim(struct bfa_sfp_s *sfp, u8 *dm_kva, u64 dm_pa)
3818{
3819 sfp->dbuf_kva = dm_kva;
3820 sfp->dbuf_pa = dm_pa;
3821 memset(sfp->dbuf_kva, 0, sizeof(struct sfp_mem_s));
3822
3823 dm_kva += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3824 dm_pa += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ);
3825}
3826
3827/*
3828 * Show SFP eeprom content
3829 *
3830 * @param[in] sfp - bfa sfp module
3831 *
3832 * @param[out] sfpmem - sfp eeprom data
3833 *
3834 */
3835bfa_status_t
3836bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem,
3837 bfa_cb_sfp_t cbfn, void *cbarg)
3838{
3839
3840 if (!bfa_ioc_is_operational(sfp->ioc)) {
3841 bfa_trc(sfp, 0);
3842 return BFA_STATUS_IOC_NON_OP;
3843 }
3844
3845 if (sfp->lock) {
3846 bfa_trc(sfp, 0);
3847 return BFA_STATUS_DEVBUSY;
3848 }
3849
3850 sfp->cbfn = cbfn;
3851 sfp->cbarg = cbarg;
3852 sfp->sfpmem = sfpmem;
3853
3854 bfa_sfp_getdata(sfp, BFI_SFP_MEM_DIAGEXT);
3855 return BFA_STATUS_OK;
3856}
3857
3858/*
3859 * Return SFP Media type
3860 *
3861 * @param[in] sfp - bfa sfp module
3862 *
3863 * @param[out] media - port speed from user
3864 *
3865 */
3866bfa_status_t
3867bfa_sfp_media(struct bfa_sfp_s *sfp, enum bfa_defs_sfp_media_e *media,
3868 bfa_cb_sfp_t cbfn, void *cbarg)
3869{
3870 if (!bfa_ioc_is_operational(sfp->ioc)) {
3871 bfa_trc(sfp, 0);
3872 return BFA_STATUS_IOC_NON_OP;
3873 }
3874
3875 sfp->media = media;
3876 if (sfp->state == BFA_SFP_STATE_INIT) {
3877 if (sfp->state_query_lock) {
3878 bfa_trc(sfp, 0);
3879 return BFA_STATUS_DEVBUSY;
3880 } else {
3881 sfp->state_query_cbfn = cbfn;
3882 sfp->state_query_cbarg = cbarg;
3883 bfa_sfp_state_query(sfp);
3884 return BFA_STATUS_SFP_NOT_READY;
3885 }
3886 }
3887
3888 bfa_sfp_media_get(sfp);
3889 return BFA_STATUS_OK;
3890}
3891
3892/*
3893 * Check if user set port speed is allowed by the SFP
3894 *
3895 * @param[in] sfp - bfa sfp module
3896 * @param[in] portspeed - port speed from user
3897 *
3898 */
3899bfa_status_t
3900bfa_sfp_speed(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed,
3901 bfa_cb_sfp_t cbfn, void *cbarg)
3902{
3903 WARN_ON(portspeed == BFA_PORT_SPEED_UNKNOWN);
3904
3905 if (!bfa_ioc_is_operational(sfp->ioc))
3906 return BFA_STATUS_IOC_NON_OP;
3907
3908 /* For Mezz card, all speed is allowed */
3909 if (bfa_mfg_is_mezz(sfp->ioc->attr->card_type))
3910 return BFA_STATUS_OK;
3911
3912 /* Check SFP state */
3913 sfp->portspeed = portspeed;
3914 if (sfp->state == BFA_SFP_STATE_INIT) {
3915 if (sfp->state_query_lock) {
3916 bfa_trc(sfp, 0);
3917 return BFA_STATUS_DEVBUSY;
3918 } else {
3919 sfp->state_query_cbfn = cbfn;
3920 sfp->state_query_cbarg = cbarg;
3921 bfa_sfp_state_query(sfp);
3922 return BFA_STATUS_SFP_NOT_READY;
3923 }
3924 }
3925
3926 if (sfp->state == BFA_SFP_STATE_REMOVED ||
3927 sfp->state == BFA_SFP_STATE_FAILED) {
3928 bfa_trc(sfp, sfp->state);
3929 return BFA_STATUS_NO_SFP_DEV;
3930 }
3931
3932 if (sfp->state == BFA_SFP_STATE_INSERTED) {
3933 bfa_trc(sfp, sfp->state);
3934 return BFA_STATUS_DEVBUSY; /* sfp is reading data */
3935 }
3936
3937 /* For eloopback, all speed is allowed */
3938 if (sfp->is_elb)
3939 return BFA_STATUS_OK;
3940
3941 return bfa_sfp_speed_valid(sfp, portspeed);
3942}
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07003943
3944/*
3945 * Flash module specific
3946 */
3947
3948/*
3949 * FLASH DMA buffer should be big enough to hold both MFG block and
3950 * asic block(64k) at the same time and also should be 2k aligned to
3951 * avoid write segement to cross sector boundary.
3952 */
3953#define BFA_FLASH_SEG_SZ 2048
3954#define BFA_FLASH_DMA_BUF_SZ \
3955 BFA_ROUNDUP(0x010000 + sizeof(struct bfa_mfg_block_s), BFA_FLASH_SEG_SZ)
3956
3957static void
Krishna Gudipati7826f302011-07-20 16:59:13 -07003958bfa_flash_aen_audit_post(struct bfa_ioc_s *ioc, enum bfa_audit_aen_event event,
3959 int inst, int type)
3960{
3961 struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad;
3962 struct bfa_aen_entry_s *aen_entry;
3963
3964 bfad_get_aen_entry(bfad, aen_entry);
3965 if (!aen_entry)
3966 return;
3967
3968 aen_entry->aen_data.audit.pwwn = ioc->attr->pwwn;
3969 aen_entry->aen_data.audit.partition_inst = inst;
3970 aen_entry->aen_data.audit.partition_type = type;
3971
3972 /* Send the AEN notification */
3973 bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq,
3974 BFA_AEN_CAT_AUDIT, event);
3975}
3976
3977static void
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07003978bfa_flash_cb(struct bfa_flash_s *flash)
3979{
3980 flash->op_busy = 0;
3981 if (flash->cbfn)
3982 flash->cbfn(flash->cbarg, flash->status);
3983}
3984
3985static void
3986bfa_flash_notify(void *cbarg, enum bfa_ioc_event_e event)
3987{
3988 struct bfa_flash_s *flash = cbarg;
3989
3990 bfa_trc(flash, event);
3991 switch (event) {
3992 case BFA_IOC_E_DISABLED:
3993 case BFA_IOC_E_FAILED:
3994 if (flash->op_busy) {
3995 flash->status = BFA_STATUS_IOC_FAILURE;
3996 flash->cbfn(flash->cbarg, flash->status);
3997 flash->op_busy = 0;
3998 }
3999 break;
4000
4001 default:
4002 break;
4003 }
4004}
4005
4006/*
4007 * Send flash attribute query request.
4008 *
4009 * @param[in] cbarg - callback argument
4010 */
4011static void
4012bfa_flash_query_send(void *cbarg)
4013{
4014 struct bfa_flash_s *flash = cbarg;
4015 struct bfi_flash_query_req_s *msg =
4016 (struct bfi_flash_query_req_s *) flash->mb.msg;
4017
4018 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ,
4019 bfa_ioc_portid(flash->ioc));
4020 bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr_s),
4021 flash->dbuf_pa);
4022 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4023}
4024
4025/*
4026 * Send flash write request.
4027 *
4028 * @param[in] cbarg - callback argument
4029 */
4030static void
4031bfa_flash_write_send(struct bfa_flash_s *flash)
4032{
4033 struct bfi_flash_write_req_s *msg =
4034 (struct bfi_flash_write_req_s *) flash->mb.msg;
4035 u32 len;
4036
4037 msg->type = be32_to_cpu(flash->type);
4038 msg->instance = flash->instance;
4039 msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
4040 len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
4041 flash->residue : BFA_FLASH_DMA_BUF_SZ;
4042 msg->length = be32_to_cpu(len);
4043
4044 /* indicate if it's the last msg of the whole write operation */
4045 msg->last = (len == flash->residue) ? 1 : 0;
4046
4047 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ,
4048 bfa_ioc_portid(flash->ioc));
4049 bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
4050 memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len);
4051 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4052
4053 flash->residue -= len;
4054 flash->offset += len;
4055}
4056
4057/*
4058 * Send flash read request.
4059 *
4060 * @param[in] cbarg - callback argument
4061 */
4062static void
4063bfa_flash_read_send(void *cbarg)
4064{
4065 struct bfa_flash_s *flash = cbarg;
4066 struct bfi_flash_read_req_s *msg =
4067 (struct bfi_flash_read_req_s *) flash->mb.msg;
4068 u32 len;
4069
4070 msg->type = be32_to_cpu(flash->type);
4071 msg->instance = flash->instance;
4072 msg->offset = be32_to_cpu(flash->addr_off + flash->offset);
4073 len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ?
4074 flash->residue : BFA_FLASH_DMA_BUF_SZ;
4075 msg->length = be32_to_cpu(len);
4076 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ,
4077 bfa_ioc_portid(flash->ioc));
4078 bfa_alen_set(&msg->alen, len, flash->dbuf_pa);
4079 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4080}
4081
4082/*
4083 * Send flash erase request.
4084 *
4085 * @param[in] cbarg - callback argument
4086 */
4087static void
4088bfa_flash_erase_send(void *cbarg)
4089{
4090 struct bfa_flash_s *flash = cbarg;
4091 struct bfi_flash_erase_req_s *msg =
4092 (struct bfi_flash_erase_req_s *) flash->mb.msg;
4093
4094 msg->type = be32_to_cpu(flash->type);
4095 msg->instance = flash->instance;
4096 bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_ERASE_REQ,
4097 bfa_ioc_portid(flash->ioc));
4098 bfa_ioc_mbox_queue(flash->ioc, &flash->mb);
4099}
4100
4101/*
4102 * Process flash response messages upon receiving interrupts.
4103 *
4104 * @param[in] flasharg - flash structure
4105 * @param[in] msg - message structure
4106 */
4107static void
4108bfa_flash_intr(void *flasharg, struct bfi_mbmsg_s *msg)
4109{
4110 struct bfa_flash_s *flash = flasharg;
4111 u32 status;
4112
4113 union {
4114 struct bfi_flash_query_rsp_s *query;
4115 struct bfi_flash_erase_rsp_s *erase;
4116 struct bfi_flash_write_rsp_s *write;
4117 struct bfi_flash_read_rsp_s *read;
Krishna Gudipati7826f302011-07-20 16:59:13 -07004118 struct bfi_flash_event_s *event;
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07004119 struct bfi_mbmsg_s *msg;
4120 } m;
4121
4122 m.msg = msg;
4123 bfa_trc(flash, msg->mh.msg_id);
4124
4125 if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT) {
4126 /* receiving response after ioc failure */
4127 bfa_trc(flash, 0x9999);
4128 return;
4129 }
4130
4131 switch (msg->mh.msg_id) {
4132 case BFI_FLASH_I2H_QUERY_RSP:
4133 status = be32_to_cpu(m.query->status);
4134 bfa_trc(flash, status);
4135 if (status == BFA_STATUS_OK) {
4136 u32 i;
4137 struct bfa_flash_attr_s *attr, *f;
4138
4139 attr = (struct bfa_flash_attr_s *) flash->ubuf;
4140 f = (struct bfa_flash_attr_s *) flash->dbuf_kva;
4141 attr->status = be32_to_cpu(f->status);
4142 attr->npart = be32_to_cpu(f->npart);
4143 bfa_trc(flash, attr->status);
4144 bfa_trc(flash, attr->npart);
4145 for (i = 0; i < attr->npart; i++) {
4146 attr->part[i].part_type =
4147 be32_to_cpu(f->part[i].part_type);
4148 attr->part[i].part_instance =
4149 be32_to_cpu(f->part[i].part_instance);
4150 attr->part[i].part_off =
4151 be32_to_cpu(f->part[i].part_off);
4152 attr->part[i].part_size =
4153 be32_to_cpu(f->part[i].part_size);
4154 attr->part[i].part_len =
4155 be32_to_cpu(f->part[i].part_len);
4156 attr->part[i].part_status =
4157 be32_to_cpu(f->part[i].part_status);
4158 }
4159 }
4160 flash->status = status;
4161 bfa_flash_cb(flash);
4162 break;
4163 case BFI_FLASH_I2H_ERASE_RSP:
4164 status = be32_to_cpu(m.erase->status);
4165 bfa_trc(flash, status);
4166 flash->status = status;
4167 bfa_flash_cb(flash);
4168 break;
4169 case BFI_FLASH_I2H_WRITE_RSP:
4170 status = be32_to_cpu(m.write->status);
4171 bfa_trc(flash, status);
4172 if (status != BFA_STATUS_OK || flash->residue == 0) {
4173 flash->status = status;
4174 bfa_flash_cb(flash);
4175 } else {
4176 bfa_trc(flash, flash->offset);
4177 bfa_flash_write_send(flash);
4178 }
4179 break;
4180 case BFI_FLASH_I2H_READ_RSP:
4181 status = be32_to_cpu(m.read->status);
4182 bfa_trc(flash, status);
4183 if (status != BFA_STATUS_OK) {
4184 flash->status = status;
4185 bfa_flash_cb(flash);
4186 } else {
4187 u32 len = be32_to_cpu(m.read->length);
4188 bfa_trc(flash, flash->offset);
4189 bfa_trc(flash, len);
4190 memcpy(flash->ubuf + flash->offset,
4191 flash->dbuf_kva, len);
4192 flash->residue -= len;
4193 flash->offset += len;
4194 if (flash->residue == 0) {
4195 flash->status = status;
4196 bfa_flash_cb(flash);
4197 } else
4198 bfa_flash_read_send(flash);
4199 }
4200 break;
4201 case BFI_FLASH_I2H_BOOT_VER_RSP:
Krishna Gudipati7826f302011-07-20 16:59:13 -07004202 break;
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07004203 case BFI_FLASH_I2H_EVENT:
Krishna Gudipati7826f302011-07-20 16:59:13 -07004204 status = be32_to_cpu(m.event->status);
4205 bfa_trc(flash, status);
4206 if (status == BFA_STATUS_BAD_FWCFG)
4207 bfa_ioc_aen_post(flash->ioc, BFA_IOC_AEN_FWCFG_ERROR);
4208 else if (status == BFA_STATUS_INVALID_VENDOR) {
4209 u32 param;
4210 param = be32_to_cpu(m.event->param);
4211 bfa_trc(flash, param);
4212 bfa_ioc_aen_post(flash->ioc,
4213 BFA_IOC_AEN_INVALID_VENDOR);
4214 }
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07004215 break;
4216
4217 default:
4218 WARN_ON(1);
4219 }
4220}
4221
4222/*
4223 * Flash memory info API.
4224 *
4225 * @param[in] mincfg - minimal cfg variable
4226 */
4227u32
4228bfa_flash_meminfo(bfa_boolean_t mincfg)
4229{
4230 /* min driver doesn't need flash */
4231 if (mincfg)
4232 return 0;
4233 return BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
4234}
4235
4236/*
4237 * Flash attach API.
4238 *
4239 * @param[in] flash - flash structure
4240 * @param[in] ioc - ioc structure
4241 * @param[in] dev - device structure
4242 * @param[in] trcmod - trace module
4243 * @param[in] logmod - log module
4244 */
4245void
4246bfa_flash_attach(struct bfa_flash_s *flash, struct bfa_ioc_s *ioc, void *dev,
4247 struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
4248{
4249 flash->ioc = ioc;
4250 flash->trcmod = trcmod;
4251 flash->cbfn = NULL;
4252 flash->cbarg = NULL;
4253 flash->op_busy = 0;
4254
4255 bfa_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash);
4256 bfa_q_qe_init(&flash->ioc_notify);
4257 bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash);
4258 list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q);
4259
4260 /* min driver doesn't need flash */
4261 if (mincfg) {
4262 flash->dbuf_kva = NULL;
4263 flash->dbuf_pa = 0;
4264 }
4265}
4266
4267/*
4268 * Claim memory for flash
4269 *
4270 * @param[in] flash - flash structure
4271 * @param[in] dm_kva - pointer to virtual memory address
4272 * @param[in] dm_pa - physical memory address
4273 * @param[in] mincfg - minimal cfg variable
4274 */
4275void
4276bfa_flash_memclaim(struct bfa_flash_s *flash, u8 *dm_kva, u64 dm_pa,
4277 bfa_boolean_t mincfg)
4278{
4279 if (mincfg)
4280 return;
4281
4282 flash->dbuf_kva = dm_kva;
4283 flash->dbuf_pa = dm_pa;
4284 memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ);
4285 dm_kva += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
4286 dm_pa += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
4287}
4288
4289/*
4290 * Get flash attribute.
4291 *
4292 * @param[in] flash - flash structure
4293 * @param[in] attr - flash attribute structure
4294 * @param[in] cbfn - callback function
4295 * @param[in] cbarg - callback argument
4296 *
4297 * Return status.
4298 */
4299bfa_status_t
4300bfa_flash_get_attr(struct bfa_flash_s *flash, struct bfa_flash_attr_s *attr,
4301 bfa_cb_flash_t cbfn, void *cbarg)
4302{
4303 bfa_trc(flash, BFI_FLASH_H2I_QUERY_REQ);
4304
4305 if (!bfa_ioc_is_operational(flash->ioc))
4306 return BFA_STATUS_IOC_NON_OP;
4307
4308 if (flash->op_busy) {
4309 bfa_trc(flash, flash->op_busy);
4310 return BFA_STATUS_DEVBUSY;
4311 }
4312
4313 flash->op_busy = 1;
4314 flash->cbfn = cbfn;
4315 flash->cbarg = cbarg;
4316 flash->ubuf = (u8 *) attr;
4317 bfa_flash_query_send(flash);
4318
4319 return BFA_STATUS_OK;
4320}
4321
4322/*
4323 * Erase flash partition.
4324 *
4325 * @param[in] flash - flash structure
4326 * @param[in] type - flash partition type
4327 * @param[in] instance - flash partition instance
4328 * @param[in] cbfn - callback function
4329 * @param[in] cbarg - callback argument
4330 *
4331 * Return status.
4332 */
4333bfa_status_t
4334bfa_flash_erase_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
4335 u8 instance, bfa_cb_flash_t cbfn, void *cbarg)
4336{
4337 bfa_trc(flash, BFI_FLASH_H2I_ERASE_REQ);
4338 bfa_trc(flash, type);
4339 bfa_trc(flash, instance);
4340
4341 if (!bfa_ioc_is_operational(flash->ioc))
4342 return BFA_STATUS_IOC_NON_OP;
4343
4344 if (flash->op_busy) {
4345 bfa_trc(flash, flash->op_busy);
4346 return BFA_STATUS_DEVBUSY;
4347 }
4348
4349 flash->op_busy = 1;
4350 flash->cbfn = cbfn;
4351 flash->cbarg = cbarg;
4352 flash->type = type;
4353 flash->instance = instance;
4354
4355 bfa_flash_erase_send(flash);
Krishna Gudipati7826f302011-07-20 16:59:13 -07004356 bfa_flash_aen_audit_post(flash->ioc, BFA_AUDIT_AEN_FLASH_ERASE,
4357 instance, type);
Krishna Gudipati5a54b1d2011-06-24 20:27:13 -07004358 return BFA_STATUS_OK;
4359}
4360
4361/*
4362 * Update flash partition.
4363 *
4364 * @param[in] flash - flash structure
4365 * @param[in] type - flash partition type
4366 * @param[in] instance - flash partition instance
4367 * @param[in] buf - update data buffer
4368 * @param[in] len - data buffer length
4369 * @param[in] offset - offset relative to the partition starting address
4370 * @param[in] cbfn - callback function
4371 * @param[in] cbarg - callback argument
4372 *
4373 * Return status.
4374 */
4375bfa_status_t
4376bfa_flash_update_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
4377 u8 instance, void *buf, u32 len, u32 offset,
4378 bfa_cb_flash_t cbfn, void *cbarg)
4379{
4380 bfa_trc(flash, BFI_FLASH_H2I_WRITE_REQ);
4381 bfa_trc(flash, type);
4382 bfa_trc(flash, instance);
4383 bfa_trc(flash, len);
4384 bfa_trc(flash, offset);
4385
4386 if (!bfa_ioc_is_operational(flash->ioc))
4387 return BFA_STATUS_IOC_NON_OP;
4388
4389 /*
4390 * 'len' must be in word (4-byte) boundary
4391 * 'offset' must be in sector (16kb) boundary
4392 */
4393 if (!len || (len & 0x03) || (offset & 0x00003FFF))
4394 return BFA_STATUS_FLASH_BAD_LEN;
4395
4396 if (type == BFA_FLASH_PART_MFG)
4397 return BFA_STATUS_EINVAL;
4398
4399 if (flash->op_busy) {
4400 bfa_trc(flash, flash->op_busy);
4401 return BFA_STATUS_DEVBUSY;
4402 }
4403
4404 flash->op_busy = 1;
4405 flash->cbfn = cbfn;
4406 flash->cbarg = cbarg;
4407 flash->type = type;
4408 flash->instance = instance;
4409 flash->residue = len;
4410 flash->offset = 0;
4411 flash->addr_off = offset;
4412 flash->ubuf = buf;
4413
4414 bfa_flash_write_send(flash);
4415 return BFA_STATUS_OK;
4416}
4417
4418/*
4419 * Read flash partition.
4420 *
4421 * @param[in] flash - flash structure
4422 * @param[in] type - flash partition type
4423 * @param[in] instance - flash partition instance
4424 * @param[in] buf - read data buffer
4425 * @param[in] len - data buffer length
4426 * @param[in] offset - offset relative to the partition starting address
4427 * @param[in] cbfn - callback function
4428 * @param[in] cbarg - callback argument
4429 *
4430 * Return status.
4431 */
4432bfa_status_t
4433bfa_flash_read_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type,
4434 u8 instance, void *buf, u32 len, u32 offset,
4435 bfa_cb_flash_t cbfn, void *cbarg)
4436{
4437 bfa_trc(flash, BFI_FLASH_H2I_READ_REQ);
4438 bfa_trc(flash, type);
4439 bfa_trc(flash, instance);
4440 bfa_trc(flash, len);
4441 bfa_trc(flash, offset);
4442
4443 if (!bfa_ioc_is_operational(flash->ioc))
4444 return BFA_STATUS_IOC_NON_OP;
4445
4446 /*
4447 * 'len' must be in word (4-byte) boundary
4448 * 'offset' must be in sector (16kb) boundary
4449 */
4450 if (!len || (len & 0x03) || (offset & 0x00003FFF))
4451 return BFA_STATUS_FLASH_BAD_LEN;
4452
4453 if (flash->op_busy) {
4454 bfa_trc(flash, flash->op_busy);
4455 return BFA_STATUS_DEVBUSY;
4456 }
4457
4458 flash->op_busy = 1;
4459 flash->cbfn = cbfn;
4460 flash->cbarg = cbarg;
4461 flash->type = type;
4462 flash->instance = instance;
4463 flash->residue = len;
4464 flash->offset = 0;
4465 flash->addr_off = offset;
4466 flash->ubuf = buf;
4467 bfa_flash_read_send(flash);
4468
4469 return BFA_STATUS_OK;
4470}
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004471
4472/*
4473 * DIAG module specific
4474 */
4475
4476#define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07004477#define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004478
4479/* IOC event handler */
4480static void
4481bfa_diag_notify(void *diag_arg, enum bfa_ioc_event_e event)
4482{
4483 struct bfa_diag_s *diag = diag_arg;
4484
4485 bfa_trc(diag, event);
4486 bfa_trc(diag, diag->block);
4487 bfa_trc(diag, diag->fwping.lock);
4488 bfa_trc(diag, diag->tsensor.lock);
4489
4490 switch (event) {
4491 case BFA_IOC_E_DISABLED:
4492 case BFA_IOC_E_FAILED:
4493 if (diag->fwping.lock) {
4494 diag->fwping.status = BFA_STATUS_IOC_FAILURE;
4495 diag->fwping.cbfn(diag->fwping.cbarg,
4496 diag->fwping.status);
4497 diag->fwping.lock = 0;
4498 }
4499
4500 if (diag->tsensor.lock) {
4501 diag->tsensor.status = BFA_STATUS_IOC_FAILURE;
4502 diag->tsensor.cbfn(diag->tsensor.cbarg,
4503 diag->tsensor.status);
4504 diag->tsensor.lock = 0;
4505 }
4506
4507 if (diag->block) {
4508 if (diag->timer_active) {
4509 bfa_timer_stop(&diag->timer);
4510 diag->timer_active = 0;
4511 }
4512
4513 diag->status = BFA_STATUS_IOC_FAILURE;
4514 diag->cbfn(diag->cbarg, diag->status);
4515 diag->block = 0;
4516 }
4517 break;
4518
4519 default:
4520 break;
4521 }
4522}
4523
4524static void
4525bfa_diag_memtest_done(void *cbarg)
4526{
4527 struct bfa_diag_s *diag = cbarg;
4528 struct bfa_ioc_s *ioc = diag->ioc;
4529 struct bfa_diag_memtest_result *res = diag->result;
4530 u32 loff = BFI_BOOT_MEMTEST_RES_ADDR;
4531 u32 pgnum, pgoff, i;
4532
4533 pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff);
4534 pgoff = PSS_SMEM_PGOFF(loff);
4535
4536 writel(pgnum, ioc->ioc_regs.host_page_num_fn);
4537
4538 for (i = 0; i < (sizeof(struct bfa_diag_memtest_result) /
4539 sizeof(u32)); i++) {
4540 /* read test result from smem */
4541 *((u32 *) res + i) =
4542 bfa_mem_read(ioc->ioc_regs.smem_page_start, loff);
4543 loff += sizeof(u32);
4544 }
4545
4546 /* Reset IOC fwstates to BFI_IOC_UNINIT */
4547 bfa_ioc_reset_fwstate(ioc);
4548
4549 res->status = swab32(res->status);
4550 bfa_trc(diag, res->status);
4551
4552 if (res->status == BFI_BOOT_MEMTEST_RES_SIG)
4553 diag->status = BFA_STATUS_OK;
4554 else {
4555 diag->status = BFA_STATUS_MEMTEST_FAILED;
4556 res->addr = swab32(res->addr);
4557 res->exp = swab32(res->exp);
4558 res->act = swab32(res->act);
4559 res->err_status = swab32(res->err_status);
4560 res->err_status1 = swab32(res->err_status1);
4561 res->err_addr = swab32(res->err_addr);
4562 bfa_trc(diag, res->addr);
4563 bfa_trc(diag, res->exp);
4564 bfa_trc(diag, res->act);
4565 bfa_trc(diag, res->err_status);
4566 bfa_trc(diag, res->err_status1);
4567 bfa_trc(diag, res->err_addr);
4568 }
4569 diag->timer_active = 0;
4570 diag->cbfn(diag->cbarg, diag->status);
4571 diag->block = 0;
4572}
4573
4574/*
4575 * Firmware ping
4576 */
4577
4578/*
4579 * Perform DMA test directly
4580 */
4581static void
4582diag_fwping_send(struct bfa_diag_s *diag)
4583{
4584 struct bfi_diag_fwping_req_s *fwping_req;
4585 u32 i;
4586
4587 bfa_trc(diag, diag->fwping.dbuf_pa);
4588
4589 /* fill DMA area with pattern */
4590 for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++)
4591 *((u32 *)diag->fwping.dbuf_kva + i) = diag->fwping.data;
4592
4593 /* Fill mbox msg */
4594 fwping_req = (struct bfi_diag_fwping_req_s *)diag->fwping.mbcmd.msg;
4595
4596 /* Setup SG list */
4597 bfa_alen_set(&fwping_req->alen, BFI_DIAG_DMA_BUF_SZ,
4598 diag->fwping.dbuf_pa);
4599 /* Set up dma count */
4600 fwping_req->count = cpu_to_be32(diag->fwping.count);
4601 /* Set up data pattern */
4602 fwping_req->data = diag->fwping.data;
4603
4604 /* build host command */
4605 bfi_h2i_set(fwping_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_FWPING,
4606 bfa_ioc_portid(diag->ioc));
4607
4608 /* send mbox cmd */
4609 bfa_ioc_mbox_queue(diag->ioc, &diag->fwping.mbcmd);
4610}
4611
4612static void
4613diag_fwping_comp(struct bfa_diag_s *diag,
4614 struct bfi_diag_fwping_rsp_s *diag_rsp)
4615{
4616 u32 rsp_data = diag_rsp->data;
4617 u8 rsp_dma_status = diag_rsp->dma_status;
4618
4619 bfa_trc(diag, rsp_data);
4620 bfa_trc(diag, rsp_dma_status);
4621
4622 if (rsp_dma_status == BFA_STATUS_OK) {
4623 u32 i, pat;
4624 pat = (diag->fwping.count & 0x1) ? ~(diag->fwping.data) :
4625 diag->fwping.data;
4626 /* Check mbox data */
4627 if (diag->fwping.data != rsp_data) {
4628 bfa_trc(diag, rsp_data);
4629 diag->fwping.result->dmastatus =
4630 BFA_STATUS_DATACORRUPTED;
4631 diag->fwping.status = BFA_STATUS_DATACORRUPTED;
4632 diag->fwping.cbfn(diag->fwping.cbarg,
4633 diag->fwping.status);
4634 diag->fwping.lock = 0;
4635 return;
4636 }
4637 /* Check dma pattern */
4638 for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++) {
4639 if (*((u32 *)diag->fwping.dbuf_kva + i) != pat) {
4640 bfa_trc(diag, i);
4641 bfa_trc(diag, pat);
4642 bfa_trc(diag,
4643 *((u32 *)diag->fwping.dbuf_kva + i));
4644 diag->fwping.result->dmastatus =
4645 BFA_STATUS_DATACORRUPTED;
4646 diag->fwping.status = BFA_STATUS_DATACORRUPTED;
4647 diag->fwping.cbfn(diag->fwping.cbarg,
4648 diag->fwping.status);
4649 diag->fwping.lock = 0;
4650 return;
4651 }
4652 }
4653 diag->fwping.result->dmastatus = BFA_STATUS_OK;
4654 diag->fwping.status = BFA_STATUS_OK;
4655 diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
4656 diag->fwping.lock = 0;
4657 } else {
4658 diag->fwping.status = BFA_STATUS_HDMA_FAILED;
4659 diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status);
4660 diag->fwping.lock = 0;
4661 }
4662}
4663
4664/*
4665 * Temperature Sensor
4666 */
4667
4668static void
4669diag_tempsensor_send(struct bfa_diag_s *diag)
4670{
4671 struct bfi_diag_ts_req_s *msg;
4672
4673 msg = (struct bfi_diag_ts_req_s *)diag->tsensor.mbcmd.msg;
4674 bfa_trc(diag, msg->temp);
4675 /* build host command */
4676 bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_TEMPSENSOR,
4677 bfa_ioc_portid(diag->ioc));
4678 /* send mbox cmd */
4679 bfa_ioc_mbox_queue(diag->ioc, &diag->tsensor.mbcmd);
4680}
4681
4682static void
4683diag_tempsensor_comp(struct bfa_diag_s *diag, bfi_diag_ts_rsp_t *rsp)
4684{
4685 if (!diag->tsensor.lock) {
4686 /* receiving response after ioc failure */
4687 bfa_trc(diag, diag->tsensor.lock);
4688 return;
4689 }
4690
4691 /*
4692 * ASIC junction tempsensor is a reg read operation
4693 * it will always return OK
4694 */
4695 diag->tsensor.temp->temp = be16_to_cpu(rsp->temp);
4696 diag->tsensor.temp->ts_junc = rsp->ts_junc;
4697 diag->tsensor.temp->ts_brd = rsp->ts_brd;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004698
4699 if (rsp->ts_brd) {
Krishna Gudipati4a49b042012-09-21 17:27:01 -07004700 /* tsensor.temp->status is brd_temp status */
4701 diag->tsensor.temp->status = rsp->status;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004702 if (rsp->status == BFA_STATUS_OK) {
4703 diag->tsensor.temp->brd_temp =
4704 be16_to_cpu(rsp->brd_temp);
Krishna Gudipati4a49b042012-09-21 17:27:01 -07004705 } else
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004706 diag->tsensor.temp->brd_temp = 0;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004707 }
Krishna Gudipati4a49b042012-09-21 17:27:01 -07004708
4709 bfa_trc(diag, rsp->status);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004710 bfa_trc(diag, rsp->ts_junc);
4711 bfa_trc(diag, rsp->temp);
4712 bfa_trc(diag, rsp->ts_brd);
4713 bfa_trc(diag, rsp->brd_temp);
Krishna Gudipati4a49b042012-09-21 17:27:01 -07004714
4715 /* tsensor status is always good bcos we always have junction temp */
4716 diag->tsensor.status = BFA_STATUS_OK;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004717 diag->tsensor.cbfn(diag->tsensor.cbarg, diag->tsensor.status);
4718 diag->tsensor.lock = 0;
4719}
4720
4721/*
4722 * LED Test command
4723 */
4724static void
4725diag_ledtest_send(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
4726{
4727 struct bfi_diag_ledtest_req_s *msg;
4728
4729 msg = (struct bfi_diag_ledtest_req_s *)diag->ledtest.mbcmd.msg;
4730 /* build host command */
4731 bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LEDTEST,
4732 bfa_ioc_portid(diag->ioc));
4733
4734 /*
4735 * convert the freq from N blinks per 10 sec to
4736 * crossbow ontime value. We do it here because division is need
4737 */
4738 if (ledtest->freq)
4739 ledtest->freq = 500 / ledtest->freq;
4740
4741 if (ledtest->freq == 0)
4742 ledtest->freq = 1;
4743
4744 bfa_trc(diag, ledtest->freq);
4745 /* mcpy(&ledtest_req->req, ledtest, sizeof(bfa_diag_ledtest_t)); */
4746 msg->cmd = (u8) ledtest->cmd;
4747 msg->color = (u8) ledtest->color;
4748 msg->portid = bfa_ioc_portid(diag->ioc);
4749 msg->led = ledtest->led;
4750 msg->freq = cpu_to_be16(ledtest->freq);
4751
4752 /* send mbox cmd */
4753 bfa_ioc_mbox_queue(diag->ioc, &diag->ledtest.mbcmd);
4754}
4755
4756static void
Krishna Gudipati89196782012-03-13 17:38:56 -07004757diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s *msg)
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004758{
4759 bfa_trc(diag, diag->ledtest.lock);
4760 diag->ledtest.lock = BFA_FALSE;
4761 /* no bfa_cb_queue is needed because driver is not waiting */
4762}
4763
4764/*
4765 * Port beaconing
4766 */
4767static void
4768diag_portbeacon_send(struct bfa_diag_s *diag, bfa_boolean_t beacon, u32 sec)
4769{
4770 struct bfi_diag_portbeacon_req_s *msg;
4771
4772 msg = (struct bfi_diag_portbeacon_req_s *)diag->beacon.mbcmd.msg;
4773 /* build host command */
4774 bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_PORTBEACON,
4775 bfa_ioc_portid(diag->ioc));
4776 msg->beacon = beacon;
4777 msg->period = cpu_to_be32(sec);
4778 /* send mbox cmd */
4779 bfa_ioc_mbox_queue(diag->ioc, &diag->beacon.mbcmd);
4780}
4781
4782static void
4783diag_portbeacon_comp(struct bfa_diag_s *diag)
4784{
4785 bfa_trc(diag, diag->beacon.state);
4786 diag->beacon.state = BFA_FALSE;
4787 if (diag->cbfn_beacon)
4788 diag->cbfn_beacon(diag->dev, BFA_FALSE, diag->beacon.link_e2e);
4789}
4790
4791/*
4792 * Diag hmbox handler
4793 */
4794void
4795bfa_diag_intr(void *diagarg, struct bfi_mbmsg_s *msg)
4796{
4797 struct bfa_diag_s *diag = diagarg;
4798
4799 switch (msg->mh.msg_id) {
4800 case BFI_DIAG_I2H_PORTBEACON:
4801 diag_portbeacon_comp(diag);
4802 break;
4803 case BFI_DIAG_I2H_FWPING:
4804 diag_fwping_comp(diag, (struct bfi_diag_fwping_rsp_s *) msg);
4805 break;
4806 case BFI_DIAG_I2H_TEMPSENSOR:
4807 diag_tempsensor_comp(diag, (bfi_diag_ts_rsp_t *) msg);
4808 break;
4809 case BFI_DIAG_I2H_LEDTEST:
4810 diag_ledtest_comp(diag, (struct bfi_diag_ledtest_rsp_s *) msg);
4811 break;
4812 default:
4813 bfa_trc(diag, msg->mh.msg_id);
4814 WARN_ON(1);
4815 }
4816}
4817
4818/*
4819 * Gen RAM Test
4820 *
4821 * @param[in] *diag - diag data struct
4822 * @param[in] *memtest - mem test params input from upper layer,
4823 * @param[in] pattern - mem test pattern
4824 * @param[in] *result - mem test result
4825 * @param[in] cbfn - mem test callback functioin
4826 * @param[in] cbarg - callback functioin arg
4827 *
4828 * @param[out]
4829 */
4830bfa_status_t
4831bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest,
4832 u32 pattern, struct bfa_diag_memtest_result *result,
4833 bfa_cb_diag_t cbfn, void *cbarg)
4834{
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07004835 u32 memtest_tov;
4836
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004837 bfa_trc(diag, pattern);
4838
4839 if (!bfa_ioc_adapter_is_disabled(diag->ioc))
4840 return BFA_STATUS_ADAPTER_ENABLED;
4841
4842 /* check to see if there is another destructive diag cmd running */
4843 if (diag->block) {
4844 bfa_trc(diag, diag->block);
4845 return BFA_STATUS_DEVBUSY;
4846 } else
4847 diag->block = 1;
4848
4849 diag->result = result;
4850 diag->cbfn = cbfn;
4851 diag->cbarg = cbarg;
4852
4853 /* download memtest code and take LPU0 out of reset */
4854 bfa_ioc_boot(diag->ioc, BFI_FWBOOT_TYPE_MEMTEST, BFI_FWBOOT_ENV_OS);
4855
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07004856 memtest_tov = (bfa_ioc_asic_gen(diag->ioc) == BFI_ASIC_GEN_CT2) ?
4857 CT2_BFA_DIAG_MEMTEST_TOV : BFA_DIAG_MEMTEST_TOV;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004858 bfa_timer_begin(diag->ioc->timer_mod, &diag->timer,
Krishna Gudipatibd5a0262012-03-13 17:41:02 -07004859 bfa_diag_memtest_done, diag, memtest_tov);
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004860 diag->timer_active = 1;
4861 return BFA_STATUS_OK;
4862}
4863
4864/*
4865 * DIAG firmware ping command
4866 *
4867 * @param[in] *diag - diag data struct
4868 * @param[in] cnt - dma loop count for testing PCIE
4869 * @param[in] data - data pattern to pass in fw
4870 * @param[in] *result - pt to bfa_diag_fwping_result_t data struct
4871 * @param[in] cbfn - callback function
4872 * @param[in] *cbarg - callback functioin arg
4873 *
4874 * @param[out]
4875 */
4876bfa_status_t
4877bfa_diag_fwping(struct bfa_diag_s *diag, u32 cnt, u32 data,
4878 struct bfa_diag_results_fwping *result, bfa_cb_diag_t cbfn,
4879 void *cbarg)
4880{
4881 bfa_trc(diag, cnt);
4882 bfa_trc(diag, data);
4883
4884 if (!bfa_ioc_is_operational(diag->ioc))
4885 return BFA_STATUS_IOC_NON_OP;
4886
4887 if (bfa_asic_id_ct2(bfa_ioc_devid((diag->ioc))) &&
4888 ((diag->ioc)->clscode == BFI_PCIFN_CLASS_ETH))
4889 return BFA_STATUS_CMD_NOTSUPP;
4890
4891 /* check to see if there is another destructive diag cmd running */
4892 if (diag->block || diag->fwping.lock) {
4893 bfa_trc(diag, diag->block);
4894 bfa_trc(diag, diag->fwping.lock);
4895 return BFA_STATUS_DEVBUSY;
4896 }
4897
4898 /* Initialization */
4899 diag->fwping.lock = 1;
4900 diag->fwping.cbfn = cbfn;
4901 diag->fwping.cbarg = cbarg;
4902 diag->fwping.result = result;
4903 diag->fwping.data = data;
4904 diag->fwping.count = cnt;
4905
4906 /* Init test results */
4907 diag->fwping.result->data = 0;
4908 diag->fwping.result->status = BFA_STATUS_OK;
4909
4910 /* kick off the first ping */
4911 diag_fwping_send(diag);
4912 return BFA_STATUS_OK;
4913}
4914
4915/*
4916 * Read Temperature Sensor
4917 *
4918 * @param[in] *diag - diag data struct
4919 * @param[in] *result - pt to bfa_diag_temp_t data struct
4920 * @param[in] cbfn - callback function
4921 * @param[in] *cbarg - callback functioin arg
4922 *
4923 * @param[out]
4924 */
4925bfa_status_t
4926bfa_diag_tsensor_query(struct bfa_diag_s *diag,
4927 struct bfa_diag_results_tempsensor_s *result,
4928 bfa_cb_diag_t cbfn, void *cbarg)
4929{
4930 /* check to see if there is a destructive diag cmd running */
4931 if (diag->block || diag->tsensor.lock) {
4932 bfa_trc(diag, diag->block);
4933 bfa_trc(diag, diag->tsensor.lock);
4934 return BFA_STATUS_DEVBUSY;
4935 }
4936
4937 if (!bfa_ioc_is_operational(diag->ioc))
4938 return BFA_STATUS_IOC_NON_OP;
4939
4940 /* Init diag mod params */
4941 diag->tsensor.lock = 1;
4942 diag->tsensor.temp = result;
4943 diag->tsensor.cbfn = cbfn;
4944 diag->tsensor.cbarg = cbarg;
Krishna Gudipati4a49b042012-09-21 17:27:01 -07004945 diag->tsensor.status = BFA_STATUS_OK;
Krishna Gudipati3d7fc662011-06-24 20:28:17 -07004946
4947 /* Send msg to fw */
4948 diag_tempsensor_send(diag);
4949
4950 return BFA_STATUS_OK;
4951}
4952
4953/*
4954 * LED Test command
4955 *
4956 * @param[in] *diag - diag data struct
4957 * @param[in] *ledtest - pt to ledtest data structure
4958 *
4959 * @param[out]
4960 */
4961bfa_status_t
4962bfa_diag_ledtest(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest)
4963{
4964 bfa_trc(diag, ledtest->cmd);
4965
4966 if (!bfa_ioc_is_operational(diag->ioc))
4967 return BFA_STATUS_IOC_NON_OP;
4968
4969 if (diag->beacon.state)
4970 return BFA_STATUS_BEACON_ON;
4971
4972 if (diag->ledtest.lock)
4973 return BFA_STATUS_LEDTEST_OP;
4974
4975 /* Send msg to fw */
4976 diag->ledtest.lock = BFA_TRUE;
4977 diag_ledtest_send(diag, ledtest);
4978
4979 return BFA_STATUS_OK;
4980}
4981
4982/*
4983 * Port beaconing command
4984 *
4985 * @param[in] *diag - diag data struct
4986 * @param[in] beacon - port beaconing 1:ON 0:OFF
4987 * @param[in] link_e2e_beacon - link beaconing 1:ON 0:OFF
4988 * @param[in] sec - beaconing duration in seconds
4989 *
4990 * @param[out]
4991 */
4992bfa_status_t
4993bfa_diag_beacon_port(struct bfa_diag_s *diag, bfa_boolean_t beacon,
4994 bfa_boolean_t link_e2e_beacon, uint32_t sec)
4995{
4996 bfa_trc(diag, beacon);
4997 bfa_trc(diag, link_e2e_beacon);
4998 bfa_trc(diag, sec);
4999
5000 if (!bfa_ioc_is_operational(diag->ioc))
5001 return BFA_STATUS_IOC_NON_OP;
5002
5003 if (diag->ledtest.lock)
5004 return BFA_STATUS_LEDTEST_OP;
5005
5006 if (diag->beacon.state && beacon) /* beacon alread on */
5007 return BFA_STATUS_BEACON_ON;
5008
5009 diag->beacon.state = beacon;
5010 diag->beacon.link_e2e = link_e2e_beacon;
5011 if (diag->cbfn_beacon)
5012 diag->cbfn_beacon(diag->dev, beacon, link_e2e_beacon);
5013
5014 /* Send msg to fw */
5015 diag_portbeacon_send(diag, beacon, sec);
5016
5017 return BFA_STATUS_OK;
5018}
5019
5020/*
5021 * Return DMA memory needed by diag module.
5022 */
5023u32
5024bfa_diag_meminfo(void)
5025{
5026 return BFA_ROUNDUP(BFI_DIAG_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5027}
5028
5029/*
5030 * Attach virtual and physical memory for Diag.
5031 */
5032void
5033bfa_diag_attach(struct bfa_diag_s *diag, struct bfa_ioc_s *ioc, void *dev,
5034 bfa_cb_diag_beacon_t cbfn_beacon, struct bfa_trc_mod_s *trcmod)
5035{
5036 diag->dev = dev;
5037 diag->ioc = ioc;
5038 diag->trcmod = trcmod;
5039
5040 diag->block = 0;
5041 diag->cbfn = NULL;
5042 diag->cbarg = NULL;
5043 diag->result = NULL;
5044 diag->cbfn_beacon = cbfn_beacon;
5045
5046 bfa_ioc_mbox_regisr(diag->ioc, BFI_MC_DIAG, bfa_diag_intr, diag);
5047 bfa_q_qe_init(&diag->ioc_notify);
5048 bfa_ioc_notify_init(&diag->ioc_notify, bfa_diag_notify, diag);
5049 list_add_tail(&diag->ioc_notify.qe, &diag->ioc->notify_q);
5050}
5051
5052void
5053bfa_diag_memclaim(struct bfa_diag_s *diag, u8 *dm_kva, u64 dm_pa)
5054{
5055 diag->fwping.dbuf_kva = dm_kva;
5056 diag->fwping.dbuf_pa = dm_pa;
5057 memset(diag->fwping.dbuf_kva, 0, BFI_DIAG_DMA_BUF_SZ);
5058}
Krishna Gudipati3350d982011-06-24 20:28:37 -07005059
5060/*
5061 * PHY module specific
5062 */
5063#define BFA_PHY_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
5064#define BFA_PHY_LOCK_STATUS 0x018878 /* phy semaphore status reg */
5065
5066static void
5067bfa_phy_ntoh32(u32 *obuf, u32 *ibuf, int sz)
5068{
5069 int i, m = sz >> 2;
5070
5071 for (i = 0; i < m; i++)
5072 obuf[i] = be32_to_cpu(ibuf[i]);
5073}
5074
5075static bfa_boolean_t
5076bfa_phy_present(struct bfa_phy_s *phy)
5077{
5078 return (phy->ioc->attr->card_type == BFA_MFG_TYPE_LIGHTNING);
5079}
5080
5081static void
5082bfa_phy_notify(void *cbarg, enum bfa_ioc_event_e event)
5083{
5084 struct bfa_phy_s *phy = cbarg;
5085
5086 bfa_trc(phy, event);
5087
5088 switch (event) {
5089 case BFA_IOC_E_DISABLED:
5090 case BFA_IOC_E_FAILED:
5091 if (phy->op_busy) {
5092 phy->status = BFA_STATUS_IOC_FAILURE;
5093 phy->cbfn(phy->cbarg, phy->status);
5094 phy->op_busy = 0;
5095 }
5096 break;
5097
5098 default:
5099 break;
5100 }
5101}
5102
5103/*
5104 * Send phy attribute query request.
5105 *
5106 * @param[in] cbarg - callback argument
5107 */
5108static void
5109bfa_phy_query_send(void *cbarg)
5110{
5111 struct bfa_phy_s *phy = cbarg;
5112 struct bfi_phy_query_req_s *msg =
5113 (struct bfi_phy_query_req_s *) phy->mb.msg;
5114
5115 msg->instance = phy->instance;
5116 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_QUERY_REQ,
5117 bfa_ioc_portid(phy->ioc));
5118 bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_attr_s), phy->dbuf_pa);
5119 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5120}
5121
5122/*
5123 * Send phy write request.
5124 *
5125 * @param[in] cbarg - callback argument
5126 */
5127static void
5128bfa_phy_write_send(void *cbarg)
5129{
5130 struct bfa_phy_s *phy = cbarg;
5131 struct bfi_phy_write_req_s *msg =
5132 (struct bfi_phy_write_req_s *) phy->mb.msg;
5133 u32 len;
5134 u16 *buf, *dbuf;
5135 int i, sz;
5136
5137 msg->instance = phy->instance;
5138 msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
5139 len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
5140 phy->residue : BFA_PHY_DMA_BUF_SZ;
5141 msg->length = cpu_to_be32(len);
5142
5143 /* indicate if it's the last msg of the whole write operation */
5144 msg->last = (len == phy->residue) ? 1 : 0;
5145
5146 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_WRITE_REQ,
5147 bfa_ioc_portid(phy->ioc));
5148 bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
5149
5150 buf = (u16 *) (phy->ubuf + phy->offset);
5151 dbuf = (u16 *)phy->dbuf_kva;
5152 sz = len >> 1;
5153 for (i = 0; i < sz; i++)
5154 buf[i] = cpu_to_be16(dbuf[i]);
5155
5156 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5157
5158 phy->residue -= len;
5159 phy->offset += len;
5160}
5161
5162/*
5163 * Send phy read request.
5164 *
5165 * @param[in] cbarg - callback argument
5166 */
5167static void
5168bfa_phy_read_send(void *cbarg)
5169{
5170 struct bfa_phy_s *phy = cbarg;
5171 struct bfi_phy_read_req_s *msg =
5172 (struct bfi_phy_read_req_s *) phy->mb.msg;
5173 u32 len;
5174
5175 msg->instance = phy->instance;
5176 msg->offset = cpu_to_be32(phy->addr_off + phy->offset);
5177 len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ?
5178 phy->residue : BFA_PHY_DMA_BUF_SZ;
5179 msg->length = cpu_to_be32(len);
5180 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_READ_REQ,
5181 bfa_ioc_portid(phy->ioc));
5182 bfa_alen_set(&msg->alen, len, phy->dbuf_pa);
5183 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5184}
5185
5186/*
5187 * Send phy stats request.
5188 *
5189 * @param[in] cbarg - callback argument
5190 */
5191static void
5192bfa_phy_stats_send(void *cbarg)
5193{
5194 struct bfa_phy_s *phy = cbarg;
5195 struct bfi_phy_stats_req_s *msg =
5196 (struct bfi_phy_stats_req_s *) phy->mb.msg;
5197
5198 msg->instance = phy->instance;
5199 bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_STATS_REQ,
5200 bfa_ioc_portid(phy->ioc));
5201 bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_stats_s), phy->dbuf_pa);
5202 bfa_ioc_mbox_queue(phy->ioc, &phy->mb);
5203}
5204
5205/*
5206 * Flash memory info API.
5207 *
5208 * @param[in] mincfg - minimal cfg variable
5209 */
5210u32
5211bfa_phy_meminfo(bfa_boolean_t mincfg)
5212{
5213 /* min driver doesn't need phy */
5214 if (mincfg)
5215 return 0;
5216
5217 return BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5218}
5219
5220/*
5221 * Flash attach API.
5222 *
5223 * @param[in] phy - phy structure
5224 * @param[in] ioc - ioc structure
5225 * @param[in] dev - device structure
5226 * @param[in] trcmod - trace module
5227 * @param[in] logmod - log module
5228 */
5229void
5230bfa_phy_attach(struct bfa_phy_s *phy, struct bfa_ioc_s *ioc, void *dev,
5231 struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
5232{
5233 phy->ioc = ioc;
5234 phy->trcmod = trcmod;
5235 phy->cbfn = NULL;
5236 phy->cbarg = NULL;
5237 phy->op_busy = 0;
5238
5239 bfa_ioc_mbox_regisr(phy->ioc, BFI_MC_PHY, bfa_phy_intr, phy);
5240 bfa_q_qe_init(&phy->ioc_notify);
5241 bfa_ioc_notify_init(&phy->ioc_notify, bfa_phy_notify, phy);
5242 list_add_tail(&phy->ioc_notify.qe, &phy->ioc->notify_q);
5243
5244 /* min driver doesn't need phy */
5245 if (mincfg) {
5246 phy->dbuf_kva = NULL;
5247 phy->dbuf_pa = 0;
5248 }
5249}
5250
5251/*
5252 * Claim memory for phy
5253 *
5254 * @param[in] phy - phy structure
5255 * @param[in] dm_kva - pointer to virtual memory address
5256 * @param[in] dm_pa - physical memory address
5257 * @param[in] mincfg - minimal cfg variable
5258 */
5259void
5260bfa_phy_memclaim(struct bfa_phy_s *phy, u8 *dm_kva, u64 dm_pa,
5261 bfa_boolean_t mincfg)
5262{
5263 if (mincfg)
5264 return;
5265
5266 phy->dbuf_kva = dm_kva;
5267 phy->dbuf_pa = dm_pa;
5268 memset(phy->dbuf_kva, 0, BFA_PHY_DMA_BUF_SZ);
5269 dm_kva += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5270 dm_pa += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
5271}
5272
5273bfa_boolean_t
5274bfa_phy_busy(struct bfa_ioc_s *ioc)
5275{
5276 void __iomem *rb;
5277
5278 rb = bfa_ioc_bar0(ioc);
5279 return readl(rb + BFA_PHY_LOCK_STATUS);
5280}
5281
5282/*
5283 * Get phy attribute.
5284 *
5285 * @param[in] phy - phy structure
5286 * @param[in] attr - phy attribute structure
5287 * @param[in] cbfn - callback function
5288 * @param[in] cbarg - callback argument
5289 *
5290 * Return status.
5291 */
5292bfa_status_t
5293bfa_phy_get_attr(struct bfa_phy_s *phy, u8 instance,
5294 struct bfa_phy_attr_s *attr, bfa_cb_phy_t cbfn, void *cbarg)
5295{
5296 bfa_trc(phy, BFI_PHY_H2I_QUERY_REQ);
5297 bfa_trc(phy, instance);
5298
5299 if (!bfa_phy_present(phy))
5300 return BFA_STATUS_PHY_NOT_PRESENT;
5301
5302 if (!bfa_ioc_is_operational(phy->ioc))
5303 return BFA_STATUS_IOC_NON_OP;
5304
5305 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5306 bfa_trc(phy, phy->op_busy);
5307 return BFA_STATUS_DEVBUSY;
5308 }
5309
5310 phy->op_busy = 1;
5311 phy->cbfn = cbfn;
5312 phy->cbarg = cbarg;
5313 phy->instance = instance;
5314 phy->ubuf = (uint8_t *) attr;
5315 bfa_phy_query_send(phy);
5316
5317 return BFA_STATUS_OK;
5318}
5319
5320/*
5321 * Get phy stats.
5322 *
5323 * @param[in] phy - phy structure
5324 * @param[in] instance - phy image instance
5325 * @param[in] stats - pointer to phy stats
5326 * @param[in] cbfn - callback function
5327 * @param[in] cbarg - callback argument
5328 *
5329 * Return status.
5330 */
5331bfa_status_t
5332bfa_phy_get_stats(struct bfa_phy_s *phy, u8 instance,
5333 struct bfa_phy_stats_s *stats,
5334 bfa_cb_phy_t cbfn, void *cbarg)
5335{
5336 bfa_trc(phy, BFI_PHY_H2I_STATS_REQ);
5337 bfa_trc(phy, instance);
5338
5339 if (!bfa_phy_present(phy))
5340 return BFA_STATUS_PHY_NOT_PRESENT;
5341
5342 if (!bfa_ioc_is_operational(phy->ioc))
5343 return BFA_STATUS_IOC_NON_OP;
5344
5345 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5346 bfa_trc(phy, phy->op_busy);
5347 return BFA_STATUS_DEVBUSY;
5348 }
5349
5350 phy->op_busy = 1;
5351 phy->cbfn = cbfn;
5352 phy->cbarg = cbarg;
5353 phy->instance = instance;
5354 phy->ubuf = (u8 *) stats;
5355 bfa_phy_stats_send(phy);
5356
5357 return BFA_STATUS_OK;
5358}
5359
5360/*
5361 * Update phy image.
5362 *
5363 * @param[in] phy - phy structure
5364 * @param[in] instance - phy image instance
5365 * @param[in] buf - update data buffer
5366 * @param[in] len - data buffer length
5367 * @param[in] offset - offset relative to starting address
5368 * @param[in] cbfn - callback function
5369 * @param[in] cbarg - callback argument
5370 *
5371 * Return status.
5372 */
5373bfa_status_t
5374bfa_phy_update(struct bfa_phy_s *phy, u8 instance,
5375 void *buf, u32 len, u32 offset,
5376 bfa_cb_phy_t cbfn, void *cbarg)
5377{
5378 bfa_trc(phy, BFI_PHY_H2I_WRITE_REQ);
5379 bfa_trc(phy, instance);
5380 bfa_trc(phy, len);
5381 bfa_trc(phy, offset);
5382
5383 if (!bfa_phy_present(phy))
5384 return BFA_STATUS_PHY_NOT_PRESENT;
5385
5386 if (!bfa_ioc_is_operational(phy->ioc))
5387 return BFA_STATUS_IOC_NON_OP;
5388
5389 /* 'len' must be in word (4-byte) boundary */
5390 if (!len || (len & 0x03))
5391 return BFA_STATUS_FAILED;
5392
5393 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5394 bfa_trc(phy, phy->op_busy);
5395 return BFA_STATUS_DEVBUSY;
5396 }
5397
5398 phy->op_busy = 1;
5399 phy->cbfn = cbfn;
5400 phy->cbarg = cbarg;
5401 phy->instance = instance;
5402 phy->residue = len;
5403 phy->offset = 0;
5404 phy->addr_off = offset;
5405 phy->ubuf = buf;
5406
5407 bfa_phy_write_send(phy);
5408 return BFA_STATUS_OK;
5409}
5410
5411/*
5412 * Read phy image.
5413 *
5414 * @param[in] phy - phy structure
5415 * @param[in] instance - phy image instance
5416 * @param[in] buf - read data buffer
5417 * @param[in] len - data buffer length
5418 * @param[in] offset - offset relative to starting address
5419 * @param[in] cbfn - callback function
5420 * @param[in] cbarg - callback argument
5421 *
5422 * Return status.
5423 */
5424bfa_status_t
5425bfa_phy_read(struct bfa_phy_s *phy, u8 instance,
5426 void *buf, u32 len, u32 offset,
5427 bfa_cb_phy_t cbfn, void *cbarg)
5428{
5429 bfa_trc(phy, BFI_PHY_H2I_READ_REQ);
5430 bfa_trc(phy, instance);
5431 bfa_trc(phy, len);
5432 bfa_trc(phy, offset);
5433
5434 if (!bfa_phy_present(phy))
5435 return BFA_STATUS_PHY_NOT_PRESENT;
5436
5437 if (!bfa_ioc_is_operational(phy->ioc))
5438 return BFA_STATUS_IOC_NON_OP;
5439
5440 /* 'len' must be in word (4-byte) boundary */
5441 if (!len || (len & 0x03))
5442 return BFA_STATUS_FAILED;
5443
5444 if (phy->op_busy || bfa_phy_busy(phy->ioc)) {
5445 bfa_trc(phy, phy->op_busy);
5446 return BFA_STATUS_DEVBUSY;
5447 }
5448
5449 phy->op_busy = 1;
5450 phy->cbfn = cbfn;
5451 phy->cbarg = cbarg;
5452 phy->instance = instance;
5453 phy->residue = len;
5454 phy->offset = 0;
5455 phy->addr_off = offset;
5456 phy->ubuf = buf;
5457 bfa_phy_read_send(phy);
5458
5459 return BFA_STATUS_OK;
5460}
5461
5462/*
5463 * Process phy response messages upon receiving interrupts.
5464 *
5465 * @param[in] phyarg - phy structure
5466 * @param[in] msg - message structure
5467 */
5468void
5469bfa_phy_intr(void *phyarg, struct bfi_mbmsg_s *msg)
5470{
5471 struct bfa_phy_s *phy = phyarg;
5472 u32 status;
5473
5474 union {
5475 struct bfi_phy_query_rsp_s *query;
5476 struct bfi_phy_stats_rsp_s *stats;
5477 struct bfi_phy_write_rsp_s *write;
5478 struct bfi_phy_read_rsp_s *read;
5479 struct bfi_mbmsg_s *msg;
5480 } m;
5481
5482 m.msg = msg;
5483 bfa_trc(phy, msg->mh.msg_id);
5484
5485 if (!phy->op_busy) {
5486 /* receiving response after ioc failure */
5487 bfa_trc(phy, 0x9999);
5488 return;
5489 }
5490
5491 switch (msg->mh.msg_id) {
5492 case BFI_PHY_I2H_QUERY_RSP:
5493 status = be32_to_cpu(m.query->status);
5494 bfa_trc(phy, status);
5495
5496 if (status == BFA_STATUS_OK) {
5497 struct bfa_phy_attr_s *attr =
5498 (struct bfa_phy_attr_s *) phy->ubuf;
5499 bfa_phy_ntoh32((u32 *)attr, (u32 *)phy->dbuf_kva,
5500 sizeof(struct bfa_phy_attr_s));
5501 bfa_trc(phy, attr->status);
5502 bfa_trc(phy, attr->length);
5503 }
5504
5505 phy->status = status;
5506 phy->op_busy = 0;
5507 if (phy->cbfn)
5508 phy->cbfn(phy->cbarg, phy->status);
5509 break;
5510 case BFI_PHY_I2H_STATS_RSP:
5511 status = be32_to_cpu(m.stats->status);
5512 bfa_trc(phy, status);
5513
5514 if (status == BFA_STATUS_OK) {
5515 struct bfa_phy_stats_s *stats =
5516 (struct bfa_phy_stats_s *) phy->ubuf;
5517 bfa_phy_ntoh32((u32 *)stats, (u32 *)phy->dbuf_kva,
5518 sizeof(struct bfa_phy_stats_s));
5519 bfa_trc(phy, stats->status);
5520 }
5521
5522 phy->status = status;
5523 phy->op_busy = 0;
5524 if (phy->cbfn)
5525 phy->cbfn(phy->cbarg, phy->status);
5526 break;
5527 case BFI_PHY_I2H_WRITE_RSP:
5528 status = be32_to_cpu(m.write->status);
5529 bfa_trc(phy, status);
5530
5531 if (status != BFA_STATUS_OK || phy->residue == 0) {
5532 phy->status = status;
5533 phy->op_busy = 0;
5534 if (phy->cbfn)
5535 phy->cbfn(phy->cbarg, phy->status);
5536 } else {
5537 bfa_trc(phy, phy->offset);
5538 bfa_phy_write_send(phy);
5539 }
5540 break;
5541 case BFI_PHY_I2H_READ_RSP:
5542 status = be32_to_cpu(m.read->status);
5543 bfa_trc(phy, status);
5544
5545 if (status != BFA_STATUS_OK) {
5546 phy->status = status;
5547 phy->op_busy = 0;
5548 if (phy->cbfn)
5549 phy->cbfn(phy->cbarg, phy->status);
5550 } else {
5551 u32 len = be32_to_cpu(m.read->length);
5552 u16 *buf = (u16 *)(phy->ubuf + phy->offset);
5553 u16 *dbuf = (u16 *)phy->dbuf_kva;
5554 int i, sz = len >> 1;
5555
5556 bfa_trc(phy, phy->offset);
5557 bfa_trc(phy, len);
5558
5559 for (i = 0; i < sz; i++)
5560 buf[i] = be16_to_cpu(dbuf[i]);
5561
5562 phy->residue -= len;
5563 phy->offset += len;
5564
5565 if (phy->residue == 0) {
5566 phy->status = status;
5567 phy->op_busy = 0;
5568 if (phy->cbfn)
5569 phy->cbfn(phy->cbarg, phy->status);
5570 } else
5571 bfa_phy_read_send(phy);
5572 }
5573 break;
5574 default:
5575 WARN_ON(1);
5576 }
5577}
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005578
5579/*
5580 * DCONF module specific
5581 */
5582
5583BFA_MODULE(dconf);
5584
5585/*
5586 * DCONF state machine events
5587 */
5588enum bfa_dconf_event {
5589 BFA_DCONF_SM_INIT = 1, /* dconf Init */
5590 BFA_DCONF_SM_FLASH_COMP = 2, /* read/write to flash */
5591 BFA_DCONF_SM_WR = 3, /* binding change, map */
5592 BFA_DCONF_SM_TIMEOUT = 4, /* Start timer */
5593 BFA_DCONF_SM_EXIT = 5, /* exit dconf module */
5594 BFA_DCONF_SM_IOCDISABLE = 6, /* IOC disable event */
5595};
5596
5597/* forward declaration of DCONF state machine */
5598static void bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf,
5599 enum bfa_dconf_event event);
5600static void bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
5601 enum bfa_dconf_event event);
5602static void bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf,
5603 enum bfa_dconf_event event);
5604static void bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf,
5605 enum bfa_dconf_event event);
5606static void bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf,
5607 enum bfa_dconf_event event);
5608static void bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
5609 enum bfa_dconf_event event);
5610static void bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
5611 enum bfa_dconf_event event);
5612
5613static void bfa_dconf_cbfn(void *dconf, bfa_status_t status);
5614static void bfa_dconf_timer(void *cbarg);
5615static bfa_status_t bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf);
5616static void bfa_dconf_init_cb(void *arg, bfa_status_t status);
5617
5618/*
Anatol Pomozov4907cb72012-09-01 10:31:09 -07005619 * Beginning state of dconf module. Waiting for an event to start.
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005620 */
5621static void
5622bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5623{
5624 bfa_status_t bfa_status;
5625 bfa_trc(dconf->bfa, event);
5626
5627 switch (event) {
5628 case BFA_DCONF_SM_INIT:
5629 if (dconf->min_cfg) {
5630 bfa_trc(dconf->bfa, dconf->min_cfg);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005631 bfa_fsm_send_event(&dconf->bfa->iocfc,
5632 IOCFC_E_DCONF_DONE);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005633 return;
5634 }
5635 bfa_sm_set_state(dconf, bfa_dconf_sm_flash_read);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005636 bfa_timer_start(dconf->bfa, &dconf->timer,
Krishna Gudipati7ac83b12012-09-21 17:24:21 -07005637 bfa_dconf_timer, dconf, 2 * BFA_DCONF_UPDATE_TOV);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005638 bfa_status = bfa_flash_read_part(BFA_FLASH(dconf->bfa),
5639 BFA_FLASH_PART_DRV, dconf->instance,
5640 dconf->dconf,
5641 sizeof(struct bfa_dconf_s), 0,
5642 bfa_dconf_init_cb, dconf->bfa);
5643 if (bfa_status != BFA_STATUS_OK) {
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005644 bfa_timer_stop(&dconf->timer);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005645 bfa_dconf_init_cb(dconf->bfa, BFA_STATUS_FAILED);
5646 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5647 return;
5648 }
5649 break;
5650 case BFA_DCONF_SM_EXIT:
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005651 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005652 case BFA_DCONF_SM_IOCDISABLE:
5653 case BFA_DCONF_SM_WR:
5654 case BFA_DCONF_SM_FLASH_COMP:
5655 break;
5656 default:
5657 bfa_sm_fault(dconf->bfa, event);
5658 }
5659}
5660
5661/*
5662 * Read flash for dconf entries and make a call back to the driver once done.
5663 */
5664static void
5665bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf,
5666 enum bfa_dconf_event event)
5667{
5668 bfa_trc(dconf->bfa, event);
5669
5670 switch (event) {
5671 case BFA_DCONF_SM_FLASH_COMP:
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005672 bfa_timer_stop(&dconf->timer);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005673 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
5674 break;
5675 case BFA_DCONF_SM_TIMEOUT:
5676 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
Krishna Gudipati7ac83b12012-09-21 17:24:21 -07005677 bfa_ioc_suspend(&dconf->bfa->ioc);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005678 break;
5679 case BFA_DCONF_SM_EXIT:
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005680 bfa_timer_stop(&dconf->timer);
5681 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5682 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
5683 break;
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005684 case BFA_DCONF_SM_IOCDISABLE:
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005685 bfa_timer_stop(&dconf->timer);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005686 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5687 break;
5688 default:
5689 bfa_sm_fault(dconf->bfa, event);
5690 }
5691}
5692
5693/*
5694 * DCONF Module is in ready state. Has completed the initialization.
5695 */
5696static void
5697bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5698{
5699 bfa_trc(dconf->bfa, event);
5700
5701 switch (event) {
5702 case BFA_DCONF_SM_WR:
5703 bfa_timer_start(dconf->bfa, &dconf->timer,
5704 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5705 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
5706 break;
5707 case BFA_DCONF_SM_EXIT:
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005708 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005709 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005710 break;
5711 case BFA_DCONF_SM_INIT:
5712 case BFA_DCONF_SM_IOCDISABLE:
5713 break;
5714 default:
5715 bfa_sm_fault(dconf->bfa, event);
5716 }
5717}
5718
5719/*
5720 * entries are dirty, write back to the flash.
5721 */
5722
5723static void
5724bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5725{
5726 bfa_trc(dconf->bfa, event);
5727
5728 switch (event) {
5729 case BFA_DCONF_SM_TIMEOUT:
5730 bfa_sm_set_state(dconf, bfa_dconf_sm_sync);
5731 bfa_dconf_flash_write(dconf);
5732 break;
5733 case BFA_DCONF_SM_WR:
5734 bfa_timer_stop(&dconf->timer);
5735 bfa_timer_start(dconf->bfa, &dconf->timer,
5736 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5737 break;
5738 case BFA_DCONF_SM_EXIT:
5739 bfa_timer_stop(&dconf->timer);
5740 bfa_timer_start(dconf->bfa, &dconf->timer,
5741 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5742 bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
5743 bfa_dconf_flash_write(dconf);
5744 break;
5745 case BFA_DCONF_SM_FLASH_COMP:
5746 break;
5747 case BFA_DCONF_SM_IOCDISABLE:
5748 bfa_timer_stop(&dconf->timer);
5749 bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
5750 break;
5751 default:
5752 bfa_sm_fault(dconf->bfa, event);
5753 }
5754}
5755
5756/*
5757 * Sync the dconf entries to the flash.
5758 */
5759static void
5760bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf,
5761 enum bfa_dconf_event event)
5762{
5763 bfa_trc(dconf->bfa, event);
5764
5765 switch (event) {
5766 case BFA_DCONF_SM_IOCDISABLE:
5767 case BFA_DCONF_SM_FLASH_COMP:
5768 bfa_timer_stop(&dconf->timer);
5769 case BFA_DCONF_SM_TIMEOUT:
5770 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005771 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005772 break;
5773 default:
5774 bfa_sm_fault(dconf->bfa, event);
5775 }
5776}
5777
5778static void
5779bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event)
5780{
5781 bfa_trc(dconf->bfa, event);
5782
5783 switch (event) {
5784 case BFA_DCONF_SM_FLASH_COMP:
5785 bfa_sm_set_state(dconf, bfa_dconf_sm_ready);
5786 break;
5787 case BFA_DCONF_SM_WR:
5788 bfa_timer_start(dconf->bfa, &dconf->timer,
5789 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5790 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
5791 break;
5792 case BFA_DCONF_SM_EXIT:
5793 bfa_timer_start(dconf->bfa, &dconf->timer,
5794 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5795 bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync);
5796 break;
5797 case BFA_DCONF_SM_IOCDISABLE:
5798 bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty);
5799 break;
5800 default:
5801 bfa_sm_fault(dconf->bfa, event);
5802 }
5803}
5804
5805static void
5806bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf,
5807 enum bfa_dconf_event event)
5808{
5809 bfa_trc(dconf->bfa, event);
5810
5811 switch (event) {
5812 case BFA_DCONF_SM_INIT:
5813 bfa_timer_start(dconf->bfa, &dconf->timer,
5814 bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV);
5815 bfa_sm_set_state(dconf, bfa_dconf_sm_dirty);
5816 break;
5817 case BFA_DCONF_SM_EXIT:
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005818 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005819 bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005820 break;
5821 case BFA_DCONF_SM_IOCDISABLE:
5822 break;
5823 default:
5824 bfa_sm_fault(dconf->bfa, event);
5825 }
5826}
5827
5828/*
5829 * Compute and return memory needed by DRV_CFG module.
5830 */
5831static void
5832bfa_dconf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
5833 struct bfa_s *bfa)
5834{
5835 struct bfa_mem_kva_s *dconf_kva = BFA_MEM_DCONF_KVA(bfa);
5836
5837 if (cfg->drvcfg.min_cfg)
5838 bfa_mem_kva_setup(meminfo, dconf_kva,
5839 sizeof(struct bfa_dconf_hdr_s));
5840 else
5841 bfa_mem_kva_setup(meminfo, dconf_kva,
5842 sizeof(struct bfa_dconf_s));
5843}
5844
5845static void
5846bfa_dconf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
5847 struct bfa_pcidev_s *pcidev)
5848{
5849 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5850
5851 dconf->bfad = bfad;
5852 dconf->bfa = bfa;
5853 dconf->instance = bfa->ioc.port_id;
5854 bfa_trc(bfa, dconf->instance);
5855
5856 dconf->dconf = (struct bfa_dconf_s *) bfa_mem_kva_curp(dconf);
5857 if (cfg->drvcfg.min_cfg) {
5858 bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_hdr_s);
5859 dconf->min_cfg = BFA_TRUE;
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005860 } else {
5861 dconf->min_cfg = BFA_FALSE;
5862 bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_s);
5863 }
5864
5865 bfa_dconf_read_data_valid(bfa) = BFA_FALSE;
5866 bfa_sm_set_state(dconf, bfa_dconf_sm_uninit);
5867}
5868
5869static void
5870bfa_dconf_init_cb(void *arg, bfa_status_t status)
5871{
5872 struct bfa_s *bfa = arg;
5873 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5874
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005875 if (status == BFA_STATUS_OK) {
5876 bfa_dconf_read_data_valid(bfa) = BFA_TRUE;
5877 if (dconf->dconf->hdr.signature != BFI_DCONF_SIGNATURE)
5878 dconf->dconf->hdr.signature = BFI_DCONF_SIGNATURE;
5879 if (dconf->dconf->hdr.version != BFI_DCONF_VERSION)
5880 dconf->dconf->hdr.version = BFI_DCONF_VERSION;
5881 }
Krishna Gudipati7ac83b12012-09-21 17:24:21 -07005882 bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
Krishna Gudipatidb9d8a72012-03-13 17:39:36 -07005883 bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DCONF_DONE);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005884}
5885
5886void
5887bfa_dconf_modinit(struct bfa_s *bfa)
5888{
5889 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5890 bfa_sm_send_event(dconf, BFA_DCONF_SM_INIT);
5891}
5892static void
5893bfa_dconf_start(struct bfa_s *bfa)
5894{
5895}
5896
5897static void
5898bfa_dconf_stop(struct bfa_s *bfa)
5899{
5900}
5901
5902static void bfa_dconf_timer(void *cbarg)
5903{
5904 struct bfa_dconf_mod_s *dconf = cbarg;
5905 bfa_sm_send_event(dconf, BFA_DCONF_SM_TIMEOUT);
5906}
5907static void
5908bfa_dconf_iocdisable(struct bfa_s *bfa)
5909{
5910 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5911 bfa_sm_send_event(dconf, BFA_DCONF_SM_IOCDISABLE);
5912}
5913
5914static void
5915bfa_dconf_detach(struct bfa_s *bfa)
5916{
5917}
5918
5919static bfa_status_t
5920bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf)
5921{
5922 bfa_status_t bfa_status;
5923 bfa_trc(dconf->bfa, 0);
5924
5925 bfa_status = bfa_flash_update_part(BFA_FLASH(dconf->bfa),
5926 BFA_FLASH_PART_DRV, dconf->instance,
5927 dconf->dconf, sizeof(struct bfa_dconf_s), 0,
5928 bfa_dconf_cbfn, dconf);
5929 if (bfa_status != BFA_STATUS_OK)
5930 WARN_ON(bfa_status);
5931 bfa_trc(dconf->bfa, bfa_status);
5932
5933 return bfa_status;
5934}
5935
5936bfa_status_t
5937bfa_dconf_update(struct bfa_s *bfa)
5938{
5939 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
5940 bfa_trc(dconf->bfa, 0);
5941 if (bfa_sm_cmp_state(dconf, bfa_dconf_sm_iocdown_dirty))
5942 return BFA_STATUS_FAILED;
5943
5944 if (dconf->min_cfg) {
5945 bfa_trc(dconf->bfa, dconf->min_cfg);
5946 return BFA_STATUS_FAILED;
5947 }
5948
5949 bfa_sm_send_event(dconf, BFA_DCONF_SM_WR);
5950 return BFA_STATUS_OK;
5951}
5952
5953static void
5954bfa_dconf_cbfn(void *arg, bfa_status_t status)
5955{
5956 struct bfa_dconf_mod_s *dconf = arg;
5957 WARN_ON(status);
5958 bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP);
5959}
5960
5961void
5962bfa_dconf_modexit(struct bfa_s *bfa)
5963{
5964 struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa);
Krishna Gudipati45c5dc12011-07-20 17:03:46 -07005965 bfa_sm_send_event(dconf, BFA_DCONF_SM_EXIT);
5966}
Krishna Gudipatie6826c92012-09-21 17:27:14 -07005967
5968/*
5969 * FRU specific functions
5970 */
5971
5972#define BFA_FRU_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
5973#define BFA_FRU_CHINOOK_MAX_SIZE 0x10000
5974#define BFA_FRU_LIGHTNING_MAX_SIZE 0x200
5975
5976static void
5977bfa_fru_notify(void *cbarg, enum bfa_ioc_event_e event)
5978{
5979 struct bfa_fru_s *fru = cbarg;
5980
5981 bfa_trc(fru, event);
5982
5983 switch (event) {
5984 case BFA_IOC_E_DISABLED:
5985 case BFA_IOC_E_FAILED:
5986 if (fru->op_busy) {
5987 fru->status = BFA_STATUS_IOC_FAILURE;
5988 fru->cbfn(fru->cbarg, fru->status);
5989 fru->op_busy = 0;
5990 }
5991 break;
5992
5993 default:
5994 break;
5995 }
5996}
5997
5998/*
5999 * Send fru write request.
6000 *
6001 * @param[in] cbarg - callback argument
6002 */
6003static void
6004bfa_fru_write_send(void *cbarg, enum bfi_fru_h2i_msgs msg_type)
6005{
6006 struct bfa_fru_s *fru = cbarg;
6007 struct bfi_fru_write_req_s *msg =
6008 (struct bfi_fru_write_req_s *) fru->mb.msg;
6009 u32 len;
6010
6011 msg->offset = cpu_to_be32(fru->addr_off + fru->offset);
6012 len = (fru->residue < BFA_FRU_DMA_BUF_SZ) ?
6013 fru->residue : BFA_FRU_DMA_BUF_SZ;
6014 msg->length = cpu_to_be32(len);
6015
6016 /*
6017 * indicate if it's the last msg of the whole write operation
6018 */
6019 msg->last = (len == fru->residue) ? 1 : 0;
6020
6021 bfi_h2i_set(msg->mh, BFI_MC_FRU, msg_type, bfa_ioc_portid(fru->ioc));
6022 bfa_alen_set(&msg->alen, len, fru->dbuf_pa);
6023
6024 memcpy(fru->dbuf_kva, fru->ubuf + fru->offset, len);
6025 bfa_ioc_mbox_queue(fru->ioc, &fru->mb);
6026
6027 fru->residue -= len;
6028 fru->offset += len;
6029}
6030
6031/*
6032 * Send fru read request.
6033 *
6034 * @param[in] cbarg - callback argument
6035 */
6036static void
6037bfa_fru_read_send(void *cbarg, enum bfi_fru_h2i_msgs msg_type)
6038{
6039 struct bfa_fru_s *fru = cbarg;
6040 struct bfi_fru_read_req_s *msg =
6041 (struct bfi_fru_read_req_s *) fru->mb.msg;
6042 u32 len;
6043
6044 msg->offset = cpu_to_be32(fru->addr_off + fru->offset);
6045 len = (fru->residue < BFA_FRU_DMA_BUF_SZ) ?
6046 fru->residue : BFA_FRU_DMA_BUF_SZ;
6047 msg->length = cpu_to_be32(len);
6048 bfi_h2i_set(msg->mh, BFI_MC_FRU, msg_type, bfa_ioc_portid(fru->ioc));
6049 bfa_alen_set(&msg->alen, len, fru->dbuf_pa);
6050 bfa_ioc_mbox_queue(fru->ioc, &fru->mb);
6051}
6052
6053/*
6054 * Flash memory info API.
6055 *
6056 * @param[in] mincfg - minimal cfg variable
6057 */
6058u32
6059bfa_fru_meminfo(bfa_boolean_t mincfg)
6060{
6061 /* min driver doesn't need fru */
6062 if (mincfg)
6063 return 0;
6064
6065 return BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
6066}
6067
6068/*
6069 * Flash attach API.
6070 *
6071 * @param[in] fru - fru structure
6072 * @param[in] ioc - ioc structure
6073 * @param[in] dev - device structure
6074 * @param[in] trcmod - trace module
6075 * @param[in] logmod - log module
6076 */
6077void
6078bfa_fru_attach(struct bfa_fru_s *fru, struct bfa_ioc_s *ioc, void *dev,
6079 struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg)
6080{
6081 fru->ioc = ioc;
6082 fru->trcmod = trcmod;
6083 fru->cbfn = NULL;
6084 fru->cbarg = NULL;
6085 fru->op_busy = 0;
6086
6087 bfa_ioc_mbox_regisr(fru->ioc, BFI_MC_FRU, bfa_fru_intr, fru);
6088 bfa_q_qe_init(&fru->ioc_notify);
6089 bfa_ioc_notify_init(&fru->ioc_notify, bfa_fru_notify, fru);
6090 list_add_tail(&fru->ioc_notify.qe, &fru->ioc->notify_q);
6091
6092 /* min driver doesn't need fru */
6093 if (mincfg) {
6094 fru->dbuf_kva = NULL;
6095 fru->dbuf_pa = 0;
6096 }
6097}
6098
6099/*
6100 * Claim memory for fru
6101 *
6102 * @param[in] fru - fru structure
6103 * @param[in] dm_kva - pointer to virtual memory address
6104 * @param[in] dm_pa - frusical memory address
6105 * @param[in] mincfg - minimal cfg variable
6106 */
6107void
6108bfa_fru_memclaim(struct bfa_fru_s *fru, u8 *dm_kva, u64 dm_pa,
6109 bfa_boolean_t mincfg)
6110{
6111 if (mincfg)
6112 return;
6113
6114 fru->dbuf_kva = dm_kva;
6115 fru->dbuf_pa = dm_pa;
6116 memset(fru->dbuf_kva, 0, BFA_FRU_DMA_BUF_SZ);
6117 dm_kva += BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
6118 dm_pa += BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ);
6119}
6120
6121/*
6122 * Update fru vpd image.
6123 *
6124 * @param[in] fru - fru structure
6125 * @param[in] buf - update data buffer
6126 * @param[in] len - data buffer length
6127 * @param[in] offset - offset relative to starting address
6128 * @param[in] cbfn - callback function
6129 * @param[in] cbarg - callback argument
6130 *
6131 * Return status.
6132 */
6133bfa_status_t
6134bfa_fruvpd_update(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
6135 bfa_cb_fru_t cbfn, void *cbarg)
6136{
6137 bfa_trc(fru, BFI_FRUVPD_H2I_WRITE_REQ);
6138 bfa_trc(fru, len);
6139 bfa_trc(fru, offset);
6140
6141 if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
6142 return BFA_STATUS_FRU_NOT_PRESENT;
6143
6144 if (fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK)
6145 return BFA_STATUS_CMD_NOTSUPP;
6146
6147 if (!bfa_ioc_is_operational(fru->ioc))
6148 return BFA_STATUS_IOC_NON_OP;
6149
6150 if (fru->op_busy) {
6151 bfa_trc(fru, fru->op_busy);
6152 return BFA_STATUS_DEVBUSY;
6153 }
6154
6155 fru->op_busy = 1;
6156
6157 fru->cbfn = cbfn;
6158 fru->cbarg = cbarg;
6159 fru->residue = len;
6160 fru->offset = 0;
6161 fru->addr_off = offset;
6162 fru->ubuf = buf;
6163
6164 bfa_fru_write_send(fru, BFI_FRUVPD_H2I_WRITE_REQ);
6165
6166 return BFA_STATUS_OK;
6167}
6168
6169/*
6170 * Read fru vpd image.
6171 *
6172 * @param[in] fru - fru structure
6173 * @param[in] buf - read data buffer
6174 * @param[in] len - data buffer length
6175 * @param[in] offset - offset relative to starting address
6176 * @param[in] cbfn - callback function
6177 * @param[in] cbarg - callback argument
6178 *
6179 * Return status.
6180 */
6181bfa_status_t
6182bfa_fruvpd_read(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
6183 bfa_cb_fru_t cbfn, void *cbarg)
6184{
6185 bfa_trc(fru, BFI_FRUVPD_H2I_READ_REQ);
6186 bfa_trc(fru, len);
6187 bfa_trc(fru, offset);
6188
6189 if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
6190 return BFA_STATUS_FRU_NOT_PRESENT;
6191
6192 if (fru->ioc->attr->card_type != BFA_MFG_TYPE_CHINOOK)
6193 return BFA_STATUS_CMD_NOTSUPP;
6194
6195 if (!bfa_ioc_is_operational(fru->ioc))
6196 return BFA_STATUS_IOC_NON_OP;
6197
6198 if (fru->op_busy) {
6199 bfa_trc(fru, fru->op_busy);
6200 return BFA_STATUS_DEVBUSY;
6201 }
6202
6203 fru->op_busy = 1;
6204
6205 fru->cbfn = cbfn;
6206 fru->cbarg = cbarg;
6207 fru->residue = len;
6208 fru->offset = 0;
6209 fru->addr_off = offset;
6210 fru->ubuf = buf;
6211 bfa_fru_read_send(fru, BFI_FRUVPD_H2I_READ_REQ);
6212
6213 return BFA_STATUS_OK;
6214}
6215
6216/*
6217 * Get maximum size fru vpd image.
6218 *
6219 * @param[in] fru - fru structure
6220 * @param[out] size - maximum size of fru vpd data
6221 *
6222 * Return status.
6223 */
6224bfa_status_t
6225bfa_fruvpd_get_max_size(struct bfa_fru_s *fru, u32 *max_size)
6226{
6227 if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
6228 return BFA_STATUS_FRU_NOT_PRESENT;
6229
6230 if (!bfa_ioc_is_operational(fru->ioc))
6231 return BFA_STATUS_IOC_NON_OP;
6232
6233 if (fru->ioc->attr->card_type == BFA_MFG_TYPE_CHINOOK)
6234 *max_size = BFA_FRU_CHINOOK_MAX_SIZE;
6235 else
6236 return BFA_STATUS_CMD_NOTSUPP;
6237 return BFA_STATUS_OK;
6238}
6239/*
6240 * tfru write.
6241 *
6242 * @param[in] fru - fru structure
6243 * @param[in] buf - update data buffer
6244 * @param[in] len - data buffer length
6245 * @param[in] offset - offset relative to starting address
6246 * @param[in] cbfn - callback function
6247 * @param[in] cbarg - callback argument
6248 *
6249 * Return status.
6250 */
6251bfa_status_t
6252bfa_tfru_write(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
6253 bfa_cb_fru_t cbfn, void *cbarg)
6254{
6255 bfa_trc(fru, BFI_TFRU_H2I_WRITE_REQ);
6256 bfa_trc(fru, len);
6257 bfa_trc(fru, offset);
6258 bfa_trc(fru, *((u8 *) buf));
6259
6260 if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
6261 return BFA_STATUS_FRU_NOT_PRESENT;
6262
6263 if (!bfa_ioc_is_operational(fru->ioc))
6264 return BFA_STATUS_IOC_NON_OP;
6265
6266 if (fru->op_busy) {
6267 bfa_trc(fru, fru->op_busy);
6268 return BFA_STATUS_DEVBUSY;
6269 }
6270
6271 fru->op_busy = 1;
6272
6273 fru->cbfn = cbfn;
6274 fru->cbarg = cbarg;
6275 fru->residue = len;
6276 fru->offset = 0;
6277 fru->addr_off = offset;
6278 fru->ubuf = buf;
6279
6280 bfa_fru_write_send(fru, BFI_TFRU_H2I_WRITE_REQ);
6281
6282 return BFA_STATUS_OK;
6283}
6284
6285/*
6286 * tfru read.
6287 *
6288 * @param[in] fru - fru structure
6289 * @param[in] buf - read data buffer
6290 * @param[in] len - data buffer length
6291 * @param[in] offset - offset relative to starting address
6292 * @param[in] cbfn - callback function
6293 * @param[in] cbarg - callback argument
6294 *
6295 * Return status.
6296 */
6297bfa_status_t
6298bfa_tfru_read(struct bfa_fru_s *fru, void *buf, u32 len, u32 offset,
6299 bfa_cb_fru_t cbfn, void *cbarg)
6300{
6301 bfa_trc(fru, BFI_TFRU_H2I_READ_REQ);
6302 bfa_trc(fru, len);
6303 bfa_trc(fru, offset);
6304
6305 if (fru->ioc->asic_gen != BFI_ASIC_GEN_CT2)
6306 return BFA_STATUS_FRU_NOT_PRESENT;
6307
6308 if (!bfa_ioc_is_operational(fru->ioc))
6309 return BFA_STATUS_IOC_NON_OP;
6310
6311 if (fru->op_busy) {
6312 bfa_trc(fru, fru->op_busy);
6313 return BFA_STATUS_DEVBUSY;
6314 }
6315
6316 fru->op_busy = 1;
6317
6318 fru->cbfn = cbfn;
6319 fru->cbarg = cbarg;
6320 fru->residue = len;
6321 fru->offset = 0;
6322 fru->addr_off = offset;
6323 fru->ubuf = buf;
6324 bfa_fru_read_send(fru, BFI_TFRU_H2I_READ_REQ);
6325
6326 return BFA_STATUS_OK;
6327}
6328
6329/*
6330 * Process fru response messages upon receiving interrupts.
6331 *
6332 * @param[in] fruarg - fru structure
6333 * @param[in] msg - message structure
6334 */
6335void
6336bfa_fru_intr(void *fruarg, struct bfi_mbmsg_s *msg)
6337{
6338 struct bfa_fru_s *fru = fruarg;
6339 struct bfi_fru_rsp_s *rsp = (struct bfi_fru_rsp_s *)msg;
6340 u32 status;
6341
6342 bfa_trc(fru, msg->mh.msg_id);
6343
6344 if (!fru->op_busy) {
6345 /*
6346 * receiving response after ioc failure
6347 */
6348 bfa_trc(fru, 0x9999);
6349 return;
6350 }
6351
6352 switch (msg->mh.msg_id) {
6353 case BFI_FRUVPD_I2H_WRITE_RSP:
6354 case BFI_TFRU_I2H_WRITE_RSP:
6355 status = be32_to_cpu(rsp->status);
6356 bfa_trc(fru, status);
6357
6358 if (status != BFA_STATUS_OK || fru->residue == 0) {
6359 fru->status = status;
6360 fru->op_busy = 0;
6361 if (fru->cbfn)
6362 fru->cbfn(fru->cbarg, fru->status);
6363 } else {
6364 bfa_trc(fru, fru->offset);
6365 if (msg->mh.msg_id == BFI_FRUVPD_I2H_WRITE_RSP)
6366 bfa_fru_write_send(fru,
6367 BFI_FRUVPD_H2I_WRITE_REQ);
6368 else
6369 bfa_fru_write_send(fru,
6370 BFI_TFRU_H2I_WRITE_REQ);
6371 }
6372 break;
6373 case BFI_FRUVPD_I2H_READ_RSP:
6374 case BFI_TFRU_I2H_READ_RSP:
6375 status = be32_to_cpu(rsp->status);
6376 bfa_trc(fru, status);
6377
6378 if (status != BFA_STATUS_OK) {
6379 fru->status = status;
6380 fru->op_busy = 0;
6381 if (fru->cbfn)
6382 fru->cbfn(fru->cbarg, fru->status);
6383 } else {
6384 u32 len = be32_to_cpu(rsp->length);
6385
6386 bfa_trc(fru, fru->offset);
6387 bfa_trc(fru, len);
6388
6389 memcpy(fru->ubuf + fru->offset, fru->dbuf_kva, len);
6390 fru->residue -= len;
6391 fru->offset += len;
6392
6393 if (fru->residue == 0) {
6394 fru->status = status;
6395 fru->op_busy = 0;
6396 if (fru->cbfn)
6397 fru->cbfn(fru->cbarg, fru->status);
6398 } else {
6399 if (msg->mh.msg_id == BFI_FRUVPD_I2H_READ_RSP)
6400 bfa_fru_read_send(fru,
6401 BFI_FRUVPD_H2I_READ_REQ);
6402 else
6403 bfa_fru_read_send(fru,
6404 BFI_TFRU_H2I_READ_REQ);
6405 }
6406 }
6407 break;
6408 default:
6409 WARN_ON(1);
6410 }
6411}