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