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" |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 20 | #include "bfi_reg.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | f7f7381 | 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 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1222 | while ((r32 & 1) && (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 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1228 | if (!(r32 & 1)) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 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); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1245 | if (!(r32 & 1)) { |
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 | f7f7381 | 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 | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1354 | bfa_cb_image_get_chunk(bfa_ioc_asic_gen(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 | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1380 | bfa_cb_image_get_chunk(bfa_ioc_asic_gen(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 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1388 | if (swab32(fwhdr.bootenv) != boot_env) { |
| 1389 | bfa_trc(ioc, fwhdr.bootenv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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 | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1425 | boot_type = BFI_FWBOOT_TYPE_NORMAL; |
| 1426 | boot_env = BFI_FWBOOT_ENV_OS; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 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; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1583 | u32 asicmode; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1584 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1585 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1586 | * Initialize LMEM first before code download |
| 1587 | */ |
| 1588 | bfa_ioc_lmem_init(ioc); |
| 1589 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1590 | bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc))); |
| 1591 | fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1592 | |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1593 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff); |
| 1594 | pgoff = PSS_SMEM_PGOFF(loff); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1595 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1596 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1597 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1598 | for (i = 0; i < bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc)); i++) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1599 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1600 | if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) { |
| 1601 | chunkno = BFA_IOC_FLASH_CHUNK_NO(i); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1602 | fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1603 | BFA_IOC_FLASH_CHUNK_ADDR(chunkno)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1604 | } |
| 1605 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1606 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1607 | * write smem |
| 1608 | */ |
| 1609 | bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1610 | fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)]); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1611 | |
| 1612 | loff += sizeof(u32); |
| 1613 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1614 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1615 | * handle page offset wrap around |
| 1616 | */ |
| 1617 | loff = PSS_SMEM_PGOFF(loff); |
| 1618 | if (loff == 0) { |
| 1619 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1620 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1621 | } |
| 1622 | } |
| 1623 | |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1624 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1625 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | 13cc20c | 2010-03-05 19:37:29 -0800 | [diff] [blame] | 1626 | |
| 1627 | /* |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1628 | * Set boot type and device mode at the end. |
| 1629 | */ |
| 1630 | asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode, |
| 1631 | ioc->port0_mode, ioc->port1_mode); |
| 1632 | bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF, |
| 1633 | swab32(asicmode)); |
| 1634 | bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_TYPE_OFF, |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1635 | swab32(boot_type)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1636 | bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_ENV_OFF, |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1637 | swab32(boot_env)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1638 | } |
| 1639 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1640 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1641 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1642 | * Update BFA configuration from firmware configuration. |
| 1643 | */ |
| 1644 | static void |
| 1645 | bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc) |
| 1646 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1647 | struct bfi_ioc_attr_s *attr = ioc->attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1648 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1649 | attr->adapter_prop = be32_to_cpu(attr->adapter_prop); |
| 1650 | attr->card_type = be32_to_cpu(attr->card_type); |
| 1651 | attr->maxfrsize = be16_to_cpu(attr->maxfrsize); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1652 | |
| 1653 | bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR); |
| 1654 | } |
| 1655 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1656 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1657 | * Attach time initialization of mbox logic. |
| 1658 | */ |
| 1659 | static void |
| 1660 | bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc) |
| 1661 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1662 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1663 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1664 | |
| 1665 | INIT_LIST_HEAD(&mod->cmd_q); |
| 1666 | for (mc = 0; mc < BFI_MC_MAX; mc++) { |
| 1667 | mod->mbhdlr[mc].cbfn = NULL; |
| 1668 | mod->mbhdlr[mc].cbarg = ioc->bfa; |
| 1669 | } |
| 1670 | } |
| 1671 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1672 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1673 | * Mbox poll timer -- restarts any pending mailbox requests. |
| 1674 | */ |
| 1675 | static void |
| 1676 | bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc) |
| 1677 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1678 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1679 | struct bfa_mbox_cmd_s *cmd; |
| 1680 | u32 stat; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1681 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1682 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1683 | * If no command pending, do nothing |
| 1684 | */ |
| 1685 | if (list_empty(&mod->cmd_q)) |
| 1686 | return; |
| 1687 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1688 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1689 | * If previous command is not yet fetched by firmware, do nothing |
| 1690 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1691 | stat = readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1692 | if (stat) |
| 1693 | return; |
| 1694 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1695 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1696 | * Enqueue command to firmware. |
| 1697 | */ |
| 1698 | bfa_q_deq(&mod->cmd_q, &cmd); |
| 1699 | bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); |
| 1700 | } |
| 1701 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1702 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1703 | * Cleanup any pending requests. |
| 1704 | */ |
| 1705 | static void |
| 1706 | bfa_ioc_mbox_hbfail(struct bfa_ioc_s *ioc) |
| 1707 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1708 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1709 | struct bfa_mbox_cmd_s *cmd; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1710 | |
| 1711 | while (!list_empty(&mod->cmd_q)) |
| 1712 | bfa_q_deq(&mod->cmd_q, &cmd); |
| 1713 | } |
| 1714 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1715 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1716 | * Read data from SMEM to host through PCI memmap |
| 1717 | * |
| 1718 | * @param[in] ioc memory for IOC |
| 1719 | * @param[in] tbuf app memory to store data from smem |
| 1720 | * @param[in] soff smem offset |
| 1721 | * @param[in] sz size of smem in bytes |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1722 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1723 | static bfa_status_t |
| 1724 | bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz) |
| 1725 | { |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 1726 | u32 pgnum, loff; |
| 1727 | __be32 r32; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1728 | int i, len; |
| 1729 | u32 *buf = tbuf; |
| 1730 | |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1731 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff); |
| 1732 | loff = PSS_SMEM_PGOFF(soff); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1733 | bfa_trc(ioc, pgnum); |
| 1734 | bfa_trc(ioc, loff); |
| 1735 | bfa_trc(ioc, sz); |
| 1736 | |
| 1737 | /* |
| 1738 | * Hold semaphore to serialize pll init and fwtrc. |
| 1739 | */ |
| 1740 | if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) { |
| 1741 | bfa_trc(ioc, 0); |
| 1742 | return BFA_STATUS_FAILED; |
| 1743 | } |
| 1744 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1745 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1746 | |
| 1747 | len = sz/sizeof(u32); |
| 1748 | bfa_trc(ioc, len); |
| 1749 | for (i = 0; i < len; i++) { |
| 1750 | r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1751 | buf[i] = be32_to_cpu(r32); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1752 | loff += sizeof(u32); |
| 1753 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1754 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1755 | * handle page offset wrap around |
| 1756 | */ |
| 1757 | loff = PSS_SMEM_PGOFF(loff); |
| 1758 | if (loff == 0) { |
| 1759 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1760 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1761 | } |
| 1762 | } |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1763 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1764 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1765 | /* |
| 1766 | * release semaphore. |
| 1767 | */ |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1768 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1769 | |
| 1770 | bfa_trc(ioc, pgnum); |
| 1771 | return BFA_STATUS_OK; |
| 1772 | } |
| 1773 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1774 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1775 | * Clear SMEM data from host through PCI memmap |
| 1776 | * |
| 1777 | * @param[in] ioc memory for IOC |
| 1778 | * @param[in] soff smem offset |
| 1779 | * @param[in] sz size of smem in bytes |
| 1780 | */ |
| 1781 | static bfa_status_t |
| 1782 | bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz) |
| 1783 | { |
| 1784 | int i, len; |
| 1785 | u32 pgnum, loff; |
| 1786 | |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1787 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff); |
| 1788 | loff = PSS_SMEM_PGOFF(soff); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1789 | bfa_trc(ioc, pgnum); |
| 1790 | bfa_trc(ioc, loff); |
| 1791 | bfa_trc(ioc, sz); |
| 1792 | |
| 1793 | /* |
| 1794 | * Hold semaphore to serialize pll init and fwtrc. |
| 1795 | */ |
| 1796 | if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) { |
| 1797 | bfa_trc(ioc, 0); |
| 1798 | return BFA_STATUS_FAILED; |
| 1799 | } |
| 1800 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1801 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1802 | |
| 1803 | len = sz/sizeof(u32); /* len in words */ |
| 1804 | bfa_trc(ioc, len); |
| 1805 | for (i = 0; i < len; i++) { |
| 1806 | bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0); |
| 1807 | loff += sizeof(u32); |
| 1808 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1809 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1810 | * handle page offset wrap around |
| 1811 | */ |
| 1812 | loff = PSS_SMEM_PGOFF(loff); |
| 1813 | if (loff == 0) { |
| 1814 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1815 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1816 | } |
| 1817 | } |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1818 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1819 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1820 | |
| 1821 | /* |
| 1822 | * release semaphore. |
| 1823 | */ |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1824 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1825 | bfa_trc(ioc, pgnum); |
| 1826 | return BFA_STATUS_OK; |
| 1827 | } |
| 1828 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1829 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1830 | bfa_ioc_fail_notify(struct bfa_ioc_s *ioc) |
| 1831 | { |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1832 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
| 1833 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1834 | /* |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1835 | * Notify driver and common modules registered for notification. |
| 1836 | */ |
| 1837 | ioc->cbfn->hbfail_cbfn(ioc->bfa); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 1838 | bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1839 | |
| 1840 | bfa_ioc_debug_save_ftrc(ioc); |
| 1841 | |
| 1842 | BFA_LOG(KERN_CRIT, bfad, bfa_log_level, |
| 1843 | "Heart Beat of IOC has failed\n"); |
| 1844 | |
| 1845 | } |
| 1846 | |
| 1847 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1848 | bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc) |
| 1849 | { |
| 1850 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1851 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1852 | * Provide enable completion callback. |
| 1853 | */ |
| 1854 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 1855 | BFA_LOG(KERN_WARNING, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1856 | "Running firmware version is incompatible " |
| 1857 | "with the driver version\n"); |
| 1858 | } |
| 1859 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1860 | bfa_status_t |
| 1861 | bfa_ioc_pll_init(struct bfa_ioc_s *ioc) |
| 1862 | { |
| 1863 | |
| 1864 | /* |
| 1865 | * Hold semaphore so that nobody can access the chip during init. |
| 1866 | */ |
| 1867 | bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg); |
| 1868 | |
| 1869 | bfa_ioc_pll_init_asic(ioc); |
| 1870 | |
| 1871 | ioc->pllinit = BFA_TRUE; |
| 1872 | /* |
| 1873 | * release semaphore. |
| 1874 | */ |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1875 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1876 | |
| 1877 | return BFA_STATUS_OK; |
| 1878 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1879 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1880 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1881 | * Interface used by diag module to do firmware boot with memory test |
| 1882 | * as the entry vector. |
| 1883 | */ |
| 1884 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1885 | 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] | 1886 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1887 | bfa_ioc_stats(ioc, ioc_boots); |
| 1888 | |
| 1889 | if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK) |
| 1890 | return; |
| 1891 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1892 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1893 | * Initialize IOC state of all functions on a chip reset. |
| 1894 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1895 | if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) { |
| 1896 | writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate); |
| 1897 | writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1898 | } else { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1899 | writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate); |
| 1900 | writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1901 | } |
| 1902 | |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 1903 | bfa_ioc_msgflush(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1904 | bfa_ioc_download_fw(ioc, boot_type, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1905 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1906 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1907 | * Enable interrupts just before starting LPU |
| 1908 | */ |
| 1909 | ioc->cbfn->reset_cbfn(ioc->bfa); |
| 1910 | bfa_ioc_lpu_start(ioc); |
| 1911 | } |
| 1912 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1913 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1914 | * Enable/disable IOC failure auto recovery. |
| 1915 | */ |
| 1916 | void |
| 1917 | bfa_ioc_auto_recover(bfa_boolean_t auto_recover) |
| 1918 | { |
Krishna Gudipati | 2f9b885 | 2010-03-03 17:42:51 -0800 | [diff] [blame] | 1919 | bfa_auto_recover = auto_recover; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1923 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1924 | bfa_boolean_t |
| 1925 | bfa_ioc_is_operational(struct bfa_ioc_s *ioc) |
| 1926 | { |
| 1927 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op); |
| 1928 | } |
| 1929 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1930 | bfa_boolean_t |
| 1931 | bfa_ioc_is_initialized(struct bfa_ioc_s *ioc) |
| 1932 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1933 | u32 r32 = readl(ioc->ioc_regs.ioc_fwstate); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1934 | |
| 1935 | return ((r32 != BFI_IOC_UNINIT) && |
| 1936 | (r32 != BFI_IOC_INITING) && |
| 1937 | (r32 != BFI_IOC_MEMTEST)); |
| 1938 | } |
| 1939 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1940 | bfa_boolean_t |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1941 | bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg) |
| 1942 | { |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 1943 | __be32 *msgp = mbmsg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1944 | u32 r32; |
| 1945 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1946 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1947 | r32 = readl(ioc->ioc_regs.lpu_mbox_cmd); |
| 1948 | if ((r32 & 1) == 0) |
| 1949 | return BFA_FALSE; |
| 1950 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1951 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1952 | * read the MBOX msg |
| 1953 | */ |
| 1954 | for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32)); |
| 1955 | i++) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1956 | r32 = readl(ioc->ioc_regs.lpu_mbox + |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1957 | i * sizeof(u32)); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1958 | msgp[i] = cpu_to_be32(r32); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1959 | } |
| 1960 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1961 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1962 | * turn off mailbox interrupt by clearing mailbox status |
| 1963 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1964 | writel(1, ioc->ioc_regs.lpu_mbox_cmd); |
| 1965 | readl(ioc->ioc_regs.lpu_mbox_cmd); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 1966 | |
| 1967 | return BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
| 1970 | void |
| 1971 | bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m) |
| 1972 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1973 | union bfi_ioc_i2h_msg_u *msg; |
| 1974 | struct bfa_iocpf_s *iocpf = &ioc->iocpf; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1975 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1976 | msg = (union bfi_ioc_i2h_msg_u *) m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1977 | |
| 1978 | bfa_ioc_stats(ioc, ioc_isrs); |
| 1979 | |
| 1980 | switch (msg->mh.msg_id) { |
| 1981 | case BFI_IOC_I2H_HBEAT: |
| 1982 | break; |
| 1983 | |
| 1984 | case BFI_IOC_I2H_READY_EVENT: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1985 | bfa_fsm_send_event(iocpf, IOCPF_E_FWREADY); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1986 | break; |
| 1987 | |
| 1988 | case BFI_IOC_I2H_ENABLE_REPLY: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1989 | bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1990 | break; |
| 1991 | |
| 1992 | case BFI_IOC_I2H_DISABLE_REPLY: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1993 | bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1994 | break; |
| 1995 | |
| 1996 | case BFI_IOC_I2H_GETATTR_REPLY: |
| 1997 | bfa_ioc_getattr_reply(ioc); |
| 1998 | break; |
| 1999 | |
| 2000 | default: |
| 2001 | bfa_trc(ioc, msg->mh.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2002 | WARN_ON(1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2003 | } |
| 2004 | } |
| 2005 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2006 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2007 | * IOC attach time initialization and setup. |
| 2008 | * |
| 2009 | * @param[in] ioc memory for IOC |
| 2010 | * @param[in] bfa driver instance structure |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2011 | */ |
| 2012 | void |
| 2013 | 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] | 2014 | struct bfa_timer_mod_s *timer_mod) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2015 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2016 | ioc->bfa = bfa; |
| 2017 | ioc->cbfn = cbfn; |
| 2018 | ioc->timer_mod = timer_mod; |
| 2019 | ioc->fcmode = BFA_FALSE; |
| 2020 | ioc->pllinit = BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2021 | ioc->dbg_fwsave_once = BFA_TRUE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2022 | ioc->iocpf.ioc = ioc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2023 | |
| 2024 | bfa_ioc_mbox_attach(ioc); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 2025 | INIT_LIST_HEAD(&ioc->notify_q); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2026 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2027 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
| 2028 | bfa_fsm_send_event(ioc, IOC_E_RESET); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2031 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2032 | * Driver detach time IOC cleanup. |
| 2033 | */ |
| 2034 | void |
| 2035 | bfa_ioc_detach(struct bfa_ioc_s *ioc) |
| 2036 | { |
| 2037 | bfa_fsm_send_event(ioc, IOC_E_DETACH); |
| 2038 | } |
| 2039 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2040 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2041 | * Setup IOC PCI properties. |
| 2042 | * |
| 2043 | * @param[in] pcidev PCI device information for this IOC |
| 2044 | */ |
| 2045 | void |
| 2046 | 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] | 2047 | enum bfi_pcifn_class clscode) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2048 | { |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 2049 | ioc->clscode = clscode; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2050 | ioc->pcidev = *pcidev; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2051 | |
| 2052 | /* |
| 2053 | * Initialize IOC and device personality |
| 2054 | */ |
| 2055 | ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC; |
| 2056 | ioc->asic_mode = BFI_ASIC_MODE_FC; |
| 2057 | |
| 2058 | switch (pcidev->device_id) { |
| 2059 | case BFA_PCI_DEVICE_ID_FC_8G1P: |
| 2060 | case BFA_PCI_DEVICE_ID_FC_8G2P: |
| 2061 | ioc->asic_gen = BFI_ASIC_GEN_CB; |
| 2062 | break; |
| 2063 | |
| 2064 | case BFA_PCI_DEVICE_ID_CT: |
| 2065 | ioc->asic_gen = BFI_ASIC_GEN_CT; |
| 2066 | ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH; |
| 2067 | ioc->asic_mode = BFI_ASIC_MODE_ETH; |
| 2068 | break; |
| 2069 | |
| 2070 | case BFA_PCI_DEVICE_ID_CT_FC: |
| 2071 | ioc->asic_gen = BFI_ASIC_GEN_CT; |
| 2072 | break; |
| 2073 | |
| 2074 | case BFA_PCI_DEVICE_ID_CT2: |
| 2075 | ioc->asic_gen = BFI_ASIC_GEN_CT2; |
| 2076 | if (clscode == BFI_PCIFN_CLASS_FC) |
| 2077 | ioc->asic_mode = BFI_ASIC_MODE_FC16; |
| 2078 | else { |
| 2079 | ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH; |
| 2080 | ioc->asic_mode = BFI_ASIC_MODE_ETH; |
| 2081 | } |
| 2082 | break; |
| 2083 | |
| 2084 | default: |
| 2085 | WARN_ON(1); |
| 2086 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2087 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2088 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2089 | * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c |
| 2090 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2091 | if (ioc->asic_gen == BFI_ASIC_GEN_CB) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2092 | bfa_ioc_set_cb_hwif(ioc); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2093 | else if (ioc->asic_gen == BFI_ASIC_GEN_CT) |
| 2094 | bfa_ioc_set_ct_hwif(ioc); |
| 2095 | else { |
| 2096 | WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2); |
| 2097 | bfa_ioc_set_ct2_hwif(ioc); |
| 2098 | bfa_ioc_ct2_poweron(ioc); |
| 2099 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2100 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2101 | bfa_ioc_map_port(ioc); |
| 2102 | bfa_ioc_reg_init(ioc); |
| 2103 | } |
| 2104 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2105 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2106 | * Initialize IOC dma memory |
| 2107 | * |
| 2108 | * @param[in] dm_kva kernel virtual address of IOC dma memory |
| 2109 | * @param[in] dm_pa physical address of IOC dma memory |
| 2110 | */ |
| 2111 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2112 | 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] | 2113 | { |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2114 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2115 | * dma memory for firmware attribute |
| 2116 | */ |
| 2117 | ioc->attr_dma.kva = dm_kva; |
| 2118 | ioc->attr_dma.pa = dm_pa; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2119 | ioc->attr = (struct bfi_ioc_attr_s *) dm_kva; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2122 | void |
| 2123 | bfa_ioc_enable(struct bfa_ioc_s *ioc) |
| 2124 | { |
| 2125 | bfa_ioc_stats(ioc, ioc_enables); |
| 2126 | ioc->dbg_fwsave_once = BFA_TRUE; |
| 2127 | |
| 2128 | bfa_fsm_send_event(ioc, IOC_E_ENABLE); |
| 2129 | } |
| 2130 | |
| 2131 | void |
| 2132 | bfa_ioc_disable(struct bfa_ioc_s *ioc) |
| 2133 | { |
| 2134 | bfa_ioc_stats(ioc, ioc_disables); |
| 2135 | bfa_fsm_send_event(ioc, IOC_E_DISABLE); |
| 2136 | } |
| 2137 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2138 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2139 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2140 | * Initialize memory for saving firmware trace. Driver must initialize |
| 2141 | * trace memory before call bfa_ioc_enable(). |
| 2142 | */ |
| 2143 | void |
| 2144 | bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave) |
| 2145 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2146 | ioc->dbg_fwsave = dbg_fwsave; |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 2147 | 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] | 2148 | } |
| 2149 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2150 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2151 | * Register mailbox message handler functions |
| 2152 | * |
| 2153 | * @param[in] ioc IOC instance |
| 2154 | * @param[in] mcfuncs message class handler functions |
| 2155 | */ |
| 2156 | void |
| 2157 | bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs) |
| 2158 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2159 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2160 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2161 | |
| 2162 | for (mc = 0; mc < BFI_MC_MAX; mc++) |
| 2163 | mod->mbhdlr[mc].cbfn = mcfuncs[mc]; |
| 2164 | } |
| 2165 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2166 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2167 | * Register mailbox message handler function, to be called by common modules |
| 2168 | */ |
| 2169 | void |
| 2170 | bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc, |
| 2171 | bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg) |
| 2172 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2173 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2174 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2175 | mod->mbhdlr[mc].cbfn = cbfn; |
| 2176 | mod->mbhdlr[mc].cbarg = cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2177 | } |
| 2178 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2179 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2180 | * Queue a mailbox command request to firmware. Waits if mailbox is busy. |
| 2181 | * Responsibility of caller to serialize |
| 2182 | * |
| 2183 | * @param[in] ioc IOC instance |
| 2184 | * @param[i] cmd Mailbox command |
| 2185 | */ |
| 2186 | void |
| 2187 | bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd) |
| 2188 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2189 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2190 | u32 stat; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2191 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2192 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2193 | * If a previous command is pending, queue new command |
| 2194 | */ |
| 2195 | if (!list_empty(&mod->cmd_q)) { |
| 2196 | list_add_tail(&cmd->qe, &mod->cmd_q); |
| 2197 | return; |
| 2198 | } |
| 2199 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2200 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2201 | * If mailbox is busy, queue command for poll timer |
| 2202 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2203 | stat = readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2204 | if (stat) { |
| 2205 | list_add_tail(&cmd->qe, &mod->cmd_q); |
| 2206 | return; |
| 2207 | } |
| 2208 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2209 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2210 | * mailbox is free -- queue command to firmware |
| 2211 | */ |
| 2212 | bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); |
| 2213 | } |
| 2214 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2215 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2216 | * Handle mailbox interrupts |
| 2217 | */ |
| 2218 | void |
| 2219 | bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc) |
| 2220 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2221 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2222 | struct bfi_mbmsg_s m; |
| 2223 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2224 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2225 | if (!bfa_ioc_msgget(ioc, &m)) |
| 2226 | return; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2227 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2228 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2229 | * Treat IOC message class as special. |
| 2230 | */ |
| 2231 | mc = m.mh.msg_class; |
| 2232 | if (mc == BFI_MC_IOC) { |
| 2233 | bfa_ioc_isr(ioc, &m); |
| 2234 | return; |
| 2235 | } |
| 2236 | |
| 2237 | if ((mc > BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL)) |
| 2238 | return; |
| 2239 | |
| 2240 | mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m); |
| 2241 | } |
| 2242 | |
| 2243 | void |
| 2244 | bfa_ioc_error_isr(struct bfa_ioc_s *ioc) |
| 2245 | { |
| 2246 | bfa_fsm_send_event(ioc, IOC_E_HWERROR); |
| 2247 | } |
| 2248 | |
Jing Huang | ed96932 | 2010-07-08 19:45:56 -0700 | [diff] [blame] | 2249 | void |
| 2250 | bfa_ioc_set_fcmode(struct bfa_ioc_s *ioc) |
| 2251 | { |
| 2252 | ioc->fcmode = BFA_TRUE; |
Jing Huang | ed96932 | 2010-07-08 19:45:56 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2255 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2256 | * return true if IOC is disabled |
| 2257 | */ |
| 2258 | bfa_boolean_t |
| 2259 | bfa_ioc_is_disabled(struct bfa_ioc_s *ioc) |
| 2260 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2261 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) || |
| 2262 | bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2265 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2266 | * return true if IOC firmware is different. |
| 2267 | */ |
| 2268 | bfa_boolean_t |
| 2269 | bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc) |
| 2270 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2271 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) || |
| 2272 | bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) || |
| 2273 | bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | #define bfa_ioc_state_disabled(__sm) \ |
| 2277 | (((__sm) == BFI_IOC_UNINIT) || \ |
| 2278 | ((__sm) == BFI_IOC_INITING) || \ |
| 2279 | ((__sm) == BFI_IOC_HWINIT) || \ |
| 2280 | ((__sm) == BFI_IOC_DISABLED) || \ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2281 | ((__sm) == BFI_IOC_FAIL) || \ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2282 | ((__sm) == BFI_IOC_CFG_DISABLED)) |
| 2283 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2284 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2285 | * Check if adapter is disabled -- both IOCs should be in a disabled |
| 2286 | * state. |
| 2287 | */ |
| 2288 | bfa_boolean_t |
| 2289 | bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc) |
| 2290 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2291 | u32 ioc_state; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2292 | |
| 2293 | if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled)) |
| 2294 | return BFA_FALSE; |
| 2295 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2296 | ioc_state = readl(ioc->ioc_regs.ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2297 | if (!bfa_ioc_state_disabled(ioc_state)) |
| 2298 | return BFA_FALSE; |
| 2299 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2300 | if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2301 | ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2302 | if (!bfa_ioc_state_disabled(ioc_state)) |
| 2303 | return BFA_FALSE; |
| 2304 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2305 | |
| 2306 | return BFA_TRUE; |
| 2307 | } |
| 2308 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 2309 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 2310 | * Reset IOC fwstate registers. |
| 2311 | */ |
| 2312 | void |
| 2313 | bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc) |
| 2314 | { |
| 2315 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate); |
| 2316 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate); |
| 2317 | } |
| 2318 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2319 | #define BFA_MFG_NAME "Brocade" |
| 2320 | void |
| 2321 | bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc, |
| 2322 | struct bfa_adapter_attr_s *ad_attr) |
| 2323 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2324 | struct bfi_ioc_attr_s *ioc_attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2325 | |
| 2326 | ioc_attr = ioc->attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2327 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2328 | bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num); |
| 2329 | bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver); |
| 2330 | bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver); |
| 2331 | bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2332 | memcpy(&ad_attr->vpd, &ioc_attr->vpd, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2333 | sizeof(struct bfa_mfg_vpd_s)); |
| 2334 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2335 | ad_attr->nports = bfa_ioc_get_nports(ioc); |
| 2336 | ad_attr->max_speed = bfa_ioc_speed_sup(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2337 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2338 | bfa_ioc_get_adapter_model(ioc, ad_attr->model); |
| 2339 | /* For now, model descr uses same model string */ |
| 2340 | bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2341 | |
Jing Huang | ed96932 | 2010-07-08 19:45:56 -0700 | [diff] [blame] | 2342 | ad_attr->card_type = ioc_attr->card_type; |
| 2343 | ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type); |
| 2344 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2345 | if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop)) |
| 2346 | ad_attr->prototype = 1; |
| 2347 | else |
| 2348 | ad_attr->prototype = 0; |
| 2349 | |
Maggie Zhang | f7f7381 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 2350 | ad_attr->pwwn = ioc->attr->pwwn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2351 | ad_attr->mac = bfa_ioc_get_mac(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2352 | |
| 2353 | ad_attr->pcie_gen = ioc_attr->pcie_gen; |
| 2354 | ad_attr->pcie_lanes = ioc_attr->pcie_lanes; |
| 2355 | ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig; |
| 2356 | ad_attr->asic_rev = ioc_attr->asic_rev; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2357 | |
| 2358 | bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2359 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2360 | ad_attr->cna_capable = bfa_ioc_is_cna(ioc); |
| 2361 | ad_attr->trunk_capable = (ad_attr->nports > 1) && |
| 2362 | !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2363 | } |
| 2364 | |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2365 | enum bfa_ioc_type_e |
| 2366 | bfa_ioc_get_type(struct bfa_ioc_s *ioc) |
| 2367 | { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2368 | enum bfi_port_mode mode; |
| 2369 | |
| 2370 | if (ioc->clscode == BFI_PCIFN_CLASS_ETH) |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2371 | return BFA_IOC_TYPE_LL; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2372 | |
| 2373 | WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC); |
| 2374 | |
| 2375 | mode = (ioc->port_id == 0) ? ioc->port0_mode : ioc->port1_mode; |
| 2376 | return (mode == BFI_PORT_MODE_FC) |
| 2377 | ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE; |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2378 | } |
| 2379 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2380 | void |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2381 | bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num) |
| 2382 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2383 | memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN); |
| 2384 | memcpy((void *)serial_num, |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2385 | (void *)ioc->attr->brcd_serialnum, |
| 2386 | BFA_ADAPTER_SERIAL_NUM_LEN); |
| 2387 | } |
| 2388 | |
| 2389 | void |
| 2390 | bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver) |
| 2391 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2392 | memset((void *)fw_ver, 0, BFA_VERSION_LEN); |
| 2393 | memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2394 | } |
| 2395 | |
| 2396 | void |
| 2397 | bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev) |
| 2398 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2399 | WARN_ON(!chip_rev); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2400 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2401 | memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2402 | |
| 2403 | chip_rev[0] = 'R'; |
| 2404 | chip_rev[1] = 'e'; |
| 2405 | chip_rev[2] = 'v'; |
| 2406 | chip_rev[3] = '-'; |
| 2407 | chip_rev[4] = ioc->attr->asic_rev; |
| 2408 | chip_rev[5] = '\0'; |
| 2409 | } |
| 2410 | |
| 2411 | void |
| 2412 | bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver) |
| 2413 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2414 | memset((void *)optrom_ver, 0, BFA_VERSION_LEN); |
| 2415 | memcpy(optrom_ver, ioc->attr->optrom_version, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2416 | BFA_VERSION_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2417 | } |
| 2418 | |
| 2419 | void |
| 2420 | bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer) |
| 2421 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2422 | memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN); |
| 2423 | memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | void |
| 2427 | bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model) |
| 2428 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2429 | struct bfi_ioc_attr_s *ioc_attr; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2430 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2431 | WARN_ON(!model); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2432 | memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2433 | |
| 2434 | ioc_attr = ioc->attr; |
| 2435 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2436 | /* |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2437 | * model name |
| 2438 | */ |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2439 | snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u", |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2440 | BFA_MFG_NAME, ioc_attr->card_type); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2441 | } |
| 2442 | |
| 2443 | enum bfa_ioc_state |
| 2444 | bfa_ioc_get_state(struct bfa_ioc_s *ioc) |
| 2445 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2446 | enum bfa_iocpf_state iocpf_st; |
| 2447 | enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm); |
| 2448 | |
| 2449 | if (ioc_st == BFA_IOC_ENABLING || |
| 2450 | ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) { |
| 2451 | |
| 2452 | iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm); |
| 2453 | |
| 2454 | switch (iocpf_st) { |
| 2455 | case BFA_IOCPF_SEMWAIT: |
| 2456 | ioc_st = BFA_IOC_SEMWAIT; |
| 2457 | break; |
| 2458 | |
| 2459 | case BFA_IOCPF_HWINIT: |
| 2460 | ioc_st = BFA_IOC_HWINIT; |
| 2461 | break; |
| 2462 | |
| 2463 | case BFA_IOCPF_FWMISMATCH: |
| 2464 | ioc_st = BFA_IOC_FWMISMATCH; |
| 2465 | break; |
| 2466 | |
| 2467 | case BFA_IOCPF_FAIL: |
| 2468 | ioc_st = BFA_IOC_FAIL; |
| 2469 | break; |
| 2470 | |
| 2471 | case BFA_IOCPF_INITFAIL: |
| 2472 | ioc_st = BFA_IOC_INITFAIL; |
| 2473 | break; |
| 2474 | |
| 2475 | default: |
| 2476 | break; |
| 2477 | } |
| 2478 | } |
| 2479 | |
| 2480 | return ioc_st; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | void |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2484 | bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr) |
| 2485 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2486 | memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2487 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2488 | ioc_attr->state = bfa_ioc_get_state(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2489 | ioc_attr->port_id = ioc->port_id; |
| 2490 | |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2491 | ioc_attr->ioc_type = bfa_ioc_get_type(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2492 | |
| 2493 | bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr); |
| 2494 | |
| 2495 | ioc_attr->pci_attr.device_id = ioc->pcidev.device_id; |
| 2496 | ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2497 | 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] | 2498 | } |
| 2499 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2500 | mac_t |
| 2501 | bfa_ioc_get_mac(struct bfa_ioc_s *ioc) |
| 2502 | { |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2503 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2504 | * Check the IOC type and return the appropriate MAC |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2505 | */ |
| 2506 | if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2507 | return ioc->attr->fcoe_mac; |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2508 | else |
| 2509 | return ioc->attr->mac; |
| 2510 | } |
| 2511 | |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2512 | mac_t |
| 2513 | bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc) |
| 2514 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2515 | mac_t m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2516 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2517 | m = ioc->attr->mfg_mac; |
| 2518 | if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type)) |
| 2519 | m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc); |
| 2520 | else |
| 2521 | bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]), |
| 2522 | bfa_ioc_pcifn(ioc)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2523 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2524 | return m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2527 | bfa_boolean_t |
| 2528 | bfa_ioc_get_fcmode(struct bfa_ioc_s *ioc) |
| 2529 | { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame^] | 2530 | return ioc->fcmode || bfa_asic_id_cb(ioc->pcidev.device_id); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2533 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2534 | * Retrieve saved firmware trace from a prior IOC failure. |
| 2535 | */ |
| 2536 | bfa_status_t |
| 2537 | bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen) |
| 2538 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2539 | int tlen; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2540 | |
| 2541 | if (ioc->dbg_fwsave_len == 0) |
| 2542 | return BFA_STATUS_ENOFSAVE; |
| 2543 | |
| 2544 | tlen = *trclen; |
| 2545 | if (tlen > ioc->dbg_fwsave_len) |
| 2546 | tlen = ioc->dbg_fwsave_len; |
| 2547 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2548 | memcpy(trcdata, ioc->dbg_fwsave, tlen); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2549 | *trclen = tlen; |
| 2550 | return BFA_STATUS_OK; |
| 2551 | } |
| 2552 | |
Krishna Gudipati | 738c9e6 | 2010-03-05 19:36:19 -0800 | [diff] [blame] | 2553 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2554 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2555 | * Retrieve saved firmware trace from a prior IOC failure. |
| 2556 | */ |
| 2557 | bfa_status_t |
| 2558 | bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen) |
| 2559 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2560 | u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc)); |
| 2561 | int tlen; |
| 2562 | bfa_status_t status; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2563 | |
| 2564 | bfa_trc(ioc, *trclen); |
| 2565 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2566 | tlen = *trclen; |
| 2567 | if (tlen > BFA_DBG_FWTRC_LEN) |
| 2568 | tlen = BFA_DBG_FWTRC_LEN; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2569 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2570 | status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen); |
| 2571 | *trclen = tlen; |
| 2572 | return status; |
| 2573 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2574 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2575 | static void |
| 2576 | bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc) |
| 2577 | { |
| 2578 | struct bfa_mbox_cmd_s cmd; |
| 2579 | 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] | 2580 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2581 | bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC, |
| 2582 | bfa_ioc_portid(ioc)); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 2583 | req->clscode = cpu_to_be16(ioc->clscode); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2584 | bfa_ioc_mbox_queue(ioc, &cmd); |
| 2585 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2586 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2587 | static void |
| 2588 | bfa_ioc_fwsync(struct bfa_ioc_s *ioc) |
| 2589 | { |
| 2590 | u32 fwsync_iter = 1000; |
| 2591 | |
| 2592 | bfa_ioc_send_fwsync(ioc); |
| 2593 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2594 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2595 | * After sending a fw sync mbox command wait for it to |
| 2596 | * take effect. We will not wait for a response because |
| 2597 | * 1. fw_sync mbox cmd doesn't have a response. |
| 2598 | * 2. Even if we implement that, interrupts might not |
| 2599 | * be enabled when we call this function. |
| 2600 | * So, just keep checking if any mbox cmd is pending, and |
| 2601 | * after waiting for a reasonable amount of time, go ahead. |
| 2602 | * It is possible that fw has crashed and the mbox command |
| 2603 | * is never acknowledged. |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2604 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2605 | while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0) |
| 2606 | fwsync_iter--; |
| 2607 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2608 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2609 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2610 | * Dump firmware smem |
| 2611 | */ |
| 2612 | bfa_status_t |
| 2613 | bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf, |
| 2614 | u32 *offset, int *buflen) |
| 2615 | { |
| 2616 | u32 loff; |
| 2617 | int dlen; |
| 2618 | bfa_status_t status; |
| 2619 | u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2620 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2621 | if (*offset >= smem_len) { |
| 2622 | *offset = *buflen = 0; |
| 2623 | return BFA_STATUS_EINVAL; |
| 2624 | } |
| 2625 | |
| 2626 | loff = *offset; |
| 2627 | dlen = *buflen; |
| 2628 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2629 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2630 | * First smem read, sync smem before proceeding |
| 2631 | * No need to sync before reading every chunk. |
| 2632 | */ |
| 2633 | if (loff == 0) |
| 2634 | bfa_ioc_fwsync(ioc); |
| 2635 | |
| 2636 | if ((loff + dlen) >= smem_len) |
| 2637 | dlen = smem_len - loff; |
| 2638 | |
| 2639 | status = bfa_ioc_smem_read(ioc, buf, loff, dlen); |
| 2640 | |
| 2641 | if (status != BFA_STATUS_OK) { |
| 2642 | *offset = *buflen = 0; |
| 2643 | return status; |
| 2644 | } |
| 2645 | |
| 2646 | *offset += dlen; |
| 2647 | |
| 2648 | if (*offset >= smem_len) |
| 2649 | *offset = 0; |
| 2650 | |
| 2651 | *buflen = dlen; |
| 2652 | |
| 2653 | return status; |
| 2654 | } |
| 2655 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2656 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2657 | * Firmware statistics |
| 2658 | */ |
| 2659 | bfa_status_t |
| 2660 | bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats) |
| 2661 | { |
| 2662 | u32 loff = BFI_IOC_FWSTATS_OFF + \ |
| 2663 | BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc)); |
| 2664 | int tlen; |
| 2665 | bfa_status_t status; |
| 2666 | |
| 2667 | if (ioc->stats_busy) { |
| 2668 | bfa_trc(ioc, ioc->stats_busy); |
| 2669 | return BFA_STATUS_DEVBUSY; |
| 2670 | } |
| 2671 | ioc->stats_busy = BFA_TRUE; |
| 2672 | |
| 2673 | tlen = sizeof(struct bfa_fw_stats_s); |
| 2674 | status = bfa_ioc_smem_read(ioc, stats, loff, tlen); |
| 2675 | |
| 2676 | ioc->stats_busy = BFA_FALSE; |
| 2677 | return status; |
| 2678 | } |
| 2679 | |
| 2680 | bfa_status_t |
| 2681 | bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc) |
| 2682 | { |
| 2683 | u32 loff = BFI_IOC_FWSTATS_OFF + \ |
| 2684 | BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc)); |
| 2685 | int tlen; |
| 2686 | bfa_status_t status; |
| 2687 | |
| 2688 | if (ioc->stats_busy) { |
| 2689 | bfa_trc(ioc, ioc->stats_busy); |
| 2690 | return BFA_STATUS_DEVBUSY; |
| 2691 | } |
| 2692 | ioc->stats_busy = BFA_TRUE; |
| 2693 | |
| 2694 | tlen = sizeof(struct bfa_fw_stats_s); |
| 2695 | status = bfa_ioc_smem_clr(ioc, loff, tlen); |
| 2696 | |
| 2697 | ioc->stats_busy = BFA_FALSE; |
| 2698 | return status; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2699 | } |
| 2700 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2701 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2702 | * Save firmware trace if configured. |
| 2703 | */ |
| 2704 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 2705 | bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2706 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2707 | int tlen; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2708 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 2709 | if (ioc->dbg_fwsave_once) { |
| 2710 | ioc->dbg_fwsave_once = BFA_FALSE; |
| 2711 | if (ioc->dbg_fwsave_len) { |
| 2712 | tlen = ioc->dbg_fwsave_len; |
| 2713 | bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen); |
| 2714 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2715 | } |
| 2716 | } |
| 2717 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2718 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2719 | * Firmware failure detected. Start recovery actions. |
| 2720 | */ |
| 2721 | static void |
| 2722 | bfa_ioc_recover(struct bfa_ioc_s *ioc) |
| 2723 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2724 | bfa_ioc_stats(ioc, ioc_hbfails); |
| 2725 | bfa_fsm_send_event(ioc, IOC_E_HBFAIL); |
| 2726 | } |
| 2727 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2728 | static void |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 2729 | bfa_ioc_check_attr_wwns(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2730 | { |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 2731 | if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_LL) |
| 2732 | return; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2735 | /* |
Maggie Zhang | df0f193 | 2010-12-09 19:07:46 -0800 | [diff] [blame] | 2736 | * BFA IOC PF private functions |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2737 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2738 | static void |
| 2739 | bfa_iocpf_timeout(void *ioc_arg) |
| 2740 | { |
| 2741 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
| 2742 | |
| 2743 | bfa_trc(ioc, 0); |
| 2744 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT); |
| 2745 | } |
| 2746 | |
| 2747 | static void |
| 2748 | bfa_iocpf_sem_timeout(void *ioc_arg) |
| 2749 | { |
| 2750 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
| 2751 | |
| 2752 | bfa_ioc_hw_sem_get(ioc); |
| 2753 | } |
| 2754 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2755 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2756 | * bfa timer function |
| 2757 | */ |
| 2758 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2759 | bfa_timer_beat(struct bfa_timer_mod_s *mod) |
| 2760 | { |
| 2761 | struct list_head *qh = &mod->timer_q; |
| 2762 | struct list_head *qe, *qe_next; |
| 2763 | struct bfa_timer_s *elem; |
| 2764 | struct list_head timedout_q; |
| 2765 | |
| 2766 | INIT_LIST_HEAD(&timedout_q); |
| 2767 | |
| 2768 | qe = bfa_q_next(qh); |
| 2769 | |
| 2770 | while (qe != qh) { |
| 2771 | qe_next = bfa_q_next(qe); |
| 2772 | |
| 2773 | elem = (struct bfa_timer_s *) qe; |
| 2774 | if (elem->timeout <= BFA_TIMER_FREQ) { |
| 2775 | elem->timeout = 0; |
| 2776 | list_del(&elem->qe); |
| 2777 | list_add_tail(&elem->qe, &timedout_q); |
| 2778 | } else { |
| 2779 | elem->timeout -= BFA_TIMER_FREQ; |
| 2780 | } |
| 2781 | |
| 2782 | qe = qe_next; /* go to next elem */ |
| 2783 | } |
| 2784 | |
| 2785 | /* |
| 2786 | * Pop all the timeout entries |
| 2787 | */ |
| 2788 | while (!list_empty(&timedout_q)) { |
| 2789 | bfa_q_deq(&timedout_q, &elem); |
| 2790 | elem->timercb(elem->arg); |
| 2791 | } |
| 2792 | } |
| 2793 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2794 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2795 | * Should be called with lock protection |
| 2796 | */ |
| 2797 | void |
| 2798 | bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer, |
| 2799 | void (*timercb) (void *), void *arg, unsigned int timeout) |
| 2800 | { |
| 2801 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2802 | WARN_ON(timercb == NULL); |
| 2803 | WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2804 | |
| 2805 | timer->timeout = timeout; |
| 2806 | timer->timercb = timercb; |
| 2807 | timer->arg = arg; |
| 2808 | |
| 2809 | list_add_tail(&timer->qe, &mod->timer_q); |
| 2810 | } |
| 2811 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2812 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2813 | * Should be called with lock protection |
| 2814 | */ |
| 2815 | void |
| 2816 | bfa_timer_stop(struct bfa_timer_s *timer) |
| 2817 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2818 | WARN_ON(list_empty(&timer->qe)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2819 | |
| 2820 | list_del(&timer->qe); |
| 2821 | } |