1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001 - 2015 Intel Corporation
7 STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw);
10 * e1000_init_nvm_ops_generic - Initialize NVM function pointers
11 * @hw: pointer to the HW structure
13 * Setups up the function pointers to no-op functions
15 void e1000_init_nvm_ops_generic(struct e1000_hw *hw)
17 struct e1000_nvm_info *nvm = &hw->nvm;
18 DEBUGFUNC("e1000_init_nvm_ops_generic");
20 /* Initialize function pointers */
21 nvm->ops.init_params = e1000_null_ops_generic;
22 nvm->ops.acquire = e1000_null_ops_generic;
23 nvm->ops.read = e1000_null_read_nvm;
24 nvm->ops.release = e1000_null_nvm_generic;
25 nvm->ops.reload = e1000_reload_nvm_generic;
26 nvm->ops.update = e1000_null_ops_generic;
27 nvm->ops.valid_led_default = e1000_null_led_default;
28 nvm->ops.validate = e1000_null_ops_generic;
29 nvm->ops.write = e1000_null_write_nvm;
33 * e1000_null_nvm_read - No-op function, return 0
34 * @hw: pointer to the HW structure
36 s32 e1000_null_read_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
37 u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
38 u16 E1000_UNUSEDARG *c)
40 DEBUGFUNC("e1000_null_read_nvm");
41 UNREFERENCED_4PARAMETER(hw, a, b, c);
46 * e1000_null_nvm_generic - No-op function, return void
47 * @hw: pointer to the HW structure
49 void e1000_null_nvm_generic(struct e1000_hw E1000_UNUSEDARG *hw)
51 DEBUGFUNC("e1000_null_nvm_generic");
52 UNREFERENCED_1PARAMETER(hw);
57 * e1000_null_led_default - No-op function, return 0
58 * @hw: pointer to the HW structure
60 s32 e1000_null_led_default(struct e1000_hw E1000_UNUSEDARG *hw,
61 u16 E1000_UNUSEDARG *data)
63 DEBUGFUNC("e1000_null_led_default");
64 UNREFERENCED_2PARAMETER(hw, data);
69 * e1000_null_write_nvm - No-op function, return 0
70 * @hw: pointer to the HW structure
72 s32 e1000_null_write_nvm(struct e1000_hw E1000_UNUSEDARG *hw,
73 u16 E1000_UNUSEDARG a, u16 E1000_UNUSEDARG b,
74 u16 E1000_UNUSEDARG *c)
76 DEBUGFUNC("e1000_null_write_nvm");
77 UNREFERENCED_4PARAMETER(hw, a, b, c);
82 * e1000_raise_eec_clk - Raise EEPROM clock
83 * @hw: pointer to the HW structure
84 * @eecd: pointer to the EEPROM
86 * Enable/Raise the EEPROM clock bit.
88 STATIC void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
90 *eecd = *eecd | E1000_EECD_SK;
91 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
92 E1000_WRITE_FLUSH(hw);
93 usec_delay(hw->nvm.delay_usec);
97 * e1000_lower_eec_clk - Lower EEPROM clock
98 * @hw: pointer to the HW structure
99 * @eecd: pointer to the EEPROM
101 * Clear/Lower the EEPROM clock bit.
103 STATIC void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
105 *eecd = *eecd & ~E1000_EECD_SK;
106 E1000_WRITE_REG(hw, E1000_EECD, *eecd);
107 E1000_WRITE_FLUSH(hw);
108 usec_delay(hw->nvm.delay_usec);
112 * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
113 * @hw: pointer to the HW structure
114 * @data: data to send to the EEPROM
115 * @count: number of bits to shift out
117 * We need to shift 'count' bits out to the EEPROM. So, the value in the
118 * "data" parameter will be shifted out to the EEPROM one bit at a time.
119 * In order to do this, "data" must be broken down into bits.
121 STATIC void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
123 struct e1000_nvm_info *nvm = &hw->nvm;
124 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
127 DEBUGFUNC("e1000_shift_out_eec_bits");
129 mask = 0x01 << (count - 1);
130 if (nvm->type == e1000_nvm_eeprom_microwire)
131 eecd &= ~E1000_EECD_DO;
133 if (nvm->type == e1000_nvm_eeprom_spi)
134 eecd |= E1000_EECD_DO;
137 eecd &= ~E1000_EECD_DI;
140 eecd |= E1000_EECD_DI;
142 E1000_WRITE_REG(hw, E1000_EECD, eecd);
143 E1000_WRITE_FLUSH(hw);
145 usec_delay(nvm->delay_usec);
147 e1000_raise_eec_clk(hw, &eecd);
148 e1000_lower_eec_clk(hw, &eecd);
153 eecd &= ~E1000_EECD_DI;
154 E1000_WRITE_REG(hw, E1000_EECD, eecd);
158 * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
159 * @hw: pointer to the HW structure
160 * @count: number of bits to shift in
162 * In order to read a register from the EEPROM, we need to shift 'count' bits
163 * in from the EEPROM. Bits are "shifted in" by raising the clock input to
164 * the EEPROM (setting the SK bit), and then reading the value of the data out
165 * "DO" bit. During this "shifting in" process the data in "DI" bit should
168 STATIC u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
174 DEBUGFUNC("e1000_shift_in_eec_bits");
176 eecd = E1000_READ_REG(hw, E1000_EECD);
178 eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
181 for (i = 0; i < count; i++) {
183 e1000_raise_eec_clk(hw, &eecd);
185 eecd = E1000_READ_REG(hw, E1000_EECD);
187 eecd &= ~E1000_EECD_DI;
188 if (eecd & E1000_EECD_DO)
191 e1000_lower_eec_clk(hw, &eecd);
198 * e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
199 * @hw: pointer to the HW structure
200 * @ee_reg: EEPROM flag for polling
202 * Polls the EEPROM status bit for either read or write completion based
203 * upon the value of 'ee_reg'.
205 s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
207 u32 attempts = 100000;
210 DEBUGFUNC("e1000_poll_eerd_eewr_done");
212 for (i = 0; i < attempts; i++) {
213 if (ee_reg == E1000_NVM_POLL_READ)
214 reg = E1000_READ_REG(hw, E1000_EERD);
216 reg = E1000_READ_REG(hw, E1000_EEWR);
218 if (reg & E1000_NVM_RW_REG_DONE)
219 return E1000_SUCCESS;
224 return -E1000_ERR_NVM;
228 * e1000_acquire_nvm_generic - Generic request for access to EEPROM
229 * @hw: pointer to the HW structure
231 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
232 * Return successful if access grant bit set, else clear the request for
233 * EEPROM access and return -E1000_ERR_NVM (-1).
235 s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
237 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
238 s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
240 DEBUGFUNC("e1000_acquire_nvm_generic");
242 E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
243 eecd = E1000_READ_REG(hw, E1000_EECD);
246 if (eecd & E1000_EECD_GNT)
249 eecd = E1000_READ_REG(hw, E1000_EECD);
254 eecd &= ~E1000_EECD_REQ;
255 E1000_WRITE_REG(hw, E1000_EECD, eecd);
256 DEBUGOUT("Could not acquire NVM grant\n");
257 return -E1000_ERR_NVM;
260 return E1000_SUCCESS;
264 * e1000_standby_nvm - Return EEPROM to standby state
265 * @hw: pointer to the HW structure
267 * Return the EEPROM to a standby state.
269 STATIC void e1000_standby_nvm(struct e1000_hw *hw)
271 struct e1000_nvm_info *nvm = &hw->nvm;
272 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
274 DEBUGFUNC("e1000_standby_nvm");
276 if (nvm->type == e1000_nvm_eeprom_microwire) {
277 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
278 E1000_WRITE_REG(hw, E1000_EECD, eecd);
279 E1000_WRITE_FLUSH(hw);
280 usec_delay(nvm->delay_usec);
282 e1000_raise_eec_clk(hw, &eecd);
285 eecd |= E1000_EECD_CS;
286 E1000_WRITE_REG(hw, E1000_EECD, eecd);
287 E1000_WRITE_FLUSH(hw);
288 usec_delay(nvm->delay_usec);
290 e1000_lower_eec_clk(hw, &eecd);
291 } else if (nvm->type == e1000_nvm_eeprom_spi) {
292 /* Toggle CS to flush commands */
293 eecd |= E1000_EECD_CS;
294 E1000_WRITE_REG(hw, E1000_EECD, eecd);
295 E1000_WRITE_FLUSH(hw);
296 usec_delay(nvm->delay_usec);
297 eecd &= ~E1000_EECD_CS;
298 E1000_WRITE_REG(hw, E1000_EECD, eecd);
299 E1000_WRITE_FLUSH(hw);
300 usec_delay(nvm->delay_usec);
305 * e1000_stop_nvm - Terminate EEPROM command
306 * @hw: pointer to the HW structure
308 * Terminates the current command by inverting the EEPROM's chip select pin.
310 void e1000_stop_nvm(struct e1000_hw *hw)
314 DEBUGFUNC("e1000_stop_nvm");
316 eecd = E1000_READ_REG(hw, E1000_EECD);
317 if (hw->nvm.type == e1000_nvm_eeprom_spi) {
319 eecd |= E1000_EECD_CS;
320 e1000_lower_eec_clk(hw, &eecd);
321 } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
322 /* CS on Microwire is active-high */
323 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
324 E1000_WRITE_REG(hw, E1000_EECD, eecd);
325 e1000_raise_eec_clk(hw, &eecd);
326 e1000_lower_eec_clk(hw, &eecd);
331 * e1000_release_nvm_generic - Release exclusive access to EEPROM
332 * @hw: pointer to the HW structure
334 * Stop any current commands to the EEPROM and clear the EEPROM request bit.
336 void e1000_release_nvm_generic(struct e1000_hw *hw)
340 DEBUGFUNC("e1000_release_nvm_generic");
344 eecd = E1000_READ_REG(hw, E1000_EECD);
345 eecd &= ~E1000_EECD_REQ;
346 E1000_WRITE_REG(hw, E1000_EECD, eecd);
350 * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
351 * @hw: pointer to the HW structure
353 * Setups the EEPROM for reading and writing.
355 STATIC s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
357 struct e1000_nvm_info *nvm = &hw->nvm;
358 u32 eecd = E1000_READ_REG(hw, E1000_EECD);
361 DEBUGFUNC("e1000_ready_nvm_eeprom");
363 if (nvm->type == e1000_nvm_eeprom_microwire) {
364 /* Clear SK and DI */
365 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
366 E1000_WRITE_REG(hw, E1000_EECD, eecd);
368 eecd |= E1000_EECD_CS;
369 E1000_WRITE_REG(hw, E1000_EECD, eecd);
370 } else if (nvm->type == e1000_nvm_eeprom_spi) {
371 u16 timeout = NVM_MAX_RETRY_SPI;
373 /* Clear SK and CS */
374 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
375 E1000_WRITE_REG(hw, E1000_EECD, eecd);
376 E1000_WRITE_FLUSH(hw);
379 /* Read "Status Register" repeatedly until the LSB is cleared.
380 * The EEPROM will signal that the command has been completed
381 * by clearing bit 0 of the internal status register. If it's
382 * not cleared within 'timeout', then error out.
385 e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
386 hw->nvm.opcode_bits);
387 spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
388 if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
392 e1000_standby_nvm(hw);
397 DEBUGOUT("SPI NVM Status error\n");
398 return -E1000_ERR_NVM;
402 return E1000_SUCCESS;
406 * e1000_read_nvm_spi - Read EEPROM's using SPI
407 * @hw: pointer to the HW structure
408 * @offset: offset of word in the EEPROM to read
409 * @words: number of words to read
410 * @data: word read from the EEPROM
412 * Reads a 16 bit word from the EEPROM.
414 s32 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
416 struct e1000_nvm_info *nvm = &hw->nvm;
420 u8 read_opcode = NVM_READ_OPCODE_SPI;
422 DEBUGFUNC("e1000_read_nvm_spi");
424 /* A check for invalid values: offset too large, too many words,
425 * and not enough words.
427 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
429 DEBUGOUT("nvm parameter(s) out of bounds\n");
430 return -E1000_ERR_NVM;
433 ret_val = nvm->ops.acquire(hw);
437 ret_val = e1000_ready_nvm_eeprom(hw);
441 e1000_standby_nvm(hw);
443 if ((nvm->address_bits == 8) && (offset >= 128))
444 read_opcode |= NVM_A8_OPCODE_SPI;
446 /* Send the READ command (opcode + addr) */
447 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
448 e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
450 /* Read the data. SPI NVMs increment the address with each byte
451 * read and will roll over if reading beyond the end. This allows
452 * us to read the whole NVM from any offset
454 for (i = 0; i < words; i++) {
455 word_in = e1000_shift_in_eec_bits(hw, 16);
456 data[i] = (word_in >> 8) | (word_in << 8);
460 nvm->ops.release(hw);
466 * e1000_read_nvm_microwire - Reads EEPROM's using microwire
467 * @hw: pointer to the HW structure
468 * @offset: offset of word in the EEPROM to read
469 * @words: number of words to read
470 * @data: word read from the EEPROM
472 * Reads a 16 bit word from the EEPROM.
474 s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
477 struct e1000_nvm_info *nvm = &hw->nvm;
480 u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
482 DEBUGFUNC("e1000_read_nvm_microwire");
484 /* A check for invalid values: offset too large, too many words,
485 * and not enough words.
487 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
489 DEBUGOUT("nvm parameter(s) out of bounds\n");
490 return -E1000_ERR_NVM;
493 ret_val = nvm->ops.acquire(hw);
497 ret_val = e1000_ready_nvm_eeprom(hw);
501 for (i = 0; i < words; i++) {
502 /* Send the READ command (opcode + addr) */
503 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
504 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
507 /* Read the data. For microwire, each word requires the
508 * overhead of setup and tear-down.
510 data[i] = e1000_shift_in_eec_bits(hw, 16);
511 e1000_standby_nvm(hw);
515 nvm->ops.release(hw);
521 * e1000_read_nvm_eerd - Reads EEPROM using EERD register
522 * @hw: pointer to the HW structure
523 * @offset: offset of word in the EEPROM to read
524 * @words: number of words to read
525 * @data: word read from the EEPROM
527 * Reads a 16 bit word from the EEPROM using the EERD register.
529 s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
531 struct e1000_nvm_info *nvm = &hw->nvm;
533 s32 ret_val = E1000_SUCCESS;
535 DEBUGFUNC("e1000_read_nvm_eerd");
537 /* A check for invalid values: offset too large, too many words,
538 * too many words for the offset, and not enough words.
540 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
542 DEBUGOUT("nvm parameter(s) out of bounds\n");
543 return -E1000_ERR_NVM;
546 for (i = 0; i < words; i++) {
547 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
548 E1000_NVM_RW_REG_START;
550 E1000_WRITE_REG(hw, E1000_EERD, eerd);
551 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
555 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
556 E1000_NVM_RW_REG_DATA);
560 DEBUGOUT1("NVM read error: %d\n", ret_val);
566 * e1000_write_nvm_spi - Write to EEPROM using SPI
567 * @hw: pointer to the HW structure
568 * @offset: offset within the EEPROM to be written to
569 * @words: number of words to write
570 * @data: 16 bit word(s) to be written to the EEPROM
572 * Writes data to EEPROM at offset using SPI interface.
574 * If e1000_update_nvm_checksum is not called after this function , the
575 * EEPROM will most likely contain an invalid checksum.
577 s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
579 struct e1000_nvm_info *nvm = &hw->nvm;
580 s32 ret_val = -E1000_ERR_NVM;
583 DEBUGFUNC("e1000_write_nvm_spi");
585 /* A check for invalid values: offset too large, too many words,
586 * and not enough words.
588 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
590 DEBUGOUT("nvm parameter(s) out of bounds\n");
591 return -E1000_ERR_NVM;
594 while (widx < words) {
595 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
597 ret_val = nvm->ops.acquire(hw);
601 ret_val = e1000_ready_nvm_eeprom(hw);
603 nvm->ops.release(hw);
607 e1000_standby_nvm(hw);
609 /* Send the WRITE ENABLE command (8 bit opcode) */
610 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
613 e1000_standby_nvm(hw);
615 /* Some SPI eeproms use the 8th address bit embedded in the
618 if ((nvm->address_bits == 8) && (offset >= 128))
619 write_opcode |= NVM_A8_OPCODE_SPI;
621 /* Send the Write command (8-bit opcode + addr) */
622 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
623 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
626 /* Loop to allow for up to whole page write of eeprom */
627 while (widx < words) {
628 u16 word_out = data[widx];
629 word_out = (word_out >> 8) | (word_out << 8);
630 e1000_shift_out_eec_bits(hw, word_out, 16);
633 if ((((offset + widx) * 2) % nvm->page_size) == 0) {
634 e1000_standby_nvm(hw);
639 nvm->ops.release(hw);
646 * e1000_write_nvm_microwire - Writes EEPROM using microwire
647 * @hw: pointer to the HW structure
648 * @offset: offset within the EEPROM to be written to
649 * @words: number of words to write
650 * @data: 16 bit word(s) to be written to the EEPROM
652 * Writes data to EEPROM at offset using microwire interface.
654 * If e1000_update_nvm_checksum is not called after this function , the
655 * EEPROM will most likely contain an invalid checksum.
657 s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
660 struct e1000_nvm_info *nvm = &hw->nvm;
663 u16 words_written = 0;
666 DEBUGFUNC("e1000_write_nvm_microwire");
668 /* A check for invalid values: offset too large, too many words,
669 * and not enough words.
671 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
673 DEBUGOUT("nvm parameter(s) out of bounds\n");
674 return -E1000_ERR_NVM;
677 ret_val = nvm->ops.acquire(hw);
681 ret_val = e1000_ready_nvm_eeprom(hw);
685 e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
686 (u16)(nvm->opcode_bits + 2));
688 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
690 e1000_standby_nvm(hw);
692 while (words_written < words) {
693 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
696 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
699 e1000_shift_out_eec_bits(hw, data[words_written], 16);
701 e1000_standby_nvm(hw);
703 for (widx = 0; widx < 200; widx++) {
704 eecd = E1000_READ_REG(hw, E1000_EECD);
705 if (eecd & E1000_EECD_DO)
711 DEBUGOUT("NVM Write did not complete\n");
712 ret_val = -E1000_ERR_NVM;
716 e1000_standby_nvm(hw);
721 e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
722 (u16)(nvm->opcode_bits + 2));
724 e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
727 nvm->ops.release(hw);
733 * e1000_read_pba_string_generic - Read device part number
734 * @hw: pointer to the HW structure
735 * @pba_num: pointer to device part number
736 * @pba_num_size: size of part number buffer
738 * Reads the product board assembly (PBA) number from the EEPROM and stores
739 * the value in pba_num.
741 s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num,
750 DEBUGFUNC("e1000_read_pba_string_generic");
752 if ((hw->mac.type >= e1000_i210) &&
753 !e1000_get_flash_presence_i210(hw)) {
754 DEBUGOUT("Flashless no PBA string\n");
755 return -E1000_ERR_NVM_PBA_SECTION;
758 if (pba_num == NULL) {
759 DEBUGOUT("PBA string buffer was null\n");
760 return -E1000_ERR_INVALID_ARGUMENT;
763 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
765 DEBUGOUT("NVM Read Error\n");
769 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
771 DEBUGOUT("NVM Read Error\n");
775 /* if nvm_data is not ptr guard the PBA must be in legacy format which
776 * means pba_ptr is actually our second data word for the PBA number
777 * and we can decode it into an ascii string
779 if (nvm_data != NVM_PBA_PTR_GUARD) {
780 DEBUGOUT("NVM PBA number is not stored as string\n");
782 /* make sure callers buffer is big enough to store the PBA */
783 if (pba_num_size < E1000_PBANUM_LENGTH) {
784 DEBUGOUT("PBA string buffer too small\n");
785 return E1000_ERR_NO_SPACE;
788 /* extract hex string from data and pba_ptr */
789 pba_num[0] = (nvm_data >> 12) & 0xF;
790 pba_num[1] = (nvm_data >> 8) & 0xF;
791 pba_num[2] = (nvm_data >> 4) & 0xF;
792 pba_num[3] = nvm_data & 0xF;
793 pba_num[4] = (pba_ptr >> 12) & 0xF;
794 pba_num[5] = (pba_ptr >> 8) & 0xF;
797 pba_num[8] = (pba_ptr >> 4) & 0xF;
798 pba_num[9] = pba_ptr & 0xF;
800 /* put a null character on the end of our string */
803 /* switch all the data but the '-' to hex char */
804 for (offset = 0; offset < 10; offset++) {
805 if (pba_num[offset] < 0xA)
806 pba_num[offset] += '0';
807 else if (pba_num[offset] < 0x10)
808 pba_num[offset] += 'A' - 0xA;
811 return E1000_SUCCESS;
814 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
816 DEBUGOUT("NVM Read Error\n");
820 if (length == 0xFFFF || length == 0) {
821 DEBUGOUT("NVM PBA number section invalid length\n");
822 return -E1000_ERR_NVM_PBA_SECTION;
824 /* check if pba_num buffer is big enough */
825 if (pba_num_size < (((u32)length * 2) - 1)) {
826 DEBUGOUT("PBA string buffer too small\n");
827 return -E1000_ERR_NO_SPACE;
830 /* trim pba length from start of string */
834 for (offset = 0; offset < length; offset++) {
835 ret_val = hw->nvm.ops.read(hw, pba_ptr + offset, 1, &nvm_data);
837 DEBUGOUT("NVM Read Error\n");
840 pba_num[offset * 2] = (u8)(nvm_data >> 8);
841 pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF);
843 pba_num[offset * 2] = '\0';
845 return E1000_SUCCESS;
849 * e1000_read_pba_length_generic - Read device part number length
850 * @hw: pointer to the HW structure
851 * @pba_num_size: size of part number buffer
853 * Reads the product board assembly (PBA) number length from the EEPROM and
854 * stores the value in pba_num_size.
856 s32 e1000_read_pba_length_generic(struct e1000_hw *hw, u32 *pba_num_size)
863 DEBUGFUNC("e1000_read_pba_length_generic");
865 if (pba_num_size == NULL) {
866 DEBUGOUT("PBA buffer size was null\n");
867 return -E1000_ERR_INVALID_ARGUMENT;
870 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
872 DEBUGOUT("NVM Read Error\n");
876 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr);
878 DEBUGOUT("NVM Read Error\n");
882 /* if data is not ptr guard the PBA must be in legacy format */
883 if (nvm_data != NVM_PBA_PTR_GUARD) {
884 *pba_num_size = E1000_PBANUM_LENGTH;
885 return E1000_SUCCESS;
888 ret_val = hw->nvm.ops.read(hw, pba_ptr, 1, &length);
890 DEBUGOUT("NVM Read Error\n");
894 if (length == 0xFFFF || length == 0) {
895 DEBUGOUT("NVM PBA number section invalid length\n");
896 return -E1000_ERR_NVM_PBA_SECTION;
899 /* Convert from length in u16 values to u8 chars, add 1 for NULL,
900 * and subtract 2 because length field is included in length.
902 *pba_num_size = ((u32)length * 2) - 1;
904 return E1000_SUCCESS;
908 * e1000_read_pba_num_generic - Read device part number
909 * @hw: pointer to the HW structure
910 * @pba_num: pointer to device part number
912 * Reads the product board assembly (PBA) number from the EEPROM and stores
913 * the value in pba_num.
915 s32 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
920 DEBUGFUNC("e1000_read_pba_num_generic");
922 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
924 DEBUGOUT("NVM Read Error\n");
926 } else if (nvm_data == NVM_PBA_PTR_GUARD) {
927 DEBUGOUT("NVM Not Supported\n");
928 return -E1000_NOT_IMPLEMENTED;
930 *pba_num = (u32)(nvm_data << 16);
932 ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
934 DEBUGOUT("NVM Read Error\n");
937 *pba_num |= nvm_data;
939 return E1000_SUCCESS;
945 * @hw: pointer to the HW structure
946 * @eeprom_buf: optional pointer to EEPROM image
947 * @eeprom_buf_size: size of EEPROM image in words
948 * @max_pba_block_size: PBA block size limit
949 * @pba: pointer to output PBA structure
951 * Reads PBA from EEPROM image when eeprom_buf is not NULL.
952 * Reads PBA from physical EEPROM device when eeprom_buf is NULL.
955 s32 e1000_read_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
956 u32 eeprom_buf_size, u16 max_pba_block_size,
957 struct e1000_pba *pba)
963 return -E1000_ERR_PARAM;
965 if (eeprom_buf == NULL) {
966 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2,
971 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
972 pba->word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
973 pba->word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
975 return -E1000_ERR_PARAM;
979 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
980 if (pba->pba_block == NULL)
981 return -E1000_ERR_PARAM;
983 ret_val = e1000_get_pba_block_size(hw, eeprom_buf,
989 if (pba_block_size > max_pba_block_size)
990 return -E1000_ERR_PARAM;
992 if (eeprom_buf == NULL) {
993 ret_val = e1000_read_nvm(hw, pba->word[1],
999 if (eeprom_buf_size > (u32)(pba->word[1] +
1001 memcpy(pba->pba_block,
1002 &eeprom_buf[pba->word[1]],
1003 pba_block_size * sizeof(u16));
1005 return -E1000_ERR_PARAM;
1010 return E1000_SUCCESS;
1014 * e1000_write_pba_raw
1015 * @hw: pointer to the HW structure
1016 * @eeprom_buf: optional pointer to EEPROM image
1017 * @eeprom_buf_size: size of EEPROM image in words
1018 * @pba: pointer to PBA structure
1020 * Writes PBA to EEPROM image when eeprom_buf is not NULL.
1021 * Writes PBA to physical EEPROM device when eeprom_buf is NULL.
1024 s32 e1000_write_pba_raw(struct e1000_hw *hw, u16 *eeprom_buf,
1025 u32 eeprom_buf_size, struct e1000_pba *pba)
1030 return -E1000_ERR_PARAM;
1032 if (eeprom_buf == NULL) {
1033 ret_val = e1000_write_nvm(hw, NVM_PBA_OFFSET_0, 2,
1038 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1039 eeprom_buf[NVM_PBA_OFFSET_0] = pba->word[0];
1040 eeprom_buf[NVM_PBA_OFFSET_1] = pba->word[1];
1042 return -E1000_ERR_PARAM;
1046 if (pba->word[0] == NVM_PBA_PTR_GUARD) {
1047 if (pba->pba_block == NULL)
1048 return -E1000_ERR_PARAM;
1050 if (eeprom_buf == NULL) {
1051 ret_val = e1000_write_nvm(hw, pba->word[1],
1057 if (eeprom_buf_size > (u32)(pba->word[1] +
1058 pba->pba_block[0])) {
1059 memcpy(&eeprom_buf[pba->word[1]],
1061 pba->pba_block[0] * sizeof(u16));
1063 return -E1000_ERR_PARAM;
1068 return E1000_SUCCESS;
1072 * e1000_get_pba_block_size
1073 * @hw: pointer to the HW structure
1074 * @eeprom_buf: optional pointer to EEPROM image
1075 * @eeprom_buf_size: size of EEPROM image in words
1076 * @pba_data_size: pointer to output variable
1078 * Returns the size of the PBA block in words. Function operates on EEPROM
1079 * image if the eeprom_buf pointer is not NULL otherwise it accesses physical
1083 s32 e1000_get_pba_block_size(struct e1000_hw *hw, u16 *eeprom_buf,
1084 u32 eeprom_buf_size, u16 *pba_block_size)
1090 DEBUGFUNC("e1000_get_pba_block_size");
1092 if (eeprom_buf == NULL) {
1093 ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 2, &pba_word[0]);
1097 if (eeprom_buf_size > NVM_PBA_OFFSET_1) {
1098 pba_word[0] = eeprom_buf[NVM_PBA_OFFSET_0];
1099 pba_word[1] = eeprom_buf[NVM_PBA_OFFSET_1];
1101 return -E1000_ERR_PARAM;
1105 if (pba_word[0] == NVM_PBA_PTR_GUARD) {
1106 if (eeprom_buf == NULL) {
1107 ret_val = e1000_read_nvm(hw, pba_word[1] + 0, 1,
1112 if (eeprom_buf_size > pba_word[1])
1113 length = eeprom_buf[pba_word[1] + 0];
1115 return -E1000_ERR_PARAM;
1118 if (length == 0xFFFF || length == 0)
1119 return -E1000_ERR_NVM_PBA_SECTION;
1121 /* PBA number in legacy format, there is no PBA Block. */
1125 if (pba_block_size != NULL)
1126 *pba_block_size = length;
1128 return E1000_SUCCESS;
1132 * e1000_read_mac_addr_generic - Read device MAC address
1133 * @hw: pointer to the HW structure
1135 * Reads the device MAC address from the EEPROM and stores the value.
1136 * Since devices with two ports use the same EEPROM, we increment the
1137 * last bit in the MAC address for the second port.
1139 s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
1145 rar_high = E1000_READ_REG(hw, E1000_RAH(0));
1146 rar_low = E1000_READ_REG(hw, E1000_RAL(0));
1148 for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
1149 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
1151 for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
1152 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
1154 for (i = 0; i < ETH_ADDR_LEN; i++)
1155 hw->mac.addr[i] = hw->mac.perm_addr[i];
1157 return E1000_SUCCESS;
1161 * e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
1162 * @hw: pointer to the HW structure
1164 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
1165 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
1167 s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
1173 DEBUGFUNC("e1000_validate_nvm_checksum_generic");
1175 for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
1176 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1178 DEBUGOUT("NVM Read Error\n");
1181 checksum += nvm_data;
1184 if (checksum != (u16) NVM_SUM) {
1185 DEBUGOUT("NVM Checksum Invalid\n");
1186 return -E1000_ERR_NVM;
1189 return E1000_SUCCESS;
1193 * e1000_update_nvm_checksum_generic - Update EEPROM checksum
1194 * @hw: pointer to the HW structure
1196 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
1197 * up to the checksum. Then calculates the EEPROM checksum and writes the
1198 * value to the EEPROM.
1200 s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
1206 DEBUGFUNC("e1000_update_nvm_checksum");
1208 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
1209 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
1211 DEBUGOUT("NVM Read Error while updating checksum.\n");
1214 checksum += nvm_data;
1216 checksum = (u16) NVM_SUM - checksum;
1217 ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
1219 DEBUGOUT("NVM Write Error while updating checksum.\n");
1225 * e1000_reload_nvm_generic - Reloads EEPROM
1226 * @hw: pointer to the HW structure
1228 * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
1229 * extended control register.
1231 STATIC void e1000_reload_nvm_generic(struct e1000_hw *hw)
1235 DEBUGFUNC("e1000_reload_nvm_generic");
1238 ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
1239 ctrl_ext |= E1000_CTRL_EXT_EE_RST;
1240 E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
1241 E1000_WRITE_FLUSH(hw);
1245 * e1000_get_fw_version - Get firmware version information
1246 * @hw: pointer to the HW structure
1247 * @fw_vers: pointer to output version structure
1249 * unsupported/not present features return 0 in version structure
1251 void e1000_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers)
1253 u16 eeprom_verh, eeprom_verl, etrack_test, fw_version;
1254 u8 q, hval, rem, result;
1255 u16 comb_verh, comb_verl, comb_offset;
1257 memset(fw_vers, 0, sizeof(struct e1000_fw_version));
1259 /* basic eeprom version numbers, bits used vary by part and by tool
1260 * used to create the nvm images */
1261 /* Check which data format we have */
1262 switch (hw->mac.type) {
1264 e1000_read_invm_version(hw, fw_vers);
1270 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1271 /* Use this format, unless EETRACK ID exists,
1272 * then use alternate format
1274 if ((etrack_test & NVM_MAJOR_MASK) != NVM_ETRACK_VALID) {
1275 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1276 fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1278 fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK)
1280 fw_vers->eep_build = (fw_version & NVM_IMAGE_ID_MASK);
1285 if (!(e1000_get_flash_presence_i210(hw))) {
1286 e1000_read_invm_version(hw, fw_vers);
1291 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1292 /* find combo image version */
1293 hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset);
1294 if ((comb_offset != 0x0) &&
1295 (comb_offset != NVM_VER_INVALID)) {
1297 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset
1298 + 1), 1, &comb_verh);
1299 hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset),
1302 /* get Option Rom version if it exists and is valid */
1303 if ((comb_verh && comb_verl) &&
1304 ((comb_verh != NVM_VER_INVALID) &&
1305 (comb_verl != NVM_VER_INVALID))) {
1307 fw_vers->or_valid = true;
1309 comb_verl >> NVM_COMB_VER_SHFT;
1311 (comb_verl << NVM_COMB_VER_SHFT)
1312 | (comb_verh >> NVM_COMB_VER_SHFT);
1314 comb_verh & NVM_COMB_VER_MASK;
1319 hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test);
1322 hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version);
1323 fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK)
1326 /* check for old style version format in newer images*/
1327 if ((fw_version & NVM_NEW_DEC_MASK) == 0x0) {
1328 eeprom_verl = (fw_version & NVM_COMB_VER_MASK);
1330 eeprom_verl = (fw_version & NVM_MINOR_MASK)
1333 /* Convert minor value to hex before assigning to output struct
1334 * Val to be converted will not be higher than 99, per tool output
1336 q = eeprom_verl / NVM_HEX_CONV;
1337 hval = q * NVM_HEX_TENS;
1338 rem = eeprom_verl % NVM_HEX_CONV;
1339 result = hval + rem;
1340 fw_vers->eep_minor = result;
1343 if ((etrack_test & NVM_MAJOR_MASK) == NVM_ETRACK_VALID) {
1344 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl);
1345 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh);
1346 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT)
1348 } else if ((etrack_test & NVM_ETRACK_VALID) == 0) {
1349 hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verh);
1350 hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verl);
1351 fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) |