net/e1000/base: fall through explicitly
[dpdk.git] / drivers / net / e1000 / base / e1000_nvm.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001 - 2015 Intel Corporation
3  */
4
5 #include "e1000_api.h"
6
7 STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw);
8
9 /**
10  *  e1000_init_nvm_ops_generic - Initialize NVM function pointers
11  *  @hw: pointer to the HW structure
12  *
13  *  Setups up the function pointers to no-op functions
14  **/
15 void e1000_init_nvm_ops_generic(struct e1000_hw *hw)
16 {
17         struct e1000_nvm_info *nvm = &hw->nvm;
18         DEBUGFUNC("e1000_init_nvm_ops_generic");
19
20         /* Initialize function pointers */
21         nvm->ops.init_params = e1000_null_ops_generic;
22         nvm->ops.acquire = e1000_null_ops_generic;
23         nvm->ops.read = e1000_null_read_nvm;
24         nvm->ops.release = e1000_null_nvm_generic;
25         nvm->ops.reload = e1000_reload_nvm_generic;
26         nvm->ops.update = e1000_null_ops_generic;
27         nvm->ops.valid_led_default = e1000_null_led_default;
28         nvm->ops.validate = e1000_null_ops_generic;
29         nvm->ops.write = e1000_null_write_nvm;
30 }
31
32 /**
33  *  e1000_null_nvm_read - No-op function, return 0
34  *  @hw: pointer to the HW structure
35  **/
36 s32 e1000_null_read_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
37                         u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
38                         u16 E1000_UNUSEDARG *c)
39 {
40         DEBUGFUNC("e1000_null_read_nvm");
41         UNREFERENCED_4PARAMETER(hw, a, b, c);
42         return E1000_SUCCESS;
43 }
44
45 /**
46  *  e1000_null_nvm_generic - No-op function, return void
47  *  @hw: pointer to the HW structure
48  **/
49 void e1000_null_nvm_generic(struct e1000_hw E1000_UNUSEDARG *hw)
50 {
51         DEBUGFUNC("e1000_null_nvm_generic");
52         UNREFERENCED_1PARAMETER(hw);
53         return;
54 }
55
56 /**
57  *  e1000_null_led_default - No-op function, return 0
58  *  @hw: pointer to the HW structure
59  **/
60 s32 e1000_null_led_default(struct e1000_hw E1000_UNUSEDARG *hw,
61                            u16 E1000_UNUSEDARG *data)
62 {
63         DEBUGFUNC("e1000_null_led_default");
64         UNREFERENCED_2PARAMETER(hw, data);
65         return E1000_SUCCESS;
66 }
67
68 /**
69  *  e1000_null_write_nvm - No-op function, return 0
70  *  @hw: pointer to the HW structure
71  **/
72 s32 e1000_null_write_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
73                          u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
74                          u16 E1000_UNUSEDARG *c)
75 {
76         DEBUGFUNC("e1000_null_write_nvm");
77         UNREFERENCED_4PARAMETER(hw, a, b, c);
78         return E1000_SUCCESS;
79 }
80
81 /**
82  *  e1000_raise_eec_clk - Raise EEPROM clock
83  *  @hw: pointer to the HW structure
84  *  @eecd: pointer to the EEPROM
85  *
86  *  Enable/Raise the EEPROM clock bit.
87  **/
88 STATIC void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
89 {
90         *eecd = *eecd | E1000_EECD_SK;
91         E1000_WRITE_REG(hw, E1000_EECD, *eecd);
92         E1000_WRITE_FLUSH(hw);
93         usec_delay(hw->nvm.delay_usec);
94 }
95
96 /**
97  *  e1000_lower_eec_clk - Lower EEPROM clock
98  *  @hw: pointer to the HW structure
99  *  @eecd: pointer to the EEPROM
100  *
101  *  Clear/Lower the EEPROM clock bit.
102  **/
103 STATIC void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
104 {
105         *eecd = *eecd & ~E1000_EECD_SK;
106         E1000_WRITE_REG(hw, E1000_EECD, *eecd);
107         E1000_WRITE_FLUSH(hw);
108         usec_delay(hw->nvm.delay_usec);
109 }
110
111 /**
112  *  e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
113  *  @hw: pointer to the HW structure
114  *  @data: data to send to the EEPROM
115  *  @count: number of bits to shift out
116  *
117  *  We need to shift 'count' bits out to the EEPROM.  So, the value in the
118  *  "data" parameter will be shifted out to the EEPROM one bit at a time.
119  *  In order to do this, "data" must be broken down into bits.
120  **/
121 STATIC void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
122 {
123         struct e1000_nvm_info *nvm = &hw->nvm;
124         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
125         u32 mask;
126
127         DEBUGFUNC("e1000_shift_out_eec_bits");
128
129         mask = 0x01 << (count - 1);
130         if (nvm->type == e1000_nvm_eeprom_microwire)
131                 eecd &= ~E1000_EECD_DO;
132         else
133         if (nvm->type == e1000_nvm_eeprom_spi)
134                 eecd |= E1000_EECD_DO;
135
136         do {
137                 eecd &= ~E1000_EECD_DI;
138
139                 if (data & mask)
140                         eecd |= E1000_EECD_DI;
141
142                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
143                 E1000_WRITE_FLUSH(hw);
144
145                 usec_delay(nvm->delay_usec);
146
147                 e1000_raise_eec_clk(hw, &eecd);
148                 e1000_lower_eec_clk(hw, &eecd);
149
150                 mask >>= 1;
151         } while (mask);
152
153         eecd &= ~E1000_EECD_DI;
154         E1000_WRITE_REG(hw, E1000_EECD, eecd);
155 }
156
157 /**
158  *  e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
159  *  @hw: pointer to the HW structure
160  *  @count: number of bits to shift in
161  *
162  *  In order to read a register from the EEPROM, we need to shift 'count' bits
163  *  in from the EEPROM.  Bits are "shifted in" by raising the clock input to
164  *  the EEPROM (setting the SK bit), and then reading the value of the data out
165  *  "DO" bit.  During this "shifting in" process the data in "DI" bit should
166  *  always be clear.
167  **/
168 STATIC u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
169 {
170         u32 eecd;
171         u32 i;
172         u16 data;
173
174         DEBUGFUNC("e1000_shift_in_eec_bits");
175
176         eecd = E1000_READ_REG(hw, E1000_EECD);
177
178         eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
179         data = 0;
180
181         for (i = 0; i < count; i++) {
182                 data <<= 1;
183                 e1000_raise_eec_clk(hw, &eecd);
184
185                 eecd = E1000_READ_REG(hw, E1000_EECD);
186
187                 eecd &= ~E1000_EECD_DI;
188                 if (eecd & E1000_EECD_DO)
189                         data |= 1;
190
191                 e1000_lower_eec_clk(hw, &eecd);
192         }
193
194         return data;
195 }
196
197 /**
198  *  e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
199  *  @hw: pointer to the HW structure
200  *  @ee_reg: EEPROM flag for polling
201  *
202  *  Polls the EEPROM status bit for either read or write completion based
203  *  upon the value of 'ee_reg'.
204  **/
205 s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
206 {
207         u32 attempts = 100000;
208         u32 i, reg = 0;
209
210         DEBUGFUNC("e1000_poll_eerd_eewr_done");
211
212         for (i = 0; i < attempts; i++) {
213                 if (ee_reg == E1000_NVM_POLL_READ)
214                         reg = E1000_READ_REG(hw, E1000_EERD);
215                 else
216                         reg = E1000_READ_REG(hw, E1000_EEWR);
217
218                 if (reg & E1000_NVM_RW_REG_DONE)
219                         return E1000_SUCCESS;
220
221                 usec_delay(5);
222         }
223
224         return -E1000_ERR_NVM;
225 }
226
227 /**
228  *  e1000_acquire_nvm_generic - Generic request for access to EEPROM
229  *  @hw: pointer to the HW structure
230  *
231  *  Set the EEPROM access request bit and wait for EEPROM access grant bit.
232  *  Return successful if access grant bit set, else clear the request for
233  *  EEPROM access and return -E1000_ERR_NVM (-1).
234  **/
235 s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
236 {
237         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
238         s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
239
240         DEBUGFUNC("e1000_acquire_nvm_generic");
241
242         E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
243         eecd = E1000_READ_REG(hw, E1000_EECD);
244
245         while (timeout) {
246                 if (eecd & E1000_EECD_GNT)
247                         break;
248                 usec_delay(5);
249                 eecd = E1000_READ_REG(hw, E1000_EECD);
250                 timeout--;
251         }
252
253         if (!timeout) {
254                 eecd &= ~E1000_EECD_REQ;
255                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
256                 DEBUGOUT("Could not acquire NVM grant\n");
257                 return -E1000_ERR_NVM;
258         }
259
260         return E1000_SUCCESS;
261 }
262
263 /**
264  *  e1000_standby_nvm - Return EEPROM to standby state
265  *  @hw: pointer to the HW structure
266  *
267  *  Return the EEPROM to a standby state.
268  **/
269 STATIC void e1000_standby_nvm(struct e1000_hw *hw)
270 {
271         struct e1000_nvm_info *nvm = &hw->nvm;
272         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
273
274         DEBUGFUNC("e1000_standby_nvm");
275
276         if (nvm->type == e1000_nvm_eeprom_microwire) {
277                 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
278                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
279                 E1000_WRITE_FLUSH(hw);
280                 usec_delay(nvm->delay_usec);
281
282                 e1000_raise_eec_clk(hw, &eecd);
283
284                 /* Select EEPROM */
285                 eecd |= E1000_EECD_CS;
286                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
287                 E1000_WRITE_FLUSH(hw);
288                 usec_delay(nvm->delay_usec);
289
290                 e1000_lower_eec_clk(hw, &eecd);
291         } else if (nvm->type == e1000_nvm_eeprom_spi) {
292                 /* Toggle CS to flush commands */
293                 eecd |= E1000_EECD_CS;
294                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
295                 E1000_WRITE_FLUSH(hw);
296                 usec_delay(nvm->delay_usec);
297                 eecd &= ~E1000_EECD_CS;
298                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
299                 E1000_WRITE_FLUSH(hw);
300                 usec_delay(nvm->delay_usec);
301         }
302 }
303
304 /**
305  *  e1000_stop_nvm - Terminate EEPROM command
306  *  @hw: pointer to the HW structure
307  *
308  *  Terminates the current command by inverting the EEPROM's chip select pin.
309  **/
310 void e1000_stop_nvm(struct e1000_hw *hw)
311 {
312         u32 eecd;
313
314         DEBUGFUNC("e1000_stop_nvm");
315
316         eecd = E1000_READ_REG(hw, E1000_EECD);
317         if (hw->nvm.type == e1000_nvm_eeprom_spi) {
318                 /* Pull CS high */
319                 eecd |= E1000_EECD_CS;
320                 e1000_lower_eec_clk(hw, &eecd);
321         } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
322                 /* CS on Microwire is active-high */
323                 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
324                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
325                 e1000_raise_eec_clk(hw, &eecd);
326                 e1000_lower_eec_clk(hw, &eecd);
327         }
328 }
329
330 /**
331  *  e1000_release_nvm_generic - Release exclusive access to EEPROM
332  *  @hw: pointer to the HW structure
333  *
334  *  Stop any current commands to the EEPROM and clear the EEPROM request bit.
335  **/
336 void e1000_release_nvm_generic(struct e1000_hw *hw)
337 {
338         u32 eecd;
339
340         DEBUGFUNC("e1000_release_nvm_generic");
341
342         e1000_stop_nvm(hw);
343
344         eecd = E1000_READ_REG(hw, E1000_EECD);
345         eecd &= ~E1000_EECD_REQ;
346         E1000_WRITE_REG(hw, E1000_EECD, eecd);
347 }
348
349 /**
350  *  e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
351  *  @hw: pointer to the HW structure
352  *
353  *  Setups the EEPROM for reading and writing.
354  **/
355 STATIC s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
356 {
357         struct e1000_nvm_info *nvm = &hw->nvm;
358         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
359         u8 spi_stat_reg;
360
361         DEBUGFUNC("e1000_ready_nvm_eeprom");
362
363         if (nvm->type == e1000_nvm_eeprom_microwire) {
364                 /* Clear SK and DI */
365                 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
366                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
367                 /* Set CS */
368                 eecd |= E1000_EECD_CS;
369                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
370         } else if (nvm->type == e1000_nvm_eeprom_spi) {
371                 u16 timeout = NVM_MAX_RETRY_SPI;
372
373                 /* Clear SK and CS */
374                 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
375                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
376                 E1000_WRITE_FLUSH(hw);
377                 usec_delay(1);
378
379                 /* Read "Status Register" repeatedly until the LSB is cleared.
380                  * The EEPROM will signal that the command has been completed
381                  * by clearing bit 0 of the internal status register.  If it's
382                  * not cleared within 'timeout', then error out.
383                  */
384                 while (timeout) {
385                         e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
386                                                  hw->nvm.opcode_bits);
387                         spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
388                         if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
389                                 break;
390
391                         usec_delay(5);
392                         e1000_standby_nvm(hw);
393                         timeout--;
394                 }
395
396                 if (!timeout) {
397                         DEBUGOUT("SPI NVM Status error\n");
398                         return -E1000_ERR_NVM;
399                 }
400         }
401
402         return E1000_SUCCESS;
403 }
404
405 /**
406  *  e1000_read_nvm_spi - Read EEPROM's using SPI
407  *  @hw: pointer to the HW structure
408  *  @offset: offset of word in the EEPROM to read
409  *  @words: number of words to read
410  *  @data: word read from the EEPROM
411  *
412  *  Reads a 16 bit word from the EEPROM.
413  **/
414 s32 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
415 {
416         struct e1000_nvm_info *nvm = &hw->nvm;
417         u32 i = 0;
418         s32 ret_val;
419         u16 word_in;
420         u8 read_opcode = NVM_READ_OPCODE_SPI;
421
422         DEBUGFUNC("e1000_read_nvm_spi");
423
424         /* A check for invalid values:  offset too large, too many words,
425          * and not enough words.
426          */
427         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
428             (words == 0)) {
429                 DEBUGOUT("nvm parameter(s) out of bounds\n");
430                 return -E1000_ERR_NVM;
431         }
432
433         ret_val = nvm->ops.acquire(hw);
434         if (ret_val)
435                 return ret_val;
436
437         ret_val = e1000_ready_nvm_eeprom(hw);
438         if (ret_val)
439                 goto release;
440
441         e1000_standby_nvm(hw);
442
443         if ((nvm->address_bits == 8) && (offset >= 128))
444                 read_opcode |= NVM_A8_OPCODE_SPI;
445
446         /* Send the READ command (opcode + addr) */
447         e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
448         e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
449
450         /* Read the data.  SPI NVMs increment the address with each byte
451          * read and will roll over if reading beyond the end.  This allows
452          * us to read the whole NVM from any offset
453          */
454         for (i = 0; i < words; i++) {
455                 word_in = e1000_shift_in_eec_bits(hw, 16);
456                 data[i] = (word_in >> 8) | (word_in << 8);
457         }
458
459 release:
460         nvm->ops.release(hw);
461
462         return ret_val;
463 }
464
465 /**
466  *  e1000_read_nvm_microwire - Reads EEPROM's using microwire
467  *  @hw: pointer to the HW structure
468  *  @offset: offset of word in the EEPROM to read
469  *  @words: number of words to read
470  *  @data: word read from the EEPROM
471  *
472  *  Reads a 16 bit word from the EEPROM.
473  **/
474 s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
475                              u16 *data)
476 {
477         struct e1000_nvm_info *nvm = &hw->nvm;
478         u32 i = 0;
479         s32 ret_val;
480         u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
481
482         DEBUGFUNC("e1000_read_nvm_microwire");
483
484         /* A check for invalid values:  offset too large, too many words,
485          * and not enough words.
486          */
487         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
488             (words == 0)) {
489                 DEBUGOUT("nvm parameter(s) out of bounds\n");
490                 return -E1000_ERR_NVM;
491         }
492
493         ret_val = nvm->ops.acquire(hw);
494         if (ret_val)
495                 return ret_val;
496
497         ret_val = e1000_ready_nvm_eeprom(hw);
498         if (ret_val)
499                 goto release;
500
501         for (i = 0; i < words; i++) {
502                 /* Send the READ command (opcode + addr) */
503                 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
504                 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
505                                         nvm->address_bits);
506
507                 /* Read the data.  For microwire, each word requires the
508                  * overhead of setup and tear-down.
509                  */
510                 data[i] = e1000_shift_in_eec_bits(hw, 16);
511                 e1000_standby_nvm(hw);
512         }
513
514 release:
515         nvm->ops.release(hw);
516
517         return ret_val;
518 }
519
520 /**
521  *  e1000_read_nvm_eerd - Reads EEPROM using EERD register
522  *  @hw: pointer to the HW structure
523  *  @offset: offset of word in the EEPROM to read
524  *  @words: number of words to read
525  *  @data: word read from the EEPROM
526  *
527  *  Reads a 16 bit word from the EEPROM using the EERD register.
528  **/
529 s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
530 {
531         struct e1000_nvm_info *nvm = &hw->nvm;
532         u32 i, eerd = 0;
533         s32 ret_val = E1000_SUCCESS;
534
535         DEBUGFUNC("e1000_read_nvm_eerd");
536
537         /* A check for invalid values:  offset too large, too many words,
538          * too many words for the offset, and not enough words.
539          */
540         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
541             (words == 0)) {
542                 DEBUGOUT("nvm parameter(s) out of bounds\n");
543                 return -E1000_ERR_NVM;
544         }
545
546         for (i = 0; i < words; i++) {
547                 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
548                        E1000_NVM_RW_REG_START;
549
550                 E1000_WRITE_REG(hw, E1000_EERD, eerd);
551                 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
552                 if (ret_val)
553                         break;
554
555                 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
556                            E1000_NVM_RW_REG_DATA);
557         }
558
559         if (ret_val)
560                 DEBUGOUT1("NVM read error: %d\n", ret_val);
561
562         return ret_val;
563 }
564
565 /**
566  *  e1000_write_nvm_spi - Write to EEPROM using SPI
567  *  @hw: pointer to the HW structure
568  *  @offset: offset within the EEPROM to be written to
569  *  @words: number of words to write
570  *  @data: 16 bit word(s) to be written to the EEPROM
571  *
572  *  Writes data to EEPROM at offset using SPI interface.
573  *
574  *  If e1000_update_nvm_checksum is not called after this function , the
575  *  EEPROM will most likely contain an invalid checksum.
576  **/
577 s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
578 {
579         struct e1000_nvm_info *nvm = &hw->nvm;
580         s32 ret_val = -E1000_ERR_NVM;
581         u16 widx = 0;
582
583         DEBUGFUNC("e1000_write_nvm_spi");
584
585         /* A check for invalid values:  offset too large, too many words,
586          * and not enough words.
587          */
588         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
589             (words == 0)) {
590                 DEBUGOUT("nvm parameter(s) out of bounds\n");
591                 return -E1000_ERR_NVM;
592         }
593
594         while (widx < words) {
595                 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
596
597                 ret_val = nvm->ops.acquire(hw);
598                 if (ret_val)
599                         return ret_val;
600
601                 ret_val = e1000_ready_nvm_eeprom(hw);
602                 if (ret_val) {
603                         nvm->ops.release(hw);
604                         return ret_val;
605                 }
606
607                 e1000_standby_nvm(hw);
608
609                 /* Send the WRITE ENABLE command (8 bit opcode) */
610                 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
611                                          nvm->opcode_bits);
612
613                 e1000_standby_nvm(hw);
614
615                 /* Some SPI eeproms use the 8th address bit embedded in the
616                  * opcode
617                  */
618                 if ((nvm->address_bits == 8) && (offset >= 128))
619                         write_opcode |= NVM_A8_OPCODE_SPI;
620
621                 /* Send the Write command (8-bit opcode + addr) */
622                 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
623                 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
624                                          nvm->address_bits);
625
626                 /* Loop to allow for up to whole page write of eeprom */
627                 while (widx < words) {
628                         u16 word_out = data[widx];
629                         word_out = (word_out >> 8) | (word_out << 8);
630                         e1000_shift_out_eec_bits(hw, word_out, 16);
631                         widx++;
632
633                         if ((((offset + widx) * 2) % nvm->page_size) == 0) {
634                                 e1000_standby_nvm(hw);
635                                 break;
636                         }
637                 }
638                 msec_delay(10);
639                 nvm->ops.release(hw);
640         }
641
642         return ret_val;
643 }
644
645 /**
646  *  e1000_write_nvm_microwire - Writes EEPROM using microwire
647  *  @hw: pointer to the HW structure
648  *  @offset: offset within the EEPROM to be written to
649  *  @words: number of words to write
650  *  @data: 16 bit word(s) to be written to the EEPROM
651  *
652  *  Writes data to EEPROM at offset using microwire interface.
653  *
654  *  If e1000_update_nvm_checksum is not called after this function , the
655  *  EEPROM will most likely contain an invalid checksum.
656  **/
657 s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
658                               u16 *data)
659 {
660         struct e1000_nvm_info *nvm = &hw->nvm;
661         s32  ret_val;
662         u32 eecd;
663         u16 words_written = 0;
664         u16 widx = 0;
665
666         DEBUGFUNC("e1000_write_nvm_microwire");
667
668         /* A check for invalid values:  offset too large, too many words,
669          * and not enough words.
670          */
671         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
672             (words == 0)) {
673                 DEBUGOUT("nvm parameter(s) out of bounds\n");
674                 return -E1000_ERR_NVM;
675         }
676
677         ret_val = nvm->ops.acquire(hw);
678         if (ret_val)
679                 return ret_val;
680
681         ret_val = e1000_ready_nvm_eeprom(hw);
682         if (ret_val)
683                 goto release;
684
685         e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
686                                  (u16)(nvm->opcode_bits + 2));
687
688         e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
689
690         e1000_standby_nvm(hw);
691
692         while (words_written < words) {
693                 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
694                                          nvm->opcode_bits);
695
696                 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
697                                          nvm->address_bits);
698
699                 e1000_shift_out_eec_bits(hw, data[words_written], 16);
700
701                 e1000_standby_nvm(hw);
702
703                 for (widx = 0; widx < 200; widx++) {
704                         eecd = E1000_READ_REG(hw, E1000_EECD);
705                         if (eecd & E1000_EECD_DO)
706                                 break;
707                         usec_delay(50);
708                 }
709
710                 if (widx == 200) {
711                         DEBUGOUT("NVM Write did not complete\n");
712                         ret_val = -E1000_ERR_NVM;
713                         goto release;
714                 }
715
716                 e1000_standby_nvm(hw);
717
718                 words_written++;
719         }
720
721         e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
722                                  (u16)(nvm->opcode_bits + 2));
723
724         e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
725
726 release:
727         nvm->ops.release(hw);
728
729         return ret_val;
730 }
731
732 /**
733  *  e1000_read_pba_string_generic - Read device part number
734  *  @hw: pointer to the HW structure
735  *  @pba_num: pointer to device part number
736  *  @pba_num_size: size of part number buffer
737  *
738  *  Reads the product board assembly (PBA) number from the EEPROM and stores
739  *  the value in pba_num.
740  **/
741 s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
742                                   u32 pba_num_size)
743 {
744         s32 ret_val;
745         u16 nvm_data;
746         u16 pba_ptr;
747         u16 offset;
748         u16 length;
749
750         DEBUGFUNC("e1000_read_pba_string_generic");
751
752         if ((hw->mac.type == e1000_i210 ||
753              hw->mac.type == e1000_i211) &&
754              !e1000_get_flash_presence_i210(hw)) {
755                 DEBUGOUT("Flashless no PBA string\n");
756                 return -E1000_ERR_NVM_PBA_SECTION;
757         }
758
759         if (pba_num == NULL) {
760                 DEBUGOUT("PBA string buffer was null\n");
761                 return -E1000_ERR_INVALID_ARGUMENT;
762         }
763
764         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
765         if (ret_val) {
766                 DEBUGOUT("NVM Read Error\n");
767                 return ret_val;
768         }
769
770         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
771         if (ret_val) {
772                 DEBUGOUT("NVM Read Error\n");
773                 return ret_val;
774         }
775
776         /* if nvm_data is not ptr guard the PBA must be in legacy format which
777          * means pba_ptr is actually our second data word for the PBA number
778          * and we can decode it into an ascii string
779          */
780         if (nvm_data != NVM_PBA_PTR_GUARD) {
781                 DEBUGOUT("NVM PBA number is not stored as string\n");
782
783                 /* make sure callers buffer is big enough to store the PBA */
784                 if (pba_num_size < E1000_PBANUM_LENGTH) {
785                         DEBUGOUT("PBA string buffer too small\n");
786                         return E1000_ERR_NO_SPACE;
787                 }
788
789                 /* extract hex string from data and pba_ptr */
790                 pba_num[0] = (nvm_data >> 12) & 0xF;
791                 pba_num[1] = (nvm_data >> 8) & 0xF;
792                 pba_num[2] = (nvm_data >> 4) & 0xF;
793                 pba_num[3] = nvm_data & 0xF;
794                 pba_num[4] = (pba_ptr >> 12) & 0xF;
795                 pba_num[5] = (pba_ptr >> 8) & 0xF;
796                 pba_num[6] = '-';
797                 pba_num[7] = 0;
798                 pba_num[8] = (pba_ptr >> 4) & 0xF;
799                 pba_num[9] = pba_ptr & 0xF;
800
801                 /* put a null character on the end of our string */
802                 pba_num[10] = '\0';
803
804                 /* switch all the data but the '-' to hex char */
805                 for (offset = 0; offset < 10; offset++) {
806                         if (pba_num[offset] < 0xA)
807                                 pba_num[offset] += '0';
808                         else if (pba_num[offset] < 0x10)
809                                 pba_num[offset] += 'A' - 0xA;
810                 }
811
812                 return E1000_SUCCESS;
813         }
814
815         ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
816         if (ret_val) {
817                 DEBUGOUT("NVM Read Error\n");
818                 return ret_val;
819         }
820
821         if (length == 0xFFFF || length == 0) {
822                 DEBUGOUT("NVM PBA number section invalid length\n");
823                 return -E1000_ERR_NVM_PBA_SECTION;
824         }
825         /* check if pba_num buffer is big enough */
826         if (pba_num_size < (((u32)length * 2) - 1)) {
827                 DEBUGOUT("PBA string buffer too small\n");
828                 return -E1000_ERR_NO_SPACE;
829         }
830
831         /* trim pba length from start of string */
832         pba_ptr++;
833         length--;
834
835         for (offset = 0; offset < length; offset++) {
836                 ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
837                 if (ret_val) {
838                         DEBUGOUT("NVM Read Error\n");
839                         return ret_val;
840                 }
841                 pba_num[offset * 2] = (u8)(nvm_data >> 8);
842                 pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
843         }
844         pba_num[offset * 2] = '\0';
845
846         return E1000_SUCCESS;
847 }
848
849 /**
850  *  e1000_read_pba_length_generic - Read device part number length
851  *  @hw: pointer to the HW structure
852  *  @pba_num_size: size of part number buffer
853  *
854  *  Reads the product board assembly (PBA) number length from the EEPROM and
855  *  stores the value in pba_num_size.
856  **/
857 s32 e1000_read_pba_length_generic(struct e1000_hw *hw, u32 *pba_num_size)
858 {
859         s32 ret_val;
860         u16 nvm_data;
861         u16 pba_ptr;
862         u16 length;
863
864         DEBUGFUNC("e1000_read_pba_length_generic");
865
866         if (pba_num_size == NULL) {
867                 DEBUGOUT("PBA buffer size was null\n");
868                 return -E1000_ERR_INVALID_ARGUMENT;
869         }
870
871         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
872         if (ret_val) {
873                 DEBUGOUT("NVM Read Error\n");
874                 return ret_val;
875         }
876
877         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
878         if (ret_val) {
879                 DEBUGOUT("NVM Read Error\n");
880                 return ret_val;
881         }
882
883          /* if data is not ptr guard the PBA must be in legacy format */
884         if (nvm_data != NVM_PBA_PTR_GUARD) {
885                 *pba_num_size = E1000_PBANUM_LENGTH;
886                 return E1000_SUCCESS;
887         }
888
889         ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
890         if (ret_val) {
891                 DEBUGOUT("NVM Read Error\n");
892                 return ret_val;
893         }
894
895         if (length == 0xFFFF || length == 0) {
896                 DEBUGOUT("NVM PBA number section invalid length\n");
897                 return -E1000_ERR_NVM_PBA_SECTION;
898         }
899
900         /* Convert from length in u16 values to u8 chars, add 1 for NULL,
901          * and subtract 2 because length field is included in length.
902          */
903         *pba_num_size = ((u32)length * 2) - 1;
904
905         return E1000_SUCCESS;
906 }
907
908 /**
909  *  e1000_read_pba_num_generic - Read device part number
910  *  @hw: pointer to the HW structure
911  *  @pba_num: pointer to device part number
912  *
913  *  Reads the product board assembly (PBA) number from the EEPROM and stores
914  *  the value in pba_num.
915  **/
916 s32 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
917 {
918         s32 ret_val;
919         u16 nvm_data;
920
921         DEBUGFUNC("e1000_read_pba_num_generic");
922
923         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
924         if (ret_val) {
925                 DEBUGOUT("NVM Read Error\n");
926                 return ret_val;
927         } else if (nvm_data == NVM_PBA_PTR_GUARD) {
928                 DEBUGOUT("NVM Not Supported\n");
929                 return -E1000_NOT_IMPLEMENTED;
930         }
931         *pba_num = (u32)(nvm_data << 16);
932
933         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
934         if (ret_val) {
935                 DEBUGOUT("NVM Read Error\n");
936                 return ret_val;
937         }
938         *pba_num |= nvm_data;
939
940         return E1000_SUCCESS;
941 }
942
943
944 /**
945  *  e1000_read_pba_raw
946  *  @hw: pointer to the HW structure
947  *  @eeprom_buf: optional pointer to EEPROM image
948  *  @eeprom_buf_size: size of EEPROM image in words
949  *  @max_pba_block_size: PBA block size limit
950  *  @pba: pointer to output PBA structure
951  *
952  *  Reads PBA from EEPROM image when eeprom_buf is not NULL.
953  *  Reads PBA from physical EEPROM device when eeprom_buf is NULL.
954  *
955  **/
956 s32 e1000_read_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
957                        u32 eeprom_buf_size, u16 max_pba_block_size,
958                        struct e1000_pba *pba)
959 {
960         s32 ret_val;
961         u16 pba_block_size;
962
963         if (pba == NULL)
964                 return -E1000_ERR_PARAM;
965
966         if (eeprom_buf == NULL) {
967                 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2,
968                                          &pba->word[0]);
969                 if (ret_val)
970                         return ret_val;
971         } else {
972                 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
973                         pba->word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
974                         pba->word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
975                 } else {
976                         return -E1000_ERR_PARAM;
977                 }
978         }
979
980         if (pba->word[0] == NVM_PBA_PTR_GUARD) {
981                 if (pba->pba_block == NULL)
982                         return -E1000_ERR_PARAM;
983
984                 ret_val = e1000_get_pba_block_size(hw, eeprom_buf,
985                                                    eeprom_buf_size,
986                                                    &pba_block_size);
987                 if (ret_val)
988                         return ret_val;
989
990                 if (pba_block_size > max_pba_block_size)
991                         return -E1000_ERR_PARAM;
992
993                 if (eeprom_buf == NULL) {
994                         ret_val = e1000_read_nvm(hw, pba->word[1],
995                                                  pba_block_size,
996                                                  pba->pba_block);
997                         if (ret_val)
998                                 return ret_val;
999                 } else {
1000                         if (eeprom_buf_size > (u32)(pba->word[1] +
1001                                               pba_block_size)) {
1002                                 memcpy(pba->pba_block,
1003                                        &eeprom_buf[pba->word[1]],
1004                                        pba_block_size * sizeof(u16));
1005                         } else {
1006                                 return -E1000_ERR_PARAM;
1007                         }
1008                 }
1009         }
1010
1011         return E1000_SUCCESS;
1012 }
1013
1014 /**
1015  *  e1000_write_pba_raw
1016  *  @hw: pointer to the HW structure
1017  *  @eeprom_buf: optional pointer to EEPROM image
1018  *  @eeprom_buf_size: size of EEPROM image in words
1019  *  @pba: pointer to PBA structure
1020  *
1021  *  Writes PBA to EEPROM image when eeprom_buf is not NULL.
1022  *  Writes PBA to physical EEPROM device when eeprom_buf is NULL.
1023  *
1024  **/
1025 s32 e1000_write_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
1026                         u32 eeprom_buf_size, struct e1000_pba *pba)
1027 {
1028         s32 ret_val;
1029
1030         if (pba == NULL)
1031                 return -E1000_ERR_PARAM;
1032
1033         if (eeprom_buf == NULL) {
1034                 ret_val = e1000_write_nvm(hw, NVM_PBA_OFFSET_0, 2,
1035                                           &pba->word[0]);
1036                 if (ret_val)
1037                         return ret_val;
1038         } else {
1039                 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1040                         eeprom_buf[NVM_PBA_OFFSET_0] = pba->word[0];
1041                         eeprom_buf[NVM_PBA_OFFSET_1] = pba->word[1];
1042                 } else {
1043                         return -E1000_ERR_PARAM;
1044                 }
1045         }
1046
1047         if (pba->word[0] == NVM_PBA_PTR_GUARD) {
1048                 if (pba->pba_block == NULL)
1049                         return -E1000_ERR_PARAM;
1050
1051                 if (eeprom_buf == NULL) {
1052                         ret_val = e1000_write_nvm(hw, pba->word[1],
1053                                                   pba->pba_block[0],
1054                                                   pba->pba_block);
1055                         if (ret_val)
1056                                 return ret_val;
1057                 } else {
1058                         if (eeprom_buf_size > (u32)(pba->word[1] +
1059                                               pba->pba_block[0])) {
1060                                 memcpy(&eeprom_buf[pba->word[1]],
1061                                        pba->pba_block,
1062                                        pba->pba_block[0] * sizeof(u16));
1063                         } else {
1064                                 return -E1000_ERR_PARAM;
1065                         }
1066                 }
1067         }
1068
1069         return E1000_SUCCESS;
1070 }
1071
1072 /**
1073  *  e1000_get_pba_block_size
1074  *  @hw: pointer to the HW structure
1075  *  @eeprom_buf: optional pointer to EEPROM image
1076  *  @eeprom_buf_size: size of EEPROM image in words
1077  *  @pba_data_size: pointer to output variable
1078  *
1079  *  Returns the size of the PBA block in words. Function operates on EEPROM
1080  *  image if the eeprom_buf pointer is not NULL otherwise it accesses physical
1081  *  EEPROM device.
1082  *
1083  **/
1084 s32 e1000_get_pba_block_size(struct e1000_hw *hw, u16 *eeprom_buf,
1085                              u32 eeprom_buf_size, u16 *pba_block_size)
1086 {
1087         s32 ret_val;
1088         u16 pba_word[2];
1089         u16 length;
1090
1091         DEBUGFUNC("e1000_get_pba_block_size");
1092
1093         if (eeprom_buf == NULL) {
1094                 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2, &pba_word[0]);
1095                 if (ret_val)
1096                         return ret_val;
1097         } else {
1098                 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1099                         pba_word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
1100                         pba_word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
1101                 } else {
1102                         return -E1000_ERR_PARAM;
1103                 }
1104         }
1105
1106         if (pba_word[0] == NVM_PBA_PTR_GUARD) {
1107                 if (eeprom_buf == NULL) {
1108                         ret_val = e1000_read_nvm(hw, pba_word[1] + 0, 1,
1109                                                  &length);
1110                         if (ret_val)
1111                                 return ret_val;
1112                 } else {
1113                         if (eeprom_buf_size > pba_word[1])
1114                                 length = eeprom_buf[pba_word[1] + 0];
1115                         else
1116                                 return -E1000_ERR_PARAM;
1117                 }
1118
1119                 if (length == 0xFFFF || length == 0)
1120                         return -E1000_ERR_NVM_PBA_SECTION;
1121         } else {
1122                 /* PBA number in legacy format, there is no PBA Block. */
1123                 length = 0;
1124         }
1125
1126         if (pba_block_size != NULL)
1127                 *pba_block_size = length;
1128
1129         return E1000_SUCCESS;
1130 }
1131
1132 /**
1133  *  e1000_read_mac_addr_generic - Read device MAC address
1134  *  @hw: pointer to the HW structure
1135  *
1136  *  Reads the device MAC address from the EEPROM and stores the value.
1137  *  Since devices with two ports use the same EEPROM, we increment the
1138  *  last bit in the MAC address for the second port.
1139  **/
1140 s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
1141 {
1142         u32 rar_high;
1143         u32 rar_low;
1144         u16 i;
1145
1146         rar_high = E1000_READ_REG(hw, E1000_RAH(0));
1147         rar_low = E1000_READ_REG(hw, E1000_RAL(0));
1148
1149         for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
1150                 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
1151
1152         for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
1153                 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
1154
1155         for (i = 0; i < ETH_ADDR_LEN; i++)
1156                 hw->mac.addr[i] = hw->mac.perm_addr[i];
1157
1158         return E1000_SUCCESS;
1159 }
1160
1161 /**
1162  *  e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
1163  *  @hw: pointer to the HW structure
1164  *
1165  *  Calculates the EEPROM checksum by reading/adding each word of the EEPROM
1166  *  and then verifies that the sum of the EEPROM is equal to 0xBABA.
1167  **/
1168 s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
1169 {
1170         s32 ret_val;
1171         u16 checksum = 0;
1172         u16 i, nvm_data;
1173
1174         DEBUGFUNC("e1000_validate_nvm_checksum_generic");
1175
1176         for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
1177                 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1178                 if (ret_val) {
1179                         DEBUGOUT("NVM Read Error\n");
1180                         return ret_val;
1181                 }
1182                 checksum += nvm_data;
1183         }
1184
1185         if (checksum != (u16) NVM_SUM) {
1186                 DEBUGOUT("NVM Checksum Invalid\n");
1187                 return -E1000_ERR_NVM;
1188         }
1189
1190         return E1000_SUCCESS;
1191 }
1192
1193 /**
1194  *  e1000_update_nvm_checksum_generic - Update EEPROM checksum
1195  *  @hw: pointer to the HW structure
1196  *
1197  *  Updates the EEPROM checksum by reading/adding each word of the EEPROM
1198  *  up to the checksum.  Then calculates the EEPROM checksum and writes the
1199  *  value to the EEPROM.
1200  **/
1201 s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
1202 {
1203         s32 ret_val;
1204         u16 checksum = 0;
1205         u16 i, nvm_data;
1206
1207         DEBUGFUNC("e1000_update_nvm_checksum");
1208
1209         for (i = 0; i < NVM_CHECKSUM_REG; i++) {
1210                 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1211                 if (ret_val) {
1212                         DEBUGOUT("NVM Read Error while updating checksum.\n");
1213                         return ret_val;
1214                 }
1215                 checksum += nvm_data;
1216         }
1217         checksum = (u16) NVM_SUM - checksum;
1218         ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
1219         if (ret_val)
1220                 DEBUGOUT("NVM Write Error while updating checksum.\n");
1221
1222         return ret_val;
1223 }
1224
1225 /**
1226  *  e1000_reload_nvm_generic - Reloads EEPROM
1227  *  @hw: pointer to the HW structure
1228  *
1229  *  Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1230  *  extended control register.
1231  **/
1232 STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw)
1233 {
1234         u32 ctrl_ext;
1235
1236         DEBUGFUNC("e1000_reload_nvm_generic");
1237
1238         usec_delay(10);
1239         ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1240         ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1241         E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1242         E1000_WRITE_FLUSH(hw);
1243 }
1244
1245 /**
1246  *  e1000_get_fw_version - Get firmware version information
1247  *  @hw: pointer to the HW structure
1248  *  @fw_vers: pointer to output version structure
1249  *
1250  *  unsupported/not present features return 0 in version structure
1251  **/
1252 void e1000_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
1253 {
1254         u16 eeprom_verh, eeprom_verl, etrack_test, fw_version;
1255         u8 q, hval, rem, result;
1256         u16 comb_verh, comb_verl, comb_offset;
1257
1258         memset(fw_vers, 0, sizeof(struct e1000_fw_version));
1259
1260         /* basic eeprom version numbers, bits used vary by part and by tool
1261          * used to create the nvm images */
1262         /* Check which data format we have */
1263         switch (hw->mac.type) {
1264         case e1000_i211:
1265                 e1000_read_invm_version(hw, fw_vers);
1266                 return;
1267         case e1000_82575:
1268         case e1000_82576:
1269         case e1000_82580:
1270         case e1000_i354:
1271                 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1272                 /* Use this format, unless EETRACK ID exists,
1273                  * then use alternate format
1274                  */
1275                 if ((etrack_test &  NVM_MAJOR_MASK) != NVM_ETRACK_VALID) {
1276                         hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1277                         fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1278                                               >> NVM_MAJOR_SHIFT;
1279                         fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK)
1280                                               >> NVM_MINOR_SHIFT;
1281                         fw_vers->eep_build = (fw_version & NVM_IMAGE_ID_MASK);
1282                         goto etrack_id;
1283                 }
1284                 break;
1285         case e1000_i210:
1286                 if (!(e1000_get_flash_presence_i210(hw))) {
1287                         e1000_read_invm_version(hw, fw_vers);
1288                         return;
1289                 }
1290                 /* fall through */
1291         case e1000_i350:
1292                 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1293                 /* find combo image version */
1294                 hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
1295                 if ((comb_offset != 0x0) &&
1296                     (comb_offset != NVM_VER_INVALID)) {
1297
1298                         hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
1299                                          + 1), 1, &comb_verh);
1300                         hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
1301                                          1, &comb_verl);
1302
1303                         /* get Option Rom version if it exists and is valid */
1304                         if ((comb_verh && comb_verl) &&
1305                             ((comb_verh != NVM_VER_INVALID) &&
1306                              (comb_verl != NVM_VER_INVALID))) {
1307
1308                                 fw_vers->or_valid = true;
1309                                 fw_vers->or_major =
1310                                         comb_verl >> NVM_COMB_VER_SHFT;
1311                                 fw_vers->or_build =
1312                                         (comb_verl << NVM_COMB_VER_SHFT)
1313                                         | (comb_verh >> NVM_COMB_VER_SHFT);
1314                                 fw_vers->or_patch =
1315                                         comb_verh & NVM_COMB_VER_MASK;
1316                         }
1317                 }
1318                 break;
1319         default:
1320                 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1321                 return;
1322         }
1323         hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1324         fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1325                               >> NVM_MAJOR_SHIFT;
1326
1327         /* check for old style version format in newer images*/
1328         if ((fw_version & NVM_NEW_DEC_MASK) == 0x0) {
1329                 eeprom_verl = (fw_version & NVM_COMB_VER_MASK);
1330         } else {
1331                 eeprom_verl = (fw_version & NVM_MINOR_MASK)
1332                                 >> NVM_MINOR_SHIFT;
1333         }
1334         /* Convert minor value to hex before assigning to output struct
1335          * Val to be converted will not be higher than 99, per tool output
1336          */
1337         q = eeprom_verl / NVM_HEX_CONV;
1338         hval = q * NVM_HEX_TENS;
1339         rem = eeprom_verl % NVM_HEX_CONV;
1340         result = hval + rem;
1341         fw_vers->eep_minor = result;
1342
1343 etrack_id:
1344         if ((etrack_test &  NVM_MAJOR_MASK) == NVM_ETRACK_VALID) {
1345                 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl);
1346                 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh);
1347                 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT)
1348                         | eeprom_verl;
1349         } else if ((etrack_test & NVM_ETRACK_VALID) == 0) {
1350                 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verh);
1351                 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verl);
1352                 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) |
1353                                      eeprom_verl;
1354         }
1355 }
1356
1357