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 E1000_UNUSEDARG *hw,
66 u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
67 u16 E1000_UNUSEDARG *c)
69 DEBUGFUNC("e1000_null_read_nvm");
70 UNREFERENCED_4PARAMETER(hw, a, b, c);
75 * e1000_null_nvm_generic - No-op function, return void
76 * @hw: pointer to the HW structure
78 void e1000_null_nvm_generic(struct e1000_hw E1000_UNUSEDARG *hw)
80 DEBUGFUNC("e1000_null_nvm_generic");
81 UNREFERENCED_1PARAMETER(hw);
86 * e1000_null_led_default - No-op function, return 0
87 * @hw: pointer to the HW structure
89 s32 e1000_null_led_default(struct e1000_hw E1000_UNUSEDARG *hw,
90 u16 E1000_UNUSEDARG *data)
92 DEBUGFUNC("e1000_null_led_default");
93 UNREFERENCED_2PARAMETER(hw, data);
98 * e1000_null_write_nvm - No-op function, return 0
99 * @hw: pointer to the HW structure
101 s32 e1000_null_write_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
102 u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
103 u16 E1000_UNUSEDARG *c)
105 DEBUGFUNC("e1000_null_write_nvm");
106 UNREFERENCED_4PARAMETER(hw, a, b, c);
107 return E1000_SUCCESS;
111 * e1000_raise_eec_clk - Raise EEPROM clock
112 * @hw: pointer to the HW structure
113 * @eecd: pointer to the EEPROM
115 * Enable/Raise the EEPROM clock bit.
117 static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
119 *eecd = *eecd | E1000_EECD_SK;
120 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
121 E1000_WRITE_FLUSH(hw);
122 usec_delay(hw->nvm.delay_usec);
126 * e1000_lower_eec_clk - Lower EEPROM clock
127 * @hw: pointer to the HW structure
128 * @eecd: pointer to the EEPROM
130 * Clear/Lower the EEPROM clock bit.
132 static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
134 *eecd = *eecd & ~E1000_EECD_SK;
135 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
136 E1000_WRITE_FLUSH(hw);
137 usec_delay(hw->nvm.delay_usec);
141 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
142 * @hw: pointer to the HW structure
143 * @data: data to send to the EEPROM
144 * @count: number of bits to shift out
146 * We need to shift 'count' bits out to the EEPROM. So, the value in the
147 * "data" parameter will be shifted out to the EEPROM one bit at a time.
148 * In order to do this, "data" must be broken down into bits.
150 static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
152 struct e1000_nvm_info *nvm = &hw->nvm;
153 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
156 DEBUGFUNC("e1000_shift_out_eec_bits");
158 mask = 0x01 << (count - 1);
159 if (nvm->type == e1000_nvm_eeprom_microwire)
160 eecd &= ~E1000_EECD_DO;
162 if (nvm->type == e1000_nvm_eeprom_spi)
163 eecd |= E1000_EECD_DO;
166 eecd &= ~E1000_EECD_DI;
169 eecd |= E1000_EECD_DI;
171 E1000_WRITE_REG(hw, E1000_EECD, eecd);
172 E1000_WRITE_FLUSH(hw);
174 usec_delay(nvm->delay_usec);
176 e1000_raise_eec_clk(hw, &eecd);
177 e1000_lower_eec_clk(hw, &eecd);
182 eecd &= ~E1000_EECD_DI;
183 E1000_WRITE_REG(hw, E1000_EECD, eecd);
187 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
188 * @hw: pointer to the HW structure
189 * @count: number of bits to shift in
191 * In order to read a register from the EEPROM, we need to shift 'count' bits
192 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
193 * the EEPROM (setting the SK bit), and then reading the value of the data out
194 * "DO" bit. During this "shifting in" process the data in "DI" bit should
197 static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
203 DEBUGFUNC("e1000_shift_in_eec_bits");
205 eecd = E1000_READ_REG(hw, E1000_EECD);
207 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
210 for (i = 0; i < count; i++) {
212 e1000_raise_eec_clk(hw, &eecd);
214 eecd = E1000_READ_REG(hw, E1000_EECD);
216 eecd &= ~E1000_EECD_DI;
217 if (eecd & E1000_EECD_DO)
220 e1000_lower_eec_clk(hw, &eecd);
227 * e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
228 * @hw: pointer to the HW structure
229 * @ee_reg: EEPROM flag for polling
231 * Polls the EEPROM status bit for either read or write completion based
232 * upon the value of 'ee_reg'.
234 s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
236 u32 attempts = 100000;
239 DEBUGFUNC("e1000_poll_eerd_eewr_done");
241 for (i = 0; i < attempts; i++) {
242 if (ee_reg == E1000_NVM_POLL_READ)
243 reg = E1000_READ_REG(hw, E1000_EERD);
245 reg = E1000_READ_REG(hw, E1000_EEWR);
247 if (reg & E1000_NVM_RW_REG_DONE)
248 return E1000_SUCCESS;
253 return -E1000_ERR_NVM;
257 * e1000_acquire_nvm_generic - Generic request for access to EEPROM
258 * @hw: pointer to the HW structure
260 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
261 * Return successful if access grant bit set, else clear the request for
262 * EEPROM access and return -E1000_ERR_NVM (-1).
264 s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
266 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
267 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
269 DEBUGFUNC("e1000_acquire_nvm_generic");
271 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
272 eecd = E1000_READ_REG(hw, E1000_EECD);
275 if (eecd & E1000_EECD_GNT)
278 eecd = E1000_READ_REG(hw, E1000_EECD);
283 eecd &= ~E1000_EECD_REQ;
284 E1000_WRITE_REG(hw, E1000_EECD, eecd);
285 DEBUGOUT("Could not acquire NVM grant\n");
286 return -E1000_ERR_NVM;
289 return E1000_SUCCESS;
293 * e1000_standby_nvm - Return EEPROM to standby state
294 * @hw: pointer to the HW structure
296 * Return the EEPROM to a standby state.
298 static void e1000_standby_nvm(struct e1000_hw *hw)
300 struct e1000_nvm_info *nvm = &hw->nvm;
301 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
303 DEBUGFUNC("e1000_standby_nvm");
305 if (nvm->type == e1000_nvm_eeprom_microwire) {
306 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
307 E1000_WRITE_REG(hw, E1000_EECD, eecd);
308 E1000_WRITE_FLUSH(hw);
309 usec_delay(nvm->delay_usec);
311 e1000_raise_eec_clk(hw, &eecd);
314 eecd |= E1000_EECD_CS;
315 E1000_WRITE_REG(hw, E1000_EECD, eecd);
316 E1000_WRITE_FLUSH(hw);
317 usec_delay(nvm->delay_usec);
319 e1000_lower_eec_clk(hw, &eecd);
320 } else if (nvm->type == e1000_nvm_eeprom_spi) {
321 /* Toggle CS to flush commands */
322 eecd |= E1000_EECD_CS;
323 E1000_WRITE_REG(hw, E1000_EECD, eecd);
324 E1000_WRITE_FLUSH(hw);
325 usec_delay(nvm->delay_usec);
326 eecd &= ~E1000_EECD_CS;
327 E1000_WRITE_REG(hw, E1000_EECD, eecd);
328 E1000_WRITE_FLUSH(hw);
329 usec_delay(nvm->delay_usec);
334 * e1000_stop_nvm - Terminate EEPROM command
335 * @hw: pointer to the HW structure
337 * Terminates the current command by inverting the EEPROM's chip select pin.
339 void e1000_stop_nvm(struct e1000_hw *hw)
343 DEBUGFUNC("e1000_stop_nvm");
345 eecd = E1000_READ_REG(hw, E1000_EECD);
346 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
348 eecd |= E1000_EECD_CS;
349 e1000_lower_eec_clk(hw, &eecd);
350 } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
351 /* CS on Microwire is active-high */
352 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
353 E1000_WRITE_REG(hw, E1000_EECD, eecd);
354 e1000_raise_eec_clk(hw, &eecd);
355 e1000_lower_eec_clk(hw, &eecd);
360 * e1000_release_nvm_generic - Release exclusive access to EEPROM
361 * @hw: pointer to the HW structure
363 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
365 void e1000_release_nvm_generic(struct e1000_hw *hw)
369 DEBUGFUNC("e1000_release_nvm_generic");
373 eecd = E1000_READ_REG(hw, E1000_EECD);
374 eecd &= ~E1000_EECD_REQ;
375 E1000_WRITE_REG(hw, E1000_EECD, eecd);
379 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
380 * @hw: pointer to the HW structure
382 * Setups the EEPROM for reading and writing.
384 static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
386 struct e1000_nvm_info *nvm = &hw->nvm;
387 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
390 DEBUGFUNC("e1000_ready_nvm_eeprom");
392 if (nvm->type == e1000_nvm_eeprom_microwire) {
393 /* Clear SK and DI */
394 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
395 E1000_WRITE_REG(hw, E1000_EECD, eecd);
397 eecd |= E1000_EECD_CS;
398 E1000_WRITE_REG(hw, E1000_EECD, eecd);
399 } else if (nvm->type == e1000_nvm_eeprom_spi) {
400 u16 timeout = NVM_MAX_RETRY_SPI;
402 /* Clear SK and CS */
403 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
404 E1000_WRITE_REG(hw, E1000_EECD, eecd);
405 E1000_WRITE_FLUSH(hw);
408 /* Read "Status Register" repeatedly until the LSB is cleared.
409 * The EEPROM will signal that the command has been completed
410 * by clearing bit 0 of the internal status register. If it's
411 * not cleared within 'timeout', then error out.
414 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
415 hw->nvm.opcode_bits);
416 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
417 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
421 e1000_standby_nvm(hw);
426 DEBUGOUT("SPI NVM Status error\n");
427 return -E1000_ERR_NVM;
431 return E1000_SUCCESS;
435 * e1000_read_nvm_spi - Read EEPROM's using SPI
436 * @hw: pointer to the HW structure
437 * @offset: offset of word in the EEPROM to read
438 * @words: number of words to read
439 * @data: word read from the EEPROM
441 * Reads a 16 bit word from the EEPROM.
443 s32 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
445 struct e1000_nvm_info *nvm = &hw->nvm;
449 u8 read_opcode = NVM_READ_OPCODE_SPI;
451 DEBUGFUNC("e1000_read_nvm_spi");
453 /* A check for invalid values: offset too large, too many words,
454 * and not enough words.
456 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
458 DEBUGOUT("nvm parameter(s) out of bounds\n");
459 return -E1000_ERR_NVM;
462 ret_val = nvm->ops.acquire(hw);
466 ret_val = e1000_ready_nvm_eeprom(hw);
470 e1000_standby_nvm(hw);
472 if ((nvm->address_bits == 8) && (offset >= 128))
473 read_opcode |= NVM_A8_OPCODE_SPI;
475 /* Send the READ command (opcode + addr) */
476 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
477 e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
479 /* Read the data. SPI NVMs increment the address with each byte
480 * read and will roll over if reading beyond the end. This allows
481 * us to read the whole NVM from any offset
483 for (i = 0; i < words; i++) {
484 word_in = e1000_shift_in_eec_bits(hw, 16);
485 data[i] = (word_in >> 8) | (word_in << 8);
489 nvm->ops.release(hw);
495 * e1000_read_nvm_microwire - Reads EEPROM's using microwire
496 * @hw: pointer to the HW structure
497 * @offset: offset of word in the EEPROM to read
498 * @words: number of words to read
499 * @data: word read from the EEPROM
501 * Reads a 16 bit word from the EEPROM.
503 s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
506 struct e1000_nvm_info *nvm = &hw->nvm;
509 u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
511 DEBUGFUNC("e1000_read_nvm_microwire");
513 /* A check for invalid values: offset too large, too many words,
514 * and not enough words.
516 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
518 DEBUGOUT("nvm parameter(s) out of bounds\n");
519 return -E1000_ERR_NVM;
522 ret_val = nvm->ops.acquire(hw);
526 ret_val = e1000_ready_nvm_eeprom(hw);
530 for (i = 0; i < words; i++) {
531 /* Send the READ command (opcode + addr) */
532 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
533 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
536 /* Read the data. For microwire, each word requires the
537 * overhead of setup and tear-down.
539 data[i] = e1000_shift_in_eec_bits(hw, 16);
540 e1000_standby_nvm(hw);
544 nvm->ops.release(hw);
550 * e1000_read_nvm_eerd - Reads EEPROM using EERD register
551 * @hw: pointer to the HW structure
552 * @offset: offset of word in the EEPROM to read
553 * @words: number of words to read
554 * @data: word read from the EEPROM
556 * Reads a 16 bit word from the EEPROM using the EERD register.
558 s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
560 struct e1000_nvm_info *nvm = &hw->nvm;
562 s32 ret_val = E1000_SUCCESS;
564 DEBUGFUNC("e1000_read_nvm_eerd");
566 /* A check for invalid values: offset too large, too many words,
567 * too many words for the offset, and not enough words.
569 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
571 DEBUGOUT("nvm parameter(s) out of bounds\n");
572 return -E1000_ERR_NVM;
575 for (i = 0; i < words; i++) {
576 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
577 E1000_NVM_RW_REG_START;
579 E1000_WRITE_REG(hw, E1000_EERD, eerd);
580 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
584 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
585 E1000_NVM_RW_REG_DATA);
592 * e1000_write_nvm_spi - Write to EEPROM using SPI
593 * @hw: pointer to the HW structure
594 * @offset: offset within the EEPROM to be written to
595 * @words: number of words to write
596 * @data: 16 bit word(s) to be written to the EEPROM
598 * Writes data to EEPROM at offset using SPI interface.
600 * If e1000_update_nvm_checksum is not called after this function , the
601 * EEPROM will most likely contain an invalid checksum.
603 s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
605 struct e1000_nvm_info *nvm = &hw->nvm;
606 s32 ret_val = -E1000_ERR_NVM;
609 DEBUGFUNC("e1000_write_nvm_spi");
611 /* A check for invalid values: offset too large, too many words,
612 * and not enough words.
614 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
616 DEBUGOUT("nvm parameter(s) out of bounds\n");
617 return -E1000_ERR_NVM;
620 while (widx < words) {
621 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
623 ret_val = nvm->ops.acquire(hw);
627 ret_val = e1000_ready_nvm_eeprom(hw);
629 nvm->ops.release(hw);
633 e1000_standby_nvm(hw);
635 /* Send the WRITE ENABLE command (8 bit opcode) */
636 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
639 e1000_standby_nvm(hw);
641 /* Some SPI eeproms use the 8th address bit embedded in the
644 if ((nvm->address_bits == 8) && (offset >= 128))
645 write_opcode |= NVM_A8_OPCODE_SPI;
647 /* Send the Write command (8-bit opcode + addr) */
648 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
649 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
652 /* Loop to allow for up to whole page write of eeprom */
653 while (widx < words) {
654 u16 word_out = data[widx];
655 word_out = (word_out >> 8) | (word_out << 8);
656 e1000_shift_out_eec_bits(hw, word_out, 16);
659 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
660 e1000_standby_nvm(hw);
665 nvm->ops.release(hw);
672 * e1000_write_nvm_microwire - Writes EEPROM using microwire
673 * @hw: pointer to the HW structure
674 * @offset: offset within the EEPROM to be written to
675 * @words: number of words to write
676 * @data: 16 bit word(s) to be written to the EEPROM
678 * Writes data to EEPROM at offset using microwire interface.
680 * If e1000_update_nvm_checksum is not called after this function , the
681 * EEPROM will most likely contain an invalid checksum.
683 s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
686 struct e1000_nvm_info *nvm = &hw->nvm;
689 u16 words_written = 0;
692 DEBUGFUNC("e1000_write_nvm_microwire");
694 /* A check for invalid values: offset too large, too many words,
695 * and not enough words.
697 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
699 DEBUGOUT("nvm parameter(s) out of bounds\n");
700 return -E1000_ERR_NVM;
703 ret_val = nvm->ops.acquire(hw);
707 ret_val = e1000_ready_nvm_eeprom(hw);
711 e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
712 (u16)(nvm->opcode_bits + 2));
714 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
716 e1000_standby_nvm(hw);
718 while (words_written < words) {
719 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
722 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
725 e1000_shift_out_eec_bits(hw, data[words_written], 16);
727 e1000_standby_nvm(hw);
729 for (widx = 0; widx < 200; widx++) {
730 eecd = E1000_READ_REG(hw, E1000_EECD);
731 if (eecd & E1000_EECD_DO)
737 DEBUGOUT("NVM Write did not complete\n");
738 ret_val = -E1000_ERR_NVM;
742 e1000_standby_nvm(hw);
747 e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
748 (u16)(nvm->opcode_bits + 2));
750 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
753 nvm->ops.release(hw);
759 * e1000_read_pba_string_generic - Read device part number
760 * @hw: pointer to the HW structure
761 * @pba_num: pointer to device part number
762 * @pba_num_size: size of part number buffer
764 * Reads the product board assembly (PBA) number from the EEPROM and stores
765 * the value in pba_num.
767 s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
776 DEBUGFUNC("e1000_read_pba_string_generic");
778 if (pba_num == NULL) {
779 DEBUGOUT("PBA string buffer was null\n");
780 return -E1000_ERR_INVALID_ARGUMENT;
783 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
785 DEBUGOUT("NVM Read Error\n");
789 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
791 DEBUGOUT("NVM Read Error\n");
795 /* if nvm_data is not ptr guard the PBA must be in legacy format which
796 * means pba_ptr is actually our second data word for the PBA number
797 * and we can decode it into an ascii string
799 if (nvm_data != NVM_PBA_PTR_GUARD) {
800 DEBUGOUT("NVM PBA number is not stored as string\n");
802 /* make sure callers buffer is big enough to store the PBA */
803 if (pba_num_size < E1000_PBANUM_LENGTH) {
804 DEBUGOUT("PBA string buffer too small\n");
805 return E1000_ERR_NO_SPACE;
808 /* extract hex string from data and pba_ptr */
809 pba_num[0] = (nvm_data >> 12) & 0xF;
810 pba_num[1] = (nvm_data >> 8) & 0xF;
811 pba_num[2] = (nvm_data >> 4) & 0xF;
812 pba_num[3] = nvm_data & 0xF;
813 pba_num[4] = (pba_ptr >> 12) & 0xF;
814 pba_num[5] = (pba_ptr >> 8) & 0xF;
817 pba_num[8] = (pba_ptr >> 4) & 0xF;
818 pba_num[9] = pba_ptr & 0xF;
820 /* put a null character on the end of our string */
823 /* switch all the data but the '-' to hex char */
824 for (offset = 0; offset < 10; offset++) {
825 if (pba_num[offset] < 0xA)
826 pba_num[offset] += '0';
827 else if (pba_num[offset] < 0x10)
828 pba_num[offset] += 'A' - 0xA;
831 return E1000_SUCCESS;
834 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
836 DEBUGOUT("NVM Read Error\n");
840 if (length == 0xFFFF || length == 0) {
841 DEBUGOUT("NVM PBA number section invalid length\n");
842 return -E1000_ERR_NVM_PBA_SECTION;
844 /* check if pba_num buffer is big enough */
845 if (pba_num_size < (((u32)length * 2) - 1)) {
846 DEBUGOUT("PBA string buffer too small\n");
847 return -E1000_ERR_NO_SPACE;
850 /* trim pba length from start of string */
854 for (offset = 0; offset < length; offset++) {
855 ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
857 DEBUGOUT("NVM Read Error\n");
860 pba_num[offset * 2] = (u8)(nvm_data >> 8);
861 pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
863 pba_num[offset * 2] = '\0';
865 return E1000_SUCCESS;
869 * e1000_read_pba_length_generic - Read device part number length
870 * @hw: pointer to the HW structure
871 * @pba_num_size: size of part number buffer
873 * Reads the product board assembly (PBA) number length from the EEPROM and
874 * stores the value in pba_num_size.
876 s32 e1000_read_pba_length_generic(struct e1000_hw *hw, u32 *pba_num_size)
883 DEBUGFUNC("e1000_read_pba_length_generic");
885 if (pba_num_size == NULL) {
886 DEBUGOUT("PBA buffer size was null\n");
887 return -E1000_ERR_INVALID_ARGUMENT;
890 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
892 DEBUGOUT("NVM Read Error\n");
896 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
898 DEBUGOUT("NVM Read Error\n");
902 /* if data is not ptr guard the PBA must be in legacy format */
903 if (nvm_data != NVM_PBA_PTR_GUARD) {
904 *pba_num_size = E1000_PBANUM_LENGTH;
905 return E1000_SUCCESS;
908 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
910 DEBUGOUT("NVM Read Error\n");
914 if (length == 0xFFFF || length == 0) {
915 DEBUGOUT("NVM PBA number section invalid length\n");
916 return -E1000_ERR_NVM_PBA_SECTION;
919 /* Convert from length in u16 values to u8 chars, add 1 for NULL,
920 * and subtract 2 because length field is included in length.
922 *pba_num_size = ((u32)length * 2) - 1;
924 return E1000_SUCCESS;
930 * @hw: pointer to the HW structure
931 * @eeprom_buf: optional pointer to EEPROM image
932 * @eeprom_buf_size: size of EEPROM image in words
933 * @max_pba_block_size: PBA block size limit
934 * @pba: pointer to output PBA structure
936 * Reads PBA from EEPROM image when eeprom_buf is not NULL.
937 * Reads PBA from physical EEPROM device when eeprom_buf is NULL.
940 s32 e1000_read_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
941 u32 eeprom_buf_size, u16 max_pba_block_size,
942 struct e1000_pba *pba)
948 return -E1000_ERR_PARAM;
950 if (eeprom_buf == NULL) {
951 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2,
956 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
957 pba->word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
958 pba->word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
960 return -E1000_ERR_PARAM;
964 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
965 if (pba->pba_block == NULL)
966 return -E1000_ERR_PARAM;
968 ret_val = e1000_get_pba_block_size(hw, eeprom_buf,
974 if (pba_block_size > max_pba_block_size)
975 return -E1000_ERR_PARAM;
977 if (eeprom_buf == NULL) {
978 ret_val = e1000_read_nvm(hw, pba->word[1],
984 if (eeprom_buf_size > (u32)(pba->word[1] +
985 pba->pba_block[0])) {
986 memcpy(pba->pba_block,
987 &eeprom_buf[pba->word[1]],
988 pba_block_size * sizeof(u16));
990 return -E1000_ERR_PARAM;
995 return E1000_SUCCESS;
999 * e1000_write_pba_raw
1000 * @hw: pointer to the HW structure
1001 * @eeprom_buf: optional pointer to EEPROM image
1002 * @eeprom_buf_size: size of EEPROM image in words
1003 * @pba: pointer to PBA structure
1005 * Writes PBA to EEPROM image when eeprom_buf is not NULL.
1006 * Writes PBA to physical EEPROM device when eeprom_buf is NULL.
1009 s32 e1000_write_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
1010 u32 eeprom_buf_size, struct e1000_pba *pba)
1015 return -E1000_ERR_PARAM;
1017 if (eeprom_buf == NULL) {
1018 ret_val = e1000_write_nvm(hw, NVM_PBA_OFFSET_0, 2,
1023 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1024 eeprom_buf[NVM_PBA_OFFSET_0] = pba->word[0];
1025 eeprom_buf[NVM_PBA_OFFSET_1] = pba->word[1];
1027 return -E1000_ERR_PARAM;
1031 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
1032 if (pba->pba_block == NULL)
1033 return -E1000_ERR_PARAM;
1035 if (eeprom_buf == NULL) {
1036 ret_val = e1000_write_nvm(hw, pba->word[1],
1042 if (eeprom_buf_size > (u32)(pba->word[1] +
1043 pba->pba_block[0])) {
1044 memcpy(&eeprom_buf[pba->word[1]],
1046 pba->pba_block[0] * sizeof(u16));
1048 return -E1000_ERR_PARAM;
1053 return E1000_SUCCESS;
1057 * e1000_get_pba_block_size
1058 * @hw: pointer to the HW structure
1059 * @eeprom_buf: optional pointer to EEPROM image
1060 * @eeprom_buf_size: size of EEPROM image in words
1061 * @pba_data_size: pointer to output variable
1063 * Returns the size of the PBA block in words. Function operates on EEPROM
1064 * image if the eeprom_buf pointer is not NULL otherwise it accesses physical
1068 s32 e1000_get_pba_block_size(struct e1000_hw *hw, u16 *eeprom_buf,
1069 u32 eeprom_buf_size, u16 *pba_block_size)
1075 DEBUGFUNC("e1000_get_pba_block_size");
1077 if (eeprom_buf == NULL) {
1078 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2, &pba_word[0]);
1082 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1083 pba_word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
1084 pba_word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
1086 return -E1000_ERR_PARAM;
1090 if (pba_word[0] == NVM_PBA_PTR_GUARD) {
1091 if (eeprom_buf == NULL) {
1092 ret_val = e1000_read_nvm(hw, pba_word[1] + 0, 1,
1097 if (eeprom_buf_size > pba_word[1])
1098 length = eeprom_buf[pba_word[1] + 0];
1100 return -E1000_ERR_PARAM;
1103 if (length == 0xFFFF || length == 0)
1104 return -E1000_ERR_NVM_PBA_SECTION;
1106 /* PBA number in legacy format, there is no PBA Block. */
1110 if (pba_block_size != NULL)
1111 *pba_block_size = length;
1113 return E1000_SUCCESS;
1117 * e1000_read_mac_addr_generic - Read device MAC address
1118 * @hw: pointer to the HW structure
1120 * Reads the device MAC address from the EEPROM and stores the value.
1121 * Since devices with two ports use the same EEPROM, we increment the
1122 * last bit in the MAC address for the second port.
1124 s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
1130 rar_high = E1000_READ_REG(hw, E1000_RAH(0));
1131 rar_low = E1000_READ_REG(hw, E1000_RAL(0));
1133 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
1134 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
1136 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
1137 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
1139 for (i = 0; i < ETH_ADDR_LEN; i++)
1140 hw->mac.addr[i] = hw->mac.perm_addr[i];
1142 return E1000_SUCCESS;
1146 * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
1147 * @hw: pointer to the HW structure
1149 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
1150 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
1152 s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
1158 DEBUGFUNC("e1000_validate_nvm_checksum_generic");
1160 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
1161 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1163 DEBUGOUT("NVM Read Error\n");
1166 checksum += nvm_data;
1169 if (checksum != (u16) NVM_SUM) {
1170 DEBUGOUT("NVM Checksum Invalid\n");
1171 return -E1000_ERR_NVM;
1174 return E1000_SUCCESS;
1178 * e1000_update_nvm_checksum_generic - Update EEPROM checksum
1179 * @hw: pointer to the HW structure
1181 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
1182 * up to the checksum. Then calculates the EEPROM checksum and writes the
1183 * value to the EEPROM.
1185 s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
1191 DEBUGFUNC("e1000_update_nvm_checksum");
1193 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
1194 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1196 DEBUGOUT("NVM Read Error while updating checksum.\n");
1199 checksum += nvm_data;
1201 checksum = (u16) NVM_SUM - checksum;
1202 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
1204 DEBUGOUT("NVM Write Error while updating checksum.\n");
1210 * e1000_reload_nvm_generic - Reloads EEPROM
1211 * @hw: pointer to the HW structure
1213 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1214 * extended control register.
1216 STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw)
1220 DEBUGFUNC("e1000_reload_nvm_generic");
1223 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1224 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1225 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1226 E1000_WRITE_FLUSH(hw);
1230 * e1000_get_fw_version - Get firmware version information
1231 * @hw: pointer to the HW structure
1232 * @fw_vers: pointer to output version structure
1234 * unsupported/not present features return 0 in version structure
1236 void e1000_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
1238 u16 eeprom_verh, eeprom_verl, fw_version;
1239 u16 comb_verh, comb_verl, comb_offset;
1241 memset(fw_vers, 0, sizeof(struct e1000_fw_version));
1243 /* this code only applies to certain mac types */
1244 switch (hw->mac.type) {
1246 e1000_read_invm_version(hw, fw_vers);
1258 /* basic eeprom version numbers */
1259 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1260 fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK) >> NVM_MAJOR_SHIFT;
1261 fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK);
1264 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl);
1265 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh);
1266 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) | eeprom_verl;
1268 switch (hw->mac.type) {
1271 /* find combo image version */
1272 hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
1273 if ((comb_offset != 0x0) &&
1274 (comb_offset != NVM_VER_INVALID)) {
1276 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
1277 + 1), 1, &comb_verh);
1278 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
1281 /* get Option Rom version if it exists and is valid */
1282 if ((comb_verh && comb_verl) &&
1283 ((comb_verh != NVM_VER_INVALID) &&
1284 (comb_verl != NVM_VER_INVALID))) {
1286 fw_vers->or_valid = true;
1288 comb_verl >> NVM_COMB_VER_SHFT;
1290 (comb_verl << NVM_COMB_VER_SHFT)
1291 | (comb_verh >> NVM_COMB_VER_SHFT);
1293 comb_verh & NVM_COMB_VER_MASK;