15779Sxy150489 /* 25779Sxy150489 * CDDL HEADER START 35779Sxy150489 * 48571SChenlu.Chen@Sun.COM * Copyright(c) 2007-2009 Intel Corporation. All rights reserved. 55779Sxy150489 * The contents of this file are subject to the terms of the 65779Sxy150489 * Common Development and Distribution License (the "License"). 75779Sxy150489 * You may not use this file except in compliance with the License. 85779Sxy150489 * 95779Sxy150489 * You can obtain a copy of the license at: 105779Sxy150489 * http://www.opensolaris.org/os/licensing. 115779Sxy150489 * See the License for the specific language governing permissions 125779Sxy150489 * and limitations under the License. 135779Sxy150489 * 145779Sxy150489 * When using or redistributing this file, you may do so under the 155779Sxy150489 * License only. No other modification of this header is permitted. 165779Sxy150489 * 175779Sxy150489 * If applicable, add the following below this CDDL HEADER, with the 185779Sxy150489 * fields enclosed by brackets "[]" replaced with your own identifying 195779Sxy150489 * information: Portions Copyright [yyyy] [name of copyright owner] 205779Sxy150489 * 215779Sxy150489 * CDDL HEADER END 225779Sxy150489 */ 235779Sxy150489 245779Sxy150489 /* 258571SChenlu.Chen@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 265779Sxy150489 * Use is subject to license terms of the CDDL. 275779Sxy150489 */ 285779Sxy150489 29*10319SJason.Xu@Sun.COM /* IntelVersion: 1.104 v2-9-8_2009-6-12 */ 305779Sxy150489 315779Sxy150489 #include "igb_api.h" 328571SChenlu.Chen@Sun.COM 338571SChenlu.Chen@Sun.COM static s32 e1000_set_default_fc_generic(struct e1000_hw *hw); 348571SChenlu.Chen@Sun.COM static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw); 358571SChenlu.Chen@Sun.COM static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw); 368571SChenlu.Chen@Sun.COM static s32 e1000_validate_mdi_setting_generic(struct e1000_hw *hw); 37*10319SJason.Xu@Sun.COM static void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw); 385779Sxy150489 395779Sxy150489 /* 408571SChenlu.Chen@Sun.COM * e1000_init_mac_ops_generic - Initialize MAC function pointers 415779Sxy150489 * @hw: pointer to the HW structure 425779Sxy150489 * 438571SChenlu.Chen@Sun.COM * Setups up the function pointers to no-op functions 448571SChenlu.Chen@Sun.COM */ 458571SChenlu.Chen@Sun.COM void 468571SChenlu.Chen@Sun.COM e1000_init_mac_ops_generic(struct e1000_hw *hw) 478571SChenlu.Chen@Sun.COM { 488571SChenlu.Chen@Sun.COM struct e1000_mac_info *mac = &hw->mac; 498571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_init_mac_ops_generic"); 508571SChenlu.Chen@Sun.COM 518571SChenlu.Chen@Sun.COM /* General Setup */ 528571SChenlu.Chen@Sun.COM mac->ops.init_params = e1000_null_ops_generic; 538571SChenlu.Chen@Sun.COM mac->ops.init_hw = e1000_null_ops_generic; 548571SChenlu.Chen@Sun.COM mac->ops.reset_hw = e1000_null_ops_generic; 558571SChenlu.Chen@Sun.COM mac->ops.setup_physical_interface = e1000_null_ops_generic; 568571SChenlu.Chen@Sun.COM mac->ops.get_bus_info = e1000_null_ops_generic; 57*10319SJason.Xu@Sun.COM mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pcie; 588571SChenlu.Chen@Sun.COM mac->ops.read_mac_addr = e1000_read_mac_addr_generic; 598571SChenlu.Chen@Sun.COM mac->ops.config_collision_dist = e1000_config_collision_dist_generic; 608571SChenlu.Chen@Sun.COM mac->ops.clear_hw_cntrs = e1000_null_mac_generic; 618571SChenlu.Chen@Sun.COM /* LED */ 628571SChenlu.Chen@Sun.COM mac->ops.cleanup_led = e1000_null_ops_generic; 638571SChenlu.Chen@Sun.COM mac->ops.setup_led = e1000_null_ops_generic; 648571SChenlu.Chen@Sun.COM mac->ops.blink_led = e1000_null_ops_generic; 658571SChenlu.Chen@Sun.COM mac->ops.led_on = e1000_null_ops_generic; 668571SChenlu.Chen@Sun.COM mac->ops.led_off = e1000_null_ops_generic; 678571SChenlu.Chen@Sun.COM /* LINK */ 688571SChenlu.Chen@Sun.COM mac->ops.setup_link = e1000_null_ops_generic; 698571SChenlu.Chen@Sun.COM mac->ops.get_link_up_info = e1000_null_link_info; 708571SChenlu.Chen@Sun.COM mac->ops.check_for_link = e1000_null_ops_generic; 718571SChenlu.Chen@Sun.COM mac->ops.wait_autoneg = e1000_wait_autoneg_generic; 728571SChenlu.Chen@Sun.COM /* Management */ 738571SChenlu.Chen@Sun.COM mac->ops.check_mng_mode = e1000_null_mng_mode; 748571SChenlu.Chen@Sun.COM mac->ops.mng_host_if_write = e1000_mng_host_if_write_generic; 758571SChenlu.Chen@Sun.COM mac->ops.mng_write_cmd_header = e1000_mng_write_cmd_header_generic; 768571SChenlu.Chen@Sun.COM mac->ops.mng_enable_host_if = e1000_mng_enable_host_if_generic; 778571SChenlu.Chen@Sun.COM /* VLAN, MC, etc. */ 788571SChenlu.Chen@Sun.COM mac->ops.update_mc_addr_list = e1000_null_update_mc; 798571SChenlu.Chen@Sun.COM mac->ops.clear_vfta = e1000_null_mac_generic; 808571SChenlu.Chen@Sun.COM mac->ops.write_vfta = e1000_null_write_vfta; 818571SChenlu.Chen@Sun.COM mac->ops.mta_set = e1000_null_mta_set; 828571SChenlu.Chen@Sun.COM mac->ops.rar_set = e1000_rar_set_generic; 838571SChenlu.Chen@Sun.COM mac->ops.validate_mdi_setting = e1000_validate_mdi_setting_generic; 848571SChenlu.Chen@Sun.COM } 858571SChenlu.Chen@Sun.COM 868571SChenlu.Chen@Sun.COM /* 878571SChenlu.Chen@Sun.COM * e1000_null_ops_generic - No-op function, returns 0 888571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 898571SChenlu.Chen@Sun.COM */ 908571SChenlu.Chen@Sun.COM s32 918571SChenlu.Chen@Sun.COM e1000_null_ops_generic(struct e1000_hw *hw) 928571SChenlu.Chen@Sun.COM { 938571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_ops_generic"); 948571SChenlu.Chen@Sun.COM UNREFERENCED_1PARAMETER(hw); 958571SChenlu.Chen@Sun.COM return (E1000_SUCCESS); 968571SChenlu.Chen@Sun.COM } 978571SChenlu.Chen@Sun.COM 988571SChenlu.Chen@Sun.COM /* 998571SChenlu.Chen@Sun.COM * e1000_null_mac_generic - No-op function, return void 1008571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 1015779Sxy150489 */ 1025779Sxy150489 void 1038571SChenlu.Chen@Sun.COM e1000_null_mac_generic(struct e1000_hw *hw) 1048571SChenlu.Chen@Sun.COM { 1058571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_mac_generic"); 1068571SChenlu.Chen@Sun.COM UNREFERENCED_1PARAMETER(hw); 1078571SChenlu.Chen@Sun.COM } 1088571SChenlu.Chen@Sun.COM 1098571SChenlu.Chen@Sun.COM /* 1108571SChenlu.Chen@Sun.COM * e1000_null_link_info - No-op function, return 0 1118571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 1128571SChenlu.Chen@Sun.COM */ 1138571SChenlu.Chen@Sun.COM s32 1148571SChenlu.Chen@Sun.COM e1000_null_link_info(struct e1000_hw *hw, u16 *s, u16 *d) 1158571SChenlu.Chen@Sun.COM { 1168571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_link_info"); 1178571SChenlu.Chen@Sun.COM UNREFERENCED_3PARAMETER(hw, s, d); 1188571SChenlu.Chen@Sun.COM return (E1000_SUCCESS); 1198571SChenlu.Chen@Sun.COM } 1208571SChenlu.Chen@Sun.COM 1218571SChenlu.Chen@Sun.COM /* 1228571SChenlu.Chen@Sun.COM * e1000_null_mng_mode - No-op function, return false 1238571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 1248571SChenlu.Chen@Sun.COM */ 1258571SChenlu.Chen@Sun.COM bool 1268571SChenlu.Chen@Sun.COM e1000_null_mng_mode(struct e1000_hw *hw) 1275779Sxy150489 { 1288571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_mng_mode"); 1298571SChenlu.Chen@Sun.COM UNREFERENCED_1PARAMETER(hw); 1308571SChenlu.Chen@Sun.COM return (false); 1318571SChenlu.Chen@Sun.COM } 1328571SChenlu.Chen@Sun.COM 1338571SChenlu.Chen@Sun.COM /* 1348571SChenlu.Chen@Sun.COM * e1000_null_update_mc - No-op function, return void 1358571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 1368571SChenlu.Chen@Sun.COM */ 1378571SChenlu.Chen@Sun.COM void 138*10319SJason.Xu@Sun.COM e1000_null_update_mc(struct e1000_hw *hw, u8 *h, u32 a) 1398571SChenlu.Chen@Sun.COM { 1408571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_update_mc"); 141*10319SJason.Xu@Sun.COM UNREFERENCED_3PARAMETER(hw, h, a); 1428571SChenlu.Chen@Sun.COM } 1435779Sxy150489 1448571SChenlu.Chen@Sun.COM /* 1458571SChenlu.Chen@Sun.COM * e1000_null_write_vfta - No-op function, return void 1468571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 1478571SChenlu.Chen@Sun.COM */ 1488571SChenlu.Chen@Sun.COM void 1498571SChenlu.Chen@Sun.COM e1000_null_write_vfta(struct e1000_hw *hw, u32 a, u32 b) 1508571SChenlu.Chen@Sun.COM { 1518571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_write_vfta"); 1528571SChenlu.Chen@Sun.COM UNREFERENCED_3PARAMETER(hw, a, b); 1538571SChenlu.Chen@Sun.COM } 1548571SChenlu.Chen@Sun.COM 1558571SChenlu.Chen@Sun.COM /* 1568571SChenlu.Chen@Sun.COM * e1000_null_set_mta - No-op function, return void 1578571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 1588571SChenlu.Chen@Sun.COM */ 1598571SChenlu.Chen@Sun.COM void 1608571SChenlu.Chen@Sun.COM e1000_null_mta_set(struct e1000_hw *hw, u32 a) 1618571SChenlu.Chen@Sun.COM { 1628571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_mta_set"); 1638571SChenlu.Chen@Sun.COM UNREFERENCED_2PARAMETER(hw, a); 1648571SChenlu.Chen@Sun.COM } 1658571SChenlu.Chen@Sun.COM 1668571SChenlu.Chen@Sun.COM /* 1678571SChenlu.Chen@Sun.COM * e1000_null_rar_set - No-op function, return void 1688571SChenlu.Chen@Sun.COM * @hw: pointer to the HW structure 1698571SChenlu.Chen@Sun.COM */ 1708571SChenlu.Chen@Sun.COM void 1718571SChenlu.Chen@Sun.COM e1000_null_rar_set(struct e1000_hw *hw, u8 *h, u32 a) 1728571SChenlu.Chen@Sun.COM { 1738571SChenlu.Chen@Sun.COM DEBUGFUNC("e1000_null_rar_set"); 1748571SChenlu.Chen@Sun.COM UNREFERENCED_3PARAMETER(hw, h, a); 1755779Sxy150489 } 1765779Sxy150489 1775779Sxy150489 /* 1785779Sxy150489 * e1000_get_bus_info_pcie_generic - Get PCIe bus information 1795779Sxy150489 * @hw: pointer to the HW structure 1805779Sxy150489 * 1815779Sxy150489 * Determines and stores the system bus information for a particular 1825779Sxy150489 * network interface. The following bus information is determined and stored: 1835779Sxy150489 * bus speed, bus width, type (PCIe), and PCIe function. 1845779Sxy150489 */ 1855779Sxy150489 s32 1865779Sxy150489 e1000_get_bus_info_pcie_generic(struct e1000_hw *hw) 1875779Sxy150489 { 188*10319SJason.Xu@Sun.COM struct e1000_mac_info *mac = &hw->mac; 1895779Sxy150489 struct e1000_bus_info *bus = &hw->bus; 1905779Sxy150489 s32 ret_val; 191*10319SJason.Xu@Sun.COM u16 pcie_link_status; 1925779Sxy150489 1935779Sxy150489 DEBUGFUNC("e1000_get_bus_info_pcie_generic"); 1945779Sxy150489 1955779Sxy150489 bus->type = e1000_bus_type_pci_express; 1965779Sxy150489 bus->speed = e1000_bus_speed_2500; 1975779Sxy150489 1985779Sxy150489 ret_val = e1000_read_pcie_cap_reg(hw, 1995779Sxy150489 PCIE_LINK_STATUS, &pcie_link_status); 2005779Sxy150489 if (ret_val) 2015779Sxy150489 bus->width = e1000_bus_width_unknown; 2025779Sxy150489 else 2038571SChenlu.Chen@Sun.COM bus->width = (enum e1000_bus_width)((pcie_link_status & 2045779Sxy150489 PCIE_LINK_WIDTH_MASK) >> PCIE_LINK_WIDTH_SHIFT); 2055779Sxy150489 206*10319SJason.Xu@Sun.COM mac->ops.set_lan_id(hw); 2075779Sxy150489 2085779Sxy150489 return (E1000_SUCCESS); 2095779Sxy150489 } 2105779Sxy150489 2115779Sxy150489 /* 212*10319SJason.Xu@Sun.COM * e1000_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices 213*10319SJason.Xu@Sun.COM * 214*10319SJason.Xu@Sun.COM * @hw: pointer to the HW structure 215*10319SJason.Xu@Sun.COM * 216*10319SJason.Xu@Sun.COM * Determines the LAN function id by reading memory-mapped registers 217*10319SJason.Xu@Sun.COM * and swaps the port value if requested. 218*10319SJason.Xu@Sun.COM */ 219*10319SJason.Xu@Sun.COM static void 220*10319SJason.Xu@Sun.COM e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw) 221*10319SJason.Xu@Sun.COM { 222*10319SJason.Xu@Sun.COM struct e1000_bus_info *bus = &hw->bus; 223*10319SJason.Xu@Sun.COM u32 reg; 224*10319SJason.Xu@Sun.COM 225*10319SJason.Xu@Sun.COM /* 226*10319SJason.Xu@Sun.COM * The status register reports the correct function number 227*10319SJason.Xu@Sun.COM * for the device regardless of function swap state. 228*10319SJason.Xu@Sun.COM */ 229*10319SJason.Xu@Sun.COM reg = E1000_READ_REG(hw, E1000_STATUS); 230*10319SJason.Xu@Sun.COM bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT; 231*10319SJason.Xu@Sun.COM } 232*10319SJason.Xu@Sun.COM 233*10319SJason.Xu@Sun.COM /* 234*10319SJason.Xu@Sun.COM * e1000_set_lan_id_single_port - Set LAN id for a single port device 235*10319SJason.Xu@Sun.COM * @hw: pointer to the HW structure 236*10319SJason.Xu@Sun.COM * 237*10319SJason.Xu@Sun.COM * Sets the LAN function id to zero for a single port device. 238*10319SJason.Xu@Sun.COM */ 239*10319SJason.Xu@Sun.COM void 240*10319SJason.Xu@Sun.COM e1000_set_lan_id_single_port(struct e1000_hw *hw) 241*10319SJason.Xu@Sun.COM { 242*10319SJason.Xu@Sun.COM struct e1000_bus_info *bus = &hw->bus; 243*10319SJason.Xu@Sun.COM 244*10319SJason.Xu@Sun.COM bus->func = 0; 245*10319SJason.Xu@Sun.COM } 246*10319SJason.Xu@Sun.COM 247*10319SJason.Xu@Sun.COM /* 2485779Sxy150489 * e1000_clear_vfta_generic - Clear VLAN filter table 2495779Sxy150489 * @hw: pointer to the HW structure 2505779Sxy150489 * 2515779Sxy150489 * Clears the register array which contains the VLAN filter table by 2525779Sxy150489 * setting all the values to 0. 2535779Sxy150489 */ 2545779Sxy150489 void 2555779Sxy150489 e1000_clear_vfta_generic(struct e1000_hw *hw) 2565779Sxy150489 { 2575779Sxy150489 u32 offset; 2585779Sxy150489 2595779Sxy150489 DEBUGFUNC("e1000_clear_vfta_generic"); 2605779Sxy150489 2615779Sxy150489 for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) { 2625779Sxy150489 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0); 2635779Sxy150489 E1000_WRITE_FLUSH(hw); 2645779Sxy150489 } 2655779Sxy150489 } 2665779Sxy150489 2675779Sxy150489 /* 2685779Sxy150489 * e1000_write_vfta_generic - Write value to VLAN filter table 2695779Sxy150489 * @hw: pointer to the HW structure 2705779Sxy150489 * @offset: register offset in VLAN filter table 2715779Sxy150489 * @value: register value written to VLAN filter table 2725779Sxy150489 * 2735779Sxy150489 * Writes value at the given offset in the register array which stores 2745779Sxy150489 * the VLAN filter table. 2755779Sxy150489 */ 2765779Sxy150489 void 2775779Sxy150489 e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value) 2785779Sxy150489 { 2795779Sxy150489 DEBUGFUNC("e1000_write_vfta_generic"); 2805779Sxy150489 2815779Sxy150489 E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value); 2825779Sxy150489 E1000_WRITE_FLUSH(hw); 2835779Sxy150489 } 2845779Sxy150489 2855779Sxy150489 /* 2865779Sxy150489 * e1000_init_rx_addrs_generic - Initialize receive address's 2875779Sxy150489 * @hw: pointer to the HW structure 2885779Sxy150489 * @rar_count: receive address registers 2895779Sxy150489 * 2905779Sxy150489 * Setups the receive address registers by setting the base receive address 2915779Sxy150489 * register to the devices MAC address and clearing all the other receive 2925779Sxy150489 * address registers to 0. 2935779Sxy150489 */ 2945779Sxy150489 void 2955779Sxy150489 e1000_init_rx_addrs_generic(struct e1000_hw *hw, u16 rar_count) 2965779Sxy150489 { 2975779Sxy150489 u32 i; 298*10319SJason.Xu@Sun.COM u8 mac_addr[ETH_ADDR_LEN] = {0}; 2995779Sxy150489 3005779Sxy150489 DEBUGFUNC("e1000_init_rx_addrs_generic"); 3015779Sxy150489 3025779Sxy150489 /* Setup the receive address */ 3035779Sxy150489 DEBUGOUT("Programming MAC Address into RAR[0]\n"); 3045779Sxy150489 3058571SChenlu.Chen@Sun.COM hw->mac.ops.rar_set(hw, hw->mac.addr, 0); 3065779Sxy150489 3075779Sxy150489 /* Zero out the other (rar_entry_count - 1) receive addresses */ 3085779Sxy150489 DEBUGOUT1("Clearing RAR[1-%u]\n", rar_count-1); 309*10319SJason.Xu@Sun.COM for (i = 1; i < rar_count; i++) 310*10319SJason.Xu@Sun.COM hw->mac.ops.rar_set(hw, mac_addr, i); 3115779Sxy150489 } 3125779Sxy150489 3135779Sxy150489 /* 3145779Sxy150489 * e1000_check_alt_mac_addr_generic - Check for alternate MAC addr 3155779Sxy150489 * @hw: pointer to the HW structure 3165779Sxy150489 * 3175779Sxy150489 * Checks the nvm for an alternate MAC address. An alternate MAC address 3185779Sxy150489 * can be setup by pre-boot software and must be treated like a permanent 3195779Sxy150489 * address and must override the actual permanent MAC address. If an 320*10319SJason.Xu@Sun.COM * alternate MAC address is found it is programmed into RAR0, replacing 321*10319SJason.Xu@Sun.COM * the permanent address that was installed into RAR0 by the Si on reset. 322*10319SJason.Xu@Sun.COM * This function will return SUCCESS unless it encounters an error while 323*10319SJason.Xu@Sun.COM * reading the EEPROM. 3245779Sxy150489 */ 3255779Sxy150489 s32 3265779Sxy150489 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw) 3275779Sxy150489 { 3285779Sxy150489 u32 i; 3295779Sxy150489 s32 ret_val = E1000_SUCCESS; 3305779Sxy150489 u16 offset, nvm_alt_mac_addr_offset, nvm_data; 3315779Sxy150489 u8 alt_mac_addr[ETH_ADDR_LEN]; 3325779Sxy150489 3335779Sxy150489 DEBUGFUNC("e1000_check_alt_mac_addr_generic"); 3345779Sxy150489 3358571SChenlu.Chen@Sun.COM ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1, 3365779Sxy150489 &nvm_alt_mac_addr_offset); 3375779Sxy150489 if (ret_val) { 3385779Sxy150489 DEBUGOUT("NVM Read Error\n"); 3395779Sxy150489 goto out; 3405779Sxy150489 } 3415779Sxy150489 3425779Sxy150489 if (nvm_alt_mac_addr_offset == 0xFFFF) { 343*10319SJason.Xu@Sun.COM /* There is no Alternate MAC Address */ 3445779Sxy150489 goto out; 3455779Sxy150489 } 3465779Sxy150489 3475779Sxy150489 if (hw->bus.func == E1000_FUNC_1) 348*10319SJason.Xu@Sun.COM nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1; 3495779Sxy150489 for (i = 0; i < ETH_ADDR_LEN; i += 2) { 3505779Sxy150489 offset = nvm_alt_mac_addr_offset + (i >> 1); 3518571SChenlu.Chen@Sun.COM ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data); 3525779Sxy150489 if (ret_val) { 3535779Sxy150489 DEBUGOUT("NVM Read Error\n"); 3545779Sxy150489 goto out; 3555779Sxy150489 } 3565779Sxy150489 3575779Sxy150489 alt_mac_addr[i] = (u8)(nvm_data & 0xFF); 3585779Sxy150489 alt_mac_addr[i + 1] = (u8)(nvm_data >> 8); 3595779Sxy150489 } 3605779Sxy150489 3615779Sxy150489 /* if multicast bit is set, the alternate address will not be used */ 3625779Sxy150489 if (alt_mac_addr[0] & 0x01) { 363*10319SJason.Xu@Sun.COM DEBUGOUT("Ignoring Alternate Mac Address with MC bit set\n"); 3645779Sxy150489 goto out; 3655779Sxy150489 } 3665779Sxy150489 367*10319SJason.Xu@Sun.COM /* 368*10319SJason.Xu@Sun.COM * We have a valid alternate MAC address, and we want to treat it the 369*10319SJason.Xu@Sun.COM * same as the normal permanent MAC address stored by the HW into the 370*10319SJason.Xu@Sun.COM * RAR. Do this by mapping this address into RAR0. 371*10319SJason.Xu@Sun.COM */ 372*10319SJason.Xu@Sun.COM hw->mac.ops.rar_set(hw, alt_mac_addr, 0); 3735779Sxy150489 3745779Sxy150489 out: 3755779Sxy150489 return (ret_val); 3765779Sxy150489 } 3775779Sxy150489 3785779Sxy150489 /* 3795779Sxy150489 * e1000_rar_set_generic - Set receive address register 3805779Sxy150489 * @hw: pointer to the HW structure 3815779Sxy150489 * @addr: pointer to the receive address 3825779Sxy150489 * @index: receive address array register 3835779Sxy150489 * 3845779Sxy150489 * Sets the receive address array register at index to the address passed 3855779Sxy150489 * in by addr. 3865779Sxy150489 */ 3875779Sxy150489 void 3885779Sxy150489 e1000_rar_set_generic(struct e1000_hw *hw, u8 *addr, u32 index) 3895779Sxy150489 { 3905779Sxy150489 u32 rar_low, rar_high; 3915779Sxy150489 3925779Sxy150489 DEBUGFUNC("e1000_rar_set_generic"); 3935779Sxy150489 3945779Sxy150489 /* 3955779Sxy150489 * HW expects these in little endian so we reverse the byte order 3965779Sxy150489 * from network order (big endian) to little endian 3975779Sxy150489 */ 3985779Sxy150489 rar_low = ((u32) addr[0] | 3995779Sxy150489 ((u32) addr[1] << 8) | 4005779Sxy150489 ((u32) addr[2] << 16) | ((u32) addr[3] << 24)); 4015779Sxy150489 4025779Sxy150489 rar_high = ((u32) addr[4] | ((u32) addr[5] << 8)); 4035779Sxy150489 4045779Sxy150489 /* If MAC address zero, no need to set the AV bit */ 4058571SChenlu.Chen@Sun.COM if (rar_low || rar_high) 4068571SChenlu.Chen@Sun.COM rar_high |= E1000_RAH_AV; 4075779Sxy150489 408*10319SJason.Xu@Sun.COM /* 409*10319SJason.Xu@Sun.COM * Some bridges will combine consecutive 32-bit writes into 410*10319SJason.Xu@Sun.COM * a single burst write, which will malfunction on some parts. 411*10319SJason.Xu@Sun.COM * The flushes avoid this. 412*10319SJason.Xu@Sun.COM */ 4138571SChenlu.Chen@Sun.COM E1000_WRITE_REG(hw, E1000_RAL(index), rar_low); 414*10319SJason.Xu@Sun.COM E1000_WRITE_FLUSH(hw); 4158571SChenlu.Chen@Sun.COM E1000_WRITE_REG(hw, E1000_RAH(index), rar_high); 416*10319SJason.Xu@Sun.COM E1000_WRITE_FLUSH(hw); 4175779Sxy150489 } 4185779Sxy150489 4195779Sxy150489 /* 4205779Sxy150489 * e1000_mta_set_generic - Set multicast filter table address 4215779Sxy150489 * @hw: pointer to the HW structure 4225779Sxy150489 * @hash_value: determines the MTA register and bit to set 4235779Sxy150489 * 4245779Sxy150489 * The multicast table address is a register array of 32-bit registers. 4255779Sxy150489 * The hash_value is used to determine what register the bit is in, the 4265779Sxy150489 * current value is read, the new bit is OR'd in and the new value is 4275779Sxy150489 * written back into the register. 4285779Sxy150489 */ 4295779Sxy150489 void 4305779Sxy150489 e1000_mta_set_generic(struct e1000_hw *hw, u32 hash_value) 4315779Sxy150489 { 4325779Sxy150489 u32 hash_bit, hash_reg, mta; 4335779Sxy150489 4345779Sxy150489 DEBUGFUNC("e1000_mta_set_generic"); 4355779Sxy150489 /* 4365779Sxy150489 * The MTA is a register array of 32-bit registers. It is 4375779Sxy150489 * treated like an array of (32*mta_reg_count) bits. We want to 4385779Sxy150489 * set bit BitArray[hash_value]. So we figure out what register 4395779Sxy150489 * the bit is in, read it, OR in the new bit, then write 4405779Sxy150489 * back the new value. The (hw->mac.mta_reg_count - 1) serves as a 4415779Sxy150489 * mask to bits 31:5 of the hash value which gives us the 4425779Sxy150489 * register we're modifying. The hash bit within that register 4435779Sxy150489 * is determined by the lower 5 bits of the hash value. 4445779Sxy150489 */ 4455779Sxy150489 hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); 4465779Sxy150489 hash_bit = hash_value & 0x1F; 4475779Sxy150489 4485779Sxy150489 mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg); 4495779Sxy150489 4505779Sxy150489 mta |= (1 << hash_bit); 4515779Sxy150489 4525779Sxy150489 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta); 4535779Sxy150489 E1000_WRITE_FLUSH(hw); 4545779Sxy150489 } 4555779Sxy150489 4565779Sxy150489 /* 4575779Sxy150489 * e1000_update_mc_addr_list_generic - Update Multicast addresses 4585779Sxy150489 * @hw: pointer to the HW structure 4595779Sxy150489 * @mc_addr_list: array of multicast addresses to program 4605779Sxy150489 * @mc_addr_count: number of multicast addresses to program 4615779Sxy150489 * 462*10319SJason.Xu@Sun.COM * Updates the Multicast Table Array. 4635779Sxy150489 * The caller must have a packed mc_addr_list of multicast addresses. 4645779Sxy150489 */ 4655779Sxy150489 void 4665779Sxy150489 e1000_update_mc_addr_list_generic(struct e1000_hw *hw, 467*10319SJason.Xu@Sun.COM u8 *mc_addr_list, u32 mc_addr_count) 4685779Sxy150489 { 469*10319SJason.Xu@Sun.COM u32 hash_value, hash_bit, hash_reg; 470*10319SJason.Xu@Sun.COM int i; 4715779Sxy150489 4725779Sxy150489 DEBUGFUNC("e1000_update_mc_addr_list_generic"); 4735779Sxy150489 474*10319SJason.Xu@Sun.COM /* clear mta_shadow */ 475*10319SJason.Xu@Sun.COM memset(&hw->mac.mta_shadow, 0, sizeof (hw->mac.mta_shadow)); 476*10319SJason.Xu@Sun.COM 477*10319SJason.Xu@Sun.COM /* update mta_shadow from mc_addr_list */ 478*10319SJason.Xu@Sun.COM for (i = 0; (u32) i < mc_addr_count; i++) { 479*10319SJason.Xu@Sun.COM hash_value = e1000_hash_mc_addr_generic(hw, mc_addr_list); 480*10319SJason.Xu@Sun.COM 481*10319SJason.Xu@Sun.COM hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1); 482*10319SJason.Xu@Sun.COM hash_bit = hash_value & 0x1F; 483*10319SJason.Xu@Sun.COM 484*10319SJason.Xu@Sun.COM hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit); 485*10319SJason.Xu@Sun.COM mc_addr_list += (ETH_ADDR_LEN); 4865779Sxy150489 } 4875779Sxy150489 488*10319SJason.Xu@Sun.COM /* replace the entire MTA table */ 489*10319SJason.Xu@Sun.COM for (i = hw->mac.mta_reg_count - 1; i >= 0; i--) 490*10319SJason.Xu@Sun.COM E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]); 491*10319SJason.Xu@Sun.COM E1000_WRITE_FLUSH(hw); 4925779Sxy150489 } 4935779Sxy150489 4945779Sxy150489 /* 4955779Sxy150489 * e1000_hash_mc_addr_generic - Generate a multicast hash value 4965779Sxy150489 * @hw: pointer to the HW structure 4975779Sxy150489 * @mc_addr: pointer to a multicast address 4985779Sxy150489 * 4995779Sxy150489 * Generates a multicast address hash value which is used to determine 5005779Sxy150489 * the multicast filter table array address and new table value. See 5015779Sxy150489 * e1000_mta_set_generic() 5025779Sxy150489 */ 5035779Sxy150489 u32 5045779Sxy150489 e1000_hash_mc_addr_generic(struct e1000_hw *hw, u8 *mc_addr) 5055779Sxy150489 { 5065779Sxy150489 u32 hash_value, hash_mask; 5075779Sxy150489 u8 bit_shift = 0; 5085779Sxy150489 5095779Sxy150489 DEBUGFUNC("e1000_hash_mc_addr_generic"); 5105779Sxy150489 5115779Sxy150489 /* Register count multiplied by bits per register */ 5125779Sxy150489 hash_mask = (hw->mac.mta_reg_count * 32) - 1; 5135779Sxy150489 5145779Sxy150489 /* 5155779Sxy150489 * For a mc_filter_type of 0, bit_shift is the number of left-shifts 5165779Sxy150489 * where 0xFF would still fall within the hash mask. 5175779Sxy150489 */ 5185779Sxy150489 while (hash_mask >> bit_shift != 0xFF) 5195779Sxy150489 bit_shift++; 5205779Sxy150489 5215779Sxy150489 /* 5225779Sxy150489 * The portion of the address that is used for the hash table 5235779Sxy150489 * is determined by the mc_filter_type setting. 5245779Sxy150489 * The algorithm is such that there is a total of 8 bits of shifting. 5255779Sxy150489 * The bit_shift for a mc_filter_type of 0 represents the number of 5265779Sxy150489 * left-shifts where the MSB of mc_addr[5] would still fall within 5275779Sxy150489 * the hash_mask. Case 0 does this exactly. Since there are a total 5285779Sxy150489 * of 8 bits of shifting, then mc_addr[4] will shift right the 5295779Sxy150489 * remaining number of bits. Thus 8 - bit_shift. The rest of the 5305779Sxy150489 * cases are a variation of this algorithm...essentially raising the 5315779Sxy150489 * number of bits to shift mc_addr[5] left, while still keeping the 5325779Sxy150489 * 8-bit shifting total. 5335779Sxy150489 * 5345779Sxy150489 * For example, given the following Destination MAC Address and an 5355779Sxy150489 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask), 5365779Sxy150489 * we can see that the bit_shift for case 0 is 4. These are the hash 5375779Sxy150489 * values resulting from each mc_filter_type... 5385779Sxy150489 * [0] [1] [2] [3] [4] [5] 5395779Sxy150489 * 01 AA 00 12 34 56 5405779Sxy150489 * LSB MSB 5415779Sxy150489 * 5425779Sxy150489 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563 5435779Sxy150489 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6 5445779Sxy150489 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163 5455779Sxy150489 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634 5465779Sxy150489 */ 5475779Sxy150489 switch (hw->mac.mc_filter_type) { 5485779Sxy150489 default: 5495779Sxy150489 case 0: 5505779Sxy150489 break; 5515779Sxy150489 case 1: 5525779Sxy150489 bit_shift += 1; 5535779Sxy150489 break; 5545779Sxy150489 case 2: 5555779Sxy150489 bit_shift += 2; 5565779Sxy150489 break; 5575779Sxy150489 case 3: 5585779Sxy150489 bit_shift += 4; 5595779Sxy150489 break; 5605779Sxy150489 } 5615779Sxy150489 5625779Sxy150489 hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) | 5635779Sxy150489 (((u16) mc_addr[5]) << bit_shift))); 5645779Sxy150489 5655779Sxy150489 return (hash_value); 5665779Sxy150489 } 5675779Sxy150489 5685779Sxy150489 /* 5695779Sxy150489 * e1000_clear_hw_cntrs_base_generic - Clear base hardware counters 5705779Sxy150489 * @hw: pointer to the HW structure 5715779Sxy150489 * 5725779Sxy150489 * Clears the base hardware counters by reading the counter registers. 5735779Sxy150489 */ 5745779Sxy150489 void 5755779Sxy150489 e1000_clear_hw_cntrs_base_generic(struct e1000_hw *hw) 5765779Sxy150489 { 5775779Sxy150489 DEBUGFUNC("e1000_clear_hw_cntrs_base_generic"); 5785779Sxy150489 5795779Sxy150489 (void) E1000_READ_REG(hw, E1000_CRCERRS); 5805779Sxy150489 (void) E1000_READ_REG(hw, E1000_SYMERRS); 5815779Sxy150489 (void) E1000_READ_REG(hw, E1000_MPC); 5825779Sxy150489 (void) E1000_READ_REG(hw, E1000_SCC); 5835779Sxy150489 (void) E1000_READ_REG(hw, E1000_ECOL); 5845779Sxy150489 (void) E1000_READ_REG(hw, E1000_MCC); 5855779Sxy150489 (void) E1000_READ_REG(hw, E1000_LATECOL); 5865779Sxy150489 (void) E1000_READ_REG(hw, E1000_COLC); 5875779Sxy150489 (void) E1000_READ_REG(hw, E1000_DC); 5885779Sxy150489 (void) E1000_READ_REG(hw, E1000_SEC); 5895779Sxy150489 (void) E1000_READ_REG(hw, E1000_RLEC); 5905779Sxy150489 (void) E1000_READ_REG(hw, E1000_XONRXC); 5915779Sxy150489 (void) E1000_READ_REG(hw, E1000_XONTXC); 5925779Sxy150489 (void) E1000_READ_REG(hw, E1000_XOFFRXC); 5935779Sxy150489 (void) E1000_READ_REG(hw, E1000_XOFFTXC); 5945779Sxy150489 (void) E1000_READ_REG(hw, E1000_FCRUC); 5955779Sxy150489 (void) E1000_READ_REG(hw, E1000_GPRC); 5965779Sxy150489 (void) E1000_READ_REG(hw, E1000_BPRC); 5975779Sxy150489 (void) E1000_READ_REG(hw, E1000_MPRC); 5985779Sxy150489 (void) E1000_READ_REG(hw, E1000_GPTC); 5995779Sxy150489 (void) E1000_READ_REG(hw, E1000_GORCL); 6005779Sxy150489 (void) E1000_READ_REG(hw, E1000_GORCH); 6015779Sxy150489 (void) E1000_READ_REG(hw, E1000_GOTCL); 6025779Sxy150489 (void) E1000_READ_REG(hw, E1000_GOTCH); 6035779Sxy150489 (void) E1000_READ_REG(hw, E1000_RNBC); 6045779Sxy150489 (void) E1000_READ_REG(hw, E1000_RUC); 6055779Sxy150489 (void) E1000_READ_REG(hw, E1000_RFC); 6065779Sxy150489 (void) E1000_READ_REG(hw, E1000_ROC); 6075779Sxy150489 (void) E1000_READ_REG(hw, E1000_RJC); 6085779Sxy150489 (void) E1000_READ_REG(hw, E1000_TORL); 6095779Sxy150489 (void) E1000_READ_REG(hw, E1000_TORH); 6105779Sxy150489 (void) E1000_READ_REG(hw, E1000_TOTL); 6115779Sxy150489 (void) E1000_READ_REG(hw, E1000_TOTH); 6125779Sxy150489 (void) E1000_READ_REG(hw, E1000_TPR); 6135779Sxy150489 (void) E1000_READ_REG(hw, E1000_TPT); 6145779Sxy150489 (void) E1000_READ_REG(hw, E1000_MPTC); 6155779Sxy150489 (void) E1000_READ_REG(hw, E1000_BPTC); 6165779Sxy150489 } 6175779Sxy150489 6185779Sxy150489 /* 6195779Sxy150489 * e1000_check_for_copper_link_generic - Check for link (Copper) 6205779Sxy150489 * @hw: pointer to the HW structure 6215779Sxy150489 * 6225779Sxy150489 * Checks to see of the link status of the hardware has changed. If a 6235779Sxy150489 * change in link status has been detected, then we read the PHY registers 6245779Sxy150489 * to get the current speed/duplex if link exists. 6255779Sxy150489 */ 6265779Sxy150489 s32 6275779Sxy150489 e1000_check_for_copper_link_generic(struct e1000_hw *hw) 6285779Sxy150489 { 6295779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 6305779Sxy150489 s32 ret_val; 6315779Sxy150489 bool link; 6325779Sxy150489 6335779Sxy150489 DEBUGFUNC("e1000_check_for_copper_link"); 6345779Sxy150489 6355779Sxy150489 /* 6365779Sxy150489 * We only want to go out to the PHY registers to see if Auto-Neg 6375779Sxy150489 * has completed and/or if our link status has changed. The 6385779Sxy150489 * get_link_status flag is set upon receiving a Link Status 6395779Sxy150489 * Change or Rx Sequence Error interrupt. 6405779Sxy150489 */ 6415779Sxy150489 if (!mac->get_link_status) { 6425779Sxy150489 ret_val = E1000_SUCCESS; 6435779Sxy150489 goto out; 6445779Sxy150489 } 6455779Sxy150489 6465779Sxy150489 /* 6475779Sxy150489 * First we want to see if the MII Status Register reports 6485779Sxy150489 * link. If so, then we want to get the current speed/duplex 6495779Sxy150489 * of the PHY. 6505779Sxy150489 */ 6515779Sxy150489 ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link); 6525779Sxy150489 if (ret_val) 6535779Sxy150489 goto out; 6545779Sxy150489 6555779Sxy150489 if (!link) 6565779Sxy150489 goto out; /* No link detected */ 6575779Sxy150489 6588571SChenlu.Chen@Sun.COM mac->get_link_status = false; 6595779Sxy150489 6605779Sxy150489 /* 6615779Sxy150489 * Check if there was DownShift, must be checked 6625779Sxy150489 * immediately after link-up 6635779Sxy150489 */ 6645779Sxy150489 (void) e1000_check_downshift_generic(hw); 6655779Sxy150489 6665779Sxy150489 /* 6675779Sxy150489 * If we are forcing speed/duplex, then we simply return since 6685779Sxy150489 * we have already determined whether we have link or not. 6695779Sxy150489 */ 6705779Sxy150489 if (!mac->autoneg) { 6715779Sxy150489 ret_val = -E1000_ERR_CONFIG; 6725779Sxy150489 goto out; 6735779Sxy150489 } 6745779Sxy150489 6755779Sxy150489 /* 6765779Sxy150489 * Auto-Neg is enabled. Auto Speed Detection takes care 6775779Sxy150489 * of MAC speed/duplex configuration. So we only need to 6785779Sxy150489 * configure Collision Distance in the MAC. 6795779Sxy150489 */ 6805779Sxy150489 e1000_config_collision_dist_generic(hw); 6815779Sxy150489 6825779Sxy150489 /* 6835779Sxy150489 * Configure Flow Control now that Auto-Neg has completed. 6845779Sxy150489 * First, we need to restore the desired flow control 6855779Sxy150489 * settings because we may have had to re-autoneg with a 6865779Sxy150489 * different link partner. 6875779Sxy150489 */ 6885779Sxy150489 ret_val = e1000_config_fc_after_link_up_generic(hw); 6898571SChenlu.Chen@Sun.COM if (ret_val) 6905779Sxy150489 DEBUGOUT("Error configuring flow control\n"); 6915779Sxy150489 6925779Sxy150489 out: 6935779Sxy150489 return (ret_val); 6945779Sxy150489 } 6955779Sxy150489 6965779Sxy150489 /* 6975779Sxy150489 * e1000_check_for_fiber_link_generic - Check for link (Fiber) 6985779Sxy150489 * @hw: pointer to the HW structure 6995779Sxy150489 * 7005779Sxy150489 * Checks for link up on the hardware. If link is not up and we have 7015779Sxy150489 * a signal, then we need to force link up. 7025779Sxy150489 */ 7035779Sxy150489 s32 7045779Sxy150489 e1000_check_for_fiber_link_generic(struct e1000_hw *hw) 7055779Sxy150489 { 7065779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 7075779Sxy150489 u32 rxcw; 7085779Sxy150489 u32 ctrl; 7095779Sxy150489 u32 status; 7105779Sxy150489 s32 ret_val = E1000_SUCCESS; 7115779Sxy150489 7125779Sxy150489 DEBUGFUNC("e1000_check_for_fiber_link_generic"); 7135779Sxy150489 7145779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 7155779Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 7165779Sxy150489 rxcw = E1000_READ_REG(hw, E1000_RXCW); 7175779Sxy150489 7185779Sxy150489 /* 7195779Sxy150489 * If we don't have link (auto-negotiation failed or link partner 7205779Sxy150489 * cannot auto-negotiate), the cable is plugged in (we have signal), 7215779Sxy150489 * and our link partner is not trying to auto-negotiate with us (we 7225779Sxy150489 * are receiving idles or data), we need to force link up. We also 7235779Sxy150489 * need to give auto-negotiation time to complete, in case the cable 7245779Sxy150489 * was just plugged in. The autoneg_failed flag does this. 7255779Sxy150489 */ 7265779Sxy150489 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ 7275779Sxy150489 if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) && 7285779Sxy150489 (!(rxcw & E1000_RXCW_C))) { 7295779Sxy150489 if (mac->autoneg_failed == 0) { 7305779Sxy150489 mac->autoneg_failed = 1; 7315779Sxy150489 goto out; 7325779Sxy150489 } 7335779Sxy150489 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); 7345779Sxy150489 7355779Sxy150489 /* Disable auto-negotiation in the TXCW register */ 7365779Sxy150489 E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE)); 7375779Sxy150489 7385779Sxy150489 /* Force link-up and also force full-duplex. */ 7395779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 7405779Sxy150489 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); 7415779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 7425779Sxy150489 7435779Sxy150489 /* Configure Flow Control after forcing link up. */ 7445779Sxy150489 ret_val = e1000_config_fc_after_link_up_generic(hw); 7455779Sxy150489 if (ret_val) { 7465779Sxy150489 DEBUGOUT("Error configuring flow control\n"); 7475779Sxy150489 goto out; 7485779Sxy150489 } 7495779Sxy150489 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { 7505779Sxy150489 /* 7515779Sxy150489 * If we are forcing link and we are receiving /C/ ordered 7525779Sxy150489 * sets, re-enable auto-negotiation in the TXCW register 7535779Sxy150489 * and disable forced link in the Device Control register 7545779Sxy150489 * in an attempt to auto-negotiate with our link partner. 7555779Sxy150489 */ 7565779Sxy150489 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); 7575779Sxy150489 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw); 7585779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU)); 7595779Sxy150489 7608571SChenlu.Chen@Sun.COM mac->serdes_has_link = true; 7615779Sxy150489 } 7625779Sxy150489 7635779Sxy150489 out: 7645779Sxy150489 return (ret_val); 7655779Sxy150489 } 7665779Sxy150489 7675779Sxy150489 /* 7685779Sxy150489 * e1000_check_for_serdes_link_generic - Check for link (Serdes) 7695779Sxy150489 * @hw: pointer to the HW structure 7705779Sxy150489 * 7715779Sxy150489 * Checks for link up on the hardware. If link is not up and we have 7725779Sxy150489 * a signal, then we need to force link up. 7735779Sxy150489 */ 7745779Sxy150489 s32 7755779Sxy150489 e1000_check_for_serdes_link_generic(struct e1000_hw *hw) 7765779Sxy150489 { 7775779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 7785779Sxy150489 u32 rxcw; 7795779Sxy150489 u32 ctrl; 7805779Sxy150489 u32 status; 7815779Sxy150489 s32 ret_val = E1000_SUCCESS; 7825779Sxy150489 7835779Sxy150489 DEBUGFUNC("e1000_check_for_serdes_link_generic"); 7845779Sxy150489 7855779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 7865779Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 7875779Sxy150489 rxcw = E1000_READ_REG(hw, E1000_RXCW); 7885779Sxy150489 7895779Sxy150489 /* 7905779Sxy150489 * If we don't have link (auto-negotiation failed or link partner 7915779Sxy150489 * cannot auto-negotiate), and our link partner is not trying to 7925779Sxy150489 * auto-negotiate with us (we are receiving idles or data), 7935779Sxy150489 * we need to force link up. We also need to give auto-negotiation 7945779Sxy150489 * time to complete. 7955779Sxy150489 */ 7965779Sxy150489 /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ 7975779Sxy150489 if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { 7985779Sxy150489 if (mac->autoneg_failed == 0) { 7995779Sxy150489 mac->autoneg_failed = 1; 8005779Sxy150489 goto out; 8015779Sxy150489 } 8025779Sxy150489 DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n"); 8035779Sxy150489 8045779Sxy150489 /* Disable auto-negotiation in the TXCW register */ 8055779Sxy150489 E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE)); 8065779Sxy150489 8075779Sxy150489 /* Force link-up and also force full-duplex. */ 8085779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 8095779Sxy150489 ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD); 8105779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 8115779Sxy150489 8125779Sxy150489 /* Configure Flow Control after forcing link up. */ 8135779Sxy150489 ret_val = e1000_config_fc_after_link_up_generic(hw); 8145779Sxy150489 if (ret_val) { 8155779Sxy150489 DEBUGOUT("Error configuring flow control\n"); 8165779Sxy150489 goto out; 8175779Sxy150489 } 8185779Sxy150489 } else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { 8195779Sxy150489 /* 8205779Sxy150489 * If we are forcing link and we are receiving /C/ ordered 8215779Sxy150489 * sets, re-enable auto-negotiation in the TXCW register 8225779Sxy150489 * and disable forced link in the Device Control register 8235779Sxy150489 * in an attempt to auto-negotiate with our link partner. 8245779Sxy150489 */ 8255779Sxy150489 DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n"); 8265779Sxy150489 E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw); 8275779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU)); 8285779Sxy150489 8298571SChenlu.Chen@Sun.COM mac->serdes_has_link = true; 8305779Sxy150489 } else if (!(E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW))) { 8315779Sxy150489 /* 8325779Sxy150489 * If we force link for non-auto-negotiation switch, check 8335779Sxy150489 * link status based on MAC synchronization for internal 8345779Sxy150489 * serdes media type. 8355779Sxy150489 */ 8365779Sxy150489 /* SYNCH bit and IV bit are sticky. */ 8375779Sxy150489 usec_delay(10); 8388571SChenlu.Chen@Sun.COM rxcw = E1000_READ_REG(hw, E1000_RXCW); 8398571SChenlu.Chen@Sun.COM if (rxcw & E1000_RXCW_SYNCH) { 8405779Sxy150489 if (!(rxcw & E1000_RXCW_IV)) { 8418571SChenlu.Chen@Sun.COM mac->serdes_has_link = true; 8428571SChenlu.Chen@Sun.COM DEBUGOUT("SERDES: Link up - forced.\n"); 8435779Sxy150489 } 8445779Sxy150489 } else { 8458571SChenlu.Chen@Sun.COM mac->serdes_has_link = false; 8468571SChenlu.Chen@Sun.COM DEBUGOUT("SERDES: Link down - force failed.\n"); 8475779Sxy150489 } 8485779Sxy150489 } 8495779Sxy150489 8505779Sxy150489 if (E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW)) { 8515779Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 8528571SChenlu.Chen@Sun.COM if (status & E1000_STATUS_LU) { 8538571SChenlu.Chen@Sun.COM /* SYNCH bit and IV bit are sticky, so reread rxcw. */ 8548571SChenlu.Chen@Sun.COM usec_delay(10); 8558571SChenlu.Chen@Sun.COM rxcw = E1000_READ_REG(hw, E1000_RXCW); 8568571SChenlu.Chen@Sun.COM if (rxcw & E1000_RXCW_SYNCH) { 8578571SChenlu.Chen@Sun.COM if (!(rxcw & E1000_RXCW_IV)) { 8588571SChenlu.Chen@Sun.COM mac->serdes_has_link = true; 8598571SChenlu.Chen@Sun.COM DEBUGOUT("SERDES: Link up - autoneg " 8608571SChenlu.Chen@Sun.COM "completed sucessfully.\n"); 8618571SChenlu.Chen@Sun.COM } else { 8628571SChenlu.Chen@Sun.COM mac->serdes_has_link = false; 8638571SChenlu.Chen@Sun.COM DEBUGOUT("SERDES: Link down - invalid" 8648571SChenlu.Chen@Sun.COM "codewords detected in autoneg.\n"); 8658571SChenlu.Chen@Sun.COM } 8668571SChenlu.Chen@Sun.COM } else { 8678571SChenlu.Chen@Sun.COM mac->serdes_has_link = false; 8688571SChenlu.Chen@Sun.COM DEBUGOUT("SERDES: Link down - no sync.\n"); 8698571SChenlu.Chen@Sun.COM } 8708571SChenlu.Chen@Sun.COM } else { 8718571SChenlu.Chen@Sun.COM mac->serdes_has_link = false; 8728571SChenlu.Chen@Sun.COM DEBUGOUT("SERDES: Link down - autoneg failed\n"); 8738571SChenlu.Chen@Sun.COM } 8745779Sxy150489 } 8755779Sxy150489 8765779Sxy150489 out: 8775779Sxy150489 return (ret_val); 8785779Sxy150489 } 8795779Sxy150489 8805779Sxy150489 /* 8815779Sxy150489 * e1000_setup_link_generic - Setup flow control and link settings 8825779Sxy150489 * @hw: pointer to the HW structure 8835779Sxy150489 * 8845779Sxy150489 * Determines which flow control settings to use, then configures flow 8855779Sxy150489 * control. Calls the appropriate media-specific link configuration 8865779Sxy150489 * function. Assuming the adapter has a valid link partner, a valid link 8875779Sxy150489 * should be established. Assumes the hardware has previously been reset 8885779Sxy150489 * and the transmitter and receiver are not enabled. 8895779Sxy150489 */ 8905779Sxy150489 s32 8915779Sxy150489 e1000_setup_link_generic(struct e1000_hw *hw) 8925779Sxy150489 { 8935779Sxy150489 s32 ret_val = E1000_SUCCESS; 8945779Sxy150489 8955779Sxy150489 DEBUGFUNC("e1000_setup_link_generic"); 8965779Sxy150489 8975779Sxy150489 /* 8985779Sxy150489 * In the case of the phy reset being blocked, we already have a link. 8995779Sxy150489 * We do not need to set it up again. 9005779Sxy150489 */ 9018571SChenlu.Chen@Sun.COM if (hw->phy.ops.check_reset_block) 9028571SChenlu.Chen@Sun.COM if (hw->phy.ops.check_reset_block(hw)) 9038571SChenlu.Chen@Sun.COM goto out; 9045779Sxy150489 9055779Sxy150489 /* 9068571SChenlu.Chen@Sun.COM * If requested flow control is set to default, set flow control 9078571SChenlu.Chen@Sun.COM * based on the EEPROM flow control settings. 9085779Sxy150489 */ 9098571SChenlu.Chen@Sun.COM if (hw->fc.requested_mode == e1000_fc_default) { 9105779Sxy150489 ret_val = e1000_set_default_fc_generic(hw); 9115779Sxy150489 if (ret_val) 9125779Sxy150489 goto out; 9135779Sxy150489 } 9145779Sxy150489 9155779Sxy150489 /* 9168571SChenlu.Chen@Sun.COM * Save off the requested flow control mode for use later. Depending 9178571SChenlu.Chen@Sun.COM * on the link partner's capabilities, we may or may not use this mode. 9185779Sxy150489 */ 9198571SChenlu.Chen@Sun.COM hw->fc.current_mode = hw->fc.requested_mode; 9205779Sxy150489 9218571SChenlu.Chen@Sun.COM DEBUGOUT1("After fix-ups FlowControl is now = %x\n", 9228571SChenlu.Chen@Sun.COM hw->fc.current_mode); 9235779Sxy150489 9245779Sxy150489 /* Call the necessary media_type subroutine to configure the link. */ 9258571SChenlu.Chen@Sun.COM ret_val = hw->mac.ops.setup_physical_interface(hw); 9265779Sxy150489 if (ret_val) 9275779Sxy150489 goto out; 9285779Sxy150489 9295779Sxy150489 /* 9305779Sxy150489 * Initialize the flow control address, type, and PAUSE timer 9315779Sxy150489 * registers to their default values. This is done even if flow 9325779Sxy150489 * control is disabled, because it does not hurt anything to 9335779Sxy150489 * initialize these registers. 9345779Sxy150489 */ 9355779Sxy150489 DEBUGOUT("Initializing the Flow Control address,type and timer regs\n"); 9365779Sxy150489 E1000_WRITE_REG(hw, E1000_FCT, FLOW_CONTROL_TYPE); 9375779Sxy150489 E1000_WRITE_REG(hw, E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH); 9385779Sxy150489 E1000_WRITE_REG(hw, E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW); 9395779Sxy150489 9405779Sxy150489 E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time); 9415779Sxy150489 9425779Sxy150489 ret_val = e1000_set_fc_watermarks_generic(hw); 9435779Sxy150489 9445779Sxy150489 out: 9455779Sxy150489 return (ret_val); 9465779Sxy150489 } 9475779Sxy150489 9485779Sxy150489 /* 9495779Sxy150489 * e1000_setup_fiber_serdes_link_generic - Setup link for fiber/serdes 9505779Sxy150489 * @hw: pointer to the HW structure 9515779Sxy150489 * 9525779Sxy150489 * Configures collision distance and flow control for fiber and serdes 9535779Sxy150489 * links. Upon successful setup, poll for link. 9545779Sxy150489 */ 9555779Sxy150489 s32 9565779Sxy150489 e1000_setup_fiber_serdes_link_generic(struct e1000_hw *hw) 9575779Sxy150489 { 9585779Sxy150489 u32 ctrl; 9595779Sxy150489 s32 ret_val = E1000_SUCCESS; 9605779Sxy150489 9615779Sxy150489 DEBUGFUNC("e1000_setup_fiber_serdes_link_generic"); 9625779Sxy150489 9635779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 9645779Sxy150489 9655779Sxy150489 /* Take the link out of reset */ 9665779Sxy150489 ctrl &= ~E1000_CTRL_LRST; 9675779Sxy150489 9685779Sxy150489 e1000_config_collision_dist_generic(hw); 9695779Sxy150489 9705779Sxy150489 ret_val = e1000_commit_fc_settings_generic(hw); 9715779Sxy150489 if (ret_val) 9725779Sxy150489 goto out; 9735779Sxy150489 9745779Sxy150489 /* 9755779Sxy150489 * Since auto-negotiation is enabled, take the link out of reset (the 9765779Sxy150489 * link will be in reset, because we previously reset the chip). This 9775779Sxy150489 * will restart auto-negotiation. If auto-negotiation is successful 9785779Sxy150489 * then the link-up status bit will be set and the flow control enable 9795779Sxy150489 * bits (RFCE and TFCE) will be set according to their negotiated value. 9805779Sxy150489 */ 9815779Sxy150489 DEBUGOUT("Auto-negotiation enabled\n"); 9825779Sxy150489 9835779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 9845779Sxy150489 E1000_WRITE_FLUSH(hw); 9855779Sxy150489 msec_delay(1); 9865779Sxy150489 9875779Sxy150489 /* 9888571SChenlu.Chen@Sun.COM * For these adapters, the SW definable pin 1 is set when the optics 9895779Sxy150489 * detect a signal. If we have a signal, then poll for a "Link-Up" 9905779Sxy150489 * indication. 9915779Sxy150489 */ 9925779Sxy150489 if (hw->phy.media_type == e1000_media_type_internal_serdes || 9935779Sxy150489 (E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) { 9945779Sxy150489 ret_val = e1000_poll_fiber_serdes_link_generic(hw); 9955779Sxy150489 } else { 9965779Sxy150489 DEBUGOUT("No signal detected\n"); 9975779Sxy150489 } 9985779Sxy150489 9995779Sxy150489 out: 10005779Sxy150489 return (ret_val); 10015779Sxy150489 } 10025779Sxy150489 10035779Sxy150489 /* 10045779Sxy150489 * e1000_config_collision_dist_generic - Configure collision distance 10055779Sxy150489 * @hw: pointer to the HW structure 10065779Sxy150489 * 10075779Sxy150489 * Configures the collision distance to the default value and is used 10085779Sxy150489 * during link setup. Currently no func pointer exists and all 10095779Sxy150489 * implementations are handled in the generic version of this function. 10105779Sxy150489 */ 10115779Sxy150489 void 10125779Sxy150489 e1000_config_collision_dist_generic(struct e1000_hw *hw) 10135779Sxy150489 { 10145779Sxy150489 u32 tctl; 10155779Sxy150489 10165779Sxy150489 DEBUGFUNC("e1000_config_collision_dist_generic"); 10175779Sxy150489 10185779Sxy150489 tctl = E1000_READ_REG(hw, E1000_TCTL); 10195779Sxy150489 10205779Sxy150489 tctl &= ~E1000_TCTL_COLD; 10215779Sxy150489 tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT; 10225779Sxy150489 10235779Sxy150489 E1000_WRITE_REG(hw, E1000_TCTL, tctl); 10245779Sxy150489 E1000_WRITE_FLUSH(hw); 10255779Sxy150489 } 10265779Sxy150489 10275779Sxy150489 /* 10285779Sxy150489 * e1000_poll_fiber_serdes_link_generic - Poll for link up 10295779Sxy150489 * @hw: pointer to the HW structure 10305779Sxy150489 * 10315779Sxy150489 * Polls for link up by reading the status register, if link fails to come 10325779Sxy150489 * up with auto-negotiation, then the link is forced if a signal is detected. 10335779Sxy150489 */ 10345779Sxy150489 s32 10355779Sxy150489 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw) 10365779Sxy150489 { 10375779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 10385779Sxy150489 u32 i, status; 10395779Sxy150489 s32 ret_val = E1000_SUCCESS; 10405779Sxy150489 10415779Sxy150489 DEBUGFUNC("e1000_poll_fiber_serdes_link_generic"); 10425779Sxy150489 10435779Sxy150489 /* 10445779Sxy150489 * If we have a signal (the cable is plugged in, or assumed true for 10455779Sxy150489 * serdes media) then poll for a "Link-Up" indication in the Device 10465779Sxy150489 * Status Register. Time-out if a link isn't seen in 500 milliseconds 10475779Sxy150489 * seconds (Auto-negotiation should complete in less than 500 10485779Sxy150489 * milliseconds even if the other end is doing it in SW). 10495779Sxy150489 */ 10505779Sxy150489 for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) { 10515779Sxy150489 msec_delay(10); 10525779Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 10535779Sxy150489 if (status & E1000_STATUS_LU) 10545779Sxy150489 break; 10555779Sxy150489 } 10565779Sxy150489 if (i == FIBER_LINK_UP_LIMIT) { 10575779Sxy150489 DEBUGOUT("Never got a valid link from auto-neg!!!\n"); 10585779Sxy150489 mac->autoneg_failed = 1; 10595779Sxy150489 /* 10605779Sxy150489 * AutoNeg failed to achieve a link, so we'll call 10615779Sxy150489 * mac->check_for_link. This routine will force the 10625779Sxy150489 * link up if we detect a signal. This will allow us to 10635779Sxy150489 * communicate with non-autonegotiating link partners. 10645779Sxy150489 */ 10658571SChenlu.Chen@Sun.COM ret_val = hw->mac.ops.check_for_link(hw); 10665779Sxy150489 if (ret_val) { 10675779Sxy150489 DEBUGOUT("Error while checking for link\n"); 10685779Sxy150489 goto out; 10695779Sxy150489 } 10705779Sxy150489 mac->autoneg_failed = 0; 10715779Sxy150489 } else { 10725779Sxy150489 mac->autoneg_failed = 0; 10735779Sxy150489 DEBUGOUT("Valid Link Found\n"); 10745779Sxy150489 } 10755779Sxy150489 10765779Sxy150489 out: 10775779Sxy150489 return (ret_val); 10785779Sxy150489 } 10795779Sxy150489 10805779Sxy150489 /* 10815779Sxy150489 * e1000_commit_fc_settings_generic - Configure flow control 10825779Sxy150489 * @hw: pointer to the HW structure 10835779Sxy150489 * 10845779Sxy150489 * Write the flow control settings to the Transmit Config Word Register (TXCW) 10855779Sxy150489 * base on the flow control settings in e1000_mac_info. 10865779Sxy150489 */ 10875779Sxy150489 s32 10885779Sxy150489 e1000_commit_fc_settings_generic(struct e1000_hw *hw) 10895779Sxy150489 { 10905779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 10915779Sxy150489 u32 txcw; 10925779Sxy150489 s32 ret_val = E1000_SUCCESS; 10935779Sxy150489 10945779Sxy150489 DEBUGFUNC("e1000_commit_fc_settings_generic"); 10955779Sxy150489 10965779Sxy150489 /* 10975779Sxy150489 * Check for a software override of the flow control settings, and 10985779Sxy150489 * setup the device accordingly. If auto-negotiation is enabled, then 10995779Sxy150489 * software will have to set the "PAUSE" bits to the correct value in 11005779Sxy150489 * the Transmit Config Word Register (TXCW) and re-start auto- 11015779Sxy150489 * negotiation. However, if auto-negotiation is disabled, then 11025779Sxy150489 * software will have to manually configure the two flow control enable 11035779Sxy150489 * bits in the CTRL register. 11045779Sxy150489 * 11055779Sxy150489 * The possible values of the "fc" parameter are: 11065779Sxy150489 * 0: Flow control is completely disabled 11075779Sxy150489 * 1: Rx flow control is enabled (we can receive pause frames, 11085779Sxy150489 * but not send pause frames). 11095779Sxy150489 * 2: Tx flow control is enabled (we can send pause frames but we 11105779Sxy150489 * do not support receiving pause frames). 11115779Sxy150489 * 3: Both Rx and Tx flow control (symmetric) are enabled. 11125779Sxy150489 */ 11138571SChenlu.Chen@Sun.COM switch (hw->fc.current_mode) { 11145779Sxy150489 case e1000_fc_none: 11155779Sxy150489 /* Flow control completely disabled by a software over-ride. */ 11165779Sxy150489 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); 11175779Sxy150489 break; 11185779Sxy150489 case e1000_fc_rx_pause: 11195779Sxy150489 /* 11205779Sxy150489 * Rx Flow control is enabled and Tx Flow control is disabled 11215779Sxy150489 * by a software over-ride. Since there really isn't a way to 11225779Sxy150489 * advertise that we are capable of Rx Pause ONLY, we will 11235779Sxy150489 * advertise that we support both symmetric and asymmetric RX 11245779Sxy150489 * PAUSE. Later, we will disable the adapter's ability to send 11255779Sxy150489 * PAUSE frames. 11265779Sxy150489 */ 11275779Sxy150489 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); 11285779Sxy150489 break; 11295779Sxy150489 case e1000_fc_tx_pause: 11305779Sxy150489 /* 11315779Sxy150489 * Tx Flow control is enabled, and Rx Flow control is disabled, 11325779Sxy150489 * by a software over-ride. 11335779Sxy150489 */ 11345779Sxy150489 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); 11355779Sxy150489 break; 11365779Sxy150489 case e1000_fc_full: 11375779Sxy150489 /* 11385779Sxy150489 * Flow control (both Rx and Tx) is enabled by a software 11395779Sxy150489 * over-ride. 11405779Sxy150489 */ 11415779Sxy150489 txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); 11425779Sxy150489 break; 11435779Sxy150489 default: 11445779Sxy150489 DEBUGOUT("Flow control param set incorrectly\n"); 11455779Sxy150489 ret_val = -E1000_ERR_CONFIG; 11465779Sxy150489 goto out; 11475779Sxy150489 } 11485779Sxy150489 11495779Sxy150489 E1000_WRITE_REG(hw, E1000_TXCW, txcw); 11505779Sxy150489 mac->txcw = txcw; 11515779Sxy150489 11525779Sxy150489 out: 11535779Sxy150489 return (ret_val); 11545779Sxy150489 } 11555779Sxy150489 11565779Sxy150489 /* 11575779Sxy150489 * e1000_set_fc_watermarks_generic - Set flow control high/low watermarks 11585779Sxy150489 * @hw: pointer to the HW structure 11595779Sxy150489 * 11605779Sxy150489 * Sets the flow control high/low threshold (watermark) registers. If 11615779Sxy150489 * flow control XON frame transmission is enabled, then set XON frame 11628571SChenlu.Chen@Sun.COM * transmission as well. 11635779Sxy150489 */ 11645779Sxy150489 s32 11655779Sxy150489 e1000_set_fc_watermarks_generic(struct e1000_hw *hw) 11665779Sxy150489 { 11675779Sxy150489 s32 ret_val = E1000_SUCCESS; 11685779Sxy150489 u32 fcrtl = 0, fcrth = 0; 11695779Sxy150489 11705779Sxy150489 DEBUGFUNC("e1000_set_fc_watermarks_generic"); 11715779Sxy150489 11725779Sxy150489 /* 11735779Sxy150489 * Set the flow control receive threshold registers. Normally, 11745779Sxy150489 * these registers will be set to a default threshold that may be 11755779Sxy150489 * adjusted later by the driver's runtime code. However, if the 11765779Sxy150489 * ability to transmit pause frames is not enabled, then these 11775779Sxy150489 * registers will be set to 0. 11785779Sxy150489 */ 11798571SChenlu.Chen@Sun.COM if (hw->fc.current_mode & e1000_fc_tx_pause) { 11805779Sxy150489 /* 11815779Sxy150489 * We need to set up the Receive Threshold high and low water 11825779Sxy150489 * marks as well as (optionally) enabling the transmission of 11835779Sxy150489 * XON frames. 11845779Sxy150489 */ 11855779Sxy150489 fcrtl = hw->fc.low_water; 11865779Sxy150489 if (hw->fc.send_xon) 11875779Sxy150489 fcrtl |= E1000_FCRTL_XONE; 11885779Sxy150489 11895779Sxy150489 fcrth = hw->fc.high_water; 11905779Sxy150489 } 11915779Sxy150489 E1000_WRITE_REG(hw, E1000_FCRTL, fcrtl); 11925779Sxy150489 E1000_WRITE_REG(hw, E1000_FCRTH, fcrth); 11935779Sxy150489 11945779Sxy150489 return (ret_val); 11955779Sxy150489 } 11965779Sxy150489 11975779Sxy150489 /* 11985779Sxy150489 * e1000_set_default_fc_generic - Set flow control default values 11995779Sxy150489 * @hw: pointer to the HW structure 12005779Sxy150489 * 12015779Sxy150489 * Read the EEPROM for the default values for flow control and store the 12025779Sxy150489 * values. 12035779Sxy150489 */ 12045779Sxy150489 s32 12055779Sxy150489 e1000_set_default_fc_generic(struct e1000_hw *hw) 12065779Sxy150489 { 12075779Sxy150489 s32 ret_val = E1000_SUCCESS; 12085779Sxy150489 u16 nvm_data; 12095779Sxy150489 12105779Sxy150489 DEBUGFUNC("e1000_set_default_fc_generic"); 12115779Sxy150489 12125779Sxy150489 /* 12135779Sxy150489 * Read and store word 0x0F of the EEPROM. This word contains bits 12145779Sxy150489 * that determine the hardware's default PAUSE (flow control) mode, 12155779Sxy150489 * a bit that determines whether the HW defaults to enabling or 12165779Sxy150489 * disabling auto-negotiation, and the direction of the 12175779Sxy150489 * SW defined pins. If there is no SW over-ride of the flow 12185779Sxy150489 * control setting, then the variable hw->fc will 12195779Sxy150489 * be initialized based on a value in the EEPROM. 12205779Sxy150489 */ 12218571SChenlu.Chen@Sun.COM ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data); 12225779Sxy150489 12235779Sxy150489 if (ret_val) { 12245779Sxy150489 DEBUGOUT("NVM Read Error\n"); 12255779Sxy150489 goto out; 12265779Sxy150489 } 12275779Sxy150489 12285779Sxy150489 if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0) 12298571SChenlu.Chen@Sun.COM hw->fc.requested_mode = e1000_fc_none; 12305779Sxy150489 else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 12315779Sxy150489 NVM_WORD0F_ASM_DIR) 12328571SChenlu.Chen@Sun.COM hw->fc.requested_mode = e1000_fc_tx_pause; 12335779Sxy150489 else 12348571SChenlu.Chen@Sun.COM hw->fc.requested_mode = e1000_fc_full; 12355779Sxy150489 12365779Sxy150489 out: 12375779Sxy150489 return (ret_val); 12385779Sxy150489 } 12395779Sxy150489 12405779Sxy150489 /* 12415779Sxy150489 * e1000_force_mac_fc_generic - Force the MAC's flow control settings 12425779Sxy150489 * @hw: pointer to the HW structure 12435779Sxy150489 * 12445779Sxy150489 * Force the MAC's flow control settings. Sets the TFCE and RFCE bits in the 12455779Sxy150489 * device control register to reflect the adapter settings. TFCE and RFCE 12465779Sxy150489 * need to be explicitly set by software when a copper PHY is used because 12475779Sxy150489 * autonegotiation is managed by the PHY rather than the MAC. Software must 12485779Sxy150489 * also configure these bits when link is forced on a fiber connection. 12495779Sxy150489 */ 12505779Sxy150489 s32 12515779Sxy150489 e1000_force_mac_fc_generic(struct e1000_hw *hw) 12525779Sxy150489 { 12535779Sxy150489 u32 ctrl; 12545779Sxy150489 s32 ret_val = E1000_SUCCESS; 12555779Sxy150489 12565779Sxy150489 DEBUGFUNC("e1000_force_mac_fc_generic"); 12575779Sxy150489 12585779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 12595779Sxy150489 12605779Sxy150489 /* 12615779Sxy150489 * Because we didn't get link via the internal auto-negotiation 12625779Sxy150489 * mechanism (we either forced link or we got link via PHY 12635779Sxy150489 * auto-neg), we have to manually enable/disable transmit an 12645779Sxy150489 * receive flow control. 12655779Sxy150489 * 12665779Sxy150489 * The "Case" statement below enables/disable flow control 12678571SChenlu.Chen@Sun.COM * according to the "hw->fc.current_mode" parameter. 12685779Sxy150489 * 12695779Sxy150489 * The possible values of the "fc" parameter are: 12705779Sxy150489 * 0: Flow control is completely disabled 12715779Sxy150489 * 1: Rx flow control is enabled (we can receive pause 12725779Sxy150489 * frames but not send pause frames). 12735779Sxy150489 * 2: Tx flow control is enabled (we can send pause frames 12745779Sxy150489 * frames but we do not receive pause frames). 12755779Sxy150489 * 3: Both Rx and Tx flow control (symmetric) is enabled. 12765779Sxy150489 * other: No other values should be possible at this point. 12775779Sxy150489 */ 12788571SChenlu.Chen@Sun.COM DEBUGOUT1("hw->fc.current_mode = %u\n", hw->fc.current_mode); 12795779Sxy150489 12808571SChenlu.Chen@Sun.COM switch (hw->fc.current_mode) { 12815779Sxy150489 case e1000_fc_none: 12825779Sxy150489 ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); 12835779Sxy150489 break; 12845779Sxy150489 case e1000_fc_rx_pause: 12855779Sxy150489 ctrl &= (~E1000_CTRL_TFCE); 12865779Sxy150489 ctrl |= E1000_CTRL_RFCE; 12875779Sxy150489 break; 12885779Sxy150489 case e1000_fc_tx_pause: 12895779Sxy150489 ctrl &= (~E1000_CTRL_RFCE); 12905779Sxy150489 ctrl |= E1000_CTRL_TFCE; 12915779Sxy150489 break; 12925779Sxy150489 case e1000_fc_full: 12935779Sxy150489 ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); 12945779Sxy150489 break; 12955779Sxy150489 default: 12965779Sxy150489 DEBUGOUT("Flow control param set incorrectly\n"); 12975779Sxy150489 ret_val = -E1000_ERR_CONFIG; 12985779Sxy150489 goto out; 12995779Sxy150489 } 13005779Sxy150489 13015779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 13025779Sxy150489 13035779Sxy150489 out: 13045779Sxy150489 return (ret_val); 13055779Sxy150489 } 13065779Sxy150489 13075779Sxy150489 /* 13085779Sxy150489 * e1000_config_fc_after_link_up_generic - Configures flow control after link 13095779Sxy150489 * @hw: pointer to the HW structure 13105779Sxy150489 * 13115779Sxy150489 * Checks the status of auto-negotiation after link up to ensure that the 13125779Sxy150489 * speed and duplex were not forced. If the link needed to be forced, then 13135779Sxy150489 * flow control needs to be forced also. If auto-negotiation is enabled 13145779Sxy150489 * and did not fail, then we configure flow control based on our link 13155779Sxy150489 * partner. 13165779Sxy150489 */ 13175779Sxy150489 s32 13185779Sxy150489 e1000_config_fc_after_link_up_generic(struct e1000_hw *hw) 13195779Sxy150489 { 13205779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 13215779Sxy150489 s32 ret_val = E1000_SUCCESS; 13225779Sxy150489 u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg; 13235779Sxy150489 u16 speed, duplex; 13245779Sxy150489 13255779Sxy150489 DEBUGFUNC("e1000_config_fc_after_link_up_generic"); 13265779Sxy150489 13275779Sxy150489 /* 13285779Sxy150489 * Check for the case where we have fiber media and auto-neg failed 13295779Sxy150489 * so we had to force link. In this case, we need to force the 13305779Sxy150489 * configuration of the MAC to match the "fc" parameter. 13315779Sxy150489 */ 13325779Sxy150489 if (mac->autoneg_failed) { 13335779Sxy150489 if (hw->phy.media_type == e1000_media_type_fiber || 13345779Sxy150489 hw->phy.media_type == e1000_media_type_internal_serdes) 13355779Sxy150489 ret_val = e1000_force_mac_fc_generic(hw); 13365779Sxy150489 } else { 13375779Sxy150489 if (hw->phy.media_type == e1000_media_type_copper) 13385779Sxy150489 ret_val = e1000_force_mac_fc_generic(hw); 13395779Sxy150489 } 13405779Sxy150489 13415779Sxy150489 if (ret_val) { 13425779Sxy150489 DEBUGOUT("Error forcing flow control settings\n"); 13435779Sxy150489 goto out; 13445779Sxy150489 } 13455779Sxy150489 13465779Sxy150489 /* 13475779Sxy150489 * Check for the case where we have copper media and auto-neg is 13485779Sxy150489 * enabled. In this case, we need to check and see if Auto-Neg 13495779Sxy150489 * has completed, and if so, how the PHY and link partner has 13505779Sxy150489 * flow control configured. 13515779Sxy150489 */ 13525779Sxy150489 if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) { 13535779Sxy150489 /* 13545779Sxy150489 * Read the MII Status Register and check to see if AutoNeg 13555779Sxy150489 * has completed. We read this twice because this reg has 13565779Sxy150489 * some "sticky" (latched) bits. 13575779Sxy150489 */ 13588571SChenlu.Chen@Sun.COM ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg); 13595779Sxy150489 if (ret_val) 13605779Sxy150489 goto out; 13618571SChenlu.Chen@Sun.COM ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg); 13625779Sxy150489 if (ret_val) 13635779Sxy150489 goto out; 13645779Sxy150489 13655779Sxy150489 if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) { 13665779Sxy150489 DEBUGOUT("Copper PHY and Auto Neg " 13675779Sxy150489 "has not completed.\n"); 13685779Sxy150489 goto out; 13695779Sxy150489 } 13705779Sxy150489 13715779Sxy150489 /* 13725779Sxy150489 * The AutoNeg process has completed, so we now need to 13735779Sxy150489 * read both the Auto Negotiation Advertisement 13745779Sxy150489 * Register (Address 4) and the Auto_Negotiation Base 13755779Sxy150489 * Page Ability Register (Address 5) to determine how 13765779Sxy150489 * flow control was negotiated. 13775779Sxy150489 */ 13788571SChenlu.Chen@Sun.COM ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV, 13795779Sxy150489 &mii_nway_adv_reg); 13805779Sxy150489 if (ret_val) 13815779Sxy150489 goto out; 13828571SChenlu.Chen@Sun.COM ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY, 13835779Sxy150489 &mii_nway_lp_ability_reg); 13845779Sxy150489 if (ret_val) 13855779Sxy150489 goto out; 13865779Sxy150489 13875779Sxy150489 /* 13885779Sxy150489 * Two bits in the Auto Negotiation Advertisement Register 13895779Sxy150489 * (Address 4) and two bits in the Auto Negotiation Base 13905779Sxy150489 * Page Ability Register (Address 5) determine flow control 13915779Sxy150489 * for both the PHY and the link partner. The following 13925779Sxy150489 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25, 13935779Sxy150489 * 1999, describes these PAUSE resolution bits and how flow 13945779Sxy150489 * control is determined based upon these settings. 13955779Sxy150489 * NOTE: DC = Don't Care 13965779Sxy150489 * 13975779Sxy150489 * LOCAL DEVICE | LINK PARTNER 13985779Sxy150489 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution 13995779Sxy150489 * ------|---------|-------|---------|-------------------- 14005779Sxy150489 * 0 | 0 | DC | DC | e1000_fc_none 14015779Sxy150489 * 0 | 1 | 0 | DC | e1000_fc_none 14025779Sxy150489 * 0 | 1 | 1 | 0 | e1000_fc_none 14035779Sxy150489 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 14045779Sxy150489 * 1 | 0 | 0 | DC | e1000_fc_none 14055779Sxy150489 * 1 | DC | 1 | DC | e1000_fc_full 14065779Sxy150489 * 1 | 1 | 0 | 0 | e1000_fc_none 14075779Sxy150489 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 14085779Sxy150489 * 14095779Sxy150489 * Are both PAUSE bits set to 1? If so, this implies 14105779Sxy150489 * Symmetric Flow Control is enabled at both ends. The 14115779Sxy150489 * ASM_DIR bits are irrelevant per the spec. 14125779Sxy150489 * 14135779Sxy150489 * For Symmetric Flow Control: 14145779Sxy150489 * 14155779Sxy150489 * LOCAL DEVICE | LINK PARTNER 14165779Sxy150489 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 14175779Sxy150489 * ------|---------|-------|---------|-------------------- 14185779Sxy150489 * 1 | DC | 1 | DC | E1000_fc_full 14195779Sxy150489 * 14205779Sxy150489 */ 14215779Sxy150489 if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && 14225779Sxy150489 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { 14235779Sxy150489 /* 14245779Sxy150489 * Now we need to check if the user selected Rx ONLY 14255779Sxy150489 * of pause frames. In this case, we had to advertise 14265779Sxy150489 * FULL flow control because we could not advertise RX 14275779Sxy150489 * ONLY. Hence, we must now check to see if we need to 14285779Sxy150489 * turn OFF the TRANSMISSION of PAUSE frames. 14295779Sxy150489 */ 14308571SChenlu.Chen@Sun.COM if (hw->fc.requested_mode == e1000_fc_full) { 14318571SChenlu.Chen@Sun.COM hw->fc.current_mode = e1000_fc_full; 14325779Sxy150489 DEBUGOUT("Flow Control = FULL.\r\n"); 14335779Sxy150489 } else { 14348571SChenlu.Chen@Sun.COM hw->fc.current_mode = e1000_fc_rx_pause; 14355779Sxy150489 DEBUGOUT("Flow Control = " 14365779Sxy150489 "RX PAUSE frames only.\r\n"); 14375779Sxy150489 } 14385779Sxy150489 } 14395779Sxy150489 /* 14405779Sxy150489 * For receiving PAUSE frames ONLY. 14415779Sxy150489 * 14425779Sxy150489 * LOCAL DEVICE | LINK PARTNER 14435779Sxy150489 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 14445779Sxy150489 * ------|---------|-------|---------|-------------------- 14455779Sxy150489 * 0 | 1 | 1 | 1 | e1000_fc_tx_pause 14465779Sxy150489 */ 14475779Sxy150489 else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) && 14485779Sxy150489 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 14495779Sxy150489 (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 14505779Sxy150489 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 14518571SChenlu.Chen@Sun.COM hw->fc.current_mode = e1000_fc_tx_pause; 14525779Sxy150489 DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n"); 14535779Sxy150489 } 14545779Sxy150489 /* 14555779Sxy150489 * For transmitting PAUSE frames ONLY. 14565779Sxy150489 * 14575779Sxy150489 * LOCAL DEVICE | LINK PARTNER 14585779Sxy150489 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result 14595779Sxy150489 * ------|---------|-------|---------|-------------------- 14605779Sxy150489 * 1 | 1 | 0 | 1 | e1000_fc_rx_pause 14615779Sxy150489 */ 14625779Sxy150489 else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) && 14635779Sxy150489 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) && 14645779Sxy150489 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) && 14655779Sxy150489 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) { 14668571SChenlu.Chen@Sun.COM hw->fc.current_mode = e1000_fc_rx_pause; 14675779Sxy150489 DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n"); 14685779Sxy150489 } else { 14695779Sxy150489 /* 14705779Sxy150489 * Per the IEEE spec, at this point flow control 14715779Sxy150489 * should be disabled. 14725779Sxy150489 */ 14738571SChenlu.Chen@Sun.COM hw->fc.current_mode = e1000_fc_none; 14745779Sxy150489 DEBUGOUT("Flow Control = NONE.\r\n"); 14755779Sxy150489 } 14765779Sxy150489 14775779Sxy150489 /* 14785779Sxy150489 * Now we need to do one last check... If we auto- 14795779Sxy150489 * negotiated to HALF DUPLEX, flow control should not be 14805779Sxy150489 * enabled per IEEE 802.3 spec. 14815779Sxy150489 */ 14828571SChenlu.Chen@Sun.COM ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex); 14835779Sxy150489 if (ret_val) { 14845779Sxy150489 DEBUGOUT("Error getting link speed and duplex\n"); 14855779Sxy150489 goto out; 14865779Sxy150489 } 14875779Sxy150489 14885779Sxy150489 if (duplex == HALF_DUPLEX) 14898571SChenlu.Chen@Sun.COM hw->fc.current_mode = e1000_fc_none; 14905779Sxy150489 14915779Sxy150489 /* 14925779Sxy150489 * Now we call a subroutine to actually force the MAC 14935779Sxy150489 * controller to use the correct flow control settings. 14945779Sxy150489 */ 14955779Sxy150489 ret_val = e1000_force_mac_fc_generic(hw); 14965779Sxy150489 if (ret_val) { 14975779Sxy150489 DEBUGOUT("Error forcing flow control settings\n"); 14985779Sxy150489 goto out; 14995779Sxy150489 } 15005779Sxy150489 } 15015779Sxy150489 15025779Sxy150489 out: 15035779Sxy150489 return (ret_val); 15045779Sxy150489 } 15055779Sxy150489 15065779Sxy150489 /* 15078571SChenlu.Chen@Sun.COM * e1000_get_speed_and_duplex_copper_generic - Retrieve current speed/duplex 15085779Sxy150489 * @hw: pointer to the HW structure 15095779Sxy150489 * @speed: stores the current speed 15105779Sxy150489 * @duplex: stores the current duplex 15115779Sxy150489 * 15125779Sxy150489 * Read the status register for the current speed/duplex and store the current 15135779Sxy150489 * speed and duplex for copper connections. 15145779Sxy150489 */ 15155779Sxy150489 s32 15165779Sxy150489 e1000_get_speed_and_duplex_copper_generic(struct e1000_hw *hw, u16 *speed, 15175779Sxy150489 u16 *duplex) 15185779Sxy150489 { 15195779Sxy150489 u32 status; 15205779Sxy150489 15215779Sxy150489 DEBUGFUNC("e1000_get_speed_and_duplex_copper_generic"); 15225779Sxy150489 15235779Sxy150489 status = E1000_READ_REG(hw, E1000_STATUS); 15245779Sxy150489 if (status & E1000_STATUS_SPEED_1000) { 15255779Sxy150489 *speed = SPEED_1000; 15265779Sxy150489 DEBUGOUT("1000 Mbs, "); 15275779Sxy150489 } else if (status & E1000_STATUS_SPEED_100) { 15285779Sxy150489 *speed = SPEED_100; 15295779Sxy150489 DEBUGOUT("100 Mbs, "); 15305779Sxy150489 } else { 15315779Sxy150489 *speed = SPEED_10; 15325779Sxy150489 DEBUGOUT("10 Mbs, "); 15335779Sxy150489 } 15345779Sxy150489 15355779Sxy150489 if (status & E1000_STATUS_FD) { 15365779Sxy150489 *duplex = FULL_DUPLEX; 15375779Sxy150489 DEBUGOUT("Full Duplex\n"); 15385779Sxy150489 } else { 15395779Sxy150489 *duplex = HALF_DUPLEX; 15405779Sxy150489 DEBUGOUT("Half Duplex\n"); 15415779Sxy150489 } 15425779Sxy150489 15435779Sxy150489 return (E1000_SUCCESS); 15445779Sxy150489 } 15455779Sxy150489 15465779Sxy150489 /* 15478571SChenlu.Chen@Sun.COM * e1000_get_speed_and_duplex_fiber_generic - Retrieve current speed/duplex 15485779Sxy150489 * @hw: pointer to the HW structure 15495779Sxy150489 * @speed: stores the current speed 15505779Sxy150489 * @duplex: stores the current duplex 15515779Sxy150489 * 15525779Sxy150489 * Sets the speed and duplex to gigabit full duplex (the only possible option) 15535779Sxy150489 * for fiber/serdes links. 15545779Sxy150489 */ 15555779Sxy150489 s32 15565779Sxy150489 e1000_get_speed_and_duplex_fiber_serdes_generic(struct e1000_hw *hw, 15575779Sxy150489 u16 *speed, u16 *duplex) 15585779Sxy150489 { 15595779Sxy150489 DEBUGFUNC("e1000_get_speed_and_duplex_fiber_serdes_generic"); 15608571SChenlu.Chen@Sun.COM UNREFERENCED_1PARAMETER(hw); 15615779Sxy150489 15625779Sxy150489 *speed = SPEED_1000; 15635779Sxy150489 *duplex = FULL_DUPLEX; 15645779Sxy150489 15655779Sxy150489 return (E1000_SUCCESS); 15665779Sxy150489 } 15675779Sxy150489 15685779Sxy150489 /* 15695779Sxy150489 * e1000_get_hw_semaphore_generic - Acquire hardware semaphore 15705779Sxy150489 * @hw: pointer to the HW structure 15715779Sxy150489 * 15725779Sxy150489 * Acquire the HW semaphore to access the PHY or NVM 15735779Sxy150489 */ 15745779Sxy150489 s32 15755779Sxy150489 e1000_get_hw_semaphore_generic(struct e1000_hw *hw) 15765779Sxy150489 { 15775779Sxy150489 u32 swsm; 15785779Sxy150489 s32 ret_val = E1000_SUCCESS; 15795779Sxy150489 s32 timeout = hw->nvm.word_size + 1; 15805779Sxy150489 s32 i = 0; 15815779Sxy150489 15825779Sxy150489 DEBUGFUNC("e1000_get_hw_semaphore_generic"); 15835779Sxy150489 15845779Sxy150489 /* Get the SW semaphore */ 15855779Sxy150489 while (i < timeout) { 15865779Sxy150489 swsm = E1000_READ_REG(hw, E1000_SWSM); 15875779Sxy150489 if (!(swsm & E1000_SWSM_SMBI)) 15885779Sxy150489 break; 15895779Sxy150489 15905779Sxy150489 usec_delay(50); 15915779Sxy150489 i++; 15925779Sxy150489 } 15935779Sxy150489 15945779Sxy150489 if (i == timeout) { 15955779Sxy150489 DEBUGOUT("Driver can't access device - SMBI bit is set.\n"); 15965779Sxy150489 ret_val = -E1000_ERR_NVM; 15975779Sxy150489 goto out; 15985779Sxy150489 } 15995779Sxy150489 16005779Sxy150489 /* Get the FW semaphore. */ 16015779Sxy150489 for (i = 0; i < timeout; i++) { 16025779Sxy150489 swsm = E1000_READ_REG(hw, E1000_SWSM); 16035779Sxy150489 E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_SWESMBI); 16045779Sxy150489 16055779Sxy150489 /* Semaphore acquired if bit latched */ 16065779Sxy150489 if (E1000_READ_REG(hw, E1000_SWSM) & E1000_SWSM_SWESMBI) 16075779Sxy150489 break; 16085779Sxy150489 16095779Sxy150489 usec_delay(50); 16105779Sxy150489 } 16115779Sxy150489 16125779Sxy150489 if (i == timeout) { 16135779Sxy150489 /* Release semaphores */ 16145779Sxy150489 e1000_put_hw_semaphore_generic(hw); 16155779Sxy150489 DEBUGOUT("Driver can't access the NVM\n"); 16165779Sxy150489 ret_val = -E1000_ERR_NVM; 16175779Sxy150489 goto out; 16185779Sxy150489 } 16195779Sxy150489 16205779Sxy150489 out: 16215779Sxy150489 return (ret_val); 16225779Sxy150489 } 16235779Sxy150489 16245779Sxy150489 /* 16255779Sxy150489 * e1000_put_hw_semaphore_generic - Release hardware semaphore 16265779Sxy150489 * @hw: pointer to the HW structure 16275779Sxy150489 * 16285779Sxy150489 * Release hardware semaphore used to access the PHY or NVM 16295779Sxy150489 */ 16305779Sxy150489 void 16315779Sxy150489 e1000_put_hw_semaphore_generic(struct e1000_hw *hw) 16325779Sxy150489 { 16335779Sxy150489 u32 swsm; 16345779Sxy150489 16355779Sxy150489 DEBUGFUNC("e1000_put_hw_semaphore_generic"); 16365779Sxy150489 16375779Sxy150489 swsm = E1000_READ_REG(hw, E1000_SWSM); 16385779Sxy150489 16395779Sxy150489 swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI); 16405779Sxy150489 16415779Sxy150489 E1000_WRITE_REG(hw, E1000_SWSM, swsm); 16425779Sxy150489 } 16435779Sxy150489 16445779Sxy150489 /* 16455779Sxy150489 * e1000_get_auto_rd_done_generic - Check for auto read completion 16465779Sxy150489 * @hw: pointer to the HW structure 16475779Sxy150489 * 16485779Sxy150489 * Check EEPROM for Auto Read done bit. 16495779Sxy150489 */ 16505779Sxy150489 s32 16515779Sxy150489 e1000_get_auto_rd_done_generic(struct e1000_hw *hw) 16525779Sxy150489 { 16535779Sxy150489 s32 i = 0; 16545779Sxy150489 s32 ret_val = E1000_SUCCESS; 16555779Sxy150489 16565779Sxy150489 DEBUGFUNC("e1000_get_auto_rd_done_generic"); 16575779Sxy150489 16585779Sxy150489 while (i < AUTO_READ_DONE_TIMEOUT) { 16595779Sxy150489 if (E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_AUTO_RD) 16605779Sxy150489 break; 16615779Sxy150489 msec_delay(1); 16625779Sxy150489 i++; 16635779Sxy150489 } 16645779Sxy150489 16655779Sxy150489 if (i == AUTO_READ_DONE_TIMEOUT) { 16665779Sxy150489 DEBUGOUT("Auto read by HW from NVM has not completed.\n"); 16675779Sxy150489 ret_val = -E1000_ERR_RESET; 16685779Sxy150489 goto out; 16695779Sxy150489 } 16705779Sxy150489 16715779Sxy150489 out: 16725779Sxy150489 return (ret_val); 16735779Sxy150489 } 16745779Sxy150489 16755779Sxy150489 /* 16765779Sxy150489 * e1000_valid_led_default_generic - Verify a valid default LED config 16775779Sxy150489 * @hw: pointer to the HW structure 16785779Sxy150489 * @data: pointer to the NVM (EEPROM) 16795779Sxy150489 * 16805779Sxy150489 * Read the EEPROM for the current default LED configuration. If the 16815779Sxy150489 * LED configuration is not valid, set to a valid LED configuration. 16825779Sxy150489 */ 16835779Sxy150489 s32 16845779Sxy150489 e1000_valid_led_default_generic(struct e1000_hw *hw, u16 *data) 16855779Sxy150489 { 16865779Sxy150489 s32 ret_val; 16875779Sxy150489 16885779Sxy150489 DEBUGFUNC("e1000_valid_led_default_generic"); 16895779Sxy150489 16908571SChenlu.Chen@Sun.COM ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data); 16915779Sxy150489 if (ret_val) { 16925779Sxy150489 DEBUGOUT("NVM Read Error\n"); 16935779Sxy150489 goto out; 16945779Sxy150489 } 16955779Sxy150489 16965779Sxy150489 if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF) 16975779Sxy150489 *data = ID_LED_DEFAULT; 16985779Sxy150489 16995779Sxy150489 out: 17005779Sxy150489 return (ret_val); 17015779Sxy150489 } 17025779Sxy150489 17035779Sxy150489 /* 17045779Sxy150489 * e1000_id_led_init_generic - 17055779Sxy150489 * @hw: pointer to the HW structure 17065779Sxy150489 * 17075779Sxy150489 */ 17085779Sxy150489 s32 17095779Sxy150489 e1000_id_led_init_generic(struct e1000_hw *hw) 17105779Sxy150489 { 17115779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 17125779Sxy150489 s32 ret_val; 17135779Sxy150489 const u32 ledctl_mask = 0x000000FF; 17145779Sxy150489 const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON; 17155779Sxy150489 const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF; 17165779Sxy150489 u16 data, i, temp; 17175779Sxy150489 const u16 led_mask = 0x0F; 17185779Sxy150489 17195779Sxy150489 DEBUGFUNC("e1000_id_led_init_generic"); 17205779Sxy150489 17218571SChenlu.Chen@Sun.COM ret_val = hw->nvm.ops.valid_led_default(hw, &data); 17225779Sxy150489 if (ret_val) 17235779Sxy150489 goto out; 17245779Sxy150489 17255779Sxy150489 mac->ledctl_default = E1000_READ_REG(hw, E1000_LEDCTL); 17265779Sxy150489 mac->ledctl_mode1 = mac->ledctl_default; 17275779Sxy150489 mac->ledctl_mode2 = mac->ledctl_default; 17285779Sxy150489 17295779Sxy150489 for (i = 0; i < 4; i++) { 17305779Sxy150489 temp = (data >> (i << 2)) & led_mask; 17315779Sxy150489 switch (temp) { 17325779Sxy150489 case ID_LED_ON1_DEF2: 17335779Sxy150489 case ID_LED_ON1_ON2: 17345779Sxy150489 case ID_LED_ON1_OFF2: 17355779Sxy150489 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); 17365779Sxy150489 mac->ledctl_mode1 |= ledctl_on << (i << 3); 17375779Sxy150489 break; 17385779Sxy150489 case ID_LED_OFF1_DEF2: 17395779Sxy150489 case ID_LED_OFF1_ON2: 17405779Sxy150489 case ID_LED_OFF1_OFF2: 17415779Sxy150489 mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3)); 17425779Sxy150489 mac->ledctl_mode1 |= ledctl_off << (i << 3); 17435779Sxy150489 break; 17445779Sxy150489 default: 17455779Sxy150489 /* Do nothing */ 17465779Sxy150489 break; 17475779Sxy150489 } 17485779Sxy150489 switch (temp) { 17495779Sxy150489 case ID_LED_DEF1_ON2: 17505779Sxy150489 case ID_LED_ON1_ON2: 17515779Sxy150489 case ID_LED_OFF1_ON2: 17525779Sxy150489 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); 17535779Sxy150489 mac->ledctl_mode2 |= ledctl_on << (i << 3); 17545779Sxy150489 break; 17555779Sxy150489 case ID_LED_DEF1_OFF2: 17565779Sxy150489 case ID_LED_ON1_OFF2: 17575779Sxy150489 case ID_LED_OFF1_OFF2: 17585779Sxy150489 mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3)); 17595779Sxy150489 mac->ledctl_mode2 |= ledctl_off << (i << 3); 17605779Sxy150489 break; 17615779Sxy150489 default: 17625779Sxy150489 /* Do nothing */ 17635779Sxy150489 break; 17645779Sxy150489 } 17655779Sxy150489 } 17665779Sxy150489 17675779Sxy150489 out: 17685779Sxy150489 return (ret_val); 17695779Sxy150489 } 17705779Sxy150489 17715779Sxy150489 /* 17725779Sxy150489 * e1000_setup_led_generic - Configures SW controllable LED 17735779Sxy150489 * @hw: pointer to the HW structure 17745779Sxy150489 * 17755779Sxy150489 * This prepares the SW controllable LED for use and saves the current state 17765779Sxy150489 * of the LED so it can be later restored. 17775779Sxy150489 */ 17785779Sxy150489 s32 17795779Sxy150489 e1000_setup_led_generic(struct e1000_hw *hw) 17805779Sxy150489 { 17815779Sxy150489 u32 ledctl; 17825779Sxy150489 s32 ret_val = E1000_SUCCESS; 17835779Sxy150489 17845779Sxy150489 DEBUGFUNC("e1000_setup_led_generic"); 17855779Sxy150489 17868571SChenlu.Chen@Sun.COM if (hw->mac.ops.setup_led != e1000_setup_led_generic) { 17875779Sxy150489 ret_val = -E1000_ERR_CONFIG; 17885779Sxy150489 goto out; 17895779Sxy150489 } 17905779Sxy150489 17915779Sxy150489 if (hw->phy.media_type == e1000_media_type_fiber) { 17925779Sxy150489 ledctl = E1000_READ_REG(hw, E1000_LEDCTL); 17935779Sxy150489 hw->mac.ledctl_default = ledctl; 17945779Sxy150489 /* Turn off LED0 */ 17955779Sxy150489 ledctl &= ~(E1000_LEDCTL_LED0_IVRT | 17965779Sxy150489 E1000_LEDCTL_LED0_BLINK | 17975779Sxy150489 E1000_LEDCTL_LED0_MODE_MASK); 17985779Sxy150489 ledctl |= (E1000_LEDCTL_MODE_LED_OFF << 17995779Sxy150489 E1000_LEDCTL_LED0_MODE_SHIFT); 18005779Sxy150489 E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl); 18015779Sxy150489 } else if (hw->phy.media_type == e1000_media_type_copper) { 18025779Sxy150489 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1); 18035779Sxy150489 } 18045779Sxy150489 18055779Sxy150489 out: 18065779Sxy150489 return (ret_val); 18075779Sxy150489 } 18085779Sxy150489 18095779Sxy150489 /* 18105779Sxy150489 * e1000_cleanup_led_generic - Set LED config to default operation 18115779Sxy150489 * @hw: pointer to the HW structure 18125779Sxy150489 * 18135779Sxy150489 * Remove the current LED configuration and set the LED configuration 18145779Sxy150489 * to the default value, saved from the EEPROM. 18155779Sxy150489 */ 18165779Sxy150489 s32 18175779Sxy150489 e1000_cleanup_led_generic(struct e1000_hw *hw) 18185779Sxy150489 { 18195779Sxy150489 s32 ret_val = E1000_SUCCESS; 18205779Sxy150489 18215779Sxy150489 DEBUGFUNC("e1000_cleanup_led_generic"); 18225779Sxy150489 18238571SChenlu.Chen@Sun.COM if (hw->mac.ops.cleanup_led != e1000_cleanup_led_generic) { 18245779Sxy150489 ret_val = -E1000_ERR_CONFIG; 18255779Sxy150489 goto out; 18265779Sxy150489 } 18275779Sxy150489 18285779Sxy150489 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default); 18295779Sxy150489 18305779Sxy150489 out: 18315779Sxy150489 return (ret_val); 18325779Sxy150489 } 18335779Sxy150489 18345779Sxy150489 /* 18355779Sxy150489 * e1000_blink_led_generic - Blink LED 18365779Sxy150489 * @hw: pointer to the HW structure 18375779Sxy150489 * 18388571SChenlu.Chen@Sun.COM * Blink the LEDs which are set to be on. 18395779Sxy150489 */ 18405779Sxy150489 s32 18415779Sxy150489 e1000_blink_led_generic(struct e1000_hw *hw) 18425779Sxy150489 { 18435779Sxy150489 u32 ledctl_blink = 0; 18445779Sxy150489 u32 i; 18455779Sxy150489 18465779Sxy150489 DEBUGFUNC("e1000_blink_led_generic"); 18475779Sxy150489 18485779Sxy150489 if (hw->phy.media_type == e1000_media_type_fiber) { 18495779Sxy150489 /* always blink LED0 for PCI-E fiber */ 18505779Sxy150489 ledctl_blink = E1000_LEDCTL_LED0_BLINK | 18515779Sxy150489 (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT); 18525779Sxy150489 } else { 18535779Sxy150489 /* 18545779Sxy150489 * set the blink bit for each LED that's "on" (0x0E) 18555779Sxy150489 * in ledctl_mode2 18565779Sxy150489 */ 18575779Sxy150489 ledctl_blink = hw->mac.ledctl_mode2; 18585779Sxy150489 for (i = 0; i < 4; i++) 18595779Sxy150489 if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) == 18605779Sxy150489 E1000_LEDCTL_MODE_LED_ON) 18615779Sxy150489 ledctl_blink |= (E1000_LEDCTL_LED0_BLINK << 18625779Sxy150489 (i * 8)); 18635779Sxy150489 } 18645779Sxy150489 18655779Sxy150489 E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl_blink); 18665779Sxy150489 18675779Sxy150489 return (E1000_SUCCESS); 18685779Sxy150489 } 18695779Sxy150489 18705779Sxy150489 /* 18715779Sxy150489 * e1000_led_on_generic - Turn LED on 18725779Sxy150489 * @hw: pointer to the HW structure 18735779Sxy150489 * 18745779Sxy150489 * Turn LED on. 18755779Sxy150489 */ 18765779Sxy150489 s32 18775779Sxy150489 e1000_led_on_generic(struct e1000_hw *hw) 18785779Sxy150489 { 18795779Sxy150489 u32 ctrl; 18805779Sxy150489 18815779Sxy150489 DEBUGFUNC("e1000_led_on_generic"); 18825779Sxy150489 18835779Sxy150489 switch (hw->phy.media_type) { 18845779Sxy150489 case e1000_media_type_fiber: 18855779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 18865779Sxy150489 ctrl &= ~E1000_CTRL_SWDPIN0; 18875779Sxy150489 ctrl |= E1000_CTRL_SWDPIO0; 18885779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 18895779Sxy150489 break; 18905779Sxy150489 case e1000_media_type_copper: 18915779Sxy150489 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2); 18925779Sxy150489 break; 18935779Sxy150489 default: 18945779Sxy150489 break; 18955779Sxy150489 } 18965779Sxy150489 18975779Sxy150489 return (E1000_SUCCESS); 18985779Sxy150489 } 18995779Sxy150489 19005779Sxy150489 /* 19015779Sxy150489 * e1000_led_off_generic - Turn LED off 19025779Sxy150489 * @hw: pointer to the HW structure 19035779Sxy150489 * 19045779Sxy150489 * Turn LED off. 19055779Sxy150489 */ 19065779Sxy150489 s32 19075779Sxy150489 e1000_led_off_generic(struct e1000_hw *hw) 19085779Sxy150489 { 19095779Sxy150489 u32 ctrl; 19105779Sxy150489 19115779Sxy150489 DEBUGFUNC("e1000_led_off_generic"); 19125779Sxy150489 19135779Sxy150489 switch (hw->phy.media_type) { 19145779Sxy150489 case e1000_media_type_fiber: 19155779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 19165779Sxy150489 ctrl |= E1000_CTRL_SWDPIN0; 19175779Sxy150489 ctrl |= E1000_CTRL_SWDPIO0; 19185779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 19195779Sxy150489 break; 19205779Sxy150489 case e1000_media_type_copper: 19215779Sxy150489 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1); 19225779Sxy150489 break; 19235779Sxy150489 default: 19245779Sxy150489 break; 19255779Sxy150489 } 19265779Sxy150489 19275779Sxy150489 return (E1000_SUCCESS); 19285779Sxy150489 } 19295779Sxy150489 19305779Sxy150489 /* 19315779Sxy150489 * e1000_set_pcie_no_snoop_generic - Set PCI-express capabilities 19325779Sxy150489 * @hw: pointer to the HW structure 19335779Sxy150489 * @no_snoop: bitmap of snoop events 19345779Sxy150489 * 19355779Sxy150489 * Set the PCI-express register to snoop for events enabled in 'no_snoop'. 19365779Sxy150489 */ 19375779Sxy150489 void 19385779Sxy150489 e1000_set_pcie_no_snoop_generic(struct e1000_hw *hw, u32 no_snoop) 19395779Sxy150489 { 19405779Sxy150489 u32 gcr; 19415779Sxy150489 19425779Sxy150489 DEBUGFUNC("e1000_set_pcie_no_snoop_generic"); 19435779Sxy150489 19445779Sxy150489 if (hw->bus.type != e1000_bus_type_pci_express) 19455779Sxy150489 return; 19465779Sxy150489 19475779Sxy150489 if (no_snoop) { 19485779Sxy150489 gcr = E1000_READ_REG(hw, E1000_GCR); 19495779Sxy150489 gcr &= ~(PCIE_NO_SNOOP_ALL); 19505779Sxy150489 gcr |= no_snoop; 19515779Sxy150489 E1000_WRITE_REG(hw, E1000_GCR, gcr); 19525779Sxy150489 } 19535779Sxy150489 } 19545779Sxy150489 19555779Sxy150489 /* 19565779Sxy150489 * e1000_disable_pcie_master_generic - Disables PCI-express master access 19575779Sxy150489 * @hw: pointer to the HW structure 19585779Sxy150489 * 19595779Sxy150489 * Returns 0 (E1000_SUCCESS) if successful, else returns -10 19608571SChenlu.Chen@Sun.COM * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused 19615779Sxy150489 * the master requests to be disabled. 19625779Sxy150489 * 19635779Sxy150489 * Disables PCI-Express master access and verifies there are no pending 19645779Sxy150489 * requests. 19655779Sxy150489 */ 19665779Sxy150489 s32 19675779Sxy150489 e1000_disable_pcie_master_generic(struct e1000_hw *hw) 19685779Sxy150489 { 19695779Sxy150489 u32 ctrl; 19705779Sxy150489 s32 timeout = MASTER_DISABLE_TIMEOUT; 19715779Sxy150489 s32 ret_val = E1000_SUCCESS; 19725779Sxy150489 19735779Sxy150489 DEBUGFUNC("e1000_disable_pcie_master_generic"); 19745779Sxy150489 19755779Sxy150489 if (hw->bus.type != e1000_bus_type_pci_express) 19765779Sxy150489 goto out; 19775779Sxy150489 19785779Sxy150489 ctrl = E1000_READ_REG(hw, E1000_CTRL); 19795779Sxy150489 ctrl |= E1000_CTRL_GIO_MASTER_DISABLE; 19805779Sxy150489 E1000_WRITE_REG(hw, E1000_CTRL, ctrl); 19815779Sxy150489 19825779Sxy150489 while (timeout) { 19835779Sxy150489 if (!(E1000_READ_REG(hw, E1000_STATUS) & 19845779Sxy150489 E1000_STATUS_GIO_MASTER_ENABLE)) 19855779Sxy150489 break; 19865779Sxy150489 usec_delay(100); 19875779Sxy150489 timeout--; 19885779Sxy150489 } 19895779Sxy150489 19905779Sxy150489 if (!timeout) { 19915779Sxy150489 DEBUGOUT("Master requests are pending.\n"); 19925779Sxy150489 ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING; 19935779Sxy150489 goto out; 19945779Sxy150489 } 19955779Sxy150489 19965779Sxy150489 out: 19975779Sxy150489 return (ret_val); 19985779Sxy150489 } 19995779Sxy150489 20005779Sxy150489 /* 20015779Sxy150489 * e1000_reset_adaptive_generic - Reset Adaptive Interframe Spacing 20025779Sxy150489 * @hw: pointer to the HW structure 20035779Sxy150489 * 20045779Sxy150489 * Reset the Adaptive Interframe Spacing throttle to default values. 20055779Sxy150489 */ 20065779Sxy150489 void 20075779Sxy150489 e1000_reset_adaptive_generic(struct e1000_hw *hw) 20085779Sxy150489 { 20095779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 20105779Sxy150489 20115779Sxy150489 DEBUGFUNC("e1000_reset_adaptive_generic"); 20125779Sxy150489 20135779Sxy150489 if (!mac->adaptive_ifs) { 20145779Sxy150489 DEBUGOUT("Not in Adaptive IFS mode!\n"); 20155779Sxy150489 return; 20165779Sxy150489 } 20175779Sxy150489 20188571SChenlu.Chen@Sun.COM mac->current_ifs_val = 0; 20198571SChenlu.Chen@Sun.COM mac->ifs_min_val = IFS_MIN; 20208571SChenlu.Chen@Sun.COM mac->ifs_max_val = IFS_MAX; 20218571SChenlu.Chen@Sun.COM mac->ifs_step_size = IFS_STEP; 20228571SChenlu.Chen@Sun.COM mac->ifs_ratio = IFS_RATIO; 20235779Sxy150489 20248571SChenlu.Chen@Sun.COM mac->in_ifs_mode = false; 20255779Sxy150489 E1000_WRITE_REG(hw, E1000_AIT, 0); 20265779Sxy150489 } 20275779Sxy150489 20285779Sxy150489 /* 20295779Sxy150489 * e1000_update_adaptive_generic - Update Adaptive Interframe Spacing 20305779Sxy150489 * @hw: pointer to the HW structure 20315779Sxy150489 * 20325779Sxy150489 * Update the Adaptive Interframe Spacing Throttle value based on the 20335779Sxy150489 * time between transmitted packets and time between collisions. 20345779Sxy150489 */ 20355779Sxy150489 void 20365779Sxy150489 e1000_update_adaptive_generic(struct e1000_hw *hw) 20375779Sxy150489 { 20385779Sxy150489 struct e1000_mac_info *mac = &hw->mac; 20395779Sxy150489 20405779Sxy150489 DEBUGFUNC("e1000_update_adaptive_generic"); 20415779Sxy150489 20425779Sxy150489 if (!mac->adaptive_ifs) { 20435779Sxy150489 DEBUGOUT("Not in Adaptive IFS mode!\n"); 20445779Sxy150489 return; 20455779Sxy150489 } 20465779Sxy150489 20475779Sxy150489 if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) { 20485779Sxy150489 if (mac->tx_packet_delta > MIN_NUM_XMITS) { 20498571SChenlu.Chen@Sun.COM mac->in_ifs_mode = true; 20505779Sxy150489 if (mac->current_ifs_val < mac->ifs_max_val) { 20515779Sxy150489 if (!mac->current_ifs_val) 20525779Sxy150489 mac->current_ifs_val = mac->ifs_min_val; 20535779Sxy150489 else 20545779Sxy150489 mac->current_ifs_val += 20555779Sxy150489 mac->ifs_step_size; 20565779Sxy150489 E1000_WRITE_REG(hw, E1000_AIT, 20575779Sxy150489 mac->current_ifs_val); 20585779Sxy150489 } 20595779Sxy150489 } 20605779Sxy150489 } else { 20615779Sxy150489 if (mac->in_ifs_mode && 20625779Sxy150489 (mac->tx_packet_delta <= MIN_NUM_XMITS)) { 20635779Sxy150489 mac->current_ifs_val = 0; 20648571SChenlu.Chen@Sun.COM mac->in_ifs_mode = false; 20655779Sxy150489 E1000_WRITE_REG(hw, E1000_AIT, 0); 20665779Sxy150489 } 20675779Sxy150489 } 20685779Sxy150489 } 20695779Sxy150489 20705779Sxy150489 /* 20715779Sxy150489 * e1000_validate_mdi_setting_generic - Verify MDI/MDIx settings 20725779Sxy150489 * @hw: pointer to the HW structure 20735779Sxy150489 * 20748571SChenlu.Chen@Sun.COM * Verify that when not using auto-negotiation that MDI/MDIx is correctly 20755779Sxy150489 * set, which is forced to MDI mode only. 20765779Sxy150489 */ 20775779Sxy150489 s32 20785779Sxy150489 e1000_validate_mdi_setting_generic(struct e1000_hw *hw) 20795779Sxy150489 { 20805779Sxy150489 s32 ret_val = E1000_SUCCESS; 20815779Sxy150489 20825779Sxy150489 DEBUGFUNC("e1000_validate_mdi_setting_generic"); 20835779Sxy150489 20845779Sxy150489 if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) { 20855779Sxy150489 DEBUGOUT("Invalid MDI setting detected\n"); 20865779Sxy150489 hw->phy.mdix = 1; 20875779Sxy150489 ret_val = -E1000_ERR_CONFIG; 20885779Sxy150489 goto out; 20895779Sxy150489 } 20905779Sxy150489 20915779Sxy150489 out: 20925779Sxy150489 return (ret_val); 20935779Sxy150489 } 20945779Sxy150489 20955779Sxy150489 /* 20965779Sxy150489 * e1000_write_8bit_ctrl_reg_generic - Write a 8bit CTRL register 20975779Sxy150489 * @hw: pointer to the HW structure 20985779Sxy150489 * @reg: 32bit register offset such as E1000_SCTL 20995779Sxy150489 * @offset: register offset to write to 21005779Sxy150489 * @data: data to write at register offset 21015779Sxy150489 * 21025779Sxy150489 * Writes an address/data control type register. There are several of these 21035779Sxy150489 * and they all have the format address << 8 | data and bit 31 is polled for 21045779Sxy150489 * completion. 21055779Sxy150489 */ 21065779Sxy150489 s32 21075779Sxy150489 e1000_write_8bit_ctrl_reg_generic(struct e1000_hw *hw, u32 reg, 21085779Sxy150489 u32 offset, u8 data) 21095779Sxy150489 { 21105779Sxy150489 u32 i, regvalue = 0; 21115779Sxy150489 s32 ret_val = E1000_SUCCESS; 21125779Sxy150489 21135779Sxy150489 DEBUGFUNC("e1000_write_8bit_ctrl_reg_generic"); 21145779Sxy150489 21155779Sxy150489 /* Set up the address and data */ 21165779Sxy150489 regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT); 21175779Sxy150489 E1000_WRITE_REG(hw, reg, regvalue); 21185779Sxy150489 21195779Sxy150489 /* Poll the ready bit to see if the MDI read completed */ 21205779Sxy150489 for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) { 21215779Sxy150489 usec_delay(5); 21225779Sxy150489 regvalue = E1000_READ_REG(hw, reg); 21235779Sxy150489 if (regvalue & E1000_GEN_CTL_READY) 21245779Sxy150489 break; 21255779Sxy150489 } 21265779Sxy150489 if (!(regvalue & E1000_GEN_CTL_READY)) { 21275779Sxy150489 DEBUGOUT1("Reg %08x did not indicate ready\n", reg); 21285779Sxy150489 ret_val = -E1000_ERR_PHY; 21295779Sxy150489 goto out; 21305779Sxy150489 } 21315779Sxy150489 21325779Sxy150489 out: 21335779Sxy150489 return (ret_val); 21345779Sxy150489 } 2135