Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * |
| 3 | * Intel Ethernet Controller XL710 Family Linux Driver |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 4 | * Copyright(c) 2013 - 2014 Intel Corporation. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms and conditions of the GNU General Public License, |
| 8 | * version 2, as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
Greg Rose | dc641b7 | 2013-12-18 13:45:51 +0000 | [diff] [blame] | 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in |
| 19 | * the file called "COPYING". |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 23 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 24 | * |
| 25 | ******************************************************************************/ |
| 26 | |
| 27 | #include "i40e_prototype.h" |
| 28 | |
| 29 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 30 | * i40e_init_nvm_ops - Initialize NVM function pointers |
| 31 | * @hw: pointer to the HW structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 32 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 33 | * Setup the function pointers and the NVM info structure. Should be called |
| 34 | * once per NVM initialization, e.g. inside the i40e_init_shared_code(). |
| 35 | * Please notice that the NVM term is used here (& in all methods covered |
| 36 | * in this file) as an equivalent of the FLASH part mapped into the SR. |
| 37 | * We are accessing FLASH always thru the Shadow RAM. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 38 | **/ |
| 39 | i40e_status i40e_init_nvm(struct i40e_hw *hw) |
| 40 | { |
| 41 | struct i40e_nvm_info *nvm = &hw->nvm; |
| 42 | i40e_status ret_code = 0; |
| 43 | u32 fla, gens; |
| 44 | u8 sr_size; |
| 45 | |
| 46 | /* The SR size is stored regardless of the nvm programming mode |
| 47 | * as the blank mode may be used in the factory line. |
| 48 | */ |
| 49 | gens = rd32(hw, I40E_GLNVM_GENS); |
| 50 | sr_size = ((gens & I40E_GLNVM_GENS_SR_SIZE_MASK) >> |
| 51 | I40E_GLNVM_GENS_SR_SIZE_SHIFT); |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 52 | /* Switching to words (sr_size contains power of 2KB) */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 53 | nvm->sr_size = (1 << sr_size) * I40E_SR_WORDS_IN_1KB; |
| 54 | |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 55 | /* Check if we are in the normal or blank NVM programming mode */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 56 | fla = rd32(hw, I40E_GLNVM_FLA); |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 57 | if (fla & I40E_GLNVM_FLA_LOCKED_MASK) { /* Normal programming mode */ |
| 58 | /* Max NVM timeout */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 59 | nvm->timeout = I40E_MAX_NVM_TIMEOUT; |
| 60 | nvm->blank_nvm_mode = false; |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 61 | } else { /* Blank programming mode */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 62 | nvm->blank_nvm_mode = true; |
| 63 | ret_code = I40E_ERR_NVM_BLANK_MODE; |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 64 | i40e_debug(hw, I40E_DEBUG_NVM, "NVM init error: unsupported blank mode.\n"); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | return ret_code; |
| 68 | } |
| 69 | |
| 70 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 71 | * i40e_acquire_nvm - Generic request for acquiring the NVM ownership |
| 72 | * @hw: pointer to the HW structure |
| 73 | * @access: NVM access type (read or write) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 74 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 75 | * This function will request NVM ownership for reading |
| 76 | * via the proper Admin Command. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 77 | **/ |
| 78 | i40e_status i40e_acquire_nvm(struct i40e_hw *hw, |
| 79 | enum i40e_aq_resource_access_type access) |
| 80 | { |
| 81 | i40e_status ret_code = 0; |
| 82 | u64 gtime, timeout; |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 83 | u64 time_left = 0; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 84 | |
| 85 | if (hw->nvm.blank_nvm_mode) |
| 86 | goto i40e_i40e_acquire_nvm_exit; |
| 87 | |
| 88 | ret_code = i40e_aq_request_resource(hw, I40E_NVM_RESOURCE_ID, access, |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 89 | 0, &time_left, NULL); |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 90 | /* Reading the Global Device Timer */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 91 | gtime = rd32(hw, I40E_GLVFGEN_TIMER); |
| 92 | |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 93 | /* Store the timeout */ |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 94 | hw->nvm.hw_semaphore_timeout = I40E_MS_TO_GTIME(time_left) + gtime; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 95 | |
| 96 | if (ret_code) { |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 97 | /* Poll until the current NVM owner timeouts */ |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 98 | timeout = I40E_MS_TO_GTIME(I40E_MAX_NVM_TIMEOUT) + gtime; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 99 | while (gtime < timeout) { |
| 100 | usleep_range(10000, 20000); |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 101 | gtime = rd32(hw, I40E_GLVFGEN_TIMER); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 102 | ret_code = i40e_aq_request_resource(hw, |
| 103 | I40E_NVM_RESOURCE_ID, |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 104 | access, 0, &time_left, |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 105 | NULL); |
| 106 | if (!ret_code) { |
| 107 | hw->nvm.hw_semaphore_timeout = |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 108 | I40E_MS_TO_GTIME(time_left) + gtime; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 109 | break; |
| 110 | } |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 111 | } |
| 112 | if (ret_code) { |
| 113 | hw->nvm.hw_semaphore_timeout = 0; |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 114 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 115 | "NVM acquire timed out, wait %llu ms before trying again.\n", |
Shannon Nelson | c509c1d | 2014-11-13 08:23:19 +0000 | [diff] [blame] | 116 | time_left); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 117 | } |
| 118 | } |
| 119 | |
| 120 | i40e_i40e_acquire_nvm_exit: |
| 121 | return ret_code; |
| 122 | } |
| 123 | |
| 124 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 125 | * i40e_release_nvm - Generic request for releasing the NVM ownership |
| 126 | * @hw: pointer to the HW structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 127 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 128 | * This function will release NVM resource via the proper Admin Command. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 129 | **/ |
| 130 | void i40e_release_nvm(struct i40e_hw *hw) |
| 131 | { |
| 132 | if (!hw->nvm.blank_nvm_mode) |
| 133 | i40e_aq_release_resource(hw, I40E_NVM_RESOURCE_ID, 0, NULL); |
| 134 | } |
| 135 | |
| 136 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 137 | * i40e_poll_sr_srctl_done_bit - Polls the GLNVM_SRCTL done bit |
| 138 | * @hw: pointer to the HW structure |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 139 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 140 | * Polls the SRCTL Shadow RAM register done bit. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 141 | **/ |
| 142 | static i40e_status i40e_poll_sr_srctl_done_bit(struct i40e_hw *hw) |
| 143 | { |
| 144 | i40e_status ret_code = I40E_ERR_TIMEOUT; |
| 145 | u32 srctl, wait_cnt; |
| 146 | |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 147 | /* Poll the I40E_GLNVM_SRCTL until the done bit is set */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 148 | for (wait_cnt = 0; wait_cnt < I40E_SRRD_SRCTL_ATTEMPTS; wait_cnt++) { |
| 149 | srctl = rd32(hw, I40E_GLNVM_SRCTL); |
| 150 | if (srctl & I40E_GLNVM_SRCTL_DONE_MASK) { |
| 151 | ret_code = 0; |
| 152 | break; |
| 153 | } |
| 154 | udelay(5); |
| 155 | } |
| 156 | if (ret_code == I40E_ERR_TIMEOUT) |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 157 | i40e_debug(hw, I40E_DEBUG_NVM, "Done bit in GLNVM_SRCTL not set"); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 158 | return ret_code; |
| 159 | } |
| 160 | |
| 161 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 162 | * i40e_read_nvm_word - Reads Shadow RAM |
| 163 | * @hw: pointer to the HW structure |
| 164 | * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF) |
| 165 | * @data: word read from the Shadow RAM |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 166 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 167 | * Reads one 16 bit word from the Shadow RAM using the GLNVM_SRCTL register. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 168 | **/ |
Shannon Nelson | a4bcfbb | 2013-12-11 08:17:15 +0000 | [diff] [blame] | 169 | i40e_status i40e_read_nvm_word(struct i40e_hw *hw, u16 offset, |
| 170 | u16 *data) |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 171 | { |
| 172 | i40e_status ret_code = I40E_ERR_TIMEOUT; |
| 173 | u32 sr_reg; |
| 174 | |
| 175 | if (offset >= hw->nvm.sr_size) { |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 176 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 177 | "NVM read error: offset %d beyond Shadow RAM limit %d\n", |
| 178 | offset, hw->nvm.sr_size); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 179 | ret_code = I40E_ERR_PARAM; |
| 180 | goto read_nvm_exit; |
| 181 | } |
| 182 | |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 183 | /* Poll the done bit first */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 184 | ret_code = i40e_poll_sr_srctl_done_bit(hw); |
| 185 | if (!ret_code) { |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 186 | /* Write the address and start reading */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 187 | sr_reg = (u32)(offset << I40E_GLNVM_SRCTL_ADDR_SHIFT) | |
| 188 | (1 << I40E_GLNVM_SRCTL_START_SHIFT); |
| 189 | wr32(hw, I40E_GLNVM_SRCTL, sr_reg); |
| 190 | |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 191 | /* Poll I40E_GLNVM_SRCTL until the done bit is set */ |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 192 | ret_code = i40e_poll_sr_srctl_done_bit(hw); |
| 193 | if (!ret_code) { |
| 194 | sr_reg = rd32(hw, I40E_GLNVM_SRDATA); |
| 195 | *data = (u16)((sr_reg & |
| 196 | I40E_GLNVM_SRDATA_RDDATA_MASK) |
| 197 | >> I40E_GLNVM_SRDATA_RDDATA_SHIFT); |
| 198 | } |
| 199 | } |
| 200 | if (ret_code) |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 201 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 202 | "NVM read error: Couldn't access Shadow RAM address: 0x%x\n", |
| 203 | offset); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 204 | |
| 205 | read_nvm_exit: |
| 206 | return ret_code; |
| 207 | } |
| 208 | |
| 209 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 210 | * i40e_read_nvm_buffer - Reads Shadow RAM buffer |
| 211 | * @hw: pointer to the HW structure |
| 212 | * @offset: offset of the Shadow RAM word to read (0x000000 - 0x001FFF). |
| 213 | * @words: (in) number of words to read; (out) number of words actually read |
| 214 | * @data: words read from the Shadow RAM |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 215 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 216 | * Reads 16 bit words (data buffer) from the SR using the i40e_read_nvm_srrd() |
| 217 | * method. The buffer read is preceded by the NVM ownership take |
| 218 | * and followed by the release. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 219 | **/ |
| 220 | i40e_status i40e_read_nvm_buffer(struct i40e_hw *hw, u16 offset, |
| 221 | u16 *words, u16 *data) |
| 222 | { |
| 223 | i40e_status ret_code = 0; |
| 224 | u16 index, word; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 225 | |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 226 | /* Loop thru the selected region */ |
Shannon Nelson | a4bcfbb | 2013-12-11 08:17:15 +0000 | [diff] [blame] | 227 | for (word = 0; word < *words; word++) { |
| 228 | index = offset + word; |
| 229 | ret_code = i40e_read_nvm_word(hw, index, &data[word]); |
| 230 | if (ret_code) |
| 231 | break; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 234 | /* Update the number of words read from the Shadow RAM */ |
Shannon Nelson | a4bcfbb | 2013-12-11 08:17:15 +0000 | [diff] [blame] | 235 | *words = word; |
| 236 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 237 | return ret_code; |
| 238 | } |
| 239 | |
| 240 | /** |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 241 | * i40e_write_nvm_aq - Writes Shadow RAM. |
| 242 | * @hw: pointer to the HW structure. |
| 243 | * @module_pointer: module pointer location in words from the NVM beginning |
| 244 | * @offset: offset in words from module start |
| 245 | * @words: number of words to write |
| 246 | * @data: buffer with words to write to the Shadow RAM |
| 247 | * @last_command: tells the AdminQ that this is the last command |
| 248 | * |
| 249 | * Writes a 16 bit words buffer to the Shadow RAM using the admin command. |
| 250 | **/ |
Wei Yongjun | 952d963 | 2014-07-30 09:02:53 +0000 | [diff] [blame] | 251 | static i40e_status i40e_write_nvm_aq(struct i40e_hw *hw, u8 module_pointer, |
| 252 | u32 offset, u16 words, void *data, |
| 253 | bool last_command) |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 254 | { |
| 255 | i40e_status ret_code = I40E_ERR_NVM; |
| 256 | |
| 257 | /* Here we are checking the SR limit only for the flat memory model. |
| 258 | * We cannot do it for the module-based model, as we did not acquire |
| 259 | * the NVM resource yet (we cannot get the module pointer value). |
| 260 | * Firmware will check the module-based model. |
| 261 | */ |
| 262 | if ((offset + words) > hw->nvm.sr_size) |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 263 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 264 | "NVM write error: offset %d beyond Shadow RAM limit %d\n", |
| 265 | (offset + words), hw->nvm.sr_size); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 266 | else if (words > I40E_SR_SECTOR_SIZE_IN_WORDS) |
| 267 | /* We can write only up to 4KB (one sector), in one AQ write */ |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 268 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 269 | "NVM write fail error: tried to write %d words, limit is %d.\n", |
| 270 | words, I40E_SR_SECTOR_SIZE_IN_WORDS); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 271 | else if (((offset + (words - 1)) / I40E_SR_SECTOR_SIZE_IN_WORDS) |
| 272 | != (offset / I40E_SR_SECTOR_SIZE_IN_WORDS)) |
| 273 | /* A single write cannot spread over two sectors */ |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 274 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 275 | "NVM write error: cannot spread over two sectors in a single write offset=%d words=%d\n", |
| 276 | offset, words); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 277 | else |
| 278 | ret_code = i40e_aq_update_nvm(hw, module_pointer, |
| 279 | 2 * offset, /*bytes*/ |
| 280 | 2 * words, /*bytes*/ |
| 281 | data, last_command, NULL); |
| 282 | |
| 283 | return ret_code; |
| 284 | } |
| 285 | |
| 286 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 287 | * i40e_calc_nvm_checksum - Calculates and returns the checksum |
| 288 | * @hw: pointer to hardware structure |
| 289 | * @checksum: pointer to the checksum |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 290 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 291 | * This function calculates SW Checksum that covers the whole 64kB shadow RAM |
| 292 | * except the VPD and PCIe ALT Auto-load modules. The structure and size of VPD |
| 293 | * is customer specific and unknown. Therefore, this function skips all maximum |
| 294 | * possible size of VPD (1kB). |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 295 | **/ |
| 296 | static i40e_status i40e_calc_nvm_checksum(struct i40e_hw *hw, |
| 297 | u16 *checksum) |
| 298 | { |
| 299 | i40e_status ret_code = 0; |
| 300 | u16 pcie_alt_module = 0; |
| 301 | u16 checksum_local = 0; |
| 302 | u16 vpd_module = 0; |
| 303 | u16 word = 0; |
| 304 | u32 i = 0; |
| 305 | |
| 306 | /* read pointer to VPD area */ |
Shannon Nelson | a4bcfbb | 2013-12-11 08:17:15 +0000 | [diff] [blame] | 307 | ret_code = i40e_read_nvm_word(hw, I40E_SR_VPD_PTR, &vpd_module); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 308 | if (ret_code) { |
| 309 | ret_code = I40E_ERR_NVM_CHECKSUM; |
| 310 | goto i40e_calc_nvm_checksum_exit; |
| 311 | } |
| 312 | |
| 313 | /* read pointer to PCIe Alt Auto-load module */ |
Shannon Nelson | a4bcfbb | 2013-12-11 08:17:15 +0000 | [diff] [blame] | 314 | ret_code = i40e_read_nvm_word(hw, I40E_SR_PCIE_ALT_AUTO_LOAD_PTR, |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 315 | &pcie_alt_module); |
| 316 | if (ret_code) { |
| 317 | ret_code = I40E_ERR_NVM_CHECKSUM; |
| 318 | goto i40e_calc_nvm_checksum_exit; |
| 319 | } |
| 320 | |
| 321 | /* Calculate SW checksum that covers the whole 64kB shadow RAM |
| 322 | * except the VPD and PCIe ALT Auto-load modules |
| 323 | */ |
| 324 | for (i = 0; i < hw->nvm.sr_size; i++) { |
| 325 | /* Skip Checksum word */ |
| 326 | if (i == I40E_SR_SW_CHECKSUM_WORD) |
| 327 | i++; |
| 328 | /* Skip VPD module (convert byte size to word count) */ |
| 329 | if (i == (u32)vpd_module) { |
| 330 | i += (I40E_SR_VPD_MODULE_MAX_SIZE / 2); |
| 331 | if (i >= hw->nvm.sr_size) |
| 332 | break; |
| 333 | } |
| 334 | /* Skip PCIe ALT module (convert byte size to word count) */ |
| 335 | if (i == (u32)pcie_alt_module) { |
| 336 | i += (I40E_SR_PCIE_ALT_MODULE_MAX_SIZE / 2); |
| 337 | if (i >= hw->nvm.sr_size) |
| 338 | break; |
| 339 | } |
| 340 | |
Shannon Nelson | a4bcfbb | 2013-12-11 08:17:15 +0000 | [diff] [blame] | 341 | ret_code = i40e_read_nvm_word(hw, (u16)i, &word); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 342 | if (ret_code) { |
| 343 | ret_code = I40E_ERR_NVM_CHECKSUM; |
| 344 | goto i40e_calc_nvm_checksum_exit; |
| 345 | } |
| 346 | checksum_local += word; |
| 347 | } |
| 348 | |
| 349 | *checksum = (u16)I40E_SR_SW_CHECKSUM_BASE - checksum_local; |
| 350 | |
| 351 | i40e_calc_nvm_checksum_exit: |
| 352 | return ret_code; |
| 353 | } |
| 354 | |
| 355 | /** |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 356 | * i40e_update_nvm_checksum - Updates the NVM checksum |
| 357 | * @hw: pointer to hardware structure |
| 358 | * |
| 359 | * NVM ownership must be acquired before calling this function and released |
| 360 | * on ARQ completion event reception by caller. |
| 361 | * This function will commit SR to NVM. |
| 362 | **/ |
| 363 | i40e_status i40e_update_nvm_checksum(struct i40e_hw *hw) |
| 364 | { |
| 365 | i40e_status ret_code = 0; |
| 366 | u16 checksum; |
| 367 | |
| 368 | ret_code = i40e_calc_nvm_checksum(hw, &checksum); |
| 369 | if (!ret_code) |
| 370 | ret_code = i40e_write_nvm_aq(hw, 0x00, I40E_SR_SW_CHECKSUM_WORD, |
| 371 | 1, &checksum, true); |
| 372 | |
| 373 | return ret_code; |
| 374 | } |
| 375 | |
| 376 | /** |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 377 | * i40e_validate_nvm_checksum - Validate EEPROM checksum |
| 378 | * @hw: pointer to hardware structure |
| 379 | * @checksum: calculated checksum |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 380 | * |
Shannon Nelson | 3e26186 | 2014-02-06 05:51:06 +0000 | [diff] [blame] | 381 | * Performs checksum calculation and validates the NVM SW checksum. If the |
| 382 | * caller does not need checksum, the value can be NULL. |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 383 | **/ |
| 384 | i40e_status i40e_validate_nvm_checksum(struct i40e_hw *hw, |
| 385 | u16 *checksum) |
| 386 | { |
| 387 | i40e_status ret_code = 0; |
| 388 | u16 checksum_sr = 0; |
Jesse Brandeburg | e15c9fa | 2014-01-17 15:36:31 -0800 | [diff] [blame] | 389 | u16 checksum_local = 0; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 390 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 391 | ret_code = i40e_calc_nvm_checksum(hw, &checksum_local); |
| 392 | if (ret_code) |
Kamil Krawczyk | 7a208e8 | 2014-06-04 04:22:36 +0000 | [diff] [blame] | 393 | goto i40e_validate_nvm_checksum_exit; |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 394 | |
| 395 | /* Do not use i40e_read_nvm_word() because we do not want to take |
| 396 | * the synchronization semaphores twice here. |
| 397 | */ |
Shannon Nelson | a4bcfbb | 2013-12-11 08:17:15 +0000 | [diff] [blame] | 398 | i40e_read_nvm_word(hw, I40E_SR_SW_CHECKSUM_WORD, &checksum_sr); |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 399 | |
| 400 | /* Verify read checksum from EEPROM is the same as |
| 401 | * calculated checksum |
| 402 | */ |
| 403 | if (checksum_local != checksum_sr) |
| 404 | ret_code = I40E_ERR_NVM_CHECKSUM; |
| 405 | |
| 406 | /* If the user cares, return the calculated checksum */ |
| 407 | if (checksum) |
| 408 | *checksum = checksum_local; |
| 409 | |
Jesse Brandeburg | 56a62fc | 2013-09-11 08:40:12 +0000 | [diff] [blame] | 410 | i40e_validate_nvm_checksum_exit: |
| 411 | return ret_code; |
| 412 | } |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 413 | |
| 414 | static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw, |
| 415 | struct i40e_nvm_access *cmd, |
| 416 | u8 *bytes, int *errno); |
| 417 | static i40e_status i40e_nvmupd_state_reading(struct i40e_hw *hw, |
| 418 | struct i40e_nvm_access *cmd, |
| 419 | u8 *bytes, int *errno); |
| 420 | static i40e_status i40e_nvmupd_state_writing(struct i40e_hw *hw, |
| 421 | struct i40e_nvm_access *cmd, |
| 422 | u8 *bytes, int *errno); |
| 423 | static enum i40e_nvmupd_cmd i40e_nvmupd_validate_command(struct i40e_hw *hw, |
| 424 | struct i40e_nvm_access *cmd, |
| 425 | int *errno); |
| 426 | static i40e_status i40e_nvmupd_nvm_erase(struct i40e_hw *hw, |
| 427 | struct i40e_nvm_access *cmd, |
| 428 | int *errno); |
| 429 | static i40e_status i40e_nvmupd_nvm_write(struct i40e_hw *hw, |
| 430 | struct i40e_nvm_access *cmd, |
| 431 | u8 *bytes, int *errno); |
| 432 | static i40e_status i40e_nvmupd_nvm_read(struct i40e_hw *hw, |
| 433 | struct i40e_nvm_access *cmd, |
| 434 | u8 *bytes, int *errno); |
| 435 | static inline u8 i40e_nvmupd_get_module(u32 val) |
| 436 | { |
| 437 | return (u8)(val & I40E_NVM_MOD_PNT_MASK); |
| 438 | } |
| 439 | static inline u8 i40e_nvmupd_get_transaction(u32 val) |
| 440 | { |
| 441 | return (u8)((val & I40E_NVM_TRANS_MASK) >> I40E_NVM_TRANS_SHIFT); |
| 442 | } |
| 443 | |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 444 | static char *i40e_nvm_update_state_str[] = { |
| 445 | "I40E_NVMUPD_INVALID", |
| 446 | "I40E_NVMUPD_READ_CON", |
| 447 | "I40E_NVMUPD_READ_SNT", |
| 448 | "I40E_NVMUPD_READ_LCB", |
| 449 | "I40E_NVMUPD_READ_SA", |
| 450 | "I40E_NVMUPD_WRITE_ERA", |
| 451 | "I40E_NVMUPD_WRITE_CON", |
| 452 | "I40E_NVMUPD_WRITE_SNT", |
| 453 | "I40E_NVMUPD_WRITE_LCB", |
| 454 | "I40E_NVMUPD_WRITE_SA", |
| 455 | "I40E_NVMUPD_CSUM_CON", |
| 456 | "I40E_NVMUPD_CSUM_SA", |
| 457 | "I40E_NVMUPD_CSUM_LCB", |
| 458 | }; |
| 459 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 460 | /** |
| 461 | * i40e_nvmupd_command - Process an NVM update command |
| 462 | * @hw: pointer to hardware structure |
| 463 | * @cmd: pointer to nvm update command |
| 464 | * @bytes: pointer to the data buffer |
| 465 | * @errno: pointer to return error code |
| 466 | * |
| 467 | * Dispatches command depending on what update state is current |
| 468 | **/ |
| 469 | i40e_status i40e_nvmupd_command(struct i40e_hw *hw, |
| 470 | struct i40e_nvm_access *cmd, |
| 471 | u8 *bytes, int *errno) |
| 472 | { |
| 473 | i40e_status status; |
| 474 | |
| 475 | /* assume success */ |
| 476 | *errno = 0; |
| 477 | |
| 478 | switch (hw->nvmupd_state) { |
| 479 | case I40E_NVMUPD_STATE_INIT: |
| 480 | status = i40e_nvmupd_state_init(hw, cmd, bytes, errno); |
| 481 | break; |
| 482 | |
| 483 | case I40E_NVMUPD_STATE_READING: |
| 484 | status = i40e_nvmupd_state_reading(hw, cmd, bytes, errno); |
| 485 | break; |
| 486 | |
| 487 | case I40E_NVMUPD_STATE_WRITING: |
| 488 | status = i40e_nvmupd_state_writing(hw, cmd, bytes, errno); |
| 489 | break; |
| 490 | |
| 491 | default: |
| 492 | /* invalid state, should never happen */ |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 493 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 494 | "NVMUPD: no such state %d\n", hw->nvmupd_state); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 495 | status = I40E_NOT_SUPPORTED; |
| 496 | *errno = -ESRCH; |
| 497 | break; |
| 498 | } |
| 499 | return status; |
| 500 | } |
| 501 | |
| 502 | /** |
| 503 | * i40e_nvmupd_state_init - Handle NVM update state Init |
| 504 | * @hw: pointer to hardware structure |
| 505 | * @cmd: pointer to nvm update command buffer |
| 506 | * @bytes: pointer to the data buffer |
| 507 | * @errno: pointer to return error code |
| 508 | * |
| 509 | * Process legitimate commands of the Init state and conditionally set next |
| 510 | * state. Reject all other commands. |
| 511 | **/ |
| 512 | static i40e_status i40e_nvmupd_state_init(struct i40e_hw *hw, |
| 513 | struct i40e_nvm_access *cmd, |
| 514 | u8 *bytes, int *errno) |
| 515 | { |
| 516 | i40e_status status = 0; |
| 517 | enum i40e_nvmupd_cmd upd_cmd; |
| 518 | |
| 519 | upd_cmd = i40e_nvmupd_validate_command(hw, cmd, errno); |
| 520 | |
| 521 | switch (upd_cmd) { |
| 522 | case I40E_NVMUPD_READ_SA: |
| 523 | status = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); |
| 524 | if (status) { |
| 525 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
| 526 | } else { |
| 527 | status = i40e_nvmupd_nvm_read(hw, cmd, bytes, errno); |
| 528 | i40e_release_nvm(hw); |
| 529 | } |
| 530 | break; |
| 531 | |
| 532 | case I40E_NVMUPD_READ_SNT: |
| 533 | status = i40e_acquire_nvm(hw, I40E_RESOURCE_READ); |
| 534 | if (status) { |
| 535 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
| 536 | } else { |
| 537 | status = i40e_nvmupd_nvm_read(hw, cmd, bytes, errno); |
Shannon Nelson | 0fdd052 | 2014-11-13 08:23:20 +0000 | [diff] [blame^] | 538 | if (status) |
| 539 | i40e_release_nvm(hw); |
| 540 | else |
| 541 | hw->nvmupd_state = I40E_NVMUPD_STATE_READING; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 542 | } |
| 543 | break; |
| 544 | |
| 545 | case I40E_NVMUPD_WRITE_ERA: |
| 546 | status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE); |
| 547 | if (status) { |
| 548 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
| 549 | } else { |
| 550 | status = i40e_nvmupd_nvm_erase(hw, cmd, errno); |
| 551 | if (status) |
| 552 | i40e_release_nvm(hw); |
| 553 | else |
| 554 | hw->aq.nvm_release_on_done = true; |
| 555 | } |
| 556 | break; |
| 557 | |
| 558 | case I40E_NVMUPD_WRITE_SA: |
| 559 | status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE); |
| 560 | if (status) { |
| 561 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
| 562 | } else { |
| 563 | status = i40e_nvmupd_nvm_write(hw, cmd, bytes, errno); |
| 564 | if (status) |
| 565 | i40e_release_nvm(hw); |
| 566 | else |
| 567 | hw->aq.nvm_release_on_done = true; |
| 568 | } |
| 569 | break; |
| 570 | |
| 571 | case I40E_NVMUPD_WRITE_SNT: |
| 572 | status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE); |
| 573 | if (status) { |
| 574 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
| 575 | } else { |
| 576 | status = i40e_nvmupd_nvm_write(hw, cmd, bytes, errno); |
Shannon Nelson | 0fdd052 | 2014-11-13 08:23:20 +0000 | [diff] [blame^] | 577 | if (status) |
| 578 | i40e_release_nvm(hw); |
| 579 | else |
| 580 | hw->nvmupd_state = I40E_NVMUPD_STATE_WRITING; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 581 | } |
| 582 | break; |
| 583 | |
| 584 | case I40E_NVMUPD_CSUM_SA: |
| 585 | status = i40e_acquire_nvm(hw, I40E_RESOURCE_WRITE); |
| 586 | if (status) { |
| 587 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
| 588 | } else { |
| 589 | status = i40e_update_nvm_checksum(hw); |
| 590 | if (status) { |
| 591 | *errno = hw->aq.asq_last_status ? |
| 592 | i40e_aq_rc_to_posix(hw->aq.asq_last_status) : |
| 593 | -EIO; |
| 594 | i40e_release_nvm(hw); |
| 595 | } else { |
| 596 | hw->aq.nvm_release_on_done = true; |
| 597 | } |
| 598 | } |
| 599 | break; |
| 600 | |
| 601 | default: |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 602 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 603 | "NVMUPD: bad cmd %s in init state\n", |
| 604 | i40e_nvm_update_state_str[upd_cmd]); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 605 | status = I40E_ERR_NVM; |
| 606 | *errno = -ESRCH; |
| 607 | break; |
| 608 | } |
| 609 | return status; |
| 610 | } |
| 611 | |
| 612 | /** |
| 613 | * i40e_nvmupd_state_reading - Handle NVM update state Reading |
| 614 | * @hw: pointer to hardware structure |
| 615 | * @cmd: pointer to nvm update command buffer |
| 616 | * @bytes: pointer to the data buffer |
| 617 | * @errno: pointer to return error code |
| 618 | * |
| 619 | * NVM ownership is already held. Process legitimate commands and set any |
| 620 | * change in state; reject all other commands. |
| 621 | **/ |
| 622 | static i40e_status i40e_nvmupd_state_reading(struct i40e_hw *hw, |
| 623 | struct i40e_nvm_access *cmd, |
| 624 | u8 *bytes, int *errno) |
| 625 | { |
| 626 | i40e_status status; |
| 627 | enum i40e_nvmupd_cmd upd_cmd; |
| 628 | |
| 629 | upd_cmd = i40e_nvmupd_validate_command(hw, cmd, errno); |
| 630 | |
| 631 | switch (upd_cmd) { |
| 632 | case I40E_NVMUPD_READ_SA: |
| 633 | case I40E_NVMUPD_READ_CON: |
| 634 | status = i40e_nvmupd_nvm_read(hw, cmd, bytes, errno); |
| 635 | break; |
| 636 | |
| 637 | case I40E_NVMUPD_READ_LCB: |
| 638 | status = i40e_nvmupd_nvm_read(hw, cmd, bytes, errno); |
| 639 | i40e_release_nvm(hw); |
| 640 | hw->nvmupd_state = I40E_NVMUPD_STATE_INIT; |
| 641 | break; |
| 642 | |
| 643 | default: |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 644 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 645 | "NVMUPD: bad cmd %s in reading state.\n", |
| 646 | i40e_nvm_update_state_str[upd_cmd]); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 647 | status = I40E_NOT_SUPPORTED; |
| 648 | *errno = -ESRCH; |
| 649 | break; |
| 650 | } |
| 651 | return status; |
| 652 | } |
| 653 | |
| 654 | /** |
| 655 | * i40e_nvmupd_state_writing - Handle NVM update state Writing |
| 656 | * @hw: pointer to hardware structure |
| 657 | * @cmd: pointer to nvm update command buffer |
| 658 | * @bytes: pointer to the data buffer |
| 659 | * @errno: pointer to return error code |
| 660 | * |
| 661 | * NVM ownership is already held. Process legitimate commands and set any |
| 662 | * change in state; reject all other commands |
| 663 | **/ |
| 664 | static i40e_status i40e_nvmupd_state_writing(struct i40e_hw *hw, |
| 665 | struct i40e_nvm_access *cmd, |
| 666 | u8 *bytes, int *errno) |
| 667 | { |
| 668 | i40e_status status; |
| 669 | enum i40e_nvmupd_cmd upd_cmd; |
| 670 | |
| 671 | upd_cmd = i40e_nvmupd_validate_command(hw, cmd, errno); |
| 672 | |
| 673 | switch (upd_cmd) { |
| 674 | case I40E_NVMUPD_WRITE_CON: |
| 675 | status = i40e_nvmupd_nvm_write(hw, cmd, bytes, errno); |
| 676 | break; |
| 677 | |
| 678 | case I40E_NVMUPD_WRITE_LCB: |
| 679 | status = i40e_nvmupd_nvm_write(hw, cmd, bytes, errno); |
Shannon Nelson | 0fdd052 | 2014-11-13 08:23:20 +0000 | [diff] [blame^] | 680 | if (!status) |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 681 | hw->aq.nvm_release_on_done = true; |
Shannon Nelson | 0fdd052 | 2014-11-13 08:23:20 +0000 | [diff] [blame^] | 682 | hw->nvmupd_state = I40E_NVMUPD_STATE_INIT; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 683 | break; |
| 684 | |
| 685 | case I40E_NVMUPD_CSUM_CON: |
| 686 | status = i40e_update_nvm_checksum(hw); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 687 | if (status) { |
| 688 | *errno = hw->aq.asq_last_status ? |
| 689 | i40e_aq_rc_to_posix(hw->aq.asq_last_status) : |
| 690 | -EIO; |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 691 | hw->nvmupd_state = I40E_NVMUPD_STATE_INIT; |
| 692 | } |
| 693 | break; |
| 694 | |
Shannon Nelson | 0fdd052 | 2014-11-13 08:23:20 +0000 | [diff] [blame^] | 695 | case I40E_NVMUPD_CSUM_LCB: |
| 696 | status = i40e_update_nvm_checksum(hw); |
| 697 | if (status) |
| 698 | *errno = hw->aq.asq_last_status ? |
| 699 | i40e_aq_rc_to_posix(hw->aq.asq_last_status) : |
| 700 | -EIO; |
| 701 | else |
| 702 | hw->aq.nvm_release_on_done = true; |
| 703 | hw->nvmupd_state = I40E_NVMUPD_STATE_INIT; |
| 704 | break; |
| 705 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 706 | default: |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 707 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 708 | "NVMUPD: bad cmd %s in writing state.\n", |
| 709 | i40e_nvm_update_state_str[upd_cmd]); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 710 | status = I40E_NOT_SUPPORTED; |
| 711 | *errno = -ESRCH; |
| 712 | break; |
| 713 | } |
| 714 | return status; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * i40e_nvmupd_validate_command - Validate given command |
| 719 | * @hw: pointer to hardware structure |
| 720 | * @cmd: pointer to nvm update command buffer |
| 721 | * @errno: pointer to return error code |
| 722 | * |
| 723 | * Return one of the valid command types or I40E_NVMUPD_INVALID |
| 724 | **/ |
| 725 | static enum i40e_nvmupd_cmd i40e_nvmupd_validate_command(struct i40e_hw *hw, |
| 726 | struct i40e_nvm_access *cmd, |
| 727 | int *errno) |
| 728 | { |
| 729 | enum i40e_nvmupd_cmd upd_cmd; |
| 730 | u8 transaction, module; |
| 731 | |
| 732 | /* anything that doesn't match a recognized case is an error */ |
| 733 | upd_cmd = I40E_NVMUPD_INVALID; |
| 734 | |
| 735 | transaction = i40e_nvmupd_get_transaction(cmd->config); |
| 736 | module = i40e_nvmupd_get_module(cmd->config); |
| 737 | |
| 738 | /* limits on data size */ |
| 739 | if ((cmd->data_size < 1) || |
| 740 | (cmd->data_size > I40E_NVMUPD_MAX_DATA)) { |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 741 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 742 | "i40e_nvmupd_validate_command data_size %d\n", |
| 743 | cmd->data_size); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 744 | *errno = -EFAULT; |
| 745 | return I40E_NVMUPD_INVALID; |
| 746 | } |
| 747 | |
| 748 | switch (cmd->command) { |
| 749 | case I40E_NVM_READ: |
| 750 | switch (transaction) { |
| 751 | case I40E_NVM_CON: |
| 752 | upd_cmd = I40E_NVMUPD_READ_CON; |
| 753 | break; |
| 754 | case I40E_NVM_SNT: |
| 755 | upd_cmd = I40E_NVMUPD_READ_SNT; |
| 756 | break; |
| 757 | case I40E_NVM_LCB: |
| 758 | upd_cmd = I40E_NVMUPD_READ_LCB; |
| 759 | break; |
| 760 | case I40E_NVM_SA: |
| 761 | upd_cmd = I40E_NVMUPD_READ_SA; |
| 762 | break; |
| 763 | } |
| 764 | break; |
| 765 | |
| 766 | case I40E_NVM_WRITE: |
| 767 | switch (transaction) { |
| 768 | case I40E_NVM_CON: |
| 769 | upd_cmd = I40E_NVMUPD_WRITE_CON; |
| 770 | break; |
| 771 | case I40E_NVM_SNT: |
| 772 | upd_cmd = I40E_NVMUPD_WRITE_SNT; |
| 773 | break; |
| 774 | case I40E_NVM_LCB: |
| 775 | upd_cmd = I40E_NVMUPD_WRITE_LCB; |
| 776 | break; |
| 777 | case I40E_NVM_SA: |
| 778 | upd_cmd = I40E_NVMUPD_WRITE_SA; |
| 779 | break; |
| 780 | case I40E_NVM_ERA: |
| 781 | upd_cmd = I40E_NVMUPD_WRITE_ERA; |
| 782 | break; |
| 783 | case I40E_NVM_CSUM: |
| 784 | upd_cmd = I40E_NVMUPD_CSUM_CON; |
| 785 | break; |
| 786 | case (I40E_NVM_CSUM|I40E_NVM_SA): |
| 787 | upd_cmd = I40E_NVMUPD_CSUM_SA; |
| 788 | break; |
| 789 | case (I40E_NVM_CSUM|I40E_NVM_LCB): |
| 790 | upd_cmd = I40E_NVMUPD_CSUM_LCB; |
| 791 | break; |
| 792 | } |
| 793 | break; |
| 794 | } |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 795 | i40e_debug(hw, I40E_DEBUG_NVM, "%s\n", |
| 796 | i40e_nvm_update_state_str[upd_cmd]); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 797 | |
| 798 | if (upd_cmd == I40E_NVMUPD_INVALID) { |
| 799 | *errno = -EFAULT; |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 800 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 801 | "i40e_nvmupd_validate_command returns %d errno %d\n", |
| 802 | upd_cmd, *errno); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 803 | } |
| 804 | return upd_cmd; |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * i40e_nvmupd_nvm_read - Read NVM |
| 809 | * @hw: pointer to hardware structure |
| 810 | * @cmd: pointer to nvm update command buffer |
| 811 | * @bytes: pointer to the data buffer |
| 812 | * @errno: pointer to return error code |
| 813 | * |
| 814 | * cmd structure contains identifiers and data buffer |
| 815 | **/ |
| 816 | static i40e_status i40e_nvmupd_nvm_read(struct i40e_hw *hw, |
| 817 | struct i40e_nvm_access *cmd, |
| 818 | u8 *bytes, int *errno) |
| 819 | { |
| 820 | i40e_status status; |
| 821 | u8 module, transaction; |
| 822 | bool last; |
| 823 | |
| 824 | transaction = i40e_nvmupd_get_transaction(cmd->config); |
| 825 | module = i40e_nvmupd_get_module(cmd->config); |
| 826 | last = (transaction == I40E_NVM_LCB) || (transaction == I40E_NVM_SA); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 827 | |
| 828 | status = i40e_aq_read_nvm(hw, module, cmd->offset, (u16)cmd->data_size, |
| 829 | bytes, last, NULL); |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 830 | if (status) { |
| 831 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 832 | "i40e_nvmupd_nvm_read mod 0x%x off 0x%x len 0x%x\n", |
| 833 | module, cmd->offset, cmd->data_size); |
| 834 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 835 | "i40e_nvmupd_nvm_read status %d aq %d\n", |
| 836 | status, hw->aq.asq_last_status); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 837 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 838 | } |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 839 | |
| 840 | return status; |
| 841 | } |
| 842 | |
| 843 | /** |
| 844 | * i40e_nvmupd_nvm_erase - Erase an NVM module |
| 845 | * @hw: pointer to hardware structure |
| 846 | * @cmd: pointer to nvm update command buffer |
| 847 | * @errno: pointer to return error code |
| 848 | * |
| 849 | * module, offset, data_size and data are in cmd structure |
| 850 | **/ |
| 851 | static i40e_status i40e_nvmupd_nvm_erase(struct i40e_hw *hw, |
| 852 | struct i40e_nvm_access *cmd, |
| 853 | int *errno) |
| 854 | { |
| 855 | i40e_status status = 0; |
| 856 | u8 module, transaction; |
| 857 | bool last; |
| 858 | |
| 859 | transaction = i40e_nvmupd_get_transaction(cmd->config); |
| 860 | module = i40e_nvmupd_get_module(cmd->config); |
| 861 | last = (transaction & I40E_NVM_LCB); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 862 | status = i40e_aq_erase_nvm(hw, module, cmd->offset, (u16)cmd->data_size, |
| 863 | last, NULL); |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 864 | if (status) { |
| 865 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 866 | "i40e_nvmupd_nvm_erase mod 0x%x off 0x%x len 0x%x\n", |
| 867 | module, cmd->offset, cmd->data_size); |
| 868 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 869 | "i40e_nvmupd_nvm_erase status %d aq %d\n", |
| 870 | status, hw->aq.asq_last_status); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 871 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 872 | } |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 873 | |
| 874 | return status; |
| 875 | } |
| 876 | |
| 877 | /** |
| 878 | * i40e_nvmupd_nvm_write - Write NVM |
| 879 | * @hw: pointer to hardware structure |
| 880 | * @cmd: pointer to nvm update command buffer |
| 881 | * @bytes: pointer to the data buffer |
| 882 | * @errno: pointer to return error code |
| 883 | * |
| 884 | * module, offset, data_size and data are in cmd structure |
| 885 | **/ |
| 886 | static i40e_status i40e_nvmupd_nvm_write(struct i40e_hw *hw, |
| 887 | struct i40e_nvm_access *cmd, |
| 888 | u8 *bytes, int *errno) |
| 889 | { |
| 890 | i40e_status status = 0; |
| 891 | u8 module, transaction; |
| 892 | bool last; |
| 893 | |
| 894 | transaction = i40e_nvmupd_get_transaction(cmd->config); |
| 895 | module = i40e_nvmupd_get_module(cmd->config); |
| 896 | last = (transaction & I40E_NVM_LCB); |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 897 | |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 898 | status = i40e_aq_update_nvm(hw, module, cmd->offset, |
| 899 | (u16)cmd->data_size, bytes, last, NULL); |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 900 | if (status) { |
| 901 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 902 | "i40e_nvmupd_nvm_write mod 0x%x off 0x%x len 0x%x\n", |
| 903 | module, cmd->offset, cmd->data_size); |
| 904 | i40e_debug(hw, I40E_DEBUG_NVM, |
| 905 | "i40e_nvmupd_nvm_write status %d aq %d\n", |
| 906 | status, hw->aq.asq_last_status); |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 907 | *errno = i40e_aq_rc_to_posix(hw->aq.asq_last_status); |
Shannon Nelson | 74d0d0e | 2014-11-13 08:23:15 +0000 | [diff] [blame] | 908 | } |
Shannon Nelson | cd552cb | 2014-07-09 07:46:09 +0000 | [diff] [blame] | 909 | |
| 910 | return status; |
| 911 | } |