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