Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2 | * Copyright (c) 2005-2010 Brocade Communications Systems, Inc. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 3 | * All rights reserved |
| 4 | * www.brocade.com |
| 5 | * |
| 6 | * Linux driver for Brocade Fibre Channel Host Bus Adapter. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License (GPL) Version 2 as |
| 10 | * published by the Free Software Foundation |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | */ |
| 17 | |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 18 | #include "bfad_drv.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 19 | #include "bfa_ioc.h" |
| 20 | #include "bfi_ctreg.h" |
| 21 | #include "bfa_defs.h" |
| 22 | #include "bfa_defs_svc.h" |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 23 | |
Krishna Gudipati | 7af074d | 2010-03-05 19:35:45 -0800 | [diff] [blame] | 24 | BFA_TRC_FILE(CNA, IOC); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 25 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 26 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 27 | * IOC local definitions |
| 28 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 29 | #define BFA_IOC_TOV 3000 /* msecs */ |
| 30 | #define BFA_IOC_HWSEM_TOV 500 /* msecs */ |
| 31 | #define BFA_IOC_HB_TOV 500 /* msecs */ |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 32 | #define BFA_IOC_HWINIT_MAX 5 |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 33 | #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 34 | |
| 35 | #define bfa_ioc_timer_start(__ioc) \ |
| 36 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \ |
| 37 | bfa_ioc_timeout, (__ioc), BFA_IOC_TOV) |
| 38 | #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer) |
| 39 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 40 | #define bfa_hb_timer_start(__ioc) \ |
| 41 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \ |
| 42 | bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV) |
| 43 | #define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer) |
| 44 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 45 | #define BFA_DBG_FWTRC_OFF(_fn) (BFI_IOC_TRC_OFF + BFA_DBG_FWTRC_LEN * (_fn)) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 46 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 47 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 48 | * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details. |
| 49 | */ |
| 50 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 51 | #define bfa_ioc_firmware_lock(__ioc) \ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 52 | ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 53 | #define bfa_ioc_firmware_unlock(__ioc) \ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 54 | ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc)) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 55 | #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc)) |
| 56 | #define bfa_ioc_map_port(__ioc) ((__ioc)->ioc_hwif->ioc_map_port(__ioc)) |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 57 | #define bfa_ioc_notify_fail(__ioc) \ |
| 58 | ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc)) |
| 59 | #define bfa_ioc_sync_join(__ioc) \ |
| 60 | ((__ioc)->ioc_hwif->ioc_sync_join(__ioc)) |
| 61 | #define bfa_ioc_sync_leave(__ioc) \ |
| 62 | ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc)) |
| 63 | #define bfa_ioc_sync_ack(__ioc) \ |
| 64 | ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc)) |
| 65 | #define bfa_ioc_sync_complete(__ioc) \ |
| 66 | ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 67 | |
| 68 | #define bfa_ioc_mbox_cmd_pending(__ioc) \ |
| 69 | (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 70 | readl((__ioc)->ioc_regs.hfn_mbox_cmd)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 71 | |
| 72 | bfa_boolean_t bfa_auto_recover = BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * forward declarations |
| 76 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 77 | static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 78 | static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force); |
| 79 | static void bfa_ioc_timeout(void *ioc); |
| 80 | static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc); |
| 81 | static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc); |
| 82 | static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc); |
| 83 | static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 84 | static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc); |
| 85 | static void bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc); |
| 86 | static void bfa_ioc_recover(struct bfa_ioc_s *ioc); |
| 87 | static void bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc); |
| 88 | static void bfa_ioc_disable_comp(struct bfa_ioc_s *ioc); |
| 89 | static void bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 90 | static void bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc); |
| 91 | static void bfa_ioc_fail_notify(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 92 | static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 93 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 94 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 95 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 96 | * IOC state machine definitions/declarations |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 97 | */ |
| 98 | enum ioc_event { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 99 | IOC_E_RESET = 1, /* IOC reset request */ |
| 100 | IOC_E_ENABLE = 2, /* IOC enable request */ |
| 101 | IOC_E_DISABLE = 3, /* IOC disable request */ |
| 102 | IOC_E_DETACH = 4, /* driver detach cleanup */ |
| 103 | IOC_E_ENABLED = 5, /* f/w enabled */ |
| 104 | IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */ |
| 105 | IOC_E_DISABLED = 7, /* f/w disabled */ |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 106 | IOC_E_INITFAILED = 8, /* failure notice by iocpf sm */ |
| 107 | IOC_E_PFFAILED = 9, /* failure notice by iocpf sm */ |
| 108 | IOC_E_HBFAIL = 10, /* heartbeat failure */ |
| 109 | IOC_E_HWERROR = 11, /* hardware error interrupt */ |
| 110 | IOC_E_TIMEOUT = 12, /* timeout */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 113 | bfa_fsm_state_decl(bfa_ioc, uninit, struct bfa_ioc_s, enum ioc_event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 114 | bfa_fsm_state_decl(bfa_ioc, reset, struct bfa_ioc_s, enum ioc_event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 115 | bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event); |
| 116 | bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event); |
| 117 | bfa_fsm_state_decl(bfa_ioc, op, struct bfa_ioc_s, enum ioc_event); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 118 | bfa_fsm_state_decl(bfa_ioc, fail_retry, struct bfa_ioc_s, enum ioc_event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 119 | bfa_fsm_state_decl(bfa_ioc, fail, struct bfa_ioc_s, enum ioc_event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 120 | bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event); |
| 121 | bfa_fsm_state_decl(bfa_ioc, disabled, struct bfa_ioc_s, enum ioc_event); |
| 122 | |
| 123 | static struct bfa_sm_table_s ioc_sm_table[] = { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 124 | {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT}, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 125 | {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 126 | {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING}, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 127 | {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR}, |
| 128 | {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL}, |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 129 | {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 130 | {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL}, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 131 | {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING}, |
| 132 | {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED}, |
| 133 | }; |
| 134 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 135 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 136 | * IOCPF state machine definitions/declarations |
| 137 | */ |
| 138 | |
| 139 | #define bfa_iocpf_timer_start(__ioc) \ |
| 140 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \ |
| 141 | bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV) |
| 142 | #define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer) |
| 143 | |
| 144 | #define bfa_iocpf_recovery_timer_start(__ioc) \ |
| 145 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \ |
| 146 | bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV_RECOVER) |
| 147 | |
| 148 | #define bfa_sem_timer_start(__ioc) \ |
| 149 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \ |
| 150 | bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV) |
| 151 | #define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer) |
| 152 | |
| 153 | /* |
| 154 | * Forward declareations for iocpf state machine |
| 155 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 156 | static void bfa_iocpf_timeout(void *ioc_arg); |
| 157 | static void bfa_iocpf_sem_timeout(void *ioc_arg); |
| 158 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 159 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 160 | * IOCPF state machine events |
| 161 | */ |
| 162 | enum iocpf_event { |
| 163 | IOCPF_E_ENABLE = 1, /* IOCPF enable request */ |
| 164 | IOCPF_E_DISABLE = 2, /* IOCPF disable request */ |
| 165 | IOCPF_E_STOP = 3, /* stop on driver detach */ |
| 166 | IOCPF_E_FWREADY = 4, /* f/w initialization done */ |
| 167 | IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */ |
| 168 | IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */ |
| 169 | IOCPF_E_FAIL = 7, /* failure notice by ioc sm */ |
| 170 | IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */ |
| 171 | IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */ |
| 172 | IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */ |
| 173 | IOCPF_E_TIMEOUT = 11, /* f/w response timeout */ |
| 174 | }; |
| 175 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 176 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 177 | * IOCPF states |
| 178 | */ |
| 179 | enum bfa_iocpf_state { |
| 180 | BFA_IOCPF_RESET = 1, /* IOC is in reset state */ |
| 181 | BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */ |
| 182 | BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */ |
| 183 | BFA_IOCPF_READY = 4, /* IOCPF is initialized */ |
| 184 | BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */ |
| 185 | BFA_IOCPF_FAIL = 6, /* IOCPF failed */ |
| 186 | BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */ |
| 187 | BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */ |
| 188 | BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */ |
| 189 | }; |
| 190 | |
| 191 | bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event); |
| 192 | bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event); |
| 193 | bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event); |
| 194 | bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event); |
| 195 | bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event); |
| 196 | bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event); |
| 197 | bfa_fsm_state_decl(bfa_iocpf, ready, struct bfa_iocpf_s, enum iocpf_event); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 198 | bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s, |
| 199 | enum iocpf_event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 200 | bfa_fsm_state_decl(bfa_iocpf, initfail, struct bfa_iocpf_s, enum iocpf_event); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 201 | bfa_fsm_state_decl(bfa_iocpf, fail_sync, struct bfa_iocpf_s, enum iocpf_event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 202 | bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event); |
| 203 | bfa_fsm_state_decl(bfa_iocpf, disabling, struct bfa_iocpf_s, enum iocpf_event); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 204 | bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s, |
| 205 | enum iocpf_event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 206 | bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event); |
| 207 | |
| 208 | static struct bfa_sm_table_s iocpf_sm_table[] = { |
| 209 | {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET}, |
| 210 | {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH}, |
| 211 | {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH}, |
| 212 | {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT}, |
| 213 | {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT}, |
| 214 | {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT}, |
| 215 | {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY}, |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 216 | {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 217 | {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL}, |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 218 | {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 219 | {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL}, |
| 220 | {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING}, |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 221 | {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 222 | {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED}, |
| 223 | }; |
| 224 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 225 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 226 | * IOC State Machine |
| 227 | */ |
| 228 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 229 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 230 | * Beginning state. IOC uninit state. |
| 231 | */ |
| 232 | |
| 233 | static void |
| 234 | bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc) |
| 235 | { |
| 236 | } |
| 237 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 238 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 239 | * IOC is in uninit state. |
| 240 | */ |
| 241 | static void |
| 242 | bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 243 | { |
| 244 | bfa_trc(ioc, event); |
| 245 | |
| 246 | switch (event) { |
| 247 | case IOC_E_RESET: |
| 248 | bfa_fsm_set_state(ioc, bfa_ioc_sm_reset); |
| 249 | break; |
| 250 | |
| 251 | default: |
| 252 | bfa_sm_fault(ioc, event); |
| 253 | } |
| 254 | } |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 255 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 256 | * Reset entry actions -- initialize state machine |
| 257 | */ |
| 258 | static void |
| 259 | bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc) |
| 260 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 261 | bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 264 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 265 | * IOC is in reset state. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 266 | */ |
| 267 | static void |
| 268 | bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 269 | { |
| 270 | bfa_trc(ioc, event); |
| 271 | |
| 272 | switch (event) { |
| 273 | case IOC_E_ENABLE: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 274 | bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling); |
| 275 | break; |
| 276 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 277 | case IOC_E_DISABLE: |
| 278 | bfa_ioc_disable_comp(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 279 | break; |
| 280 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 281 | case IOC_E_DETACH: |
| 282 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 283 | break; |
| 284 | |
| 285 | default: |
| 286 | bfa_sm_fault(ioc, event); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | |
| 291 | static void |
| 292 | bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc) |
| 293 | { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 294 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 297 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 298 | * Host IOC function is being enabled, awaiting response from firmware. |
| 299 | * Semaphore is acquired. |
| 300 | */ |
| 301 | static void |
| 302 | bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 303 | { |
| 304 | bfa_trc(ioc, event); |
| 305 | |
| 306 | switch (event) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 307 | case IOC_E_ENABLED: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 308 | bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr); |
| 309 | break; |
| 310 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 311 | case IOC_E_PFFAILED: |
| 312 | /* !!! fall through !!! */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 313 | case IOC_E_HWERROR: |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 314 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
| 315 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry); |
| 316 | if (event != IOC_E_PFFAILED) |
| 317 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 318 | break; |
| 319 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 320 | case IOC_E_DISABLE: |
| 321 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
| 322 | break; |
| 323 | |
| 324 | case IOC_E_DETACH: |
| 325 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 326 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 327 | break; |
| 328 | |
| 329 | case IOC_E_ENABLE: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 330 | break; |
| 331 | |
| 332 | default: |
| 333 | bfa_sm_fault(ioc, event); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | |
| 338 | static void |
| 339 | bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc) |
| 340 | { |
| 341 | bfa_ioc_timer_start(ioc); |
| 342 | bfa_ioc_send_getattr(ioc); |
| 343 | } |
| 344 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 345 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 346 | * IOC configuration in progress. Timer is active. |
| 347 | */ |
| 348 | static void |
| 349 | bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 350 | { |
| 351 | bfa_trc(ioc, event); |
| 352 | |
| 353 | switch (event) { |
| 354 | case IOC_E_FWRSP_GETATTR: |
| 355 | bfa_ioc_timer_stop(ioc); |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 356 | bfa_ioc_check_attr_wwns(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 357 | bfa_fsm_set_state(ioc, bfa_ioc_sm_op); |
| 358 | break; |
| 359 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 360 | break; |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 361 | case IOC_E_PFFAILED: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 362 | case IOC_E_HWERROR: |
| 363 | bfa_ioc_timer_stop(ioc); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 364 | /* !!! fall through !!! */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 365 | case IOC_E_TIMEOUT: |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 366 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
| 367 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry); |
| 368 | if (event != IOC_E_PFFAILED) |
| 369 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 370 | break; |
| 371 | |
| 372 | case IOC_E_DISABLE: |
| 373 | bfa_ioc_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 374 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
| 375 | break; |
| 376 | |
| 377 | case IOC_E_ENABLE: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 378 | break; |
| 379 | |
| 380 | default: |
| 381 | bfa_sm_fault(ioc, event); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | |
| 386 | static void |
| 387 | bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc) |
| 388 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 389 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
| 390 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 391 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK); |
| 392 | bfa_ioc_hb_monitor(ioc); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 393 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static void |
| 397 | bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 398 | { |
| 399 | bfa_trc(ioc, event); |
| 400 | |
| 401 | switch (event) { |
| 402 | case IOC_E_ENABLE: |
| 403 | break; |
| 404 | |
| 405 | case IOC_E_DISABLE: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 406 | bfa_hb_timer_stop(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 407 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
| 408 | break; |
| 409 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 410 | case IOC_E_PFFAILED: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 411 | case IOC_E_HWERROR: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 412 | bfa_hb_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 413 | /* !!! fall through !!! */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 414 | case IOC_E_HBFAIL: |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 415 | bfa_ioc_fail_notify(ioc); |
| 416 | |
| 417 | if (ioc->iocpf.auto_recover) |
| 418 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry); |
| 419 | else |
| 420 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail); |
| 421 | |
| 422 | if (event != IOC_E_PFFAILED) |
| 423 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 424 | break; |
| 425 | |
| 426 | default: |
| 427 | bfa_sm_fault(ioc, event); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | |
| 432 | static void |
| 433 | bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc) |
| 434 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 435 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 436 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 437 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 440 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 441 | * IOC is being disabled |
| 442 | */ |
| 443 | static void |
| 444 | bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 445 | { |
| 446 | bfa_trc(ioc, event); |
| 447 | |
| 448 | switch (event) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 449 | case IOC_E_DISABLED: |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 450 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled); |
| 451 | break; |
| 452 | |
| 453 | case IOC_E_HWERROR: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 454 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 455 | * No state change. Will move to disabled state |
| 456 | * after iocpf sm completes failure processing and |
| 457 | * moves to disabled state. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 458 | */ |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 459 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 460 | break; |
| 461 | |
| 462 | default: |
| 463 | bfa_sm_fault(ioc, event); |
| 464 | } |
| 465 | } |
| 466 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 467 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 468 | * IOC disable completion entry. |
| 469 | */ |
| 470 | static void |
| 471 | bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc) |
| 472 | { |
| 473 | bfa_ioc_disable_comp(ioc); |
| 474 | } |
| 475 | |
| 476 | static void |
| 477 | bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 478 | { |
| 479 | bfa_trc(ioc, event); |
| 480 | |
| 481 | switch (event) { |
| 482 | case IOC_E_ENABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 483 | bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 484 | break; |
| 485 | |
| 486 | case IOC_E_DISABLE: |
| 487 | ioc->cbfn->disable_cbfn(ioc->bfa); |
| 488 | break; |
| 489 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 490 | case IOC_E_DETACH: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 491 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 492 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 493 | break; |
| 494 | |
| 495 | default: |
| 496 | bfa_sm_fault(ioc, event); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | |
| 501 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 502 | bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 503 | { |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 504 | bfa_trc(ioc, 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 507 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 508 | * Hardware initialization retry. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 509 | */ |
| 510 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 511 | bfa_ioc_sm_fail_retry(struct bfa_ioc_s *ioc, enum ioc_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 512 | { |
| 513 | bfa_trc(ioc, event); |
| 514 | |
| 515 | switch (event) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 516 | case IOC_E_ENABLED: |
| 517 | bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr); |
| 518 | break; |
| 519 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 520 | case IOC_E_PFFAILED: |
| 521 | case IOC_E_HWERROR: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 522 | /* |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 523 | * Initialization retry failed. |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 524 | */ |
| 525 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 526 | if (event != IOC_E_PFFAILED) |
| 527 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL); |
| 528 | break; |
| 529 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 530 | case IOC_E_INITFAILED: |
| 531 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail); |
| 532 | break; |
| 533 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 534 | case IOC_E_ENABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 535 | break; |
| 536 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 537 | case IOC_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 538 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 539 | break; |
| 540 | |
| 541 | case IOC_E_DETACH: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 542 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 543 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 544 | break; |
| 545 | |
| 546 | default: |
| 547 | bfa_sm_fault(ioc, event); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | |
| 552 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 553 | bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 554 | { |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 555 | bfa_trc(ioc, 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 558 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 559 | * IOC failure. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 560 | */ |
| 561 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 562 | bfa_ioc_sm_fail(struct bfa_ioc_s *ioc, enum ioc_event event) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 563 | { |
| 564 | bfa_trc(ioc, event); |
| 565 | |
| 566 | switch (event) { |
| 567 | |
| 568 | case IOC_E_ENABLE: |
| 569 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
| 570 | break; |
| 571 | |
| 572 | case IOC_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 573 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 574 | break; |
| 575 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 576 | case IOC_E_DETACH: |
| 577 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
| 578 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
| 579 | break; |
| 580 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 581 | case IOC_E_HWERROR: |
| 582 | /* |
| 583 | * HB failure notification, ignore. |
| 584 | */ |
| 585 | break; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 586 | default: |
| 587 | bfa_sm_fault(ioc, event); |
| 588 | } |
| 589 | } |
| 590 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 591 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 592 | * IOCPF State Machine |
| 593 | */ |
| 594 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 595 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 596 | * Reset entry actions -- initialize state machine |
| 597 | */ |
| 598 | static void |
| 599 | bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf) |
| 600 | { |
| 601 | iocpf->retry_count = 0; |
| 602 | iocpf->auto_recover = bfa_auto_recover; |
| 603 | } |
| 604 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 605 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 606 | * Beginning state. IOC is in reset state. |
| 607 | */ |
| 608 | static void |
| 609 | bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 610 | { |
| 611 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 612 | |
| 613 | bfa_trc(ioc, event); |
| 614 | |
| 615 | switch (event) { |
| 616 | case IOCPF_E_ENABLE: |
| 617 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck); |
| 618 | break; |
| 619 | |
| 620 | case IOCPF_E_STOP: |
| 621 | break; |
| 622 | |
| 623 | default: |
| 624 | bfa_sm_fault(ioc, event); |
| 625 | } |
| 626 | } |
| 627 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 628 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 629 | * Semaphore should be acquired for version check. |
| 630 | */ |
| 631 | static void |
| 632 | bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf) |
| 633 | { |
| 634 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 635 | } |
| 636 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 637 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 638 | * Awaiting h/w semaphore to continue with version check. |
| 639 | */ |
| 640 | static void |
| 641 | bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 642 | { |
| 643 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 644 | |
| 645 | bfa_trc(ioc, event); |
| 646 | |
| 647 | switch (event) { |
| 648 | case IOCPF_E_SEMLOCKED: |
| 649 | if (bfa_ioc_firmware_lock(ioc)) { |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 650 | if (bfa_ioc_sync_complete(ioc)) { |
| 651 | iocpf->retry_count = 0; |
| 652 | bfa_ioc_sync_join(ioc); |
| 653 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); |
| 654 | } else { |
| 655 | bfa_ioc_firmware_unlock(ioc); |
| 656 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 657 | bfa_sem_timer_start(ioc); |
| 658 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 659 | } else { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 660 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 661 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch); |
| 662 | } |
| 663 | break; |
| 664 | |
| 665 | case IOCPF_E_DISABLE: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 666 | bfa_sem_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 667 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 668 | bfa_fsm_send_event(ioc, IOC_E_DISABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
| 671 | case IOCPF_E_STOP: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 672 | bfa_sem_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 673 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 674 | break; |
| 675 | |
| 676 | default: |
| 677 | bfa_sm_fault(ioc, event); |
| 678 | } |
| 679 | } |
| 680 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 681 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 682 | * Notify enable completion callback. |
| 683 | */ |
| 684 | static void |
| 685 | bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf) |
| 686 | { |
| 687 | /* |
| 688 | * Call only the first time sm enters fwmismatch state. |
| 689 | */ |
| 690 | if (iocpf->retry_count == 0) |
| 691 | bfa_ioc_pf_fwmismatch(iocpf->ioc); |
| 692 | |
| 693 | iocpf->retry_count++; |
| 694 | bfa_iocpf_timer_start(iocpf->ioc); |
| 695 | } |
| 696 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 697 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 698 | * Awaiting firmware version match. |
| 699 | */ |
| 700 | static void |
| 701 | bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 702 | { |
| 703 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 704 | |
| 705 | bfa_trc(ioc, event); |
| 706 | |
| 707 | switch (event) { |
| 708 | case IOCPF_E_TIMEOUT: |
| 709 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck); |
| 710 | break; |
| 711 | |
| 712 | case IOCPF_E_DISABLE: |
| 713 | bfa_iocpf_timer_stop(ioc); |
| 714 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 715 | bfa_fsm_send_event(ioc, IOC_E_DISABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case IOCPF_E_STOP: |
| 719 | bfa_iocpf_timer_stop(ioc); |
| 720 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 721 | break; |
| 722 | |
| 723 | default: |
| 724 | bfa_sm_fault(ioc, event); |
| 725 | } |
| 726 | } |
| 727 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 728 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 729 | * Request for semaphore. |
| 730 | */ |
| 731 | static void |
| 732 | bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf) |
| 733 | { |
| 734 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 735 | } |
| 736 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 737 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 738 | * Awaiting semaphore for h/w initialzation. |
| 739 | */ |
| 740 | static void |
| 741 | bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 742 | { |
| 743 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 744 | |
| 745 | bfa_trc(ioc, event); |
| 746 | |
| 747 | switch (event) { |
| 748 | case IOCPF_E_SEMLOCKED: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 749 | if (bfa_ioc_sync_complete(ioc)) { |
| 750 | bfa_ioc_sync_join(ioc); |
| 751 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); |
| 752 | } else { |
| 753 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 754 | bfa_sem_timer_start(ioc); |
| 755 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 756 | break; |
| 757 | |
| 758 | case IOCPF_E_DISABLE: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 759 | bfa_sem_timer_stop(ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 760 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | default: |
| 764 | bfa_sm_fault(ioc, event); |
| 765 | } |
| 766 | } |
| 767 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 768 | static void |
| 769 | bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf) |
| 770 | { |
| 771 | bfa_iocpf_timer_start(iocpf->ioc); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 772 | bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 775 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 776 | * Hardware is being initialized. Interrupts are enabled. |
| 777 | * Holding hardware semaphore lock. |
| 778 | */ |
| 779 | static void |
| 780 | bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 781 | { |
| 782 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 783 | |
| 784 | bfa_trc(ioc, event); |
| 785 | |
| 786 | switch (event) { |
| 787 | case IOCPF_E_FWREADY: |
| 788 | bfa_iocpf_timer_stop(ioc); |
| 789 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling); |
| 790 | break; |
| 791 | |
| 792 | case IOCPF_E_INITFAIL: |
| 793 | bfa_iocpf_timer_stop(ioc); |
| 794 | /* |
| 795 | * !!! fall through !!! |
| 796 | */ |
| 797 | |
| 798 | case IOCPF_E_TIMEOUT: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 799 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 800 | if (event == IOCPF_E_TIMEOUT) |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 801 | bfa_fsm_send_event(ioc, IOC_E_PFFAILED); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 802 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | case IOCPF_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 806 | bfa_iocpf_timer_stop(ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 807 | bfa_ioc_sync_leave(ioc); |
| 808 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 809 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 810 | break; |
| 811 | |
| 812 | default: |
| 813 | bfa_sm_fault(ioc, event); |
| 814 | } |
| 815 | } |
| 816 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 817 | static void |
| 818 | bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf) |
| 819 | { |
| 820 | bfa_iocpf_timer_start(iocpf->ioc); |
| 821 | bfa_ioc_send_enable(iocpf->ioc); |
| 822 | } |
| 823 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 824 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 825 | * Host IOC function is being enabled, awaiting response from firmware. |
| 826 | * Semaphore is acquired. |
| 827 | */ |
| 828 | static void |
| 829 | bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 830 | { |
| 831 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 832 | |
| 833 | bfa_trc(ioc, event); |
| 834 | |
| 835 | switch (event) { |
| 836 | case IOCPF_E_FWRSP_ENABLE: |
| 837 | bfa_iocpf_timer_stop(ioc); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 838 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 839 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready); |
| 840 | break; |
| 841 | |
| 842 | case IOCPF_E_INITFAIL: |
| 843 | bfa_iocpf_timer_stop(ioc); |
| 844 | /* |
| 845 | * !!! fall through !!! |
| 846 | */ |
| 847 | |
| 848 | case IOCPF_E_TIMEOUT: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 849 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 850 | if (event == IOCPF_E_TIMEOUT) |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 851 | bfa_fsm_send_event(ioc, IOC_E_PFFAILED); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 852 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 853 | break; |
| 854 | |
| 855 | case IOCPF_E_DISABLE: |
| 856 | bfa_iocpf_timer_stop(ioc); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 857 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 858 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling); |
| 859 | break; |
| 860 | |
| 861 | case IOCPF_E_FWREADY: |
| 862 | bfa_ioc_send_enable(ioc); |
| 863 | break; |
| 864 | |
| 865 | default: |
| 866 | bfa_sm_fault(ioc, event); |
| 867 | } |
| 868 | } |
| 869 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 870 | static void |
| 871 | bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf) |
| 872 | { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 873 | bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | static void |
| 877 | bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 878 | { |
| 879 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 880 | |
| 881 | bfa_trc(ioc, event); |
| 882 | |
| 883 | switch (event) { |
| 884 | case IOCPF_E_DISABLE: |
| 885 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling); |
| 886 | break; |
| 887 | |
| 888 | case IOCPF_E_GETATTRFAIL: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 889 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 890 | break; |
| 891 | |
| 892 | case IOCPF_E_FAIL: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 893 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 894 | break; |
| 895 | |
| 896 | case IOCPF_E_FWREADY: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 897 | if (bfa_ioc_is_operational(ioc)) { |
| 898 | bfa_fsm_send_event(ioc, IOC_E_PFFAILED); |
| 899 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync); |
| 900 | } else { |
| 901 | bfa_fsm_send_event(ioc, IOC_E_PFFAILED); |
| 902 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync); |
| 903 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 904 | break; |
| 905 | |
| 906 | default: |
| 907 | bfa_sm_fault(ioc, event); |
| 908 | } |
| 909 | } |
| 910 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 911 | static void |
| 912 | bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf) |
| 913 | { |
| 914 | bfa_iocpf_timer_start(iocpf->ioc); |
| 915 | bfa_ioc_send_disable(iocpf->ioc); |
| 916 | } |
| 917 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 918 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 919 | * IOC is being disabled |
| 920 | */ |
| 921 | static void |
| 922 | bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 923 | { |
| 924 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 925 | |
| 926 | bfa_trc(ioc, event); |
| 927 | |
| 928 | switch (event) { |
| 929 | case IOCPF_E_FWRSP_DISABLE: |
| 930 | case IOCPF_E_FWREADY: |
| 931 | bfa_iocpf_timer_stop(ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 932 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 933 | break; |
| 934 | |
| 935 | case IOCPF_E_FAIL: |
| 936 | bfa_iocpf_timer_stop(ioc); |
| 937 | /* |
| 938 | * !!! fall through !!! |
| 939 | */ |
| 940 | |
| 941 | case IOCPF_E_TIMEOUT: |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 942 | writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 943 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 944 | break; |
| 945 | |
| 946 | case IOCPF_E_FWRSP_ENABLE: |
| 947 | break; |
| 948 | |
| 949 | default: |
| 950 | bfa_sm_fault(ioc, event); |
| 951 | } |
| 952 | } |
| 953 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 954 | static void |
| 955 | bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf) |
| 956 | { |
| 957 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * IOC hb ack request is being removed. |
| 962 | */ |
| 963 | static void |
| 964 | bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 965 | { |
| 966 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 967 | |
| 968 | bfa_trc(ioc, event); |
| 969 | |
| 970 | switch (event) { |
| 971 | case IOCPF_E_SEMLOCKED: |
| 972 | bfa_ioc_sync_leave(ioc); |
| 973 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 974 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 975 | break; |
| 976 | |
| 977 | case IOCPF_E_FAIL: |
| 978 | break; |
| 979 | |
| 980 | default: |
| 981 | bfa_sm_fault(ioc, event); |
| 982 | } |
| 983 | } |
| 984 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 985 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 986 | * IOC disable completion entry. |
| 987 | */ |
| 988 | static void |
| 989 | bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf) |
| 990 | { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 991 | bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | static void |
| 995 | bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 996 | { |
| 997 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 998 | |
| 999 | bfa_trc(ioc, event); |
| 1000 | |
| 1001 | switch (event) { |
| 1002 | case IOCPF_E_ENABLE: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1003 | iocpf->retry_count = 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1004 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait); |
| 1005 | break; |
| 1006 | |
| 1007 | case IOCPF_E_STOP: |
| 1008 | bfa_ioc_firmware_unlock(ioc); |
| 1009 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 1010 | break; |
| 1011 | |
| 1012 | default: |
| 1013 | bfa_sm_fault(ioc, event); |
| 1014 | } |
| 1015 | } |
| 1016 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1017 | static void |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1018 | bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf) |
| 1019 | { |
| 1020 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * @brief |
| 1025 | * Hardware initialization failed. |
| 1026 | */ |
| 1027 | static void |
| 1028 | bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1029 | { |
| 1030 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1031 | |
| 1032 | bfa_trc(ioc, event); |
| 1033 | |
| 1034 | switch (event) { |
| 1035 | case IOCPF_E_SEMLOCKED: |
| 1036 | bfa_ioc_notify_fail(ioc); |
| 1037 | bfa_ioc_sync_ack(ioc); |
| 1038 | iocpf->retry_count++; |
| 1039 | if (iocpf->retry_count >= BFA_IOC_HWINIT_MAX) { |
| 1040 | bfa_ioc_sync_leave(ioc); |
| 1041 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1042 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail); |
| 1043 | } else { |
| 1044 | if (bfa_ioc_sync_complete(ioc)) |
| 1045 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); |
| 1046 | else { |
| 1047 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1048 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait); |
| 1049 | } |
| 1050 | } |
| 1051 | break; |
| 1052 | |
| 1053 | case IOCPF_E_DISABLE: |
| 1054 | bfa_sem_timer_stop(ioc); |
| 1055 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
| 1056 | break; |
| 1057 | |
| 1058 | case IOCPF_E_STOP: |
| 1059 | bfa_sem_timer_stop(ioc); |
| 1060 | bfa_ioc_firmware_unlock(ioc); |
| 1061 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 1062 | break; |
| 1063 | |
| 1064 | case IOCPF_E_FAIL: |
| 1065 | break; |
| 1066 | |
| 1067 | default: |
| 1068 | bfa_sm_fault(ioc, event); |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1073 | bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf) |
| 1074 | { |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1075 | bfa_fsm_send_event(iocpf->ioc, IOC_E_INITFAILED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1076 | } |
| 1077 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1078 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1079 | * Hardware initialization failed. |
| 1080 | */ |
| 1081 | static void |
| 1082 | bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1083 | { |
| 1084 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1085 | |
| 1086 | bfa_trc(ioc, event); |
| 1087 | |
| 1088 | switch (event) { |
| 1089 | case IOCPF_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1090 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 1091 | break; |
| 1092 | |
| 1093 | case IOCPF_E_STOP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1094 | bfa_ioc_firmware_unlock(ioc); |
| 1095 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 1096 | break; |
| 1097 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1098 | default: |
| 1099 | bfa_sm_fault(ioc, event); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | static void |
| 1104 | bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf) |
| 1105 | { |
| 1106 | /** |
| 1107 | * Mark IOC as failed in hardware and stop firmware. |
| 1108 | */ |
| 1109 | bfa_ioc_lpu_stop(iocpf->ioc); |
| 1110 | |
| 1111 | /** |
| 1112 | * Flush any queued up mailbox requests. |
| 1113 | */ |
| 1114 | bfa_ioc_mbox_hbfail(iocpf->ioc); |
| 1115 | |
| 1116 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 1117 | } |
| 1118 | |
| 1119 | static void |
| 1120 | bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1121 | { |
| 1122 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1123 | |
| 1124 | bfa_trc(ioc, event); |
| 1125 | |
| 1126 | switch (event) { |
| 1127 | case IOCPF_E_SEMLOCKED: |
| 1128 | iocpf->retry_count = 0; |
| 1129 | bfa_ioc_sync_ack(ioc); |
| 1130 | bfa_ioc_notify_fail(ioc); |
| 1131 | if (!iocpf->auto_recover) { |
| 1132 | bfa_ioc_sync_leave(ioc); |
| 1133 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1134 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail); |
| 1135 | } else { |
| 1136 | if (bfa_ioc_sync_complete(ioc)) |
| 1137 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); |
| 1138 | else { |
| 1139 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1140 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait); |
| 1141 | } |
| 1142 | } |
| 1143 | break; |
| 1144 | |
| 1145 | case IOCPF_E_DISABLE: |
| 1146 | bfa_sem_timer_stop(ioc); |
| 1147 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
| 1148 | break; |
| 1149 | |
| 1150 | case IOCPF_E_FAIL: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1151 | break; |
| 1152 | |
| 1153 | default: |
| 1154 | bfa_sm_fault(ioc, event); |
| 1155 | } |
| 1156 | } |
| 1157 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1158 | static void |
| 1159 | bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf) |
| 1160 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1161 | } |
| 1162 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1163 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1164 | * IOC is in failed state. |
| 1165 | */ |
| 1166 | static void |
| 1167 | bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1168 | { |
| 1169 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1170 | |
| 1171 | bfa_trc(ioc, event); |
| 1172 | |
| 1173 | switch (event) { |
| 1174 | case IOCPF_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1175 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 1176 | break; |
| 1177 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1178 | default: |
| 1179 | bfa_sm_fault(ioc, event); |
| 1180 | } |
| 1181 | } |
| 1182 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1183 | /* |
Maggie Zhang | df0f193 | 2010-12-09 19:07:46 -0800 | [diff] [blame] | 1184 | * BFA IOC private functions |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1185 | */ |
| 1186 | |
| 1187 | static void |
| 1188 | bfa_ioc_disable_comp(struct bfa_ioc_s *ioc) |
| 1189 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1190 | struct list_head *qe; |
| 1191 | struct bfa_ioc_hbfail_notify_s *notify; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1192 | |
| 1193 | ioc->cbfn->disable_cbfn(ioc->bfa); |
| 1194 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1195 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1196 | * Notify common modules registered for notification. |
| 1197 | */ |
| 1198 | list_for_each(qe, &ioc->hb_notify_q) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1199 | notify = (struct bfa_ioc_hbfail_notify_s *) qe; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1200 | notify->cbfn(notify->cbarg); |
| 1201 | } |
| 1202 | } |
| 1203 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1204 | bfa_boolean_t |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1205 | bfa_ioc_sem_get(void __iomem *sem_reg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1206 | { |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1207 | u32 r32; |
| 1208 | int cnt = 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1209 | #define BFA_SEM_SPINCNT 3000 |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1210 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1211 | r32 = readl(sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1212 | |
| 1213 | while (r32 && (cnt < BFA_SEM_SPINCNT)) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1214 | cnt++; |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1215 | udelay(2); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1216 | r32 = readl(sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | if (r32 == 0) |
| 1220 | return BFA_TRUE; |
| 1221 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 1222 | WARN_ON(cnt >= BFA_SEM_SPINCNT); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1223 | return BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1224 | } |
| 1225 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1226 | static void |
| 1227 | bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc) |
| 1228 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1229 | u32 r32; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1230 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1231 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1232 | * First read to the semaphore register will return 0, subsequent reads |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1233 | * will return 1. Semaphore is released by writing 1 to the register |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1234 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1235 | r32 = readl(ioc->ioc_regs.ioc_sem_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1236 | if (r32 == 0) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1237 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1238 | return; |
| 1239 | } |
| 1240 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1241 | bfa_sem_timer_start(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1244 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1245 | * Initialize LPU local memory (aka secondary memory / SRAM) |
| 1246 | */ |
| 1247 | static void |
| 1248 | bfa_ioc_lmem_init(struct bfa_ioc_s *ioc) |
| 1249 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1250 | u32 pss_ctl; |
| 1251 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1252 | #define PSS_LMEM_INIT_TIME 10000 |
| 1253 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1254 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1255 | pss_ctl &= ~__PSS_LMEM_RESET; |
| 1256 | pss_ctl |= __PSS_LMEM_INIT_EN; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1257 | |
| 1258 | /* |
| 1259 | * i2c workaround 12.5khz clock |
| 1260 | */ |
| 1261 | pss_ctl |= __PSS_I2C_CLK_DIV(3UL); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1262 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1263 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1264 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1265 | * wait for memory initialization to be complete |
| 1266 | */ |
| 1267 | i = 0; |
| 1268 | do { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1269 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1270 | i++; |
| 1271 | } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME)); |
| 1272 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1273 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1274 | * If memory initialization is not successful, IOC timeout will catch |
| 1275 | * such failures. |
| 1276 | */ |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 1277 | WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1278 | bfa_trc(ioc, pss_ctl); |
| 1279 | |
| 1280 | pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1281 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | static void |
| 1285 | bfa_ioc_lpu_start(struct bfa_ioc_s *ioc) |
| 1286 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1287 | u32 pss_ctl; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1288 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1289 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1290 | * Take processor out of reset. |
| 1291 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1292 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1293 | pss_ctl &= ~__PSS_LPU0_RESET; |
| 1294 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1295 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | static void |
| 1299 | bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc) |
| 1300 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1301 | u32 pss_ctl; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1302 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1303 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1304 | * Put processors in reset. |
| 1305 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1306 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1307 | pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET); |
| 1308 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1309 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1312 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1313 | * Get driver and firmware versions. |
| 1314 | */ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1315 | void |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1316 | bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr) |
| 1317 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1318 | u32 pgnum, pgoff; |
| 1319 | u32 loff = 0; |
| 1320 | int i; |
| 1321 | u32 *fwsig = (u32 *) fwhdr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1322 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1323 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff); |
| 1324 | pgoff = PSS_SMEM_PGOFF(loff); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1325 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1326 | |
| 1327 | for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32)); |
| 1328 | i++) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1329 | fwsig[i] = |
| 1330 | bfa_mem_read(ioc->ioc_regs.smem_page_start, loff); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1331 | loff += sizeof(u32); |
| 1332 | } |
| 1333 | } |
| 1334 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1335 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1336 | * Returns TRUE if same. |
| 1337 | */ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1338 | bfa_boolean_t |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1339 | bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr) |
| 1340 | { |
| 1341 | struct bfi_ioc_image_hdr_s *drv_fwhdr; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1342 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1343 | |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 1344 | drv_fwhdr = (struct bfi_ioc_image_hdr_s *) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1345 | bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1346 | |
| 1347 | for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) { |
| 1348 | if (fwhdr->md5sum[i] != drv_fwhdr->md5sum[i]) { |
| 1349 | bfa_trc(ioc, i); |
| 1350 | bfa_trc(ioc, fwhdr->md5sum[i]); |
| 1351 | bfa_trc(ioc, drv_fwhdr->md5sum[i]); |
| 1352 | return BFA_FALSE; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | bfa_trc(ioc, fwhdr->md5sum[0]); |
| 1357 | return BFA_TRUE; |
| 1358 | } |
| 1359 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1360 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1361 | * Return true if current running version is valid. Firmware signature and |
| 1362 | * execution context (driver/bios) must match. |
| 1363 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1364 | static bfa_boolean_t |
| 1365 | bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1366 | { |
| 1367 | struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr; |
| 1368 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1369 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1370 | * If bios/efi boot (flash based) -- return true |
| 1371 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1372 | if (bfa_ioc_is_bios_optrom(ioc)) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1373 | return BFA_TRUE; |
| 1374 | |
| 1375 | bfa_ioc_fwver_get(ioc, &fwhdr); |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 1376 | drv_fwhdr = (struct bfi_ioc_image_hdr_s *) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1377 | bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1378 | |
| 1379 | if (fwhdr.signature != drv_fwhdr->signature) { |
| 1380 | bfa_trc(ioc, fwhdr.signature); |
| 1381 | bfa_trc(ioc, drv_fwhdr->signature); |
| 1382 | return BFA_FALSE; |
| 1383 | } |
| 1384 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1385 | if (swab32(fwhdr.param) != boot_env) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1386 | bfa_trc(ioc, fwhdr.param); |
| 1387 | bfa_trc(ioc, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1388 | return BFA_FALSE; |
| 1389 | } |
| 1390 | |
| 1391 | return bfa_ioc_fwver_cmp(ioc, &fwhdr); |
| 1392 | } |
| 1393 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1394 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1395 | * Conditionally flush any pending message from firmware at start. |
| 1396 | */ |
| 1397 | static void |
| 1398 | bfa_ioc_msgflush(struct bfa_ioc_s *ioc) |
| 1399 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1400 | u32 r32; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1401 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1402 | r32 = readl(ioc->ioc_regs.lpu_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1403 | if (r32) |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1404 | writel(1, ioc->ioc_regs.lpu_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1405 | } |
| 1406 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1407 | static void |
| 1408 | bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force) |
| 1409 | { |
| 1410 | enum bfi_ioc_state ioc_fwstate; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1411 | bfa_boolean_t fwvalid; |
| 1412 | u32 boot_type; |
| 1413 | u32 boot_env; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1414 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1415 | ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1416 | |
| 1417 | if (force) |
| 1418 | ioc_fwstate = BFI_IOC_UNINIT; |
| 1419 | |
| 1420 | bfa_trc(ioc, ioc_fwstate); |
| 1421 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1422 | boot_type = BFI_BOOT_TYPE_NORMAL; |
| 1423 | boot_env = BFI_BOOT_LOADER_OS; |
| 1424 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1425 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1426 | * Flash based firmware boot BIOS env. |
| 1427 | */ |
| 1428 | if (bfa_ioc_is_bios_optrom(ioc)) { |
| 1429 | boot_type = BFI_BOOT_TYPE_FLASH; |
| 1430 | boot_env = BFI_BOOT_LOADER_BIOS; |
| 1431 | } |
| 1432 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1433 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1434 | * Flash based firmware boot UEFI env. |
| 1435 | */ |
| 1436 | if (bfa_ioc_is_uefi(ioc)) { |
| 1437 | boot_type = BFI_BOOT_TYPE_FLASH; |
| 1438 | boot_env = BFI_BOOT_LOADER_UEFI; |
| 1439 | } |
| 1440 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1441 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1442 | * check if firmware is valid |
| 1443 | */ |
| 1444 | fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ? |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1445 | BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1446 | |
| 1447 | if (!fwvalid) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1448 | bfa_ioc_boot(ioc, boot_type, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1449 | return; |
| 1450 | } |
| 1451 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1452 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1453 | * If hardware initialization is in progress (initialized by other IOC), |
| 1454 | * just wait for an initialization completion interrupt. |
| 1455 | */ |
| 1456 | if (ioc_fwstate == BFI_IOC_INITING) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1457 | ioc->cbfn->reset_cbfn(ioc->bfa); |
| 1458 | return; |
| 1459 | } |
| 1460 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1461 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1462 | * If IOC function is disabled and firmware version is same, |
| 1463 | * just re-enable IOC. |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 1464 | * |
| 1465 | * If option rom, IOC must not be in operational state. With |
| 1466 | * convergence, IOC will be in operational state when 2nd driver |
| 1467 | * is loaded. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1468 | */ |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 1469 | if (ioc_fwstate == BFI_IOC_DISABLED || |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1470 | (!bfa_ioc_is_bios_optrom(ioc) && ioc_fwstate == BFI_IOC_OP)) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1471 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1472 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1473 | * When using MSI-X any pending firmware ready event should |
| 1474 | * be flushed. Otherwise MSI-X interrupts are not delivered. |
| 1475 | */ |
| 1476 | bfa_ioc_msgflush(ioc); |
| 1477 | ioc->cbfn->reset_cbfn(ioc->bfa); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1478 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1479 | return; |
| 1480 | } |
| 1481 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1482 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1483 | * Initialize the h/w for any other states. |
| 1484 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1485 | bfa_ioc_boot(ioc, boot_type, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1486 | } |
| 1487 | |
| 1488 | static void |
| 1489 | bfa_ioc_timeout(void *ioc_arg) |
| 1490 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1491 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1492 | |
| 1493 | bfa_trc(ioc, 0); |
| 1494 | bfa_fsm_send_event(ioc, IOC_E_TIMEOUT); |
| 1495 | } |
| 1496 | |
| 1497 | void |
| 1498 | bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len) |
| 1499 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1500 | u32 *msgp = (u32 *) ioc_msg; |
| 1501 | u32 i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1502 | |
| 1503 | bfa_trc(ioc, msgp[0]); |
| 1504 | bfa_trc(ioc, len); |
| 1505 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 1506 | WARN_ON(len > BFI_IOC_MSGLEN_MAX); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1507 | |
| 1508 | /* |
| 1509 | * first write msg to mailbox registers |
| 1510 | */ |
| 1511 | for (i = 0; i < len / sizeof(u32); i++) |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1512 | writel(cpu_to_le32(msgp[i]), |
| 1513 | ioc->ioc_regs.hfn_mbox + i * sizeof(u32)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1514 | |
| 1515 | for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++) |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1516 | writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1517 | |
| 1518 | /* |
| 1519 | * write 1 to mailbox CMD to trigger LPU event |
| 1520 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1521 | writel(1, ioc->ioc_regs.hfn_mbox_cmd); |
| 1522 | (void) readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | static void |
| 1526 | bfa_ioc_send_enable(struct bfa_ioc_s *ioc) |
| 1527 | { |
| 1528 | struct bfi_ioc_ctrl_req_s enable_req; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1529 | struct timeval tv; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1530 | |
| 1531 | bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ, |
| 1532 | bfa_ioc_portid(ioc)); |
| 1533 | enable_req.ioc_class = ioc->ioc_mc; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1534 | do_gettimeofday(&tv); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1535 | enable_req.tv_sec = be32_to_cpu(tv.tv_sec); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1536 | bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s)); |
| 1537 | } |
| 1538 | |
| 1539 | static void |
| 1540 | bfa_ioc_send_disable(struct bfa_ioc_s *ioc) |
| 1541 | { |
| 1542 | struct bfi_ioc_ctrl_req_s disable_req; |
| 1543 | |
| 1544 | bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ, |
| 1545 | bfa_ioc_portid(ioc)); |
| 1546 | bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s)); |
| 1547 | } |
| 1548 | |
| 1549 | static void |
| 1550 | bfa_ioc_send_getattr(struct bfa_ioc_s *ioc) |
| 1551 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1552 | struct bfi_ioc_getattr_req_s attr_req; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1553 | |
| 1554 | bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ, |
| 1555 | bfa_ioc_portid(ioc)); |
| 1556 | bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa); |
| 1557 | bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req)); |
| 1558 | } |
| 1559 | |
| 1560 | static void |
| 1561 | bfa_ioc_hb_check(void *cbarg) |
| 1562 | { |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1563 | struct bfa_ioc_s *ioc = cbarg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1564 | u32 hb_count; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1565 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1566 | hb_count = readl(ioc->ioc_regs.heartbeat); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1567 | if (ioc->hb_count == hb_count) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1568 | bfa_ioc_recover(ioc); |
| 1569 | return; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1570 | } else { |
| 1571 | ioc->hb_count = hb_count; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1572 | } |
| 1573 | |
| 1574 | bfa_ioc_mbox_poll(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1575 | bfa_hb_timer_start(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | static void |
| 1579 | bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc) |
| 1580 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1581 | ioc->hb_count = readl(ioc->ioc_regs.heartbeat); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1582 | bfa_hb_timer_start(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1585 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1586 | * Initiate a full firmware download. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1587 | */ |
| 1588 | static void |
| 1589 | bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1590 | u32 boot_env) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1591 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1592 | u32 *fwimg; |
| 1593 | u32 pgnum, pgoff; |
| 1594 | u32 loff = 0; |
| 1595 | u32 chunkno = 0; |
| 1596 | u32 i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1597 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1598 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1599 | * Initialize LMEM first before code download |
| 1600 | */ |
| 1601 | bfa_ioc_lmem_init(ioc); |
| 1602 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1603 | bfa_trc(ioc, bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc))); |
| 1604 | fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), chunkno); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1605 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1606 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff); |
| 1607 | pgoff = PSS_SMEM_PGOFF(loff); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1608 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1609 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1610 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1611 | for (i = 0; i < bfa_cb_image_get_size(BFA_IOC_FWIMG_TYPE(ioc)); i++) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1612 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1613 | if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) { |
| 1614 | chunkno = BFA_IOC_FLASH_CHUNK_NO(i); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1615 | fwimg = bfa_cb_image_get_chunk(BFA_IOC_FWIMG_TYPE(ioc), |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1616 | BFA_IOC_FLASH_CHUNK_ADDR(chunkno)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1617 | } |
| 1618 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1619 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1620 | * write smem |
| 1621 | */ |
| 1622 | bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1623 | fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1624 | |
| 1625 | loff += sizeof(u32); |
| 1626 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1627 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1628 | * handle page offset wrap around |
| 1629 | */ |
| 1630 | loff = PSS_SMEM_PGOFF(loff); |
| 1631 | if (loff == 0) { |
| 1632 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1633 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1637 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1638 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | 13cc20c | 2010-03-05 19:37:29 -0800 | [diff] [blame] | 1639 | |
| 1640 | /* |
| 1641 | * Set boot type and boot param at the end. |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1642 | */ |
Krishna Gudipati | 13cc20c | 2010-03-05 19:37:29 -0800 | [diff] [blame] | 1643 | bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_TYPE_OFF, |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1644 | swab32(boot_type)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1645 | bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_BOOT_LOADER_OFF, |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1646 | swab32(boot_env)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1647 | } |
| 1648 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1649 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1650 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1651 | * Update BFA configuration from firmware configuration. |
| 1652 | */ |
| 1653 | static void |
| 1654 | bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc) |
| 1655 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1656 | struct bfi_ioc_attr_s *attr = ioc->attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1657 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1658 | attr->adapter_prop = be32_to_cpu(attr->adapter_prop); |
| 1659 | attr->card_type = be32_to_cpu(attr->card_type); |
| 1660 | attr->maxfrsize = be16_to_cpu(attr->maxfrsize); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1661 | |
| 1662 | bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR); |
| 1663 | } |
| 1664 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1665 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1666 | * Attach time initialization of mbox logic. |
| 1667 | */ |
| 1668 | static void |
| 1669 | bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc) |
| 1670 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1671 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1672 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1673 | |
| 1674 | INIT_LIST_HEAD(&mod->cmd_q); |
| 1675 | for (mc = 0; mc < BFI_MC_MAX; mc++) { |
| 1676 | mod->mbhdlr[mc].cbfn = NULL; |
| 1677 | mod->mbhdlr[mc].cbarg = ioc->bfa; |
| 1678 | } |
| 1679 | } |
| 1680 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1681 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1682 | * Mbox poll timer -- restarts any pending mailbox requests. |
| 1683 | */ |
| 1684 | static void |
| 1685 | bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc) |
| 1686 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1687 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1688 | struct bfa_mbox_cmd_s *cmd; |
| 1689 | u32 stat; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1690 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1691 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1692 | * If no command pending, do nothing |
| 1693 | */ |
| 1694 | if (list_empty(&mod->cmd_q)) |
| 1695 | return; |
| 1696 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1697 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1698 | * If previous command is not yet fetched by firmware, do nothing |
| 1699 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1700 | stat = readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1701 | if (stat) |
| 1702 | return; |
| 1703 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1704 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1705 | * Enqueue command to firmware. |
| 1706 | */ |
| 1707 | bfa_q_deq(&mod->cmd_q, &cmd); |
| 1708 | bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); |
| 1709 | } |
| 1710 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1711 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1712 | * Cleanup any pending requests. |
| 1713 | */ |
| 1714 | static void |
| 1715 | bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc) |
| 1716 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1717 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1718 | struct bfa_mbox_cmd_s *cmd; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1719 | |
| 1720 | while (!list_empty(&mod->cmd_q)) |
| 1721 | bfa_q_deq(&mod->cmd_q, &cmd); |
| 1722 | } |
| 1723 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1724 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1725 | * Read data from SMEM to host through PCI memmap |
| 1726 | * |
| 1727 | * @param[in] ioc memory for IOC |
| 1728 | * @param[in] tbuf app memory to store data from smem |
| 1729 | * @param[in] soff smem offset |
| 1730 | * @param[in] sz size of smem in bytes |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1731 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1732 | static bfa_status_t |
| 1733 | bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz) |
| 1734 | { |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 1735 | u32 pgnum, loff; |
| 1736 | __be32 r32; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1737 | int i, len; |
| 1738 | u32 *buf = tbuf; |
| 1739 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1740 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff); |
| 1741 | loff = PSS_SMEM_PGOFF(soff); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1742 | bfa_trc(ioc, pgnum); |
| 1743 | bfa_trc(ioc, loff); |
| 1744 | bfa_trc(ioc, sz); |
| 1745 | |
| 1746 | /* |
| 1747 | * Hold semaphore to serialize pll init and fwtrc. |
| 1748 | */ |
| 1749 | if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) { |
| 1750 | bfa_trc(ioc, 0); |
| 1751 | return BFA_STATUS_FAILED; |
| 1752 | } |
| 1753 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1754 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1755 | |
| 1756 | len = sz/sizeof(u32); |
| 1757 | bfa_trc(ioc, len); |
| 1758 | for (i = 0; i < len; i++) { |
| 1759 | r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1760 | buf[i] = be32_to_cpu(r32); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1761 | loff += sizeof(u32); |
| 1762 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1763 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1764 | * handle page offset wrap around |
| 1765 | */ |
| 1766 | loff = PSS_SMEM_PGOFF(loff); |
| 1767 | if (loff == 0) { |
| 1768 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1769 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1770 | } |
| 1771 | } |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1772 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1773 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1774 | /* |
| 1775 | * release semaphore. |
| 1776 | */ |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1777 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1778 | |
| 1779 | bfa_trc(ioc, pgnum); |
| 1780 | return BFA_STATUS_OK; |
| 1781 | } |
| 1782 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1783 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1784 | * Clear SMEM data from host through PCI memmap |
| 1785 | * |
| 1786 | * @param[in] ioc memory for IOC |
| 1787 | * @param[in] soff smem offset |
| 1788 | * @param[in] sz size of smem in bytes |
| 1789 | */ |
| 1790 | static bfa_status_t |
| 1791 | bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz) |
| 1792 | { |
| 1793 | int i, len; |
| 1794 | u32 pgnum, loff; |
| 1795 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1796 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff); |
| 1797 | loff = PSS_SMEM_PGOFF(soff); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1798 | bfa_trc(ioc, pgnum); |
| 1799 | bfa_trc(ioc, loff); |
| 1800 | bfa_trc(ioc, sz); |
| 1801 | |
| 1802 | /* |
| 1803 | * Hold semaphore to serialize pll init and fwtrc. |
| 1804 | */ |
| 1805 | if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) { |
| 1806 | bfa_trc(ioc, 0); |
| 1807 | return BFA_STATUS_FAILED; |
| 1808 | } |
| 1809 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1810 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1811 | |
| 1812 | len = sz/sizeof(u32); /* len in words */ |
| 1813 | bfa_trc(ioc, len); |
| 1814 | for (i = 0; i < len; i++) { |
| 1815 | bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0); |
| 1816 | loff += sizeof(u32); |
| 1817 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1818 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1819 | * handle page offset wrap around |
| 1820 | */ |
| 1821 | loff = PSS_SMEM_PGOFF(loff); |
| 1822 | if (loff == 0) { |
| 1823 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1824 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1825 | } |
| 1826 | } |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1827 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1828 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1829 | |
| 1830 | /* |
| 1831 | * release semaphore. |
| 1832 | */ |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1833 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1834 | bfa_trc(ioc, pgnum); |
| 1835 | return BFA_STATUS_OK; |
| 1836 | } |
| 1837 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1838 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1839 | bfa_ioc_fail_notify(struct bfa_ioc_s *ioc) |
| 1840 | { |
| 1841 | struct list_head *qe; |
| 1842 | struct bfa_ioc_hbfail_notify_s *notify; |
| 1843 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
| 1844 | |
| 1845 | /** |
| 1846 | * Notify driver and common modules registered for notification. |
| 1847 | */ |
| 1848 | ioc->cbfn->hbfail_cbfn(ioc->bfa); |
| 1849 | list_for_each(qe, &ioc->hb_notify_q) { |
| 1850 | notify = (struct bfa_ioc_hbfail_notify_s *) qe; |
| 1851 | notify->cbfn(notify->cbarg); |
| 1852 | } |
| 1853 | |
| 1854 | bfa_ioc_debug_save_ftrc(ioc); |
| 1855 | |
| 1856 | BFA_LOG(KERN_CRIT, bfad, bfa_log_level, |
| 1857 | "Heart Beat of IOC has failed\n"); |
| 1858 | |
| 1859 | } |
| 1860 | |
| 1861 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1862 | bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc) |
| 1863 | { |
| 1864 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1865 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1866 | * Provide enable completion callback. |
| 1867 | */ |
| 1868 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 1869 | BFA_LOG(KERN_WARNING, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1870 | "Running firmware version is incompatible " |
| 1871 | "with the driver version\n"); |
| 1872 | } |
| 1873 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1874 | bfa_status_t |
| 1875 | bfa_ioc_pll_init(struct bfa_ioc_s *ioc) |
| 1876 | { |
| 1877 | |
| 1878 | /* |
| 1879 | * Hold semaphore so that nobody can access the chip during init. |
| 1880 | */ |
| 1881 | bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg); |
| 1882 | |
| 1883 | bfa_ioc_pll_init_asic(ioc); |
| 1884 | |
| 1885 | ioc->pllinit = BFA_TRUE; |
| 1886 | /* |
| 1887 | * release semaphore. |
| 1888 | */ |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1889 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1890 | |
| 1891 | return BFA_STATUS_OK; |
| 1892 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1893 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1894 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1895 | * Interface used by diag module to do firmware boot with memory test |
| 1896 | * as the entry vector. |
| 1897 | */ |
| 1898 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1899 | bfa_ioc_boot(struct bfa_ioc_s *ioc, u32 boot_type, u32 boot_env) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1900 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1901 | void __iomem *rb; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1902 | |
| 1903 | bfa_ioc_stats(ioc, ioc_boots); |
| 1904 | |
| 1905 | if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK) |
| 1906 | return; |
| 1907 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1908 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1909 | * Initialize IOC state of all functions on a chip reset. |
| 1910 | */ |
| 1911 | rb = ioc->pcidev.pci_bar_kva; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1912 | if (boot_type == BFI_BOOT_TYPE_MEMTEST) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1913 | writel(BFI_IOC_MEMTEST, (rb + BFA_IOC0_STATE_REG)); |
| 1914 | writel(BFI_IOC_MEMTEST, (rb + BFA_IOC1_STATE_REG)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1915 | } else { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1916 | writel(BFI_IOC_INITING, (rb + BFA_IOC0_STATE_REG)); |
| 1917 | writel(BFI_IOC_INITING, (rb + BFA_IOC1_STATE_REG)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 1920 | bfa_ioc_msgflush(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1921 | bfa_ioc_download_fw(ioc, boot_type, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1922 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1923 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1924 | * Enable interrupts just before starting LPU |
| 1925 | */ |
| 1926 | ioc->cbfn->reset_cbfn(ioc->bfa); |
| 1927 | bfa_ioc_lpu_start(ioc); |
| 1928 | } |
| 1929 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1930 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1931 | * Enable/disable IOC failure auto recovery. |
| 1932 | */ |
| 1933 | void |
| 1934 | bfa_ioc_auto_recover(bfa_boolean_t auto_recover) |
| 1935 | { |
Krishna Gudipati | 2f9b885 | 2010-03-03 17:42:51 -0800 | [diff] [blame] | 1936 | bfa_auto_recover = auto_recover; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1940 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1941 | bfa_boolean_t |
| 1942 | bfa_ioc_is_operational(struct bfa_ioc_s *ioc) |
| 1943 | { |
| 1944 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op); |
| 1945 | } |
| 1946 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1947 | bfa_boolean_t |
| 1948 | bfa_ioc_is_initialized(struct bfa_ioc_s *ioc) |
| 1949 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1950 | u32 r32 = readl(ioc->ioc_regs.ioc_fwstate); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1951 | |
| 1952 | return ((r32 != BFI_IOC_UNINIT) && |
| 1953 | (r32 != BFI_IOC_INITING) && |
| 1954 | (r32 != BFI_IOC_MEMTEST)); |
| 1955 | } |
| 1956 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1957 | void |
| 1958 | bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg) |
| 1959 | { |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 1960 | __be32 *msgp = mbmsg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1961 | u32 r32; |
| 1962 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1963 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1964 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1965 | * read the MBOX msg |
| 1966 | */ |
| 1967 | for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32)); |
| 1968 | i++) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1969 | r32 = readl(ioc->ioc_regs.lpu_mbox + |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1970 | i * sizeof(u32)); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1971 | msgp[i] = cpu_to_be32(r32); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1974 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1975 | * turn off mailbox interrupt by clearing mailbox status |
| 1976 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1977 | writel(1, ioc->ioc_regs.lpu_mbox_cmd); |
| 1978 | readl(ioc->ioc_regs.lpu_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | void |
| 1982 | bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m) |
| 1983 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1984 | union bfi_ioc_i2h_msg_u *msg; |
| 1985 | struct bfa_iocpf_s *iocpf = &ioc->iocpf; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1986 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1987 | msg = (union bfi_ioc_i2h_msg_u *) m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1988 | |
| 1989 | bfa_ioc_stats(ioc, ioc_isrs); |
| 1990 | |
| 1991 | switch (msg->mh.msg_id) { |
| 1992 | case BFI_IOC_I2H_HBEAT: |
| 1993 | break; |
| 1994 | |
| 1995 | case BFI_IOC_I2H_READY_EVENT: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1996 | bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1997 | break; |
| 1998 | |
| 1999 | case BFI_IOC_I2H_ENABLE_REPLY: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2000 | bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2001 | break; |
| 2002 | |
| 2003 | case BFI_IOC_I2H_DISABLE_REPLY: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2004 | bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2005 | break; |
| 2006 | |
| 2007 | case BFI_IOC_I2H_GETATTR_REPLY: |
| 2008 | bfa_ioc_getattr_reply(ioc); |
| 2009 | break; |
| 2010 | |
| 2011 | default: |
| 2012 | bfa_trc(ioc, msg->mh.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 2013 | WARN_ON(1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2017 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2018 | * IOC attach time initialization and setup. |
| 2019 | * |
| 2020 | * @param[in] ioc memory for IOC |
| 2021 | * @param[in] bfa driver instance structure |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2022 | */ |
| 2023 | void |
| 2024 | bfa_ioc_attach(struct bfa_ioc_s *ioc, void *bfa, struct bfa_ioc_cbfn_s *cbfn, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2025 | struct bfa_timer_mod_s *timer_mod) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2026 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2027 | ioc->bfa = bfa; |
| 2028 | ioc->cbfn = cbfn; |
| 2029 | ioc->timer_mod = timer_mod; |
| 2030 | ioc->fcmode = BFA_FALSE; |
| 2031 | ioc->pllinit = BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2032 | ioc->dbg_fwsave_once = BFA_TRUE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2033 | ioc->iocpf.ioc = ioc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2034 | |
| 2035 | bfa_ioc_mbox_attach(ioc); |
| 2036 | INIT_LIST_HEAD(&ioc->hb_notify_q); |
| 2037 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2038 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
| 2039 | bfa_fsm_send_event(ioc, IOC_E_RESET); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2042 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2043 | * Driver detach time IOC cleanup. |
| 2044 | */ |
| 2045 | void |
| 2046 | bfa_ioc_detach(struct bfa_ioc_s *ioc) |
| 2047 | { |
| 2048 | bfa_fsm_send_event(ioc, IOC_E_DETACH); |
| 2049 | } |
| 2050 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2051 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2052 | * Setup IOC PCI properties. |
| 2053 | * |
| 2054 | * @param[in] pcidev PCI device information for this IOC |
| 2055 | */ |
| 2056 | void |
| 2057 | bfa_ioc_pci_init(struct bfa_ioc_s *ioc, struct bfa_pcidev_s *pcidev, |
| 2058 | enum bfi_mclass mc) |
| 2059 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2060 | ioc->ioc_mc = mc; |
| 2061 | ioc->pcidev = *pcidev; |
| 2062 | ioc->ctdev = bfa_asic_id_ct(ioc->pcidev.device_id); |
| 2063 | ioc->cna = ioc->ctdev && !ioc->fcmode; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2064 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2065 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2066 | * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c |
| 2067 | */ |
| 2068 | if (ioc->ctdev) |
| 2069 | bfa_ioc_set_ct_hwif(ioc); |
| 2070 | else |
| 2071 | bfa_ioc_set_cb_hwif(ioc); |
| 2072 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2073 | bfa_ioc_map_port(ioc); |
| 2074 | bfa_ioc_reg_init(ioc); |
| 2075 | } |
| 2076 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2077 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2078 | * Initialize IOC dma memory |
| 2079 | * |
| 2080 | * @param[in] dm_kva kernel virtual address of IOC dma memory |
| 2081 | * @param[in] dm_pa physical address of IOC dma memory |
| 2082 | */ |
| 2083 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2084 | bfa_ioc_mem_claim(struct bfa_ioc_s *ioc, u8 *dm_kva, u64 dm_pa) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2085 | { |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2086 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2087 | * dma memory for firmware attribute |
| 2088 | */ |
| 2089 | ioc->attr_dma.kva = dm_kva; |
| 2090 | ioc->attr_dma.pa = dm_pa; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2091 | ioc->attr = (struct bfi_ioc_attr_s *) dm_kva; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2092 | } |
| 2093 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2094 | void |
| 2095 | bfa_ioc_enable(struct bfa_ioc_s *ioc) |
| 2096 | { |
| 2097 | bfa_ioc_stats(ioc, ioc_enables); |
| 2098 | ioc->dbg_fwsave_once = BFA_TRUE; |
| 2099 | |
| 2100 | bfa_fsm_send_event(ioc, IOC_E_ENABLE); |
| 2101 | } |
| 2102 | |
| 2103 | void |
| 2104 | bfa_ioc_disable(struct bfa_ioc_s *ioc) |
| 2105 | { |
| 2106 | bfa_ioc_stats(ioc, ioc_disables); |
| 2107 | bfa_fsm_send_event(ioc, IOC_E_DISABLE); |
| 2108 | } |
| 2109 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2110 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2111 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2112 | * Initialize memory for saving firmware trace. Driver must initialize |
| 2113 | * trace memory before call bfa_ioc_enable(). |
| 2114 | */ |
| 2115 | void |
| 2116 | bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave) |
| 2117 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2118 | ioc->dbg_fwsave = dbg_fwsave; |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 2119 | ioc->dbg_fwsave_len = (ioc->iocpf.auto_recover) ? BFA_DBG_FWTRC_LEN : 0; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2122 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2123 | * Register mailbox message handler functions |
| 2124 | * |
| 2125 | * @param[in] ioc IOC instance |
| 2126 | * @param[in] mcfuncs message class handler functions |
| 2127 | */ |
| 2128 | void |
| 2129 | bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs) |
| 2130 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2131 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2132 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2133 | |
| 2134 | for (mc = 0; mc < BFI_MC_MAX; mc++) |
| 2135 | mod->mbhdlr[mc].cbfn = mcfuncs[mc]; |
| 2136 | } |
| 2137 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2138 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2139 | * Register mailbox message handler function, to be called by common modules |
| 2140 | */ |
| 2141 | void |
| 2142 | bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc, |
| 2143 | bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg) |
| 2144 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2145 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2146 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2147 | mod->mbhdlr[mc].cbfn = cbfn; |
| 2148 | mod->mbhdlr[mc].cbarg = cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2151 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2152 | * Queue a mailbox command request to firmware. Waits if mailbox is busy. |
| 2153 | * Responsibility of caller to serialize |
| 2154 | * |
| 2155 | * @param[in] ioc IOC instance |
| 2156 | * @param[i] cmd Mailbox command |
| 2157 | */ |
| 2158 | void |
| 2159 | bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd) |
| 2160 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2161 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2162 | u32 stat; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2163 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2164 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2165 | * If a previous command is pending, queue new command |
| 2166 | */ |
| 2167 | if (!list_empty(&mod->cmd_q)) { |
| 2168 | list_add_tail(&cmd->qe, &mod->cmd_q); |
| 2169 | return; |
| 2170 | } |
| 2171 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2172 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2173 | * If mailbox is busy, queue command for poll timer |
| 2174 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2175 | stat = readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2176 | if (stat) { |
| 2177 | list_add_tail(&cmd->qe, &mod->cmd_q); |
| 2178 | return; |
| 2179 | } |
| 2180 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2181 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2182 | * mailbox is free -- queue command to firmware |
| 2183 | */ |
| 2184 | bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); |
| 2185 | } |
| 2186 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2187 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2188 | * Handle mailbox interrupts |
| 2189 | */ |
| 2190 | void |
| 2191 | bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc) |
| 2192 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2193 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2194 | struct bfi_mbmsg_s m; |
| 2195 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2196 | |
| 2197 | bfa_ioc_msgget(ioc, &m); |
| 2198 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2199 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2200 | * Treat IOC message class as special. |
| 2201 | */ |
| 2202 | mc = m.mh.msg_class; |
| 2203 | if (mc == BFI_MC_IOC) { |
| 2204 | bfa_ioc_isr(ioc, &m); |
| 2205 | return; |
| 2206 | } |
| 2207 | |
| 2208 | if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL)) |
| 2209 | return; |
| 2210 | |
| 2211 | mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m); |
| 2212 | } |
| 2213 | |
| 2214 | void |
| 2215 | bfa_ioc_error_isr(struct bfa_ioc_s *ioc) |
| 2216 | { |
| 2217 | bfa_fsm_send_event(ioc, IOC_E_HWERROR); |
| 2218 | } |
| 2219 | |
Jing Huang | ed96932 | 2010-07-08 19:45:56 -0700 | [diff] [blame] | 2220 | void |
| 2221 | bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc) |
| 2222 | { |
| 2223 | ioc->fcmode = BFA_TRUE; |
| 2224 | ioc->port_id = bfa_ioc_pcifn(ioc); |
| 2225 | } |
| 2226 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2227 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2228 | * return true if IOC is disabled |
| 2229 | */ |
| 2230 | bfa_boolean_t |
| 2231 | bfa_ioc_is_disabled(struct bfa_ioc_s *ioc) |
| 2232 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2233 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) || |
| 2234 | bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2235 | } |
| 2236 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2237 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2238 | * return true if IOC firmware is different. |
| 2239 | */ |
| 2240 | bfa_boolean_t |
| 2241 | bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc) |
| 2242 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2243 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) || |
| 2244 | bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) || |
| 2245 | bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2246 | } |
| 2247 | |
| 2248 | #define bfa_ioc_state_disabled(__sm) \ |
| 2249 | (((__sm) == BFI_IOC_UNINIT) || \ |
| 2250 | ((__sm) == BFI_IOC_INITING) || \ |
| 2251 | ((__sm) == BFI_IOC_HWINIT) || \ |
| 2252 | ((__sm) == BFI_IOC_DISABLED) || \ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2253 | ((__sm) == BFI_IOC_FAIL) || \ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2254 | ((__sm) == BFI_IOC_CFG_DISABLED)) |
| 2255 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2256 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2257 | * Check if adapter is disabled -- both IOCs should be in a disabled |
| 2258 | * state. |
| 2259 | */ |
| 2260 | bfa_boolean_t |
| 2261 | bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc) |
| 2262 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2263 | u32 ioc_state; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2264 | void __iomem *rb = ioc->pcidev.pci_bar_kva; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2265 | |
| 2266 | if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled)) |
| 2267 | return BFA_FALSE; |
| 2268 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2269 | ioc_state = readl(rb + BFA_IOC0_STATE_REG); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2270 | if (!bfa_ioc_state_disabled(ioc_state)) |
| 2271 | return BFA_FALSE; |
| 2272 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2273 | if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2274 | ioc_state = readl(rb + BFA_IOC1_STATE_REG); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2275 | if (!bfa_ioc_state_disabled(ioc_state)) |
| 2276 | return BFA_FALSE; |
| 2277 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2278 | |
| 2279 | return BFA_TRUE; |
| 2280 | } |
| 2281 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 2282 | /** |
| 2283 | * Reset IOC fwstate registers. |
| 2284 | */ |
| 2285 | void |
| 2286 | bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc) |
| 2287 | { |
| 2288 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate); |
| 2289 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate); |
| 2290 | } |
| 2291 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2292 | #define BFA_MFG_NAME "Brocade" |
| 2293 | void |
| 2294 | bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc, |
| 2295 | struct bfa_adapter_attr_s *ad_attr) |
| 2296 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2297 | struct bfi_ioc_attr_s *ioc_attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2298 | |
| 2299 | ioc_attr = ioc->attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2300 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2301 | bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num); |
| 2302 | bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver); |
| 2303 | bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver); |
| 2304 | bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2305 | memcpy(&ad_attr->vpd, &ioc_attr->vpd, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2306 | sizeof(struct bfa_mfg_vpd_s)); |
| 2307 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2308 | ad_attr->nports = bfa_ioc_get_nports(ioc); |
| 2309 | ad_attr->max_speed = bfa_ioc_speed_sup(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2310 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2311 | bfa_ioc_get_adapter_model(ioc, ad_attr->model); |
| 2312 | /* For now, model descr uses same model string */ |
| 2313 | bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2314 | |
Jing Huang | ed96932 | 2010-07-08 19:45:56 -0700 | [diff] [blame] | 2315 | ad_attr->card_type = ioc_attr->card_type; |
| 2316 | ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type); |
| 2317 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2318 | if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop)) |
| 2319 | ad_attr->prototype = 1; |
| 2320 | else |
| 2321 | ad_attr->prototype = 0; |
| 2322 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 2323 | ad_attr->pwwn = ioc->attr->pwwn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2324 | ad_attr->mac = bfa_ioc_get_mac(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2325 | |
| 2326 | ad_attr->pcie_gen = ioc_attr->pcie_gen; |
| 2327 | ad_attr->pcie_lanes = ioc_attr->pcie_lanes; |
| 2328 | ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig; |
| 2329 | ad_attr->asic_rev = ioc_attr->asic_rev; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2330 | |
| 2331 | bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2332 | |
| 2333 | ad_attr->cna_capable = ioc->cna; |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 2334 | ad_attr->trunk_capable = (ad_attr->nports > 1) && !ioc->cna && |
| 2335 | !ad_attr->is_mezz; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2336 | } |
| 2337 | |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2338 | enum bfa_ioc_type_e |
| 2339 | bfa_ioc_get_type(struct bfa_ioc_s *ioc) |
| 2340 | { |
| 2341 | if (!ioc->ctdev || ioc->fcmode) |
| 2342 | return BFA_IOC_TYPE_FC; |
| 2343 | else if (ioc->ioc_mc == BFI_MC_IOCFC) |
| 2344 | return BFA_IOC_TYPE_FCoE; |
| 2345 | else if (ioc->ioc_mc == BFI_MC_LL) |
| 2346 | return BFA_IOC_TYPE_LL; |
| 2347 | else { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 2348 | WARN_ON(ioc->ioc_mc != BFI_MC_LL); |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2349 | return BFA_IOC_TYPE_LL; |
| 2350 | } |
| 2351 | } |
| 2352 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2353 | void |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2354 | bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num) |
| 2355 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2356 | memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN); |
| 2357 | memcpy((void *)serial_num, |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2358 | (void *)ioc->attr->brcd_serialnum, |
| 2359 | BFA_ADAPTER_SERIAL_NUM_LEN); |
| 2360 | } |
| 2361 | |
| 2362 | void |
| 2363 | bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver) |
| 2364 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2365 | memset((void *)fw_ver, 0, BFA_VERSION_LEN); |
| 2366 | memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | void |
| 2370 | bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev) |
| 2371 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 2372 | WARN_ON(!chip_rev); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2373 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2374 | memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2375 | |
| 2376 | chip_rev[0] = 'R'; |
| 2377 | chip_rev[1] = 'e'; |
| 2378 | chip_rev[2] = 'v'; |
| 2379 | chip_rev[3] = '-'; |
| 2380 | chip_rev[4] = ioc->attr->asic_rev; |
| 2381 | chip_rev[5] = '\0'; |
| 2382 | } |
| 2383 | |
| 2384 | void |
| 2385 | bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver) |
| 2386 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2387 | memset((void *)optrom_ver, 0, BFA_VERSION_LEN); |
| 2388 | memcpy(optrom_ver, ioc->attr->optrom_version, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2389 | BFA_VERSION_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | void |
| 2393 | bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer) |
| 2394 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2395 | memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN); |
| 2396 | memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2397 | } |
| 2398 | |
| 2399 | void |
| 2400 | bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model) |
| 2401 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2402 | struct bfi_ioc_attr_s *ioc_attr; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2403 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 2404 | WARN_ON(!model); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2405 | memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2406 | |
| 2407 | ioc_attr = ioc->attr; |
| 2408 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2409 | /* |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2410 | * model name |
| 2411 | */ |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2412 | snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u", |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2413 | BFA_MFG_NAME, ioc_attr->card_type); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | enum bfa_ioc_state |
| 2417 | bfa_ioc_get_state(struct bfa_ioc_s *ioc) |
| 2418 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2419 | enum bfa_iocpf_state iocpf_st; |
| 2420 | enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm); |
| 2421 | |
| 2422 | if (ioc_st == BFA_IOC_ENABLING || |
| 2423 | ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) { |
| 2424 | |
| 2425 | iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm); |
| 2426 | |
| 2427 | switch (iocpf_st) { |
| 2428 | case BFA_IOCPF_SEMWAIT: |
| 2429 | ioc_st = BFA_IOC_SEMWAIT; |
| 2430 | break; |
| 2431 | |
| 2432 | case BFA_IOCPF_HWINIT: |
| 2433 | ioc_st = BFA_IOC_HWINIT; |
| 2434 | break; |
| 2435 | |
| 2436 | case BFA_IOCPF_FWMISMATCH: |
| 2437 | ioc_st = BFA_IOC_FWMISMATCH; |
| 2438 | break; |
| 2439 | |
| 2440 | case BFA_IOCPF_FAIL: |
| 2441 | ioc_st = BFA_IOC_FAIL; |
| 2442 | break; |
| 2443 | |
| 2444 | case BFA_IOCPF_INITFAIL: |
| 2445 | ioc_st = BFA_IOC_INITFAIL; |
| 2446 | break; |
| 2447 | |
| 2448 | default: |
| 2449 | break; |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | return ioc_st; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | void |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2457 | bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr) |
| 2458 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2459 | memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2460 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2461 | ioc_attr->state = bfa_ioc_get_state(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2462 | ioc_attr->port_id = ioc->port_id; |
| 2463 | |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2464 | ioc_attr->ioc_type = bfa_ioc_get_type(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2465 | |
| 2466 | bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr); |
| 2467 | |
| 2468 | ioc_attr->pci_attr.device_id = ioc->pcidev.device_id; |
| 2469 | ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2470 | bfa_ioc_get_pci_chip_rev(ioc, ioc_attr->pci_attr.chip_rev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2473 | mac_t |
| 2474 | bfa_ioc_get_mac(struct bfa_ioc_s *ioc) |
| 2475 | { |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2476 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2477 | * Check the IOC type and return the appropriate MAC |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2478 | */ |
| 2479 | if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2480 | return ioc->attr->fcoe_mac; |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2481 | else |
| 2482 | return ioc->attr->mac; |
| 2483 | } |
| 2484 | |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2485 | mac_t |
| 2486 | bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc) |
| 2487 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2488 | mac_t m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2489 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2490 | m = ioc->attr->mfg_mac; |
| 2491 | if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type)) |
| 2492 | m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc); |
| 2493 | else |
| 2494 | bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]), |
| 2495 | bfa_ioc_pcifn(ioc)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2496 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2497 | return m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2498 | } |
| 2499 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2500 | bfa_boolean_t |
| 2501 | bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc) |
| 2502 | { |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 2503 | return ioc->fcmode || !bfa_asic_id_ct(ioc->pcidev.device_id); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2504 | } |
| 2505 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2506 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2507 | * Retrieve saved firmware trace from a prior IOC failure. |
| 2508 | */ |
| 2509 | bfa_status_t |
| 2510 | bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen) |
| 2511 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2512 | int tlen; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2513 | |
| 2514 | if (ioc->dbg_fwsave_len == 0) |
| 2515 | return BFA_STATUS_ENOFSAVE; |
| 2516 | |
| 2517 | tlen = *trclen; |
| 2518 | if (tlen > ioc->dbg_fwsave_len) |
| 2519 | tlen = ioc->dbg_fwsave_len; |
| 2520 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2521 | memcpy(trcdata, ioc->dbg_fwsave, tlen); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2522 | *trclen = tlen; |
| 2523 | return BFA_STATUS_OK; |
| 2524 | } |
| 2525 | |
Krishna Gudipati | 738c9e6 | 2010-03-05 19:36:19 -0800 | [diff] [blame] | 2526 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2527 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2528 | * Retrieve saved firmware trace from a prior IOC failure. |
| 2529 | */ |
| 2530 | bfa_status_t |
| 2531 | bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen) |
| 2532 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2533 | u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc)); |
| 2534 | int tlen; |
| 2535 | bfa_status_t status; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2536 | |
| 2537 | bfa_trc(ioc, *trclen); |
| 2538 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2539 | tlen = *trclen; |
| 2540 | if (tlen > BFA_DBG_FWTRC_LEN) |
| 2541 | tlen = BFA_DBG_FWTRC_LEN; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2542 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2543 | status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen); |
| 2544 | *trclen = tlen; |
| 2545 | return status; |
| 2546 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2547 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2548 | static void |
| 2549 | bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc) |
| 2550 | { |
| 2551 | struct bfa_mbox_cmd_s cmd; |
| 2552 | struct bfi_ioc_ctrl_req_s *req = (struct bfi_ioc_ctrl_req_s *) cmd.msg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2553 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2554 | bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC, |
| 2555 | bfa_ioc_portid(ioc)); |
| 2556 | req->ioc_class = ioc->ioc_mc; |
| 2557 | bfa_ioc_mbox_queue(ioc, &cmd); |
| 2558 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2559 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2560 | static void |
| 2561 | bfa_ioc_fwsync(struct bfa_ioc_s *ioc) |
| 2562 | { |
| 2563 | u32 fwsync_iter = 1000; |
| 2564 | |
| 2565 | bfa_ioc_send_fwsync(ioc); |
| 2566 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2567 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2568 | * After sending a fw sync mbox command wait for it to |
| 2569 | * take effect. We will not wait for a response because |
| 2570 | * 1. fw_sync mbox cmd doesn't have a response. |
| 2571 | * 2. Even if we implement that, interrupts might not |
| 2572 | * be enabled when we call this function. |
| 2573 | * So, just keep checking if any mbox cmd is pending, and |
| 2574 | * after waiting for a reasonable amount of time, go ahead. |
| 2575 | * It is possible that fw has crashed and the mbox command |
| 2576 | * is never acknowledged. |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2577 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2578 | while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0) |
| 2579 | fwsync_iter--; |
| 2580 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2581 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2582 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2583 | * Dump firmware smem |
| 2584 | */ |
| 2585 | bfa_status_t |
| 2586 | bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf, |
| 2587 | u32 *offset, int *buflen) |
| 2588 | { |
| 2589 | u32 loff; |
| 2590 | int dlen; |
| 2591 | bfa_status_t status; |
| 2592 | u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2593 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2594 | if (*offset >= smem_len) { |
| 2595 | *offset = *buflen = 0; |
| 2596 | return BFA_STATUS_EINVAL; |
| 2597 | } |
| 2598 | |
| 2599 | loff = *offset; |
| 2600 | dlen = *buflen; |
| 2601 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2602 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2603 | * First smem read, sync smem before proceeding |
| 2604 | * No need to sync before reading every chunk. |
| 2605 | */ |
| 2606 | if (loff == 0) |
| 2607 | bfa_ioc_fwsync(ioc); |
| 2608 | |
| 2609 | if ((loff + dlen) >= smem_len) |
| 2610 | dlen = smem_len - loff; |
| 2611 | |
| 2612 | status = bfa_ioc_smem_read(ioc, buf, loff, dlen); |
| 2613 | |
| 2614 | if (status != BFA_STATUS_OK) { |
| 2615 | *offset = *buflen = 0; |
| 2616 | return status; |
| 2617 | } |
| 2618 | |
| 2619 | *offset += dlen; |
| 2620 | |
| 2621 | if (*offset >= smem_len) |
| 2622 | *offset = 0; |
| 2623 | |
| 2624 | *buflen = dlen; |
| 2625 | |
| 2626 | return status; |
| 2627 | } |
| 2628 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2629 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2630 | * Firmware statistics |
| 2631 | */ |
| 2632 | bfa_status_t |
| 2633 | bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats) |
| 2634 | { |
| 2635 | u32 loff = BFI_IOC_FWSTATS_OFF + \ |
| 2636 | BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc)); |
| 2637 | int tlen; |
| 2638 | bfa_status_t status; |
| 2639 | |
| 2640 | if (ioc->stats_busy) { |
| 2641 | bfa_trc(ioc, ioc->stats_busy); |
| 2642 | return BFA_STATUS_DEVBUSY; |
| 2643 | } |
| 2644 | ioc->stats_busy = BFA_TRUE; |
| 2645 | |
| 2646 | tlen = sizeof(struct bfa_fw_stats_s); |
| 2647 | status = bfa_ioc_smem_read(ioc, stats, loff, tlen); |
| 2648 | |
| 2649 | ioc->stats_busy = BFA_FALSE; |
| 2650 | return status; |
| 2651 | } |
| 2652 | |
| 2653 | bfa_status_t |
| 2654 | bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc) |
| 2655 | { |
| 2656 | u32 loff = BFI_IOC_FWSTATS_OFF + \ |
| 2657 | BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc)); |
| 2658 | int tlen; |
| 2659 | bfa_status_t status; |
| 2660 | |
| 2661 | if (ioc->stats_busy) { |
| 2662 | bfa_trc(ioc, ioc->stats_busy); |
| 2663 | return BFA_STATUS_DEVBUSY; |
| 2664 | } |
| 2665 | ioc->stats_busy = BFA_TRUE; |
| 2666 | |
| 2667 | tlen = sizeof(struct bfa_fw_stats_s); |
| 2668 | status = bfa_ioc_smem_clr(ioc, loff, tlen); |
| 2669 | |
| 2670 | ioc->stats_busy = BFA_FALSE; |
| 2671 | return status; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2672 | } |
| 2673 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2674 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2675 | * Save firmware trace if configured. |
| 2676 | */ |
| 2677 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 2678 | bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2679 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2680 | int tlen; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2681 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 2682 | if (ioc->dbg_fwsave_once) { |
| 2683 | ioc->dbg_fwsave_once = BFA_FALSE; |
| 2684 | if (ioc->dbg_fwsave_len) { |
| 2685 | tlen = ioc->dbg_fwsave_len; |
| 2686 | bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen); |
| 2687 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2688 | } |
| 2689 | } |
| 2690 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2691 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2692 | * Firmware failure detected. Start recovery actions. |
| 2693 | */ |
| 2694 | static void |
| 2695 | bfa_ioc_recover(struct bfa_ioc_s *ioc) |
| 2696 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2697 | bfa_ioc_stats(ioc, ioc_hbfails); |
| 2698 | bfa_fsm_send_event(ioc, IOC_E_HBFAIL); |
| 2699 | } |
| 2700 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2701 | static void |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 2702 | bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2703 | { |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 2704 | if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL) |
| 2705 | return; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2706 | } |
| 2707 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2708 | /* |
Maggie Zhang | df0f193 | 2010-12-09 19:07:46 -0800 | [diff] [blame] | 2709 | * BFA IOC PF private functions |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2710 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2711 | static void |
| 2712 | bfa_iocpf_timeout(void *ioc_arg) |
| 2713 | { |
| 2714 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
| 2715 | |
| 2716 | bfa_trc(ioc, 0); |
| 2717 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT); |
| 2718 | } |
| 2719 | |
| 2720 | static void |
| 2721 | bfa_iocpf_sem_timeout(void *ioc_arg) |
| 2722 | { |
| 2723 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
| 2724 | |
| 2725 | bfa_ioc_hw_sem_get(ioc); |
| 2726 | } |
| 2727 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2728 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2729 | * bfa timer function |
| 2730 | */ |
| 2731 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2732 | bfa_timer_beat(struct bfa_timer_mod_s *mod) |
| 2733 | { |
| 2734 | struct list_head *qh = &mod->timer_q; |
| 2735 | struct list_head *qe, *qe_next; |
| 2736 | struct bfa_timer_s *elem; |
| 2737 | struct list_head timedout_q; |
| 2738 | |
| 2739 | INIT_LIST_HEAD(&timedout_q); |
| 2740 | |
| 2741 | qe = bfa_q_next(qh); |
| 2742 | |
| 2743 | while (qe != qh) { |
| 2744 | qe_next = bfa_q_next(qe); |
| 2745 | |
| 2746 | elem = (struct bfa_timer_s *) qe; |
| 2747 | if (elem->timeout <= BFA_TIMER_FREQ) { |
| 2748 | elem->timeout = 0; |
| 2749 | list_del(&elem->qe); |
| 2750 | list_add_tail(&elem->qe, &timedout_q); |
| 2751 | } else { |
| 2752 | elem->timeout -= BFA_TIMER_FREQ; |
| 2753 | } |
| 2754 | |
| 2755 | qe = qe_next; /* go to next elem */ |
| 2756 | } |
| 2757 | |
| 2758 | /* |
| 2759 | * Pop all the timeout entries |
| 2760 | */ |
| 2761 | while (!list_empty(&timedout_q)) { |
| 2762 | bfa_q_deq(&timedout_q, &elem); |
| 2763 | elem->timercb(elem->arg); |
| 2764 | } |
| 2765 | } |
| 2766 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2767 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2768 | * Should be called with lock protection |
| 2769 | */ |
| 2770 | void |
| 2771 | bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer, |
| 2772 | void (*timercb) (void *), void *arg, unsigned int timeout) |
| 2773 | { |
| 2774 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 2775 | WARN_ON(timercb == NULL); |
| 2776 | WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2777 | |
| 2778 | timer->timeout = timeout; |
| 2779 | timer->timercb = timercb; |
| 2780 | timer->arg = arg; |
| 2781 | |
| 2782 | list_add_tail(&timer->qe, &mod->timer_q); |
| 2783 | } |
| 2784 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2785 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2786 | * Should be called with lock protection |
| 2787 | */ |
| 2788 | void |
| 2789 | bfa_timer_stop(struct bfa_timer_s *timer) |
| 2790 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame^] | 2791 | WARN_ON(list_empty(&timer->qe)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2792 | |
| 2793 | list_del(&timer->qe); |
| 2794 | } |