16621Sbt150084 /* 26621Sbt150084 * CDDL HEADER START 36621Sbt150084 * 46621Sbt150084 * The contents of this file are subject to the terms of the 56621Sbt150084 * Common Development and Distribution License (the "License"). 66621Sbt150084 * You may not use this file except in compliance with the License. 76621Sbt150084 * 8*8275SEric Cheng * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*8275SEric Cheng * or http://www.opensolaris.org/os/licensing. 106621Sbt150084 * See the License for the specific language governing permissions 116621Sbt150084 * and limitations under the License. 126621Sbt150084 * 13*8275SEric Cheng * When distributing Covered Code, include this CDDL HEADER in each 14*8275SEric Cheng * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 156621Sbt150084 * If applicable, add the following below this CDDL HEADER, with the 166621Sbt150084 * fields enclosed by brackets "[]" replaced with your own identifying 176621Sbt150084 * information: Portions Copyright [yyyy] [name of copyright owner] 186621Sbt150084 * 196621Sbt150084 * CDDL HEADER END 206621Sbt150084 */ 216621Sbt150084 226621Sbt150084 /* 23*8275SEric Cheng * Copyright(c) 2007-2008 Intel Corporation. All rights reserved. 24*8275SEric Cheng */ 25*8275SEric Cheng 26*8275SEric Cheng /* 276621Sbt150084 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 28*8275SEric Cheng * Use is subject to license terms. 296621Sbt150084 */ 306621Sbt150084 316621Sbt150084 /* IntelVersion: 1.159 v2008-03-04 */ 326621Sbt150084 336621Sbt150084 #include "ixgbe_common.h" 346621Sbt150084 #include "ixgbe_api.h" 356621Sbt150084 366621Sbt150084 static s32 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw); 376621Sbt150084 static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw); 386621Sbt150084 static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw); 396621Sbt150084 static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw); 406621Sbt150084 static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw); 416621Sbt150084 static void ixgbe_standby_eeprom(struct ixgbe_hw *hw); 426621Sbt150084 static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, 436621Sbt150084 u16 count); 446621Sbt150084 static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count); 456621Sbt150084 static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); 466621Sbt150084 static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec); 476621Sbt150084 static void ixgbe_release_eeprom(struct ixgbe_hw *hw); 486621Sbt150084 static u16 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw); 496621Sbt150084 506621Sbt150084 static void ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index); 516621Sbt150084 static void ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index); 526621Sbt150084 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr); 536621Sbt150084 void ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr); 546621Sbt150084 void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq); 556621Sbt150084 566621Sbt150084 /* 576621Sbt150084 * ixgbe_init_ops_generic - Inits function ptrs 586621Sbt150084 * @hw: pointer to the hardware structure 596621Sbt150084 * 606621Sbt150084 * Initialize the function pointers. 616621Sbt150084 */ 626621Sbt150084 s32 636621Sbt150084 ixgbe_init_ops_generic(struct ixgbe_hw *hw) 646621Sbt150084 { 656621Sbt150084 struct ixgbe_eeprom_info *eeprom = &hw->eeprom; 666621Sbt150084 struct ixgbe_mac_info *mac = &hw->mac; 676621Sbt150084 686621Sbt150084 /* EEPROM */ 696621Sbt150084 eeprom->ops.init_params = &ixgbe_init_eeprom_params_generic; 706621Sbt150084 eeprom->ops.read = &ixgbe_read_eeprom_generic; 716621Sbt150084 eeprom->ops.write = &ixgbe_write_eeprom_generic; 726621Sbt150084 eeprom->ops.validate_checksum = 736621Sbt150084 &ixgbe_validate_eeprom_checksum_generic; 746621Sbt150084 eeprom->ops.update_checksum = &ixgbe_update_eeprom_checksum_generic; 756621Sbt150084 766621Sbt150084 /* MAC */ 776621Sbt150084 mac->ops.init_hw = &ixgbe_init_hw_generic; 786621Sbt150084 mac->ops.reset_hw = NULL; 796621Sbt150084 mac->ops.start_hw = &ixgbe_start_hw_generic; 806621Sbt150084 mac->ops.clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic; 816621Sbt150084 mac->ops.get_media_type = NULL; 826621Sbt150084 mac->ops.get_mac_addr = &ixgbe_get_mac_addr_generic; 836621Sbt150084 mac->ops.stop_adapter = &ixgbe_stop_adapter_generic; 846621Sbt150084 mac->ops.get_bus_info = &ixgbe_get_bus_info_generic; 856621Sbt150084 mac->ops.read_analog_reg8 = &ixgbe_read_analog_reg8_generic; 866621Sbt150084 mac->ops.write_analog_reg8 = &ixgbe_write_analog_reg8_generic; 876621Sbt150084 886621Sbt150084 /* LEDs */ 896621Sbt150084 mac->ops.led_on = &ixgbe_led_on_generic; 906621Sbt150084 mac->ops.led_off = &ixgbe_led_off_generic; 916621Sbt150084 mac->ops.blink_led_start = NULL; 926621Sbt150084 mac->ops.blink_led_stop = NULL; 936621Sbt150084 946621Sbt150084 /* RAR, Multicast, VLAN */ 956621Sbt150084 mac->ops.set_rar = &ixgbe_set_rar_generic; 966621Sbt150084 mac->ops.set_vmdq = NULL; 976621Sbt150084 mac->ops.init_rx_addrs = &ixgbe_init_rx_addrs_generic; 986621Sbt150084 mac->ops.update_uc_addr_list = &ixgbe_update_uc_addr_list_generic; 996621Sbt150084 mac->ops.update_mc_addr_list = &ixgbe_update_mc_addr_list_generic; 1006621Sbt150084 mac->ops.enable_mc = &ixgbe_enable_mc_generic; 1016621Sbt150084 mac->ops.disable_mc = &ixgbe_disable_mc_generic; 1026621Sbt150084 mac->ops.clear_vfta = &ixgbe_clear_vfta_generic; 1036621Sbt150084 mac->ops.set_vfta = &ixgbe_set_vfta_generic; 1046621Sbt150084 1056621Sbt150084 /* Flow Control */ 1066621Sbt150084 mac->ops.setup_fc = NULL; 1076621Sbt150084 1086621Sbt150084 /* Link */ 1096621Sbt150084 mac->ops.get_link_capabilities = NULL; 1106621Sbt150084 mac->ops.setup_link = NULL; 1116621Sbt150084 mac->ops.setup_link_speed = NULL; 1126621Sbt150084 mac->ops.check_link = NULL; 1136621Sbt150084 1146621Sbt150084 return (IXGBE_SUCCESS); 1156621Sbt150084 } 1166621Sbt150084 1176621Sbt150084 /* 1186621Sbt150084 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx 1196621Sbt150084 * @hw: pointer to hardware structure 1206621Sbt150084 * 1216621Sbt150084 * Starts the hardware by filling the bus info structure and media type, clears 1226621Sbt150084 * all on chip counters, initializes receive address registers, multicast 1236621Sbt150084 * table, VLAN filter table, calls routine to set up link and flow control 1246621Sbt150084 * settings, and leaves transmit and receive units disabled and uninitialized 1256621Sbt150084 */ 1266621Sbt150084 s32 1276621Sbt150084 ixgbe_start_hw_generic(struct ixgbe_hw *hw) 1286621Sbt150084 { 1296621Sbt150084 u32 ctrl_ext; 1306621Sbt150084 1316621Sbt150084 /* Set the media type */ 1326621Sbt150084 hw->phy.media_type = hw->mac.ops.get_media_type(hw); 1336621Sbt150084 1346621Sbt150084 /* Set bus info */ 1356621Sbt150084 hw->mac.ops.get_bus_info(hw); 1366621Sbt150084 1376621Sbt150084 /* Identify the PHY */ 1386621Sbt150084 hw->phy.ops.identify(hw); 1396621Sbt150084 1406621Sbt150084 /* 1416621Sbt150084 * Store MAC address from RAR0, clear receive address registers, and 1426621Sbt150084 * clear the multicast table 1436621Sbt150084 */ 1446621Sbt150084 hw->mac.ops.init_rx_addrs(hw); 1456621Sbt150084 1466621Sbt150084 /* Clear the VLAN filter table */ 1476621Sbt150084 hw->mac.ops.clear_vfta(hw); 1486621Sbt150084 1496621Sbt150084 /* Set up link */ 1506621Sbt150084 hw->mac.ops.setup_link(hw); 1516621Sbt150084 1526621Sbt150084 /* Clear statistics registers */ 1536621Sbt150084 hw->mac.ops.clear_hw_cntrs(hw); 1546621Sbt150084 1556621Sbt150084 /* Set No Snoop Disable */ 1566621Sbt150084 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); 1576621Sbt150084 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS; 1586621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); 1596621Sbt150084 IXGBE_WRITE_FLUSH(hw); 1606621Sbt150084 1616621Sbt150084 /* Clear adapter stopped flag */ 1626621Sbt150084 hw->adapter_stopped = FALSE; 1636621Sbt150084 1646621Sbt150084 return (IXGBE_SUCCESS); 1656621Sbt150084 } 1666621Sbt150084 1676621Sbt150084 /* 1686621Sbt150084 * ixgbe_init_hw_generic - Generic hardware initialization 1696621Sbt150084 * @hw: pointer to hardware structure 1706621Sbt150084 * 1716621Sbt150084 * Initialize the hardware by resetting the hardware, filling the bus info 1726621Sbt150084 * structure and media type, clears all on chip counters, initializes receive 1736621Sbt150084 * address registers, multicast table, VLAN filter table, calls routine to set 1746621Sbt150084 * up link and flow control settings, and leaves transmit and receive units 1756621Sbt150084 * disabled and uninitialized 1766621Sbt150084 */ 1776621Sbt150084 s32 1786621Sbt150084 ixgbe_init_hw_generic(struct ixgbe_hw *hw) 1796621Sbt150084 { 1806621Sbt150084 /* Reset the hardware */ 1816621Sbt150084 hw->mac.ops.reset_hw(hw); 1826621Sbt150084 1836621Sbt150084 /* Start the HW */ 1846621Sbt150084 hw->mac.ops.start_hw(hw); 1856621Sbt150084 1866621Sbt150084 return (IXGBE_SUCCESS); 1876621Sbt150084 } 1886621Sbt150084 1896621Sbt150084 /* 1906621Sbt150084 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters 1916621Sbt150084 * @hw: pointer to hardware structure 1926621Sbt150084 * 1936621Sbt150084 * Clears all hardware statistics counters by reading them from the hardware 1946621Sbt150084 * Statistics counters are clear on read. 1956621Sbt150084 */ 1966621Sbt150084 s32 1976621Sbt150084 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw) 1986621Sbt150084 { 1996621Sbt150084 u16 i = 0; 2006621Sbt150084 2016621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_CRCERRS); 2026621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_ILLERRC); 2036621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_ERRBC); 2046621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MSPDC); 2056621Sbt150084 for (i = 0; i < 8; i++) 2066621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MPC(i)); 2076621Sbt150084 2086621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MLFC); 2096621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MRFC); 2106621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RLEC); 2116621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_LXONTXC); 2126621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_LXONRXC); 2136621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); 2146621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); 2156621Sbt150084 2166621Sbt150084 for (i = 0; i < 8; i++) { 2176621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PXONTXC(i)); 2186621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PXONRXC(i)); 2196621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i)); 2206621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i)); 2216621Sbt150084 } 2226621Sbt150084 2236621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC64); 2246621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC127); 2256621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC255); 2266621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC511); 2276621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC1023); 2286621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PRC1522); 2296621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GPRC); 2306621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_BPRC); 2316621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MPRC); 2326621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GPTC); 2336621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GORCL); 2346621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GORCH); 2356621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GOTCL); 2366621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_GOTCH); 2376621Sbt150084 for (i = 0; i < 8; i++) 2386621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RNBC(i)); 2396621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RUC); 2406621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RFC); 2416621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_ROC); 2426621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_RJC); 2436621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MNGPRC); 2446621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MNGPDC); 2456621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MNGPTC); 2466621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TORL); 2476621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TORH); 2486621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TPR); 2496621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_TPT); 2506621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC64); 2516621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC127); 2526621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC255); 2536621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC511); 2546621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC1023); 2556621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_PTC1522); 2566621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_MPTC); 2576621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_BPTC); 2586621Sbt150084 for (i = 0; i < 16; i++) { 2596621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_QPRC(i)); 2606621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_QBRC(i)); 2616621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_QPTC(i)); 2626621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_QBTC(i)); 2636621Sbt150084 } 2646621Sbt150084 2656621Sbt150084 return (IXGBE_SUCCESS); 2666621Sbt150084 } 2676621Sbt150084 2686621Sbt150084 /* 2696621Sbt150084 * ixgbe_read_pba_num - Reads part number from EEPROM 2706621Sbt150084 * @hw: pointer to hardware structure 2716621Sbt150084 * @pba_num: stores the part number from the EEPROM 2726621Sbt150084 * 2736621Sbt150084 * Reads the part number from the EEPROM. 2746621Sbt150084 */ 2756621Sbt150084 s32 2766621Sbt150084 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num) 2776621Sbt150084 { 2786621Sbt150084 s32 ret_val; 2796621Sbt150084 u16 data; 2806621Sbt150084 2816621Sbt150084 DEBUGFUNC("ixgbe_read_pba_num_generic"); 2826621Sbt150084 2836621Sbt150084 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data); 2846621Sbt150084 if (ret_val) { 2856621Sbt150084 DEBUGOUT("NVM Read Error\n"); 2866621Sbt150084 return (ret_val); 2876621Sbt150084 } 2886621Sbt150084 *pba_num = (u32)(data << 16); 2896621Sbt150084 2906621Sbt150084 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data); 2916621Sbt150084 if (ret_val) { 2926621Sbt150084 DEBUGOUT("NVM Read Error\n"); 2936621Sbt150084 return (ret_val); 2946621Sbt150084 } 2956621Sbt150084 *pba_num |= data; 2966621Sbt150084 2976621Sbt150084 return (IXGBE_SUCCESS); 2986621Sbt150084 } 2996621Sbt150084 3006621Sbt150084 /* 3016621Sbt150084 * ixgbe_get_mac_addr_generic - Generic get MAC address 3026621Sbt150084 * @hw: pointer to hardware structure 3036621Sbt150084 * @mac_addr: Adapter MAC address 3046621Sbt150084 * 3056621Sbt150084 * Reads the adapter's MAC address from first Receive Address Register (RAR0) 3066621Sbt150084 * A reset of the adapter must be performed prior to calling this function 3076621Sbt150084 * in order for the MAC address to have been loaded from the EEPROM into RAR0 3086621Sbt150084 */ 3096621Sbt150084 s32 3106621Sbt150084 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr) 3116621Sbt150084 { 3126621Sbt150084 u32 rar_high; 3136621Sbt150084 u32 rar_low; 3146621Sbt150084 u16 i; 3156621Sbt150084 3166621Sbt150084 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0)); 3176621Sbt150084 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0)); 3186621Sbt150084 3196621Sbt150084 for (i = 0; i < 4; i++) 3206621Sbt150084 mac_addr[i] = (u8)(rar_low >> (i*8)); 3216621Sbt150084 3226621Sbt150084 for (i = 0; i < 2; i++) 3236621Sbt150084 mac_addr[i+4] = (u8)(rar_high >> (i*8)); 3246621Sbt150084 3256621Sbt150084 return (IXGBE_SUCCESS); 3266621Sbt150084 } 3276621Sbt150084 3286621Sbt150084 /* 3296621Sbt150084 * ixgbe_get_bus_info_generic - Generic set PCI bus info 3306621Sbt150084 * @hw: pointer to hardware structure 3316621Sbt150084 * 3326621Sbt150084 * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure 3336621Sbt150084 */ 3346621Sbt150084 s32 3356621Sbt150084 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw) 3366621Sbt150084 { 3376621Sbt150084 u16 link_status; 3386621Sbt150084 3396621Sbt150084 hw->bus.type = ixgbe_bus_type_pci_express; 3406621Sbt150084 3416621Sbt150084 /* Get the negotiated link width and speed from PCI config space */ 3426621Sbt150084 link_status = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_LINK_STATUS); 3436621Sbt150084 3446621Sbt150084 switch (link_status & IXGBE_PCI_LINK_WIDTH) { 3456621Sbt150084 case IXGBE_PCI_LINK_WIDTH_1: 3466621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x1; 3476621Sbt150084 break; 3486621Sbt150084 case IXGBE_PCI_LINK_WIDTH_2: 3496621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x2; 3506621Sbt150084 break; 3516621Sbt150084 case IXGBE_PCI_LINK_WIDTH_4: 3526621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x4; 3536621Sbt150084 break; 3546621Sbt150084 case IXGBE_PCI_LINK_WIDTH_8: 3556621Sbt150084 hw->bus.width = ixgbe_bus_width_pcie_x8; 3566621Sbt150084 break; 3576621Sbt150084 default: 3586621Sbt150084 hw->bus.width = ixgbe_bus_width_unknown; 3596621Sbt150084 break; 3606621Sbt150084 } 3616621Sbt150084 3626621Sbt150084 switch (link_status & IXGBE_PCI_LINK_SPEED) { 3636621Sbt150084 case IXGBE_PCI_LINK_SPEED_2500: 3646621Sbt150084 hw->bus.speed = ixgbe_bus_speed_2500; 3656621Sbt150084 break; 3666621Sbt150084 case IXGBE_PCI_LINK_SPEED_5000: 3676621Sbt150084 hw->bus.speed = ixgbe_bus_speed_5000; 3686621Sbt150084 break; 3696621Sbt150084 default: 3706621Sbt150084 hw->bus.speed = ixgbe_bus_speed_unknown; 3716621Sbt150084 break; 3726621Sbt150084 } 3736621Sbt150084 3746621Sbt150084 return (IXGBE_SUCCESS); 3756621Sbt150084 } 3766621Sbt150084 3776621Sbt150084 /* 3786621Sbt150084 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units 3796621Sbt150084 * @hw: pointer to hardware structure 3806621Sbt150084 * 3816621Sbt150084 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts, 3826621Sbt150084 * disables transmit and receive units. The adapter_stopped flag is used by 3836621Sbt150084 * the shared code and drivers to determine if the adapter is in a stopped 3846621Sbt150084 * state and should not touch the hardware. 3856621Sbt150084 */ 3866621Sbt150084 s32 3876621Sbt150084 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw) 3886621Sbt150084 { 3896621Sbt150084 u32 number_of_queues; 3906621Sbt150084 u32 reg_val; 3916621Sbt150084 u16 i; 3926621Sbt150084 3936621Sbt150084 /* 3946621Sbt150084 * Set the adapter_stopped flag so other driver functions stop touching 3956621Sbt150084 * the hardware 3966621Sbt150084 */ 3976621Sbt150084 hw->adapter_stopped = TRUE; 3986621Sbt150084 3996621Sbt150084 /* Disable the receive unit */ 4006621Sbt150084 reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL); 4016621Sbt150084 reg_val &= ~(IXGBE_RXCTRL_RXEN); 4026621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val); 4036621Sbt150084 IXGBE_WRITE_FLUSH(hw); 4046621Sbt150084 msec_delay(2); 4056621Sbt150084 4066621Sbt150084 /* Clear interrupt mask to stop from interrupts being generated */ 4076621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); 4086621Sbt150084 4096621Sbt150084 /* Clear any pending interrupts */ 4106621Sbt150084 (void) IXGBE_READ_REG(hw, IXGBE_EICR); 4116621Sbt150084 4126621Sbt150084 /* Disable the transmit unit. Each queue must be disabled. */ 4136621Sbt150084 number_of_queues = hw->mac.max_tx_queues; 4146621Sbt150084 for (i = 0; i < number_of_queues; i++) { 4156621Sbt150084 reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i)); 4166621Sbt150084 if (reg_val & IXGBE_TXDCTL_ENABLE) { 4176621Sbt150084 reg_val &= ~IXGBE_TXDCTL_ENABLE; 4186621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val); 4196621Sbt150084 } 4206621Sbt150084 } 4216621Sbt150084 4226621Sbt150084 /* 4236621Sbt150084 * Prevent the PCI-E bus from from hanging by disabling PCI-E master 4246621Sbt150084 * access and verify no pending requests 4256621Sbt150084 */ 4266621Sbt150084 if (ixgbe_disable_pcie_master(hw) != IXGBE_SUCCESS) { 4276621Sbt150084 DEBUGOUT("PCI-E Master disable polling has failed.\n"); 4286621Sbt150084 } 4296621Sbt150084 4306621Sbt150084 return (IXGBE_SUCCESS); 4316621Sbt150084 } 4326621Sbt150084 4336621Sbt150084 /* 4346621Sbt150084 * ixgbe_led_on_generic - Turns on the software controllable LEDs. 4356621Sbt150084 * @hw: pointer to hardware structure 4366621Sbt150084 * @index: led number to turn on 4376621Sbt150084 */ 4386621Sbt150084 s32 4396621Sbt150084 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index) 4406621Sbt150084 { 4416621Sbt150084 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); 4426621Sbt150084 4436621Sbt150084 /* To turn on the LED, set mode to ON. */ 4446621Sbt150084 led_reg &= ~IXGBE_LED_MODE_MASK(index); 4456621Sbt150084 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index); 4466621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); 4476621Sbt150084 IXGBE_WRITE_FLUSH(hw); 4486621Sbt150084 4496621Sbt150084 return (IXGBE_SUCCESS); 4506621Sbt150084 } 4516621Sbt150084 4526621Sbt150084 /* 4536621Sbt150084 * ixgbe_led_off_generic - Turns off the software controllable LEDs. 4546621Sbt150084 * @hw: pointer to hardware structure 4556621Sbt150084 * @index: led number to turn off 4566621Sbt150084 */ 4576621Sbt150084 s32 4586621Sbt150084 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index) 4596621Sbt150084 { 4606621Sbt150084 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL); 4616621Sbt150084 4626621Sbt150084 /* To turn off the LED, set mode to OFF. */ 4636621Sbt150084 led_reg &= ~IXGBE_LED_MODE_MASK(index); 4646621Sbt150084 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index); 4656621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg); 4666621Sbt150084 IXGBE_WRITE_FLUSH(hw); 4676621Sbt150084 4686621Sbt150084 return (IXGBE_SUCCESS); 4696621Sbt150084 } 4706621Sbt150084 4716621Sbt150084 /* 4726621Sbt150084 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params 4736621Sbt150084 * @hw: pointer to hardware structure 4746621Sbt150084 * 4756621Sbt150084 * Initializes the EEPROM parameters ixgbe_eeprom_info within the 4766621Sbt150084 * ixgbe_hw struct in order to set up EEPROM access. 4776621Sbt150084 */ 4786621Sbt150084 s32 4796621Sbt150084 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw) 4806621Sbt150084 { 4816621Sbt150084 struct ixgbe_eeprom_info *eeprom = &hw->eeprom; 4826621Sbt150084 u32 eec; 4836621Sbt150084 u16 eeprom_size; 4846621Sbt150084 4856621Sbt150084 if (eeprom->type == ixgbe_eeprom_uninitialized) { 4866621Sbt150084 eeprom->type = ixgbe_eeprom_none; 4876621Sbt150084 4886621Sbt150084 /* 4896621Sbt150084 * Check for EEPROM present first. 4906621Sbt150084 * If not present leave as none 4916621Sbt150084 */ 4926621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 4936621Sbt150084 if (eec & IXGBE_EEC_PRES) { 4946621Sbt150084 eeprom->type = ixgbe_eeprom_spi; 4956621Sbt150084 4966621Sbt150084 /* 4976621Sbt150084 * SPI EEPROM is assumed here. This code would need to 4986621Sbt150084 * change if a future EEPROM is not SPI. 4996621Sbt150084 */ 5006621Sbt150084 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >> 5016621Sbt150084 IXGBE_EEC_SIZE_SHIFT); 5026621Sbt150084 eeprom->word_size = 1 << (eeprom_size + 5036621Sbt150084 IXGBE_EEPROM_WORD_SIZE_SHIFT); 5046621Sbt150084 } 5056621Sbt150084 5066621Sbt150084 if (eec & IXGBE_EEC_ADDR_SIZE) 5076621Sbt150084 eeprom->address_bits = 16; 5086621Sbt150084 else 5096621Sbt150084 eeprom->address_bits = 8; 5106621Sbt150084 DEBUGOUT3("Eeprom params: type = %d, size = %d, address bits: " 5116621Sbt150084 "%d\n", eeprom->type, eeprom->word_size, 5126621Sbt150084 eeprom->address_bits); 5136621Sbt150084 } 5146621Sbt150084 5156621Sbt150084 return (IXGBE_SUCCESS); 5166621Sbt150084 } 5176621Sbt150084 5186621Sbt150084 /* 5196621Sbt150084 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM 5206621Sbt150084 * @hw: pointer to hardware structure 5216621Sbt150084 * @offset: offset within the EEPROM to be written to 5226621Sbt150084 * @data: 16 bit word to be written to the EEPROM 5236621Sbt150084 * 5246621Sbt150084 * If ixgbe_eeprom_update_checksum is not called after this function, the 5256621Sbt150084 * EEPROM will most likely contain an invalid checksum. 5266621Sbt150084 */ 5276621Sbt150084 s32 5286621Sbt150084 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data) 5296621Sbt150084 { 5306621Sbt150084 s32 status; 5316621Sbt150084 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI; 5326621Sbt150084 5336621Sbt150084 hw->eeprom.ops.init_params(hw); 5346621Sbt150084 5356621Sbt150084 if (offset >= hw->eeprom.word_size) { 5366621Sbt150084 status = IXGBE_ERR_EEPROM; 5376621Sbt150084 goto out; 5386621Sbt150084 } 5396621Sbt150084 5406621Sbt150084 /* Prepare the EEPROM for writing */ 5416621Sbt150084 status = ixgbe_acquire_eeprom(hw); 5426621Sbt150084 5436621Sbt150084 if (status == IXGBE_SUCCESS) { 5446621Sbt150084 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) { 5456621Sbt150084 ixgbe_release_eeprom(hw); 5466621Sbt150084 status = IXGBE_ERR_EEPROM; 5476621Sbt150084 } 5486621Sbt150084 } 5496621Sbt150084 5506621Sbt150084 if (status == IXGBE_SUCCESS) { 5516621Sbt150084 ixgbe_standby_eeprom(hw); 5526621Sbt150084 5536621Sbt150084 /* Send the WRITE ENABLE command (8 bit opcode ) */ 5546621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI, 5556621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 5566621Sbt150084 5576621Sbt150084 ixgbe_standby_eeprom(hw); 5586621Sbt150084 5596621Sbt150084 /* 5606621Sbt150084 * Some SPI eeproms use the 8th address bit embedded in the 5616621Sbt150084 * opcode 5626621Sbt150084 */ 5636621Sbt150084 if ((hw->eeprom.address_bits == 8) && (offset >= 128)) 5646621Sbt150084 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; 5656621Sbt150084 5666621Sbt150084 /* Send the Write command (8-bit opcode + addr) */ 5676621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, write_opcode, 5686621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 5696621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2), 5706621Sbt150084 hw->eeprom.address_bits); 5716621Sbt150084 5726621Sbt150084 /* Send the data */ 5736621Sbt150084 data = (data >> 8) | (data << 8); 5746621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, data, 16); 5756621Sbt150084 ixgbe_standby_eeprom(hw); 5766621Sbt150084 5776621Sbt150084 msec_delay(10); 5786621Sbt150084 5796621Sbt150084 /* Done with writing - release the EEPROM */ 5806621Sbt150084 ixgbe_release_eeprom(hw); 5816621Sbt150084 } 5826621Sbt150084 5836621Sbt150084 out: 5846621Sbt150084 return (status); 5856621Sbt150084 } 5866621Sbt150084 5876621Sbt150084 /* 5886621Sbt150084 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang 5896621Sbt150084 * @hw: pointer to hardware structure 5906621Sbt150084 * @offset: offset within the EEPROM to be read 5916621Sbt150084 * @data: read 16 bit value from EEPROM 5926621Sbt150084 * 5936621Sbt150084 * Reads 16 bit value from EEPROM through bit-bang method 5946621Sbt150084 */ 5956621Sbt150084 s32 5966621Sbt150084 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset, 5976621Sbt150084 u16 *data) 5986621Sbt150084 { 5996621Sbt150084 s32 status; 6006621Sbt150084 u16 word_in; 6016621Sbt150084 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI; 6026621Sbt150084 6036621Sbt150084 hw->eeprom.ops.init_params(hw); 6046621Sbt150084 6056621Sbt150084 if (offset >= hw->eeprom.word_size) { 6066621Sbt150084 status = IXGBE_ERR_EEPROM; 6076621Sbt150084 goto out; 6086621Sbt150084 } 6096621Sbt150084 6106621Sbt150084 /* Prepare the EEPROM for reading */ 6116621Sbt150084 status = ixgbe_acquire_eeprom(hw); 6126621Sbt150084 6136621Sbt150084 if (status == IXGBE_SUCCESS) { 6146621Sbt150084 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) { 6156621Sbt150084 ixgbe_release_eeprom(hw); 6166621Sbt150084 status = IXGBE_ERR_EEPROM; 6176621Sbt150084 } 6186621Sbt150084 } 6196621Sbt150084 6206621Sbt150084 if (status == IXGBE_SUCCESS) { 6216621Sbt150084 ixgbe_standby_eeprom(hw); 6226621Sbt150084 6236621Sbt150084 /* 6246621Sbt150084 * Some SPI eeproms use the 8th address bit embedded in the 6256621Sbt150084 * opcode 6266621Sbt150084 */ 6276621Sbt150084 if ((hw->eeprom.address_bits == 8) && (offset >= 128)) 6286621Sbt150084 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI; 6296621Sbt150084 6306621Sbt150084 /* Send the READ command (opcode + addr) */ 6316621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, read_opcode, 6326621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 6336621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2), 6346621Sbt150084 hw->eeprom.address_bits); 6356621Sbt150084 6366621Sbt150084 /* Read the data. */ 6376621Sbt150084 word_in = ixgbe_shift_in_eeprom_bits(hw, 16); 6386621Sbt150084 *data = (word_in >> 8) | (word_in << 8); 6396621Sbt150084 6406621Sbt150084 /* End this read operation */ 6416621Sbt150084 ixgbe_release_eeprom(hw); 6426621Sbt150084 } 6436621Sbt150084 6446621Sbt150084 out: 6456621Sbt150084 return (status); 6466621Sbt150084 } 6476621Sbt150084 6486621Sbt150084 /* 6496621Sbt150084 * ixgbe_read_eeprom_generic - Read EEPROM word using EERD 6506621Sbt150084 * @hw: pointer to hardware structure 6516621Sbt150084 * @offset: offset of word in the EEPROM to read 6526621Sbt150084 * @data: word read from the EEPROM 6536621Sbt150084 * 6546621Sbt150084 * Reads a 16 bit word from the EEPROM using the EERD register. 6556621Sbt150084 */ 6566621Sbt150084 s32 6576621Sbt150084 ixgbe_read_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 *data) 6586621Sbt150084 { 6596621Sbt150084 u32 eerd; 6606621Sbt150084 s32 status; 6616621Sbt150084 6626621Sbt150084 hw->eeprom.ops.init_params(hw); 6636621Sbt150084 6646621Sbt150084 if (offset >= hw->eeprom.word_size) { 6656621Sbt150084 status = IXGBE_ERR_EEPROM; 6666621Sbt150084 goto out; 6676621Sbt150084 } 6686621Sbt150084 6696621Sbt150084 eerd = (offset << IXGBE_EEPROM_READ_ADDR_SHIFT) + 6706621Sbt150084 IXGBE_EEPROM_READ_REG_START; 6716621Sbt150084 6726621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd); 6736621Sbt150084 status = ixgbe_poll_eeprom_eerd_done(hw); 6746621Sbt150084 6756621Sbt150084 if (status == IXGBE_SUCCESS) 6766621Sbt150084 *data = (IXGBE_READ_REG(hw, IXGBE_EERD) >> 6776621Sbt150084 IXGBE_EEPROM_READ_REG_DATA); 6786621Sbt150084 else 6796621Sbt150084 DEBUGOUT("Eeprom read timed out\n"); 6806621Sbt150084 6816621Sbt150084 out: 6826621Sbt150084 return (status); 6836621Sbt150084 } 6846621Sbt150084 6856621Sbt150084 /* 6866621Sbt150084 * ixgbe_poll_eeprom_eerd_done - Poll EERD status 6876621Sbt150084 * @hw: pointer to hardware structure 6886621Sbt150084 * 6896621Sbt150084 * Polls the status bit (bit 1) of the EERD to determine when the read is done. 6906621Sbt150084 */ 6916621Sbt150084 static s32 6926621Sbt150084 ixgbe_poll_eeprom_eerd_done(struct ixgbe_hw *hw) 6936621Sbt150084 { 6946621Sbt150084 u32 i; 6956621Sbt150084 u32 reg; 6966621Sbt150084 s32 status = IXGBE_ERR_EEPROM; 6976621Sbt150084 6986621Sbt150084 for (i = 0; i < IXGBE_EERD_ATTEMPTS; i++) { 6996621Sbt150084 reg = IXGBE_READ_REG(hw, IXGBE_EERD); 7006621Sbt150084 if (reg & IXGBE_EEPROM_READ_REG_DONE) { 7016621Sbt150084 status = IXGBE_SUCCESS; 7026621Sbt150084 break; 7036621Sbt150084 } 7046621Sbt150084 usec_delay(5); 7056621Sbt150084 } 7066621Sbt150084 return (status); 7076621Sbt150084 } 7086621Sbt150084 7096621Sbt150084 /* 7106621Sbt150084 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang 7116621Sbt150084 * @hw: pointer to hardware structure 7126621Sbt150084 * 7136621Sbt150084 * Prepares EEPROM for access using bit-bang method. This function should 7146621Sbt150084 * be called before issuing a command to the EEPROM. 7156621Sbt150084 */ 7166621Sbt150084 static s32 7176621Sbt150084 ixgbe_acquire_eeprom(struct ixgbe_hw *hw) 7186621Sbt150084 { 7196621Sbt150084 s32 status = IXGBE_SUCCESS; 7206621Sbt150084 u32 eec; 7216621Sbt150084 u32 i; 7226621Sbt150084 7236621Sbt150084 if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != IXGBE_SUCCESS) 7246621Sbt150084 status = IXGBE_ERR_SWFW_SYNC; 7256621Sbt150084 7266621Sbt150084 if (status == IXGBE_SUCCESS) { 7276621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 7286621Sbt150084 7296621Sbt150084 /* Request EEPROM Access */ 7306621Sbt150084 eec |= IXGBE_EEC_REQ; 7316621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 7326621Sbt150084 7336621Sbt150084 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) { 7346621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 7356621Sbt150084 if (eec & IXGBE_EEC_GNT) 7366621Sbt150084 break; 7376621Sbt150084 usec_delay(5); 7386621Sbt150084 } 7396621Sbt150084 7406621Sbt150084 /* Release if grant not acquired */ 7416621Sbt150084 if (!(eec & IXGBE_EEC_GNT)) { 7426621Sbt150084 eec &= ~IXGBE_EEC_REQ; 7436621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 7446621Sbt150084 DEBUGOUT("Could not acquire EEPROM grant\n"); 7456621Sbt150084 7466621Sbt150084 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); 7476621Sbt150084 status = IXGBE_ERR_EEPROM; 7486621Sbt150084 } 7496621Sbt150084 } 7506621Sbt150084 7516621Sbt150084 /* Setup EEPROM for Read/Write */ 7526621Sbt150084 if (status == IXGBE_SUCCESS) { 7536621Sbt150084 /* Clear CS and SK */ 7546621Sbt150084 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK); 7556621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 7566621Sbt150084 IXGBE_WRITE_FLUSH(hw); 7576621Sbt150084 usec_delay(1); 7586621Sbt150084 } 7596621Sbt150084 return (status); 7606621Sbt150084 } 7616621Sbt150084 7626621Sbt150084 /* 7636621Sbt150084 * ixgbe_get_eeprom_semaphore - Get hardware semaphore 7646621Sbt150084 * @hw: pointer to hardware structure 7656621Sbt150084 * 7666621Sbt150084 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method 7676621Sbt150084 */ 7686621Sbt150084 static s32 7696621Sbt150084 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw) 7706621Sbt150084 { 7716621Sbt150084 s32 status = IXGBE_ERR_EEPROM; 7726621Sbt150084 u32 timeout; 7736621Sbt150084 u32 i; 7746621Sbt150084 u32 swsm; 7756621Sbt150084 7766621Sbt150084 /* Set timeout value based on size of EEPROM */ 7776621Sbt150084 timeout = hw->eeprom.word_size + 1; 7786621Sbt150084 7796621Sbt150084 /* Get SMBI software semaphore between device drivers first */ 7806621Sbt150084 for (i = 0; i < timeout; i++) { 7816621Sbt150084 /* 7826621Sbt150084 * If the SMBI bit is 0 when we read it, then the bit will be 7836621Sbt150084 * set and we have the semaphore 7846621Sbt150084 */ 7856621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 7866621Sbt150084 if (!(swsm & IXGBE_SWSM_SMBI)) { 7876621Sbt150084 status = IXGBE_SUCCESS; 7886621Sbt150084 break; 7896621Sbt150084 } 7906621Sbt150084 msec_delay(1); 7916621Sbt150084 } 7926621Sbt150084 7936621Sbt150084 /* Now get the semaphore between SW/FW through the SWESMBI bit */ 7946621Sbt150084 if (status == IXGBE_SUCCESS) { 7956621Sbt150084 for (i = 0; i < timeout; i++) { 7966621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 7976621Sbt150084 7986621Sbt150084 /* Set the SW EEPROM semaphore bit to request access */ 7996621Sbt150084 swsm |= IXGBE_SWSM_SWESMBI; 8006621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); 8016621Sbt150084 8026621Sbt150084 /* 8036621Sbt150084 * If we set the bit successfully then we got the 8046621Sbt150084 * semaphore. 8056621Sbt150084 */ 8066621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 8076621Sbt150084 if (swsm & IXGBE_SWSM_SWESMBI) 8086621Sbt150084 break; 8096621Sbt150084 8106621Sbt150084 usec_delay(50); 8116621Sbt150084 } 8126621Sbt150084 8136621Sbt150084 /* 8146621Sbt150084 * Release semaphores and return error if SW EEPROM semaphore 8156621Sbt150084 * was not granted because we don't have access to the EEPROM 8166621Sbt150084 */ 8176621Sbt150084 if (i >= timeout) { 8186621Sbt150084 DEBUGOUT("Driver can't access the Eeprom - Semaphore " 8196621Sbt150084 "not granted.\n"); 8206621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 8216621Sbt150084 status = IXGBE_ERR_EEPROM; 8226621Sbt150084 } 8236621Sbt150084 } 8246621Sbt150084 8256621Sbt150084 return (status); 8266621Sbt150084 } 8276621Sbt150084 8286621Sbt150084 /* 8296621Sbt150084 * ixgbe_release_eeprom_semaphore - Release hardware semaphore 8306621Sbt150084 * @hw: pointer to hardware structure 8316621Sbt150084 * 8326621Sbt150084 * This function clears hardware semaphore bits. 8336621Sbt150084 */ 8346621Sbt150084 static void 8356621Sbt150084 ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw) 8366621Sbt150084 { 8376621Sbt150084 u32 swsm; 8386621Sbt150084 8396621Sbt150084 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM); 8406621Sbt150084 8416621Sbt150084 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */ 8426621Sbt150084 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI); 8436621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm); 8446621Sbt150084 IXGBE_WRITE_FLUSH(hw); 8456621Sbt150084 } 8466621Sbt150084 8476621Sbt150084 /* 8486621Sbt150084 * ixgbe_ready_eeprom - Polls for EEPROM ready 8496621Sbt150084 * @hw: pointer to hardware structure 8506621Sbt150084 */ 8516621Sbt150084 static s32 8526621Sbt150084 ixgbe_ready_eeprom(struct ixgbe_hw *hw) 8536621Sbt150084 { 8546621Sbt150084 s32 status = IXGBE_SUCCESS; 8556621Sbt150084 u16 i; 8566621Sbt150084 u8 spi_stat_reg; 8576621Sbt150084 8586621Sbt150084 /* 8596621Sbt150084 * Read "Status Register" repeatedly until the LSB is cleared. The 8606621Sbt150084 * EEPROM will signal that the command has been completed by clearing 8616621Sbt150084 * bit 0 of the internal status register. If it's not cleared within 8626621Sbt150084 * 5 milliseconds, then error out. 8636621Sbt150084 */ 8646621Sbt150084 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) { 8656621Sbt150084 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI, 8666621Sbt150084 IXGBE_EEPROM_OPCODE_BITS); 8676621Sbt150084 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8); 8686621Sbt150084 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI)) 8696621Sbt150084 break; 8706621Sbt150084 8716621Sbt150084 usec_delay(5); 8726621Sbt150084 ixgbe_standby_eeprom(hw); 8736621Sbt150084 }; 8746621Sbt150084 8756621Sbt150084 /* 8766621Sbt150084 * On some parts, SPI write time could vary from 0-20mSec on 3.3V 8776621Sbt150084 * devices (and only 0-5mSec on 5V devices) 8786621Sbt150084 */ 8796621Sbt150084 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) { 8806621Sbt150084 DEBUGOUT("SPI EEPROM Status error\n"); 8816621Sbt150084 status = IXGBE_ERR_EEPROM; 8826621Sbt150084 } 8836621Sbt150084 8846621Sbt150084 return (status); 8856621Sbt150084 } 8866621Sbt150084 8876621Sbt150084 /* 8886621Sbt150084 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state 8896621Sbt150084 * @hw: pointer to hardware structure 8906621Sbt150084 */ 8916621Sbt150084 static void 8926621Sbt150084 ixgbe_standby_eeprom(struct ixgbe_hw *hw) 8936621Sbt150084 { 8946621Sbt150084 u32 eec; 8956621Sbt150084 8966621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 8976621Sbt150084 8986621Sbt150084 /* Toggle CS to flush commands */ 8996621Sbt150084 eec |= IXGBE_EEC_CS; 9006621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 9016621Sbt150084 IXGBE_WRITE_FLUSH(hw); 9026621Sbt150084 usec_delay(1); 9036621Sbt150084 eec &= ~IXGBE_EEC_CS; 9046621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 9056621Sbt150084 IXGBE_WRITE_FLUSH(hw); 9066621Sbt150084 usec_delay(1); 9076621Sbt150084 } 9086621Sbt150084 9096621Sbt150084 /* 9106621Sbt150084 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM. 9116621Sbt150084 * @hw: pointer to hardware structure 9126621Sbt150084 * @data: data to send to the EEPROM 9136621Sbt150084 * @count: number of bits to shift out 9146621Sbt150084 */ 9156621Sbt150084 static void 9166621Sbt150084 ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data, 9176621Sbt150084 u16 count) 9186621Sbt150084 { 9196621Sbt150084 u32 eec; 9206621Sbt150084 u32 mask; 9216621Sbt150084 u32 i; 9226621Sbt150084 9236621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 9246621Sbt150084 9256621Sbt150084 /* 9266621Sbt150084 * Mask is used to shift "count" bits of "data" out to the EEPROM 9276621Sbt150084 * one bit at a time. Determine the starting bit based on count 9286621Sbt150084 */ 9296621Sbt150084 mask = 0x01 << (count - 1); 9306621Sbt150084 9316621Sbt150084 for (i = 0; i < count; i++) { 9326621Sbt150084 /* 9336621Sbt150084 * A "1" is shifted out to the EEPROM by setting bit "DI" to a 9346621Sbt150084 * "1", and then raising and then lowering the clock (the SK 9356621Sbt150084 * bit controls the clock input to the EEPROM). A "0" is 9366621Sbt150084 * shifted out to the EEPROM by setting "DI" to "0" and then 9376621Sbt150084 * raising and then lowering the clock. 9386621Sbt150084 */ 9396621Sbt150084 if (data & mask) 9406621Sbt150084 eec |= IXGBE_EEC_DI; 9416621Sbt150084 else 9426621Sbt150084 eec &= ~IXGBE_EEC_DI; 9436621Sbt150084 9446621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 9456621Sbt150084 IXGBE_WRITE_FLUSH(hw); 9466621Sbt150084 9476621Sbt150084 usec_delay(1); 9486621Sbt150084 9496621Sbt150084 ixgbe_raise_eeprom_clk(hw, &eec); 9506621Sbt150084 ixgbe_lower_eeprom_clk(hw, &eec); 9516621Sbt150084 9526621Sbt150084 /* 9536621Sbt150084 * Shift mask to signify next bit of data to shift in to the 9546621Sbt150084 * EEPROM 9556621Sbt150084 */ 9566621Sbt150084 mask = mask >> 1; 9576621Sbt150084 }; 9586621Sbt150084 9596621Sbt150084 /* We leave the "DI" bit set to "0" when we leave this routine. */ 9606621Sbt150084 eec &= ~IXGBE_EEC_DI; 9616621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 9626621Sbt150084 IXGBE_WRITE_FLUSH(hw); 9636621Sbt150084 } 9646621Sbt150084 9656621Sbt150084 /* 9666621Sbt150084 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM 9676621Sbt150084 * @hw: pointer to hardware structure 9686621Sbt150084 */ 9696621Sbt150084 static u16 9706621Sbt150084 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count) 9716621Sbt150084 { 9726621Sbt150084 u32 eec; 9736621Sbt150084 u32 i; 9746621Sbt150084 u16 data = 0; 9756621Sbt150084 9766621Sbt150084 /* 9776621Sbt150084 * In order to read a register from the EEPROM, we need to shift 9786621Sbt150084 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising 9796621Sbt150084 * the clock input to the EEPROM (setting the SK bit), and then reading 9806621Sbt150084 * the value of the "DO" bit. During this "shifting in" process the 9816621Sbt150084 * "DI" bit should always be clear. 9826621Sbt150084 */ 9836621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 9846621Sbt150084 9856621Sbt150084 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI); 9866621Sbt150084 9876621Sbt150084 for (i = 0; i < count; i++) { 9886621Sbt150084 data = data << 1; 9896621Sbt150084 ixgbe_raise_eeprom_clk(hw, &eec); 9906621Sbt150084 9916621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 9926621Sbt150084 9936621Sbt150084 eec &= ~(IXGBE_EEC_DI); 9946621Sbt150084 if (eec & IXGBE_EEC_DO) 9956621Sbt150084 data |= 1; 9966621Sbt150084 9976621Sbt150084 ixgbe_lower_eeprom_clk(hw, &eec); 9986621Sbt150084 } 9996621Sbt150084 10006621Sbt150084 return (data); 10016621Sbt150084 } 10026621Sbt150084 10036621Sbt150084 /* 10046621Sbt150084 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input. 10056621Sbt150084 * @hw: pointer to hardware structure 10066621Sbt150084 * @eec: EEC register's current value 10076621Sbt150084 */ 10086621Sbt150084 static void 10096621Sbt150084 ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) 10106621Sbt150084 { 10116621Sbt150084 /* 10126621Sbt150084 * Raise the clock input to the EEPROM 10136621Sbt150084 * (setting the SK bit), then delay 10146621Sbt150084 */ 10156621Sbt150084 *eec = *eec | IXGBE_EEC_SK; 10166621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); 10176621Sbt150084 IXGBE_WRITE_FLUSH(hw); 10186621Sbt150084 usec_delay(1); 10196621Sbt150084 } 10206621Sbt150084 10216621Sbt150084 /* 10226621Sbt150084 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input. 10236621Sbt150084 * @hw: pointer to hardware structure 10246621Sbt150084 * @eecd: EECD's current value 10256621Sbt150084 */ 10266621Sbt150084 static void 10276621Sbt150084 ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec) 10286621Sbt150084 { 10296621Sbt150084 /* 10306621Sbt150084 * Lower the clock input to the EEPROM (clearing the SK bit), then 10316621Sbt150084 * delay 10326621Sbt150084 */ 10336621Sbt150084 *eec = *eec & ~IXGBE_EEC_SK; 10346621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec); 10356621Sbt150084 IXGBE_WRITE_FLUSH(hw); 10366621Sbt150084 usec_delay(1); 10376621Sbt150084 } 10386621Sbt150084 10396621Sbt150084 /* 10406621Sbt150084 * ixgbe_release_eeprom - Release EEPROM, release semaphores 10416621Sbt150084 * @hw: pointer to hardware structure 10426621Sbt150084 */ 10436621Sbt150084 static void 10446621Sbt150084 ixgbe_release_eeprom(struct ixgbe_hw *hw) 10456621Sbt150084 { 10466621Sbt150084 u32 eec; 10476621Sbt150084 10486621Sbt150084 eec = IXGBE_READ_REG(hw, IXGBE_EEC); 10496621Sbt150084 10506621Sbt150084 eec |= IXGBE_EEC_CS; /* Pull CS high */ 10516621Sbt150084 eec &= ~IXGBE_EEC_SK; /* Lower SCK */ 10526621Sbt150084 10536621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 10546621Sbt150084 IXGBE_WRITE_FLUSH(hw); 10556621Sbt150084 10566621Sbt150084 usec_delay(1); 10576621Sbt150084 10586621Sbt150084 /* Stop requesting EEPROM access */ 10596621Sbt150084 eec &= ~IXGBE_EEC_REQ; 10606621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_EEC, eec); 10616621Sbt150084 10626621Sbt150084 ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM); 10636621Sbt150084 } 10646621Sbt150084 10656621Sbt150084 /* 10666621Sbt150084 * ixgbe_calc_eeprom_checksum - Calculates and returns the checksum 10676621Sbt150084 * @hw: pointer to hardware structure 10686621Sbt150084 */ 10696621Sbt150084 static u16 10706621Sbt150084 ixgbe_calc_eeprom_checksum(struct ixgbe_hw *hw) 10716621Sbt150084 { 10726621Sbt150084 u16 i; 10736621Sbt150084 u16 j; 10746621Sbt150084 u16 checksum = 0; 10756621Sbt150084 u16 length = 0; 10766621Sbt150084 u16 pointer = 0; 10776621Sbt150084 u16 word = 0; 10786621Sbt150084 10796621Sbt150084 /* Include 0x0-0x3F in the checksum */ 10806621Sbt150084 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) { 10816621Sbt150084 if (hw->eeprom.ops.read(hw, i, &word) != IXGBE_SUCCESS) { 10826621Sbt150084 DEBUGOUT("EEPROM read failed\n"); 10836621Sbt150084 break; 10846621Sbt150084 } 10856621Sbt150084 checksum += word; 10866621Sbt150084 } 10876621Sbt150084 10886621Sbt150084 /* Include all data from pointers except for the fw pointer */ 10896621Sbt150084 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) { 10906621Sbt150084 hw->eeprom.ops.read(hw, i, &pointer); 10916621Sbt150084 10926621Sbt150084 /* Make sure the pointer seems valid */ 10936621Sbt150084 if (pointer != 0xFFFF && pointer != 0) { 10946621Sbt150084 hw->eeprom.ops.read(hw, pointer, &length); 10956621Sbt150084 10966621Sbt150084 if (length != 0xFFFF && length != 0) { 10976621Sbt150084 for (j = pointer+1; j <= pointer+length; j++) { 10986621Sbt150084 hw->eeprom.ops.read(hw, j, &word); 10996621Sbt150084 checksum += word; 11006621Sbt150084 } 11016621Sbt150084 } 11026621Sbt150084 } 11036621Sbt150084 } 11046621Sbt150084 11056621Sbt150084 checksum = (u16)IXGBE_EEPROM_SUM - checksum; 11066621Sbt150084 11076621Sbt150084 return (checksum); 11086621Sbt150084 } 11096621Sbt150084 11106621Sbt150084 /* 11116621Sbt150084 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum 11126621Sbt150084 * @hw: pointer to hardware structure 11136621Sbt150084 * @checksum_val: calculated checksum 11146621Sbt150084 * 11156621Sbt150084 * Performs checksum calculation and validates the EEPROM checksum. If the 11166621Sbt150084 * caller does not need checksum_val, the value can be NULL. 11176621Sbt150084 */ 11186621Sbt150084 s32 11196621Sbt150084 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw, 11206621Sbt150084 u16 *checksum_val) 11216621Sbt150084 { 11226621Sbt150084 s32 status; 11236621Sbt150084 u16 checksum; 11246621Sbt150084 u16 read_checksum = 0; 11256621Sbt150084 11266621Sbt150084 /* 11276621Sbt150084 * Read the first word from the EEPROM. If this times out or fails, do 11286621Sbt150084 * not continue or we could be in for a very long wait while every 11296621Sbt150084 * EEPROM read fails 11306621Sbt150084 */ 11316621Sbt150084 status = hw->eeprom.ops.read(hw, 0, &checksum); 11326621Sbt150084 11336621Sbt150084 if (status == IXGBE_SUCCESS) { 11346621Sbt150084 checksum = ixgbe_calc_eeprom_checksum(hw); 11356621Sbt150084 11366621Sbt150084 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum); 11376621Sbt150084 11386621Sbt150084 /* 11396621Sbt150084 * Verify read checksum from EEPROM is the same as 11406621Sbt150084 * calculated checksum 11416621Sbt150084 */ 11426621Sbt150084 if (read_checksum != checksum) 11436621Sbt150084 status = IXGBE_ERR_EEPROM_CHECKSUM; 11446621Sbt150084 11456621Sbt150084 /* If the user cares, return the calculated checksum */ 11466621Sbt150084 if (checksum_val) 11476621Sbt150084 *checksum_val = checksum; 11486621Sbt150084 } else { 11496621Sbt150084 DEBUGOUT("EEPROM read failed\n"); 11506621Sbt150084 } 11516621Sbt150084 11526621Sbt150084 return (status); 11536621Sbt150084 } 11546621Sbt150084 11556621Sbt150084 /* 11566621Sbt150084 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum 11576621Sbt150084 * @hw: pointer to hardware structure 11586621Sbt150084 */ 11596621Sbt150084 s32 11606621Sbt150084 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw) 11616621Sbt150084 { 11626621Sbt150084 s32 status; 11636621Sbt150084 u16 checksum; 11646621Sbt150084 11656621Sbt150084 /* 11666621Sbt150084 * Read the first word from the EEPROM. If this times out or fails, do 11676621Sbt150084 * not continue or we could be in for a very long wait while every 11686621Sbt150084 * EEPROM read fails 11696621Sbt150084 */ 11706621Sbt150084 status = hw->eeprom.ops.read(hw, 0, &checksum); 11716621Sbt150084 11726621Sbt150084 if (status == IXGBE_SUCCESS) { 11736621Sbt150084 checksum = ixgbe_calc_eeprom_checksum(hw); 11746621Sbt150084 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, 11756621Sbt150084 checksum); 11766621Sbt150084 } else { 11776621Sbt150084 DEBUGOUT("EEPROM read failed\n"); 11786621Sbt150084 } 11796621Sbt150084 11806621Sbt150084 return (status); 11816621Sbt150084 } 11826621Sbt150084 11836621Sbt150084 /* 11846621Sbt150084 * ixgbe_validate_mac_addr - Validate MAC address 11856621Sbt150084 * @mac_addr: pointer to MAC address. 11866621Sbt150084 * 11876621Sbt150084 * Tests a MAC address to ensure it is a valid Individual Address 11886621Sbt150084 */ 11896621Sbt150084 s32 11906621Sbt150084 ixgbe_validate_mac_addr(u8 *mac_addr) 11916621Sbt150084 { 11926621Sbt150084 s32 status = IXGBE_SUCCESS; 11936621Sbt150084 11946621Sbt150084 /* Make sure it is not a multicast address */ 11956621Sbt150084 if (IXGBE_IS_MULTICAST(mac_addr)) { 11966621Sbt150084 DEBUGOUT("MAC address is multicast\n"); 11976621Sbt150084 status = IXGBE_ERR_INVALID_MAC_ADDR; 11986621Sbt150084 /* Not a broadcast address */ 11996621Sbt150084 } else if (IXGBE_IS_BROADCAST(mac_addr)) { 12006621Sbt150084 DEBUGOUT("MAC address is broadcast\n"); 12016621Sbt150084 status = IXGBE_ERR_INVALID_MAC_ADDR; 12026621Sbt150084 /* Reject the zero address */ 12036621Sbt150084 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 && 12046621Sbt150084 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) { 12056621Sbt150084 DEBUGOUT("MAC address is all zeros\n"); 12066621Sbt150084 status = IXGBE_ERR_INVALID_MAC_ADDR; 12076621Sbt150084 } 12086621Sbt150084 return (status); 12096621Sbt150084 } 12106621Sbt150084 12116621Sbt150084 /* 12126621Sbt150084 * ixgbe_set_rar_generic - Set Rx address register 12136621Sbt150084 * @hw: pointer to hardware structure 12146621Sbt150084 * @index: Receive address register to write 12156621Sbt150084 * @addr: Address to put into receive address register 12166621Sbt150084 * @vmdq: VMDq "set" or "pool" index 12176621Sbt150084 * @enable_addr: set flag that address is active 12186621Sbt150084 * 12196621Sbt150084 * Puts an ethernet address into a receive address register. 12206621Sbt150084 */ 12216621Sbt150084 s32 12226621Sbt150084 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq, 12236621Sbt150084 u32 enable_addr) 12246621Sbt150084 { 12256621Sbt150084 u32 rar_low, rar_high; 12266621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 12276621Sbt150084 12286621Sbt150084 /* setup VMDq pool selection before this RAR gets enabled */ 12296621Sbt150084 hw->mac.ops.set_vmdq(hw, index, vmdq); 12306621Sbt150084 12316621Sbt150084 /* Make sure we are using a valid rar index range */ 12326621Sbt150084 if (index < rar_entries) { 12336621Sbt150084 /* 12346621Sbt150084 * HW expects these in little endian so we reverse the byte 12356621Sbt150084 * order from network order (big endian) to little endian 12366621Sbt150084 */ 12376621Sbt150084 rar_low = ((u32)addr[0] | 12386621Sbt150084 ((u32)addr[1] << 8) | 12396621Sbt150084 ((u32)addr[2] << 16) | 12406621Sbt150084 ((u32)addr[3] << 24)); 12416621Sbt150084 /* 12426621Sbt150084 * Some parts put the VMDq setting in the extra RAH bits, 12436621Sbt150084 * so save everything except the lower 16 bits that hold part 12446621Sbt150084 * of the address and the address valid bit. 12456621Sbt150084 */ 12466621Sbt150084 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); 12476621Sbt150084 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV); 12486621Sbt150084 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8)); 12496621Sbt150084 12506621Sbt150084 if (enable_addr != 0) 12516621Sbt150084 rar_high |= IXGBE_RAH_AV; 12526621Sbt150084 12536621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low); 12546621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); 12556621Sbt150084 } else { 12566621Sbt150084 DEBUGOUT("Current RAR index is out of range."); 12576621Sbt150084 } 12586621Sbt150084 12596621Sbt150084 return (IXGBE_SUCCESS); 12606621Sbt150084 } 12616621Sbt150084 12626621Sbt150084 /* 12636621Sbt150084 * ixgbe_enable_rar - Enable Rx address register 12646621Sbt150084 * @hw: pointer to hardware structure 12656621Sbt150084 * @index: index into the RAR table 12666621Sbt150084 * 12676621Sbt150084 * Enables the select receive address register. 12686621Sbt150084 */ 12696621Sbt150084 static void 12706621Sbt150084 ixgbe_enable_rar(struct ixgbe_hw *hw, u32 index) 12716621Sbt150084 { 12726621Sbt150084 u32 rar_high; 12736621Sbt150084 12746621Sbt150084 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); 12756621Sbt150084 rar_high |= IXGBE_RAH_AV; 12766621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); 12776621Sbt150084 } 12786621Sbt150084 12796621Sbt150084 /* 12806621Sbt150084 * ixgbe_disable_rar - Disable Rx address register 12816621Sbt150084 * @hw: pointer to hardware structure 12826621Sbt150084 * @index: index into the RAR table 12836621Sbt150084 * 12846621Sbt150084 * Disables the select receive address register. 12856621Sbt150084 */ 12866621Sbt150084 static void 12876621Sbt150084 ixgbe_disable_rar(struct ixgbe_hw *hw, u32 index) 12886621Sbt150084 { 12896621Sbt150084 u32 rar_high; 12906621Sbt150084 12916621Sbt150084 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index)); 12926621Sbt150084 rar_high &= (~IXGBE_RAH_AV); 12936621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high); 12946621Sbt150084 } 12956621Sbt150084 12966621Sbt150084 /* 12976621Sbt150084 * ixgbe_init_rx_addrs_generic - Initializes receive address filters. 12986621Sbt150084 * @hw: pointer to hardware structure 12996621Sbt150084 * 13006621Sbt150084 * Places the MAC address in receive address register 0 and clears the rest 13016621Sbt150084 * of the receive address registers. Clears the multicast table. Assumes 13026621Sbt150084 * the receiver is in reset when the routine is called. 13036621Sbt150084 */ 13046621Sbt150084 s32 13056621Sbt150084 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw) 13066621Sbt150084 { 13076621Sbt150084 u32 i; 13086621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 13096621Sbt150084 13106621Sbt150084 /* 13116621Sbt150084 * If the current mac address is valid, assume it is a software override 13126621Sbt150084 * to the permanent address. 13136621Sbt150084 * Otherwise, use the permanent address from the eeprom. 13146621Sbt150084 */ 13156621Sbt150084 if (ixgbe_validate_mac_addr(hw->mac.addr) == 13166621Sbt150084 IXGBE_ERR_INVALID_MAC_ADDR) { 13176621Sbt150084 /* Get the MAC address from the RAR0 for later reference */ 13186621Sbt150084 hw->mac.ops.get_mac_addr(hw, hw->mac.addr); 13196621Sbt150084 13206621Sbt150084 DEBUGOUT3(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ", 13216621Sbt150084 hw->mac.addr[0], hw->mac.addr[1], 13226621Sbt150084 hw->mac.addr[2]); 13236621Sbt150084 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3], 13246621Sbt150084 hw->mac.addr[4], hw->mac.addr[5]); 13256621Sbt150084 } else { 13266621Sbt150084 /* Setup the receive address. */ 13276621Sbt150084 DEBUGOUT("Overriding MAC Address in RAR[0]\n"); 13286621Sbt150084 DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ", 13296621Sbt150084 hw->mac.addr[0], hw->mac.addr[1], 13306621Sbt150084 hw->mac.addr[2]); 13316621Sbt150084 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3], 13326621Sbt150084 hw->mac.addr[4], hw->mac.addr[5]); 13336621Sbt150084 13346621Sbt150084 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV); 13356621Sbt150084 } 13366621Sbt150084 hw->addr_ctrl.overflow_promisc = 0; 13376621Sbt150084 13386621Sbt150084 hw->addr_ctrl.rar_used_count = 1; 13396621Sbt150084 13406621Sbt150084 /* Zero out the other receive addresses. */ 13416621Sbt150084 DEBUGOUT1("Clearing RAR[1-%d]\n", rar_entries - 1); 13426621Sbt150084 for (i = 1; i < rar_entries; i++) { 13436621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0); 13446621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0); 13456621Sbt150084 } 13466621Sbt150084 13476621Sbt150084 /* Clear the MTA */ 13486621Sbt150084 hw->addr_ctrl.mc_addr_in_rar_count = 0; 13496621Sbt150084 hw->addr_ctrl.mta_in_use = 0; 13506621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); 13516621Sbt150084 13526621Sbt150084 DEBUGOUT(" Clearing MTA\n"); 13536621Sbt150084 for (i = 0; i < hw->mac.mcft_size; i++) 13546621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); 13556621Sbt150084 13566621Sbt150084 return (IXGBE_SUCCESS); 13576621Sbt150084 } 13586621Sbt150084 13596621Sbt150084 /* 13606621Sbt150084 * ixgbe_add_uc_addr - Adds a secondary unicast address. 13616621Sbt150084 * @hw: pointer to hardware structure 13626621Sbt150084 * @addr: new address 13636621Sbt150084 * 13646621Sbt150084 * Adds it to unused receive address register or goes into promiscuous mode. 13656621Sbt150084 */ 13666621Sbt150084 void 13676621Sbt150084 ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq) 13686621Sbt150084 { 13696621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 13706621Sbt150084 u32 rar; 13716621Sbt150084 13726621Sbt150084 DEBUGOUT6(" UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n", 13736621Sbt150084 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]); 13746621Sbt150084 13756621Sbt150084 /* 13766621Sbt150084 * Place this address in the RAR if there is room, 13776621Sbt150084 * else put the controller into promiscuous mode 13786621Sbt150084 */ 13796621Sbt150084 if (hw->addr_ctrl.rar_used_count < rar_entries) { 13806621Sbt150084 rar = hw->addr_ctrl.rar_used_count - 13816621Sbt150084 hw->addr_ctrl.mc_addr_in_rar_count; 13826621Sbt150084 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV); 13836621Sbt150084 DEBUGOUT1("Added a secondary address to RAR[%d]\n", rar); 13846621Sbt150084 hw->addr_ctrl.rar_used_count++; 13856621Sbt150084 } else { 13866621Sbt150084 hw->addr_ctrl.overflow_promisc++; 13876621Sbt150084 } 13886621Sbt150084 13896621Sbt150084 DEBUGOUT("ixgbe_add_uc_addr Complete\n"); 13906621Sbt150084 } 13916621Sbt150084 13926621Sbt150084 /* 13936621Sbt150084 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses 13946621Sbt150084 * @hw: pointer to hardware structure 13956621Sbt150084 * @addr_list: the list of new addresses 13966621Sbt150084 * @addr_count: number of addresses 13976621Sbt150084 * @next: iterator function to walk the address list 13986621Sbt150084 * 13996621Sbt150084 * The given list replaces any existing list. Clears the secondary addrs from 14006621Sbt150084 * receive address registers. Uses unused receive address registers for the 14016621Sbt150084 * first secondary addresses, and falls back to promiscuous mode as needed. 14026621Sbt150084 * 14036621Sbt150084 * Drivers using secondary unicast addresses must set user_set_promisc when 14046621Sbt150084 * manually putting the device into promiscuous mode. 14056621Sbt150084 */ 14066621Sbt150084 s32 14076621Sbt150084 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list, 14086621Sbt150084 u32 addr_count, ixgbe_mc_addr_itr next) 14096621Sbt150084 { 14106621Sbt150084 u8 *addr; 14116621Sbt150084 u32 i; 14126621Sbt150084 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc; 14136621Sbt150084 u32 uc_addr_in_use; 14146621Sbt150084 u32 fctrl; 14156621Sbt150084 u32 vmdq; 14166621Sbt150084 14176621Sbt150084 /* 14186621Sbt150084 * Clear accounting of old secondary address list, 14196621Sbt150084 * don't count RAR[0] 14206621Sbt150084 */ 14216621Sbt150084 uc_addr_in_use = hw->addr_ctrl.rar_used_count - 14226621Sbt150084 hw->addr_ctrl.mc_addr_in_rar_count - 1; 14236621Sbt150084 hw->addr_ctrl.rar_used_count -= uc_addr_in_use; 14246621Sbt150084 hw->addr_ctrl.overflow_promisc = 0; 14256621Sbt150084 14266621Sbt150084 /* Zero out the other receive addresses */ 14276621Sbt150084 DEBUGOUT1("Clearing RAR[1-%d]\n", uc_addr_in_use); 14286621Sbt150084 for (i = 1; i <= uc_addr_in_use; i++) { 14296621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0); 14306621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0); 14316621Sbt150084 } 14326621Sbt150084 14336621Sbt150084 /* Add the new addresses */ 14346621Sbt150084 for (i = 0; i < addr_count; i++) { 14356621Sbt150084 DEBUGOUT(" Adding the secondary addresses:\n"); 14366621Sbt150084 addr = next(hw, &addr_list, &vmdq); 14376621Sbt150084 ixgbe_add_uc_addr(hw, addr, vmdq); 14386621Sbt150084 } 14396621Sbt150084 14406621Sbt150084 if (hw->addr_ctrl.overflow_promisc) { 14416621Sbt150084 /* enable promisc if not already in overflow or set by user */ 14426621Sbt150084 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) { 14436621Sbt150084 DEBUGOUT(" Entering address overflow promisc mode\n"); 14446621Sbt150084 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); 14456621Sbt150084 fctrl |= IXGBE_FCTRL_UPE; 14466621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); 14476621Sbt150084 } 14486621Sbt150084 } else { 14496621Sbt150084 /* only disable if set by overflow, not by user */ 14506621Sbt150084 if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) { 14516621Sbt150084 DEBUGOUT(" Leaving address overflow promisc mode\n"); 14526621Sbt150084 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); 14536621Sbt150084 fctrl &= ~IXGBE_FCTRL_UPE; 14546621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); 14556621Sbt150084 } 14566621Sbt150084 } 14576621Sbt150084 14586621Sbt150084 DEBUGOUT("ixgbe_update_uc_addr_list_generic Complete\n"); 14596621Sbt150084 return (IXGBE_SUCCESS); 14606621Sbt150084 } 14616621Sbt150084 14626621Sbt150084 /* 14636621Sbt150084 * ixgbe_mta_vector - Determines bit-vector in multicast table to set 14646621Sbt150084 * @hw: pointer to hardware structure 14656621Sbt150084 * @mc_addr: the multicast address 14666621Sbt150084 * 14676621Sbt150084 * Extracts the 12 bits, from a multicast address, to determine which 14686621Sbt150084 * bit-vector to set in the multicast table. The hardware uses 12 bits, from 14696621Sbt150084 * incoming rx multicast addresses, to determine the bit-vector to check in 14706621Sbt150084 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set 14716621Sbt150084 * by the MO field of the MCSTCTRL. The MO field is set during initialization 14726621Sbt150084 * to mc_filter_type. 14736621Sbt150084 */ 14746621Sbt150084 static s32 14756621Sbt150084 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr) 14766621Sbt150084 { 14776621Sbt150084 u32 vector = 0; 14786621Sbt150084 14796621Sbt150084 switch (hw->mac.mc_filter_type) { 14806621Sbt150084 case 0: /* use bits [47:36] of the address */ 14816621Sbt150084 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4)); 14826621Sbt150084 break; 14836621Sbt150084 case 1: /* use bits [46:35] of the address */ 14846621Sbt150084 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5)); 14856621Sbt150084 break; 14866621Sbt150084 case 2: /* use bits [45:34] of the address */ 14876621Sbt150084 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6)); 14886621Sbt150084 break; 14896621Sbt150084 case 3: /* use bits [43:32] of the address */ 14906621Sbt150084 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8)); 14916621Sbt150084 break; 14926621Sbt150084 default: /* Invalid mc_filter_type */ 14936621Sbt150084 DEBUGOUT("MC filter type param set incorrectly\n"); 14946621Sbt150084 ASSERT(0); 14956621Sbt150084 break; 14966621Sbt150084 } 14976621Sbt150084 14986621Sbt150084 /* vector can only be 12-bits or boundary will be exceeded */ 14996621Sbt150084 vector &= 0xFFF; 15006621Sbt150084 return (vector); 15016621Sbt150084 } 15026621Sbt150084 15036621Sbt150084 /* 15046621Sbt150084 * ixgbe_set_mta - Set bit-vector in multicast table 15056621Sbt150084 * @hw: pointer to hardware structure 15066621Sbt150084 * @hash_value: Multicast address hash value 15076621Sbt150084 * 15086621Sbt150084 * Sets the bit-vector in the multicast table. 15096621Sbt150084 */ 15106621Sbt150084 void 15116621Sbt150084 ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr) 15126621Sbt150084 { 15136621Sbt150084 u32 vector; 15146621Sbt150084 u32 vector_bit; 15156621Sbt150084 u32 vector_reg; 15166621Sbt150084 u32 mta_reg; 15176621Sbt150084 15186621Sbt150084 hw->addr_ctrl.mta_in_use++; 15196621Sbt150084 15206621Sbt150084 vector = ixgbe_mta_vector(hw, mc_addr); 15216621Sbt150084 DEBUGOUT1(" bit-vector = 0x%03X\n", vector); 15226621Sbt150084 15236621Sbt150084 /* 15246621Sbt150084 * The MTA is a register array of 128 32-bit registers. It is treated 15256621Sbt150084 * like an array of 4096 bits. We want to set bit 15266621Sbt150084 * BitArray[vector_value]. So we figure out what register the bit is 15276621Sbt150084 * in, read it, OR in the new bit, then write back the new value. The 15286621Sbt150084 * register is determined by the upper 7 bits of the vector value and 15296621Sbt150084 * the bit within that register are determined by the lower 5 bits of 15306621Sbt150084 * the value. 15316621Sbt150084 */ 15326621Sbt150084 vector_reg = (vector >> 5) & 0x7F; 15336621Sbt150084 vector_bit = vector & 0x1F; 15346621Sbt150084 mta_reg = IXGBE_READ_REG(hw, IXGBE_MTA(vector_reg)); 15356621Sbt150084 mta_reg |= (1 << vector_bit); 15366621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MTA(vector_reg), mta_reg); 15376621Sbt150084 } 15386621Sbt150084 15396621Sbt150084 /* 15406621Sbt150084 * ixgbe_add_mc_addr - Adds a multicast address. 15416621Sbt150084 * @hw: pointer to hardware structure 15426621Sbt150084 * @mc_addr: new multicast address 15436621Sbt150084 * 15446621Sbt150084 * Adds it to unused receive address register or to the multicast table. 15456621Sbt150084 */ 15466621Sbt150084 void 15476621Sbt150084 ixgbe_add_mc_addr(struct ixgbe_hw *hw, u8 *mc_addr) 15486621Sbt150084 { 15496621Sbt150084 DEBUGOUT6(" MC Addr =%.2X %.2X %.2X %.2X %.2X %.2X\n", 15506621Sbt150084 mc_addr[0], mc_addr[1], mc_addr[2], 15516621Sbt150084 mc_addr[3], mc_addr[4], mc_addr[5]); 15526621Sbt150084 1553*8275SEric Cheng ixgbe_set_mta(hw, mc_addr); 15546621Sbt150084 15556621Sbt150084 DEBUGOUT("ixgbe_add_mc_addr Complete\n"); 15566621Sbt150084 } 15576621Sbt150084 15586621Sbt150084 /* 15596621Sbt150084 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses 15606621Sbt150084 * @hw: pointer to hardware structure 15616621Sbt150084 * @mc_addr_list: the list of new multicast addresses 15626621Sbt150084 * @mc_addr_count: number of addresses 15636621Sbt150084 * @next: iterator function to walk the multicast address list 15646621Sbt150084 * 15656621Sbt150084 * The given list replaces any existing list. Clears the MC addrs from receive 15666621Sbt150084 * address registers and the multicast table. Uses unused receive address 15676621Sbt150084 * registers for the first multicast addresses, and hashes the rest into the 15686621Sbt150084 * multicast table. 15696621Sbt150084 */ 15706621Sbt150084 s32 15716621Sbt150084 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list, 15726621Sbt150084 u32 mc_addr_count, ixgbe_mc_addr_itr next) 15736621Sbt150084 { 15746621Sbt150084 u32 i; 15756621Sbt150084 u32 vmdq; 15766621Sbt150084 15776621Sbt150084 /* 15786621Sbt150084 * Set the new number of MC addresses that we are being requested to 15796621Sbt150084 * use. 15806621Sbt150084 */ 15816621Sbt150084 hw->addr_ctrl.num_mc_addrs = mc_addr_count; 15826621Sbt150084 hw->addr_ctrl.mta_in_use = 0; 15836621Sbt150084 15846621Sbt150084 /* Clear the MTA */ 15856621Sbt150084 DEBUGOUT(" Clearing MTA\n"); 15866621Sbt150084 for (i = 0; i < hw->mac.mcft_size; i++) 15876621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0); 15886621Sbt150084 15896621Sbt150084 /* Add the new addresses */ 15906621Sbt150084 for (i = 0; i < mc_addr_count; i++) { 15916621Sbt150084 DEBUGOUT(" Adding the multicast addresses:\n"); 15926621Sbt150084 ixgbe_add_mc_addr(hw, next(hw, &mc_addr_list, &vmdq)); 15936621Sbt150084 } 15946621Sbt150084 15956621Sbt150084 /* Enable mta */ 15966621Sbt150084 if (hw->addr_ctrl.mta_in_use > 0) 15976621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, 15986621Sbt150084 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type); 15996621Sbt150084 16006621Sbt150084 DEBUGOUT("ixgbe_update_mc_addr_list_generic Complete\n"); 16016621Sbt150084 return (IXGBE_SUCCESS); 16026621Sbt150084 } 16036621Sbt150084 16046621Sbt150084 /* 16056621Sbt150084 * ixgbe_enable_mc_generic - Enable multicast address in RAR 16066621Sbt150084 * @hw: pointer to hardware structure 16076621Sbt150084 * 16086621Sbt150084 * Enables multicast address in RAR and the use of the multicast hash table. 16096621Sbt150084 */ 16106621Sbt150084 s32 16116621Sbt150084 ixgbe_enable_mc_generic(struct ixgbe_hw *hw) 16126621Sbt150084 { 16136621Sbt150084 u32 i; 16146621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 16156621Sbt150084 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; 16166621Sbt150084 16176621Sbt150084 if (a->mc_addr_in_rar_count > 0) 16186621Sbt150084 for (i = (rar_entries - a->mc_addr_in_rar_count); 16196621Sbt150084 i < rar_entries; i++) 16206621Sbt150084 ixgbe_enable_rar(hw, i); 16216621Sbt150084 16226621Sbt150084 if (a->mta_in_use > 0) 16236621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE | 16246621Sbt150084 hw->mac.mc_filter_type); 16256621Sbt150084 16266621Sbt150084 return (IXGBE_SUCCESS); 16276621Sbt150084 } 16286621Sbt150084 16296621Sbt150084 /* 16306621Sbt150084 * ixgbe_disable_mc_generic - Disable multicast address in RAR 16316621Sbt150084 * @hw: pointer to hardware structure 16326621Sbt150084 * 16336621Sbt150084 * Disables multicast address in RAR and the use of the multicast hash table. 16346621Sbt150084 */ 16356621Sbt150084 s32 16366621Sbt150084 ixgbe_disable_mc_generic(struct ixgbe_hw *hw) 16376621Sbt150084 { 16386621Sbt150084 u32 i; 16396621Sbt150084 u32 rar_entries = hw->mac.num_rar_entries; 16406621Sbt150084 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl; 16416621Sbt150084 16426621Sbt150084 if (a->mc_addr_in_rar_count > 0) 16436621Sbt150084 for (i = (rar_entries - a->mc_addr_in_rar_count); 16446621Sbt150084 i < rar_entries; i++) 16456621Sbt150084 ixgbe_disable_rar(hw, i); 16466621Sbt150084 16476621Sbt150084 if (a->mta_in_use > 0) 16486621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type); 16496621Sbt150084 16506621Sbt150084 return (IXGBE_SUCCESS); 16516621Sbt150084 } 16526621Sbt150084 16536621Sbt150084 /* 16546621Sbt150084 * ixgbe_clear_vfta_generic - Clear VLAN filter table 16556621Sbt150084 * @hw: pointer to hardware structure 16566621Sbt150084 * 16576621Sbt150084 * Clears the VLAN filer table, and the VMDq index associated with the filter 16586621Sbt150084 */ 16596621Sbt150084 s32 16606621Sbt150084 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw) 16616621Sbt150084 { 16626621Sbt150084 u32 offset; 16636621Sbt150084 u32 vlanbyte; 16646621Sbt150084 16656621Sbt150084 for (offset = 0; offset < hw->mac.vft_size; offset++) 16666621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0); 16676621Sbt150084 16686621Sbt150084 for (vlanbyte = 0; vlanbyte < 4; vlanbyte++) 16696621Sbt150084 for (offset = 0; offset < hw->mac.vft_size; offset++) 16706621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(vlanbyte, offset), 16716621Sbt150084 0); 16726621Sbt150084 16736621Sbt150084 return (IXGBE_SUCCESS); 16746621Sbt150084 } 16756621Sbt150084 16766621Sbt150084 /* 16776621Sbt150084 * ixgbe_set_vfta_generic - Set VLAN filter table 16786621Sbt150084 * @hw: pointer to hardware structure 16796621Sbt150084 * @vlan: VLAN id to write to VLAN filter 16806621Sbt150084 * @vind: VMDq output index that maps queue to VLAN id in VFTA 16816621Sbt150084 * @vlan_on: boolean flag to turn on/off VLAN in VFTA 16826621Sbt150084 * 16836621Sbt150084 * Turn on/off specified VLAN in the VLAN filter table. 16846621Sbt150084 */ 16856621Sbt150084 s32 16866621Sbt150084 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind, 16876621Sbt150084 bool vlan_on) 16886621Sbt150084 { 16896621Sbt150084 u32 VftaIndex; 16906621Sbt150084 u32 BitOffset; 16916621Sbt150084 u32 VftaReg; 16926621Sbt150084 u32 VftaByte; 16936621Sbt150084 16946621Sbt150084 /* Determine 32-bit word position in array */ 16956621Sbt150084 VftaIndex = (vlan >> 5) & 0x7F; /* upper seven bits */ 16966621Sbt150084 16976621Sbt150084 /* Determine the location of the (VMD) queue index */ 16986621Sbt150084 VftaByte = ((vlan >> 3) & 0x03); /* bits (4:3) indicating byte array */ 16996621Sbt150084 BitOffset = (vlan & 0x7) << 2; /* lower 3 bits indicate nibble */ 17006621Sbt150084 17016621Sbt150084 /* Set the nibble for VMD queue index */ 17026621Sbt150084 VftaReg = IXGBE_READ_REG(hw, IXGBE_VFTAVIND(VftaByte, VftaIndex)); 17036621Sbt150084 VftaReg &= (~(0x0F << BitOffset)); 17046621Sbt150084 VftaReg |= (vind << BitOffset); 17056621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_VFTAVIND(VftaByte, VftaIndex), VftaReg); 17066621Sbt150084 17076621Sbt150084 /* Determine the location of the bit for this VLAN id */ 17086621Sbt150084 BitOffset = vlan & 0x1F; /* lower five bits */ 17096621Sbt150084 17106621Sbt150084 VftaReg = IXGBE_READ_REG(hw, IXGBE_VFTA(VftaIndex)); 17116621Sbt150084 if (vlan_on) 17126621Sbt150084 /* Turn on this VLAN id */ 17136621Sbt150084 VftaReg |= (1 << BitOffset); 17146621Sbt150084 else 17156621Sbt150084 /* Turn off this VLAN id */ 17166621Sbt150084 VftaReg &= ~(1 << BitOffset); 17176621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_VFTA(VftaIndex), VftaReg); 17186621Sbt150084 17196621Sbt150084 return (IXGBE_SUCCESS); 17206621Sbt150084 } 17216621Sbt150084 17226621Sbt150084 /* 17236621Sbt150084 * ixgbe_disable_pcie_master - Disable PCI-express master access 17246621Sbt150084 * @hw: pointer to hardware structure 17256621Sbt150084 * 17266621Sbt150084 * Disables PCI-Express master access and verifies there are no pending 17276621Sbt150084 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable 17286621Sbt150084 * bit hasn't caused the master requests to be disabled, else IXGBE_SUCCESS 17296621Sbt150084 * is returned signifying master requests disabled. 17306621Sbt150084 */ 17316621Sbt150084 s32 17326621Sbt150084 ixgbe_disable_pcie_master(struct ixgbe_hw *hw) 17336621Sbt150084 { 17346621Sbt150084 u32 ctrl; 17356621Sbt150084 s32 i; 17366621Sbt150084 s32 status = IXGBE_ERR_MASTER_REQUESTS_PENDING; 17376621Sbt150084 17386621Sbt150084 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); 17396621Sbt150084 ctrl |= IXGBE_CTRL_GIO_DIS; 17406621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); 17416621Sbt150084 17426621Sbt150084 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) { 17436621Sbt150084 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO)) { 17446621Sbt150084 status = IXGBE_SUCCESS; 17456621Sbt150084 break; 17466621Sbt150084 } 17476621Sbt150084 usec_delay(100); 17486621Sbt150084 } 17496621Sbt150084 17506621Sbt150084 return (status); 17516621Sbt150084 } 17526621Sbt150084 17536621Sbt150084 17546621Sbt150084 /* 17556621Sbt150084 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore 17566621Sbt150084 * @hw: pointer to hardware structure 17576621Sbt150084 * @mask: Mask to specify which semaphore to acquire 17586621Sbt150084 * 17596621Sbt150084 * Acquires the SWFW semaphore thought the GSSR register for the specified 17606621Sbt150084 * function (CSR, PHY0, PHY1, EEPROM, Flash) 17616621Sbt150084 */ 17626621Sbt150084 s32 17636621Sbt150084 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask) 17646621Sbt150084 { 17656621Sbt150084 u32 gssr; 17666621Sbt150084 u32 swmask = mask; 17676621Sbt150084 u32 fwmask = mask << 5; 17686621Sbt150084 s32 timeout = 200; 17696621Sbt150084 17706621Sbt150084 while (timeout) { 17716621Sbt150084 if (ixgbe_get_eeprom_semaphore(hw)) 17726621Sbt150084 return (-IXGBE_ERR_SWFW_SYNC); 17736621Sbt150084 17746621Sbt150084 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); 17756621Sbt150084 if (!(gssr & (fwmask | swmask))) 17766621Sbt150084 break; 17776621Sbt150084 17786621Sbt150084 /* 17796621Sbt150084 * Firmware currently using resource (fwmask) or other software 17806621Sbt150084 * thread currently using resource (swmask) 17816621Sbt150084 */ 17826621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 17836621Sbt150084 msec_delay(5); 17846621Sbt150084 timeout--; 17856621Sbt150084 } 17866621Sbt150084 17876621Sbt150084 if (!timeout) { 17886621Sbt150084 DEBUGOUT("Driver can't access resource, GSSR timeout.\n"); 17896621Sbt150084 return (-IXGBE_ERR_SWFW_SYNC); 17906621Sbt150084 } 17916621Sbt150084 17926621Sbt150084 gssr |= swmask; 17936621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); 17946621Sbt150084 17956621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 17966621Sbt150084 return (IXGBE_SUCCESS); 17976621Sbt150084 } 17986621Sbt150084 17996621Sbt150084 /* 18006621Sbt150084 * ixgbe_release_swfw_sync - Release SWFW semaphore 18016621Sbt150084 * @hw: pointer to hardware structure 18026621Sbt150084 * @mask: Mask to specify which semaphore to release 18036621Sbt150084 * 18046621Sbt150084 * Releases the SWFW semaphore thought the GSSR register for the specified 18056621Sbt150084 * function (CSR, PHY0, PHY1, EEPROM, Flash) 18066621Sbt150084 */ 18076621Sbt150084 void 18086621Sbt150084 ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask) 18096621Sbt150084 { 18106621Sbt150084 u32 gssr; 18116621Sbt150084 u32 swmask = mask; 18126621Sbt150084 18136621Sbt150084 (void) ixgbe_get_eeprom_semaphore(hw); 18146621Sbt150084 18156621Sbt150084 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR); 18166621Sbt150084 gssr &= ~swmask; 18176621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr); 18186621Sbt150084 18196621Sbt150084 ixgbe_release_eeprom_semaphore(hw); 18206621Sbt150084 } 18216621Sbt150084 18226621Sbt150084 /* 18236621Sbt150084 * ixgbe_read_analog_reg8_generic - Reads 8 bit Atlas analog register 18246621Sbt150084 * @hw: pointer to hardware structure 18256621Sbt150084 * @reg: analog register to read 18266621Sbt150084 * @val: read value 18276621Sbt150084 * 18286621Sbt150084 * Performs read operation to Atlas analog register specified. 18296621Sbt150084 */ 18306621Sbt150084 s32 18316621Sbt150084 ixgbe_read_analog_reg8_generic(struct ixgbe_hw *hw, u32 reg, u8 *val) 18326621Sbt150084 { 18336621Sbt150084 u32 atlas_ctl; 18346621Sbt150084 18356621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, 18366621Sbt150084 IXGBE_ATLASCTL_WRITE_CMD | (reg << 8)); 18376621Sbt150084 IXGBE_WRITE_FLUSH(hw); 18386621Sbt150084 usec_delay(10); 18396621Sbt150084 atlas_ctl = IXGBE_READ_REG(hw, IXGBE_ATLASCTL); 18406621Sbt150084 *val = (u8)atlas_ctl; 18416621Sbt150084 18426621Sbt150084 return (IXGBE_SUCCESS); 18436621Sbt150084 } 18446621Sbt150084 18456621Sbt150084 /* 18466621Sbt150084 * ixgbe_write_analog_reg8_generic - Writes 8 bit Atlas analog register 18476621Sbt150084 * @hw: pointer to hardware structure 18486621Sbt150084 * @reg: atlas register to write 18496621Sbt150084 * @val: value to write 18506621Sbt150084 * 18516621Sbt150084 * Performs write operation to Atlas analog register specified. 18526621Sbt150084 */ 18536621Sbt150084 s32 18546621Sbt150084 ixgbe_write_analog_reg8_generic(struct ixgbe_hw *hw, u32 reg, u8 val) 18556621Sbt150084 { 18566621Sbt150084 u32 atlas_ctl; 18576621Sbt150084 18586621Sbt150084 atlas_ctl = (reg << 8) | val; 18596621Sbt150084 IXGBE_WRITE_REG(hw, IXGBE_ATLASCTL, atlas_ctl); 18606621Sbt150084 IXGBE_WRITE_FLUSH(hw); 18616621Sbt150084 usec_delay(10); 18626621Sbt150084 18636621Sbt150084 return (IXGBE_SUCCESS); 18646621Sbt150084 } 1865