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