18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright(c) 2007 - 2018 Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include <linux/if_ether.h> 58c2ecf20Sopenharmony_ci#include <linux/delay.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include "e1000_mac.h" 88c2ecf20Sopenharmony_ci#include "e1000_nvm.h" 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci/** 118c2ecf20Sopenharmony_ci * igb_raise_eec_clk - Raise EEPROM clock 128c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 138c2ecf20Sopenharmony_ci * @eecd: pointer to the EEPROM 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * Enable/Raise the EEPROM clock bit. 168c2ecf20Sopenharmony_ci **/ 178c2ecf20Sopenharmony_cistatic void igb_raise_eec_clk(struct e1000_hw *hw, u32 *eecd) 188c2ecf20Sopenharmony_ci{ 198c2ecf20Sopenharmony_ci *eecd = *eecd | E1000_EECD_SK; 208c2ecf20Sopenharmony_ci wr32(E1000_EECD, *eecd); 218c2ecf20Sopenharmony_ci wrfl(); 228c2ecf20Sopenharmony_ci udelay(hw->nvm.delay_usec); 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/** 268c2ecf20Sopenharmony_ci * igb_lower_eec_clk - Lower EEPROM clock 278c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 288c2ecf20Sopenharmony_ci * @eecd: pointer to the EEPROM 298c2ecf20Sopenharmony_ci * 308c2ecf20Sopenharmony_ci * Clear/Lower the EEPROM clock bit. 318c2ecf20Sopenharmony_ci **/ 328c2ecf20Sopenharmony_cistatic void igb_lower_eec_clk(struct e1000_hw *hw, u32 *eecd) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci *eecd = *eecd & ~E1000_EECD_SK; 358c2ecf20Sopenharmony_ci wr32(E1000_EECD, *eecd); 368c2ecf20Sopenharmony_ci wrfl(); 378c2ecf20Sopenharmony_ci udelay(hw->nvm.delay_usec); 388c2ecf20Sopenharmony_ci} 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/** 418c2ecf20Sopenharmony_ci * igb_shift_out_eec_bits - Shift data bits our to the EEPROM 428c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 438c2ecf20Sopenharmony_ci * @data: data to send to the EEPROM 448c2ecf20Sopenharmony_ci * @count: number of bits to shift out 458c2ecf20Sopenharmony_ci * 468c2ecf20Sopenharmony_ci * We need to shift 'count' bits out to the EEPROM. So, the value in the 478c2ecf20Sopenharmony_ci * "data" parameter will be shifted out to the EEPROM one bit at a time. 488c2ecf20Sopenharmony_ci * In order to do this, "data" must be broken down into bits. 498c2ecf20Sopenharmony_ci **/ 508c2ecf20Sopenharmony_cistatic void igb_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count) 518c2ecf20Sopenharmony_ci{ 528c2ecf20Sopenharmony_ci struct e1000_nvm_info *nvm = &hw->nvm; 538c2ecf20Sopenharmony_ci u32 eecd = rd32(E1000_EECD); 548c2ecf20Sopenharmony_ci u32 mask; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci mask = 1u << (count - 1); 578c2ecf20Sopenharmony_ci if (nvm->type == e1000_nvm_eeprom_spi) 588c2ecf20Sopenharmony_ci eecd |= E1000_EECD_DO; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci do { 618c2ecf20Sopenharmony_ci eecd &= ~E1000_EECD_DI; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci if (data & mask) 648c2ecf20Sopenharmony_ci eecd |= E1000_EECD_DI; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd); 678c2ecf20Sopenharmony_ci wrfl(); 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci udelay(nvm->delay_usec); 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci igb_raise_eec_clk(hw, &eecd); 728c2ecf20Sopenharmony_ci igb_lower_eec_clk(hw, &eecd); 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci mask >>= 1; 758c2ecf20Sopenharmony_ci } while (mask); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci eecd &= ~E1000_EECD_DI; 788c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd); 798c2ecf20Sopenharmony_ci} 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/** 828c2ecf20Sopenharmony_ci * igb_shift_in_eec_bits - Shift data bits in from the EEPROM 838c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 848c2ecf20Sopenharmony_ci * @count: number of bits to shift in 858c2ecf20Sopenharmony_ci * 868c2ecf20Sopenharmony_ci * In order to read a register from the EEPROM, we need to shift 'count' bits 878c2ecf20Sopenharmony_ci * in from the EEPROM. Bits are "shifted in" by raising the clock input to 888c2ecf20Sopenharmony_ci * the EEPROM (setting the SK bit), and then reading the value of the data out 898c2ecf20Sopenharmony_ci * "DO" bit. During this "shifting in" process the data in "DI" bit should 908c2ecf20Sopenharmony_ci * always be clear. 918c2ecf20Sopenharmony_ci **/ 928c2ecf20Sopenharmony_cistatic u16 igb_shift_in_eec_bits(struct e1000_hw *hw, u16 count) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci u32 eecd; 958c2ecf20Sopenharmony_ci u32 i; 968c2ecf20Sopenharmony_ci u16 data; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci eecd = rd32(E1000_EECD); 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); 1018c2ecf20Sopenharmony_ci data = 0; 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci for (i = 0; i < count; i++) { 1048c2ecf20Sopenharmony_ci data <<= 1; 1058c2ecf20Sopenharmony_ci igb_raise_eec_clk(hw, &eecd); 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci eecd = rd32(E1000_EECD); 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci eecd &= ~E1000_EECD_DI; 1108c2ecf20Sopenharmony_ci if (eecd & E1000_EECD_DO) 1118c2ecf20Sopenharmony_ci data |= 1; 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci igb_lower_eec_clk(hw, &eecd); 1148c2ecf20Sopenharmony_ci } 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci return data; 1178c2ecf20Sopenharmony_ci} 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci/** 1208c2ecf20Sopenharmony_ci * igb_poll_eerd_eewr_done - Poll for EEPROM read/write completion 1218c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 1228c2ecf20Sopenharmony_ci * @ee_reg: EEPROM flag for polling 1238c2ecf20Sopenharmony_ci * 1248c2ecf20Sopenharmony_ci * Polls the EEPROM status bit for either read or write completion based 1258c2ecf20Sopenharmony_ci * upon the value of 'ee_reg'. 1268c2ecf20Sopenharmony_ci **/ 1278c2ecf20Sopenharmony_cistatic s32 igb_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg) 1288c2ecf20Sopenharmony_ci{ 1298c2ecf20Sopenharmony_ci u32 attempts = 100000; 1308c2ecf20Sopenharmony_ci u32 i, reg = 0; 1318c2ecf20Sopenharmony_ci s32 ret_val = -E1000_ERR_NVM; 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci for (i = 0; i < attempts; i++) { 1348c2ecf20Sopenharmony_ci if (ee_reg == E1000_NVM_POLL_READ) 1358c2ecf20Sopenharmony_ci reg = rd32(E1000_EERD); 1368c2ecf20Sopenharmony_ci else 1378c2ecf20Sopenharmony_ci reg = rd32(E1000_EEWR); 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci if (reg & E1000_NVM_RW_REG_DONE) { 1408c2ecf20Sopenharmony_ci ret_val = 0; 1418c2ecf20Sopenharmony_ci break; 1428c2ecf20Sopenharmony_ci } 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci udelay(5); 1458c2ecf20Sopenharmony_ci } 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci return ret_val; 1488c2ecf20Sopenharmony_ci} 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci/** 1518c2ecf20Sopenharmony_ci * igb_acquire_nvm - Generic request for access to EEPROM 1528c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 1538c2ecf20Sopenharmony_ci * 1548c2ecf20Sopenharmony_ci * Set the EEPROM access request bit and wait for EEPROM access grant bit. 1558c2ecf20Sopenharmony_ci * Return successful if access grant bit set, else clear the request for 1568c2ecf20Sopenharmony_ci * EEPROM access and return -E1000_ERR_NVM (-1). 1578c2ecf20Sopenharmony_ci **/ 1588c2ecf20Sopenharmony_cis32 igb_acquire_nvm(struct e1000_hw *hw) 1598c2ecf20Sopenharmony_ci{ 1608c2ecf20Sopenharmony_ci u32 eecd = rd32(E1000_EECD); 1618c2ecf20Sopenharmony_ci s32 timeout = E1000_NVM_GRANT_ATTEMPTS; 1628c2ecf20Sopenharmony_ci s32 ret_val = 0; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd | E1000_EECD_REQ); 1668c2ecf20Sopenharmony_ci eecd = rd32(E1000_EECD); 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci while (timeout) { 1698c2ecf20Sopenharmony_ci if (eecd & E1000_EECD_GNT) 1708c2ecf20Sopenharmony_ci break; 1718c2ecf20Sopenharmony_ci udelay(5); 1728c2ecf20Sopenharmony_ci eecd = rd32(E1000_EECD); 1738c2ecf20Sopenharmony_ci timeout--; 1748c2ecf20Sopenharmony_ci } 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci if (!timeout) { 1778c2ecf20Sopenharmony_ci eecd &= ~E1000_EECD_REQ; 1788c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd); 1798c2ecf20Sopenharmony_ci hw_dbg("Could not acquire NVM grant\n"); 1808c2ecf20Sopenharmony_ci ret_val = -E1000_ERR_NVM; 1818c2ecf20Sopenharmony_ci } 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci return ret_val; 1848c2ecf20Sopenharmony_ci} 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci/** 1878c2ecf20Sopenharmony_ci * igb_standby_nvm - Return EEPROM to standby state 1888c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 1898c2ecf20Sopenharmony_ci * 1908c2ecf20Sopenharmony_ci * Return the EEPROM to a standby state. 1918c2ecf20Sopenharmony_ci **/ 1928c2ecf20Sopenharmony_cistatic void igb_standby_nvm(struct e1000_hw *hw) 1938c2ecf20Sopenharmony_ci{ 1948c2ecf20Sopenharmony_ci struct e1000_nvm_info *nvm = &hw->nvm; 1958c2ecf20Sopenharmony_ci u32 eecd = rd32(E1000_EECD); 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_ci if (nvm->type == e1000_nvm_eeprom_spi) { 1988c2ecf20Sopenharmony_ci /* Toggle CS to flush commands */ 1998c2ecf20Sopenharmony_ci eecd |= E1000_EECD_CS; 2008c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd); 2018c2ecf20Sopenharmony_ci wrfl(); 2028c2ecf20Sopenharmony_ci udelay(nvm->delay_usec); 2038c2ecf20Sopenharmony_ci eecd &= ~E1000_EECD_CS; 2048c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd); 2058c2ecf20Sopenharmony_ci wrfl(); 2068c2ecf20Sopenharmony_ci udelay(nvm->delay_usec); 2078c2ecf20Sopenharmony_ci } 2088c2ecf20Sopenharmony_ci} 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/** 2118c2ecf20Sopenharmony_ci * e1000_stop_nvm - Terminate EEPROM command 2128c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 2138c2ecf20Sopenharmony_ci * 2148c2ecf20Sopenharmony_ci * Terminates the current command by inverting the EEPROM's chip select pin. 2158c2ecf20Sopenharmony_ci **/ 2168c2ecf20Sopenharmony_cistatic void e1000_stop_nvm(struct e1000_hw *hw) 2178c2ecf20Sopenharmony_ci{ 2188c2ecf20Sopenharmony_ci u32 eecd; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci eecd = rd32(E1000_EECD); 2218c2ecf20Sopenharmony_ci if (hw->nvm.type == e1000_nvm_eeprom_spi) { 2228c2ecf20Sopenharmony_ci /* Pull CS high */ 2238c2ecf20Sopenharmony_ci eecd |= E1000_EECD_CS; 2248c2ecf20Sopenharmony_ci igb_lower_eec_clk(hw, &eecd); 2258c2ecf20Sopenharmony_ci } 2268c2ecf20Sopenharmony_ci} 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci/** 2298c2ecf20Sopenharmony_ci * igb_release_nvm - Release exclusive access to EEPROM 2308c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 2318c2ecf20Sopenharmony_ci * 2328c2ecf20Sopenharmony_ci * Stop any current commands to the EEPROM and clear the EEPROM request bit. 2338c2ecf20Sopenharmony_ci **/ 2348c2ecf20Sopenharmony_civoid igb_release_nvm(struct e1000_hw *hw) 2358c2ecf20Sopenharmony_ci{ 2368c2ecf20Sopenharmony_ci u32 eecd; 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci e1000_stop_nvm(hw); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci eecd = rd32(E1000_EECD); 2418c2ecf20Sopenharmony_ci eecd &= ~E1000_EECD_REQ; 2428c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd); 2438c2ecf20Sopenharmony_ci} 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci/** 2468c2ecf20Sopenharmony_ci * igb_ready_nvm_eeprom - Prepares EEPROM for read/write 2478c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 2488c2ecf20Sopenharmony_ci * 2498c2ecf20Sopenharmony_ci * Setups the EEPROM for reading and writing. 2508c2ecf20Sopenharmony_ci **/ 2518c2ecf20Sopenharmony_cistatic s32 igb_ready_nvm_eeprom(struct e1000_hw *hw) 2528c2ecf20Sopenharmony_ci{ 2538c2ecf20Sopenharmony_ci struct e1000_nvm_info *nvm = &hw->nvm; 2548c2ecf20Sopenharmony_ci u32 eecd = rd32(E1000_EECD); 2558c2ecf20Sopenharmony_ci s32 ret_val = 0; 2568c2ecf20Sopenharmony_ci u16 timeout = 0; 2578c2ecf20Sopenharmony_ci u8 spi_stat_reg; 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci if (nvm->type == e1000_nvm_eeprom_spi) { 2618c2ecf20Sopenharmony_ci /* Clear SK and CS */ 2628c2ecf20Sopenharmony_ci eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); 2638c2ecf20Sopenharmony_ci wr32(E1000_EECD, eecd); 2648c2ecf20Sopenharmony_ci wrfl(); 2658c2ecf20Sopenharmony_ci udelay(1); 2668c2ecf20Sopenharmony_ci timeout = NVM_MAX_RETRY_SPI; 2678c2ecf20Sopenharmony_ci 2688c2ecf20Sopenharmony_ci /* Read "Status Register" repeatedly until the LSB is cleared. 2698c2ecf20Sopenharmony_ci * The EEPROM will signal that the command has been completed 2708c2ecf20Sopenharmony_ci * by clearing bit 0 of the internal status register. If it's 2718c2ecf20Sopenharmony_ci * not cleared within 'timeout', then error out. 2728c2ecf20Sopenharmony_ci */ 2738c2ecf20Sopenharmony_ci while (timeout) { 2748c2ecf20Sopenharmony_ci igb_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI, 2758c2ecf20Sopenharmony_ci hw->nvm.opcode_bits); 2768c2ecf20Sopenharmony_ci spi_stat_reg = (u8)igb_shift_in_eec_bits(hw, 8); 2778c2ecf20Sopenharmony_ci if (!(spi_stat_reg & NVM_STATUS_RDY_SPI)) 2788c2ecf20Sopenharmony_ci break; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci udelay(5); 2818c2ecf20Sopenharmony_ci igb_standby_nvm(hw); 2828c2ecf20Sopenharmony_ci timeout--; 2838c2ecf20Sopenharmony_ci } 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci if (!timeout) { 2868c2ecf20Sopenharmony_ci hw_dbg("SPI NVM Status error\n"); 2878c2ecf20Sopenharmony_ci ret_val = -E1000_ERR_NVM; 2888c2ecf20Sopenharmony_ci goto out; 2898c2ecf20Sopenharmony_ci } 2908c2ecf20Sopenharmony_ci } 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ciout: 2938c2ecf20Sopenharmony_ci return ret_val; 2948c2ecf20Sopenharmony_ci} 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci/** 2978c2ecf20Sopenharmony_ci * igb_read_nvm_spi - Read EEPROM's using SPI 2988c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 2998c2ecf20Sopenharmony_ci * @offset: offset of word in the EEPROM to read 3008c2ecf20Sopenharmony_ci * @words: number of words to read 3018c2ecf20Sopenharmony_ci * @data: word read from the EEPROM 3028c2ecf20Sopenharmony_ci * 3038c2ecf20Sopenharmony_ci * Reads a 16 bit word from the EEPROM. 3048c2ecf20Sopenharmony_ci **/ 3058c2ecf20Sopenharmony_cis32 igb_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 3068c2ecf20Sopenharmony_ci{ 3078c2ecf20Sopenharmony_ci struct e1000_nvm_info *nvm = &hw->nvm; 3088c2ecf20Sopenharmony_ci u32 i = 0; 3098c2ecf20Sopenharmony_ci s32 ret_val; 3108c2ecf20Sopenharmony_ci u16 word_in; 3118c2ecf20Sopenharmony_ci u8 read_opcode = NVM_READ_OPCODE_SPI; 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci /* A check for invalid values: offset too large, too many words, 3148c2ecf20Sopenharmony_ci * and not enough words. 3158c2ecf20Sopenharmony_ci */ 3168c2ecf20Sopenharmony_ci if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 3178c2ecf20Sopenharmony_ci (words == 0)) { 3188c2ecf20Sopenharmony_ci hw_dbg("nvm parameter(s) out of bounds\n"); 3198c2ecf20Sopenharmony_ci ret_val = -E1000_ERR_NVM; 3208c2ecf20Sopenharmony_ci goto out; 3218c2ecf20Sopenharmony_ci } 3228c2ecf20Sopenharmony_ci 3238c2ecf20Sopenharmony_ci ret_val = nvm->ops.acquire(hw); 3248c2ecf20Sopenharmony_ci if (ret_val) 3258c2ecf20Sopenharmony_ci goto out; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci ret_val = igb_ready_nvm_eeprom(hw); 3288c2ecf20Sopenharmony_ci if (ret_val) 3298c2ecf20Sopenharmony_ci goto release; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci igb_standby_nvm(hw); 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci if ((nvm->address_bits == 8) && (offset >= 128)) 3348c2ecf20Sopenharmony_ci read_opcode |= NVM_A8_OPCODE_SPI; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_ci /* Send the READ command (opcode + addr) */ 3378c2ecf20Sopenharmony_ci igb_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits); 3388c2ecf20Sopenharmony_ci igb_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits); 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_ci /* Read the data. SPI NVMs increment the address with each byte 3418c2ecf20Sopenharmony_ci * read and will roll over if reading beyond the end. This allows 3428c2ecf20Sopenharmony_ci * us to read the whole NVM from any offset 3438c2ecf20Sopenharmony_ci */ 3448c2ecf20Sopenharmony_ci for (i = 0; i < words; i++) { 3458c2ecf20Sopenharmony_ci word_in = igb_shift_in_eec_bits(hw, 16); 3468c2ecf20Sopenharmony_ci data[i] = (word_in >> 8) | (word_in << 8); 3478c2ecf20Sopenharmony_ci } 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_cirelease: 3508c2ecf20Sopenharmony_ci nvm->ops.release(hw); 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ciout: 3538c2ecf20Sopenharmony_ci return ret_val; 3548c2ecf20Sopenharmony_ci} 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci/** 3578c2ecf20Sopenharmony_ci * igb_read_nvm_eerd - Reads EEPROM using EERD register 3588c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 3598c2ecf20Sopenharmony_ci * @offset: offset of word in the EEPROM to read 3608c2ecf20Sopenharmony_ci * @words: number of words to read 3618c2ecf20Sopenharmony_ci * @data: word read from the EEPROM 3628c2ecf20Sopenharmony_ci * 3638c2ecf20Sopenharmony_ci * Reads a 16 bit word from the EEPROM using the EERD register. 3648c2ecf20Sopenharmony_ci **/ 3658c2ecf20Sopenharmony_cis32 igb_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 3668c2ecf20Sopenharmony_ci{ 3678c2ecf20Sopenharmony_ci struct e1000_nvm_info *nvm = &hw->nvm; 3688c2ecf20Sopenharmony_ci u32 i, eerd = 0; 3698c2ecf20Sopenharmony_ci s32 ret_val = 0; 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci /* A check for invalid values: offset too large, too many words, 3728c2ecf20Sopenharmony_ci * and not enough words. 3738c2ecf20Sopenharmony_ci */ 3748c2ecf20Sopenharmony_ci if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 3758c2ecf20Sopenharmony_ci (words == 0)) { 3768c2ecf20Sopenharmony_ci hw_dbg("nvm parameter(s) out of bounds\n"); 3778c2ecf20Sopenharmony_ci ret_val = -E1000_ERR_NVM; 3788c2ecf20Sopenharmony_ci goto out; 3798c2ecf20Sopenharmony_ci } 3808c2ecf20Sopenharmony_ci 3818c2ecf20Sopenharmony_ci for (i = 0; i < words; i++) { 3828c2ecf20Sopenharmony_ci eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) + 3838c2ecf20Sopenharmony_ci E1000_NVM_RW_REG_START; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci wr32(E1000_EERD, eerd); 3868c2ecf20Sopenharmony_ci ret_val = igb_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ); 3878c2ecf20Sopenharmony_ci if (ret_val) 3888c2ecf20Sopenharmony_ci break; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci data[i] = (rd32(E1000_EERD) >> 3918c2ecf20Sopenharmony_ci E1000_NVM_RW_REG_DATA); 3928c2ecf20Sopenharmony_ci } 3938c2ecf20Sopenharmony_ci 3948c2ecf20Sopenharmony_ciout: 3958c2ecf20Sopenharmony_ci return ret_val; 3968c2ecf20Sopenharmony_ci} 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci/** 3998c2ecf20Sopenharmony_ci * igb_write_nvm_spi - Write to EEPROM using SPI 4008c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 4018c2ecf20Sopenharmony_ci * @offset: offset within the EEPROM to be written to 4028c2ecf20Sopenharmony_ci * @words: number of words to write 4038c2ecf20Sopenharmony_ci * @data: 16 bit word(s) to be written to the EEPROM 4048c2ecf20Sopenharmony_ci * 4058c2ecf20Sopenharmony_ci * Writes data to EEPROM at offset using SPI interface. 4068c2ecf20Sopenharmony_ci * 4078c2ecf20Sopenharmony_ci * If e1000_update_nvm_checksum is not called after this function , the 4088c2ecf20Sopenharmony_ci * EEPROM will most likley contain an invalid checksum. 4098c2ecf20Sopenharmony_ci **/ 4108c2ecf20Sopenharmony_cis32 igb_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 4118c2ecf20Sopenharmony_ci{ 4128c2ecf20Sopenharmony_ci struct e1000_nvm_info *nvm = &hw->nvm; 4138c2ecf20Sopenharmony_ci s32 ret_val = -E1000_ERR_NVM; 4148c2ecf20Sopenharmony_ci u16 widx = 0; 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci /* A check for invalid values: offset too large, too many words, 4178c2ecf20Sopenharmony_ci * and not enough words. 4188c2ecf20Sopenharmony_ci */ 4198c2ecf20Sopenharmony_ci if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 4208c2ecf20Sopenharmony_ci (words == 0)) { 4218c2ecf20Sopenharmony_ci hw_dbg("nvm parameter(s) out of bounds\n"); 4228c2ecf20Sopenharmony_ci return ret_val; 4238c2ecf20Sopenharmony_ci } 4248c2ecf20Sopenharmony_ci 4258c2ecf20Sopenharmony_ci while (widx < words) { 4268c2ecf20Sopenharmony_ci u8 write_opcode = NVM_WRITE_OPCODE_SPI; 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci ret_val = nvm->ops.acquire(hw); 4298c2ecf20Sopenharmony_ci if (ret_val) 4308c2ecf20Sopenharmony_ci return ret_val; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci ret_val = igb_ready_nvm_eeprom(hw); 4338c2ecf20Sopenharmony_ci if (ret_val) { 4348c2ecf20Sopenharmony_ci nvm->ops.release(hw); 4358c2ecf20Sopenharmony_ci return ret_val; 4368c2ecf20Sopenharmony_ci } 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci igb_standby_nvm(hw); 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci /* Send the WRITE ENABLE command (8 bit opcode) */ 4418c2ecf20Sopenharmony_ci igb_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI, 4428c2ecf20Sopenharmony_ci nvm->opcode_bits); 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci igb_standby_nvm(hw); 4458c2ecf20Sopenharmony_ci 4468c2ecf20Sopenharmony_ci /* Some SPI eeproms use the 8th address bit embedded in the 4478c2ecf20Sopenharmony_ci * opcode 4488c2ecf20Sopenharmony_ci */ 4498c2ecf20Sopenharmony_ci if ((nvm->address_bits == 8) && (offset >= 128)) 4508c2ecf20Sopenharmony_ci write_opcode |= NVM_A8_OPCODE_SPI; 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci /* Send the Write command (8-bit opcode + addr) */ 4538c2ecf20Sopenharmony_ci igb_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits); 4548c2ecf20Sopenharmony_ci igb_shift_out_eec_bits(hw, (u16)((offset + widx) * 2), 4558c2ecf20Sopenharmony_ci nvm->address_bits); 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci /* Loop to allow for up to whole page write of eeprom */ 4588c2ecf20Sopenharmony_ci while (widx < words) { 4598c2ecf20Sopenharmony_ci u16 word_out = data[widx]; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci word_out = (word_out >> 8) | (word_out << 8); 4628c2ecf20Sopenharmony_ci igb_shift_out_eec_bits(hw, word_out, 16); 4638c2ecf20Sopenharmony_ci widx++; 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_ci if ((((offset + widx) * 2) % nvm->page_size) == 0) { 4668c2ecf20Sopenharmony_ci igb_standby_nvm(hw); 4678c2ecf20Sopenharmony_ci break; 4688c2ecf20Sopenharmony_ci } 4698c2ecf20Sopenharmony_ci } 4708c2ecf20Sopenharmony_ci usleep_range(1000, 2000); 4718c2ecf20Sopenharmony_ci nvm->ops.release(hw); 4728c2ecf20Sopenharmony_ci } 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci return ret_val; 4758c2ecf20Sopenharmony_ci} 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci/** 4788c2ecf20Sopenharmony_ci * igb_read_part_string - Read device part number 4798c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 4808c2ecf20Sopenharmony_ci * @part_num: pointer to device part number 4818c2ecf20Sopenharmony_ci * @part_num_size: size of part number buffer 4828c2ecf20Sopenharmony_ci * 4838c2ecf20Sopenharmony_ci * Reads the product board assembly (PBA) number from the EEPROM and stores 4848c2ecf20Sopenharmony_ci * the value in part_num. 4858c2ecf20Sopenharmony_ci **/ 4868c2ecf20Sopenharmony_cis32 igb_read_part_string(struct e1000_hw *hw, u8 *part_num, u32 part_num_size) 4878c2ecf20Sopenharmony_ci{ 4888c2ecf20Sopenharmony_ci s32 ret_val; 4898c2ecf20Sopenharmony_ci u16 nvm_data; 4908c2ecf20Sopenharmony_ci u16 pointer; 4918c2ecf20Sopenharmony_ci u16 offset; 4928c2ecf20Sopenharmony_ci u16 length; 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci if (part_num == NULL) { 4958c2ecf20Sopenharmony_ci hw_dbg("PBA string buffer was null\n"); 4968c2ecf20Sopenharmony_ci ret_val = E1000_ERR_INVALID_ARGUMENT; 4978c2ecf20Sopenharmony_ci goto out; 4988c2ecf20Sopenharmony_ci } 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data); 5018c2ecf20Sopenharmony_ci if (ret_val) { 5028c2ecf20Sopenharmony_ci hw_dbg("NVM Read Error\n"); 5038c2ecf20Sopenharmony_ci goto out; 5048c2ecf20Sopenharmony_ci } 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &pointer); 5078c2ecf20Sopenharmony_ci if (ret_val) { 5088c2ecf20Sopenharmony_ci hw_dbg("NVM Read Error\n"); 5098c2ecf20Sopenharmony_ci goto out; 5108c2ecf20Sopenharmony_ci } 5118c2ecf20Sopenharmony_ci 5128c2ecf20Sopenharmony_ci /* if nvm_data is not ptr guard the PBA must be in legacy format which 5138c2ecf20Sopenharmony_ci * means pointer is actually our second data word for the PBA number 5148c2ecf20Sopenharmony_ci * and we can decode it into an ascii string 5158c2ecf20Sopenharmony_ci */ 5168c2ecf20Sopenharmony_ci if (nvm_data != NVM_PBA_PTR_GUARD) { 5178c2ecf20Sopenharmony_ci hw_dbg("NVM PBA number is not stored as string\n"); 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci /* we will need 11 characters to store the PBA */ 5208c2ecf20Sopenharmony_ci if (part_num_size < 11) { 5218c2ecf20Sopenharmony_ci hw_dbg("PBA string buffer too small\n"); 5228c2ecf20Sopenharmony_ci return E1000_ERR_NO_SPACE; 5238c2ecf20Sopenharmony_ci } 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci /* extract hex string from data and pointer */ 5268c2ecf20Sopenharmony_ci part_num[0] = (nvm_data >> 12) & 0xF; 5278c2ecf20Sopenharmony_ci part_num[1] = (nvm_data >> 8) & 0xF; 5288c2ecf20Sopenharmony_ci part_num[2] = (nvm_data >> 4) & 0xF; 5298c2ecf20Sopenharmony_ci part_num[3] = nvm_data & 0xF; 5308c2ecf20Sopenharmony_ci part_num[4] = (pointer >> 12) & 0xF; 5318c2ecf20Sopenharmony_ci part_num[5] = (pointer >> 8) & 0xF; 5328c2ecf20Sopenharmony_ci part_num[6] = '-'; 5338c2ecf20Sopenharmony_ci part_num[7] = 0; 5348c2ecf20Sopenharmony_ci part_num[8] = (pointer >> 4) & 0xF; 5358c2ecf20Sopenharmony_ci part_num[9] = pointer & 0xF; 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci /* put a null character on the end of our string */ 5388c2ecf20Sopenharmony_ci part_num[10] = '\0'; 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci /* switch all the data but the '-' to hex char */ 5418c2ecf20Sopenharmony_ci for (offset = 0; offset < 10; offset++) { 5428c2ecf20Sopenharmony_ci if (part_num[offset] < 0xA) 5438c2ecf20Sopenharmony_ci part_num[offset] += '0'; 5448c2ecf20Sopenharmony_ci else if (part_num[offset] < 0x10) 5458c2ecf20Sopenharmony_ci part_num[offset] += 'A' - 0xA; 5468c2ecf20Sopenharmony_ci } 5478c2ecf20Sopenharmony_ci 5488c2ecf20Sopenharmony_ci goto out; 5498c2ecf20Sopenharmony_ci } 5508c2ecf20Sopenharmony_ci 5518c2ecf20Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, pointer, 1, &length); 5528c2ecf20Sopenharmony_ci if (ret_val) { 5538c2ecf20Sopenharmony_ci hw_dbg("NVM Read Error\n"); 5548c2ecf20Sopenharmony_ci goto out; 5558c2ecf20Sopenharmony_ci } 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci if (length == 0xFFFF || length == 0) { 5588c2ecf20Sopenharmony_ci hw_dbg("NVM PBA number section invalid length\n"); 5598c2ecf20Sopenharmony_ci ret_val = E1000_ERR_NVM_PBA_SECTION; 5608c2ecf20Sopenharmony_ci goto out; 5618c2ecf20Sopenharmony_ci } 5628c2ecf20Sopenharmony_ci /* check if part_num buffer is big enough */ 5638c2ecf20Sopenharmony_ci if (part_num_size < (((u32)length * 2) - 1)) { 5648c2ecf20Sopenharmony_ci hw_dbg("PBA string buffer too small\n"); 5658c2ecf20Sopenharmony_ci ret_val = E1000_ERR_NO_SPACE; 5668c2ecf20Sopenharmony_ci goto out; 5678c2ecf20Sopenharmony_ci } 5688c2ecf20Sopenharmony_ci 5698c2ecf20Sopenharmony_ci /* trim pba length from start of string */ 5708c2ecf20Sopenharmony_ci pointer++; 5718c2ecf20Sopenharmony_ci length--; 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_ci for (offset = 0; offset < length; offset++) { 5748c2ecf20Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, pointer + offset, 1, &nvm_data); 5758c2ecf20Sopenharmony_ci if (ret_val) { 5768c2ecf20Sopenharmony_ci hw_dbg("NVM Read Error\n"); 5778c2ecf20Sopenharmony_ci goto out; 5788c2ecf20Sopenharmony_ci } 5798c2ecf20Sopenharmony_ci part_num[offset * 2] = (u8)(nvm_data >> 8); 5808c2ecf20Sopenharmony_ci part_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF); 5818c2ecf20Sopenharmony_ci } 5828c2ecf20Sopenharmony_ci part_num[offset * 2] = '\0'; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ciout: 5858c2ecf20Sopenharmony_ci return ret_val; 5868c2ecf20Sopenharmony_ci} 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci/** 5898c2ecf20Sopenharmony_ci * igb_read_mac_addr - Read device MAC address 5908c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 5918c2ecf20Sopenharmony_ci * 5928c2ecf20Sopenharmony_ci * Reads the device MAC address from the EEPROM and stores the value. 5938c2ecf20Sopenharmony_ci * Since devices with two ports use the same EEPROM, we increment the 5948c2ecf20Sopenharmony_ci * last bit in the MAC address for the second port. 5958c2ecf20Sopenharmony_ci **/ 5968c2ecf20Sopenharmony_cis32 igb_read_mac_addr(struct e1000_hw *hw) 5978c2ecf20Sopenharmony_ci{ 5988c2ecf20Sopenharmony_ci u32 rar_high; 5998c2ecf20Sopenharmony_ci u32 rar_low; 6008c2ecf20Sopenharmony_ci u16 i; 6018c2ecf20Sopenharmony_ci 6028c2ecf20Sopenharmony_ci rar_high = rd32(E1000_RAH(0)); 6038c2ecf20Sopenharmony_ci rar_low = rd32(E1000_RAL(0)); 6048c2ecf20Sopenharmony_ci 6058c2ecf20Sopenharmony_ci for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++) 6068c2ecf20Sopenharmony_ci hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8)); 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++) 6098c2ecf20Sopenharmony_ci hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8)); 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci for (i = 0; i < ETH_ALEN; i++) 6128c2ecf20Sopenharmony_ci hw->mac.addr[i] = hw->mac.perm_addr[i]; 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_ci return 0; 6158c2ecf20Sopenharmony_ci} 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci/** 6188c2ecf20Sopenharmony_ci * igb_validate_nvm_checksum - Validate EEPROM checksum 6198c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 6208c2ecf20Sopenharmony_ci * 6218c2ecf20Sopenharmony_ci * Calculates the EEPROM checksum by reading/adding each word of the EEPROM 6228c2ecf20Sopenharmony_ci * and then verifies that the sum of the EEPROM is equal to 0xBABA. 6238c2ecf20Sopenharmony_ci **/ 6248c2ecf20Sopenharmony_cis32 igb_validate_nvm_checksum(struct e1000_hw *hw) 6258c2ecf20Sopenharmony_ci{ 6268c2ecf20Sopenharmony_ci s32 ret_val = 0; 6278c2ecf20Sopenharmony_ci u16 checksum = 0; 6288c2ecf20Sopenharmony_ci u16 i, nvm_data; 6298c2ecf20Sopenharmony_ci 6308c2ecf20Sopenharmony_ci for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { 6318c2ecf20Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data); 6328c2ecf20Sopenharmony_ci if (ret_val) { 6338c2ecf20Sopenharmony_ci hw_dbg("NVM Read Error\n"); 6348c2ecf20Sopenharmony_ci goto out; 6358c2ecf20Sopenharmony_ci } 6368c2ecf20Sopenharmony_ci checksum += nvm_data; 6378c2ecf20Sopenharmony_ci } 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci if (checksum != (u16) NVM_SUM) { 6408c2ecf20Sopenharmony_ci hw_dbg("NVM Checksum Invalid\n"); 6418c2ecf20Sopenharmony_ci ret_val = -E1000_ERR_NVM; 6428c2ecf20Sopenharmony_ci goto out; 6438c2ecf20Sopenharmony_ci } 6448c2ecf20Sopenharmony_ci 6458c2ecf20Sopenharmony_ciout: 6468c2ecf20Sopenharmony_ci return ret_val; 6478c2ecf20Sopenharmony_ci} 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci/** 6508c2ecf20Sopenharmony_ci * igb_update_nvm_checksum - Update EEPROM checksum 6518c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 6528c2ecf20Sopenharmony_ci * 6538c2ecf20Sopenharmony_ci * Updates the EEPROM checksum by reading/adding each word of the EEPROM 6548c2ecf20Sopenharmony_ci * up to the checksum. Then calculates the EEPROM checksum and writes the 6558c2ecf20Sopenharmony_ci * value to the EEPROM. 6568c2ecf20Sopenharmony_ci **/ 6578c2ecf20Sopenharmony_cis32 igb_update_nvm_checksum(struct e1000_hw *hw) 6588c2ecf20Sopenharmony_ci{ 6598c2ecf20Sopenharmony_ci s32 ret_val; 6608c2ecf20Sopenharmony_ci u16 checksum = 0; 6618c2ecf20Sopenharmony_ci u16 i, nvm_data; 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci for (i = 0; i < NVM_CHECKSUM_REG; i++) { 6648c2ecf20Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data); 6658c2ecf20Sopenharmony_ci if (ret_val) { 6668c2ecf20Sopenharmony_ci hw_dbg("NVM Read Error while updating checksum.\n"); 6678c2ecf20Sopenharmony_ci goto out; 6688c2ecf20Sopenharmony_ci } 6698c2ecf20Sopenharmony_ci checksum += nvm_data; 6708c2ecf20Sopenharmony_ci } 6718c2ecf20Sopenharmony_ci checksum = (u16) NVM_SUM - checksum; 6728c2ecf20Sopenharmony_ci ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum); 6738c2ecf20Sopenharmony_ci if (ret_val) 6748c2ecf20Sopenharmony_ci hw_dbg("NVM Write Error while updating checksum.\n"); 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ciout: 6778c2ecf20Sopenharmony_ci return ret_val; 6788c2ecf20Sopenharmony_ci} 6798c2ecf20Sopenharmony_ci 6808c2ecf20Sopenharmony_ci/** 6818c2ecf20Sopenharmony_ci * igb_get_fw_version - Get firmware version information 6828c2ecf20Sopenharmony_ci * @hw: pointer to the HW structure 6838c2ecf20Sopenharmony_ci * @fw_vers: pointer to output structure 6848c2ecf20Sopenharmony_ci * 6858c2ecf20Sopenharmony_ci * unsupported MAC types will return all 0 version structure 6868c2ecf20Sopenharmony_ci **/ 6878c2ecf20Sopenharmony_civoid igb_get_fw_version(struct e1000_hw *hw, struct e1000_fw_version *fw_vers) 6888c2ecf20Sopenharmony_ci{ 6898c2ecf20Sopenharmony_ci u16 eeprom_verh, eeprom_verl, etrack_test, fw_version; 6908c2ecf20Sopenharmony_ci u8 q, hval, rem, result; 6918c2ecf20Sopenharmony_ci u16 comb_verh, comb_verl, comb_offset; 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci memset(fw_vers, 0, sizeof(struct e1000_fw_version)); 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci /* basic eeprom version numbers and bits used vary by part and by tool 6968c2ecf20Sopenharmony_ci * used to create the nvm images. Check which data format we have. 6978c2ecf20Sopenharmony_ci */ 6988c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, NVM_ETRACK_HIWORD, 1, &etrack_test); 6998c2ecf20Sopenharmony_ci switch (hw->mac.type) { 7008c2ecf20Sopenharmony_ci case e1000_i211: 7018c2ecf20Sopenharmony_ci igb_read_invm_version(hw, fw_vers); 7028c2ecf20Sopenharmony_ci return; 7038c2ecf20Sopenharmony_ci case e1000_82575: 7048c2ecf20Sopenharmony_ci case e1000_82576: 7058c2ecf20Sopenharmony_ci case e1000_82580: 7068c2ecf20Sopenharmony_ci /* Use this format, unless EETRACK ID exists, 7078c2ecf20Sopenharmony_ci * then use alternate format 7088c2ecf20Sopenharmony_ci */ 7098c2ecf20Sopenharmony_ci if ((etrack_test & NVM_MAJOR_MASK) != NVM_ETRACK_VALID) { 7108c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version); 7118c2ecf20Sopenharmony_ci fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK) 7128c2ecf20Sopenharmony_ci >> NVM_MAJOR_SHIFT; 7138c2ecf20Sopenharmony_ci fw_vers->eep_minor = (fw_version & NVM_MINOR_MASK) 7148c2ecf20Sopenharmony_ci >> NVM_MINOR_SHIFT; 7158c2ecf20Sopenharmony_ci fw_vers->eep_build = (fw_version & NVM_IMAGE_ID_MASK); 7168c2ecf20Sopenharmony_ci goto etrack_id; 7178c2ecf20Sopenharmony_ci } 7188c2ecf20Sopenharmony_ci break; 7198c2ecf20Sopenharmony_ci case e1000_i210: 7208c2ecf20Sopenharmony_ci if (!(igb_get_flash_presence_i210(hw))) { 7218c2ecf20Sopenharmony_ci igb_read_invm_version(hw, fw_vers); 7228c2ecf20Sopenharmony_ci return; 7238c2ecf20Sopenharmony_ci } 7248c2ecf20Sopenharmony_ci fallthrough; 7258c2ecf20Sopenharmony_ci case e1000_i350: 7268c2ecf20Sopenharmony_ci /* find combo image version */ 7278c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, NVM_COMB_VER_PTR, 1, &comb_offset); 7288c2ecf20Sopenharmony_ci if ((comb_offset != 0x0) && 7298c2ecf20Sopenharmony_ci (comb_offset != NVM_VER_INVALID)) { 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset 7328c2ecf20Sopenharmony_ci + 1), 1, &comb_verh); 7338c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, (NVM_COMB_VER_OFF + comb_offset), 7348c2ecf20Sopenharmony_ci 1, &comb_verl); 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ci /* get Option Rom version if it exists and is valid */ 7378c2ecf20Sopenharmony_ci if ((comb_verh && comb_verl) && 7388c2ecf20Sopenharmony_ci ((comb_verh != NVM_VER_INVALID) && 7398c2ecf20Sopenharmony_ci (comb_verl != NVM_VER_INVALID))) { 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci fw_vers->or_valid = true; 7428c2ecf20Sopenharmony_ci fw_vers->or_major = 7438c2ecf20Sopenharmony_ci comb_verl >> NVM_COMB_VER_SHFT; 7448c2ecf20Sopenharmony_ci fw_vers->or_build = 7458c2ecf20Sopenharmony_ci (comb_verl << NVM_COMB_VER_SHFT) 7468c2ecf20Sopenharmony_ci | (comb_verh >> NVM_COMB_VER_SHFT); 7478c2ecf20Sopenharmony_ci fw_vers->or_patch = 7488c2ecf20Sopenharmony_ci comb_verh & NVM_COMB_VER_MASK; 7498c2ecf20Sopenharmony_ci } 7508c2ecf20Sopenharmony_ci } 7518c2ecf20Sopenharmony_ci break; 7528c2ecf20Sopenharmony_ci default: 7538c2ecf20Sopenharmony_ci return; 7548c2ecf20Sopenharmony_ci } 7558c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, NVM_VERSION, 1, &fw_version); 7568c2ecf20Sopenharmony_ci fw_vers->eep_major = (fw_version & NVM_MAJOR_MASK) 7578c2ecf20Sopenharmony_ci >> NVM_MAJOR_SHIFT; 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ci /* check for old style version format in newer images*/ 7608c2ecf20Sopenharmony_ci if ((fw_version & NVM_NEW_DEC_MASK) == 0x0) { 7618c2ecf20Sopenharmony_ci eeprom_verl = (fw_version & NVM_COMB_VER_MASK); 7628c2ecf20Sopenharmony_ci } else { 7638c2ecf20Sopenharmony_ci eeprom_verl = (fw_version & NVM_MINOR_MASK) 7648c2ecf20Sopenharmony_ci >> NVM_MINOR_SHIFT; 7658c2ecf20Sopenharmony_ci } 7668c2ecf20Sopenharmony_ci /* Convert minor value to hex before assigning to output struct 7678c2ecf20Sopenharmony_ci * Val to be converted will not be higher than 99, per tool output 7688c2ecf20Sopenharmony_ci */ 7698c2ecf20Sopenharmony_ci q = eeprom_verl / NVM_HEX_CONV; 7708c2ecf20Sopenharmony_ci hval = q * NVM_HEX_TENS; 7718c2ecf20Sopenharmony_ci rem = eeprom_verl % NVM_HEX_CONV; 7728c2ecf20Sopenharmony_ci result = hval + rem; 7738c2ecf20Sopenharmony_ci fw_vers->eep_minor = result; 7748c2ecf20Sopenharmony_ci 7758c2ecf20Sopenharmony_cietrack_id: 7768c2ecf20Sopenharmony_ci if ((etrack_test & NVM_MAJOR_MASK) == NVM_ETRACK_VALID) { 7778c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, NVM_ETRACK_WORD, 1, &eeprom_verl); 7788c2ecf20Sopenharmony_ci hw->nvm.ops.read(hw, (NVM_ETRACK_WORD + 1), 1, &eeprom_verh); 7798c2ecf20Sopenharmony_ci fw_vers->etrack_id = (eeprom_verh << NVM_ETRACK_SHIFT) 7808c2ecf20Sopenharmony_ci | eeprom_verl; 7818c2ecf20Sopenharmony_ci } 7828c2ecf20Sopenharmony_ci} 783