3881 want device driver for HP SmartArray RAID controllers
[illumos-gate.git] / usr / src / uts / common / io / e1000g / e1000_nvm.c
blob2b01ef1db598b70c7c9f98d2c5d324a3d0cb6589
1 /*
2 * This file is provided under a CDDLv1 license. When using or
3 * redistributing this file, you may do so under this license.
4 * In redistributing this file this license must be included
5 * and no other modification of this header file is permitted.
7 * CDDL LICENSE SUMMARY
9 * Copyright(c) 1999 - 2009 Intel Corporation. All rights reserved.
11 * The contents of this file are subject to the terms of Version
12 * 1.0 of the Common Development and Distribution License (the "License").
14 * You should have received a copy of the License with this software.
15 * You can obtain a copy of the License at
16 * http://www.opensolaris.org/os/licensing.
17 * See the License for the specific language governing permissions
18 * and limitations under the License.
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms of the CDDLv1.
27 * IntelVersion: 1.49 v3-1-10-1_2009-9-18_Release14-6
29 #include "e1000_api.h"
31 static void e1000_reload_nvm_generic(struct e1000_hw *hw);
34 * e1000_init_nvm_ops_generic - Initialize NVM function pointers
35 * @hw: pointer to the HW structure
37 * Setups up the function pointers to no-op functions
39 void
40 e1000_init_nvm_ops_generic(struct e1000_hw *hw)
42 struct e1000_nvm_info *nvm = &hw->nvm;
43 DEBUGFUNC("e1000_init_nvm_ops_generic");
45 /* Initialize function pointers */
46 nvm->ops.init_params = e1000_null_ops_generic;
47 nvm->ops.acquire = e1000_null_ops_generic;
48 nvm->ops.read = e1000_null_read_nvm;
49 nvm->ops.release = e1000_null_nvm_generic;
50 nvm->ops.reload = e1000_reload_nvm_generic;
51 nvm->ops.update = e1000_null_ops_generic;
52 nvm->ops.valid_led_default = e1000_null_led_default;
53 nvm->ops.validate = e1000_null_ops_generic;
54 nvm->ops.write = e1000_null_write_nvm;
58 * e1000_null_nvm_read - No-op function, return 0
59 * @hw: pointer to the HW structure
61 s32
62 e1000_null_read_nvm(struct e1000_hw *hw, u16 a, u16 b, u16 *c)
64 DEBUGFUNC("e1000_null_read_nvm");
65 UNREFERENCED_4PARAMETER(hw, a, b, c);
66 return (E1000_SUCCESS);
70 * e1000_null_nvm_generic - No-op function, return void
71 * @hw: pointer to the HW structure
73 void
74 e1000_null_nvm_generic(struct e1000_hw *hw)
76 DEBUGFUNC("e1000_null_nvm_generic");
77 UNREFERENCED_1PARAMETER(hw);
81 * e1000_null_led_default - No-op function, return 0
82 * @hw: pointer to the HW structure
84 s32
85 e1000_null_led_default(struct e1000_hw *hw, u16 *data)
87 DEBUGFUNC("e1000_null_led_default");
88 UNREFERENCED_2PARAMETER(hw, data);
89 return (E1000_SUCCESS);
93 * e1000_null_write_nvm - No-op function, return 0
94 * @hw: pointer to the HW structure
96 s32
97 e1000_null_write_nvm(struct e1000_hw *hw, u16 a, u16 b, u16 *c)
99 DEBUGFUNC("e1000_null_write_nvm");
100 UNREFERENCED_4PARAMETER(hw, a, b, c);
101 return (E1000_SUCCESS);
105 * e1000_raise_eec_clk - Raise EEPROM clock
106 * @hw: pointer to the HW structure
107 * @eecd: pointer to the EEPROM
109 * Enable/Raise the EEPROM clock bit.
111 static void
112 e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
114 *eecd = *eecd | E1000_EECD_SK;
115 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
116 E1000_WRITE_FLUSH(hw);
117 usec_delay(hw->nvm.delay_usec);
121 * e1000_lower_eec_clk - Lower EEPROM clock
122 * @hw: pointer to the HW structure
123 * @eecd: pointer to the EEPROM
125 * Clear/Lower the EEPROM clock bit.
127 static void
128 e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
130 *eecd = *eecd & ~E1000_EECD_SK;
131 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
132 E1000_WRITE_FLUSH(hw);
133 usec_delay(hw->nvm.delay_usec);
137 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
138 * @hw: pointer to the HW structure
139 * @data: data to send to the EEPROM
140 * @count: number of bits to shift out
142 * We need to shift 'count' bits out to the EEPROM. So, the value in the
143 * "data" parameter will be shifted out to the EEPROM one bit at a time.
144 * In order to do this, "data" must be broken down into bits.
146 static void
147 e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
149 struct e1000_nvm_info *nvm = &hw->nvm;
150 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
151 u32 mask;
153 DEBUGFUNC("e1000_shift_out_eec_bits");
155 mask = 0x01 << (count - 1);
156 if (nvm->type == e1000_nvm_eeprom_microwire)
157 eecd &= ~E1000_EECD_DO;
158 else if (nvm->type == e1000_nvm_eeprom_spi)
159 eecd |= E1000_EECD_DO;
161 do {
162 eecd &= ~E1000_EECD_DI;
164 if (data & mask)
165 eecd |= E1000_EECD_DI;
167 E1000_WRITE_REG(hw, E1000_EECD, eecd);
168 E1000_WRITE_FLUSH(hw);
170 usec_delay(nvm->delay_usec);
172 e1000_raise_eec_clk(hw, &eecd);
173 e1000_lower_eec_clk(hw, &eecd);
175 mask >>= 1;
176 } while (mask);
178 eecd &= ~E1000_EECD_DI;
179 E1000_WRITE_REG(hw, E1000_EECD, eecd);
183 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
184 * @hw: pointer to the HW structure
185 * @count: number of bits to shift in
187 * In order to read a register from the EEPROM, we need to shift 'count' bits
188 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
189 * the EEPROM (setting the SK bit), and then reading the value of the data out
190 * "DO" bit. During this "shifting in" process the data in "DI" bit should
191 * always be clear.
193 static u16
194 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
196 u32 eecd;
197 u32 i;
198 u16 data;
200 DEBUGFUNC("e1000_shift_in_eec_bits");
202 eecd = E1000_READ_REG(hw, E1000_EECD);
204 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
205 data = 0;
207 for (i = 0; i < count; i++) {
208 data <<= 1;
209 e1000_raise_eec_clk(hw, &eecd);
211 eecd = E1000_READ_REG(hw, E1000_EECD);
213 eecd &= ~E1000_EECD_DI;
214 if (eecd & E1000_EECD_DO)
215 data |= 1;
217 e1000_lower_eec_clk(hw, &eecd);
220 return (data);
224 * e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
225 * @hw: pointer to the HW structure
226 * @ee_reg: EEPROM flag for polling
228 * Polls the EEPROM status bit for either read or write completion based
229 * upon the value of 'ee_reg'.
232 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
234 u32 attempts = 100000;
235 u32 i, reg = 0;
236 s32 ret_val = -E1000_ERR_NVM;
238 DEBUGFUNC("e1000_poll_eerd_eewr_done");
240 for (i = 0; i < attempts; i++) {
241 if (ee_reg == E1000_NVM_POLL_READ)
242 reg = E1000_READ_REG(hw, E1000_EERD);
243 else
244 reg = E1000_READ_REG(hw, E1000_EEWR);
246 if (reg & E1000_NVM_RW_REG_DONE) {
247 ret_val = E1000_SUCCESS;
248 break;
251 usec_delay(5);
254 return (ret_val);
258 * e1000_acquire_nvm_generic - Generic request for access to EEPROM
259 * @hw: pointer to the HW structure
261 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
262 * Return successful if access grant bit set, else clear the request for
263 * EEPROM access and return -E1000_ERR_NVM (-1).
266 e1000_acquire_nvm_generic(struct e1000_hw *hw)
268 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
269 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
270 s32 ret_val = E1000_SUCCESS;
272 DEBUGFUNC("e1000_acquire_nvm_generic");
274 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
275 eecd = E1000_READ_REG(hw, E1000_EECD);
277 while (timeout) {
278 if (eecd & E1000_EECD_GNT)
279 break;
280 usec_delay(5);
281 eecd = E1000_READ_REG(hw, E1000_EECD);
282 timeout--;
285 if (!timeout) {
286 eecd &= ~E1000_EECD_REQ;
287 E1000_WRITE_REG(hw, E1000_EECD, eecd);
288 DEBUGOUT("Could not acquire NVM grant\n");
289 ret_val = -E1000_ERR_NVM;
291 return (ret_val);
295 * e1000_standby_nvm - Return EEPROM to standby state
296 * @hw: pointer to the HW structure
298 * Return the EEPROM to a standby state.
300 static void
301 e1000_standby_nvm(struct e1000_hw *hw)
303 struct e1000_nvm_info *nvm = &hw->nvm;
304 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
306 DEBUGFUNC("e1000_standby_nvm");
308 if (nvm->type == e1000_nvm_eeprom_microwire) {
309 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
310 E1000_WRITE_REG(hw, E1000_EECD, eecd);
311 E1000_WRITE_FLUSH(hw);
312 usec_delay(nvm->delay_usec);
314 e1000_raise_eec_clk(hw, &eecd);
316 /* Select EEPROM */
317 eecd |= E1000_EECD_CS;
318 E1000_WRITE_REG(hw, E1000_EECD, eecd);
319 E1000_WRITE_FLUSH(hw);
320 usec_delay(nvm->delay_usec);
322 e1000_lower_eec_clk(hw, &eecd);
323 } else if (nvm->type == e1000_nvm_eeprom_spi) {
324 /* Toggle CS to flush commands */
325 eecd |= E1000_EECD_CS;
326 E1000_WRITE_REG(hw, E1000_EECD, eecd);
327 E1000_WRITE_FLUSH(hw);
328 usec_delay(nvm->delay_usec);
329 eecd &= ~E1000_EECD_CS;
330 E1000_WRITE_REG(hw, E1000_EECD, eecd);
331 E1000_WRITE_FLUSH(hw);
332 usec_delay(nvm->delay_usec);
337 * e1000_stop_nvm - Terminate EEPROM command
338 * @hw: pointer to the HW structure
340 * Terminates the current command by inverting the EEPROM's chip select pin.
342 void
343 e1000_stop_nvm(struct e1000_hw *hw)
345 u32 eecd;
347 DEBUGFUNC("e1000_stop_nvm");
349 eecd = E1000_READ_REG(hw, E1000_EECD);
350 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
351 /* Pull CS high */
352 eecd |= E1000_EECD_CS;
353 e1000_lower_eec_clk(hw, &eecd);
354 } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
355 /* CS on Microwire is active-high */
356 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
357 E1000_WRITE_REG(hw, E1000_EECD, eecd);
358 e1000_raise_eec_clk(hw, &eecd);
359 e1000_lower_eec_clk(hw, &eecd);
364 * e1000_release_nvm_generic - Release exclusive access to EEPROM
365 * @hw: pointer to the HW structure
367 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
369 void
370 e1000_release_nvm_generic(struct e1000_hw *hw)
372 u32 eecd;
374 DEBUGFUNC("e1000_release_nvm_generic");
376 e1000_stop_nvm(hw);
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
390 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
392 struct e1000_nvm_info *nvm = &hw->nvm;
393 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
394 s32 ret_val = E1000_SUCCESS;
395 u16 timeout = 0;
396 u8 spi_stat_reg;
398 DEBUGFUNC("e1000_ready_nvm_eeprom");
400 if (nvm->type == e1000_nvm_eeprom_microwire) {
401 /* Clear SK and DI */
402 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
403 E1000_WRITE_REG(hw, E1000_EECD, eecd);
404 /* Set CS */
405 eecd |= E1000_EECD_CS;
406 E1000_WRITE_REG(hw, E1000_EECD, eecd);
407 } else if (nvm->type == e1000_nvm_eeprom_spi) {
408 /* Clear SK and CS */
409 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
410 E1000_WRITE_REG(hw, E1000_EECD, eecd);
411 usec_delay(1);
412 timeout = NVM_MAX_RETRY_SPI;
415 * Read "Status Register" repeatedly until the LSB is cleared.
416 * The EEPROM will signal that the command has been completed
417 * by clearing bit 0 of the internal status register. If it's
418 * not cleared within 'timeout', then error out.
420 while (timeout) {
421 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
422 hw->nvm.opcode_bits);
423 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
424 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
425 break;
427 usec_delay(5);
428 e1000_standby_nvm(hw);
429 timeout--;
432 if (!timeout) {
433 DEBUGOUT("SPI NVM Status error\n");
434 ret_val = -E1000_ERR_NVM;
435 goto out;
439 out:
440 return (ret_val);
444 * e1000_read_nvm_spi - Read EEPROM's using SPI
445 * @hw: pointer to the HW structure
446 * @offset: offset of word in the EEPROM to read
447 * @words: number of words to read
448 * @data: word read from the EEPROM
450 * Reads a 16 bit word from the EEPROM.
453 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 * data)
455 struct e1000_nvm_info *nvm = &hw->nvm;
456 u32 i = 0;
457 s32 ret_val;
458 u16 word_in;
459 u8 read_opcode = NVM_READ_OPCODE_SPI;
461 DEBUGFUNC("e1000_read_nvm_spi");
464 * A check for invalid values: offset too large, too many words, and
465 * not enough words.
467 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
468 (words == 0)) {
469 DEBUGOUT("nvm parameter(s) out of bounds\n");
470 ret_val = -E1000_ERR_NVM;
471 goto out;
474 ret_val = nvm->ops.acquire(hw);
475 if (ret_val)
476 goto out;
478 ret_val = e1000_ready_nvm_eeprom(hw);
479 if (ret_val)
480 goto release;
482 e1000_standby_nvm(hw);
484 if ((nvm->address_bits == 8) && (offset >= 128))
485 read_opcode |= NVM_A8_OPCODE_SPI;
487 /* Send the READ command (opcode + addr) */
488 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
489 e1000_shift_out_eec_bits(hw, (u16)(offset * 2), nvm->address_bits);
492 * Read the data. SPI NVMs increment the address with each byte read
493 * and will roll over if reading beyond the end. This allows us to
494 * read the whole NVM from any offset
496 for (i = 0; i < words; i++) {
497 word_in = e1000_shift_in_eec_bits(hw, 16);
498 data[i] = (word_in >> 8) | (word_in << 8);
501 release:
502 nvm->ops.release(hw);
504 out:
505 return (ret_val);
509 * e1000_read_nvm_microwire - Reads EEPROM's using microwire
510 * @hw: pointer to the HW structure
511 * @offset: offset of word in the EEPROM to read
512 * @words: number of words to read
513 * @data: word read from the EEPROM
515 * Reads a 16 bit word from the EEPROM.
518 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
520 struct e1000_nvm_info *nvm = &hw->nvm;
521 u32 i = 0;
522 s32 ret_val;
523 u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
525 DEBUGFUNC("e1000_read_nvm_microwire");
528 * A check for invalid values: offset too large, too many words, and
529 * not enough words.
531 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
532 (words == 0)) {
533 DEBUGOUT("nvm parameter(s) out of bounds\n");
534 ret_val = -E1000_ERR_NVM;
535 goto out;
538 ret_val = nvm->ops.acquire(hw);
539 if (ret_val)
540 goto out;
542 ret_val = e1000_ready_nvm_eeprom(hw);
543 if (ret_val)
544 goto release;
546 for (i = 0; i < words; i++) {
547 /* Send the READ command (opcode + addr) */
548 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
549 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
550 nvm->address_bits);
553 * Read the data. For microwire, each word requires the
554 * overhead of setup and tear-down.
556 data[i] = e1000_shift_in_eec_bits(hw, 16);
557 e1000_standby_nvm(hw);
560 release:
561 nvm->ops.release(hw);
563 out:
564 return (ret_val);
568 * e1000_read_nvm_eerd - Reads EEPROM using EERD register
569 * @hw: pointer to the HW structure
570 * @offset: offset of word in the EEPROM to read
571 * @words: number of words to read
572 * @data: word read from the EEPROM
574 * Reads a 16 bit word from the EEPROM using the EERD register.
577 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
579 struct e1000_nvm_info *nvm = &hw->nvm;
580 u32 i, eerd = 0;
581 s32 ret_val = E1000_SUCCESS;
583 DEBUGFUNC("e1000_read_nvm_eerd");
586 * A check for invalid values: offset too large, too many words,
587 * too many words for the offset, and not enough words.
589 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
590 (words == 0)) {
591 DEBUGOUT("nvm parameter(s) out of bounds\n");
592 ret_val = -E1000_ERR_NVM;
593 goto out;
596 for (i = 0; i < words; i++) {
597 eerd = ((offset + i) << E1000_NVM_RW_ADDR_SHIFT) +
598 E1000_NVM_RW_REG_START;
600 E1000_WRITE_REG(hw, E1000_EERD, eerd);
601 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
602 if (ret_val)
603 break;
605 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
606 E1000_NVM_RW_REG_DATA);
609 out:
610 return (ret_val);
614 * e1000_write_nvm_spi - Write to EEPROM using SPI
615 * @hw: pointer to the HW structure
616 * @offset: offset within the EEPROM to be written to
617 * @words: number of words to write
618 * @data: 16 bit word(s) to be written to the EEPROM
620 * Writes data to EEPROM at offset using SPI interface.
622 * If e1000_update_nvm_checksum is not called after this function , the
623 * EEPROM will most likely contain an invalid checksum.
626 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
628 struct e1000_nvm_info *nvm = &hw->nvm;
629 s32 ret_val;
630 u16 widx = 0;
632 DEBUGFUNC("e1000_write_nvm_spi");
635 * A check for invalid values: offset too large, too many words, and
636 * not enough words.
638 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
639 (words == 0)) {
640 DEBUGOUT("nvm parameter(s) out of bounds\n");
641 ret_val = -E1000_ERR_NVM;
642 goto out;
645 ret_val = nvm->ops.acquire(hw);
646 if (ret_val)
647 goto out;
649 while (widx < words) {
650 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
652 ret_val = e1000_ready_nvm_eeprom(hw);
653 if (ret_val)
654 goto release;
656 e1000_standby_nvm(hw);
658 /* Send the WRITE ENABLE command (8 bit opcode) */
659 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
660 nvm->opcode_bits);
662 e1000_standby_nvm(hw);
665 * Some SPI eeproms use the 8th address bit embedded in the
666 * opcode
668 if ((nvm->address_bits == 8) && (offset >= 128))
669 write_opcode |= NVM_A8_OPCODE_SPI;
671 /* Send the Write command (8-bit opcode + addr) */
672 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
673 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
674 nvm->address_bits);
676 /* Loop to allow for up to whole page write of eeprom */
677 while (widx < words) {
678 u16 word_out = data[widx];
680 word_out = (word_out >> 8) | (word_out << 8);
681 e1000_shift_out_eec_bits(hw, word_out, 16);
682 widx++;
684 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
685 e1000_standby_nvm(hw);
686 break;
691 msec_delay(10);
692 release:
693 nvm->ops.release(hw);
695 out:
696 return (ret_val);
700 * e1000_write_nvm_microwire - Writes EEPROM using microwire
701 * @hw: pointer to the HW structure
702 * @offset: offset within the EEPROM to be written to
703 * @words: number of words to write
704 * @data: 16 bit word(s) to be written to the EEPROM
706 * Writes data to EEPROM at offset using microwire interface.
708 * If e1000_update_nvm_checksum is not called after this function , the
709 * EEPROM will most likely contain an invalid checksum.
712 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
714 struct e1000_nvm_info *nvm = &hw->nvm;
715 s32 ret_val;
716 u32 eecd;
717 u16 words_written = 0;
718 u16 widx = 0;
720 DEBUGFUNC("e1000_write_nvm_microwire");
723 * A check for invalid values: offset too large, too many words, and
724 * not enough words.
726 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
727 (words == 0)) {
728 DEBUGOUT("nvm parameter(s) out of bounds\n");
729 ret_val = -E1000_ERR_NVM;
730 goto out;
733 ret_val = nvm->ops.acquire(hw);
734 if (ret_val)
735 goto out;
737 ret_val = e1000_ready_nvm_eeprom(hw);
738 if (ret_val)
739 goto release;
741 e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
742 (u16)(nvm->opcode_bits + 2));
744 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
746 e1000_standby_nvm(hw);
748 while (words_written < words) {
749 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
750 nvm->opcode_bits);
752 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
753 nvm->address_bits);
755 e1000_shift_out_eec_bits(hw, data[words_written], 16);
757 e1000_standby_nvm(hw);
759 for (widx = 0; widx < 200; widx++) {
760 eecd = E1000_READ_REG(hw, E1000_EECD);
761 if (eecd & E1000_EECD_DO)
762 break;
763 usec_delay(50);
766 if (widx == 200) {
767 DEBUGOUT("NVM Write did not complete\n");
768 ret_val = -E1000_ERR_NVM;
769 goto release;
772 e1000_standby_nvm(hw);
774 words_written++;
777 e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
778 (u16)(nvm->opcode_bits + 2));
780 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
782 release:
783 nvm->ops.release(hw);
785 out:
786 return (ret_val);
790 * e1000_read_pba_num_generic - Read device part number
791 * @hw: pointer to the HW structure
792 * @pba_num: pointer to device part number
794 * Reads the product board assembly (PBA) number from the EEPROM and stores
795 * the value in pba_num.
798 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
800 s32 ret_val;
801 u16 nvm_data;
803 DEBUGFUNC("e1000_read_pba_num_generic");
805 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
806 if (ret_val) {
807 DEBUGOUT("NVM Read Error\n");
808 goto out;
810 *pba_num = (u32)(nvm_data << 16);
812 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
813 if (ret_val) {
814 DEBUGOUT("NVM Read Error\n");
815 goto out;
817 *pba_num |= nvm_data;
819 out:
820 return (ret_val);
824 * e1000_read_mac_addr_generic - Read device MAC address
825 * @hw: pointer to the HW structure
827 * Reads the device MAC address from the EEPROM and stores the value.
828 * Since devices with two ports use the same EEPROM, we increment the
829 * last bit in the MAC address for the second port.
832 e1000_read_mac_addr_generic(struct e1000_hw *hw)
834 u32 rar_high;
835 u32 rar_low;
836 u16 i;
838 rar_high = E1000_READ_REG(hw, E1000_RAH(0));
839 rar_low = E1000_READ_REG(hw, E1000_RAL(0));
841 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
842 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
844 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
845 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
847 for (i = 0; i < ETH_ADDR_LEN; i++)
848 hw->mac.addr[i] = hw->mac.perm_addr[i];
850 return (E1000_SUCCESS);
854 * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
855 * @hw: pointer to the HW structure
857 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
858 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
861 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
863 s32 ret_val = E1000_SUCCESS;
864 u16 checksum = 0;
865 u16 i, nvm_data;
867 DEBUGFUNC("e1000_validate_nvm_checksum_generic");
869 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
870 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
871 if (ret_val) {
872 DEBUGOUT("NVM Read Error\n");
873 goto out;
875 checksum += nvm_data;
878 if (checksum != (u16)NVM_SUM) {
879 DEBUGOUT("NVM Checksum Invalid\n");
880 ret_val = -E1000_ERR_NVM;
881 goto out;
884 out:
885 return (ret_val);
889 * e1000_update_nvm_checksum_generic - Update EEPROM checksum
890 * @hw: pointer to the HW structure
892 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
893 * up to the checksum. Then calculates the EEPROM checksum and writes the
894 * value to the EEPROM.
897 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
899 s32 ret_val;
900 u16 checksum = 0;
901 u16 i, nvm_data;
903 DEBUGFUNC("e1000_update_nvm_checksum");
905 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
906 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
907 if (ret_val) {
908 DEBUGOUT("NVM Read Error while updating checksum.\n");
909 goto out;
911 checksum += nvm_data;
913 checksum = (u16)NVM_SUM - checksum;
914 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
915 if (ret_val) {
916 /* EMPTY */
917 DEBUGOUT("NVM Write Error while updating checksum.\n");
920 out:
921 return (ret_val);
925 * e1000_reload_nvm_generic - Reloads EEPROM
926 * @hw: pointer to the HW structure
928 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
929 * extended control register.
931 void
932 e1000_reload_nvm_generic(struct e1000_hw *hw)
934 u32 ctrl_ext;
936 DEBUGFUNC("e1000_reload_nvm_generic");
938 usec_delay(10);
939 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
940 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
941 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
942 E1000_WRITE_FLUSH(hw);