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