1 /******************************************************************************
2 SPDX-License-Identifier: BSD-3-Clause
4 Copyright (c) 2001-2020, Intel Corporation
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 3. Neither the name of the Intel Corporation nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************/
36 #include "e1000_api.h"
38 static void e1000_reload_nvm_generic(struct e1000_hw *hw);
41 * e1000_init_nvm_ops_generic - Initialize NVM function pointers
42 * @hw: pointer to the HW structure
44 * Setups up the function pointers to no-op functions
46 void e1000_init_nvm_ops_generic(struct e1000_hw *hw)
48 struct e1000_nvm_info *nvm = &hw->nvm;
49 DEBUGFUNC("e1000_init_nvm_ops_generic");
51 /* Initialize function pointers */
52 nvm->ops.init_params = e1000_null_ops_generic;
53 nvm->ops.acquire = e1000_null_ops_generic;
54 nvm->ops.read = e1000_null_read_nvm;
55 nvm->ops.release = e1000_null_nvm_generic;
56 nvm->ops.reload = e1000_reload_nvm_generic;
57 nvm->ops.update = e1000_null_ops_generic;
58 nvm->ops.valid_led_default = e1000_null_led_default;
59 nvm->ops.validate = e1000_null_ops_generic;
60 nvm->ops.write = e1000_null_write_nvm;
64 * e1000_null_nvm_read - No-op function, return 0
65 * @hw: pointer to the HW structure
70 s32 e1000_null_read_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
71 u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
72 u16 E1000_UNUSEDARG *c)
74 DEBUGFUNC("e1000_null_read_nvm");
79 * e1000_null_nvm_generic - No-op function, return void
80 * @hw: pointer to the HW structure
82 void e1000_null_nvm_generic(struct e1000_hw E1000_UNUSEDARG *hw)
84 DEBUGFUNC("e1000_null_nvm_generic");
89 * e1000_null_led_default - No-op function, return 0
90 * @hw: pointer to the HW structure
91 * @data: dummy variable
93 s32 e1000_null_led_default(struct e1000_hw E1000_UNUSEDARG *hw,
94 u16 E1000_UNUSEDARG *data)
96 DEBUGFUNC("e1000_null_led_default");
101 * e1000_null_write_nvm - No-op function, return 0
102 * @hw: pointer to the HW structure
107 s32 e1000_null_write_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
108 u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
109 u16 E1000_UNUSEDARG *c)
111 DEBUGFUNC("e1000_null_write_nvm");
112 return E1000_SUCCESS;
116 * e1000_raise_eec_clk - Raise EEPROM clock
117 * @hw: pointer to the HW structure
118 * @eecd: pointer to the EEPROM
120 * Enable/Raise the EEPROM clock bit.
122 static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
124 *eecd = *eecd | E1000_EECD_SK;
125 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
126 E1000_WRITE_FLUSH(hw);
127 usec_delay(hw->nvm.delay_usec);
131 * e1000_lower_eec_clk - Lower EEPROM clock
132 * @hw: pointer to the HW structure
133 * @eecd: pointer to the EEPROM
135 * Clear/Lower the EEPROM clock bit.
137 static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
139 *eecd = *eecd & ~E1000_EECD_SK;
140 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
141 E1000_WRITE_FLUSH(hw);
142 usec_delay(hw->nvm.delay_usec);
146 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
147 * @hw: pointer to the HW structure
148 * @data: data to send to the EEPROM
149 * @count: number of bits to shift out
151 * We need to shift 'count' bits out to the EEPROM. So, the value in the
152 * "data" parameter will be shifted out to the EEPROM one bit at a time.
153 * In order to do this, "data" must be broken down into bits.
155 static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
157 struct e1000_nvm_info *nvm = &hw->nvm;
158 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
161 DEBUGFUNC("e1000_shift_out_eec_bits");
163 mask = 0x01 << (count - 1);
164 if (nvm->type == e1000_nvm_eeprom_microwire)
165 eecd &= ~E1000_EECD_DO;
167 if (nvm->type == e1000_nvm_eeprom_spi)
168 eecd |= E1000_EECD_DO;
171 eecd &= ~E1000_EECD_DI;
174 eecd |= E1000_EECD_DI;
176 E1000_WRITE_REG(hw, E1000_EECD, eecd);
177 E1000_WRITE_FLUSH(hw);
179 usec_delay(nvm->delay_usec);
181 e1000_raise_eec_clk(hw, &eecd);
182 e1000_lower_eec_clk(hw, &eecd);
187 eecd &= ~E1000_EECD_DI;
188 E1000_WRITE_REG(hw, E1000_EECD, eecd);
192 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
193 * @hw: pointer to the HW structure
194 * @count: number of bits to shift in
196 * In order to read a register from the EEPROM, we need to shift 'count' bits
197 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
198 * the EEPROM (setting the SK bit), and then reading the value of the data out
199 * "DO" bit. During this "shifting in" process the data in "DI" bit should
202 static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
208 DEBUGFUNC("e1000_shift_in_eec_bits");
210 eecd = E1000_READ_REG(hw, E1000_EECD);
212 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
215 for (i = 0; i < count; i++) {
217 e1000_raise_eec_clk(hw, &eecd);
219 eecd = E1000_READ_REG(hw, E1000_EECD);
221 eecd &= ~E1000_EECD_DI;
222 if (eecd & E1000_EECD_DO)
225 e1000_lower_eec_clk(hw, &eecd);
232 * e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
233 * @hw: pointer to the HW structure
234 * @ee_reg: EEPROM flag for polling
236 * Polls the EEPROM status bit for either read or write completion based
237 * upon the value of 'ee_reg'.
239 s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
241 u32 attempts = 100000;
244 DEBUGFUNC("e1000_poll_eerd_eewr_done");
246 for (i = 0; i < attempts; i++) {
247 if (ee_reg == E1000_NVM_POLL_READ)
248 reg = E1000_READ_REG(hw, E1000_EERD);
250 reg = E1000_READ_REG(hw, E1000_EEWR);
252 if (reg & E1000_NVM_RW_REG_DONE)
253 return E1000_SUCCESS;
258 return -E1000_ERR_NVM;
262 * e1000_acquire_nvm_generic - Generic request for access to EEPROM
263 * @hw: pointer to the HW structure
265 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
266 * Return successful if access grant bit set, else clear the request for
267 * EEPROM access and return -E1000_ERR_NVM (-1).
269 s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
271 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
272 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
274 DEBUGFUNC("e1000_acquire_nvm_generic");
276 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
277 eecd = E1000_READ_REG(hw, E1000_EECD);
280 if (eecd & E1000_EECD_GNT)
283 eecd = E1000_READ_REG(hw, E1000_EECD);
288 eecd &= ~E1000_EECD_REQ;
289 E1000_WRITE_REG(hw, E1000_EECD, eecd);
290 DEBUGOUT("Could not acquire NVM grant\n");
291 return -E1000_ERR_NVM;
294 return E1000_SUCCESS;
298 * e1000_standby_nvm - Return EEPROM to standby state
299 * @hw: pointer to the HW structure
301 * Return the EEPROM to a standby state.
303 static void e1000_standby_nvm(struct e1000_hw *hw)
305 struct e1000_nvm_info *nvm = &hw->nvm;
306 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
308 DEBUGFUNC("e1000_standby_nvm");
310 if (nvm->type == e1000_nvm_eeprom_microwire) {
311 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
312 E1000_WRITE_REG(hw, E1000_EECD, eecd);
313 E1000_WRITE_FLUSH(hw);
314 usec_delay(nvm->delay_usec);
316 e1000_raise_eec_clk(hw, &eecd);
319 eecd |= E1000_EECD_CS;
320 E1000_WRITE_REG(hw, E1000_EECD, eecd);
321 E1000_WRITE_FLUSH(hw);
322 usec_delay(nvm->delay_usec);
324 e1000_lower_eec_clk(hw, &eecd);
325 } else if (nvm->type == e1000_nvm_eeprom_spi) {
326 /* Toggle CS to flush commands */
327 eecd |= E1000_EECD_CS;
328 E1000_WRITE_REG(hw, E1000_EECD, eecd);
329 E1000_WRITE_FLUSH(hw);
330 usec_delay(nvm->delay_usec);
331 eecd &= ~E1000_EECD_CS;
332 E1000_WRITE_REG(hw, E1000_EECD, eecd);
333 E1000_WRITE_FLUSH(hw);
334 usec_delay(nvm->delay_usec);
339 * e1000_stop_nvm - Terminate EEPROM command
340 * @hw: pointer to the HW structure
342 * Terminates the current command by inverting the EEPROM's chip select pin.
344 void e1000_stop_nvm(struct e1000_hw *hw)
348 DEBUGFUNC("e1000_stop_nvm");
350 eecd = E1000_READ_REG(hw, E1000_EECD);
351 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
353 eecd |= E1000_EECD_CS;
354 e1000_lower_eec_clk(hw, &eecd);
355 } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
356 /* CS on Microwire is active-high */
357 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
358 E1000_WRITE_REG(hw, E1000_EECD, eecd);
359 e1000_raise_eec_clk(hw, &eecd);
360 e1000_lower_eec_clk(hw, &eecd);
365 * e1000_release_nvm_generic - Release exclusive access to EEPROM
366 * @hw: pointer to the HW structure
368 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
370 void e1000_release_nvm_generic(struct e1000_hw *hw)
374 DEBUGFUNC("e1000_release_nvm_generic");
378 eecd = E1000_READ_REG(hw, E1000_EECD);
379 eecd &= ~E1000_EECD_REQ;
380 E1000_WRITE_REG(hw, E1000_EECD, eecd);
384 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
385 * @hw: pointer to the HW structure
387 * Setups the EEPROM for reading and writing.
389 static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
391 struct e1000_nvm_info *nvm = &hw->nvm;
392 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
395 DEBUGFUNC("e1000_ready_nvm_eeprom");
397 if (nvm->type == e1000_nvm_eeprom_microwire) {
398 /* Clear SK and DI */
399 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
400 E1000_WRITE_REG(hw, E1000_EECD, eecd);
402 eecd |= E1000_EECD_CS;
403 E1000_WRITE_REG(hw, E1000_EECD, eecd);
404 } else if (nvm->type == e1000_nvm_eeprom_spi) {
405 u16 timeout = NVM_MAX_RETRY_SPI;
407 /* Clear SK and CS */
408 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
409 E1000_WRITE_REG(hw, E1000_EECD, eecd);
410 E1000_WRITE_FLUSH(hw);
413 /* Read "Status Register" repeatedly until the LSB is cleared.
414 * The EEPROM will signal that the command has been completed
415 * by clearing bit 0 of the internal status register. If it's
416 * not cleared within 'timeout', then error out.
419 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
420 hw->nvm.opcode_bits);
421 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
422 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
426 e1000_standby_nvm(hw);
431 DEBUGOUT("SPI NVM Status error\n");
432 return -E1000_ERR_NVM;
436 return E1000_SUCCESS;
440 * e1000_read_nvm_spi - Read EEPROM's using SPI
441 * @hw: pointer to the HW structure
442 * @offset: offset of word in the EEPROM to read
443 * @words: number of words to read
444 * @data: word read from the EEPROM
446 * Reads a 16 bit word from the EEPROM.
448 s32 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
450 struct e1000_nvm_info *nvm = &hw->nvm;
454 u8 read_opcode = NVM_READ_OPCODE_SPI;
456 DEBUGFUNC("e1000_read_nvm_spi");
458 /* A check for invalid values: offset too large, too many words,
459 * and not enough words.
461 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
463 DEBUGOUT("nvm parameter(s) out of bounds\n");
464 return -E1000_ERR_NVM;
467 ret_val = nvm->ops.acquire(hw);
471 ret_val = e1000_ready_nvm_eeprom(hw);
475 e1000_standby_nvm(hw);
477 if ((nvm->address_bits == 8) && (offset >= 128))
478 read_opcode |= NVM_A8_OPCODE_SPI;
480 /* Send the READ command (opcode + addr) */
481 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
482 e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
484 /* Read the data. SPI NVMs increment the address with each byte
485 * read and will roll over if reading beyond the end. This allows
486 * us to read the whole NVM from any offset
488 for (i = 0; i < words; i++) {
489 word_in = e1000_shift_in_eec_bits(hw, 16);
490 data[i] = (word_in >> 8) | (word_in << 8);
494 nvm->ops.release(hw);
500 * e1000_read_nvm_microwire - Reads EEPROM's using microwire
501 * @hw: pointer to the HW structure
502 * @offset: offset of word in the EEPROM to read
503 * @words: number of words to read
504 * @data: word read from the EEPROM
506 * Reads a 16 bit word from the EEPROM.
508 s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
511 struct e1000_nvm_info *nvm = &hw->nvm;
514 u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
516 DEBUGFUNC("e1000_read_nvm_microwire");
518 /* A check for invalid values: offset too large, too many words,
519 * and not enough words.
521 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
523 DEBUGOUT("nvm parameter(s) out of bounds\n");
524 return -E1000_ERR_NVM;
527 ret_val = nvm->ops.acquire(hw);
531 ret_val = e1000_ready_nvm_eeprom(hw);
535 for (i = 0; i < words; i++) {
536 /* Send the READ command (opcode + addr) */
537 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
538 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
541 /* Read the data. For microwire, each word requires the
542 * overhead of setup and tear-down.
544 data[i] = e1000_shift_in_eec_bits(hw, 16);
545 e1000_standby_nvm(hw);
549 nvm->ops.release(hw);
555 * e1000_read_nvm_eerd - Reads EEPROM using EERD register
556 * @hw: pointer to the HW structure
557 * @offset: offset of word in the EEPROM to read
558 * @words: number of words to read
559 * @data: word read from the EEPROM
561 * Reads a 16 bit word from the EEPROM using the EERD register.
563 s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
565 struct e1000_nvm_info *nvm = &hw->nvm;
567 s32 ret_val = E1000_SUCCESS;
569 DEBUGFUNC("e1000_read_nvm_eerd");
571 /* A check for invalid values: offset too large, too many words,
572 * too many words for the offset, and not enough words.
574 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
576 DEBUGOUT("nvm parameter(s) out of bounds\n");
577 return -E1000_ERR_NVM;
580 for (i = 0; i < words; i++) {
581 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
582 E1000_NVM_RW_REG_START;
584 E1000_WRITE_REG(hw, E1000_EERD, eerd);
585 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
589 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
590 E1000_NVM_RW_REG_DATA);
594 DEBUGOUT1("NVM read error: %d\n", ret_val);
600 * e1000_write_nvm_spi - Write to EEPROM using SPI
601 * @hw: pointer to the HW structure
602 * @offset: offset within the EEPROM to be written to
603 * @words: number of words to write
604 * @data: 16 bit word(s) to be written to the EEPROM
606 * Writes data to EEPROM at offset using SPI interface.
608 * If e1000_update_nvm_checksum is not called after this function , the
609 * EEPROM will most likely contain an invalid checksum.
611 s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
613 struct e1000_nvm_info *nvm = &hw->nvm;
614 s32 ret_val = -E1000_ERR_NVM;
617 DEBUGFUNC("e1000_write_nvm_spi");
619 /* A check for invalid values: offset too large, too many words,
620 * and not enough words.
622 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
624 DEBUGOUT("nvm parameter(s) out of bounds\n");
625 return -E1000_ERR_NVM;
628 while (widx < words) {
629 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
631 ret_val = nvm->ops.acquire(hw);
635 ret_val = e1000_ready_nvm_eeprom(hw);
637 nvm->ops.release(hw);
641 e1000_standby_nvm(hw);
643 /* Send the WRITE ENABLE command (8 bit opcode) */
644 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
647 e1000_standby_nvm(hw);
649 /* Some SPI eeproms use the 8th address bit embedded in the
652 if ((nvm->address_bits == 8) && (offset >= 128))
653 write_opcode |= NVM_A8_OPCODE_SPI;
655 /* Send the Write command (8-bit opcode + addr) */
656 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
657 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
660 /* Loop to allow for up to whole page write of eeprom */
661 while (widx < words) {
662 u16 word_out = data[widx];
663 word_out = (word_out >> 8) | (word_out << 8);
664 e1000_shift_out_eec_bits(hw, word_out, 16);
667 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
668 e1000_standby_nvm(hw);
673 nvm->ops.release(hw);
680 * e1000_write_nvm_microwire - Writes EEPROM using microwire
681 * @hw: pointer to the HW structure
682 * @offset: offset within the EEPROM to be written to
683 * @words: number of words to write
684 * @data: 16 bit word(s) to be written to the EEPROM
686 * Writes data to EEPROM at offset using microwire interface.
688 * If e1000_update_nvm_checksum is not called after this function , the
689 * EEPROM will most likely contain an invalid checksum.
691 s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
694 struct e1000_nvm_info *nvm = &hw->nvm;
697 u16 words_written = 0;
700 DEBUGFUNC("e1000_write_nvm_microwire");
702 /* A check for invalid values: offset too large, too many words,
703 * and not enough words.
705 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
707 DEBUGOUT("nvm parameter(s) out of bounds\n");
708 return -E1000_ERR_NVM;
711 ret_val = nvm->ops.acquire(hw);
715 ret_val = e1000_ready_nvm_eeprom(hw);
719 e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
720 (u16)(nvm->opcode_bits + 2));
722 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
724 e1000_standby_nvm(hw);
726 while (words_written < words) {
727 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
730 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
733 e1000_shift_out_eec_bits(hw, data[words_written], 16);
735 e1000_standby_nvm(hw);
737 for (widx = 0; widx < 200; widx++) {
738 eecd = E1000_READ_REG(hw, E1000_EECD);
739 if (eecd & E1000_EECD_DO)
745 DEBUGOUT("NVM Write did not complete\n");
746 ret_val = -E1000_ERR_NVM;
750 e1000_standby_nvm(hw);
755 e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
756 (u16)(nvm->opcode_bits + 2));
758 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
761 nvm->ops.release(hw);
767 * e1000_read_pba_string_generic - Read device part number
768 * @hw: pointer to the HW structure
769 * @pba_num: pointer to device part number
770 * @pba_num_size: size of part number buffer
772 * Reads the product board assembly (PBA) number from the EEPROM and stores
773 * the value in pba_num.
775 s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
784 DEBUGFUNC("e1000_read_pba_string_generic");
786 if ((hw->mac.type == e1000_i210 ||
787 hw->mac.type == e1000_i211) &&
788 !e1000_get_flash_presence_i210(hw)) {
789 DEBUGOUT("Flashless no PBA string\n");
790 return -E1000_ERR_NVM_PBA_SECTION;
793 if (pba_num == NULL) {
794 DEBUGOUT("PBA string buffer was null\n");
795 return -E1000_ERR_INVALID_ARGUMENT;
798 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
800 DEBUGOUT("NVM Read Error\n");
804 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
806 DEBUGOUT("NVM Read Error\n");
810 /* if nvm_data is not ptr guard the PBA must be in legacy format which
811 * means pba_ptr is actually our second data word for the PBA number
812 * and we can decode it into an ascii string
814 if (nvm_data != NVM_PBA_PTR_GUARD) {
815 DEBUGOUT("NVM PBA number is not stored as string\n");
817 /* make sure callers buffer is big enough to store the PBA */
818 if (pba_num_size < E1000_PBANUM_LENGTH) {
819 DEBUGOUT("PBA string buffer too small\n");
820 return E1000_ERR_NO_SPACE;
823 /* extract hex string from data and pba_ptr */
824 pba_num[0] = (nvm_data >> 12) & 0xF;
825 pba_num[1] = (nvm_data >> 8) & 0xF;
826 pba_num[2] = (nvm_data >> 4) & 0xF;
827 pba_num[3] = nvm_data & 0xF;
828 pba_num[4] = (pba_ptr >> 12) & 0xF;
829 pba_num[5] = (pba_ptr >> 8) & 0xF;
832 pba_num[8] = (pba_ptr >> 4) & 0xF;
833 pba_num[9] = pba_ptr & 0xF;
835 /* put a null character on the end of our string */
838 /* switch all the data but the '-' to hex char */
839 for (offset = 0; offset < 10; offset++) {
840 if (pba_num[offset] < 0xA)
841 pba_num[offset] += '0';
842 else if (pba_num[offset] < 0x10)
843 pba_num[offset] += 'A' - 0xA;
846 return E1000_SUCCESS;
849 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
851 DEBUGOUT("NVM Read Error\n");
855 if (length == 0xFFFF || length == 0) {
856 DEBUGOUT("NVM PBA number section invalid length\n");
857 return -E1000_ERR_NVM_PBA_SECTION;
859 /* check if pba_num buffer is big enough */
860 if (pba_num_size < (((u32)length * 2) - 1)) {
861 DEBUGOUT("PBA string buffer too small\n");
862 return -E1000_ERR_NO_SPACE;
865 /* trim pba length from start of string */
869 for (offset = 0; offset < length; offset++) {
870 ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
872 DEBUGOUT("NVM Read Error\n");
875 pba_num[offset * 2] = (u8)(nvm_data >> 8);
876 pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
878 pba_num[offset * 2] = '\0';
880 return E1000_SUCCESS;
884 * e1000_read_pba_length_generic - Read device part number length
885 * @hw: pointer to the HW structure
886 * @pba_num_size: size of part number buffer
888 * Reads the product board assembly (PBA) number length from the EEPROM and
889 * stores the value in pba_num_size.
891 s32 e1000_read_pba_length_generic(struct e1000_hw *hw, u32 *pba_num_size)
898 DEBUGFUNC("e1000_read_pba_length_generic");
900 if (pba_num_size == NULL) {
901 DEBUGOUT("PBA buffer size was null\n");
902 return -E1000_ERR_INVALID_ARGUMENT;
905 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
907 DEBUGOUT("NVM Read Error\n");
911 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
913 DEBUGOUT("NVM Read Error\n");
917 /* if data is not ptr guard the PBA must be in legacy format */
918 if (nvm_data != NVM_PBA_PTR_GUARD) {
919 *pba_num_size = E1000_PBANUM_LENGTH;
920 return E1000_SUCCESS;
923 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
925 DEBUGOUT("NVM Read Error\n");
929 if (length == 0xFFFF || length == 0) {
930 DEBUGOUT("NVM PBA number section invalid length\n");
931 return -E1000_ERR_NVM_PBA_SECTION;
934 /* Convert from length in u16 values to u8 chars, add 1 for NULL,
935 * and subtract 2 because length field is included in length.
937 *pba_num_size = ((u32)length * 2) - 1;
939 return E1000_SUCCESS;
943 * e1000_read_pba_num_generic - Read device part number
944 * @hw: pointer to the HW structure
945 * @pba_num: pointer to device part number
947 * Reads the product board assembly (PBA) number from the EEPROM and stores
948 * the value in pba_num.
950 s32 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
955 DEBUGFUNC("e1000_read_pba_num_generic");
957 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
959 DEBUGOUT("NVM Read Error\n");
961 } else if (nvm_data == NVM_PBA_PTR_GUARD) {
962 DEBUGOUT("NVM Not Supported\n");
963 return -E1000_NOT_IMPLEMENTED;
965 *pba_num = (u32)(nvm_data << 16);
967 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
969 DEBUGOUT("NVM Read Error\n");
972 *pba_num |= nvm_data;
974 return E1000_SUCCESS;
980 * @hw: pointer to the HW structure
981 * @eeprom_buf: optional pointer to EEPROM image
982 * @eeprom_buf_size: size of EEPROM image in words
983 * @max_pba_block_size: PBA block size limit
984 * @pba: pointer to output PBA structure
986 * Reads PBA from EEPROM image when eeprom_buf is not NULL.
987 * Reads PBA from physical EEPROM device when eeprom_buf is NULL.
990 s32 e1000_read_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
991 u32 eeprom_buf_size, u16 max_pba_block_size,
992 struct e1000_pba *pba)
998 return -E1000_ERR_PARAM;
1000 if (eeprom_buf == NULL) {
1001 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2,
1006 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1007 pba->word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
1008 pba->word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
1010 return -E1000_ERR_PARAM;
1014 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
1015 if (pba->pba_block == NULL)
1016 return -E1000_ERR_PARAM;
1018 ret_val = e1000_get_pba_block_size(hw, eeprom_buf,
1024 if (pba_block_size > max_pba_block_size)
1025 return -E1000_ERR_PARAM;
1027 if (eeprom_buf == NULL) {
1028 ret_val = e1000_read_nvm(hw, pba->word[1],
1034 if (eeprom_buf_size > (u32)(pba->word[1] +
1036 memcpy(pba->pba_block,
1037 &eeprom_buf[pba->word[1]],
1038 pba_block_size * sizeof(u16));
1040 return -E1000_ERR_PARAM;
1045 return E1000_SUCCESS;
1049 * e1000_write_pba_raw
1050 * @hw: pointer to the HW structure
1051 * @eeprom_buf: optional pointer to EEPROM image
1052 * @eeprom_buf_size: size of EEPROM image in words
1053 * @pba: pointer to PBA structure
1055 * Writes PBA to EEPROM image when eeprom_buf is not NULL.
1056 * Writes PBA to physical EEPROM device when eeprom_buf is NULL.
1059 s32 e1000_write_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
1060 u32 eeprom_buf_size, struct e1000_pba *pba)
1065 return -E1000_ERR_PARAM;
1067 if (eeprom_buf == NULL) {
1068 ret_val = e1000_write_nvm(hw, NVM_PBA_OFFSET_0, 2,
1073 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1074 eeprom_buf[NVM_PBA_OFFSET_0] = pba->word[0];
1075 eeprom_buf[NVM_PBA_OFFSET_1] = pba->word[1];
1077 return -E1000_ERR_PARAM;
1081 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
1082 if (pba->pba_block == NULL)
1083 return -E1000_ERR_PARAM;
1085 if (eeprom_buf == NULL) {
1086 ret_val = e1000_write_nvm(hw, pba->word[1],
1092 if (eeprom_buf_size > (u32)(pba->word[1] +
1093 pba->pba_block[0])) {
1094 memcpy(&eeprom_buf[pba->word[1]],
1096 pba->pba_block[0] * sizeof(u16));
1098 return -E1000_ERR_PARAM;
1103 return E1000_SUCCESS;
1107 * e1000_get_pba_block_size
1108 * @hw: pointer to the HW structure
1109 * @eeprom_buf: optional pointer to EEPROM image
1110 * @eeprom_buf_size: size of EEPROM image in words
1111 * @pba_data_size: pointer to output variable
1113 * Returns the size of the PBA block in words. Function operates on EEPROM
1114 * image if the eeprom_buf pointer is not NULL otherwise it accesses physical
1118 s32 e1000_get_pba_block_size(struct e1000_hw *hw, u16 *eeprom_buf,
1119 u32 eeprom_buf_size, u16 *pba_block_size)
1125 DEBUGFUNC("e1000_get_pba_block_size");
1127 if (eeprom_buf == NULL) {
1128 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2, &pba_word[0]);
1132 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1133 pba_word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
1134 pba_word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
1136 return -E1000_ERR_PARAM;
1140 if (pba_word[0] == NVM_PBA_PTR_GUARD) {
1141 if (eeprom_buf == NULL) {
1142 ret_val = e1000_read_nvm(hw, pba_word[1] + 0, 1,
1147 if (eeprom_buf_size > pba_word[1])
1148 length = eeprom_buf[pba_word[1] + 0];
1150 return -E1000_ERR_PARAM;
1153 if (length == 0xFFFF || length == 0)
1154 return -E1000_ERR_NVM_PBA_SECTION;
1156 /* PBA number in legacy format, there is no PBA Block. */
1160 if (pba_block_size != NULL)
1161 *pba_block_size = length;
1163 return E1000_SUCCESS;
1167 * e1000_read_mac_addr_generic - Read device MAC address
1168 * @hw: pointer to the HW structure
1170 * Reads the device MAC address from the EEPROM and stores the value.
1171 * Since devices with two ports use the same EEPROM, we increment the
1172 * last bit in the MAC address for the second port.
1174 s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
1180 rar_high = E1000_READ_REG(hw, E1000_RAH(0));
1181 rar_low = E1000_READ_REG(hw, E1000_RAL(0));
1183 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
1184 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
1186 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
1187 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
1189 for (i = 0; i < ETHER_ADDR_LEN; i++)
1190 hw->mac.addr[i] = hw->mac.perm_addr[i];
1192 return E1000_SUCCESS;
1196 * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
1197 * @hw: pointer to the HW structure
1199 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
1200 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
1202 s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
1208 DEBUGFUNC("e1000_validate_nvm_checksum_generic");
1210 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
1211 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1213 DEBUGOUT("NVM Read Error\n");
1216 checksum += nvm_data;
1219 if (checksum != (u16) NVM_SUM) {
1220 DEBUGOUT("NVM Checksum Invalid\n");
1221 return -E1000_ERR_NVM;
1224 return E1000_SUCCESS;
1228 * e1000_update_nvm_checksum_generic - Update EEPROM checksum
1229 * @hw: pointer to the HW structure
1231 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
1232 * up to the checksum. Then calculates the EEPROM checksum and writes the
1233 * value to the EEPROM.
1235 s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
1241 DEBUGFUNC("e1000_update_nvm_checksum");
1243 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
1244 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1246 DEBUGOUT("NVM Read Error while updating checksum.\n");
1249 checksum += nvm_data;
1251 checksum = (u16) NVM_SUM - checksum;
1252 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
1254 DEBUGOUT("NVM Write Error while updating checksum.\n");
1260 * e1000_reload_nvm_generic - Reloads EEPROM
1261 * @hw: pointer to the HW structure
1263 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1264 * extended control register.
1266 static void e1000_reload_nvm_generic(struct e1000_hw *hw)
1270 DEBUGFUNC("e1000_reload_nvm_generic");
1273 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1274 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1275 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1276 E1000_WRITE_FLUSH(hw);
1280 * e1000_get_fw_version - Get firmware version information
1281 * @hw: pointer to the HW structure
1282 * @fw_vers: pointer to output version structure
1284 * unsupported/not present features return 0 in version structure
1286 void e1000_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
1288 u16 eeprom_verh, eeprom_verl, etrack_test, fw_version;
1289 u8 q, hval, rem, result;
1290 u16 comb_verh, comb_verl, comb_offset;
1292 memset(fw_vers, 0, sizeof(struct e1000_fw_version));
1294 /* basic eeprom version numbers, bits used vary by part and by tool
1295 * used to create the nvm images */
1296 /* Check which data format we have */
1297 switch (hw->mac.type) {
1299 e1000_read_invm_version(hw, fw_vers);
1305 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1306 /* Use this format, unless EETRACK ID exists,
1307 * then use alternate format
1309 if ((etrack_test & NVM_MAJOR_MASK) != NVM_ETRACK_VALID) {
1310 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1311 fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1313 fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK)
1315 fw_vers->eep_build = (fw_version & NVM_IMAGE_ID_MASK);
1320 if (!(e1000_get_flash_presence_i210(hw))) {
1321 e1000_read_invm_version(hw, fw_vers);
1326 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1327 /* find combo image version */
1328 hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
1329 if ((comb_offset != 0x0) &&
1330 (comb_offset != NVM_VER_INVALID)) {
1332 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
1333 + 1), 1, &comb_verh);
1334 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
1337 /* get Option Rom version if it exists and is valid */
1338 if ((comb_verh && comb_verl) &&
1339 ((comb_verh != NVM_VER_INVALID) &&
1340 (comb_verl != NVM_VER_INVALID))) {
1342 fw_vers->or_valid = true;
1344 comb_verl >> NVM_COMB_VER_SHFT;
1346 (comb_verl << NVM_COMB_VER_SHFT)
1347 | (comb_verh >> NVM_COMB_VER_SHFT);
1349 comb_verh & NVM_COMB_VER_MASK;
1354 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1357 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1358 fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1361 /* check for old style version format in newer images*/
1362 if ((fw_version & NVM_NEW_DEC_MASK) == 0x0) {
1363 eeprom_verl = (fw_version & NVM_COMB_VER_MASK);
1365 eeprom_verl = (fw_version & NVM_MINOR_MASK)
1368 /* Convert minor value to hex before assigning to output struct
1369 * Val to be converted will not be higher than 99, per tool output
1371 q = eeprom_verl / NVM_HEX_CONV;
1372 hval = q * NVM_HEX_TENS;
1373 rem = eeprom_verl % NVM_HEX_CONV;
1374 result = hval + rem;
1375 fw_vers->eep_minor = result;
1378 if ((etrack_test & NVM_MAJOR_MASK) == NVM_ETRACK_VALID) {
1379 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl);
1380 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh);
1381 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT)
1383 } else if ((etrack_test & NVM_ETRACK_VALID) == 0) {
1384 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verh);
1385 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verl);
1386 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) |