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