1 /*******************************************************************************
3 Copyright (c) 2001-2012, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
34 #include "e1000_api.h"
36 STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw);
39 * e1000_init_nvm_ops_generic - Initialize NVM function pointers
40 * @hw: pointer to the HW structure
42 * Setups up the function pointers to no-op functions
44 void e1000_init_nvm_ops_generic(struct e1000_hw *hw)
46 struct e1000_nvm_info *nvm = &hw->nvm;
47 DEBUGFUNC("e1000_init_nvm_ops_generic");
49 /* Initialize function pointers */
50 nvm->ops.init_params = e1000_null_ops_generic;
51 nvm->ops.acquire = e1000_null_ops_generic;
52 nvm->ops.read = e1000_null_read_nvm;
53 nvm->ops.release = e1000_null_nvm_generic;
54 nvm->ops.reload = e1000_reload_nvm_generic;
55 nvm->ops.update = e1000_null_ops_generic;
56 nvm->ops.valid_led_default = e1000_null_led_default;
57 nvm->ops.validate = e1000_null_ops_generic;
58 nvm->ops.write = e1000_null_write_nvm;
62 * e1000_null_nvm_read - No-op function, return 0
63 * @hw: pointer to the HW structure
65 s32 e1000_null_read_nvm(struct e1000_hw *hw, u16 a, u16 b, u16 *c)
67 DEBUGFUNC("e1000_null_read_nvm");
72 * e1000_null_nvm_generic - No-op function, return void
73 * @hw: pointer to the HW structure
75 void e1000_null_nvm_generic(struct e1000_hw *hw)
77 DEBUGFUNC("e1000_null_nvm_generic");
82 * e1000_null_led_default - No-op function, return 0
83 * @hw: pointer to the HW structure
85 s32 e1000_null_led_default(struct e1000_hw *hw, u16 *data)
87 DEBUGFUNC("e1000_null_led_default");
92 * e1000_null_write_nvm - No-op function, return 0
93 * @hw: pointer to the HW structure
95 s32 e1000_null_write_nvm(struct e1000_hw *hw, u16 a, u16 b, u16 *c)
97 DEBUGFUNC("e1000_null_write_nvm");
102 * e1000_raise_eec_clk - Raise EEPROM clock
103 * @hw: pointer to the HW structure
104 * @eecd: pointer to the EEPROM
106 * Enable/Raise the EEPROM clock bit.
108 static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
110 *eecd = *eecd | E1000_EECD_SK;
111 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
112 E1000_WRITE_FLUSH(hw);
113 usec_delay(hw->nvm.delay_usec);
117 * e1000_lower_eec_clk - Lower EEPROM clock
118 * @hw: pointer to the HW structure
119 * @eecd: pointer to the EEPROM
121 * Clear/Lower the EEPROM clock bit.
123 static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
125 *eecd = *eecd & ~E1000_EECD_SK;
126 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
127 E1000_WRITE_FLUSH(hw);
128 usec_delay(hw->nvm.delay_usec);
132 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
133 * @hw: pointer to the HW structure
134 * @data: data to send to the EEPROM
135 * @count: number of bits to shift out
137 * We need to shift 'count' bits out to the EEPROM. So, the value in the
138 * "data" parameter will be shifted out to the EEPROM one bit at a time.
139 * In order to do this, "data" must be broken down into bits.
141 static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
143 struct e1000_nvm_info *nvm = &hw->nvm;
144 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
147 DEBUGFUNC("e1000_shift_out_eec_bits");
149 mask = 0x01 << (count - 1);
150 if (nvm->type == e1000_nvm_eeprom_microwire)
151 eecd &= ~E1000_EECD_DO;
153 if (nvm->type == e1000_nvm_eeprom_spi)
154 eecd |= E1000_EECD_DO;
157 eecd &= ~E1000_EECD_DI;
160 eecd |= E1000_EECD_DI;
162 E1000_WRITE_REG(hw, E1000_EECD, eecd);
163 E1000_WRITE_FLUSH(hw);
165 usec_delay(nvm->delay_usec);
167 e1000_raise_eec_clk(hw, &eecd);
168 e1000_lower_eec_clk(hw, &eecd);
173 eecd &= ~E1000_EECD_DI;
174 E1000_WRITE_REG(hw, E1000_EECD, eecd);
178 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
179 * @hw: pointer to the HW structure
180 * @count: number of bits to shift in
182 * In order to read a register from the EEPROM, we need to shift 'count' bits
183 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
184 * the EEPROM (setting the SK bit), and then reading the value of the data out
185 * "DO" bit. During this "shifting in" process the data in "DI" bit should
188 static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
194 DEBUGFUNC("e1000_shift_in_eec_bits");
196 eecd = E1000_READ_REG(hw, E1000_EECD);
198 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
201 for (i = 0; i < count; i++) {
203 e1000_raise_eec_clk(hw, &eecd);
205 eecd = E1000_READ_REG(hw, E1000_EECD);
207 eecd &= ~E1000_EECD_DI;
208 if (eecd & E1000_EECD_DO)
211 e1000_lower_eec_clk(hw, &eecd);
218 * e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
219 * @hw: pointer to the HW structure
220 * @ee_reg: EEPROM flag for polling
222 * Polls the EEPROM status bit for either read or write completion based
223 * upon the value of 'ee_reg'.
225 s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
227 u32 attempts = 100000;
230 DEBUGFUNC("e1000_poll_eerd_eewr_done");
232 for (i = 0; i < attempts; i++) {
233 if (ee_reg == E1000_NVM_POLL_READ)
234 reg = E1000_READ_REG(hw, E1000_EERD);
236 reg = E1000_READ_REG(hw, E1000_EEWR);
238 if (reg & E1000_NVM_RW_REG_DONE)
239 return E1000_SUCCESS;
244 return -E1000_ERR_NVM;
248 * e1000_acquire_nvm_generic - Generic request for access to EEPROM
249 * @hw: pointer to the HW structure
251 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
252 * Return successful if access grant bit set, else clear the request for
253 * EEPROM access and return -E1000_ERR_NVM (-1).
255 s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
257 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
258 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
260 DEBUGFUNC("e1000_acquire_nvm_generic");
262 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
263 eecd = E1000_READ_REG(hw, E1000_EECD);
266 if (eecd & E1000_EECD_GNT)
269 eecd = E1000_READ_REG(hw, E1000_EECD);
274 eecd &= ~E1000_EECD_REQ;
275 E1000_WRITE_REG(hw, E1000_EECD, eecd);
276 DEBUGOUT("Could not acquire NVM grant\n");
277 return -E1000_ERR_NVM;
280 return E1000_SUCCESS;
284 * e1000_standby_nvm - Return EEPROM to standby state
285 * @hw: pointer to the HW structure
287 * Return the EEPROM to a standby state.
289 static void e1000_standby_nvm(struct e1000_hw *hw)
291 struct e1000_nvm_info *nvm = &hw->nvm;
292 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
294 DEBUGFUNC("e1000_standby_nvm");
296 if (nvm->type == e1000_nvm_eeprom_microwire) {
297 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
298 E1000_WRITE_REG(hw, E1000_EECD, eecd);
299 E1000_WRITE_FLUSH(hw);
300 usec_delay(nvm->delay_usec);
302 e1000_raise_eec_clk(hw, &eecd);
305 eecd |= E1000_EECD_CS;
306 E1000_WRITE_REG(hw, E1000_EECD, eecd);
307 E1000_WRITE_FLUSH(hw);
308 usec_delay(nvm->delay_usec);
310 e1000_lower_eec_clk(hw, &eecd);
311 } else if (nvm->type == e1000_nvm_eeprom_spi) {
312 /* Toggle CS to flush commands */
313 eecd |= E1000_EECD_CS;
314 E1000_WRITE_REG(hw, E1000_EECD, eecd);
315 E1000_WRITE_FLUSH(hw);
316 usec_delay(nvm->delay_usec);
317 eecd &= ~E1000_EECD_CS;
318 E1000_WRITE_REG(hw, E1000_EECD, eecd);
319 E1000_WRITE_FLUSH(hw);
320 usec_delay(nvm->delay_usec);
325 * e1000_stop_nvm - Terminate EEPROM command
326 * @hw: pointer to the HW structure
328 * Terminates the current command by inverting the EEPROM's chip select pin.
330 void e1000_stop_nvm(struct e1000_hw *hw)
334 DEBUGFUNC("e1000_stop_nvm");
336 eecd = E1000_READ_REG(hw, E1000_EECD);
337 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
339 eecd |= E1000_EECD_CS;
340 e1000_lower_eec_clk(hw, &eecd);
341 } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
342 /* CS on Microwire is active-high */
343 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
344 E1000_WRITE_REG(hw, E1000_EECD, eecd);
345 e1000_raise_eec_clk(hw, &eecd);
346 e1000_lower_eec_clk(hw, &eecd);
351 * e1000_release_nvm_generic - Release exclusive access to EEPROM
352 * @hw: pointer to the HW structure
354 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
356 void e1000_release_nvm_generic(struct e1000_hw *hw)
360 DEBUGFUNC("e1000_release_nvm_generic");
364 eecd = E1000_READ_REG(hw, E1000_EECD);
365 eecd &= ~E1000_EECD_REQ;
366 E1000_WRITE_REG(hw, E1000_EECD, eecd);
370 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
371 * @hw: pointer to the HW structure
373 * Setups the EEPROM for reading and writing.
375 static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
377 struct e1000_nvm_info *nvm = &hw->nvm;
378 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
381 DEBUGFUNC("e1000_ready_nvm_eeprom");
383 if (nvm->type == e1000_nvm_eeprom_microwire) {
384 /* Clear SK and DI */
385 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
386 E1000_WRITE_REG(hw, E1000_EECD, eecd);
388 eecd |= E1000_EECD_CS;
389 E1000_WRITE_REG(hw, E1000_EECD, eecd);
390 } else if (nvm->type == e1000_nvm_eeprom_spi) {
391 u16 timeout = NVM_MAX_RETRY_SPI;
393 /* Clear SK and CS */
394 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
395 E1000_WRITE_REG(hw, E1000_EECD, eecd);
396 E1000_WRITE_FLUSH(hw);
399 /* Read "Status Register" repeatedly until the LSB is cleared.
400 * The EEPROM will signal that the command has been completed
401 * by clearing bit 0 of the internal status register. If it's
402 * not cleared within 'timeout', then error out.
405 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
406 hw->nvm.opcode_bits);
407 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
408 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
412 e1000_standby_nvm(hw);
417 DEBUGOUT("SPI NVM Status error\n");
418 return -E1000_ERR_NVM;
422 return E1000_SUCCESS;
426 * e1000_read_nvm_spi - Read EEPROM's using SPI
427 * @hw: pointer to the HW structure
428 * @offset: offset of word in the EEPROM to read
429 * @words: number of words to read
430 * @data: word read from the EEPROM
432 * Reads a 16 bit word from the EEPROM.
434 s32 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
436 struct e1000_nvm_info *nvm = &hw->nvm;
440 u8 read_opcode = NVM_READ_OPCODE_SPI;
442 DEBUGFUNC("e1000_read_nvm_spi");
444 /* A check for invalid values: offset too large, too many words,
445 * and not enough words.
447 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
449 DEBUGOUT("nvm parameter(s) out of bounds\n");
450 return -E1000_ERR_NVM;
453 ret_val = nvm->ops.acquire(hw);
457 ret_val = e1000_ready_nvm_eeprom(hw);
461 e1000_standby_nvm(hw);
463 if ((nvm->address_bits == 8) && (offset >= 128))
464 read_opcode |= NVM_A8_OPCODE_SPI;
466 /* Send the READ command (opcode + addr) */
467 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
468 e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
470 /* Read the data. SPI NVMs increment the address with each byte
471 * read and will roll over if reading beyond the end. This allows
472 * us to read the whole NVM from any offset
474 for (i = 0; i < words; i++) {
475 word_in = e1000_shift_in_eec_bits(hw, 16);
476 data[i] = (word_in >> 8) | (word_in << 8);
480 nvm->ops.release(hw);
486 * e1000_read_nvm_microwire - Reads EEPROM's using microwire
487 * @hw: pointer to the HW structure
488 * @offset: offset of word in the EEPROM to read
489 * @words: number of words to read
490 * @data: word read from the EEPROM
492 * Reads a 16 bit word from the EEPROM.
494 s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
497 struct e1000_nvm_info *nvm = &hw->nvm;
500 u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
502 DEBUGFUNC("e1000_read_nvm_microwire");
504 /* A check for invalid values: offset too large, too many words,
505 * and not enough words.
507 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
509 DEBUGOUT("nvm parameter(s) out of bounds\n");
510 return -E1000_ERR_NVM;
513 ret_val = nvm->ops.acquire(hw);
517 ret_val = e1000_ready_nvm_eeprom(hw);
521 for (i = 0; i < words; i++) {
522 /* Send the READ command (opcode + addr) */
523 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
524 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
527 /* Read the data. For microwire, each word requires the
528 * overhead of setup and tear-down.
530 data[i] = e1000_shift_in_eec_bits(hw, 16);
531 e1000_standby_nvm(hw);
535 nvm->ops.release(hw);
541 * e1000_read_nvm_eerd - Reads EEPROM using EERD register
542 * @hw: pointer to the HW structure
543 * @offset: offset of word in the EEPROM to read
544 * @words: number of words to read
545 * @data: word read from the EEPROM
547 * Reads a 16 bit word from the EEPROM using the EERD register.
549 s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
551 struct e1000_nvm_info *nvm = &hw->nvm;
553 s32 ret_val = E1000_SUCCESS;
555 DEBUGFUNC("e1000_read_nvm_eerd");
557 /* A check for invalid values: offset too large, too many words,
558 * too many words for the offset, and not enough words.
560 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
562 DEBUGOUT("nvm parameter(s) out of bounds\n");
563 return -E1000_ERR_NVM;
566 for (i = 0; i < words; i++) {
567 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
568 E1000_NVM_RW_REG_START;
570 E1000_WRITE_REG(hw, E1000_EERD, eerd);
571 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
575 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
576 E1000_NVM_RW_REG_DATA);
583 * e1000_write_nvm_spi - Write to EEPROM using SPI
584 * @hw: pointer to the HW structure
585 * @offset: offset within the EEPROM to be written to
586 * @words: number of words to write
587 * @data: 16 bit word(s) to be written to the EEPROM
589 * Writes data to EEPROM at offset using SPI interface.
591 * If e1000_update_nvm_checksum is not called after this function , the
592 * EEPROM will most likely contain an invalid checksum.
594 s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
596 struct e1000_nvm_info *nvm = &hw->nvm;
597 s32 ret_val = -E1000_ERR_NVM;
600 DEBUGFUNC("e1000_write_nvm_spi");
602 /* A check for invalid values: offset too large, too many words,
603 * and not enough words.
605 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
607 DEBUGOUT("nvm parameter(s) out of bounds\n");
608 return -E1000_ERR_NVM;
611 while (widx < words) {
612 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
614 ret_val = nvm->ops.acquire(hw);
618 ret_val = e1000_ready_nvm_eeprom(hw);
620 nvm->ops.release(hw);
624 e1000_standby_nvm(hw);
626 /* Send the WRITE ENABLE command (8 bit opcode) */
627 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
630 e1000_standby_nvm(hw);
632 /* Some SPI eeproms use the 8th address bit embedded in the
635 if ((nvm->address_bits == 8) && (offset >= 128))
636 write_opcode |= NVM_A8_OPCODE_SPI;
638 /* Send the Write command (8-bit opcode + addr) */
639 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
640 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
643 /* Loop to allow for up to whole page write of eeprom */
644 while (widx < words) {
645 u16 word_out = data[widx];
646 word_out = (word_out >> 8) | (word_out << 8);
647 e1000_shift_out_eec_bits(hw, word_out, 16);
650 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
651 e1000_standby_nvm(hw);
656 nvm->ops.release(hw);
663 * e1000_write_nvm_microwire - Writes EEPROM using microwire
664 * @hw: pointer to the HW structure
665 * @offset: offset within the EEPROM to be written to
666 * @words: number of words to write
667 * @data: 16 bit word(s) to be written to the EEPROM
669 * Writes data to EEPROM at offset using microwire interface.
671 * If e1000_update_nvm_checksum is not called after this function , the
672 * EEPROM will most likely contain an invalid checksum.
674 s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
677 struct e1000_nvm_info *nvm = &hw->nvm;
680 u16 words_written = 0;
683 DEBUGFUNC("e1000_write_nvm_microwire");
685 /* A check for invalid values: offset too large, too many words,
686 * and not enough words.
688 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
690 DEBUGOUT("nvm parameter(s) out of bounds\n");
691 return -E1000_ERR_NVM;
694 ret_val = nvm->ops.acquire(hw);
698 ret_val = e1000_ready_nvm_eeprom(hw);
702 e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
703 (u16)(nvm->opcode_bits + 2));
705 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
707 e1000_standby_nvm(hw);
709 while (words_written < words) {
710 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
713 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
716 e1000_shift_out_eec_bits(hw, data[words_written], 16);
718 e1000_standby_nvm(hw);
720 for (widx = 0; widx < 200; widx++) {
721 eecd = E1000_READ_REG(hw, E1000_EECD);
722 if (eecd & E1000_EECD_DO)
728 DEBUGOUT("NVM Write did not complete\n");
729 ret_val = -E1000_ERR_NVM;
733 e1000_standby_nvm(hw);
738 e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
739 (u16)(nvm->opcode_bits + 2));
741 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
744 nvm->ops.release(hw);
750 * e1000_read_pba_string_generic - Read device part number
751 * @hw: pointer to the HW structure
752 * @pba_num: pointer to device part number
753 * @pba_num_size: size of part number buffer
755 * Reads the product board assembly (PBA) number from the EEPROM and stores
756 * the value in pba_num.
758 s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
767 DEBUGFUNC("e1000_read_pba_string_generic");
769 if (pba_num == NULL) {
770 DEBUGOUT("PBA string buffer was null\n");
771 return -E1000_ERR_INVALID_ARGUMENT;
774 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
776 DEBUGOUT("NVM Read Error\n");
780 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
782 DEBUGOUT("NVM Read Error\n");
786 /* if nvm_data is not ptr guard the PBA must be in legacy format which
787 * means pba_ptr is actually our second data word for the PBA number
788 * and we can decode it into an ascii string
790 if (nvm_data != NVM_PBA_PTR_GUARD) {
791 DEBUGOUT("NVM PBA number is not stored as string\n");
793 /* make sure callers buffer is big enough to store the PBA */
794 if (pba_num_size < E1000_PBANUM_LENGTH) {
795 DEBUGOUT("PBA string buffer too small\n");
796 return E1000_ERR_NO_SPACE;
799 /* extract hex string from data and pba_ptr */
800 pba_num[0] = (nvm_data >> 12) & 0xF;
801 pba_num[1] = (nvm_data >> 8) & 0xF;
802 pba_num[2] = (nvm_data >> 4) & 0xF;
803 pba_num[3] = nvm_data & 0xF;
804 pba_num[4] = (pba_ptr >> 12) & 0xF;
805 pba_num[5] = (pba_ptr >> 8) & 0xF;
808 pba_num[8] = (pba_ptr >> 4) & 0xF;
809 pba_num[9] = pba_ptr & 0xF;
811 /* put a null character on the end of our string */
814 /* switch all the data but the '-' to hex char */
815 for (offset = 0; offset < 10; offset++) {
816 if (pba_num[offset] < 0xA)
817 pba_num[offset] += '0';
818 else if (pba_num[offset] < 0x10)
819 pba_num[offset] += 'A' - 0xA;
822 return E1000_SUCCESS;
825 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
827 DEBUGOUT("NVM Read Error\n");
831 if (length == 0xFFFF || length == 0) {
832 DEBUGOUT("NVM PBA number section invalid length\n");
833 return -E1000_ERR_NVM_PBA_SECTION;
835 /* check if pba_num buffer is big enough */
836 if (pba_num_size < (((u32)length * 2) - 1)) {
837 DEBUGOUT("PBA string buffer too small\n");
838 return -E1000_ERR_NO_SPACE;
841 /* trim pba length from start of string */
845 for (offset = 0; offset < length; offset++) {
846 ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
848 DEBUGOUT("NVM Read Error\n");
851 pba_num[offset * 2] = (u8)(nvm_data >> 8);
852 pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
854 pba_num[offset * 2] = '\0';
856 return E1000_SUCCESS;
860 * e1000_read_pba_length_generic - Read device part number length
861 * @hw: pointer to the HW structure
862 * @pba_num_size: size of part number buffer
864 * Reads the product board assembly (PBA) number length from the EEPROM and
865 * stores the value in pba_num_size.
867 s32 e1000_read_pba_length_generic(struct e1000_hw *hw, u32 *pba_num_size)
874 DEBUGFUNC("e1000_read_pba_length_generic");
876 if (pba_num_size == NULL) {
877 DEBUGOUT("PBA buffer size was null\n");
878 return -E1000_ERR_INVALID_ARGUMENT;
881 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
883 DEBUGOUT("NVM Read Error\n");
887 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
889 DEBUGOUT("NVM Read Error\n");
893 /* if data is not ptr guard the PBA must be in legacy format */
894 if (nvm_data != NVM_PBA_PTR_GUARD) {
895 *pba_num_size = E1000_PBANUM_LENGTH;
896 return E1000_SUCCESS;
899 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
901 DEBUGOUT("NVM Read Error\n");
905 if (length == 0xFFFF || length == 0) {
906 DEBUGOUT("NVM PBA number section invalid length\n");
907 return -E1000_ERR_NVM_PBA_SECTION;
910 /* Convert from length in u16 values to u8 chars, add 1 for NULL,
911 * and subtract 2 because length field is included in length.
913 *pba_num_size = ((u32)length * 2) - 1;
915 return E1000_SUCCESS;
921 * @hw: pointer to the HW structure
922 * @eeprom_buf: optional pointer to EEPROM image
923 * @eeprom_buf_size: size of EEPROM image in words
924 * @max_pba_block_size: PBA block size limit
925 * @pba: pointer to output PBA structure
927 * Reads PBA from EEPROM image when eeprom_buf is not NULL.
928 * Reads PBA from physical EEPROM device when eeprom_buf is NULL.
931 s32 e1000_read_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
932 u32 eeprom_buf_size, u16 max_pba_block_size,
933 struct e1000_pba *pba)
939 return -E1000_ERR_PARAM;
941 if (eeprom_buf == NULL) {
942 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2,
947 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
948 pba->word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
949 pba->word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
951 return -E1000_ERR_PARAM;
955 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
956 if (pba->pba_block == NULL)
957 return -E1000_ERR_PARAM;
959 ret_val = e1000_get_pba_block_size(hw, eeprom_buf,
965 if (pba_block_size > max_pba_block_size)
966 return -E1000_ERR_PARAM;
968 if (eeprom_buf == NULL) {
969 ret_val = e1000_read_nvm(hw, pba->word[1],
975 if (eeprom_buf_size > (u32)(pba->word[1] +
976 pba->pba_block[0])) {
977 memcpy(pba->pba_block,
978 &eeprom_buf[pba->word[1]],
979 pba_block_size * sizeof(u16));
981 return -E1000_ERR_PARAM;
986 return E1000_SUCCESS;
990 * e1000_write_pba_raw
991 * @hw: pointer to the HW structure
992 * @eeprom_buf: optional pointer to EEPROM image
993 * @eeprom_buf_size: size of EEPROM image in words
994 * @pba: pointer to PBA structure
996 * Writes PBA to EEPROM image when eeprom_buf is not NULL.
997 * Writes PBA to physical EEPROM device when eeprom_buf is NULL.
1000 s32 e1000_write_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
1001 u32 eeprom_buf_size, struct e1000_pba *pba)
1006 return -E1000_ERR_PARAM;
1008 if (eeprom_buf == NULL) {
1009 ret_val = e1000_write_nvm(hw, NVM_PBA_OFFSET_0, 2,
1014 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1015 eeprom_buf[NVM_PBA_OFFSET_0] = pba->word[0];
1016 eeprom_buf[NVM_PBA_OFFSET_1] = pba->word[1];
1018 return -E1000_ERR_PARAM;
1022 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
1023 if (pba->pba_block == NULL)
1024 return -E1000_ERR_PARAM;
1026 if (eeprom_buf == NULL) {
1027 ret_val = e1000_write_nvm(hw, pba->word[1],
1033 if (eeprom_buf_size > (u32)(pba->word[1] +
1034 pba->pba_block[0])) {
1035 memcpy(&eeprom_buf[pba->word[1]],
1037 pba->pba_block[0] * sizeof(u16));
1039 return -E1000_ERR_PARAM;
1044 return E1000_SUCCESS;
1048 * e1000_get_pba_block_size
1049 * @hw: pointer to the HW structure
1050 * @eeprom_buf: optional pointer to EEPROM image
1051 * @eeprom_buf_size: size of EEPROM image in words
1052 * @pba_data_size: pointer to output variable
1054 * Returns the size of the PBA block in words. Function operates on EEPROM
1055 * image if the eeprom_buf pointer is not NULL otherwise it accesses physical
1059 s32 e1000_get_pba_block_size(struct e1000_hw *hw, u16 *eeprom_buf,
1060 u32 eeprom_buf_size, u16 *pba_block_size)
1066 DEBUGFUNC("e1000_get_pba_block_size");
1068 if (eeprom_buf == NULL) {
1069 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2, &pba_word[0]);
1073 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1074 pba_word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
1075 pba_word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
1077 return -E1000_ERR_PARAM;
1081 if (pba_word[0] == NVM_PBA_PTR_GUARD) {
1082 if (eeprom_buf == NULL) {
1083 ret_val = e1000_read_nvm(hw, pba_word[1] + 0, 1,
1088 if (eeprom_buf_size > pba_word[1])
1089 length = eeprom_buf[pba_word[1] + 0];
1091 return -E1000_ERR_PARAM;
1094 if (length == 0xFFFF || length == 0)
1095 return -E1000_ERR_NVM_PBA_SECTION;
1097 /* PBA number in legacy format, there is no PBA Block. */
1101 if (pba_block_size != NULL)
1102 *pba_block_size = length;
1104 return E1000_SUCCESS;
1108 * e1000_read_mac_addr_generic - Read device MAC address
1109 * @hw: pointer to the HW structure
1111 * Reads the device MAC address from the EEPROM and stores the value.
1112 * Since devices with two ports use the same EEPROM, we increment the
1113 * last bit in the MAC address for the second port.
1115 s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
1121 rar_high = E1000_READ_REG(hw, E1000_RAH(0));
1122 rar_low = E1000_READ_REG(hw, E1000_RAL(0));
1124 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
1125 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
1127 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
1128 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
1130 for (i = 0; i < ETH_ADDR_LEN; i++)
1131 hw->mac.addr[i] = hw->mac.perm_addr[i];
1133 return E1000_SUCCESS;
1137 * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
1138 * @hw: pointer to the HW structure
1140 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
1141 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
1143 s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
1149 DEBUGFUNC("e1000_validate_nvm_checksum_generic");
1151 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
1152 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1154 DEBUGOUT("NVM Read Error\n");
1157 checksum += nvm_data;
1160 if (checksum != (u16) NVM_SUM) {
1161 DEBUGOUT("NVM Checksum Invalid\n");
1162 return -E1000_ERR_NVM;
1165 return E1000_SUCCESS;
1169 * e1000_update_nvm_checksum_generic - Update EEPROM checksum
1170 * @hw: pointer to the HW structure
1172 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
1173 * up to the checksum. Then calculates the EEPROM checksum and writes the
1174 * value to the EEPROM.
1176 s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
1182 DEBUGFUNC("e1000_update_nvm_checksum");
1184 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
1185 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1187 DEBUGOUT("NVM Read Error while updating checksum.\n");
1190 checksum += nvm_data;
1192 checksum = (u16) NVM_SUM - checksum;
1193 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
1195 DEBUGOUT("NVM Write Error while updating checksum.\n");
1201 * e1000_reload_nvm_generic - Reloads EEPROM
1202 * @hw: pointer to the HW structure
1204 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1205 * extended control register.
1207 STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw)
1211 DEBUGFUNC("e1000_reload_nvm_generic");
1214 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1215 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1216 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1217 E1000_WRITE_FLUSH(hw);
1221 * e1000_get_fw_version - Get firmware version information
1222 * @hw: pointer to the HW structure
1223 * @fw_vers: pointer to output version structure
1225 * unsupported/not present features return 0 in version structure
1227 void e1000_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
1229 u16 eeprom_verh, eeprom_verl, fw_version;
1230 u16 comb_verh, comb_verl, comb_offset;
1232 memset(fw_vers, 0, sizeof(struct e1000_fw_version));
1234 /* this code only applies to certain mac types */
1235 switch (hw->mac.type) {
1237 e1000_read_invm_version(hw, fw_vers);
1249 /* basic eeprom version numbers */
1250 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1251 fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK) >> NVM_MAJOR_SHIFT;
1252 fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK);
1255 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl);
1256 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh);
1257 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) | eeprom_verl;
1259 switch (hw->mac.type) {
1262 /* find combo image version */
1263 hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
1264 if ((comb_offset != 0x0) &&
1265 (comb_offset != NVM_VER_INVALID)) {
1267 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
1268 + 1), 1, &comb_verh);
1269 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
1272 /* get Option Rom version if it exists and is valid */
1273 if ((comb_verh && comb_verl) &&
1274 ((comb_verh != NVM_VER_INVALID) &&
1275 (comb_verl != NVM_VER_INVALID))) {
1277 fw_vers->or_valid = true;
1279 comb_verl >> NVM_COMB_VER_SHFT;
1281 (comb_verl << NVM_COMB_VER_SHFT)
1282 | (comb_verh >> NVM_COMB_VER_SHFT);
1284 comb_verh & NVM_COMB_VER_MASK;