Make gpxe build.
[gpxe/hramrach.git] / src / drivers / net / e1000 / e1000_nvm.c
blob488252f4261da9d23c13bb96240f441c229a4e04
1 /*******************************************************************************
3 Intel PRO/1000 Linux driver
4 Copyright(c) 1999 - 2008 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
29 FILE_LICENCE ( GPL2_OR_LATER );
31 #include "e1000_api.h"
33 static void e1000_reload_nvm_generic(struct e1000_hw *hw);
35 /**
36 * e1000_init_nvm_ops_generic - Initialize NVM function pointers
37 * @hw: pointer to the HW structure
39 * Setups up the function pointers to no-op functions
40 **/
41 void e1000_init_nvm_ops_generic(struct e1000_hw *hw)
43 struct e1000_nvm_info *nvm = &hw->nvm;
44 DEBUGFUNC("e1000_init_nvm_ops_generic");
46 /* Initialize function pointers */
47 nvm->ops.init_params = e1000_null_ops_generic;
48 nvm->ops.acquire = e1000_null_ops_generic;
49 nvm->ops.read = e1000_null_read_nvm;
50 nvm->ops.release = e1000_null_nvm_generic;
51 nvm->ops.reload = e1000_reload_nvm_generic;
52 nvm->ops.update = e1000_null_ops_generic;
53 nvm->ops.valid_led_default = e1000_null_led_default;
54 nvm->ops.validate = e1000_null_ops_generic;
55 nvm->ops.write = e1000_null_write_nvm;
58 /**
59 * e1000_null_nvm_read - No-op function, return 0
60 * @hw: pointer to the HW structure
61 **/
62 s32 e1000_null_read_nvm(struct e1000_hw *hw __unused, u16 a __unused,
63 u16 b __unused, u16 *c __unused)
65 DEBUGFUNC("e1000_null_read_nvm");
66 return E1000_SUCCESS;
69 /**
70 * e1000_null_nvm_generic - No-op function, return void
71 * @hw: pointer to the HW structure
72 **/
73 void e1000_null_nvm_generic(struct e1000_hw *hw __unused)
75 DEBUGFUNC("e1000_null_nvm_generic");
76 return;
79 /**
80 * e1000_null_led_default - No-op function, return 0
81 * @hw: pointer to the HW structure
82 **/
83 s32 e1000_null_led_default(struct e1000_hw *hw __unused,
84 u16 *data __unused)
86 DEBUGFUNC("e1000_null_led_default");
87 return E1000_SUCCESS;
90 /**
91 * e1000_null_write_nvm - No-op function, return 0
92 * @hw: pointer to the HW structure
93 **/
94 s32 e1000_null_write_nvm(struct e1000_hw *hw __unused, u16 a __unused,
95 u16 b __unused, u16 *c __unused)
97 DEBUGFUNC("e1000_null_write_nvm");
98 return E1000_SUCCESS;
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);
145 u32 mask;
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;
152 else
153 if (nvm->type == e1000_nvm_eeprom_spi)
154 eecd |= E1000_EECD_DO;
156 do {
157 eecd &= ~E1000_EECD_DI;
159 if (data & mask)
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);
170 mask >>= 1;
171 } while (mask);
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
186 * always be clear.
188 static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
190 u32 eecd;
191 u32 i;
192 u16 data;
194 DEBUGFUNC("e1000_shift_in_eec_bits");
196 eecd = E1000_READ_REG(hw, E1000_EECD);
198 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
199 data = 0;
201 for (i = 0; i < count; i++) {
202 data <<= 1;
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)
209 data |= 1;
211 e1000_lower_eec_clk(hw, &eecd);
214 return data;
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;
228 u32 i, reg = 0;
229 s32 ret_val = -E1000_ERR_NVM;
231 DEBUGFUNC("e1000_poll_eerd_eewr_done");
233 for (i = 0; i < attempts; i++) {
234 if (ee_reg == E1000_NVM_POLL_READ)
235 reg = E1000_READ_REG(hw, E1000_EERD);
236 else
237 reg = E1000_READ_REG(hw, E1000_EEWR);
239 if (reg & E1000_NVM_RW_REG_DONE) {
240 ret_val = E1000_SUCCESS;
241 break;
244 usec_delay(5);
247 return ret_val;
251 * e1000_acquire_nvm_generic - Generic request for access to EEPROM
252 * @hw: pointer to the HW structure
254 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
255 * Return successful if access grant bit set, else clear the request for
256 * EEPROM access and return -E1000_ERR_NVM (-1).
258 s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
260 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
261 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
262 s32 ret_val = E1000_SUCCESS;
264 DEBUGFUNC("e1000_acquire_nvm_generic");
266 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
267 eecd = E1000_READ_REG(hw, E1000_EECD);
269 while (timeout) {
270 if (eecd & E1000_EECD_GNT)
271 break;
272 usec_delay(5);
273 eecd = E1000_READ_REG(hw, E1000_EECD);
274 timeout--;
277 if (!timeout) {
278 eecd &= ~E1000_EECD_REQ;
279 E1000_WRITE_REG(hw, E1000_EECD, eecd);
280 DEBUGOUT("Could not acquire NVM grant\n");
281 ret_val = -E1000_ERR_NVM;
284 return ret_val;
288 * e1000_standby_nvm - Return EEPROM to standby state
289 * @hw: pointer to the HW structure
291 * Return the EEPROM to a standby state.
293 static void e1000_standby_nvm(struct e1000_hw *hw)
295 struct e1000_nvm_info *nvm = &hw->nvm;
296 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
298 DEBUGFUNC("e1000_standby_nvm");
300 if (nvm->type == e1000_nvm_eeprom_microwire) {
301 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
302 E1000_WRITE_REG(hw, E1000_EECD, eecd);
303 E1000_WRITE_FLUSH(hw);
304 usec_delay(nvm->delay_usec);
306 e1000_raise_eec_clk(hw, &eecd);
308 /* Select EEPROM */
309 eecd |= E1000_EECD_CS;
310 E1000_WRITE_REG(hw, E1000_EECD, eecd);
311 E1000_WRITE_FLUSH(hw);
312 usec_delay(nvm->delay_usec);
314 e1000_lower_eec_clk(hw, &eecd);
315 } else
316 if (nvm->type == e1000_nvm_eeprom_spi) {
317 /* Toggle CS to flush commands */
318 eecd |= E1000_EECD_CS;
319 E1000_WRITE_REG(hw, E1000_EECD, eecd);
320 E1000_WRITE_FLUSH(hw);
321 usec_delay(nvm->delay_usec);
322 eecd &= ~E1000_EECD_CS;
323 E1000_WRITE_REG(hw, E1000_EECD, eecd);
324 E1000_WRITE_FLUSH(hw);
325 usec_delay(nvm->delay_usec);
330 * e1000_stop_nvm - Terminate EEPROM command
331 * @hw: pointer to the HW structure
333 * Terminates the current command by inverting the EEPROM's chip select pin.
335 void e1000_stop_nvm(struct e1000_hw *hw)
337 u32 eecd;
339 DEBUGFUNC("e1000_stop_nvm");
341 eecd = E1000_READ_REG(hw, E1000_EECD);
342 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
343 /* Pull CS high */
344 eecd |= E1000_EECD_CS;
345 e1000_lower_eec_clk(hw, &eecd);
346 } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
347 /* CS on Microwire is active-high */
348 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
349 E1000_WRITE_REG(hw, E1000_EECD, eecd);
350 e1000_raise_eec_clk(hw, &eecd);
351 e1000_lower_eec_clk(hw, &eecd);
356 * e1000_release_nvm_generic - Release exclusive access to EEPROM
357 * @hw: pointer to the HW structure
359 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
361 void e1000_release_nvm_generic(struct e1000_hw *hw)
363 u32 eecd;
365 DEBUGFUNC("e1000_release_nvm_generic");
367 e1000_stop_nvm(hw);
369 eecd = E1000_READ_REG(hw, E1000_EECD);
370 eecd &= ~E1000_EECD_REQ;
371 E1000_WRITE_REG(hw, E1000_EECD, eecd);
375 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
376 * @hw: pointer to the HW structure
378 * Setups the EEPROM for reading and writing.
380 static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
382 struct e1000_nvm_info *nvm = &hw->nvm;
383 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
384 s32 ret_val = E1000_SUCCESS;
385 u16 timeout = 0;
386 u8 spi_stat_reg;
388 DEBUGFUNC("e1000_ready_nvm_eeprom");
390 if (nvm->type == e1000_nvm_eeprom_microwire) {
391 /* Clear SK and DI */
392 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
393 E1000_WRITE_REG(hw, E1000_EECD, eecd);
394 /* Set CS */
395 eecd |= E1000_EECD_CS;
396 E1000_WRITE_REG(hw, E1000_EECD, eecd);
397 } else
398 if (nvm->type == e1000_nvm_eeprom_spi) {
399 /* Clear SK and CS */
400 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
401 E1000_WRITE_REG(hw, E1000_EECD, eecd);
402 usec_delay(1);
403 timeout = NVM_MAX_RETRY_SPI;
406 * Read "Status Register" repeatedly until the LSB is cleared.
407 * The EEPROM will signal that the command has been completed
408 * by clearing bit 0 of the internal status register. If it's
409 * not cleared within 'timeout', then error out.
411 while (timeout) {
412 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
413 hw->nvm.opcode_bits);
414 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
415 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
416 break;
418 usec_delay(5);
419 e1000_standby_nvm(hw);
420 timeout--;
423 if (!timeout) {
424 DEBUGOUT("SPI NVM Status error\n");
425 ret_val = -E1000_ERR_NVM;
426 goto out;
430 out:
431 return ret_val;
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;
446 u32 i = 0;
447 s32 ret_val;
448 u16 word_in;
449 u8 read_opcode = NVM_READ_OPCODE_SPI;
451 DEBUGFUNC("e1000_read_nvm_spi");
454 * A check for invalid values: offset too large, too many words,
455 * and not enough words.
457 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
458 (words == 0)) {
459 DEBUGOUT("nvm parameter(s) out of bounds\n");
460 ret_val = -E1000_ERR_NVM;
461 goto out;
464 ret_val = nvm->ops.acquire(hw);
465 if (ret_val)
466 goto out;
468 ret_val = e1000_ready_nvm_eeprom(hw);
469 if (ret_val)
470 goto release;
472 e1000_standby_nvm(hw);
474 if ((nvm->address_bits == 8) && (offset >= 128))
475 read_opcode |= NVM_A8_OPCODE_SPI;
477 /* Send the READ command (opcode + addr) */
478 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
479 e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
482 * Read the data. SPI NVMs increment the address with each byte
483 * read and will roll over if reading beyond the end. This allows
484 * us to read the whole NVM from any offset
486 for (i = 0; i < words; i++) {
487 word_in = e1000_shift_in_eec_bits(hw, 16);
488 data[i] = (word_in >> 8) | (word_in << 8);
491 release:
492 nvm->ops.release(hw);
494 out:
495 return ret_val;
499 * e1000_read_nvm_microwire - Reads EEPROM's using microwire
500 * @hw: pointer to the HW structure
501 * @offset: offset of word in the EEPROM to read
502 * @words: number of words to read
503 * @data: word read from the EEPROM
505 * Reads a 16 bit word from the EEPROM.
507 s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
508 u16 *data)
510 struct e1000_nvm_info *nvm = &hw->nvm;
511 u32 i = 0;
512 s32 ret_val;
513 u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
515 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)) ||
522 (words == 0)) {
523 DEBUGOUT("nvm parameter(s) out of bounds\n");
524 ret_val = -E1000_ERR_NVM;
525 goto out;
528 ret_val = nvm->ops.acquire(hw);
529 if (ret_val)
530 goto out;
532 ret_val = e1000_ready_nvm_eeprom(hw);
533 if (ret_val)
534 goto release;
536 for (i = 0; i < words; i++) {
537 /* Send the READ command (opcode + addr) */
538 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
539 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
540 nvm->address_bits);
543 * Read the data. For microwire, each word requires the
544 * overhead of setup and tear-down.
546 data[i] = e1000_shift_in_eec_bits(hw, 16);
547 e1000_standby_nvm(hw);
550 release:
551 nvm->ops.release(hw);
553 out:
554 return ret_val;
558 * e1000_read_nvm_eerd - Reads EEPROM using EERD register
559 * @hw: pointer to the HW structure
560 * @offset: offset of word in the EEPROM to read
561 * @words: number of words to read
562 * @data: word read from the EEPROM
564 * Reads a 16 bit word from the EEPROM using the EERD register.
566 s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
568 struct e1000_nvm_info *nvm = &hw->nvm;
569 u32 i, eerd = 0;
570 s32 ret_val = E1000_SUCCESS;
572 DEBUGFUNC("e1000_read_nvm_eerd");
575 * A check for invalid values: offset too large, too many words,
576 * too many words for the offset, and not enough words.
578 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
579 (words == 0)) {
580 DEBUGOUT("nvm parameter(s) out of bounds\n");
581 ret_val = -E1000_ERR_NVM;
582 goto out;
585 for (i = 0; i < words; i++) {
586 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
587 E1000_NVM_RW_REG_START;
589 E1000_WRITE_REG(hw, E1000_EERD, eerd);
590 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
591 if (ret_val)
592 break;
594 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
595 E1000_NVM_RW_REG_DATA);
598 out:
599 return ret_val;
603 * e1000_write_nvm_spi - Write to EEPROM using SPI
604 * @hw: pointer to the HW structure
605 * @offset: offset within the EEPROM to be written to
606 * @words: number of words to write
607 * @data: 16 bit word(s) to be written to the EEPROM
609 * Writes data to EEPROM at offset using SPI interface.
611 * If e1000_update_nvm_checksum is not called after this function , the
612 * EEPROM will most likely contain an invalid checksum.
614 s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
616 struct e1000_nvm_info *nvm = &hw->nvm;
617 s32 ret_val;
618 u16 widx = 0;
620 DEBUGFUNC("e1000_write_nvm_spi");
623 * A check for invalid values: offset too large, too many words,
624 * and not enough words.
626 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
627 (words == 0)) {
628 DEBUGOUT("nvm parameter(s) out of bounds\n");
629 ret_val = -E1000_ERR_NVM;
630 goto out;
633 ret_val = nvm->ops.acquire(hw);
634 if (ret_val)
635 goto out;
637 while (widx < words) {
638 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
640 ret_val = e1000_ready_nvm_eeprom(hw);
641 if (ret_val)
642 goto release;
644 e1000_standby_nvm(hw);
646 /* Send the WRITE ENABLE command (8 bit opcode) */
647 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
648 nvm->opcode_bits);
650 e1000_standby_nvm(hw);
653 * Some SPI eeproms use the 8th address bit embedded in the
654 * opcode
656 if ((nvm->address_bits == 8) && (offset >= 128))
657 write_opcode |= NVM_A8_OPCODE_SPI;
659 /* Send the Write command (8-bit opcode + addr) */
660 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
661 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
662 nvm->address_bits);
664 /* Loop to allow for up to whole page write of eeprom */
665 while (widx < words) {
666 u16 word_out = data[widx];
667 word_out = (word_out >> 8) | (word_out << 8);
668 e1000_shift_out_eec_bits(hw, word_out, 16);
669 widx++;
671 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
672 e1000_standby_nvm(hw);
673 break;
678 msec_delay(10);
679 release:
680 nvm->ops.release(hw);
682 out:
683 return ret_val;
687 * e1000_write_nvm_microwire - Writes EEPROM using microwire
688 * @hw: pointer to the HW structure
689 * @offset: offset within the EEPROM to be written to
690 * @words: number of words to write
691 * @data: 16 bit word(s) to be written to the EEPROM
693 * Writes data to EEPROM at offset using microwire interface.
695 * If e1000_update_nvm_checksum is not called after this function , the
696 * EEPROM will most likely contain an invalid checksum.
698 s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
699 u16 *data)
701 struct e1000_nvm_info *nvm = &hw->nvm;
702 s32 ret_val;
703 u32 eecd;
704 u16 words_written = 0;
705 u16 widx = 0;
707 DEBUGFUNC("e1000_write_nvm_microwire");
710 * A check for invalid values: offset too large, too many words,
711 * and not enough words.
713 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
714 (words == 0)) {
715 DEBUGOUT("nvm parameter(s) out of bounds\n");
716 ret_val = -E1000_ERR_NVM;
717 goto out;
720 ret_val = nvm->ops.acquire(hw);
721 if (ret_val)
722 goto out;
724 ret_val = e1000_ready_nvm_eeprom(hw);
725 if (ret_val)
726 goto release;
728 e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
729 (u16)(nvm->opcode_bits + 2));
731 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
733 e1000_standby_nvm(hw);
735 while (words_written < words) {
736 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
737 nvm->opcode_bits);
739 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
740 nvm->address_bits);
742 e1000_shift_out_eec_bits(hw, data[words_written], 16);
744 e1000_standby_nvm(hw);
746 for (widx = 0; widx < 200; widx++) {
747 eecd = E1000_READ_REG(hw, E1000_EECD);
748 if (eecd & E1000_EECD_DO)
749 break;
750 usec_delay(50);
753 if (widx == 200) {
754 DEBUGOUT("NVM Write did not complete\n");
755 ret_val = -E1000_ERR_NVM;
756 goto release;
759 e1000_standby_nvm(hw);
761 words_written++;
764 e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
765 (u16)(nvm->opcode_bits + 2));
767 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
769 release:
770 nvm->ops.release(hw);
772 out:
773 return ret_val;
777 * e1000_read_pba_num_generic - Read device part number
778 * @hw: pointer to the HW structure
779 * @pba_num: pointer to device part number
781 * Reads the product board assembly (PBA) number from the EEPROM and stores
782 * the value in pba_num.
784 s32 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
786 s32 ret_val;
787 u16 nvm_data;
789 DEBUGFUNC("e1000_read_pba_num_generic");
791 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
792 if (ret_val) {
793 DEBUGOUT("NVM Read Error\n");
794 goto out;
796 *pba_num = (u32)(nvm_data << 16);
798 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
799 if (ret_val) {
800 DEBUGOUT("NVM Read Error\n");
801 goto out;
803 *pba_num |= nvm_data;
805 out:
806 return ret_val;
810 * e1000_read_mac_addr_generic - Read device MAC address
811 * @hw: pointer to the HW structure
813 * Reads the device MAC address from the EEPROM and stores the value.
814 * Since devices with two ports use the same EEPROM, we increment the
815 * last bit in the MAC address for the second port.
817 s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
819 u32 rar_high;
820 u32 rar_low;
821 u16 i;
823 rar_high = E1000_READ_REG(hw, E1000_RAH(0));
824 rar_low = E1000_READ_REG(hw, E1000_RAL(0));
826 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
827 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
829 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
830 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
832 for (i = 0; i < ETH_ADDR_LEN; i++)
833 hw->mac.addr[i] = hw->mac.perm_addr[i];
835 return E1000_SUCCESS;
839 * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
840 * @hw: pointer to the HW structure
842 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
843 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
845 s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
847 s32 ret_val = E1000_SUCCESS;
848 u16 checksum = 0;
849 u16 i, nvm_data;
851 DEBUGFUNC("e1000_validate_nvm_checksum_generic");
853 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
854 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
855 if (ret_val) {
856 DEBUGOUT("NVM Read Error\n");
857 goto out;
859 checksum += nvm_data;
862 if (checksum != (u16) NVM_SUM) {
863 DEBUGOUT("NVM Checksum Invalid\n");
864 ret_val = -E1000_ERR_NVM;
865 goto out;
868 out:
869 return ret_val;
873 * e1000_update_nvm_checksum_generic - Update EEPROM checksum
874 * @hw: pointer to the HW structure
876 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
877 * up to the checksum. Then calculates the EEPROM checksum and writes the
878 * value to the EEPROM.
880 s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
882 s32 ret_val;
883 u16 checksum = 0;
884 u16 i, nvm_data;
886 DEBUGFUNC("e1000_update_nvm_checksum");
888 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
889 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
890 if (ret_val) {
891 DEBUGOUT("NVM Read Error while updating checksum.\n");
892 goto out;
894 checksum += nvm_data;
896 checksum = (u16) NVM_SUM - checksum;
897 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
898 if (ret_val)
899 DEBUGOUT("NVM Write Error while updating checksum.\n");
901 out:
902 return ret_val;
906 * e1000_reload_nvm_generic - Reloads EEPROM
907 * @hw: pointer to the HW structure
909 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
910 * extended control register.
912 static void e1000_reload_nvm_generic(struct e1000_hw *hw)
914 u32 ctrl_ext;
916 DEBUGFUNC("e1000_reload_nvm_generic");
918 usec_delay(10);
919 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
920 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
921 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
922 E1000_WRITE_FLUSH(hw);