162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* Copyright(c) 2007 - 2018 Intel Corporation. */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci#include <linux/if_ether.h> 562306a36Sopenharmony_ci#include <linux/delay.h> 662306a36Sopenharmony_ci#include <linux/pci.h> 762306a36Sopenharmony_ci#include <linux/netdevice.h> 862306a36Sopenharmony_ci#include <linux/etherdevice.h> 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include "e1000_mac.h" 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include "igb.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_cistatic s32 igb_set_default_fc(struct e1000_hw *hw); 1562306a36Sopenharmony_cistatic void igb_set_fc_watermarks(struct e1000_hw *hw); 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci/** 1862306a36Sopenharmony_ci * igb_get_bus_info_pcie - Get PCIe bus information 1962306a36Sopenharmony_ci * @hw: pointer to the HW structure 2062306a36Sopenharmony_ci * 2162306a36Sopenharmony_ci * Determines and stores the system bus information for a particular 2262306a36Sopenharmony_ci * network interface. The following bus information is determined and stored: 2362306a36Sopenharmony_ci * bus speed, bus width, type (PCIe), and PCIe function. 2462306a36Sopenharmony_ci **/ 2562306a36Sopenharmony_cis32 igb_get_bus_info_pcie(struct e1000_hw *hw) 2662306a36Sopenharmony_ci{ 2762306a36Sopenharmony_ci struct e1000_bus_info *bus = &hw->bus; 2862306a36Sopenharmony_ci s32 ret_val; 2962306a36Sopenharmony_ci u32 reg; 3062306a36Sopenharmony_ci u16 pcie_link_status; 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci bus->type = e1000_bus_type_pci_express; 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci ret_val = igb_read_pcie_cap_reg(hw, 3562306a36Sopenharmony_ci PCI_EXP_LNKSTA, 3662306a36Sopenharmony_ci &pcie_link_status); 3762306a36Sopenharmony_ci if (ret_val) { 3862306a36Sopenharmony_ci bus->width = e1000_bus_width_unknown; 3962306a36Sopenharmony_ci bus->speed = e1000_bus_speed_unknown; 4062306a36Sopenharmony_ci } else { 4162306a36Sopenharmony_ci switch (pcie_link_status & PCI_EXP_LNKSTA_CLS) { 4262306a36Sopenharmony_ci case PCI_EXP_LNKSTA_CLS_2_5GB: 4362306a36Sopenharmony_ci bus->speed = e1000_bus_speed_2500; 4462306a36Sopenharmony_ci break; 4562306a36Sopenharmony_ci case PCI_EXP_LNKSTA_CLS_5_0GB: 4662306a36Sopenharmony_ci bus->speed = e1000_bus_speed_5000; 4762306a36Sopenharmony_ci break; 4862306a36Sopenharmony_ci default: 4962306a36Sopenharmony_ci bus->speed = e1000_bus_speed_unknown; 5062306a36Sopenharmony_ci break; 5162306a36Sopenharmony_ci } 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci bus->width = (enum e1000_bus_width)((pcie_link_status & 5462306a36Sopenharmony_ci PCI_EXP_LNKSTA_NLW) >> 5562306a36Sopenharmony_ci PCI_EXP_LNKSTA_NLW_SHIFT); 5662306a36Sopenharmony_ci } 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci reg = rd32(E1000_STATUS); 5962306a36Sopenharmony_ci bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT; 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci return 0; 6262306a36Sopenharmony_ci} 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci/** 6562306a36Sopenharmony_ci * igb_clear_vfta - Clear VLAN filter table 6662306a36Sopenharmony_ci * @hw: pointer to the HW structure 6762306a36Sopenharmony_ci * 6862306a36Sopenharmony_ci * Clears the register array which contains the VLAN filter table by 6962306a36Sopenharmony_ci * setting all the values to 0. 7062306a36Sopenharmony_ci **/ 7162306a36Sopenharmony_civoid igb_clear_vfta(struct e1000_hw *hw) 7262306a36Sopenharmony_ci{ 7362306a36Sopenharmony_ci u32 offset; 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci for (offset = E1000_VLAN_FILTER_TBL_SIZE; offset--;) 7662306a36Sopenharmony_ci hw->mac.ops.write_vfta(hw, offset, 0); 7762306a36Sopenharmony_ci} 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci/** 8062306a36Sopenharmony_ci * igb_write_vfta - Write value to VLAN filter table 8162306a36Sopenharmony_ci * @hw: pointer to the HW structure 8262306a36Sopenharmony_ci * @offset: register offset in VLAN filter table 8362306a36Sopenharmony_ci * @value: register value written to VLAN filter table 8462306a36Sopenharmony_ci * 8562306a36Sopenharmony_ci * Writes value at the given offset in the register array which stores 8662306a36Sopenharmony_ci * the VLAN filter table. 8762306a36Sopenharmony_ci **/ 8862306a36Sopenharmony_civoid igb_write_vfta(struct e1000_hw *hw, u32 offset, u32 value) 8962306a36Sopenharmony_ci{ 9062306a36Sopenharmony_ci struct igb_adapter *adapter = hw->back; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci array_wr32(E1000_VFTA, offset, value); 9362306a36Sopenharmony_ci wrfl(); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci adapter->shadow_vfta[offset] = value; 9662306a36Sopenharmony_ci} 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci/** 9962306a36Sopenharmony_ci * igb_init_rx_addrs - Initialize receive address's 10062306a36Sopenharmony_ci * @hw: pointer to the HW structure 10162306a36Sopenharmony_ci * @rar_count: receive address registers 10262306a36Sopenharmony_ci * 10362306a36Sopenharmony_ci * Setups the receive address registers by setting the base receive address 10462306a36Sopenharmony_ci * register to the devices MAC address and clearing all the other receive 10562306a36Sopenharmony_ci * address registers to 0. 10662306a36Sopenharmony_ci **/ 10762306a36Sopenharmony_civoid igb_init_rx_addrs(struct e1000_hw *hw, u16 rar_count) 10862306a36Sopenharmony_ci{ 10962306a36Sopenharmony_ci u32 i; 11062306a36Sopenharmony_ci u8 mac_addr[ETH_ALEN] = {0}; 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci /* Setup the receive address */ 11362306a36Sopenharmony_ci hw_dbg("Programming MAC Address into RAR[0]\n"); 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci hw->mac.ops.rar_set(hw, hw->mac.addr, 0); 11662306a36Sopenharmony_ci 11762306a36Sopenharmony_ci /* Zero out the other (rar_entry_count - 1) receive addresses */ 11862306a36Sopenharmony_ci hw_dbg("Clearing RAR[1-%u]\n", rar_count-1); 11962306a36Sopenharmony_ci for (i = 1; i < rar_count; i++) 12062306a36Sopenharmony_ci hw->mac.ops.rar_set(hw, mac_addr, i); 12162306a36Sopenharmony_ci} 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci/** 12462306a36Sopenharmony_ci * igb_find_vlvf_slot - find the VLAN id or the first empty slot 12562306a36Sopenharmony_ci * @hw: pointer to hardware structure 12662306a36Sopenharmony_ci * @vlan: VLAN id to write to VLAN filter 12762306a36Sopenharmony_ci * @vlvf_bypass: skip VLVF if no match is found 12862306a36Sopenharmony_ci * 12962306a36Sopenharmony_ci * return the VLVF index where this VLAN id should be placed 13062306a36Sopenharmony_ci * 13162306a36Sopenharmony_ci **/ 13262306a36Sopenharmony_cistatic s32 igb_find_vlvf_slot(struct e1000_hw *hw, u32 vlan, bool vlvf_bypass) 13362306a36Sopenharmony_ci{ 13462306a36Sopenharmony_ci s32 regindex, first_empty_slot; 13562306a36Sopenharmony_ci u32 bits; 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci /* short cut the special case */ 13862306a36Sopenharmony_ci if (vlan == 0) 13962306a36Sopenharmony_ci return 0; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci /* if vlvf_bypass is set we don't want to use an empty slot, we 14262306a36Sopenharmony_ci * will simply bypass the VLVF if there are no entries present in the 14362306a36Sopenharmony_ci * VLVF that contain our VLAN 14462306a36Sopenharmony_ci */ 14562306a36Sopenharmony_ci first_empty_slot = vlvf_bypass ? -E1000_ERR_NO_SPACE : 0; 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci /* Search for the VLAN id in the VLVF entries. Save off the first empty 14862306a36Sopenharmony_ci * slot found along the way. 14962306a36Sopenharmony_ci * 15062306a36Sopenharmony_ci * pre-decrement loop covering (IXGBE_VLVF_ENTRIES - 1) .. 1 15162306a36Sopenharmony_ci */ 15262306a36Sopenharmony_ci for (regindex = E1000_VLVF_ARRAY_SIZE; --regindex > 0;) { 15362306a36Sopenharmony_ci bits = rd32(E1000_VLVF(regindex)) & E1000_VLVF_VLANID_MASK; 15462306a36Sopenharmony_ci if (bits == vlan) 15562306a36Sopenharmony_ci return regindex; 15662306a36Sopenharmony_ci if (!first_empty_slot && !bits) 15762306a36Sopenharmony_ci first_empty_slot = regindex; 15862306a36Sopenharmony_ci } 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci return first_empty_slot ? : -E1000_ERR_NO_SPACE; 16162306a36Sopenharmony_ci} 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci/** 16462306a36Sopenharmony_ci * igb_vfta_set - enable or disable vlan in VLAN filter table 16562306a36Sopenharmony_ci * @hw: pointer to the HW structure 16662306a36Sopenharmony_ci * @vlan: VLAN id to add or remove 16762306a36Sopenharmony_ci * @vind: VMDq output index that maps queue to VLAN id 16862306a36Sopenharmony_ci * @vlan_on: if true add filter, if false remove 16962306a36Sopenharmony_ci * @vlvf_bypass: skip VLVF if no match is found 17062306a36Sopenharmony_ci * 17162306a36Sopenharmony_ci * Sets or clears a bit in the VLAN filter table array based on VLAN id 17262306a36Sopenharmony_ci * and if we are adding or removing the filter 17362306a36Sopenharmony_ci **/ 17462306a36Sopenharmony_cis32 igb_vfta_set(struct e1000_hw *hw, u32 vlan, u32 vind, 17562306a36Sopenharmony_ci bool vlan_on, bool vlvf_bypass) 17662306a36Sopenharmony_ci{ 17762306a36Sopenharmony_ci struct igb_adapter *adapter = hw->back; 17862306a36Sopenharmony_ci u32 regidx, vfta_delta, vfta, bits; 17962306a36Sopenharmony_ci s32 vlvf_index; 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci if ((vlan > 4095) || (vind > 7)) 18262306a36Sopenharmony_ci return -E1000_ERR_PARAM; 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci /* this is a 2 part operation - first the VFTA, then the 18562306a36Sopenharmony_ci * VLVF and VLVFB if VT Mode is set 18662306a36Sopenharmony_ci * We don't write the VFTA until we know the VLVF part succeeded. 18762306a36Sopenharmony_ci */ 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci /* Part 1 19062306a36Sopenharmony_ci * The VFTA is a bitstring made up of 128 32-bit registers 19162306a36Sopenharmony_ci * that enable the particular VLAN id, much like the MTA: 19262306a36Sopenharmony_ci * bits[11-5]: which register 19362306a36Sopenharmony_ci * bits[4-0]: which bit in the register 19462306a36Sopenharmony_ci */ 19562306a36Sopenharmony_ci regidx = vlan / 32; 19662306a36Sopenharmony_ci vfta_delta = BIT(vlan % 32); 19762306a36Sopenharmony_ci vfta = adapter->shadow_vfta[regidx]; 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci /* vfta_delta represents the difference between the current value 20062306a36Sopenharmony_ci * of vfta and the value we want in the register. Since the diff 20162306a36Sopenharmony_ci * is an XOR mask we can just update vfta using an XOR. 20262306a36Sopenharmony_ci */ 20362306a36Sopenharmony_ci vfta_delta &= vlan_on ? ~vfta : vfta; 20462306a36Sopenharmony_ci vfta ^= vfta_delta; 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci /* Part 2 20762306a36Sopenharmony_ci * If VT Mode is set 20862306a36Sopenharmony_ci * Either vlan_on 20962306a36Sopenharmony_ci * make sure the VLAN is in VLVF 21062306a36Sopenharmony_ci * set the vind bit in the matching VLVFB 21162306a36Sopenharmony_ci * Or !vlan_on 21262306a36Sopenharmony_ci * clear the pool bit and possibly the vind 21362306a36Sopenharmony_ci */ 21462306a36Sopenharmony_ci if (!adapter->vfs_allocated_count) 21562306a36Sopenharmony_ci goto vfta_update; 21662306a36Sopenharmony_ci 21762306a36Sopenharmony_ci vlvf_index = igb_find_vlvf_slot(hw, vlan, vlvf_bypass); 21862306a36Sopenharmony_ci if (vlvf_index < 0) { 21962306a36Sopenharmony_ci if (vlvf_bypass) 22062306a36Sopenharmony_ci goto vfta_update; 22162306a36Sopenharmony_ci return vlvf_index; 22262306a36Sopenharmony_ci } 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci bits = rd32(E1000_VLVF(vlvf_index)); 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci /* set the pool bit */ 22762306a36Sopenharmony_ci bits |= BIT(E1000_VLVF_POOLSEL_SHIFT + vind); 22862306a36Sopenharmony_ci if (vlan_on) 22962306a36Sopenharmony_ci goto vlvf_update; 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci /* clear the pool bit */ 23262306a36Sopenharmony_ci bits ^= BIT(E1000_VLVF_POOLSEL_SHIFT + vind); 23362306a36Sopenharmony_ci 23462306a36Sopenharmony_ci if (!(bits & E1000_VLVF_POOLSEL_MASK)) { 23562306a36Sopenharmony_ci /* Clear VFTA first, then disable VLVF. Otherwise 23662306a36Sopenharmony_ci * we run the risk of stray packets leaking into 23762306a36Sopenharmony_ci * the PF via the default pool 23862306a36Sopenharmony_ci */ 23962306a36Sopenharmony_ci if (vfta_delta) 24062306a36Sopenharmony_ci hw->mac.ops.write_vfta(hw, regidx, vfta); 24162306a36Sopenharmony_ci 24262306a36Sopenharmony_ci /* disable VLVF and clear remaining bit from pool */ 24362306a36Sopenharmony_ci wr32(E1000_VLVF(vlvf_index), 0); 24462306a36Sopenharmony_ci 24562306a36Sopenharmony_ci return 0; 24662306a36Sopenharmony_ci } 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci /* If there are still bits set in the VLVFB registers 24962306a36Sopenharmony_ci * for the VLAN ID indicated we need to see if the 25062306a36Sopenharmony_ci * caller is requesting that we clear the VFTA entry bit. 25162306a36Sopenharmony_ci * If the caller has requested that we clear the VFTA 25262306a36Sopenharmony_ci * entry bit but there are still pools/VFs using this VLAN 25362306a36Sopenharmony_ci * ID entry then ignore the request. We're not worried 25462306a36Sopenharmony_ci * about the case where we're turning the VFTA VLAN ID 25562306a36Sopenharmony_ci * entry bit on, only when requested to turn it off as 25662306a36Sopenharmony_ci * there may be multiple pools and/or VFs using the 25762306a36Sopenharmony_ci * VLAN ID entry. In that case we cannot clear the 25862306a36Sopenharmony_ci * VFTA bit until all pools/VFs using that VLAN ID have also 25962306a36Sopenharmony_ci * been cleared. This will be indicated by "bits" being 26062306a36Sopenharmony_ci * zero. 26162306a36Sopenharmony_ci */ 26262306a36Sopenharmony_ci vfta_delta = 0; 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_civlvf_update: 26562306a36Sopenharmony_ci /* record pool change and enable VLAN ID if not already enabled */ 26662306a36Sopenharmony_ci wr32(E1000_VLVF(vlvf_index), bits | vlan | E1000_VLVF_VLANID_ENABLE); 26762306a36Sopenharmony_ci 26862306a36Sopenharmony_civfta_update: 26962306a36Sopenharmony_ci /* bit was set/cleared before we started */ 27062306a36Sopenharmony_ci if (vfta_delta) 27162306a36Sopenharmony_ci hw->mac.ops.write_vfta(hw, regidx, vfta); 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci return 0; 27462306a36Sopenharmony_ci} 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci/** 27762306a36Sopenharmony_ci * igb_check_alt_mac_addr - Check for alternate MAC addr 27862306a36Sopenharmony_ci * @hw: pointer to the HW structure 27962306a36Sopenharmony_ci * 28062306a36Sopenharmony_ci * Checks the nvm for an alternate MAC address. An alternate MAC address 28162306a36Sopenharmony_ci * can be setup by pre-boot software and must be treated like a permanent 28262306a36Sopenharmony_ci * address and must override the actual permanent MAC address. If an 28362306a36Sopenharmony_ci * alternate MAC address is found it is saved in the hw struct and 28462306a36Sopenharmony_ci * programmed into RAR0 and the function returns success, otherwise the 28562306a36Sopenharmony_ci * function returns an error. 28662306a36Sopenharmony_ci **/ 28762306a36Sopenharmony_cis32 igb_check_alt_mac_addr(struct e1000_hw *hw) 28862306a36Sopenharmony_ci{ 28962306a36Sopenharmony_ci u32 i; 29062306a36Sopenharmony_ci s32 ret_val = 0; 29162306a36Sopenharmony_ci u16 offset, nvm_alt_mac_addr_offset, nvm_data; 29262306a36Sopenharmony_ci u8 alt_mac_addr[ETH_ALEN]; 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci /* Alternate MAC address is handled by the option ROM for 82580 29562306a36Sopenharmony_ci * and newer. SW support not required. 29662306a36Sopenharmony_ci */ 29762306a36Sopenharmony_ci if (hw->mac.type >= e1000_82580) 29862306a36Sopenharmony_ci goto out; 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1, 30162306a36Sopenharmony_ci &nvm_alt_mac_addr_offset); 30262306a36Sopenharmony_ci if (ret_val) { 30362306a36Sopenharmony_ci hw_dbg("NVM Read Error\n"); 30462306a36Sopenharmony_ci goto out; 30562306a36Sopenharmony_ci } 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ci if ((nvm_alt_mac_addr_offset == 0xFFFF) || 30862306a36Sopenharmony_ci (nvm_alt_mac_addr_offset == 0x0000)) 30962306a36Sopenharmony_ci /* There is no Alternate MAC Address */ 31062306a36Sopenharmony_ci goto out; 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci if (hw->bus.func == E1000_FUNC_1) 31362306a36Sopenharmony_ci nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1; 31462306a36Sopenharmony_ci if (hw->bus.func == E1000_FUNC_2) 31562306a36Sopenharmony_ci nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN2; 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ci if (hw->bus.func == E1000_FUNC_3) 31862306a36Sopenharmony_ci nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN3; 31962306a36Sopenharmony_ci for (i = 0; i < ETH_ALEN; i += 2) { 32062306a36Sopenharmony_ci offset = nvm_alt_mac_addr_offset + (i >> 1); 32162306a36Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data); 32262306a36Sopenharmony_ci if (ret_val) { 32362306a36Sopenharmony_ci hw_dbg("NVM Read Error\n"); 32462306a36Sopenharmony_ci goto out; 32562306a36Sopenharmony_ci } 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci alt_mac_addr[i] = (u8)(nvm_data & 0xFF); 32862306a36Sopenharmony_ci alt_mac_addr[i + 1] = (u8)(nvm_data >> 8); 32962306a36Sopenharmony_ci } 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci /* if multicast bit is set, the alternate address will not be used */ 33262306a36Sopenharmony_ci if (is_multicast_ether_addr(alt_mac_addr)) { 33362306a36Sopenharmony_ci hw_dbg("Ignoring Alternate Mac Address with MC bit set\n"); 33462306a36Sopenharmony_ci goto out; 33562306a36Sopenharmony_ci } 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci /* We have a valid alternate MAC address, and we want to treat it the 33862306a36Sopenharmony_ci * same as the normal permanent MAC address stored by the HW into the 33962306a36Sopenharmony_ci * RAR. Do this by mapping this address into RAR0. 34062306a36Sopenharmony_ci */ 34162306a36Sopenharmony_ci hw->mac.ops.rar_set(hw, alt_mac_addr, 0); 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ciout: 34462306a36Sopenharmony_ci return ret_val; 34562306a36Sopenharmony_ci} 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci/** 34862306a36Sopenharmony_ci * igb_rar_set - Set receive address register 34962306a36Sopenharmony_ci * @hw: pointer to the HW structure 35062306a36Sopenharmony_ci * @addr: pointer to the receive address 35162306a36Sopenharmony_ci * @index: receive address array register 35262306a36Sopenharmony_ci * 35362306a36Sopenharmony_ci * Sets the receive address array register at index to the address passed 35462306a36Sopenharmony_ci * in by addr. 35562306a36Sopenharmony_ci **/ 35662306a36Sopenharmony_civoid igb_rar_set(struct e1000_hw *hw, u8 *addr, u32 index) 35762306a36Sopenharmony_ci{ 35862306a36Sopenharmony_ci u32 rar_low, rar_high; 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_ci /* HW expects these in little endian so we reverse the byte order 36162306a36Sopenharmony_ci * from network order (big endian) to little endian 36262306a36Sopenharmony_ci */ 36362306a36Sopenharmony_ci rar_low = ((u32) addr[0] | 36462306a36Sopenharmony_ci ((u32) addr[1] << 8) | 36562306a36Sopenharmony_ci ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_ci /* If MAC address zero, no need to set the AV bit */ 37062306a36Sopenharmony_ci if (rar_low || rar_high) 37162306a36Sopenharmony_ci rar_high |= E1000_RAH_AV; 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ci /* Some bridges will combine consecutive 32-bit writes into 37462306a36Sopenharmony_ci * a single burst write, which will malfunction on some parts. 37562306a36Sopenharmony_ci * The flushes avoid this. 37662306a36Sopenharmony_ci */ 37762306a36Sopenharmony_ci wr32(E1000_RAL(index), rar_low); 37862306a36Sopenharmony_ci wrfl(); 37962306a36Sopenharmony_ci wr32(E1000_RAH(index), rar_high); 38062306a36Sopenharmony_ci wrfl(); 38162306a36Sopenharmony_ci} 38262306a36Sopenharmony_ci 38362306a36Sopenharmony_ci/** 38462306a36Sopenharmony_ci * igb_mta_set - Set multicast filter table address 38562306a36Sopenharmony_ci * @hw: pointer to the HW structure 38662306a36Sopenharmony_ci * @hash_value: determines the MTA register and bit to set 38762306a36Sopenharmony_ci * 38862306a36Sopenharmony_ci * The multicast table address is a register array of 32-bit registers. 38962306a36Sopenharmony_ci * The hash_value is used to determine what register the bit is in, the 39062306a36Sopenharmony_ci * current value is read, the new bit is OR'd in and the new value is 39162306a36Sopenharmony_ci * written back into the register. 39262306a36Sopenharmony_ci **/ 39362306a36Sopenharmony_civoid igb_mta_set(struct e1000_hw *hw, u32 hash_value) 39462306a36Sopenharmony_ci{ 39562306a36Sopenharmony_ci u32 hash_bit, hash_reg, mta; 39662306a36Sopenharmony_ci 39762306a36Sopenharmony_ci /* The MTA is a register array of 32-bit registers. It is 39862306a36Sopenharmony_ci * treated like an array of (32*mta_reg_count) bits. We want to 39962306a36Sopenharmony_ci * set bit BitArray[hash_value]. So we figure out what register 40062306a36Sopenharmony_ci * the bit is in, read it, OR in the new bit, then write 40162306a36Sopenharmony_ci * back the new value. The (hw->mac.mta_reg_count - 1) serves as a 40262306a36Sopenharmony_ci * mask to bits 31:5 of the hash value which gives us the 40362306a36Sopenharmony_ci * register we're modifying. The hash bit within that register 40462306a36Sopenharmony_ci * is determined by the lower 5 bits of the hash value. 40562306a36Sopenharmony_ci */ 40662306a36Sopenharmony_ci hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); 40762306a36Sopenharmony_ci hash_bit = hash_value & 0x1F; 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_ci mta = array_rd32(E1000_MTA, hash_reg); 41062306a36Sopenharmony_ci 41162306a36Sopenharmony_ci mta |= BIT(hash_bit); 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci array_wr32(E1000_MTA, hash_reg, mta); 41462306a36Sopenharmony_ci wrfl(); 41562306a36Sopenharmony_ci} 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci/** 41862306a36Sopenharmony_ci * igb_hash_mc_addr - Generate a multicast hash value 41962306a36Sopenharmony_ci * @hw: pointer to the HW structure 42062306a36Sopenharmony_ci * @mc_addr: pointer to a multicast address 42162306a36Sopenharmony_ci * 42262306a36Sopenharmony_ci * Generates a multicast address hash value which is used to determine 42362306a36Sopenharmony_ci * the multicast filter table array address and new table value. See 42462306a36Sopenharmony_ci * igb_mta_set() 42562306a36Sopenharmony_ci **/ 42662306a36Sopenharmony_cistatic u32 igb_hash_mc_addr(struct e1000_hw *hw, u8 *mc_addr) 42762306a36Sopenharmony_ci{ 42862306a36Sopenharmony_ci u32 hash_value, hash_mask; 42962306a36Sopenharmony_ci u8 bit_shift = 1; 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_ci /* Register count multiplied by bits per register */ 43262306a36Sopenharmony_ci hash_mask = (hw->mac.mta_reg_count * 32) - 1; 43362306a36Sopenharmony_ci 43462306a36Sopenharmony_ci /* For a mc_filter_type of 0, bit_shift is the number of left-shifts 43562306a36Sopenharmony_ci * where 0xFF would still fall within the hash mask. 43662306a36Sopenharmony_ci */ 43762306a36Sopenharmony_ci while (hash_mask >> bit_shift != 0xFF && bit_shift < 4) 43862306a36Sopenharmony_ci bit_shift++; 43962306a36Sopenharmony_ci 44062306a36Sopenharmony_ci /* The portion of the address that is used for the hash table 44162306a36Sopenharmony_ci * is determined by the mc_filter_type setting. 44262306a36Sopenharmony_ci * The algorithm is such that there is a total of 8 bits of shifting. 44362306a36Sopenharmony_ci * The bit_shift for a mc_filter_type of 0 represents the number of 44462306a36Sopenharmony_ci * left-shifts where the MSB of mc_addr[5] would still fall within 44562306a36Sopenharmony_ci * the hash_mask. Case 0 does this exactly. Since there are a total 44662306a36Sopenharmony_ci * of 8 bits of shifting, then mc_addr[4] will shift right the 44762306a36Sopenharmony_ci * remaining number of bits. Thus 8 - bit_shift. The rest of the 44862306a36Sopenharmony_ci * cases are a variation of this algorithm...essentially raising the 44962306a36Sopenharmony_ci * number of bits to shift mc_addr[5] left, while still keeping the 45062306a36Sopenharmony_ci * 8-bit shifting total. 45162306a36Sopenharmony_ci * 45262306a36Sopenharmony_ci * For example, given the following Destination MAC Address and an 45362306a36Sopenharmony_ci * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask), 45462306a36Sopenharmony_ci * we can see that the bit_shift for case 0 is 4. These are the hash 45562306a36Sopenharmony_ci * values resulting from each mc_filter_type... 45662306a36Sopenharmony_ci * [0] [1] [2] [3] [4] [5] 45762306a36Sopenharmony_ci * 01 AA 00 12 34 56 45862306a36Sopenharmony_ci * LSB MSB 45962306a36Sopenharmony_ci * 46062306a36Sopenharmony_ci * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563 46162306a36Sopenharmony_ci * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6 46262306a36Sopenharmony_ci * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163 46362306a36Sopenharmony_ci * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634 46462306a36Sopenharmony_ci */ 46562306a36Sopenharmony_ci switch (hw->mac.mc_filter_type) { 46662306a36Sopenharmony_ci default: 46762306a36Sopenharmony_ci case 0: 46862306a36Sopenharmony_ci break; 46962306a36Sopenharmony_ci case 1: 47062306a36Sopenharmony_ci bit_shift += 1; 47162306a36Sopenharmony_ci break; 47262306a36Sopenharmony_ci case 2: 47362306a36Sopenharmony_ci bit_shift += 2; 47462306a36Sopenharmony_ci break; 47562306a36Sopenharmony_ci case 3: 47662306a36Sopenharmony_ci bit_shift += 4; 47762306a36Sopenharmony_ci break; 47862306a36Sopenharmony_ci } 47962306a36Sopenharmony_ci 48062306a36Sopenharmony_ci hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) | 48162306a36Sopenharmony_ci (((u16) mc_addr[5]) << bit_shift))); 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_ci return hash_value; 48462306a36Sopenharmony_ci} 48562306a36Sopenharmony_ci 48662306a36Sopenharmony_ci/** 48762306a36Sopenharmony_ci * igb_i21x_hw_doublecheck - double checks potential HW issue in i21X 48862306a36Sopenharmony_ci * @hw: pointer to the HW structure 48962306a36Sopenharmony_ci * 49062306a36Sopenharmony_ci * Checks if multicast array is wrote correctly 49162306a36Sopenharmony_ci * If not then rewrites again to register 49262306a36Sopenharmony_ci **/ 49362306a36Sopenharmony_cistatic void igb_i21x_hw_doublecheck(struct e1000_hw *hw) 49462306a36Sopenharmony_ci{ 49562306a36Sopenharmony_ci int failed_cnt = 3; 49662306a36Sopenharmony_ci bool is_failed; 49762306a36Sopenharmony_ci int i; 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci do { 50062306a36Sopenharmony_ci is_failed = false; 50162306a36Sopenharmony_ci for (i = hw->mac.mta_reg_count - 1; i >= 0; i--) { 50262306a36Sopenharmony_ci if (array_rd32(E1000_MTA, i) != hw->mac.mta_shadow[i]) { 50362306a36Sopenharmony_ci is_failed = true; 50462306a36Sopenharmony_ci array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]); 50562306a36Sopenharmony_ci wrfl(); 50662306a36Sopenharmony_ci } 50762306a36Sopenharmony_ci } 50862306a36Sopenharmony_ci if (is_failed && --failed_cnt <= 0) { 50962306a36Sopenharmony_ci hw_dbg("Failed to update MTA_REGISTER, too many retries"); 51062306a36Sopenharmony_ci break; 51162306a36Sopenharmony_ci } 51262306a36Sopenharmony_ci } while (is_failed); 51362306a36Sopenharmony_ci} 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci/** 51662306a36Sopenharmony_ci * igb_update_mc_addr_list - Update Multicast addresses 51762306a36Sopenharmony_ci * @hw: pointer to the HW structure 51862306a36Sopenharmony_ci * @mc_addr_list: array of multicast addresses to program 51962306a36Sopenharmony_ci * @mc_addr_count: number of multicast addresses to program 52062306a36Sopenharmony_ci * 52162306a36Sopenharmony_ci * Updates entire Multicast Table Array. 52262306a36Sopenharmony_ci * The caller must have a packed mc_addr_list of multicast addresses. 52362306a36Sopenharmony_ci **/ 52462306a36Sopenharmony_civoid igb_update_mc_addr_list(struct e1000_hw *hw, 52562306a36Sopenharmony_ci u8 *mc_addr_list, u32 mc_addr_count) 52662306a36Sopenharmony_ci{ 52762306a36Sopenharmony_ci u32 hash_value, hash_bit, hash_reg; 52862306a36Sopenharmony_ci int i; 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_ci /* clear mta_shadow */ 53162306a36Sopenharmony_ci memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow)); 53262306a36Sopenharmony_ci 53362306a36Sopenharmony_ci /* update mta_shadow from mc_addr_list */ 53462306a36Sopenharmony_ci for (i = 0; (u32) i < mc_addr_count; i++) { 53562306a36Sopenharmony_ci hash_value = igb_hash_mc_addr(hw, mc_addr_list); 53662306a36Sopenharmony_ci 53762306a36Sopenharmony_ci hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); 53862306a36Sopenharmony_ci hash_bit = hash_value & 0x1F; 53962306a36Sopenharmony_ci 54062306a36Sopenharmony_ci hw->mac.mta_shadow[hash_reg] |= BIT(hash_bit); 54162306a36Sopenharmony_ci mc_addr_list += (ETH_ALEN); 54262306a36Sopenharmony_ci } 54362306a36Sopenharmony_ci 54462306a36Sopenharmony_ci /* replace the entire MTA table */ 54562306a36Sopenharmony_ci for (i = hw->mac.mta_reg_count - 1; i >= 0; i--) 54662306a36Sopenharmony_ci array_wr32(E1000_MTA, i, hw->mac.mta_shadow[i]); 54762306a36Sopenharmony_ci wrfl(); 54862306a36Sopenharmony_ci if (hw->mac.type == e1000_i210 || hw->mac.type == e1000_i211) 54962306a36Sopenharmony_ci igb_i21x_hw_doublecheck(hw); 55062306a36Sopenharmony_ci} 55162306a36Sopenharmony_ci 55262306a36Sopenharmony_ci/** 55362306a36Sopenharmony_ci * igb_clear_hw_cntrs_base - Clear base hardware counters 55462306a36Sopenharmony_ci * @hw: pointer to the HW structure 55562306a36Sopenharmony_ci * 55662306a36Sopenharmony_ci * Clears the base hardware counters by reading the counter registers. 55762306a36Sopenharmony_ci **/ 55862306a36Sopenharmony_civoid igb_clear_hw_cntrs_base(struct e1000_hw *hw) 55962306a36Sopenharmony_ci{ 56062306a36Sopenharmony_ci rd32(E1000_CRCERRS); 56162306a36Sopenharmony_ci rd32(E1000_SYMERRS); 56262306a36Sopenharmony_ci rd32(E1000_MPC); 56362306a36Sopenharmony_ci rd32(E1000_SCC); 56462306a36Sopenharmony_ci rd32(E1000_ECOL); 56562306a36Sopenharmony_ci rd32(E1000_MCC); 56662306a36Sopenharmony_ci rd32(E1000_LATECOL); 56762306a36Sopenharmony_ci rd32(E1000_COLC); 56862306a36Sopenharmony_ci rd32(E1000_DC); 56962306a36Sopenharmony_ci rd32(E1000_SEC); 57062306a36Sopenharmony_ci rd32(E1000_RLEC); 57162306a36Sopenharmony_ci rd32(E1000_XONRXC); 57262306a36Sopenharmony_ci rd32(E1000_XONTXC); 57362306a36Sopenharmony_ci rd32(E1000_XOFFRXC); 57462306a36Sopenharmony_ci rd32(E1000_XOFFTXC); 57562306a36Sopenharmony_ci rd32(E1000_FCRUC); 57662306a36Sopenharmony_ci rd32(E1000_GPRC); 57762306a36Sopenharmony_ci rd32(E1000_BPRC); 57862306a36Sopenharmony_ci rd32(E1000_MPRC); 57962306a36Sopenharmony_ci rd32(E1000_GPTC); 58062306a36Sopenharmony_ci rd32(E1000_GORCL); 58162306a36Sopenharmony_ci rd32(E1000_GORCH); 58262306a36Sopenharmony_ci rd32(E1000_GOTCL); 58362306a36Sopenharmony_ci rd32(E1000_GOTCH); 58462306a36Sopenharmony_ci rd32(E1000_RNBC); 58562306a36Sopenharmony_ci rd32(E1000_RUC); 58662306a36Sopenharmony_ci rd32(E1000_RFC); 58762306a36Sopenharmony_ci rd32(E1000_ROC); 58862306a36Sopenharmony_ci rd32(E1000_RJC); 58962306a36Sopenharmony_ci rd32(E1000_TORL); 59062306a36Sopenharmony_ci rd32(E1000_TORH); 59162306a36Sopenharmony_ci rd32(E1000_TOTL); 59262306a36Sopenharmony_ci rd32(E1000_TOTH); 59362306a36Sopenharmony_ci rd32(E1000_TPR); 59462306a36Sopenharmony_ci rd32(E1000_TPT); 59562306a36Sopenharmony_ci rd32(E1000_MPTC); 59662306a36Sopenharmony_ci rd32(E1000_BPTC); 59762306a36Sopenharmony_ci} 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_ci/** 60062306a36Sopenharmony_ci * igb_check_for_copper_link - Check for link (Copper) 60162306a36Sopenharmony_ci * @hw: pointer to the HW structure 60262306a36Sopenharmony_ci * 60362306a36Sopenharmony_ci * Checks to see of the link status of the hardware has changed. If a 60462306a36Sopenharmony_ci * change in link status has been detected, then we read the PHY registers 60562306a36Sopenharmony_ci * to get the current speed/duplex if link exists. 60662306a36Sopenharmony_ci **/ 60762306a36Sopenharmony_cis32 igb_check_for_copper_link(struct e1000_hw *hw) 60862306a36Sopenharmony_ci{ 60962306a36Sopenharmony_ci struct e1000_mac_info *mac = &hw->mac; 61062306a36Sopenharmony_ci s32 ret_val; 61162306a36Sopenharmony_ci bool link; 61262306a36Sopenharmony_ci 61362306a36Sopenharmony_ci /* We only want to go out to the PHY registers to see if Auto-Neg 61462306a36Sopenharmony_ci * has completed and/or if our link status has changed. The 61562306a36Sopenharmony_ci * get_link_status flag is set upon receiving a Link Status 61662306a36Sopenharmony_ci * Change or Rx Sequence Error interrupt. 61762306a36Sopenharmony_ci */ 61862306a36Sopenharmony_ci if (!mac->get_link_status) { 61962306a36Sopenharmony_ci ret_val = 0; 62062306a36Sopenharmony_ci goto out; 62162306a36Sopenharmony_ci } 62262306a36Sopenharmony_ci 62362306a36Sopenharmony_ci /* First we want to see if the MII Status Register reports 62462306a36Sopenharmony_ci * link. If so, then we want to get the current speed/duplex 62562306a36Sopenharmony_ci * of the PHY. 62662306a36Sopenharmony_ci */ 62762306a36Sopenharmony_ci ret_val = igb_phy_has_link(hw, 1, 0, &link); 62862306a36Sopenharmony_ci if (ret_val) 62962306a36Sopenharmony_ci goto out; 63062306a36Sopenharmony_ci 63162306a36Sopenharmony_ci if (!link) 63262306a36Sopenharmony_ci goto out; /* No link detected */ 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_ci mac->get_link_status = false; 63562306a36Sopenharmony_ci 63662306a36Sopenharmony_ci /* Check if there was DownShift, must be checked 63762306a36Sopenharmony_ci * immediately after link-up 63862306a36Sopenharmony_ci */ 63962306a36Sopenharmony_ci igb_check_downshift(hw); 64062306a36Sopenharmony_ci 64162306a36Sopenharmony_ci /* If we are forcing speed/duplex, then we simply return since 64262306a36Sopenharmony_ci * we have already determined whether we have link or not. 64362306a36Sopenharmony_ci */ 64462306a36Sopenharmony_ci if (!mac->autoneg) { 64562306a36Sopenharmony_ci ret_val = -E1000_ERR_CONFIG; 64662306a36Sopenharmony_ci goto out; 64762306a36Sopenharmony_ci } 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_ci /* Auto-Neg is enabled. Auto Speed Detection takes care 65062306a36Sopenharmony_ci * of MAC speed/duplex configuration. So we only need to 65162306a36Sopenharmony_ci * configure Collision Distance in the MAC. 65262306a36Sopenharmony_ci */ 65362306a36Sopenharmony_ci igb_config_collision_dist(hw); 65462306a36Sopenharmony_ci 65562306a36Sopenharmony_ci /* Configure Flow Control now that Auto-Neg has completed. 65662306a36Sopenharmony_ci * First, we need to restore the desired flow control 65762306a36Sopenharmony_ci * settings because we may have had to re-autoneg with a 65862306a36Sopenharmony_ci * different link partner. 65962306a36Sopenharmony_ci */ 66062306a36Sopenharmony_ci ret_val = igb_config_fc_after_link_up(hw); 66162306a36Sopenharmony_ci if (ret_val) 66262306a36Sopenharmony_ci hw_dbg("Error configuring flow control\n"); 66362306a36Sopenharmony_ci 66462306a36Sopenharmony_ciout: 66562306a36Sopenharmony_ci return ret_val; 66662306a36Sopenharmony_ci} 66762306a36Sopenharmony_ci 66862306a36Sopenharmony_ci/** 66962306a36Sopenharmony_ci * igb_setup_link - Setup flow control and link settings 67062306a36Sopenharmony_ci * @hw: pointer to the HW structure 67162306a36Sopenharmony_ci * 67262306a36Sopenharmony_ci * Determines which flow control settings to use, then configures flow 67362306a36Sopenharmony_ci * control. Calls the appropriate media-specific link configuration 67462306a36Sopenharmony_ci * function. Assuming the adapter has a valid link partner, a valid link 67562306a36Sopenharmony_ci * should be established. Assumes the hardware has previously been reset 67662306a36Sopenharmony_ci * and the transmitter and receiver are not enabled. 67762306a36Sopenharmony_ci **/ 67862306a36Sopenharmony_cis32 igb_setup_link(struct e1000_hw *hw) 67962306a36Sopenharmony_ci{ 68062306a36Sopenharmony_ci s32 ret_val = 0; 68162306a36Sopenharmony_ci 68262306a36Sopenharmony_ci /* In the case of the phy reset being blocked, we already have a link. 68362306a36Sopenharmony_ci * We do not need to set it up again. 68462306a36Sopenharmony_ci */ 68562306a36Sopenharmony_ci if (igb_check_reset_block(hw)) 68662306a36Sopenharmony_ci goto out; 68762306a36Sopenharmony_ci 68862306a36Sopenharmony_ci /* If requested flow control is set to default, set flow control 68962306a36Sopenharmony_ci * based on the EEPROM flow control settings. 69062306a36Sopenharmony_ci */ 69162306a36Sopenharmony_ci if (hw->fc.requested_mode == e1000_fc_default) { 69262306a36Sopenharmony_ci ret_val = igb_set_default_fc(hw); 69362306a36Sopenharmony_ci if (ret_val) 69462306a36Sopenharmony_ci goto out; 69562306a36Sopenharmony_ci } 69662306a36Sopenharmony_ci 69762306a36Sopenharmony_ci /* We want to save off the original Flow Control configuration just 69862306a36Sopenharmony_ci * in case we get disconnected and then reconnected into a different 69962306a36Sopenharmony_ci * hub or switch with different Flow Control capabilities. 70062306a36Sopenharmony_ci */ 70162306a36Sopenharmony_ci hw->fc.current_mode = hw->fc.requested_mode; 70262306a36Sopenharmony_ci 70362306a36Sopenharmony_ci hw_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode); 70462306a36Sopenharmony_ci 70562306a36Sopenharmony_ci /* Call the necessary media_type subroutine to configure the link. */ 70662306a36Sopenharmony_ci ret_val = hw->mac.ops.setup_physical_interface(hw); 70762306a36Sopenharmony_ci if (ret_val) 70862306a36Sopenharmony_ci goto out; 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ci /* Initialize the flow control address, type, and PAUSE timer 71162306a36Sopenharmony_ci * registers to their default values. This is done even if flow 71262306a36Sopenharmony_ci * control is disabled, because it does not hurt anything to 71362306a36Sopenharmony_ci * initialize these registers. 71462306a36Sopenharmony_ci */ 71562306a36Sopenharmony_ci hw_dbg("Initializing the Flow Control address, type and timer regs\n"); 71662306a36Sopenharmony_ci wr32(E1000_FCT, FLOW_CONTROL_TYPE); 71762306a36Sopenharmony_ci wr32(E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH); 71862306a36Sopenharmony_ci wr32(E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW); 71962306a36Sopenharmony_ci 72062306a36Sopenharmony_ci wr32(E1000_FCTTV, hw->fc.pause_time); 72162306a36Sopenharmony_ci 72262306a36Sopenharmony_ci igb_set_fc_watermarks(hw); 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_ciout: 72562306a36Sopenharmony_ci 72662306a36Sopenharmony_ci return ret_val; 72762306a36Sopenharmony_ci} 72862306a36Sopenharmony_ci 72962306a36Sopenharmony_ci/** 73062306a36Sopenharmony_ci * igb_config_collision_dist - Configure collision distance 73162306a36Sopenharmony_ci * @hw: pointer to the HW structure 73262306a36Sopenharmony_ci * 73362306a36Sopenharmony_ci * Configures the collision distance to the default value and is used 73462306a36Sopenharmony_ci * during link setup. Currently no func pointer exists and all 73562306a36Sopenharmony_ci * implementations are handled in the generic version of this function. 73662306a36Sopenharmony_ci **/ 73762306a36Sopenharmony_civoid igb_config_collision_dist(struct e1000_hw *hw) 73862306a36Sopenharmony_ci{ 73962306a36Sopenharmony_ci u32 tctl; 74062306a36Sopenharmony_ci 74162306a36Sopenharmony_ci tctl = rd32(E1000_TCTL); 74262306a36Sopenharmony_ci 74362306a36Sopenharmony_ci tctl &= ~E1000_TCTL_COLD; 74462306a36Sopenharmony_ci tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT; 74562306a36Sopenharmony_ci 74662306a36Sopenharmony_ci wr32(E1000_TCTL, tctl); 74762306a36Sopenharmony_ci wrfl(); 74862306a36Sopenharmony_ci} 74962306a36Sopenharmony_ci 75062306a36Sopenharmony_ci/** 75162306a36Sopenharmony_ci * igb_set_fc_watermarks - Set flow control high/low watermarks 75262306a36Sopenharmony_ci * @hw: pointer to the HW structure 75362306a36Sopenharmony_ci * 75462306a36Sopenharmony_ci * Sets the flow control high/low threshold (watermark) registers. If 75562306a36Sopenharmony_ci * flow control XON frame transmission is enabled, then set XON frame 75662306a36Sopenharmony_ci * tansmission as well. 75762306a36Sopenharmony_ci **/ 75862306a36Sopenharmony_cistatic void igb_set_fc_watermarks(struct e1000_hw *hw) 75962306a36Sopenharmony_ci{ 76062306a36Sopenharmony_ci u32 fcrtl = 0, fcrth = 0; 76162306a36Sopenharmony_ci 76262306a36Sopenharmony_ci /* Set the flow control receive threshold registers. Normally, 76362306a36Sopenharmony_ci * these registers will be set to a default threshold that may be 76462306a36Sopenharmony_ci * adjusted later by the driver's runtime code. However, if the 76562306a36Sopenharmony_ci * ability to transmit pause frames is not enabled, then these 76662306a36Sopenharmony_ci * registers will be set to 0. 76762306a36Sopenharmony_ci */ 76862306a36Sopenharmony_ci if (hw->fc.current_mode & e1000_fc_tx_pause) { 76962306a36Sopenharmony_ci /* We need to set up the Receive Threshold high and low water 77062306a36Sopenharmony_ci * marks as well as (optionally) enabling the transmission of 77162306a36Sopenharmony_ci * XON frames. 77262306a36Sopenharmony_ci */ 77362306a36Sopenharmony_ci fcrtl = hw->fc.low_water; 77462306a36Sopenharmony_ci if (hw->fc.send_xon) 77562306a36Sopenharmony_ci fcrtl |= E1000_FCRTL_XONE; 77662306a36Sopenharmony_ci 77762306a36Sopenharmony_ci fcrth = hw->fc.high_water; 77862306a36Sopenharmony_ci } 77962306a36Sopenharmony_ci wr32(E1000_FCRTL, fcrtl); 78062306a36Sopenharmony_ci wr32(E1000_FCRTH, fcrth); 78162306a36Sopenharmony_ci} 78262306a36Sopenharmony_ci 78362306a36Sopenharmony_ci/** 78462306a36Sopenharmony_ci * igb_set_default_fc - Set flow control default values 78562306a36Sopenharmony_ci * @hw: pointer to the HW structure 78662306a36Sopenharmony_ci * 78762306a36Sopenharmony_ci * Read the EEPROM for the default values for flow control and store the 78862306a36Sopenharmony_ci * values. 78962306a36Sopenharmony_ci **/ 79062306a36Sopenharmony_cistatic s32 igb_set_default_fc(struct e1000_hw *hw) 79162306a36Sopenharmony_ci{ 79262306a36Sopenharmony_ci s32 ret_val = 0; 79362306a36Sopenharmony_ci u16 lan_offset; 79462306a36Sopenharmony_ci u16 nvm_data; 79562306a36Sopenharmony_ci 79662306a36Sopenharmony_ci /* Read and store word 0x0F of the EEPROM. This word contains bits 79762306a36Sopenharmony_ci * that determine the hardware's default PAUSE (flow control) mode, 79862306a36Sopenharmony_ci * a bit that determines whether the HW defaults to enabling or 79962306a36Sopenharmony_ci * disabling auto-negotiation, and the direction of the 80062306a36Sopenharmony_ci * SW defined pins. If there is no SW over-ride of the flow 80162306a36Sopenharmony_ci * control setting, then the variable hw->fc will 80262306a36Sopenharmony_ci * be initialized based on a value in the EEPROM. 80362306a36Sopenharmony_ci */ 80462306a36Sopenharmony_ci if (hw->mac.type == e1000_i350) 80562306a36Sopenharmony_ci lan_offset = NVM_82580_LAN_FUNC_OFFSET(hw->bus.func); 80662306a36Sopenharmony_ci else 80762306a36Sopenharmony_ci lan_offset = 0; 80862306a36Sopenharmony_ci 80962306a36Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG + lan_offset, 81062306a36Sopenharmony_ci 1, &nvm_data); 81162306a36Sopenharmony_ci if (ret_val) { 81262306a36Sopenharmony_ci hw_dbg("NVM Read Error\n"); 81362306a36Sopenharmony_ci goto out; 81462306a36Sopenharmony_ci } 81562306a36Sopenharmony_ci 81662306a36Sopenharmony_ci if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0) 81762306a36Sopenharmony_ci hw->fc.requested_mode = e1000_fc_none; 81862306a36Sopenharmony_ci else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == NVM_WORD0F_ASM_DIR) 81962306a36Sopenharmony_ci hw->fc.requested_mode = e1000_fc_tx_pause; 82062306a36Sopenharmony_ci else 82162306a36Sopenharmony_ci hw->fc.requested_mode = e1000_fc_full; 82262306a36Sopenharmony_ci 82362306a36Sopenharmony_ciout: 82462306a36Sopenharmony_ci return ret_val; 82562306a36Sopenharmony_ci} 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_ci/** 82862306a36Sopenharmony_ci * igb_force_mac_fc - Force the MAC's flow control settings 82962306a36Sopenharmony_ci * @hw: pointer to the HW structure 83062306a36Sopenharmony_ci * 83162306a36Sopenharmony_ci * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the 83262306a36Sopenharmony_ci * device control register to reflect the adapter settings. TFCE and RFCE 83362306a36Sopenharmony_ci * need to be explicitly set by software when a copper PHY is used because 83462306a36Sopenharmony_ci * autonegotiation is managed by the PHY rather than the MAC. Software must 83562306a36Sopenharmony_ci * also configure these bits when link is forced on a fiber connection. 83662306a36Sopenharmony_ci **/ 83762306a36Sopenharmony_cis32 igb_force_mac_fc(struct e1000_hw *hw) 83862306a36Sopenharmony_ci{ 83962306a36Sopenharmony_ci u32 ctrl; 84062306a36Sopenharmony_ci s32 ret_val = 0; 84162306a36Sopenharmony_ci 84262306a36Sopenharmony_ci ctrl = rd32(E1000_CTRL); 84362306a36Sopenharmony_ci 84462306a36Sopenharmony_ci /* Because we didn't get link via the internal auto-negotiation 84562306a36Sopenharmony_ci * mechanism (we either forced link or we got link via PHY 84662306a36Sopenharmony_ci * auto-neg), we have to manually enable/disable transmit an 84762306a36Sopenharmony_ci * receive flow control. 84862306a36Sopenharmony_ci * 84962306a36Sopenharmony_ci * The "Case" statement below enables/disable flow control 85062306a36Sopenharmony_ci * according to the "hw->fc.current_mode" parameter. 85162306a36Sopenharmony_ci * 85262306a36Sopenharmony_ci * The possible values of the "fc" parameter are: 85362306a36Sopenharmony_ci * 0: Flow control is completely disabled 85462306a36Sopenharmony_ci * 1: Rx flow control is enabled (we can receive pause 85562306a36Sopenharmony_ci * frames but not send pause frames). 85662306a36Sopenharmony_ci * 2: Tx flow control is enabled (we can send pause frames 85762306a36Sopenharmony_ci * but we do not receive pause frames). 85862306a36Sopenharmony_ci * 3: Both Rx and TX flow control (symmetric) is enabled. 85962306a36Sopenharmony_ci * other: No other values should be possible at this point. 86062306a36Sopenharmony_ci */ 86162306a36Sopenharmony_ci hw_dbg("hw->fc.current_mode = %u\n", hw->fc.current_mode); 86262306a36Sopenharmony_ci 86362306a36Sopenharmony_ci switch (hw->fc.current_mode) { 86462306a36Sopenharmony_ci case e1000_fc_none: 86562306a36Sopenharmony_ci ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); 86662306a36Sopenharmony_ci break; 86762306a36Sopenharmony_ci case e1000_fc_rx_pause: 86862306a36Sopenharmony_ci ctrl &= (~E1000_CTRL_TFCE); 86962306a36Sopenharmony_ci ctrl |= E1000_CTRL_RFCE; 87062306a36Sopenharmony_ci break; 87162306a36Sopenharmony_ci case e1000_fc_tx_pause: 87262306a36Sopenharmony_ci ctrl &= (~E1000_CTRL_RFCE); 87362306a36Sopenharmony_ci ctrl |= E1000_CTRL_TFCE; 87462306a36Sopenharmony_ci break; 87562306a36Sopenharmony_ci case e1000_fc_full: 87662306a36Sopenharmony_ci ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); 87762306a36Sopenharmony_ci break; 87862306a36Sopenharmony_ci default: 87962306a36Sopenharmony_ci hw_dbg("Flow control param set incorrectly\n"); 88062306a36Sopenharmony_ci ret_val = -E1000_ERR_CONFIG; 88162306a36Sopenharmony_ci goto out; 88262306a36Sopenharmony_ci } 88362306a36Sopenharmony_ci 88462306a36Sopenharmony_ci wr32(E1000_CTRL, ctrl); 88562306a36Sopenharmony_ci 88662306a36Sopenharmony_ciout: 88762306a36Sopenharmony_ci return ret_val; 88862306a36Sopenharmony_ci} 88962306a36Sopenharmony_ci 89062306a36Sopenharmony_ci/** 89162306a36Sopenharmony_ci * igb_config_fc_after_link_up - Configures flow control after link 89262306a36Sopenharmony_ci * @hw: pointer to the HW structure 89362306a36Sopenharmony_ci * 89462306a36Sopenharmony_ci * Checks the status of auto-negotiation after link up to ensure that the 89562306a36Sopenharmony_ci * speed and duplex were not forced. If the link needed to be forced, then 89662306a36Sopenharmony_ci * flow control needs to be forced also. If auto-negotiation is enabled 89762306a36Sopenharmony_ci * and did not fail, then we configure flow control based on our link 89862306a36Sopenharmony_ci * partner. 89962306a36Sopenharmony_ci **/ 90062306a36Sopenharmony_cis32 igb_config_fc_after_link_up(struct e1000_hw *hw) 90162306a36Sopenharmony_ci{ 90262306a36Sopenharmony_ci struct e1000_mac_info *mac = &hw->mac; 90362306a36Sopenharmony_ci s32 ret_val = 0; 90462306a36Sopenharmony_ci u32 pcs_status_reg, pcs_adv_reg, pcs_lp_ability_reg, pcs_ctrl_reg; 90562306a36Sopenharmony_ci u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg; 90662306a36Sopenharmony_ci u16 speed, duplex; 90762306a36Sopenharmony_ci 90862306a36Sopenharmony_ci /* Check for the case where we have fiber media and auto-neg failed 90962306a36Sopenharmony_ci * so we had to force link. In this case, we need to force the 91062306a36Sopenharmony_ci * configuration of the MAC to match the "fc" parameter. 91162306a36Sopenharmony_ci */ 91262306a36Sopenharmony_ci if (mac->autoneg_failed) { 91362306a36Sopenharmony_ci if (hw->phy.media_type == e1000_media_type_internal_serdes) 91462306a36Sopenharmony_ci ret_val = igb_force_mac_fc(hw); 91562306a36Sopenharmony_ci } else { 91662306a36Sopenharmony_ci if (hw->phy.media_type == e1000_media_type_copper) 91762306a36Sopenharmony_ci ret_val = igb_force_mac_fc(hw); 91862306a36Sopenharmony_ci } 91962306a36Sopenharmony_ci 92062306a36Sopenharmony_ci if (ret_val) { 92162306a36Sopenharmony_ci hw_dbg("Error forcing flow control settings\n"); 92262306a36Sopenharmony_ci goto out; 92362306a36Sopenharmony_ci } 92462306a36Sopenharmony_ci 92562306a36Sopenharmony_ci /* Check for the case where we have copper media and auto-neg is 92662306a36Sopenharmony_ci * enabled. In this case, we need to check and see if Auto-Neg 92762306a36Sopenharmony_ci * has completed, and if so, how the PHY and link partner has 92862306a36Sopenharmony_ci * flow control configured. 92962306a36Sopenharmony_ci */ 93062306a36Sopenharmony_ci if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) { 93162306a36Sopenharmony_ci /* Read the MII Status Register and check to see if AutoNeg 93262306a36Sopenharmony_ci * has completed. We read this twice because this reg has 93362306a36Sopenharmony_ci * some "sticky" (latched) bits. 93462306a36Sopenharmony_ci */ 93562306a36Sopenharmony_ci ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, 93662306a36Sopenharmony_ci &mii_status_reg); 93762306a36Sopenharmony_ci if (ret_val) 93862306a36Sopenharmony_ci goto out; 93962306a36Sopenharmony_ci ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, 94062306a36Sopenharmony_ci &mii_status_reg); 94162306a36Sopenharmony_ci if (ret_val) 94262306a36Sopenharmony_ci goto out; 94362306a36Sopenharmony_ci 94462306a36Sopenharmony_ci if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) { 94562306a36Sopenharmony_ci hw_dbg("Copper PHY and Auto Neg has not completed.\n"); 94662306a36Sopenharmony_ci goto out; 94762306a36Sopenharmony_ci } 94862306a36Sopenharmony_ci 94962306a36Sopenharmony_ci /* The AutoNeg process has completed, so we now need to 95062306a36Sopenharmony_ci * read both the Auto Negotiation Advertisement 95162306a36Sopenharmony_ci * Register (Address 4) and the Auto_Negotiation Base 95262306a36Sopenharmony_ci * Page Ability Register (Address 5) to determine how 95362306a36Sopenharmony_ci * flow control was negotiated. 95462306a36Sopenharmony_ci */ 95562306a36Sopenharmony_ci ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV, 95662306a36Sopenharmony_ci &mii_nway_adv_reg); 95762306a36Sopenharmony_ci if (ret_val) 95862306a36Sopenharmony_ci goto out; 95962306a36Sopenharmony_ci ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY, 96062306a36Sopenharmony_ci &mii_nway_lp_ability_reg); 96162306a36Sopenharmony_ci if (ret_val) 96262306a36Sopenharmony_ci goto out; 96362306a36Sopenharmony_ci 96462306a36Sopenharmony_ci /* Two bits in the Auto Negotiation Advertisement Register 96562306a36Sopenharmony_ci * (Address 4) and two bits in the Auto Negotiation Base 96662306a36Sopenharmony_ci * Page Ability Register (Address 5) determine flow control 96762306a36Sopenharmony_ci * for both the PHY and the link partner. The following 96862306a36Sopenharmony_ci * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, 96962306a36Sopenharmony_ci * 1999, describes these PAUSE resolution bits and how flow 97062306a36Sopenharmony_ci * control is determined based upon these settings. 97162306a36Sopenharmony_ci * NOTE: DC = Don't Care 97262306a36Sopenharmony_ci * 97362306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 97462306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution 97562306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 97662306a36Sopenharmony_ci * 0 | 0 | DC | DC | e1000_fc_none 97762306a36Sopenharmony_ci * 0 | 1 | 0 | DC | e1000_fc_none 97862306a36Sopenharmony_ci * 0 | 1 | 1 | 0 | e1000_fc_none 97962306a36Sopenharmony_ci * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 98062306a36Sopenharmony_ci * 1 | 0 | 0 | DC | e1000_fc_none 98162306a36Sopenharmony_ci * 1 | DC | 1 | DC | e1000_fc_full 98262306a36Sopenharmony_ci * 1 | 1 | 0 | 0 | e1000_fc_none 98362306a36Sopenharmony_ci * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 98462306a36Sopenharmony_ci * 98562306a36Sopenharmony_ci * Are both PAUSE bits set to 1? If so, this implies 98662306a36Sopenharmony_ci * Symmetric Flow Control is enabled at both ends. The 98762306a36Sopenharmony_ci * ASM_DIR bits are irrelevant per the spec. 98862306a36Sopenharmony_ci * 98962306a36Sopenharmony_ci * For Symmetric Flow Control: 99062306a36Sopenharmony_ci * 99162306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 99262306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 99362306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 99462306a36Sopenharmony_ci * 1 | DC | 1 | DC | E1000_fc_full 99562306a36Sopenharmony_ci * 99662306a36Sopenharmony_ci */ 99762306a36Sopenharmony_ci if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && 99862306a36Sopenharmony_ci (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { 99962306a36Sopenharmony_ci /* Now we need to check if the user selected RX ONLY 100062306a36Sopenharmony_ci * of pause frames. In this case, we had to advertise 100162306a36Sopenharmony_ci * FULL flow control because we could not advertise RX 100262306a36Sopenharmony_ci * ONLY. Hence, we must now check to see if we need to 100362306a36Sopenharmony_ci * turn OFF the TRANSMISSION of PAUSE frames. 100462306a36Sopenharmony_ci */ 100562306a36Sopenharmony_ci if (hw->fc.requested_mode == e1000_fc_full) { 100662306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_full; 100762306a36Sopenharmony_ci hw_dbg("Flow Control = FULL.\n"); 100862306a36Sopenharmony_ci } else { 100962306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_rx_pause; 101062306a36Sopenharmony_ci hw_dbg("Flow Control = RX PAUSE frames only.\n"); 101162306a36Sopenharmony_ci } 101262306a36Sopenharmony_ci } 101362306a36Sopenharmony_ci /* For receiving PAUSE frames ONLY. 101462306a36Sopenharmony_ci * 101562306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 101662306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 101762306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 101862306a36Sopenharmony_ci * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 101962306a36Sopenharmony_ci */ 102062306a36Sopenharmony_ci else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && 102162306a36Sopenharmony_ci (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 102262306a36Sopenharmony_ci (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 102362306a36Sopenharmony_ci (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 102462306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_tx_pause; 102562306a36Sopenharmony_ci hw_dbg("Flow Control = TX PAUSE frames only.\n"); 102662306a36Sopenharmony_ci } 102762306a36Sopenharmony_ci /* For transmitting PAUSE frames ONLY. 102862306a36Sopenharmony_ci * 102962306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 103062306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 103162306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 103262306a36Sopenharmony_ci * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 103362306a36Sopenharmony_ci */ 103462306a36Sopenharmony_ci else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && 103562306a36Sopenharmony_ci (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 103662306a36Sopenharmony_ci !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 103762306a36Sopenharmony_ci (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 103862306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_rx_pause; 103962306a36Sopenharmony_ci hw_dbg("Flow Control = RX PAUSE frames only.\n"); 104062306a36Sopenharmony_ci } 104162306a36Sopenharmony_ci /* Per the IEEE spec, at this point flow control should be 104262306a36Sopenharmony_ci * disabled. However, we want to consider that we could 104362306a36Sopenharmony_ci * be connected to a legacy switch that doesn't advertise 104462306a36Sopenharmony_ci * desired flow control, but can be forced on the link 104562306a36Sopenharmony_ci * partner. So if we advertised no flow control, that is 104662306a36Sopenharmony_ci * what we will resolve to. If we advertised some kind of 104762306a36Sopenharmony_ci * receive capability (Rx Pause Only or Full Flow Control) 104862306a36Sopenharmony_ci * and the link partner advertised none, we will configure 104962306a36Sopenharmony_ci * ourselves to enable Rx Flow Control only. We can do 105062306a36Sopenharmony_ci * this safely for two reasons: If the link partner really 105162306a36Sopenharmony_ci * didn't want flow control enabled, and we enable Rx, no 105262306a36Sopenharmony_ci * harm done since we won't be receiving any PAUSE frames 105362306a36Sopenharmony_ci * anyway. If the intent on the link partner was to have 105462306a36Sopenharmony_ci * flow control enabled, then by us enabling RX only, we 105562306a36Sopenharmony_ci * can at least receive pause frames and process them. 105662306a36Sopenharmony_ci * This is a good idea because in most cases, since we are 105762306a36Sopenharmony_ci * predominantly a server NIC, more times than not we will 105862306a36Sopenharmony_ci * be asked to delay transmission of packets than asking 105962306a36Sopenharmony_ci * our link partner to pause transmission of frames. 106062306a36Sopenharmony_ci */ 106162306a36Sopenharmony_ci else if ((hw->fc.requested_mode == e1000_fc_none) || 106262306a36Sopenharmony_ci (hw->fc.requested_mode == e1000_fc_tx_pause) || 106362306a36Sopenharmony_ci (hw->fc.strict_ieee)) { 106462306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_none; 106562306a36Sopenharmony_ci hw_dbg("Flow Control = NONE.\n"); 106662306a36Sopenharmony_ci } else { 106762306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_rx_pause; 106862306a36Sopenharmony_ci hw_dbg("Flow Control = RX PAUSE frames only.\n"); 106962306a36Sopenharmony_ci } 107062306a36Sopenharmony_ci 107162306a36Sopenharmony_ci /* Now we need to do one last check... If we auto- 107262306a36Sopenharmony_ci * negotiated to HALF DUPLEX, flow control should not be 107362306a36Sopenharmony_ci * enabled per IEEE 802.3 spec. 107462306a36Sopenharmony_ci */ 107562306a36Sopenharmony_ci ret_val = hw->mac.ops.get_speed_and_duplex(hw, &speed, &duplex); 107662306a36Sopenharmony_ci if (ret_val) { 107762306a36Sopenharmony_ci hw_dbg("Error getting link speed and duplex\n"); 107862306a36Sopenharmony_ci goto out; 107962306a36Sopenharmony_ci } 108062306a36Sopenharmony_ci 108162306a36Sopenharmony_ci if (duplex == HALF_DUPLEX) 108262306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_none; 108362306a36Sopenharmony_ci 108462306a36Sopenharmony_ci /* Now we call a subroutine to actually force the MAC 108562306a36Sopenharmony_ci * controller to use the correct flow control settings. 108662306a36Sopenharmony_ci */ 108762306a36Sopenharmony_ci ret_val = igb_force_mac_fc(hw); 108862306a36Sopenharmony_ci if (ret_val) { 108962306a36Sopenharmony_ci hw_dbg("Error forcing flow control settings\n"); 109062306a36Sopenharmony_ci goto out; 109162306a36Sopenharmony_ci } 109262306a36Sopenharmony_ci } 109362306a36Sopenharmony_ci /* Check for the case where we have SerDes media and auto-neg is 109462306a36Sopenharmony_ci * enabled. In this case, we need to check and see if Auto-Neg 109562306a36Sopenharmony_ci * has completed, and if so, how the PHY and link partner has 109662306a36Sopenharmony_ci * flow control configured. 109762306a36Sopenharmony_ci */ 109862306a36Sopenharmony_ci if ((hw->phy.media_type == e1000_media_type_internal_serdes) 109962306a36Sopenharmony_ci && mac->autoneg) { 110062306a36Sopenharmony_ci /* Read the PCS_LSTS and check to see if AutoNeg 110162306a36Sopenharmony_ci * has completed. 110262306a36Sopenharmony_ci */ 110362306a36Sopenharmony_ci pcs_status_reg = rd32(E1000_PCS_LSTAT); 110462306a36Sopenharmony_ci 110562306a36Sopenharmony_ci if (!(pcs_status_reg & E1000_PCS_LSTS_AN_COMPLETE)) { 110662306a36Sopenharmony_ci hw_dbg("PCS Auto Neg has not completed.\n"); 110762306a36Sopenharmony_ci return ret_val; 110862306a36Sopenharmony_ci } 110962306a36Sopenharmony_ci 111062306a36Sopenharmony_ci /* The AutoNeg process has completed, so we now need to 111162306a36Sopenharmony_ci * read both the Auto Negotiation Advertisement 111262306a36Sopenharmony_ci * Register (PCS_ANADV) and the Auto_Negotiation Base 111362306a36Sopenharmony_ci * Page Ability Register (PCS_LPAB) to determine how 111462306a36Sopenharmony_ci * flow control was negotiated. 111562306a36Sopenharmony_ci */ 111662306a36Sopenharmony_ci pcs_adv_reg = rd32(E1000_PCS_ANADV); 111762306a36Sopenharmony_ci pcs_lp_ability_reg = rd32(E1000_PCS_LPAB); 111862306a36Sopenharmony_ci 111962306a36Sopenharmony_ci /* Two bits in the Auto Negotiation Advertisement Register 112062306a36Sopenharmony_ci * (PCS_ANADV) and two bits in the Auto Negotiation Base 112162306a36Sopenharmony_ci * Page Ability Register (PCS_LPAB) determine flow control 112262306a36Sopenharmony_ci * for both the PHY and the link partner. The following 112362306a36Sopenharmony_ci * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, 112462306a36Sopenharmony_ci * 1999, describes these PAUSE resolution bits and how flow 112562306a36Sopenharmony_ci * control is determined based upon these settings. 112662306a36Sopenharmony_ci * NOTE: DC = Don't Care 112762306a36Sopenharmony_ci * 112862306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 112962306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution 113062306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 113162306a36Sopenharmony_ci * 0 | 0 | DC | DC | e1000_fc_none 113262306a36Sopenharmony_ci * 0 | 1 | 0 | DC | e1000_fc_none 113362306a36Sopenharmony_ci * 0 | 1 | 1 | 0 | e1000_fc_none 113462306a36Sopenharmony_ci * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 113562306a36Sopenharmony_ci * 1 | 0 | 0 | DC | e1000_fc_none 113662306a36Sopenharmony_ci * 1 | DC | 1 | DC | e1000_fc_full 113762306a36Sopenharmony_ci * 1 | 1 | 0 | 0 | e1000_fc_none 113862306a36Sopenharmony_ci * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 113962306a36Sopenharmony_ci * 114062306a36Sopenharmony_ci * Are both PAUSE bits set to 1? If so, this implies 114162306a36Sopenharmony_ci * Symmetric Flow Control is enabled at both ends. The 114262306a36Sopenharmony_ci * ASM_DIR bits are irrelevant per the spec. 114362306a36Sopenharmony_ci * 114462306a36Sopenharmony_ci * For Symmetric Flow Control: 114562306a36Sopenharmony_ci * 114662306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 114762306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 114862306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 114962306a36Sopenharmony_ci * 1 | DC | 1 | DC | e1000_fc_full 115062306a36Sopenharmony_ci * 115162306a36Sopenharmony_ci */ 115262306a36Sopenharmony_ci if ((pcs_adv_reg & E1000_TXCW_PAUSE) && 115362306a36Sopenharmony_ci (pcs_lp_ability_reg & E1000_TXCW_PAUSE)) { 115462306a36Sopenharmony_ci /* Now we need to check if the user selected Rx ONLY 115562306a36Sopenharmony_ci * of pause frames. In this case, we had to advertise 115662306a36Sopenharmony_ci * FULL flow control because we could not advertise Rx 115762306a36Sopenharmony_ci * ONLY. Hence, we must now check to see if we need to 115862306a36Sopenharmony_ci * turn OFF the TRANSMISSION of PAUSE frames. 115962306a36Sopenharmony_ci */ 116062306a36Sopenharmony_ci if (hw->fc.requested_mode == e1000_fc_full) { 116162306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_full; 116262306a36Sopenharmony_ci hw_dbg("Flow Control = FULL.\n"); 116362306a36Sopenharmony_ci } else { 116462306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_rx_pause; 116562306a36Sopenharmony_ci hw_dbg("Flow Control = Rx PAUSE frames only.\n"); 116662306a36Sopenharmony_ci } 116762306a36Sopenharmony_ci } 116862306a36Sopenharmony_ci /* For receiving PAUSE frames ONLY. 116962306a36Sopenharmony_ci * 117062306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 117162306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 117262306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 117362306a36Sopenharmony_ci * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 117462306a36Sopenharmony_ci */ 117562306a36Sopenharmony_ci else if (!(pcs_adv_reg & E1000_TXCW_PAUSE) && 117662306a36Sopenharmony_ci (pcs_adv_reg & E1000_TXCW_ASM_DIR) && 117762306a36Sopenharmony_ci (pcs_lp_ability_reg & E1000_TXCW_PAUSE) && 117862306a36Sopenharmony_ci (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) { 117962306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_tx_pause; 118062306a36Sopenharmony_ci hw_dbg("Flow Control = Tx PAUSE frames only.\n"); 118162306a36Sopenharmony_ci } 118262306a36Sopenharmony_ci /* For transmitting PAUSE frames ONLY. 118362306a36Sopenharmony_ci * 118462306a36Sopenharmony_ci * LOCAL DEVICE | LINK PARTNER 118562306a36Sopenharmony_ci * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 118662306a36Sopenharmony_ci *-------|---------|-------|---------|-------------------- 118762306a36Sopenharmony_ci * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 118862306a36Sopenharmony_ci */ 118962306a36Sopenharmony_ci else if ((pcs_adv_reg & E1000_TXCW_PAUSE) && 119062306a36Sopenharmony_ci (pcs_adv_reg & E1000_TXCW_ASM_DIR) && 119162306a36Sopenharmony_ci !(pcs_lp_ability_reg & E1000_TXCW_PAUSE) && 119262306a36Sopenharmony_ci (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) { 119362306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_rx_pause; 119462306a36Sopenharmony_ci hw_dbg("Flow Control = Rx PAUSE frames only.\n"); 119562306a36Sopenharmony_ci } else { 119662306a36Sopenharmony_ci /* Per the IEEE spec, at this point flow control 119762306a36Sopenharmony_ci * should be disabled. 119862306a36Sopenharmony_ci */ 119962306a36Sopenharmony_ci hw->fc.current_mode = e1000_fc_none; 120062306a36Sopenharmony_ci hw_dbg("Flow Control = NONE.\n"); 120162306a36Sopenharmony_ci } 120262306a36Sopenharmony_ci 120362306a36Sopenharmony_ci /* Now we call a subroutine to actually force the MAC 120462306a36Sopenharmony_ci * controller to use the correct flow control settings. 120562306a36Sopenharmony_ci */ 120662306a36Sopenharmony_ci pcs_ctrl_reg = rd32(E1000_PCS_LCTL); 120762306a36Sopenharmony_ci pcs_ctrl_reg |= E1000_PCS_LCTL_FORCE_FCTRL; 120862306a36Sopenharmony_ci wr32(E1000_PCS_LCTL, pcs_ctrl_reg); 120962306a36Sopenharmony_ci 121062306a36Sopenharmony_ci ret_val = igb_force_mac_fc(hw); 121162306a36Sopenharmony_ci if (ret_val) { 121262306a36Sopenharmony_ci hw_dbg("Error forcing flow control settings\n"); 121362306a36Sopenharmony_ci return ret_val; 121462306a36Sopenharmony_ci } 121562306a36Sopenharmony_ci } 121662306a36Sopenharmony_ci 121762306a36Sopenharmony_ciout: 121862306a36Sopenharmony_ci return ret_val; 121962306a36Sopenharmony_ci} 122062306a36Sopenharmony_ci 122162306a36Sopenharmony_ci/** 122262306a36Sopenharmony_ci * igb_get_speed_and_duplex_copper - Retrieve current speed/duplex 122362306a36Sopenharmony_ci * @hw: pointer to the HW structure 122462306a36Sopenharmony_ci * @speed: stores the current speed 122562306a36Sopenharmony_ci * @duplex: stores the current duplex 122662306a36Sopenharmony_ci * 122762306a36Sopenharmony_ci * Read the status register for the current speed/duplex and store the current 122862306a36Sopenharmony_ci * speed and duplex for copper connections. 122962306a36Sopenharmony_ci **/ 123062306a36Sopenharmony_cis32 igb_get_speed_and_duplex_copper(struct e1000_hw *hw, u16 *speed, 123162306a36Sopenharmony_ci u16 *duplex) 123262306a36Sopenharmony_ci{ 123362306a36Sopenharmony_ci u32 status; 123462306a36Sopenharmony_ci 123562306a36Sopenharmony_ci status = rd32(E1000_STATUS); 123662306a36Sopenharmony_ci if (status & E1000_STATUS_SPEED_1000) { 123762306a36Sopenharmony_ci *speed = SPEED_1000; 123862306a36Sopenharmony_ci hw_dbg("1000 Mbs, "); 123962306a36Sopenharmony_ci } else if (status & E1000_STATUS_SPEED_100) { 124062306a36Sopenharmony_ci *speed = SPEED_100; 124162306a36Sopenharmony_ci hw_dbg("100 Mbs, "); 124262306a36Sopenharmony_ci } else { 124362306a36Sopenharmony_ci *speed = SPEED_10; 124462306a36Sopenharmony_ci hw_dbg("10 Mbs, "); 124562306a36Sopenharmony_ci } 124662306a36Sopenharmony_ci 124762306a36Sopenharmony_ci if (status & E1000_STATUS_FD) { 124862306a36Sopenharmony_ci *duplex = FULL_DUPLEX; 124962306a36Sopenharmony_ci hw_dbg("Full Duplex\n"); 125062306a36Sopenharmony_ci } else { 125162306a36Sopenharmony_ci *duplex = HALF_DUPLEX; 125262306a36Sopenharmony_ci hw_dbg("Half Duplex\n"); 125362306a36Sopenharmony_ci } 125462306a36Sopenharmony_ci 125562306a36Sopenharmony_ci return 0; 125662306a36Sopenharmony_ci} 125762306a36Sopenharmony_ci 125862306a36Sopenharmony_ci/** 125962306a36Sopenharmony_ci * igb_get_hw_semaphore - Acquire hardware semaphore 126062306a36Sopenharmony_ci * @hw: pointer to the HW structure 126162306a36Sopenharmony_ci * 126262306a36Sopenharmony_ci * Acquire the HW semaphore to access the PHY or NVM 126362306a36Sopenharmony_ci **/ 126462306a36Sopenharmony_cis32 igb_get_hw_semaphore(struct e1000_hw *hw) 126562306a36Sopenharmony_ci{ 126662306a36Sopenharmony_ci u32 swsm; 126762306a36Sopenharmony_ci s32 ret_val = 0; 126862306a36Sopenharmony_ci s32 timeout = hw->nvm.word_size + 1; 126962306a36Sopenharmony_ci s32 i = 0; 127062306a36Sopenharmony_ci 127162306a36Sopenharmony_ci /* Get the SW semaphore */ 127262306a36Sopenharmony_ci while (i < timeout) { 127362306a36Sopenharmony_ci swsm = rd32(E1000_SWSM); 127462306a36Sopenharmony_ci if (!(swsm & E1000_SWSM_SMBI)) 127562306a36Sopenharmony_ci break; 127662306a36Sopenharmony_ci 127762306a36Sopenharmony_ci udelay(50); 127862306a36Sopenharmony_ci i++; 127962306a36Sopenharmony_ci } 128062306a36Sopenharmony_ci 128162306a36Sopenharmony_ci if (i == timeout) { 128262306a36Sopenharmony_ci hw_dbg("Driver can't access device - SMBI bit is set.\n"); 128362306a36Sopenharmony_ci ret_val = -E1000_ERR_NVM; 128462306a36Sopenharmony_ci goto out; 128562306a36Sopenharmony_ci } 128662306a36Sopenharmony_ci 128762306a36Sopenharmony_ci /* Get the FW semaphore. */ 128862306a36Sopenharmony_ci for (i = 0; i < timeout; i++) { 128962306a36Sopenharmony_ci swsm = rd32(E1000_SWSM); 129062306a36Sopenharmony_ci wr32(E1000_SWSM, swsm | E1000_SWSM_SWESMBI); 129162306a36Sopenharmony_ci 129262306a36Sopenharmony_ci /* Semaphore acquired if bit latched */ 129362306a36Sopenharmony_ci if (rd32(E1000_SWSM) & E1000_SWSM_SWESMBI) 129462306a36Sopenharmony_ci break; 129562306a36Sopenharmony_ci 129662306a36Sopenharmony_ci udelay(50); 129762306a36Sopenharmony_ci } 129862306a36Sopenharmony_ci 129962306a36Sopenharmony_ci if (i == timeout) { 130062306a36Sopenharmony_ci /* Release semaphores */ 130162306a36Sopenharmony_ci igb_put_hw_semaphore(hw); 130262306a36Sopenharmony_ci hw_dbg("Driver can't access the NVM\n"); 130362306a36Sopenharmony_ci ret_val = -E1000_ERR_NVM; 130462306a36Sopenharmony_ci goto out; 130562306a36Sopenharmony_ci } 130662306a36Sopenharmony_ci 130762306a36Sopenharmony_ciout: 130862306a36Sopenharmony_ci return ret_val; 130962306a36Sopenharmony_ci} 131062306a36Sopenharmony_ci 131162306a36Sopenharmony_ci/** 131262306a36Sopenharmony_ci * igb_put_hw_semaphore - Release hardware semaphore 131362306a36Sopenharmony_ci * @hw: pointer to the HW structure 131462306a36Sopenharmony_ci * 131562306a36Sopenharmony_ci * Release hardware semaphore used to access the PHY or NVM 131662306a36Sopenharmony_ci **/ 131762306a36Sopenharmony_civoid igb_put_hw_semaphore(struct e1000_hw *hw) 131862306a36Sopenharmony_ci{ 131962306a36Sopenharmony_ci u32 swsm; 132062306a36Sopenharmony_ci 132162306a36Sopenharmony_ci swsm = rd32(E1000_SWSM); 132262306a36Sopenharmony_ci 132362306a36Sopenharmony_ci swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); 132462306a36Sopenharmony_ci 132562306a36Sopenharmony_ci wr32(E1000_SWSM, swsm); 132662306a36Sopenharmony_ci} 132762306a36Sopenharmony_ci 132862306a36Sopenharmony_ci/** 132962306a36Sopenharmony_ci * igb_get_auto_rd_done - Check for auto read completion 133062306a36Sopenharmony_ci * @hw: pointer to the HW structure 133162306a36Sopenharmony_ci * 133262306a36Sopenharmony_ci * Check EEPROM for Auto Read done bit. 133362306a36Sopenharmony_ci **/ 133462306a36Sopenharmony_cis32 igb_get_auto_rd_done(struct e1000_hw *hw) 133562306a36Sopenharmony_ci{ 133662306a36Sopenharmony_ci s32 i = 0; 133762306a36Sopenharmony_ci s32 ret_val = 0; 133862306a36Sopenharmony_ci 133962306a36Sopenharmony_ci 134062306a36Sopenharmony_ci while (i < AUTO_READ_DONE_TIMEOUT) { 134162306a36Sopenharmony_ci if (rd32(E1000_EECD) & E1000_EECD_AUTO_RD) 134262306a36Sopenharmony_ci break; 134362306a36Sopenharmony_ci usleep_range(1000, 2000); 134462306a36Sopenharmony_ci i++; 134562306a36Sopenharmony_ci } 134662306a36Sopenharmony_ci 134762306a36Sopenharmony_ci if (i == AUTO_READ_DONE_TIMEOUT) { 134862306a36Sopenharmony_ci hw_dbg("Auto read by HW from NVM has not completed.\n"); 134962306a36Sopenharmony_ci ret_val = -E1000_ERR_RESET; 135062306a36Sopenharmony_ci goto out; 135162306a36Sopenharmony_ci } 135262306a36Sopenharmony_ci 135362306a36Sopenharmony_ciout: 135462306a36Sopenharmony_ci return ret_val; 135562306a36Sopenharmony_ci} 135662306a36Sopenharmony_ci 135762306a36Sopenharmony_ci/** 135862306a36Sopenharmony_ci * igb_valid_led_default - Verify a valid default LED config 135962306a36Sopenharmony_ci * @hw: pointer to the HW structure 136062306a36Sopenharmony_ci * @data: pointer to the NVM (EEPROM) 136162306a36Sopenharmony_ci * 136262306a36Sopenharmony_ci * Read the EEPROM for the current default LED configuration. If the 136362306a36Sopenharmony_ci * LED configuration is not valid, set to a valid LED configuration. 136462306a36Sopenharmony_ci **/ 136562306a36Sopenharmony_cistatic s32 igb_valid_led_default(struct e1000_hw *hw, u16 *data) 136662306a36Sopenharmony_ci{ 136762306a36Sopenharmony_ci s32 ret_val; 136862306a36Sopenharmony_ci 136962306a36Sopenharmony_ci ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data); 137062306a36Sopenharmony_ci if (ret_val) { 137162306a36Sopenharmony_ci hw_dbg("NVM Read Error\n"); 137262306a36Sopenharmony_ci goto out; 137362306a36Sopenharmony_ci } 137462306a36Sopenharmony_ci 137562306a36Sopenharmony_ci if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) { 137662306a36Sopenharmony_ci switch (hw->phy.media_type) { 137762306a36Sopenharmony_ci case e1000_media_type_internal_serdes: 137862306a36Sopenharmony_ci *data = ID_LED_DEFAULT_82575_SERDES; 137962306a36Sopenharmony_ci break; 138062306a36Sopenharmony_ci case e1000_media_type_copper: 138162306a36Sopenharmony_ci default: 138262306a36Sopenharmony_ci *data = ID_LED_DEFAULT; 138362306a36Sopenharmony_ci break; 138462306a36Sopenharmony_ci } 138562306a36Sopenharmony_ci } 138662306a36Sopenharmony_ciout: 138762306a36Sopenharmony_ci return ret_val; 138862306a36Sopenharmony_ci} 138962306a36Sopenharmony_ci 139062306a36Sopenharmony_ci/** 139162306a36Sopenharmony_ci * igb_id_led_init - 139262306a36Sopenharmony_ci * @hw: pointer to the HW structure 139362306a36Sopenharmony_ci * 139462306a36Sopenharmony_ci **/ 139562306a36Sopenharmony_cis32 igb_id_led_init(struct e1000_hw *hw) 139662306a36Sopenharmony_ci{ 139762306a36Sopenharmony_ci struct e1000_mac_info *mac = &hw->mac; 139862306a36Sopenharmony_ci s32 ret_val; 139962306a36Sopenharmony_ci const u32 ledctl_mask = 0x000000FF; 140062306a36Sopenharmony_ci const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; 140162306a36Sopenharmony_ci const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; 140262306a36Sopenharmony_ci u16 data, i, temp; 140362306a36Sopenharmony_ci const u16 led_mask = 0x0F; 140462306a36Sopenharmony_ci 140562306a36Sopenharmony_ci /* i210 and i211 devices have different LED mechanism */ 140662306a36Sopenharmony_ci if ((hw->mac.type == e1000_i210) || 140762306a36Sopenharmony_ci (hw->mac.type == e1000_i211)) 140862306a36Sopenharmony_ci ret_val = igb_valid_led_default_i210(hw, &data); 140962306a36Sopenharmony_ci else 141062306a36Sopenharmony_ci ret_val = igb_valid_led_default(hw, &data); 141162306a36Sopenharmony_ci 141262306a36Sopenharmony_ci if (ret_val) 141362306a36Sopenharmony_ci goto out; 141462306a36Sopenharmony_ci 141562306a36Sopenharmony_ci mac->ledctl_default = rd32(E1000_LEDCTL); 141662306a36Sopenharmony_ci mac->ledctl_mode1 = mac->ledctl_default; 141762306a36Sopenharmony_ci mac->ledctl_mode2 = mac->ledctl_default; 141862306a36Sopenharmony_ci 141962306a36Sopenharmony_ci for (i = 0; i < 4; i++) { 142062306a36Sopenharmony_ci temp = (data >> (i << 2)) & led_mask; 142162306a36Sopenharmony_ci switch (temp) { 142262306a36Sopenharmony_ci case ID_LED_ON1_DEF2: 142362306a36Sopenharmony_ci case ID_LED_ON1_ON2: 142462306a36Sopenharmony_ci case ID_LED_ON1_OFF2: 142562306a36Sopenharmony_ci mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); 142662306a36Sopenharmony_ci mac->ledctl_mode1 |= ledctl_on << (i << 3); 142762306a36Sopenharmony_ci break; 142862306a36Sopenharmony_ci case ID_LED_OFF1_DEF2: 142962306a36Sopenharmony_ci case ID_LED_OFF1_ON2: 143062306a36Sopenharmony_ci case ID_LED_OFF1_OFF2: 143162306a36Sopenharmony_ci mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); 143262306a36Sopenharmony_ci mac->ledctl_mode1 |= ledctl_off << (i << 3); 143362306a36Sopenharmony_ci break; 143462306a36Sopenharmony_ci default: 143562306a36Sopenharmony_ci /* Do nothing */ 143662306a36Sopenharmony_ci break; 143762306a36Sopenharmony_ci } 143862306a36Sopenharmony_ci switch (temp) { 143962306a36Sopenharmony_ci case ID_LED_DEF1_ON2: 144062306a36Sopenharmony_ci case ID_LED_ON1_ON2: 144162306a36Sopenharmony_ci case ID_LED_OFF1_ON2: 144262306a36Sopenharmony_ci mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); 144362306a36Sopenharmony_ci mac->ledctl_mode2 |= ledctl_on << (i << 3); 144462306a36Sopenharmony_ci break; 144562306a36Sopenharmony_ci case ID_LED_DEF1_OFF2: 144662306a36Sopenharmony_ci case ID_LED_ON1_OFF2: 144762306a36Sopenharmony_ci case ID_LED_OFF1_OFF2: 144862306a36Sopenharmony_ci mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); 144962306a36Sopenharmony_ci mac->ledctl_mode2 |= ledctl_off << (i << 3); 145062306a36Sopenharmony_ci break; 145162306a36Sopenharmony_ci default: 145262306a36Sopenharmony_ci /* Do nothing */ 145362306a36Sopenharmony_ci break; 145462306a36Sopenharmony_ci } 145562306a36Sopenharmony_ci } 145662306a36Sopenharmony_ci 145762306a36Sopenharmony_ciout: 145862306a36Sopenharmony_ci return ret_val; 145962306a36Sopenharmony_ci} 146062306a36Sopenharmony_ci 146162306a36Sopenharmony_ci/** 146262306a36Sopenharmony_ci * igb_cleanup_led - Set LED config to default operation 146362306a36Sopenharmony_ci * @hw: pointer to the HW structure 146462306a36Sopenharmony_ci * 146562306a36Sopenharmony_ci * Remove the current LED configuration and set the LED configuration 146662306a36Sopenharmony_ci * to the default value, saved from the EEPROM. 146762306a36Sopenharmony_ci **/ 146862306a36Sopenharmony_cis32 igb_cleanup_led(struct e1000_hw *hw) 146962306a36Sopenharmony_ci{ 147062306a36Sopenharmony_ci wr32(E1000_LEDCTL, hw->mac.ledctl_default); 147162306a36Sopenharmony_ci return 0; 147262306a36Sopenharmony_ci} 147362306a36Sopenharmony_ci 147462306a36Sopenharmony_ci/** 147562306a36Sopenharmony_ci * igb_blink_led - Blink LED 147662306a36Sopenharmony_ci * @hw: pointer to the HW structure 147762306a36Sopenharmony_ci * 147862306a36Sopenharmony_ci * Blink the led's which are set to be on. 147962306a36Sopenharmony_ci **/ 148062306a36Sopenharmony_cis32 igb_blink_led(struct e1000_hw *hw) 148162306a36Sopenharmony_ci{ 148262306a36Sopenharmony_ci u32 ledctl_blink = 0; 148362306a36Sopenharmony_ci u32 i; 148462306a36Sopenharmony_ci 148562306a36Sopenharmony_ci if (hw->phy.media_type == e1000_media_type_fiber) { 148662306a36Sopenharmony_ci /* always blink LED0 for PCI-E fiber */ 148762306a36Sopenharmony_ci ledctl_blink = E1000_LEDCTL_LED0_BLINK | 148862306a36Sopenharmony_ci (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); 148962306a36Sopenharmony_ci } else { 149062306a36Sopenharmony_ci /* Set the blink bit for each LED that's "on" (0x0E) 149162306a36Sopenharmony_ci * (or "off" if inverted) in ledctl_mode2. The blink 149262306a36Sopenharmony_ci * logic in hardware only works when mode is set to "on" 149362306a36Sopenharmony_ci * so it must be changed accordingly when the mode is 149462306a36Sopenharmony_ci * "off" and inverted. 149562306a36Sopenharmony_ci */ 149662306a36Sopenharmony_ci ledctl_blink = hw->mac.ledctl_mode2; 149762306a36Sopenharmony_ci for (i = 0; i < 32; i += 8) { 149862306a36Sopenharmony_ci u32 mode = (hw->mac.ledctl_mode2 >> i) & 149962306a36Sopenharmony_ci E1000_LEDCTL_LED0_MODE_MASK; 150062306a36Sopenharmony_ci u32 led_default = hw->mac.ledctl_default >> i; 150162306a36Sopenharmony_ci 150262306a36Sopenharmony_ci if ((!(led_default & E1000_LEDCTL_LED0_IVRT) && 150362306a36Sopenharmony_ci (mode == E1000_LEDCTL_MODE_LED_ON)) || 150462306a36Sopenharmony_ci ((led_default & E1000_LEDCTL_LED0_IVRT) && 150562306a36Sopenharmony_ci (mode == E1000_LEDCTL_MODE_LED_OFF))) { 150662306a36Sopenharmony_ci ledctl_blink &= 150762306a36Sopenharmony_ci ~(E1000_LEDCTL_LED0_MODE_MASK << i); 150862306a36Sopenharmony_ci ledctl_blink |= (E1000_LEDCTL_LED0_BLINK | 150962306a36Sopenharmony_ci E1000_LEDCTL_MODE_LED_ON) << i; 151062306a36Sopenharmony_ci } 151162306a36Sopenharmony_ci } 151262306a36Sopenharmony_ci } 151362306a36Sopenharmony_ci 151462306a36Sopenharmony_ci wr32(E1000_LEDCTL, ledctl_blink); 151562306a36Sopenharmony_ci 151662306a36Sopenharmony_ci return 0; 151762306a36Sopenharmony_ci} 151862306a36Sopenharmony_ci 151962306a36Sopenharmony_ci/** 152062306a36Sopenharmony_ci * igb_led_off - Turn LED off 152162306a36Sopenharmony_ci * @hw: pointer to the HW structure 152262306a36Sopenharmony_ci * 152362306a36Sopenharmony_ci * Turn LED off. 152462306a36Sopenharmony_ci **/ 152562306a36Sopenharmony_cis32 igb_led_off(struct e1000_hw *hw) 152662306a36Sopenharmony_ci{ 152762306a36Sopenharmony_ci switch (hw->phy.media_type) { 152862306a36Sopenharmony_ci case e1000_media_type_copper: 152962306a36Sopenharmony_ci wr32(E1000_LEDCTL, hw->mac.ledctl_mode1); 153062306a36Sopenharmony_ci break; 153162306a36Sopenharmony_ci default: 153262306a36Sopenharmony_ci break; 153362306a36Sopenharmony_ci } 153462306a36Sopenharmony_ci 153562306a36Sopenharmony_ci return 0; 153662306a36Sopenharmony_ci} 153762306a36Sopenharmony_ci 153862306a36Sopenharmony_ci/** 153962306a36Sopenharmony_ci * igb_disable_pcie_master - Disables PCI-express master access 154062306a36Sopenharmony_ci * @hw: pointer to the HW structure 154162306a36Sopenharmony_ci * 154262306a36Sopenharmony_ci * Returns 0 (0) if successful, else returns -10 154362306a36Sopenharmony_ci * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused 154462306a36Sopenharmony_ci * the master requests to be disabled. 154562306a36Sopenharmony_ci * 154662306a36Sopenharmony_ci * Disables PCI-Express master access and verifies there are no pending 154762306a36Sopenharmony_ci * requests. 154862306a36Sopenharmony_ci **/ 154962306a36Sopenharmony_cis32 igb_disable_pcie_master(struct e1000_hw *hw) 155062306a36Sopenharmony_ci{ 155162306a36Sopenharmony_ci u32 ctrl; 155262306a36Sopenharmony_ci s32 timeout = MASTER_DISABLE_TIMEOUT; 155362306a36Sopenharmony_ci s32 ret_val = 0; 155462306a36Sopenharmony_ci 155562306a36Sopenharmony_ci if (hw->bus.type != e1000_bus_type_pci_express) 155662306a36Sopenharmony_ci goto out; 155762306a36Sopenharmony_ci 155862306a36Sopenharmony_ci ctrl = rd32(E1000_CTRL); 155962306a36Sopenharmony_ci ctrl |= E1000_CTRL_GIO_MASTER_DISABLE; 156062306a36Sopenharmony_ci wr32(E1000_CTRL, ctrl); 156162306a36Sopenharmony_ci 156262306a36Sopenharmony_ci while (timeout) { 156362306a36Sopenharmony_ci if (!(rd32(E1000_STATUS) & 156462306a36Sopenharmony_ci E1000_STATUS_GIO_MASTER_ENABLE)) 156562306a36Sopenharmony_ci break; 156662306a36Sopenharmony_ci udelay(100); 156762306a36Sopenharmony_ci timeout--; 156862306a36Sopenharmony_ci } 156962306a36Sopenharmony_ci 157062306a36Sopenharmony_ci if (!timeout) { 157162306a36Sopenharmony_ci hw_dbg("Master requests are pending.\n"); 157262306a36Sopenharmony_ci ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING; 157362306a36Sopenharmony_ci goto out; 157462306a36Sopenharmony_ci } 157562306a36Sopenharmony_ci 157662306a36Sopenharmony_ciout: 157762306a36Sopenharmony_ci return ret_val; 157862306a36Sopenharmony_ci} 157962306a36Sopenharmony_ci 158062306a36Sopenharmony_ci/** 158162306a36Sopenharmony_ci * igb_validate_mdi_setting - Verify MDI/MDIx settings 158262306a36Sopenharmony_ci * @hw: pointer to the HW structure 158362306a36Sopenharmony_ci * 158462306a36Sopenharmony_ci * Verify that when not using auto-negotitation that MDI/MDIx is correctly 158562306a36Sopenharmony_ci * set, which is forced to MDI mode only. 158662306a36Sopenharmony_ci **/ 158762306a36Sopenharmony_cis32 igb_validate_mdi_setting(struct e1000_hw *hw) 158862306a36Sopenharmony_ci{ 158962306a36Sopenharmony_ci s32 ret_val = 0; 159062306a36Sopenharmony_ci 159162306a36Sopenharmony_ci /* All MDI settings are supported on 82580 and newer. */ 159262306a36Sopenharmony_ci if (hw->mac.type >= e1000_82580) 159362306a36Sopenharmony_ci goto out; 159462306a36Sopenharmony_ci 159562306a36Sopenharmony_ci if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) { 159662306a36Sopenharmony_ci hw_dbg("Invalid MDI setting detected\n"); 159762306a36Sopenharmony_ci hw->phy.mdix = 1; 159862306a36Sopenharmony_ci ret_val = -E1000_ERR_CONFIG; 159962306a36Sopenharmony_ci goto out; 160062306a36Sopenharmony_ci } 160162306a36Sopenharmony_ci 160262306a36Sopenharmony_ciout: 160362306a36Sopenharmony_ci return ret_val; 160462306a36Sopenharmony_ci} 160562306a36Sopenharmony_ci 160662306a36Sopenharmony_ci/** 160762306a36Sopenharmony_ci * igb_write_8bit_ctrl_reg - Write a 8bit CTRL register 160862306a36Sopenharmony_ci * @hw: pointer to the HW structure 160962306a36Sopenharmony_ci * @reg: 32bit register offset such as E1000_SCTL 161062306a36Sopenharmony_ci * @offset: register offset to write to 161162306a36Sopenharmony_ci * @data: data to write at register offset 161262306a36Sopenharmony_ci * 161362306a36Sopenharmony_ci * Writes an address/data control type register. There are several of these 161462306a36Sopenharmony_ci * and they all have the format address << 8 | data and bit 31 is polled for 161562306a36Sopenharmony_ci * completion. 161662306a36Sopenharmony_ci **/ 161762306a36Sopenharmony_cis32 igb_write_8bit_ctrl_reg(struct e1000_hw *hw, u32 reg, 161862306a36Sopenharmony_ci u32 offset, u8 data) 161962306a36Sopenharmony_ci{ 162062306a36Sopenharmony_ci u32 i, regvalue = 0; 162162306a36Sopenharmony_ci s32 ret_val = 0; 162262306a36Sopenharmony_ci 162362306a36Sopenharmony_ci /* Set up the address and data */ 162462306a36Sopenharmony_ci regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT); 162562306a36Sopenharmony_ci wr32(reg, regvalue); 162662306a36Sopenharmony_ci 162762306a36Sopenharmony_ci /* Poll the ready bit to see if the MDI read completed */ 162862306a36Sopenharmony_ci for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) { 162962306a36Sopenharmony_ci udelay(5); 163062306a36Sopenharmony_ci regvalue = rd32(reg); 163162306a36Sopenharmony_ci if (regvalue & E1000_GEN_CTL_READY) 163262306a36Sopenharmony_ci break; 163362306a36Sopenharmony_ci } 163462306a36Sopenharmony_ci if (!(regvalue & E1000_GEN_CTL_READY)) { 163562306a36Sopenharmony_ci hw_dbg("Reg %08x did not indicate ready\n", reg); 163662306a36Sopenharmony_ci ret_val = -E1000_ERR_PHY; 163762306a36Sopenharmony_ci goto out; 163862306a36Sopenharmony_ci } 163962306a36Sopenharmony_ci 164062306a36Sopenharmony_ciout: 164162306a36Sopenharmony_ci return ret_val; 164262306a36Sopenharmony_ci} 164362306a36Sopenharmony_ci 164462306a36Sopenharmony_ci/** 164562306a36Sopenharmony_ci * igb_enable_mng_pass_thru - Enable processing of ARP's 164662306a36Sopenharmony_ci * @hw: pointer to the HW structure 164762306a36Sopenharmony_ci * 164862306a36Sopenharmony_ci * Verifies the hardware needs to leave interface enabled so that frames can 164962306a36Sopenharmony_ci * be directed to and from the management interface. 165062306a36Sopenharmony_ci **/ 165162306a36Sopenharmony_cibool igb_enable_mng_pass_thru(struct e1000_hw *hw) 165262306a36Sopenharmony_ci{ 165362306a36Sopenharmony_ci u32 manc; 165462306a36Sopenharmony_ci u32 fwsm, factps; 165562306a36Sopenharmony_ci bool ret_val = false; 165662306a36Sopenharmony_ci 165762306a36Sopenharmony_ci if (!hw->mac.asf_firmware_present) 165862306a36Sopenharmony_ci goto out; 165962306a36Sopenharmony_ci 166062306a36Sopenharmony_ci manc = rd32(E1000_MANC); 166162306a36Sopenharmony_ci 166262306a36Sopenharmony_ci if (!(manc & E1000_MANC_RCV_TCO_EN)) 166362306a36Sopenharmony_ci goto out; 166462306a36Sopenharmony_ci 166562306a36Sopenharmony_ci if (hw->mac.arc_subsystem_valid) { 166662306a36Sopenharmony_ci fwsm = rd32(E1000_FWSM); 166762306a36Sopenharmony_ci factps = rd32(E1000_FACTPS); 166862306a36Sopenharmony_ci 166962306a36Sopenharmony_ci if (!(factps & E1000_FACTPS_MNGCG) && 167062306a36Sopenharmony_ci ((fwsm & E1000_FWSM_MODE_MASK) == 167162306a36Sopenharmony_ci (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT))) { 167262306a36Sopenharmony_ci ret_val = true; 167362306a36Sopenharmony_ci goto out; 167462306a36Sopenharmony_ci } 167562306a36Sopenharmony_ci } else { 167662306a36Sopenharmony_ci if ((manc & E1000_MANC_SMBUS_EN) && 167762306a36Sopenharmony_ci !(manc & E1000_MANC_ASF_EN)) { 167862306a36Sopenharmony_ci ret_val = true; 167962306a36Sopenharmony_ci goto out; 168062306a36Sopenharmony_ci } 168162306a36Sopenharmony_ci } 168262306a36Sopenharmony_ci 168362306a36Sopenharmony_ciout: 168462306a36Sopenharmony_ci return ret_val; 168562306a36Sopenharmony_ci} 1686