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