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 ******************************************************************************/
35 #include "e1000_api.h"
38 static s32 e1000_acquire_nvm_i210(struct e1000_hw *hw);
39 static void e1000_release_nvm_i210(struct e1000_hw *hw);
40 static s32 e1000_get_hw_semaphore_i210(struct e1000_hw *hw);
41 static void e1000_put_hw_semaphore_i210(struct e1000_hw *hw);
42 static s32 e1000_write_nvm_srwr(struct e1000_hw *hw, u16 offset, u16 words,
44 static s32 e1000_pool_flash_update_done_i210(struct e1000_hw *hw);
45 static s32 e1000_valid_led_default_i210(struct e1000_hw *hw, u16 *data);
46 static s32 e1000_read_nvm_i211(struct e1000_hw *hw, u16 offset, u16 words,
50 * e1000_acquire_nvm_i210 - Request for access to EEPROM
51 * @hw: pointer to the HW structure
53 * Acquire the necessary semaphores for exclusive access to the EEPROM.
54 * Set the EEPROM access request bit and wait for EEPROM access grant bit.
55 * Return successful if access grant bit set, else clear the request for
56 * EEPROM access and return -E1000_ERR_NVM (-1).
58 static s32 e1000_acquire_nvm_i210(struct e1000_hw *hw)
62 DEBUGFUNC("e1000_acquire_nvm_i210");
64 ret_val = e1000_acquire_swfw_sync_i210(hw, E1000_SWFW_EEP_SM);
70 * e1000_release_nvm_i210 - Release exclusive access to EEPROM
71 * @hw: pointer to the HW structure
73 * Stop any current commands to the EEPROM and clear the EEPROM request bit,
74 * then release the semaphores acquired.
76 static void e1000_release_nvm_i210(struct e1000_hw *hw)
78 DEBUGFUNC("e1000_release_nvm_i210");
80 e1000_release_swfw_sync_i210(hw, E1000_SWFW_EEP_SM);
84 * e1000_acquire_swfw_sync_i210 - Acquire SW/FW semaphore
85 * @hw: pointer to the HW structure
86 * @mask: specifies which semaphore to acquire
88 * Acquire the SW/FW semaphore to access the PHY or NVM. The mask
89 * will also specify which port we're acquiring the lock for.
91 s32 e1000_acquire_swfw_sync_i210(struct e1000_hw *hw, u16 mask)
95 u32 fwmask = mask << 16;
96 s32 ret_val = E1000_SUCCESS;
97 s32 i = 0, timeout = 200; /* FIXME: find real value to use here */
99 DEBUGFUNC("e1000_acquire_swfw_sync_i210");
101 while (i < timeout) {
102 if (e1000_get_hw_semaphore_i210(hw)) {
103 ret_val = -E1000_ERR_SWFW_SYNC;
107 swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
108 if (!(swfw_sync & fwmask))
112 * Firmware currently using resource (fwmask)
114 e1000_put_hw_semaphore_i210(hw);
120 DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
121 ret_val = -E1000_ERR_SWFW_SYNC;
126 E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
128 e1000_put_hw_semaphore_i210(hw);
135 * e1000_release_swfw_sync_i210 - Release SW/FW semaphore
136 * @hw: pointer to the HW structure
137 * @mask: specifies which semaphore to acquire
139 * Release the SW/FW semaphore used to access the PHY or NVM. The mask
140 * will also specify which port we're releasing the lock for.
142 void e1000_release_swfw_sync_i210(struct e1000_hw *hw, u16 mask)
146 DEBUGFUNC("e1000_release_swfw_sync_i210");
148 while (e1000_get_hw_semaphore_i210(hw) != E1000_SUCCESS)
151 swfw_sync = E1000_READ_REG(hw, E1000_SW_FW_SYNC);
153 E1000_WRITE_REG(hw, E1000_SW_FW_SYNC, swfw_sync);
155 e1000_put_hw_semaphore_i210(hw);
159 * e1000_get_hw_semaphore_i210 - Acquire hardware semaphore
160 * @hw: pointer to the HW structure
162 * Acquire the HW semaphore to access the PHY or NVM
164 static s32 e1000_get_hw_semaphore_i210(struct e1000_hw *hw)
167 s32 ret_val = E1000_SUCCESS;
168 s32 timeout = hw->nvm.word_size + 1;
171 DEBUGFUNC("e1000_get_hw_semaphore_i210");
173 /* Get the FW semaphore. */
174 for (i = 0; i < timeout; i++) {
175 swsm = E1000_READ_REG(hw, E1000_SWSM);
176 E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
178 /* Semaphore acquired if bit latched */
179 if (E1000_READ_REG(hw, E1000_SWSM) & E1000_SWSM_SWESMBI)
186 /* Release semaphores */
187 e1000_put_hw_semaphore_generic(hw);
188 DEBUGOUT("Driver can't access the NVM\n");
189 ret_val = -E1000_ERR_NVM;
198 * e1000_put_hw_semaphore_i210 - Release hardware semaphore
199 * @hw: pointer to the HW structure
201 * Release hardware semaphore used to access the PHY or NVM
203 static void e1000_put_hw_semaphore_i210(struct e1000_hw *hw)
207 DEBUGFUNC("e1000_put_hw_semaphore_i210");
209 swsm = E1000_READ_REG(hw, E1000_SWSM);
211 swsm &= ~E1000_SWSM_SWESMBI;
213 E1000_WRITE_REG(hw, E1000_SWSM, swsm);
217 * e1000_read_nvm_srrd_i210 - Reads Shadow Ram using EERD register
218 * @hw: pointer to the HW structure
219 * @offset: offset of word in the Shadow Ram to read
220 * @words: number of words to read
221 * @data: word read from the Shadow Ram
223 * Reads a 16 bit word from the Shadow Ram using the EERD register.
224 * Uses necessary synchronization semaphores.
226 s32 e1000_read_nvm_srrd_i210(struct e1000_hw *hw, u16 offset, u16 words,
229 s32 status = E1000_SUCCESS;
232 DEBUGFUNC("e1000_read_nvm_srrd_i210");
234 /* We cannot hold synchronization semaphores for too long,
235 * because of forceful takeover procedure. However it is more efficient
236 * to read in bursts than synchronizing access for each word. */
237 for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
238 count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
239 E1000_EERD_EEWR_MAX_COUNT : (words - i);
240 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
241 status = e1000_read_nvm_eerd(hw, offset, count,
243 hw->nvm.ops.release(hw);
245 status = E1000_ERR_SWFW_SYNC;
248 if (status != E1000_SUCCESS)
256 * e1000_write_nvm_srwr_i210 - Write to Shadow RAM using EEWR
257 * @hw: pointer to the HW structure
258 * @offset: offset within the Shadow RAM to be written to
259 * @words: number of words to write
260 * @data: 16 bit word(s) to be written to the Shadow RAM
262 * Writes data to Shadow RAM at offset using EEWR register.
264 * If e1000_update_nvm_checksum is not called after this function , the
265 * data will not be committed to FLASH and also Shadow RAM will most likely
266 * contain an invalid checksum.
268 * If error code is returned, data and Shadow RAM may be inconsistent - buffer
271 s32 e1000_write_nvm_srwr_i210(struct e1000_hw *hw, u16 offset, u16 words,
274 s32 status = E1000_SUCCESS;
277 DEBUGFUNC("e1000_write_nvm_srwr_i210");
279 /* We cannot hold synchronization semaphores for too long,
280 * because of forceful takeover procedure. However it is more efficient
281 * to write in bursts than synchronizing access for each word. */
282 for (i = 0; i < words; i += E1000_EERD_EEWR_MAX_COUNT) {
283 count = (words - i) / E1000_EERD_EEWR_MAX_COUNT > 0 ?
284 E1000_EERD_EEWR_MAX_COUNT : (words - i);
285 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
286 status = e1000_write_nvm_srwr(hw, offset, count,
288 hw->nvm.ops.release(hw);
290 status = E1000_ERR_SWFW_SYNC;
293 if (status != E1000_SUCCESS)
301 * e1000_write_nvm_srwr - Write to Shadow Ram using EEWR
302 * @hw: pointer to the HW structure
303 * @offset: offset within the Shadow Ram to be written to
304 * @words: number of words to write
305 * @data: 16 bit word(s) to be written to the Shadow Ram
307 * Writes data to Shadow Ram at offset using EEWR register.
309 * If e1000_update_nvm_checksum is not called after this function , the
310 * Shadow Ram will most likely contain an invalid checksum.
312 static s32 e1000_write_nvm_srwr(struct e1000_hw *hw, u16 offset, u16 words,
315 struct e1000_nvm_info *nvm = &hw->nvm;
317 u32 attempts = 100000;
318 s32 ret_val = E1000_SUCCESS;
320 DEBUGFUNC("e1000_write_nvm_srwr");
323 * A check for invalid values: offset too large, too many words,
324 * too many words for the offset, and not enough words.
326 if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
328 DEBUGOUT("nvm parameter(s) out of bounds\n");
329 ret_val = -E1000_ERR_NVM;
333 for (i = 0; i < words; i++) {
334 eewr = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) |
335 (data[i] << E1000_NVM_RW_REG_DATA) |
336 E1000_NVM_RW_REG_START;
338 E1000_WRITE_REG(hw, E1000_SRWR, eewr);
340 for (k = 0; k < attempts; k++) {
341 if (E1000_NVM_RW_REG_DONE &
342 E1000_READ_REG(hw, E1000_SRWR)) {
343 ret_val = E1000_SUCCESS;
349 if (ret_val != E1000_SUCCESS) {
350 DEBUGOUT("Shadow RAM write EEWR timed out\n");
360 * e1000_read_nvm_i211 - Read NVM wrapper function for I211
361 * @hw: pointer to the HW structure
362 * @address: the word address (aka eeprom offset) to read
363 * @data: pointer to the data read
365 * Wrapper function to return data formerly found in the NVM.
367 static s32 e1000_read_nvm_i211(struct e1000_hw *hw, u16 offset, u16 words,
370 s32 ret_val = E1000_SUCCESS;
372 DEBUGFUNC("e1000_read_nvm_i211");
374 /* Only the MAC addr is required to be present in the iNVM */
377 ret_val = e1000_read_invm_i211(hw, (u8)offset, &data[0]);
378 ret_val |= e1000_read_invm_i211(hw, (u8)offset+1, &data[1]);
379 ret_val |= e1000_read_invm_i211(hw, (u8)offset+2, &data[2]);
380 if (ret_val != E1000_SUCCESS)
381 DEBUGOUT("MAC Addr not found in iNVM\n");
383 case NVM_ID_LED_SETTINGS:
384 case NVM_INIT_CTRL_2:
385 case NVM_INIT_CTRL_4:
387 case NVM_LED_0_2_CFG:
388 e1000_read_invm_i211(hw, (u8)offset, data);
391 *data = ID_LED_DEFAULT_I210;
394 *data = hw->subsystem_device_id;
397 *data = hw->subsystem_vendor_id;
400 *data = hw->device_id;
403 *data = hw->vendor_id;
406 DEBUGOUT1("NVM word 0x%02x is not mapped.\n", offset);
407 *data = NVM_RESERVED_WORD;
414 * e1000_read_invm_i211 - Reads OTP
415 * @hw: pointer to the HW structure
416 * @address: the word address (aka eeprom offset) to read
417 * @data: pointer to the data read
419 * Reads 16-bit words from the OTP. Return error when the word is not
422 s32 e1000_read_invm_i211(struct e1000_hw *hw, u8 address, u16 *data)
424 s32 status = -E1000_ERR_INVM_VALUE_NOT_FOUND;
427 u8 record_type, word_address;
429 DEBUGFUNC("e1000_read_invm_i211");
431 for (i = 0; i < E1000_INVM_SIZE; i++) {
432 invm_dword = E1000_READ_REG(hw, E1000_INVM_DATA_REG(i));
433 /* Get record type */
434 record_type = INVM_DWORD_TO_RECORD_TYPE(invm_dword);
435 if (record_type == E1000_INVM_UNINITIALIZED_STRUCTURE)
437 if (record_type == E1000_INVM_CSR_AUTOLOAD_STRUCTURE)
438 i += E1000_INVM_CSR_AUTOLOAD_DATA_SIZE_IN_DWORDS;
439 if (record_type == E1000_INVM_RSA_KEY_SHA256_STRUCTURE)
440 i += E1000_INVM_RSA_KEY_SHA256_DATA_SIZE_IN_DWORDS;
441 if (record_type == E1000_INVM_WORD_AUTOLOAD_STRUCTURE) {
442 word_address = INVM_DWORD_TO_WORD_ADDRESS(invm_dword);
443 if (word_address == address) {
444 *data = INVM_DWORD_TO_WORD_DATA(invm_dword);
445 DEBUGOUT2("Read INVM Word 0x%02x = %x",
447 status = E1000_SUCCESS;
452 if (status != E1000_SUCCESS)
453 DEBUGOUT1("Requested word 0x%02x not found in OTP\n", address);
458 * e1000_validate_nvm_checksum_i210 - Validate EEPROM checksum
459 * @hw: pointer to the HW structure
461 * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
462 * and then verifies that the sum of the EEPROM is equal to 0xBABA.
464 s32 e1000_validate_nvm_checksum_i210(struct e1000_hw *hw)
466 s32 status = E1000_SUCCESS;
467 s32 (*read_op_ptr)(struct e1000_hw *, u16, u16, u16 *);
469 DEBUGFUNC("e1000_validate_nvm_checksum_i210");
471 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
474 * Replace the read function with semaphore grabbing with
475 * the one that skips this for a while.
476 * We have semaphore taken already here.
478 read_op_ptr = hw->nvm.ops.read;
479 hw->nvm.ops.read = e1000_read_nvm_eerd;
481 status = e1000_validate_nvm_checksum_generic(hw);
483 /* Revert original read operation. */
484 hw->nvm.ops.read = read_op_ptr;
486 hw->nvm.ops.release(hw);
488 status = E1000_ERR_SWFW_SYNC;
496 * e1000_update_nvm_checksum_i210 - Update EEPROM checksum
497 * @hw: pointer to the HW structure
499 * Updates the EEPROM checksum by reading/adding each word of the EEPROM
500 * up to the checksum. Then calculates the EEPROM checksum and writes the
501 * value to the EEPROM. Next commit EEPROM data onto the Flash.
503 s32 e1000_update_nvm_checksum_i210(struct e1000_hw *hw)
505 s32 ret_val = E1000_SUCCESS;
509 DEBUGFUNC("e1000_update_nvm_checksum_i210");
512 * Read the first word from the EEPROM. If this times out or fails, do
513 * not continue or we could be in for a very long wait while every
516 ret_val = e1000_read_nvm_eerd(hw, 0, 1, &nvm_data);
517 if (ret_val != E1000_SUCCESS) {
518 DEBUGOUT("EEPROM read failed\n");
522 if (hw->nvm.ops.acquire(hw) == E1000_SUCCESS) {
524 * Do not use hw->nvm.ops.write, hw->nvm.ops.read
525 * because we do not want to take the synchronization
526 * semaphores twice here.
529 for (i = 0; i < NVM_CHECKSUM_REG; i++) {
530 ret_val = e1000_read_nvm_eerd(hw, i, 1, &nvm_data);
532 hw->nvm.ops.release(hw);
533 DEBUGOUT("NVM Read Error while updating checksum.\n");
536 checksum += nvm_data;
538 checksum = (u16) NVM_SUM - checksum;
539 ret_val = e1000_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
541 if (ret_val != E1000_SUCCESS) {
542 hw->nvm.ops.release(hw);
543 DEBUGOUT("NVM Write Error while updating checksum.\n");
547 hw->nvm.ops.release(hw);
549 ret_val = e1000_update_flash_i210(hw);
551 ret_val = E1000_ERR_SWFW_SYNC;
558 * e1000_get_flash_presence_i210 - Check if flash device is detected.
559 * @hw: pointer to the HW structure
562 static bool e1000_get_flash_presence_i210(struct e1000_hw *hw)
565 bool ret_val = FALSE;
567 DEBUGFUNC("e1000_get_flash_presence_i210");
569 eec = E1000_READ_REG(hw, E1000_EECD);
571 if (eec & E1000_EECD_FLASH_DETECTED_I210)
578 * e1000_update_flash_i210 - Commit EEPROM to the flash
579 * @hw: pointer to the HW structure
582 s32 e1000_update_flash_i210(struct e1000_hw *hw)
584 s32 ret_val = E1000_SUCCESS;
587 DEBUGFUNC("e1000_update_flash_i210");
589 ret_val = e1000_pool_flash_update_done_i210(hw);
590 if (ret_val == -E1000_ERR_NVM) {
591 DEBUGOUT("Flash update time out\n");
595 flup = E1000_READ_REG(hw, E1000_EECD) | E1000_EECD_FLUPD_I210;
596 E1000_WRITE_REG(hw, E1000_EECD, flup);
598 ret_val = e1000_pool_flash_update_done_i210(hw);
599 if (ret_val == E1000_SUCCESS)
600 DEBUGOUT("Flash update complete\n");
602 DEBUGOUT("Flash update time out\n");
609 * e1000_pool_flash_update_done_i210 - Pool FLUDONE status.
610 * @hw: pointer to the HW structure
613 s32 e1000_pool_flash_update_done_i210(struct e1000_hw *hw)
615 s32 ret_val = -E1000_ERR_NVM;
618 DEBUGFUNC("e1000_pool_flash_update_done_i210");
620 for (i = 0; i < E1000_FLUDONE_ATTEMPTS; i++) {
621 reg = E1000_READ_REG(hw, E1000_EECD);
622 if (reg & E1000_EECD_FLUDONE_I210) {
623 ret_val = E1000_SUCCESS;
633 * e1000_init_nvm_params_i210 - Initialize i210 NVM function pointers
634 * @hw: pointer to the HW structure
636 * Initialize the i210 NVM parameters and function pointers.
638 static s32 e1000_init_nvm_params_i210(struct e1000_hw *hw)
640 s32 ret_val = E1000_SUCCESS;
641 struct e1000_nvm_info *nvm = &hw->nvm;
643 DEBUGFUNC("e1000_init_nvm_params_i210");
645 ret_val = e1000_init_nvm_params_82575(hw);
647 nvm->ops.acquire = e1000_acquire_nvm_i210;
648 nvm->ops.release = e1000_release_nvm_i210;
649 nvm->ops.read = e1000_read_nvm_srrd_i210;
650 nvm->ops.write = e1000_write_nvm_srwr_i210;
651 nvm->ops.valid_led_default = e1000_valid_led_default_i210;
652 nvm->ops.validate = e1000_validate_nvm_checksum_i210;
653 nvm->ops.update = e1000_update_nvm_checksum_i210;
659 * e1000_init_nvm_params_i211 - Initialize i211 NVM function pointers
660 * @hw: pointer to the HW structure
662 * Initialize the NVM parameters and function pointers for i211.
664 static s32 e1000_init_nvm_params_i211(struct e1000_hw *hw)
666 struct e1000_nvm_info *nvm = &hw->nvm;
668 DEBUGFUNC("e1000_init_nvm_params_i211");
670 nvm->ops.acquire = e1000_acquire_nvm_i210;
671 nvm->ops.release = e1000_release_nvm_i210;
672 nvm->ops.read = e1000_read_nvm_i211;
673 nvm->ops.valid_led_default = e1000_valid_led_default_i210;
674 nvm->ops.write = e1000_null_write_nvm;
675 nvm->ops.validate = e1000_null_ops_generic;
676 nvm->ops.update = e1000_null_ops_generic;
678 return E1000_SUCCESS;
682 * e1000_init_function_pointers_i210 - Init func ptrs.
683 * @hw: pointer to the HW structure
685 * Called to initialize all function pointers and parameters.
687 void e1000_init_function_pointers_i210(struct e1000_hw *hw)
689 e1000_init_function_pointers_82575(hw);
691 switch (hw->mac.type) {
693 if (e1000_get_flash_presence_i210(hw))
694 hw->nvm.ops.init_params = e1000_init_nvm_params_i210;
696 hw->nvm.ops.init_params = e1000_init_nvm_params_i211;
699 hw->nvm.ops.init_params = e1000_init_nvm_params_i211;
708 * e1000_valid_led_default_i210 - Verify a valid default LED config
709 * @hw: pointer to the HW structure
710 * @data: pointer to the NVM (EEPROM)
712 * Read the EEPROM for the current default LED configuration. If the
713 * LED configuration is not valid, set to a valid LED configuration.
715 static s32 e1000_valid_led_default_i210(struct e1000_hw *hw, u16 *data)
719 DEBUGFUNC("e1000_valid_led_default_i210");
721 ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
723 DEBUGOUT("NVM Read Error\n");
727 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) {
728 switch (hw->phy.media_type) {
729 case e1000_media_type_internal_serdes:
730 *data = ID_LED_DEFAULT_I210_SERDES;
732 case e1000_media_type_copper:
734 *data = ID_LED_DEFAULT_I210;