Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

e1000e: split lib.c into three more-appropriate files

The generic lib.c file contains code relative to the various MACs, NVM and
Manageability supported by the driver. This patch splits the file into
three which are specific to those areas similar to how the PHY-specific
code is in phy.c and code specific to the 80003es2lan, 8257x, and ichX
MAC families are in their own files. The generic code that is applicable
to all MAC/PHY parts supported by the driver remains in netdev.c, param.c
and ethtool.c files. No change in functionality, just moving code
around for ease of maintenance, with some whitespace and other checkpatch
cleanups.

Signed-off-by: Bruce Allan <bruce.w.allan@intel.com>
Tested-by: Aaron Brown <aaron.f.brown@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>

authored by

Bruce Allan and committed by
Jeff Kirsher
fe2ddfb5 c8243ee0

+1051 -995
+2 -1
drivers/net/ethernet/intel/e1000e/Makefile
··· 33 33 obj-$(CONFIG_E1000E) += e1000e.o 34 34 35 35 e1000e-objs := 82571.o ich8lan.o 80003es2lan.o \ 36 - lib.o phy.o param.o ethtool.o netdev.o 36 + mac.o manage.o nvm.o phy.o \ 37 + param.o ethtool.o netdev.o 37 38
+25 -994
drivers/net/ethernet/intel/e1000e/lib.c drivers/net/ethernet/intel/e1000e/mac.c
··· 28 28 29 29 #include "e1000.h" 30 30 31 - enum e1000_mng_mode { 32 - e1000_mng_mode_none = 0, 33 - e1000_mng_mode_asf, 34 - e1000_mng_mode_pt, 35 - e1000_mng_mode_ipmi, 36 - e1000_mng_mode_host_if_only 37 - }; 38 - 39 - #define E1000_FACTPS_MNGCG 0x20000000 40 - 41 - /* Intel(R) Active Management Technology signature */ 42 - #define E1000_IAMT_SIGNATURE 0x544D4149 43 - 44 31 /** 45 32 * e1000e_get_bus_info_pcie - Get PCIe bus information 46 33 * @hw: pointer to the HW structure ··· 138 151 void e1000e_init_rx_addrs(struct e1000_hw *hw, u16 rar_count) 139 152 { 140 153 u32 i; 141 - u8 mac_addr[ETH_ALEN] = {0}; 154 + u8 mac_addr[ETH_ALEN] = { 0 }; 142 155 143 156 /* Setup the receive address */ 144 157 e_dbg("Programming MAC Address into RAR[0]\n"); ··· 146 159 e1000e_rar_set(hw, hw->mac.addr, 0); 147 160 148 161 /* Zero out the other (rar_entry_count - 1) receive addresses */ 149 - e_dbg("Clearing RAR[1-%u]\n", rar_count-1); 162 + e_dbg("Clearing RAR[1-%u]\n", rar_count - 1); 150 163 for (i = 1; i < rar_count; i++) 151 164 e1000e_rar_set(hw, mac_addr, i); 152 165 } ··· 179 192 goto out; 180 193 181 194 ret_val = e1000_read_nvm(hw, NVM_ALT_MAC_ADDR_PTR, 1, 182 - &nvm_alt_mac_addr_offset); 195 + &nvm_alt_mac_addr_offset); 183 196 if (ret_val) { 184 197 e_dbg("NVM Read Error\n"); 185 198 goto out; ··· 238 251 * HW expects these in little endian so we reverse the byte order 239 252 * from network order (big endian) to little endian 240 253 */ 241 - rar_low = ((u32) addr[0] | 242 - ((u32) addr[1] << 8) | 243 - ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); 254 + rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) | 255 + ((u32)addr[2] << 16) | ((u32)addr[3] << 24)); 244 256 245 - rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); 257 + rar_high = ((u32)addr[4] | ((u32)addr[5] << 8)); 246 258 247 259 /* If MAC address zero, no need to set the AV bit */ 248 260 if (rar_low || rar_high) ··· 301 315 * values resulting from each mc_filter_type... 302 316 * [0] [1] [2] [3] [4] [5] 303 317 * 01 AA 00 12 34 56 304 - * LSB MSB 318 + * LSB MSB 305 319 * 306 320 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563 307 321 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6 ··· 324 338 } 325 339 326 340 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) | 327 - (((u16) mc_addr[5]) << bit_shift))); 341 + (((u16)mc_addr[5]) << bit_shift))); 328 342 329 343 return hash_value; 330 344 } ··· 348 362 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow)); 349 363 350 364 /* update mta_shadow from mc_addr_list */ 351 - for (i = 0; (u32) i < mc_addr_count; i++) { 365 + for (i = 0; (u32)i < mc_addr_count; i++) { 352 366 hash_value = e1000_hash_mc_addr(hw, mc_addr_list); 353 367 354 368 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); ··· 444 458 return ret_val; 445 459 446 460 if (!link) 447 - return ret_val; /* No link detected */ 461 + return ret_val; /* No link detected */ 448 462 449 463 mac->get_link_status = false; 450 464 ··· 687 701 688 702 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0) 689 703 hw->fc.requested_mode = e1000_fc_none; 690 - else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 691 - NVM_WORD0F_ASM_DIR) 704 + else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == NVM_WORD0F_ASM_DIR) 692 705 hw->fc.requested_mode = e1000_fc_tx_pause; 693 706 else 694 707 hw->fc.requested_mode = e1000_fc_full; ··· 733 748 */ 734 749 hw->fc.current_mode = hw->fc.requested_mode; 735 750 736 - e_dbg("After fix-ups FlowControl is now = %x\n", 737 - hw->fc.current_mode); 751 + e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode); 738 752 739 753 /* Call the necessary media_type subroutine to configure the link. */ 740 754 ret_val = mac->ops.setup_physical_interface(hw); ··· 1179 1195 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 1180 1196 */ 1181 1197 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && 1182 - (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 1183 - (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 1184 - (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 1198 + (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 1199 + (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 1200 + (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 1185 1201 hw->fc.current_mode = e1000_fc_tx_pause; 1186 1202 e_dbg("Flow Control = Tx PAUSE frames only.\n"); 1187 1203 } ··· 1245 1261 * Read the status register for the current speed/duplex and store the current 1246 1262 * speed and duplex for copper connections. 1247 1263 **/ 1248 - s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, u16 *duplex) 1264 + s32 e1000e_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, 1265 + u16 *duplex) 1249 1266 { 1250 1267 u32 status; 1251 1268 ··· 1279 1294 * Sets the speed and duplex to gigabit full duplex (the only possible option) 1280 1295 * for fiber/serdes links. 1281 1296 **/ 1282 - s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, u16 *duplex) 1297 + s32 e1000e_get_speed_and_duplex_fiber_serdes(struct e1000_hw *hw, u16 *speed, 1298 + u16 *duplex) 1283 1299 { 1284 1300 *speed = SPEED_1000; 1285 1301 *duplex = FULL_DUPLEX; ··· 1483 1497 ledctl = er32(LEDCTL); 1484 1498 hw->mac.ledctl_default = ledctl; 1485 1499 /* Turn off LED0 */ 1486 - ledctl &= ~(E1000_LEDCTL_LED0_IVRT | 1487 - E1000_LEDCTL_LED0_BLINK | 1488 - E1000_LEDCTL_LED0_MODE_MASK); 1500 + ledctl &= ~(E1000_LEDCTL_LED0_IVRT | E1000_LEDCTL_LED0_BLINK | 1501 + E1000_LEDCTL_LED0_MODE_MASK); 1489 1502 ledctl |= (E1000_LEDCTL_MODE_LED_OFF << 1490 - E1000_LEDCTL_LED0_MODE_SHIFT); 1503 + E1000_LEDCTL_LED0_MODE_SHIFT); 1491 1504 ew32(LEDCTL, ledctl); 1492 1505 } else if (hw->phy.media_type == e1000_media_type_copper) { 1493 1506 ew32(LEDCTL, hw->mac.ledctl_mode1); ··· 1522 1537 if (hw->phy.media_type == e1000_media_type_fiber) { 1523 1538 /* always blink LED0 for PCI-E fiber */ 1524 1539 ledctl_blink = E1000_LEDCTL_LED0_BLINK | 1525 - (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); 1540 + (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); 1526 1541 } else { 1527 1542 /* 1528 1543 * set the blink bit for each LED that's "on" (0x0E) ··· 1635 1650 ew32(CTRL, ctrl); 1636 1651 1637 1652 while (timeout) { 1638 - if (!(er32(STATUS) & 1639 - E1000_STATUS_GIO_MASTER_ENABLE)) 1653 + if (!(er32(STATUS) & E1000_STATUS_GIO_MASTER_ENABLE)) 1640 1654 break; 1641 1655 udelay(100); 1642 1656 timeout--; ··· 1700 1716 mac->current_ifs_val = mac->ifs_min_val; 1701 1717 else 1702 1718 mac->current_ifs_val += 1703 - mac->ifs_step_size; 1719 + mac->ifs_step_size; 1704 1720 ew32(AIT, mac->current_ifs_val); 1705 1721 } 1706 1722 } ··· 1714 1730 } 1715 1731 out: 1716 1732 return; 1717 - } 1718 - 1719 - /** 1720 - * e1000_raise_eec_clk - Raise EEPROM clock 1721 - * @hw: pointer to the HW structure 1722 - * @eecd: pointer to the EEPROM 1723 - * 1724 - * Enable/Raise the EEPROM clock bit. 1725 - **/ 1726 - static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd) 1727 - { 1728 - *eecd = *eecd | E1000_EECD_SK; 1729 - ew32(EECD, *eecd); 1730 - e1e_flush(); 1731 - udelay(hw->nvm.delay_usec); 1732 - } 1733 - 1734 - /** 1735 - * e1000_lower_eec_clk - Lower EEPROM clock 1736 - * @hw: pointer to the HW structure 1737 - * @eecd: pointer to the EEPROM 1738 - * 1739 - * Clear/Lower the EEPROM clock bit. 1740 - **/ 1741 - static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd) 1742 - { 1743 - *eecd = *eecd & ~E1000_EECD_SK; 1744 - ew32(EECD, *eecd); 1745 - e1e_flush(); 1746 - udelay(hw->nvm.delay_usec); 1747 - } 1748 - 1749 - /** 1750 - * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM 1751 - * @hw: pointer to the HW structure 1752 - * @data: data to send to the EEPROM 1753 - * @count: number of bits to shift out 1754 - * 1755 - * We need to shift 'count' bits out to the EEPROM. So, the value in the 1756 - * "data" parameter will be shifted out to the EEPROM one bit at a time. 1757 - * In order to do this, "data" must be broken down into bits. 1758 - **/ 1759 - static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count) 1760 - { 1761 - struct e1000_nvm_info *nvm = &hw->nvm; 1762 - u32 eecd = er32(EECD); 1763 - u32 mask; 1764 - 1765 - mask = 0x01 << (count - 1); 1766 - if (nvm->type == e1000_nvm_eeprom_spi) 1767 - eecd |= E1000_EECD_DO; 1768 - 1769 - do { 1770 - eecd &= ~E1000_EECD_DI; 1771 - 1772 - if (data & mask) 1773 - eecd |= E1000_EECD_DI; 1774 - 1775 - ew32(EECD, eecd); 1776 - e1e_flush(); 1777 - 1778 - udelay(nvm->delay_usec); 1779 - 1780 - e1000_raise_eec_clk(hw, &eecd); 1781 - e1000_lower_eec_clk(hw, &eecd); 1782 - 1783 - mask >>= 1; 1784 - } while (mask); 1785 - 1786 - eecd &= ~E1000_EECD_DI; 1787 - ew32(EECD, eecd); 1788 - } 1789 - 1790 - /** 1791 - * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM 1792 - * @hw: pointer to the HW structure 1793 - * @count: number of bits to shift in 1794 - * 1795 - * In order to read a register from the EEPROM, we need to shift 'count' bits 1796 - * in from the EEPROM. Bits are "shifted in" by raising the clock input to 1797 - * the EEPROM (setting the SK bit), and then reading the value of the data out 1798 - * "DO" bit. During this "shifting in" process the data in "DI" bit should 1799 - * always be clear. 1800 - **/ 1801 - static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count) 1802 - { 1803 - u32 eecd; 1804 - u32 i; 1805 - u16 data; 1806 - 1807 - eecd = er32(EECD); 1808 - 1809 - eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); 1810 - data = 0; 1811 - 1812 - for (i = 0; i < count; i++) { 1813 - data <<= 1; 1814 - e1000_raise_eec_clk(hw, &eecd); 1815 - 1816 - eecd = er32(EECD); 1817 - 1818 - eecd &= ~E1000_EECD_DI; 1819 - if (eecd & E1000_EECD_DO) 1820 - data |= 1; 1821 - 1822 - e1000_lower_eec_clk(hw, &eecd); 1823 - } 1824 - 1825 - return data; 1826 - } 1827 - 1828 - /** 1829 - * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion 1830 - * @hw: pointer to the HW structure 1831 - * @ee_reg: EEPROM flag for polling 1832 - * 1833 - * Polls the EEPROM status bit for either read or write completion based 1834 - * upon the value of 'ee_reg'. 1835 - **/ 1836 - s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg) 1837 - { 1838 - u32 attempts = 100000; 1839 - u32 i, reg = 0; 1840 - 1841 - for (i = 0; i < attempts; i++) { 1842 - if (ee_reg == E1000_NVM_POLL_READ) 1843 - reg = er32(EERD); 1844 - else 1845 - reg = er32(EEWR); 1846 - 1847 - if (reg & E1000_NVM_RW_REG_DONE) 1848 - return 0; 1849 - 1850 - udelay(5); 1851 - } 1852 - 1853 - return -E1000_ERR_NVM; 1854 - } 1855 - 1856 - /** 1857 - * e1000e_acquire_nvm - Generic request for access to EEPROM 1858 - * @hw: pointer to the HW structure 1859 - * 1860 - * Set the EEPROM access request bit and wait for EEPROM access grant bit. 1861 - * Return successful if access grant bit set, else clear the request for 1862 - * EEPROM access and return -E1000_ERR_NVM (-1). 1863 - **/ 1864 - s32 e1000e_acquire_nvm(struct e1000_hw *hw) 1865 - { 1866 - u32 eecd = er32(EECD); 1867 - s32 timeout = E1000_NVM_GRANT_ATTEMPTS; 1868 - 1869 - ew32(EECD, eecd | E1000_EECD_REQ); 1870 - eecd = er32(EECD); 1871 - 1872 - while (timeout) { 1873 - if (eecd & E1000_EECD_GNT) 1874 - break; 1875 - udelay(5); 1876 - eecd = er32(EECD); 1877 - timeout--; 1878 - } 1879 - 1880 - if (!timeout) { 1881 - eecd &= ~E1000_EECD_REQ; 1882 - ew32(EECD, eecd); 1883 - e_dbg("Could not acquire NVM grant\n"); 1884 - return -E1000_ERR_NVM; 1885 - } 1886 - 1887 - return 0; 1888 - } 1889 - 1890 - /** 1891 - * e1000_standby_nvm - Return EEPROM to standby state 1892 - * @hw: pointer to the HW structure 1893 - * 1894 - * Return the EEPROM to a standby state. 1895 - **/ 1896 - static void e1000_standby_nvm(struct e1000_hw *hw) 1897 - { 1898 - struct e1000_nvm_info *nvm = &hw->nvm; 1899 - u32 eecd = er32(EECD); 1900 - 1901 - if (nvm->type == e1000_nvm_eeprom_spi) { 1902 - /* Toggle CS to flush commands */ 1903 - eecd |= E1000_EECD_CS; 1904 - ew32(EECD, eecd); 1905 - e1e_flush(); 1906 - udelay(nvm->delay_usec); 1907 - eecd &= ~E1000_EECD_CS; 1908 - ew32(EECD, eecd); 1909 - e1e_flush(); 1910 - udelay(nvm->delay_usec); 1911 - } 1912 - } 1913 - 1914 - /** 1915 - * e1000_stop_nvm - Terminate EEPROM command 1916 - * @hw: pointer to the HW structure 1917 - * 1918 - * Terminates the current command by inverting the EEPROM's chip select pin. 1919 - **/ 1920 - static void e1000_stop_nvm(struct e1000_hw *hw) 1921 - { 1922 - u32 eecd; 1923 - 1924 - eecd = er32(EECD); 1925 - if (hw->nvm.type == e1000_nvm_eeprom_spi) { 1926 - /* Pull CS high */ 1927 - eecd |= E1000_EECD_CS; 1928 - e1000_lower_eec_clk(hw, &eecd); 1929 - } 1930 - } 1931 - 1932 - /** 1933 - * e1000e_release_nvm - Release exclusive access to EEPROM 1934 - * @hw: pointer to the HW structure 1935 - * 1936 - * Stop any current commands to the EEPROM and clear the EEPROM request bit. 1937 - **/ 1938 - void e1000e_release_nvm(struct e1000_hw *hw) 1939 - { 1940 - u32 eecd; 1941 - 1942 - e1000_stop_nvm(hw); 1943 - 1944 - eecd = er32(EECD); 1945 - eecd &= ~E1000_EECD_REQ; 1946 - ew32(EECD, eecd); 1947 - } 1948 - 1949 - /** 1950 - * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write 1951 - * @hw: pointer to the HW structure 1952 - * 1953 - * Setups the EEPROM for reading and writing. 1954 - **/ 1955 - static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw) 1956 - { 1957 - struct e1000_nvm_info *nvm = &hw->nvm; 1958 - u32 eecd = er32(EECD); 1959 - u8 spi_stat_reg; 1960 - 1961 - if (nvm->type == e1000_nvm_eeprom_spi) { 1962 - u16 timeout = NVM_MAX_RETRY_SPI; 1963 - 1964 - /* Clear SK and CS */ 1965 - eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); 1966 - ew32(EECD, eecd); 1967 - e1e_flush(); 1968 - udelay(1); 1969 - 1970 - /* 1971 - * Read "Status Register" repeatedly until the LSB is cleared. 1972 - * The EEPROM will signal that the command has been completed 1973 - * by clearing bit 0 of the internal status register. If it's 1974 - * not cleared within 'timeout', then error out. 1975 - */ 1976 - while (timeout) { 1977 - e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI, 1978 - hw->nvm.opcode_bits); 1979 - spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8); 1980 - if (!(spi_stat_reg & NVM_STATUS_RDY_SPI)) 1981 - break; 1982 - 1983 - udelay(5); 1984 - e1000_standby_nvm(hw); 1985 - timeout--; 1986 - } 1987 - 1988 - if (!timeout) { 1989 - e_dbg("SPI NVM Status error\n"); 1990 - return -E1000_ERR_NVM; 1991 - } 1992 - } 1993 - 1994 - return 0; 1995 - } 1996 - 1997 - /** 1998 - * e1000e_read_nvm_eerd - Reads EEPROM using EERD register 1999 - * @hw: pointer to the HW structure 2000 - * @offset: offset of word in the EEPROM to read 2001 - * @words: number of words to read 2002 - * @data: word read from the EEPROM 2003 - * 2004 - * Reads a 16 bit word from the EEPROM using the EERD register. 2005 - **/ 2006 - s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 2007 - { 2008 - struct e1000_nvm_info *nvm = &hw->nvm; 2009 - u32 i, eerd = 0; 2010 - s32 ret_val = 0; 2011 - 2012 - /* 2013 - * A check for invalid values: offset too large, too many words, 2014 - * too many words for the offset, and not enough words. 2015 - */ 2016 - if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 2017 - (words == 0)) { 2018 - e_dbg("nvm parameter(s) out of bounds\n"); 2019 - return -E1000_ERR_NVM; 2020 - } 2021 - 2022 - for (i = 0; i < words; i++) { 2023 - eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) + 2024 - E1000_NVM_RW_REG_START; 2025 - 2026 - ew32(EERD, eerd); 2027 - ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ); 2028 - if (ret_val) 2029 - break; 2030 - 2031 - data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA); 2032 - } 2033 - 2034 - return ret_val; 2035 - } 2036 - 2037 - /** 2038 - * e1000e_write_nvm_spi - Write to EEPROM using SPI 2039 - * @hw: pointer to the HW structure 2040 - * @offset: offset within the EEPROM to be written to 2041 - * @words: number of words to write 2042 - * @data: 16 bit word(s) to be written to the EEPROM 2043 - * 2044 - * Writes data to EEPROM at offset using SPI interface. 2045 - * 2046 - * If e1000e_update_nvm_checksum is not called after this function , the 2047 - * EEPROM will most likely contain an invalid checksum. 2048 - **/ 2049 - s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 2050 - { 2051 - struct e1000_nvm_info *nvm = &hw->nvm; 2052 - s32 ret_val; 2053 - u16 widx = 0; 2054 - 2055 - /* 2056 - * A check for invalid values: offset too large, too many words, 2057 - * and not enough words. 2058 - */ 2059 - if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 2060 - (words == 0)) { 2061 - e_dbg("nvm parameter(s) out of bounds\n"); 2062 - return -E1000_ERR_NVM; 2063 - } 2064 - 2065 - ret_val = nvm->ops.acquire(hw); 2066 - if (ret_val) 2067 - return ret_val; 2068 - 2069 - while (widx < words) { 2070 - u8 write_opcode = NVM_WRITE_OPCODE_SPI; 2071 - 2072 - ret_val = e1000_ready_nvm_eeprom(hw); 2073 - if (ret_val) { 2074 - nvm->ops.release(hw); 2075 - return ret_val; 2076 - } 2077 - 2078 - e1000_standby_nvm(hw); 2079 - 2080 - /* Send the WRITE ENABLE command (8 bit opcode) */ 2081 - e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI, 2082 - nvm->opcode_bits); 2083 - 2084 - e1000_standby_nvm(hw); 2085 - 2086 - /* 2087 - * Some SPI eeproms use the 8th address bit embedded in the 2088 - * opcode 2089 - */ 2090 - if ((nvm->address_bits == 8) && (offset >= 128)) 2091 - write_opcode |= NVM_A8_OPCODE_SPI; 2092 - 2093 - /* Send the Write command (8-bit opcode + addr) */ 2094 - e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits); 2095 - e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2), 2096 - nvm->address_bits); 2097 - 2098 - /* Loop to allow for up to whole page write of eeprom */ 2099 - while (widx < words) { 2100 - u16 word_out = data[widx]; 2101 - word_out = (word_out >> 8) | (word_out << 8); 2102 - e1000_shift_out_eec_bits(hw, word_out, 16); 2103 - widx++; 2104 - 2105 - if ((((offset + widx) * 2) % nvm->page_size) == 0) { 2106 - e1000_standby_nvm(hw); 2107 - break; 2108 - } 2109 - } 2110 - } 2111 - 2112 - usleep_range(10000, 20000); 2113 - nvm->ops.release(hw); 2114 - return 0; 2115 - } 2116 - 2117 - /** 2118 - * e1000_read_pba_string_generic - Read device part number 2119 - * @hw: pointer to the HW structure 2120 - * @pba_num: pointer to device part number 2121 - * @pba_num_size: size of part number buffer 2122 - * 2123 - * Reads the product board assembly (PBA) number from the EEPROM and stores 2124 - * the value in pba_num. 2125 - **/ 2126 - s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num, 2127 - u32 pba_num_size) 2128 - { 2129 - s32 ret_val; 2130 - u16 nvm_data; 2131 - u16 pba_ptr; 2132 - u16 offset; 2133 - u16 length; 2134 - 2135 - if (pba_num == NULL) { 2136 - e_dbg("PBA string buffer was null\n"); 2137 - ret_val = E1000_ERR_INVALID_ARGUMENT; 2138 - goto out; 2139 - } 2140 - 2141 - ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data); 2142 - if (ret_val) { 2143 - e_dbg("NVM Read Error\n"); 2144 - goto out; 2145 - } 2146 - 2147 - ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr); 2148 - if (ret_val) { 2149 - e_dbg("NVM Read Error\n"); 2150 - goto out; 2151 - } 2152 - 2153 - /* 2154 - * if nvm_data is not ptr guard the PBA must be in legacy format which 2155 - * means pba_ptr is actually our second data word for the PBA number 2156 - * and we can decode it into an ascii string 2157 - */ 2158 - if (nvm_data != NVM_PBA_PTR_GUARD) { 2159 - e_dbg("NVM PBA number is not stored as string\n"); 2160 - 2161 - /* we will need 11 characters to store the PBA */ 2162 - if (pba_num_size < 11) { 2163 - e_dbg("PBA string buffer too small\n"); 2164 - return E1000_ERR_NO_SPACE; 2165 - } 2166 - 2167 - /* extract hex string from data and pba_ptr */ 2168 - pba_num[0] = (nvm_data >> 12) & 0xF; 2169 - pba_num[1] = (nvm_data >> 8) & 0xF; 2170 - pba_num[2] = (nvm_data >> 4) & 0xF; 2171 - pba_num[3] = nvm_data & 0xF; 2172 - pba_num[4] = (pba_ptr >> 12) & 0xF; 2173 - pba_num[5] = (pba_ptr >> 8) & 0xF; 2174 - pba_num[6] = '-'; 2175 - pba_num[7] = 0; 2176 - pba_num[8] = (pba_ptr >> 4) & 0xF; 2177 - pba_num[9] = pba_ptr & 0xF; 2178 - 2179 - /* put a null character on the end of our string */ 2180 - pba_num[10] = '\0'; 2181 - 2182 - /* switch all the data but the '-' to hex char */ 2183 - for (offset = 0; offset < 10; offset++) { 2184 - if (pba_num[offset] < 0xA) 2185 - pba_num[offset] += '0'; 2186 - else if (pba_num[offset] < 0x10) 2187 - pba_num[offset] += 'A' - 0xA; 2188 - } 2189 - 2190 - goto out; 2191 - } 2192 - 2193 - ret_val = e1000_read_nvm(hw, pba_ptr, 1, &length); 2194 - if (ret_val) { 2195 - e_dbg("NVM Read Error\n"); 2196 - goto out; 2197 - } 2198 - 2199 - if (length == 0xFFFF || length == 0) { 2200 - e_dbg("NVM PBA number section invalid length\n"); 2201 - ret_val = E1000_ERR_NVM_PBA_SECTION; 2202 - goto out; 2203 - } 2204 - /* check if pba_num buffer is big enough */ 2205 - if (pba_num_size < (((u32)length * 2) - 1)) { 2206 - e_dbg("PBA string buffer too small\n"); 2207 - ret_val = E1000_ERR_NO_SPACE; 2208 - goto out; 2209 - } 2210 - 2211 - /* trim pba length from start of string */ 2212 - pba_ptr++; 2213 - length--; 2214 - 2215 - for (offset = 0; offset < length; offset++) { 2216 - ret_val = e1000_read_nvm(hw, pba_ptr + offset, 1, &nvm_data); 2217 - if (ret_val) { 2218 - e_dbg("NVM Read Error\n"); 2219 - goto out; 2220 - } 2221 - pba_num[offset * 2] = (u8)(nvm_data >> 8); 2222 - pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF); 2223 - } 2224 - pba_num[offset * 2] = '\0'; 2225 - 2226 - out: 2227 - return ret_val; 2228 - } 2229 - 2230 - /** 2231 - * e1000_read_mac_addr_generic - Read device MAC address 2232 - * @hw: pointer to the HW structure 2233 - * 2234 - * Reads the device MAC address from the EEPROM and stores the value. 2235 - * Since devices with two ports use the same EEPROM, we increment the 2236 - * last bit in the MAC address for the second port. 2237 - **/ 2238 - s32 e1000_read_mac_addr_generic(struct e1000_hw *hw) 2239 - { 2240 - u32 rar_high; 2241 - u32 rar_low; 2242 - u16 i; 2243 - 2244 - rar_high = er32(RAH(0)); 2245 - rar_low = er32(RAL(0)); 2246 - 2247 - for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++) 2248 - hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8)); 2249 - 2250 - for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++) 2251 - hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8)); 2252 - 2253 - for (i = 0; i < ETH_ALEN; i++) 2254 - hw->mac.addr[i] = hw->mac.perm_addr[i]; 2255 - 2256 - return 0; 2257 - } 2258 - 2259 - /** 2260 - * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum 2261 - * @hw: pointer to the HW structure 2262 - * 2263 - * Calculates the EEPROM checksum by reading/adding each word of the EEPROM 2264 - * and then verifies that the sum of the EEPROM is equal to 0xBABA. 2265 - **/ 2266 - s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw) 2267 - { 2268 - s32 ret_val; 2269 - u16 checksum = 0; 2270 - u16 i, nvm_data; 2271 - 2272 - for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { 2273 - ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); 2274 - if (ret_val) { 2275 - e_dbg("NVM Read Error\n"); 2276 - return ret_val; 2277 - } 2278 - checksum += nvm_data; 2279 - } 2280 - 2281 - if (checksum != (u16) NVM_SUM) { 2282 - e_dbg("NVM Checksum Invalid\n"); 2283 - return -E1000_ERR_NVM; 2284 - } 2285 - 2286 - return 0; 2287 - } 2288 - 2289 - /** 2290 - * e1000e_update_nvm_checksum_generic - Update EEPROM checksum 2291 - * @hw: pointer to the HW structure 2292 - * 2293 - * Updates the EEPROM checksum by reading/adding each word of the EEPROM 2294 - * up to the checksum. Then calculates the EEPROM checksum and writes the 2295 - * value to the EEPROM. 2296 - **/ 2297 - s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw) 2298 - { 2299 - s32 ret_val; 2300 - u16 checksum = 0; 2301 - u16 i, nvm_data; 2302 - 2303 - for (i = 0; i < NVM_CHECKSUM_REG; i++) { 2304 - ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); 2305 - if (ret_val) { 2306 - e_dbg("NVM Read Error while updating checksum.\n"); 2307 - return ret_val; 2308 - } 2309 - checksum += nvm_data; 2310 - } 2311 - checksum = (u16) NVM_SUM - checksum; 2312 - ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum); 2313 - if (ret_val) 2314 - e_dbg("NVM Write Error while updating checksum.\n"); 2315 - 2316 - return ret_val; 2317 - } 2318 - 2319 - /** 2320 - * e1000e_reload_nvm - Reloads EEPROM 2321 - * @hw: pointer to the HW structure 2322 - * 2323 - * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the 2324 - * extended control register. 2325 - **/ 2326 - void e1000e_reload_nvm(struct e1000_hw *hw) 2327 - { 2328 - u32 ctrl_ext; 2329 - 2330 - udelay(10); 2331 - ctrl_ext = er32(CTRL_EXT); 2332 - ctrl_ext |= E1000_CTRL_EXT_EE_RST; 2333 - ew32(CTRL_EXT, ctrl_ext); 2334 - e1e_flush(); 2335 - } 2336 - 2337 - /** 2338 - * e1000_calculate_checksum - Calculate checksum for buffer 2339 - * @buffer: pointer to EEPROM 2340 - * @length: size of EEPROM to calculate a checksum for 2341 - * 2342 - * Calculates the checksum for some buffer on a specified length. The 2343 - * checksum calculated is returned. 2344 - **/ 2345 - static u8 e1000_calculate_checksum(u8 *buffer, u32 length) 2346 - { 2347 - u32 i; 2348 - u8 sum = 0; 2349 - 2350 - if (!buffer) 2351 - return 0; 2352 - 2353 - for (i = 0; i < length; i++) 2354 - sum += buffer[i]; 2355 - 2356 - return (u8) (0 - sum); 2357 - } 2358 - 2359 - /** 2360 - * e1000_mng_enable_host_if - Checks host interface is enabled 2361 - * @hw: pointer to the HW structure 2362 - * 2363 - * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND 2364 - * 2365 - * This function checks whether the HOST IF is enabled for command operation 2366 - * and also checks whether the previous command is completed. It busy waits 2367 - * in case of previous command is not completed. 2368 - **/ 2369 - static s32 e1000_mng_enable_host_if(struct e1000_hw *hw) 2370 - { 2371 - u32 hicr; 2372 - u8 i; 2373 - 2374 - if (!(hw->mac.arc_subsystem_valid)) { 2375 - e_dbg("ARC subsystem not valid.\n"); 2376 - return -E1000_ERR_HOST_INTERFACE_COMMAND; 2377 - } 2378 - 2379 - /* Check that the host interface is enabled. */ 2380 - hicr = er32(HICR); 2381 - if ((hicr & E1000_HICR_EN) == 0) { 2382 - e_dbg("E1000_HOST_EN bit disabled.\n"); 2383 - return -E1000_ERR_HOST_INTERFACE_COMMAND; 2384 - } 2385 - /* check the previous command is completed */ 2386 - for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) { 2387 - hicr = er32(HICR); 2388 - if (!(hicr & E1000_HICR_C)) 2389 - break; 2390 - mdelay(1); 2391 - } 2392 - 2393 - if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) { 2394 - e_dbg("Previous command timeout failed .\n"); 2395 - return -E1000_ERR_HOST_INTERFACE_COMMAND; 2396 - } 2397 - 2398 - return 0; 2399 - } 2400 - 2401 - /** 2402 - * e1000e_check_mng_mode_generic - check management mode 2403 - * @hw: pointer to the HW structure 2404 - * 2405 - * Reads the firmware semaphore register and returns true (>0) if 2406 - * manageability is enabled, else false (0). 2407 - **/ 2408 - bool e1000e_check_mng_mode_generic(struct e1000_hw *hw) 2409 - { 2410 - u32 fwsm = er32(FWSM); 2411 - 2412 - return (fwsm & E1000_FWSM_MODE_MASK) == 2413 - (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT); 2414 - } 2415 - 2416 - /** 2417 - * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx 2418 - * @hw: pointer to the HW structure 2419 - * 2420 - * Enables packet filtering on transmit packets if manageability is enabled 2421 - * and host interface is enabled. 2422 - **/ 2423 - bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw) 2424 - { 2425 - struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie; 2426 - u32 *buffer = (u32 *)&hw->mng_cookie; 2427 - u32 offset; 2428 - s32 ret_val, hdr_csum, csum; 2429 - u8 i, len; 2430 - 2431 - hw->mac.tx_pkt_filtering = true; 2432 - 2433 - /* No manageability, no filtering */ 2434 - if (!e1000e_check_mng_mode(hw)) { 2435 - hw->mac.tx_pkt_filtering = false; 2436 - goto out; 2437 - } 2438 - 2439 - /* 2440 - * If we can't read from the host interface for whatever 2441 - * reason, disable filtering. 2442 - */ 2443 - ret_val = e1000_mng_enable_host_if(hw); 2444 - if (ret_val) { 2445 - hw->mac.tx_pkt_filtering = false; 2446 - goto out; 2447 - } 2448 - 2449 - /* Read in the header. Length and offset are in dwords. */ 2450 - len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2; 2451 - offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2; 2452 - for (i = 0; i < len; i++) 2453 - *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset + i); 2454 - hdr_csum = hdr->checksum; 2455 - hdr->checksum = 0; 2456 - csum = e1000_calculate_checksum((u8 *)hdr, 2457 - E1000_MNG_DHCP_COOKIE_LENGTH); 2458 - /* 2459 - * If either the checksums or signature don't match, then 2460 - * the cookie area isn't considered valid, in which case we 2461 - * take the safe route of assuming Tx filtering is enabled. 2462 - */ 2463 - if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) { 2464 - hw->mac.tx_pkt_filtering = true; 2465 - goto out; 2466 - } 2467 - 2468 - /* Cookie area is valid, make the final check for filtering. */ 2469 - if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) { 2470 - hw->mac.tx_pkt_filtering = false; 2471 - goto out; 2472 - } 2473 - 2474 - out: 2475 - return hw->mac.tx_pkt_filtering; 2476 - } 2477 - 2478 - /** 2479 - * e1000_mng_write_cmd_header - Writes manageability command header 2480 - * @hw: pointer to the HW structure 2481 - * @hdr: pointer to the host interface command header 2482 - * 2483 - * Writes the command header after does the checksum calculation. 2484 - **/ 2485 - static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw, 2486 - struct e1000_host_mng_command_header *hdr) 2487 - { 2488 - u16 i, length = sizeof(struct e1000_host_mng_command_header); 2489 - 2490 - /* Write the whole command header structure with new checksum. */ 2491 - 2492 - hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length); 2493 - 2494 - length >>= 2; 2495 - /* Write the relevant command block into the ram area. */ 2496 - for (i = 0; i < length; i++) { 2497 - E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i, 2498 - *((u32 *) hdr + i)); 2499 - e1e_flush(); 2500 - } 2501 - 2502 - return 0; 2503 - } 2504 - 2505 - /** 2506 - * e1000_mng_host_if_write - Write to the manageability host interface 2507 - * @hw: pointer to the HW structure 2508 - * @buffer: pointer to the host interface buffer 2509 - * @length: size of the buffer 2510 - * @offset: location in the buffer to write to 2511 - * @sum: sum of the data (not checksum) 2512 - * 2513 - * This function writes the buffer content at the offset given on the host if. 2514 - * It also does alignment considerations to do the writes in most efficient 2515 - * way. Also fills up the sum of the buffer in *buffer parameter. 2516 - **/ 2517 - static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, 2518 - u16 length, u16 offset, u8 *sum) 2519 - { 2520 - u8 *tmp; 2521 - u8 *bufptr = buffer; 2522 - u32 data = 0; 2523 - u16 remaining, i, j, prev_bytes; 2524 - 2525 - /* sum = only sum of the data and it is not checksum */ 2526 - 2527 - if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) 2528 - return -E1000_ERR_PARAM; 2529 - 2530 - tmp = (u8 *)&data; 2531 - prev_bytes = offset & 0x3; 2532 - offset >>= 2; 2533 - 2534 - if (prev_bytes) { 2535 - data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset); 2536 - for (j = prev_bytes; j < sizeof(u32); j++) { 2537 - *(tmp + j) = *bufptr++; 2538 - *sum += *(tmp + j); 2539 - } 2540 - E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data); 2541 - length -= j - prev_bytes; 2542 - offset++; 2543 - } 2544 - 2545 - remaining = length & 0x3; 2546 - length -= remaining; 2547 - 2548 - /* Calculate length in DWORDs */ 2549 - length >>= 2; 2550 - 2551 - /* 2552 - * The device driver writes the relevant command block into the 2553 - * ram area. 2554 - */ 2555 - for (i = 0; i < length; i++) { 2556 - for (j = 0; j < sizeof(u32); j++) { 2557 - *(tmp + j) = *bufptr++; 2558 - *sum += *(tmp + j); 2559 - } 2560 - 2561 - E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); 2562 - } 2563 - if (remaining) { 2564 - for (j = 0; j < sizeof(u32); j++) { 2565 - if (j < remaining) 2566 - *(tmp + j) = *bufptr++; 2567 - else 2568 - *(tmp + j) = 0; 2569 - 2570 - *sum += *(tmp + j); 2571 - } 2572 - E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); 2573 - } 2574 - 2575 - return 0; 2576 - } 2577 - 2578 - /** 2579 - * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface 2580 - * @hw: pointer to the HW structure 2581 - * @buffer: pointer to the host interface 2582 - * @length: size of the buffer 2583 - * 2584 - * Writes the DHCP information to the host interface. 2585 - **/ 2586 - s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length) 2587 - { 2588 - struct e1000_host_mng_command_header hdr; 2589 - s32 ret_val; 2590 - u32 hicr; 2591 - 2592 - hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD; 2593 - hdr.command_length = length; 2594 - hdr.reserved1 = 0; 2595 - hdr.reserved2 = 0; 2596 - hdr.checksum = 0; 2597 - 2598 - /* Enable the host interface */ 2599 - ret_val = e1000_mng_enable_host_if(hw); 2600 - if (ret_val) 2601 - return ret_val; 2602 - 2603 - /* Populate the host interface with the contents of "buffer". */ 2604 - ret_val = e1000_mng_host_if_write(hw, buffer, length, 2605 - sizeof(hdr), &(hdr.checksum)); 2606 - if (ret_val) 2607 - return ret_val; 2608 - 2609 - /* Write the manageability command header */ 2610 - ret_val = e1000_mng_write_cmd_header(hw, &hdr); 2611 - if (ret_val) 2612 - return ret_val; 2613 - 2614 - /* Tell the ARC a new command is pending. */ 2615 - hicr = er32(HICR); 2616 - ew32(HICR, hicr | E1000_HICR_C); 2617 - 2618 - return 0; 2619 - } 2620 - 2621 - /** 2622 - * e1000e_enable_mng_pass_thru - Check if management passthrough is needed 2623 - * @hw: pointer to the HW structure 2624 - * 2625 - * Verifies the hardware needs to leave interface enabled so that frames can 2626 - * be directed to and from the management interface. 2627 - **/ 2628 - bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw) 2629 - { 2630 - u32 manc; 2631 - u32 fwsm, factps; 2632 - bool ret_val = false; 2633 - 2634 - manc = er32(MANC); 2635 - 2636 - if (!(manc & E1000_MANC_RCV_TCO_EN)) 2637 - goto out; 2638 - 2639 - if (hw->mac.has_fwsm) { 2640 - fwsm = er32(FWSM); 2641 - factps = er32(FACTPS); 2642 - 2643 - if (!(factps & E1000_FACTPS_MNGCG) && 2644 - ((fwsm & E1000_FWSM_MODE_MASK) == 2645 - (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) { 2646 - ret_val = true; 2647 - goto out; 2648 - } 2649 - } else if ((hw->mac.type == e1000_82574) || 2650 - (hw->mac.type == e1000_82583)) { 2651 - u16 data; 2652 - 2653 - factps = er32(FACTPS); 2654 - e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data); 2655 - 2656 - if (!(factps & E1000_FACTPS_MNGCG) && 2657 - ((data & E1000_NVM_INIT_CTRL2_MNGM) == 2658 - (e1000_mng_mode_pt << 13))) { 2659 - ret_val = true; 2660 - goto out; 2661 - } 2662 - } else if ((manc & E1000_MANC_SMBUS_EN) && 2663 - !(manc & E1000_MANC_ASF_EN)) { 2664 - ret_val = true; 2665 - goto out; 2666 - } 2667 - 2668 - out: 2669 - return ret_val; 2670 1733 }
+377
drivers/net/ethernet/intel/e1000e/manage.c
··· 1 + /******************************************************************************* 2 + 3 + Intel PRO/1000 Linux driver 4 + Copyright(c) 1999 - 2011 Intel Corporation. 5 + 6 + This program is free software; you can redistribute it and/or modify it 7 + under the terms and conditions of the GNU General Public License, 8 + version 2, as published by the Free Software Foundation. 9 + 10 + This program is distributed in the hope it will be useful, but WITHOUT 11 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + more details. 14 + 15 + You should have received a copy of the GNU General Public License along with 16 + this program; if not, write to the Free Software Foundation, Inc., 17 + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 + 19 + The full GNU General Public License is included in this distribution in 20 + the file called "COPYING". 21 + 22 + Contact Information: 23 + Linux NICS <linux.nics@intel.com> 24 + e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 25 + Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 26 + 27 + *******************************************************************************/ 28 + 29 + #include "e1000.h" 30 + 31 + enum e1000_mng_mode { 32 + e1000_mng_mode_none = 0, 33 + e1000_mng_mode_asf, 34 + e1000_mng_mode_pt, 35 + e1000_mng_mode_ipmi, 36 + e1000_mng_mode_host_if_only 37 + }; 38 + 39 + #define E1000_FACTPS_MNGCG 0x20000000 40 + 41 + /* Intel(R) Active Management Technology signature */ 42 + #define E1000_IAMT_SIGNATURE 0x544D4149 43 + 44 + /** 45 + * e1000_calculate_checksum - Calculate checksum for buffer 46 + * @buffer: pointer to EEPROM 47 + * @length: size of EEPROM to calculate a checksum for 48 + * 49 + * Calculates the checksum for some buffer on a specified length. The 50 + * checksum calculated is returned. 51 + **/ 52 + static u8 e1000_calculate_checksum(u8 *buffer, u32 length) 53 + { 54 + u32 i; 55 + u8 sum = 0; 56 + 57 + if (!buffer) 58 + return 0; 59 + 60 + for (i = 0; i < length; i++) 61 + sum += buffer[i]; 62 + 63 + return (u8)(0 - sum); 64 + } 65 + 66 + /** 67 + * e1000_mng_enable_host_if - Checks host interface is enabled 68 + * @hw: pointer to the HW structure 69 + * 70 + * Returns E1000_success upon success, else E1000_ERR_HOST_INTERFACE_COMMAND 71 + * 72 + * This function checks whether the HOST IF is enabled for command operation 73 + * and also checks whether the previous command is completed. It busy waits 74 + * in case of previous command is not completed. 75 + **/ 76 + static s32 e1000_mng_enable_host_if(struct e1000_hw *hw) 77 + { 78 + u32 hicr; 79 + u8 i; 80 + 81 + if (!(hw->mac.arc_subsystem_valid)) { 82 + e_dbg("ARC subsystem not valid.\n"); 83 + return -E1000_ERR_HOST_INTERFACE_COMMAND; 84 + } 85 + 86 + /* Check that the host interface is enabled. */ 87 + hicr = er32(HICR); 88 + if ((hicr & E1000_HICR_EN) == 0) { 89 + e_dbg("E1000_HOST_EN bit disabled.\n"); 90 + return -E1000_ERR_HOST_INTERFACE_COMMAND; 91 + } 92 + /* check the previous command is completed */ 93 + for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) { 94 + hicr = er32(HICR); 95 + if (!(hicr & E1000_HICR_C)) 96 + break; 97 + mdelay(1); 98 + } 99 + 100 + if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) { 101 + e_dbg("Previous command timeout failed .\n"); 102 + return -E1000_ERR_HOST_INTERFACE_COMMAND; 103 + } 104 + 105 + return 0; 106 + } 107 + 108 + /** 109 + * e1000e_check_mng_mode_generic - check management mode 110 + * @hw: pointer to the HW structure 111 + * 112 + * Reads the firmware semaphore register and returns true (>0) if 113 + * manageability is enabled, else false (0). 114 + **/ 115 + bool e1000e_check_mng_mode_generic(struct e1000_hw *hw) 116 + { 117 + u32 fwsm = er32(FWSM); 118 + 119 + return (fwsm & E1000_FWSM_MODE_MASK) == 120 + (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT); 121 + } 122 + 123 + /** 124 + * e1000e_enable_tx_pkt_filtering - Enable packet filtering on Tx 125 + * @hw: pointer to the HW structure 126 + * 127 + * Enables packet filtering on transmit packets if manageability is enabled 128 + * and host interface is enabled. 129 + **/ 130 + bool e1000e_enable_tx_pkt_filtering(struct e1000_hw *hw) 131 + { 132 + struct e1000_host_mng_dhcp_cookie *hdr = &hw->mng_cookie; 133 + u32 *buffer = (u32 *)&hw->mng_cookie; 134 + u32 offset; 135 + s32 ret_val, hdr_csum, csum; 136 + u8 i, len; 137 + 138 + hw->mac.tx_pkt_filtering = true; 139 + 140 + /* No manageability, no filtering */ 141 + if (!e1000e_check_mng_mode(hw)) { 142 + hw->mac.tx_pkt_filtering = false; 143 + goto out; 144 + } 145 + 146 + /* 147 + * If we can't read from the host interface for whatever 148 + * reason, disable filtering. 149 + */ 150 + ret_val = e1000_mng_enable_host_if(hw); 151 + if (ret_val) { 152 + hw->mac.tx_pkt_filtering = false; 153 + goto out; 154 + } 155 + 156 + /* Read in the header. Length and offset are in dwords. */ 157 + len = E1000_MNG_DHCP_COOKIE_LENGTH >> 2; 158 + offset = E1000_MNG_DHCP_COOKIE_OFFSET >> 2; 159 + for (i = 0; i < len; i++) 160 + *(buffer + i) = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, 161 + offset + i); 162 + hdr_csum = hdr->checksum; 163 + hdr->checksum = 0; 164 + csum = e1000_calculate_checksum((u8 *)hdr, 165 + E1000_MNG_DHCP_COOKIE_LENGTH); 166 + /* 167 + * If either the checksums or signature don't match, then 168 + * the cookie area isn't considered valid, in which case we 169 + * take the safe route of assuming Tx filtering is enabled. 170 + */ 171 + if ((hdr_csum != csum) || (hdr->signature != E1000_IAMT_SIGNATURE)) { 172 + hw->mac.tx_pkt_filtering = true; 173 + goto out; 174 + } 175 + 176 + /* Cookie area is valid, make the final check for filtering. */ 177 + if (!(hdr->status & E1000_MNG_DHCP_COOKIE_STATUS_PARSING)) { 178 + hw->mac.tx_pkt_filtering = false; 179 + goto out; 180 + } 181 + 182 + out: 183 + return hw->mac.tx_pkt_filtering; 184 + } 185 + 186 + /** 187 + * e1000_mng_write_cmd_header - Writes manageability command header 188 + * @hw: pointer to the HW structure 189 + * @hdr: pointer to the host interface command header 190 + * 191 + * Writes the command header after does the checksum calculation. 192 + **/ 193 + static s32 e1000_mng_write_cmd_header(struct e1000_hw *hw, 194 + struct e1000_host_mng_command_header *hdr) 195 + { 196 + u16 i, length = sizeof(struct e1000_host_mng_command_header); 197 + 198 + /* Write the whole command header structure with new checksum. */ 199 + 200 + hdr->checksum = e1000_calculate_checksum((u8 *)hdr, length); 201 + 202 + length >>= 2; 203 + /* Write the relevant command block into the ram area. */ 204 + for (i = 0; i < length; i++) { 205 + E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, i, *((u32 *)hdr + i)); 206 + e1e_flush(); 207 + } 208 + 209 + return 0; 210 + } 211 + 212 + /** 213 + * e1000_mng_host_if_write - Write to the manageability host interface 214 + * @hw: pointer to the HW structure 215 + * @buffer: pointer to the host interface buffer 216 + * @length: size of the buffer 217 + * @offset: location in the buffer to write to 218 + * @sum: sum of the data (not checksum) 219 + * 220 + * This function writes the buffer content at the offset given on the host if. 221 + * It also does alignment considerations to do the writes in most efficient 222 + * way. Also fills up the sum of the buffer in *buffer parameter. 223 + **/ 224 + static s32 e1000_mng_host_if_write(struct e1000_hw *hw, u8 *buffer, 225 + u16 length, u16 offset, u8 *sum) 226 + { 227 + u8 *tmp; 228 + u8 *bufptr = buffer; 229 + u32 data = 0; 230 + u16 remaining, i, j, prev_bytes; 231 + 232 + /* sum = only sum of the data and it is not checksum */ 233 + 234 + if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) 235 + return -E1000_ERR_PARAM; 236 + 237 + tmp = (u8 *)&data; 238 + prev_bytes = offset & 0x3; 239 + offset >>= 2; 240 + 241 + if (prev_bytes) { 242 + data = E1000_READ_REG_ARRAY(hw, E1000_HOST_IF, offset); 243 + for (j = prev_bytes; j < sizeof(u32); j++) { 244 + *(tmp + j) = *bufptr++; 245 + *sum += *(tmp + j); 246 + } 247 + E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset, data); 248 + length -= j - prev_bytes; 249 + offset++; 250 + } 251 + 252 + remaining = length & 0x3; 253 + length -= remaining; 254 + 255 + /* Calculate length in DWORDs */ 256 + length >>= 2; 257 + 258 + /* 259 + * The device driver writes the relevant command block into the 260 + * ram area. 261 + */ 262 + for (i = 0; i < length; i++) { 263 + for (j = 0; j < sizeof(u32); j++) { 264 + *(tmp + j) = *bufptr++; 265 + *sum += *(tmp + j); 266 + } 267 + 268 + E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); 269 + } 270 + if (remaining) { 271 + for (j = 0; j < sizeof(u32); j++) { 272 + if (j < remaining) 273 + *(tmp + j) = *bufptr++; 274 + else 275 + *(tmp + j) = 0; 276 + 277 + *sum += *(tmp + j); 278 + } 279 + E1000_WRITE_REG_ARRAY(hw, E1000_HOST_IF, offset + i, data); 280 + } 281 + 282 + return 0; 283 + } 284 + 285 + /** 286 + * e1000e_mng_write_dhcp_info - Writes DHCP info to host interface 287 + * @hw: pointer to the HW structure 288 + * @buffer: pointer to the host interface 289 + * @length: size of the buffer 290 + * 291 + * Writes the DHCP information to the host interface. 292 + **/ 293 + s32 e1000e_mng_write_dhcp_info(struct e1000_hw *hw, u8 *buffer, u16 length) 294 + { 295 + struct e1000_host_mng_command_header hdr; 296 + s32 ret_val; 297 + u32 hicr; 298 + 299 + hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD; 300 + hdr.command_length = length; 301 + hdr.reserved1 = 0; 302 + hdr.reserved2 = 0; 303 + hdr.checksum = 0; 304 + 305 + /* Enable the host interface */ 306 + ret_val = e1000_mng_enable_host_if(hw); 307 + if (ret_val) 308 + return ret_val; 309 + 310 + /* Populate the host interface with the contents of "buffer". */ 311 + ret_val = e1000_mng_host_if_write(hw, buffer, length, 312 + sizeof(hdr), &(hdr.checksum)); 313 + if (ret_val) 314 + return ret_val; 315 + 316 + /* Write the manageability command header */ 317 + ret_val = e1000_mng_write_cmd_header(hw, &hdr); 318 + if (ret_val) 319 + return ret_val; 320 + 321 + /* Tell the ARC a new command is pending. */ 322 + hicr = er32(HICR); 323 + ew32(HICR, hicr | E1000_HICR_C); 324 + 325 + return 0; 326 + } 327 + 328 + /** 329 + * e1000e_enable_mng_pass_thru - Check if management passthrough is needed 330 + * @hw: pointer to the HW structure 331 + * 332 + * Verifies the hardware needs to leave interface enabled so that frames can 333 + * be directed to and from the management interface. 334 + **/ 335 + bool e1000e_enable_mng_pass_thru(struct e1000_hw *hw) 336 + { 337 + u32 manc; 338 + u32 fwsm, factps; 339 + bool ret_val = false; 340 + 341 + manc = er32(MANC); 342 + 343 + if (!(manc & E1000_MANC_RCV_TCO_EN)) 344 + goto out; 345 + 346 + if (hw->mac.has_fwsm) { 347 + fwsm = er32(FWSM); 348 + factps = er32(FACTPS); 349 + 350 + if (!(factps & E1000_FACTPS_MNGCG) && 351 + ((fwsm & E1000_FWSM_MODE_MASK) == 352 + (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) { 353 + ret_val = true; 354 + goto out; 355 + } 356 + } else if ((hw->mac.type == e1000_82574) || 357 + (hw->mac.type == e1000_82583)) { 358 + u16 data; 359 + 360 + factps = er32(FACTPS); 361 + e1000_read_nvm(hw, NVM_INIT_CONTROL2_REG, 1, &data); 362 + 363 + if (!(factps & E1000_FACTPS_MNGCG) && 364 + ((data & E1000_NVM_INIT_CTRL2_MNGM) == 365 + (e1000_mng_mode_pt << 13))) { 366 + ret_val = true; 367 + goto out; 368 + } 369 + } else if ((manc & E1000_MANC_SMBUS_EN) && 370 + !(manc & E1000_MANC_ASF_EN)) { 371 + ret_val = true; 372 + goto out; 373 + } 374 + 375 + out: 376 + return ret_val; 377 + }
+647
drivers/net/ethernet/intel/e1000e/nvm.c
··· 1 + /******************************************************************************* 2 + 3 + Intel PRO/1000 Linux driver 4 + Copyright(c) 1999 - 2011 Intel Corporation. 5 + 6 + This program is free software; you can redistribute it and/or modify it 7 + under the terms and conditions of the GNU General Public License, 8 + version 2, as published by the Free Software Foundation. 9 + 10 + This program is distributed in the hope it will be useful, but WITHOUT 11 + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 + more details. 14 + 15 + You should have received a copy of the GNU General Public License along with 16 + this program; if not, write to the Free Software Foundation, Inc., 17 + 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. 18 + 19 + The full GNU General Public License is included in this distribution in 20 + the file called "COPYING". 21 + 22 + Contact Information: 23 + Linux NICS <linux.nics@intel.com> 24 + e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> 25 + Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 26 + 27 + *******************************************************************************/ 28 + 29 + #include "e1000.h" 30 + 31 + /** 32 + * e1000_raise_eec_clk - Raise EEPROM clock 33 + * @hw: pointer to the HW structure 34 + * @eecd: pointer to the EEPROM 35 + * 36 + * Enable/Raise the EEPROM clock bit. 37 + **/ 38 + static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd) 39 + { 40 + *eecd = *eecd | E1000_EECD_SK; 41 + ew32(EECD, *eecd); 42 + e1e_flush(); 43 + udelay(hw->nvm.delay_usec); 44 + } 45 + 46 + /** 47 + * e1000_lower_eec_clk - Lower EEPROM clock 48 + * @hw: pointer to the HW structure 49 + * @eecd: pointer to the EEPROM 50 + * 51 + * Clear/Lower the EEPROM clock bit. 52 + **/ 53 + static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd) 54 + { 55 + *eecd = *eecd & ~E1000_EECD_SK; 56 + ew32(EECD, *eecd); 57 + e1e_flush(); 58 + udelay(hw->nvm.delay_usec); 59 + } 60 + 61 + /** 62 + * e1000_shift_out_eec_bits - Shift data bits our to the EEPROM 63 + * @hw: pointer to the HW structure 64 + * @data: data to send to the EEPROM 65 + * @count: number of bits to shift out 66 + * 67 + * We need to shift 'count' bits out to the EEPROM. So, the value in the 68 + * "data" parameter will be shifted out to the EEPROM one bit at a time. 69 + * In order to do this, "data" must be broken down into bits. 70 + **/ 71 + static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count) 72 + { 73 + struct e1000_nvm_info *nvm = &hw->nvm; 74 + u32 eecd = er32(EECD); 75 + u32 mask; 76 + 77 + mask = 0x01 << (count - 1); 78 + if (nvm->type == e1000_nvm_eeprom_spi) 79 + eecd |= E1000_EECD_DO; 80 + 81 + do { 82 + eecd &= ~E1000_EECD_DI; 83 + 84 + if (data & mask) 85 + eecd |= E1000_EECD_DI; 86 + 87 + ew32(EECD, eecd); 88 + e1e_flush(); 89 + 90 + udelay(nvm->delay_usec); 91 + 92 + e1000_raise_eec_clk(hw, &eecd); 93 + e1000_lower_eec_clk(hw, &eecd); 94 + 95 + mask >>= 1; 96 + } while (mask); 97 + 98 + eecd &= ~E1000_EECD_DI; 99 + ew32(EECD, eecd); 100 + } 101 + 102 + /** 103 + * e1000_shift_in_eec_bits - Shift data bits in from the EEPROM 104 + * @hw: pointer to the HW structure 105 + * @count: number of bits to shift in 106 + * 107 + * In order to read a register from the EEPROM, we need to shift 'count' bits 108 + * in from the EEPROM. Bits are "shifted in" by raising the clock input to 109 + * the EEPROM (setting the SK bit), and then reading the value of the data out 110 + * "DO" bit. During this "shifting in" process the data in "DI" bit should 111 + * always be clear. 112 + **/ 113 + static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count) 114 + { 115 + u32 eecd; 116 + u32 i; 117 + u16 data; 118 + 119 + eecd = er32(EECD); 120 + 121 + eecd &= ~(E1000_EECD_DO | E1000_EECD_DI); 122 + data = 0; 123 + 124 + for (i = 0; i < count; i++) { 125 + data <<= 1; 126 + e1000_raise_eec_clk(hw, &eecd); 127 + 128 + eecd = er32(EECD); 129 + 130 + eecd &= ~E1000_EECD_DI; 131 + if (eecd & E1000_EECD_DO) 132 + data |= 1; 133 + 134 + e1000_lower_eec_clk(hw, &eecd); 135 + } 136 + 137 + return data; 138 + } 139 + 140 + /** 141 + * e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion 142 + * @hw: pointer to the HW structure 143 + * @ee_reg: EEPROM flag for polling 144 + * 145 + * Polls the EEPROM status bit for either read or write completion based 146 + * upon the value of 'ee_reg'. 147 + **/ 148 + s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg) 149 + { 150 + u32 attempts = 100000; 151 + u32 i, reg = 0; 152 + 153 + for (i = 0; i < attempts; i++) { 154 + if (ee_reg == E1000_NVM_POLL_READ) 155 + reg = er32(EERD); 156 + else 157 + reg = er32(EEWR); 158 + 159 + if (reg & E1000_NVM_RW_REG_DONE) 160 + return 0; 161 + 162 + udelay(5); 163 + } 164 + 165 + return -E1000_ERR_NVM; 166 + } 167 + 168 + /** 169 + * e1000e_acquire_nvm - Generic request for access to EEPROM 170 + * @hw: pointer to the HW structure 171 + * 172 + * Set the EEPROM access request bit and wait for EEPROM access grant bit. 173 + * Return successful if access grant bit set, else clear the request for 174 + * EEPROM access and return -E1000_ERR_NVM (-1). 175 + **/ 176 + s32 e1000e_acquire_nvm(struct e1000_hw *hw) 177 + { 178 + u32 eecd = er32(EECD); 179 + s32 timeout = E1000_NVM_GRANT_ATTEMPTS; 180 + 181 + ew32(EECD, eecd | E1000_EECD_REQ); 182 + eecd = er32(EECD); 183 + 184 + while (timeout) { 185 + if (eecd & E1000_EECD_GNT) 186 + break; 187 + udelay(5); 188 + eecd = er32(EECD); 189 + timeout--; 190 + } 191 + 192 + if (!timeout) { 193 + eecd &= ~E1000_EECD_REQ; 194 + ew32(EECD, eecd); 195 + e_dbg("Could not acquire NVM grant\n"); 196 + return -E1000_ERR_NVM; 197 + } 198 + 199 + return 0; 200 + } 201 + 202 + /** 203 + * e1000_standby_nvm - Return EEPROM to standby state 204 + * @hw: pointer to the HW structure 205 + * 206 + * Return the EEPROM to a standby state. 207 + **/ 208 + static void e1000_standby_nvm(struct e1000_hw *hw) 209 + { 210 + struct e1000_nvm_info *nvm = &hw->nvm; 211 + u32 eecd = er32(EECD); 212 + 213 + if (nvm->type == e1000_nvm_eeprom_spi) { 214 + /* Toggle CS to flush commands */ 215 + eecd |= E1000_EECD_CS; 216 + ew32(EECD, eecd); 217 + e1e_flush(); 218 + udelay(nvm->delay_usec); 219 + eecd &= ~E1000_EECD_CS; 220 + ew32(EECD, eecd); 221 + e1e_flush(); 222 + udelay(nvm->delay_usec); 223 + } 224 + } 225 + 226 + /** 227 + * e1000_stop_nvm - Terminate EEPROM command 228 + * @hw: pointer to the HW structure 229 + * 230 + * Terminates the current command by inverting the EEPROM's chip select pin. 231 + **/ 232 + static void e1000_stop_nvm(struct e1000_hw *hw) 233 + { 234 + u32 eecd; 235 + 236 + eecd = er32(EECD); 237 + if (hw->nvm.type == e1000_nvm_eeprom_spi) { 238 + /* Pull CS high */ 239 + eecd |= E1000_EECD_CS; 240 + e1000_lower_eec_clk(hw, &eecd); 241 + } 242 + } 243 + 244 + /** 245 + * e1000e_release_nvm - Release exclusive access to EEPROM 246 + * @hw: pointer to the HW structure 247 + * 248 + * Stop any current commands to the EEPROM and clear the EEPROM request bit. 249 + **/ 250 + void e1000e_release_nvm(struct e1000_hw *hw) 251 + { 252 + u32 eecd; 253 + 254 + e1000_stop_nvm(hw); 255 + 256 + eecd = er32(EECD); 257 + eecd &= ~E1000_EECD_REQ; 258 + ew32(EECD, eecd); 259 + } 260 + 261 + /** 262 + * e1000_ready_nvm_eeprom - Prepares EEPROM for read/write 263 + * @hw: pointer to the HW structure 264 + * 265 + * Setups the EEPROM for reading and writing. 266 + **/ 267 + static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw) 268 + { 269 + struct e1000_nvm_info *nvm = &hw->nvm; 270 + u32 eecd = er32(EECD); 271 + u8 spi_stat_reg; 272 + 273 + if (nvm->type == e1000_nvm_eeprom_spi) { 274 + u16 timeout = NVM_MAX_RETRY_SPI; 275 + 276 + /* Clear SK and CS */ 277 + eecd &= ~(E1000_EECD_CS | E1000_EECD_SK); 278 + ew32(EECD, eecd); 279 + e1e_flush(); 280 + udelay(1); 281 + 282 + /* 283 + * Read "Status Register" repeatedly until the LSB is cleared. 284 + * The EEPROM will signal that the command has been completed 285 + * by clearing bit 0 of the internal status register. If it's 286 + * not cleared within 'timeout', then error out. 287 + */ 288 + while (timeout) { 289 + e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI, 290 + hw->nvm.opcode_bits); 291 + spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8); 292 + if (!(spi_stat_reg & NVM_STATUS_RDY_SPI)) 293 + break; 294 + 295 + udelay(5); 296 + e1000_standby_nvm(hw); 297 + timeout--; 298 + } 299 + 300 + if (!timeout) { 301 + e_dbg("SPI NVM Status error\n"); 302 + return -E1000_ERR_NVM; 303 + } 304 + } 305 + 306 + return 0; 307 + } 308 + 309 + /** 310 + * e1000e_read_nvm_eerd - Reads EEPROM using EERD register 311 + * @hw: pointer to the HW structure 312 + * @offset: offset of word in the EEPROM to read 313 + * @words: number of words to read 314 + * @data: word read from the EEPROM 315 + * 316 + * Reads a 16 bit word from the EEPROM using the EERD register. 317 + **/ 318 + s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 319 + { 320 + struct e1000_nvm_info *nvm = &hw->nvm; 321 + u32 i, eerd = 0; 322 + s32 ret_val = 0; 323 + 324 + /* 325 + * A check for invalid values: offset too large, too many words, 326 + * too many words for the offset, and not enough words. 327 + */ 328 + if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 329 + (words == 0)) { 330 + e_dbg("nvm parameter(s) out of bounds\n"); 331 + return -E1000_ERR_NVM; 332 + } 333 + 334 + for (i = 0; i < words; i++) { 335 + eerd = ((offset + i) << E1000_NVM_RW_ADDR_SHIFT) + 336 + E1000_NVM_RW_REG_START; 337 + 338 + ew32(EERD, eerd); 339 + ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ); 340 + if (ret_val) 341 + break; 342 + 343 + data[i] = (er32(EERD) >> E1000_NVM_RW_REG_DATA); 344 + } 345 + 346 + return ret_val; 347 + } 348 + 349 + /** 350 + * e1000e_write_nvm_spi - Write to EEPROM using SPI 351 + * @hw: pointer to the HW structure 352 + * @offset: offset within the EEPROM to be written to 353 + * @words: number of words to write 354 + * @data: 16 bit word(s) to be written to the EEPROM 355 + * 356 + * Writes data to EEPROM at offset using SPI interface. 357 + * 358 + * If e1000e_update_nvm_checksum is not called after this function , the 359 + * EEPROM will most likely contain an invalid checksum. 360 + **/ 361 + s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data) 362 + { 363 + struct e1000_nvm_info *nvm = &hw->nvm; 364 + s32 ret_val; 365 + u16 widx = 0; 366 + 367 + /* 368 + * A check for invalid values: offset too large, too many words, 369 + * and not enough words. 370 + */ 371 + if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) || 372 + (words == 0)) { 373 + e_dbg("nvm parameter(s) out of bounds\n"); 374 + return -E1000_ERR_NVM; 375 + } 376 + 377 + ret_val = nvm->ops.acquire(hw); 378 + if (ret_val) 379 + return ret_val; 380 + 381 + while (widx < words) { 382 + u8 write_opcode = NVM_WRITE_OPCODE_SPI; 383 + 384 + ret_val = e1000_ready_nvm_eeprom(hw); 385 + if (ret_val) { 386 + nvm->ops.release(hw); 387 + return ret_val; 388 + } 389 + 390 + e1000_standby_nvm(hw); 391 + 392 + /* Send the WRITE ENABLE command (8 bit opcode) */ 393 + e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI, 394 + nvm->opcode_bits); 395 + 396 + e1000_standby_nvm(hw); 397 + 398 + /* 399 + * Some SPI eeproms use the 8th address bit embedded in the 400 + * opcode 401 + */ 402 + if ((nvm->address_bits == 8) && (offset >= 128)) 403 + write_opcode |= NVM_A8_OPCODE_SPI; 404 + 405 + /* Send the Write command (8-bit opcode + addr) */ 406 + e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits); 407 + e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2), 408 + nvm->address_bits); 409 + 410 + /* Loop to allow for up to whole page write of eeprom */ 411 + while (widx < words) { 412 + u16 word_out = data[widx]; 413 + word_out = (word_out >> 8) | (word_out << 8); 414 + e1000_shift_out_eec_bits(hw, word_out, 16); 415 + widx++; 416 + 417 + if ((((offset + widx) * 2) % nvm->page_size) == 0) { 418 + e1000_standby_nvm(hw); 419 + break; 420 + } 421 + } 422 + } 423 + 424 + usleep_range(10000, 20000); 425 + nvm->ops.release(hw); 426 + return 0; 427 + } 428 + 429 + /** 430 + * e1000_read_pba_string_generic - Read device part number 431 + * @hw: pointer to the HW structure 432 + * @pba_num: pointer to device part number 433 + * @pba_num_size: size of part number buffer 434 + * 435 + * Reads the product board assembly (PBA) number from the EEPROM and stores 436 + * the value in pba_num. 437 + **/ 438 + s32 e1000_read_pba_string_generic(struct e1000_hw *hw, u8 *pba_num, 439 + u32 pba_num_size) 440 + { 441 + s32 ret_val; 442 + u16 nvm_data; 443 + u16 pba_ptr; 444 + u16 offset; 445 + u16 length; 446 + 447 + if (pba_num == NULL) { 448 + e_dbg("PBA string buffer was null\n"); 449 + ret_val = E1000_ERR_INVALID_ARGUMENT; 450 + goto out; 451 + } 452 + 453 + ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data); 454 + if (ret_val) { 455 + e_dbg("NVM Read Error\n"); 456 + goto out; 457 + } 458 + 459 + ret_val = e1000_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &pba_ptr); 460 + if (ret_val) { 461 + e_dbg("NVM Read Error\n"); 462 + goto out; 463 + } 464 + 465 + /* 466 + * if nvm_data is not ptr guard the PBA must be in legacy format which 467 + * means pba_ptr is actually our second data word for the PBA number 468 + * and we can decode it into an ascii string 469 + */ 470 + if (nvm_data != NVM_PBA_PTR_GUARD) { 471 + e_dbg("NVM PBA number is not stored as string\n"); 472 + 473 + /* we will need 11 characters to store the PBA */ 474 + if (pba_num_size < 11) { 475 + e_dbg("PBA string buffer too small\n"); 476 + return E1000_ERR_NO_SPACE; 477 + } 478 + 479 + /* extract hex string from data and pba_ptr */ 480 + pba_num[0] = (nvm_data >> 12) & 0xF; 481 + pba_num[1] = (nvm_data >> 8) & 0xF; 482 + pba_num[2] = (nvm_data >> 4) & 0xF; 483 + pba_num[3] = nvm_data & 0xF; 484 + pba_num[4] = (pba_ptr >> 12) & 0xF; 485 + pba_num[5] = (pba_ptr >> 8) & 0xF; 486 + pba_num[6] = '-'; 487 + pba_num[7] = 0; 488 + pba_num[8] = (pba_ptr >> 4) & 0xF; 489 + pba_num[9] = pba_ptr & 0xF; 490 + 491 + /* put a null character on the end of our string */ 492 + pba_num[10] = '\0'; 493 + 494 + /* switch all the data but the '-' to hex char */ 495 + for (offset = 0; offset < 10; offset++) { 496 + if (pba_num[offset] < 0xA) 497 + pba_num[offset] += '0'; 498 + else if (pba_num[offset] < 0x10) 499 + pba_num[offset] += 'A' - 0xA; 500 + } 501 + 502 + goto out; 503 + } 504 + 505 + ret_val = e1000_read_nvm(hw, pba_ptr, 1, &length); 506 + if (ret_val) { 507 + e_dbg("NVM Read Error\n"); 508 + goto out; 509 + } 510 + 511 + if (length == 0xFFFF || length == 0) { 512 + e_dbg("NVM PBA number section invalid length\n"); 513 + ret_val = E1000_ERR_NVM_PBA_SECTION; 514 + goto out; 515 + } 516 + /* check if pba_num buffer is big enough */ 517 + if (pba_num_size < (((u32)length * 2) - 1)) { 518 + e_dbg("PBA string buffer too small\n"); 519 + ret_val = E1000_ERR_NO_SPACE; 520 + goto out; 521 + } 522 + 523 + /* trim pba length from start of string */ 524 + pba_ptr++; 525 + length--; 526 + 527 + for (offset = 0; offset < length; offset++) { 528 + ret_val = e1000_read_nvm(hw, pba_ptr + offset, 1, &nvm_data); 529 + if (ret_val) { 530 + e_dbg("NVM Read Error\n"); 531 + goto out; 532 + } 533 + pba_num[offset * 2] = (u8)(nvm_data >> 8); 534 + pba_num[(offset * 2) + 1] = (u8)(nvm_data & 0xFF); 535 + } 536 + pba_num[offset * 2] = '\0'; 537 + 538 + out: 539 + return ret_val; 540 + } 541 + 542 + /** 543 + * e1000_read_mac_addr_generic - Read device MAC address 544 + * @hw: pointer to the HW structure 545 + * 546 + * Reads the device MAC address from the EEPROM and stores the value. 547 + * Since devices with two ports use the same EEPROM, we increment the 548 + * last bit in the MAC address for the second port. 549 + **/ 550 + s32 e1000_read_mac_addr_generic(struct e1000_hw *hw) 551 + { 552 + u32 rar_high; 553 + u32 rar_low; 554 + u16 i; 555 + 556 + rar_high = er32(RAH(0)); 557 + rar_low = er32(RAL(0)); 558 + 559 + for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++) 560 + hw->mac.perm_addr[i] = (u8)(rar_low >> (i * 8)); 561 + 562 + for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++) 563 + hw->mac.perm_addr[i + 4] = (u8)(rar_high >> (i * 8)); 564 + 565 + for (i = 0; i < ETH_ALEN; i++) 566 + hw->mac.addr[i] = hw->mac.perm_addr[i]; 567 + 568 + return 0; 569 + } 570 + 571 + /** 572 + * e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum 573 + * @hw: pointer to the HW structure 574 + * 575 + * Calculates the EEPROM checksum by reading/adding each word of the EEPROM 576 + * and then verifies that the sum of the EEPROM is equal to 0xBABA. 577 + **/ 578 + s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw) 579 + { 580 + s32 ret_val; 581 + u16 checksum = 0; 582 + u16 i, nvm_data; 583 + 584 + for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) { 585 + ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); 586 + if (ret_val) { 587 + e_dbg("NVM Read Error\n"); 588 + return ret_val; 589 + } 590 + checksum += nvm_data; 591 + } 592 + 593 + if (checksum != (u16)NVM_SUM) { 594 + e_dbg("NVM Checksum Invalid\n"); 595 + return -E1000_ERR_NVM; 596 + } 597 + 598 + return 0; 599 + } 600 + 601 + /** 602 + * e1000e_update_nvm_checksum_generic - Update EEPROM checksum 603 + * @hw: pointer to the HW structure 604 + * 605 + * Updates the EEPROM checksum by reading/adding each word of the EEPROM 606 + * up to the checksum. Then calculates the EEPROM checksum and writes the 607 + * value to the EEPROM. 608 + **/ 609 + s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw) 610 + { 611 + s32 ret_val; 612 + u16 checksum = 0; 613 + u16 i, nvm_data; 614 + 615 + for (i = 0; i < NVM_CHECKSUM_REG; i++) { 616 + ret_val = e1000_read_nvm(hw, i, 1, &nvm_data); 617 + if (ret_val) { 618 + e_dbg("NVM Read Error while updating checksum.\n"); 619 + return ret_val; 620 + } 621 + checksum += nvm_data; 622 + } 623 + checksum = (u16)NVM_SUM - checksum; 624 + ret_val = e1000_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum); 625 + if (ret_val) 626 + e_dbg("NVM Write Error while updating checksum.\n"); 627 + 628 + return ret_val; 629 + } 630 + 631 + /** 632 + * e1000e_reload_nvm - Reloads EEPROM 633 + * @hw: pointer to the HW structure 634 + * 635 + * Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the 636 + * extended control register. 637 + **/ 638 + void e1000e_reload_nvm(struct e1000_hw *hw) 639 + { 640 + u32 ctrl_ext; 641 + 642 + udelay(10); 643 + ctrl_ext = er32(CTRL_EXT); 644 + ctrl_ext |= E1000_CTRL_EXT_EE_RST; 645 + ew32(CTRL_EXT, ctrl_ext); 646 + e1e_flush(); 647 + }