blob: 239650e5e54563a9697dfdec6bfcb6f9f34d0a4c [file] [log] [blame]
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +00001/*******************************************************************************
2
3 Intel(R) Gigabit Ethernet Linux driver
4 Copyright(c) 2007-2012 Intel Corporation.
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
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26******************************************************************************/
27
28/* e1000_i210
29 * e1000_i211
30 */
31
32#include <linux/types.h>
33#include <linux/if_ether.h>
34
35#include "e1000_hw.h"
36#include "e1000_i210.h"
37
38static s32 igb_get_hw_semaphore_i210(struct e1000_hw *hw);
39static void igb_put_hw_semaphore_i210(struct e1000_hw *hw);
40static s32 igb_write_nvm_srwr(struct e1000_hw *hw, u16 offset, u16 words,
41 u16 *data);
42static s32 igb_pool_flash_update_done_i210(struct e1000_hw *hw);
43
44/**
45 * igb_acquire_nvm_i210 - Request for access to EEPROM
46 * @hw: pointer to the HW structure
47 *
48 * Acquire the necessary semaphores for exclusive access to the EEPROM.
49 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
50 * Return successful if access grant bit set, else clear the request for
51 * EEPROM access and return -E1000_ERR_NVM (-1).
52 **/
53s32 igb_acquire_nvm_i210(struct e1000_hw *hw)
54{
55 return igb_acquire_swfw_sync_i210(hw, E1000_SWFW_EEP_SM);
56}
57
58/**
59 * igb_release_nvm_i210 - Release exclusive access to EEPROM
60 * @hw: pointer to the HW structure
61 *
62 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
63 * then release the semaphores acquired.
64 **/
65void igb_release_nvm_i210(struct e1000_hw *hw)
66{
67 igb_release_swfw_sync_i210(hw, E1000_SWFW_EEP_SM);
68}
69
70/**
71 * igb_acquire_swfw_sync_i210 - Acquire SW/FW semaphore
72 * @hw: pointer to the HW structure
73 * @mask: specifies which semaphore to acquire
74 *
75 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
76 * will also specify which port we're acquiring the lock for.
77 **/
78s32 igb_acquire_swfw_sync_i210(struct e1000_hw *hw, u16 mask)
79{
80 u32 swfw_sync;
81 u32 swmask = mask;
82 u32 fwmask = mask << 16;
83 s32 ret_val = E1000_SUCCESS;
84 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
85
86 while (i < timeout) {
87 if (igb_get_hw_semaphore_i210(hw)) {
88 ret_val = -E1000_ERR_SWFW_SYNC;
89 goto out;
90 }
91
92 swfw_sync = rd32(E1000_SW_FW_SYNC);
93 if (!(swfw_sync & fwmask))
94 break;
95
96 /*
97 * Firmware currently using resource (fwmask)
98 */
99 igb_put_hw_semaphore_i210(hw);
100 mdelay(5);
101 i++;
102 }
103
104 if (i == timeout) {
105 hw_dbg("Driver can't access resource, SW_FW_SYNC timeout.\n");
106 ret_val = -E1000_ERR_SWFW_SYNC;
107 goto out;
108 }
109
110 swfw_sync |= swmask;
111 wr32(E1000_SW_FW_SYNC, swfw_sync);
112
113 igb_put_hw_semaphore_i210(hw);
114out:
115 return ret_val;
116}
117
118/**
119 * igb_release_swfw_sync_i210 - Release SW/FW semaphore
120 * @hw: pointer to the HW structure
121 * @mask: specifies which semaphore to acquire
122 *
123 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
124 * will also specify which port we're releasing the lock for.
125 **/
126void igb_release_swfw_sync_i210(struct e1000_hw *hw, u16 mask)
127{
128 u32 swfw_sync;
129
130 while (igb_get_hw_semaphore_i210(hw) != E1000_SUCCESS)
131 ; /* Empty */
132
133 swfw_sync = rd32(E1000_SW_FW_SYNC);
134 swfw_sync &= ~mask;
135 wr32(E1000_SW_FW_SYNC, swfw_sync);
136
137 igb_put_hw_semaphore_i210(hw);
138}
139
140/**
141 * igb_get_hw_semaphore_i210 - Acquire hardware semaphore
142 * @hw: pointer to the HW structure
143 *
144 * Acquire the HW semaphore to access the PHY or NVM
145 **/
146static s32 igb_get_hw_semaphore_i210(struct e1000_hw *hw)
147{
148 u32 swsm;
149 s32 ret_val = E1000_SUCCESS;
150 s32 timeout = hw->nvm.word_size + 1;
151 s32 i = 0;
152
153 /* Get the FW semaphore. */
154 for (i = 0; i < timeout; i++) {
155 swsm = rd32(E1000_SWSM);
156 wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
157
158 /* Semaphore acquired if bit latched */
159 if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI)
160 break;
161
162 udelay(50);
163 }
164
165 if (i == timeout) {
166 /* Release semaphores */
167 igb_put_hw_semaphore(hw);
168 hw_dbg("Driver can't access the NVM\n");
169 ret_val = -E1000_ERR_NVM;
170 goto out;
171 }
172
173out:
174 return ret_val;
175}
176
177/**
178 * igb_put_hw_semaphore_i210 - Release hardware semaphore
179 * @hw: pointer to the HW structure
180 *
181 * Release hardware semaphore used to access the PHY or NVM
182 **/
183static void igb_put_hw_semaphore_i210(struct e1000_hw *hw)
184{
185 u32 swsm;
186
187 swsm = rd32(E1000_SWSM);
188
189 swsm &= ~E1000_SWSM_SWESMBI;
190
191 wr32(E1000_SWSM, swsm);
192}
193
194/**
195 * igb_read_nvm_srrd_i210 - Reads Shadow Ram using EERD register
196 * @hw: pointer to the HW structure
197 * @offset: offset of word in the Shadow Ram to read
198 * @words: number of words to read
199 * @data: word read from the Shadow Ram
200 *
201 * Reads a 16 bit word from the Shadow Ram using the EERD register.
202 * Uses necessary synchronization semaphores.
203 **/
204s32 igb_read_nvm_srrd_i210(struct e1000_hw *hw, u16 offset, u16 words,
205 u16 *data)
206{
207 s32 status = E1000_SUCCESS;
208 u16 i, count;
209
210 /* We cannot hold synchronization semaphores for too long,
211 * because of forceful takeover procedure. However it is more efficient
212 * to read in bursts than synchronizing access for each word. */
213 for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
214 count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
215 E1000_EERD_EEWR_MAX_COUNT : (words - i);
216 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
217 status = igb_read_nvm_eerd(hw, offset, count,
218 data + i);
219 hw->nvm.ops.release(hw);
220 } else {
221 status = E1000_ERR_SWFW_SYNC;
222 }
223
224 if (status != E1000_SUCCESS)
225 break;
226 }
227
228 return status;
229}
230
231/**
232 * igb_write_nvm_srwr_i210 - Write to Shadow RAM using EEWR
233 * @hw: pointer to the HW structure
234 * @offset: offset within the Shadow RAM to be written to
235 * @words: number of words to write
236 * @data: 16 bit word(s) to be written to the Shadow RAM
237 *
238 * Writes data to Shadow RAM at offset using EEWR register.
239 *
240 * If e1000_update_nvm_checksum is not called after this function , the
241 * data will not be committed to FLASH and also Shadow RAM will most likely
242 * contain an invalid checksum.
243 *
244 * If error code is returned, data and Shadow RAM may be inconsistent - buffer
245 * partially written.
246 **/
247s32 igb_write_nvm_srwr_i210(struct e1000_hw *hw, u16 offset, u16 words,
248 u16 *data)
249{
250 s32 status = E1000_SUCCESS;
251 u16 i, count;
252
253 /* We cannot hold synchronization semaphores for too long,
254 * because of forceful takeover procedure. However it is more efficient
255 * to write in bursts than synchronizing access for each word. */
256 for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
257 count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
258 E1000_EERD_EEWR_MAX_COUNT : (words - i);
259 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
260 status = igb_write_nvm_srwr(hw, offset, count,
261 data + i);
262 hw->nvm.ops.release(hw);
263 } else {
264 status = E1000_ERR_SWFW_SYNC;
265 }
266
267 if (status != E1000_SUCCESS)
268 break;
269 }
270
271 return status;
272}
273
274/**
275 * igb_write_nvm_srwr - Write to Shadow Ram using EEWR
276 * @hw: pointer to the HW structure
277 * @offset: offset within the Shadow Ram to be written to
278 * @words: number of words to write
279 * @data: 16 bit word(s) to be written to the Shadow Ram
280 *
281 * Writes data to Shadow Ram at offset using EEWR register.
282 *
283 * If igb_update_nvm_checksum is not called after this function , the
284 * Shadow Ram will most likely contain an invalid checksum.
285 **/
286static s32 igb_write_nvm_srwr(struct e1000_hw *hw, u16 offset, u16 words,
287 u16 *data)
288{
289 struct e1000_nvm_info *nvm = &hw->nvm;
290 u32 i, k, eewr = 0;
291 u32 attempts = 100000;
292 s32 ret_val = E1000_SUCCESS;
293
294 /*
295 * A check for invalid values: offset too large, too many words,
296 * too many words for the offset, and not enough words.
297 */
298 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
299 (words == 0)) {
300 hw_dbg("nvm parameter(s) out of bounds\n");
301 ret_val = -E1000_ERR_NVM;
302 goto out;
303 }
304
305 for (i = 0; i < words; i++) {
306 eewr = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
307 (data[i] << E1000_NVM_RW_REG_DATA) |
308 E1000_NVM_RW_REG_START;
309
310 wr32(E1000_SRWR, eewr);
311
312 for (k = 0; k < attempts; k++) {
313 if (E1000_NVM_RW_REG_DONE &
314 rd32(E1000_SRWR)) {
315 ret_val = E1000_SUCCESS;
316 break;
317 }
318 udelay(5);
319 }
320
321 if (ret_val != E1000_SUCCESS) {
322 hw_dbg("Shadow RAM write EEWR timed out\n");
323 break;
324 }
325 }
326
327out:
328 return ret_val;
329}
330
331/**
332 * igb_read_nvm_i211 - Read NVM wrapper function for I211
333 * @hw: pointer to the HW structure
334 * @address: the word address (aka eeprom offset) to read
335 * @data: pointer to the data read
336 *
337 * Wrapper function to return data formerly found in the NVM.
338 **/
339s32 igb_read_nvm_i211(struct e1000_hw *hw, u16 offset, u16 words,
340 u16 *data)
341{
342 s32 ret_val = E1000_SUCCESS;
343
344 /* Only the MAC addr is required to be present in the iNVM */
345 switch (offset) {
346 case NVM_MAC_ADDR:
347 ret_val = igb_read_invm_i211(hw, offset, &data[0]);
348 ret_val |= igb_read_invm_i211(hw, offset+1, &data[1]);
349 ret_val |= igb_read_invm_i211(hw, offset+2, &data[2]);
350 if (ret_val != E1000_SUCCESS)
351 hw_dbg("MAC Addr not found in iNVM\n");
352 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000353 case NVM_INIT_CTRL_2:
Carolyn Wyborny1720ee32012-10-11 02:15:45 +0000354 ret_val = igb_read_invm_i211(hw, (u8)offset, data);
355 if (ret_val != E1000_SUCCESS) {
356 *data = NVM_INIT_CTRL_2_DEFAULT_I211;
357 ret_val = E1000_SUCCESS;
358 }
359 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000360 case NVM_INIT_CTRL_4:
Carolyn Wyborny1720ee32012-10-11 02:15:45 +0000361 ret_val = igb_read_invm_i211(hw, (u8)offset, data);
362 if (ret_val != E1000_SUCCESS) {
363 *data = NVM_INIT_CTRL_4_DEFAULT_I211;
364 ret_val = E1000_SUCCESS;
365 }
366 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000367 case NVM_LED_1_CFG:
Carolyn Wyborny1720ee32012-10-11 02:15:45 +0000368 ret_val = igb_read_invm_i211(hw, (u8)offset, data);
369 if (ret_val != E1000_SUCCESS) {
370 *data = NVM_LED_1_CFG_DEFAULT_I211;
371 ret_val = E1000_SUCCESS;
372 }
373 break;
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000374 case NVM_LED_0_2_CFG:
375 igb_read_invm_i211(hw, offset, data);
Carolyn Wyborny1720ee32012-10-11 02:15:45 +0000376 if (ret_val != E1000_SUCCESS) {
377 *data = NVM_LED_0_2_CFG_DEFAULT_I211;
378 ret_val = E1000_SUCCESS;
379 }
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000380 break;
Carolyn Wyborny1720ee32012-10-11 02:15:45 +0000381 case NVM_ID_LED_SETTINGS:
382 ret_val = igb_read_invm_i211(hw, (u8)offset, data);
383 if (ret_val != E1000_SUCCESS) {
384 *data = ID_LED_RESERVED_FFFF;
385 ret_val = E1000_SUCCESS;
386 }
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000387 case NVM_SUB_DEV_ID:
388 *data = hw->subsystem_device_id;
389 break;
390 case NVM_SUB_VEN_ID:
391 *data = hw->subsystem_vendor_id;
392 break;
393 case NVM_DEV_ID:
394 *data = hw->device_id;
395 break;
396 case NVM_VEN_ID:
397 *data = hw->vendor_id;
398 break;
399 default:
400 hw_dbg("NVM word 0x%02x is not mapped.\n", offset);
401 *data = NVM_RESERVED_WORD;
402 break;
403 }
404 return ret_val;
405}
406
407/**
408 * igb_read_invm_i211 - Reads OTP
409 * @hw: pointer to the HW structure
410 * @address: the word address (aka eeprom offset) to read
411 * @data: pointer to the data read
412 *
413 * Reads 16-bit words from the OTP. Return error when the word is not
414 * stored in OTP.
415 **/
416s32 igb_read_invm_i211(struct e1000_hw *hw, u16 address, u16 *data)
417{
418 s32 status = -E1000_ERR_INVM_VALUE_NOT_FOUND;
419 u32 invm_dword;
420 u16 i;
421 u8 record_type, word_address;
422
423 for (i = 0; i < E1000_INVM_SIZE; i++) {
424 invm_dword = rd32(E1000_INVM_DATA_REG(i));
425 /* Get record type */
426 record_type = INVM_DWORD_TO_RECORD_TYPE(invm_dword);
427 if (record_type == E1000_INVM_UNINITIALIZED_STRUCTURE)
428 break;
429 if (record_type == E1000_INVM_CSR_AUTOLOAD_STRUCTURE)
430 i += E1000_INVM_CSR_AUTOLOAD_DATA_SIZE_IN_DWORDS;
431 if (record_type == E1000_INVM_RSA_KEY_SHA256_STRUCTURE)
432 i += E1000_INVM_RSA_KEY_SHA256_DATA_SIZE_IN_DWORDS;
433 if (record_type == E1000_INVM_WORD_AUTOLOAD_STRUCTURE) {
434 word_address = INVM_DWORD_TO_WORD_ADDRESS(invm_dword);
435 if (word_address == (u8)address) {
436 *data = INVM_DWORD_TO_WORD_DATA(invm_dword);
437 hw_dbg("Read INVM Word 0x%02x = %x",
438 address, *data);
439 status = E1000_SUCCESS;
440 break;
441 }
442 }
443 }
444 if (status != E1000_SUCCESS)
445 hw_dbg("Requested word 0x%02x not found in OTP\n", address);
446 return status;
447}
448
449/**
Carolyn Wyborny09e77282012-10-23 13:04:37 +0000450 * igb_read_invm_version - Reads iNVM version and image type
451 * @hw: pointer to the HW structure
452 * @invm_ver: version structure for the version read
453 *
454 * Reads iNVM version and image type.
455 **/
456s32 igb_read_invm_version(struct e1000_hw *hw,
457 struct e1000_fw_version *invm_ver) {
458 u32 *record = NULL;
459 u32 *next_record = NULL;
460 u32 i = 0;
461 u32 invm_dword = 0;
462 u32 invm_blocks = E1000_INVM_SIZE - (E1000_INVM_ULT_BYTES_SIZE /
463 E1000_INVM_RECORD_SIZE_IN_BYTES);
464 u32 buffer[E1000_INVM_SIZE];
465 s32 status = -E1000_ERR_INVM_VALUE_NOT_FOUND;
466 u16 version = 0;
467
468 /* Read iNVM memory */
469 for (i = 0; i < E1000_INVM_SIZE; i++) {
470 invm_dword = rd32(E1000_INVM_DATA_REG(i));
471 buffer[i] = invm_dword;
472 }
473
474 /* Read version number */
475 for (i = 1; i < invm_blocks; i++) {
476 record = &buffer[invm_blocks - i];
477 next_record = &buffer[invm_blocks - i + 1];
478
479 /* Check if we have first version location used */
480 if ((i == 1) && ((*record & E1000_INVM_VER_FIELD_ONE) == 0)) {
481 version = 0;
482 status = E1000_SUCCESS;
483 break;
484 }
485 /* Check if we have second version location used */
486 else if ((i == 1) &&
487 ((*record & E1000_INVM_VER_FIELD_TWO) == 0)) {
488 version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
489 status = E1000_SUCCESS;
490 break;
491 }
492 /* Check if we have odd version location
493 * used and it is the last one used
494 */
495 else if ((((*record & E1000_INVM_VER_FIELD_ONE) == 0) &&
496 ((*record & 0x3) == 0)) || (((*record & 0x3) != 0) &&
497 (i != 1))) {
498 version = (*next_record & E1000_INVM_VER_FIELD_TWO)
499 >> 13;
500 status = E1000_SUCCESS;
501 break;
502 }
503 /* Check if we have even version location
504 * used and it is the last one used
505 */
506 else if (((*record & E1000_INVM_VER_FIELD_TWO) == 0) &&
507 ((*record & 0x3) == 0)) {
508 version = (*record & E1000_INVM_VER_FIELD_ONE) >> 3;
509 status = E1000_SUCCESS;
510 break;
511 }
512 }
513
514 if (status == E1000_SUCCESS) {
515 invm_ver->invm_major = (version & E1000_INVM_MAJOR_MASK)
516 >> E1000_INVM_MAJOR_SHIFT;
517 invm_ver->invm_minor = version & E1000_INVM_MINOR_MASK;
518 }
519 /* Read Image Type */
520 for (i = 1; i < invm_blocks; i++) {
521 record = &buffer[invm_blocks - i];
522 next_record = &buffer[invm_blocks - i + 1];
523
524 /* Check if we have image type in first location used */
525 if ((i == 1) && ((*record & E1000_INVM_IMGTYPE_FIELD) == 0)) {
526 invm_ver->invm_img_type = 0;
527 status = E1000_SUCCESS;
528 break;
529 }
530 /* Check if we have image type in first location used */
531 else if ((((*record & 0x3) == 0) &&
532 ((*record & E1000_INVM_IMGTYPE_FIELD) == 0)) ||
533 ((((*record & 0x3) != 0) && (i != 1)))) {
534 invm_ver->invm_img_type =
535 (*next_record & E1000_INVM_IMGTYPE_FIELD) >> 23;
536 status = E1000_SUCCESS;
537 break;
538 }
539 }
540 return status;
541}
542
543/**
Carolyn Wybornyf96a8a02012-04-06 23:25:19 +0000544 * igb_validate_nvm_checksum_i210 - Validate EEPROM checksum
545 * @hw: pointer to the HW structure
546 *
547 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
548 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
549 **/
550s32 igb_validate_nvm_checksum_i210(struct e1000_hw *hw)
551{
552 s32 status = E1000_SUCCESS;
553 s32 (*read_op_ptr)(struct e1000_hw *, u16, u16, u16 *);
554
555 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
556
557 /*
558 * Replace the read function with semaphore grabbing with
559 * the one that skips this for a while.
560 * We have semaphore taken already here.
561 */
562 read_op_ptr = hw->nvm.ops.read;
563 hw->nvm.ops.read = igb_read_nvm_eerd;
564
565 status = igb_validate_nvm_checksum(hw);
566
567 /* Revert original read operation. */
568 hw->nvm.ops.read = read_op_ptr;
569
570 hw->nvm.ops.release(hw);
571 } else {
572 status = E1000_ERR_SWFW_SYNC;
573 }
574
575 return status;
576}
577
578
579/**
580 * igb_update_nvm_checksum_i210 - Update EEPROM checksum
581 * @hw: pointer to the HW structure
582 *
583 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
584 * up to the checksum. Then calculates the EEPROM checksum and writes the
585 * value to the EEPROM. Next commit EEPROM data onto the Flash.
586 **/
587s32 igb_update_nvm_checksum_i210(struct e1000_hw *hw)
588{
589 s32 ret_val = E1000_SUCCESS;
590 u16 checksum = 0;
591 u16 i, nvm_data;
592
593 /*
594 * Read the first word from the EEPROM. If this times out or fails, do
595 * not continue or we could be in for a very long wait while every
596 * EEPROM read fails
597 */
598 ret_val = igb_read_nvm_eerd(hw, 0, 1, &nvm_data);
599 if (ret_val != E1000_SUCCESS) {
600 hw_dbg("EEPROM read failed\n");
601 goto out;
602 }
603
604 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
605 /*
606 * Do not use hw->nvm.ops.write, hw->nvm.ops.read
607 * because we do not want to take the synchronization
608 * semaphores twice here.
609 */
610
611 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
612 ret_val = igb_read_nvm_eerd(hw, i, 1, &nvm_data);
613 if (ret_val) {
614 hw->nvm.ops.release(hw);
615 hw_dbg("NVM Read Error while updating checksum.\n");
616 goto out;
617 }
618 checksum += nvm_data;
619 }
620 checksum = (u16) NVM_SUM - checksum;
621 ret_val = igb_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
622 &checksum);
623 if (ret_val != E1000_SUCCESS) {
624 hw->nvm.ops.release(hw);
625 hw_dbg("NVM Write Error while updating checksum.\n");
626 goto out;
627 }
628
629 hw->nvm.ops.release(hw);
630
631 ret_val = igb_update_flash_i210(hw);
632 } else {
633 ret_val = -E1000_ERR_SWFW_SYNC;
634 }
635out:
636 return ret_val;
637}
638
639/**
640 * igb_update_flash_i210 - Commit EEPROM to the flash
641 * @hw: pointer to the HW structure
642 *
643 **/
644s32 igb_update_flash_i210(struct e1000_hw *hw)
645{
646 s32 ret_val = E1000_SUCCESS;
647 u32 flup;
648
649 ret_val = igb_pool_flash_update_done_i210(hw);
650 if (ret_val == -E1000_ERR_NVM) {
651 hw_dbg("Flash update time out\n");
652 goto out;
653 }
654
655 flup = rd32(E1000_EECD) | E1000_EECD_FLUPD_I210;
656 wr32(E1000_EECD, flup);
657
658 ret_val = igb_pool_flash_update_done_i210(hw);
659 if (ret_val == E1000_SUCCESS)
660 hw_dbg("Flash update complete\n");
661 else
662 hw_dbg("Flash update time out\n");
663
664out:
665 return ret_val;
666}
667
668/**
669 * igb_pool_flash_update_done_i210 - Pool FLUDONE status.
670 * @hw: pointer to the HW structure
671 *
672 **/
673s32 igb_pool_flash_update_done_i210(struct e1000_hw *hw)
674{
675 s32 ret_val = -E1000_ERR_NVM;
676 u32 i, reg;
677
678 for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
679 reg = rd32(E1000_EECD);
680 if (reg & E1000_EECD_FLUDONE_I210) {
681 ret_val = E1000_SUCCESS;
682 break;
683 }
684 udelay(5);
685 }
686
687 return ret_val;
688}
689
690/**
691 * igb_valid_led_default_i210 - Verify a valid default LED config
692 * @hw: pointer to the HW structure
693 * @data: pointer to the NVM (EEPROM)
694 *
695 * Read the EEPROM for the current default LED configuration. If the
696 * LED configuration is not valid, set to a valid LED configuration.
697 **/
698s32 igb_valid_led_default_i210(struct e1000_hw *hw, u16 *data)
699{
700 s32 ret_val;
701
702 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
703 if (ret_val) {
704 hw_dbg("NVM Read Error\n");
705 goto out;
706 }
707
708 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
709 switch (hw->phy.media_type) {
710 case e1000_media_type_internal_serdes:
711 *data = ID_LED_DEFAULT_I210_SERDES;
712 break;
713 case e1000_media_type_copper:
714 default:
715 *data = ID_LED_DEFAULT_I210;
716 break;
717 }
718 }
719out:
720 return ret_val;
721}