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 | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 19 | #include "bfad_im.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 20 | #include "bfa_ioc.h" |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 21 | #include "bfi_reg.h" |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 22 | #include "bfa_defs.h" |
| 23 | #include "bfa_defs_svc.h" |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 24 | |
Krishna Gudipati | 7af074d | 2010-03-05 19:35:45 -0800 | [diff] [blame] | 25 | BFA_TRC_FILE(CNA, IOC); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 26 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 27 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 28 | * IOC local definitions |
| 29 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 30 | #define BFA_IOC_TOV 3000 /* msecs */ |
| 31 | #define BFA_IOC_HWSEM_TOV 500 /* msecs */ |
| 32 | #define BFA_IOC_HB_TOV 500 /* msecs */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 33 | #define BFA_IOC_TOV_RECOVER BFA_IOC_HB_TOV |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 34 | #define BFA_IOC_POLL_TOV BFA_TIMER_FREQ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 35 | |
| 36 | #define bfa_ioc_timer_start(__ioc) \ |
| 37 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \ |
| 38 | bfa_ioc_timeout, (__ioc), BFA_IOC_TOV) |
| 39 | #define bfa_ioc_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer) |
| 40 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 41 | #define bfa_hb_timer_start(__ioc) \ |
| 42 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->hb_timer, \ |
| 43 | bfa_ioc_hb_check, (__ioc), BFA_IOC_HB_TOV) |
| 44 | #define bfa_hb_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->hb_timer) |
| 45 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 46 | #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] | 47 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 48 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 49 | * Asic specific macros : see bfa_hw_cb.c and bfa_hw_ct.c for details. |
| 50 | */ |
| 51 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 52 | #define bfa_ioc_firmware_lock(__ioc) \ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 53 | ((__ioc)->ioc_hwif->ioc_firmware_lock(__ioc)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 54 | #define bfa_ioc_firmware_unlock(__ioc) \ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 55 | ((__ioc)->ioc_hwif->ioc_firmware_unlock(__ioc)) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 56 | #define bfa_ioc_reg_init(__ioc) ((__ioc)->ioc_hwif->ioc_reg_init(__ioc)) |
| 57 | #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] | 58 | #define bfa_ioc_notify_fail(__ioc) \ |
| 59 | ((__ioc)->ioc_hwif->ioc_notify_fail(__ioc)) |
Jing Huang | 45d7f0c | 2011-04-13 11:45:53 -0700 | [diff] [blame] | 60 | #define bfa_ioc_sync_start(__ioc) \ |
| 61 | ((__ioc)->ioc_hwif->ioc_sync_start(__ioc)) |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 62 | #define bfa_ioc_sync_join(__ioc) \ |
| 63 | ((__ioc)->ioc_hwif->ioc_sync_join(__ioc)) |
| 64 | #define bfa_ioc_sync_leave(__ioc) \ |
| 65 | ((__ioc)->ioc_hwif->ioc_sync_leave(__ioc)) |
| 66 | #define bfa_ioc_sync_ack(__ioc) \ |
| 67 | ((__ioc)->ioc_hwif->ioc_sync_ack(__ioc)) |
| 68 | #define bfa_ioc_sync_complete(__ioc) \ |
| 69 | ((__ioc)->ioc_hwif->ioc_sync_complete(__ioc)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 70 | |
| 71 | #define bfa_ioc_mbox_cmd_pending(__ioc) \ |
| 72 | (!list_empty(&((__ioc)->mbox_mod.cmd_q)) || \ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 73 | readl((__ioc)->ioc_regs.hfn_mbox_cmd)) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 74 | |
| 75 | bfa_boolean_t bfa_auto_recover = BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * forward declarations |
| 79 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 80 | static void bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 81 | static void bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force); |
| 82 | static void bfa_ioc_timeout(void *ioc); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 83 | static void bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 84 | static void bfa_ioc_send_enable(struct bfa_ioc_s *ioc); |
| 85 | static void bfa_ioc_send_disable(struct bfa_ioc_s *ioc); |
| 86 | static void bfa_ioc_send_getattr(struct bfa_ioc_s *ioc); |
| 87 | static void bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 88 | static void bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc); |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 89 | static void bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 90 | static void bfa_ioc_recover(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_fail_notify(struct bfa_ioc_s *ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 96 | static void bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 97 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 98 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 99 | * IOC state machine definitions/declarations |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 100 | */ |
| 101 | enum ioc_event { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 102 | IOC_E_RESET = 1, /* IOC reset request */ |
| 103 | IOC_E_ENABLE = 2, /* IOC enable request */ |
| 104 | IOC_E_DISABLE = 3, /* IOC disable request */ |
| 105 | IOC_E_DETACH = 4, /* driver detach cleanup */ |
| 106 | IOC_E_ENABLED = 5, /* f/w enabled */ |
| 107 | IOC_E_FWRSP_GETATTR = 6, /* IOC get attribute response */ |
| 108 | IOC_E_DISABLED = 7, /* f/w disabled */ |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 109 | IOC_E_PFFAILED = 8, /* failure notice by iocpf sm */ |
| 110 | IOC_E_HBFAIL = 9, /* heartbeat failure */ |
| 111 | IOC_E_HWERROR = 10, /* hardware error interrupt */ |
| 112 | IOC_E_TIMEOUT = 11, /* timeout */ |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 113 | IOC_E_HWFAILED = 12, /* PCI mapping failure notice */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 114 | }; |
| 115 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 116 | 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] | 117 | 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] | 118 | bfa_fsm_state_decl(bfa_ioc, enabling, struct bfa_ioc_s, enum ioc_event); |
| 119 | bfa_fsm_state_decl(bfa_ioc, getattr, struct bfa_ioc_s, enum ioc_event); |
| 120 | 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] | 121 | 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] | 122 | 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] | 123 | bfa_fsm_state_decl(bfa_ioc, disabling, struct bfa_ioc_s, enum ioc_event); |
| 124 | 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] | 125 | bfa_fsm_state_decl(bfa_ioc, hwfail, struct bfa_ioc_s, enum ioc_event); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 126 | |
| 127 | static struct bfa_sm_table_s ioc_sm_table[] = { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 128 | {BFA_SM(bfa_ioc_sm_uninit), BFA_IOC_UNINIT}, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 129 | {BFA_SM(bfa_ioc_sm_reset), BFA_IOC_RESET}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 130 | {BFA_SM(bfa_ioc_sm_enabling), BFA_IOC_ENABLING}, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 131 | {BFA_SM(bfa_ioc_sm_getattr), BFA_IOC_GETATTR}, |
| 132 | {BFA_SM(bfa_ioc_sm_op), BFA_IOC_OPERATIONAL}, |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 133 | {BFA_SM(bfa_ioc_sm_fail_retry), BFA_IOC_INITFAIL}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 134 | {BFA_SM(bfa_ioc_sm_fail), BFA_IOC_FAIL}, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 135 | {BFA_SM(bfa_ioc_sm_disabling), BFA_IOC_DISABLING}, |
| 136 | {BFA_SM(bfa_ioc_sm_disabled), BFA_IOC_DISABLED}, |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 137 | {BFA_SM(bfa_ioc_sm_hwfail), BFA_IOC_HWFAIL}, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 140 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 141 | * IOCPF state machine definitions/declarations |
| 142 | */ |
| 143 | |
| 144 | #define bfa_iocpf_timer_start(__ioc) \ |
| 145 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \ |
| 146 | bfa_iocpf_timeout, (__ioc), BFA_IOC_TOV) |
| 147 | #define bfa_iocpf_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->ioc_timer) |
| 148 | |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 149 | #define bfa_iocpf_poll_timer_start(__ioc) \ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 150 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->ioc_timer, \ |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 151 | bfa_iocpf_poll_timeout, (__ioc), BFA_IOC_POLL_TOV) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 152 | |
| 153 | #define bfa_sem_timer_start(__ioc) \ |
| 154 | bfa_timer_begin((__ioc)->timer_mod, &(__ioc)->sem_timer, \ |
| 155 | bfa_iocpf_sem_timeout, (__ioc), BFA_IOC_HWSEM_TOV) |
| 156 | #define bfa_sem_timer_stop(__ioc) bfa_timer_stop(&(__ioc)->sem_timer) |
| 157 | |
| 158 | /* |
| 159 | * Forward declareations for iocpf state machine |
| 160 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 161 | static void bfa_iocpf_timeout(void *ioc_arg); |
| 162 | static void bfa_iocpf_sem_timeout(void *ioc_arg); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 163 | static void bfa_iocpf_poll_timeout(void *ioc_arg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 164 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 165 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 166 | * IOCPF state machine events |
| 167 | */ |
| 168 | enum iocpf_event { |
| 169 | IOCPF_E_ENABLE = 1, /* IOCPF enable request */ |
| 170 | IOCPF_E_DISABLE = 2, /* IOCPF disable request */ |
| 171 | IOCPF_E_STOP = 3, /* stop on driver detach */ |
| 172 | IOCPF_E_FWREADY = 4, /* f/w initialization done */ |
| 173 | IOCPF_E_FWRSP_ENABLE = 5, /* enable f/w response */ |
| 174 | IOCPF_E_FWRSP_DISABLE = 6, /* disable f/w response */ |
| 175 | IOCPF_E_FAIL = 7, /* failure notice by ioc sm */ |
| 176 | IOCPF_E_INITFAIL = 8, /* init fail notice by ioc sm */ |
| 177 | IOCPF_E_GETATTRFAIL = 9, /* init fail notice by ioc sm */ |
| 178 | IOCPF_E_SEMLOCKED = 10, /* h/w semaphore is locked */ |
| 179 | IOCPF_E_TIMEOUT = 11, /* f/w response timeout */ |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 180 | IOCPF_E_SEM_ERROR = 12, /* h/w sem mapping error */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 183 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 184 | * IOCPF states |
| 185 | */ |
| 186 | enum bfa_iocpf_state { |
| 187 | BFA_IOCPF_RESET = 1, /* IOC is in reset state */ |
| 188 | BFA_IOCPF_SEMWAIT = 2, /* Waiting for IOC h/w semaphore */ |
| 189 | BFA_IOCPF_HWINIT = 3, /* IOC h/w is being initialized */ |
| 190 | BFA_IOCPF_READY = 4, /* IOCPF is initialized */ |
| 191 | BFA_IOCPF_INITFAIL = 5, /* IOCPF failed */ |
| 192 | BFA_IOCPF_FAIL = 6, /* IOCPF failed */ |
| 193 | BFA_IOCPF_DISABLING = 7, /* IOCPF is being disabled */ |
| 194 | BFA_IOCPF_DISABLED = 8, /* IOCPF is disabled */ |
| 195 | BFA_IOCPF_FWMISMATCH = 9, /* IOC f/w different from drivers */ |
| 196 | }; |
| 197 | |
| 198 | bfa_fsm_state_decl(bfa_iocpf, reset, struct bfa_iocpf_s, enum iocpf_event); |
| 199 | bfa_fsm_state_decl(bfa_iocpf, fwcheck, struct bfa_iocpf_s, enum iocpf_event); |
| 200 | bfa_fsm_state_decl(bfa_iocpf, mismatch, struct bfa_iocpf_s, enum iocpf_event); |
| 201 | bfa_fsm_state_decl(bfa_iocpf, semwait, struct bfa_iocpf_s, enum iocpf_event); |
| 202 | bfa_fsm_state_decl(bfa_iocpf, hwinit, struct bfa_iocpf_s, enum iocpf_event); |
| 203 | bfa_fsm_state_decl(bfa_iocpf, enabling, struct bfa_iocpf_s, enum iocpf_event); |
| 204 | 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] | 205 | bfa_fsm_state_decl(bfa_iocpf, initfail_sync, struct bfa_iocpf_s, |
| 206 | enum iocpf_event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 207 | 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] | 208 | 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] | 209 | bfa_fsm_state_decl(bfa_iocpf, fail, struct bfa_iocpf_s, enum iocpf_event); |
| 210 | 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] | 211 | bfa_fsm_state_decl(bfa_iocpf, disabling_sync, struct bfa_iocpf_s, |
| 212 | enum iocpf_event); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 213 | bfa_fsm_state_decl(bfa_iocpf, disabled, struct bfa_iocpf_s, enum iocpf_event); |
| 214 | |
| 215 | static struct bfa_sm_table_s iocpf_sm_table[] = { |
| 216 | {BFA_SM(bfa_iocpf_sm_reset), BFA_IOCPF_RESET}, |
| 217 | {BFA_SM(bfa_iocpf_sm_fwcheck), BFA_IOCPF_FWMISMATCH}, |
| 218 | {BFA_SM(bfa_iocpf_sm_mismatch), BFA_IOCPF_FWMISMATCH}, |
| 219 | {BFA_SM(bfa_iocpf_sm_semwait), BFA_IOCPF_SEMWAIT}, |
| 220 | {BFA_SM(bfa_iocpf_sm_hwinit), BFA_IOCPF_HWINIT}, |
| 221 | {BFA_SM(bfa_iocpf_sm_enabling), BFA_IOCPF_HWINIT}, |
| 222 | {BFA_SM(bfa_iocpf_sm_ready), BFA_IOCPF_READY}, |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 223 | {BFA_SM(bfa_iocpf_sm_initfail_sync), BFA_IOCPF_INITFAIL}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 224 | {BFA_SM(bfa_iocpf_sm_initfail), BFA_IOCPF_INITFAIL}, |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 225 | {BFA_SM(bfa_iocpf_sm_fail_sync), BFA_IOCPF_FAIL}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 226 | {BFA_SM(bfa_iocpf_sm_fail), BFA_IOCPF_FAIL}, |
| 227 | {BFA_SM(bfa_iocpf_sm_disabling), BFA_IOCPF_DISABLING}, |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 228 | {BFA_SM(bfa_iocpf_sm_disabling_sync), BFA_IOCPF_DISABLING}, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 229 | {BFA_SM(bfa_iocpf_sm_disabled), BFA_IOCPF_DISABLED}, |
| 230 | }; |
| 231 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 232 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 233 | * IOC State Machine |
| 234 | */ |
| 235 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 236 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 237 | * Beginning state. IOC uninit state. |
| 238 | */ |
| 239 | |
| 240 | static void |
| 241 | bfa_ioc_sm_uninit_entry(struct bfa_ioc_s *ioc) |
| 242 | { |
| 243 | } |
| 244 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 245 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 246 | * IOC is in uninit state. |
| 247 | */ |
| 248 | static void |
| 249 | bfa_ioc_sm_uninit(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 250 | { |
| 251 | bfa_trc(ioc, event); |
| 252 | |
| 253 | switch (event) { |
| 254 | case IOC_E_RESET: |
| 255 | bfa_fsm_set_state(ioc, bfa_ioc_sm_reset); |
| 256 | break; |
| 257 | |
| 258 | default: |
| 259 | bfa_sm_fault(ioc, event); |
| 260 | } |
| 261 | } |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 262 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 263 | * Reset entry actions -- initialize state machine |
| 264 | */ |
| 265 | static void |
| 266 | bfa_ioc_sm_reset_entry(struct bfa_ioc_s *ioc) |
| 267 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 268 | bfa_fsm_set_state(&ioc->iocpf, bfa_iocpf_sm_reset); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 271 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 272 | * IOC is in reset state. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 273 | */ |
| 274 | static void |
| 275 | bfa_ioc_sm_reset(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 276 | { |
| 277 | bfa_trc(ioc, event); |
| 278 | |
| 279 | switch (event) { |
| 280 | case IOC_E_ENABLE: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 281 | bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling); |
| 282 | break; |
| 283 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 284 | case IOC_E_DISABLE: |
| 285 | bfa_ioc_disable_comp(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 286 | break; |
| 287 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 288 | case IOC_E_DETACH: |
| 289 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 290 | break; |
| 291 | |
| 292 | default: |
| 293 | bfa_sm_fault(ioc, event); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | |
| 298 | static void |
| 299 | bfa_ioc_sm_enabling_entry(struct bfa_ioc_s *ioc) |
| 300 | { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 301 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_ENABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 304 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 305 | * Host IOC function is being enabled, awaiting response from firmware. |
| 306 | * Semaphore is acquired. |
| 307 | */ |
| 308 | static void |
| 309 | bfa_ioc_sm_enabling(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 310 | { |
| 311 | bfa_trc(ioc, event); |
| 312 | |
| 313 | switch (event) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 314 | case IOC_E_ENABLED: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 315 | bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr); |
| 316 | break; |
| 317 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 318 | case IOC_E_PFFAILED: |
| 319 | /* !!! fall through !!! */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 320 | case IOC_E_HWERROR: |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 321 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 322 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 323 | if (event != IOC_E_PFFAILED) |
| 324 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 325 | break; |
| 326 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 327 | case IOC_E_HWFAILED: |
| 328 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
| 329 | bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail); |
| 330 | break; |
| 331 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 332 | case IOC_E_DISABLE: |
| 333 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
| 334 | break; |
| 335 | |
| 336 | case IOC_E_DETACH: |
| 337 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 338 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 339 | break; |
| 340 | |
| 341 | case IOC_E_ENABLE: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 342 | break; |
| 343 | |
| 344 | default: |
| 345 | bfa_sm_fault(ioc, event); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | |
| 350 | static void |
| 351 | bfa_ioc_sm_getattr_entry(struct bfa_ioc_s *ioc) |
| 352 | { |
| 353 | bfa_ioc_timer_start(ioc); |
| 354 | bfa_ioc_send_getattr(ioc); |
| 355 | } |
| 356 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 357 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 358 | * IOC configuration in progress. Timer is active. |
| 359 | */ |
| 360 | static void |
| 361 | bfa_ioc_sm_getattr(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 362 | { |
| 363 | bfa_trc(ioc, event); |
| 364 | |
| 365 | switch (event) { |
| 366 | case IOC_E_FWRSP_GETATTR: |
| 367 | bfa_ioc_timer_stop(ioc); |
| 368 | bfa_fsm_set_state(ioc, bfa_ioc_sm_op); |
| 369 | break; |
| 370 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 371 | case IOC_E_PFFAILED: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 372 | case IOC_E_HWERROR: |
| 373 | bfa_ioc_timer_stop(ioc); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 374 | /* !!! fall through !!! */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 375 | case IOC_E_TIMEOUT: |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 376 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 377 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 378 | if (event != IOC_E_PFFAILED) |
| 379 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_GETATTRFAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 380 | break; |
| 381 | |
| 382 | case IOC_E_DISABLE: |
| 383 | bfa_ioc_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 384 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
| 385 | break; |
| 386 | |
| 387 | case IOC_E_ENABLE: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 388 | break; |
| 389 | |
| 390 | default: |
| 391 | bfa_sm_fault(ioc, event); |
| 392 | } |
| 393 | } |
| 394 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 395 | static void |
| 396 | bfa_ioc_sm_op_entry(struct bfa_ioc_s *ioc) |
| 397 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 398 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
| 399 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 400 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_OK); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 401 | bfa_ioc_event_notify(ioc, BFA_IOC_E_ENABLED); |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 402 | bfa_ioc_hb_monitor(ioc); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 403 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC enabled\n"); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 404 | bfa_ioc_aen_post(ioc, BFA_IOC_AEN_ENABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | static void |
| 408 | bfa_ioc_sm_op(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 409 | { |
| 410 | bfa_trc(ioc, event); |
| 411 | |
| 412 | switch (event) { |
| 413 | case IOC_E_ENABLE: |
| 414 | break; |
| 415 | |
| 416 | case IOC_E_DISABLE: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 417 | bfa_hb_timer_stop(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 418 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
| 419 | break; |
| 420 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 421 | case IOC_E_PFFAILED: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 422 | case IOC_E_HWERROR: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 423 | bfa_hb_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 424 | /* !!! fall through !!! */ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 425 | case IOC_E_HBFAIL: |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 426 | if (ioc->iocpf.auto_recover) |
| 427 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail_retry); |
| 428 | else |
| 429 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail); |
| 430 | |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 431 | bfa_ioc_fail_notify(ioc); |
| 432 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 433 | if (event != IOC_E_PFFAILED) |
| 434 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 435 | break; |
| 436 | |
| 437 | default: |
| 438 | bfa_sm_fault(ioc, event); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | |
| 443 | static void |
| 444 | bfa_ioc_sm_disabling_entry(struct bfa_ioc_s *ioc) |
| 445 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 446 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 447 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_DISABLE); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 448 | BFA_LOG(KERN_INFO, bfad, bfa_log_level, "IOC disabled\n"); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 449 | bfa_ioc_aen_post(ioc, BFA_IOC_AEN_DISABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 450 | } |
| 451 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 452 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 453 | * IOC is being disabled |
| 454 | */ |
| 455 | static void |
| 456 | bfa_ioc_sm_disabling(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 457 | { |
| 458 | bfa_trc(ioc, event); |
| 459 | |
| 460 | switch (event) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 461 | case IOC_E_DISABLED: |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 462 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabled); |
| 463 | break; |
| 464 | |
| 465 | case IOC_E_HWERROR: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 466 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 467 | * No state change. Will move to disabled state |
| 468 | * after iocpf sm completes failure processing and |
| 469 | * moves to disabled state. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 470 | */ |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 471 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FAIL); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 472 | break; |
| 473 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 474 | case IOC_E_HWFAILED: |
| 475 | bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail); |
| 476 | bfa_ioc_disable_comp(ioc); |
| 477 | break; |
| 478 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 479 | default: |
| 480 | bfa_sm_fault(ioc, event); |
| 481 | } |
| 482 | } |
| 483 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 484 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 485 | * IOC disable completion entry. |
| 486 | */ |
| 487 | static void |
| 488 | bfa_ioc_sm_disabled_entry(struct bfa_ioc_s *ioc) |
| 489 | { |
| 490 | bfa_ioc_disable_comp(ioc); |
| 491 | } |
| 492 | |
| 493 | static void |
| 494 | bfa_ioc_sm_disabled(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 495 | { |
| 496 | bfa_trc(ioc, event); |
| 497 | |
| 498 | switch (event) { |
| 499 | case IOC_E_ENABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 500 | bfa_fsm_set_state(ioc, bfa_ioc_sm_enabling); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 501 | break; |
| 502 | |
| 503 | case IOC_E_DISABLE: |
| 504 | ioc->cbfn->disable_cbfn(ioc->bfa); |
| 505 | break; |
| 506 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 507 | case IOC_E_DETACH: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 508 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 509 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 510 | break; |
| 511 | |
| 512 | default: |
| 513 | bfa_sm_fault(ioc, event); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | |
| 518 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 519 | bfa_ioc_sm_fail_retry_entry(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 520 | { |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 521 | bfa_trc(ioc, 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 522 | } |
| 523 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 524 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 525 | * Hardware initialization retry. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 526 | */ |
| 527 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 528 | 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] | 529 | { |
| 530 | bfa_trc(ioc, event); |
| 531 | |
| 532 | switch (event) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 533 | case IOC_E_ENABLED: |
| 534 | bfa_fsm_set_state(ioc, bfa_ioc_sm_getattr); |
| 535 | break; |
| 536 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 537 | case IOC_E_PFFAILED: |
| 538 | case IOC_E_HWERROR: |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 539 | /* |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 540 | * Initialization retry failed. |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 541 | */ |
| 542 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 543 | bfa_fsm_set_state(ioc, bfa_ioc_sm_fail); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 544 | if (event != IOC_E_PFFAILED) |
| 545 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_INITFAIL); |
| 546 | break; |
| 547 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 548 | case IOC_E_HWFAILED: |
| 549 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
| 550 | bfa_fsm_set_state(ioc, bfa_ioc_sm_hwfail); |
| 551 | break; |
| 552 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 553 | case IOC_E_ENABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 554 | break; |
| 555 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 556 | case IOC_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 557 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 558 | break; |
| 559 | |
| 560 | case IOC_E_DETACH: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 561 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 562 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 563 | break; |
| 564 | |
| 565 | default: |
| 566 | bfa_sm_fault(ioc, event); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | |
| 571 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 572 | bfa_ioc_sm_fail_entry(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 573 | { |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 574 | bfa_trc(ioc, 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 575 | } |
| 576 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 577 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 578 | * IOC failure. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 579 | */ |
| 580 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 581 | 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] | 582 | { |
| 583 | bfa_trc(ioc, event); |
| 584 | |
| 585 | switch (event) { |
| 586 | |
| 587 | case IOC_E_ENABLE: |
| 588 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
| 589 | break; |
| 590 | |
| 591 | case IOC_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 592 | bfa_fsm_set_state(ioc, bfa_ioc_sm_disabling); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 593 | break; |
| 594 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 595 | case IOC_E_DETACH: |
| 596 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
| 597 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_STOP); |
| 598 | break; |
| 599 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 600 | case IOC_E_HWERROR: |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 601 | case IOC_E_HWFAILED: |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 602 | /* |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 603 | * HB failure / HW error notification, ignore. |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 604 | */ |
| 605 | break; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 606 | default: |
| 607 | bfa_sm_fault(ioc, event); |
| 608 | } |
| 609 | } |
| 610 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 611 | static void |
| 612 | bfa_ioc_sm_hwfail_entry(struct bfa_ioc_s *ioc) |
| 613 | { |
| 614 | bfa_trc(ioc, 0); |
| 615 | } |
| 616 | |
| 617 | static void |
| 618 | bfa_ioc_sm_hwfail(struct bfa_ioc_s *ioc, enum ioc_event event) |
| 619 | { |
| 620 | bfa_trc(ioc, event); |
| 621 | |
| 622 | switch (event) { |
| 623 | case IOC_E_ENABLE: |
| 624 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
| 625 | break; |
| 626 | |
| 627 | case IOC_E_DISABLE: |
| 628 | ioc->cbfn->disable_cbfn(ioc->bfa); |
| 629 | break; |
| 630 | |
| 631 | case IOC_E_DETACH: |
| 632 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
| 633 | break; |
| 634 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 635 | case IOC_E_HWERROR: |
| 636 | /* Ignore - already in hwfail state */ |
| 637 | break; |
| 638 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 639 | default: |
| 640 | bfa_sm_fault(ioc, event); |
| 641 | } |
| 642 | } |
| 643 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 644 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 645 | * IOCPF State Machine |
| 646 | */ |
| 647 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 648 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 649 | * Reset entry actions -- initialize state machine |
| 650 | */ |
| 651 | static void |
| 652 | bfa_iocpf_sm_reset_entry(struct bfa_iocpf_s *iocpf) |
| 653 | { |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 654 | iocpf->fw_mismatch_notified = BFA_FALSE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 655 | iocpf->auto_recover = bfa_auto_recover; |
| 656 | } |
| 657 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 658 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 659 | * Beginning state. IOC is in reset state. |
| 660 | */ |
| 661 | static void |
| 662 | bfa_iocpf_sm_reset(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 663 | { |
| 664 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 665 | |
| 666 | bfa_trc(ioc, event); |
| 667 | |
| 668 | switch (event) { |
| 669 | case IOCPF_E_ENABLE: |
| 670 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck); |
| 671 | break; |
| 672 | |
| 673 | case IOCPF_E_STOP: |
| 674 | break; |
| 675 | |
| 676 | default: |
| 677 | bfa_sm_fault(ioc, event); |
| 678 | } |
| 679 | } |
| 680 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 681 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 682 | * Semaphore should be acquired for version check. |
| 683 | */ |
| 684 | static void |
| 685 | bfa_iocpf_sm_fwcheck_entry(struct bfa_iocpf_s *iocpf) |
| 686 | { |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 687 | struct bfi_ioc_image_hdr_s fwhdr; |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 688 | u32 r32, fwstate, pgnum, pgoff, loff = 0; |
| 689 | int i; |
| 690 | |
| 691 | /* |
| 692 | * Spin on init semaphore to serialize. |
| 693 | */ |
| 694 | r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg); |
| 695 | while (r32 & 0x1) { |
| 696 | udelay(20); |
| 697 | r32 = readl(iocpf->ioc->ioc_regs.ioc_init_sem_reg); |
| 698 | } |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 699 | |
| 700 | /* h/w sem init */ |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 701 | fwstate = readl(iocpf->ioc->ioc_regs.ioc_fwstate); |
| 702 | if (fwstate == BFI_IOC_UNINIT) { |
| 703 | writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 704 | goto sem_get; |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 705 | } |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 706 | |
| 707 | bfa_ioc_fwver_get(iocpf->ioc, &fwhdr); |
| 708 | |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 709 | if (swab32(fwhdr.exec) == BFI_FWBOOT_TYPE_NORMAL) { |
| 710 | writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 711 | goto sem_get; |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 712 | } |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 713 | |
| 714 | /* |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 715 | * Clear fwver hdr |
| 716 | */ |
| 717 | pgnum = PSS_SMEM_PGNUM(iocpf->ioc->ioc_regs.smem_pg0, loff); |
| 718 | pgoff = PSS_SMEM_PGOFF(loff); |
| 719 | writel(pgnum, iocpf->ioc->ioc_regs.host_page_num_fn); |
| 720 | |
| 721 | for (i = 0; i < sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32); i++) { |
| 722 | bfa_mem_write(iocpf->ioc->ioc_regs.smem_page_start, loff, 0); |
| 723 | loff += sizeof(u32); |
| 724 | } |
| 725 | |
| 726 | bfa_trc(iocpf->ioc, fwstate); |
| 727 | bfa_trc(iocpf->ioc, swab32(fwhdr.exec)); |
| 728 | writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.ioc_fwstate); |
| 729 | writel(BFI_IOC_UNINIT, iocpf->ioc->ioc_regs.alt_ioc_fwstate); |
| 730 | |
| 731 | /* |
| 732 | * Unlock the hw semaphore. Should be here only once per boot. |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 733 | */ |
Krishna Gudipati | 7ac83b1 | 2012-09-21 17:24:21 -0700 | [diff] [blame^] | 734 | bfa_ioc_ownership_reset(iocpf->ioc); |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 735 | |
| 736 | /* |
| 737 | * unlock init semaphore. |
| 738 | */ |
| 739 | writel(1, iocpf->ioc->ioc_regs.ioc_init_sem_reg); |
| 740 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 741 | sem_get: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 742 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 743 | } |
| 744 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 745 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 746 | * Awaiting h/w semaphore to continue with version check. |
| 747 | */ |
| 748 | static void |
| 749 | bfa_iocpf_sm_fwcheck(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 750 | { |
| 751 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 752 | |
| 753 | bfa_trc(ioc, event); |
| 754 | |
| 755 | switch (event) { |
| 756 | case IOCPF_E_SEMLOCKED: |
| 757 | if (bfa_ioc_firmware_lock(ioc)) { |
Jing Huang | 45d7f0c | 2011-04-13 11:45:53 -0700 | [diff] [blame] | 758 | if (bfa_ioc_sync_start(ioc)) { |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 759 | bfa_ioc_sync_join(ioc); |
| 760 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); |
| 761 | } else { |
| 762 | bfa_ioc_firmware_unlock(ioc); |
| 763 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 764 | bfa_sem_timer_start(ioc); |
| 765 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 766 | } else { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 767 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 768 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_mismatch); |
| 769 | } |
| 770 | break; |
| 771 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 772 | case IOCPF_E_SEM_ERROR: |
| 773 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail); |
| 774 | bfa_fsm_send_event(ioc, IOC_E_HWFAILED); |
| 775 | break; |
| 776 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 777 | case IOCPF_E_DISABLE: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 778 | bfa_sem_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 779 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 780 | bfa_fsm_send_event(ioc, IOC_E_DISABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 781 | break; |
| 782 | |
| 783 | case IOCPF_E_STOP: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 784 | bfa_sem_timer_stop(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 785 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 786 | break; |
| 787 | |
| 788 | default: |
| 789 | bfa_sm_fault(ioc, event); |
| 790 | } |
| 791 | } |
| 792 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 793 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 794 | * Notify enable completion callback. |
| 795 | */ |
| 796 | static void |
| 797 | bfa_iocpf_sm_mismatch_entry(struct bfa_iocpf_s *iocpf) |
| 798 | { |
| 799 | /* |
| 800 | * Call only the first time sm enters fwmismatch state. |
| 801 | */ |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 802 | if (iocpf->fw_mismatch_notified == BFA_FALSE) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 803 | bfa_ioc_pf_fwmismatch(iocpf->ioc); |
| 804 | |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 805 | iocpf->fw_mismatch_notified = BFA_TRUE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 806 | bfa_iocpf_timer_start(iocpf->ioc); |
| 807 | } |
| 808 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 809 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 810 | * Awaiting firmware version match. |
| 811 | */ |
| 812 | static void |
| 813 | bfa_iocpf_sm_mismatch(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 814 | { |
| 815 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 816 | |
| 817 | bfa_trc(ioc, event); |
| 818 | |
| 819 | switch (event) { |
| 820 | case IOCPF_E_TIMEOUT: |
| 821 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fwcheck); |
| 822 | break; |
| 823 | |
| 824 | case IOCPF_E_DISABLE: |
| 825 | bfa_iocpf_timer_stop(ioc); |
| 826 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 827 | bfa_fsm_send_event(ioc, IOC_E_DISABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 828 | break; |
| 829 | |
| 830 | case IOCPF_E_STOP: |
| 831 | bfa_iocpf_timer_stop(ioc); |
| 832 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 833 | break; |
| 834 | |
| 835 | default: |
| 836 | bfa_sm_fault(ioc, event); |
| 837 | } |
| 838 | } |
| 839 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 840 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 841 | * Request for semaphore. |
| 842 | */ |
| 843 | static void |
| 844 | bfa_iocpf_sm_semwait_entry(struct bfa_iocpf_s *iocpf) |
| 845 | { |
| 846 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 847 | } |
| 848 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 849 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 850 | * Awaiting semaphore for h/w initialzation. |
| 851 | */ |
| 852 | static void |
| 853 | bfa_iocpf_sm_semwait(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 854 | { |
| 855 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 856 | |
| 857 | bfa_trc(ioc, event); |
| 858 | |
| 859 | switch (event) { |
| 860 | case IOCPF_E_SEMLOCKED: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 861 | if (bfa_ioc_sync_complete(ioc)) { |
| 862 | bfa_ioc_sync_join(ioc); |
| 863 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); |
| 864 | } else { |
| 865 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 866 | bfa_sem_timer_start(ioc); |
| 867 | } |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 868 | break; |
| 869 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 870 | case IOCPF_E_SEM_ERROR: |
| 871 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail); |
| 872 | bfa_fsm_send_event(ioc, IOC_E_HWFAILED); |
| 873 | break; |
| 874 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 875 | case IOCPF_E_DISABLE: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 876 | bfa_sem_timer_stop(ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 877 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 878 | break; |
| 879 | |
| 880 | default: |
| 881 | bfa_sm_fault(ioc, event); |
| 882 | } |
| 883 | } |
| 884 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 885 | static void |
| 886 | bfa_iocpf_sm_hwinit_entry(struct bfa_iocpf_s *iocpf) |
| 887 | { |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 888 | iocpf->poll_time = 0; |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 889 | bfa_ioc_hwinit(iocpf->ioc, BFA_FALSE); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 892 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 893 | * Hardware is being initialized. Interrupts are enabled. |
| 894 | * Holding hardware semaphore lock. |
| 895 | */ |
| 896 | static void |
| 897 | bfa_iocpf_sm_hwinit(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 898 | { |
| 899 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 900 | |
| 901 | bfa_trc(ioc, event); |
| 902 | |
| 903 | switch (event) { |
| 904 | case IOCPF_E_FWREADY: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 905 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_enabling); |
| 906 | break; |
| 907 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 908 | case IOCPF_E_TIMEOUT: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 909 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 910 | bfa_fsm_send_event(ioc, IOC_E_PFFAILED); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 911 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case IOCPF_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 915 | bfa_iocpf_timer_stop(ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 916 | bfa_ioc_sync_leave(ioc); |
| 917 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 918 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 919 | break; |
| 920 | |
| 921 | default: |
| 922 | bfa_sm_fault(ioc, event); |
| 923 | } |
| 924 | } |
| 925 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 926 | static void |
| 927 | bfa_iocpf_sm_enabling_entry(struct bfa_iocpf_s *iocpf) |
| 928 | { |
| 929 | bfa_iocpf_timer_start(iocpf->ioc); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 930 | /* |
| 931 | * Enable Interrupts before sending fw IOC ENABLE cmd. |
| 932 | */ |
| 933 | iocpf->ioc->cbfn->reset_cbfn(iocpf->ioc->bfa); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 934 | bfa_ioc_send_enable(iocpf->ioc); |
| 935 | } |
| 936 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 937 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 938 | * Host IOC function is being enabled, awaiting response from firmware. |
| 939 | * Semaphore is acquired. |
| 940 | */ |
| 941 | static void |
| 942 | bfa_iocpf_sm_enabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 943 | { |
| 944 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 945 | |
| 946 | bfa_trc(ioc, event); |
| 947 | |
| 948 | switch (event) { |
| 949 | case IOCPF_E_FWRSP_ENABLE: |
| 950 | bfa_iocpf_timer_stop(ioc); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 951 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 952 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_ready); |
| 953 | break; |
| 954 | |
| 955 | case IOCPF_E_INITFAIL: |
| 956 | bfa_iocpf_timer_stop(ioc); |
| 957 | /* |
| 958 | * !!! fall through !!! |
| 959 | */ |
| 960 | |
| 961 | case IOCPF_E_TIMEOUT: |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 962 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 963 | if (event == IOCPF_E_TIMEOUT) |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 964 | bfa_fsm_send_event(ioc, IOC_E_PFFAILED); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 965 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 966 | break; |
| 967 | |
| 968 | case IOCPF_E_DISABLE: |
| 969 | bfa_iocpf_timer_stop(ioc); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 970 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 971 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling); |
| 972 | break; |
| 973 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 974 | default: |
| 975 | bfa_sm_fault(ioc, event); |
| 976 | } |
| 977 | } |
| 978 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 979 | static void |
| 980 | bfa_iocpf_sm_ready_entry(struct bfa_iocpf_s *iocpf) |
| 981 | { |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 982 | bfa_fsm_send_event(iocpf->ioc, IOC_E_ENABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static void |
| 986 | bfa_iocpf_sm_ready(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 987 | { |
| 988 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 989 | |
| 990 | bfa_trc(ioc, event); |
| 991 | |
| 992 | switch (event) { |
| 993 | case IOCPF_E_DISABLE: |
| 994 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling); |
| 995 | break; |
| 996 | |
| 997 | case IOCPF_E_GETATTRFAIL: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 998 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 999 | break; |
| 1000 | |
| 1001 | case IOCPF_E_FAIL: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1002 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1003 | break; |
| 1004 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1005 | default: |
| 1006 | bfa_sm_fault(ioc, event); |
| 1007 | } |
| 1008 | } |
| 1009 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1010 | static void |
| 1011 | bfa_iocpf_sm_disabling_entry(struct bfa_iocpf_s *iocpf) |
| 1012 | { |
| 1013 | bfa_iocpf_timer_start(iocpf->ioc); |
| 1014 | bfa_ioc_send_disable(iocpf->ioc); |
| 1015 | } |
| 1016 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1017 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1018 | * IOC is being disabled |
| 1019 | */ |
| 1020 | static void |
| 1021 | bfa_iocpf_sm_disabling(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1022 | { |
| 1023 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1024 | |
| 1025 | bfa_trc(ioc, event); |
| 1026 | |
| 1027 | switch (event) { |
| 1028 | case IOCPF_E_FWRSP_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1029 | bfa_iocpf_timer_stop(ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1030 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1031 | break; |
| 1032 | |
| 1033 | case IOCPF_E_FAIL: |
| 1034 | bfa_iocpf_timer_stop(ioc); |
| 1035 | /* |
| 1036 | * !!! fall through !!! |
| 1037 | */ |
| 1038 | |
| 1039 | case IOCPF_E_TIMEOUT: |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1040 | writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1041 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1042 | break; |
| 1043 | |
| 1044 | case IOCPF_E_FWRSP_ENABLE: |
| 1045 | break; |
| 1046 | |
| 1047 | default: |
| 1048 | bfa_sm_fault(ioc, event); |
| 1049 | } |
| 1050 | } |
| 1051 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1052 | static void |
| 1053 | bfa_iocpf_sm_disabling_sync_entry(struct bfa_iocpf_s *iocpf) |
| 1054 | { |
| 1055 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 1056 | } |
| 1057 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1058 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1059 | * IOC hb ack request is being removed. |
| 1060 | */ |
| 1061 | static void |
| 1062 | bfa_iocpf_sm_disabling_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1063 | { |
| 1064 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1065 | |
| 1066 | bfa_trc(ioc, event); |
| 1067 | |
| 1068 | switch (event) { |
| 1069 | case IOCPF_E_SEMLOCKED: |
| 1070 | bfa_ioc_sync_leave(ioc); |
| 1071 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1072 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 1073 | break; |
| 1074 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1075 | case IOCPF_E_SEM_ERROR: |
| 1076 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail); |
| 1077 | bfa_fsm_send_event(ioc, IOC_E_HWFAILED); |
| 1078 | break; |
| 1079 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1080 | case IOCPF_E_FAIL: |
| 1081 | break; |
| 1082 | |
| 1083 | default: |
| 1084 | bfa_sm_fault(ioc, event); |
| 1085 | } |
| 1086 | } |
| 1087 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1088 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1089 | * IOC disable completion entry. |
| 1090 | */ |
| 1091 | static void |
| 1092 | bfa_iocpf_sm_disabled_entry(struct bfa_iocpf_s *iocpf) |
| 1093 | { |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 1094 | bfa_ioc_mbox_flush(iocpf->ioc); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1095 | bfa_fsm_send_event(iocpf->ioc, IOC_E_DISABLED); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | static void |
| 1099 | bfa_iocpf_sm_disabled(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1100 | { |
| 1101 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1102 | |
| 1103 | bfa_trc(ioc, event); |
| 1104 | |
| 1105 | switch (event) { |
| 1106 | case IOCPF_E_ENABLE: |
| 1107 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait); |
| 1108 | break; |
| 1109 | |
| 1110 | case IOCPF_E_STOP: |
| 1111 | bfa_ioc_firmware_unlock(ioc); |
| 1112 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 1113 | break; |
| 1114 | |
| 1115 | default: |
| 1116 | bfa_sm_fault(ioc, event); |
| 1117 | } |
| 1118 | } |
| 1119 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1120 | static void |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1121 | bfa_iocpf_sm_initfail_sync_entry(struct bfa_iocpf_s *iocpf) |
| 1122 | { |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1123 | bfa_ioc_debug_save_ftrc(iocpf->ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1124 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 1125 | } |
| 1126 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1127 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1128 | * Hardware initialization failed. |
| 1129 | */ |
| 1130 | static void |
| 1131 | bfa_iocpf_sm_initfail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1132 | { |
| 1133 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1134 | |
| 1135 | bfa_trc(ioc, event); |
| 1136 | |
| 1137 | switch (event) { |
| 1138 | case IOCPF_E_SEMLOCKED: |
| 1139 | bfa_ioc_notify_fail(ioc); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 1140 | bfa_ioc_sync_leave(ioc); |
| 1141 | writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate); |
| 1142 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1143 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_initfail); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1144 | break; |
| 1145 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1146 | case IOCPF_E_SEM_ERROR: |
| 1147 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail); |
| 1148 | bfa_fsm_send_event(ioc, IOC_E_HWFAILED); |
| 1149 | break; |
| 1150 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1151 | case IOCPF_E_DISABLE: |
| 1152 | bfa_sem_timer_stop(ioc); |
| 1153 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
| 1154 | break; |
| 1155 | |
| 1156 | case IOCPF_E_STOP: |
| 1157 | bfa_sem_timer_stop(ioc); |
| 1158 | bfa_ioc_firmware_unlock(ioc); |
| 1159 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 1160 | break; |
| 1161 | |
| 1162 | case IOCPF_E_FAIL: |
| 1163 | break; |
| 1164 | |
| 1165 | default: |
| 1166 | bfa_sm_fault(ioc, event); |
| 1167 | } |
| 1168 | } |
| 1169 | |
| 1170 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1171 | bfa_iocpf_sm_initfail_entry(struct bfa_iocpf_s *iocpf) |
| 1172 | { |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1173 | bfa_trc(iocpf->ioc, 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1176 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1177 | * Hardware initialization failed. |
| 1178 | */ |
| 1179 | static void |
| 1180 | bfa_iocpf_sm_initfail(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1181 | { |
| 1182 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1183 | |
| 1184 | bfa_trc(ioc, event); |
| 1185 | |
| 1186 | switch (event) { |
| 1187 | case IOCPF_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1188 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 1189 | break; |
| 1190 | |
| 1191 | case IOCPF_E_STOP: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1192 | bfa_ioc_firmware_unlock(ioc); |
| 1193 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_reset); |
| 1194 | break; |
| 1195 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1196 | default: |
| 1197 | bfa_sm_fault(ioc, event); |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | static void |
| 1202 | bfa_iocpf_sm_fail_sync_entry(struct bfa_iocpf_s *iocpf) |
| 1203 | { |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1204 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1205 | * Mark IOC as failed in hardware and stop firmware. |
| 1206 | */ |
| 1207 | bfa_ioc_lpu_stop(iocpf->ioc); |
| 1208 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1209 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1210 | * Flush any queued up mailbox requests. |
| 1211 | */ |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 1212 | bfa_ioc_mbox_flush(iocpf->ioc); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1213 | |
| 1214 | bfa_ioc_hw_sem_get(iocpf->ioc); |
| 1215 | } |
| 1216 | |
| 1217 | static void |
| 1218 | bfa_iocpf_sm_fail_sync(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1219 | { |
| 1220 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1221 | |
| 1222 | bfa_trc(ioc, event); |
| 1223 | |
| 1224 | switch (event) { |
| 1225 | case IOCPF_E_SEMLOCKED: |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1226 | bfa_ioc_sync_ack(ioc); |
| 1227 | bfa_ioc_notify_fail(ioc); |
| 1228 | if (!iocpf->auto_recover) { |
| 1229 | bfa_ioc_sync_leave(ioc); |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 1230 | writel(BFI_IOC_FAIL, ioc->ioc_regs.ioc_fwstate); |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1231 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1232 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail); |
| 1233 | } else { |
| 1234 | if (bfa_ioc_sync_complete(ioc)) |
| 1235 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_hwinit); |
| 1236 | else { |
| 1237 | writel(1, ioc->ioc_regs.ioc_sem_reg); |
| 1238 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_semwait); |
| 1239 | } |
| 1240 | } |
| 1241 | break; |
| 1242 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1243 | case IOCPF_E_SEM_ERROR: |
| 1244 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_fail); |
| 1245 | bfa_fsm_send_event(ioc, IOC_E_HWFAILED); |
| 1246 | break; |
| 1247 | |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 1248 | case IOCPF_E_DISABLE: |
| 1249 | bfa_sem_timer_stop(ioc); |
| 1250 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabling_sync); |
| 1251 | break; |
| 1252 | |
| 1253 | case IOCPF_E_FAIL: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1254 | break; |
| 1255 | |
| 1256 | default: |
| 1257 | bfa_sm_fault(ioc, event); |
| 1258 | } |
| 1259 | } |
| 1260 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1261 | static void |
| 1262 | bfa_iocpf_sm_fail_entry(struct bfa_iocpf_s *iocpf) |
| 1263 | { |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1264 | bfa_trc(iocpf->ioc, 0); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1267 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1268 | * IOC is in failed state. |
| 1269 | */ |
| 1270 | static void |
| 1271 | bfa_iocpf_sm_fail(struct bfa_iocpf_s *iocpf, enum iocpf_event event) |
| 1272 | { |
| 1273 | struct bfa_ioc_s *ioc = iocpf->ioc; |
| 1274 | |
| 1275 | bfa_trc(ioc, event); |
| 1276 | |
| 1277 | switch (event) { |
| 1278 | case IOCPF_E_DISABLE: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1279 | bfa_fsm_set_state(iocpf, bfa_iocpf_sm_disabled); |
| 1280 | break; |
| 1281 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1282 | default: |
| 1283 | bfa_sm_fault(ioc, event); |
| 1284 | } |
| 1285 | } |
| 1286 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1287 | /* |
Maggie Zhang | df0f193 | 2010-12-09 19:07:46 -0800 | [diff] [blame] | 1288 | * BFA IOC private functions |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1289 | */ |
| 1290 | |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 1291 | /* |
| 1292 | * Notify common modules registered for notification. |
| 1293 | */ |
| 1294 | static void |
| 1295 | bfa_ioc_event_notify(struct bfa_ioc_s *ioc, enum bfa_ioc_event_e event) |
| 1296 | { |
| 1297 | struct bfa_ioc_notify_s *notify; |
| 1298 | struct list_head *qe; |
| 1299 | |
| 1300 | list_for_each(qe, &ioc->notify_q) { |
| 1301 | notify = (struct bfa_ioc_notify_s *)qe; |
| 1302 | notify->cbfn(notify->cbarg, event); |
| 1303 | } |
| 1304 | } |
| 1305 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1306 | static void |
| 1307 | bfa_ioc_disable_comp(struct bfa_ioc_s *ioc) |
| 1308 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1309 | ioc->cbfn->disable_cbfn(ioc->bfa); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 1310 | bfa_ioc_event_notify(ioc, BFA_IOC_E_DISABLED); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1311 | } |
| 1312 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1313 | bfa_boolean_t |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1314 | bfa_ioc_sem_get(void __iomem *sem_reg) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1315 | { |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1316 | u32 r32; |
| 1317 | int cnt = 0; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1318 | #define BFA_SEM_SPINCNT 3000 |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1319 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1320 | r32 = readl(sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1321 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1322 | while ((r32 & 1) && (cnt < BFA_SEM_SPINCNT)) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1323 | cnt++; |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 1324 | udelay(2); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1325 | r32 = readl(sem_reg); |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1328 | if (!(r32 & 1)) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1329 | return BFA_TRUE; |
| 1330 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1331 | return BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1334 | static void |
| 1335 | bfa_ioc_hw_sem_get(struct bfa_ioc_s *ioc) |
| 1336 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1337 | u32 r32; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1338 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1339 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1340 | * First read to the semaphore register will return 0, subsequent reads |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1341 | * will return 1. Semaphore is released by writing 1 to the register |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1342 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1343 | r32 = readl(ioc->ioc_regs.ioc_sem_reg); |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1344 | if (r32 == ~0) { |
| 1345 | WARN_ON(r32 == ~0); |
| 1346 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEM_ERROR); |
| 1347 | return; |
| 1348 | } |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1349 | if (!(r32 & 1)) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1350 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_SEMLOCKED); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1351 | return; |
| 1352 | } |
| 1353 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1354 | bfa_sem_timer_start(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1355 | } |
| 1356 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1357 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1358 | * Initialize LPU local memory (aka secondary memory / SRAM) |
| 1359 | */ |
| 1360 | static void |
| 1361 | bfa_ioc_lmem_init(struct bfa_ioc_s *ioc) |
| 1362 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1363 | u32 pss_ctl; |
| 1364 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1365 | #define PSS_LMEM_INIT_TIME 10000 |
| 1366 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1367 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1368 | pss_ctl &= ~__PSS_LMEM_RESET; |
| 1369 | pss_ctl |= __PSS_LMEM_INIT_EN; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1370 | |
| 1371 | /* |
| 1372 | * i2c workaround 12.5khz clock |
| 1373 | */ |
| 1374 | pss_ctl |= __PSS_I2C_CLK_DIV(3UL); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1375 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1376 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1377 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1378 | * wait for memory initialization to be complete |
| 1379 | */ |
| 1380 | i = 0; |
| 1381 | do { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1382 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1383 | i++; |
| 1384 | } while (!(pss_ctl & __PSS_LMEM_INIT_DONE) && (i < PSS_LMEM_INIT_TIME)); |
| 1385 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1386 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1387 | * If memory initialization is not successful, IOC timeout will catch |
| 1388 | * such failures. |
| 1389 | */ |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1390 | WARN_ON(!(pss_ctl & __PSS_LMEM_INIT_DONE)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1391 | bfa_trc(ioc, pss_ctl); |
| 1392 | |
| 1393 | pss_ctl &= ~(__PSS_LMEM_INIT_DONE | __PSS_LMEM_INIT_EN); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1394 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1395 | } |
| 1396 | |
| 1397 | static void |
| 1398 | bfa_ioc_lpu_start(struct bfa_ioc_s *ioc) |
| 1399 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1400 | u32 pss_ctl; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1401 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1402 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1403 | * Take processor out of reset. |
| 1404 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1405 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1406 | pss_ctl &= ~__PSS_LPU0_RESET; |
| 1407 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1408 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | static void |
| 1412 | bfa_ioc_lpu_stop(struct bfa_ioc_s *ioc) |
| 1413 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1414 | u32 pss_ctl; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1415 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1416 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1417 | * Put processors in reset. |
| 1418 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1419 | pss_ctl = readl(ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1420 | pss_ctl |= (__PSS_LPU0_RESET | __PSS_LPU1_RESET); |
| 1421 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1422 | writel(pss_ctl, ioc->ioc_regs.pss_ctl_reg); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1423 | } |
| 1424 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1425 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1426 | * Get driver and firmware versions. |
| 1427 | */ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1428 | void |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1429 | bfa_ioc_fwver_get(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr) |
| 1430 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1431 | u32 pgnum, pgoff; |
| 1432 | u32 loff = 0; |
| 1433 | int i; |
| 1434 | u32 *fwsig = (u32 *) fwhdr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1435 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1436 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff); |
| 1437 | pgoff = PSS_SMEM_PGOFF(loff); |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1438 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1439 | |
| 1440 | for (i = 0; i < (sizeof(struct bfi_ioc_image_hdr_s) / sizeof(u32)); |
| 1441 | i++) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1442 | fwsig[i] = |
| 1443 | bfa_mem_read(ioc->ioc_regs.smem_page_start, loff); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1444 | loff += sizeof(u32); |
| 1445 | } |
| 1446 | } |
| 1447 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1448 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1449 | * Returns TRUE if same. |
| 1450 | */ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1451 | bfa_boolean_t |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1452 | bfa_ioc_fwver_cmp(struct bfa_ioc_s *ioc, struct bfi_ioc_image_hdr_s *fwhdr) |
| 1453 | { |
| 1454 | struct bfi_ioc_image_hdr_s *drv_fwhdr; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1455 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1456 | |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 1457 | drv_fwhdr = (struct bfi_ioc_image_hdr_s *) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1458 | bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1459 | |
| 1460 | for (i = 0; i < BFI_IOC_MD5SUM_SZ; i++) { |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1461 | if (fwhdr->md5sum[i] != cpu_to_le32(drv_fwhdr->md5sum[i])) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1462 | bfa_trc(ioc, i); |
| 1463 | bfa_trc(ioc, fwhdr->md5sum[i]); |
| 1464 | bfa_trc(ioc, drv_fwhdr->md5sum[i]); |
| 1465 | return BFA_FALSE; |
| 1466 | } |
| 1467 | } |
| 1468 | |
| 1469 | bfa_trc(ioc, fwhdr->md5sum[0]); |
| 1470 | return BFA_TRUE; |
| 1471 | } |
| 1472 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1473 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1474 | * Return true if current running version is valid. Firmware signature and |
| 1475 | * execution context (driver/bios) must match. |
| 1476 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1477 | static bfa_boolean_t |
| 1478 | bfa_ioc_fwver_valid(struct bfa_ioc_s *ioc, u32 boot_env) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1479 | { |
| 1480 | struct bfi_ioc_image_hdr_s fwhdr, *drv_fwhdr; |
| 1481 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1482 | bfa_ioc_fwver_get(ioc, &fwhdr); |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 1483 | drv_fwhdr = (struct bfi_ioc_image_hdr_s *) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1484 | bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), 0); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1485 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1486 | if (fwhdr.signature != cpu_to_le32(drv_fwhdr->signature)) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1487 | bfa_trc(ioc, fwhdr.signature); |
| 1488 | bfa_trc(ioc, drv_fwhdr->signature); |
| 1489 | return BFA_FALSE; |
| 1490 | } |
| 1491 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1492 | if (swab32(fwhdr.bootenv) != boot_env) { |
| 1493 | bfa_trc(ioc, fwhdr.bootenv); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1494 | bfa_trc(ioc, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1495 | return BFA_FALSE; |
| 1496 | } |
| 1497 | |
| 1498 | return bfa_ioc_fwver_cmp(ioc, &fwhdr); |
| 1499 | } |
| 1500 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1501 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1502 | * Conditionally flush any pending message from firmware at start. |
| 1503 | */ |
| 1504 | static void |
| 1505 | bfa_ioc_msgflush(struct bfa_ioc_s *ioc) |
| 1506 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1507 | u32 r32; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1508 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1509 | r32 = readl(ioc->ioc_regs.lpu_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1510 | if (r32) |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1511 | writel(1, ioc->ioc_regs.lpu_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1514 | static void |
| 1515 | bfa_ioc_hwinit(struct bfa_ioc_s *ioc, bfa_boolean_t force) |
| 1516 | { |
| 1517 | enum bfi_ioc_state ioc_fwstate; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1518 | bfa_boolean_t fwvalid; |
| 1519 | u32 boot_type; |
| 1520 | u32 boot_env; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1521 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1522 | ioc_fwstate = readl(ioc->ioc_regs.ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1523 | |
| 1524 | if (force) |
| 1525 | ioc_fwstate = BFI_IOC_UNINIT; |
| 1526 | |
| 1527 | bfa_trc(ioc, ioc_fwstate); |
| 1528 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1529 | boot_type = BFI_FWBOOT_TYPE_NORMAL; |
| 1530 | boot_env = BFI_FWBOOT_ENV_OS; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1531 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1532 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1533 | * check if firmware is valid |
| 1534 | */ |
| 1535 | fwvalid = (ioc_fwstate == BFI_IOC_UNINIT) ? |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1536 | BFA_FALSE : bfa_ioc_fwver_valid(ioc, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1537 | |
| 1538 | if (!fwvalid) { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1539 | bfa_ioc_boot(ioc, boot_type, boot_env); |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 1540 | bfa_ioc_poll_fwinit(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1541 | return; |
| 1542 | } |
| 1543 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1544 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1545 | * If hardware initialization is in progress (initialized by other IOC), |
| 1546 | * just wait for an initialization completion interrupt. |
| 1547 | */ |
| 1548 | if (ioc_fwstate == BFI_IOC_INITING) { |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 1549 | bfa_ioc_poll_fwinit(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1550 | return; |
| 1551 | } |
| 1552 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1553 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1554 | * If IOC function is disabled and firmware version is same, |
| 1555 | * just re-enable IOC. |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 1556 | * |
| 1557 | * If option rom, IOC must not be in operational state. With |
| 1558 | * convergence, IOC will be in operational state when 2nd driver |
| 1559 | * is loaded. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1560 | */ |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1561 | if (ioc_fwstate == BFI_IOC_DISABLED || ioc_fwstate == BFI_IOC_OP) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1562 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1563 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1564 | * When using MSI-X any pending firmware ready event should |
| 1565 | * be flushed. Otherwise MSI-X interrupts are not delivered. |
| 1566 | */ |
| 1567 | bfa_ioc_msgflush(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1568 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1569 | return; |
| 1570 | } |
| 1571 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1572 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1573 | * Initialize the h/w for any other states. |
| 1574 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1575 | bfa_ioc_boot(ioc, boot_type, boot_env); |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 1576 | bfa_ioc_poll_fwinit(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | static void |
| 1580 | bfa_ioc_timeout(void *ioc_arg) |
| 1581 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1582 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1583 | |
| 1584 | bfa_trc(ioc, 0); |
| 1585 | bfa_fsm_send_event(ioc, IOC_E_TIMEOUT); |
| 1586 | } |
| 1587 | |
| 1588 | void |
| 1589 | bfa_ioc_mbox_send(struct bfa_ioc_s *ioc, void *ioc_msg, int len) |
| 1590 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1591 | u32 *msgp = (u32 *) ioc_msg; |
| 1592 | u32 i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1593 | |
| 1594 | bfa_trc(ioc, msgp[0]); |
| 1595 | bfa_trc(ioc, len); |
| 1596 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 1597 | WARN_ON(len > BFI_IOC_MSGLEN_MAX); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1598 | |
| 1599 | /* |
| 1600 | * first write msg to mailbox registers |
| 1601 | */ |
| 1602 | for (i = 0; i < len / sizeof(u32); i++) |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1603 | writel(cpu_to_le32(msgp[i]), |
| 1604 | ioc->ioc_regs.hfn_mbox + i * sizeof(u32)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1605 | |
| 1606 | for (; i < BFI_IOC_MSGLEN_MAX / sizeof(u32); i++) |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1607 | writel(0, ioc->ioc_regs.hfn_mbox + i * sizeof(u32)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1608 | |
| 1609 | /* |
| 1610 | * write 1 to mailbox CMD to trigger LPU event |
| 1611 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1612 | writel(1, ioc->ioc_regs.hfn_mbox_cmd); |
| 1613 | (void) readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | static void |
| 1617 | bfa_ioc_send_enable(struct bfa_ioc_s *ioc) |
| 1618 | { |
| 1619 | struct bfi_ioc_ctrl_req_s enable_req; |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1620 | struct timeval tv; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1621 | |
| 1622 | bfi_h2i_set(enable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_ENABLE_REQ, |
| 1623 | bfa_ioc_portid(ioc)); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 1624 | enable_req.clscode = cpu_to_be16(ioc->clscode); |
Maggie Zhang | f16a175 | 2010-12-09 19:12:32 -0800 | [diff] [blame] | 1625 | do_gettimeofday(&tv); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1626 | enable_req.tv_sec = be32_to_cpu(tv.tv_sec); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1627 | bfa_ioc_mbox_send(ioc, &enable_req, sizeof(struct bfi_ioc_ctrl_req_s)); |
| 1628 | } |
| 1629 | |
| 1630 | static void |
| 1631 | bfa_ioc_send_disable(struct bfa_ioc_s *ioc) |
| 1632 | { |
| 1633 | struct bfi_ioc_ctrl_req_s disable_req; |
| 1634 | |
| 1635 | bfi_h2i_set(disable_req.mh, BFI_MC_IOC, BFI_IOC_H2I_DISABLE_REQ, |
| 1636 | bfa_ioc_portid(ioc)); |
| 1637 | bfa_ioc_mbox_send(ioc, &disable_req, sizeof(struct bfi_ioc_ctrl_req_s)); |
| 1638 | } |
| 1639 | |
| 1640 | static void |
| 1641 | bfa_ioc_send_getattr(struct bfa_ioc_s *ioc) |
| 1642 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1643 | struct bfi_ioc_getattr_req_s attr_req; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1644 | |
| 1645 | bfi_h2i_set(attr_req.mh, BFI_MC_IOC, BFI_IOC_H2I_GETATTR_REQ, |
| 1646 | bfa_ioc_portid(ioc)); |
| 1647 | bfa_dma_be_addr_set(attr_req.attr_addr, ioc->attr_dma.pa); |
| 1648 | bfa_ioc_mbox_send(ioc, &attr_req, sizeof(attr_req)); |
| 1649 | } |
| 1650 | |
| 1651 | static void |
| 1652 | bfa_ioc_hb_check(void *cbarg) |
| 1653 | { |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1654 | struct bfa_ioc_s *ioc = cbarg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1655 | u32 hb_count; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1656 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1657 | hb_count = readl(ioc->ioc_regs.heartbeat); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1658 | if (ioc->hb_count == hb_count) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1659 | bfa_ioc_recover(ioc); |
| 1660 | return; |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1661 | } else { |
| 1662 | ioc->hb_count = hb_count; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | bfa_ioc_mbox_poll(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1666 | bfa_hb_timer_start(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | static void |
| 1670 | bfa_ioc_hb_monitor(struct bfa_ioc_s *ioc) |
| 1671 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1672 | ioc->hb_count = readl(ioc->ioc_regs.heartbeat); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1673 | bfa_hb_timer_start(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1676 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1677 | * Initiate a full firmware download. |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1678 | */ |
| 1679 | static void |
| 1680 | bfa_ioc_download_fw(struct bfa_ioc_s *ioc, u32 boot_type, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1681 | u32 boot_env) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1682 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1683 | u32 *fwimg; |
| 1684 | u32 pgnum, pgoff; |
| 1685 | u32 loff = 0; |
| 1686 | u32 chunkno = 0; |
| 1687 | u32 i; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1688 | u32 asicmode; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1689 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1690 | bfa_trc(ioc, bfa_cb_image_get_size(bfa_ioc_asic_gen(ioc))); |
| 1691 | fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), chunkno); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1692 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1693 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff); |
| 1694 | pgoff = PSS_SMEM_PGOFF(loff); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1695 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1696 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1697 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1698 | 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] | 1699 | |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1700 | if (BFA_IOC_FLASH_CHUNK_NO(i) != chunkno) { |
| 1701 | chunkno = BFA_IOC_FLASH_CHUNK_NO(i); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1702 | fwimg = bfa_cb_image_get_chunk(bfa_ioc_asic_gen(ioc), |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 1703 | BFA_IOC_FLASH_CHUNK_ADDR(chunkno)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1704 | } |
| 1705 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1706 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1707 | * write smem |
| 1708 | */ |
| 1709 | bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 1710 | cpu_to_le32(fwimg[BFA_IOC_FLASH_OFFSET_IN_CHUNK(i)])); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1711 | |
| 1712 | loff += sizeof(u32); |
| 1713 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1714 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1715 | * handle page offset wrap around |
| 1716 | */ |
| 1717 | loff = PSS_SMEM_PGOFF(loff); |
| 1718 | if (loff == 0) { |
| 1719 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1720 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1721 | } |
| 1722 | } |
| 1723 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1724 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1725 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | 13cc20c | 2010-03-05 19:37:29 -0800 | [diff] [blame] | 1726 | |
| 1727 | /* |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1728 | * Set boot type and device mode at the end. |
| 1729 | */ |
| 1730 | asicmode = BFI_FWBOOT_DEVMODE(ioc->asic_gen, ioc->asic_mode, |
| 1731 | ioc->port0_mode, ioc->port1_mode); |
| 1732 | bfa_mem_write(ioc->ioc_regs.smem_page_start, BFI_FWBOOT_DEVMODE_OFF, |
| 1733 | swab32(asicmode)); |
| 1734 | 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] | 1735 | swab32(boot_type)); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 1736 | 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] | 1737 | swab32(boot_env)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1740 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1741 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1742 | * Update BFA configuration from firmware configuration. |
| 1743 | */ |
| 1744 | static void |
| 1745 | bfa_ioc_getattr_reply(struct bfa_ioc_s *ioc) |
| 1746 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1747 | struct bfi_ioc_attr_s *attr = ioc->attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1748 | |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1749 | attr->adapter_prop = be32_to_cpu(attr->adapter_prop); |
| 1750 | attr->card_type = be32_to_cpu(attr->card_type); |
| 1751 | attr->maxfrsize = be16_to_cpu(attr->maxfrsize); |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1752 | ioc->fcmode = (attr->port_mode == BFI_PORT_MODE_FC); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1753 | |
| 1754 | bfa_fsm_send_event(ioc, IOC_E_FWRSP_GETATTR); |
| 1755 | } |
| 1756 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1757 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1758 | * Attach time initialization of mbox logic. |
| 1759 | */ |
| 1760 | static void |
| 1761 | bfa_ioc_mbox_attach(struct bfa_ioc_s *ioc) |
| 1762 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1763 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1764 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1765 | |
| 1766 | INIT_LIST_HEAD(&mod->cmd_q); |
| 1767 | for (mc = 0; mc < BFI_MC_MAX; mc++) { |
| 1768 | mod->mbhdlr[mc].cbfn = NULL; |
| 1769 | mod->mbhdlr[mc].cbarg = ioc->bfa; |
| 1770 | } |
| 1771 | } |
| 1772 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1773 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1774 | * Mbox poll timer -- restarts any pending mailbox requests. |
| 1775 | */ |
| 1776 | static void |
| 1777 | bfa_ioc_mbox_poll(struct bfa_ioc_s *ioc) |
| 1778 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1779 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1780 | struct bfa_mbox_cmd_s *cmd; |
| 1781 | u32 stat; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1782 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1783 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1784 | * If no command pending, do nothing |
| 1785 | */ |
| 1786 | if (list_empty(&mod->cmd_q)) |
| 1787 | return; |
| 1788 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1789 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1790 | * If previous command is not yet fetched by firmware, do nothing |
| 1791 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1792 | stat = readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1793 | if (stat) |
| 1794 | return; |
| 1795 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1796 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1797 | * Enqueue command to firmware. |
| 1798 | */ |
| 1799 | bfa_q_deq(&mod->cmd_q, &cmd); |
| 1800 | bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); |
| 1801 | } |
| 1802 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1803 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1804 | * Cleanup any pending requests. |
| 1805 | */ |
| 1806 | static void |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 1807 | bfa_ioc_mbox_flush(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1808 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1809 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 1810 | struct bfa_mbox_cmd_s *cmd; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1811 | |
| 1812 | while (!list_empty(&mod->cmd_q)) |
| 1813 | bfa_q_deq(&mod->cmd_q, &cmd); |
| 1814 | } |
| 1815 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1816 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1817 | * Read data from SMEM to host through PCI memmap |
| 1818 | * |
| 1819 | * @param[in] ioc memory for IOC |
| 1820 | * @param[in] tbuf app memory to store data from smem |
| 1821 | * @param[in] soff smem offset |
| 1822 | * @param[in] sz size of smem in bytes |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1823 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1824 | static bfa_status_t |
| 1825 | bfa_ioc_smem_read(struct bfa_ioc_s *ioc, void *tbuf, u32 soff, u32 sz) |
| 1826 | { |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 1827 | u32 pgnum, loff; |
| 1828 | __be32 r32; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1829 | int i, len; |
| 1830 | u32 *buf = tbuf; |
| 1831 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1832 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff); |
| 1833 | loff = PSS_SMEM_PGOFF(soff); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1834 | bfa_trc(ioc, pgnum); |
| 1835 | bfa_trc(ioc, loff); |
| 1836 | bfa_trc(ioc, sz); |
| 1837 | |
| 1838 | /* |
| 1839 | * Hold semaphore to serialize pll init and fwtrc. |
| 1840 | */ |
| 1841 | if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) { |
| 1842 | bfa_trc(ioc, 0); |
| 1843 | return BFA_STATUS_FAILED; |
| 1844 | } |
| 1845 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1846 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1847 | |
| 1848 | len = sz/sizeof(u32); |
| 1849 | bfa_trc(ioc, len); |
| 1850 | for (i = 0; i < len; i++) { |
| 1851 | r32 = bfa_mem_read(ioc->ioc_regs.smem_page_start, loff); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 1852 | buf[i] = be32_to_cpu(r32); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1853 | loff += sizeof(u32); |
| 1854 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1855 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1856 | * handle page offset wrap around |
| 1857 | */ |
| 1858 | loff = PSS_SMEM_PGOFF(loff); |
| 1859 | if (loff == 0) { |
| 1860 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1861 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1862 | } |
| 1863 | } |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1864 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1865 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1866 | /* |
| 1867 | * release semaphore. |
| 1868 | */ |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1869 | readl(ioc->ioc_regs.ioc_init_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1870 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1871 | |
| 1872 | bfa_trc(ioc, pgnum); |
| 1873 | return BFA_STATUS_OK; |
| 1874 | } |
| 1875 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1876 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1877 | * Clear SMEM data from host through PCI memmap |
| 1878 | * |
| 1879 | * @param[in] ioc memory for IOC |
| 1880 | * @param[in] soff smem offset |
| 1881 | * @param[in] sz size of smem in bytes |
| 1882 | */ |
| 1883 | static bfa_status_t |
| 1884 | bfa_ioc_smem_clr(struct bfa_ioc_s *ioc, u32 soff, u32 sz) |
| 1885 | { |
| 1886 | int i, len; |
| 1887 | u32 pgnum, loff; |
| 1888 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1889 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, soff); |
| 1890 | loff = PSS_SMEM_PGOFF(soff); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1891 | bfa_trc(ioc, pgnum); |
| 1892 | bfa_trc(ioc, loff); |
| 1893 | bfa_trc(ioc, sz); |
| 1894 | |
| 1895 | /* |
| 1896 | * Hold semaphore to serialize pll init and fwtrc. |
| 1897 | */ |
| 1898 | if (BFA_FALSE == bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg)) { |
| 1899 | bfa_trc(ioc, 0); |
| 1900 | return BFA_STATUS_FAILED; |
| 1901 | } |
| 1902 | |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1903 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1904 | |
| 1905 | len = sz/sizeof(u32); /* len in words */ |
| 1906 | bfa_trc(ioc, len); |
| 1907 | for (i = 0; i < len; i++) { |
| 1908 | bfa_mem_write(ioc->ioc_regs.smem_page_start, loff, 0); |
| 1909 | loff += sizeof(u32); |
| 1910 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1911 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1912 | * handle page offset wrap around |
| 1913 | */ |
| 1914 | loff = PSS_SMEM_PGOFF(loff); |
| 1915 | if (loff == 0) { |
| 1916 | pgnum++; |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 1917 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1918 | } |
| 1919 | } |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1920 | writel(PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, 0), |
| 1921 | ioc->ioc_regs.host_page_num_fn); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1922 | |
| 1923 | /* |
| 1924 | * release semaphore. |
| 1925 | */ |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1926 | readl(ioc->ioc_regs.ioc_init_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1927 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1928 | bfa_trc(ioc, pgnum); |
| 1929 | return BFA_STATUS_OK; |
| 1930 | } |
| 1931 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1932 | static void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1933 | bfa_ioc_fail_notify(struct bfa_ioc_s *ioc) |
| 1934 | { |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1935 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
| 1936 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 1937 | /* |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1938 | * Notify driver and common modules registered for notification. |
| 1939 | */ |
| 1940 | ioc->cbfn->hbfail_cbfn(ioc->bfa); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 1941 | bfa_ioc_event_notify(ioc, BFA_IOC_E_FAILED); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1942 | |
| 1943 | bfa_ioc_debug_save_ftrc(ioc); |
| 1944 | |
| 1945 | BFA_LOG(KERN_CRIT, bfad, bfa_log_level, |
| 1946 | "Heart Beat of IOC has failed\n"); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 1947 | bfa_ioc_aen_post(ioc, BFA_IOC_AEN_HBFAIL); |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 1948 | |
| 1949 | } |
| 1950 | |
| 1951 | static void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1952 | bfa_ioc_pf_fwmismatch(struct bfa_ioc_s *ioc) |
| 1953 | { |
| 1954 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1955 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1956 | * Provide enable completion callback. |
| 1957 | */ |
| 1958 | ioc->cbfn->enable_cbfn(ioc->bfa, BFA_STATUS_IOC_FAILURE); |
Jing Huang | 8816624 | 2010-12-09 17:11:53 -0800 | [diff] [blame] | 1959 | BFA_LOG(KERN_WARNING, bfad, bfa_log_level, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1960 | "Running firmware version is incompatible " |
| 1961 | "with the driver version\n"); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 1962 | bfa_ioc_aen_post(ioc, BFA_IOC_AEN_FWMISMATCH); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1965 | bfa_status_t |
| 1966 | bfa_ioc_pll_init(struct bfa_ioc_s *ioc) |
| 1967 | { |
| 1968 | |
| 1969 | /* |
| 1970 | * Hold semaphore so that nobody can access the chip during init. |
| 1971 | */ |
| 1972 | bfa_ioc_sem_get(ioc->ioc_regs.ioc_init_sem_reg); |
| 1973 | |
| 1974 | bfa_ioc_pll_init_asic(ioc); |
| 1975 | |
| 1976 | ioc->pllinit = BFA_TRUE; |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 1977 | |
| 1978 | /* |
| 1979 | * Initialize LMEM |
| 1980 | */ |
| 1981 | bfa_ioc_lmem_init(ioc); |
| 1982 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1983 | /* |
| 1984 | * release semaphore. |
| 1985 | */ |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 1986 | readl(ioc->ioc_regs.ioc_init_sem_reg); |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 1987 | writel(1, ioc->ioc_regs.ioc_init_sem_reg); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1988 | |
| 1989 | return BFA_STATUS_OK; |
| 1990 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1991 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 1992 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1993 | * Interface used by diag module to do firmware boot with memory test |
| 1994 | * as the entry vector. |
| 1995 | */ |
| 1996 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 1997 | 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] | 1998 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1999 | bfa_ioc_stats(ioc, ioc_boots); |
| 2000 | |
| 2001 | if (bfa_ioc_pll_init(ioc) != BFA_STATUS_OK) |
| 2002 | return; |
| 2003 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2004 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2005 | * Initialize IOC state of all functions on a chip reset. |
| 2006 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2007 | if (boot_type == BFI_FWBOOT_TYPE_MEMTEST) { |
| 2008 | writel(BFI_IOC_MEMTEST, ioc->ioc_regs.ioc_fwstate); |
| 2009 | writel(BFI_IOC_MEMTEST, ioc->ioc_regs.alt_ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2010 | } else { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2011 | writel(BFI_IOC_INITING, ioc->ioc_regs.ioc_fwstate); |
| 2012 | writel(BFI_IOC_INITING, ioc->ioc_regs.alt_ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2013 | } |
| 2014 | |
Jing Huang | 07b2838 | 2010-07-08 19:59:24 -0700 | [diff] [blame] | 2015 | bfa_ioc_msgflush(ioc); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2016 | bfa_ioc_download_fw(ioc, boot_type, boot_env); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2017 | bfa_ioc_lpu_start(ioc); |
| 2018 | } |
| 2019 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2020 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2021 | * Enable/disable IOC failure auto recovery. |
| 2022 | */ |
| 2023 | void |
| 2024 | bfa_ioc_auto_recover(bfa_boolean_t auto_recover) |
| 2025 | { |
Krishna Gudipati | 2f9b885 | 2010-03-03 17:42:51 -0800 | [diff] [blame] | 2026 | bfa_auto_recover = auto_recover; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2030 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2031 | bfa_boolean_t |
| 2032 | bfa_ioc_is_operational(struct bfa_ioc_s *ioc) |
| 2033 | { |
| 2034 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_op); |
| 2035 | } |
| 2036 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2037 | bfa_boolean_t |
| 2038 | bfa_ioc_is_initialized(struct bfa_ioc_s *ioc) |
| 2039 | { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2040 | u32 r32 = readl(ioc->ioc_regs.ioc_fwstate); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2041 | |
| 2042 | return ((r32 != BFI_IOC_UNINIT) && |
| 2043 | (r32 != BFI_IOC_INITING) && |
| 2044 | (r32 != BFI_IOC_MEMTEST)); |
| 2045 | } |
| 2046 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2047 | bfa_boolean_t |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2048 | bfa_ioc_msgget(struct bfa_ioc_s *ioc, void *mbmsg) |
| 2049 | { |
Maggie | 50444a3 | 2010-11-29 18:26:32 -0800 | [diff] [blame] | 2050 | __be32 *msgp = mbmsg; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2051 | u32 r32; |
| 2052 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2053 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2054 | r32 = readl(ioc->ioc_regs.lpu_mbox_cmd); |
| 2055 | if ((r32 & 1) == 0) |
| 2056 | return BFA_FALSE; |
| 2057 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2058 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2059 | * read the MBOX msg |
| 2060 | */ |
| 2061 | for (i = 0; i < (sizeof(union bfi_ioc_i2h_msg_u) / sizeof(u32)); |
| 2062 | i++) { |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2063 | r32 = readl(ioc->ioc_regs.lpu_mbox + |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2064 | i * sizeof(u32)); |
Jing Huang | ba816ea | 2010-10-18 17:10:50 -0700 | [diff] [blame] | 2065 | msgp[i] = cpu_to_be32(r32); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2068 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2069 | * turn off mailbox interrupt by clearing mailbox status |
| 2070 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2071 | writel(1, ioc->ioc_regs.lpu_mbox_cmd); |
| 2072 | readl(ioc->ioc_regs.lpu_mbox_cmd); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2073 | |
| 2074 | return BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | void |
| 2078 | bfa_ioc_isr(struct bfa_ioc_s *ioc, struct bfi_mbmsg_s *m) |
| 2079 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2080 | union bfi_ioc_i2h_msg_u *msg; |
| 2081 | struct bfa_iocpf_s *iocpf = &ioc->iocpf; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2082 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2083 | msg = (union bfi_ioc_i2h_msg_u *) m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2084 | |
| 2085 | bfa_ioc_stats(ioc, ioc_isrs); |
| 2086 | |
| 2087 | switch (msg->mh.msg_id) { |
| 2088 | case BFI_IOC_I2H_HBEAT: |
| 2089 | break; |
| 2090 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2091 | case BFI_IOC_I2H_ENABLE_REPLY: |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2092 | ioc->port_mode = ioc->port_mode_cfg = |
| 2093 | (enum bfa_mode_s)msg->fw_event.port_mode; |
| 2094 | ioc->ad_cap_bm = msg->fw_event.cap_bm; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2095 | bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_ENABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2096 | break; |
| 2097 | |
| 2098 | case BFI_IOC_I2H_DISABLE_REPLY: |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2099 | bfa_fsm_send_event(iocpf, IOCPF_E_FWRSP_DISABLE); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2100 | break; |
| 2101 | |
| 2102 | case BFI_IOC_I2H_GETATTR_REPLY: |
| 2103 | bfa_ioc_getattr_reply(ioc); |
| 2104 | break; |
| 2105 | |
| 2106 | default: |
| 2107 | bfa_trc(ioc, msg->mh.msg_id); |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2108 | WARN_ON(1); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2109 | } |
| 2110 | } |
| 2111 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2112 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2113 | * IOC attach time initialization and setup. |
| 2114 | * |
| 2115 | * @param[in] ioc memory for IOC |
| 2116 | * @param[in] bfa driver instance structure |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2117 | */ |
| 2118 | void |
| 2119 | 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] | 2120 | struct bfa_timer_mod_s *timer_mod) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2121 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2122 | ioc->bfa = bfa; |
| 2123 | ioc->cbfn = cbfn; |
| 2124 | ioc->timer_mod = timer_mod; |
| 2125 | ioc->fcmode = BFA_FALSE; |
| 2126 | ioc->pllinit = BFA_FALSE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2127 | ioc->dbg_fwsave_once = BFA_TRUE; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2128 | ioc->iocpf.ioc = ioc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2129 | |
| 2130 | bfa_ioc_mbox_attach(ioc); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 2131 | INIT_LIST_HEAD(&ioc->notify_q); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2132 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2133 | bfa_fsm_set_state(ioc, bfa_ioc_sm_uninit); |
| 2134 | bfa_fsm_send_event(ioc, IOC_E_RESET); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2137 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2138 | * Driver detach time IOC cleanup. |
| 2139 | */ |
| 2140 | void |
| 2141 | bfa_ioc_detach(struct bfa_ioc_s *ioc) |
| 2142 | { |
| 2143 | bfa_fsm_send_event(ioc, IOC_E_DETACH); |
Krishna Gudipati | 3350d98 | 2011-06-24 20:28:37 -0700 | [diff] [blame] | 2144 | INIT_LIST_HEAD(&ioc->notify_q); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2145 | } |
| 2146 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2147 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2148 | * Setup IOC PCI properties. |
| 2149 | * |
| 2150 | * @param[in] pcidev PCI device information for this IOC |
| 2151 | */ |
| 2152 | void |
| 2153 | 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] | 2154 | enum bfi_pcifn_class clscode) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2155 | { |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 2156 | ioc->clscode = clscode; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2157 | ioc->pcidev = *pcidev; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2158 | |
| 2159 | /* |
| 2160 | * Initialize IOC and device personality |
| 2161 | */ |
| 2162 | ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_FC; |
| 2163 | ioc->asic_mode = BFI_ASIC_MODE_FC; |
| 2164 | |
| 2165 | switch (pcidev->device_id) { |
| 2166 | case BFA_PCI_DEVICE_ID_FC_8G1P: |
| 2167 | case BFA_PCI_DEVICE_ID_FC_8G2P: |
| 2168 | ioc->asic_gen = BFI_ASIC_GEN_CB; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2169 | ioc->fcmode = BFA_TRUE; |
| 2170 | ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA; |
| 2171 | ioc->ad_cap_bm = BFA_CM_HBA; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2172 | break; |
| 2173 | |
| 2174 | case BFA_PCI_DEVICE_ID_CT: |
| 2175 | ioc->asic_gen = BFI_ASIC_GEN_CT; |
| 2176 | ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH; |
| 2177 | ioc->asic_mode = BFI_ASIC_MODE_ETH; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2178 | ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_CNA; |
| 2179 | ioc->ad_cap_bm = BFA_CM_CNA; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2180 | break; |
| 2181 | |
| 2182 | case BFA_PCI_DEVICE_ID_CT_FC: |
| 2183 | ioc->asic_gen = BFI_ASIC_GEN_CT; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2184 | ioc->fcmode = BFA_TRUE; |
| 2185 | ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA; |
| 2186 | ioc->ad_cap_bm = BFA_CM_HBA; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2187 | break; |
| 2188 | |
| 2189 | case BFA_PCI_DEVICE_ID_CT2: |
| 2190 | ioc->asic_gen = BFI_ASIC_GEN_CT2; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2191 | if (clscode == BFI_PCIFN_CLASS_FC && |
| 2192 | pcidev->ssid == BFA_PCI_CT2_SSID_FC) { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2193 | ioc->asic_mode = BFI_ASIC_MODE_FC16; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2194 | ioc->fcmode = BFA_TRUE; |
| 2195 | ioc->port_mode = ioc->port_mode_cfg = BFA_MODE_HBA; |
| 2196 | ioc->ad_cap_bm = BFA_CM_HBA; |
| 2197 | } else { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2198 | ioc->port0_mode = ioc->port1_mode = BFI_PORT_MODE_ETH; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2199 | ioc->asic_mode = BFI_ASIC_MODE_ETH; |
| 2200 | if (pcidev->ssid == BFA_PCI_CT2_SSID_FCoE) { |
| 2201 | ioc->port_mode = |
| 2202 | ioc->port_mode_cfg = BFA_MODE_CNA; |
| 2203 | ioc->ad_cap_bm = BFA_CM_CNA; |
| 2204 | } else { |
| 2205 | ioc->port_mode = |
| 2206 | ioc->port_mode_cfg = BFA_MODE_NIC; |
| 2207 | ioc->ad_cap_bm = BFA_CM_NIC; |
| 2208 | } |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2209 | } |
| 2210 | break; |
| 2211 | |
| 2212 | default: |
| 2213 | WARN_ON(1); |
| 2214 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2215 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2216 | /* |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2217 | * Set asic specific interfaces. See bfa_ioc_cb.c and bfa_ioc_ct.c |
| 2218 | */ |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2219 | if (ioc->asic_gen == BFI_ASIC_GEN_CB) |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2220 | bfa_ioc_set_cb_hwif(ioc); |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2221 | else if (ioc->asic_gen == BFI_ASIC_GEN_CT) |
| 2222 | bfa_ioc_set_ct_hwif(ioc); |
| 2223 | else { |
| 2224 | WARN_ON(ioc->asic_gen != BFI_ASIC_GEN_CT2); |
| 2225 | bfa_ioc_set_ct2_hwif(ioc); |
| 2226 | bfa_ioc_ct2_poweron(ioc); |
| 2227 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2228 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2229 | bfa_ioc_map_port(ioc); |
| 2230 | bfa_ioc_reg_init(ioc); |
| 2231 | } |
| 2232 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2233 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2234 | * Initialize IOC dma memory |
| 2235 | * |
| 2236 | * @param[in] dm_kva kernel virtual address of IOC dma memory |
| 2237 | * @param[in] dm_pa physical address of IOC dma memory |
| 2238 | */ |
| 2239 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2240 | 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] | 2241 | { |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2242 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2243 | * dma memory for firmware attribute |
| 2244 | */ |
| 2245 | ioc->attr_dma.kva = dm_kva; |
| 2246 | ioc->attr_dma.pa = dm_pa; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2247 | ioc->attr = (struct bfi_ioc_attr_s *) dm_kva; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2248 | } |
| 2249 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2250 | void |
| 2251 | bfa_ioc_enable(struct bfa_ioc_s *ioc) |
| 2252 | { |
| 2253 | bfa_ioc_stats(ioc, ioc_enables); |
| 2254 | ioc->dbg_fwsave_once = BFA_TRUE; |
| 2255 | |
| 2256 | bfa_fsm_send_event(ioc, IOC_E_ENABLE); |
| 2257 | } |
| 2258 | |
| 2259 | void |
| 2260 | bfa_ioc_disable(struct bfa_ioc_s *ioc) |
| 2261 | { |
| 2262 | bfa_ioc_stats(ioc, ioc_disables); |
| 2263 | bfa_fsm_send_event(ioc, IOC_E_DISABLE); |
| 2264 | } |
| 2265 | |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 2266 | void |
| 2267 | bfa_ioc_suspend(struct bfa_ioc_s *ioc) |
| 2268 | { |
| 2269 | ioc->dbg_fwsave_once = BFA_TRUE; |
| 2270 | bfa_fsm_send_event(ioc, IOC_E_HWERROR); |
| 2271 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2272 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2273 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2274 | * Initialize memory for saving firmware trace. Driver must initialize |
| 2275 | * trace memory before call bfa_ioc_enable(). |
| 2276 | */ |
| 2277 | void |
| 2278 | bfa_ioc_debug_memclaim(struct bfa_ioc_s *ioc, void *dbg_fwsave) |
| 2279 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2280 | ioc->dbg_fwsave = dbg_fwsave; |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 2281 | ioc->dbg_fwsave_len = BFA_DBG_FWTRC_LEN; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2282 | } |
| 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 | * Register mailbox message handler functions |
| 2286 | * |
| 2287 | * @param[in] ioc IOC instance |
| 2288 | * @param[in] mcfuncs message class handler functions |
| 2289 | */ |
| 2290 | void |
| 2291 | bfa_ioc_mbox_register(struct bfa_ioc_s *ioc, bfa_ioc_mbox_mcfunc_t *mcfuncs) |
| 2292 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2293 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2294 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2295 | |
| 2296 | for (mc = 0; mc < BFI_MC_MAX; mc++) |
| 2297 | mod->mbhdlr[mc].cbfn = mcfuncs[mc]; |
| 2298 | } |
| 2299 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2300 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2301 | * Register mailbox message handler function, to be called by common modules |
| 2302 | */ |
| 2303 | void |
| 2304 | bfa_ioc_mbox_regisr(struct bfa_ioc_s *ioc, enum bfi_mclass mc, |
| 2305 | bfa_ioc_mbox_mcfunc_t cbfn, void *cbarg) |
| 2306 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2307 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2308 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2309 | mod->mbhdlr[mc].cbfn = cbfn; |
| 2310 | mod->mbhdlr[mc].cbarg = cbarg; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2313 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2314 | * Queue a mailbox command request to firmware. Waits if mailbox is busy. |
| 2315 | * Responsibility of caller to serialize |
| 2316 | * |
| 2317 | * @param[in] ioc IOC instance |
| 2318 | * @param[i] cmd Mailbox command |
| 2319 | */ |
| 2320 | void |
| 2321 | bfa_ioc_mbox_queue(struct bfa_ioc_s *ioc, struct bfa_mbox_cmd_s *cmd) |
| 2322 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2323 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2324 | u32 stat; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2325 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2326 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2327 | * If a previous command is pending, queue new command |
| 2328 | */ |
| 2329 | if (!list_empty(&mod->cmd_q)) { |
| 2330 | list_add_tail(&cmd->qe, &mod->cmd_q); |
| 2331 | return; |
| 2332 | } |
| 2333 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2334 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2335 | * If mailbox is busy, queue command for poll timer |
| 2336 | */ |
Jing Huang | 5344026 | 2010-10-18 17:12:29 -0700 | [diff] [blame] | 2337 | stat = readl(ioc->ioc_regs.hfn_mbox_cmd); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2338 | if (stat) { |
| 2339 | list_add_tail(&cmd->qe, &mod->cmd_q); |
| 2340 | return; |
| 2341 | } |
| 2342 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2343 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2344 | * mailbox is free -- queue command to firmware |
| 2345 | */ |
| 2346 | bfa_ioc_mbox_send(ioc, cmd->msg, sizeof(cmd->msg)); |
| 2347 | } |
| 2348 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2349 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2350 | * Handle mailbox interrupts |
| 2351 | */ |
| 2352 | void |
| 2353 | bfa_ioc_mbox_isr(struct bfa_ioc_s *ioc) |
| 2354 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2355 | struct bfa_ioc_mbox_mod_s *mod = &ioc->mbox_mod; |
| 2356 | struct bfi_mbmsg_s m; |
| 2357 | int mc; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2358 | |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 2359 | if (bfa_ioc_msgget(ioc, &m)) { |
| 2360 | /* |
| 2361 | * Treat IOC message class as special. |
| 2362 | */ |
| 2363 | mc = m.mh.msg_class; |
| 2364 | if (mc == BFI_MC_IOC) { |
| 2365 | bfa_ioc_isr(ioc, &m); |
| 2366 | return; |
| 2367 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2368 | |
Dan Carpenter | fffa692 | 2012-06-27 11:59:36 +0300 | [diff] [blame] | 2369 | if ((mc >= BFI_MC_MAX) || (mod->mbhdlr[mc].cbfn == NULL)) |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 2370 | return; |
| 2371 | |
| 2372 | mod->mbhdlr[mc].cbfn(mod->mbhdlr[mc].cbarg, &m); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 2375 | bfa_ioc_lpu_read_stat(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2376 | |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 2377 | /* |
| 2378 | * Try to send pending mailbox commands |
| 2379 | */ |
| 2380 | bfa_ioc_mbox_poll(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | void |
| 2384 | bfa_ioc_error_isr(struct bfa_ioc_s *ioc) |
| 2385 | { |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 2386 | bfa_ioc_stats(ioc, ioc_hbfails); |
| 2387 | ioc->stats.hb_count = ioc->hb_count; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2388 | bfa_fsm_send_event(ioc, IOC_E_HWERROR); |
| 2389 | } |
| 2390 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2391 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2392 | * return true if IOC is disabled |
| 2393 | */ |
| 2394 | bfa_boolean_t |
| 2395 | bfa_ioc_is_disabled(struct bfa_ioc_s *ioc) |
| 2396 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2397 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabling) || |
| 2398 | bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2399 | } |
| 2400 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2401 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2402 | * return true if IOC firmware is different. |
| 2403 | */ |
| 2404 | bfa_boolean_t |
| 2405 | bfa_ioc_fw_mismatch(struct bfa_ioc_s *ioc) |
| 2406 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2407 | return bfa_fsm_cmp_state(ioc, bfa_ioc_sm_reset) || |
| 2408 | bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_fwcheck) || |
| 2409 | bfa_fsm_cmp_state(&ioc->iocpf, bfa_iocpf_sm_mismatch); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | #define bfa_ioc_state_disabled(__sm) \ |
| 2413 | (((__sm) == BFI_IOC_UNINIT) || \ |
| 2414 | ((__sm) == BFI_IOC_INITING) || \ |
| 2415 | ((__sm) == BFI_IOC_HWINIT) || \ |
| 2416 | ((__sm) == BFI_IOC_DISABLED) || \ |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2417 | ((__sm) == BFI_IOC_FAIL) || \ |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2418 | ((__sm) == BFI_IOC_CFG_DISABLED)) |
| 2419 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2420 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2421 | * Check if adapter is disabled -- both IOCs should be in a disabled |
| 2422 | * state. |
| 2423 | */ |
| 2424 | bfa_boolean_t |
| 2425 | bfa_ioc_adapter_is_disabled(struct bfa_ioc_s *ioc) |
| 2426 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2427 | u32 ioc_state; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2428 | |
| 2429 | if (!bfa_fsm_cmp_state(ioc, bfa_ioc_sm_disabled)) |
| 2430 | return BFA_FALSE; |
| 2431 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2432 | ioc_state = readl(ioc->ioc_regs.ioc_fwstate); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2433 | if (!bfa_ioc_state_disabled(ioc_state)) |
| 2434 | return BFA_FALSE; |
| 2435 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2436 | if (ioc->pcidev.device_id != BFA_PCI_DEVICE_ID_FC_8G1P) { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2437 | ioc_state = readl(ioc->ioc_regs.alt_ioc_fwstate); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2438 | if (!bfa_ioc_state_disabled(ioc_state)) |
| 2439 | return BFA_FALSE; |
| 2440 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2441 | |
| 2442 | return BFA_TRUE; |
| 2443 | } |
| 2444 | |
Jing Huang | 8f4bfad | 2010-12-26 21:50:10 -0800 | [diff] [blame] | 2445 | /* |
Krishna Gudipati | f1d584d | 2010-12-13 16:17:11 -0800 | [diff] [blame] | 2446 | * Reset IOC fwstate registers. |
| 2447 | */ |
| 2448 | void |
| 2449 | bfa_ioc_reset_fwstate(struct bfa_ioc_s *ioc) |
| 2450 | { |
| 2451 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.ioc_fwstate); |
| 2452 | writel(BFI_IOC_UNINIT, ioc->ioc_regs.alt_ioc_fwstate); |
| 2453 | } |
| 2454 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2455 | #define BFA_MFG_NAME "Brocade" |
| 2456 | void |
| 2457 | bfa_ioc_get_adapter_attr(struct bfa_ioc_s *ioc, |
| 2458 | struct bfa_adapter_attr_s *ad_attr) |
| 2459 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2460 | struct bfi_ioc_attr_s *ioc_attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2461 | |
| 2462 | ioc_attr = ioc->attr; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2463 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2464 | bfa_ioc_get_adapter_serial_num(ioc, ad_attr->serial_num); |
| 2465 | bfa_ioc_get_adapter_fw_ver(ioc, ad_attr->fw_ver); |
| 2466 | bfa_ioc_get_adapter_optrom_ver(ioc, ad_attr->optrom_ver); |
| 2467 | bfa_ioc_get_adapter_manufacturer(ioc, ad_attr->manufacturer); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2468 | memcpy(&ad_attr->vpd, &ioc_attr->vpd, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2469 | sizeof(struct bfa_mfg_vpd_s)); |
| 2470 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2471 | ad_attr->nports = bfa_ioc_get_nports(ioc); |
| 2472 | ad_attr->max_speed = bfa_ioc_speed_sup(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2473 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2474 | bfa_ioc_get_adapter_model(ioc, ad_attr->model); |
| 2475 | /* For now, model descr uses same model string */ |
| 2476 | bfa_ioc_get_adapter_model(ioc, ad_attr->model_descr); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2477 | |
Jing Huang | ed96932 | 2010-07-08 19:45:56 -0700 | [diff] [blame] | 2478 | ad_attr->card_type = ioc_attr->card_type; |
| 2479 | ad_attr->is_mezz = bfa_mfg_is_mezz(ioc_attr->card_type); |
| 2480 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2481 | if (BFI_ADAPTER_IS_SPECIAL(ioc_attr->adapter_prop)) |
| 2482 | ad_attr->prototype = 1; |
| 2483 | else |
| 2484 | ad_attr->prototype = 0; |
| 2485 | |
Maggie Zhang | f7f73812 | 2010-12-09 19:08:43 -0800 | [diff] [blame] | 2486 | ad_attr->pwwn = ioc->attr->pwwn; |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2487 | ad_attr->mac = bfa_ioc_get_mac(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2488 | |
| 2489 | ad_attr->pcie_gen = ioc_attr->pcie_gen; |
| 2490 | ad_attr->pcie_lanes = ioc_attr->pcie_lanes; |
| 2491 | ad_attr->pcie_lanes_orig = ioc_attr->pcie_lanes_orig; |
| 2492 | ad_attr->asic_rev = ioc_attr->asic_rev; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2493 | |
| 2494 | bfa_ioc_get_pci_chip_rev(ioc, ad_attr->hw_ver); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2495 | |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2496 | ad_attr->cna_capable = bfa_ioc_is_cna(ioc); |
| 2497 | ad_attr->trunk_capable = (ad_attr->nports > 1) && |
| 2498 | !bfa_ioc_is_cna(ioc) && !ad_attr->is_mezz; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2499 | } |
| 2500 | |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2501 | enum bfa_ioc_type_e |
| 2502 | bfa_ioc_get_type(struct bfa_ioc_s *ioc) |
| 2503 | { |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2504 | if (ioc->clscode == BFI_PCIFN_CLASS_ETH) |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2505 | return BFA_IOC_TYPE_LL; |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2506 | |
| 2507 | WARN_ON(ioc->clscode != BFI_PCIFN_CLASS_FC); |
| 2508 | |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 2509 | return (ioc->attr->port_mode == BFI_PORT_MODE_FC) |
Krishna Gudipati | 1118920 | 2011-06-13 15:50:35 -0700 | [diff] [blame] | 2510 | ? BFA_IOC_TYPE_FC : BFA_IOC_TYPE_FCoE; |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2511 | } |
| 2512 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2513 | void |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2514 | bfa_ioc_get_adapter_serial_num(struct bfa_ioc_s *ioc, char *serial_num) |
| 2515 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2516 | memset((void *)serial_num, 0, BFA_ADAPTER_SERIAL_NUM_LEN); |
| 2517 | memcpy((void *)serial_num, |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2518 | (void *)ioc->attr->brcd_serialnum, |
| 2519 | BFA_ADAPTER_SERIAL_NUM_LEN); |
| 2520 | } |
| 2521 | |
| 2522 | void |
| 2523 | bfa_ioc_get_adapter_fw_ver(struct bfa_ioc_s *ioc, char *fw_ver) |
| 2524 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2525 | memset((void *)fw_ver, 0, BFA_VERSION_LEN); |
| 2526 | memcpy(fw_ver, ioc->attr->fw_version, BFA_VERSION_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2527 | } |
| 2528 | |
| 2529 | void |
| 2530 | bfa_ioc_get_pci_chip_rev(struct bfa_ioc_s *ioc, char *chip_rev) |
| 2531 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2532 | WARN_ON(!chip_rev); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2533 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2534 | memset((void *)chip_rev, 0, BFA_IOC_CHIP_REV_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2535 | |
| 2536 | chip_rev[0] = 'R'; |
| 2537 | chip_rev[1] = 'e'; |
| 2538 | chip_rev[2] = 'v'; |
| 2539 | chip_rev[3] = '-'; |
| 2540 | chip_rev[4] = ioc->attr->asic_rev; |
| 2541 | chip_rev[5] = '\0'; |
| 2542 | } |
| 2543 | |
| 2544 | void |
| 2545 | bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc_s *ioc, char *optrom_ver) |
| 2546 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2547 | memset((void *)optrom_ver, 0, BFA_VERSION_LEN); |
| 2548 | memcpy(optrom_ver, ioc->attr->optrom_version, |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2549 | BFA_VERSION_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | void |
| 2553 | bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer) |
| 2554 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2555 | memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN); |
| 2556 | memcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | void |
| 2560 | bfa_ioc_get_adapter_model(struct bfa_ioc_s *ioc, char *model) |
| 2561 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2562 | struct bfi_ioc_attr_s *ioc_attr; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2563 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2564 | WARN_ON(!model); |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2565 | memset((void *)model, 0, BFA_ADAPTER_MODEL_NAME_LEN); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2566 | |
| 2567 | ioc_attr = ioc->attr; |
| 2568 | |
Krishna Gudipati | 10a0737 | 2011-06-24 20:23:38 -0700 | [diff] [blame] | 2569 | snprintf(model, BFA_ADAPTER_MODEL_NAME_LEN, "%s-%u", |
Krishna Gudipati | 8b070b4 | 2011-06-13 15:52:40 -0700 | [diff] [blame] | 2570 | BFA_MFG_NAME, ioc_attr->card_type); |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | enum bfa_ioc_state |
| 2574 | bfa_ioc_get_state(struct bfa_ioc_s *ioc) |
| 2575 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2576 | enum bfa_iocpf_state iocpf_st; |
| 2577 | enum bfa_ioc_state ioc_st = bfa_sm_to_state(ioc_sm_table, ioc->fsm); |
| 2578 | |
| 2579 | if (ioc_st == BFA_IOC_ENABLING || |
| 2580 | ioc_st == BFA_IOC_FAIL || ioc_st == BFA_IOC_INITFAIL) { |
| 2581 | |
| 2582 | iocpf_st = bfa_sm_to_state(iocpf_sm_table, ioc->iocpf.fsm); |
| 2583 | |
| 2584 | switch (iocpf_st) { |
| 2585 | case BFA_IOCPF_SEMWAIT: |
| 2586 | ioc_st = BFA_IOC_SEMWAIT; |
| 2587 | break; |
| 2588 | |
| 2589 | case BFA_IOCPF_HWINIT: |
| 2590 | ioc_st = BFA_IOC_HWINIT; |
| 2591 | break; |
| 2592 | |
| 2593 | case BFA_IOCPF_FWMISMATCH: |
| 2594 | ioc_st = BFA_IOC_FWMISMATCH; |
| 2595 | break; |
| 2596 | |
| 2597 | case BFA_IOCPF_FAIL: |
| 2598 | ioc_st = BFA_IOC_FAIL; |
| 2599 | break; |
| 2600 | |
| 2601 | case BFA_IOCPF_INITFAIL: |
| 2602 | ioc_st = BFA_IOC_INITFAIL; |
| 2603 | break; |
| 2604 | |
| 2605 | default: |
| 2606 | break; |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | return ioc_st; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | void |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2614 | bfa_ioc_get_attr(struct bfa_ioc_s *ioc, struct bfa_ioc_attr_s *ioc_attr) |
| 2615 | { |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2616 | memset((void *)ioc_attr, 0, sizeof(struct bfa_ioc_attr_s)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2617 | |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2618 | ioc_attr->state = bfa_ioc_get_state(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2619 | ioc_attr->port_id = ioc->port_id; |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 2620 | ioc_attr->port_mode = ioc->port_mode; |
| 2621 | ioc_attr->port_mode_cfg = ioc->port_mode_cfg; |
| 2622 | ioc_attr->cap_bm = ioc->ad_cap_bm; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2623 | |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 2624 | ioc_attr->ioc_type = bfa_ioc_get_type(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2625 | |
| 2626 | bfa_ioc_get_adapter_attr(ioc, &ioc_attr->adapter_attr); |
| 2627 | |
| 2628 | ioc_attr->pci_attr.device_id = ioc->pcidev.device_id; |
| 2629 | ioc_attr->pci_attr.pcifn = ioc->pcidev.pci_func; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 2630 | 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] | 2631 | } |
| 2632 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2633 | mac_t |
| 2634 | bfa_ioc_get_mac(struct bfa_ioc_s *ioc) |
| 2635 | { |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2636 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2637 | * Check the IOC type and return the appropriate MAC |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2638 | */ |
| 2639 | if (bfa_ioc_get_type(ioc) == BFA_IOC_TYPE_FCoE) |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2640 | return ioc->attr->fcoe_mac; |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2641 | else |
| 2642 | return ioc->attr->mac; |
| 2643 | } |
| 2644 | |
Jing Huang | 15b64a8 | 2010-07-08 19:48:12 -0700 | [diff] [blame] | 2645 | mac_t |
| 2646 | bfa_ioc_get_mfg_mac(struct bfa_ioc_s *ioc) |
| 2647 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2648 | mac_t m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2649 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2650 | m = ioc->attr->mfg_mac; |
| 2651 | if (bfa_mfg_is_old_wwn_mac_model(ioc->attr->card_type)) |
| 2652 | m.mac[MAC_ADDRLEN - 1] += bfa_ioc_pcifn(ioc); |
| 2653 | else |
| 2654 | bfa_mfg_increment_wwn_mac(&(m.mac[MAC_ADDRLEN-3]), |
| 2655 | bfa_ioc_pcifn(ioc)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2656 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2657 | return m; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2660 | /* |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 2661 | * Send AEN notification |
| 2662 | */ |
| 2663 | void |
| 2664 | bfa_ioc_aen_post(struct bfa_ioc_s *ioc, enum bfa_ioc_aen_event event) |
| 2665 | { |
| 2666 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
| 2667 | struct bfa_aen_entry_s *aen_entry; |
| 2668 | enum bfa_ioc_type_e ioc_type; |
| 2669 | |
| 2670 | bfad_get_aen_entry(bfad, aen_entry); |
| 2671 | if (!aen_entry) |
| 2672 | return; |
| 2673 | |
| 2674 | ioc_type = bfa_ioc_get_type(ioc); |
| 2675 | switch (ioc_type) { |
| 2676 | case BFA_IOC_TYPE_FC: |
| 2677 | aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn; |
| 2678 | break; |
| 2679 | case BFA_IOC_TYPE_FCoE: |
| 2680 | aen_entry->aen_data.ioc.pwwn = ioc->attr->pwwn; |
| 2681 | aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc); |
| 2682 | break; |
| 2683 | case BFA_IOC_TYPE_LL: |
| 2684 | aen_entry->aen_data.ioc.mac = bfa_ioc_get_mac(ioc); |
| 2685 | break; |
| 2686 | default: |
| 2687 | WARN_ON(ioc_type != BFA_IOC_TYPE_FC); |
| 2688 | break; |
| 2689 | } |
| 2690 | |
| 2691 | /* Send the AEN notification */ |
| 2692 | aen_entry->aen_data.ioc.ioc_type = ioc_type; |
| 2693 | bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq, |
| 2694 | BFA_AEN_CAT_IOC, event); |
| 2695 | } |
| 2696 | |
| 2697 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2698 | * Retrieve saved firmware trace from a prior IOC failure. |
| 2699 | */ |
| 2700 | bfa_status_t |
| 2701 | bfa_ioc_debug_fwsave(struct bfa_ioc_s *ioc, void *trcdata, int *trclen) |
| 2702 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2703 | int tlen; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2704 | |
| 2705 | if (ioc->dbg_fwsave_len == 0) |
| 2706 | return BFA_STATUS_ENOFSAVE; |
| 2707 | |
| 2708 | tlen = *trclen; |
| 2709 | if (tlen > ioc->dbg_fwsave_len) |
| 2710 | tlen = ioc->dbg_fwsave_len; |
| 2711 | |
Jing Huang | 6a18b16 | 2010-10-18 17:08:54 -0700 | [diff] [blame] | 2712 | memcpy(trcdata, ioc->dbg_fwsave, tlen); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2713 | *trclen = tlen; |
| 2714 | return BFA_STATUS_OK; |
| 2715 | } |
| 2716 | |
Krishna Gudipati | 738c9e6 | 2010-03-05 19:36:19 -0800 | [diff] [blame] | 2717 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2718 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2719 | * Retrieve saved firmware trace from a prior IOC failure. |
| 2720 | */ |
| 2721 | bfa_status_t |
| 2722 | bfa_ioc_debug_fwtrc(struct bfa_ioc_s *ioc, void *trcdata, int *trclen) |
| 2723 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2724 | u32 loff = BFA_DBG_FWTRC_OFF(bfa_ioc_portid(ioc)); |
| 2725 | int tlen; |
| 2726 | bfa_status_t status; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2727 | |
| 2728 | bfa_trc(ioc, *trclen); |
| 2729 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2730 | tlen = *trclen; |
| 2731 | if (tlen > BFA_DBG_FWTRC_LEN) |
| 2732 | tlen = BFA_DBG_FWTRC_LEN; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2733 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2734 | status = bfa_ioc_smem_read(ioc, trcdata, loff, tlen); |
| 2735 | *trclen = tlen; |
| 2736 | return status; |
| 2737 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2738 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2739 | static void |
| 2740 | bfa_ioc_send_fwsync(struct bfa_ioc_s *ioc) |
| 2741 | { |
| 2742 | struct bfa_mbox_cmd_s cmd; |
| 2743 | 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] | 2744 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2745 | bfi_h2i_set(req->mh, BFI_MC_IOC, BFI_IOC_H2I_DBG_SYNC, |
| 2746 | bfa_ioc_portid(ioc)); |
Krishna Gudipati | d37779f | 2011-06-13 15:42:10 -0700 | [diff] [blame] | 2747 | req->clscode = cpu_to_be16(ioc->clscode); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2748 | bfa_ioc_mbox_queue(ioc, &cmd); |
| 2749 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2750 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2751 | static void |
| 2752 | bfa_ioc_fwsync(struct bfa_ioc_s *ioc) |
| 2753 | { |
| 2754 | u32 fwsync_iter = 1000; |
| 2755 | |
| 2756 | bfa_ioc_send_fwsync(ioc); |
| 2757 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2758 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2759 | * After sending a fw sync mbox command wait for it to |
| 2760 | * take effect. We will not wait for a response because |
| 2761 | * 1. fw_sync mbox cmd doesn't have a response. |
| 2762 | * 2. Even if we implement that, interrupts might not |
| 2763 | * be enabled when we call this function. |
| 2764 | * So, just keep checking if any mbox cmd is pending, and |
| 2765 | * after waiting for a reasonable amount of time, go ahead. |
| 2766 | * It is possible that fw has crashed and the mbox command |
| 2767 | * is never acknowledged. |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2768 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2769 | while (bfa_ioc_mbox_cmd_pending(ioc) && fwsync_iter > 0) |
| 2770 | fwsync_iter--; |
| 2771 | } |
Krishna Gudipati | 0a20de4 | 2010-03-05 19:34:20 -0800 | [diff] [blame] | 2772 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2773 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2774 | * Dump firmware smem |
| 2775 | */ |
| 2776 | bfa_status_t |
| 2777 | bfa_ioc_debug_fwcore(struct bfa_ioc_s *ioc, void *buf, |
| 2778 | u32 *offset, int *buflen) |
| 2779 | { |
| 2780 | u32 loff; |
| 2781 | int dlen; |
| 2782 | bfa_status_t status; |
| 2783 | u32 smem_len = BFA_IOC_FW_SMEM_SIZE(ioc); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2784 | |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2785 | if (*offset >= smem_len) { |
| 2786 | *offset = *buflen = 0; |
| 2787 | return BFA_STATUS_EINVAL; |
| 2788 | } |
| 2789 | |
| 2790 | loff = *offset; |
| 2791 | dlen = *buflen; |
| 2792 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2793 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2794 | * First smem read, sync smem before proceeding |
| 2795 | * No need to sync before reading every chunk. |
| 2796 | */ |
| 2797 | if (loff == 0) |
| 2798 | bfa_ioc_fwsync(ioc); |
| 2799 | |
| 2800 | if ((loff + dlen) >= smem_len) |
| 2801 | dlen = smem_len - loff; |
| 2802 | |
| 2803 | status = bfa_ioc_smem_read(ioc, buf, loff, dlen); |
| 2804 | |
| 2805 | if (status != BFA_STATUS_OK) { |
| 2806 | *offset = *buflen = 0; |
| 2807 | return status; |
| 2808 | } |
| 2809 | |
| 2810 | *offset += dlen; |
| 2811 | |
| 2812 | if (*offset >= smem_len) |
| 2813 | *offset = 0; |
| 2814 | |
| 2815 | *buflen = dlen; |
| 2816 | |
| 2817 | return status; |
| 2818 | } |
| 2819 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2820 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2821 | * Firmware statistics |
| 2822 | */ |
| 2823 | bfa_status_t |
| 2824 | bfa_ioc_fw_stats_get(struct bfa_ioc_s *ioc, void *stats) |
| 2825 | { |
| 2826 | u32 loff = BFI_IOC_FWSTATS_OFF + \ |
| 2827 | BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc)); |
| 2828 | int tlen; |
| 2829 | bfa_status_t status; |
| 2830 | |
| 2831 | if (ioc->stats_busy) { |
| 2832 | bfa_trc(ioc, ioc->stats_busy); |
| 2833 | return BFA_STATUS_DEVBUSY; |
| 2834 | } |
| 2835 | ioc->stats_busy = BFA_TRUE; |
| 2836 | |
| 2837 | tlen = sizeof(struct bfa_fw_stats_s); |
| 2838 | status = bfa_ioc_smem_read(ioc, stats, loff, tlen); |
| 2839 | |
| 2840 | ioc->stats_busy = BFA_FALSE; |
| 2841 | return status; |
| 2842 | } |
| 2843 | |
| 2844 | bfa_status_t |
| 2845 | bfa_ioc_fw_stats_clear(struct bfa_ioc_s *ioc) |
| 2846 | { |
| 2847 | u32 loff = BFI_IOC_FWSTATS_OFF + \ |
| 2848 | BFI_IOC_FWSTATS_SZ * (bfa_ioc_portid(ioc)); |
| 2849 | int tlen; |
| 2850 | bfa_status_t status; |
| 2851 | |
| 2852 | if (ioc->stats_busy) { |
| 2853 | bfa_trc(ioc, ioc->stats_busy); |
| 2854 | return BFA_STATUS_DEVBUSY; |
| 2855 | } |
| 2856 | ioc->stats_busy = BFA_TRUE; |
| 2857 | |
| 2858 | tlen = sizeof(struct bfa_fw_stats_s); |
| 2859 | status = bfa_ioc_smem_clr(ioc, loff, tlen); |
| 2860 | |
| 2861 | ioc->stats_busy = BFA_FALSE; |
| 2862 | return status; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 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 | * Save firmware trace if configured. |
| 2867 | */ |
Krishna Gudipati | 881c1b3 | 2012-08-22 19:52:02 -0700 | [diff] [blame] | 2868 | void |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 2869 | bfa_ioc_debug_save_ftrc(struct bfa_ioc_s *ioc) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2870 | { |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2871 | int tlen; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2872 | |
Krishna Gudipati | 4e78efe | 2010-12-13 16:16:09 -0800 | [diff] [blame] | 2873 | if (ioc->dbg_fwsave_once) { |
| 2874 | ioc->dbg_fwsave_once = BFA_FALSE; |
| 2875 | if (ioc->dbg_fwsave_len) { |
| 2876 | tlen = ioc->dbg_fwsave_len; |
| 2877 | bfa_ioc_debug_fwtrc(ioc, ioc->dbg_fwsave, &tlen); |
| 2878 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2879 | } |
| 2880 | } |
| 2881 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2882 | /* |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2883 | * Firmware failure detected. Start recovery actions. |
| 2884 | */ |
| 2885 | static void |
| 2886 | bfa_ioc_recover(struct bfa_ioc_s *ioc) |
| 2887 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2888 | bfa_ioc_stats(ioc, ioc_hbfails); |
Krishna Gudipati | 5a0adae | 2011-06-24 20:22:56 -0700 | [diff] [blame] | 2889 | ioc->stats.hb_count = ioc->hb_count; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 2890 | bfa_fsm_send_event(ioc, IOC_E_HBFAIL); |
| 2891 | } |
| 2892 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2893 | /* |
Maggie Zhang | df0f193 | 2010-12-09 19:07:46 -0800 | [diff] [blame] | 2894 | * BFA IOC PF private functions |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2895 | */ |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2896 | static void |
| 2897 | bfa_iocpf_timeout(void *ioc_arg) |
| 2898 | { |
| 2899 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
| 2900 | |
| 2901 | bfa_trc(ioc, 0); |
| 2902 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_TIMEOUT); |
| 2903 | } |
| 2904 | |
| 2905 | static void |
| 2906 | bfa_iocpf_sem_timeout(void *ioc_arg) |
| 2907 | { |
| 2908 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
| 2909 | |
| 2910 | bfa_ioc_hw_sem_get(ioc); |
| 2911 | } |
| 2912 | |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 2913 | static void |
| 2914 | bfa_ioc_poll_fwinit(struct bfa_ioc_s *ioc) |
| 2915 | { |
| 2916 | u32 fwstate = readl(ioc->ioc_regs.ioc_fwstate); |
| 2917 | |
| 2918 | bfa_trc(ioc, fwstate); |
| 2919 | |
| 2920 | if (fwstate == BFI_IOC_DISABLED) { |
| 2921 | bfa_fsm_send_event(&ioc->iocpf, IOCPF_E_FWREADY); |
| 2922 | return; |
| 2923 | } |
| 2924 | |
Krishna Gudipati | 7ac83b1 | 2012-09-21 17:24:21 -0700 | [diff] [blame^] | 2925 | if (ioc->iocpf.poll_time >= (3 * BFA_IOC_TOV)) |
Krishna Gudipati | 775c774 | 2011-06-13 15:52:12 -0700 | [diff] [blame] | 2926 | bfa_iocpf_timeout(ioc); |
| 2927 | else { |
| 2928 | ioc->iocpf.poll_time += BFA_IOC_POLL_TOV; |
| 2929 | bfa_iocpf_poll_timer_start(ioc); |
| 2930 | } |
| 2931 | } |
| 2932 | |
| 2933 | static void |
| 2934 | bfa_iocpf_poll_timeout(void *ioc_arg) |
| 2935 | { |
| 2936 | struct bfa_ioc_s *ioc = (struct bfa_ioc_s *) ioc_arg; |
| 2937 | |
| 2938 | bfa_ioc_poll_fwinit(ioc); |
| 2939 | } |
| 2940 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2941 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2942 | * bfa timer function |
| 2943 | */ |
| 2944 | void |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2945 | bfa_timer_beat(struct bfa_timer_mod_s *mod) |
| 2946 | { |
| 2947 | struct list_head *qh = &mod->timer_q; |
| 2948 | struct list_head *qe, *qe_next; |
| 2949 | struct bfa_timer_s *elem; |
| 2950 | struct list_head timedout_q; |
| 2951 | |
| 2952 | INIT_LIST_HEAD(&timedout_q); |
| 2953 | |
| 2954 | qe = bfa_q_next(qh); |
| 2955 | |
| 2956 | while (qe != qh) { |
| 2957 | qe_next = bfa_q_next(qe); |
| 2958 | |
| 2959 | elem = (struct bfa_timer_s *) qe; |
| 2960 | if (elem->timeout <= BFA_TIMER_FREQ) { |
| 2961 | elem->timeout = 0; |
| 2962 | list_del(&elem->qe); |
| 2963 | list_add_tail(&elem->qe, &timedout_q); |
| 2964 | } else { |
| 2965 | elem->timeout -= BFA_TIMER_FREQ; |
| 2966 | } |
| 2967 | |
| 2968 | qe = qe_next; /* go to next elem */ |
| 2969 | } |
| 2970 | |
| 2971 | /* |
| 2972 | * Pop all the timeout entries |
| 2973 | */ |
| 2974 | while (!list_empty(&timedout_q)) { |
| 2975 | bfa_q_deq(&timedout_q, &elem); |
| 2976 | elem->timercb(elem->arg); |
| 2977 | } |
| 2978 | } |
| 2979 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2980 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2981 | * Should be called with lock protection |
| 2982 | */ |
| 2983 | void |
| 2984 | bfa_timer_begin(struct bfa_timer_mod_s *mod, struct bfa_timer_s *timer, |
| 2985 | void (*timercb) (void *), void *arg, unsigned int timeout) |
| 2986 | { |
| 2987 | |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 2988 | WARN_ON(timercb == NULL); |
| 2989 | WARN_ON(bfa_q_is_on_q(&mod->timer_q, timer)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2990 | |
| 2991 | timer->timeout = timeout; |
| 2992 | timer->timercb = timercb; |
| 2993 | timer->arg = arg; |
| 2994 | |
| 2995 | list_add_tail(&timer->qe, &mod->timer_q); |
| 2996 | } |
| 2997 | |
Jing Huang | 5fbe25c | 2010-10-18 17:17:23 -0700 | [diff] [blame] | 2998 | /* |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 2999 | * Should be called with lock protection |
| 3000 | */ |
| 3001 | void |
| 3002 | bfa_timer_stop(struct bfa_timer_s *timer) |
| 3003 | { |
Jing Huang | d4b671c | 2010-12-26 21:46:35 -0800 | [diff] [blame] | 3004 | WARN_ON(list_empty(&timer->qe)); |
Krishna Gudipati | a36c61f | 2010-09-15 11:50:55 -0700 | [diff] [blame] | 3005 | |
| 3006 | list_del(&timer->qe); |
| 3007 | } |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 3008 | |
| 3009 | /* |
| 3010 | * ASIC block related |
| 3011 | */ |
| 3012 | static void |
| 3013 | bfa_ablk_config_swap(struct bfa_ablk_cfg_s *cfg) |
| 3014 | { |
| 3015 | struct bfa_ablk_cfg_inst_s *cfg_inst; |
| 3016 | int i, j; |
| 3017 | u16 be16; |
| 3018 | u32 be32; |
| 3019 | |
| 3020 | for (i = 0; i < BFA_ABLK_MAX; i++) { |
| 3021 | cfg_inst = &cfg->inst[i]; |
| 3022 | for (j = 0; j < BFA_ABLK_MAX_PFS; j++) { |
| 3023 | be16 = cfg_inst->pf_cfg[j].pers; |
| 3024 | cfg_inst->pf_cfg[j].pers = be16_to_cpu(be16); |
| 3025 | be16 = cfg_inst->pf_cfg[j].num_qpairs; |
| 3026 | cfg_inst->pf_cfg[j].num_qpairs = be16_to_cpu(be16); |
| 3027 | be16 = cfg_inst->pf_cfg[j].num_vectors; |
| 3028 | cfg_inst->pf_cfg[j].num_vectors = be16_to_cpu(be16); |
| 3029 | be32 = cfg_inst->pf_cfg[j].bw; |
| 3030 | cfg_inst->pf_cfg[j].bw = be16_to_cpu(be32); |
| 3031 | } |
| 3032 | } |
| 3033 | } |
| 3034 | |
| 3035 | static void |
| 3036 | bfa_ablk_isr(void *cbarg, struct bfi_mbmsg_s *msg) |
| 3037 | { |
| 3038 | struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg; |
| 3039 | struct bfi_ablk_i2h_rsp_s *rsp = (struct bfi_ablk_i2h_rsp_s *)msg; |
| 3040 | bfa_ablk_cbfn_t cbfn; |
| 3041 | |
| 3042 | WARN_ON(msg->mh.msg_class != BFI_MC_ABLK); |
| 3043 | bfa_trc(ablk->ioc, msg->mh.msg_id); |
| 3044 | |
| 3045 | switch (msg->mh.msg_id) { |
| 3046 | case BFI_ABLK_I2H_QUERY: |
| 3047 | if (rsp->status == BFA_STATUS_OK) { |
| 3048 | memcpy(ablk->cfg, ablk->dma_addr.kva, |
| 3049 | sizeof(struct bfa_ablk_cfg_s)); |
| 3050 | bfa_ablk_config_swap(ablk->cfg); |
| 3051 | ablk->cfg = NULL; |
| 3052 | } |
| 3053 | break; |
| 3054 | |
| 3055 | case BFI_ABLK_I2H_ADPT_CONFIG: |
| 3056 | case BFI_ABLK_I2H_PORT_CONFIG: |
| 3057 | /* update config port mode */ |
| 3058 | ablk->ioc->port_mode_cfg = rsp->port_mode; |
| 3059 | |
| 3060 | case BFI_ABLK_I2H_PF_DELETE: |
| 3061 | case BFI_ABLK_I2H_PF_UPDATE: |
| 3062 | case BFI_ABLK_I2H_OPTROM_ENABLE: |
| 3063 | case BFI_ABLK_I2H_OPTROM_DISABLE: |
| 3064 | /* No-op */ |
| 3065 | break; |
| 3066 | |
| 3067 | case BFI_ABLK_I2H_PF_CREATE: |
| 3068 | *(ablk->pcifn) = rsp->pcifn; |
| 3069 | ablk->pcifn = NULL; |
| 3070 | break; |
| 3071 | |
| 3072 | default: |
| 3073 | WARN_ON(1); |
| 3074 | } |
| 3075 | |
| 3076 | ablk->busy = BFA_FALSE; |
| 3077 | if (ablk->cbfn) { |
| 3078 | cbfn = ablk->cbfn; |
| 3079 | ablk->cbfn = NULL; |
| 3080 | cbfn(ablk->cbarg, rsp->status); |
| 3081 | } |
| 3082 | } |
| 3083 | |
| 3084 | static void |
| 3085 | bfa_ablk_notify(void *cbarg, enum bfa_ioc_event_e event) |
| 3086 | { |
| 3087 | struct bfa_ablk_s *ablk = (struct bfa_ablk_s *)cbarg; |
| 3088 | |
| 3089 | bfa_trc(ablk->ioc, event); |
| 3090 | |
| 3091 | switch (event) { |
| 3092 | case BFA_IOC_E_ENABLED: |
| 3093 | WARN_ON(ablk->busy != BFA_FALSE); |
| 3094 | break; |
| 3095 | |
| 3096 | case BFA_IOC_E_DISABLED: |
| 3097 | case BFA_IOC_E_FAILED: |
| 3098 | /* Fail any pending requests */ |
| 3099 | ablk->pcifn = NULL; |
| 3100 | if (ablk->busy) { |
| 3101 | if (ablk->cbfn) |
| 3102 | ablk->cbfn(ablk->cbarg, BFA_STATUS_FAILED); |
| 3103 | ablk->cbfn = NULL; |
| 3104 | ablk->busy = BFA_FALSE; |
| 3105 | } |
| 3106 | break; |
| 3107 | |
| 3108 | default: |
| 3109 | WARN_ON(1); |
| 3110 | break; |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | u32 |
| 3115 | bfa_ablk_meminfo(void) |
| 3116 | { |
| 3117 | return BFA_ROUNDUP(sizeof(struct bfa_ablk_cfg_s), BFA_DMA_ALIGN_SZ); |
| 3118 | } |
| 3119 | |
| 3120 | void |
| 3121 | bfa_ablk_memclaim(struct bfa_ablk_s *ablk, u8 *dma_kva, u64 dma_pa) |
| 3122 | { |
| 3123 | ablk->dma_addr.kva = dma_kva; |
| 3124 | ablk->dma_addr.pa = dma_pa; |
| 3125 | } |
| 3126 | |
| 3127 | void |
| 3128 | bfa_ablk_attach(struct bfa_ablk_s *ablk, struct bfa_ioc_s *ioc) |
| 3129 | { |
| 3130 | ablk->ioc = ioc; |
| 3131 | |
| 3132 | bfa_ioc_mbox_regisr(ablk->ioc, BFI_MC_ABLK, bfa_ablk_isr, ablk); |
Krishna Gudipati | 3350d98 | 2011-06-24 20:28:37 -0700 | [diff] [blame] | 3133 | bfa_q_qe_init(&ablk->ioc_notify); |
Krishna Gudipati | 1a4d8e1 | 2011-06-24 20:22:28 -0700 | [diff] [blame] | 3134 | bfa_ioc_notify_init(&ablk->ioc_notify, bfa_ablk_notify, ablk); |
| 3135 | list_add_tail(&ablk->ioc_notify.qe, &ablk->ioc->notify_q); |
| 3136 | } |
| 3137 | |
| 3138 | bfa_status_t |
| 3139 | bfa_ablk_query(struct bfa_ablk_s *ablk, struct bfa_ablk_cfg_s *ablk_cfg, |
| 3140 | bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3141 | { |
| 3142 | struct bfi_ablk_h2i_query_s *m; |
| 3143 | |
| 3144 | WARN_ON(!ablk_cfg); |
| 3145 | |
| 3146 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3147 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3148 | return BFA_STATUS_IOC_FAILURE; |
| 3149 | } |
| 3150 | |
| 3151 | if (ablk->busy) { |
| 3152 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3153 | return BFA_STATUS_DEVBUSY; |
| 3154 | } |
| 3155 | |
| 3156 | ablk->cfg = ablk_cfg; |
| 3157 | ablk->cbfn = cbfn; |
| 3158 | ablk->cbarg = cbarg; |
| 3159 | ablk->busy = BFA_TRUE; |
| 3160 | |
| 3161 | m = (struct bfi_ablk_h2i_query_s *)ablk->mb.msg; |
| 3162 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_QUERY, |
| 3163 | bfa_ioc_portid(ablk->ioc)); |
| 3164 | bfa_dma_be_addr_set(m->addr, ablk->dma_addr.pa); |
| 3165 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3166 | |
| 3167 | return BFA_STATUS_OK; |
| 3168 | } |
| 3169 | |
| 3170 | bfa_status_t |
| 3171 | bfa_ablk_pf_create(struct bfa_ablk_s *ablk, u16 *pcifn, |
| 3172 | u8 port, enum bfi_pcifn_class personality, int bw, |
| 3173 | bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3174 | { |
| 3175 | struct bfi_ablk_h2i_pf_req_s *m; |
| 3176 | |
| 3177 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3178 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3179 | return BFA_STATUS_IOC_FAILURE; |
| 3180 | } |
| 3181 | |
| 3182 | if (ablk->busy) { |
| 3183 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3184 | return BFA_STATUS_DEVBUSY; |
| 3185 | } |
| 3186 | |
| 3187 | ablk->pcifn = pcifn; |
| 3188 | ablk->cbfn = cbfn; |
| 3189 | ablk->cbarg = cbarg; |
| 3190 | ablk->busy = BFA_TRUE; |
| 3191 | |
| 3192 | m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg; |
| 3193 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_CREATE, |
| 3194 | bfa_ioc_portid(ablk->ioc)); |
| 3195 | m->pers = cpu_to_be16((u16)personality); |
| 3196 | m->bw = cpu_to_be32(bw); |
| 3197 | m->port = port; |
| 3198 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3199 | |
| 3200 | return BFA_STATUS_OK; |
| 3201 | } |
| 3202 | |
| 3203 | bfa_status_t |
| 3204 | bfa_ablk_pf_delete(struct bfa_ablk_s *ablk, int pcifn, |
| 3205 | bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3206 | { |
| 3207 | struct bfi_ablk_h2i_pf_req_s *m; |
| 3208 | |
| 3209 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3210 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3211 | return BFA_STATUS_IOC_FAILURE; |
| 3212 | } |
| 3213 | |
| 3214 | if (ablk->busy) { |
| 3215 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3216 | return BFA_STATUS_DEVBUSY; |
| 3217 | } |
| 3218 | |
| 3219 | ablk->cbfn = cbfn; |
| 3220 | ablk->cbarg = cbarg; |
| 3221 | ablk->busy = BFA_TRUE; |
| 3222 | |
| 3223 | m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg; |
| 3224 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_DELETE, |
| 3225 | bfa_ioc_portid(ablk->ioc)); |
| 3226 | m->pcifn = (u8)pcifn; |
| 3227 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3228 | |
| 3229 | return BFA_STATUS_OK; |
| 3230 | } |
| 3231 | |
| 3232 | bfa_status_t |
| 3233 | bfa_ablk_adapter_config(struct bfa_ablk_s *ablk, enum bfa_mode_s mode, |
| 3234 | int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3235 | { |
| 3236 | struct bfi_ablk_h2i_cfg_req_s *m; |
| 3237 | |
| 3238 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3239 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3240 | return BFA_STATUS_IOC_FAILURE; |
| 3241 | } |
| 3242 | |
| 3243 | if (ablk->busy) { |
| 3244 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3245 | return BFA_STATUS_DEVBUSY; |
| 3246 | } |
| 3247 | |
| 3248 | ablk->cbfn = cbfn; |
| 3249 | ablk->cbarg = cbarg; |
| 3250 | ablk->busy = BFA_TRUE; |
| 3251 | |
| 3252 | m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg; |
| 3253 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_ADPT_CONFIG, |
| 3254 | bfa_ioc_portid(ablk->ioc)); |
| 3255 | m->mode = (u8)mode; |
| 3256 | m->max_pf = (u8)max_pf; |
| 3257 | m->max_vf = (u8)max_vf; |
| 3258 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3259 | |
| 3260 | return BFA_STATUS_OK; |
| 3261 | } |
| 3262 | |
| 3263 | bfa_status_t |
| 3264 | bfa_ablk_port_config(struct bfa_ablk_s *ablk, int port, enum bfa_mode_s mode, |
| 3265 | int max_pf, int max_vf, bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3266 | { |
| 3267 | struct bfi_ablk_h2i_cfg_req_s *m; |
| 3268 | |
| 3269 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3270 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3271 | return BFA_STATUS_IOC_FAILURE; |
| 3272 | } |
| 3273 | |
| 3274 | if (ablk->busy) { |
| 3275 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3276 | return BFA_STATUS_DEVBUSY; |
| 3277 | } |
| 3278 | |
| 3279 | ablk->cbfn = cbfn; |
| 3280 | ablk->cbarg = cbarg; |
| 3281 | ablk->busy = BFA_TRUE; |
| 3282 | |
| 3283 | m = (struct bfi_ablk_h2i_cfg_req_s *)ablk->mb.msg; |
| 3284 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PORT_CONFIG, |
| 3285 | bfa_ioc_portid(ablk->ioc)); |
| 3286 | m->port = (u8)port; |
| 3287 | m->mode = (u8)mode; |
| 3288 | m->max_pf = (u8)max_pf; |
| 3289 | m->max_vf = (u8)max_vf; |
| 3290 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3291 | |
| 3292 | return BFA_STATUS_OK; |
| 3293 | } |
| 3294 | |
| 3295 | bfa_status_t |
| 3296 | bfa_ablk_pf_update(struct bfa_ablk_s *ablk, int pcifn, int bw, |
| 3297 | bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3298 | { |
| 3299 | struct bfi_ablk_h2i_pf_req_s *m; |
| 3300 | |
| 3301 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3302 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3303 | return BFA_STATUS_IOC_FAILURE; |
| 3304 | } |
| 3305 | |
| 3306 | if (ablk->busy) { |
| 3307 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3308 | return BFA_STATUS_DEVBUSY; |
| 3309 | } |
| 3310 | |
| 3311 | ablk->cbfn = cbfn; |
| 3312 | ablk->cbarg = cbarg; |
| 3313 | ablk->busy = BFA_TRUE; |
| 3314 | |
| 3315 | m = (struct bfi_ablk_h2i_pf_req_s *)ablk->mb.msg; |
| 3316 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_PF_UPDATE, |
| 3317 | bfa_ioc_portid(ablk->ioc)); |
| 3318 | m->pcifn = (u8)pcifn; |
| 3319 | m->bw = cpu_to_be32(bw); |
| 3320 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3321 | |
| 3322 | return BFA_STATUS_OK; |
| 3323 | } |
| 3324 | |
| 3325 | bfa_status_t |
| 3326 | bfa_ablk_optrom_en(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3327 | { |
| 3328 | struct bfi_ablk_h2i_optrom_s *m; |
| 3329 | |
| 3330 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3331 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3332 | return BFA_STATUS_IOC_FAILURE; |
| 3333 | } |
| 3334 | |
| 3335 | if (ablk->busy) { |
| 3336 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3337 | return BFA_STATUS_DEVBUSY; |
| 3338 | } |
| 3339 | |
| 3340 | ablk->cbfn = cbfn; |
| 3341 | ablk->cbarg = cbarg; |
| 3342 | ablk->busy = BFA_TRUE; |
| 3343 | |
| 3344 | m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg; |
| 3345 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_ENABLE, |
| 3346 | bfa_ioc_portid(ablk->ioc)); |
| 3347 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3348 | |
| 3349 | return BFA_STATUS_OK; |
| 3350 | } |
| 3351 | |
| 3352 | bfa_status_t |
| 3353 | bfa_ablk_optrom_dis(struct bfa_ablk_s *ablk, bfa_ablk_cbfn_t cbfn, void *cbarg) |
| 3354 | { |
| 3355 | struct bfi_ablk_h2i_optrom_s *m; |
| 3356 | |
| 3357 | if (!bfa_ioc_is_operational(ablk->ioc)) { |
| 3358 | bfa_trc(ablk->ioc, BFA_STATUS_IOC_FAILURE); |
| 3359 | return BFA_STATUS_IOC_FAILURE; |
| 3360 | } |
| 3361 | |
| 3362 | if (ablk->busy) { |
| 3363 | bfa_trc(ablk->ioc, BFA_STATUS_DEVBUSY); |
| 3364 | return BFA_STATUS_DEVBUSY; |
| 3365 | } |
| 3366 | |
| 3367 | ablk->cbfn = cbfn; |
| 3368 | ablk->cbarg = cbarg; |
| 3369 | ablk->busy = BFA_TRUE; |
| 3370 | |
| 3371 | m = (struct bfi_ablk_h2i_optrom_s *)ablk->mb.msg; |
| 3372 | bfi_h2i_set(m->mh, BFI_MC_ABLK, BFI_ABLK_H2I_OPTROM_DISABLE, |
| 3373 | bfa_ioc_portid(ablk->ioc)); |
| 3374 | bfa_ioc_mbox_queue(ablk->ioc, &ablk->mb); |
| 3375 | |
| 3376 | return BFA_STATUS_OK; |
| 3377 | } |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame] | 3378 | |
| 3379 | /* |
| 3380 | * SFP module specific |
| 3381 | */ |
| 3382 | |
| 3383 | /* forward declarations */ |
| 3384 | static void bfa_sfp_getdata_send(struct bfa_sfp_s *sfp); |
| 3385 | static void bfa_sfp_media_get(struct bfa_sfp_s *sfp); |
| 3386 | static bfa_status_t bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, |
| 3387 | enum bfa_port_speed portspeed); |
| 3388 | |
| 3389 | static void |
| 3390 | bfa_cb_sfp_show(struct bfa_sfp_s *sfp) |
| 3391 | { |
| 3392 | bfa_trc(sfp, sfp->lock); |
| 3393 | if (sfp->cbfn) |
| 3394 | sfp->cbfn(sfp->cbarg, sfp->status); |
| 3395 | sfp->lock = 0; |
| 3396 | sfp->cbfn = NULL; |
| 3397 | } |
| 3398 | |
| 3399 | static void |
| 3400 | bfa_cb_sfp_state_query(struct bfa_sfp_s *sfp) |
| 3401 | { |
| 3402 | bfa_trc(sfp, sfp->portspeed); |
| 3403 | if (sfp->media) { |
| 3404 | bfa_sfp_media_get(sfp); |
| 3405 | if (sfp->state_query_cbfn) |
| 3406 | sfp->state_query_cbfn(sfp->state_query_cbarg, |
| 3407 | sfp->status); |
| 3408 | sfp->media = NULL; |
| 3409 | } |
| 3410 | |
| 3411 | if (sfp->portspeed) { |
| 3412 | sfp->status = bfa_sfp_speed_valid(sfp, sfp->portspeed); |
| 3413 | if (sfp->state_query_cbfn) |
| 3414 | sfp->state_query_cbfn(sfp->state_query_cbarg, |
| 3415 | sfp->status); |
| 3416 | sfp->portspeed = BFA_PORT_SPEED_UNKNOWN; |
| 3417 | } |
| 3418 | |
| 3419 | sfp->state_query_lock = 0; |
| 3420 | sfp->state_query_cbfn = NULL; |
| 3421 | } |
| 3422 | |
| 3423 | /* |
| 3424 | * IOC event handler. |
| 3425 | */ |
| 3426 | static void |
| 3427 | bfa_sfp_notify(void *sfp_arg, enum bfa_ioc_event_e event) |
| 3428 | { |
| 3429 | struct bfa_sfp_s *sfp = sfp_arg; |
| 3430 | |
| 3431 | bfa_trc(sfp, event); |
| 3432 | bfa_trc(sfp, sfp->lock); |
| 3433 | bfa_trc(sfp, sfp->state_query_lock); |
| 3434 | |
| 3435 | switch (event) { |
| 3436 | case BFA_IOC_E_DISABLED: |
| 3437 | case BFA_IOC_E_FAILED: |
| 3438 | if (sfp->lock) { |
| 3439 | sfp->status = BFA_STATUS_IOC_FAILURE; |
| 3440 | bfa_cb_sfp_show(sfp); |
| 3441 | } |
| 3442 | |
| 3443 | if (sfp->state_query_lock) { |
| 3444 | sfp->status = BFA_STATUS_IOC_FAILURE; |
| 3445 | bfa_cb_sfp_state_query(sfp); |
| 3446 | } |
| 3447 | break; |
| 3448 | |
| 3449 | default: |
| 3450 | break; |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | /* |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 3455 | * SFP's State Change Notification post to AEN |
| 3456 | */ |
| 3457 | static void |
| 3458 | bfa_sfp_scn_aen_post(struct bfa_sfp_s *sfp, struct bfi_sfp_scn_s *rsp) |
| 3459 | { |
| 3460 | struct bfad_s *bfad = (struct bfad_s *)sfp->ioc->bfa->bfad; |
| 3461 | struct bfa_aen_entry_s *aen_entry; |
| 3462 | enum bfa_port_aen_event aen_evt = 0; |
| 3463 | |
| 3464 | bfa_trc(sfp, (((u64)rsp->pomlvl) << 16) | (((u64)rsp->sfpid) << 8) | |
| 3465 | ((u64)rsp->event)); |
| 3466 | |
| 3467 | bfad_get_aen_entry(bfad, aen_entry); |
| 3468 | if (!aen_entry) |
| 3469 | return; |
| 3470 | |
| 3471 | aen_entry->aen_data.port.ioc_type = bfa_ioc_get_type(sfp->ioc); |
| 3472 | aen_entry->aen_data.port.pwwn = sfp->ioc->attr->pwwn; |
| 3473 | aen_entry->aen_data.port.mac = bfa_ioc_get_mac(sfp->ioc); |
| 3474 | |
| 3475 | switch (rsp->event) { |
| 3476 | case BFA_SFP_SCN_INSERTED: |
| 3477 | aen_evt = BFA_PORT_AEN_SFP_INSERT; |
| 3478 | break; |
| 3479 | case BFA_SFP_SCN_REMOVED: |
| 3480 | aen_evt = BFA_PORT_AEN_SFP_REMOVE; |
| 3481 | break; |
| 3482 | case BFA_SFP_SCN_FAILED: |
| 3483 | aen_evt = BFA_PORT_AEN_SFP_ACCESS_ERROR; |
| 3484 | break; |
| 3485 | case BFA_SFP_SCN_UNSUPPORT: |
| 3486 | aen_evt = BFA_PORT_AEN_SFP_UNSUPPORT; |
| 3487 | break; |
| 3488 | case BFA_SFP_SCN_POM: |
| 3489 | aen_evt = BFA_PORT_AEN_SFP_POM; |
| 3490 | aen_entry->aen_data.port.level = rsp->pomlvl; |
| 3491 | break; |
| 3492 | default: |
| 3493 | bfa_trc(sfp, rsp->event); |
| 3494 | WARN_ON(1); |
| 3495 | } |
| 3496 | |
| 3497 | /* Send the AEN notification */ |
| 3498 | bfad_im_post_vendor_event(aen_entry, bfad, ++sfp->ioc->ioc_aen_seq, |
| 3499 | BFA_AEN_CAT_PORT, aen_evt); |
| 3500 | } |
| 3501 | |
| 3502 | /* |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame] | 3503 | * SFP get data send |
| 3504 | */ |
| 3505 | static void |
| 3506 | bfa_sfp_getdata_send(struct bfa_sfp_s *sfp) |
| 3507 | { |
| 3508 | struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg; |
| 3509 | |
| 3510 | bfa_trc(sfp, req->memtype); |
| 3511 | |
| 3512 | /* build host command */ |
| 3513 | bfi_h2i_set(req->mh, BFI_MC_SFP, BFI_SFP_H2I_SHOW, |
| 3514 | bfa_ioc_portid(sfp->ioc)); |
| 3515 | |
| 3516 | /* send mbox cmd */ |
| 3517 | bfa_ioc_mbox_queue(sfp->ioc, &sfp->mbcmd); |
| 3518 | } |
| 3519 | |
| 3520 | /* |
| 3521 | * SFP is valid, read sfp data |
| 3522 | */ |
| 3523 | static void |
| 3524 | bfa_sfp_getdata(struct bfa_sfp_s *sfp, enum bfi_sfp_mem_e memtype) |
| 3525 | { |
| 3526 | struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg; |
| 3527 | |
| 3528 | WARN_ON(sfp->lock != 0); |
| 3529 | bfa_trc(sfp, sfp->state); |
| 3530 | |
| 3531 | sfp->lock = 1; |
| 3532 | sfp->memtype = memtype; |
| 3533 | req->memtype = memtype; |
| 3534 | |
| 3535 | /* Setup SG list */ |
| 3536 | bfa_alen_set(&req->alen, sizeof(struct sfp_mem_s), sfp->dbuf_pa); |
| 3537 | |
| 3538 | bfa_sfp_getdata_send(sfp); |
| 3539 | } |
| 3540 | |
| 3541 | /* |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 3542 | * SFP scn handler |
| 3543 | */ |
| 3544 | static void |
| 3545 | bfa_sfp_scn(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg) |
| 3546 | { |
| 3547 | struct bfi_sfp_scn_s *rsp = (struct bfi_sfp_scn_s *) msg; |
| 3548 | |
| 3549 | switch (rsp->event) { |
| 3550 | case BFA_SFP_SCN_INSERTED: |
| 3551 | sfp->state = BFA_SFP_STATE_INSERTED; |
| 3552 | sfp->data_valid = 0; |
| 3553 | bfa_sfp_scn_aen_post(sfp, rsp); |
| 3554 | break; |
| 3555 | case BFA_SFP_SCN_REMOVED: |
| 3556 | sfp->state = BFA_SFP_STATE_REMOVED; |
| 3557 | sfp->data_valid = 0; |
| 3558 | bfa_sfp_scn_aen_post(sfp, rsp); |
| 3559 | break; |
| 3560 | case BFA_SFP_SCN_FAILED: |
| 3561 | sfp->state = BFA_SFP_STATE_FAILED; |
| 3562 | sfp->data_valid = 0; |
| 3563 | bfa_sfp_scn_aen_post(sfp, rsp); |
| 3564 | break; |
| 3565 | case BFA_SFP_SCN_UNSUPPORT: |
| 3566 | sfp->state = BFA_SFP_STATE_UNSUPPORT; |
| 3567 | bfa_sfp_scn_aen_post(sfp, rsp); |
| 3568 | if (!sfp->lock) |
| 3569 | bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL); |
| 3570 | break; |
| 3571 | case BFA_SFP_SCN_POM: |
| 3572 | bfa_sfp_scn_aen_post(sfp, rsp); |
| 3573 | break; |
| 3574 | case BFA_SFP_SCN_VALID: |
| 3575 | sfp->state = BFA_SFP_STATE_VALID; |
| 3576 | if (!sfp->lock) |
| 3577 | bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL); |
| 3578 | break; |
| 3579 | default: |
| 3580 | bfa_trc(sfp, rsp->event); |
| 3581 | WARN_ON(1); |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | /* |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame] | 3586 | * SFP show complete |
| 3587 | */ |
| 3588 | static void |
| 3589 | bfa_sfp_show_comp(struct bfa_sfp_s *sfp, struct bfi_mbmsg_s *msg) |
| 3590 | { |
| 3591 | struct bfi_sfp_rsp_s *rsp = (struct bfi_sfp_rsp_s *) msg; |
| 3592 | |
| 3593 | if (!sfp->lock) { |
| 3594 | /* |
| 3595 | * receiving response after ioc failure |
| 3596 | */ |
| 3597 | bfa_trc(sfp, sfp->lock); |
| 3598 | return; |
| 3599 | } |
| 3600 | |
| 3601 | bfa_trc(sfp, rsp->status); |
| 3602 | if (rsp->status == BFA_STATUS_OK) { |
| 3603 | sfp->data_valid = 1; |
| 3604 | if (sfp->state == BFA_SFP_STATE_VALID) |
| 3605 | sfp->status = BFA_STATUS_OK; |
| 3606 | else if (sfp->state == BFA_SFP_STATE_UNSUPPORT) |
| 3607 | sfp->status = BFA_STATUS_SFP_UNSUPP; |
| 3608 | else |
| 3609 | bfa_trc(sfp, sfp->state); |
| 3610 | } else { |
| 3611 | sfp->data_valid = 0; |
| 3612 | sfp->status = rsp->status; |
| 3613 | /* sfpshow shouldn't change sfp state */ |
| 3614 | } |
| 3615 | |
| 3616 | bfa_trc(sfp, sfp->memtype); |
| 3617 | if (sfp->memtype == BFI_SFP_MEM_DIAGEXT) { |
| 3618 | bfa_trc(sfp, sfp->data_valid); |
| 3619 | if (sfp->data_valid) { |
| 3620 | u32 size = sizeof(struct sfp_mem_s); |
| 3621 | u8 *des = (u8 *) &(sfp->sfpmem->srlid_base); |
| 3622 | memcpy(des, sfp->dbuf_kva, size); |
| 3623 | } |
| 3624 | /* |
| 3625 | * Queue completion callback. |
| 3626 | */ |
| 3627 | bfa_cb_sfp_show(sfp); |
| 3628 | } else |
| 3629 | sfp->lock = 0; |
| 3630 | |
| 3631 | bfa_trc(sfp, sfp->state_query_lock); |
| 3632 | if (sfp->state_query_lock) { |
| 3633 | sfp->state = rsp->state; |
| 3634 | /* Complete callback */ |
| 3635 | bfa_cb_sfp_state_query(sfp); |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | /* |
| 3640 | * SFP query fw sfp state |
| 3641 | */ |
| 3642 | static void |
| 3643 | bfa_sfp_state_query(struct bfa_sfp_s *sfp) |
| 3644 | { |
| 3645 | struct bfi_sfp_req_s *req = (struct bfi_sfp_req_s *)sfp->mbcmd.msg; |
| 3646 | |
| 3647 | /* Should not be doing query if not in _INIT state */ |
| 3648 | WARN_ON(sfp->state != BFA_SFP_STATE_INIT); |
| 3649 | WARN_ON(sfp->state_query_lock != 0); |
| 3650 | bfa_trc(sfp, sfp->state); |
| 3651 | |
| 3652 | sfp->state_query_lock = 1; |
| 3653 | req->memtype = 0; |
| 3654 | |
| 3655 | if (!sfp->lock) |
| 3656 | bfa_sfp_getdata(sfp, BFI_SFP_MEM_ALL); |
| 3657 | } |
| 3658 | |
| 3659 | static void |
| 3660 | bfa_sfp_media_get(struct bfa_sfp_s *sfp) |
| 3661 | { |
| 3662 | enum bfa_defs_sfp_media_e *media = sfp->media; |
| 3663 | |
| 3664 | *media = BFA_SFP_MEDIA_UNKNOWN; |
| 3665 | |
| 3666 | if (sfp->state == BFA_SFP_STATE_UNSUPPORT) |
| 3667 | *media = BFA_SFP_MEDIA_UNSUPPORT; |
| 3668 | else if (sfp->state == BFA_SFP_STATE_VALID) { |
| 3669 | union sfp_xcvr_e10g_code_u e10g; |
| 3670 | struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva; |
| 3671 | u16 xmtr_tech = (sfpmem->srlid_base.xcvr[4] & 0x3) << 7 | |
| 3672 | (sfpmem->srlid_base.xcvr[5] >> 1); |
| 3673 | |
| 3674 | e10g.b = sfpmem->srlid_base.xcvr[0]; |
| 3675 | bfa_trc(sfp, e10g.b); |
| 3676 | bfa_trc(sfp, xmtr_tech); |
| 3677 | /* check fc transmitter tech */ |
| 3678 | if ((xmtr_tech & SFP_XMTR_TECH_CU) || |
| 3679 | (xmtr_tech & SFP_XMTR_TECH_CP) || |
| 3680 | (xmtr_tech & SFP_XMTR_TECH_CA)) |
| 3681 | *media = BFA_SFP_MEDIA_CU; |
| 3682 | else if ((xmtr_tech & SFP_XMTR_TECH_EL_INTRA) || |
| 3683 | (xmtr_tech & SFP_XMTR_TECH_EL_INTER)) |
| 3684 | *media = BFA_SFP_MEDIA_EL; |
| 3685 | else if ((xmtr_tech & SFP_XMTR_TECH_LL) || |
| 3686 | (xmtr_tech & SFP_XMTR_TECH_LC)) |
| 3687 | *media = BFA_SFP_MEDIA_LW; |
| 3688 | else if ((xmtr_tech & SFP_XMTR_TECH_SL) || |
| 3689 | (xmtr_tech & SFP_XMTR_TECH_SN) || |
| 3690 | (xmtr_tech & SFP_XMTR_TECH_SA)) |
| 3691 | *media = BFA_SFP_MEDIA_SW; |
| 3692 | /* Check 10G Ethernet Compilance code */ |
Jing Huang | 98cdfb4 | 2011-11-16 12:29:26 -0800 | [diff] [blame] | 3693 | else if (e10g.r.e10g_sr) |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame] | 3694 | *media = BFA_SFP_MEDIA_SW; |
Jing Huang | 98cdfb4 | 2011-11-16 12:29:26 -0800 | [diff] [blame] | 3695 | else if (e10g.r.e10g_lrm && e10g.r.e10g_lr) |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame] | 3696 | *media = BFA_SFP_MEDIA_LW; |
Jing Huang | 98cdfb4 | 2011-11-16 12:29:26 -0800 | [diff] [blame] | 3697 | else if (e10g.r.e10g_unall) |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame] | 3698 | *media = BFA_SFP_MEDIA_UNKNOWN; |
| 3699 | else |
| 3700 | bfa_trc(sfp, 0); |
| 3701 | } else |
| 3702 | bfa_trc(sfp, sfp->state); |
| 3703 | } |
| 3704 | |
| 3705 | static bfa_status_t |
| 3706 | bfa_sfp_speed_valid(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed) |
| 3707 | { |
| 3708 | struct sfp_mem_s *sfpmem = (struct sfp_mem_s *)sfp->dbuf_kva; |
| 3709 | struct sfp_xcvr_s *xcvr = (struct sfp_xcvr_s *) sfpmem->srlid_base.xcvr; |
| 3710 | union sfp_xcvr_fc3_code_u fc3 = xcvr->fc3; |
| 3711 | union sfp_xcvr_e10g_code_u e10g = xcvr->e10g; |
| 3712 | |
| 3713 | if (portspeed == BFA_PORT_SPEED_10GBPS) { |
| 3714 | if (e10g.r.e10g_sr || e10g.r.e10g_lr) |
| 3715 | return BFA_STATUS_OK; |
| 3716 | else { |
| 3717 | bfa_trc(sfp, e10g.b); |
| 3718 | return BFA_STATUS_UNSUPP_SPEED; |
| 3719 | } |
| 3720 | } |
| 3721 | if (((portspeed & BFA_PORT_SPEED_16GBPS) && fc3.r.mb1600) || |
| 3722 | ((portspeed & BFA_PORT_SPEED_8GBPS) && fc3.r.mb800) || |
| 3723 | ((portspeed & BFA_PORT_SPEED_4GBPS) && fc3.r.mb400) || |
| 3724 | ((portspeed & BFA_PORT_SPEED_2GBPS) && fc3.r.mb200) || |
| 3725 | ((portspeed & BFA_PORT_SPEED_1GBPS) && fc3.r.mb100)) |
| 3726 | return BFA_STATUS_OK; |
| 3727 | else { |
| 3728 | bfa_trc(sfp, portspeed); |
| 3729 | bfa_trc(sfp, fc3.b); |
| 3730 | bfa_trc(sfp, e10g.b); |
| 3731 | return BFA_STATUS_UNSUPP_SPEED; |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | /* |
| 3736 | * SFP hmbox handler |
| 3737 | */ |
| 3738 | void |
| 3739 | bfa_sfp_intr(void *sfparg, struct bfi_mbmsg_s *msg) |
| 3740 | { |
| 3741 | struct bfa_sfp_s *sfp = sfparg; |
| 3742 | |
| 3743 | switch (msg->mh.msg_id) { |
| 3744 | case BFI_SFP_I2H_SHOW: |
| 3745 | bfa_sfp_show_comp(sfp, msg); |
| 3746 | break; |
| 3747 | |
| 3748 | case BFI_SFP_I2H_SCN: |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 3749 | bfa_sfp_scn(sfp, msg); |
Krishna Gudipati | 51e569a | 2011-06-24 20:26:25 -0700 | [diff] [blame] | 3750 | break; |
| 3751 | |
| 3752 | default: |
| 3753 | bfa_trc(sfp, msg->mh.msg_id); |
| 3754 | WARN_ON(1); |
| 3755 | } |
| 3756 | } |
| 3757 | |
| 3758 | /* |
| 3759 | * Return DMA memory needed by sfp module. |
| 3760 | */ |
| 3761 | u32 |
| 3762 | bfa_sfp_meminfo(void) |
| 3763 | { |
| 3764 | return BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ); |
| 3765 | } |
| 3766 | |
| 3767 | /* |
| 3768 | * Attach virtual and physical memory for SFP. |
| 3769 | */ |
| 3770 | void |
| 3771 | bfa_sfp_attach(struct bfa_sfp_s *sfp, struct bfa_ioc_s *ioc, void *dev, |
| 3772 | struct bfa_trc_mod_s *trcmod) |
| 3773 | { |
| 3774 | sfp->dev = dev; |
| 3775 | sfp->ioc = ioc; |
| 3776 | sfp->trcmod = trcmod; |
| 3777 | |
| 3778 | sfp->cbfn = NULL; |
| 3779 | sfp->cbarg = NULL; |
| 3780 | sfp->sfpmem = NULL; |
| 3781 | sfp->lock = 0; |
| 3782 | sfp->data_valid = 0; |
| 3783 | sfp->state = BFA_SFP_STATE_INIT; |
| 3784 | sfp->state_query_lock = 0; |
| 3785 | sfp->state_query_cbfn = NULL; |
| 3786 | sfp->state_query_cbarg = NULL; |
| 3787 | sfp->media = NULL; |
| 3788 | sfp->portspeed = BFA_PORT_SPEED_UNKNOWN; |
| 3789 | sfp->is_elb = BFA_FALSE; |
| 3790 | |
| 3791 | bfa_ioc_mbox_regisr(sfp->ioc, BFI_MC_SFP, bfa_sfp_intr, sfp); |
| 3792 | bfa_q_qe_init(&sfp->ioc_notify); |
| 3793 | bfa_ioc_notify_init(&sfp->ioc_notify, bfa_sfp_notify, sfp); |
| 3794 | list_add_tail(&sfp->ioc_notify.qe, &sfp->ioc->notify_q); |
| 3795 | } |
| 3796 | |
| 3797 | /* |
| 3798 | * Claim Memory for SFP |
| 3799 | */ |
| 3800 | void |
| 3801 | bfa_sfp_memclaim(struct bfa_sfp_s *sfp, u8 *dm_kva, u64 dm_pa) |
| 3802 | { |
| 3803 | sfp->dbuf_kva = dm_kva; |
| 3804 | sfp->dbuf_pa = dm_pa; |
| 3805 | memset(sfp->dbuf_kva, 0, sizeof(struct sfp_mem_s)); |
| 3806 | |
| 3807 | dm_kva += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ); |
| 3808 | dm_pa += BFA_ROUNDUP(sizeof(struct sfp_mem_s), BFA_DMA_ALIGN_SZ); |
| 3809 | } |
| 3810 | |
| 3811 | /* |
| 3812 | * Show SFP eeprom content |
| 3813 | * |
| 3814 | * @param[in] sfp - bfa sfp module |
| 3815 | * |
| 3816 | * @param[out] sfpmem - sfp eeprom data |
| 3817 | * |
| 3818 | */ |
| 3819 | bfa_status_t |
| 3820 | bfa_sfp_show(struct bfa_sfp_s *sfp, struct sfp_mem_s *sfpmem, |
| 3821 | bfa_cb_sfp_t cbfn, void *cbarg) |
| 3822 | { |
| 3823 | |
| 3824 | if (!bfa_ioc_is_operational(sfp->ioc)) { |
| 3825 | bfa_trc(sfp, 0); |
| 3826 | return BFA_STATUS_IOC_NON_OP; |
| 3827 | } |
| 3828 | |
| 3829 | if (sfp->lock) { |
| 3830 | bfa_trc(sfp, 0); |
| 3831 | return BFA_STATUS_DEVBUSY; |
| 3832 | } |
| 3833 | |
| 3834 | sfp->cbfn = cbfn; |
| 3835 | sfp->cbarg = cbarg; |
| 3836 | sfp->sfpmem = sfpmem; |
| 3837 | |
| 3838 | bfa_sfp_getdata(sfp, BFI_SFP_MEM_DIAGEXT); |
| 3839 | return BFA_STATUS_OK; |
| 3840 | } |
| 3841 | |
| 3842 | /* |
| 3843 | * Return SFP Media type |
| 3844 | * |
| 3845 | * @param[in] sfp - bfa sfp module |
| 3846 | * |
| 3847 | * @param[out] media - port speed from user |
| 3848 | * |
| 3849 | */ |
| 3850 | bfa_status_t |
| 3851 | bfa_sfp_media(struct bfa_sfp_s *sfp, enum bfa_defs_sfp_media_e *media, |
| 3852 | bfa_cb_sfp_t cbfn, void *cbarg) |
| 3853 | { |
| 3854 | if (!bfa_ioc_is_operational(sfp->ioc)) { |
| 3855 | bfa_trc(sfp, 0); |
| 3856 | return BFA_STATUS_IOC_NON_OP; |
| 3857 | } |
| 3858 | |
| 3859 | sfp->media = media; |
| 3860 | if (sfp->state == BFA_SFP_STATE_INIT) { |
| 3861 | if (sfp->state_query_lock) { |
| 3862 | bfa_trc(sfp, 0); |
| 3863 | return BFA_STATUS_DEVBUSY; |
| 3864 | } else { |
| 3865 | sfp->state_query_cbfn = cbfn; |
| 3866 | sfp->state_query_cbarg = cbarg; |
| 3867 | bfa_sfp_state_query(sfp); |
| 3868 | return BFA_STATUS_SFP_NOT_READY; |
| 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | bfa_sfp_media_get(sfp); |
| 3873 | return BFA_STATUS_OK; |
| 3874 | } |
| 3875 | |
| 3876 | /* |
| 3877 | * Check if user set port speed is allowed by the SFP |
| 3878 | * |
| 3879 | * @param[in] sfp - bfa sfp module |
| 3880 | * @param[in] portspeed - port speed from user |
| 3881 | * |
| 3882 | */ |
| 3883 | bfa_status_t |
| 3884 | bfa_sfp_speed(struct bfa_sfp_s *sfp, enum bfa_port_speed portspeed, |
| 3885 | bfa_cb_sfp_t cbfn, void *cbarg) |
| 3886 | { |
| 3887 | WARN_ON(portspeed == BFA_PORT_SPEED_UNKNOWN); |
| 3888 | |
| 3889 | if (!bfa_ioc_is_operational(sfp->ioc)) |
| 3890 | return BFA_STATUS_IOC_NON_OP; |
| 3891 | |
| 3892 | /* For Mezz card, all speed is allowed */ |
| 3893 | if (bfa_mfg_is_mezz(sfp->ioc->attr->card_type)) |
| 3894 | return BFA_STATUS_OK; |
| 3895 | |
| 3896 | /* Check SFP state */ |
| 3897 | sfp->portspeed = portspeed; |
| 3898 | if (sfp->state == BFA_SFP_STATE_INIT) { |
| 3899 | if (sfp->state_query_lock) { |
| 3900 | bfa_trc(sfp, 0); |
| 3901 | return BFA_STATUS_DEVBUSY; |
| 3902 | } else { |
| 3903 | sfp->state_query_cbfn = cbfn; |
| 3904 | sfp->state_query_cbarg = cbarg; |
| 3905 | bfa_sfp_state_query(sfp); |
| 3906 | return BFA_STATUS_SFP_NOT_READY; |
| 3907 | } |
| 3908 | } |
| 3909 | |
| 3910 | if (sfp->state == BFA_SFP_STATE_REMOVED || |
| 3911 | sfp->state == BFA_SFP_STATE_FAILED) { |
| 3912 | bfa_trc(sfp, sfp->state); |
| 3913 | return BFA_STATUS_NO_SFP_DEV; |
| 3914 | } |
| 3915 | |
| 3916 | if (sfp->state == BFA_SFP_STATE_INSERTED) { |
| 3917 | bfa_trc(sfp, sfp->state); |
| 3918 | return BFA_STATUS_DEVBUSY; /* sfp is reading data */ |
| 3919 | } |
| 3920 | |
| 3921 | /* For eloopback, all speed is allowed */ |
| 3922 | if (sfp->is_elb) |
| 3923 | return BFA_STATUS_OK; |
| 3924 | |
| 3925 | return bfa_sfp_speed_valid(sfp, portspeed); |
| 3926 | } |
Krishna Gudipati | 5a54b1d | 2011-06-24 20:27:13 -0700 | [diff] [blame] | 3927 | |
| 3928 | /* |
| 3929 | * Flash module specific |
| 3930 | */ |
| 3931 | |
| 3932 | /* |
| 3933 | * FLASH DMA buffer should be big enough to hold both MFG block and |
| 3934 | * asic block(64k) at the same time and also should be 2k aligned to |
| 3935 | * avoid write segement to cross sector boundary. |
| 3936 | */ |
| 3937 | #define BFA_FLASH_SEG_SZ 2048 |
| 3938 | #define BFA_FLASH_DMA_BUF_SZ \ |
| 3939 | BFA_ROUNDUP(0x010000 + sizeof(struct bfa_mfg_block_s), BFA_FLASH_SEG_SZ) |
| 3940 | |
| 3941 | static void |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 3942 | bfa_flash_aen_audit_post(struct bfa_ioc_s *ioc, enum bfa_audit_aen_event event, |
| 3943 | int inst, int type) |
| 3944 | { |
| 3945 | struct bfad_s *bfad = (struct bfad_s *)ioc->bfa->bfad; |
| 3946 | struct bfa_aen_entry_s *aen_entry; |
| 3947 | |
| 3948 | bfad_get_aen_entry(bfad, aen_entry); |
| 3949 | if (!aen_entry) |
| 3950 | return; |
| 3951 | |
| 3952 | aen_entry->aen_data.audit.pwwn = ioc->attr->pwwn; |
| 3953 | aen_entry->aen_data.audit.partition_inst = inst; |
| 3954 | aen_entry->aen_data.audit.partition_type = type; |
| 3955 | |
| 3956 | /* Send the AEN notification */ |
| 3957 | bfad_im_post_vendor_event(aen_entry, bfad, ++ioc->ioc_aen_seq, |
| 3958 | BFA_AEN_CAT_AUDIT, event); |
| 3959 | } |
| 3960 | |
| 3961 | static void |
Krishna Gudipati | 5a54b1d | 2011-06-24 20:27:13 -0700 | [diff] [blame] | 3962 | bfa_flash_cb(struct bfa_flash_s *flash) |
| 3963 | { |
| 3964 | flash->op_busy = 0; |
| 3965 | if (flash->cbfn) |
| 3966 | flash->cbfn(flash->cbarg, flash->status); |
| 3967 | } |
| 3968 | |
| 3969 | static void |
| 3970 | bfa_flash_notify(void *cbarg, enum bfa_ioc_event_e event) |
| 3971 | { |
| 3972 | struct bfa_flash_s *flash = cbarg; |
| 3973 | |
| 3974 | bfa_trc(flash, event); |
| 3975 | switch (event) { |
| 3976 | case BFA_IOC_E_DISABLED: |
| 3977 | case BFA_IOC_E_FAILED: |
| 3978 | if (flash->op_busy) { |
| 3979 | flash->status = BFA_STATUS_IOC_FAILURE; |
| 3980 | flash->cbfn(flash->cbarg, flash->status); |
| 3981 | flash->op_busy = 0; |
| 3982 | } |
| 3983 | break; |
| 3984 | |
| 3985 | default: |
| 3986 | break; |
| 3987 | } |
| 3988 | } |
| 3989 | |
| 3990 | /* |
| 3991 | * Send flash attribute query request. |
| 3992 | * |
| 3993 | * @param[in] cbarg - callback argument |
| 3994 | */ |
| 3995 | static void |
| 3996 | bfa_flash_query_send(void *cbarg) |
| 3997 | { |
| 3998 | struct bfa_flash_s *flash = cbarg; |
| 3999 | struct bfi_flash_query_req_s *msg = |
| 4000 | (struct bfi_flash_query_req_s *) flash->mb.msg; |
| 4001 | |
| 4002 | bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_QUERY_REQ, |
| 4003 | bfa_ioc_portid(flash->ioc)); |
| 4004 | bfa_alen_set(&msg->alen, sizeof(struct bfa_flash_attr_s), |
| 4005 | flash->dbuf_pa); |
| 4006 | bfa_ioc_mbox_queue(flash->ioc, &flash->mb); |
| 4007 | } |
| 4008 | |
| 4009 | /* |
| 4010 | * Send flash write request. |
| 4011 | * |
| 4012 | * @param[in] cbarg - callback argument |
| 4013 | */ |
| 4014 | static void |
| 4015 | bfa_flash_write_send(struct bfa_flash_s *flash) |
| 4016 | { |
| 4017 | struct bfi_flash_write_req_s *msg = |
| 4018 | (struct bfi_flash_write_req_s *) flash->mb.msg; |
| 4019 | u32 len; |
| 4020 | |
| 4021 | msg->type = be32_to_cpu(flash->type); |
| 4022 | msg->instance = flash->instance; |
| 4023 | msg->offset = be32_to_cpu(flash->addr_off + flash->offset); |
| 4024 | len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ? |
| 4025 | flash->residue : BFA_FLASH_DMA_BUF_SZ; |
| 4026 | msg->length = be32_to_cpu(len); |
| 4027 | |
| 4028 | /* indicate if it's the last msg of the whole write operation */ |
| 4029 | msg->last = (len == flash->residue) ? 1 : 0; |
| 4030 | |
| 4031 | bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_WRITE_REQ, |
| 4032 | bfa_ioc_portid(flash->ioc)); |
| 4033 | bfa_alen_set(&msg->alen, len, flash->dbuf_pa); |
| 4034 | memcpy(flash->dbuf_kva, flash->ubuf + flash->offset, len); |
| 4035 | bfa_ioc_mbox_queue(flash->ioc, &flash->mb); |
| 4036 | |
| 4037 | flash->residue -= len; |
| 4038 | flash->offset += len; |
| 4039 | } |
| 4040 | |
| 4041 | /* |
| 4042 | * Send flash read request. |
| 4043 | * |
| 4044 | * @param[in] cbarg - callback argument |
| 4045 | */ |
| 4046 | static void |
| 4047 | bfa_flash_read_send(void *cbarg) |
| 4048 | { |
| 4049 | struct bfa_flash_s *flash = cbarg; |
| 4050 | struct bfi_flash_read_req_s *msg = |
| 4051 | (struct bfi_flash_read_req_s *) flash->mb.msg; |
| 4052 | u32 len; |
| 4053 | |
| 4054 | msg->type = be32_to_cpu(flash->type); |
| 4055 | msg->instance = flash->instance; |
| 4056 | msg->offset = be32_to_cpu(flash->addr_off + flash->offset); |
| 4057 | len = (flash->residue < BFA_FLASH_DMA_BUF_SZ) ? |
| 4058 | flash->residue : BFA_FLASH_DMA_BUF_SZ; |
| 4059 | msg->length = be32_to_cpu(len); |
| 4060 | bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_READ_REQ, |
| 4061 | bfa_ioc_portid(flash->ioc)); |
| 4062 | bfa_alen_set(&msg->alen, len, flash->dbuf_pa); |
| 4063 | bfa_ioc_mbox_queue(flash->ioc, &flash->mb); |
| 4064 | } |
| 4065 | |
| 4066 | /* |
| 4067 | * Send flash erase request. |
| 4068 | * |
| 4069 | * @param[in] cbarg - callback argument |
| 4070 | */ |
| 4071 | static void |
| 4072 | bfa_flash_erase_send(void *cbarg) |
| 4073 | { |
| 4074 | struct bfa_flash_s *flash = cbarg; |
| 4075 | struct bfi_flash_erase_req_s *msg = |
| 4076 | (struct bfi_flash_erase_req_s *) flash->mb.msg; |
| 4077 | |
| 4078 | msg->type = be32_to_cpu(flash->type); |
| 4079 | msg->instance = flash->instance; |
| 4080 | bfi_h2i_set(msg->mh, BFI_MC_FLASH, BFI_FLASH_H2I_ERASE_REQ, |
| 4081 | bfa_ioc_portid(flash->ioc)); |
| 4082 | bfa_ioc_mbox_queue(flash->ioc, &flash->mb); |
| 4083 | } |
| 4084 | |
| 4085 | /* |
| 4086 | * Process flash response messages upon receiving interrupts. |
| 4087 | * |
| 4088 | * @param[in] flasharg - flash structure |
| 4089 | * @param[in] msg - message structure |
| 4090 | */ |
| 4091 | static void |
| 4092 | bfa_flash_intr(void *flasharg, struct bfi_mbmsg_s *msg) |
| 4093 | { |
| 4094 | struct bfa_flash_s *flash = flasharg; |
| 4095 | u32 status; |
| 4096 | |
| 4097 | union { |
| 4098 | struct bfi_flash_query_rsp_s *query; |
| 4099 | struct bfi_flash_erase_rsp_s *erase; |
| 4100 | struct bfi_flash_write_rsp_s *write; |
| 4101 | struct bfi_flash_read_rsp_s *read; |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 4102 | struct bfi_flash_event_s *event; |
Krishna Gudipati | 5a54b1d | 2011-06-24 20:27:13 -0700 | [diff] [blame] | 4103 | struct bfi_mbmsg_s *msg; |
| 4104 | } m; |
| 4105 | |
| 4106 | m.msg = msg; |
| 4107 | bfa_trc(flash, msg->mh.msg_id); |
| 4108 | |
| 4109 | if (!flash->op_busy && msg->mh.msg_id != BFI_FLASH_I2H_EVENT) { |
| 4110 | /* receiving response after ioc failure */ |
| 4111 | bfa_trc(flash, 0x9999); |
| 4112 | return; |
| 4113 | } |
| 4114 | |
| 4115 | switch (msg->mh.msg_id) { |
| 4116 | case BFI_FLASH_I2H_QUERY_RSP: |
| 4117 | status = be32_to_cpu(m.query->status); |
| 4118 | bfa_trc(flash, status); |
| 4119 | if (status == BFA_STATUS_OK) { |
| 4120 | u32 i; |
| 4121 | struct bfa_flash_attr_s *attr, *f; |
| 4122 | |
| 4123 | attr = (struct bfa_flash_attr_s *) flash->ubuf; |
| 4124 | f = (struct bfa_flash_attr_s *) flash->dbuf_kva; |
| 4125 | attr->status = be32_to_cpu(f->status); |
| 4126 | attr->npart = be32_to_cpu(f->npart); |
| 4127 | bfa_trc(flash, attr->status); |
| 4128 | bfa_trc(flash, attr->npart); |
| 4129 | for (i = 0; i < attr->npart; i++) { |
| 4130 | attr->part[i].part_type = |
| 4131 | be32_to_cpu(f->part[i].part_type); |
| 4132 | attr->part[i].part_instance = |
| 4133 | be32_to_cpu(f->part[i].part_instance); |
| 4134 | attr->part[i].part_off = |
| 4135 | be32_to_cpu(f->part[i].part_off); |
| 4136 | attr->part[i].part_size = |
| 4137 | be32_to_cpu(f->part[i].part_size); |
| 4138 | attr->part[i].part_len = |
| 4139 | be32_to_cpu(f->part[i].part_len); |
| 4140 | attr->part[i].part_status = |
| 4141 | be32_to_cpu(f->part[i].part_status); |
| 4142 | } |
| 4143 | } |
| 4144 | flash->status = status; |
| 4145 | bfa_flash_cb(flash); |
| 4146 | break; |
| 4147 | case BFI_FLASH_I2H_ERASE_RSP: |
| 4148 | status = be32_to_cpu(m.erase->status); |
| 4149 | bfa_trc(flash, status); |
| 4150 | flash->status = status; |
| 4151 | bfa_flash_cb(flash); |
| 4152 | break; |
| 4153 | case BFI_FLASH_I2H_WRITE_RSP: |
| 4154 | status = be32_to_cpu(m.write->status); |
| 4155 | bfa_trc(flash, status); |
| 4156 | if (status != BFA_STATUS_OK || flash->residue == 0) { |
| 4157 | flash->status = status; |
| 4158 | bfa_flash_cb(flash); |
| 4159 | } else { |
| 4160 | bfa_trc(flash, flash->offset); |
| 4161 | bfa_flash_write_send(flash); |
| 4162 | } |
| 4163 | break; |
| 4164 | case BFI_FLASH_I2H_READ_RSP: |
| 4165 | status = be32_to_cpu(m.read->status); |
| 4166 | bfa_trc(flash, status); |
| 4167 | if (status != BFA_STATUS_OK) { |
| 4168 | flash->status = status; |
| 4169 | bfa_flash_cb(flash); |
| 4170 | } else { |
| 4171 | u32 len = be32_to_cpu(m.read->length); |
| 4172 | bfa_trc(flash, flash->offset); |
| 4173 | bfa_trc(flash, len); |
| 4174 | memcpy(flash->ubuf + flash->offset, |
| 4175 | flash->dbuf_kva, len); |
| 4176 | flash->residue -= len; |
| 4177 | flash->offset += len; |
| 4178 | if (flash->residue == 0) { |
| 4179 | flash->status = status; |
| 4180 | bfa_flash_cb(flash); |
| 4181 | } else |
| 4182 | bfa_flash_read_send(flash); |
| 4183 | } |
| 4184 | break; |
| 4185 | case BFI_FLASH_I2H_BOOT_VER_RSP: |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 4186 | break; |
Krishna Gudipati | 5a54b1d | 2011-06-24 20:27:13 -0700 | [diff] [blame] | 4187 | case BFI_FLASH_I2H_EVENT: |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 4188 | status = be32_to_cpu(m.event->status); |
| 4189 | bfa_trc(flash, status); |
| 4190 | if (status == BFA_STATUS_BAD_FWCFG) |
| 4191 | bfa_ioc_aen_post(flash->ioc, BFA_IOC_AEN_FWCFG_ERROR); |
| 4192 | else if (status == BFA_STATUS_INVALID_VENDOR) { |
| 4193 | u32 param; |
| 4194 | param = be32_to_cpu(m.event->param); |
| 4195 | bfa_trc(flash, param); |
| 4196 | bfa_ioc_aen_post(flash->ioc, |
| 4197 | BFA_IOC_AEN_INVALID_VENDOR); |
| 4198 | } |
Krishna Gudipati | 5a54b1d | 2011-06-24 20:27:13 -0700 | [diff] [blame] | 4199 | break; |
| 4200 | |
| 4201 | default: |
| 4202 | WARN_ON(1); |
| 4203 | } |
| 4204 | } |
| 4205 | |
| 4206 | /* |
| 4207 | * Flash memory info API. |
| 4208 | * |
| 4209 | * @param[in] mincfg - minimal cfg variable |
| 4210 | */ |
| 4211 | u32 |
| 4212 | bfa_flash_meminfo(bfa_boolean_t mincfg) |
| 4213 | { |
| 4214 | /* min driver doesn't need flash */ |
| 4215 | if (mincfg) |
| 4216 | return 0; |
| 4217 | return BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ); |
| 4218 | } |
| 4219 | |
| 4220 | /* |
| 4221 | * Flash attach API. |
| 4222 | * |
| 4223 | * @param[in] flash - flash structure |
| 4224 | * @param[in] ioc - ioc structure |
| 4225 | * @param[in] dev - device structure |
| 4226 | * @param[in] trcmod - trace module |
| 4227 | * @param[in] logmod - log module |
| 4228 | */ |
| 4229 | void |
| 4230 | bfa_flash_attach(struct bfa_flash_s *flash, struct bfa_ioc_s *ioc, void *dev, |
| 4231 | struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg) |
| 4232 | { |
| 4233 | flash->ioc = ioc; |
| 4234 | flash->trcmod = trcmod; |
| 4235 | flash->cbfn = NULL; |
| 4236 | flash->cbarg = NULL; |
| 4237 | flash->op_busy = 0; |
| 4238 | |
| 4239 | bfa_ioc_mbox_regisr(flash->ioc, BFI_MC_FLASH, bfa_flash_intr, flash); |
| 4240 | bfa_q_qe_init(&flash->ioc_notify); |
| 4241 | bfa_ioc_notify_init(&flash->ioc_notify, bfa_flash_notify, flash); |
| 4242 | list_add_tail(&flash->ioc_notify.qe, &flash->ioc->notify_q); |
| 4243 | |
| 4244 | /* min driver doesn't need flash */ |
| 4245 | if (mincfg) { |
| 4246 | flash->dbuf_kva = NULL; |
| 4247 | flash->dbuf_pa = 0; |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | /* |
| 4252 | * Claim memory for flash |
| 4253 | * |
| 4254 | * @param[in] flash - flash structure |
| 4255 | * @param[in] dm_kva - pointer to virtual memory address |
| 4256 | * @param[in] dm_pa - physical memory address |
| 4257 | * @param[in] mincfg - minimal cfg variable |
| 4258 | */ |
| 4259 | void |
| 4260 | bfa_flash_memclaim(struct bfa_flash_s *flash, u8 *dm_kva, u64 dm_pa, |
| 4261 | bfa_boolean_t mincfg) |
| 4262 | { |
| 4263 | if (mincfg) |
| 4264 | return; |
| 4265 | |
| 4266 | flash->dbuf_kva = dm_kva; |
| 4267 | flash->dbuf_pa = dm_pa; |
| 4268 | memset(flash->dbuf_kva, 0, BFA_FLASH_DMA_BUF_SZ); |
| 4269 | dm_kva += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ); |
| 4270 | dm_pa += BFA_ROUNDUP(BFA_FLASH_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ); |
| 4271 | } |
| 4272 | |
| 4273 | /* |
| 4274 | * Get flash attribute. |
| 4275 | * |
| 4276 | * @param[in] flash - flash structure |
| 4277 | * @param[in] attr - flash attribute structure |
| 4278 | * @param[in] cbfn - callback function |
| 4279 | * @param[in] cbarg - callback argument |
| 4280 | * |
| 4281 | * Return status. |
| 4282 | */ |
| 4283 | bfa_status_t |
| 4284 | bfa_flash_get_attr(struct bfa_flash_s *flash, struct bfa_flash_attr_s *attr, |
| 4285 | bfa_cb_flash_t cbfn, void *cbarg) |
| 4286 | { |
| 4287 | bfa_trc(flash, BFI_FLASH_H2I_QUERY_REQ); |
| 4288 | |
| 4289 | if (!bfa_ioc_is_operational(flash->ioc)) |
| 4290 | return BFA_STATUS_IOC_NON_OP; |
| 4291 | |
| 4292 | if (flash->op_busy) { |
| 4293 | bfa_trc(flash, flash->op_busy); |
| 4294 | return BFA_STATUS_DEVBUSY; |
| 4295 | } |
| 4296 | |
| 4297 | flash->op_busy = 1; |
| 4298 | flash->cbfn = cbfn; |
| 4299 | flash->cbarg = cbarg; |
| 4300 | flash->ubuf = (u8 *) attr; |
| 4301 | bfa_flash_query_send(flash); |
| 4302 | |
| 4303 | return BFA_STATUS_OK; |
| 4304 | } |
| 4305 | |
| 4306 | /* |
| 4307 | * Erase flash partition. |
| 4308 | * |
| 4309 | * @param[in] flash - flash structure |
| 4310 | * @param[in] type - flash partition type |
| 4311 | * @param[in] instance - flash partition instance |
| 4312 | * @param[in] cbfn - callback function |
| 4313 | * @param[in] cbarg - callback argument |
| 4314 | * |
| 4315 | * Return status. |
| 4316 | */ |
| 4317 | bfa_status_t |
| 4318 | bfa_flash_erase_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type, |
| 4319 | u8 instance, bfa_cb_flash_t cbfn, void *cbarg) |
| 4320 | { |
| 4321 | bfa_trc(flash, BFI_FLASH_H2I_ERASE_REQ); |
| 4322 | bfa_trc(flash, type); |
| 4323 | bfa_trc(flash, instance); |
| 4324 | |
| 4325 | if (!bfa_ioc_is_operational(flash->ioc)) |
| 4326 | return BFA_STATUS_IOC_NON_OP; |
| 4327 | |
| 4328 | if (flash->op_busy) { |
| 4329 | bfa_trc(flash, flash->op_busy); |
| 4330 | return BFA_STATUS_DEVBUSY; |
| 4331 | } |
| 4332 | |
| 4333 | flash->op_busy = 1; |
| 4334 | flash->cbfn = cbfn; |
| 4335 | flash->cbarg = cbarg; |
| 4336 | flash->type = type; |
| 4337 | flash->instance = instance; |
| 4338 | |
| 4339 | bfa_flash_erase_send(flash); |
Krishna Gudipati | 7826f30 | 2011-07-20 16:59:13 -0700 | [diff] [blame] | 4340 | bfa_flash_aen_audit_post(flash->ioc, BFA_AUDIT_AEN_FLASH_ERASE, |
| 4341 | instance, type); |
Krishna Gudipati | 5a54b1d | 2011-06-24 20:27:13 -0700 | [diff] [blame] | 4342 | return BFA_STATUS_OK; |
| 4343 | } |
| 4344 | |
| 4345 | /* |
| 4346 | * Update flash partition. |
| 4347 | * |
| 4348 | * @param[in] flash - flash structure |
| 4349 | * @param[in] type - flash partition type |
| 4350 | * @param[in] instance - flash partition instance |
| 4351 | * @param[in] buf - update data buffer |
| 4352 | * @param[in] len - data buffer length |
| 4353 | * @param[in] offset - offset relative to the partition starting address |
| 4354 | * @param[in] cbfn - callback function |
| 4355 | * @param[in] cbarg - callback argument |
| 4356 | * |
| 4357 | * Return status. |
| 4358 | */ |
| 4359 | bfa_status_t |
| 4360 | bfa_flash_update_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type, |
| 4361 | u8 instance, void *buf, u32 len, u32 offset, |
| 4362 | bfa_cb_flash_t cbfn, void *cbarg) |
| 4363 | { |
| 4364 | bfa_trc(flash, BFI_FLASH_H2I_WRITE_REQ); |
| 4365 | bfa_trc(flash, type); |
| 4366 | bfa_trc(flash, instance); |
| 4367 | bfa_trc(flash, len); |
| 4368 | bfa_trc(flash, offset); |
| 4369 | |
| 4370 | if (!bfa_ioc_is_operational(flash->ioc)) |
| 4371 | return BFA_STATUS_IOC_NON_OP; |
| 4372 | |
| 4373 | /* |
| 4374 | * 'len' must be in word (4-byte) boundary |
| 4375 | * 'offset' must be in sector (16kb) boundary |
| 4376 | */ |
| 4377 | if (!len || (len & 0x03) || (offset & 0x00003FFF)) |
| 4378 | return BFA_STATUS_FLASH_BAD_LEN; |
| 4379 | |
| 4380 | if (type == BFA_FLASH_PART_MFG) |
| 4381 | return BFA_STATUS_EINVAL; |
| 4382 | |
| 4383 | if (flash->op_busy) { |
| 4384 | bfa_trc(flash, flash->op_busy); |
| 4385 | return BFA_STATUS_DEVBUSY; |
| 4386 | } |
| 4387 | |
| 4388 | flash->op_busy = 1; |
| 4389 | flash->cbfn = cbfn; |
| 4390 | flash->cbarg = cbarg; |
| 4391 | flash->type = type; |
| 4392 | flash->instance = instance; |
| 4393 | flash->residue = len; |
| 4394 | flash->offset = 0; |
| 4395 | flash->addr_off = offset; |
| 4396 | flash->ubuf = buf; |
| 4397 | |
| 4398 | bfa_flash_write_send(flash); |
| 4399 | return BFA_STATUS_OK; |
| 4400 | } |
| 4401 | |
| 4402 | /* |
| 4403 | * Read flash partition. |
| 4404 | * |
| 4405 | * @param[in] flash - flash structure |
| 4406 | * @param[in] type - flash partition type |
| 4407 | * @param[in] instance - flash partition instance |
| 4408 | * @param[in] buf - read data buffer |
| 4409 | * @param[in] len - data buffer length |
| 4410 | * @param[in] offset - offset relative to the partition starting address |
| 4411 | * @param[in] cbfn - callback function |
| 4412 | * @param[in] cbarg - callback argument |
| 4413 | * |
| 4414 | * Return status. |
| 4415 | */ |
| 4416 | bfa_status_t |
| 4417 | bfa_flash_read_part(struct bfa_flash_s *flash, enum bfa_flash_part_type type, |
| 4418 | u8 instance, void *buf, u32 len, u32 offset, |
| 4419 | bfa_cb_flash_t cbfn, void *cbarg) |
| 4420 | { |
| 4421 | bfa_trc(flash, BFI_FLASH_H2I_READ_REQ); |
| 4422 | bfa_trc(flash, type); |
| 4423 | bfa_trc(flash, instance); |
| 4424 | bfa_trc(flash, len); |
| 4425 | bfa_trc(flash, offset); |
| 4426 | |
| 4427 | if (!bfa_ioc_is_operational(flash->ioc)) |
| 4428 | return BFA_STATUS_IOC_NON_OP; |
| 4429 | |
| 4430 | /* |
| 4431 | * 'len' must be in word (4-byte) boundary |
| 4432 | * 'offset' must be in sector (16kb) boundary |
| 4433 | */ |
| 4434 | if (!len || (len & 0x03) || (offset & 0x00003FFF)) |
| 4435 | return BFA_STATUS_FLASH_BAD_LEN; |
| 4436 | |
| 4437 | if (flash->op_busy) { |
| 4438 | bfa_trc(flash, flash->op_busy); |
| 4439 | return BFA_STATUS_DEVBUSY; |
| 4440 | } |
| 4441 | |
| 4442 | flash->op_busy = 1; |
| 4443 | flash->cbfn = cbfn; |
| 4444 | flash->cbarg = cbarg; |
| 4445 | flash->type = type; |
| 4446 | flash->instance = instance; |
| 4447 | flash->residue = len; |
| 4448 | flash->offset = 0; |
| 4449 | flash->addr_off = offset; |
| 4450 | flash->ubuf = buf; |
| 4451 | bfa_flash_read_send(flash); |
| 4452 | |
| 4453 | return BFA_STATUS_OK; |
| 4454 | } |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 4455 | |
| 4456 | /* |
| 4457 | * DIAG module specific |
| 4458 | */ |
| 4459 | |
| 4460 | #define BFA_DIAG_MEMTEST_TOV 50000 /* memtest timeout in msec */ |
Krishna Gudipati | bd5a026 | 2012-03-13 17:41:02 -0700 | [diff] [blame] | 4461 | #define CT2_BFA_DIAG_MEMTEST_TOV (9*30*1000) /* 4.5 min */ |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 4462 | |
| 4463 | /* IOC event handler */ |
| 4464 | static void |
| 4465 | bfa_diag_notify(void *diag_arg, enum bfa_ioc_event_e event) |
| 4466 | { |
| 4467 | struct bfa_diag_s *diag = diag_arg; |
| 4468 | |
| 4469 | bfa_trc(diag, event); |
| 4470 | bfa_trc(diag, diag->block); |
| 4471 | bfa_trc(diag, diag->fwping.lock); |
| 4472 | bfa_trc(diag, diag->tsensor.lock); |
| 4473 | |
| 4474 | switch (event) { |
| 4475 | case BFA_IOC_E_DISABLED: |
| 4476 | case BFA_IOC_E_FAILED: |
| 4477 | if (diag->fwping.lock) { |
| 4478 | diag->fwping.status = BFA_STATUS_IOC_FAILURE; |
| 4479 | diag->fwping.cbfn(diag->fwping.cbarg, |
| 4480 | diag->fwping.status); |
| 4481 | diag->fwping.lock = 0; |
| 4482 | } |
| 4483 | |
| 4484 | if (diag->tsensor.lock) { |
| 4485 | diag->tsensor.status = BFA_STATUS_IOC_FAILURE; |
| 4486 | diag->tsensor.cbfn(diag->tsensor.cbarg, |
| 4487 | diag->tsensor.status); |
| 4488 | diag->tsensor.lock = 0; |
| 4489 | } |
| 4490 | |
| 4491 | if (diag->block) { |
| 4492 | if (diag->timer_active) { |
| 4493 | bfa_timer_stop(&diag->timer); |
| 4494 | diag->timer_active = 0; |
| 4495 | } |
| 4496 | |
| 4497 | diag->status = BFA_STATUS_IOC_FAILURE; |
| 4498 | diag->cbfn(diag->cbarg, diag->status); |
| 4499 | diag->block = 0; |
| 4500 | } |
| 4501 | break; |
| 4502 | |
| 4503 | default: |
| 4504 | break; |
| 4505 | } |
| 4506 | } |
| 4507 | |
| 4508 | static void |
| 4509 | bfa_diag_memtest_done(void *cbarg) |
| 4510 | { |
| 4511 | struct bfa_diag_s *diag = cbarg; |
| 4512 | struct bfa_ioc_s *ioc = diag->ioc; |
| 4513 | struct bfa_diag_memtest_result *res = diag->result; |
| 4514 | u32 loff = BFI_BOOT_MEMTEST_RES_ADDR; |
| 4515 | u32 pgnum, pgoff, i; |
| 4516 | |
| 4517 | pgnum = PSS_SMEM_PGNUM(ioc->ioc_regs.smem_pg0, loff); |
| 4518 | pgoff = PSS_SMEM_PGOFF(loff); |
| 4519 | |
| 4520 | writel(pgnum, ioc->ioc_regs.host_page_num_fn); |
| 4521 | |
| 4522 | for (i = 0; i < (sizeof(struct bfa_diag_memtest_result) / |
| 4523 | sizeof(u32)); i++) { |
| 4524 | /* read test result from smem */ |
| 4525 | *((u32 *) res + i) = |
| 4526 | bfa_mem_read(ioc->ioc_regs.smem_page_start, loff); |
| 4527 | loff += sizeof(u32); |
| 4528 | } |
| 4529 | |
| 4530 | /* Reset IOC fwstates to BFI_IOC_UNINIT */ |
| 4531 | bfa_ioc_reset_fwstate(ioc); |
| 4532 | |
| 4533 | res->status = swab32(res->status); |
| 4534 | bfa_trc(diag, res->status); |
| 4535 | |
| 4536 | if (res->status == BFI_BOOT_MEMTEST_RES_SIG) |
| 4537 | diag->status = BFA_STATUS_OK; |
| 4538 | else { |
| 4539 | diag->status = BFA_STATUS_MEMTEST_FAILED; |
| 4540 | res->addr = swab32(res->addr); |
| 4541 | res->exp = swab32(res->exp); |
| 4542 | res->act = swab32(res->act); |
| 4543 | res->err_status = swab32(res->err_status); |
| 4544 | res->err_status1 = swab32(res->err_status1); |
| 4545 | res->err_addr = swab32(res->err_addr); |
| 4546 | bfa_trc(diag, res->addr); |
| 4547 | bfa_trc(diag, res->exp); |
| 4548 | bfa_trc(diag, res->act); |
| 4549 | bfa_trc(diag, res->err_status); |
| 4550 | bfa_trc(diag, res->err_status1); |
| 4551 | bfa_trc(diag, res->err_addr); |
| 4552 | } |
| 4553 | diag->timer_active = 0; |
| 4554 | diag->cbfn(diag->cbarg, diag->status); |
| 4555 | diag->block = 0; |
| 4556 | } |
| 4557 | |
| 4558 | /* |
| 4559 | * Firmware ping |
| 4560 | */ |
| 4561 | |
| 4562 | /* |
| 4563 | * Perform DMA test directly |
| 4564 | */ |
| 4565 | static void |
| 4566 | diag_fwping_send(struct bfa_diag_s *diag) |
| 4567 | { |
| 4568 | struct bfi_diag_fwping_req_s *fwping_req; |
| 4569 | u32 i; |
| 4570 | |
| 4571 | bfa_trc(diag, diag->fwping.dbuf_pa); |
| 4572 | |
| 4573 | /* fill DMA area with pattern */ |
| 4574 | for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++) |
| 4575 | *((u32 *)diag->fwping.dbuf_kva + i) = diag->fwping.data; |
| 4576 | |
| 4577 | /* Fill mbox msg */ |
| 4578 | fwping_req = (struct bfi_diag_fwping_req_s *)diag->fwping.mbcmd.msg; |
| 4579 | |
| 4580 | /* Setup SG list */ |
| 4581 | bfa_alen_set(&fwping_req->alen, BFI_DIAG_DMA_BUF_SZ, |
| 4582 | diag->fwping.dbuf_pa); |
| 4583 | /* Set up dma count */ |
| 4584 | fwping_req->count = cpu_to_be32(diag->fwping.count); |
| 4585 | /* Set up data pattern */ |
| 4586 | fwping_req->data = diag->fwping.data; |
| 4587 | |
| 4588 | /* build host command */ |
| 4589 | bfi_h2i_set(fwping_req->mh, BFI_MC_DIAG, BFI_DIAG_H2I_FWPING, |
| 4590 | bfa_ioc_portid(diag->ioc)); |
| 4591 | |
| 4592 | /* send mbox cmd */ |
| 4593 | bfa_ioc_mbox_queue(diag->ioc, &diag->fwping.mbcmd); |
| 4594 | } |
| 4595 | |
| 4596 | static void |
| 4597 | diag_fwping_comp(struct bfa_diag_s *diag, |
| 4598 | struct bfi_diag_fwping_rsp_s *diag_rsp) |
| 4599 | { |
| 4600 | u32 rsp_data = diag_rsp->data; |
| 4601 | u8 rsp_dma_status = diag_rsp->dma_status; |
| 4602 | |
| 4603 | bfa_trc(diag, rsp_data); |
| 4604 | bfa_trc(diag, rsp_dma_status); |
| 4605 | |
| 4606 | if (rsp_dma_status == BFA_STATUS_OK) { |
| 4607 | u32 i, pat; |
| 4608 | pat = (diag->fwping.count & 0x1) ? ~(diag->fwping.data) : |
| 4609 | diag->fwping.data; |
| 4610 | /* Check mbox data */ |
| 4611 | if (diag->fwping.data != rsp_data) { |
| 4612 | bfa_trc(diag, rsp_data); |
| 4613 | diag->fwping.result->dmastatus = |
| 4614 | BFA_STATUS_DATACORRUPTED; |
| 4615 | diag->fwping.status = BFA_STATUS_DATACORRUPTED; |
| 4616 | diag->fwping.cbfn(diag->fwping.cbarg, |
| 4617 | diag->fwping.status); |
| 4618 | diag->fwping.lock = 0; |
| 4619 | return; |
| 4620 | } |
| 4621 | /* Check dma pattern */ |
| 4622 | for (i = 0; i < (BFI_DIAG_DMA_BUF_SZ >> 2); i++) { |
| 4623 | if (*((u32 *)diag->fwping.dbuf_kva + i) != pat) { |
| 4624 | bfa_trc(diag, i); |
| 4625 | bfa_trc(diag, pat); |
| 4626 | bfa_trc(diag, |
| 4627 | *((u32 *)diag->fwping.dbuf_kva + i)); |
| 4628 | diag->fwping.result->dmastatus = |
| 4629 | BFA_STATUS_DATACORRUPTED; |
| 4630 | diag->fwping.status = BFA_STATUS_DATACORRUPTED; |
| 4631 | diag->fwping.cbfn(diag->fwping.cbarg, |
| 4632 | diag->fwping.status); |
| 4633 | diag->fwping.lock = 0; |
| 4634 | return; |
| 4635 | } |
| 4636 | } |
| 4637 | diag->fwping.result->dmastatus = BFA_STATUS_OK; |
| 4638 | diag->fwping.status = BFA_STATUS_OK; |
| 4639 | diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status); |
| 4640 | diag->fwping.lock = 0; |
| 4641 | } else { |
| 4642 | diag->fwping.status = BFA_STATUS_HDMA_FAILED; |
| 4643 | diag->fwping.cbfn(diag->fwping.cbarg, diag->fwping.status); |
| 4644 | diag->fwping.lock = 0; |
| 4645 | } |
| 4646 | } |
| 4647 | |
| 4648 | /* |
| 4649 | * Temperature Sensor |
| 4650 | */ |
| 4651 | |
| 4652 | static void |
| 4653 | diag_tempsensor_send(struct bfa_diag_s *diag) |
| 4654 | { |
| 4655 | struct bfi_diag_ts_req_s *msg; |
| 4656 | |
| 4657 | msg = (struct bfi_diag_ts_req_s *)diag->tsensor.mbcmd.msg; |
| 4658 | bfa_trc(diag, msg->temp); |
| 4659 | /* build host command */ |
| 4660 | bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_TEMPSENSOR, |
| 4661 | bfa_ioc_portid(diag->ioc)); |
| 4662 | /* send mbox cmd */ |
| 4663 | bfa_ioc_mbox_queue(diag->ioc, &diag->tsensor.mbcmd); |
| 4664 | } |
| 4665 | |
| 4666 | static void |
| 4667 | diag_tempsensor_comp(struct bfa_diag_s *diag, bfi_diag_ts_rsp_t *rsp) |
| 4668 | { |
| 4669 | if (!diag->tsensor.lock) { |
| 4670 | /* receiving response after ioc failure */ |
| 4671 | bfa_trc(diag, diag->tsensor.lock); |
| 4672 | return; |
| 4673 | } |
| 4674 | |
| 4675 | /* |
| 4676 | * ASIC junction tempsensor is a reg read operation |
| 4677 | * it will always return OK |
| 4678 | */ |
| 4679 | diag->tsensor.temp->temp = be16_to_cpu(rsp->temp); |
| 4680 | diag->tsensor.temp->ts_junc = rsp->ts_junc; |
| 4681 | diag->tsensor.temp->ts_brd = rsp->ts_brd; |
| 4682 | diag->tsensor.temp->status = BFA_STATUS_OK; |
| 4683 | |
| 4684 | if (rsp->ts_brd) { |
| 4685 | if (rsp->status == BFA_STATUS_OK) { |
| 4686 | diag->tsensor.temp->brd_temp = |
| 4687 | be16_to_cpu(rsp->brd_temp); |
| 4688 | } else { |
| 4689 | bfa_trc(diag, rsp->status); |
| 4690 | diag->tsensor.temp->brd_temp = 0; |
| 4691 | diag->tsensor.temp->status = BFA_STATUS_DEVBUSY; |
| 4692 | } |
| 4693 | } |
| 4694 | bfa_trc(diag, rsp->ts_junc); |
| 4695 | bfa_trc(diag, rsp->temp); |
| 4696 | bfa_trc(diag, rsp->ts_brd); |
| 4697 | bfa_trc(diag, rsp->brd_temp); |
| 4698 | diag->tsensor.cbfn(diag->tsensor.cbarg, diag->tsensor.status); |
| 4699 | diag->tsensor.lock = 0; |
| 4700 | } |
| 4701 | |
| 4702 | /* |
| 4703 | * LED Test command |
| 4704 | */ |
| 4705 | static void |
| 4706 | diag_ledtest_send(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest) |
| 4707 | { |
| 4708 | struct bfi_diag_ledtest_req_s *msg; |
| 4709 | |
| 4710 | msg = (struct bfi_diag_ledtest_req_s *)diag->ledtest.mbcmd.msg; |
| 4711 | /* build host command */ |
| 4712 | bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_LEDTEST, |
| 4713 | bfa_ioc_portid(diag->ioc)); |
| 4714 | |
| 4715 | /* |
| 4716 | * convert the freq from N blinks per 10 sec to |
| 4717 | * crossbow ontime value. We do it here because division is need |
| 4718 | */ |
| 4719 | if (ledtest->freq) |
| 4720 | ledtest->freq = 500 / ledtest->freq; |
| 4721 | |
| 4722 | if (ledtest->freq == 0) |
| 4723 | ledtest->freq = 1; |
| 4724 | |
| 4725 | bfa_trc(diag, ledtest->freq); |
| 4726 | /* mcpy(&ledtest_req->req, ledtest, sizeof(bfa_diag_ledtest_t)); */ |
| 4727 | msg->cmd = (u8) ledtest->cmd; |
| 4728 | msg->color = (u8) ledtest->color; |
| 4729 | msg->portid = bfa_ioc_portid(diag->ioc); |
| 4730 | msg->led = ledtest->led; |
| 4731 | msg->freq = cpu_to_be16(ledtest->freq); |
| 4732 | |
| 4733 | /* send mbox cmd */ |
| 4734 | bfa_ioc_mbox_queue(diag->ioc, &diag->ledtest.mbcmd); |
| 4735 | } |
| 4736 | |
| 4737 | static void |
Krishna Gudipati | 8919678 | 2012-03-13 17:38:56 -0700 | [diff] [blame] | 4738 | diag_ledtest_comp(struct bfa_diag_s *diag, struct bfi_diag_ledtest_rsp_s *msg) |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 4739 | { |
| 4740 | bfa_trc(diag, diag->ledtest.lock); |
| 4741 | diag->ledtest.lock = BFA_FALSE; |
| 4742 | /* no bfa_cb_queue is needed because driver is not waiting */ |
| 4743 | } |
| 4744 | |
| 4745 | /* |
| 4746 | * Port beaconing |
| 4747 | */ |
| 4748 | static void |
| 4749 | diag_portbeacon_send(struct bfa_diag_s *diag, bfa_boolean_t beacon, u32 sec) |
| 4750 | { |
| 4751 | struct bfi_diag_portbeacon_req_s *msg; |
| 4752 | |
| 4753 | msg = (struct bfi_diag_portbeacon_req_s *)diag->beacon.mbcmd.msg; |
| 4754 | /* build host command */ |
| 4755 | bfi_h2i_set(msg->mh, BFI_MC_DIAG, BFI_DIAG_H2I_PORTBEACON, |
| 4756 | bfa_ioc_portid(diag->ioc)); |
| 4757 | msg->beacon = beacon; |
| 4758 | msg->period = cpu_to_be32(sec); |
| 4759 | /* send mbox cmd */ |
| 4760 | bfa_ioc_mbox_queue(diag->ioc, &diag->beacon.mbcmd); |
| 4761 | } |
| 4762 | |
| 4763 | static void |
| 4764 | diag_portbeacon_comp(struct bfa_diag_s *diag) |
| 4765 | { |
| 4766 | bfa_trc(diag, diag->beacon.state); |
| 4767 | diag->beacon.state = BFA_FALSE; |
| 4768 | if (diag->cbfn_beacon) |
| 4769 | diag->cbfn_beacon(diag->dev, BFA_FALSE, diag->beacon.link_e2e); |
| 4770 | } |
| 4771 | |
| 4772 | /* |
| 4773 | * Diag hmbox handler |
| 4774 | */ |
| 4775 | void |
| 4776 | bfa_diag_intr(void *diagarg, struct bfi_mbmsg_s *msg) |
| 4777 | { |
| 4778 | struct bfa_diag_s *diag = diagarg; |
| 4779 | |
| 4780 | switch (msg->mh.msg_id) { |
| 4781 | case BFI_DIAG_I2H_PORTBEACON: |
| 4782 | diag_portbeacon_comp(diag); |
| 4783 | break; |
| 4784 | case BFI_DIAG_I2H_FWPING: |
| 4785 | diag_fwping_comp(diag, (struct bfi_diag_fwping_rsp_s *) msg); |
| 4786 | break; |
| 4787 | case BFI_DIAG_I2H_TEMPSENSOR: |
| 4788 | diag_tempsensor_comp(diag, (bfi_diag_ts_rsp_t *) msg); |
| 4789 | break; |
| 4790 | case BFI_DIAG_I2H_LEDTEST: |
| 4791 | diag_ledtest_comp(diag, (struct bfi_diag_ledtest_rsp_s *) msg); |
| 4792 | break; |
| 4793 | default: |
| 4794 | bfa_trc(diag, msg->mh.msg_id); |
| 4795 | WARN_ON(1); |
| 4796 | } |
| 4797 | } |
| 4798 | |
| 4799 | /* |
| 4800 | * Gen RAM Test |
| 4801 | * |
| 4802 | * @param[in] *diag - diag data struct |
| 4803 | * @param[in] *memtest - mem test params input from upper layer, |
| 4804 | * @param[in] pattern - mem test pattern |
| 4805 | * @param[in] *result - mem test result |
| 4806 | * @param[in] cbfn - mem test callback functioin |
| 4807 | * @param[in] cbarg - callback functioin arg |
| 4808 | * |
| 4809 | * @param[out] |
| 4810 | */ |
| 4811 | bfa_status_t |
| 4812 | bfa_diag_memtest(struct bfa_diag_s *diag, struct bfa_diag_memtest_s *memtest, |
| 4813 | u32 pattern, struct bfa_diag_memtest_result *result, |
| 4814 | bfa_cb_diag_t cbfn, void *cbarg) |
| 4815 | { |
Krishna Gudipati | bd5a026 | 2012-03-13 17:41:02 -0700 | [diff] [blame] | 4816 | u32 memtest_tov; |
| 4817 | |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 4818 | bfa_trc(diag, pattern); |
| 4819 | |
| 4820 | if (!bfa_ioc_adapter_is_disabled(diag->ioc)) |
| 4821 | return BFA_STATUS_ADAPTER_ENABLED; |
| 4822 | |
| 4823 | /* check to see if there is another destructive diag cmd running */ |
| 4824 | if (diag->block) { |
| 4825 | bfa_trc(diag, diag->block); |
| 4826 | return BFA_STATUS_DEVBUSY; |
| 4827 | } else |
| 4828 | diag->block = 1; |
| 4829 | |
| 4830 | diag->result = result; |
| 4831 | diag->cbfn = cbfn; |
| 4832 | diag->cbarg = cbarg; |
| 4833 | |
| 4834 | /* download memtest code and take LPU0 out of reset */ |
| 4835 | bfa_ioc_boot(diag->ioc, BFI_FWBOOT_TYPE_MEMTEST, BFI_FWBOOT_ENV_OS); |
| 4836 | |
Krishna Gudipati | bd5a026 | 2012-03-13 17:41:02 -0700 | [diff] [blame] | 4837 | memtest_tov = (bfa_ioc_asic_gen(diag->ioc) == BFI_ASIC_GEN_CT2) ? |
| 4838 | CT2_BFA_DIAG_MEMTEST_TOV : BFA_DIAG_MEMTEST_TOV; |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 4839 | bfa_timer_begin(diag->ioc->timer_mod, &diag->timer, |
Krishna Gudipati | bd5a026 | 2012-03-13 17:41:02 -0700 | [diff] [blame] | 4840 | bfa_diag_memtest_done, diag, memtest_tov); |
Krishna Gudipati | 3d7fc66 | 2011-06-24 20:28:17 -0700 | [diff] [blame] | 4841 | diag->timer_active = 1; |
| 4842 | return BFA_STATUS_OK; |
| 4843 | } |
| 4844 | |
| 4845 | /* |
| 4846 | * DIAG firmware ping command |
| 4847 | * |
| 4848 | * @param[in] *diag - diag data struct |
| 4849 | * @param[in] cnt - dma loop count for testing PCIE |
| 4850 | * @param[in] data - data pattern to pass in fw |
| 4851 | * @param[in] *result - pt to bfa_diag_fwping_result_t data struct |
| 4852 | * @param[in] cbfn - callback function |
| 4853 | * @param[in] *cbarg - callback functioin arg |
| 4854 | * |
| 4855 | * @param[out] |
| 4856 | */ |
| 4857 | bfa_status_t |
| 4858 | bfa_diag_fwping(struct bfa_diag_s *diag, u32 cnt, u32 data, |
| 4859 | struct bfa_diag_results_fwping *result, bfa_cb_diag_t cbfn, |
| 4860 | void *cbarg) |
| 4861 | { |
| 4862 | bfa_trc(diag, cnt); |
| 4863 | bfa_trc(diag, data); |
| 4864 | |
| 4865 | if (!bfa_ioc_is_operational(diag->ioc)) |
| 4866 | return BFA_STATUS_IOC_NON_OP; |
| 4867 | |
| 4868 | if (bfa_asic_id_ct2(bfa_ioc_devid((diag->ioc))) && |
| 4869 | ((diag->ioc)->clscode == BFI_PCIFN_CLASS_ETH)) |
| 4870 | return BFA_STATUS_CMD_NOTSUPP; |
| 4871 | |
| 4872 | /* check to see if there is another destructive diag cmd running */ |
| 4873 | if (diag->block || diag->fwping.lock) { |
| 4874 | bfa_trc(diag, diag->block); |
| 4875 | bfa_trc(diag, diag->fwping.lock); |
| 4876 | return BFA_STATUS_DEVBUSY; |
| 4877 | } |
| 4878 | |
| 4879 | /* Initialization */ |
| 4880 | diag->fwping.lock = 1; |
| 4881 | diag->fwping.cbfn = cbfn; |
| 4882 | diag->fwping.cbarg = cbarg; |
| 4883 | diag->fwping.result = result; |
| 4884 | diag->fwping.data = data; |
| 4885 | diag->fwping.count = cnt; |
| 4886 | |
| 4887 | /* Init test results */ |
| 4888 | diag->fwping.result->data = 0; |
| 4889 | diag->fwping.result->status = BFA_STATUS_OK; |
| 4890 | |
| 4891 | /* kick off the first ping */ |
| 4892 | diag_fwping_send(diag); |
| 4893 | return BFA_STATUS_OK; |
| 4894 | } |
| 4895 | |
| 4896 | /* |
| 4897 | * Read Temperature Sensor |
| 4898 | * |
| 4899 | * @param[in] *diag - diag data struct |
| 4900 | * @param[in] *result - pt to bfa_diag_temp_t data struct |
| 4901 | * @param[in] cbfn - callback function |
| 4902 | * @param[in] *cbarg - callback functioin arg |
| 4903 | * |
| 4904 | * @param[out] |
| 4905 | */ |
| 4906 | bfa_status_t |
| 4907 | bfa_diag_tsensor_query(struct bfa_diag_s *diag, |
| 4908 | struct bfa_diag_results_tempsensor_s *result, |
| 4909 | bfa_cb_diag_t cbfn, void *cbarg) |
| 4910 | { |
| 4911 | /* check to see if there is a destructive diag cmd running */ |
| 4912 | if (diag->block || diag->tsensor.lock) { |
| 4913 | bfa_trc(diag, diag->block); |
| 4914 | bfa_trc(diag, diag->tsensor.lock); |
| 4915 | return BFA_STATUS_DEVBUSY; |
| 4916 | } |
| 4917 | |
| 4918 | if (!bfa_ioc_is_operational(diag->ioc)) |
| 4919 | return BFA_STATUS_IOC_NON_OP; |
| 4920 | |
| 4921 | /* Init diag mod params */ |
| 4922 | diag->tsensor.lock = 1; |
| 4923 | diag->tsensor.temp = result; |
| 4924 | diag->tsensor.cbfn = cbfn; |
| 4925 | diag->tsensor.cbarg = cbarg; |
| 4926 | |
| 4927 | /* Send msg to fw */ |
| 4928 | diag_tempsensor_send(diag); |
| 4929 | |
| 4930 | return BFA_STATUS_OK; |
| 4931 | } |
| 4932 | |
| 4933 | /* |
| 4934 | * LED Test command |
| 4935 | * |
| 4936 | * @param[in] *diag - diag data struct |
| 4937 | * @param[in] *ledtest - pt to ledtest data structure |
| 4938 | * |
| 4939 | * @param[out] |
| 4940 | */ |
| 4941 | bfa_status_t |
| 4942 | bfa_diag_ledtest(struct bfa_diag_s *diag, struct bfa_diag_ledtest_s *ledtest) |
| 4943 | { |
| 4944 | bfa_trc(diag, ledtest->cmd); |
| 4945 | |
| 4946 | if (!bfa_ioc_is_operational(diag->ioc)) |
| 4947 | return BFA_STATUS_IOC_NON_OP; |
| 4948 | |
| 4949 | if (diag->beacon.state) |
| 4950 | return BFA_STATUS_BEACON_ON; |
| 4951 | |
| 4952 | if (diag->ledtest.lock) |
| 4953 | return BFA_STATUS_LEDTEST_OP; |
| 4954 | |
| 4955 | /* Send msg to fw */ |
| 4956 | diag->ledtest.lock = BFA_TRUE; |
| 4957 | diag_ledtest_send(diag, ledtest); |
| 4958 | |
| 4959 | return BFA_STATUS_OK; |
| 4960 | } |
| 4961 | |
| 4962 | /* |
| 4963 | * Port beaconing command |
| 4964 | * |
| 4965 | * @param[in] *diag - diag data struct |
| 4966 | * @param[in] beacon - port beaconing 1:ON 0:OFF |
| 4967 | * @param[in] link_e2e_beacon - link beaconing 1:ON 0:OFF |
| 4968 | * @param[in] sec - beaconing duration in seconds |
| 4969 | * |
| 4970 | * @param[out] |
| 4971 | */ |
| 4972 | bfa_status_t |
| 4973 | bfa_diag_beacon_port(struct bfa_diag_s *diag, bfa_boolean_t beacon, |
| 4974 | bfa_boolean_t link_e2e_beacon, uint32_t sec) |
| 4975 | { |
| 4976 | bfa_trc(diag, beacon); |
| 4977 | bfa_trc(diag, link_e2e_beacon); |
| 4978 | bfa_trc(diag, sec); |
| 4979 | |
| 4980 | if (!bfa_ioc_is_operational(diag->ioc)) |
| 4981 | return BFA_STATUS_IOC_NON_OP; |
| 4982 | |
| 4983 | if (diag->ledtest.lock) |
| 4984 | return BFA_STATUS_LEDTEST_OP; |
| 4985 | |
| 4986 | if (diag->beacon.state && beacon) /* beacon alread on */ |
| 4987 | return BFA_STATUS_BEACON_ON; |
| 4988 | |
| 4989 | diag->beacon.state = beacon; |
| 4990 | diag->beacon.link_e2e = link_e2e_beacon; |
| 4991 | if (diag->cbfn_beacon) |
| 4992 | diag->cbfn_beacon(diag->dev, beacon, link_e2e_beacon); |
| 4993 | |
| 4994 | /* Send msg to fw */ |
| 4995 | diag_portbeacon_send(diag, beacon, sec); |
| 4996 | |
| 4997 | return BFA_STATUS_OK; |
| 4998 | } |
| 4999 | |
| 5000 | /* |
| 5001 | * Return DMA memory needed by diag module. |
| 5002 | */ |
| 5003 | u32 |
| 5004 | bfa_diag_meminfo(void) |
| 5005 | { |
| 5006 | return BFA_ROUNDUP(BFI_DIAG_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ); |
| 5007 | } |
| 5008 | |
| 5009 | /* |
| 5010 | * Attach virtual and physical memory for Diag. |
| 5011 | */ |
| 5012 | void |
| 5013 | bfa_diag_attach(struct bfa_diag_s *diag, struct bfa_ioc_s *ioc, void *dev, |
| 5014 | bfa_cb_diag_beacon_t cbfn_beacon, struct bfa_trc_mod_s *trcmod) |
| 5015 | { |
| 5016 | diag->dev = dev; |
| 5017 | diag->ioc = ioc; |
| 5018 | diag->trcmod = trcmod; |
| 5019 | |
| 5020 | diag->block = 0; |
| 5021 | diag->cbfn = NULL; |
| 5022 | diag->cbarg = NULL; |
| 5023 | diag->result = NULL; |
| 5024 | diag->cbfn_beacon = cbfn_beacon; |
| 5025 | |
| 5026 | bfa_ioc_mbox_regisr(diag->ioc, BFI_MC_DIAG, bfa_diag_intr, diag); |
| 5027 | bfa_q_qe_init(&diag->ioc_notify); |
| 5028 | bfa_ioc_notify_init(&diag->ioc_notify, bfa_diag_notify, diag); |
| 5029 | list_add_tail(&diag->ioc_notify.qe, &diag->ioc->notify_q); |
| 5030 | } |
| 5031 | |
| 5032 | void |
| 5033 | bfa_diag_memclaim(struct bfa_diag_s *diag, u8 *dm_kva, u64 dm_pa) |
| 5034 | { |
| 5035 | diag->fwping.dbuf_kva = dm_kva; |
| 5036 | diag->fwping.dbuf_pa = dm_pa; |
| 5037 | memset(diag->fwping.dbuf_kva, 0, BFI_DIAG_DMA_BUF_SZ); |
| 5038 | } |
Krishna Gudipati | 3350d98 | 2011-06-24 20:28:37 -0700 | [diff] [blame] | 5039 | |
| 5040 | /* |
| 5041 | * PHY module specific |
| 5042 | */ |
| 5043 | #define BFA_PHY_DMA_BUF_SZ 0x02000 /* 8k dma buffer */ |
| 5044 | #define BFA_PHY_LOCK_STATUS 0x018878 /* phy semaphore status reg */ |
| 5045 | |
| 5046 | static void |
| 5047 | bfa_phy_ntoh32(u32 *obuf, u32 *ibuf, int sz) |
| 5048 | { |
| 5049 | int i, m = sz >> 2; |
| 5050 | |
| 5051 | for (i = 0; i < m; i++) |
| 5052 | obuf[i] = be32_to_cpu(ibuf[i]); |
| 5053 | } |
| 5054 | |
| 5055 | static bfa_boolean_t |
| 5056 | bfa_phy_present(struct bfa_phy_s *phy) |
| 5057 | { |
| 5058 | return (phy->ioc->attr->card_type == BFA_MFG_TYPE_LIGHTNING); |
| 5059 | } |
| 5060 | |
| 5061 | static void |
| 5062 | bfa_phy_notify(void *cbarg, enum bfa_ioc_event_e event) |
| 5063 | { |
| 5064 | struct bfa_phy_s *phy = cbarg; |
| 5065 | |
| 5066 | bfa_trc(phy, event); |
| 5067 | |
| 5068 | switch (event) { |
| 5069 | case BFA_IOC_E_DISABLED: |
| 5070 | case BFA_IOC_E_FAILED: |
| 5071 | if (phy->op_busy) { |
| 5072 | phy->status = BFA_STATUS_IOC_FAILURE; |
| 5073 | phy->cbfn(phy->cbarg, phy->status); |
| 5074 | phy->op_busy = 0; |
| 5075 | } |
| 5076 | break; |
| 5077 | |
| 5078 | default: |
| 5079 | break; |
| 5080 | } |
| 5081 | } |
| 5082 | |
| 5083 | /* |
| 5084 | * Send phy attribute query request. |
| 5085 | * |
| 5086 | * @param[in] cbarg - callback argument |
| 5087 | */ |
| 5088 | static void |
| 5089 | bfa_phy_query_send(void *cbarg) |
| 5090 | { |
| 5091 | struct bfa_phy_s *phy = cbarg; |
| 5092 | struct bfi_phy_query_req_s *msg = |
| 5093 | (struct bfi_phy_query_req_s *) phy->mb.msg; |
| 5094 | |
| 5095 | msg->instance = phy->instance; |
| 5096 | bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_QUERY_REQ, |
| 5097 | bfa_ioc_portid(phy->ioc)); |
| 5098 | bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_attr_s), phy->dbuf_pa); |
| 5099 | bfa_ioc_mbox_queue(phy->ioc, &phy->mb); |
| 5100 | } |
| 5101 | |
| 5102 | /* |
| 5103 | * Send phy write request. |
| 5104 | * |
| 5105 | * @param[in] cbarg - callback argument |
| 5106 | */ |
| 5107 | static void |
| 5108 | bfa_phy_write_send(void *cbarg) |
| 5109 | { |
| 5110 | struct bfa_phy_s *phy = cbarg; |
| 5111 | struct bfi_phy_write_req_s *msg = |
| 5112 | (struct bfi_phy_write_req_s *) phy->mb.msg; |
| 5113 | u32 len; |
| 5114 | u16 *buf, *dbuf; |
| 5115 | int i, sz; |
| 5116 | |
| 5117 | msg->instance = phy->instance; |
| 5118 | msg->offset = cpu_to_be32(phy->addr_off + phy->offset); |
| 5119 | len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ? |
| 5120 | phy->residue : BFA_PHY_DMA_BUF_SZ; |
| 5121 | msg->length = cpu_to_be32(len); |
| 5122 | |
| 5123 | /* indicate if it's the last msg of the whole write operation */ |
| 5124 | msg->last = (len == phy->residue) ? 1 : 0; |
| 5125 | |
| 5126 | bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_WRITE_REQ, |
| 5127 | bfa_ioc_portid(phy->ioc)); |
| 5128 | bfa_alen_set(&msg->alen, len, phy->dbuf_pa); |
| 5129 | |
| 5130 | buf = (u16 *) (phy->ubuf + phy->offset); |
| 5131 | dbuf = (u16 *)phy->dbuf_kva; |
| 5132 | sz = len >> 1; |
| 5133 | for (i = 0; i < sz; i++) |
| 5134 | buf[i] = cpu_to_be16(dbuf[i]); |
| 5135 | |
| 5136 | bfa_ioc_mbox_queue(phy->ioc, &phy->mb); |
| 5137 | |
| 5138 | phy->residue -= len; |
| 5139 | phy->offset += len; |
| 5140 | } |
| 5141 | |
| 5142 | /* |
| 5143 | * Send phy read request. |
| 5144 | * |
| 5145 | * @param[in] cbarg - callback argument |
| 5146 | */ |
| 5147 | static void |
| 5148 | bfa_phy_read_send(void *cbarg) |
| 5149 | { |
| 5150 | struct bfa_phy_s *phy = cbarg; |
| 5151 | struct bfi_phy_read_req_s *msg = |
| 5152 | (struct bfi_phy_read_req_s *) phy->mb.msg; |
| 5153 | u32 len; |
| 5154 | |
| 5155 | msg->instance = phy->instance; |
| 5156 | msg->offset = cpu_to_be32(phy->addr_off + phy->offset); |
| 5157 | len = (phy->residue < BFA_PHY_DMA_BUF_SZ) ? |
| 5158 | phy->residue : BFA_PHY_DMA_BUF_SZ; |
| 5159 | msg->length = cpu_to_be32(len); |
| 5160 | bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_READ_REQ, |
| 5161 | bfa_ioc_portid(phy->ioc)); |
| 5162 | bfa_alen_set(&msg->alen, len, phy->dbuf_pa); |
| 5163 | bfa_ioc_mbox_queue(phy->ioc, &phy->mb); |
| 5164 | } |
| 5165 | |
| 5166 | /* |
| 5167 | * Send phy stats request. |
| 5168 | * |
| 5169 | * @param[in] cbarg - callback argument |
| 5170 | */ |
| 5171 | static void |
| 5172 | bfa_phy_stats_send(void *cbarg) |
| 5173 | { |
| 5174 | struct bfa_phy_s *phy = cbarg; |
| 5175 | struct bfi_phy_stats_req_s *msg = |
| 5176 | (struct bfi_phy_stats_req_s *) phy->mb.msg; |
| 5177 | |
| 5178 | msg->instance = phy->instance; |
| 5179 | bfi_h2i_set(msg->mh, BFI_MC_PHY, BFI_PHY_H2I_STATS_REQ, |
| 5180 | bfa_ioc_portid(phy->ioc)); |
| 5181 | bfa_alen_set(&msg->alen, sizeof(struct bfa_phy_stats_s), phy->dbuf_pa); |
| 5182 | bfa_ioc_mbox_queue(phy->ioc, &phy->mb); |
| 5183 | } |
| 5184 | |
| 5185 | /* |
| 5186 | * Flash memory info API. |
| 5187 | * |
| 5188 | * @param[in] mincfg - minimal cfg variable |
| 5189 | */ |
| 5190 | u32 |
| 5191 | bfa_phy_meminfo(bfa_boolean_t mincfg) |
| 5192 | { |
| 5193 | /* min driver doesn't need phy */ |
| 5194 | if (mincfg) |
| 5195 | return 0; |
| 5196 | |
| 5197 | return BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ); |
| 5198 | } |
| 5199 | |
| 5200 | /* |
| 5201 | * Flash attach API. |
| 5202 | * |
| 5203 | * @param[in] phy - phy structure |
| 5204 | * @param[in] ioc - ioc structure |
| 5205 | * @param[in] dev - device structure |
| 5206 | * @param[in] trcmod - trace module |
| 5207 | * @param[in] logmod - log module |
| 5208 | */ |
| 5209 | void |
| 5210 | bfa_phy_attach(struct bfa_phy_s *phy, struct bfa_ioc_s *ioc, void *dev, |
| 5211 | struct bfa_trc_mod_s *trcmod, bfa_boolean_t mincfg) |
| 5212 | { |
| 5213 | phy->ioc = ioc; |
| 5214 | phy->trcmod = trcmod; |
| 5215 | phy->cbfn = NULL; |
| 5216 | phy->cbarg = NULL; |
| 5217 | phy->op_busy = 0; |
| 5218 | |
| 5219 | bfa_ioc_mbox_regisr(phy->ioc, BFI_MC_PHY, bfa_phy_intr, phy); |
| 5220 | bfa_q_qe_init(&phy->ioc_notify); |
| 5221 | bfa_ioc_notify_init(&phy->ioc_notify, bfa_phy_notify, phy); |
| 5222 | list_add_tail(&phy->ioc_notify.qe, &phy->ioc->notify_q); |
| 5223 | |
| 5224 | /* min driver doesn't need phy */ |
| 5225 | if (mincfg) { |
| 5226 | phy->dbuf_kva = NULL; |
| 5227 | phy->dbuf_pa = 0; |
| 5228 | } |
| 5229 | } |
| 5230 | |
| 5231 | /* |
| 5232 | * Claim memory for phy |
| 5233 | * |
| 5234 | * @param[in] phy - phy structure |
| 5235 | * @param[in] dm_kva - pointer to virtual memory address |
| 5236 | * @param[in] dm_pa - physical memory address |
| 5237 | * @param[in] mincfg - minimal cfg variable |
| 5238 | */ |
| 5239 | void |
| 5240 | bfa_phy_memclaim(struct bfa_phy_s *phy, u8 *dm_kva, u64 dm_pa, |
| 5241 | bfa_boolean_t mincfg) |
| 5242 | { |
| 5243 | if (mincfg) |
| 5244 | return; |
| 5245 | |
| 5246 | phy->dbuf_kva = dm_kva; |
| 5247 | phy->dbuf_pa = dm_pa; |
| 5248 | memset(phy->dbuf_kva, 0, BFA_PHY_DMA_BUF_SZ); |
| 5249 | dm_kva += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ); |
| 5250 | dm_pa += BFA_ROUNDUP(BFA_PHY_DMA_BUF_SZ, BFA_DMA_ALIGN_SZ); |
| 5251 | } |
| 5252 | |
| 5253 | bfa_boolean_t |
| 5254 | bfa_phy_busy(struct bfa_ioc_s *ioc) |
| 5255 | { |
| 5256 | void __iomem *rb; |
| 5257 | |
| 5258 | rb = bfa_ioc_bar0(ioc); |
| 5259 | return readl(rb + BFA_PHY_LOCK_STATUS); |
| 5260 | } |
| 5261 | |
| 5262 | /* |
| 5263 | * Get phy attribute. |
| 5264 | * |
| 5265 | * @param[in] phy - phy structure |
| 5266 | * @param[in] attr - phy attribute structure |
| 5267 | * @param[in] cbfn - callback function |
| 5268 | * @param[in] cbarg - callback argument |
| 5269 | * |
| 5270 | * Return status. |
| 5271 | */ |
| 5272 | bfa_status_t |
| 5273 | bfa_phy_get_attr(struct bfa_phy_s *phy, u8 instance, |
| 5274 | struct bfa_phy_attr_s *attr, bfa_cb_phy_t cbfn, void *cbarg) |
| 5275 | { |
| 5276 | bfa_trc(phy, BFI_PHY_H2I_QUERY_REQ); |
| 5277 | bfa_trc(phy, instance); |
| 5278 | |
| 5279 | if (!bfa_phy_present(phy)) |
| 5280 | return BFA_STATUS_PHY_NOT_PRESENT; |
| 5281 | |
| 5282 | if (!bfa_ioc_is_operational(phy->ioc)) |
| 5283 | return BFA_STATUS_IOC_NON_OP; |
| 5284 | |
| 5285 | if (phy->op_busy || bfa_phy_busy(phy->ioc)) { |
| 5286 | bfa_trc(phy, phy->op_busy); |
| 5287 | return BFA_STATUS_DEVBUSY; |
| 5288 | } |
| 5289 | |
| 5290 | phy->op_busy = 1; |
| 5291 | phy->cbfn = cbfn; |
| 5292 | phy->cbarg = cbarg; |
| 5293 | phy->instance = instance; |
| 5294 | phy->ubuf = (uint8_t *) attr; |
| 5295 | bfa_phy_query_send(phy); |
| 5296 | |
| 5297 | return BFA_STATUS_OK; |
| 5298 | } |
| 5299 | |
| 5300 | /* |
| 5301 | * Get phy stats. |
| 5302 | * |
| 5303 | * @param[in] phy - phy structure |
| 5304 | * @param[in] instance - phy image instance |
| 5305 | * @param[in] stats - pointer to phy stats |
| 5306 | * @param[in] cbfn - callback function |
| 5307 | * @param[in] cbarg - callback argument |
| 5308 | * |
| 5309 | * Return status. |
| 5310 | */ |
| 5311 | bfa_status_t |
| 5312 | bfa_phy_get_stats(struct bfa_phy_s *phy, u8 instance, |
| 5313 | struct bfa_phy_stats_s *stats, |
| 5314 | bfa_cb_phy_t cbfn, void *cbarg) |
| 5315 | { |
| 5316 | bfa_trc(phy, BFI_PHY_H2I_STATS_REQ); |
| 5317 | bfa_trc(phy, instance); |
| 5318 | |
| 5319 | if (!bfa_phy_present(phy)) |
| 5320 | return BFA_STATUS_PHY_NOT_PRESENT; |
| 5321 | |
| 5322 | if (!bfa_ioc_is_operational(phy->ioc)) |
| 5323 | return BFA_STATUS_IOC_NON_OP; |
| 5324 | |
| 5325 | if (phy->op_busy || bfa_phy_busy(phy->ioc)) { |
| 5326 | bfa_trc(phy, phy->op_busy); |
| 5327 | return BFA_STATUS_DEVBUSY; |
| 5328 | } |
| 5329 | |
| 5330 | phy->op_busy = 1; |
| 5331 | phy->cbfn = cbfn; |
| 5332 | phy->cbarg = cbarg; |
| 5333 | phy->instance = instance; |
| 5334 | phy->ubuf = (u8 *) stats; |
| 5335 | bfa_phy_stats_send(phy); |
| 5336 | |
| 5337 | return BFA_STATUS_OK; |
| 5338 | } |
| 5339 | |
| 5340 | /* |
| 5341 | * Update phy image. |
| 5342 | * |
| 5343 | * @param[in] phy - phy structure |
| 5344 | * @param[in] instance - phy image instance |
| 5345 | * @param[in] buf - update data buffer |
| 5346 | * @param[in] len - data buffer length |
| 5347 | * @param[in] offset - offset relative to starting address |
| 5348 | * @param[in] cbfn - callback function |
| 5349 | * @param[in] cbarg - callback argument |
| 5350 | * |
| 5351 | * Return status. |
| 5352 | */ |
| 5353 | bfa_status_t |
| 5354 | bfa_phy_update(struct bfa_phy_s *phy, u8 instance, |
| 5355 | void *buf, u32 len, u32 offset, |
| 5356 | bfa_cb_phy_t cbfn, void *cbarg) |
| 5357 | { |
| 5358 | bfa_trc(phy, BFI_PHY_H2I_WRITE_REQ); |
| 5359 | bfa_trc(phy, instance); |
| 5360 | bfa_trc(phy, len); |
| 5361 | bfa_trc(phy, offset); |
| 5362 | |
| 5363 | if (!bfa_phy_present(phy)) |
| 5364 | return BFA_STATUS_PHY_NOT_PRESENT; |
| 5365 | |
| 5366 | if (!bfa_ioc_is_operational(phy->ioc)) |
| 5367 | return BFA_STATUS_IOC_NON_OP; |
| 5368 | |
| 5369 | /* 'len' must be in word (4-byte) boundary */ |
| 5370 | if (!len || (len & 0x03)) |
| 5371 | return BFA_STATUS_FAILED; |
| 5372 | |
| 5373 | if (phy->op_busy || bfa_phy_busy(phy->ioc)) { |
| 5374 | bfa_trc(phy, phy->op_busy); |
| 5375 | return BFA_STATUS_DEVBUSY; |
| 5376 | } |
| 5377 | |
| 5378 | phy->op_busy = 1; |
| 5379 | phy->cbfn = cbfn; |
| 5380 | phy->cbarg = cbarg; |
| 5381 | phy->instance = instance; |
| 5382 | phy->residue = len; |
| 5383 | phy->offset = 0; |
| 5384 | phy->addr_off = offset; |
| 5385 | phy->ubuf = buf; |
| 5386 | |
| 5387 | bfa_phy_write_send(phy); |
| 5388 | return BFA_STATUS_OK; |
| 5389 | } |
| 5390 | |
| 5391 | /* |
| 5392 | * Read phy image. |
| 5393 | * |
| 5394 | * @param[in] phy - phy structure |
| 5395 | * @param[in] instance - phy image instance |
| 5396 | * @param[in] buf - read data buffer |
| 5397 | * @param[in] len - data buffer length |
| 5398 | * @param[in] offset - offset relative to starting address |
| 5399 | * @param[in] cbfn - callback function |
| 5400 | * @param[in] cbarg - callback argument |
| 5401 | * |
| 5402 | * Return status. |
| 5403 | */ |
| 5404 | bfa_status_t |
| 5405 | bfa_phy_read(struct bfa_phy_s *phy, u8 instance, |
| 5406 | void *buf, u32 len, u32 offset, |
| 5407 | bfa_cb_phy_t cbfn, void *cbarg) |
| 5408 | { |
| 5409 | bfa_trc(phy, BFI_PHY_H2I_READ_REQ); |
| 5410 | bfa_trc(phy, instance); |
| 5411 | bfa_trc(phy, len); |
| 5412 | bfa_trc(phy, offset); |
| 5413 | |
| 5414 | if (!bfa_phy_present(phy)) |
| 5415 | return BFA_STATUS_PHY_NOT_PRESENT; |
| 5416 | |
| 5417 | if (!bfa_ioc_is_operational(phy->ioc)) |
| 5418 | return BFA_STATUS_IOC_NON_OP; |
| 5419 | |
| 5420 | /* 'len' must be in word (4-byte) boundary */ |
| 5421 | if (!len || (len & 0x03)) |
| 5422 | return BFA_STATUS_FAILED; |
| 5423 | |
| 5424 | if (phy->op_busy || bfa_phy_busy(phy->ioc)) { |
| 5425 | bfa_trc(phy, phy->op_busy); |
| 5426 | return BFA_STATUS_DEVBUSY; |
| 5427 | } |
| 5428 | |
| 5429 | phy->op_busy = 1; |
| 5430 | phy->cbfn = cbfn; |
| 5431 | phy->cbarg = cbarg; |
| 5432 | phy->instance = instance; |
| 5433 | phy->residue = len; |
| 5434 | phy->offset = 0; |
| 5435 | phy->addr_off = offset; |
| 5436 | phy->ubuf = buf; |
| 5437 | bfa_phy_read_send(phy); |
| 5438 | |
| 5439 | return BFA_STATUS_OK; |
| 5440 | } |
| 5441 | |
| 5442 | /* |
| 5443 | * Process phy response messages upon receiving interrupts. |
| 5444 | * |
| 5445 | * @param[in] phyarg - phy structure |
| 5446 | * @param[in] msg - message structure |
| 5447 | */ |
| 5448 | void |
| 5449 | bfa_phy_intr(void *phyarg, struct bfi_mbmsg_s *msg) |
| 5450 | { |
| 5451 | struct bfa_phy_s *phy = phyarg; |
| 5452 | u32 status; |
| 5453 | |
| 5454 | union { |
| 5455 | struct bfi_phy_query_rsp_s *query; |
| 5456 | struct bfi_phy_stats_rsp_s *stats; |
| 5457 | struct bfi_phy_write_rsp_s *write; |
| 5458 | struct bfi_phy_read_rsp_s *read; |
| 5459 | struct bfi_mbmsg_s *msg; |
| 5460 | } m; |
| 5461 | |
| 5462 | m.msg = msg; |
| 5463 | bfa_trc(phy, msg->mh.msg_id); |
| 5464 | |
| 5465 | if (!phy->op_busy) { |
| 5466 | /* receiving response after ioc failure */ |
| 5467 | bfa_trc(phy, 0x9999); |
| 5468 | return; |
| 5469 | } |
| 5470 | |
| 5471 | switch (msg->mh.msg_id) { |
| 5472 | case BFI_PHY_I2H_QUERY_RSP: |
| 5473 | status = be32_to_cpu(m.query->status); |
| 5474 | bfa_trc(phy, status); |
| 5475 | |
| 5476 | if (status == BFA_STATUS_OK) { |
| 5477 | struct bfa_phy_attr_s *attr = |
| 5478 | (struct bfa_phy_attr_s *) phy->ubuf; |
| 5479 | bfa_phy_ntoh32((u32 *)attr, (u32 *)phy->dbuf_kva, |
| 5480 | sizeof(struct bfa_phy_attr_s)); |
| 5481 | bfa_trc(phy, attr->status); |
| 5482 | bfa_trc(phy, attr->length); |
| 5483 | } |
| 5484 | |
| 5485 | phy->status = status; |
| 5486 | phy->op_busy = 0; |
| 5487 | if (phy->cbfn) |
| 5488 | phy->cbfn(phy->cbarg, phy->status); |
| 5489 | break; |
| 5490 | case BFI_PHY_I2H_STATS_RSP: |
| 5491 | status = be32_to_cpu(m.stats->status); |
| 5492 | bfa_trc(phy, status); |
| 5493 | |
| 5494 | if (status == BFA_STATUS_OK) { |
| 5495 | struct bfa_phy_stats_s *stats = |
| 5496 | (struct bfa_phy_stats_s *) phy->ubuf; |
| 5497 | bfa_phy_ntoh32((u32 *)stats, (u32 *)phy->dbuf_kva, |
| 5498 | sizeof(struct bfa_phy_stats_s)); |
| 5499 | bfa_trc(phy, stats->status); |
| 5500 | } |
| 5501 | |
| 5502 | phy->status = status; |
| 5503 | phy->op_busy = 0; |
| 5504 | if (phy->cbfn) |
| 5505 | phy->cbfn(phy->cbarg, phy->status); |
| 5506 | break; |
| 5507 | case BFI_PHY_I2H_WRITE_RSP: |
| 5508 | status = be32_to_cpu(m.write->status); |
| 5509 | bfa_trc(phy, status); |
| 5510 | |
| 5511 | if (status != BFA_STATUS_OK || phy->residue == 0) { |
| 5512 | phy->status = status; |
| 5513 | phy->op_busy = 0; |
| 5514 | if (phy->cbfn) |
| 5515 | phy->cbfn(phy->cbarg, phy->status); |
| 5516 | } else { |
| 5517 | bfa_trc(phy, phy->offset); |
| 5518 | bfa_phy_write_send(phy); |
| 5519 | } |
| 5520 | break; |
| 5521 | case BFI_PHY_I2H_READ_RSP: |
| 5522 | status = be32_to_cpu(m.read->status); |
| 5523 | bfa_trc(phy, status); |
| 5524 | |
| 5525 | if (status != BFA_STATUS_OK) { |
| 5526 | phy->status = status; |
| 5527 | phy->op_busy = 0; |
| 5528 | if (phy->cbfn) |
| 5529 | phy->cbfn(phy->cbarg, phy->status); |
| 5530 | } else { |
| 5531 | u32 len = be32_to_cpu(m.read->length); |
| 5532 | u16 *buf = (u16 *)(phy->ubuf + phy->offset); |
| 5533 | u16 *dbuf = (u16 *)phy->dbuf_kva; |
| 5534 | int i, sz = len >> 1; |
| 5535 | |
| 5536 | bfa_trc(phy, phy->offset); |
| 5537 | bfa_trc(phy, len); |
| 5538 | |
| 5539 | for (i = 0; i < sz; i++) |
| 5540 | buf[i] = be16_to_cpu(dbuf[i]); |
| 5541 | |
| 5542 | phy->residue -= len; |
| 5543 | phy->offset += len; |
| 5544 | |
| 5545 | if (phy->residue == 0) { |
| 5546 | phy->status = status; |
| 5547 | phy->op_busy = 0; |
| 5548 | if (phy->cbfn) |
| 5549 | phy->cbfn(phy->cbarg, phy->status); |
| 5550 | } else |
| 5551 | bfa_phy_read_send(phy); |
| 5552 | } |
| 5553 | break; |
| 5554 | default: |
| 5555 | WARN_ON(1); |
| 5556 | } |
| 5557 | } |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5558 | |
| 5559 | /* |
| 5560 | * DCONF module specific |
| 5561 | */ |
| 5562 | |
| 5563 | BFA_MODULE(dconf); |
| 5564 | |
| 5565 | /* |
| 5566 | * DCONF state machine events |
| 5567 | */ |
| 5568 | enum bfa_dconf_event { |
| 5569 | BFA_DCONF_SM_INIT = 1, /* dconf Init */ |
| 5570 | BFA_DCONF_SM_FLASH_COMP = 2, /* read/write to flash */ |
| 5571 | BFA_DCONF_SM_WR = 3, /* binding change, map */ |
| 5572 | BFA_DCONF_SM_TIMEOUT = 4, /* Start timer */ |
| 5573 | BFA_DCONF_SM_EXIT = 5, /* exit dconf module */ |
| 5574 | BFA_DCONF_SM_IOCDISABLE = 6, /* IOC disable event */ |
| 5575 | }; |
| 5576 | |
| 5577 | /* forward declaration of DCONF state machine */ |
| 5578 | static void bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, |
| 5579 | enum bfa_dconf_event event); |
| 5580 | static void bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf, |
| 5581 | enum bfa_dconf_event event); |
| 5582 | static void bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, |
| 5583 | enum bfa_dconf_event event); |
| 5584 | static void bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf, |
| 5585 | enum bfa_dconf_event event); |
| 5586 | static void bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf, |
| 5587 | enum bfa_dconf_event event); |
| 5588 | static void bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf, |
| 5589 | enum bfa_dconf_event event); |
| 5590 | static void bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf, |
| 5591 | enum bfa_dconf_event event); |
| 5592 | |
| 5593 | static void bfa_dconf_cbfn(void *dconf, bfa_status_t status); |
| 5594 | static void bfa_dconf_timer(void *cbarg); |
| 5595 | static bfa_status_t bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf); |
| 5596 | static void bfa_dconf_init_cb(void *arg, bfa_status_t status); |
| 5597 | |
| 5598 | /* |
Anatol Pomozov | 4907cb7 | 2012-09-01 10:31:09 -0700 | [diff] [blame] | 5599 | * Beginning state of dconf module. Waiting for an event to start. |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5600 | */ |
| 5601 | static void |
| 5602 | bfa_dconf_sm_uninit(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event) |
| 5603 | { |
| 5604 | bfa_status_t bfa_status; |
| 5605 | bfa_trc(dconf->bfa, event); |
| 5606 | |
| 5607 | switch (event) { |
| 5608 | case BFA_DCONF_SM_INIT: |
| 5609 | if (dconf->min_cfg) { |
| 5610 | bfa_trc(dconf->bfa, dconf->min_cfg); |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5611 | bfa_fsm_send_event(&dconf->bfa->iocfc, |
| 5612 | IOCFC_E_DCONF_DONE); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5613 | return; |
| 5614 | } |
| 5615 | bfa_sm_set_state(dconf, bfa_dconf_sm_flash_read); |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5616 | bfa_timer_start(dconf->bfa, &dconf->timer, |
Krishna Gudipati | 7ac83b1 | 2012-09-21 17:24:21 -0700 | [diff] [blame^] | 5617 | bfa_dconf_timer, dconf, 2 * BFA_DCONF_UPDATE_TOV); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5618 | bfa_status = bfa_flash_read_part(BFA_FLASH(dconf->bfa), |
| 5619 | BFA_FLASH_PART_DRV, dconf->instance, |
| 5620 | dconf->dconf, |
| 5621 | sizeof(struct bfa_dconf_s), 0, |
| 5622 | bfa_dconf_init_cb, dconf->bfa); |
| 5623 | if (bfa_status != BFA_STATUS_OK) { |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5624 | bfa_timer_stop(&dconf->timer); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5625 | bfa_dconf_init_cb(dconf->bfa, BFA_STATUS_FAILED); |
| 5626 | bfa_sm_set_state(dconf, bfa_dconf_sm_uninit); |
| 5627 | return; |
| 5628 | } |
| 5629 | break; |
| 5630 | case BFA_DCONF_SM_EXIT: |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5631 | bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5632 | case BFA_DCONF_SM_IOCDISABLE: |
| 5633 | case BFA_DCONF_SM_WR: |
| 5634 | case BFA_DCONF_SM_FLASH_COMP: |
| 5635 | break; |
| 5636 | default: |
| 5637 | bfa_sm_fault(dconf->bfa, event); |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | /* |
| 5642 | * Read flash for dconf entries and make a call back to the driver once done. |
| 5643 | */ |
| 5644 | static void |
| 5645 | bfa_dconf_sm_flash_read(struct bfa_dconf_mod_s *dconf, |
| 5646 | enum bfa_dconf_event event) |
| 5647 | { |
| 5648 | bfa_trc(dconf->bfa, event); |
| 5649 | |
| 5650 | switch (event) { |
| 5651 | case BFA_DCONF_SM_FLASH_COMP: |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5652 | bfa_timer_stop(&dconf->timer); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5653 | bfa_sm_set_state(dconf, bfa_dconf_sm_ready); |
| 5654 | break; |
| 5655 | case BFA_DCONF_SM_TIMEOUT: |
| 5656 | bfa_sm_set_state(dconf, bfa_dconf_sm_ready); |
Krishna Gudipati | 7ac83b1 | 2012-09-21 17:24:21 -0700 | [diff] [blame^] | 5657 | bfa_ioc_suspend(&dconf->bfa->ioc); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5658 | break; |
| 5659 | case BFA_DCONF_SM_EXIT: |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5660 | bfa_timer_stop(&dconf->timer); |
| 5661 | bfa_sm_set_state(dconf, bfa_dconf_sm_uninit); |
| 5662 | bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE); |
| 5663 | break; |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5664 | case BFA_DCONF_SM_IOCDISABLE: |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5665 | bfa_timer_stop(&dconf->timer); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5666 | bfa_sm_set_state(dconf, bfa_dconf_sm_uninit); |
| 5667 | break; |
| 5668 | default: |
| 5669 | bfa_sm_fault(dconf->bfa, event); |
| 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | /* |
| 5674 | * DCONF Module is in ready state. Has completed the initialization. |
| 5675 | */ |
| 5676 | static void |
| 5677 | bfa_dconf_sm_ready(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event) |
| 5678 | { |
| 5679 | bfa_trc(dconf->bfa, event); |
| 5680 | |
| 5681 | switch (event) { |
| 5682 | case BFA_DCONF_SM_WR: |
| 5683 | bfa_timer_start(dconf->bfa, &dconf->timer, |
| 5684 | bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV); |
| 5685 | bfa_sm_set_state(dconf, bfa_dconf_sm_dirty); |
| 5686 | break; |
| 5687 | case BFA_DCONF_SM_EXIT: |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5688 | bfa_sm_set_state(dconf, bfa_dconf_sm_uninit); |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5689 | bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5690 | break; |
| 5691 | case BFA_DCONF_SM_INIT: |
| 5692 | case BFA_DCONF_SM_IOCDISABLE: |
| 5693 | break; |
| 5694 | default: |
| 5695 | bfa_sm_fault(dconf->bfa, event); |
| 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | /* |
| 5700 | * entries are dirty, write back to the flash. |
| 5701 | */ |
| 5702 | |
| 5703 | static void |
| 5704 | bfa_dconf_sm_dirty(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event) |
| 5705 | { |
| 5706 | bfa_trc(dconf->bfa, event); |
| 5707 | |
| 5708 | switch (event) { |
| 5709 | case BFA_DCONF_SM_TIMEOUT: |
| 5710 | bfa_sm_set_state(dconf, bfa_dconf_sm_sync); |
| 5711 | bfa_dconf_flash_write(dconf); |
| 5712 | break; |
| 5713 | case BFA_DCONF_SM_WR: |
| 5714 | bfa_timer_stop(&dconf->timer); |
| 5715 | bfa_timer_start(dconf->bfa, &dconf->timer, |
| 5716 | bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV); |
| 5717 | break; |
| 5718 | case BFA_DCONF_SM_EXIT: |
| 5719 | bfa_timer_stop(&dconf->timer); |
| 5720 | bfa_timer_start(dconf->bfa, &dconf->timer, |
| 5721 | bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV); |
| 5722 | bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync); |
| 5723 | bfa_dconf_flash_write(dconf); |
| 5724 | break; |
| 5725 | case BFA_DCONF_SM_FLASH_COMP: |
| 5726 | break; |
| 5727 | case BFA_DCONF_SM_IOCDISABLE: |
| 5728 | bfa_timer_stop(&dconf->timer); |
| 5729 | bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty); |
| 5730 | break; |
| 5731 | default: |
| 5732 | bfa_sm_fault(dconf->bfa, event); |
| 5733 | } |
| 5734 | } |
| 5735 | |
| 5736 | /* |
| 5737 | * Sync the dconf entries to the flash. |
| 5738 | */ |
| 5739 | static void |
| 5740 | bfa_dconf_sm_final_sync(struct bfa_dconf_mod_s *dconf, |
| 5741 | enum bfa_dconf_event event) |
| 5742 | { |
| 5743 | bfa_trc(dconf->bfa, event); |
| 5744 | |
| 5745 | switch (event) { |
| 5746 | case BFA_DCONF_SM_IOCDISABLE: |
| 5747 | case BFA_DCONF_SM_FLASH_COMP: |
| 5748 | bfa_timer_stop(&dconf->timer); |
| 5749 | case BFA_DCONF_SM_TIMEOUT: |
| 5750 | bfa_sm_set_state(dconf, bfa_dconf_sm_uninit); |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5751 | bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5752 | break; |
| 5753 | default: |
| 5754 | bfa_sm_fault(dconf->bfa, event); |
| 5755 | } |
| 5756 | } |
| 5757 | |
| 5758 | static void |
| 5759 | bfa_dconf_sm_sync(struct bfa_dconf_mod_s *dconf, enum bfa_dconf_event event) |
| 5760 | { |
| 5761 | bfa_trc(dconf->bfa, event); |
| 5762 | |
| 5763 | switch (event) { |
| 5764 | case BFA_DCONF_SM_FLASH_COMP: |
| 5765 | bfa_sm_set_state(dconf, bfa_dconf_sm_ready); |
| 5766 | break; |
| 5767 | case BFA_DCONF_SM_WR: |
| 5768 | bfa_timer_start(dconf->bfa, &dconf->timer, |
| 5769 | bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV); |
| 5770 | bfa_sm_set_state(dconf, bfa_dconf_sm_dirty); |
| 5771 | break; |
| 5772 | case BFA_DCONF_SM_EXIT: |
| 5773 | bfa_timer_start(dconf->bfa, &dconf->timer, |
| 5774 | bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV); |
| 5775 | bfa_sm_set_state(dconf, bfa_dconf_sm_final_sync); |
| 5776 | break; |
| 5777 | case BFA_DCONF_SM_IOCDISABLE: |
| 5778 | bfa_sm_set_state(dconf, bfa_dconf_sm_iocdown_dirty); |
| 5779 | break; |
| 5780 | default: |
| 5781 | bfa_sm_fault(dconf->bfa, event); |
| 5782 | } |
| 5783 | } |
| 5784 | |
| 5785 | static void |
| 5786 | bfa_dconf_sm_iocdown_dirty(struct bfa_dconf_mod_s *dconf, |
| 5787 | enum bfa_dconf_event event) |
| 5788 | { |
| 5789 | bfa_trc(dconf->bfa, event); |
| 5790 | |
| 5791 | switch (event) { |
| 5792 | case BFA_DCONF_SM_INIT: |
| 5793 | bfa_timer_start(dconf->bfa, &dconf->timer, |
| 5794 | bfa_dconf_timer, dconf, BFA_DCONF_UPDATE_TOV); |
| 5795 | bfa_sm_set_state(dconf, bfa_dconf_sm_dirty); |
| 5796 | break; |
| 5797 | case BFA_DCONF_SM_EXIT: |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5798 | bfa_sm_set_state(dconf, bfa_dconf_sm_uninit); |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5799 | bfa_fsm_send_event(&dconf->bfa->iocfc, IOCFC_E_DCONF_DONE); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5800 | break; |
| 5801 | case BFA_DCONF_SM_IOCDISABLE: |
| 5802 | break; |
| 5803 | default: |
| 5804 | bfa_sm_fault(dconf->bfa, event); |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | /* |
| 5809 | * Compute and return memory needed by DRV_CFG module. |
| 5810 | */ |
| 5811 | static void |
| 5812 | bfa_dconf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo, |
| 5813 | struct bfa_s *bfa) |
| 5814 | { |
| 5815 | struct bfa_mem_kva_s *dconf_kva = BFA_MEM_DCONF_KVA(bfa); |
| 5816 | |
| 5817 | if (cfg->drvcfg.min_cfg) |
| 5818 | bfa_mem_kva_setup(meminfo, dconf_kva, |
| 5819 | sizeof(struct bfa_dconf_hdr_s)); |
| 5820 | else |
| 5821 | bfa_mem_kva_setup(meminfo, dconf_kva, |
| 5822 | sizeof(struct bfa_dconf_s)); |
| 5823 | } |
| 5824 | |
| 5825 | static void |
| 5826 | bfa_dconf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
| 5827 | struct bfa_pcidev_s *pcidev) |
| 5828 | { |
| 5829 | struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa); |
| 5830 | |
| 5831 | dconf->bfad = bfad; |
| 5832 | dconf->bfa = bfa; |
| 5833 | dconf->instance = bfa->ioc.port_id; |
| 5834 | bfa_trc(bfa, dconf->instance); |
| 5835 | |
| 5836 | dconf->dconf = (struct bfa_dconf_s *) bfa_mem_kva_curp(dconf); |
| 5837 | if (cfg->drvcfg.min_cfg) { |
| 5838 | bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_hdr_s); |
| 5839 | dconf->min_cfg = BFA_TRUE; |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5840 | } else { |
| 5841 | dconf->min_cfg = BFA_FALSE; |
| 5842 | bfa_mem_kva_curp(dconf) += sizeof(struct bfa_dconf_s); |
| 5843 | } |
| 5844 | |
| 5845 | bfa_dconf_read_data_valid(bfa) = BFA_FALSE; |
| 5846 | bfa_sm_set_state(dconf, bfa_dconf_sm_uninit); |
| 5847 | } |
| 5848 | |
| 5849 | static void |
| 5850 | bfa_dconf_init_cb(void *arg, bfa_status_t status) |
| 5851 | { |
| 5852 | struct bfa_s *bfa = arg; |
| 5853 | struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa); |
| 5854 | |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5855 | if (status == BFA_STATUS_OK) { |
| 5856 | bfa_dconf_read_data_valid(bfa) = BFA_TRUE; |
| 5857 | if (dconf->dconf->hdr.signature != BFI_DCONF_SIGNATURE) |
| 5858 | dconf->dconf->hdr.signature = BFI_DCONF_SIGNATURE; |
| 5859 | if (dconf->dconf->hdr.version != BFI_DCONF_VERSION) |
| 5860 | dconf->dconf->hdr.version = BFI_DCONF_VERSION; |
| 5861 | } |
Krishna Gudipati | 7ac83b1 | 2012-09-21 17:24:21 -0700 | [diff] [blame^] | 5862 | bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP); |
Krishna Gudipati | db9d8a7 | 2012-03-13 17:39:36 -0700 | [diff] [blame] | 5863 | bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DCONF_DONE); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5864 | } |
| 5865 | |
| 5866 | void |
| 5867 | bfa_dconf_modinit(struct bfa_s *bfa) |
| 5868 | { |
| 5869 | struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa); |
| 5870 | bfa_sm_send_event(dconf, BFA_DCONF_SM_INIT); |
| 5871 | } |
| 5872 | static void |
| 5873 | bfa_dconf_start(struct bfa_s *bfa) |
| 5874 | { |
| 5875 | } |
| 5876 | |
| 5877 | static void |
| 5878 | bfa_dconf_stop(struct bfa_s *bfa) |
| 5879 | { |
| 5880 | } |
| 5881 | |
| 5882 | static void bfa_dconf_timer(void *cbarg) |
| 5883 | { |
| 5884 | struct bfa_dconf_mod_s *dconf = cbarg; |
| 5885 | bfa_sm_send_event(dconf, BFA_DCONF_SM_TIMEOUT); |
| 5886 | } |
| 5887 | static void |
| 5888 | bfa_dconf_iocdisable(struct bfa_s *bfa) |
| 5889 | { |
| 5890 | struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa); |
| 5891 | bfa_sm_send_event(dconf, BFA_DCONF_SM_IOCDISABLE); |
| 5892 | } |
| 5893 | |
| 5894 | static void |
| 5895 | bfa_dconf_detach(struct bfa_s *bfa) |
| 5896 | { |
| 5897 | } |
| 5898 | |
| 5899 | static bfa_status_t |
| 5900 | bfa_dconf_flash_write(struct bfa_dconf_mod_s *dconf) |
| 5901 | { |
| 5902 | bfa_status_t bfa_status; |
| 5903 | bfa_trc(dconf->bfa, 0); |
| 5904 | |
| 5905 | bfa_status = bfa_flash_update_part(BFA_FLASH(dconf->bfa), |
| 5906 | BFA_FLASH_PART_DRV, dconf->instance, |
| 5907 | dconf->dconf, sizeof(struct bfa_dconf_s), 0, |
| 5908 | bfa_dconf_cbfn, dconf); |
| 5909 | if (bfa_status != BFA_STATUS_OK) |
| 5910 | WARN_ON(bfa_status); |
| 5911 | bfa_trc(dconf->bfa, bfa_status); |
| 5912 | |
| 5913 | return bfa_status; |
| 5914 | } |
| 5915 | |
| 5916 | bfa_status_t |
| 5917 | bfa_dconf_update(struct bfa_s *bfa) |
| 5918 | { |
| 5919 | struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa); |
| 5920 | bfa_trc(dconf->bfa, 0); |
| 5921 | if (bfa_sm_cmp_state(dconf, bfa_dconf_sm_iocdown_dirty)) |
| 5922 | return BFA_STATUS_FAILED; |
| 5923 | |
| 5924 | if (dconf->min_cfg) { |
| 5925 | bfa_trc(dconf->bfa, dconf->min_cfg); |
| 5926 | return BFA_STATUS_FAILED; |
| 5927 | } |
| 5928 | |
| 5929 | bfa_sm_send_event(dconf, BFA_DCONF_SM_WR); |
| 5930 | return BFA_STATUS_OK; |
| 5931 | } |
| 5932 | |
| 5933 | static void |
| 5934 | bfa_dconf_cbfn(void *arg, bfa_status_t status) |
| 5935 | { |
| 5936 | struct bfa_dconf_mod_s *dconf = arg; |
| 5937 | WARN_ON(status); |
| 5938 | bfa_sm_send_event(dconf, BFA_DCONF_SM_FLASH_COMP); |
| 5939 | } |
| 5940 | |
| 5941 | void |
| 5942 | bfa_dconf_modexit(struct bfa_s *bfa) |
| 5943 | { |
| 5944 | struct bfa_dconf_mod_s *dconf = BFA_DCONF_MOD(bfa); |
Krishna Gudipati | 45c5dc1 | 2011-07-20 17:03:46 -0700 | [diff] [blame] | 5945 | bfa_sm_send_event(dconf, BFA_DCONF_SM_EXIT); |
| 5946 | } |