fp@2584: /******************************************************************************* fp@2584: fp@2584: Intel PRO/1000 Linux driver fp@2584: Copyright(c) 1999 - 2012 Intel Corporation. fp@2584: fp@2584: This program is free software; you can redistribute it and/or modify it fp@2584: under the terms and conditions of the GNU General Public License, fp@2584: version 2, as published by the Free Software Foundation. fp@2584: fp@2584: This program is distributed in the hope it will be useful, but WITHOUT fp@2584: ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or fp@2584: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for fp@2584: more details. fp@2584: fp@2584: You should have received a copy of the GNU General Public License along with fp@2584: this program; if not, write to the Free Software Foundation, Inc., fp@2584: 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. fp@2584: fp@2584: The full GNU General Public License is included in this distribution in fp@2584: the file called "COPYING". fp@2584: fp@2584: Contact Information: fp@2584: Linux NICS fp@2584: e1000-devel Mailing List fp@2584: Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 fp@2584: fp@2584: *******************************************************************************/ fp@2584: fp@2584: #include "e1000-3.8-ethercat.h" fp@2584: fp@2584: /** fp@2584: * e1000_raise_eec_clk - Raise EEPROM clock fp@2584: * @hw: pointer to the HW structure fp@2584: * @eecd: pointer to the EEPROM fp@2584: * fp@2584: * Enable/Raise the EEPROM clock bit. fp@2584: **/ fp@2584: static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd) fp@2584: { fp@2584: *eecd = *eecd | E1000_EECD_SK; fp@2584: ew32(EECD, *eecd); fp@2584: e1e_flush(); fp@2584: udelay(hw->nvm.delay_usec); fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_lower_eec_clk - Lower EEPROM clock fp@2584: * @hw: pointer to the HW structure fp@2584: * @eecd: pointer to the EEPROM fp@2584: * fp@2584: * Clear/Lower the EEPROM clock bit. fp@2584: **/ fp@2584: static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd) fp@2584: { fp@2584: *eecd = *eecd & ~E1000_EECD_SK; fp@2584: ew32(EECD, *eecd); fp@2584: e1e_flush(); fp@2584: udelay(hw->nvm.delay_usec); fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM fp@2584: * @hw: pointer to the HW structure fp@2584: * @data: data to send to the EEPROM fp@2584: * @count: number of bits to shift out fp@2584: * fp@2584: * We need to shift 'count' bits out to the EEPROM. So, the value in the fp@2584: * "data" parameter will be shifted out to the EEPROM one bit at a time. fp@2584: * In order to do this, "data" must be broken down into bits. fp@2584: **/ fp@2584: static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count) fp@2584: { fp@2584: struct e1000_nvm_info *nvm = &hw->nvm; fp@2584: u32 eecd = er32(EECD); fp@2584: u32 mask; fp@2584: fp@2584: mask = 0x01 << (count - 1); fp@2584: if (nvm->type == e1000_nvm_eeprom_spi) fp@2584: eecd |= E1000_EECD_DO; fp@2584: fp@2584: do { fp@2584: eecd &= ~E1000_EECD_DI; fp@2584: fp@2584: if (data & mask) fp@2584: eecd |= E1000_EECD_DI; fp@2584: fp@2584: ew32(EECD, eecd); fp@2584: e1e_flush(); fp@2584: fp@2584: udelay(nvm->delay_usec); fp@2584: fp@2584: e1000_raise_eec_clk(hw, &eecd); fp@2584: e1000_lower_eec_clk(hw, &eecd); fp@2584: fp@2584: mask >>= 1; fp@2584: } while (mask); fp@2584: fp@2584: eecd &= ~E1000_EECD_DI; fp@2584: ew32(EECD, eecd); fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM fp@2584: * @hw: pointer to the HW structure fp@2584: * @count: number of bits to shift in fp@2584: * fp@2584: * In order to read a register from the EEPROM, we need to shift 'count' bits fp@2584: * in from the EEPROM. Bits are "shifted in" by raising the clock input to fp@2584: * the EEPROM (setting the SK bit), and then reading the value of the data out fp@2584: * "DO" bit. During this "shifting in" process the data in "DI" bit should fp@2584: * always be clear. fp@2584: **/ fp@2584: static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count) fp@2584: { fp@2584: u32 eecd; fp@2584: u32 i; fp@2584: u16 data; fp@2584: fp@2584: eecd = er32(EECD); fp@2584: fp@2584: eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); fp@2584: data = 0; fp@2584: fp@2584: for (i = 0; i < count; i++) { fp@2584: data <<= 1; fp@2584: e1000_raise_eec_clk(hw, &eecd); fp@2584: fp@2584: eecd = er32(EECD); fp@2584: fp@2584: eecd &= ~E1000_EECD_DI; fp@2584: if (eecd & E1000_EECD_DO) fp@2584: data |= 1; fp@2584: fp@2584: e1000_lower_eec_clk(hw, &eecd); fp@2584: } fp@2584: fp@2584: return data; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion fp@2584: * @hw: pointer to the HW structure fp@2584: * @ee_reg: EEPROM flag for polling fp@2584: * fp@2584: * Polls the EEPROM status bit for either read or write completion based fp@2584: * upon the value of 'ee_reg'. fp@2584: **/ fp@2584: s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg) fp@2584: { fp@2584: u32 attempts = 100000; fp@2584: u32 i, reg = 0; fp@2584: fp@2584: for (i = 0; i < attempts; i++) { fp@2584: if (ee_reg == E1000_NVM_POLL_READ) fp@2584: reg = er32(EERD); fp@2584: else fp@2584: reg = er32(EEWR); fp@2584: fp@2584: if (reg & E1000_NVM_RW_REG_DONE) fp@2584: return 0; fp@2584: fp@2584: udelay(5); fp@2584: } fp@2584: fp@2584: return -E1000_ERR_NVM; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_acquire_nvm - Generic request for access to EEPROM fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Set the EEPROM access request bit and wait for EEPROM access grant bit. fp@2584: * Return successful if access grant bit set, else clear the request for fp@2584: * EEPROM access and return -E1000_ERR_NVM (-1). fp@2584: **/ fp@2584: s32 e1000e_acquire_nvm(struct e1000_hw *hw) fp@2584: { fp@2584: u32 eecd = er32(EECD); fp@2584: s32 timeout = E1000_NVM_GRANT_ATTEMPTS; fp@2584: fp@2584: ew32(EECD, eecd | E1000_EECD_REQ); fp@2584: eecd = er32(EECD); fp@2584: fp@2584: while (timeout) { fp@2584: if (eecd & E1000_EECD_GNT) fp@2584: break; fp@2584: udelay(5); fp@2584: eecd = er32(EECD); fp@2584: timeout--; fp@2584: } fp@2584: fp@2584: if (!timeout) { fp@2584: eecd &= ~E1000_EECD_REQ; fp@2584: ew32(EECD, eecd); fp@2584: e_dbg("Could not acquire NVM grant\n"); fp@2584: return -E1000_ERR_NVM; fp@2584: } fp@2584: fp@2584: return 0; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_standby_nvm - Return EEPROM to standby state fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Return the EEPROM to a standby state. fp@2584: **/ fp@2584: static void e1000_standby_nvm(struct e1000_hw *hw) fp@2584: { fp@2584: struct e1000_nvm_info *nvm = &hw->nvm; fp@2584: u32 eecd = er32(EECD); fp@2584: fp@2584: if (nvm->type == e1000_nvm_eeprom_spi) { fp@2584: /* Toggle CS to flush commands */ fp@2584: eecd |= E1000_EECD_CS; fp@2584: ew32(EECD, eecd); fp@2584: e1e_flush(); fp@2584: udelay(nvm->delay_usec); fp@2584: eecd &= ~E1000_EECD_CS; fp@2584: ew32(EECD, eecd); fp@2584: e1e_flush(); fp@2584: udelay(nvm->delay_usec); fp@2584: } fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_stop_nvm - Terminate EEPROM command fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Terminates the current command by inverting the EEPROM's chip select pin. fp@2584: **/ fp@2584: static void e1000_stop_nvm(struct e1000_hw *hw) fp@2584: { fp@2584: u32 eecd; fp@2584: fp@2584: eecd = er32(EECD); fp@2584: if (hw->nvm.type == e1000_nvm_eeprom_spi) { fp@2584: /* Pull CS high */ fp@2584: eecd |= E1000_EECD_CS; fp@2584: e1000_lower_eec_clk(hw, &eecd); fp@2584: } fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_release_nvm - Release exclusive access to EEPROM fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Stop any current commands to the EEPROM and clear the EEPROM request bit. fp@2584: **/ fp@2584: void e1000e_release_nvm(struct e1000_hw *hw) fp@2584: { fp@2584: u32 eecd; fp@2584: fp@2584: e1000_stop_nvm(hw); fp@2584: fp@2584: eecd = er32(EECD); fp@2584: eecd &= ~E1000_EECD_REQ; fp@2584: ew32(EECD, eecd); fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Setups the EEPROM for reading and writing. fp@2584: **/ fp@2584: static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw) fp@2584: { fp@2584: struct e1000_nvm_info *nvm = &hw->nvm; fp@2584: u32 eecd = er32(EECD); fp@2584: u8 spi_stat_reg; fp@2584: fp@2584: if (nvm->type == e1000_nvm_eeprom_spi) { fp@2584: u16 timeout = NVM_MAX_RETRY_SPI; fp@2584: fp@2584: /* Clear SK and CS */ fp@2584: eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); fp@2584: ew32(EECD, eecd); fp@2584: e1e_flush(); fp@2584: udelay(1); fp@2584: fp@2584: /* Read "Status Register" repeatedly until the LSB is cleared. fp@2584: * The EEPROM will signal that the command has been completed fp@2584: * by clearing bit 0 of the internal status register. If it's fp@2584: * not cleared within 'timeout', then error out. fp@2584: */ fp@2584: while (timeout) { fp@2584: e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI, fp@2584: hw->nvm.opcode_bits); fp@2584: spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8); fp@2584: if (!(spi_stat_reg & NVM_STATUS_RDY_SPI)) fp@2584: break; fp@2584: fp@2584: udelay(5); fp@2584: e1000_standby_nvm(hw); fp@2584: timeout--; fp@2584: } fp@2584: fp@2584: if (!timeout) { fp@2584: e_dbg("SPI NVM Status error\n"); fp@2584: return -E1000_ERR_NVM; fp@2584: } fp@2584: } fp@2584: fp@2584: return 0; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_read_nvm_eerd - Reads EEPROM using EERD register fp@2584: * @hw: pointer to the HW structure fp@2584: * @offset: offset of word in the EEPROM to read fp@2584: * @words: number of words to read fp@2584: * @data: word read from the EEPROM fp@2584: * fp@2584: * Reads a 16 bit word from the EEPROM using the EERD register. fp@2584: **/ fp@2584: s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) fp@2584: { fp@2584: struct e1000_nvm_info *nvm = &hw->nvm; fp@2584: u32 i, eerd = 0; fp@2584: s32 ret_val = 0; fp@2584: fp@2584: /* A check for invalid values: offset too large, too many words, fp@2584: * too many words for the offset, and not enough words. fp@2584: */ fp@2584: if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || fp@2584: (words == 0)) { fp@2584: e_dbg("nvm parameter(s) out of bounds\n"); fp@2584: return -E1000_ERR_NVM; fp@2584: } fp@2584: fp@2584: for (i = 0; i < words; i++) { fp@2584: eerd = ((offset + i) << E1000_NVM_RW_ADDR_SHIFT) + fp@2584: E1000_NVM_RW_REG_START; fp@2584: fp@2584: ew32(EERD, eerd); fp@2584: ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ); fp@2584: if (ret_val) fp@2584: break; fp@2584: fp@2584: data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA); fp@2584: } fp@2584: fp@2584: return ret_val; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_write_nvm_spi - Write to EEPROM using SPI fp@2584: * @hw: pointer to the HW structure fp@2584: * @offset: offset within the EEPROM to be written to fp@2584: * @words: number of words to write fp@2584: * @data: 16 bit word(s) to be written to the EEPROM fp@2584: * fp@2584: * Writes data to EEPROM at offset using SPI interface. fp@2584: * fp@2584: * If e1000e_update_nvm_checksum is not called after this function , the fp@2584: * EEPROM will most likely contain an invalid checksum. fp@2584: **/ fp@2584: s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) fp@2584: { fp@2584: struct e1000_nvm_info *nvm = &hw->nvm; fp@2584: s32 ret_val; fp@2584: u16 widx = 0; fp@2584: fp@2584: /* A check for invalid values: offset too large, too many words, fp@2584: * and not enough words. fp@2584: */ fp@2584: if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || fp@2584: (words == 0)) { fp@2584: e_dbg("nvm parameter(s) out of bounds\n"); fp@2584: return -E1000_ERR_NVM; fp@2584: } fp@2584: fp@2584: ret_val = nvm->ops.acquire(hw); fp@2584: if (ret_val) fp@2584: return ret_val; fp@2584: fp@2584: while (widx < words) { fp@2584: u8 write_opcode = NVM_WRITE_OPCODE_SPI; fp@2584: fp@2584: ret_val = e1000_ready_nvm_eeprom(hw); fp@2584: if (ret_val) fp@2584: goto release; fp@2584: fp@2584: e1000_standby_nvm(hw); fp@2584: fp@2584: /* Send the WRITE ENABLE command (8 bit opcode) */ fp@2584: e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI, fp@2584: nvm->opcode_bits); fp@2584: fp@2584: e1000_standby_nvm(hw); fp@2584: fp@2584: /* Some SPI eeproms use the 8th address bit embedded in the fp@2584: * opcode fp@2584: */ fp@2584: if ((nvm->address_bits == 8) && (offset >= 128)) fp@2584: write_opcode |= NVM_A8_OPCODE_SPI; fp@2584: fp@2584: /* Send the Write command (8-bit opcode + addr) */ fp@2584: e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits); fp@2584: e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2), fp@2584: nvm->address_bits); fp@2584: fp@2584: /* Loop to allow for up to whole page write of eeprom */ fp@2584: while (widx < words) { fp@2584: u16 word_out = data[widx]; fp@2584: word_out = (word_out >> 8) | (word_out << 8); fp@2584: e1000_shift_out_eec_bits(hw, word_out, 16); fp@2584: widx++; fp@2584: fp@2584: if ((((offset + widx) * 2) % nvm->page_size) == 0) { fp@2584: e1000_standby_nvm(hw); fp@2584: break; fp@2584: } fp@2584: } fp@2584: } fp@2584: fp@2584: usleep_range(10000, 20000); fp@2584: release: fp@2584: nvm->ops.release(hw); fp@2584: fp@2584: return ret_val; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_read_pba_string_generic - Read device part number fp@2584: * @hw: pointer to the HW structure fp@2584: * @pba_num: pointer to device part number fp@2584: * @pba_num_size: size of part number buffer fp@2584: * fp@2584: * Reads the product board assembly (PBA) number from the EEPROM and stores fp@2584: * the value in pba_num. fp@2584: **/ fp@2584: s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num, fp@2584: u32 pba_num_size) fp@2584: { fp@2584: s32 ret_val; fp@2584: u16 nvm_data; fp@2584: u16 pba_ptr; fp@2584: u16 offset; fp@2584: u16 length; fp@2584: fp@2584: if (pba_num == NULL) { fp@2584: e_dbg("PBA string buffer was null\n"); fp@2584: return -E1000_ERR_INVALID_ARGUMENT; fp@2584: } fp@2584: fp@2584: ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data); fp@2584: if (ret_val) { fp@2584: e_dbg("NVM Read Error\n"); fp@2584: return ret_val; fp@2584: } fp@2584: fp@2584: ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr); fp@2584: if (ret_val) { fp@2584: e_dbg("NVM Read Error\n"); fp@2584: return ret_val; fp@2584: } fp@2584: fp@2584: /* if nvm_data is not ptr guard the PBA must be in legacy format which fp@2584: * means pba_ptr is actually our second data word for the PBA number fp@2584: * and we can decode it into an ascii string fp@2584: */ fp@2584: if (nvm_data != NVM_PBA_PTR_GUARD) { fp@2584: e_dbg("NVM PBA number is not stored as string\n"); fp@2584: fp@2584: /* we will need 11 characters to store the PBA */ fp@2584: if (pba_num_size < 11) { fp@2584: e_dbg("PBA string buffer too small\n"); fp@2584: return E1000_ERR_NO_SPACE; fp@2584: } fp@2584: fp@2584: /* extract hex string from data and pba_ptr */ fp@2584: pba_num[0] = (nvm_data >> 12) & 0xF; fp@2584: pba_num[1] = (nvm_data >> 8) & 0xF; fp@2584: pba_num[2] = (nvm_data >> 4) & 0xF; fp@2584: pba_num[3] = nvm_data & 0xF; fp@2584: pba_num[4] = (pba_ptr >> 12) & 0xF; fp@2584: pba_num[5] = (pba_ptr >> 8) & 0xF; fp@2584: pba_num[6] = '-'; fp@2584: pba_num[7] = 0; fp@2584: pba_num[8] = (pba_ptr >> 4) & 0xF; fp@2584: pba_num[9] = pba_ptr & 0xF; fp@2584: fp@2584: /* put a null character on the end of our string */ fp@2584: pba_num[10] = '\0'; fp@2584: fp@2584: /* switch all the data but the '-' to hex char */ fp@2584: for (offset = 0; offset < 10; offset++) { fp@2584: if (pba_num[offset] < 0xA) fp@2584: pba_num[offset] += '0'; fp@2584: else if (pba_num[offset] < 0x10) fp@2584: pba_num[offset] += 'A' - 0xA; fp@2584: } fp@2584: fp@2584: return 0; fp@2584: } fp@2584: fp@2584: ret_val = e1000_read_nvm(hw, pba_ptr, 1, &length); fp@2584: if (ret_val) { fp@2584: e_dbg("NVM Read Error\n"); fp@2584: return ret_val; fp@2584: } fp@2584: fp@2584: if (length == 0xFFFF || length == 0) { fp@2584: e_dbg("NVM PBA number section invalid length\n"); fp@2584: return -E1000_ERR_NVM_PBA_SECTION; fp@2584: } fp@2584: /* check if pba_num buffer is big enough */ fp@2584: if (pba_num_size < (((u32)length * 2) - 1)) { fp@2584: e_dbg("PBA string buffer too small\n"); fp@2584: return -E1000_ERR_NO_SPACE; fp@2584: } fp@2584: fp@2584: /* trim pba length from start of string */ fp@2584: pba_ptr++; fp@2584: length--; fp@2584: fp@2584: for (offset = 0; offset < length; offset++) { fp@2584: ret_val = e1000_read_nvm(hw, pba_ptr + offset, 1, &nvm_data); fp@2584: if (ret_val) { fp@2584: e_dbg("NVM Read Error\n"); fp@2584: return ret_val; fp@2584: } fp@2584: pba_num[offset * 2] = (u8)(nvm_data >> 8); fp@2584: pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF); fp@2584: } fp@2584: pba_num[offset * 2] = '\0'; fp@2584: fp@2584: return 0; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000_read_mac_addr_generic - Read device MAC address fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Reads the device MAC address from the EEPROM and stores the value. fp@2584: * Since devices with two ports use the same EEPROM, we increment the fp@2584: * last bit in the MAC address for the second port. fp@2584: **/ fp@2584: s32 e1000_read_mac_addr_generic(struct e1000_hw *hw) fp@2584: { fp@2584: u32 rar_high; fp@2584: u32 rar_low; fp@2584: u16 i; fp@2584: fp@2584: rar_high = er32(RAH(0)); fp@2584: rar_low = er32(RAL(0)); fp@2584: fp@2584: for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++) fp@2584: hw->mac.perm_addr[i] = (u8)(rar_low >> (i * 8)); fp@2584: fp@2584: for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++) fp@2584: hw->mac.perm_addr[i + 4] = (u8)(rar_high >> (i * 8)); fp@2584: fp@2584: for (i = 0; i < ETH_ALEN; i++) fp@2584: hw->mac.addr[i] = hw->mac.perm_addr[i]; fp@2584: fp@2584: return 0; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Calculates the EEPROM checksum by reading/adding each word of the EEPROM fp@2584: * and then verifies that the sum of the EEPROM is equal to 0xBABA. fp@2584: **/ fp@2584: s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw) fp@2584: { fp@2584: s32 ret_val; fp@2584: u16 checksum = 0; fp@2584: u16 i, nvm_data; fp@2584: fp@2584: for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { fp@2584: ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); fp@2584: if (ret_val) { fp@2584: e_dbg("NVM Read Error\n"); fp@2584: return ret_val; fp@2584: } fp@2584: checksum += nvm_data; fp@2584: } fp@2584: fp@2584: if (checksum != (u16)NVM_SUM) { fp@2584: e_dbg("NVM Checksum Invalid\n"); fp@2584: return -E1000_ERR_NVM; fp@2584: } fp@2584: fp@2584: return 0; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_update_nvm_checksum_generic - Update EEPROM checksum fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Updates the EEPROM checksum by reading/adding each word of the EEPROM fp@2584: * up to the checksum. Then calculates the EEPROM checksum and writes the fp@2584: * value to the EEPROM. fp@2584: **/ fp@2584: s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw) fp@2584: { fp@2584: s32 ret_val; fp@2584: u16 checksum = 0; fp@2584: u16 i, nvm_data; fp@2584: fp@2584: for (i = 0; i < NVM_CHECKSUM_REG; i++) { fp@2584: ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); fp@2584: if (ret_val) { fp@2584: e_dbg("NVM Read Error while updating checksum.\n"); fp@2584: return ret_val; fp@2584: } fp@2584: checksum += nvm_data; fp@2584: } fp@2584: checksum = (u16)NVM_SUM - checksum; fp@2584: ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum); fp@2584: if (ret_val) fp@2584: e_dbg("NVM Write Error while updating checksum.\n"); fp@2584: fp@2584: return ret_val; fp@2584: } fp@2584: fp@2584: /** fp@2584: * e1000e_reload_nvm_generic - Reloads EEPROM fp@2584: * @hw: pointer to the HW structure fp@2584: * fp@2584: * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the fp@2584: * extended control register. fp@2584: **/ fp@2584: void e1000e_reload_nvm_generic(struct e1000_hw *hw) fp@2584: { fp@2584: u32 ctrl_ext; fp@2584: fp@2584: udelay(10); fp@2584: ctrl_ext = er32(CTRL_EXT); fp@2584: ctrl_ext |= E1000_CTRL_EXT_EE_RST; fp@2584: ew32(CTRL_EXT, ctrl_ext); fp@2584: e1e_flush(); fp@2584: }