2 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
3 * Copyright (c) 2014- QLogic Corporation.
7 * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License (GPL) Version 2 as
11 * published by the Free Software Foundation
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
24 #include "bfa_defs_svc.h"
27 BFA_TRC_FILE(CNA
, IOC
);
30 * IOC local definitions
32 #define BFA_IOC_TOV 3000 /* msecs */
33 #define BFA_IOC_HWSEM_TOV 500 /* msecs */
34 #define BFA_IOC_HB_TOV 500 /* msecs */
35 #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV
36 #define BFA_IOC_POLL_TOV BFA_TIMER_FREQ
38 #define bfa_ioc_timer_start(__ioc) \
39 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
40 bfa_ioc_timeout, (__ioc), BFA_IOC_TOV)
41 #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
43 #define bfa_hb_timer_start(__ioc) \
44 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \
45 bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV)
46 #define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer)
48 #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn))
50 #define bfa_ioc_state_disabled(__sm) \
51 (((__sm) == BFI_IOC_UNINIT) || \
52 ((__sm) == BFI_IOC_INITING) || \
53 ((__sm) == BFI_IOC_HWINIT) || \
54 ((__sm) == BFI_IOC_DISABLED) || \
55 ((__sm) == BFI_IOC_FAIL) || \
56 ((__sm) == BFI_IOC_CFG_DISABLED))
59 * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details.
62 #define bfa_ioc_firmware_lock(__ioc) \
63 ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc))
64 #define bfa_ioc_firmware_unlock(__ioc) \
65 ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc))
66 #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc))
67 #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc))
68 #define bfa_ioc_notify_fail(__ioc) \
69 ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc))
70 #define bfa_ioc_sync_start(__ioc) \
71 ((__ioc)->ioc_hwif->ioc_sync_start(__ioc))
72 #define bfa_ioc_sync_join(__ioc) \
73 ((__ioc)->ioc_hwif->ioc_sync_join(__ioc))
74 #define bfa_ioc_sync_leave(__ioc) \
75 ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc))
76 #define bfa_ioc_sync_ack(__ioc) \
77 ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc))
78 #define bfa_ioc_sync_complete(__ioc) \
79 ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc))
80 #define bfa_ioc_set_cur_ioc_fwstate(__ioc, __fwstate) \
81 ((__ioc)->ioc_hwif->ioc_set_fwstate(__ioc, __fwstate))
82 #define bfa_ioc_get_cur_ioc_fwstate(__ioc) \
83 ((__ioc)->ioc_hwif->ioc_get_fwstate(__ioc))
84 #define bfa_ioc_set_alt_ioc_fwstate(__ioc, __fwstate) \
85 ((__ioc)->ioc_hwif->ioc_set_alt_fwstate(__ioc, __fwstate))
86 #define bfa_ioc_get_alt_ioc_fwstate(__ioc) \
87 ((__ioc)->ioc_hwif->ioc_get_alt_fwstate(__ioc))
89 #define bfa_ioc_mbox_cmd_pending(__ioc) \
90 (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \
91 readl((__ioc)->ioc_regs.hfn_mbox_cmd))
93 bfa_boolean_t bfa_auto_recover
= BFA_TRUE
;
96 * forward declarations
98 static void bfa_ioc_hw_sem_get(struct bfa_ioc_s
*ioc
);
99 static void bfa_ioc_hwinit(struct bfa_ioc_s
*ioc
, bfa_boolean_t force
);
100 static void bfa_ioc_timeout(void *ioc
);
101 static void bfa_ioc_poll_fwinit(struct bfa_ioc_s
*ioc
);
102 static void bfa_ioc_send_enable(struct bfa_ioc_s
*ioc
);
103 static void bfa_ioc_send_disable(struct bfa_ioc_s
*ioc
);
104 static void bfa_ioc_send_getattr(struct bfa_ioc_s
*ioc
);
105 static void bfa_ioc_hb_monitor(struct bfa_ioc_s
*ioc
);
106 static void bfa_ioc_mbox_poll(struct bfa_ioc_s
*ioc
);
107 static void bfa_ioc_mbox_flush(struct bfa_ioc_s
*ioc
);
108 static void bfa_ioc_recover(struct bfa_ioc_s
*ioc
);
109 static void bfa_ioc_event_notify(struct bfa_ioc_s
*ioc
,
110 enum bfa_ioc_event_e event
);
111 static void bfa_ioc_disable_comp(struct bfa_ioc_s
*ioc
);
112 static void bfa_ioc_lpu_stop(struct bfa_ioc_s
*ioc
);
113 static void bfa_ioc_fail_notify(struct bfa_ioc_s
*ioc
);
114 static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s
*ioc
);
115 static enum bfi_ioc_img_ver_cmp_e
bfa_ioc_fw_ver_patch_cmp(
116 struct bfi_ioc_image_hdr_s
*base_fwhdr
,
117 struct bfi_ioc_image_hdr_s
*fwhdr_to_cmp
);
118 static enum bfi_ioc_img_ver_cmp_e
bfa_ioc_flash_fwver_cmp(
119 struct bfa_ioc_s
*ioc
,
120 struct bfi_ioc_image_hdr_s
*base_fwhdr
);
123 * IOC state machine definitions/declarations
126 IOC_E_RESET
= 1, /* IOC reset request */
127 IOC_E_ENABLE
= 2, /* IOC enable request */
128 IOC_E_DISABLE
= 3, /* IOC disable request */
129 IOC_E_DETACH
= 4, /* driver detach cleanup */
130 IOC_E_ENABLED
= 5, /* f/w enabled */
131 IOC_E_FWRSP_GETATTR
= 6, /* IOC get attribute response */
132 IOC_E_DISABLED
= 7, /* f/w disabled */
133 IOC_E_PFFAILED
= 8, /* failure notice by iocpf sm */
134 IOC_E_HBFAIL
= 9, /* heartbeat failure */
135 IOC_E_HWERROR
= 10, /* hardware error interrupt */
136 IOC_E_TIMEOUT
= 11, /* timeout */
137 IOC_E_HWFAILED
= 12, /* PCI mapping failure notice */
140 bfa_fsm_state_decl(bfa_ioc
, uninit
, struct bfa_ioc_s
, enum ioc_event
);
141 bfa_fsm_state_decl(bfa_ioc
, reset
, struct bfa_ioc_s
, enum ioc_event
);
142 bfa_fsm_state_decl(bfa_ioc
, enabling
, struct bfa_ioc_s
, enum ioc_event
);
143 bfa_fsm_state_decl(bfa_ioc
, getattr
, struct bfa_ioc_s
, enum ioc_event
);
144 bfa_fsm_state_decl(bfa_ioc
, op
, struct bfa_ioc_s
, enum ioc_event
);
145 bfa_fsm_state_decl(bfa_ioc
, fail_retry
, struct bfa_ioc_s
, enum ioc_event
);
146 bfa_fsm_state_decl(bfa_ioc
, fail
, struct bfa_ioc_s
, enum ioc_event
);
147 bfa_fsm_state_decl(bfa_ioc
, disabling
, struct bfa_ioc_s
, enum ioc_event
);
148 bfa_fsm_state_decl(bfa_ioc
, disabled
, struct bfa_ioc_s
, enum ioc_event
);
149 bfa_fsm_state_decl(bfa_ioc
, hwfail
, struct bfa_ioc_s
, enum ioc_event
);
151 static struct bfa_sm_table_s ioc_sm_table
[] = {
152 {BFA_SM(bfa_ioc_sm_uninit
), BFA_IOC_UNINIT
},
153 {BFA_SM(bfa_ioc_sm_reset
), BFA_IOC_RESET
},
154 {BFA_SM(bfa_ioc_sm_enabling
), BFA_IOC_ENABLING
},
155 {BFA_SM(bfa_ioc_sm_getattr
), BFA_IOC_GETATTR
},
156 {BFA_SM(bfa_ioc_sm_op
), BFA_IOC_OPERATIONAL
},
157 {BFA_SM(bfa_ioc_sm_fail_retry
), BFA_IOC_INITFAIL
},
158 {BFA_SM(bfa_ioc_sm_fail
), BFA_IOC_FAIL
},
159 {BFA_SM(bfa_ioc_sm_disabling
), BFA_IOC_DISABLING
},
160 {BFA_SM(bfa_ioc_sm_disabled
), BFA_IOC_DISABLED
},
161 {BFA_SM(bfa_ioc_sm_hwfail
), BFA_IOC_HWFAIL
},
165 * IOCPF state machine definitions/declarations
168 #define bfa_iocpf_timer_start(__ioc) \
169 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
170 bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV)
171 #define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer)
173 #define bfa_iocpf_poll_timer_start(__ioc) \
174 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \
175 bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV)
177 #define bfa_sem_timer_start(__ioc) \
178 bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \
179 bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV)
180 #define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer)
183 * Forward declareations for iocpf state machine
185 static void bfa_iocpf_timeout(void *ioc_arg
);
186 static void bfa_iocpf_sem_timeout(void *ioc_arg
);
187 static void bfa_iocpf_poll_timeout(void *ioc_arg
);
190 * IOCPF state machine events
193 IOCPF_E_ENABLE
= 1, /* IOCPF enable request */
194 IOCPF_E_DISABLE
= 2, /* IOCPF disable request */
195 IOCPF_E_STOP
= 3, /* stop on driver detach */
196 IOCPF_E_FWREADY
= 4, /* f/w initialization done */
197 IOCPF_E_FWRSP_ENABLE
= 5, /* enable f/w response */
198 IOCPF_E_FWRSP_DISABLE
= 6, /* disable f/w response */
199 IOCPF_E_FAIL
= 7, /* failure notice by ioc sm */
200 IOCPF_E_INITFAIL
= 8, /* init fail notice by ioc sm */
201 IOCPF_E_GETATTRFAIL
= 9, /* init fail notice by ioc sm */
202 IOCPF_E_SEMLOCKED
= 10, /* h/w semaphore is locked */
203 IOCPF_E_TIMEOUT
= 11, /* f/w response timeout */
204 IOCPF_E_SEM_ERROR
= 12, /* h/w sem mapping error */
210 enum bfa_iocpf_state
{
211 BFA_IOCPF_RESET
= 1, /* IOC is in reset state */
212 BFA_IOCPF_SEMWAIT
= 2, /* Waiting for IOC h/w semaphore */
213 BFA_IOCPF_HWINIT
= 3, /* IOC h/w is being initialized */
214 BFA_IOCPF_READY
= 4, /* IOCPF is initialized */
215 BFA_IOCPF_INITFAIL
= 5, /* IOCPF failed */
216 BFA_IOCPF_FAIL
= 6, /* IOCPF failed */
217 BFA_IOCPF_DISABLING
= 7, /* IOCPF is being disabled */
218 BFA_IOCPF_DISABLED
= 8, /* IOCPF is disabled */
219 BFA_IOCPF_FWMISMATCH
= 9, /* IOC f/w different from drivers */
222 bfa_fsm_state_decl(bfa_iocpf
, reset
, struct bfa_iocpf_s
, enum iocpf_event
);
223 bfa_fsm_state_decl(bfa_iocpf
, fwcheck
, struct bfa_iocpf_s
, enum iocpf_event
);
224 bfa_fsm_state_decl(bfa_iocpf
, mismatch
, struct bfa_iocpf_s
, enum iocpf_event
);
225 bfa_fsm_state_decl(bfa_iocpf
, semwait
, struct bfa_iocpf_s
, enum iocpf_event
);
226 bfa_fsm_state_decl(bfa_iocpf
, hwinit
, struct bfa_iocpf_s
, enum iocpf_event
);
227 bfa_fsm_state_decl(bfa_iocpf
, enabling
, struct bfa_iocpf_s
, enum iocpf_event
);
228 bfa_fsm_state_decl(bfa_iocpf
, ready
, struct bfa_iocpf_s
, enum iocpf_event
);
229 bfa_fsm_state_decl(bfa_iocpf
, initfail_sync
, struct bfa_iocpf_s
,
231 bfa_fsm_state_decl(bfa_iocpf
, initfail
, struct bfa_iocpf_s
, enum iocpf_event
);
232 bfa_fsm_state_decl(bfa_iocpf
, fail_sync
, struct bfa_iocpf_s
, enum iocpf_event
);
233 bfa_fsm_state_decl(bfa_iocpf
, fail
, struct bfa_iocpf_s
, enum iocpf_event
);
234 bfa_fsm_state_decl(bfa_iocpf
, disabling
, struct bfa_iocpf_s
, enum iocpf_event
);
235 bfa_fsm_state_decl(bfa_iocpf
, disabling_sync
, struct bfa_iocpf_s
,
237 bfa_fsm_state_decl(bfa_iocpf
, disabled
, struct bfa_iocpf_s
, enum iocpf_event
);
239 static struct bfa_sm_table_s iocpf_sm_table
[] = {
240 {BFA_SM(bfa_iocpf_sm_reset
), BFA_IOCPF_RESET
},
241 {BFA_SM(bfa_iocpf_sm_fwcheck
), BFA_IOCPF_FWMISMATCH
},
242 {BFA_SM(bfa_iocpf_sm_mismatch
), BFA_IOCPF_FWMISMATCH
},
243 {BFA_SM(bfa_iocpf_sm_semwait
), BFA_IOCPF_SEMWAIT
},
244 {BFA_SM(bfa_iocpf_sm_hwinit
), BFA_IOCPF_HWINIT
},
245 {BFA_SM(bfa_iocpf_sm_enabling
), BFA_IOCPF_HWINIT
},
246 {BFA_SM(bfa_iocpf_sm_ready
), BFA_IOCPF_READY
},
247 {BFA_SM(bfa_iocpf_sm_initfail_sync
), BFA_IOCPF_INITFAIL
},
248 {BFA_SM(bfa_iocpf_sm_initfail
), BFA_IOCPF_INITFAIL
},
249 {BFA_SM(bfa_iocpf_sm_fail_sync
), BFA_IOCPF_FAIL
},
250 {BFA_SM(bfa_iocpf_sm_fail
), BFA_IOCPF_FAIL
},
251 {BFA_SM(bfa_iocpf_sm_disabling
), BFA_IOCPF_DISABLING
},
252 {BFA_SM(bfa_iocpf_sm_disabling_sync
), BFA_IOCPF_DISABLING
},
253 {BFA_SM(bfa_iocpf_sm_disabled
), BFA_IOCPF_DISABLED
},
261 * Beginning state. IOC uninit state.
265 bfa_ioc_sm_uninit_entry(struct bfa_ioc_s
*ioc
)
270 * IOC is in uninit state.
273 bfa_ioc_sm_uninit(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
279 bfa_fsm_set_state(ioc
, bfa_ioc_sm_reset
);
283 bfa_sm_fault(ioc
, event
);
287 * Reset entry actions -- initialize state machine
290 bfa_ioc_sm_reset_entry(struct bfa_ioc_s
*ioc
)
292 bfa_fsm_set_state(&ioc
->iocpf
, bfa_iocpf_sm_reset
);
296 * IOC is in reset state.
299 bfa_ioc_sm_reset(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
305 bfa_fsm_set_state(ioc
, bfa_ioc_sm_enabling
);
309 bfa_ioc_disable_comp(ioc
);
313 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
317 bfa_sm_fault(ioc
, event
);
323 bfa_ioc_sm_enabling_entry(struct bfa_ioc_s
*ioc
)
325 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_ENABLE
);
329 * Host IOC function is being enabled, awaiting response from firmware.
330 * Semaphore is acquired.
333 bfa_ioc_sm_enabling(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
339 bfa_fsm_set_state(ioc
, bfa_ioc_sm_getattr
);
343 /* !!! fall through !!! */
345 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
346 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
347 if (event
!= IOC_E_PFFAILED
)
348 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_INITFAIL
);
352 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
353 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
357 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
361 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
362 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_STOP
);
369 bfa_sm_fault(ioc
, event
);
375 bfa_ioc_sm_getattr_entry(struct bfa_ioc_s
*ioc
)
377 bfa_ioc_timer_start(ioc
);
378 bfa_ioc_send_getattr(ioc
);
382 * IOC configuration in progress. Timer is active.
385 bfa_ioc_sm_getattr(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
390 case IOC_E_FWRSP_GETATTR
:
391 bfa_ioc_timer_stop(ioc
);
392 bfa_fsm_set_state(ioc
, bfa_ioc_sm_op
);
397 bfa_ioc_timer_stop(ioc
);
398 /* !!! fall through !!! */
400 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
401 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
402 if (event
!= IOC_E_PFFAILED
)
403 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_GETATTRFAIL
);
407 bfa_ioc_timer_stop(ioc
);
408 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
415 bfa_sm_fault(ioc
, event
);
420 bfa_ioc_sm_op_entry(struct bfa_ioc_s
*ioc
)
422 struct bfad_s
*bfad
= (struct bfad_s
*)ioc
->bfa
->bfad
;
424 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_OK
);
425 bfa_ioc_event_notify(ioc
, BFA_IOC_E_ENABLED
);
426 bfa_ioc_hb_monitor(ioc
);
427 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
, "IOC enabled\n");
428 bfa_ioc_aen_post(ioc
, BFA_IOC_AEN_ENABLE
);
432 bfa_ioc_sm_op(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
441 bfa_hb_timer_stop(ioc
);
442 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
447 bfa_hb_timer_stop(ioc
);
448 /* !!! fall through !!! */
450 if (ioc
->iocpf
.auto_recover
)
451 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail_retry
);
453 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
455 bfa_ioc_fail_notify(ioc
);
457 if (event
!= IOC_E_PFFAILED
)
458 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FAIL
);
462 bfa_sm_fault(ioc
, event
);
468 bfa_ioc_sm_disabling_entry(struct bfa_ioc_s
*ioc
)
470 struct bfad_s
*bfad
= (struct bfad_s
*)ioc
->bfa
->bfad
;
471 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_DISABLE
);
472 BFA_LOG(KERN_INFO
, bfad
, bfa_log_level
, "IOC disabled\n");
473 bfa_ioc_aen_post(ioc
, BFA_IOC_AEN_DISABLE
);
477 * IOC is being disabled
480 bfa_ioc_sm_disabling(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
486 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabled
);
491 * No state change. Will move to disabled state
492 * after iocpf sm completes failure processing and
493 * moves to disabled state.
495 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FAIL
);
499 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
500 bfa_ioc_disable_comp(ioc
);
504 bfa_sm_fault(ioc
, event
);
509 * IOC disable completion entry.
512 bfa_ioc_sm_disabled_entry(struct bfa_ioc_s
*ioc
)
514 bfa_ioc_disable_comp(ioc
);
518 bfa_ioc_sm_disabled(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
524 bfa_fsm_set_state(ioc
, bfa_ioc_sm_enabling
);
528 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
532 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
533 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_STOP
);
537 bfa_sm_fault(ioc
, event
);
543 bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s
*ioc
)
549 * Hardware initialization retry.
552 bfa_ioc_sm_fail_retry(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
558 bfa_fsm_set_state(ioc
, bfa_ioc_sm_getattr
);
564 * Initialization retry failed.
566 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
567 bfa_fsm_set_state(ioc
, bfa_ioc_sm_fail
);
568 if (event
!= IOC_E_PFFAILED
)
569 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_INITFAIL
);
573 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
574 bfa_fsm_set_state(ioc
, bfa_ioc_sm_hwfail
);
581 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
585 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
586 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_STOP
);
590 bfa_sm_fault(ioc
, event
);
596 bfa_ioc_sm_fail_entry(struct bfa_ioc_s
*ioc
)
605 bfa_ioc_sm_fail(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
612 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
616 bfa_fsm_set_state(ioc
, bfa_ioc_sm_disabling
);
620 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
621 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_STOP
);
627 * HB failure / HW error notification, ignore.
631 bfa_sm_fault(ioc
, event
);
636 bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s
*ioc
)
642 bfa_ioc_sm_hwfail(struct bfa_ioc_s
*ioc
, enum ioc_event event
)
648 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
652 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
656 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
660 /* Ignore - already in hwfail state */
664 bfa_sm_fault(ioc
, event
);
669 * IOCPF State Machine
673 * Reset entry actions -- initialize state machine
676 bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s
*iocpf
)
678 iocpf
->fw_mismatch_notified
= BFA_FALSE
;
679 iocpf
->auto_recover
= bfa_auto_recover
;
683 * Beginning state. IOC is in reset state.
686 bfa_iocpf_sm_reset(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
688 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
694 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fwcheck
);
701 bfa_sm_fault(ioc
, event
);
706 * Semaphore should be acquired for version check.
709 bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s
*iocpf
)
711 struct bfi_ioc_image_hdr_s fwhdr
;
712 u32 r32
, fwstate
, pgnum
, pgoff
, loff
= 0;
716 * Spin on init semaphore to serialize.
718 r32
= readl(iocpf
->ioc
->ioc_regs
.ioc_init_sem_reg
);
721 r32
= readl(iocpf
->ioc
->ioc_regs
.ioc_init_sem_reg
);
725 fwstate
= bfa_ioc_get_cur_ioc_fwstate(iocpf
->ioc
);
726 if (fwstate
== BFI_IOC_UNINIT
) {
727 writel(1, iocpf
->ioc
->ioc_regs
.ioc_init_sem_reg
);
731 bfa_ioc_fwver_get(iocpf
->ioc
, &fwhdr
);
733 if (swab32(fwhdr
.exec
) == BFI_FWBOOT_TYPE_NORMAL
) {
734 writel(1, iocpf
->ioc
->ioc_regs
.ioc_init_sem_reg
);
741 pgnum
= PSS_SMEM_PGNUM(iocpf
->ioc
->ioc_regs
.smem_pg0
, loff
);
742 pgoff
= PSS_SMEM_PGOFF(loff
);
743 writel(pgnum
, iocpf
->ioc
->ioc_regs
.host_page_num_fn
);
745 for (i
= 0; i
< sizeof(struct bfi_ioc_image_hdr_s
) / sizeof(u32
); i
++) {
746 bfa_mem_write(iocpf
->ioc
->ioc_regs
.smem_page_start
, loff
, 0);
750 bfa_trc(iocpf
->ioc
, fwstate
);
751 bfa_trc(iocpf
->ioc
, swab32(fwhdr
.exec
));
752 bfa_ioc_set_cur_ioc_fwstate(iocpf
->ioc
, BFI_IOC_UNINIT
);
753 bfa_ioc_set_alt_ioc_fwstate(iocpf
->ioc
, BFI_IOC_UNINIT
);
756 * Unlock the hw semaphore. Should be here only once per boot.
758 bfa_ioc_ownership_reset(iocpf
->ioc
);
761 * unlock init semaphore.
763 writel(1, iocpf
->ioc
->ioc_regs
.ioc_init_sem_reg
);
766 bfa_ioc_hw_sem_get(iocpf
->ioc
);
770 * Awaiting h/w semaphore to continue with version check.
773 bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
775 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
780 case IOCPF_E_SEMLOCKED
:
781 if (bfa_ioc_firmware_lock(ioc
)) {
782 if (bfa_ioc_sync_start(ioc
)) {
783 bfa_ioc_sync_join(ioc
);
784 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_hwinit
);
786 bfa_ioc_firmware_unlock(ioc
);
787 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
788 bfa_sem_timer_start(ioc
);
791 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
792 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_mismatch
);
796 case IOCPF_E_SEM_ERROR
:
797 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
798 bfa_fsm_send_event(ioc
, IOC_E_HWFAILED
);
801 case IOCPF_E_DISABLE
:
802 bfa_sem_timer_stop(ioc
);
803 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
804 bfa_fsm_send_event(ioc
, IOC_E_DISABLED
);
808 bfa_sem_timer_stop(ioc
);
809 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
813 bfa_sm_fault(ioc
, event
);
818 * Notify enable completion callback.
821 bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s
*iocpf
)
824 * Call only the first time sm enters fwmismatch state.
826 if (iocpf
->fw_mismatch_notified
== BFA_FALSE
)
827 bfa_ioc_pf_fwmismatch(iocpf
->ioc
);
829 iocpf
->fw_mismatch_notified
= BFA_TRUE
;
830 bfa_iocpf_timer_start(iocpf
->ioc
);
834 * Awaiting firmware version match.
837 bfa_iocpf_sm_mismatch(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
839 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
844 case IOCPF_E_TIMEOUT
:
845 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fwcheck
);
848 case IOCPF_E_DISABLE
:
849 bfa_iocpf_timer_stop(ioc
);
850 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
851 bfa_fsm_send_event(ioc
, IOC_E_DISABLED
);
855 bfa_iocpf_timer_stop(ioc
);
856 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
860 bfa_sm_fault(ioc
, event
);
865 * Request for semaphore.
868 bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s
*iocpf
)
870 bfa_ioc_hw_sem_get(iocpf
->ioc
);
874 * Awaiting semaphore for h/w initialzation.
877 bfa_iocpf_sm_semwait(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
879 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
884 case IOCPF_E_SEMLOCKED
:
885 if (bfa_ioc_sync_complete(ioc
)) {
886 bfa_ioc_sync_join(ioc
);
887 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_hwinit
);
889 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
890 bfa_sem_timer_start(ioc
);
894 case IOCPF_E_SEM_ERROR
:
895 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
896 bfa_fsm_send_event(ioc
, IOC_E_HWFAILED
);
899 case IOCPF_E_DISABLE
:
900 bfa_sem_timer_stop(ioc
);
901 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
905 bfa_sm_fault(ioc
, event
);
910 bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s
*iocpf
)
912 iocpf
->poll_time
= 0;
913 bfa_ioc_hwinit(iocpf
->ioc
, BFA_FALSE
);
917 * Hardware is being initialized. Interrupts are enabled.
918 * Holding hardware semaphore lock.
921 bfa_iocpf_sm_hwinit(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
923 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
928 case IOCPF_E_FWREADY
:
929 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_enabling
);
932 case IOCPF_E_TIMEOUT
:
933 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
934 bfa_fsm_send_event(ioc
, IOC_E_PFFAILED
);
935 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail_sync
);
938 case IOCPF_E_DISABLE
:
939 bfa_iocpf_timer_stop(ioc
);
940 bfa_ioc_sync_leave(ioc
);
941 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
942 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
946 bfa_sm_fault(ioc
, event
);
951 bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s
*iocpf
)
953 bfa_iocpf_timer_start(iocpf
->ioc
);
955 * Enable Interrupts before sending fw IOC ENABLE cmd.
957 iocpf
->ioc
->cbfn
->reset_cbfn(iocpf
->ioc
->bfa
);
958 bfa_ioc_send_enable(iocpf
->ioc
);
962 * Host IOC function is being enabled, awaiting response from firmware.
963 * Semaphore is acquired.
966 bfa_iocpf_sm_enabling(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
968 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
973 case IOCPF_E_FWRSP_ENABLE
:
974 bfa_iocpf_timer_stop(ioc
);
975 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
976 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_ready
);
979 case IOCPF_E_INITFAIL
:
980 bfa_iocpf_timer_stop(ioc
);
983 case IOCPF_E_TIMEOUT
:
984 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
985 if (event
== IOCPF_E_TIMEOUT
)
986 bfa_fsm_send_event(ioc
, IOC_E_PFFAILED
);
987 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail_sync
);
990 case IOCPF_E_DISABLE
:
991 bfa_iocpf_timer_stop(ioc
);
992 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
993 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling
);
997 bfa_sm_fault(ioc
, event
);
1002 bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s
*iocpf
)
1004 bfa_fsm_send_event(iocpf
->ioc
, IOC_E_ENABLED
);
1008 bfa_iocpf_sm_ready(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1010 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1012 bfa_trc(ioc
, event
);
1015 case IOCPF_E_DISABLE
:
1016 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling
);
1019 case IOCPF_E_GETATTRFAIL
:
1020 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail_sync
);
1024 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail_sync
);
1028 bfa_sm_fault(ioc
, event
);
1033 bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s
*iocpf
)
1035 bfa_iocpf_timer_start(iocpf
->ioc
);
1036 bfa_ioc_send_disable(iocpf
->ioc
);
1040 * IOC is being disabled
1043 bfa_iocpf_sm_disabling(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1045 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1047 bfa_trc(ioc
, event
);
1050 case IOCPF_E_FWRSP_DISABLE
:
1051 bfa_iocpf_timer_stop(ioc
);
1052 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1056 bfa_iocpf_timer_stop(ioc
);
1059 case IOCPF_E_TIMEOUT
:
1060 bfa_ioc_set_cur_ioc_fwstate(ioc
, BFI_IOC_FAIL
);
1061 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1064 case IOCPF_E_FWRSP_ENABLE
:
1068 bfa_sm_fault(ioc
, event
);
1073 bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s
*iocpf
)
1075 bfa_ioc_hw_sem_get(iocpf
->ioc
);
1079 * IOC hb ack request is being removed.
1082 bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1084 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1086 bfa_trc(ioc
, event
);
1089 case IOCPF_E_SEMLOCKED
:
1090 bfa_ioc_sync_leave(ioc
);
1091 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
1092 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
1095 case IOCPF_E_SEM_ERROR
:
1096 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1097 bfa_fsm_send_event(ioc
, IOC_E_HWFAILED
);
1104 bfa_sm_fault(ioc
, event
);
1109 * IOC disable completion entry.
1112 bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s
*iocpf
)
1114 bfa_ioc_mbox_flush(iocpf
->ioc
);
1115 bfa_fsm_send_event(iocpf
->ioc
, IOC_E_DISABLED
);
1119 bfa_iocpf_sm_disabled(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1121 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1123 bfa_trc(ioc
, event
);
1126 case IOCPF_E_ENABLE
:
1127 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_semwait
);
1131 bfa_ioc_firmware_unlock(ioc
);
1132 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
1136 bfa_sm_fault(ioc
, event
);
1141 bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s
*iocpf
)
1143 bfa_ioc_debug_save_ftrc(iocpf
->ioc
);
1144 bfa_ioc_hw_sem_get(iocpf
->ioc
);
1148 * Hardware initialization failed.
1151 bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1153 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1155 bfa_trc(ioc
, event
);
1158 case IOCPF_E_SEMLOCKED
:
1159 bfa_ioc_notify_fail(ioc
);
1160 bfa_ioc_sync_leave(ioc
);
1161 bfa_ioc_set_cur_ioc_fwstate(ioc
, BFI_IOC_FAIL
);
1162 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
1163 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_initfail
);
1166 case IOCPF_E_SEM_ERROR
:
1167 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1168 bfa_fsm_send_event(ioc
, IOC_E_HWFAILED
);
1171 case IOCPF_E_DISABLE
:
1172 bfa_sem_timer_stop(ioc
);
1173 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1177 bfa_sem_timer_stop(ioc
);
1178 bfa_ioc_firmware_unlock(ioc
);
1179 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
1186 bfa_sm_fault(ioc
, event
);
1191 bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s
*iocpf
)
1193 bfa_trc(iocpf
->ioc
, 0);
1197 * Hardware initialization failed.
1200 bfa_iocpf_sm_initfail(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1202 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1204 bfa_trc(ioc
, event
);
1207 case IOCPF_E_DISABLE
:
1208 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
1212 bfa_ioc_firmware_unlock(ioc
);
1213 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_reset
);
1217 bfa_sm_fault(ioc
, event
);
1222 bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s
*iocpf
)
1225 * Mark IOC as failed in hardware and stop firmware.
1227 bfa_ioc_lpu_stop(iocpf
->ioc
);
1230 * Flush any queued up mailbox requests.
1232 bfa_ioc_mbox_flush(iocpf
->ioc
);
1234 bfa_ioc_hw_sem_get(iocpf
->ioc
);
1238 bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1240 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1242 bfa_trc(ioc
, event
);
1245 case IOCPF_E_SEMLOCKED
:
1246 bfa_ioc_sync_ack(ioc
);
1247 bfa_ioc_notify_fail(ioc
);
1248 if (!iocpf
->auto_recover
) {
1249 bfa_ioc_sync_leave(ioc
);
1250 bfa_ioc_set_cur_ioc_fwstate(ioc
, BFI_IOC_FAIL
);
1251 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
1252 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1254 if (bfa_ioc_sync_complete(ioc
))
1255 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_hwinit
);
1257 writel(1, ioc
->ioc_regs
.ioc_sem_reg
);
1258 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_semwait
);
1263 case IOCPF_E_SEM_ERROR
:
1264 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_fail
);
1265 bfa_fsm_send_event(ioc
, IOC_E_HWFAILED
);
1268 case IOCPF_E_DISABLE
:
1269 bfa_sem_timer_stop(ioc
);
1270 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabling_sync
);
1277 bfa_sm_fault(ioc
, event
);
1282 bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s
*iocpf
)
1284 bfa_trc(iocpf
->ioc
, 0);
1288 * IOC is in failed state.
1291 bfa_iocpf_sm_fail(struct bfa_iocpf_s
*iocpf
, enum iocpf_event event
)
1293 struct bfa_ioc_s
*ioc
= iocpf
->ioc
;
1295 bfa_trc(ioc
, event
);
1298 case IOCPF_E_DISABLE
:
1299 bfa_fsm_set_state(iocpf
, bfa_iocpf_sm_disabled
);
1303 bfa_sm_fault(ioc
, event
);
1308 * BFA IOC private functions
1312 * Notify common modules registered for notification.
1315 bfa_ioc_event_notify(struct bfa_ioc_s
*ioc
, enum bfa_ioc_event_e event
)
1317 struct bfa_ioc_notify_s
*notify
;
1318 struct list_head
*qe
;
1320 list_for_each(qe
, &ioc
->notify_q
) {
1321 notify
= (struct bfa_ioc_notify_s
*)qe
;
1322 notify
->cbfn(notify
->cbarg
, event
);
1327 bfa_ioc_disable_comp(struct bfa_ioc_s
*ioc
)
1329 ioc
->cbfn
->disable_cbfn(ioc
->bfa
);
1330 bfa_ioc_event_notify(ioc
, BFA_IOC_E_DISABLED
);
1334 bfa_ioc_sem_get(void __iomem
*sem_reg
)
1338 #define BFA_SEM_SPINCNT 3000
1340 r32
= readl(sem_reg
);
1342 while ((r32
& 1) && (cnt
< BFA_SEM_SPINCNT
)) {
1345 r32
= readl(sem_reg
);
1355 bfa_ioc_hw_sem_get(struct bfa_ioc_s
*ioc
)
1360 * First read to the semaphore register will return 0, subsequent reads
1361 * will return 1. Semaphore is released by writing 1 to the register
1363 r32
= readl(ioc
->ioc_regs
.ioc_sem_reg
);
1366 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_SEM_ERROR
);
1370 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_SEMLOCKED
);
1374 bfa_sem_timer_start(ioc
);
1378 * Initialize LPU local memory (aka secondary memory / SRAM)
1381 bfa_ioc_lmem_init(struct bfa_ioc_s
*ioc
)
1385 #define PSS_LMEM_INIT_TIME 10000
1387 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1388 pss_ctl
&= ~__PSS_LMEM_RESET
;
1389 pss_ctl
|= __PSS_LMEM_INIT_EN
;
1392 * i2c workaround 12.5khz clock
1394 pss_ctl
|= __PSS_I2C_CLK_DIV(3UL);
1395 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1398 * wait for memory initialization to be complete
1402 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1404 } while (!(pss_ctl
& __PSS_LMEM_INIT_DONE
) && (i
< PSS_LMEM_INIT_TIME
));
1407 * If memory initialization is not successful, IOC timeout will catch
1410 WARN_ON(!(pss_ctl
& __PSS_LMEM_INIT_DONE
));
1411 bfa_trc(ioc
, pss_ctl
);
1413 pss_ctl
&= ~(__PSS_LMEM_INIT_DONE
| __PSS_LMEM_INIT_EN
);
1414 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1418 bfa_ioc_lpu_start(struct bfa_ioc_s
*ioc
)
1423 * Take processor out of reset.
1425 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1426 pss_ctl
&= ~__PSS_LPU0_RESET
;
1428 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1432 bfa_ioc_lpu_stop(struct bfa_ioc_s
*ioc
)
1437 * Put processors in reset.
1439 pss_ctl
= readl(ioc
->ioc_regs
.pss_ctl_reg
);
1440 pss_ctl
|= (__PSS_LPU0_RESET
| __PSS_LPU1_RESET
);
1442 writel(pss_ctl
, ioc
->ioc_regs
.pss_ctl_reg
);
1446 * Get driver and firmware versions.
1449 bfa_ioc_fwver_get(struct bfa_ioc_s
*ioc
, struct bfi_ioc_image_hdr_s
*fwhdr
)
1454 u32
*fwsig
= (u32
*) fwhdr
;
1456 pgnum
= PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, loff
);
1457 pgoff
= PSS_SMEM_PGOFF(loff
);
1458 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1460 for (i
= 0; i
< (sizeof(struct bfi_ioc_image_hdr_s
) / sizeof(u32
));
1463 bfa_mem_read(ioc
->ioc_regs
.smem_page_start
, loff
);
1464 loff
+= sizeof(u32
);
1469 * Returns TRUE if driver is willing to work with current smem f/w version.
1472 bfa_ioc_fwver_cmp(struct bfa_ioc_s
*ioc
,
1473 struct bfi_ioc_image_hdr_s
*smem_fwhdr
)
1475 struct bfi_ioc_image_hdr_s
*drv_fwhdr
;
1476 enum bfi_ioc_img_ver_cmp_e smem_flash_cmp
, drv_smem_cmp
;
1478 drv_fwhdr
= (struct bfi_ioc_image_hdr_s
*)
1479 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc
), 0);
1482 * If smem is incompatible or old, driver should not work with it.
1484 drv_smem_cmp
= bfa_ioc_fw_ver_patch_cmp(drv_fwhdr
, smem_fwhdr
);
1485 if (drv_smem_cmp
== BFI_IOC_IMG_VER_INCOMP
||
1486 drv_smem_cmp
== BFI_IOC_IMG_VER_OLD
) {
1491 * IF Flash has a better F/W than smem do not work with smem.
1492 * If smem f/w == flash f/w, as smem f/w not old | incmp, work with it.
1493 * If Flash is old or incomp work with smem iff smem f/w == drv f/w.
1495 smem_flash_cmp
= bfa_ioc_flash_fwver_cmp(ioc
, smem_fwhdr
);
1497 if (smem_flash_cmp
== BFI_IOC_IMG_VER_BETTER
) {
1499 } else if (smem_flash_cmp
== BFI_IOC_IMG_VER_SAME
) {
1502 return (drv_smem_cmp
== BFI_IOC_IMG_VER_SAME
) ?
1503 BFA_TRUE
: BFA_FALSE
;
1508 * Return true if current running version is valid. Firmware signature and
1509 * execution context (driver/bios) must match.
1511 static bfa_boolean_t
1512 bfa_ioc_fwver_valid(struct bfa_ioc_s
*ioc
, u32 boot_env
)
1514 struct bfi_ioc_image_hdr_s fwhdr
;
1516 bfa_ioc_fwver_get(ioc
, &fwhdr
);
1518 if (swab32(fwhdr
.bootenv
) != boot_env
) {
1519 bfa_trc(ioc
, fwhdr
.bootenv
);
1520 bfa_trc(ioc
, boot_env
);
1524 return bfa_ioc_fwver_cmp(ioc
, &fwhdr
);
1527 static bfa_boolean_t
1528 bfa_ioc_fwver_md5_check(struct bfi_ioc_image_hdr_s
*fwhdr_1
,
1529 struct bfi_ioc_image_hdr_s
*fwhdr_2
)
1533 for (i
= 0; i
< BFI_IOC_MD5SUM_SZ
; i
++)
1534 if (fwhdr_1
->md5sum
[i
] != fwhdr_2
->md5sum
[i
])
1541 * Returns TRUE if major minor and maintainence are same.
1542 * If patch versions are same, check for MD5 Checksum to be same.
1544 static bfa_boolean_t
1545 bfa_ioc_fw_ver_compatible(struct bfi_ioc_image_hdr_s
*drv_fwhdr
,
1546 struct bfi_ioc_image_hdr_s
*fwhdr_to_cmp
)
1548 if (drv_fwhdr
->signature
!= fwhdr_to_cmp
->signature
)
1551 if (drv_fwhdr
->fwver
.major
!= fwhdr_to_cmp
->fwver
.major
)
1554 if (drv_fwhdr
->fwver
.minor
!= fwhdr_to_cmp
->fwver
.minor
)
1557 if (drv_fwhdr
->fwver
.maint
!= fwhdr_to_cmp
->fwver
.maint
)
1560 if (drv_fwhdr
->fwver
.patch
== fwhdr_to_cmp
->fwver
.patch
&&
1561 drv_fwhdr
->fwver
.phase
== fwhdr_to_cmp
->fwver
.phase
&&
1562 drv_fwhdr
->fwver
.build
== fwhdr_to_cmp
->fwver
.build
) {
1563 return bfa_ioc_fwver_md5_check(drv_fwhdr
, fwhdr_to_cmp
);
1569 static bfa_boolean_t
1570 bfa_ioc_flash_fwver_valid(struct bfi_ioc_image_hdr_s
*flash_fwhdr
)
1572 if (flash_fwhdr
->fwver
.major
== 0 || flash_fwhdr
->fwver
.major
== 0xFF)
1578 static bfa_boolean_t
fwhdr_is_ga(struct bfi_ioc_image_hdr_s
*fwhdr
)
1580 if (fwhdr
->fwver
.phase
== 0 &&
1581 fwhdr
->fwver
.build
== 0)
1588 * Returns TRUE if both are compatible and patch of fwhdr_to_cmp is better.
1590 static enum bfi_ioc_img_ver_cmp_e
1591 bfa_ioc_fw_ver_patch_cmp(struct bfi_ioc_image_hdr_s
*base_fwhdr
,
1592 struct bfi_ioc_image_hdr_s
*fwhdr_to_cmp
)
1594 if (bfa_ioc_fw_ver_compatible(base_fwhdr
, fwhdr_to_cmp
) == BFA_FALSE
)
1595 return BFI_IOC_IMG_VER_INCOMP
;
1597 if (fwhdr_to_cmp
->fwver
.patch
> base_fwhdr
->fwver
.patch
)
1598 return BFI_IOC_IMG_VER_BETTER
;
1600 else if (fwhdr_to_cmp
->fwver
.patch
< base_fwhdr
->fwver
.patch
)
1601 return BFI_IOC_IMG_VER_OLD
;
1604 * GA takes priority over internal builds of the same patch stream.
1605 * At this point major minor maint and patch numbers are same.
1608 if (fwhdr_is_ga(base_fwhdr
) == BFA_TRUE
) {
1609 if (fwhdr_is_ga(fwhdr_to_cmp
))
1610 return BFI_IOC_IMG_VER_SAME
;
1612 return BFI_IOC_IMG_VER_OLD
;
1614 if (fwhdr_is_ga(fwhdr_to_cmp
))
1615 return BFI_IOC_IMG_VER_BETTER
;
1618 if (fwhdr_to_cmp
->fwver
.phase
> base_fwhdr
->fwver
.phase
)
1619 return BFI_IOC_IMG_VER_BETTER
;
1620 else if (fwhdr_to_cmp
->fwver
.phase
< base_fwhdr
->fwver
.phase
)
1621 return BFI_IOC_IMG_VER_OLD
;
1623 if (fwhdr_to_cmp
->fwver
.build
> base_fwhdr
->fwver
.build
)
1624 return BFI_IOC_IMG_VER_BETTER
;
1625 else if (fwhdr_to_cmp
->fwver
.build
< base_fwhdr
->fwver
.build
)
1626 return BFI_IOC_IMG_VER_OLD
;
1629 * All Version Numbers are equal.
1630 * Md5 check to be done as a part of compatibility check.
1632 return BFI_IOC_IMG_VER_SAME
;
1635 #define BFA_FLASH_PART_FWIMG_ADDR 0x100000 /* fw image address */
1638 bfa_ioc_flash_img_get_chnk(struct bfa_ioc_s
*ioc
, u32 off
,
1641 return bfa_flash_raw_read(ioc
->pcidev
.pci_bar_kva
,
1642 BFA_FLASH_PART_FWIMG_ADDR
+ (off
* sizeof(u32
)),
1643 (char *)fwimg
, BFI_FLASH_CHUNK_SZ
);
1646 static enum bfi_ioc_img_ver_cmp_e
1647 bfa_ioc_flash_fwver_cmp(struct bfa_ioc_s
*ioc
,
1648 struct bfi_ioc_image_hdr_s
*base_fwhdr
)
1650 struct bfi_ioc_image_hdr_s
*flash_fwhdr
;
1651 bfa_status_t status
;
1652 u32 fwimg
[BFI_FLASH_CHUNK_SZ_WORDS
];
1654 status
= bfa_ioc_flash_img_get_chnk(ioc
, 0, fwimg
);
1655 if (status
!= BFA_STATUS_OK
)
1656 return BFI_IOC_IMG_VER_INCOMP
;
1658 flash_fwhdr
= (struct bfi_ioc_image_hdr_s
*) fwimg
;
1659 if (bfa_ioc_flash_fwver_valid(flash_fwhdr
) == BFA_TRUE
)
1660 return bfa_ioc_fw_ver_patch_cmp(base_fwhdr
, flash_fwhdr
);
1662 return BFI_IOC_IMG_VER_INCOMP
;
1667 * Invalidate fwver signature
1670 bfa_ioc_fwsig_invalidate(struct bfa_ioc_s
*ioc
)
1675 enum bfi_ioc_state ioc_fwstate
;
1677 ioc_fwstate
= bfa_ioc_get_cur_ioc_fwstate(ioc
);
1678 if (!bfa_ioc_state_disabled(ioc_fwstate
))
1679 return BFA_STATUS_ADAPTER_ENABLED
;
1681 pgnum
= PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, loff
);
1682 pgoff
= PSS_SMEM_PGOFF(loff
);
1683 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1684 bfa_mem_write(ioc
->ioc_regs
.smem_page_start
, loff
, BFA_IOC_FW_INV_SIGN
);
1686 return BFA_STATUS_OK
;
1690 * Conditionally flush any pending message from firmware at start.
1693 bfa_ioc_msgflush(struct bfa_ioc_s
*ioc
)
1697 r32
= readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
1699 writel(1, ioc
->ioc_regs
.lpu_mbox_cmd
);
1703 bfa_ioc_hwinit(struct bfa_ioc_s
*ioc
, bfa_boolean_t force
)
1705 enum bfi_ioc_state ioc_fwstate
;
1706 bfa_boolean_t fwvalid
;
1710 ioc_fwstate
= bfa_ioc_get_cur_ioc_fwstate(ioc
);
1713 ioc_fwstate
= BFI_IOC_UNINIT
;
1715 bfa_trc(ioc
, ioc_fwstate
);
1717 boot_type
= BFI_FWBOOT_TYPE_NORMAL
;
1718 boot_env
= BFI_FWBOOT_ENV_OS
;
1721 * check if firmware is valid
1723 fwvalid
= (ioc_fwstate
== BFI_IOC_UNINIT
) ?
1724 BFA_FALSE
: bfa_ioc_fwver_valid(ioc
, boot_env
);
1727 if (bfa_ioc_boot(ioc
, boot_type
, boot_env
) == BFA_STATUS_OK
)
1728 bfa_ioc_poll_fwinit(ioc
);
1733 * If hardware initialization is in progress (initialized by other IOC),
1734 * just wait for an initialization completion interrupt.
1736 if (ioc_fwstate
== BFI_IOC_INITING
) {
1737 bfa_ioc_poll_fwinit(ioc
);
1742 * If IOC function is disabled and firmware version is same,
1743 * just re-enable IOC.
1745 * If option rom, IOC must not be in operational state. With
1746 * convergence, IOC will be in operational state when 2nd driver
1749 if (ioc_fwstate
== BFI_IOC_DISABLED
|| ioc_fwstate
== BFI_IOC_OP
) {
1752 * When using MSI-X any pending firmware ready event should
1753 * be flushed. Otherwise MSI-X interrupts are not delivered.
1755 bfa_ioc_msgflush(ioc
);
1756 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FWREADY
);
1761 * Initialize the h/w for any other states.
1763 if (bfa_ioc_boot(ioc
, boot_type
, boot_env
) == BFA_STATUS_OK
)
1764 bfa_ioc_poll_fwinit(ioc
);
1768 bfa_ioc_timeout(void *ioc_arg
)
1770 struct bfa_ioc_s
*ioc
= (struct bfa_ioc_s
*) ioc_arg
;
1773 bfa_fsm_send_event(ioc
, IOC_E_TIMEOUT
);
1777 bfa_ioc_mbox_send(struct bfa_ioc_s
*ioc
, void *ioc_msg
, int len
)
1779 u32
*msgp
= (u32
*) ioc_msg
;
1782 bfa_trc(ioc
, msgp
[0]);
1785 WARN_ON(len
> BFI_IOC_MSGLEN_MAX
);
1788 * first write msg to mailbox registers
1790 for (i
= 0; i
< len
/ sizeof(u32
); i
++)
1791 writel(cpu_to_le32(msgp
[i
]),
1792 ioc
->ioc_regs
.hfn_mbox
+ i
* sizeof(u32
));
1794 for (; i
< BFI_IOC_MSGLEN_MAX
/ sizeof(u32
); i
++)
1795 writel(0, ioc
->ioc_regs
.hfn_mbox
+ i
* sizeof(u32
));
1798 * write 1 to mailbox CMD to trigger LPU event
1800 writel(1, ioc
->ioc_regs
.hfn_mbox_cmd
);
1801 (void) readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
1805 bfa_ioc_send_enable(struct bfa_ioc_s
*ioc
)
1807 struct bfi_ioc_ctrl_req_s enable_req
;
1809 bfi_h2i_set(enable_req
.mh
, BFI_MC_IOC
, BFI_IOC_H2I_ENABLE_REQ
,
1810 bfa_ioc_portid(ioc
));
1811 enable_req
.clscode
= cpu_to_be16(ioc
->clscode
);
1812 /* unsigned 32-bit time_t overflow in y2106 */
1813 enable_req
.tv_sec
= be32_to_cpu(ktime_get_real_seconds());
1814 bfa_ioc_mbox_send(ioc
, &enable_req
, sizeof(struct bfi_ioc_ctrl_req_s
));
1818 bfa_ioc_send_disable(struct bfa_ioc_s
*ioc
)
1820 struct bfi_ioc_ctrl_req_s disable_req
;
1822 bfi_h2i_set(disable_req
.mh
, BFI_MC_IOC
, BFI_IOC_H2I_DISABLE_REQ
,
1823 bfa_ioc_portid(ioc
));
1824 disable_req
.clscode
= cpu_to_be16(ioc
->clscode
);
1825 /* unsigned 32-bit time_t overflow in y2106 */
1826 disable_req
.tv_sec
= be32_to_cpu(ktime_get_real_seconds());
1827 bfa_ioc_mbox_send(ioc
, &disable_req
, sizeof(struct bfi_ioc_ctrl_req_s
));
1831 bfa_ioc_send_getattr(struct bfa_ioc_s
*ioc
)
1833 struct bfi_ioc_getattr_req_s attr_req
;
1835 bfi_h2i_set(attr_req
.mh
, BFI_MC_IOC
, BFI_IOC_H2I_GETATTR_REQ
,
1836 bfa_ioc_portid(ioc
));
1837 bfa_dma_be_addr_set(attr_req
.attr_addr
, ioc
->attr_dma
.pa
);
1838 bfa_ioc_mbox_send(ioc
, &attr_req
, sizeof(attr_req
));
1842 bfa_ioc_hb_check(void *cbarg
)
1844 struct bfa_ioc_s
*ioc
= cbarg
;
1847 hb_count
= readl(ioc
->ioc_regs
.heartbeat
);
1848 if (ioc
->hb_count
== hb_count
) {
1849 bfa_ioc_recover(ioc
);
1852 ioc
->hb_count
= hb_count
;
1855 bfa_ioc_mbox_poll(ioc
);
1856 bfa_hb_timer_start(ioc
);
1860 bfa_ioc_hb_monitor(struct bfa_ioc_s
*ioc
)
1862 ioc
->hb_count
= readl(ioc
->ioc_regs
.heartbeat
);
1863 bfa_hb_timer_start(ioc
);
1867 * Initiate a full firmware download.
1870 bfa_ioc_download_fw(struct bfa_ioc_s
*ioc
, u32 boot_type
,
1880 u32 fwimg_buf
[BFI_FLASH_CHUNK_SZ_WORDS
];
1881 bfa_status_t status
;
1883 if (boot_env
== BFI_FWBOOT_ENV_OS
&&
1884 boot_type
== BFI_FWBOOT_TYPE_FLASH
) {
1885 fwimg_size
= BFI_FLASH_IMAGE_SZ
/sizeof(u32
);
1887 status
= bfa_ioc_flash_img_get_chnk(ioc
,
1888 BFA_IOC_FLASH_CHUNK_ADDR(chunkno
), fwimg_buf
);
1889 if (status
!= BFA_STATUS_OK
)
1894 fwimg_size
= bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc
));
1895 fwimg
= bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc
),
1896 BFA_IOC_FLASH_CHUNK_ADDR(chunkno
));
1899 bfa_trc(ioc
, fwimg_size
);
1902 pgnum
= PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, loff
);
1903 pgoff
= PSS_SMEM_PGOFF(loff
);
1905 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1907 for (i
= 0; i
< fwimg_size
; i
++) {
1909 if (BFA_IOC_FLASH_CHUNK_NO(i
) != chunkno
) {
1910 chunkno
= BFA_IOC_FLASH_CHUNK_NO(i
);
1912 if (boot_env
== BFI_FWBOOT_ENV_OS
&&
1913 boot_type
== BFI_FWBOOT_TYPE_FLASH
) {
1914 status
= bfa_ioc_flash_img_get_chnk(ioc
,
1915 BFA_IOC_FLASH_CHUNK_ADDR(chunkno
),
1917 if (status
!= BFA_STATUS_OK
)
1922 fwimg
= bfa_cb_image_get_chunk(
1923 bfa_ioc_asic_gen(ioc
),
1924 BFA_IOC_FLASH_CHUNK_ADDR(chunkno
));
1931 bfa_mem_write(ioc
->ioc_regs
.smem_page_start
, loff
,
1932 fwimg
[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i
)]);
1934 loff
+= sizeof(u32
);
1937 * handle page offset wrap around
1939 loff
= PSS_SMEM_PGOFF(loff
);
1942 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
1946 writel(PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, 0),
1947 ioc
->ioc_regs
.host_page_num_fn
);
1950 * Set boot type, env and device mode at the end.
1952 if (boot_env
== BFI_FWBOOT_ENV_OS
&&
1953 boot_type
== BFI_FWBOOT_TYPE_FLASH
) {
1954 boot_type
= BFI_FWBOOT_TYPE_NORMAL
;
1956 asicmode
= BFI_FWBOOT_DEVMODE(ioc
->asic_gen
, ioc
->asic_mode
,
1957 ioc
->port0_mode
, ioc
->port1_mode
);
1958 bfa_mem_write(ioc
->ioc_regs
.smem_page_start
, BFI_FWBOOT_DEVMODE_OFF
,
1960 bfa_mem_write(ioc
->ioc_regs
.smem_page_start
, BFI_FWBOOT_TYPE_OFF
,
1962 bfa_mem_write(ioc
->ioc_regs
.smem_page_start
, BFI_FWBOOT_ENV_OFF
,
1964 return BFA_STATUS_OK
;
1969 * Update BFA configuration from firmware configuration.
1972 bfa_ioc_getattr_reply(struct bfa_ioc_s
*ioc
)
1974 struct bfi_ioc_attr_s
*attr
= ioc
->attr
;
1976 attr
->adapter_prop
= be32_to_cpu(attr
->adapter_prop
);
1977 attr
->card_type
= be32_to_cpu(attr
->card_type
);
1978 attr
->maxfrsize
= be16_to_cpu(attr
->maxfrsize
);
1979 ioc
->fcmode
= (attr
->port_mode
== BFI_PORT_MODE_FC
);
1980 attr
->mfg_year
= be16_to_cpu(attr
->mfg_year
);
1982 bfa_fsm_send_event(ioc
, IOC_E_FWRSP_GETATTR
);
1986 * Attach time initialization of mbox logic.
1989 bfa_ioc_mbox_attach(struct bfa_ioc_s
*ioc
)
1991 struct bfa_ioc_mbox_mod_s
*mod
= &ioc
->mbox_mod
;
1994 INIT_LIST_HEAD(&mod
->cmd_q
);
1995 for (mc
= 0; mc
< BFI_MC_MAX
; mc
++) {
1996 mod
->mbhdlr
[mc
].cbfn
= NULL
;
1997 mod
->mbhdlr
[mc
].cbarg
= ioc
->bfa
;
2002 * Mbox poll timer -- restarts any pending mailbox requests.
2005 bfa_ioc_mbox_poll(struct bfa_ioc_s
*ioc
)
2007 struct bfa_ioc_mbox_mod_s
*mod
= &ioc
->mbox_mod
;
2008 struct bfa_mbox_cmd_s
*cmd
;
2012 * If no command pending, do nothing
2014 if (list_empty(&mod
->cmd_q
))
2018 * If previous command is not yet fetched by firmware, do nothing
2020 stat
= readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
2025 * Enqueue command to firmware.
2027 bfa_q_deq(&mod
->cmd_q
, &cmd
);
2028 bfa_ioc_mbox_send(ioc
, cmd
->msg
, sizeof(cmd
->msg
));
2032 * Cleanup any pending requests.
2035 bfa_ioc_mbox_flush(struct bfa_ioc_s
*ioc
)
2037 struct bfa_ioc_mbox_mod_s
*mod
= &ioc
->mbox_mod
;
2038 struct bfa_mbox_cmd_s
*cmd
;
2040 while (!list_empty(&mod
->cmd_q
))
2041 bfa_q_deq(&mod
->cmd_q
, &cmd
);
2045 * Read data from SMEM to host through PCI memmap
2047 * @param[in] ioc memory for IOC
2048 * @param[in] tbuf app memory to store data from smem
2049 * @param[in] soff smem offset
2050 * @param[in] sz size of smem in bytes
2053 bfa_ioc_smem_read(struct bfa_ioc_s
*ioc
, void *tbuf
, u32 soff
, u32 sz
)
2060 pgnum
= PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, soff
);
2061 loff
= PSS_SMEM_PGOFF(soff
);
2062 bfa_trc(ioc
, pgnum
);
2067 * Hold semaphore to serialize pll init and fwtrc.
2069 if (BFA_FALSE
== bfa_ioc_sem_get(ioc
->ioc_regs
.ioc_init_sem_reg
)) {
2071 return BFA_STATUS_FAILED
;
2074 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
2076 len
= sz
/sizeof(u32
);
2078 for (i
= 0; i
< len
; i
++) {
2079 r32
= bfa_mem_read(ioc
->ioc_regs
.smem_page_start
, loff
);
2080 buf
[i
] = swab32(r32
);
2081 loff
+= sizeof(u32
);
2084 * handle page offset wrap around
2086 loff
= PSS_SMEM_PGOFF(loff
);
2089 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
2092 writel(PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, 0),
2093 ioc
->ioc_regs
.host_page_num_fn
);
2095 * release semaphore.
2097 readl(ioc
->ioc_regs
.ioc_init_sem_reg
);
2098 writel(1, ioc
->ioc_regs
.ioc_init_sem_reg
);
2100 bfa_trc(ioc
, pgnum
);
2101 return BFA_STATUS_OK
;
2105 * Clear SMEM data from host through PCI memmap
2107 * @param[in] ioc memory for IOC
2108 * @param[in] soff smem offset
2109 * @param[in] sz size of smem in bytes
2112 bfa_ioc_smem_clr(struct bfa_ioc_s
*ioc
, u32 soff
, u32 sz
)
2117 pgnum
= PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, soff
);
2118 loff
= PSS_SMEM_PGOFF(soff
);
2119 bfa_trc(ioc
, pgnum
);
2124 * Hold semaphore to serialize pll init and fwtrc.
2126 if (BFA_FALSE
== bfa_ioc_sem_get(ioc
->ioc_regs
.ioc_init_sem_reg
)) {
2128 return BFA_STATUS_FAILED
;
2131 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
2133 len
= sz
/sizeof(u32
); /* len in words */
2135 for (i
= 0; i
< len
; i
++) {
2136 bfa_mem_write(ioc
->ioc_regs
.smem_page_start
, loff
, 0);
2137 loff
+= sizeof(u32
);
2140 * handle page offset wrap around
2142 loff
= PSS_SMEM_PGOFF(loff
);
2145 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
2148 writel(PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, 0),
2149 ioc
->ioc_regs
.host_page_num_fn
);
2152 * release semaphore.
2154 readl(ioc
->ioc_regs
.ioc_init_sem_reg
);
2155 writel(1, ioc
->ioc_regs
.ioc_init_sem_reg
);
2156 bfa_trc(ioc
, pgnum
);
2157 return BFA_STATUS_OK
;
2161 bfa_ioc_fail_notify(struct bfa_ioc_s
*ioc
)
2163 struct bfad_s
*bfad
= (struct bfad_s
*)ioc
->bfa
->bfad
;
2166 * Notify driver and common modules registered for notification.
2168 ioc
->cbfn
->hbfail_cbfn(ioc
->bfa
);
2169 bfa_ioc_event_notify(ioc
, BFA_IOC_E_FAILED
);
2171 bfa_ioc_debug_save_ftrc(ioc
);
2173 BFA_LOG(KERN_CRIT
, bfad
, bfa_log_level
,
2174 "Heart Beat of IOC has failed\n");
2175 bfa_ioc_aen_post(ioc
, BFA_IOC_AEN_HBFAIL
);
2180 bfa_ioc_pf_fwmismatch(struct bfa_ioc_s
*ioc
)
2182 struct bfad_s
*bfad
= (struct bfad_s
*)ioc
->bfa
->bfad
;
2184 * Provide enable completion callback.
2186 ioc
->cbfn
->enable_cbfn(ioc
->bfa
, BFA_STATUS_IOC_FAILURE
);
2187 BFA_LOG(KERN_WARNING
, bfad
, bfa_log_level
,
2188 "Running firmware version is incompatible "
2189 "with the driver version\n");
2190 bfa_ioc_aen_post(ioc
, BFA_IOC_AEN_FWMISMATCH
);
2194 bfa_ioc_pll_init(struct bfa_ioc_s
*ioc
)
2198 * Hold semaphore so that nobody can access the chip during init.
2200 bfa_ioc_sem_get(ioc
->ioc_regs
.ioc_init_sem_reg
);
2202 bfa_ioc_pll_init_asic(ioc
);
2204 ioc
->pllinit
= BFA_TRUE
;
2209 bfa_ioc_lmem_init(ioc
);
2212 * release semaphore.
2214 readl(ioc
->ioc_regs
.ioc_init_sem_reg
);
2215 writel(1, ioc
->ioc_regs
.ioc_init_sem_reg
);
2217 return BFA_STATUS_OK
;
2221 * Interface used by diag module to do firmware boot with memory test
2222 * as the entry vector.
2225 bfa_ioc_boot(struct bfa_ioc_s
*ioc
, u32 boot_type
, u32 boot_env
)
2227 struct bfi_ioc_image_hdr_s
*drv_fwhdr
;
2228 bfa_status_t status
;
2229 bfa_ioc_stats(ioc
, ioc_boots
);
2231 if (bfa_ioc_pll_init(ioc
) != BFA_STATUS_OK
)
2232 return BFA_STATUS_FAILED
;
2234 if (boot_env
== BFI_FWBOOT_ENV_OS
&&
2235 boot_type
== BFI_FWBOOT_TYPE_NORMAL
) {
2237 drv_fwhdr
= (struct bfi_ioc_image_hdr_s
*)
2238 bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc
), 0);
2241 * Work with Flash iff flash f/w is better than driver f/w.
2242 * Otherwise push drivers firmware.
2244 if (bfa_ioc_flash_fwver_cmp(ioc
, drv_fwhdr
) ==
2245 BFI_IOC_IMG_VER_BETTER
)
2246 boot_type
= BFI_FWBOOT_TYPE_FLASH
;
2250 * Initialize IOC state of all functions on a chip reset.
2252 if (boot_type
== BFI_FWBOOT_TYPE_MEMTEST
) {
2253 bfa_ioc_set_cur_ioc_fwstate(ioc
, BFI_IOC_MEMTEST
);
2254 bfa_ioc_set_alt_ioc_fwstate(ioc
, BFI_IOC_MEMTEST
);
2256 bfa_ioc_set_cur_ioc_fwstate(ioc
, BFI_IOC_INITING
);
2257 bfa_ioc_set_alt_ioc_fwstate(ioc
, BFI_IOC_INITING
);
2260 bfa_ioc_msgflush(ioc
);
2261 status
= bfa_ioc_download_fw(ioc
, boot_type
, boot_env
);
2262 if (status
== BFA_STATUS_OK
)
2263 bfa_ioc_lpu_start(ioc
);
2265 WARN_ON(boot_type
== BFI_FWBOOT_TYPE_MEMTEST
);
2266 bfa_iocpf_timeout(ioc
);
2272 * Enable/disable IOC failure auto recovery.
2275 bfa_ioc_auto_recover(bfa_boolean_t auto_recover
)
2277 bfa_auto_recover
= auto_recover
;
2283 bfa_ioc_is_operational(struct bfa_ioc_s
*ioc
)
2285 return bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_op
);
2289 bfa_ioc_is_initialized(struct bfa_ioc_s
*ioc
)
2291 u32 r32
= bfa_ioc_get_cur_ioc_fwstate(ioc
);
2293 return ((r32
!= BFI_IOC_UNINIT
) &&
2294 (r32
!= BFI_IOC_INITING
) &&
2295 (r32
!= BFI_IOC_MEMTEST
));
2299 bfa_ioc_msgget(struct bfa_ioc_s
*ioc
, void *mbmsg
)
2301 __be32
*msgp
= mbmsg
;
2305 r32
= readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
2312 for (i
= 0; i
< (sizeof(union bfi_ioc_i2h_msg_u
) / sizeof(u32
));
2314 r32
= readl(ioc
->ioc_regs
.lpu_mbox
+
2316 msgp
[i
] = cpu_to_be32(r32
);
2320 * turn off mailbox interrupt by clearing mailbox status
2322 writel(1, ioc
->ioc_regs
.lpu_mbox_cmd
);
2323 readl(ioc
->ioc_regs
.lpu_mbox_cmd
);
2329 bfa_ioc_isr(struct bfa_ioc_s
*ioc
, struct bfi_mbmsg_s
*m
)
2331 union bfi_ioc_i2h_msg_u
*msg
;
2332 struct bfa_iocpf_s
*iocpf
= &ioc
->iocpf
;
2334 msg
= (union bfi_ioc_i2h_msg_u
*) m
;
2336 bfa_ioc_stats(ioc
, ioc_isrs
);
2338 switch (msg
->mh
.msg_id
) {
2339 case BFI_IOC_I2H_HBEAT
:
2342 case BFI_IOC_I2H_ENABLE_REPLY
:
2343 ioc
->port_mode
= ioc
->port_mode_cfg
=
2344 (enum bfa_mode_s
)msg
->fw_event
.port_mode
;
2345 ioc
->ad_cap_bm
= msg
->fw_event
.cap_bm
;
2346 bfa_fsm_send_event(iocpf
, IOCPF_E_FWRSP_ENABLE
);
2349 case BFI_IOC_I2H_DISABLE_REPLY
:
2350 bfa_fsm_send_event(iocpf
, IOCPF_E_FWRSP_DISABLE
);
2353 case BFI_IOC_I2H_GETATTR_REPLY
:
2354 bfa_ioc_getattr_reply(ioc
);
2358 bfa_trc(ioc
, msg
->mh
.msg_id
);
2364 * IOC attach time initialization and setup.
2366 * @param[in] ioc memory for IOC
2367 * @param[in] bfa driver instance structure
2370 bfa_ioc_attach(struct bfa_ioc_s
*ioc
, void *bfa
, struct bfa_ioc_cbfn_s
*cbfn
,
2371 struct bfa_timer_mod_s
*timer_mod
)
2375 ioc
->timer_mod
= timer_mod
;
2376 ioc
->fcmode
= BFA_FALSE
;
2377 ioc
->pllinit
= BFA_FALSE
;
2378 ioc
->dbg_fwsave_once
= BFA_TRUE
;
2379 ioc
->iocpf
.ioc
= ioc
;
2381 bfa_ioc_mbox_attach(ioc
);
2382 INIT_LIST_HEAD(&ioc
->notify_q
);
2384 bfa_fsm_set_state(ioc
, bfa_ioc_sm_uninit
);
2385 bfa_fsm_send_event(ioc
, IOC_E_RESET
);
2389 * Driver detach time IOC cleanup.
2392 bfa_ioc_detach(struct bfa_ioc_s
*ioc
)
2394 bfa_fsm_send_event(ioc
, IOC_E_DETACH
);
2395 INIT_LIST_HEAD(&ioc
->notify_q
);
2399 * Setup IOC PCI properties.
2401 * @param[in] pcidev PCI device information for this IOC
2404 bfa_ioc_pci_init(struct bfa_ioc_s
*ioc
, struct bfa_pcidev_s
*pcidev
,
2405 enum bfi_pcifn_class clscode
)
2407 ioc
->clscode
= clscode
;
2408 ioc
->pcidev
= *pcidev
;
2411 * Initialize IOC and device personality
2413 ioc
->port0_mode
= ioc
->port1_mode
= BFI_PORT_MODE_FC
;
2414 ioc
->asic_mode
= BFI_ASIC_MODE_FC
;
2416 switch (pcidev
->device_id
) {
2417 case BFA_PCI_DEVICE_ID_FC_8G1P
:
2418 case BFA_PCI_DEVICE_ID_FC_8G2P
:
2419 ioc
->asic_gen
= BFI_ASIC_GEN_CB
;
2420 ioc
->fcmode
= BFA_TRUE
;
2421 ioc
->port_mode
= ioc
->port_mode_cfg
= BFA_MODE_HBA
;
2422 ioc
->ad_cap_bm
= BFA_CM_HBA
;
2425 case BFA_PCI_DEVICE_ID_CT
:
2426 ioc
->asic_gen
= BFI_ASIC_GEN_CT
;
2427 ioc
->port0_mode
= ioc
->port1_mode
= BFI_PORT_MODE_ETH
;
2428 ioc
->asic_mode
= BFI_ASIC_MODE_ETH
;
2429 ioc
->port_mode
= ioc
->port_mode_cfg
= BFA_MODE_CNA
;
2430 ioc
->ad_cap_bm
= BFA_CM_CNA
;
2433 case BFA_PCI_DEVICE_ID_CT_FC
:
2434 ioc
->asic_gen
= BFI_ASIC_GEN_CT
;
2435 ioc
->fcmode
= BFA_TRUE
;
2436 ioc
->port_mode
= ioc
->port_mode_cfg
= BFA_MODE_HBA
;
2437 ioc
->ad_cap_bm
= BFA_CM_HBA
;
2440 case BFA_PCI_DEVICE_ID_CT2
:
2441 case BFA_PCI_DEVICE_ID_CT2_QUAD
:
2442 ioc
->asic_gen
= BFI_ASIC_GEN_CT2
;
2443 if (clscode
== BFI_PCIFN_CLASS_FC
&&
2444 pcidev
->ssid
== BFA_PCI_CT2_SSID_FC
) {
2445 ioc
->asic_mode
= BFI_ASIC_MODE_FC16
;
2446 ioc
->fcmode
= BFA_TRUE
;
2447 ioc
->port_mode
= ioc
->port_mode_cfg
= BFA_MODE_HBA
;
2448 ioc
->ad_cap_bm
= BFA_CM_HBA
;
2450 ioc
->port0_mode
= ioc
->port1_mode
= BFI_PORT_MODE_ETH
;
2451 ioc
->asic_mode
= BFI_ASIC_MODE_ETH
;
2452 if (pcidev
->ssid
== BFA_PCI_CT2_SSID_FCoE
) {
2454 ioc
->port_mode_cfg
= BFA_MODE_CNA
;
2455 ioc
->ad_cap_bm
= BFA_CM_CNA
;
2458 ioc
->port_mode_cfg
= BFA_MODE_NIC
;
2459 ioc
->ad_cap_bm
= BFA_CM_NIC
;
2469 * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c
2471 if (ioc
->asic_gen
== BFI_ASIC_GEN_CB
)
2472 bfa_ioc_set_cb_hwif(ioc
);
2473 else if (ioc
->asic_gen
== BFI_ASIC_GEN_CT
)
2474 bfa_ioc_set_ct_hwif(ioc
);
2476 WARN_ON(ioc
->asic_gen
!= BFI_ASIC_GEN_CT2
);
2477 bfa_ioc_set_ct2_hwif(ioc
);
2478 bfa_ioc_ct2_poweron(ioc
);
2481 bfa_ioc_map_port(ioc
);
2482 bfa_ioc_reg_init(ioc
);
2486 * Initialize IOC dma memory
2488 * @param[in] dm_kva kernel virtual address of IOC dma memory
2489 * @param[in] dm_pa physical address of IOC dma memory
2492 bfa_ioc_mem_claim(struct bfa_ioc_s
*ioc
, u8
*dm_kva
, u64 dm_pa
)
2495 * dma memory for firmware attribute
2497 ioc
->attr_dma
.kva
= dm_kva
;
2498 ioc
->attr_dma
.pa
= dm_pa
;
2499 ioc
->attr
= (struct bfi_ioc_attr_s
*) dm_kva
;
2503 bfa_ioc_enable(struct bfa_ioc_s
*ioc
)
2505 bfa_ioc_stats(ioc
, ioc_enables
);
2506 ioc
->dbg_fwsave_once
= BFA_TRUE
;
2508 bfa_fsm_send_event(ioc
, IOC_E_ENABLE
);
2512 bfa_ioc_disable(struct bfa_ioc_s
*ioc
)
2514 bfa_ioc_stats(ioc
, ioc_disables
);
2515 bfa_fsm_send_event(ioc
, IOC_E_DISABLE
);
2519 bfa_ioc_suspend(struct bfa_ioc_s
*ioc
)
2521 ioc
->dbg_fwsave_once
= BFA_TRUE
;
2522 bfa_fsm_send_event(ioc
, IOC_E_HWERROR
);
2526 * Initialize memory for saving firmware trace. Driver must initialize
2527 * trace memory before call bfa_ioc_enable().
2530 bfa_ioc_debug_memclaim(struct bfa_ioc_s
*ioc
, void *dbg_fwsave
)
2532 ioc
->dbg_fwsave
= dbg_fwsave
;
2533 ioc
->dbg_fwsave_len
= BFA_DBG_FWTRC_LEN
;
2537 * Register mailbox message handler functions
2539 * @param[in] ioc IOC instance
2540 * @param[in] mcfuncs message class handler functions
2543 bfa_ioc_mbox_register(struct bfa_ioc_s
*ioc
, bfa_ioc_mbox_mcfunc_t
*mcfuncs
)
2545 struct bfa_ioc_mbox_mod_s
*mod
= &ioc
->mbox_mod
;
2548 for (mc
= 0; mc
< BFI_MC_MAX
; mc
++)
2549 mod
->mbhdlr
[mc
].cbfn
= mcfuncs
[mc
];
2553 * Register mailbox message handler function, to be called by common modules
2556 bfa_ioc_mbox_regisr(struct bfa_ioc_s
*ioc
, enum bfi_mclass mc
,
2557 bfa_ioc_mbox_mcfunc_t cbfn
, void *cbarg
)
2559 struct bfa_ioc_mbox_mod_s
*mod
= &ioc
->mbox_mod
;
2561 mod
->mbhdlr
[mc
].cbfn
= cbfn
;
2562 mod
->mbhdlr
[mc
].cbarg
= cbarg
;
2566 * Queue a mailbox command request to firmware. Waits if mailbox is busy.
2567 * Responsibility of caller to serialize
2569 * @param[in] ioc IOC instance
2570 * @param[i] cmd Mailbox command
2573 bfa_ioc_mbox_queue(struct bfa_ioc_s
*ioc
, struct bfa_mbox_cmd_s
*cmd
)
2575 struct bfa_ioc_mbox_mod_s
*mod
= &ioc
->mbox_mod
;
2579 * If a previous command is pending, queue new command
2581 if (!list_empty(&mod
->cmd_q
)) {
2582 list_add_tail(&cmd
->qe
, &mod
->cmd_q
);
2587 * If mailbox is busy, queue command for poll timer
2589 stat
= readl(ioc
->ioc_regs
.hfn_mbox_cmd
);
2591 list_add_tail(&cmd
->qe
, &mod
->cmd_q
);
2596 * mailbox is free -- queue command to firmware
2598 bfa_ioc_mbox_send(ioc
, cmd
->msg
, sizeof(cmd
->msg
));
2602 * Handle mailbox interrupts
2605 bfa_ioc_mbox_isr(struct bfa_ioc_s
*ioc
)
2607 struct bfa_ioc_mbox_mod_s
*mod
= &ioc
->mbox_mod
;
2608 struct bfi_mbmsg_s m
;
2611 if (bfa_ioc_msgget(ioc
, &m
)) {
2613 * Treat IOC message class as special.
2615 mc
= m
.mh
.msg_class
;
2616 if (mc
== BFI_MC_IOC
) {
2617 bfa_ioc_isr(ioc
, &m
);
2621 if ((mc
>= BFI_MC_MAX
) || (mod
->mbhdlr
[mc
].cbfn
== NULL
))
2624 mod
->mbhdlr
[mc
].cbfn(mod
->mbhdlr
[mc
].cbarg
, &m
);
2627 bfa_ioc_lpu_read_stat(ioc
);
2630 * Try to send pending mailbox commands
2632 bfa_ioc_mbox_poll(ioc
);
2636 bfa_ioc_error_isr(struct bfa_ioc_s
*ioc
)
2638 bfa_ioc_stats(ioc
, ioc_hbfails
);
2639 ioc
->stats
.hb_count
= ioc
->hb_count
;
2640 bfa_fsm_send_event(ioc
, IOC_E_HWERROR
);
2644 * return true if IOC is disabled
2647 bfa_ioc_is_disabled(struct bfa_ioc_s
*ioc
)
2649 return bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_disabling
) ||
2650 bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_disabled
);
2654 * return true if IOC firmware is different.
2657 bfa_ioc_fw_mismatch(struct bfa_ioc_s
*ioc
)
2659 return bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_reset
) ||
2660 bfa_fsm_cmp_state(&ioc
->iocpf
, bfa_iocpf_sm_fwcheck
) ||
2661 bfa_fsm_cmp_state(&ioc
->iocpf
, bfa_iocpf_sm_mismatch
);
2665 * Check if adapter is disabled -- both IOCs should be in a disabled
2669 bfa_ioc_adapter_is_disabled(struct bfa_ioc_s
*ioc
)
2673 if (!bfa_fsm_cmp_state(ioc
, bfa_ioc_sm_disabled
))
2676 ioc_state
= bfa_ioc_get_cur_ioc_fwstate(ioc
);
2677 if (!bfa_ioc_state_disabled(ioc_state
))
2680 if (ioc
->pcidev
.device_id
!= BFA_PCI_DEVICE_ID_FC_8G1P
) {
2681 ioc_state
= bfa_ioc_get_cur_ioc_fwstate(ioc
);
2682 if (!bfa_ioc_state_disabled(ioc_state
))
2690 * Reset IOC fwstate registers.
2693 bfa_ioc_reset_fwstate(struct bfa_ioc_s
*ioc
)
2695 bfa_ioc_set_cur_ioc_fwstate(ioc
, BFI_IOC_UNINIT
);
2696 bfa_ioc_set_alt_ioc_fwstate(ioc
, BFI_IOC_UNINIT
);
2699 #define BFA_MFG_NAME "QLogic"
2701 bfa_ioc_get_adapter_attr(struct bfa_ioc_s
*ioc
,
2702 struct bfa_adapter_attr_s
*ad_attr
)
2704 struct bfi_ioc_attr_s
*ioc_attr
;
2706 ioc_attr
= ioc
->attr
;
2708 bfa_ioc_get_adapter_serial_num(ioc
, ad_attr
->serial_num
);
2709 bfa_ioc_get_adapter_fw_ver(ioc
, ad_attr
->fw_ver
);
2710 bfa_ioc_get_adapter_optrom_ver(ioc
, ad_attr
->optrom_ver
);
2711 bfa_ioc_get_adapter_manufacturer(ioc
, ad_attr
->manufacturer
);
2712 memcpy(&ad_attr
->vpd
, &ioc_attr
->vpd
,
2713 sizeof(struct bfa_mfg_vpd_s
));
2715 ad_attr
->nports
= bfa_ioc_get_nports(ioc
);
2716 ad_attr
->max_speed
= bfa_ioc_speed_sup(ioc
);
2718 bfa_ioc_get_adapter_model(ioc
, ad_attr
->model
);
2719 /* For now, model descr uses same model string */
2720 bfa_ioc_get_adapter_model(ioc
, ad_attr
->model_descr
);
2722 ad_attr
->card_type
= ioc_attr
->card_type
;
2723 ad_attr
->is_mezz
= bfa_mfg_is_mezz(ioc_attr
->card_type
);
2725 if (BFI_ADAPTER_IS_SPECIAL(ioc_attr
->adapter_prop
))
2726 ad_attr
->prototype
= 1;
2728 ad_attr
->prototype
= 0;
2730 ad_attr
->pwwn
= ioc
->attr
->pwwn
;
2731 ad_attr
->mac
= bfa_ioc_get_mac(ioc
);
2733 ad_attr
->pcie_gen
= ioc_attr
->pcie_gen
;
2734 ad_attr
->pcie_lanes
= ioc_attr
->pcie_lanes
;
2735 ad_attr
->pcie_lanes_orig
= ioc_attr
->pcie_lanes_orig
;
2736 ad_attr
->asic_rev
= ioc_attr
->asic_rev
;
2738 bfa_ioc_get_pci_chip_rev(ioc
, ad_attr
->hw_ver
);
2740 ad_attr
->cna_capable
= bfa_ioc_is_cna(ioc
);
2741 ad_attr
->trunk_capable
= (ad_attr
->nports
> 1) &&
2742 !bfa_ioc_is_cna(ioc
) && !ad_attr
->is_mezz
;
2743 ad_attr
->mfg_day
= ioc_attr
->mfg_day
;
2744 ad_attr
->mfg_month
= ioc_attr
->mfg_month
;
2745 ad_attr
->mfg_year
= ioc_attr
->mfg_year
;
2746 memcpy(ad_attr
->uuid
, ioc_attr
->uuid
, BFA_ADAPTER_UUID_LEN
);
2750 bfa_ioc_get_type(struct bfa_ioc_s
*ioc
)
2752 if (ioc
->clscode
== BFI_PCIFN_CLASS_ETH
)
2753 return BFA_IOC_TYPE_LL
;
2755 WARN_ON(ioc
->clscode
!= BFI_PCIFN_CLASS_FC
);
2757 return (ioc
->attr
->port_mode
== BFI_PORT_MODE_FC
)
2758 ? BFA_IOC_TYPE_FC
: BFA_IOC_TYPE_FCoE
;
2762 bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s
*ioc
, char *serial_num
)
2764 memset((void *)serial_num
, 0, BFA_ADAPTER_SERIAL_NUM_LEN
);
2765 memcpy((void *)serial_num
,
2766 (void *)ioc
->attr
->brcd_serialnum
,
2767 BFA_ADAPTER_SERIAL_NUM_LEN
);
2771 bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s
*ioc
, char *fw_ver
)
2773 memset((void *)fw_ver
, 0, BFA_VERSION_LEN
);
2774 memcpy(fw_ver
, ioc
->attr
->fw_version
, BFA_VERSION_LEN
);
2778 bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s
*ioc
, char *chip_rev
)
2782 memset((void *)chip_rev
, 0, BFA_IOC_CHIP_REV_LEN
);
2788 chip_rev
[4] = ioc
->attr
->asic_rev
;
2793 bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s
*ioc
, char *optrom_ver
)
2795 memset((void *)optrom_ver
, 0, BFA_VERSION_LEN
);
2796 memcpy(optrom_ver
, ioc
->attr
->optrom_version
,
2801 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s
*ioc
, char *manufacturer
)
2803 memset((void *)manufacturer
, 0, BFA_ADAPTER_MFG_NAME_LEN
);
2804 strlcpy(manufacturer
, BFA_MFG_NAME
, BFA_ADAPTER_MFG_NAME_LEN
);
2808 bfa_ioc_get_adapter_model(struct bfa_ioc_s
*ioc
, char *model
)
2810 struct bfi_ioc_attr_s
*ioc_attr
;
2811 u8 nports
= bfa_ioc_get_nports(ioc
);
2814 memset((void *)model
, 0, BFA_ADAPTER_MODEL_NAME_LEN
);
2816 ioc_attr
= ioc
->attr
;
2818 if (bfa_asic_id_ct2(ioc
->pcidev
.device_id
) &&
2819 (!bfa_mfg_is_mezz(ioc_attr
->card_type
)))
2820 snprintf(model
, BFA_ADAPTER_MODEL_NAME_LEN
, "%s-%u-%u%s",
2821 BFA_MFG_NAME
, ioc_attr
->card_type
, nports
, "p");
2823 snprintf(model
, BFA_ADAPTER_MODEL_NAME_LEN
, "%s-%u",
2824 BFA_MFG_NAME
, ioc_attr
->card_type
);
2828 bfa_ioc_get_state(struct bfa_ioc_s
*ioc
)
2830 enum bfa_iocpf_state iocpf_st
;
2831 enum bfa_ioc_state ioc_st
= bfa_sm_to_state(ioc_sm_table
, ioc
->fsm
);
2833 if (ioc_st
== BFA_IOC_ENABLING
||
2834 ioc_st
== BFA_IOC_FAIL
|| ioc_st
== BFA_IOC_INITFAIL
) {
2836 iocpf_st
= bfa_sm_to_state(iocpf_sm_table
, ioc
->iocpf
.fsm
);
2839 case BFA_IOCPF_SEMWAIT
:
2840 ioc_st
= BFA_IOC_SEMWAIT
;
2843 case BFA_IOCPF_HWINIT
:
2844 ioc_st
= BFA_IOC_HWINIT
;
2847 case BFA_IOCPF_FWMISMATCH
:
2848 ioc_st
= BFA_IOC_FWMISMATCH
;
2851 case BFA_IOCPF_FAIL
:
2852 ioc_st
= BFA_IOC_FAIL
;
2855 case BFA_IOCPF_INITFAIL
:
2856 ioc_st
= BFA_IOC_INITFAIL
;
2868 bfa_ioc_get_attr(struct bfa_ioc_s
*ioc
, struct bfa_ioc_attr_s
*ioc_attr
)
2870 memset((void *)ioc_attr
, 0, sizeof(struct bfa_ioc_attr_s
));
2872 ioc_attr
->state
= bfa_ioc_get_state(ioc
);
2873 ioc_attr
->port_id
= bfa_ioc_portid(ioc
);
2874 ioc_attr
->port_mode
= ioc
->port_mode
;
2875 ioc_attr
->port_mode_cfg
= ioc
->port_mode_cfg
;
2876 ioc_attr
->cap_bm
= ioc
->ad_cap_bm
;
2878 ioc_attr
->ioc_type
= bfa_ioc_get_type(ioc
);
2880 bfa_ioc_get_adapter_attr(ioc
, &ioc_attr
->adapter_attr
);
2882 ioc_attr
->pci_attr
.device_id
= bfa_ioc_devid(ioc
);
2883 ioc_attr
->pci_attr
.pcifn
= bfa_ioc_pcifn(ioc
);
2884 ioc_attr
->def_fn
= (bfa_ioc_pcifn(ioc
) == bfa_ioc_portid(ioc
));
2885 bfa_ioc_get_pci_chip_rev(ioc
, ioc_attr
->pci_attr
.chip_rev
);
2889 bfa_ioc_get_mac(struct bfa_ioc_s
*ioc
)
2892 * Check the IOC type and return the appropriate MAC
2894 if (bfa_ioc_get_type(ioc
) == BFA_IOC_TYPE_FCoE
)
2895 return ioc
->attr
->fcoe_mac
;
2897 return ioc
->attr
->mac
;
2901 bfa_ioc_get_mfg_mac(struct bfa_ioc_s
*ioc
)
2905 m
= ioc
->attr
->mfg_mac
;
2906 if (bfa_mfg_is_old_wwn_mac_model(ioc
->attr
->card_type
))
2907 m
.mac
[MAC_ADDRLEN
- 1] += bfa_ioc_pcifn(ioc
);
2909 bfa_mfg_increment_wwn_mac(&(m
.mac
[MAC_ADDRLEN
-3]),
2910 bfa_ioc_pcifn(ioc
));
2916 * Send AEN notification
2919 bfa_ioc_aen_post(struct bfa_ioc_s
*ioc
, enum bfa_ioc_aen_event event
)
2921 struct bfad_s
*bfad
= (struct bfad_s
*)ioc
->bfa
->bfad
;
2922 struct bfa_aen_entry_s
*aen_entry
;
2923 enum bfa_ioc_type_e ioc_type
;
2925 bfad_get_aen_entry(bfad
, aen_entry
);
2929 ioc_type
= bfa_ioc_get_type(ioc
);
2931 case BFA_IOC_TYPE_FC
:
2932 aen_entry
->aen_data
.ioc
.pwwn
= ioc
->attr
->pwwn
;
2934 case BFA_IOC_TYPE_FCoE
:
2935 aen_entry
->aen_data
.ioc
.pwwn
= ioc
->attr
->pwwn
;
2936 aen_entry
->aen_data
.ioc
.mac
= bfa_ioc_get_mac(ioc
);
2938 case BFA_IOC_TYPE_LL
:
2939 aen_entry
->aen_data
.ioc
.mac
= bfa_ioc_get_mac(ioc
);
2942 WARN_ON(ioc_type
!= BFA_IOC_TYPE_FC
);
2946 /* Send the AEN notification */
2947 aen_entry
->aen_data
.ioc
.ioc_type
= ioc_type
;
2948 bfad_im_post_vendor_event(aen_entry
, bfad
, ++ioc
->ioc_aen_seq
,
2949 BFA_AEN_CAT_IOC
, event
);
2953 * Retrieve saved firmware trace from a prior IOC failure.
2956 bfa_ioc_debug_fwsave(struct bfa_ioc_s
*ioc
, void *trcdata
, int *trclen
)
2960 if (ioc
->dbg_fwsave_len
== 0)
2961 return BFA_STATUS_ENOFSAVE
;
2964 if (tlen
> ioc
->dbg_fwsave_len
)
2965 tlen
= ioc
->dbg_fwsave_len
;
2967 memcpy(trcdata
, ioc
->dbg_fwsave
, tlen
);
2969 return BFA_STATUS_OK
;
2974 * Retrieve saved firmware trace from a prior IOC failure.
2977 bfa_ioc_debug_fwtrc(struct bfa_ioc_s
*ioc
, void *trcdata
, int *trclen
)
2979 u32 loff
= BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc
));
2981 bfa_status_t status
;
2983 bfa_trc(ioc
, *trclen
);
2986 if (tlen
> BFA_DBG_FWTRC_LEN
)
2987 tlen
= BFA_DBG_FWTRC_LEN
;
2989 status
= bfa_ioc_smem_read(ioc
, trcdata
, loff
, tlen
);
2995 bfa_ioc_send_fwsync(struct bfa_ioc_s
*ioc
)
2997 struct bfa_mbox_cmd_s cmd
;
2998 struct bfi_ioc_ctrl_req_s
*req
= (struct bfi_ioc_ctrl_req_s
*) cmd
.msg
;
3000 bfi_h2i_set(req
->mh
, BFI_MC_IOC
, BFI_IOC_H2I_DBG_SYNC
,
3001 bfa_ioc_portid(ioc
));
3002 req
->clscode
= cpu_to_be16(ioc
->clscode
);
3003 bfa_ioc_mbox_queue(ioc
, &cmd
);
3007 bfa_ioc_fwsync(struct bfa_ioc_s
*ioc
)
3009 u32 fwsync_iter
= 1000;
3011 bfa_ioc_send_fwsync(ioc
);
3014 * After sending a fw sync mbox command wait for it to
3015 * take effect. We will not wait for a response because
3016 * 1. fw_sync mbox cmd doesn't have a response.
3017 * 2. Even if we implement that, interrupts might not
3018 * be enabled when we call this function.
3019 * So, just keep checking if any mbox cmd is pending, and
3020 * after waiting for a reasonable amount of time, go ahead.
3021 * It is possible that fw has crashed and the mbox command
3022 * is never acknowledged.
3024 while (bfa_ioc_mbox_cmd_pending(ioc
) && fwsync_iter
> 0)
3029 * Dump firmware smem
3032 bfa_ioc_debug_fwcore(struct bfa_ioc_s
*ioc
, void *buf
,
3033 u32
*offset
, int *buflen
)
3037 bfa_status_t status
;
3038 u32 smem_len
= BFA_IOC_FW_SMEM_SIZE(ioc
);
3040 if (*offset
>= smem_len
) {
3041 *offset
= *buflen
= 0;
3042 return BFA_STATUS_EINVAL
;
3049 * First smem read, sync smem before proceeding
3050 * No need to sync before reading every chunk.
3053 bfa_ioc_fwsync(ioc
);
3055 if ((loff
+ dlen
) >= smem_len
)
3056 dlen
= smem_len
- loff
;
3058 status
= bfa_ioc_smem_read(ioc
, buf
, loff
, dlen
);
3060 if (status
!= BFA_STATUS_OK
) {
3061 *offset
= *buflen
= 0;
3067 if (*offset
>= smem_len
)
3076 * Firmware statistics
3079 bfa_ioc_fw_stats_get(struct bfa_ioc_s
*ioc
, void *stats
)
3081 u32 loff
= BFI_IOC_FWSTATS_OFF
+ \
3082 BFI_IOC_FWSTATS_SZ
* (bfa_ioc_portid(ioc
));
3084 bfa_status_t status
;
3086 if (ioc
->stats_busy
) {
3087 bfa_trc(ioc
, ioc
->stats_busy
);
3088 return BFA_STATUS_DEVBUSY
;
3090 ioc
->stats_busy
= BFA_TRUE
;
3092 tlen
= sizeof(struct bfa_fw_stats_s
);
3093 status
= bfa_ioc_smem_read(ioc
, stats
, loff
, tlen
);
3095 ioc
->stats_busy
= BFA_FALSE
;
3100 bfa_ioc_fw_stats_clear(struct bfa_ioc_s
*ioc
)
3102 u32 loff
= BFI_IOC_FWSTATS_OFF
+ \
3103 BFI_IOC_FWSTATS_SZ
* (bfa_ioc_portid(ioc
));
3105 bfa_status_t status
;
3107 if (ioc
->stats_busy
) {
3108 bfa_trc(ioc
, ioc
->stats_busy
);
3109 return BFA_STATUS_DEVBUSY
;
3111 ioc
->stats_busy
= BFA_TRUE
;
3113 tlen
= sizeof(struct bfa_fw_stats_s
);
3114 status
= bfa_ioc_smem_clr(ioc
, loff
, tlen
);
3116 ioc
->stats_busy
= BFA_FALSE
;
3121 * Save firmware trace if configured.
3124 bfa_ioc_debug_save_ftrc(struct bfa_ioc_s
*ioc
)
3128 if (ioc
->dbg_fwsave_once
) {
3129 ioc
->dbg_fwsave_once
= BFA_FALSE
;
3130 if (ioc
->dbg_fwsave_len
) {
3131 tlen
= ioc
->dbg_fwsave_len
;
3132 bfa_ioc_debug_fwtrc(ioc
, ioc
->dbg_fwsave
, &tlen
);
3138 * Firmware failure detected. Start recovery actions.
3141 bfa_ioc_recover(struct bfa_ioc_s
*ioc
)
3143 bfa_ioc_stats(ioc
, ioc_hbfails
);
3144 ioc
->stats
.hb_count
= ioc
->hb_count
;
3145 bfa_fsm_send_event(ioc
, IOC_E_HBFAIL
);
3149 * BFA IOC PF private functions
3152 bfa_iocpf_timeout(void *ioc_arg
)
3154 struct bfa_ioc_s
*ioc
= (struct bfa_ioc_s
*) ioc_arg
;
3157 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_TIMEOUT
);
3161 bfa_iocpf_sem_timeout(void *ioc_arg
)
3163 struct bfa_ioc_s
*ioc
= (struct bfa_ioc_s
*) ioc_arg
;
3165 bfa_ioc_hw_sem_get(ioc
);
3169 bfa_ioc_poll_fwinit(struct bfa_ioc_s
*ioc
)
3171 u32 fwstate
= bfa_ioc_get_cur_ioc_fwstate(ioc
);
3173 bfa_trc(ioc
, fwstate
);
3175 if (fwstate
== BFI_IOC_DISABLED
) {
3176 bfa_fsm_send_event(&ioc
->iocpf
, IOCPF_E_FWREADY
);
3180 if (ioc
->iocpf
.poll_time
>= (3 * BFA_IOC_TOV
))
3181 bfa_iocpf_timeout(ioc
);
3183 ioc
->iocpf
.poll_time
+= BFA_IOC_POLL_TOV
;
3184 bfa_iocpf_poll_timer_start(ioc
);
3189 bfa_iocpf_poll_timeout(void *ioc_arg
)
3191 struct bfa_ioc_s
*ioc
= (struct bfa_ioc_s
*) ioc_arg
;
3193 bfa_ioc_poll_fwinit(ioc
);
3197 * bfa timer function
3200 bfa_timer_beat(struct bfa_timer_mod_s
*mod
)
3202 struct list_head
*qh
= &mod
->timer_q
;
3203 struct list_head
*qe
, *qe_next
;
3204 struct bfa_timer_s
*elem
;
3205 struct list_head timedout_q
;
3207 INIT_LIST_HEAD(&timedout_q
);
3209 qe
= bfa_q_next(qh
);
3212 qe_next
= bfa_q_next(qe
);
3214 elem
= (struct bfa_timer_s
*) qe
;
3215 if (elem
->timeout
<= BFA_TIMER_FREQ
) {
3217 list_del(&elem
->qe
);
3218 list_add_tail(&elem
->qe
, &timedout_q
);
3220 elem
->timeout
-= BFA_TIMER_FREQ
;
3223 qe
= qe_next
; /* go to next elem */
3227 * Pop all the timeout entries
3229 while (!list_empty(&timedout_q
)) {
3230 bfa_q_deq(&timedout_q
, &elem
);
3231 elem
->timercb(elem
->arg
);
3236 * Should be called with lock protection
3239 bfa_timer_begin(struct bfa_timer_mod_s
*mod
, struct bfa_timer_s
*timer
,
3240 void (*timercb
) (void *), void *arg
, unsigned int timeout
)
3243 WARN_ON(timercb
== NULL
);
3244 WARN_ON(bfa_q_is_on_q(&mod
->timer_q
, timer
));
3246 timer
->timeout
= timeout
;
3247 timer
->timercb
= timercb
;
3250 list_add_tail(&timer
->qe
, &mod
->timer_q
);
3254 * Should be called with lock protection
3257 bfa_timer_stop(struct bfa_timer_s
*timer
)
3259 WARN_ON(list_empty(&timer
->qe
));
3261 list_del(&timer
->qe
);
3265 * ASIC block related
3268 bfa_ablk_config_swap(struct bfa_ablk_cfg_s
*cfg
)
3270 struct bfa_ablk_cfg_inst_s
*cfg_inst
;
3274 for (i
= 0; i
< BFA_ABLK_MAX
; i
++) {
3275 cfg_inst
= &cfg
->inst
[i
];
3276 for (j
= 0; j
< BFA_ABLK_MAX_PFS
; j
++) {
3277 be16
= cfg_inst
->pf_cfg
[j
].pers
;
3278 cfg_inst
->pf_cfg
[j
].pers
= be16_to_cpu(be16
);
3279 be16
= cfg_inst
->pf_cfg
[j
].num_qpairs
;
3280 cfg_inst
->pf_cfg
[j
].num_qpairs
= be16_to_cpu(be16
);
3281 be16
= cfg_inst
->pf_cfg
[j
].num_vectors
;
3282 cfg_inst
->pf_cfg
[j
].num_vectors
= be16_to_cpu(be16
);
3283 be16
= cfg_inst
->pf_cfg
[j
].bw_min
;
3284 cfg_inst
->pf_cfg
[j
].bw_min
= be16_to_cpu(be16
);
3285 be16
= cfg_inst
->pf_cfg
[j
].bw_max
;
3286 cfg_inst
->pf_cfg
[j
].bw_max
= be16_to_cpu(be16
);
3292 bfa_ablk_isr(void *cbarg
, struct bfi_mbmsg_s
*msg
)
3294 struct bfa_ablk_s
*ablk
= (struct bfa_ablk_s
*)cbarg
;
3295 struct bfi_ablk_i2h_rsp_s
*rsp
= (struct bfi_ablk_i2h_rsp_s
*)msg
;
3296 bfa_ablk_cbfn_t cbfn
;
3298 WARN_ON(msg
->mh
.msg_class
!= BFI_MC_ABLK
);
3299 bfa_trc(ablk
->ioc
, msg
->mh
.msg_id
);
3301 switch (msg
->mh
.msg_id
) {
3302 case BFI_ABLK_I2H_QUERY
:
3303 if (rsp
->status
== BFA_STATUS_OK
) {
3304 memcpy(ablk
->cfg
, ablk
->dma_addr
.kva
,
3305 sizeof(struct bfa_ablk_cfg_s
));
3306 bfa_ablk_config_swap(ablk
->cfg
);
3311 case BFI_ABLK_I2H_ADPT_CONFIG
:
3312 case BFI_ABLK_I2H_PORT_CONFIG
:
3313 /* update config port mode */
3314 ablk
->ioc
->port_mode_cfg
= rsp
->port_mode
;
3316 case BFI_ABLK_I2H_PF_DELETE
:
3317 case BFI_ABLK_I2H_PF_UPDATE
:
3318 case BFI_ABLK_I2H_OPTROM_ENABLE
:
3319 case BFI_ABLK_I2H_OPTROM_DISABLE
:
3323 case BFI_ABLK_I2H_PF_CREATE
:
3324 *(ablk
->pcifn
) = rsp
->pcifn
;
3332 ablk
->busy
= BFA_FALSE
;
3336 cbfn(ablk
->cbarg
, rsp
->status
);
3341 bfa_ablk_notify(void *cbarg
, enum bfa_ioc_event_e event
)
3343 struct bfa_ablk_s
*ablk
= (struct bfa_ablk_s
*)cbarg
;
3345 bfa_trc(ablk
->ioc
, event
);
3348 case BFA_IOC_E_ENABLED
:
3349 WARN_ON(ablk
->busy
!= BFA_FALSE
);
3352 case BFA_IOC_E_DISABLED
:
3353 case BFA_IOC_E_FAILED
:
3354 /* Fail any pending requests */
3358 ablk
->cbfn(ablk
->cbarg
, BFA_STATUS_FAILED
);
3360 ablk
->busy
= BFA_FALSE
;
3371 bfa_ablk_meminfo(void)
3373 return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s
), BFA_DMA_ALIGN_SZ
);
3377 bfa_ablk_memclaim(struct bfa_ablk_s
*ablk
, u8
*dma_kva
, u64 dma_pa
)
3379 ablk
->dma_addr
.kva
= dma_kva
;
3380 ablk
->dma_addr
.pa
= dma_pa
;
3384 bfa_ablk_attach(struct bfa_ablk_s
*ablk
, struct bfa_ioc_s
*ioc
)
3388 bfa_ioc_mbox_regisr(ablk
->ioc
, BFI_MC_ABLK
, bfa_ablk_isr
, ablk
);
3389 bfa_q_qe_init(&ablk
->ioc_notify
);
3390 bfa_ioc_notify_init(&ablk
->ioc_notify
, bfa_ablk_notify
, ablk
);
3391 list_add_tail(&ablk
->ioc_notify
.qe
, &ablk
->ioc
->notify_q
);
3395 bfa_ablk_query(struct bfa_ablk_s
*ablk
, struct bfa_ablk_cfg_s
*ablk_cfg
,
3396 bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3398 struct bfi_ablk_h2i_query_s
*m
;
3402 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3403 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3404 return BFA_STATUS_IOC_FAILURE
;
3408 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3409 return BFA_STATUS_DEVBUSY
;
3412 ablk
->cfg
= ablk_cfg
;
3414 ablk
->cbarg
= cbarg
;
3415 ablk
->busy
= BFA_TRUE
;
3417 m
= (struct bfi_ablk_h2i_query_s
*)ablk
->mb
.msg
;
3418 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_QUERY
,
3419 bfa_ioc_portid(ablk
->ioc
));
3420 bfa_dma_be_addr_set(m
->addr
, ablk
->dma_addr
.pa
);
3421 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3423 return BFA_STATUS_OK
;
3427 bfa_ablk_pf_create(struct bfa_ablk_s
*ablk
, u16
*pcifn
,
3428 u8 port
, enum bfi_pcifn_class personality
,
3429 u16 bw_min
, u16 bw_max
,
3430 bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3432 struct bfi_ablk_h2i_pf_req_s
*m
;
3434 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3435 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3436 return BFA_STATUS_IOC_FAILURE
;
3440 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3441 return BFA_STATUS_DEVBUSY
;
3444 ablk
->pcifn
= pcifn
;
3446 ablk
->cbarg
= cbarg
;
3447 ablk
->busy
= BFA_TRUE
;
3449 m
= (struct bfi_ablk_h2i_pf_req_s
*)ablk
->mb
.msg
;
3450 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_PF_CREATE
,
3451 bfa_ioc_portid(ablk
->ioc
));
3452 m
->pers
= cpu_to_be16((u16
)personality
);
3453 m
->bw_min
= cpu_to_be16(bw_min
);
3454 m
->bw_max
= cpu_to_be16(bw_max
);
3456 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3458 return BFA_STATUS_OK
;
3462 bfa_ablk_pf_delete(struct bfa_ablk_s
*ablk
, int pcifn
,
3463 bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3465 struct bfi_ablk_h2i_pf_req_s
*m
;
3467 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3468 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3469 return BFA_STATUS_IOC_FAILURE
;
3473 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3474 return BFA_STATUS_DEVBUSY
;
3478 ablk
->cbarg
= cbarg
;
3479 ablk
->busy
= BFA_TRUE
;
3481 m
= (struct bfi_ablk_h2i_pf_req_s
*)ablk
->mb
.msg
;
3482 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_PF_DELETE
,
3483 bfa_ioc_portid(ablk
->ioc
));
3484 m
->pcifn
= (u8
)pcifn
;
3485 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3487 return BFA_STATUS_OK
;
3491 bfa_ablk_adapter_config(struct bfa_ablk_s
*ablk
, enum bfa_mode_s mode
,
3492 int max_pf
, int max_vf
, bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3494 struct bfi_ablk_h2i_cfg_req_s
*m
;
3496 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3497 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3498 return BFA_STATUS_IOC_FAILURE
;
3502 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3503 return BFA_STATUS_DEVBUSY
;
3507 ablk
->cbarg
= cbarg
;
3508 ablk
->busy
= BFA_TRUE
;
3510 m
= (struct bfi_ablk_h2i_cfg_req_s
*)ablk
->mb
.msg
;
3511 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_ADPT_CONFIG
,
3512 bfa_ioc_portid(ablk
->ioc
));
3514 m
->max_pf
= (u8
)max_pf
;
3515 m
->max_vf
= (u8
)max_vf
;
3516 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3518 return BFA_STATUS_OK
;
3522 bfa_ablk_port_config(struct bfa_ablk_s
*ablk
, int port
, enum bfa_mode_s mode
,
3523 int max_pf
, int max_vf
, bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3525 struct bfi_ablk_h2i_cfg_req_s
*m
;
3527 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3528 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3529 return BFA_STATUS_IOC_FAILURE
;
3533 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3534 return BFA_STATUS_DEVBUSY
;
3538 ablk
->cbarg
= cbarg
;
3539 ablk
->busy
= BFA_TRUE
;
3541 m
= (struct bfi_ablk_h2i_cfg_req_s
*)ablk
->mb
.msg
;
3542 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_PORT_CONFIG
,
3543 bfa_ioc_portid(ablk
->ioc
));
3546 m
->max_pf
= (u8
)max_pf
;
3547 m
->max_vf
= (u8
)max_vf
;
3548 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3550 return BFA_STATUS_OK
;
3554 bfa_ablk_pf_update(struct bfa_ablk_s
*ablk
, int pcifn
, u16 bw_min
,
3555 u16 bw_max
, bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3557 struct bfi_ablk_h2i_pf_req_s
*m
;
3559 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3560 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3561 return BFA_STATUS_IOC_FAILURE
;
3565 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3566 return BFA_STATUS_DEVBUSY
;
3570 ablk
->cbarg
= cbarg
;
3571 ablk
->busy
= BFA_TRUE
;
3573 m
= (struct bfi_ablk_h2i_pf_req_s
*)ablk
->mb
.msg
;
3574 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_PF_UPDATE
,
3575 bfa_ioc_portid(ablk
->ioc
));
3576 m
->pcifn
= (u8
)pcifn
;
3577 m
->bw_min
= cpu_to_be16(bw_min
);
3578 m
->bw_max
= cpu_to_be16(bw_max
);
3579 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3581 return BFA_STATUS_OK
;
3585 bfa_ablk_optrom_en(struct bfa_ablk_s
*ablk
, bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3587 struct bfi_ablk_h2i_optrom_s
*m
;
3589 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3590 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3591 return BFA_STATUS_IOC_FAILURE
;
3595 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3596 return BFA_STATUS_DEVBUSY
;
3600 ablk
->cbarg
= cbarg
;
3601 ablk
->busy
= BFA_TRUE
;
3603 m
= (struct bfi_ablk_h2i_optrom_s
*)ablk
->mb
.msg
;
3604 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_OPTROM_ENABLE
,
3605 bfa_ioc_portid(ablk
->ioc
));
3606 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3608 return BFA_STATUS_OK
;
3612 bfa_ablk_optrom_dis(struct bfa_ablk_s
*ablk
, bfa_ablk_cbfn_t cbfn
, void *cbarg
)
3614 struct bfi_ablk_h2i_optrom_s
*m
;
3616 if (!bfa_ioc_is_operational(ablk
->ioc
)) {
3617 bfa_trc(ablk
->ioc
, BFA_STATUS_IOC_FAILURE
);
3618 return BFA_STATUS_IOC_FAILURE
;
3622 bfa_trc(ablk
->ioc
, BFA_STATUS_DEVBUSY
);
3623 return BFA_STATUS_DEVBUSY
;
3627 ablk
->cbarg
= cbarg
;
3628 ablk
->busy
= BFA_TRUE
;
3630 m
= (struct bfi_ablk_h2i_optrom_s
*)ablk
->mb
.msg
;
3631 bfi_h2i_set(m
->mh
, BFI_MC_ABLK
, BFI_ABLK_H2I_OPTROM_DISABLE
,
3632 bfa_ioc_portid(ablk
->ioc
));
3633 bfa_ioc_mbox_queue(ablk
->ioc
, &ablk
->mb
);
3635 return BFA_STATUS_OK
;
3639 * SFP module specific
3642 /* forward declarations */
3643 static void bfa_sfp_getdata_send(struct bfa_sfp_s
*sfp
);
3644 static void bfa_sfp_media_get(struct bfa_sfp_s
*sfp
);
3645 static bfa_status_t
bfa_sfp_speed_valid(struct bfa_sfp_s
*sfp
,
3646 enum bfa_port_speed portspeed
);
3649 bfa_cb_sfp_show(struct bfa_sfp_s
*sfp
)
3651 bfa_trc(sfp
, sfp
->lock
);
3653 sfp
->cbfn(sfp
->cbarg
, sfp
->status
);
3659 bfa_cb_sfp_state_query(struct bfa_sfp_s
*sfp
)
3661 bfa_trc(sfp
, sfp
->portspeed
);
3663 bfa_sfp_media_get(sfp
);
3664 if (sfp
->state_query_cbfn
)
3665 sfp
->state_query_cbfn(sfp
->state_query_cbarg
,
3670 if (sfp
->portspeed
) {
3671 sfp
->status
= bfa_sfp_speed_valid(sfp
, sfp
->portspeed
);
3672 if (sfp
->state_query_cbfn
)
3673 sfp
->state_query_cbfn(sfp
->state_query_cbarg
,
3675 sfp
->portspeed
= BFA_PORT_SPEED_UNKNOWN
;
3678 sfp
->state_query_lock
= 0;
3679 sfp
->state_query_cbfn
= NULL
;
3683 * IOC event handler.
3686 bfa_sfp_notify(void *sfp_arg
, enum bfa_ioc_event_e event
)
3688 struct bfa_sfp_s
*sfp
= sfp_arg
;
3690 bfa_trc(sfp
, event
);
3691 bfa_trc(sfp
, sfp
->lock
);
3692 bfa_trc(sfp
, sfp
->state_query_lock
);
3695 case BFA_IOC_E_DISABLED
:
3696 case BFA_IOC_E_FAILED
:
3698 sfp
->status
= BFA_STATUS_IOC_FAILURE
;
3699 bfa_cb_sfp_show(sfp
);
3702 if (sfp
->state_query_lock
) {
3703 sfp
->status
= BFA_STATUS_IOC_FAILURE
;
3704 bfa_cb_sfp_state_query(sfp
);
3714 * SFP's State Change Notification post to AEN
3717 bfa_sfp_scn_aen_post(struct bfa_sfp_s
*sfp
, struct bfi_sfp_scn_s
*rsp
)
3719 struct bfad_s
*bfad
= (struct bfad_s
*)sfp
->ioc
->bfa
->bfad
;
3720 struct bfa_aen_entry_s
*aen_entry
;
3721 enum bfa_port_aen_event aen_evt
= 0;
3723 bfa_trc(sfp
, (((u64
)rsp
->pomlvl
) << 16) | (((u64
)rsp
->sfpid
) << 8) |
3726 bfad_get_aen_entry(bfad
, aen_entry
);
3730 aen_entry
->aen_data
.port
.ioc_type
= bfa_ioc_get_type(sfp
->ioc
);
3731 aen_entry
->aen_data
.port
.pwwn
= sfp
->ioc
->attr
->pwwn
;
3732 aen_entry
->aen_data
.port
.mac
= bfa_ioc_get_mac(sfp
->ioc
);
3734 switch (rsp
->event
) {
3735 case BFA_SFP_SCN_INSERTED
:
3736 aen_evt
= BFA_PORT_AEN_SFP_INSERT
;
3738 case BFA_SFP_SCN_REMOVED
:
3739 aen_evt
= BFA_PORT_AEN_SFP_REMOVE
;
3741 case BFA_SFP_SCN_FAILED
:
3742 aen_evt
= BFA_PORT_AEN_SFP_ACCESS_ERROR
;
3744 case BFA_SFP_SCN_UNSUPPORT
:
3745 aen_evt
= BFA_PORT_AEN_SFP_UNSUPPORT
;
3747 case BFA_SFP_SCN_POM
:
3748 aen_evt
= BFA_PORT_AEN_SFP_POM
;
3749 aen_entry
->aen_data
.port
.level
= rsp
->pomlvl
;
3752 bfa_trc(sfp
, rsp
->event
);
3756 /* Send the AEN notification */
3757 bfad_im_post_vendor_event(aen_entry
, bfad
, ++sfp
->ioc
->ioc_aen_seq
,
3758 BFA_AEN_CAT_PORT
, aen_evt
);
3765 bfa_sfp_getdata_send(struct bfa_sfp_s
*sfp
)
3767 struct bfi_sfp_req_s
*req
= (struct bfi_sfp_req_s
*)sfp
->mbcmd
.msg
;
3769 bfa_trc(sfp
, req
->memtype
);
3771 /* build host command */
3772 bfi_h2i_set(req
->mh
, BFI_MC_SFP
, BFI_SFP_H2I_SHOW
,
3773 bfa_ioc_portid(sfp
->ioc
));
3776 bfa_ioc_mbox_queue(sfp
->ioc
, &sfp
->mbcmd
);
3780 * SFP is valid, read sfp data
3783 bfa_sfp_getdata(struct bfa_sfp_s
*sfp
, enum bfi_sfp_mem_e memtype
)
3785 struct bfi_sfp_req_s
*req
= (struct bfi_sfp_req_s
*)sfp
->mbcmd
.msg
;
3787 WARN_ON(sfp
->lock
!= 0);
3788 bfa_trc(sfp
, sfp
->state
);
3791 sfp
->memtype
= memtype
;
3792 req
->memtype
= memtype
;
3795 bfa_alen_set(&req
->alen
, sizeof(struct sfp_mem_s
), sfp
->dbuf_pa
);
3797 bfa_sfp_getdata_send(sfp
);
3804 bfa_sfp_scn(struct bfa_sfp_s
*sfp
, struct bfi_mbmsg_s
*msg
)
3806 struct bfi_sfp_scn_s
*rsp
= (struct bfi_sfp_scn_s
*) msg
;
3808 switch (rsp
->event
) {
3809 case BFA_SFP_SCN_INSERTED
:
3810 sfp
->state
= BFA_SFP_STATE_INSERTED
;
3811 sfp
->data_valid
= 0;
3812 bfa_sfp_scn_aen_post(sfp
, rsp
);
3814 case BFA_SFP_SCN_REMOVED
:
3815 sfp
->state
= BFA_SFP_STATE_REMOVED
;
3816 sfp
->data_valid
= 0;
3817 bfa_sfp_scn_aen_post(sfp
, rsp
);
3819 case BFA_SFP_SCN_FAILED
:
3820 sfp
->state
= BFA_SFP_STATE_FAILED
;
3821 sfp
->data_valid
= 0;
3822 bfa_sfp_scn_aen_post(sfp
, rsp
);
3824 case BFA_SFP_SCN_UNSUPPORT
:
3825 sfp
->state
= BFA_SFP_STATE_UNSUPPORT
;
3826 bfa_sfp_scn_aen_post(sfp
, rsp
);
3828 bfa_sfp_getdata(sfp
, BFI_SFP_MEM_ALL
);
3830 case BFA_SFP_SCN_POM
:
3831 bfa_sfp_scn_aen_post(sfp
, rsp
);
3833 case BFA_SFP_SCN_VALID
:
3834 sfp
->state
= BFA_SFP_STATE_VALID
;
3836 bfa_sfp_getdata(sfp
, BFI_SFP_MEM_ALL
);
3839 bfa_trc(sfp
, rsp
->event
);
3848 bfa_sfp_show_comp(struct bfa_sfp_s
*sfp
, struct bfi_mbmsg_s
*msg
)
3850 struct bfi_sfp_rsp_s
*rsp
= (struct bfi_sfp_rsp_s
*) msg
;
3854 * receiving response after ioc failure
3856 bfa_trc(sfp
, sfp
->lock
);
3860 bfa_trc(sfp
, rsp
->status
);
3861 if (rsp
->status
== BFA_STATUS_OK
) {
3862 sfp
->data_valid
= 1;
3863 if (sfp
->state
== BFA_SFP_STATE_VALID
)
3864 sfp
->status
= BFA_STATUS_OK
;
3865 else if (sfp
->state
== BFA_SFP_STATE_UNSUPPORT
)
3866 sfp
->status
= BFA_STATUS_SFP_UNSUPP
;
3868 bfa_trc(sfp
, sfp
->state
);
3870 sfp
->data_valid
= 0;
3871 sfp
->status
= rsp
->status
;
3872 /* sfpshow shouldn't change sfp state */
3875 bfa_trc(sfp
, sfp
->memtype
);
3876 if (sfp
->memtype
== BFI_SFP_MEM_DIAGEXT
) {
3877 bfa_trc(sfp
, sfp
->data_valid
);
3878 if (sfp
->data_valid
) {
3879 u32 size
= sizeof(struct sfp_mem_s
);
3880 u8
*des
= (u8
*)(sfp
->sfpmem
);
3881 memcpy(des
, sfp
->dbuf_kva
, size
);
3884 * Queue completion callback.
3886 bfa_cb_sfp_show(sfp
);
3890 bfa_trc(sfp
, sfp
->state_query_lock
);
3891 if (sfp
->state_query_lock
) {
3892 sfp
->state
= rsp
->state
;
3893 /* Complete callback */
3894 bfa_cb_sfp_state_query(sfp
);
3899 * SFP query fw sfp state
3902 bfa_sfp_state_query(struct bfa_sfp_s
*sfp
)
3904 struct bfi_sfp_req_s
*req
= (struct bfi_sfp_req_s
*)sfp
->mbcmd
.msg
;
3906 /* Should not be doing query if not in _INIT state */
3907 WARN_ON(sfp
->state
!= BFA_SFP_STATE_INIT
);
3908 WARN_ON(sfp
->state_query_lock
!= 0);
3909 bfa_trc(sfp
, sfp
->state
);
3911 sfp
->state_query_lock
= 1;
3915 bfa_sfp_getdata(sfp
, BFI_SFP_MEM_ALL
);
3919 bfa_sfp_media_get(struct bfa_sfp_s
*sfp
)
3921 enum bfa_defs_sfp_media_e
*media
= sfp
->media
;
3923 *media
= BFA_SFP_MEDIA_UNKNOWN
;
3925 if (sfp
->state
== BFA_SFP_STATE_UNSUPPORT
)
3926 *media
= BFA_SFP_MEDIA_UNSUPPORT
;
3927 else if (sfp
->state
== BFA_SFP_STATE_VALID
) {
3928 union sfp_xcvr_e10g_code_u e10g
;
3929 struct sfp_mem_s
*sfpmem
= (struct sfp_mem_s
*)sfp
->dbuf_kva
;
3930 u16 xmtr_tech
= (sfpmem
->srlid_base
.xcvr
[4] & 0x3) << 7 |
3931 (sfpmem
->srlid_base
.xcvr
[5] >> 1);
3933 e10g
.b
= sfpmem
->srlid_base
.xcvr
[0];
3934 bfa_trc(sfp
, e10g
.b
);
3935 bfa_trc(sfp
, xmtr_tech
);
3936 /* check fc transmitter tech */
3937 if ((xmtr_tech
& SFP_XMTR_TECH_CU
) ||
3938 (xmtr_tech
& SFP_XMTR_TECH_CP
) ||
3939 (xmtr_tech
& SFP_XMTR_TECH_CA
))
3940 *media
= BFA_SFP_MEDIA_CU
;
3941 else if ((xmtr_tech
& SFP_XMTR_TECH_EL_INTRA
) ||
3942 (xmtr_tech
& SFP_XMTR_TECH_EL_INTER
))
3943 *media
= BFA_SFP_MEDIA_EL
;
3944 else if ((xmtr_tech
& SFP_XMTR_TECH_LL
) ||
3945 (xmtr_tech
& SFP_XMTR_TECH_LC
))
3946 *media
= BFA_SFP_MEDIA_LW
;
3947 else if ((xmtr_tech
& SFP_XMTR_TECH_SL
) ||
3948 (xmtr_tech
& SFP_XMTR_TECH_SN
) ||
3949 (xmtr_tech
& SFP_XMTR_TECH_SA
))
3950 *media
= BFA_SFP_MEDIA_SW
;
3951 /* Check 10G Ethernet Compilance code */
3952 else if (e10g
.r
.e10g_sr
)
3953 *media
= BFA_SFP_MEDIA_SW
;
3954 else if (e10g
.r
.e10g_lrm
&& e10g
.r
.e10g_lr
)
3955 *media
= BFA_SFP_MEDIA_LW
;
3956 else if (e10g
.r
.e10g_unall
)
3957 *media
= BFA_SFP_MEDIA_UNKNOWN
;
3961 bfa_trc(sfp
, sfp
->state
);
3965 bfa_sfp_speed_valid(struct bfa_sfp_s
*sfp
, enum bfa_port_speed portspeed
)
3967 struct sfp_mem_s
*sfpmem
= (struct sfp_mem_s
*)sfp
->dbuf_kva
;
3968 struct sfp_xcvr_s
*xcvr
= (struct sfp_xcvr_s
*) sfpmem
->srlid_base
.xcvr
;
3969 union sfp_xcvr_fc3_code_u fc3
= xcvr
->fc3
;
3970 union sfp_xcvr_e10g_code_u e10g
= xcvr
->e10g
;
3972 if (portspeed
== BFA_PORT_SPEED_10GBPS
) {
3973 if (e10g
.r
.e10g_sr
|| e10g
.r
.e10g_lr
)
3974 return BFA_STATUS_OK
;
3976 bfa_trc(sfp
, e10g
.b
);
3977 return BFA_STATUS_UNSUPP_SPEED
;
3980 if (((portspeed
& BFA_PORT_SPEED_16GBPS
) && fc3
.r
.mb1600
) ||
3981 ((portspeed
& BFA_PORT_SPEED_8GBPS
) && fc3
.r
.mb800
) ||
3982 ((portspeed
& BFA_PORT_SPEED_4GBPS
) && fc3
.r
.mb400
) ||
3983 ((portspeed
& BFA_PORT_SPEED_2GBPS
) && fc3
.r
.mb200
) ||
3984 ((portspeed
& BFA_PORT_SPEED_1GBPS
) && fc3
.r
.mb100
))
3985 return BFA_STATUS_OK
;
3987 bfa_trc(sfp
, portspeed
);
3988 bfa_trc(sfp
, fc3
.b
);
3989 bfa_trc(sfp
, e10g
.b
);
3990 return BFA_STATUS_UNSUPP_SPEED
;
3998 bfa_sfp_intr(void *sfparg
, struct bfi_mbmsg_s
*msg
)
4000 struct bfa_sfp_s
*sfp
= sfparg
;
4002 switch (msg
->mh
.msg_id
) {
4003 case BFI_SFP_I2H_SHOW
:
4004 bfa_sfp_show_comp(sfp
, msg
);
4007 case BFI_SFP_I2H_SCN
:
4008 bfa_sfp_scn(sfp
, msg
);
4012 bfa_trc(sfp
, msg
->mh
.msg_id
);
4018 * Return DMA memory needed by sfp module.
4021 bfa_sfp_meminfo(void)
4023 return BFA_ROUNDUP(sizeof(struct sfp_mem_s
), BFA_DMA_ALIGN_SZ
);
4027 * Attach virtual and physical memory for SFP.
4030 bfa_sfp_attach(struct bfa_sfp_s
*sfp
, struct bfa_ioc_s
*ioc
, void *dev
,
4031 struct bfa_trc_mod_s
*trcmod
)
4035 sfp
->trcmod
= trcmod
;
4041 sfp
->data_valid
= 0;
4042 sfp
->state
= BFA_SFP_STATE_INIT
;
4043 sfp
->state_query_lock
= 0;
4044 sfp
->state_query_cbfn
= NULL
;
4045 sfp
->state_query_cbarg
= NULL
;
4047 sfp
->portspeed
= BFA_PORT_SPEED_UNKNOWN
;
4048 sfp
->is_elb
= BFA_FALSE
;
4050 bfa_ioc_mbox_regisr(sfp
->ioc
, BFI_MC_SFP
, bfa_sfp_intr
, sfp
);
4051 bfa_q_qe_init(&sfp
->ioc_notify
);
4052 bfa_ioc_notify_init(&sfp
->ioc_notify
, bfa_sfp_notify
, sfp
);
4053 list_add_tail(&sfp
->ioc_notify
.qe
, &sfp
->ioc
->notify_q
);
4057 * Claim Memory for SFP
4060 bfa_sfp_memclaim(struct bfa_sfp_s
*sfp
, u8
*dm_kva
, u64 dm_pa
)
4062 sfp
->dbuf_kva
= dm_kva
;
4063 sfp
->dbuf_pa
= dm_pa
;
4064 memset(sfp
->dbuf_kva
, 0, sizeof(struct sfp_mem_s
));
4066 dm_kva
+= BFA_ROUNDUP(sizeof(struct sfp_mem_s
), BFA_DMA_ALIGN_SZ
);
4067 dm_pa
+= BFA_ROUNDUP(sizeof(struct sfp_mem_s
), BFA_DMA_ALIGN_SZ
);
4071 * Show SFP eeprom content
4073 * @param[in] sfp - bfa sfp module
4075 * @param[out] sfpmem - sfp eeprom data
4079 bfa_sfp_show(struct bfa_sfp_s
*sfp
, struct sfp_mem_s
*sfpmem
,
4080 bfa_cb_sfp_t cbfn
, void *cbarg
)
4083 if (!bfa_ioc_is_operational(sfp
->ioc
)) {
4085 return BFA_STATUS_IOC_NON_OP
;
4090 return BFA_STATUS_DEVBUSY
;
4095 sfp
->sfpmem
= sfpmem
;
4097 bfa_sfp_getdata(sfp
, BFI_SFP_MEM_DIAGEXT
);
4098 return BFA_STATUS_OK
;
4102 * Return SFP Media type
4104 * @param[in] sfp - bfa sfp module
4106 * @param[out] media - port speed from user
4110 bfa_sfp_media(struct bfa_sfp_s
*sfp
, enum bfa_defs_sfp_media_e
*media
,
4111 bfa_cb_sfp_t cbfn
, void *cbarg
)
4113 if (!bfa_ioc_is_operational(sfp
->ioc
)) {
4115 return BFA_STATUS_IOC_NON_OP
;
4119 if (sfp
->state
== BFA_SFP_STATE_INIT
) {
4120 if (sfp
->state_query_lock
) {
4122 return BFA_STATUS_DEVBUSY
;
4124 sfp
->state_query_cbfn
= cbfn
;
4125 sfp
->state_query_cbarg
= cbarg
;
4126 bfa_sfp_state_query(sfp
);
4127 return BFA_STATUS_SFP_NOT_READY
;
4131 bfa_sfp_media_get(sfp
);
4132 return BFA_STATUS_OK
;
4136 * Check if user set port speed is allowed by the SFP
4138 * @param[in] sfp - bfa sfp module
4139 * @param[in] portspeed - port speed from user
4143 bfa_sfp_speed(struct bfa_sfp_s
*sfp
, enum bfa_port_speed portspeed
,
4144 bfa_cb_sfp_t cbfn
, void *cbarg
)
4146 WARN_ON(portspeed
== BFA_PORT_SPEED_UNKNOWN
);
4148 if (!bfa_ioc_is_operational(sfp
->ioc
))
4149 return BFA_STATUS_IOC_NON_OP
;
4151 /* For Mezz card, all speed is allowed */
4152 if (bfa_mfg_is_mezz(sfp
->ioc
->attr
->card_type
))
4153 return BFA_STATUS_OK
;
4155 /* Check SFP state */
4156 sfp
->portspeed
= portspeed
;
4157 if (sfp
->state
== BFA_SFP_STATE_INIT
) {
4158 if (sfp
->state_query_lock
) {
4160 return BFA_STATUS_DEVBUSY
;
4162 sfp
->state_query_cbfn
= cbfn
;
4163 sfp
->state_query_cbarg
= cbarg
;
4164 bfa_sfp_state_query(sfp
);
4165 return BFA_STATUS_SFP_NOT_READY
;
4169 if (sfp
->state
== BFA_SFP_STATE_REMOVED
||
4170 sfp
->state
== BFA_SFP_STATE_FAILED
) {
4171 bfa_trc(sfp
, sfp
->state
);
4172 return BFA_STATUS_NO_SFP_DEV
;
4175 if (sfp
->state
== BFA_SFP_STATE_INSERTED
) {
4176 bfa_trc(sfp
, sfp
->state
);
4177 return BFA_STATUS_DEVBUSY
; /* sfp is reading data */
4180 /* For eloopback, all speed is allowed */
4182 return BFA_STATUS_OK
;
4184 return bfa_sfp_speed_valid(sfp
, portspeed
);
4188 * Flash module specific
4192 * FLASH DMA buffer should be big enough to hold both MFG block and
4193 * asic block(64k) at the same time and also should be 2k aligned to
4194 * avoid write segement to cross sector boundary.
4196 #define BFA_FLASH_SEG_SZ 2048
4197 #define BFA_FLASH_DMA_BUF_SZ \
4198 BFA_ROUNDUP(0x010000 + sizeof(struct bfa_mfg_block_s), BFA_FLASH_SEG_SZ)
4201 bfa_flash_aen_audit_post(struct bfa_ioc_s
*ioc
, enum bfa_audit_aen_event event
,
4204 struct bfad_s
*bfad
= (struct bfad_s
*)ioc
->bfa
->bfad
;
4205 struct bfa_aen_entry_s
*aen_entry
;
4207 bfad_get_aen_entry(bfad
, aen_entry
);
4211 aen_entry
->aen_data
.audit
.pwwn
= ioc
->attr
->pwwn
;
4212 aen_entry
->aen_data
.audit
.partition_inst
= inst
;
4213 aen_entry
->aen_data
.audit
.partition_type
= type
;
4215 /* Send the AEN notification */
4216 bfad_im_post_vendor_event(aen_entry
, bfad
, ++ioc
->ioc_aen_seq
,
4217 BFA_AEN_CAT_AUDIT
, event
);
4221 bfa_flash_cb(struct bfa_flash_s
*flash
)
4225 flash
->cbfn(flash
->cbarg
, flash
->status
);
4229 bfa_flash_notify(void *cbarg
, enum bfa_ioc_event_e event
)
4231 struct bfa_flash_s
*flash
= cbarg
;
4233 bfa_trc(flash
, event
);
4235 case BFA_IOC_E_DISABLED
:
4236 case BFA_IOC_E_FAILED
:
4237 if (flash
->op_busy
) {
4238 flash
->status
= BFA_STATUS_IOC_FAILURE
;
4239 flash
->cbfn(flash
->cbarg
, flash
->status
);
4250 * Send flash attribute query request.
4252 * @param[in] cbarg - callback argument
4255 bfa_flash_query_send(void *cbarg
)
4257 struct bfa_flash_s
*flash
= cbarg
;
4258 struct bfi_flash_query_req_s
*msg
=
4259 (struct bfi_flash_query_req_s
*) flash
->mb
.msg
;
4261 bfi_h2i_set(msg
->mh
, BFI_MC_FLASH
, BFI_FLASH_H2I_QUERY_REQ
,
4262 bfa_ioc_portid(flash
->ioc
));
4263 bfa_alen_set(&msg
->alen
, sizeof(struct bfa_flash_attr_s
),
4265 bfa_ioc_mbox_queue(flash
->ioc
, &flash
->mb
);
4269 * Send flash write request.
4271 * @param[in] cbarg - callback argument
4274 bfa_flash_write_send(struct bfa_flash_s
*flash
)
4276 struct bfi_flash_write_req_s
*msg
=
4277 (struct bfi_flash_write_req_s
*) flash
->mb
.msg
;
4280 msg
->type
= be32_to_cpu(flash
->type
);
4281 msg
->instance
= flash
->instance
;
4282 msg
->offset
= be32_to_cpu(flash
->addr_off
+ flash
->offset
);
4283 len
= (flash
->residue
< BFA_FLASH_DMA_BUF_SZ
) ?
4284 flash
->residue
: BFA_FLASH_DMA_BUF_SZ
;
4285 msg
->length
= be32_to_cpu(len
);
4287 /* indicate if it's the last msg of the whole write operation */
4288 msg
->last
= (len
== flash
->residue
) ? 1 : 0;
4290 bfi_h2i_set(msg
->mh
, BFI_MC_FLASH
, BFI_FLASH_H2I_WRITE_REQ
,
4291 bfa_ioc_portid(flash
->ioc
));
4292 bfa_alen_set(&msg
->alen
, len
, flash
->dbuf_pa
);
4293 memcpy(flash
->dbuf_kva
, flash
->ubuf
+ flash
->offset
, len
);
4294 bfa_ioc_mbox_queue(flash
->ioc
, &flash
->mb
);
4296 flash
->residue
-= len
;
4297 flash
->offset
+= len
;
4301 * Send flash read request.
4303 * @param[in] cbarg - callback argument
4306 bfa_flash_read_send(void *cbarg
)
4308 struct bfa_flash_s
*flash
= cbarg
;
4309 struct bfi_flash_read_req_s
*msg
=
4310 (struct bfi_flash_read_req_s
*) flash
->mb
.msg
;
4313 msg
->type
= be32_to_cpu(flash
->type
);
4314 msg
->instance
= flash
->instance
;
4315 msg
->offset
= be32_to_cpu(flash
->addr_off
+ flash
->offset
);
4316 len
= (flash
->residue
< BFA_FLASH_DMA_BUF_SZ
) ?
4317 flash
->residue
: BFA_FLASH_DMA_BUF_SZ
;
4318 msg
->length
= be32_to_cpu(len
);
4319 bfi_h2i_set(msg
->mh
, BFI_MC_FLASH
, BFI_FLASH_H2I_READ_REQ
,
4320 bfa_ioc_portid(flash
->ioc
));
4321 bfa_alen_set(&msg
->alen
, len
, flash
->dbuf_pa
);
4322 bfa_ioc_mbox_queue(flash
->ioc
, &flash
->mb
);
4326 * Send flash erase request.
4328 * @param[in] cbarg - callback argument
4331 bfa_flash_erase_send(void *cbarg
)
4333 struct bfa_flash_s
*flash
= cbarg
;
4334 struct bfi_flash_erase_req_s
*msg
=
4335 (struct bfi_flash_erase_req_s
*) flash
->mb
.msg
;
4337 msg
->type
= be32_to_cpu(flash
->type
);
4338 msg
->instance
= flash
->instance
;
4339 bfi_h2i_set(msg
->mh
, BFI_MC_FLASH
, BFI_FLASH_H2I_ERASE_REQ
,
4340 bfa_ioc_portid(flash
->ioc
));
4341 bfa_ioc_mbox_queue(flash
->ioc
, &flash
->mb
);
4345 * Process flash response messages upon receiving interrupts.
4347 * @param[in] flasharg - flash structure
4348 * @param[in] msg - message structure
4351 bfa_flash_intr(void *flasharg
, struct bfi_mbmsg_s
*msg
)
4353 struct bfa_flash_s
*flash
= flasharg
;
4357 struct bfi_flash_query_rsp_s
*query
;
4358 struct bfi_flash_erase_rsp_s
*erase
;
4359 struct bfi_flash_write_rsp_s
*write
;
4360 struct bfi_flash_read_rsp_s
*read
;
4361 struct bfi_flash_event_s
*event
;
4362 struct bfi_mbmsg_s
*msg
;
4366 bfa_trc(flash
, msg
->mh
.msg_id
);
4368 if (!flash
->op_busy
&& msg
->mh
.msg_id
!= BFI_FLASH_I2H_EVENT
) {
4369 /* receiving response after ioc failure */
4370 bfa_trc(flash
, 0x9999);
4374 switch (msg
->mh
.msg_id
) {
4375 case BFI_FLASH_I2H_QUERY_RSP
:
4376 status
= be32_to_cpu(m
.query
->status
);
4377 bfa_trc(flash
, status
);
4378 if (status
== BFA_STATUS_OK
) {
4380 struct bfa_flash_attr_s
*attr
, *f
;
4382 attr
= (struct bfa_flash_attr_s
*) flash
->ubuf
;
4383 f
= (struct bfa_flash_attr_s
*) flash
->dbuf_kva
;
4384 attr
->status
= be32_to_cpu(f
->status
);
4385 attr
->npart
= be32_to_cpu(f
->npart
);
4386 bfa_trc(flash
, attr
->status
);
4387 bfa_trc(flash
, attr
->npart
);
4388 for (i
= 0; i
< attr
->npart
; i
++) {
4389 attr
->part
[i
].part_type
=
4390 be32_to_cpu(f
->part
[i
].part_type
);
4391 attr
->part
[i
].part_instance
=
4392 be32_to_cpu(f
->part
[i
].part_instance
);
4393 attr
->part
[i
].part_off
=
4394 be32_to_cpu(f
->part
[i
].part_off
);
4395 attr
->part
[i
].part_size
=
4396 be32_to_cpu(f
->part
[i
].part_size
);
4397 attr
->part
[i
].part_len
=
4398 be32_to_cpu(f
->part
[i
].part_len
);
4399 attr
->part
[i
].part_status
=
4400 be32_to_cpu(f
->part
[i
].part_status
);
4403 flash
->status
= status
;
4404 bfa_flash_cb(flash
);
4406 case BFI_FLASH_I2H_ERASE_RSP
:
4407 status
= be32_to_cpu(m
.erase
->status
);
4408 bfa_trc(flash
, status
);
4409 flash
->status
= status
;
4410 bfa_flash_cb(flash
);
4412 case BFI_FLASH_I2H_WRITE_RSP
:
4413 status
= be32_to_cpu(m
.write
->status
);
4414 bfa_trc(flash
, status
);
4415 if (status
!= BFA_STATUS_OK
|| flash
->residue
== 0) {
4416 flash
->status
= status
;
4417 bfa_flash_cb(flash
);
4419 bfa_trc(flash
, flash
->offset
);
4420 bfa_flash_write_send(flash
);
4423 case BFI_FLASH_I2H_READ_RSP
:
4424 status
= be32_to_cpu(m
.read
->status
);
4425 bfa_trc(flash
, status
);
4426 if (status
!= BFA_STATUS_OK
) {
4427 flash
->status
= status
;
4428 bfa_flash_cb(flash
);
4430 u32 len
= be32_to_cpu(m
.read
->length
);
4431 bfa_trc(flash
, flash
->offset
);
4432 bfa_trc(flash
, len
);
4433 memcpy(flash
->ubuf
+ flash
->offset
,
4434 flash
->dbuf_kva
, len
);
4435 flash
->residue
-= len
;
4436 flash
->offset
+= len
;
4437 if (flash
->residue
== 0) {
4438 flash
->status
= status
;
4439 bfa_flash_cb(flash
);
4441 bfa_flash_read_send(flash
);
4444 case BFI_FLASH_I2H_BOOT_VER_RSP
:
4446 case BFI_FLASH_I2H_EVENT
:
4447 status
= be32_to_cpu(m
.event
->status
);
4448 bfa_trc(flash
, status
);
4449 if (status
== BFA_STATUS_BAD_FWCFG
)
4450 bfa_ioc_aen_post(flash
->ioc
, BFA_IOC_AEN_FWCFG_ERROR
);
4451 else if (status
== BFA_STATUS_INVALID_VENDOR
) {
4453 param
= be32_to_cpu(m
.event
->param
);
4454 bfa_trc(flash
, param
);
4455 bfa_ioc_aen_post(flash
->ioc
,
4456 BFA_IOC_AEN_INVALID_VENDOR
);
4466 * Flash memory info API.
4468 * @param[in] mincfg - minimal cfg variable
4471 bfa_flash_meminfo(bfa_boolean_t mincfg
)
4473 /* min driver doesn't need flash */
4476 return BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
4482 * @param[in] flash - flash structure
4483 * @param[in] ioc - ioc structure
4484 * @param[in] dev - device structure
4485 * @param[in] trcmod - trace module
4486 * @param[in] logmod - log module
4489 bfa_flash_attach(struct bfa_flash_s
*flash
, struct bfa_ioc_s
*ioc
, void *dev
,
4490 struct bfa_trc_mod_s
*trcmod
, bfa_boolean_t mincfg
)
4493 flash
->trcmod
= trcmod
;
4495 flash
->cbarg
= NULL
;
4498 bfa_ioc_mbox_regisr(flash
->ioc
, BFI_MC_FLASH
, bfa_flash_intr
, flash
);
4499 bfa_q_qe_init(&flash
->ioc_notify
);
4500 bfa_ioc_notify_init(&flash
->ioc_notify
, bfa_flash_notify
, flash
);
4501 list_add_tail(&flash
->ioc_notify
.qe
, &flash
->ioc
->notify_q
);
4503 /* min driver doesn't need flash */
4505 flash
->dbuf_kva
= NULL
;
4511 * Claim memory for flash
4513 * @param[in] flash - flash structure
4514 * @param[in] dm_kva - pointer to virtual memory address
4515 * @param[in] dm_pa - physical memory address
4516 * @param[in] mincfg - minimal cfg variable
4519 bfa_flash_memclaim(struct bfa_flash_s
*flash
, u8
*dm_kva
, u64 dm_pa
,
4520 bfa_boolean_t mincfg
)
4525 flash
->dbuf_kva
= dm_kva
;
4526 flash
->dbuf_pa
= dm_pa
;
4527 memset(flash
->dbuf_kva
, 0, BFA_FLASH_DMA_BUF_SZ
);
4528 dm_kva
+= BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
4529 dm_pa
+= BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
4533 * Get flash attribute.
4535 * @param[in] flash - flash structure
4536 * @param[in] attr - flash attribute structure
4537 * @param[in] cbfn - callback function
4538 * @param[in] cbarg - callback argument
4543 bfa_flash_get_attr(struct bfa_flash_s
*flash
, struct bfa_flash_attr_s
*attr
,
4544 bfa_cb_flash_t cbfn
, void *cbarg
)
4546 bfa_trc(flash
, BFI_FLASH_H2I_QUERY_REQ
);
4548 if (!bfa_ioc_is_operational(flash
->ioc
))
4549 return BFA_STATUS_IOC_NON_OP
;
4551 if (flash
->op_busy
) {
4552 bfa_trc(flash
, flash
->op_busy
);
4553 return BFA_STATUS_DEVBUSY
;
4558 flash
->cbarg
= cbarg
;
4559 flash
->ubuf
= (u8
*) attr
;
4560 bfa_flash_query_send(flash
);
4562 return BFA_STATUS_OK
;
4566 * Erase flash partition.
4568 * @param[in] flash - flash structure
4569 * @param[in] type - flash partition type
4570 * @param[in] instance - flash partition instance
4571 * @param[in] cbfn - callback function
4572 * @param[in] cbarg - callback argument
4577 bfa_flash_erase_part(struct bfa_flash_s
*flash
, enum bfa_flash_part_type type
,
4578 u8 instance
, bfa_cb_flash_t cbfn
, void *cbarg
)
4580 bfa_trc(flash
, BFI_FLASH_H2I_ERASE_REQ
);
4581 bfa_trc(flash
, type
);
4582 bfa_trc(flash
, instance
);
4584 if (!bfa_ioc_is_operational(flash
->ioc
))
4585 return BFA_STATUS_IOC_NON_OP
;
4587 if (flash
->op_busy
) {
4588 bfa_trc(flash
, flash
->op_busy
);
4589 return BFA_STATUS_DEVBUSY
;
4594 flash
->cbarg
= cbarg
;
4596 flash
->instance
= instance
;
4598 bfa_flash_erase_send(flash
);
4599 bfa_flash_aen_audit_post(flash
->ioc
, BFA_AUDIT_AEN_FLASH_ERASE
,
4601 return BFA_STATUS_OK
;
4605 * Update flash partition.
4607 * @param[in] flash - flash structure
4608 * @param[in] type - flash partition type
4609 * @param[in] instance - flash partition instance
4610 * @param[in] buf - update data buffer
4611 * @param[in] len - data buffer length
4612 * @param[in] offset - offset relative to the partition starting address
4613 * @param[in] cbfn - callback function
4614 * @param[in] cbarg - callback argument
4619 bfa_flash_update_part(struct bfa_flash_s
*flash
, enum bfa_flash_part_type type
,
4620 u8 instance
, void *buf
, u32 len
, u32 offset
,
4621 bfa_cb_flash_t cbfn
, void *cbarg
)
4623 bfa_trc(flash
, BFI_FLASH_H2I_WRITE_REQ
);
4624 bfa_trc(flash
, type
);
4625 bfa_trc(flash
, instance
);
4626 bfa_trc(flash
, len
);
4627 bfa_trc(flash
, offset
);
4629 if (!bfa_ioc_is_operational(flash
->ioc
))
4630 return BFA_STATUS_IOC_NON_OP
;
4633 * 'len' must be in word (4-byte) boundary
4634 * 'offset' must be in sector (16kb) boundary
4636 if (!len
|| (len
& 0x03) || (offset
& 0x00003FFF))
4637 return BFA_STATUS_FLASH_BAD_LEN
;
4639 if (type
== BFA_FLASH_PART_MFG
)
4640 return BFA_STATUS_EINVAL
;
4642 if (flash
->op_busy
) {
4643 bfa_trc(flash
, flash
->op_busy
);
4644 return BFA_STATUS_DEVBUSY
;
4649 flash
->cbarg
= cbarg
;
4651 flash
->instance
= instance
;
4652 flash
->residue
= len
;
4654 flash
->addr_off
= offset
;
4657 bfa_flash_write_send(flash
);
4658 return BFA_STATUS_OK
;
4662 * Read flash partition.
4664 * @param[in] flash - flash structure
4665 * @param[in] type - flash partition type
4666 * @param[in] instance - flash partition instance
4667 * @param[in] buf - read data buffer
4668 * @param[in] len - data buffer length
4669 * @param[in] offset - offset relative to the partition starting address
4670 * @param[in] cbfn - callback function
4671 * @param[in] cbarg - callback argument
4676 bfa_flash_read_part(struct bfa_flash_s
*flash
, enum bfa_flash_part_type type
,
4677 u8 instance
, void *buf
, u32 len
, u32 offset
,
4678 bfa_cb_flash_t cbfn
, void *cbarg
)
4680 bfa_trc(flash
, BFI_FLASH_H2I_READ_REQ
);
4681 bfa_trc(flash
, type
);
4682 bfa_trc(flash
, instance
);
4683 bfa_trc(flash
, len
);
4684 bfa_trc(flash
, offset
);
4686 if (!bfa_ioc_is_operational(flash
->ioc
))
4687 return BFA_STATUS_IOC_NON_OP
;
4690 * 'len' must be in word (4-byte) boundary
4691 * 'offset' must be in sector (16kb) boundary
4693 if (!len
|| (len
& 0x03) || (offset
& 0x00003FFF))
4694 return BFA_STATUS_FLASH_BAD_LEN
;
4696 if (flash
->op_busy
) {
4697 bfa_trc(flash
, flash
->op_busy
);
4698 return BFA_STATUS_DEVBUSY
;
4703 flash
->cbarg
= cbarg
;
4705 flash
->instance
= instance
;
4706 flash
->residue
= len
;
4708 flash
->addr_off
= offset
;
4710 bfa_flash_read_send(flash
);
4712 return BFA_STATUS_OK
;
4716 * DIAG module specific
4719 #define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */
4720 #define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */
4722 /* IOC event handler */
4724 bfa_diag_notify(void *diag_arg
, enum bfa_ioc_event_e event
)
4726 struct bfa_diag_s
*diag
= diag_arg
;
4728 bfa_trc(diag
, event
);
4729 bfa_trc(diag
, diag
->block
);
4730 bfa_trc(diag
, diag
->fwping
.lock
);
4731 bfa_trc(diag
, diag
->tsensor
.lock
);
4734 case BFA_IOC_E_DISABLED
:
4735 case BFA_IOC_E_FAILED
:
4736 if (diag
->fwping
.lock
) {
4737 diag
->fwping
.status
= BFA_STATUS_IOC_FAILURE
;
4738 diag
->fwping
.cbfn(diag
->fwping
.cbarg
,
4739 diag
->fwping
.status
);
4740 diag
->fwping
.lock
= 0;
4743 if (diag
->tsensor
.lock
) {
4744 diag
->tsensor
.status
= BFA_STATUS_IOC_FAILURE
;
4745 diag
->tsensor
.cbfn(diag
->tsensor
.cbarg
,
4746 diag
->tsensor
.status
);
4747 diag
->tsensor
.lock
= 0;
4751 if (diag
->timer_active
) {
4752 bfa_timer_stop(&diag
->timer
);
4753 diag
->timer_active
= 0;
4756 diag
->status
= BFA_STATUS_IOC_FAILURE
;
4757 diag
->cbfn(diag
->cbarg
, diag
->status
);
4768 bfa_diag_memtest_done(void *cbarg
)
4770 struct bfa_diag_s
*diag
= cbarg
;
4771 struct bfa_ioc_s
*ioc
= diag
->ioc
;
4772 struct bfa_diag_memtest_result
*res
= diag
->result
;
4773 u32 loff
= BFI_BOOT_MEMTEST_RES_ADDR
;
4774 u32 pgnum
, pgoff
, i
;
4776 pgnum
= PSS_SMEM_PGNUM(ioc
->ioc_regs
.smem_pg0
, loff
);
4777 pgoff
= PSS_SMEM_PGOFF(loff
);
4779 writel(pgnum
, ioc
->ioc_regs
.host_page_num_fn
);
4781 for (i
= 0; i
< (sizeof(struct bfa_diag_memtest_result
) /
4782 sizeof(u32
)); i
++) {
4783 /* read test result from smem */
4784 *((u32
*) res
+ i
) =
4785 bfa_mem_read(ioc
->ioc_regs
.smem_page_start
, loff
);
4786 loff
+= sizeof(u32
);
4789 /* Reset IOC fwstates to BFI_IOC_UNINIT */
4790 bfa_ioc_reset_fwstate(ioc
);
4792 res
->status
= swab32(res
->status
);
4793 bfa_trc(diag
, res
->status
);
4795 if (res
->status
== BFI_BOOT_MEMTEST_RES_SIG
)
4796 diag
->status
= BFA_STATUS_OK
;
4798 diag
->status
= BFA_STATUS_MEMTEST_FAILED
;
4799 res
->addr
= swab32(res
->addr
);
4800 res
->exp
= swab32(res
->exp
);
4801 res
->act
= swab32(res
->act
);
4802 res
->err_status
= swab32(res
->err_status
);
4803 res
->err_status1
= swab32(res
->err_status1
);
4804 res
->err_addr
= swab32(res
->err_addr
);
4805 bfa_trc(diag
, res
->addr
);
4806 bfa_trc(diag
, res
->exp
);
4807 bfa_trc(diag
, res
->act
);
4808 bfa_trc(diag
, res
->err_status
);
4809 bfa_trc(diag
, res
->err_status1
);
4810 bfa_trc(diag
, res
->err_addr
);
4812 diag
->timer_active
= 0;
4813 diag
->cbfn(diag
->cbarg
, diag
->status
);
4822 * Perform DMA test directly
4825 diag_fwping_send(struct bfa_diag_s
*diag
)
4827 struct bfi_diag_fwping_req_s
*fwping_req
;
4830 bfa_trc(diag
, diag
->fwping
.dbuf_pa
);
4832 /* fill DMA area with pattern */
4833 for (i
= 0; i
< (BFI_DIAG_DMA_BUF_SZ
>> 2); i
++)
4834 *((u32
*)diag
->fwping
.dbuf_kva
+ i
) = diag
->fwping
.data
;
4837 fwping_req
= (struct bfi_diag_fwping_req_s
*)diag
->fwping
.mbcmd
.msg
;
4840 bfa_alen_set(&fwping_req
->alen
, BFI_DIAG_DMA_BUF_SZ
,
4841 diag
->fwping
.dbuf_pa
);
4842 /* Set up dma count */
4843 fwping_req
->count
= cpu_to_be32(diag
->fwping
.count
);
4844 /* Set up data pattern */
4845 fwping_req
->data
= diag
->fwping
.data
;
4847 /* build host command */
4848 bfi_h2i_set(fwping_req
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_FWPING
,
4849 bfa_ioc_portid(diag
->ioc
));
4852 bfa_ioc_mbox_queue(diag
->ioc
, &diag
->fwping
.mbcmd
);
4856 diag_fwping_comp(struct bfa_diag_s
*diag
,
4857 struct bfi_diag_fwping_rsp_s
*diag_rsp
)
4859 u32 rsp_data
= diag_rsp
->data
;
4860 u8 rsp_dma_status
= diag_rsp
->dma_status
;
4862 bfa_trc(diag
, rsp_data
);
4863 bfa_trc(diag
, rsp_dma_status
);
4865 if (rsp_dma_status
== BFA_STATUS_OK
) {
4867 pat
= (diag
->fwping
.count
& 0x1) ? ~(diag
->fwping
.data
) :
4869 /* Check mbox data */
4870 if (diag
->fwping
.data
!= rsp_data
) {
4871 bfa_trc(diag
, rsp_data
);
4872 diag
->fwping
.result
->dmastatus
=
4873 BFA_STATUS_DATACORRUPTED
;
4874 diag
->fwping
.status
= BFA_STATUS_DATACORRUPTED
;
4875 diag
->fwping
.cbfn(diag
->fwping
.cbarg
,
4876 diag
->fwping
.status
);
4877 diag
->fwping
.lock
= 0;
4880 /* Check dma pattern */
4881 for (i
= 0; i
< (BFI_DIAG_DMA_BUF_SZ
>> 2); i
++) {
4882 if (*((u32
*)diag
->fwping
.dbuf_kva
+ i
) != pat
) {
4886 *((u32
*)diag
->fwping
.dbuf_kva
+ i
));
4887 diag
->fwping
.result
->dmastatus
=
4888 BFA_STATUS_DATACORRUPTED
;
4889 diag
->fwping
.status
= BFA_STATUS_DATACORRUPTED
;
4890 diag
->fwping
.cbfn(diag
->fwping
.cbarg
,
4891 diag
->fwping
.status
);
4892 diag
->fwping
.lock
= 0;
4896 diag
->fwping
.result
->dmastatus
= BFA_STATUS_OK
;
4897 diag
->fwping
.status
= BFA_STATUS_OK
;
4898 diag
->fwping
.cbfn(diag
->fwping
.cbarg
, diag
->fwping
.status
);
4899 diag
->fwping
.lock
= 0;
4901 diag
->fwping
.status
= BFA_STATUS_HDMA_FAILED
;
4902 diag
->fwping
.cbfn(diag
->fwping
.cbarg
, diag
->fwping
.status
);
4903 diag
->fwping
.lock
= 0;
4908 * Temperature Sensor
4912 diag_tempsensor_send(struct bfa_diag_s
*diag
)
4914 struct bfi_diag_ts_req_s
*msg
;
4916 msg
= (struct bfi_diag_ts_req_s
*)diag
->tsensor
.mbcmd
.msg
;
4917 bfa_trc(diag
, msg
->temp
);
4918 /* build host command */
4919 bfi_h2i_set(msg
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_TEMPSENSOR
,
4920 bfa_ioc_portid(diag
->ioc
));
4922 bfa_ioc_mbox_queue(diag
->ioc
, &diag
->tsensor
.mbcmd
);
4926 diag_tempsensor_comp(struct bfa_diag_s
*diag
, bfi_diag_ts_rsp_t
*rsp
)
4928 if (!diag
->tsensor
.lock
) {
4929 /* receiving response after ioc failure */
4930 bfa_trc(diag
, diag
->tsensor
.lock
);
4935 * ASIC junction tempsensor is a reg read operation
4936 * it will always return OK
4938 diag
->tsensor
.temp
->temp
= be16_to_cpu(rsp
->temp
);
4939 diag
->tsensor
.temp
->ts_junc
= rsp
->ts_junc
;
4940 diag
->tsensor
.temp
->ts_brd
= rsp
->ts_brd
;
4943 /* tsensor.temp->status is brd_temp status */
4944 diag
->tsensor
.temp
->status
= rsp
->status
;
4945 if (rsp
->status
== BFA_STATUS_OK
) {
4946 diag
->tsensor
.temp
->brd_temp
=
4947 be16_to_cpu(rsp
->brd_temp
);
4949 diag
->tsensor
.temp
->brd_temp
= 0;
4952 bfa_trc(diag
, rsp
->status
);
4953 bfa_trc(diag
, rsp
->ts_junc
);
4954 bfa_trc(diag
, rsp
->temp
);
4955 bfa_trc(diag
, rsp
->ts_brd
);
4956 bfa_trc(diag
, rsp
->brd_temp
);
4958 /* tsensor status is always good bcos we always have junction temp */
4959 diag
->tsensor
.status
= BFA_STATUS_OK
;
4960 diag
->tsensor
.cbfn(diag
->tsensor
.cbarg
, diag
->tsensor
.status
);
4961 diag
->tsensor
.lock
= 0;
4968 diag_ledtest_send(struct bfa_diag_s
*diag
, struct bfa_diag_ledtest_s
*ledtest
)
4970 struct bfi_diag_ledtest_req_s
*msg
;
4972 msg
= (struct bfi_diag_ledtest_req_s
*)diag
->ledtest
.mbcmd
.msg
;
4973 /* build host command */
4974 bfi_h2i_set(msg
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_LEDTEST
,
4975 bfa_ioc_portid(diag
->ioc
));
4978 * convert the freq from N blinks per 10 sec to
4979 * crossbow ontime value. We do it here because division is need
4982 ledtest
->freq
= 500 / ledtest
->freq
;
4984 if (ledtest
->freq
== 0)
4987 bfa_trc(diag
, ledtest
->freq
);
4988 /* mcpy(&ledtest_req->req, ledtest, sizeof(bfa_diag_ledtest_t)); */
4989 msg
->cmd
= (u8
) ledtest
->cmd
;
4990 msg
->color
= (u8
) ledtest
->color
;
4991 msg
->portid
= bfa_ioc_portid(diag
->ioc
);
4992 msg
->led
= ledtest
->led
;
4993 msg
->freq
= cpu_to_be16(ledtest
->freq
);
4996 bfa_ioc_mbox_queue(diag
->ioc
, &diag
->ledtest
.mbcmd
);
5000 diag_ledtest_comp(struct bfa_diag_s
*diag
, struct bfi_diag_ledtest_rsp_s
*msg
)
5002 bfa_trc(diag
, diag
->ledtest
.lock
);
5003 diag
->ledtest
.lock
= BFA_FALSE
;
5004 /* no bfa_cb_queue is needed because driver is not waiting */
5011 diag_portbeacon_send(struct bfa_diag_s
*diag
, bfa_boolean_t beacon
, u32 sec
)
5013 struct bfi_diag_portbeacon_req_s
*msg
;
5015 msg
= (struct bfi_diag_portbeacon_req_s
*)diag
->beacon
.mbcmd
.msg
;
5016 /* build host command */
5017 bfi_h2i_set(msg
->mh
, BFI_MC_DIAG
, BFI_DIAG_H2I_PORTBEACON
,
5018 bfa_ioc_portid(diag
->ioc
));
5019 msg
->beacon
= beacon
;
5020 msg
->period
= cpu_to_be32(sec
);
5022 bfa_ioc_mbox_queue(diag
->ioc
, &diag
->beacon
.mbcmd
);
5026 diag_portbeacon_comp(struct bfa_diag_s
*diag
)
5028 bfa_trc(diag
, diag
->beacon
.state
);
5029 diag
->beacon
.state
= BFA_FALSE
;
5030 if (diag
->cbfn_beacon
)
5031 diag
->cbfn_beacon(diag
->dev
, BFA_FALSE
, diag
->beacon
.link_e2e
);
5035 * Diag hmbox handler
5038 bfa_diag_intr(void *diagarg
, struct bfi_mbmsg_s
*msg
)
5040 struct bfa_diag_s
*diag
= diagarg
;
5042 switch (msg
->mh
.msg_id
) {
5043 case BFI_DIAG_I2H_PORTBEACON
:
5044 diag_portbeacon_comp(diag
);
5046 case BFI_DIAG_I2H_FWPING
:
5047 diag_fwping_comp(diag
, (struct bfi_diag_fwping_rsp_s
*) msg
);
5049 case BFI_DIAG_I2H_TEMPSENSOR
:
5050 diag_tempsensor_comp(diag
, (bfi_diag_ts_rsp_t
*) msg
);
5052 case BFI_DIAG_I2H_LEDTEST
:
5053 diag_ledtest_comp(diag
, (struct bfi_diag_ledtest_rsp_s
*) msg
);
5056 bfa_trc(diag
, msg
->mh
.msg_id
);
5064 * @param[in] *diag - diag data struct
5065 * @param[in] *memtest - mem test params input from upper layer,
5066 * @param[in] pattern - mem test pattern
5067 * @param[in] *result - mem test result
5068 * @param[in] cbfn - mem test callback functioin
5069 * @param[in] cbarg - callback functioin arg
5074 bfa_diag_memtest(struct bfa_diag_s
*diag
, struct bfa_diag_memtest_s
*memtest
,
5075 u32 pattern
, struct bfa_diag_memtest_result
*result
,
5076 bfa_cb_diag_t cbfn
, void *cbarg
)
5080 bfa_trc(diag
, pattern
);
5082 if (!bfa_ioc_adapter_is_disabled(diag
->ioc
))
5083 return BFA_STATUS_ADAPTER_ENABLED
;
5085 /* check to see if there is another destructive diag cmd running */
5087 bfa_trc(diag
, diag
->block
);
5088 return BFA_STATUS_DEVBUSY
;
5092 diag
->result
= result
;
5094 diag
->cbarg
= cbarg
;
5096 /* download memtest code and take LPU0 out of reset */
5097 bfa_ioc_boot(diag
->ioc
, BFI_FWBOOT_TYPE_MEMTEST
, BFI_FWBOOT_ENV_OS
);
5099 memtest_tov
= (bfa_ioc_asic_gen(diag
->ioc
) == BFI_ASIC_GEN_CT2
) ?
5100 CT2_BFA_DIAG_MEMTEST_TOV
: BFA_DIAG_MEMTEST_TOV
;
5101 bfa_timer_begin(diag
->ioc
->timer_mod
, &diag
->timer
,
5102 bfa_diag_memtest_done
, diag
, memtest_tov
);
5103 diag
->timer_active
= 1;
5104 return BFA_STATUS_OK
;
5108 * DIAG firmware ping command
5110 * @param[in] *diag - diag data struct
5111 * @param[in] cnt - dma loop count for testing PCIE
5112 * @param[in] data - data pattern to pass in fw
5113 * @param[in] *result - pt to bfa_diag_fwping_result_t data struct
5114 * @param[in] cbfn - callback function
5115 * @param[in] *cbarg - callback functioin arg
5120 bfa_diag_fwping(struct bfa_diag_s
*diag
, u32 cnt
, u32 data
,
5121 struct bfa_diag_results_fwping
*result
, bfa_cb_diag_t cbfn
,
5125 bfa_trc(diag
, data
);
5127 if (!bfa_ioc_is_operational(diag
->ioc
))
5128 return BFA_STATUS_IOC_NON_OP
;
5130 if (bfa_asic_id_ct2(bfa_ioc_devid((diag
->ioc
))) &&
5131 ((diag
->ioc
)->clscode
== BFI_PCIFN_CLASS_ETH
))
5132 return BFA_STATUS_CMD_NOTSUPP
;
5134 /* check to see if there is another destructive diag cmd running */
5135 if (diag
->block
|| diag
->fwping
.lock
) {
5136 bfa_trc(diag
, diag
->block
);
5137 bfa_trc(diag
, diag
->fwping
.lock
);
5138 return BFA_STATUS_DEVBUSY
;
5141 /* Initialization */
5142 diag
->fwping
.lock
= 1;
5143 diag
->fwping
.cbfn
= cbfn
;
5144 diag
->fwping
.cbarg
= cbarg
;
5145 diag
->fwping
.result
= result
;
5146 diag
->fwping
.data
= data
;
5147 diag
->fwping
.count
= cnt
;
5149 /* Init test results */
5150 diag
->fwping
.result
->data
= 0;
5151 diag
->fwping
.result
->status
= BFA_STATUS_OK
;
5153 /* kick off the first ping */
5154 diag_fwping_send(diag
);
5155 return BFA_STATUS_OK
;
5159 * Read Temperature Sensor
5161 * @param[in] *diag - diag data struct
5162 * @param[in] *result - pt to bfa_diag_temp_t data struct
5163 * @param[in] cbfn - callback function
5164 * @param[in] *cbarg - callback functioin arg
5169 bfa_diag_tsensor_query(struct bfa_diag_s
*diag
,
5170 struct bfa_diag_results_tempsensor_s
*result
,
5171 bfa_cb_diag_t cbfn
, void *cbarg
)
5173 /* check to see if there is a destructive diag cmd running */
5174 if (diag
->block
|| diag
->tsensor
.lock
) {
5175 bfa_trc(diag
, diag
->block
);
5176 bfa_trc(diag
, diag
->tsensor
.lock
);
5177 return BFA_STATUS_DEVBUSY
;
5180 if (!bfa_ioc_is_operational(diag
->ioc
))
5181 return BFA_STATUS_IOC_NON_OP
;
5183 /* Init diag mod params */
5184 diag
->tsensor
.lock
= 1;
5185 diag
->tsensor
.temp
= result
;
5186 diag
->tsensor
.cbfn
= cbfn
;
5187 diag
->tsensor
.cbarg
= cbarg
;
5188 diag
->tsensor
.status
= BFA_STATUS_OK
;
5190 /* Send msg to fw */
5191 diag_tempsensor_send(diag
);
5193 return BFA_STATUS_OK
;
5199 * @param[in] *diag - diag data struct
5200 * @param[in] *ledtest - pt to ledtest data structure
5205 bfa_diag_ledtest(struct bfa_diag_s
*diag
, struct bfa_diag_ledtest_s
*ledtest
)
5207 bfa_trc(diag
, ledtest
->cmd
);
5209 if (!bfa_ioc_is_operational(diag
->ioc
))
5210 return BFA_STATUS_IOC_NON_OP
;
5212 if (diag
->beacon
.state
)
5213 return BFA_STATUS_BEACON_ON
;
5215 if (diag
->ledtest
.lock
)
5216 return BFA_STATUS_LEDTEST_OP
;
5218 /* Send msg to fw */
5219 diag
->ledtest
.lock
= BFA_TRUE
;
5220 diag_ledtest_send(diag
, ledtest
);
5222 return BFA_STATUS_OK
;
5226 * Port beaconing command
5228 * @param[in] *diag - diag data struct
5229 * @param[in] beacon - port beaconing 1:ON 0:OFF
5230 * @param[in] link_e2e_beacon - link beaconing 1:ON 0:OFF
5231 * @param[in] sec - beaconing duration in seconds
5236 bfa_diag_beacon_port(struct bfa_diag_s
*diag
, bfa_boolean_t beacon
,
5237 bfa_boolean_t link_e2e_beacon
, uint32_t sec
)
5239 bfa_trc(diag
, beacon
);
5240 bfa_trc(diag
, link_e2e_beacon
);
5243 if (!bfa_ioc_is_operational(diag
->ioc
))
5244 return BFA_STATUS_IOC_NON_OP
;
5246 if (diag
->ledtest
.lock
)
5247 return BFA_STATUS_LEDTEST_OP
;
5249 if (diag
->beacon
.state
&& beacon
) /* beacon alread on */
5250 return BFA_STATUS_BEACON_ON
;
5252 diag
->beacon
.state
= beacon
;
5253 diag
->beacon
.link_e2e
= link_e2e_beacon
;
5254 if (diag
->cbfn_beacon
)
5255 diag
->cbfn_beacon(diag
->dev
, beacon
, link_e2e_beacon
);
5257 /* Send msg to fw */
5258 diag_portbeacon_send(diag
, beacon
, sec
);
5260 return BFA_STATUS_OK
;
5264 * Return DMA memory needed by diag module.
5267 bfa_diag_meminfo(void)
5269 return BFA_ROUNDUP(BFI_DIAG_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
5273 * Attach virtual and physical memory for Diag.
5276 bfa_diag_attach(struct bfa_diag_s
*diag
, struct bfa_ioc_s
*ioc
, void *dev
,
5277 bfa_cb_diag_beacon_t cbfn_beacon
, struct bfa_trc_mod_s
*trcmod
)
5281 diag
->trcmod
= trcmod
;
5286 diag
->result
= NULL
;
5287 diag
->cbfn_beacon
= cbfn_beacon
;
5289 bfa_ioc_mbox_regisr(diag
->ioc
, BFI_MC_DIAG
, bfa_diag_intr
, diag
);
5290 bfa_q_qe_init(&diag
->ioc_notify
);
5291 bfa_ioc_notify_init(&diag
->ioc_notify
, bfa_diag_notify
, diag
);
5292 list_add_tail(&diag
->ioc_notify
.qe
, &diag
->ioc
->notify_q
);
5296 bfa_diag_memclaim(struct bfa_diag_s
*diag
, u8
*dm_kva
, u64 dm_pa
)
5298 diag
->fwping
.dbuf_kva
= dm_kva
;
5299 diag
->fwping
.dbuf_pa
= dm_pa
;
5300 memset(diag
->fwping
.dbuf_kva
, 0, BFI_DIAG_DMA_BUF_SZ
);
5304 * PHY module specific
5306 #define BFA_PHY_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
5307 #define BFA_PHY_LOCK_STATUS 0x018878 /* phy semaphore status reg */
5310 bfa_phy_ntoh32(u32
*obuf
, u32
*ibuf
, int sz
)
5314 for (i
= 0; i
< m
; i
++)
5315 obuf
[i
] = be32_to_cpu(ibuf
[i
]);
5318 static bfa_boolean_t
5319 bfa_phy_present(struct bfa_phy_s
*phy
)
5321 return (phy
->ioc
->attr
->card_type
== BFA_MFG_TYPE_LIGHTNING
);
5325 bfa_phy_notify(void *cbarg
, enum bfa_ioc_event_e event
)
5327 struct bfa_phy_s
*phy
= cbarg
;
5329 bfa_trc(phy
, event
);
5332 case BFA_IOC_E_DISABLED
:
5333 case BFA_IOC_E_FAILED
:
5335 phy
->status
= BFA_STATUS_IOC_FAILURE
;
5336 phy
->cbfn(phy
->cbarg
, phy
->status
);
5347 * Send phy attribute query request.
5349 * @param[in] cbarg - callback argument
5352 bfa_phy_query_send(void *cbarg
)
5354 struct bfa_phy_s
*phy
= cbarg
;
5355 struct bfi_phy_query_req_s
*msg
=
5356 (struct bfi_phy_query_req_s
*) phy
->mb
.msg
;
5358 msg
->instance
= phy
->instance
;
5359 bfi_h2i_set(msg
->mh
, BFI_MC_PHY
, BFI_PHY_H2I_QUERY_REQ
,
5360 bfa_ioc_portid(phy
->ioc
));
5361 bfa_alen_set(&msg
->alen
, sizeof(struct bfa_phy_attr_s
), phy
->dbuf_pa
);
5362 bfa_ioc_mbox_queue(phy
->ioc
, &phy
->mb
);
5366 * Send phy write request.
5368 * @param[in] cbarg - callback argument
5371 bfa_phy_write_send(void *cbarg
)
5373 struct bfa_phy_s
*phy
= cbarg
;
5374 struct bfi_phy_write_req_s
*msg
=
5375 (struct bfi_phy_write_req_s
*) phy
->mb
.msg
;
5380 msg
->instance
= phy
->instance
;
5381 msg
->offset
= cpu_to_be32(phy
->addr_off
+ phy
->offset
);
5382 len
= (phy
->residue
< BFA_PHY_DMA_BUF_SZ
) ?
5383 phy
->residue
: BFA_PHY_DMA_BUF_SZ
;
5384 msg
->length
= cpu_to_be32(len
);
5386 /* indicate if it's the last msg of the whole write operation */
5387 msg
->last
= (len
== phy
->residue
) ? 1 : 0;
5389 bfi_h2i_set(msg
->mh
, BFI_MC_PHY
, BFI_PHY_H2I_WRITE_REQ
,
5390 bfa_ioc_portid(phy
->ioc
));
5391 bfa_alen_set(&msg
->alen
, len
, phy
->dbuf_pa
);
5393 buf
= (u16
*) (phy
->ubuf
+ phy
->offset
);
5394 dbuf
= (u16
*)phy
->dbuf_kva
;
5396 for (i
= 0; i
< sz
; i
++)
5397 buf
[i
] = cpu_to_be16(dbuf
[i
]);
5399 bfa_ioc_mbox_queue(phy
->ioc
, &phy
->mb
);
5401 phy
->residue
-= len
;
5406 * Send phy read request.
5408 * @param[in] cbarg - callback argument
5411 bfa_phy_read_send(void *cbarg
)
5413 struct bfa_phy_s
*phy
= cbarg
;
5414 struct bfi_phy_read_req_s
*msg
=
5415 (struct bfi_phy_read_req_s
*) phy
->mb
.msg
;
5418 msg
->instance
= phy
->instance
;
5419 msg
->offset
= cpu_to_be32(phy
->addr_off
+ phy
->offset
);
5420 len
= (phy
->residue
< BFA_PHY_DMA_BUF_SZ
) ?
5421 phy
->residue
: BFA_PHY_DMA_BUF_SZ
;
5422 msg
->length
= cpu_to_be32(len
);
5423 bfi_h2i_set(msg
->mh
, BFI_MC_PHY
, BFI_PHY_H2I_READ_REQ
,
5424 bfa_ioc_portid(phy
->ioc
));
5425 bfa_alen_set(&msg
->alen
, len
, phy
->dbuf_pa
);
5426 bfa_ioc_mbox_queue(phy
->ioc
, &phy
->mb
);
5430 * Send phy stats request.
5432 * @param[in] cbarg - callback argument
5435 bfa_phy_stats_send(void *cbarg
)
5437 struct bfa_phy_s
*phy
= cbarg
;
5438 struct bfi_phy_stats_req_s
*msg
=
5439 (struct bfi_phy_stats_req_s
*) phy
->mb
.msg
;
5441 msg
->instance
= phy
->instance
;
5442 bfi_h2i_set(msg
->mh
, BFI_MC_PHY
, BFI_PHY_H2I_STATS_REQ
,
5443 bfa_ioc_portid(phy
->ioc
));
5444 bfa_alen_set(&msg
->alen
, sizeof(struct bfa_phy_stats_s
), phy
->dbuf_pa
);
5445 bfa_ioc_mbox_queue(phy
->ioc
, &phy
->mb
);
5449 * Flash memory info API.
5451 * @param[in] mincfg - minimal cfg variable
5454 bfa_phy_meminfo(bfa_boolean_t mincfg
)
5456 /* min driver doesn't need phy */
5460 return BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
5466 * @param[in] phy - phy structure
5467 * @param[in] ioc - ioc structure
5468 * @param[in] dev - device structure
5469 * @param[in] trcmod - trace module
5470 * @param[in] logmod - log module
5473 bfa_phy_attach(struct bfa_phy_s
*phy
, struct bfa_ioc_s
*ioc
, void *dev
,
5474 struct bfa_trc_mod_s
*trcmod
, bfa_boolean_t mincfg
)
5477 phy
->trcmod
= trcmod
;
5482 bfa_ioc_mbox_regisr(phy
->ioc
, BFI_MC_PHY
, bfa_phy_intr
, phy
);
5483 bfa_q_qe_init(&phy
->ioc_notify
);
5484 bfa_ioc_notify_init(&phy
->ioc_notify
, bfa_phy_notify
, phy
);
5485 list_add_tail(&phy
->ioc_notify
.qe
, &phy
->ioc
->notify_q
);
5487 /* min driver doesn't need phy */
5489 phy
->dbuf_kva
= NULL
;
5495 * Claim memory for phy
5497 * @param[in] phy - phy structure
5498 * @param[in] dm_kva - pointer to virtual memory address
5499 * @param[in] dm_pa - physical memory address
5500 * @param[in] mincfg - minimal cfg variable
5503 bfa_phy_memclaim(struct bfa_phy_s
*phy
, u8
*dm_kva
, u64 dm_pa
,
5504 bfa_boolean_t mincfg
)
5509 phy
->dbuf_kva
= dm_kva
;
5510 phy
->dbuf_pa
= dm_pa
;
5511 memset(phy
->dbuf_kva
, 0, BFA_PHY_DMA_BUF_SZ
);
5512 dm_kva
+= BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
5513 dm_pa
+= BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
5517 bfa_phy_busy(struct bfa_ioc_s
*ioc
)
5521 rb
= bfa_ioc_bar0(ioc
);
5522 return readl(rb
+ BFA_PHY_LOCK_STATUS
);
5526 * Get phy attribute.
5528 * @param[in] phy - phy structure
5529 * @param[in] attr - phy attribute structure
5530 * @param[in] cbfn - callback function
5531 * @param[in] cbarg - callback argument
5536 bfa_phy_get_attr(struct bfa_phy_s
*phy
, u8 instance
,
5537 struct bfa_phy_attr_s
*attr
, bfa_cb_phy_t cbfn
, void *cbarg
)
5539 bfa_trc(phy
, BFI_PHY_H2I_QUERY_REQ
);
5540 bfa_trc(phy
, instance
);
5542 if (!bfa_phy_present(phy
))
5543 return BFA_STATUS_PHY_NOT_PRESENT
;
5545 if (!bfa_ioc_is_operational(phy
->ioc
))
5546 return BFA_STATUS_IOC_NON_OP
;
5548 if (phy
->op_busy
|| bfa_phy_busy(phy
->ioc
)) {
5549 bfa_trc(phy
, phy
->op_busy
);
5550 return BFA_STATUS_DEVBUSY
;
5556 phy
->instance
= instance
;
5557 phy
->ubuf
= (uint8_t *) attr
;
5558 bfa_phy_query_send(phy
);
5560 return BFA_STATUS_OK
;
5566 * @param[in] phy - phy structure
5567 * @param[in] instance - phy image instance
5568 * @param[in] stats - pointer to phy stats
5569 * @param[in] cbfn - callback function
5570 * @param[in] cbarg - callback argument
5575 bfa_phy_get_stats(struct bfa_phy_s
*phy
, u8 instance
,
5576 struct bfa_phy_stats_s
*stats
,
5577 bfa_cb_phy_t cbfn
, void *cbarg
)
5579 bfa_trc(phy
, BFI_PHY_H2I_STATS_REQ
);
5580 bfa_trc(phy
, instance
);
5582 if (!bfa_phy_present(phy
))
5583 return BFA_STATUS_PHY_NOT_PRESENT
;
5585 if (!bfa_ioc_is_operational(phy
->ioc
))
5586 return BFA_STATUS_IOC_NON_OP
;
5588 if (phy
->op_busy
|| bfa_phy_busy(phy
->ioc
)) {
5589 bfa_trc(phy
, phy
->op_busy
);
5590 return BFA_STATUS_DEVBUSY
;
5596 phy
->instance
= instance
;
5597 phy
->ubuf
= (u8
*) stats
;
5598 bfa_phy_stats_send(phy
);
5600 return BFA_STATUS_OK
;
5606 * @param[in] phy - phy structure
5607 * @param[in] instance - phy image instance
5608 * @param[in] buf - update data buffer
5609 * @param[in] len - data buffer length
5610 * @param[in] offset - offset relative to starting address
5611 * @param[in] cbfn - callback function
5612 * @param[in] cbarg - callback argument
5617 bfa_phy_update(struct bfa_phy_s
*phy
, u8 instance
,
5618 void *buf
, u32 len
, u32 offset
,
5619 bfa_cb_phy_t cbfn
, void *cbarg
)
5621 bfa_trc(phy
, BFI_PHY_H2I_WRITE_REQ
);
5622 bfa_trc(phy
, instance
);
5624 bfa_trc(phy
, offset
);
5626 if (!bfa_phy_present(phy
))
5627 return BFA_STATUS_PHY_NOT_PRESENT
;
5629 if (!bfa_ioc_is_operational(phy
->ioc
))
5630 return BFA_STATUS_IOC_NON_OP
;
5632 /* 'len' must be in word (4-byte) boundary */
5633 if (!len
|| (len
& 0x03))
5634 return BFA_STATUS_FAILED
;
5636 if (phy
->op_busy
|| bfa_phy_busy(phy
->ioc
)) {
5637 bfa_trc(phy
, phy
->op_busy
);
5638 return BFA_STATUS_DEVBUSY
;
5644 phy
->instance
= instance
;
5647 phy
->addr_off
= offset
;
5650 bfa_phy_write_send(phy
);
5651 return BFA_STATUS_OK
;
5657 * @param[in] phy - phy structure
5658 * @param[in] instance - phy image instance
5659 * @param[in] buf - read data buffer
5660 * @param[in] len - data buffer length
5661 * @param[in] offset - offset relative to starting address
5662 * @param[in] cbfn - callback function
5663 * @param[in] cbarg - callback argument
5668 bfa_phy_read(struct bfa_phy_s
*phy
, u8 instance
,
5669 void *buf
, u32 len
, u32 offset
,
5670 bfa_cb_phy_t cbfn
, void *cbarg
)
5672 bfa_trc(phy
, BFI_PHY_H2I_READ_REQ
);
5673 bfa_trc(phy
, instance
);
5675 bfa_trc(phy
, offset
);
5677 if (!bfa_phy_present(phy
))
5678 return BFA_STATUS_PHY_NOT_PRESENT
;
5680 if (!bfa_ioc_is_operational(phy
->ioc
))
5681 return BFA_STATUS_IOC_NON_OP
;
5683 /* 'len' must be in word (4-byte) boundary */
5684 if (!len
|| (len
& 0x03))
5685 return BFA_STATUS_FAILED
;
5687 if (phy
->op_busy
|| bfa_phy_busy(phy
->ioc
)) {
5688 bfa_trc(phy
, phy
->op_busy
);
5689 return BFA_STATUS_DEVBUSY
;
5695 phy
->instance
= instance
;
5698 phy
->addr_off
= offset
;
5700 bfa_phy_read_send(phy
);
5702 return BFA_STATUS_OK
;
5706 * Process phy response messages upon receiving interrupts.
5708 * @param[in] phyarg - phy structure
5709 * @param[in] msg - message structure
5712 bfa_phy_intr(void *phyarg
, struct bfi_mbmsg_s
*msg
)
5714 struct bfa_phy_s
*phy
= phyarg
;
5718 struct bfi_phy_query_rsp_s
*query
;
5719 struct bfi_phy_stats_rsp_s
*stats
;
5720 struct bfi_phy_write_rsp_s
*write
;
5721 struct bfi_phy_read_rsp_s
*read
;
5722 struct bfi_mbmsg_s
*msg
;
5726 bfa_trc(phy
, msg
->mh
.msg_id
);
5728 if (!phy
->op_busy
) {
5729 /* receiving response after ioc failure */
5730 bfa_trc(phy
, 0x9999);
5734 switch (msg
->mh
.msg_id
) {
5735 case BFI_PHY_I2H_QUERY_RSP
:
5736 status
= be32_to_cpu(m
.query
->status
);
5737 bfa_trc(phy
, status
);
5739 if (status
== BFA_STATUS_OK
) {
5740 struct bfa_phy_attr_s
*attr
=
5741 (struct bfa_phy_attr_s
*) phy
->ubuf
;
5742 bfa_phy_ntoh32((u32
*)attr
, (u32
*)phy
->dbuf_kva
,
5743 sizeof(struct bfa_phy_attr_s
));
5744 bfa_trc(phy
, attr
->status
);
5745 bfa_trc(phy
, attr
->length
);
5748 phy
->status
= status
;
5751 phy
->cbfn(phy
->cbarg
, phy
->status
);
5753 case BFI_PHY_I2H_STATS_RSP
:
5754 status
= be32_to_cpu(m
.stats
->status
);
5755 bfa_trc(phy
, status
);
5757 if (status
== BFA_STATUS_OK
) {
5758 struct bfa_phy_stats_s
*stats
=
5759 (struct bfa_phy_stats_s
*) phy
->ubuf
;
5760 bfa_phy_ntoh32((u32
*)stats
, (u32
*)phy
->dbuf_kva
,
5761 sizeof(struct bfa_phy_stats_s
));
5762 bfa_trc(phy
, stats
->status
);
5765 phy
->status
= status
;
5768 phy
->cbfn(phy
->cbarg
, phy
->status
);
5770 case BFI_PHY_I2H_WRITE_RSP
:
5771 status
= be32_to_cpu(m
.write
->status
);
5772 bfa_trc(phy
, status
);
5774 if (status
!= BFA_STATUS_OK
|| phy
->residue
== 0) {
5775 phy
->status
= status
;
5778 phy
->cbfn(phy
->cbarg
, phy
->status
);
5780 bfa_trc(phy
, phy
->offset
);
5781 bfa_phy_write_send(phy
);
5784 case BFI_PHY_I2H_READ_RSP
:
5785 status
= be32_to_cpu(m
.read
->status
);
5786 bfa_trc(phy
, status
);
5788 if (status
!= BFA_STATUS_OK
) {
5789 phy
->status
= status
;
5792 phy
->cbfn(phy
->cbarg
, phy
->status
);
5794 u32 len
= be32_to_cpu(m
.read
->length
);
5795 u16
*buf
= (u16
*)(phy
->ubuf
+ phy
->offset
);
5796 u16
*dbuf
= (u16
*)phy
->dbuf_kva
;
5797 int i
, sz
= len
>> 1;
5799 bfa_trc(phy
, phy
->offset
);
5802 for (i
= 0; i
< sz
; i
++)
5803 buf
[i
] = be16_to_cpu(dbuf
[i
]);
5805 phy
->residue
-= len
;
5808 if (phy
->residue
== 0) {
5809 phy
->status
= status
;
5812 phy
->cbfn(phy
->cbarg
, phy
->status
);
5814 bfa_phy_read_send(phy
);
5823 * DCONF state machine events
5825 enum bfa_dconf_event
{
5826 BFA_DCONF_SM_INIT
= 1, /* dconf Init */
5827 BFA_DCONF_SM_FLASH_COMP
= 2, /* read/write to flash */
5828 BFA_DCONF_SM_WR
= 3, /* binding change, map */
5829 BFA_DCONF_SM_TIMEOUT
= 4, /* Start timer */
5830 BFA_DCONF_SM_EXIT
= 5, /* exit dconf module */
5831 BFA_DCONF_SM_IOCDISABLE
= 6, /* IOC disable event */
5834 /* forward declaration of DCONF state machine */
5835 static void bfa_dconf_sm_uninit(struct bfa_dconf_mod_s
*dconf
,
5836 enum bfa_dconf_event event
);
5837 static void bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s
*dconf
,
5838 enum bfa_dconf_event event
);
5839 static void bfa_dconf_sm_ready(struct bfa_dconf_mod_s
*dconf
,
5840 enum bfa_dconf_event event
);
5841 static void bfa_dconf_sm_dirty(struct bfa_dconf_mod_s
*dconf
,
5842 enum bfa_dconf_event event
);
5843 static void bfa_dconf_sm_sync(struct bfa_dconf_mod_s
*dconf
,
5844 enum bfa_dconf_event event
);
5845 static void bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s
*dconf
,
5846 enum bfa_dconf_event event
);
5847 static void bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s
*dconf
,
5848 enum bfa_dconf_event event
);
5850 static void bfa_dconf_cbfn(void *dconf
, bfa_status_t status
);
5851 static void bfa_dconf_timer(void *cbarg
);
5852 static bfa_status_t
bfa_dconf_flash_write(struct bfa_dconf_mod_s
*dconf
);
5853 static void bfa_dconf_init_cb(void *arg
, bfa_status_t status
);
5856 * Beginning state of dconf module. Waiting for an event to start.
5859 bfa_dconf_sm_uninit(struct bfa_dconf_mod_s
*dconf
, enum bfa_dconf_event event
)
5861 bfa_status_t bfa_status
;
5862 bfa_trc(dconf
->bfa
, event
);
5865 case BFA_DCONF_SM_INIT
:
5866 if (dconf
->min_cfg
) {
5867 bfa_trc(dconf
->bfa
, dconf
->min_cfg
);
5868 bfa_fsm_send_event(&dconf
->bfa
->iocfc
,
5869 IOCFC_E_DCONF_DONE
);
5872 bfa_sm_set_state(dconf
, bfa_dconf_sm_flash_read
);
5873 bfa_timer_start(dconf
->bfa
, &dconf
->timer
,
5874 bfa_dconf_timer
, dconf
, 2 * BFA_DCONF_UPDATE_TOV
);
5875 bfa_status
= bfa_flash_read_part(BFA_FLASH(dconf
->bfa
),
5876 BFA_FLASH_PART_DRV
, dconf
->instance
,
5878 sizeof(struct bfa_dconf_s
), 0,
5879 bfa_dconf_init_cb
, dconf
->bfa
);
5880 if (bfa_status
!= BFA_STATUS_OK
) {
5881 bfa_timer_stop(&dconf
->timer
);
5882 bfa_dconf_init_cb(dconf
->bfa
, BFA_STATUS_FAILED
);
5883 bfa_sm_set_state(dconf
, bfa_dconf_sm_uninit
);
5887 case BFA_DCONF_SM_EXIT
:
5888 bfa_fsm_send_event(&dconf
->bfa
->iocfc
, IOCFC_E_DCONF_DONE
);
5889 case BFA_DCONF_SM_IOCDISABLE
:
5890 case BFA_DCONF_SM_WR
:
5891 case BFA_DCONF_SM_FLASH_COMP
:
5894 bfa_sm_fault(dconf
->bfa
, event
);
5899 * Read flash for dconf entries and make a call back to the driver once done.
5902 bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s
*dconf
,
5903 enum bfa_dconf_event event
)
5905 bfa_trc(dconf
->bfa
, event
);
5908 case BFA_DCONF_SM_FLASH_COMP
:
5909 bfa_timer_stop(&dconf
->timer
);
5910 bfa_sm_set_state(dconf
, bfa_dconf_sm_ready
);
5912 case BFA_DCONF_SM_TIMEOUT
:
5913 bfa_sm_set_state(dconf
, bfa_dconf_sm_ready
);
5914 bfa_ioc_suspend(&dconf
->bfa
->ioc
);
5916 case BFA_DCONF_SM_EXIT
:
5917 bfa_timer_stop(&dconf
->timer
);
5918 bfa_sm_set_state(dconf
, bfa_dconf_sm_uninit
);
5919 bfa_fsm_send_event(&dconf
->bfa
->iocfc
, IOCFC_E_DCONF_DONE
);
5921 case BFA_DCONF_SM_IOCDISABLE
:
5922 bfa_timer_stop(&dconf
->timer
);
5923 bfa_sm_set_state(dconf
, bfa_dconf_sm_uninit
);
5926 bfa_sm_fault(dconf
->bfa
, event
);
5931 * DCONF Module is in ready state. Has completed the initialization.
5934 bfa_dconf_sm_ready(struct bfa_dconf_mod_s
*dconf
, enum bfa_dconf_event event
)
5936 bfa_trc(dconf
->bfa
, event
);
5939 case BFA_DCONF_SM_WR
:
5940 bfa_timer_start(dconf
->bfa
, &dconf
->timer
,
5941 bfa_dconf_timer
, dconf
, BFA_DCONF_UPDATE_TOV
);
5942 bfa_sm_set_state(dconf
, bfa_dconf_sm_dirty
);
5944 case BFA_DCONF_SM_EXIT
:
5945 bfa_sm_set_state(dconf
, bfa_dconf_sm_uninit
);
5946 bfa_fsm_send_event(&dconf
->bfa
->iocfc
, IOCFC_E_DCONF_DONE
);
5948 case BFA_DCONF_SM_INIT
:
5949 case BFA_DCONF_SM_IOCDISABLE
:
5952 bfa_sm_fault(dconf
->bfa
, event
);
5957 * entries are dirty, write back to the flash.
5961 bfa_dconf_sm_dirty(struct bfa_dconf_mod_s
*dconf
, enum bfa_dconf_event event
)
5963 bfa_trc(dconf
->bfa
, event
);
5966 case BFA_DCONF_SM_TIMEOUT
:
5967 bfa_sm_set_state(dconf
, bfa_dconf_sm_sync
);
5968 bfa_dconf_flash_write(dconf
);
5970 case BFA_DCONF_SM_WR
:
5971 bfa_timer_stop(&dconf
->timer
);
5972 bfa_timer_start(dconf
->bfa
, &dconf
->timer
,
5973 bfa_dconf_timer
, dconf
, BFA_DCONF_UPDATE_TOV
);
5975 case BFA_DCONF_SM_EXIT
:
5976 bfa_timer_stop(&dconf
->timer
);
5977 bfa_timer_start(dconf
->bfa
, &dconf
->timer
,
5978 bfa_dconf_timer
, dconf
, BFA_DCONF_UPDATE_TOV
);
5979 bfa_sm_set_state(dconf
, bfa_dconf_sm_final_sync
);
5980 bfa_dconf_flash_write(dconf
);
5982 case BFA_DCONF_SM_FLASH_COMP
:
5984 case BFA_DCONF_SM_IOCDISABLE
:
5985 bfa_timer_stop(&dconf
->timer
);
5986 bfa_sm_set_state(dconf
, bfa_dconf_sm_iocdown_dirty
);
5989 bfa_sm_fault(dconf
->bfa
, event
);
5994 * Sync the dconf entries to the flash.
5997 bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s
*dconf
,
5998 enum bfa_dconf_event event
)
6000 bfa_trc(dconf
->bfa
, event
);
6003 case BFA_DCONF_SM_IOCDISABLE
:
6004 case BFA_DCONF_SM_FLASH_COMP
:
6005 bfa_timer_stop(&dconf
->timer
);
6007 case BFA_DCONF_SM_TIMEOUT
:
6008 bfa_sm_set_state(dconf
, bfa_dconf_sm_uninit
);
6009 bfa_fsm_send_event(&dconf
->bfa
->iocfc
, IOCFC_E_DCONF_DONE
);
6012 bfa_sm_fault(dconf
->bfa
, event
);
6017 bfa_dconf_sm_sync(struct bfa_dconf_mod_s
*dconf
, enum bfa_dconf_event event
)
6019 bfa_trc(dconf
->bfa
, event
);
6022 case BFA_DCONF_SM_FLASH_COMP
:
6023 bfa_sm_set_state(dconf
, bfa_dconf_sm_ready
);
6025 case BFA_DCONF_SM_WR
:
6026 bfa_timer_start(dconf
->bfa
, &dconf
->timer
,
6027 bfa_dconf_timer
, dconf
, BFA_DCONF_UPDATE_TOV
);
6028 bfa_sm_set_state(dconf
, bfa_dconf_sm_dirty
);
6030 case BFA_DCONF_SM_EXIT
:
6031 bfa_timer_start(dconf
->bfa
, &dconf
->timer
,
6032 bfa_dconf_timer
, dconf
, BFA_DCONF_UPDATE_TOV
);
6033 bfa_sm_set_state(dconf
, bfa_dconf_sm_final_sync
);
6035 case BFA_DCONF_SM_IOCDISABLE
:
6036 bfa_sm_set_state(dconf
, bfa_dconf_sm_iocdown_dirty
);
6039 bfa_sm_fault(dconf
->bfa
, event
);
6044 bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s
*dconf
,
6045 enum bfa_dconf_event event
)
6047 bfa_trc(dconf
->bfa
, event
);
6050 case BFA_DCONF_SM_INIT
:
6051 bfa_timer_start(dconf
->bfa
, &dconf
->timer
,
6052 bfa_dconf_timer
, dconf
, BFA_DCONF_UPDATE_TOV
);
6053 bfa_sm_set_state(dconf
, bfa_dconf_sm_dirty
);
6055 case BFA_DCONF_SM_EXIT
:
6056 bfa_sm_set_state(dconf
, bfa_dconf_sm_uninit
);
6057 bfa_fsm_send_event(&dconf
->bfa
->iocfc
, IOCFC_E_DCONF_DONE
);
6059 case BFA_DCONF_SM_IOCDISABLE
:
6062 bfa_sm_fault(dconf
->bfa
, event
);
6067 * Compute and return memory needed by DRV_CFG module.
6070 bfa_dconf_meminfo(struct bfa_iocfc_cfg_s
*cfg
, struct bfa_meminfo_s
*meminfo
,
6073 struct bfa_mem_kva_s
*dconf_kva
= BFA_MEM_DCONF_KVA(bfa
);
6075 if (cfg
->drvcfg
.min_cfg
)
6076 bfa_mem_kva_setup(meminfo
, dconf_kva
,
6077 sizeof(struct bfa_dconf_hdr_s
));
6079 bfa_mem_kva_setup(meminfo
, dconf_kva
,
6080 sizeof(struct bfa_dconf_s
));
6084 bfa_dconf_attach(struct bfa_s
*bfa
, void *bfad
, struct bfa_iocfc_cfg_s
*cfg
)
6086 struct bfa_dconf_mod_s
*dconf
= BFA_DCONF_MOD(bfa
);
6090 dconf
->instance
= bfa
->ioc
.port_id
;
6091 bfa_trc(bfa
, dconf
->instance
);
6093 dconf
->dconf
= (struct bfa_dconf_s
*) bfa_mem_kva_curp(dconf
);
6094 if (cfg
->drvcfg
.min_cfg
) {
6095 bfa_mem_kva_curp(dconf
) += sizeof(struct bfa_dconf_hdr_s
);
6096 dconf
->min_cfg
= BFA_TRUE
;
6098 dconf
->min_cfg
= BFA_FALSE
;
6099 bfa_mem_kva_curp(dconf
) += sizeof(struct bfa_dconf_s
);
6102 bfa_dconf_read_data_valid(bfa
) = BFA_FALSE
;
6103 bfa_sm_set_state(dconf
, bfa_dconf_sm_uninit
);
6107 bfa_dconf_init_cb(void *arg
, bfa_status_t status
)
6109 struct bfa_s
*bfa
= arg
;
6110 struct bfa_dconf_mod_s
*dconf
= BFA_DCONF_MOD(bfa
);
6112 if (status
== BFA_STATUS_OK
) {
6113 bfa_dconf_read_data_valid(bfa
) = BFA_TRUE
;
6114 if (dconf
->dconf
->hdr
.signature
!= BFI_DCONF_SIGNATURE
)
6115 dconf
->dconf
->hdr
.signature
= BFI_DCONF_SIGNATURE
;
6116 if (dconf
->dconf
->hdr
.version
!= BFI_DCONF_VERSION
)
6117 dconf
->dconf
->hdr
.version
= BFI_DCONF_VERSION
;
6119 bfa_sm_send_event(dconf
, BFA_DCONF_SM_FLASH_COMP
);
6120 bfa_fsm_send_event(&bfa
->iocfc
, IOCFC_E_DCONF_DONE
);
6124 bfa_dconf_modinit(struct bfa_s
*bfa
)
6126 struct bfa_dconf_mod_s
*dconf
= BFA_DCONF_MOD(bfa
);
6127 bfa_sm_send_event(dconf
, BFA_DCONF_SM_INIT
);
6130 static void bfa_dconf_timer(void *cbarg
)
6132 struct bfa_dconf_mod_s
*dconf
= cbarg
;
6133 bfa_sm_send_event(dconf
, BFA_DCONF_SM_TIMEOUT
);
6137 bfa_dconf_iocdisable(struct bfa_s
*bfa
)
6139 struct bfa_dconf_mod_s
*dconf
= BFA_DCONF_MOD(bfa
);
6140 bfa_sm_send_event(dconf
, BFA_DCONF_SM_IOCDISABLE
);
6144 bfa_dconf_flash_write(struct bfa_dconf_mod_s
*dconf
)
6146 bfa_status_t bfa_status
;
6147 bfa_trc(dconf
->bfa
, 0);
6149 bfa_status
= bfa_flash_update_part(BFA_FLASH(dconf
->bfa
),
6150 BFA_FLASH_PART_DRV
, dconf
->instance
,
6151 dconf
->dconf
, sizeof(struct bfa_dconf_s
), 0,
6152 bfa_dconf_cbfn
, dconf
);
6153 if (bfa_status
!= BFA_STATUS_OK
)
6154 WARN_ON(bfa_status
);
6155 bfa_trc(dconf
->bfa
, bfa_status
);
6161 bfa_dconf_update(struct bfa_s
*bfa
)
6163 struct bfa_dconf_mod_s
*dconf
= BFA_DCONF_MOD(bfa
);
6164 bfa_trc(dconf
->bfa
, 0);
6165 if (bfa_sm_cmp_state(dconf
, bfa_dconf_sm_iocdown_dirty
))
6166 return BFA_STATUS_FAILED
;
6168 if (dconf
->min_cfg
) {
6169 bfa_trc(dconf
->bfa
, dconf
->min_cfg
);
6170 return BFA_STATUS_FAILED
;
6173 bfa_sm_send_event(dconf
, BFA_DCONF_SM_WR
);
6174 return BFA_STATUS_OK
;
6178 bfa_dconf_cbfn(void *arg
, bfa_status_t status
)
6180 struct bfa_dconf_mod_s
*dconf
= arg
;
6182 bfa_sm_send_event(dconf
, BFA_DCONF_SM_FLASH_COMP
);
6186 bfa_dconf_modexit(struct bfa_s
*bfa
)
6188 struct bfa_dconf_mod_s
*dconf
= BFA_DCONF_MOD(bfa
);
6189 bfa_sm_send_event(dconf
, BFA_DCONF_SM_EXIT
);
6193 * FRU specific functions
6196 #define BFA_FRU_DMA_BUF_SZ 0x02000 /* 8k dma buffer */
6197 #define BFA_FRU_CHINOOK_MAX_SIZE 0x10000
6198 #define BFA_FRU_LIGHTNING_MAX_SIZE 0x200
6201 bfa_fru_notify(void *cbarg
, enum bfa_ioc_event_e event
)
6203 struct bfa_fru_s
*fru
= cbarg
;
6205 bfa_trc(fru
, event
);
6208 case BFA_IOC_E_DISABLED
:
6209 case BFA_IOC_E_FAILED
:
6211 fru
->status
= BFA_STATUS_IOC_FAILURE
;
6212 fru
->cbfn(fru
->cbarg
, fru
->status
);
6223 * Send fru write request.
6225 * @param[in] cbarg - callback argument
6228 bfa_fru_write_send(void *cbarg
, enum bfi_fru_h2i_msgs msg_type
)
6230 struct bfa_fru_s
*fru
= cbarg
;
6231 struct bfi_fru_write_req_s
*msg
=
6232 (struct bfi_fru_write_req_s
*) fru
->mb
.msg
;
6235 msg
->offset
= cpu_to_be32(fru
->addr_off
+ fru
->offset
);
6236 len
= (fru
->residue
< BFA_FRU_DMA_BUF_SZ
) ?
6237 fru
->residue
: BFA_FRU_DMA_BUF_SZ
;
6238 msg
->length
= cpu_to_be32(len
);
6241 * indicate if it's the last msg of the whole write operation
6243 msg
->last
= (len
== fru
->residue
) ? 1 : 0;
6245 msg
->trfr_cmpl
= (len
== fru
->residue
) ? fru
->trfr_cmpl
: 0;
6246 bfi_h2i_set(msg
->mh
, BFI_MC_FRU
, msg_type
, bfa_ioc_portid(fru
->ioc
));
6247 bfa_alen_set(&msg
->alen
, len
, fru
->dbuf_pa
);
6249 memcpy(fru
->dbuf_kva
, fru
->ubuf
+ fru
->offset
, len
);
6250 bfa_ioc_mbox_queue(fru
->ioc
, &fru
->mb
);
6252 fru
->residue
-= len
;
6257 * Send fru read request.
6259 * @param[in] cbarg - callback argument
6262 bfa_fru_read_send(void *cbarg
, enum bfi_fru_h2i_msgs msg_type
)
6264 struct bfa_fru_s
*fru
= cbarg
;
6265 struct bfi_fru_read_req_s
*msg
=
6266 (struct bfi_fru_read_req_s
*) fru
->mb
.msg
;
6269 msg
->offset
= cpu_to_be32(fru
->addr_off
+ fru
->offset
);
6270 len
= (fru
->residue
< BFA_FRU_DMA_BUF_SZ
) ?
6271 fru
->residue
: BFA_FRU_DMA_BUF_SZ
;
6272 msg
->length
= cpu_to_be32(len
);
6273 bfi_h2i_set(msg
->mh
, BFI_MC_FRU
, msg_type
, bfa_ioc_portid(fru
->ioc
));
6274 bfa_alen_set(&msg
->alen
, len
, fru
->dbuf_pa
);
6275 bfa_ioc_mbox_queue(fru
->ioc
, &fru
->mb
);
6279 * Flash memory info API.
6281 * @param[in] mincfg - minimal cfg variable
6284 bfa_fru_meminfo(bfa_boolean_t mincfg
)
6286 /* min driver doesn't need fru */
6290 return BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
6296 * @param[in] fru - fru structure
6297 * @param[in] ioc - ioc structure
6298 * @param[in] dev - device structure
6299 * @param[in] trcmod - trace module
6300 * @param[in] logmod - log module
6303 bfa_fru_attach(struct bfa_fru_s
*fru
, struct bfa_ioc_s
*ioc
, void *dev
,
6304 struct bfa_trc_mod_s
*trcmod
, bfa_boolean_t mincfg
)
6307 fru
->trcmod
= trcmod
;
6312 bfa_ioc_mbox_regisr(fru
->ioc
, BFI_MC_FRU
, bfa_fru_intr
, fru
);
6313 bfa_q_qe_init(&fru
->ioc_notify
);
6314 bfa_ioc_notify_init(&fru
->ioc_notify
, bfa_fru_notify
, fru
);
6315 list_add_tail(&fru
->ioc_notify
.qe
, &fru
->ioc
->notify_q
);
6317 /* min driver doesn't need fru */
6319 fru
->dbuf_kva
= NULL
;
6325 * Claim memory for fru
6327 * @param[in] fru - fru structure
6328 * @param[in] dm_kva - pointer to virtual memory address
6329 * @param[in] dm_pa - frusical memory address
6330 * @param[in] mincfg - minimal cfg variable
6333 bfa_fru_memclaim(struct bfa_fru_s
*fru
, u8
*dm_kva
, u64 dm_pa
,
6334 bfa_boolean_t mincfg
)
6339 fru
->dbuf_kva
= dm_kva
;
6340 fru
->dbuf_pa
= dm_pa
;
6341 memset(fru
->dbuf_kva
, 0, BFA_FRU_DMA_BUF_SZ
);
6342 dm_kva
+= BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
6343 dm_pa
+= BFA_ROUNDUP(BFA_FRU_DMA_BUF_SZ
, BFA_DMA_ALIGN_SZ
);
6347 * Update fru vpd image.
6349 * @param[in] fru - fru structure
6350 * @param[in] buf - update data buffer
6351 * @param[in] len - data buffer length
6352 * @param[in] offset - offset relative to starting address
6353 * @param[in] cbfn - callback function
6354 * @param[in] cbarg - callback argument
6359 bfa_fruvpd_update(struct bfa_fru_s
*fru
, void *buf
, u32 len
, u32 offset
,
6360 bfa_cb_fru_t cbfn
, void *cbarg
, u8 trfr_cmpl
)
6362 bfa_trc(fru
, BFI_FRUVPD_H2I_WRITE_REQ
);
6364 bfa_trc(fru
, offset
);
6366 if (fru
->ioc
->asic_gen
!= BFI_ASIC_GEN_CT2
&&
6367 fru
->ioc
->attr
->card_type
!= BFA_MFG_TYPE_CHINOOK2
)
6368 return BFA_STATUS_FRU_NOT_PRESENT
;
6370 if (fru
->ioc
->attr
->card_type
!= BFA_MFG_TYPE_CHINOOK
)
6371 return BFA_STATUS_CMD_NOTSUPP
;
6373 if (!bfa_ioc_is_operational(fru
->ioc
))
6374 return BFA_STATUS_IOC_NON_OP
;
6377 bfa_trc(fru
, fru
->op_busy
);
6378 return BFA_STATUS_DEVBUSY
;
6387 fru
->addr_off
= offset
;
6389 fru
->trfr_cmpl
= trfr_cmpl
;
6391 bfa_fru_write_send(fru
, BFI_FRUVPD_H2I_WRITE_REQ
);
6393 return BFA_STATUS_OK
;
6397 * Read fru vpd image.
6399 * @param[in] fru - fru structure
6400 * @param[in] buf - read data buffer
6401 * @param[in] len - data buffer length
6402 * @param[in] offset - offset relative to starting address
6403 * @param[in] cbfn - callback function
6404 * @param[in] cbarg - callback argument
6409 bfa_fruvpd_read(struct bfa_fru_s
*fru
, void *buf
, u32 len
, u32 offset
,
6410 bfa_cb_fru_t cbfn
, void *cbarg
)
6412 bfa_trc(fru
, BFI_FRUVPD_H2I_READ_REQ
);
6414 bfa_trc(fru
, offset
);
6416 if (fru
->ioc
->asic_gen
!= BFI_ASIC_GEN_CT2
)
6417 return BFA_STATUS_FRU_NOT_PRESENT
;
6419 if (fru
->ioc
->attr
->card_type
!= BFA_MFG_TYPE_CHINOOK
&&
6420 fru
->ioc
->attr
->card_type
!= BFA_MFG_TYPE_CHINOOK2
)
6421 return BFA_STATUS_CMD_NOTSUPP
;
6423 if (!bfa_ioc_is_operational(fru
->ioc
))
6424 return BFA_STATUS_IOC_NON_OP
;
6427 bfa_trc(fru
, fru
->op_busy
);
6428 return BFA_STATUS_DEVBUSY
;
6437 fru
->addr_off
= offset
;
6439 bfa_fru_read_send(fru
, BFI_FRUVPD_H2I_READ_REQ
);
6441 return BFA_STATUS_OK
;
6445 * Get maximum size fru vpd image.
6447 * @param[in] fru - fru structure
6448 * @param[out] size - maximum size of fru vpd data
6453 bfa_fruvpd_get_max_size(struct bfa_fru_s
*fru
, u32
*max_size
)
6455 if (fru
->ioc
->asic_gen
!= BFI_ASIC_GEN_CT2
)
6456 return BFA_STATUS_FRU_NOT_PRESENT
;
6458 if (!bfa_ioc_is_operational(fru
->ioc
))
6459 return BFA_STATUS_IOC_NON_OP
;
6461 if (fru
->ioc
->attr
->card_type
== BFA_MFG_TYPE_CHINOOK
||
6462 fru
->ioc
->attr
->card_type
== BFA_MFG_TYPE_CHINOOK2
)
6463 *max_size
= BFA_FRU_CHINOOK_MAX_SIZE
;
6465 return BFA_STATUS_CMD_NOTSUPP
;
6466 return BFA_STATUS_OK
;
6471 * @param[in] fru - fru structure
6472 * @param[in] buf - update data buffer
6473 * @param[in] len - data buffer length
6474 * @param[in] offset - offset relative to starting address
6475 * @param[in] cbfn - callback function
6476 * @param[in] cbarg - callback argument
6481 bfa_tfru_write(struct bfa_fru_s
*fru
, void *buf
, u32 len
, u32 offset
,
6482 bfa_cb_fru_t cbfn
, void *cbarg
)
6484 bfa_trc(fru
, BFI_TFRU_H2I_WRITE_REQ
);
6486 bfa_trc(fru
, offset
);
6487 bfa_trc(fru
, *((u8
*) buf
));
6489 if (fru
->ioc
->asic_gen
!= BFI_ASIC_GEN_CT2
)
6490 return BFA_STATUS_FRU_NOT_PRESENT
;
6492 if (!bfa_ioc_is_operational(fru
->ioc
))
6493 return BFA_STATUS_IOC_NON_OP
;
6496 bfa_trc(fru
, fru
->op_busy
);
6497 return BFA_STATUS_DEVBUSY
;
6506 fru
->addr_off
= offset
;
6509 bfa_fru_write_send(fru
, BFI_TFRU_H2I_WRITE_REQ
);
6511 return BFA_STATUS_OK
;
6517 * @param[in] fru - fru structure
6518 * @param[in] buf - read data buffer
6519 * @param[in] len - data buffer length
6520 * @param[in] offset - offset relative to starting address
6521 * @param[in] cbfn - callback function
6522 * @param[in] cbarg - callback argument
6527 bfa_tfru_read(struct bfa_fru_s
*fru
, void *buf
, u32 len
, u32 offset
,
6528 bfa_cb_fru_t cbfn
, void *cbarg
)
6530 bfa_trc(fru
, BFI_TFRU_H2I_READ_REQ
);
6532 bfa_trc(fru
, offset
);
6534 if (fru
->ioc
->asic_gen
!= BFI_ASIC_GEN_CT2
)
6535 return BFA_STATUS_FRU_NOT_PRESENT
;
6537 if (!bfa_ioc_is_operational(fru
->ioc
))
6538 return BFA_STATUS_IOC_NON_OP
;
6541 bfa_trc(fru
, fru
->op_busy
);
6542 return BFA_STATUS_DEVBUSY
;
6551 fru
->addr_off
= offset
;
6553 bfa_fru_read_send(fru
, BFI_TFRU_H2I_READ_REQ
);
6555 return BFA_STATUS_OK
;
6559 * Process fru response messages upon receiving interrupts.
6561 * @param[in] fruarg - fru structure
6562 * @param[in] msg - message structure
6565 bfa_fru_intr(void *fruarg
, struct bfi_mbmsg_s
*msg
)
6567 struct bfa_fru_s
*fru
= fruarg
;
6568 struct bfi_fru_rsp_s
*rsp
= (struct bfi_fru_rsp_s
*)msg
;
6571 bfa_trc(fru
, msg
->mh
.msg_id
);
6573 if (!fru
->op_busy
) {
6575 * receiving response after ioc failure
6577 bfa_trc(fru
, 0x9999);
6581 switch (msg
->mh
.msg_id
) {
6582 case BFI_FRUVPD_I2H_WRITE_RSP
:
6583 case BFI_TFRU_I2H_WRITE_RSP
:
6584 status
= be32_to_cpu(rsp
->status
);
6585 bfa_trc(fru
, status
);
6587 if (status
!= BFA_STATUS_OK
|| fru
->residue
== 0) {
6588 fru
->status
= status
;
6591 fru
->cbfn(fru
->cbarg
, fru
->status
);
6593 bfa_trc(fru
, fru
->offset
);
6594 if (msg
->mh
.msg_id
== BFI_FRUVPD_I2H_WRITE_RSP
)
6595 bfa_fru_write_send(fru
,
6596 BFI_FRUVPD_H2I_WRITE_REQ
);
6598 bfa_fru_write_send(fru
,
6599 BFI_TFRU_H2I_WRITE_REQ
);
6602 case BFI_FRUVPD_I2H_READ_RSP
:
6603 case BFI_TFRU_I2H_READ_RSP
:
6604 status
= be32_to_cpu(rsp
->status
);
6605 bfa_trc(fru
, status
);
6607 if (status
!= BFA_STATUS_OK
) {
6608 fru
->status
= status
;
6611 fru
->cbfn(fru
->cbarg
, fru
->status
);
6613 u32 len
= be32_to_cpu(rsp
->length
);
6615 bfa_trc(fru
, fru
->offset
);
6618 memcpy(fru
->ubuf
+ fru
->offset
, fru
->dbuf_kva
, len
);
6619 fru
->residue
-= len
;
6622 if (fru
->residue
== 0) {
6623 fru
->status
= status
;
6626 fru
->cbfn(fru
->cbarg
, fru
->status
);
6628 if (msg
->mh
.msg_id
== BFI_FRUVPD_I2H_READ_RSP
)
6629 bfa_fru_read_send(fru
,
6630 BFI_FRUVPD_H2I_READ_REQ
);
6632 bfa_fru_read_send(fru
,
6633 BFI_TFRU_H2I_READ_REQ
);
6643 * register definitions
6645 #define FLI_CMD_REG 0x0001d000
6646 #define FLI_RDDATA_REG 0x0001d010
6647 #define FLI_ADDR_REG 0x0001d004
6648 #define FLI_DEV_STATUS_REG 0x0001d014
6650 #define BFA_FLASH_FIFO_SIZE 128 /* fifo size */
6651 #define BFA_FLASH_CHECK_MAX 10000 /* max # of status check */
6652 #define BFA_FLASH_BLOCKING_OP_MAX 1000000 /* max # of blocking op check */
6653 #define BFA_FLASH_WIP_MASK 0x01 /* write in progress bit mask */
6655 enum bfa_flash_cmd
{
6656 BFA_FLASH_FAST_READ
= 0x0b, /* fast read */
6657 BFA_FLASH_READ_STATUS
= 0x05, /* read status */
6661 * @brief hardware error definition
6663 enum bfa_flash_err
{
6664 BFA_FLASH_NOT_PRESENT
= -1, /*!< flash not present */
6665 BFA_FLASH_UNINIT
= -2, /*!< flash not initialized */
6666 BFA_FLASH_BAD
= -3, /*!< flash bad */
6667 BFA_FLASH_BUSY
= -4, /*!< flash busy */
6668 BFA_FLASH_ERR_CMD_ACT
= -5, /*!< command active never cleared */
6669 BFA_FLASH_ERR_FIFO_CNT
= -6, /*!< fifo count never cleared */
6670 BFA_FLASH_ERR_WIP
= -7, /*!< write-in-progress never cleared */
6671 BFA_FLASH_ERR_TIMEOUT
= -8, /*!< fli timeout */
6672 BFA_FLASH_ERR_LEN
= -9, /*!< invalid length */
6676 * @brief flash command register data structure
6678 union bfa_flash_cmd_reg_u
{
6700 * @brief flash device status register data structure
6702 union bfa_flash_dev_status_reg_u
{
6726 * @brief flash address register data structure
6728 union bfa_flash_addr_reg_u
{
6742 * dg flash_raw_private Flash raw private functions
6745 bfa_flash_set_cmd(void __iomem
*pci_bar
, u8 wr_cnt
,
6746 u8 rd_cnt
, u8 ad_cnt
, u8 op
)
6748 union bfa_flash_cmd_reg_u cmd
;
6752 cmd
.r
.write_cnt
= wr_cnt
;
6753 cmd
.r
.read_cnt
= rd_cnt
;
6754 cmd
.r
.addr_cnt
= ad_cnt
;
6756 writel(cmd
.i
, (pci_bar
+ FLI_CMD_REG
));
6760 bfa_flash_set_addr(void __iomem
*pci_bar
, u32 address
)
6762 union bfa_flash_addr_reg_u addr
;
6764 addr
.r
.addr
= address
& 0x00ffffff;
6766 writel(addr
.i
, (pci_bar
+ FLI_ADDR_REG
));
6770 bfa_flash_cmd_act_check(void __iomem
*pci_bar
)
6772 union bfa_flash_cmd_reg_u cmd
;
6774 cmd
.i
= readl(pci_bar
+ FLI_CMD_REG
);
6777 return BFA_FLASH_ERR_CMD_ACT
;
6784 * Flush FLI data fifo.
6786 * @param[in] pci_bar - pci bar address
6787 * @param[in] dev_status - device status
6789 * Return 0 on success, negative error number on error.
6792 bfa_flash_fifo_flush(void __iomem
*pci_bar
)
6796 union bfa_flash_dev_status_reg_u dev_status
;
6798 dev_status
.i
= readl(pci_bar
+ FLI_DEV_STATUS_REG
);
6800 if (!dev_status
.r
.fifo_cnt
)
6803 /* fifo counter in terms of words */
6804 for (i
= 0; i
< dev_status
.r
.fifo_cnt
; i
++)
6805 t
= readl(pci_bar
+ FLI_RDDATA_REG
);
6808 * Check the device status. It may take some time.
6810 for (i
= 0; i
< BFA_FLASH_CHECK_MAX
; i
++) {
6811 dev_status
.i
= readl(pci_bar
+ FLI_DEV_STATUS_REG
);
6812 if (!dev_status
.r
.fifo_cnt
)
6816 if (dev_status
.r
.fifo_cnt
)
6817 return BFA_FLASH_ERR_FIFO_CNT
;
6824 * Read flash status.
6826 * @param[in] pci_bar - pci bar address
6828 * Return 0 on success, negative error number on error.
6831 bfa_flash_status_read(void __iomem
*pci_bar
)
6833 union bfa_flash_dev_status_reg_u dev_status
;
6838 status
= bfa_flash_fifo_flush(pci_bar
);
6842 bfa_flash_set_cmd(pci_bar
, 0, 4, 0, BFA_FLASH_READ_STATUS
);
6844 for (i
= 0; i
< BFA_FLASH_CHECK_MAX
; i
++) {
6845 status
= bfa_flash_cmd_act_check(pci_bar
);
6853 dev_status
.i
= readl(pci_bar
+ FLI_DEV_STATUS_REG
);
6854 if (!dev_status
.r
.fifo_cnt
)
6855 return BFA_FLASH_BUSY
;
6857 ret_status
= readl(pci_bar
+ FLI_RDDATA_REG
);
6860 status
= bfa_flash_fifo_flush(pci_bar
);
6869 * Start flash read operation.
6871 * @param[in] pci_bar - pci bar address
6872 * @param[in] offset - flash address offset
6873 * @param[in] len - read data length
6874 * @param[in] buf - read data buffer
6876 * Return 0 on success, negative error number on error.
6879 bfa_flash_read_start(void __iomem
*pci_bar
, u32 offset
, u32 len
,
6885 * len must be mutiple of 4 and not exceeding fifo size
6887 if (len
== 0 || len
> BFA_FLASH_FIFO_SIZE
|| (len
& 0x03) != 0)
6888 return BFA_FLASH_ERR_LEN
;
6893 status
= bfa_flash_status_read(pci_bar
);
6894 if (status
== BFA_FLASH_BUSY
)
6895 status
= bfa_flash_status_read(pci_bar
);
6901 * check if write-in-progress bit is cleared
6903 if (status
& BFA_FLASH_WIP_MASK
)
6904 return BFA_FLASH_ERR_WIP
;
6906 bfa_flash_set_addr(pci_bar
, offset
);
6908 bfa_flash_set_cmd(pci_bar
, 0, (u8
)len
, 4, BFA_FLASH_FAST_READ
);
6915 * Check flash read operation.
6917 * @param[in] pci_bar - pci bar address
6919 * Return flash device status, 1 if busy, 0 if not.
6922 bfa_flash_read_check(void __iomem
*pci_bar
)
6924 if (bfa_flash_cmd_act_check(pci_bar
))
6931 * End flash read operation.
6933 * @param[in] pci_bar - pci bar address
6934 * @param[in] len - read data length
6935 * @param[in] buf - read data buffer
6939 bfa_flash_read_end(void __iomem
*pci_bar
, u32 len
, char *buf
)
6945 * read data fifo up to 32 words
6947 for (i
= 0; i
< len
; i
+= 4) {
6948 u32 w
= readl(pci_bar
+ FLI_RDDATA_REG
);
6949 *((u32
*) (buf
+ i
)) = swab32(w
);
6952 bfa_flash_fifo_flush(pci_bar
);
6957 * Perform flash raw read.
6959 * @param[in] pci_bar - pci bar address
6960 * @param[in] offset - flash partition address offset
6961 * @param[in] buf - read data buffer
6962 * @param[in] len - read data length
6968 #define FLASH_BLOCKING_OP_MAX 500
6969 #define FLASH_SEM_LOCK_REG 0x18820
6972 bfa_raw_sem_get(void __iomem
*bar
)
6976 locked
= readl((bar
+ FLASH_SEM_LOCK_REG
));
6982 bfa_flash_sem_get(void __iomem
*bar
)
6984 u32 n
= FLASH_BLOCKING_OP_MAX
;
6986 while (!bfa_raw_sem_get(bar
)) {
6988 return BFA_STATUS_BADFLASH
;
6991 return BFA_STATUS_OK
;
6995 bfa_flash_sem_put(void __iomem
*bar
)
6997 writel(0, (bar
+ FLASH_SEM_LOCK_REG
));
7001 bfa_flash_raw_read(void __iomem
*pci_bar
, u32 offset
, char *buf
,
7006 u32 off
, l
, s
, residue
, fifo_sz
;
7010 fifo_sz
= BFA_FLASH_FIFO_SIZE
;
7011 status
= bfa_flash_sem_get(pci_bar
);
7012 if (status
!= BFA_STATUS_OK
)
7018 l
= (n
+ 1) * fifo_sz
- s
;
7022 status
= bfa_flash_read_start(pci_bar
, offset
+ off
, l
,
7025 bfa_flash_sem_put(pci_bar
);
7026 return BFA_STATUS_FAILED
;
7029 n
= BFA_FLASH_BLOCKING_OP_MAX
;
7030 while (bfa_flash_read_check(pci_bar
)) {
7032 bfa_flash_sem_put(pci_bar
);
7033 return BFA_STATUS_FAILED
;
7037 bfa_flash_read_end(pci_bar
, l
, &buf
[off
]);
7042 bfa_flash_sem_put(pci_bar
);
7044 return BFA_STATUS_OK
;