/**
* igc_reload_nvm_generic - Reloads EEPROM
* @hw: pointer to the HW structure
*
* Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
* extended control register.
**/
void
igc_reload_nvm_generic(struct igc_hw *hw)
{
uint32_t ctrl_ext;
/**
* igc_poll_eerd_eewr_done - Poll for EEPROM read/write completion
* @hw: pointer to the HW structure
* @ee_reg: EEPROM flag for polling
*
* Polls the EEPROM status bit for either read or write completion based
* upon the value of 'ee_reg'.
**/
int
igc_poll_eerd_eewr_done(struct igc_hw *hw, int ee_reg)
{
uint32_t attempts = 100000;
uint32_t i, reg = 0;
DEBUGFUNC("igc_poll_eerd_eewr_done");
for (i = 0; i < attempts; i++) {
if (ee_reg == IGC_NVM_POLL_READ)
reg = IGC_READ_REG(hw, IGC_EERD);
else
reg = IGC_READ_REG(hw, IGC_EEWR);
if (reg & IGC_NVM_RW_REG_DONE)
return IGC_SUCCESS;
DELAY(5);
}
return -IGC_ERR_NVM;
}
/**
* igc_read_nvm_eerd - Reads EEPROM using EERD register
* @hw: pointer to the HW structure
* @offset: offset of word in the EEPROM to read
* @words: number of words to read
* @data: word read from the EEPROM
*
* Reads a 16 bit word from the EEPROM using the EERD register.
**/
int
igc_read_nvm_eerd(struct igc_hw *hw, uint16_t offset, uint16_t words,
uint16_t *data)
{
struct igc_nvm_info *nvm = &hw->nvm;
uint32_t i, eerd = 0;
int ret_val = IGC_SUCCESS;
DEBUGFUNC("igc_read_nvm_eerd");
/* A check for invalid values: offset too large, too many words,
* too many words for the offset, and not enough words.
*/
if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
(words == 0)) {
DEBUGOUT("nvm parameter(s) out of bounds\n");
return -IGC_ERR_NVM;
}
for (i = 0; i < words; i++) {
eerd = ((offset + i) << IGC_NVM_RW_ADDR_SHIFT) +
IGC_NVM_RW_REG_START;
IGC_WRITE_REG(hw, IGC_EERD, eerd);
ret_val = igc_poll_eerd_eewr_done(hw, IGC_NVM_POLL_READ);
if (ret_val)
break;
if (ret_val)
DEBUGOUT1("NVM read error: %d\n", ret_val);
return ret_val;
}
/**
* igc_read_mac_addr_generic - Read device MAC address
* @hw: pointer to the HW structure
*
* Reads the device MAC address from the EEPROM and stores the value.
* Since devices with two ports use the same EEPROM, we increment the
* last bit in the MAC address for the second port.
**/
int
igc_read_mac_addr_generic(struct igc_hw *hw)
{
uint32_t rar_high, rar_low;
uint16_t i;
for (i = 0; i < IGC_RAL_MAC_ADDR_LEN; i++)
hw->mac.perm_addr[i] = (uint8_t)(rar_low >> (i * 8));
for (i = 0; i < IGC_RAH_MAC_ADDR_LEN; i++)
hw->mac.perm_addr[i+4] = (uint8_t)(rar_high >> (i * 8));
for (i = 0; i < ETHER_ADDR_LEN; i++)
hw->mac.addr[i] = hw->mac.perm_addr[i];
return IGC_SUCCESS;
}
/**
* igc_validate_nvm_checksum_generic - Validate EEPROM checksum
* @hw: pointer to the HW structure
*
* Calculates the EEPROM checksum by reading/adding each word of the EEPROM
* and then verifies that the sum of the EEPROM is equal to 0xBABA.
**/
int
igc_validate_nvm_checksum_generic(struct igc_hw *hw)
{
uint16_t checksum = 0;
uint16_t i, nvm_data;
int ret_val;
DEBUGFUNC("igc_validate_nvm_checksum_generic");
for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
if (ret_val) {
DEBUGOUT("NVM Read Error\n");
return ret_val;
}
checksum += nvm_data;
}