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