xref: /onnv-gate/usr/src/uts/common/io/igb/igb_mac.c (revision 8571:60e408ef19cc)
15779Sxy150489 /*
25779Sxy150489  * CDDL HEADER START
35779Sxy150489  *
4*8571SChenlu.Chen@Sun.COM  * Copyright(c) 2007-2009 Intel Corporation. All rights reserved.
55779Sxy150489  * The contents of this file are subject to the terms of the
65779Sxy150489  * Common Development and Distribution License (the "License").
75779Sxy150489  * You may not use this file except in compliance with the License.
85779Sxy150489  *
95779Sxy150489  * You can obtain a copy of the license at:
105779Sxy150489  *	http://www.opensolaris.org/os/licensing.
115779Sxy150489  * See the License for the specific language governing permissions
125779Sxy150489  * and limitations under the License.
135779Sxy150489  *
145779Sxy150489  * When using or redistributing this file, you may do so under the
155779Sxy150489  * License only. No other modification of this header is permitted.
165779Sxy150489  *
175779Sxy150489  * If applicable, add the following below this CDDL HEADER, with the
185779Sxy150489  * fields enclosed by brackets "[]" replaced with your own identifying
195779Sxy150489  * information: Portions Copyright [yyyy] [name of copyright owner]
205779Sxy150489  *
215779Sxy150489  * CDDL HEADER END
225779Sxy150489  */
235779Sxy150489 
245779Sxy150489 /*
25*8571SChenlu.Chen@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
265779Sxy150489  * Use is subject to license terms of the CDDL.
275779Sxy150489  */
285779Sxy150489 
29*8571SChenlu.Chen@Sun.COM /* IntelVersion: 1.92 v2008-10-7 */
305779Sxy150489 
315779Sxy150489 #include "igb_api.h"
32*8571SChenlu.Chen@Sun.COM 
33*8571SChenlu.Chen@Sun.COM static s32 e1000_set_default_fc_generic(struct e1000_hw *hw);
34*8571SChenlu.Chen@Sun.COM static s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw);
35*8571SChenlu.Chen@Sun.COM static s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw);
36*8571SChenlu.Chen@Sun.COM static s32 e1000_validate_mdi_setting_generic(struct e1000_hw *hw);
375779Sxy150489 
385779Sxy150489 /*
39*8571SChenlu.Chen@Sun.COM  * e1000_init_mac_ops_generic - Initialize MAC function pointers
405779Sxy150489  * @hw: pointer to the HW structure
415779Sxy150489  *
42*8571SChenlu.Chen@Sun.COM  * Setups up the function pointers to no-op functions
43*8571SChenlu.Chen@Sun.COM  */
44*8571SChenlu.Chen@Sun.COM void
45*8571SChenlu.Chen@Sun.COM e1000_init_mac_ops_generic(struct e1000_hw *hw)
46*8571SChenlu.Chen@Sun.COM {
47*8571SChenlu.Chen@Sun.COM 	struct e1000_mac_info *mac = &hw->mac;
48*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_init_mac_ops_generic");
49*8571SChenlu.Chen@Sun.COM 
50*8571SChenlu.Chen@Sun.COM 	/* General Setup */
51*8571SChenlu.Chen@Sun.COM 	mac->ops.init_params = e1000_null_ops_generic;
52*8571SChenlu.Chen@Sun.COM 	mac->ops.init_hw = e1000_null_ops_generic;
53*8571SChenlu.Chen@Sun.COM 	mac->ops.reset_hw = e1000_null_ops_generic;
54*8571SChenlu.Chen@Sun.COM 	mac->ops.setup_physical_interface = e1000_null_ops_generic;
55*8571SChenlu.Chen@Sun.COM 	mac->ops.get_bus_info = e1000_null_ops_generic;
56*8571SChenlu.Chen@Sun.COM 	mac->ops.read_mac_addr = e1000_read_mac_addr_generic;
57*8571SChenlu.Chen@Sun.COM 	mac->ops.config_collision_dist = e1000_config_collision_dist_generic;
58*8571SChenlu.Chen@Sun.COM 	mac->ops.clear_hw_cntrs = e1000_null_mac_generic;
59*8571SChenlu.Chen@Sun.COM 	/* LED */
60*8571SChenlu.Chen@Sun.COM 	mac->ops.cleanup_led = e1000_null_ops_generic;
61*8571SChenlu.Chen@Sun.COM 	mac->ops.setup_led = e1000_null_ops_generic;
62*8571SChenlu.Chen@Sun.COM 	mac->ops.blink_led = e1000_null_ops_generic;
63*8571SChenlu.Chen@Sun.COM 	mac->ops.led_on = e1000_null_ops_generic;
64*8571SChenlu.Chen@Sun.COM 	mac->ops.led_off = e1000_null_ops_generic;
65*8571SChenlu.Chen@Sun.COM 	/* LINK */
66*8571SChenlu.Chen@Sun.COM 	mac->ops.setup_link = e1000_null_ops_generic;
67*8571SChenlu.Chen@Sun.COM 	mac->ops.get_link_up_info = e1000_null_link_info;
68*8571SChenlu.Chen@Sun.COM 	mac->ops.check_for_link = e1000_null_ops_generic;
69*8571SChenlu.Chen@Sun.COM 	mac->ops.wait_autoneg = e1000_wait_autoneg_generic;
70*8571SChenlu.Chen@Sun.COM 	/* Management */
71*8571SChenlu.Chen@Sun.COM 	mac->ops.check_mng_mode = e1000_null_mng_mode;
72*8571SChenlu.Chen@Sun.COM 	mac->ops.mng_host_if_write = e1000_mng_host_if_write_generic;
73*8571SChenlu.Chen@Sun.COM 	mac->ops.mng_write_cmd_header = e1000_mng_write_cmd_header_generic;
74*8571SChenlu.Chen@Sun.COM 	mac->ops.mng_enable_host_if = e1000_mng_enable_host_if_generic;
75*8571SChenlu.Chen@Sun.COM 	/* VLAN, MC, etc. */
76*8571SChenlu.Chen@Sun.COM 	mac->ops.update_mc_addr_list = e1000_null_update_mc;
77*8571SChenlu.Chen@Sun.COM 	mac->ops.clear_vfta = e1000_null_mac_generic;
78*8571SChenlu.Chen@Sun.COM 	mac->ops.write_vfta = e1000_null_write_vfta;
79*8571SChenlu.Chen@Sun.COM 	mac->ops.mta_set = e1000_null_mta_set;
80*8571SChenlu.Chen@Sun.COM 	mac->ops.rar_set = e1000_rar_set_generic;
81*8571SChenlu.Chen@Sun.COM 	mac->ops.validate_mdi_setting = e1000_validate_mdi_setting_generic;
82*8571SChenlu.Chen@Sun.COM }
83*8571SChenlu.Chen@Sun.COM 
84*8571SChenlu.Chen@Sun.COM /*
85*8571SChenlu.Chen@Sun.COM  * e1000_null_ops_generic - No-op function, returns 0
86*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
87*8571SChenlu.Chen@Sun.COM  */
88*8571SChenlu.Chen@Sun.COM s32
89*8571SChenlu.Chen@Sun.COM e1000_null_ops_generic(struct e1000_hw *hw)
90*8571SChenlu.Chen@Sun.COM {
91*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_ops_generic");
92*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_1PARAMETER(hw);
93*8571SChenlu.Chen@Sun.COM 	return (E1000_SUCCESS);
94*8571SChenlu.Chen@Sun.COM }
95*8571SChenlu.Chen@Sun.COM 
96*8571SChenlu.Chen@Sun.COM /*
97*8571SChenlu.Chen@Sun.COM  * e1000_null_mac_generic - No-op function, return void
98*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
995779Sxy150489  */
1005779Sxy150489 void
101*8571SChenlu.Chen@Sun.COM e1000_null_mac_generic(struct e1000_hw *hw)
102*8571SChenlu.Chen@Sun.COM {
103*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_mac_generic");
104*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_1PARAMETER(hw);
105*8571SChenlu.Chen@Sun.COM }
106*8571SChenlu.Chen@Sun.COM 
107*8571SChenlu.Chen@Sun.COM /*
108*8571SChenlu.Chen@Sun.COM  * e1000_null_link_info - No-op function, return 0
109*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
110*8571SChenlu.Chen@Sun.COM  */
111*8571SChenlu.Chen@Sun.COM s32
112*8571SChenlu.Chen@Sun.COM e1000_null_link_info(struct e1000_hw *hw, u16 *s, u16 *d)
113*8571SChenlu.Chen@Sun.COM {
114*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_link_info");
115*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_3PARAMETER(hw, s, d);
116*8571SChenlu.Chen@Sun.COM 	return (E1000_SUCCESS);
117*8571SChenlu.Chen@Sun.COM }
118*8571SChenlu.Chen@Sun.COM 
119*8571SChenlu.Chen@Sun.COM /*
120*8571SChenlu.Chen@Sun.COM  * e1000_null_mng_mode - No-op function, return false
121*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
122*8571SChenlu.Chen@Sun.COM  */
123*8571SChenlu.Chen@Sun.COM bool
124*8571SChenlu.Chen@Sun.COM e1000_null_mng_mode(struct e1000_hw *hw)
1255779Sxy150489 {
126*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_mng_mode");
127*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_1PARAMETER(hw);
128*8571SChenlu.Chen@Sun.COM 	return (false);
129*8571SChenlu.Chen@Sun.COM }
130*8571SChenlu.Chen@Sun.COM 
131*8571SChenlu.Chen@Sun.COM /*
132*8571SChenlu.Chen@Sun.COM  * e1000_null_update_mc - No-op function, return void
133*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
134*8571SChenlu.Chen@Sun.COM  */
135*8571SChenlu.Chen@Sun.COM void
136*8571SChenlu.Chen@Sun.COM e1000_null_update_mc(struct e1000_hw *hw, u8 *h, u32 a, u32 b, u32 c)
137*8571SChenlu.Chen@Sun.COM {
138*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_update_mc");
139*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_5PARAMETER(hw, h, a, b, c);
140*8571SChenlu.Chen@Sun.COM }
1415779Sxy150489 
142*8571SChenlu.Chen@Sun.COM /*
143*8571SChenlu.Chen@Sun.COM  * e1000_null_write_vfta - No-op function, return void
144*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
145*8571SChenlu.Chen@Sun.COM  */
146*8571SChenlu.Chen@Sun.COM void
147*8571SChenlu.Chen@Sun.COM e1000_null_write_vfta(struct e1000_hw *hw, u32 a, u32 b)
148*8571SChenlu.Chen@Sun.COM {
149*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_write_vfta");
150*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_3PARAMETER(hw, a, b);
151*8571SChenlu.Chen@Sun.COM }
152*8571SChenlu.Chen@Sun.COM 
153*8571SChenlu.Chen@Sun.COM /*
154*8571SChenlu.Chen@Sun.COM  * e1000_null_set_mta - No-op function, return void
155*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
156*8571SChenlu.Chen@Sun.COM  */
157*8571SChenlu.Chen@Sun.COM void
158*8571SChenlu.Chen@Sun.COM e1000_null_mta_set(struct e1000_hw *hw, u32 a)
159*8571SChenlu.Chen@Sun.COM {
160*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_mta_set");
161*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_2PARAMETER(hw, a);
162*8571SChenlu.Chen@Sun.COM }
163*8571SChenlu.Chen@Sun.COM 
164*8571SChenlu.Chen@Sun.COM /*
165*8571SChenlu.Chen@Sun.COM  * e1000_null_rar_set - No-op function, return void
166*8571SChenlu.Chen@Sun.COM  * @hw: pointer to the HW structure
167*8571SChenlu.Chen@Sun.COM  */
168*8571SChenlu.Chen@Sun.COM void
169*8571SChenlu.Chen@Sun.COM e1000_null_rar_set(struct e1000_hw *hw, u8 *h, u32 a)
170*8571SChenlu.Chen@Sun.COM {
171*8571SChenlu.Chen@Sun.COM 	DEBUGFUNC("e1000_null_rar_set");
172*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_3PARAMETER(hw, h, a);
1735779Sxy150489 }
1745779Sxy150489 
1755779Sxy150489 /*
1765779Sxy150489  * e1000_get_bus_info_pci_generic - Get PCI(x) bus information
1775779Sxy150489  * @hw: pointer to the HW structure
1785779Sxy150489  *
1795779Sxy150489  * Determines and stores the system bus information for a particular
1805779Sxy150489  * network interface.  The following bus information is determined and stored:
1815779Sxy150489  * bus speed, bus width, type (PCI/PCIx), and PCI(-x) function.
1825779Sxy150489  */
1835779Sxy150489 s32
1845779Sxy150489 e1000_get_bus_info_pci_generic(struct e1000_hw *hw)
1855779Sxy150489 {
1865779Sxy150489 	struct e1000_bus_info *bus = &hw->bus;
1875779Sxy150489 	u32 status = E1000_READ_REG(hw, E1000_STATUS);
1885779Sxy150489 	s32 ret_val = E1000_SUCCESS;
1895779Sxy150489 	u16 pci_header_type;
1905779Sxy150489 
1915779Sxy150489 	DEBUGFUNC("e1000_get_bus_info_pci_generic");
1925779Sxy150489 
1935779Sxy150489 	/* PCI or PCI-X? */
1945779Sxy150489 	bus->type = (status & E1000_STATUS_PCIX_MODE)
195*8571SChenlu.Chen@Sun.COM 	    ? e1000_bus_type_pcix
196*8571SChenlu.Chen@Sun.COM 	    : e1000_bus_type_pci;
1975779Sxy150489 
1985779Sxy150489 	/* Bus speed */
1995779Sxy150489 	if (bus->type == e1000_bus_type_pci) {
2005779Sxy150489 		bus->speed = (status & E1000_STATUS_PCI66)
201*8571SChenlu.Chen@Sun.COM 		    ? e1000_bus_speed_66
202*8571SChenlu.Chen@Sun.COM 		    : e1000_bus_speed_33;
2035779Sxy150489 	} else {
2045779Sxy150489 		switch (status & E1000_STATUS_PCIX_SPEED) {
2055779Sxy150489 		case E1000_STATUS_PCIX_SPEED_66:
2065779Sxy150489 			bus->speed = e1000_bus_speed_66;
2075779Sxy150489 			break;
2085779Sxy150489 		case E1000_STATUS_PCIX_SPEED_100:
2095779Sxy150489 			bus->speed = e1000_bus_speed_100;
2105779Sxy150489 			break;
2115779Sxy150489 		case E1000_STATUS_PCIX_SPEED_133:
2125779Sxy150489 			bus->speed = e1000_bus_speed_133;
2135779Sxy150489 			break;
2145779Sxy150489 		default:
2155779Sxy150489 			bus->speed = e1000_bus_speed_reserved;
2165779Sxy150489 			break;
2175779Sxy150489 		}
2185779Sxy150489 	}
2195779Sxy150489 
2205779Sxy150489 	/* Bus width */
2215779Sxy150489 	bus->width = (status & E1000_STATUS_BUS64)
222*8571SChenlu.Chen@Sun.COM 	    ? e1000_bus_width_64
223*8571SChenlu.Chen@Sun.COM 	    : e1000_bus_width_32;
2245779Sxy150489 
2255779Sxy150489 	/* Which PCI(-X) function? */
2265779Sxy150489 	e1000_read_pci_cfg(hw, PCI_HEADER_TYPE_REGISTER, &pci_header_type);
2275779Sxy150489 	if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC)
2285779Sxy150489 		bus->func = (status & E1000_STATUS_FUNC_MASK)
2295779Sxy150489 		    >> E1000_STATUS_FUNC_SHIFT;
2305779Sxy150489 	else
2315779Sxy150489 		bus->func = 0;
2325779Sxy150489 
2335779Sxy150489 	return (ret_val);
2345779Sxy150489 }
2355779Sxy150489 
2365779Sxy150489 /*
2375779Sxy150489  * e1000_get_bus_info_pcie_generic - Get PCIe bus information
2385779Sxy150489  * @hw: pointer to the HW structure
2395779Sxy150489  *
2405779Sxy150489  * Determines and stores the system bus information for a particular
2415779Sxy150489  * network interface.  The following bus information is determined and stored:
2425779Sxy150489  * bus speed, bus width, type (PCIe), and PCIe function.
2435779Sxy150489  */
2445779Sxy150489 s32
2455779Sxy150489 e1000_get_bus_info_pcie_generic(struct e1000_hw *hw)
2465779Sxy150489 {
2475779Sxy150489 	struct e1000_bus_info *bus = &hw->bus;
2485779Sxy150489 	s32 ret_val;
2495779Sxy150489 	u32 status;
2505779Sxy150489 	u16 pcie_link_status, pci_header_type;
2515779Sxy150489 
2525779Sxy150489 	DEBUGFUNC("e1000_get_bus_info_pcie_generic");
2535779Sxy150489 
2545779Sxy150489 	bus->type = e1000_bus_type_pci_express;
2555779Sxy150489 	bus->speed = e1000_bus_speed_2500;
2565779Sxy150489 
2575779Sxy150489 	ret_val = e1000_read_pcie_cap_reg(hw,
2585779Sxy150489 	    PCIE_LINK_STATUS, &pcie_link_status);
2595779Sxy150489 	if (ret_val)
2605779Sxy150489 		bus->width = e1000_bus_width_unknown;
2615779Sxy150489 	else
262*8571SChenlu.Chen@Sun.COM 		bus->width = (enum e1000_bus_width)((pcie_link_status &
2635779Sxy150489 		    PCIE_LINK_WIDTH_MASK) >> PCIE_LINK_WIDTH_SHIFT);
2645779Sxy150489 
2655779Sxy150489 	e1000_read_pci_cfg(hw, PCI_HEADER_TYPE_REGISTER, &pci_header_type);
2665779Sxy150489 	if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) {
2675779Sxy150489 		status = E1000_READ_REG(hw, E1000_STATUS);
2685779Sxy150489 		bus->func = (status & E1000_STATUS_FUNC_MASK)
2695779Sxy150489 		    >> E1000_STATUS_FUNC_SHIFT;
2705779Sxy150489 	} else {
2715779Sxy150489 		bus->func = 0;
2725779Sxy150489 	}
2735779Sxy150489 
2745779Sxy150489 	return (E1000_SUCCESS);
2755779Sxy150489 }
2765779Sxy150489 
2775779Sxy150489 /*
2785779Sxy150489  * e1000_clear_vfta_generic - Clear VLAN filter table
2795779Sxy150489  * @hw: pointer to the HW structure
2805779Sxy150489  *
2815779Sxy150489  * Clears the register array which contains the VLAN filter table by
2825779Sxy150489  * setting all the values to 0.
2835779Sxy150489  */
2845779Sxy150489 void
2855779Sxy150489 e1000_clear_vfta_generic(struct e1000_hw *hw)
2865779Sxy150489 {
2875779Sxy150489 	u32 offset;
2885779Sxy150489 
2895779Sxy150489 	DEBUGFUNC("e1000_clear_vfta_generic");
2905779Sxy150489 
2915779Sxy150489 	for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
2925779Sxy150489 		E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
2935779Sxy150489 		E1000_WRITE_FLUSH(hw);
2945779Sxy150489 	}
2955779Sxy150489 }
2965779Sxy150489 
2975779Sxy150489 /*
2985779Sxy150489  * e1000_write_vfta_generic - Write value to VLAN filter table
2995779Sxy150489  * @hw: pointer to the HW structure
3005779Sxy150489  * @offset: register offset in VLAN filter table
3015779Sxy150489  * @value: register value written to VLAN filter table
3025779Sxy150489  *
3035779Sxy150489  * Writes value at the given offset in the register array which stores
3045779Sxy150489  * the VLAN filter table.
3055779Sxy150489  */
3065779Sxy150489 void
3075779Sxy150489 e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value)
3085779Sxy150489 {
3095779Sxy150489 	DEBUGFUNC("e1000_write_vfta_generic");
3105779Sxy150489 
3115779Sxy150489 	E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
3125779Sxy150489 	E1000_WRITE_FLUSH(hw);
3135779Sxy150489 }
3145779Sxy150489 
3155779Sxy150489 /*
3165779Sxy150489  * e1000_init_rx_addrs_generic - Initialize receive address's
3175779Sxy150489  * @hw: pointer to the HW structure
3185779Sxy150489  * @rar_count: receive address registers
3195779Sxy150489  *
3205779Sxy150489  * Setups the receive address registers by setting the base receive address
3215779Sxy150489  * register to the devices MAC address and clearing all the other receive
3225779Sxy150489  * address registers to 0.
3235779Sxy150489  */
3245779Sxy150489 void
3255779Sxy150489 e1000_init_rx_addrs_generic(struct e1000_hw *hw, u16 rar_count)
3265779Sxy150489 {
3275779Sxy150489 	u32 i;
3285779Sxy150489 
3295779Sxy150489 	DEBUGFUNC("e1000_init_rx_addrs_generic");
3305779Sxy150489 
3315779Sxy150489 	/* Setup the receive address */
3325779Sxy150489 	DEBUGOUT("Programming MAC Address into RAR[0]\n");
3335779Sxy150489 
334*8571SChenlu.Chen@Sun.COM 	hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
3355779Sxy150489 
3365779Sxy150489 	/* Zero out the other (rar_entry_count - 1) receive addresses */
3375779Sxy150489 	DEBUGOUT1("Clearing RAR[1-%u]\n", rar_count-1);
3385779Sxy150489 	for (i = 1; i < rar_count; i++) {
3395779Sxy150489 		E1000_WRITE_REG_ARRAY(hw, E1000_RA, (i << 1), 0);
3405779Sxy150489 		E1000_WRITE_FLUSH(hw);
3415779Sxy150489 		E1000_WRITE_REG_ARRAY(hw, E1000_RA, ((i << 1) + 1), 0);
3425779Sxy150489 		E1000_WRITE_FLUSH(hw);
3435779Sxy150489 	}
3445779Sxy150489 }
3455779Sxy150489 
3465779Sxy150489 /*
3475779Sxy150489  * e1000_check_alt_mac_addr_generic - Check for alternate MAC addr
3485779Sxy150489  * @hw: pointer to the HW structure
3495779Sxy150489  *
3505779Sxy150489  * Checks the nvm for an alternate MAC address.  An alternate MAC address
3515779Sxy150489  * can be setup by pre-boot software and must be treated like a permanent
3525779Sxy150489  * address and must override the actual permanent MAC address.  If an
3535779Sxy150489  * alternate MAC address is found it is saved in the hw struct and
3545779Sxy150489  * programmed into RAR0 and the function returns success, otherwise the
3555779Sxy150489  * function returns an error.
3565779Sxy150489  */
3575779Sxy150489 s32
3585779Sxy150489 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw)
3595779Sxy150489 {
3605779Sxy150489 	u32 i;
3615779Sxy150489 	s32 ret_val = E1000_SUCCESS;
3625779Sxy150489 	u16 offset, nvm_alt_mac_addr_offset, nvm_data;
3635779Sxy150489 	u8 alt_mac_addr[ETH_ADDR_LEN];
3645779Sxy150489 
3655779Sxy150489 	DEBUGFUNC("e1000_check_alt_mac_addr_generic");
3665779Sxy150489 
367*8571SChenlu.Chen@Sun.COM 	ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
3685779Sxy150489 	    &nvm_alt_mac_addr_offset);
3695779Sxy150489 	if (ret_val) {
3705779Sxy150489 		DEBUGOUT("NVM Read Error\n");
3715779Sxy150489 		goto out;
3725779Sxy150489 	}
3735779Sxy150489 
3745779Sxy150489 	if (nvm_alt_mac_addr_offset == 0xFFFF) {
3755779Sxy150489 		ret_val = -(E1000_NOT_IMPLEMENTED);
3765779Sxy150489 		goto out;
3775779Sxy150489 	}
3785779Sxy150489 
3795779Sxy150489 	if (hw->bus.func == E1000_FUNC_1)
3805779Sxy150489 		nvm_alt_mac_addr_offset += ETH_ADDR_LEN / sizeof (u16);
3815779Sxy150489 
3825779Sxy150489 	for (i = 0; i < ETH_ADDR_LEN; i += 2) {
3835779Sxy150489 		offset = nvm_alt_mac_addr_offset + (i >> 1);
384*8571SChenlu.Chen@Sun.COM 		ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
3855779Sxy150489 		if (ret_val) {
3865779Sxy150489 			DEBUGOUT("NVM Read Error\n");
3875779Sxy150489 			goto out;
3885779Sxy150489 		}
3895779Sxy150489 
3905779Sxy150489 		alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
3915779Sxy150489 		alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
3925779Sxy150489 	}
3935779Sxy150489 
3945779Sxy150489 	/* if multicast bit is set, the alternate address will not be used */
3955779Sxy150489 	if (alt_mac_addr[0] & 0x01) {
3965779Sxy150489 		ret_val = -(E1000_NOT_IMPLEMENTED);
3975779Sxy150489 		goto out;
3985779Sxy150489 	}
3995779Sxy150489 
4005779Sxy150489 	for (i = 0; i < ETH_ADDR_LEN; i++)
4015779Sxy150489 		hw->mac.addr[i] = hw->mac.perm_addr[i] = alt_mac_addr[i];
4025779Sxy150489 
403*8571SChenlu.Chen@Sun.COM 	hw->mac.ops.rar_set(hw, hw->mac.perm_addr, 0);
4045779Sxy150489 
4055779Sxy150489 out:
4065779Sxy150489 	return (ret_val);
4075779Sxy150489 }
4085779Sxy150489 
4095779Sxy150489 /*
4105779Sxy150489  * e1000_rar_set_generic - Set receive address register
4115779Sxy150489  * @hw: pointer to the HW structure
4125779Sxy150489  * @addr: pointer to the receive address
4135779Sxy150489  * @index: receive address array register
4145779Sxy150489  *
4155779Sxy150489  * Sets the receive address array register at index to the address passed
4165779Sxy150489  * in by addr.
4175779Sxy150489  */
4185779Sxy150489 void
4195779Sxy150489 e1000_rar_set_generic(struct e1000_hw *hw, u8 *addr, u32 index)
4205779Sxy150489 {
4215779Sxy150489 	u32 rar_low, rar_high;
4225779Sxy150489 
4235779Sxy150489 	DEBUGFUNC("e1000_rar_set_generic");
4245779Sxy150489 
4255779Sxy150489 	/*
4265779Sxy150489 	 * HW expects these in little endian so we reverse the byte order
4275779Sxy150489 	 * from network order (big endian) to little endian
4285779Sxy150489 	 */
4295779Sxy150489 	rar_low = ((u32) addr[0] |
4305779Sxy150489 	    ((u32) addr[1] << 8) |
4315779Sxy150489 	    ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4325779Sxy150489 
4335779Sxy150489 	rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4345779Sxy150489 
4355779Sxy150489 	/* If MAC address zero, no need to set the AV bit */
436*8571SChenlu.Chen@Sun.COM 	if (rar_low || rar_high)
437*8571SChenlu.Chen@Sun.COM 		rar_high |= E1000_RAH_AV;
4385779Sxy150489 
439*8571SChenlu.Chen@Sun.COM 	E1000_WRITE_REG(hw, E1000_RAL(index), rar_low);
440*8571SChenlu.Chen@Sun.COM 	E1000_WRITE_REG(hw, E1000_RAH(index), rar_high);
4415779Sxy150489 }
4425779Sxy150489 
4435779Sxy150489 /*
4445779Sxy150489  * e1000_mta_set_generic - Set multicast filter table address
4455779Sxy150489  * @hw: pointer to the HW structure
4465779Sxy150489  * @hash_value: determines the MTA register and bit to set
4475779Sxy150489  *
4485779Sxy150489  * The multicast table address is a register array of 32-bit registers.
4495779Sxy150489  * The hash_value is used to determine what register the bit is in, the
4505779Sxy150489  * current value is read, the new bit is OR'd in and the new value is
4515779Sxy150489  * written back into the register.
4525779Sxy150489  */
4535779Sxy150489 void
4545779Sxy150489 e1000_mta_set_generic(struct e1000_hw *hw, u32 hash_value)
4555779Sxy150489 {
4565779Sxy150489 	u32 hash_bit, hash_reg, mta;
4575779Sxy150489 
4585779Sxy150489 	DEBUGFUNC("e1000_mta_set_generic");
4595779Sxy150489 	/*
4605779Sxy150489 	 * The MTA is a register array of 32-bit registers. It is
4615779Sxy150489 	 * treated like an array of (32*mta_reg_count) bits.  We want to
4625779Sxy150489 	 * set bit BitArray[hash_value]. So we figure out what register
4635779Sxy150489 	 * the bit is in, read it, OR in the new bit, then write
4645779Sxy150489 	 * back the new value.  The (hw->mac.mta_reg_count - 1) serves as a
4655779Sxy150489 	 * mask to bits 31:5 of the hash value which gives us the
4665779Sxy150489 	 * register we're modifying.  The hash bit within that register
4675779Sxy150489 	 * is determined by the lower 5 bits of the hash value.
4685779Sxy150489 	 */
4695779Sxy150489 	hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
4705779Sxy150489 	hash_bit = hash_value & 0x1F;
4715779Sxy150489 
4725779Sxy150489 	mta = E1000_READ_REG_ARRAY(hw, E1000_MTA, hash_reg);
4735779Sxy150489 
4745779Sxy150489 	mta |= (1 << hash_bit);
4755779Sxy150489 
4765779Sxy150489 	E1000_WRITE_REG_ARRAY(hw, E1000_MTA, hash_reg, mta);
4775779Sxy150489 	E1000_WRITE_FLUSH(hw);
4785779Sxy150489 }
4795779Sxy150489 
4805779Sxy150489 /*
4815779Sxy150489  * e1000_update_mc_addr_list_generic - Update Multicast addresses
4825779Sxy150489  * @hw: pointer to the HW structure
4835779Sxy150489  * @mc_addr_list: array of multicast addresses to program
4845779Sxy150489  * @mc_addr_count: number of multicast addresses to program
4855779Sxy150489  * @rar_used_count: the first RAR register free to program
4865779Sxy150489  * @rar_count: total number of supported Receive Address Registers
4875779Sxy150489  *
4885779Sxy150489  * Updates the Receive Address Registers and Multicast Table Array.
4895779Sxy150489  * The caller must have a packed mc_addr_list of multicast addresses.
4905779Sxy150489  * The parameter rar_count will usually be hw->mac.rar_entry_count
4915779Sxy150489  * unless there are workarounds that change this.
4925779Sxy150489  */
4935779Sxy150489 void
4945779Sxy150489 e1000_update_mc_addr_list_generic(struct e1000_hw *hw,
4955779Sxy150489     u8 *mc_addr_list, u32 mc_addr_count,
4965779Sxy150489     u32 rar_used_count, u32 rar_count)
4975779Sxy150489 {
4985779Sxy150489 	u32 hash_value;
4995779Sxy150489 	u32 i;
5005779Sxy150489 
5015779Sxy150489 	DEBUGFUNC("e1000_update_mc_addr_list_generic");
5025779Sxy150489 
5035779Sxy150489 	/*
5045779Sxy150489 	 * Load the first set of multicast addresses into the exact
5055779Sxy150489 	 * filters (RAR).  If there are not enough to fill the RAR
5065779Sxy150489 	 * array, clear the filters.
5075779Sxy150489 	 */
5085779Sxy150489 	for (i = rar_used_count; i < rar_count; i++) {
5095779Sxy150489 		if (mc_addr_count) {
510*8571SChenlu.Chen@Sun.COM 			hw->mac.ops.rar_set(hw, mc_addr_list, i);
5115779Sxy150489 			mc_addr_count--;
5125779Sxy150489 			mc_addr_list += ETH_ADDR_LEN;
5135779Sxy150489 		} else {
5145779Sxy150489 			E1000_WRITE_REG_ARRAY(hw, E1000_RA, i << 1, 0);
5155779Sxy150489 			E1000_WRITE_FLUSH(hw);
5165779Sxy150489 			E1000_WRITE_REG_ARRAY(hw, E1000_RA, (i << 1) + 1, 0);
5175779Sxy150489 			E1000_WRITE_FLUSH(hw);
5185779Sxy150489 		}
5195779Sxy150489 	}
5205779Sxy150489 
5215779Sxy150489 	/* Clear the old settings from the MTA */
5225779Sxy150489 	DEBUGOUT("Clearing MTA\n");
5235779Sxy150489 	for (i = 0; i < hw->mac.mta_reg_count; i++) {
5245779Sxy150489 		E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
5255779Sxy150489 		E1000_WRITE_FLUSH(hw);
5265779Sxy150489 	}
5275779Sxy150489 
5285779Sxy150489 	/* Load any remaining multicast addresses into the hash table. */
5295779Sxy150489 	for (; mc_addr_count > 0; mc_addr_count--) {
530*8571SChenlu.Chen@Sun.COM 		hash_value = e1000_hash_mc_addr_generic(hw, mc_addr_list);
5315779Sxy150489 		DEBUGOUT1("Hash value = 0x%03X\n", hash_value);
532*8571SChenlu.Chen@Sun.COM 		hw->mac.ops.mta_set(hw, hash_value);
5335779Sxy150489 		mc_addr_list += ETH_ADDR_LEN;
5345779Sxy150489 	}
5355779Sxy150489 }
5365779Sxy150489 
5375779Sxy150489 /*
5385779Sxy150489  * e1000_hash_mc_addr_generic - Generate a multicast hash value
5395779Sxy150489  * @hw: pointer to the HW structure
5405779Sxy150489  * @mc_addr: pointer to a multicast address
5415779Sxy150489  *
5425779Sxy150489  * Generates a multicast address hash value which is used to determine
5435779Sxy150489  * the multicast filter table array address and new table value.  See
5445779Sxy150489  * e1000_mta_set_generic()
5455779Sxy150489  */
5465779Sxy150489 u32
5475779Sxy150489 e1000_hash_mc_addr_generic(struct e1000_hw *hw, u8 *mc_addr)
5485779Sxy150489 {
5495779Sxy150489 	u32 hash_value, hash_mask;
5505779Sxy150489 	u8 bit_shift = 0;
5515779Sxy150489 
5525779Sxy150489 	DEBUGFUNC("e1000_hash_mc_addr_generic");
5535779Sxy150489 
5545779Sxy150489 	/* Register count multiplied by bits per register */
5555779Sxy150489 	hash_mask = (hw->mac.mta_reg_count * 32) - 1;
5565779Sxy150489 
5575779Sxy150489 	/*
5585779Sxy150489 	 * For a mc_filter_type of 0, bit_shift is the number of left-shifts
5595779Sxy150489 	 * where 0xFF would still fall within the hash mask.
5605779Sxy150489 	 */
5615779Sxy150489 	while (hash_mask >> bit_shift != 0xFF)
5625779Sxy150489 		bit_shift++;
5635779Sxy150489 
5645779Sxy150489 	/*
5655779Sxy150489 	 * The portion of the address that is used for the hash table
5665779Sxy150489 	 * is determined by the mc_filter_type setting.
5675779Sxy150489 	 * The algorithm is such that there is a total of 8 bits of shifting.
5685779Sxy150489 	 * The bit_shift for a mc_filter_type of 0 represents the number of
5695779Sxy150489 	 * left-shifts where the MSB of mc_addr[5] would still fall within
5705779Sxy150489 	 * the hash_mask.  Case 0 does this exactly.  Since there are a total
5715779Sxy150489 	 * of 8 bits of shifting, then mc_addr[4] will shift right the
5725779Sxy150489 	 * remaining number of bits. Thus 8 - bit_shift.  The rest of the
5735779Sxy150489 	 * cases are a variation of this algorithm...essentially raising the
5745779Sxy150489 	 * number of bits to shift mc_addr[5] left, while still keeping the
5755779Sxy150489 	 * 8-bit shifting total.
5765779Sxy150489 	 *
5775779Sxy150489 	 * For example, given the following Destination MAC Address and an
5785779Sxy150489 	 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
5795779Sxy150489 	 * we can see that the bit_shift for case 0 is 4.  These are the hash
5805779Sxy150489 	 * values resulting from each mc_filter_type...
5815779Sxy150489 	 * [0] [1] [2] [3] [4] [5]
5825779Sxy150489 	 * 01  AA  00  12  34  56
5835779Sxy150489 	 * LSB			MSB
5845779Sxy150489 	 *
5855779Sxy150489 	 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
5865779Sxy150489 	 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
5875779Sxy150489 	 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
5885779Sxy150489 	 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
5895779Sxy150489 	 */
5905779Sxy150489 	switch (hw->mac.mc_filter_type) {
5915779Sxy150489 		default:
5925779Sxy150489 		case 0:
5935779Sxy150489 			break;
5945779Sxy150489 		case 1:
5955779Sxy150489 			bit_shift += 1;
5965779Sxy150489 			break;
5975779Sxy150489 		case 2:
5985779Sxy150489 			bit_shift += 2;
5995779Sxy150489 			break;
6005779Sxy150489 		case 3:
6015779Sxy150489 			bit_shift += 4;
6025779Sxy150489 			break;
6035779Sxy150489 	}
6045779Sxy150489 
6055779Sxy150489 	hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
6065779Sxy150489 	    (((u16) mc_addr[5]) << bit_shift)));
6075779Sxy150489 
6085779Sxy150489 	return (hash_value);
6095779Sxy150489 }
6105779Sxy150489 
6115779Sxy150489 /*
6125779Sxy150489  * e1000_pcix_mmrbc_workaround_generic - Fix incorrect MMRBC value
6135779Sxy150489  * @hw: pointer to the HW structure
6145779Sxy150489  *
6155779Sxy150489  * In certain situations, a system BIOS may report that the PCIx maximum
6165779Sxy150489  * memory read byte count (MMRBC) value is higher than than the actual
617*8571SChenlu.Chen@Sun.COM  * value. We check the PCIx command register with the current PCIx status
618*8571SChenlu.Chen@Sun.COM  * register.
6195779Sxy150489  */
6205779Sxy150489 void
6215779Sxy150489 e1000_pcix_mmrbc_workaround_generic(struct e1000_hw *hw)
6225779Sxy150489 {
6235779Sxy150489 	u16 cmd_mmrbc;
6245779Sxy150489 	u16 pcix_cmd;
6255779Sxy150489 	u16 pcix_stat_hi_word;
6265779Sxy150489 	u16 stat_mmrbc;
6275779Sxy150489 
6285779Sxy150489 	DEBUGFUNC("e1000_pcix_mmrbc_workaround_generic");
6295779Sxy150489 
6305779Sxy150489 	/* Workaround for PCI-X issue when BIOS sets MMRBC incorrectly */
6315779Sxy150489 	if (hw->bus.type != e1000_bus_type_pcix)
6325779Sxy150489 		return;
6335779Sxy150489 
6345779Sxy150489 	e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd);
6355779Sxy150489 	e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
6365779Sxy150489 	cmd_mmrbc = (pcix_cmd & PCIX_COMMAND_MMRBC_MASK) >>
6375779Sxy150489 	    PCIX_COMMAND_MMRBC_SHIFT;
6385779Sxy150489 	stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
6395779Sxy150489 	    PCIX_STATUS_HI_MMRBC_SHIFT;
6405779Sxy150489 	if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
6415779Sxy150489 		stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
6425779Sxy150489 	if (cmd_mmrbc > stat_mmrbc) {
6435779Sxy150489 		pcix_cmd &= ~PCIX_COMMAND_MMRBC_MASK;
6445779Sxy150489 		pcix_cmd |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
6455779Sxy150489 		e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd);
6465779Sxy150489 	}
6475779Sxy150489 }
6485779Sxy150489 
6495779Sxy150489 /*
6505779Sxy150489  * e1000_clear_hw_cntrs_base_generic - Clear base hardware counters
6515779Sxy150489  * @hw: pointer to the HW structure
6525779Sxy150489  *
6535779Sxy150489  * Clears the base hardware counters by reading the counter registers.
6545779Sxy150489  */
6555779Sxy150489 void
6565779Sxy150489 e1000_clear_hw_cntrs_base_generic(struct e1000_hw *hw)
6575779Sxy150489 {
6585779Sxy150489 	DEBUGFUNC("e1000_clear_hw_cntrs_base_generic");
6595779Sxy150489 
6605779Sxy150489 	(void) E1000_READ_REG(hw, E1000_CRCERRS);
6615779Sxy150489 	(void) E1000_READ_REG(hw, E1000_SYMERRS);
6625779Sxy150489 	(void) E1000_READ_REG(hw, E1000_MPC);
6635779Sxy150489 	(void) E1000_READ_REG(hw, E1000_SCC);
6645779Sxy150489 	(void) E1000_READ_REG(hw, E1000_ECOL);
6655779Sxy150489 	(void) E1000_READ_REG(hw, E1000_MCC);
6665779Sxy150489 	(void) E1000_READ_REG(hw, E1000_LATECOL);
6675779Sxy150489 	(void) E1000_READ_REG(hw, E1000_COLC);
6685779Sxy150489 	(void) E1000_READ_REG(hw, E1000_DC);
6695779Sxy150489 	(void) E1000_READ_REG(hw, E1000_SEC);
6705779Sxy150489 	(void) E1000_READ_REG(hw, E1000_RLEC);
6715779Sxy150489 	(void) E1000_READ_REG(hw, E1000_XONRXC);
6725779Sxy150489 	(void) E1000_READ_REG(hw, E1000_XONTXC);
6735779Sxy150489 	(void) E1000_READ_REG(hw, E1000_XOFFRXC);
6745779Sxy150489 	(void) E1000_READ_REG(hw, E1000_XOFFTXC);
6755779Sxy150489 	(void) E1000_READ_REG(hw, E1000_FCRUC);
6765779Sxy150489 	(void) E1000_READ_REG(hw, E1000_GPRC);
6775779Sxy150489 	(void) E1000_READ_REG(hw, E1000_BPRC);
6785779Sxy150489 	(void) E1000_READ_REG(hw, E1000_MPRC);
6795779Sxy150489 	(void) E1000_READ_REG(hw, E1000_GPTC);
6805779Sxy150489 	(void) E1000_READ_REG(hw, E1000_GORCL);
6815779Sxy150489 	(void) E1000_READ_REG(hw, E1000_GORCH);
6825779Sxy150489 	(void) E1000_READ_REG(hw, E1000_GOTCL);
6835779Sxy150489 	(void) E1000_READ_REG(hw, E1000_GOTCH);
6845779Sxy150489 	(void) E1000_READ_REG(hw, E1000_RNBC);
6855779Sxy150489 	(void) E1000_READ_REG(hw, E1000_RUC);
6865779Sxy150489 	(void) E1000_READ_REG(hw, E1000_RFC);
6875779Sxy150489 	(void) E1000_READ_REG(hw, E1000_ROC);
6885779Sxy150489 	(void) E1000_READ_REG(hw, E1000_RJC);
6895779Sxy150489 	(void) E1000_READ_REG(hw, E1000_TORL);
6905779Sxy150489 	(void) E1000_READ_REG(hw, E1000_TORH);
6915779Sxy150489 	(void) E1000_READ_REG(hw, E1000_TOTL);
6925779Sxy150489 	(void) E1000_READ_REG(hw, E1000_TOTH);
6935779Sxy150489 	(void) E1000_READ_REG(hw, E1000_TPR);
6945779Sxy150489 	(void) E1000_READ_REG(hw, E1000_TPT);
6955779Sxy150489 	(void) E1000_READ_REG(hw, E1000_MPTC);
6965779Sxy150489 	(void) E1000_READ_REG(hw, E1000_BPTC);
6975779Sxy150489 }
6985779Sxy150489 
6995779Sxy150489 /*
7005779Sxy150489  * e1000_check_for_copper_link_generic - Check for link (Copper)
7015779Sxy150489  * @hw: pointer to the HW structure
7025779Sxy150489  *
7035779Sxy150489  * Checks to see of the link status of the hardware has changed.  If a
7045779Sxy150489  * change in link status has been detected, then we read the PHY registers
7055779Sxy150489  * to get the current speed/duplex if link exists.
7065779Sxy150489  */
7075779Sxy150489 s32
7085779Sxy150489 e1000_check_for_copper_link_generic(struct e1000_hw *hw)
7095779Sxy150489 {
7105779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
7115779Sxy150489 	s32 ret_val;
7125779Sxy150489 	bool link;
7135779Sxy150489 
7145779Sxy150489 	DEBUGFUNC("e1000_check_for_copper_link");
7155779Sxy150489 
7165779Sxy150489 	/*
7175779Sxy150489 	 * We only want to go out to the PHY registers to see if Auto-Neg
7185779Sxy150489 	 * has completed and/or if our link status has changed.  The
7195779Sxy150489 	 * get_link_status flag is set upon receiving a Link Status
7205779Sxy150489 	 * Change or Rx Sequence Error interrupt.
7215779Sxy150489 	 */
7225779Sxy150489 	if (!mac->get_link_status) {
7235779Sxy150489 		ret_val = E1000_SUCCESS;
7245779Sxy150489 		goto out;
7255779Sxy150489 	}
7265779Sxy150489 
7275779Sxy150489 	/*
7285779Sxy150489 	 * First we want to see if the MII Status Register reports
7295779Sxy150489 	 * link.  If so, then we want to get the current speed/duplex
7305779Sxy150489 	 * of the PHY.
7315779Sxy150489 	 */
7325779Sxy150489 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
7335779Sxy150489 	if (ret_val)
7345779Sxy150489 		goto out;
7355779Sxy150489 
7365779Sxy150489 	if (!link)
7375779Sxy150489 		goto out; /* No link detected */
7385779Sxy150489 
739*8571SChenlu.Chen@Sun.COM 	mac->get_link_status = false;
7405779Sxy150489 
7415779Sxy150489 	/*
7425779Sxy150489 	 * Check if there was DownShift, must be checked
7435779Sxy150489 	 * immediately after link-up
7445779Sxy150489 	 */
7455779Sxy150489 	(void) e1000_check_downshift_generic(hw);
7465779Sxy150489 
7475779Sxy150489 	/*
7485779Sxy150489 	 * If we are forcing speed/duplex, then we simply return since
7495779Sxy150489 	 * we have already determined whether we have link or not.
7505779Sxy150489 	 */
7515779Sxy150489 	if (!mac->autoneg) {
7525779Sxy150489 		ret_val = -E1000_ERR_CONFIG;
7535779Sxy150489 		goto out;
7545779Sxy150489 	}
7555779Sxy150489 
7565779Sxy150489 	/*
7575779Sxy150489 	 * Auto-Neg is enabled.  Auto Speed Detection takes care
7585779Sxy150489 	 * of MAC speed/duplex configuration.  So we only need to
7595779Sxy150489 	 * configure Collision Distance in the MAC.
7605779Sxy150489 	 */
7615779Sxy150489 	e1000_config_collision_dist_generic(hw);
7625779Sxy150489 
7635779Sxy150489 	/*
7645779Sxy150489 	 * Configure Flow Control now that Auto-Neg has completed.
7655779Sxy150489 	 * First, we need to restore the desired flow control
7665779Sxy150489 	 * settings because we may have had to re-autoneg with a
7675779Sxy150489 	 * different link partner.
7685779Sxy150489 	 */
7695779Sxy150489 	ret_val = e1000_config_fc_after_link_up_generic(hw);
770*8571SChenlu.Chen@Sun.COM 	if (ret_val)
7715779Sxy150489 		DEBUGOUT("Error configuring flow control\n");
7725779Sxy150489 
7735779Sxy150489 out:
7745779Sxy150489 	return (ret_val);
7755779Sxy150489 }
7765779Sxy150489 
7775779Sxy150489 /*
7785779Sxy150489  * e1000_check_for_fiber_link_generic - Check for link (Fiber)
7795779Sxy150489  * @hw: pointer to the HW structure
7805779Sxy150489  *
7815779Sxy150489  * Checks for link up on the hardware.  If link is not up and we have
7825779Sxy150489  * a signal, then we need to force link up.
7835779Sxy150489  */
7845779Sxy150489 s32
7855779Sxy150489 e1000_check_for_fiber_link_generic(struct e1000_hw *hw)
7865779Sxy150489 {
7875779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
7885779Sxy150489 	u32 rxcw;
7895779Sxy150489 	u32 ctrl;
7905779Sxy150489 	u32 status;
7915779Sxy150489 	s32 ret_val = E1000_SUCCESS;
7925779Sxy150489 
7935779Sxy150489 	DEBUGFUNC("e1000_check_for_fiber_link_generic");
7945779Sxy150489 
7955779Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
7965779Sxy150489 	status = E1000_READ_REG(hw, E1000_STATUS);
7975779Sxy150489 	rxcw = E1000_READ_REG(hw, E1000_RXCW);
7985779Sxy150489 
7995779Sxy150489 	/*
8005779Sxy150489 	 * If we don't have link (auto-negotiation failed or link partner
8015779Sxy150489 	 * cannot auto-negotiate), the cable is plugged in (we have signal),
8025779Sxy150489 	 * and our link partner is not trying to auto-negotiate with us (we
8035779Sxy150489 	 * are receiving idles or data), we need to force link up. We also
8045779Sxy150489 	 * need to give auto-negotiation time to complete, in case the cable
8055779Sxy150489 	 * was just plugged in. The autoneg_failed flag does this.
8065779Sxy150489 	 */
8075779Sxy150489 	/* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
8085779Sxy150489 	if ((ctrl & E1000_CTRL_SWDPIN1) && (!(status & E1000_STATUS_LU)) &&
8095779Sxy150489 	    (!(rxcw & E1000_RXCW_C))) {
8105779Sxy150489 		if (mac->autoneg_failed == 0) {
8115779Sxy150489 			mac->autoneg_failed = 1;
8125779Sxy150489 			goto out;
8135779Sxy150489 		}
8145779Sxy150489 		DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
8155779Sxy150489 
8165779Sxy150489 		/* Disable auto-negotiation in the TXCW register */
8175779Sxy150489 		E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
8185779Sxy150489 
8195779Sxy150489 		/* Force link-up and also force full-duplex. */
8205779Sxy150489 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
8215779Sxy150489 		ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
8225779Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8235779Sxy150489 
8245779Sxy150489 		/* Configure Flow Control after forcing link up. */
8255779Sxy150489 		ret_val = e1000_config_fc_after_link_up_generic(hw);
8265779Sxy150489 		if (ret_val) {
8275779Sxy150489 			DEBUGOUT("Error configuring flow control\n");
8285779Sxy150489 			goto out;
8295779Sxy150489 		}
8305779Sxy150489 	} else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
8315779Sxy150489 		/*
8325779Sxy150489 		 * If we are forcing link and we are receiving /C/ ordered
8335779Sxy150489 		 * sets, re-enable auto-negotiation in the TXCW register
8345779Sxy150489 		 * and disable forced link in the Device Control register
8355779Sxy150489 		 * in an attempt to auto-negotiate with our link partner.
8365779Sxy150489 		 */
8375779Sxy150489 		DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
8385779Sxy150489 		E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
8395779Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
8405779Sxy150489 
841*8571SChenlu.Chen@Sun.COM 		mac->serdes_has_link = true;
8425779Sxy150489 	}
8435779Sxy150489 
8445779Sxy150489 out:
8455779Sxy150489 	return (ret_val);
8465779Sxy150489 }
8475779Sxy150489 
8485779Sxy150489 /*
8495779Sxy150489  * e1000_check_for_serdes_link_generic - Check for link (Serdes)
8505779Sxy150489  * @hw: pointer to the HW structure
8515779Sxy150489  *
8525779Sxy150489  * Checks for link up on the hardware.  If link is not up and we have
8535779Sxy150489  * a signal, then we need to force link up.
8545779Sxy150489  */
8555779Sxy150489 s32
8565779Sxy150489 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
8575779Sxy150489 {
8585779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
8595779Sxy150489 	u32 rxcw;
8605779Sxy150489 	u32 ctrl;
8615779Sxy150489 	u32 status;
8625779Sxy150489 	s32 ret_val = E1000_SUCCESS;
8635779Sxy150489 
8645779Sxy150489 	DEBUGFUNC("e1000_check_for_serdes_link_generic");
8655779Sxy150489 
8665779Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
8675779Sxy150489 	status = E1000_READ_REG(hw, E1000_STATUS);
8685779Sxy150489 	rxcw = E1000_READ_REG(hw, E1000_RXCW);
8695779Sxy150489 
8705779Sxy150489 	/*
8715779Sxy150489 	 * If we don't have link (auto-negotiation failed or link partner
8725779Sxy150489 	 * cannot auto-negotiate), and our link partner is not trying to
8735779Sxy150489 	 * auto-negotiate with us (we are receiving idles or data),
8745779Sxy150489 	 * we need to force link up. We also need to give auto-negotiation
8755779Sxy150489 	 * time to complete.
8765779Sxy150489 	 */
8775779Sxy150489 	/* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
8785779Sxy150489 	if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) {
8795779Sxy150489 		if (mac->autoneg_failed == 0) {
8805779Sxy150489 			mac->autoneg_failed = 1;
8815779Sxy150489 			goto out;
8825779Sxy150489 		}
8835779Sxy150489 		DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
8845779Sxy150489 
8855779Sxy150489 		/* Disable auto-negotiation in the TXCW register */
8865779Sxy150489 		E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
8875779Sxy150489 
8885779Sxy150489 		/* Force link-up and also force full-duplex. */
8895779Sxy150489 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
8905779Sxy150489 		ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
8915779Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8925779Sxy150489 
8935779Sxy150489 		/* Configure Flow Control after forcing link up. */
8945779Sxy150489 		ret_val = e1000_config_fc_after_link_up_generic(hw);
8955779Sxy150489 		if (ret_val) {
8965779Sxy150489 			DEBUGOUT("Error configuring flow control\n");
8975779Sxy150489 			goto out;
8985779Sxy150489 		}
8995779Sxy150489 	} else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
9005779Sxy150489 		/*
9015779Sxy150489 		 * If we are forcing link and we are receiving /C/ ordered
9025779Sxy150489 		 * sets, re-enable auto-negotiation in the TXCW register
9035779Sxy150489 		 * and disable forced link in the Device Control register
9045779Sxy150489 		 * in an attempt to auto-negotiate with our link partner.
9055779Sxy150489 		 */
9065779Sxy150489 		DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
9075779Sxy150489 		E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
9085779Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
9095779Sxy150489 
910*8571SChenlu.Chen@Sun.COM 		mac->serdes_has_link = true;
9115779Sxy150489 	} else if (!(E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW))) {
9125779Sxy150489 		/*
9135779Sxy150489 		 * If we force link for non-auto-negotiation switch, check
9145779Sxy150489 		 * link status based on MAC synchronization for internal
9155779Sxy150489 		 * serdes media type.
9165779Sxy150489 		 */
9175779Sxy150489 		/* SYNCH bit and IV bit are sticky. */
9185779Sxy150489 		usec_delay(10);
919*8571SChenlu.Chen@Sun.COM 		rxcw = E1000_READ_REG(hw, E1000_RXCW);
920*8571SChenlu.Chen@Sun.COM 		if (rxcw & E1000_RXCW_SYNCH) {
9215779Sxy150489 			if (!(rxcw & E1000_RXCW_IV)) {
922*8571SChenlu.Chen@Sun.COM 				mac->serdes_has_link = true;
923*8571SChenlu.Chen@Sun.COM 				DEBUGOUT("SERDES: Link up - forced.\n");
9245779Sxy150489 			}
9255779Sxy150489 		} else {
926*8571SChenlu.Chen@Sun.COM 			mac->serdes_has_link = false;
927*8571SChenlu.Chen@Sun.COM 			DEBUGOUT("SERDES: Link down - force failed.\n");
9285779Sxy150489 		}
9295779Sxy150489 	}
9305779Sxy150489 
9315779Sxy150489 	if (E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW)) {
9325779Sxy150489 		status = E1000_READ_REG(hw, E1000_STATUS);
933*8571SChenlu.Chen@Sun.COM 		if (status & E1000_STATUS_LU) {
934*8571SChenlu.Chen@Sun.COM 			/* SYNCH bit and IV bit are sticky, so reread rxcw. */
935*8571SChenlu.Chen@Sun.COM 			usec_delay(10);
936*8571SChenlu.Chen@Sun.COM 			rxcw = E1000_READ_REG(hw, E1000_RXCW);
937*8571SChenlu.Chen@Sun.COM 			if (rxcw & E1000_RXCW_SYNCH) {
938*8571SChenlu.Chen@Sun.COM 				if (!(rxcw & E1000_RXCW_IV)) {
939*8571SChenlu.Chen@Sun.COM 					mac->serdes_has_link = true;
940*8571SChenlu.Chen@Sun.COM 					DEBUGOUT("SERDES: Link up - autoneg "
941*8571SChenlu.Chen@Sun.COM 					    "completed sucessfully.\n");
942*8571SChenlu.Chen@Sun.COM 				} else {
943*8571SChenlu.Chen@Sun.COM 					mac->serdes_has_link = false;
944*8571SChenlu.Chen@Sun.COM 					DEBUGOUT("SERDES: Link down - invalid"
945*8571SChenlu.Chen@Sun.COM 					    "codewords detected in autoneg.\n");
946*8571SChenlu.Chen@Sun.COM 				}
947*8571SChenlu.Chen@Sun.COM 			} else {
948*8571SChenlu.Chen@Sun.COM 				mac->serdes_has_link = false;
949*8571SChenlu.Chen@Sun.COM 				DEBUGOUT("SERDES: Link down - no sync.\n");
950*8571SChenlu.Chen@Sun.COM 			}
951*8571SChenlu.Chen@Sun.COM 		} else {
952*8571SChenlu.Chen@Sun.COM 			mac->serdes_has_link = false;
953*8571SChenlu.Chen@Sun.COM 			DEBUGOUT("SERDES: Link down - autoneg failed\n");
954*8571SChenlu.Chen@Sun.COM 		}
9555779Sxy150489 	}
9565779Sxy150489 
9575779Sxy150489 out:
9585779Sxy150489 	return (ret_val);
9595779Sxy150489 }
9605779Sxy150489 
9615779Sxy150489 /*
9625779Sxy150489  * e1000_setup_link_generic - Setup flow control and link settings
9635779Sxy150489  * @hw: pointer to the HW structure
9645779Sxy150489  *
9655779Sxy150489  * Determines which flow control settings to use, then configures flow
9665779Sxy150489  * control.  Calls the appropriate media-specific link configuration
9675779Sxy150489  * function.  Assuming the adapter has a valid link partner, a valid link
9685779Sxy150489  * should be established.  Assumes the hardware has previously been reset
9695779Sxy150489  * and the transmitter and receiver are not enabled.
9705779Sxy150489  */
9715779Sxy150489 s32
9725779Sxy150489 e1000_setup_link_generic(struct e1000_hw *hw)
9735779Sxy150489 {
9745779Sxy150489 	s32 ret_val = E1000_SUCCESS;
9755779Sxy150489 
9765779Sxy150489 	DEBUGFUNC("e1000_setup_link_generic");
9775779Sxy150489 
9785779Sxy150489 	/*
9795779Sxy150489 	 * In the case of the phy reset being blocked, we already have a link.
9805779Sxy150489 	 * We do not need to set it up again.
9815779Sxy150489 	 */
982*8571SChenlu.Chen@Sun.COM 	if (hw->phy.ops.check_reset_block)
983*8571SChenlu.Chen@Sun.COM 		if (hw->phy.ops.check_reset_block(hw))
984*8571SChenlu.Chen@Sun.COM 			goto out;
9855779Sxy150489 
9865779Sxy150489 	/*
987*8571SChenlu.Chen@Sun.COM 	 * If requested flow control is set to default, set flow control
988*8571SChenlu.Chen@Sun.COM 	 * based on the EEPROM flow control settings.
9895779Sxy150489 	 */
990*8571SChenlu.Chen@Sun.COM 	if (hw->fc.requested_mode == e1000_fc_default) {
9915779Sxy150489 		ret_val = e1000_set_default_fc_generic(hw);
9925779Sxy150489 		if (ret_val)
9935779Sxy150489 			goto out;
9945779Sxy150489 	}
9955779Sxy150489 
9965779Sxy150489 	/*
997*8571SChenlu.Chen@Sun.COM 	 * Save off the requested flow control mode for use later.  Depending
998*8571SChenlu.Chen@Sun.COM 	 * on the link partner's capabilities, we may or may not use this mode.
9995779Sxy150489 	 */
1000*8571SChenlu.Chen@Sun.COM 	hw->fc.current_mode = hw->fc.requested_mode;
10015779Sxy150489 
1002*8571SChenlu.Chen@Sun.COM 	DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
1003*8571SChenlu.Chen@Sun.COM 	    hw->fc.current_mode);
10045779Sxy150489 
10055779Sxy150489 	/* Call the necessary media_type subroutine to configure the link. */
1006*8571SChenlu.Chen@Sun.COM 	ret_val = hw->mac.ops.setup_physical_interface(hw);
10075779Sxy150489 	if (ret_val)
10085779Sxy150489 		goto out;
10095779Sxy150489 
10105779Sxy150489 	/*
10115779Sxy150489 	 * Initialize the flow control address, type, and PAUSE timer
10125779Sxy150489 	 * registers to their default values.  This is done even if flow
10135779Sxy150489 	 * control is disabled, because it does not hurt anything to
10145779Sxy150489 	 * initialize these registers.
10155779Sxy150489 	 */
10165779Sxy150489 	DEBUGOUT("Initializing the Flow Control address,type and timer regs\n");
10175779Sxy150489 	E1000_WRITE_REG(hw, E1000_FCT, FLOW_CONTROL_TYPE);
10185779Sxy150489 	E1000_WRITE_REG(hw, E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
10195779Sxy150489 	E1000_WRITE_REG(hw, E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
10205779Sxy150489 
10215779Sxy150489 	E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
10225779Sxy150489 
10235779Sxy150489 	ret_val = e1000_set_fc_watermarks_generic(hw);
10245779Sxy150489 
10255779Sxy150489 out:
10265779Sxy150489 	return (ret_val);
10275779Sxy150489 }
10285779Sxy150489 
10295779Sxy150489 /*
10305779Sxy150489  * e1000_setup_fiber_serdes_link_generic - Setup link for fiber/serdes
10315779Sxy150489  * @hw: pointer to the HW structure
10325779Sxy150489  *
10335779Sxy150489  * Configures collision distance and flow control for fiber and serdes
10345779Sxy150489  * links.  Upon successful setup, poll for link.
10355779Sxy150489  */
10365779Sxy150489 s32
10375779Sxy150489 e1000_setup_fiber_serdes_link_generic(struct e1000_hw *hw)
10385779Sxy150489 {
10395779Sxy150489 	u32 ctrl;
10405779Sxy150489 	s32 ret_val = E1000_SUCCESS;
10415779Sxy150489 
10425779Sxy150489 	DEBUGFUNC("e1000_setup_fiber_serdes_link_generic");
10435779Sxy150489 
10445779Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
10455779Sxy150489 
10465779Sxy150489 	/* Take the link out of reset */
10475779Sxy150489 	ctrl &= ~E1000_CTRL_LRST;
10485779Sxy150489 
10495779Sxy150489 	e1000_config_collision_dist_generic(hw);
10505779Sxy150489 
10515779Sxy150489 	ret_val = e1000_commit_fc_settings_generic(hw);
10525779Sxy150489 	if (ret_val)
10535779Sxy150489 		goto out;
10545779Sxy150489 
10555779Sxy150489 	/*
10565779Sxy150489 	 * Since auto-negotiation is enabled, take the link out of reset (the
10575779Sxy150489 	 * link will be in reset, because we previously reset the chip). This
10585779Sxy150489 	 * will restart auto-negotiation.  If auto-negotiation is successful
10595779Sxy150489 	 * then the link-up status bit will be set and the flow control enable
10605779Sxy150489 	 * bits (RFCE and TFCE) will be set according to their negotiated value.
10615779Sxy150489 	 */
10625779Sxy150489 	DEBUGOUT("Auto-negotiation enabled\n");
10635779Sxy150489 
10645779Sxy150489 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
10655779Sxy150489 	E1000_WRITE_FLUSH(hw);
10665779Sxy150489 	msec_delay(1);
10675779Sxy150489 
10685779Sxy150489 	/*
1069*8571SChenlu.Chen@Sun.COM 	 * For these adapters, the SW definable pin 1 is set when the optics
10705779Sxy150489 	 * detect a signal.  If we have a signal, then poll for a "Link-Up"
10715779Sxy150489 	 * indication.
10725779Sxy150489 	 */
10735779Sxy150489 	if (hw->phy.media_type == e1000_media_type_internal_serdes ||
10745779Sxy150489 	    (E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) {
10755779Sxy150489 		ret_val = e1000_poll_fiber_serdes_link_generic(hw);
10765779Sxy150489 	} else {
10775779Sxy150489 		DEBUGOUT("No signal detected\n");
10785779Sxy150489 	}
10795779Sxy150489 
10805779Sxy150489 out:
10815779Sxy150489 	return (ret_val);
10825779Sxy150489 }
10835779Sxy150489 
10845779Sxy150489 /*
10855779Sxy150489  * e1000_config_collision_dist_generic - Configure collision distance
10865779Sxy150489  * @hw: pointer to the HW structure
10875779Sxy150489  *
10885779Sxy150489  * Configures the collision distance to the default value and is used
10895779Sxy150489  * during link setup. Currently no func pointer exists and all
10905779Sxy150489  * implementations are handled in the generic version of this function.
10915779Sxy150489  */
10925779Sxy150489 void
10935779Sxy150489 e1000_config_collision_dist_generic(struct e1000_hw *hw)
10945779Sxy150489 {
10955779Sxy150489 	u32 tctl;
10965779Sxy150489 
10975779Sxy150489 	DEBUGFUNC("e1000_config_collision_dist_generic");
10985779Sxy150489 
10995779Sxy150489 	tctl = E1000_READ_REG(hw, E1000_TCTL);
11005779Sxy150489 
11015779Sxy150489 	tctl &= ~E1000_TCTL_COLD;
11025779Sxy150489 	tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
11035779Sxy150489 
11045779Sxy150489 	E1000_WRITE_REG(hw, E1000_TCTL, tctl);
11055779Sxy150489 	E1000_WRITE_FLUSH(hw);
11065779Sxy150489 }
11075779Sxy150489 
11085779Sxy150489 /*
11095779Sxy150489  * e1000_poll_fiber_serdes_link_generic - Poll for link up
11105779Sxy150489  * @hw: pointer to the HW structure
11115779Sxy150489  *
11125779Sxy150489  * Polls for link up by reading the status register, if link fails to come
11135779Sxy150489  * up with auto-negotiation, then the link is forced if a signal is detected.
11145779Sxy150489  */
11155779Sxy150489 s32
11165779Sxy150489 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
11175779Sxy150489 {
11185779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
11195779Sxy150489 	u32 i, status;
11205779Sxy150489 	s32 ret_val = E1000_SUCCESS;
11215779Sxy150489 
11225779Sxy150489 	DEBUGFUNC("e1000_poll_fiber_serdes_link_generic");
11235779Sxy150489 
11245779Sxy150489 	/*
11255779Sxy150489 	 * If we have a signal (the cable is plugged in, or assumed true for
11265779Sxy150489 	 * serdes media) then poll for a "Link-Up" indication in the Device
11275779Sxy150489 	 * Status Register.  Time-out if a link isn't seen in 500 milliseconds
11285779Sxy150489 	 * seconds (Auto-negotiation should complete in less than 500
11295779Sxy150489 	 * milliseconds even if the other end is doing it in SW).
11305779Sxy150489 	 */
11315779Sxy150489 	for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
11325779Sxy150489 		msec_delay(10);
11335779Sxy150489 		status = E1000_READ_REG(hw, E1000_STATUS);
11345779Sxy150489 		if (status & E1000_STATUS_LU)
11355779Sxy150489 			break;
11365779Sxy150489 	}
11375779Sxy150489 	if (i == FIBER_LINK_UP_LIMIT) {
11385779Sxy150489 		DEBUGOUT("Never got a valid link from auto-neg!!!\n");
11395779Sxy150489 		mac->autoneg_failed = 1;
11405779Sxy150489 		/*
11415779Sxy150489 		 * AutoNeg failed to achieve a link, so we'll call
11425779Sxy150489 		 * mac->check_for_link. This routine will force the
11435779Sxy150489 		 * link up if we detect a signal. This will allow us to
11445779Sxy150489 		 * communicate with non-autonegotiating link partners.
11455779Sxy150489 		 */
1146*8571SChenlu.Chen@Sun.COM 		ret_val = hw->mac.ops.check_for_link(hw);
11475779Sxy150489 		if (ret_val) {
11485779Sxy150489 			DEBUGOUT("Error while checking for link\n");
11495779Sxy150489 			goto out;
11505779Sxy150489 		}
11515779Sxy150489 		mac->autoneg_failed = 0;
11525779Sxy150489 	} else {
11535779Sxy150489 		mac->autoneg_failed = 0;
11545779Sxy150489 		DEBUGOUT("Valid Link Found\n");
11555779Sxy150489 	}
11565779Sxy150489 
11575779Sxy150489 out:
11585779Sxy150489 	return (ret_val);
11595779Sxy150489 }
11605779Sxy150489 
11615779Sxy150489 /*
11625779Sxy150489  * e1000_commit_fc_settings_generic - Configure flow control
11635779Sxy150489  * @hw: pointer to the HW structure
11645779Sxy150489  *
11655779Sxy150489  * Write the flow control settings to the Transmit Config Word Register (TXCW)
11665779Sxy150489  * base on the flow control settings in e1000_mac_info.
11675779Sxy150489  */
11685779Sxy150489 s32
11695779Sxy150489 e1000_commit_fc_settings_generic(struct e1000_hw *hw)
11705779Sxy150489 {
11715779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
11725779Sxy150489 	u32 txcw;
11735779Sxy150489 	s32 ret_val = E1000_SUCCESS;
11745779Sxy150489 
11755779Sxy150489 	DEBUGFUNC("e1000_commit_fc_settings_generic");
11765779Sxy150489 
11775779Sxy150489 	/*
11785779Sxy150489 	 * Check for a software override of the flow control settings, and
11795779Sxy150489 	 * setup the device accordingly.  If auto-negotiation is enabled, then
11805779Sxy150489 	 * software will have to set the "PAUSE" bits to the correct value in
11815779Sxy150489 	 * the Transmit Config Word Register (TXCW) and re-start auto-
11825779Sxy150489 	 * negotiation.  However, if auto-negotiation is disabled, then
11835779Sxy150489 	 * software will have to manually configure the two flow control enable
11845779Sxy150489 	 * bits in the CTRL register.
11855779Sxy150489 	 *
11865779Sxy150489 	 * The possible values of the "fc" parameter are:
11875779Sxy150489 	 *	0:  Flow control is completely disabled
11885779Sxy150489 	 *	1:  Rx flow control is enabled (we can receive pause frames,
11895779Sxy150489 	 *	    but not send pause frames).
11905779Sxy150489 	 *	2:  Tx flow control is enabled (we can send pause frames but we
11915779Sxy150489 	 *	    do not support receiving pause frames).
11925779Sxy150489 	 *	3:  Both Rx and Tx flow control (symmetric) are enabled.
11935779Sxy150489 	 */
1194*8571SChenlu.Chen@Sun.COM 	switch (hw->fc.current_mode) {
11955779Sxy150489 	case e1000_fc_none:
11965779Sxy150489 		/* Flow control completely disabled by a software over-ride. */
11975779Sxy150489 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
11985779Sxy150489 		break;
11995779Sxy150489 	case e1000_fc_rx_pause:
12005779Sxy150489 		/*
12015779Sxy150489 		 * Rx Flow control is enabled and Tx Flow control is disabled
12025779Sxy150489 		 * by a software over-ride. Since there really isn't a way to
12035779Sxy150489 		 * advertise that we are capable of Rx Pause ONLY, we will
12045779Sxy150489 		 * advertise that we support both symmetric and asymmetric RX
12055779Sxy150489 		 * PAUSE.  Later, we will disable the adapter's ability to send
12065779Sxy150489 		 * PAUSE frames.
12075779Sxy150489 		 */
12085779Sxy150489 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
12095779Sxy150489 		break;
12105779Sxy150489 	case e1000_fc_tx_pause:
12115779Sxy150489 		/*
12125779Sxy150489 		 * Tx Flow control is enabled, and Rx Flow control is disabled,
12135779Sxy150489 		 * by a software over-ride.
12145779Sxy150489 		 */
12155779Sxy150489 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
12165779Sxy150489 		break;
12175779Sxy150489 	case e1000_fc_full:
12185779Sxy150489 		/*
12195779Sxy150489 		 * Flow control (both Rx and Tx) is enabled by a software
12205779Sxy150489 		 * over-ride.
12215779Sxy150489 		 */
12225779Sxy150489 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
12235779Sxy150489 		break;
12245779Sxy150489 	default:
12255779Sxy150489 		DEBUGOUT("Flow control param set incorrectly\n");
12265779Sxy150489 		ret_val = -E1000_ERR_CONFIG;
12275779Sxy150489 		goto out;
12285779Sxy150489 	}
12295779Sxy150489 
12305779Sxy150489 	E1000_WRITE_REG(hw, E1000_TXCW, txcw);
12315779Sxy150489 	mac->txcw = txcw;
12325779Sxy150489 
12335779Sxy150489 out:
12345779Sxy150489 	return (ret_val);
12355779Sxy150489 }
12365779Sxy150489 
12375779Sxy150489 /*
12385779Sxy150489  * e1000_set_fc_watermarks_generic - Set flow control high/low watermarks
12395779Sxy150489  * @hw: pointer to the HW structure
12405779Sxy150489  *
12415779Sxy150489  * Sets the flow control high/low threshold (watermark) registers.  If
12425779Sxy150489  * flow control XON frame transmission is enabled, then set XON frame
1243*8571SChenlu.Chen@Sun.COM  * transmission as well.
12445779Sxy150489  */
12455779Sxy150489 s32
12465779Sxy150489 e1000_set_fc_watermarks_generic(struct e1000_hw *hw)
12475779Sxy150489 {
12485779Sxy150489 	s32 ret_val = E1000_SUCCESS;
12495779Sxy150489 	u32 fcrtl = 0, fcrth = 0;
12505779Sxy150489 
12515779Sxy150489 	DEBUGFUNC("e1000_set_fc_watermarks_generic");
12525779Sxy150489 
12535779Sxy150489 	/*
12545779Sxy150489 	 * Set the flow control receive threshold registers.  Normally,
12555779Sxy150489 	 * these registers will be set to a default threshold that may be
12565779Sxy150489 	 * adjusted later by the driver's runtime code.  However, if the
12575779Sxy150489 	 * ability to transmit pause frames is not enabled, then these
12585779Sxy150489 	 * registers will be set to 0.
12595779Sxy150489 	 */
1260*8571SChenlu.Chen@Sun.COM 	if (hw->fc.current_mode & e1000_fc_tx_pause) {
12615779Sxy150489 		/*
12625779Sxy150489 		 * We need to set up the Receive Threshold high and low water
12635779Sxy150489 		 * marks as well as (optionally) enabling the transmission of
12645779Sxy150489 		 * XON frames.
12655779Sxy150489 		 */
12665779Sxy150489 		fcrtl = hw->fc.low_water;
12675779Sxy150489 		if (hw->fc.send_xon)
12685779Sxy150489 			fcrtl |= E1000_FCRTL_XONE;
12695779Sxy150489 
12705779Sxy150489 		fcrth = hw->fc.high_water;
12715779Sxy150489 	}
12725779Sxy150489 	E1000_WRITE_REG(hw, E1000_FCRTL, fcrtl);
12735779Sxy150489 	E1000_WRITE_REG(hw, E1000_FCRTH, fcrth);
12745779Sxy150489 
12755779Sxy150489 	return (ret_val);
12765779Sxy150489 }
12775779Sxy150489 
12785779Sxy150489 /*
12795779Sxy150489  * e1000_set_default_fc_generic - Set flow control default values
12805779Sxy150489  * @hw: pointer to the HW structure
12815779Sxy150489  *
12825779Sxy150489  * Read the EEPROM for the default values for flow control and store the
12835779Sxy150489  * values.
12845779Sxy150489  */
12855779Sxy150489 s32
12865779Sxy150489 e1000_set_default_fc_generic(struct e1000_hw *hw)
12875779Sxy150489 {
12885779Sxy150489 	s32 ret_val = E1000_SUCCESS;
12895779Sxy150489 	u16 nvm_data;
12905779Sxy150489 
12915779Sxy150489 	DEBUGFUNC("e1000_set_default_fc_generic");
12925779Sxy150489 
12935779Sxy150489 	/*
12945779Sxy150489 	 * Read and store word 0x0F of the EEPROM. This word contains bits
12955779Sxy150489 	 * that determine the hardware's default PAUSE (flow control) mode,
12965779Sxy150489 	 * a bit that determines whether the HW defaults to enabling or
12975779Sxy150489 	 * disabling auto-negotiation, and the direction of the
12985779Sxy150489 	 * SW defined pins. If there is no SW over-ride of the flow
12995779Sxy150489 	 * control setting, then the variable hw->fc will
13005779Sxy150489 	 * be initialized based on a value in the EEPROM.
13015779Sxy150489 	 */
1302*8571SChenlu.Chen@Sun.COM 	ret_val = hw->nvm.ops.read(hw, NVM_INIT_CONTROL2_REG, 1, &nvm_data);
13035779Sxy150489 
13045779Sxy150489 	if (ret_val) {
13055779Sxy150489 		DEBUGOUT("NVM Read Error\n");
13065779Sxy150489 		goto out;
13075779Sxy150489 	}
13085779Sxy150489 
13095779Sxy150489 	if ((nvm_data & NVM_WORD0F_PAUSE_MASK) == 0)
1310*8571SChenlu.Chen@Sun.COM 		hw->fc.requested_mode = e1000_fc_none;
13115779Sxy150489 	else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
13125779Sxy150489 	    NVM_WORD0F_ASM_DIR)
1313*8571SChenlu.Chen@Sun.COM 		hw->fc.requested_mode = e1000_fc_tx_pause;
13145779Sxy150489 	else
1315*8571SChenlu.Chen@Sun.COM 		hw->fc.requested_mode = e1000_fc_full;
13165779Sxy150489 
13175779Sxy150489 out:
13185779Sxy150489 	return (ret_val);
13195779Sxy150489 }
13205779Sxy150489 
13215779Sxy150489 /*
13225779Sxy150489  * e1000_force_mac_fc_generic - Force the MAC's flow control settings
13235779Sxy150489  * @hw: pointer to the HW structure
13245779Sxy150489  *
13255779Sxy150489  * Force the MAC's flow control settings.  Sets the TFCE and RFCE bits in the
13265779Sxy150489  * device control register to reflect the adapter settings.  TFCE and RFCE
13275779Sxy150489  * need to be explicitly set by software when a copper PHY is used because
13285779Sxy150489  * autonegotiation is managed by the PHY rather than the MAC.  Software must
13295779Sxy150489  * also configure these bits when link is forced on a fiber connection.
13305779Sxy150489  */
13315779Sxy150489 s32
13325779Sxy150489 e1000_force_mac_fc_generic(struct e1000_hw *hw)
13335779Sxy150489 {
13345779Sxy150489 	u32 ctrl;
13355779Sxy150489 	s32 ret_val = E1000_SUCCESS;
13365779Sxy150489 
13375779Sxy150489 	DEBUGFUNC("e1000_force_mac_fc_generic");
13385779Sxy150489 
13395779Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
13405779Sxy150489 
13415779Sxy150489 	/*
13425779Sxy150489 	 * Because we didn't get link via the internal auto-negotiation
13435779Sxy150489 	 * mechanism (we either forced link or we got link via PHY
13445779Sxy150489 	 * auto-neg), we have to manually enable/disable transmit an
13455779Sxy150489 	 * receive flow control.
13465779Sxy150489 	 *
13475779Sxy150489 	 * The "Case" statement below enables/disable flow control
1348*8571SChenlu.Chen@Sun.COM 	 * according to the "hw->fc.current_mode" parameter.
13495779Sxy150489 	 *
13505779Sxy150489 	 * The possible values of the "fc" parameter are:
13515779Sxy150489 	 *	0:  Flow control is completely disabled
13525779Sxy150489 	 *	1:  Rx flow control is enabled (we can receive pause
13535779Sxy150489 	 *	    frames but not send pause frames).
13545779Sxy150489 	 *	2:  Tx flow control is enabled (we can send pause frames
13555779Sxy150489 	 *	    frames but we do not receive pause frames).
13565779Sxy150489 	 *	3:  Both Rx and Tx flow control (symmetric) is enabled.
13575779Sxy150489 	 *  other:  No other values should be possible at this point.
13585779Sxy150489 	 */
1359*8571SChenlu.Chen@Sun.COM 	DEBUGOUT1("hw->fc.current_mode = %u\n", hw->fc.current_mode);
13605779Sxy150489 
1361*8571SChenlu.Chen@Sun.COM 	switch (hw->fc.current_mode) {
13625779Sxy150489 	case e1000_fc_none:
13635779Sxy150489 		ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
13645779Sxy150489 		break;
13655779Sxy150489 	case e1000_fc_rx_pause:
13665779Sxy150489 		ctrl &= (~E1000_CTRL_TFCE);
13675779Sxy150489 		ctrl |= E1000_CTRL_RFCE;
13685779Sxy150489 		break;
13695779Sxy150489 	case e1000_fc_tx_pause:
13705779Sxy150489 		ctrl &= (~E1000_CTRL_RFCE);
13715779Sxy150489 		ctrl |= E1000_CTRL_TFCE;
13725779Sxy150489 		break;
13735779Sxy150489 	case e1000_fc_full:
13745779Sxy150489 		ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
13755779Sxy150489 		break;
13765779Sxy150489 	default:
13775779Sxy150489 		DEBUGOUT("Flow control param set incorrectly\n");
13785779Sxy150489 		ret_val = -E1000_ERR_CONFIG;
13795779Sxy150489 		goto out;
13805779Sxy150489 	}
13815779Sxy150489 
13825779Sxy150489 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
13835779Sxy150489 
13845779Sxy150489 out:
13855779Sxy150489 	return (ret_val);
13865779Sxy150489 }
13875779Sxy150489 
13885779Sxy150489 /*
13895779Sxy150489  * e1000_config_fc_after_link_up_generic - Configures flow control after link
13905779Sxy150489  * @hw: pointer to the HW structure
13915779Sxy150489  *
13925779Sxy150489  * Checks the status of auto-negotiation after link up to ensure that the
13935779Sxy150489  * speed and duplex were not forced.  If the link needed to be forced, then
13945779Sxy150489  * flow control needs to be forced also.  If auto-negotiation is enabled
13955779Sxy150489  * and did not fail, then we configure flow control based on our link
13965779Sxy150489  * partner.
13975779Sxy150489  */
13985779Sxy150489 s32
13995779Sxy150489 e1000_config_fc_after_link_up_generic(struct e1000_hw *hw)
14005779Sxy150489 {
14015779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
14025779Sxy150489 	s32 ret_val = E1000_SUCCESS;
14035779Sxy150489 	u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
14045779Sxy150489 	u16 speed, duplex;
14055779Sxy150489 
14065779Sxy150489 	DEBUGFUNC("e1000_config_fc_after_link_up_generic");
14075779Sxy150489 
14085779Sxy150489 	/*
14095779Sxy150489 	 * Check for the case where we have fiber media and auto-neg failed
14105779Sxy150489 	 * so we had to force link.  In this case, we need to force the
14115779Sxy150489 	 * configuration of the MAC to match the "fc" parameter.
14125779Sxy150489 	 */
14135779Sxy150489 	if (mac->autoneg_failed) {
14145779Sxy150489 		if (hw->phy.media_type == e1000_media_type_fiber ||
14155779Sxy150489 		    hw->phy.media_type == e1000_media_type_internal_serdes)
14165779Sxy150489 			ret_val = e1000_force_mac_fc_generic(hw);
14175779Sxy150489 	} else {
14185779Sxy150489 		if (hw->phy.media_type == e1000_media_type_copper)
14195779Sxy150489 			ret_val = e1000_force_mac_fc_generic(hw);
14205779Sxy150489 	}
14215779Sxy150489 
14225779Sxy150489 	if (ret_val) {
14235779Sxy150489 		DEBUGOUT("Error forcing flow control settings\n");
14245779Sxy150489 		goto out;
14255779Sxy150489 	}
14265779Sxy150489 
14275779Sxy150489 	/*
14285779Sxy150489 	 * Check for the case where we have copper media and auto-neg is
14295779Sxy150489 	 * enabled.  In this case, we need to check and see if Auto-Neg
14305779Sxy150489 	 * has completed, and if so, how the PHY and link partner has
14315779Sxy150489 	 * flow control configured.
14325779Sxy150489 	 */
14335779Sxy150489 	if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
14345779Sxy150489 		/*
14355779Sxy150489 		 * Read the MII Status Register and check to see if AutoNeg
14365779Sxy150489 		 * has completed.  We read this twice because this reg has
14375779Sxy150489 		 * some "sticky" (latched) bits.
14385779Sxy150489 		 */
1439*8571SChenlu.Chen@Sun.COM 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
14405779Sxy150489 		if (ret_val)
14415779Sxy150489 			goto out;
1442*8571SChenlu.Chen@Sun.COM 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
14435779Sxy150489 		if (ret_val)
14445779Sxy150489 			goto out;
14455779Sxy150489 
14465779Sxy150489 		if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
14475779Sxy150489 			DEBUGOUT("Copper PHY and Auto Neg "
14485779Sxy150489 			    "has not completed.\n");
14495779Sxy150489 			goto out;
14505779Sxy150489 		}
14515779Sxy150489 
14525779Sxy150489 		/*
14535779Sxy150489 		 * The AutoNeg process has completed, so we now need to
14545779Sxy150489 		 * read both the Auto Negotiation Advertisement
14555779Sxy150489 		 * Register (Address 4) and the Auto_Negotiation Base
14565779Sxy150489 		 * Page Ability Register (Address 5) to determine how
14575779Sxy150489 		 * flow control was negotiated.
14585779Sxy150489 		 */
1459*8571SChenlu.Chen@Sun.COM 		ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
14605779Sxy150489 		    &mii_nway_adv_reg);
14615779Sxy150489 		if (ret_val)
14625779Sxy150489 			goto out;
1463*8571SChenlu.Chen@Sun.COM 		ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
14645779Sxy150489 		    &mii_nway_lp_ability_reg);
14655779Sxy150489 		if (ret_val)
14665779Sxy150489 			goto out;
14675779Sxy150489 
14685779Sxy150489 		/*
14695779Sxy150489 		 * Two bits in the Auto Negotiation Advertisement Register
14705779Sxy150489 		 * (Address 4) and two bits in the Auto Negotiation Base
14715779Sxy150489 		 * Page Ability Register (Address 5) determine flow control
14725779Sxy150489 		 * for both the PHY and the link partner.  The following
14735779Sxy150489 		 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
14745779Sxy150489 		 * 1999, describes these PAUSE resolution bits and how flow
14755779Sxy150489 		 * control is determined based upon these settings.
14765779Sxy150489 		 * NOTE:  DC = Don't Care
14775779Sxy150489 		 *
14785779Sxy150489 		 *   LOCAL DEVICE  |   LINK PARTNER
14795779Sxy150489 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
14805779Sxy150489 		 * ------|---------|-------|---------|--------------------
14815779Sxy150489 		 *   0   |    0    |  DC   |   DC    | e1000_fc_none
14825779Sxy150489 		 *   0   |    1    |   0   |   DC    | e1000_fc_none
14835779Sxy150489 		 *   0   |    1    |   1   |    0    | e1000_fc_none
14845779Sxy150489 		 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
14855779Sxy150489 		 *   1   |    0    |   0   |   DC    | e1000_fc_none
14865779Sxy150489 		 *   1   |   DC    |   1   |   DC    | e1000_fc_full
14875779Sxy150489 		 *   1   |    1    |   0   |    0    | e1000_fc_none
14885779Sxy150489 		 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
14895779Sxy150489 		 *
14905779Sxy150489 		 * Are both PAUSE bits set to 1?  If so, this implies
14915779Sxy150489 		 * Symmetric Flow Control is enabled at both ends.  The
14925779Sxy150489 		 * ASM_DIR bits are irrelevant per the spec.
14935779Sxy150489 		 *
14945779Sxy150489 		 * For Symmetric Flow Control:
14955779Sxy150489 		 *
14965779Sxy150489 		 *   LOCAL DEVICE  |   LINK PARTNER
14975779Sxy150489 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
14985779Sxy150489 		 * ------|---------|-------|---------|--------------------
14995779Sxy150489 		 *   1   |   DC    |   1   |   DC    | E1000_fc_full
15005779Sxy150489 		 *
15015779Sxy150489 		 */
15025779Sxy150489 		if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
15035779Sxy150489 		    (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
15045779Sxy150489 			/*
15055779Sxy150489 			 * Now we need to check if the user selected Rx ONLY
15065779Sxy150489 			 * of pause frames.  In this case, we had to advertise
15075779Sxy150489 			 * FULL flow control because we could not advertise RX
15085779Sxy150489 			 * ONLY. Hence, we must now check to see if we need to
15095779Sxy150489 			 * turn OFF  the TRANSMISSION of PAUSE frames.
15105779Sxy150489 			 */
1511*8571SChenlu.Chen@Sun.COM 			if (hw->fc.requested_mode == e1000_fc_full) {
1512*8571SChenlu.Chen@Sun.COM 				hw->fc.current_mode = e1000_fc_full;
15135779Sxy150489 				DEBUGOUT("Flow Control = FULL.\r\n");
15145779Sxy150489 			} else {
1515*8571SChenlu.Chen@Sun.COM 				hw->fc.current_mode = e1000_fc_rx_pause;
15165779Sxy150489 				DEBUGOUT("Flow Control = "
15175779Sxy150489 				    "RX PAUSE frames only.\r\n");
15185779Sxy150489 			}
15195779Sxy150489 		}
15205779Sxy150489 		/*
15215779Sxy150489 		 * For receiving PAUSE frames ONLY.
15225779Sxy150489 		 *
15235779Sxy150489 		 *   LOCAL DEVICE  |   LINK PARTNER
15245779Sxy150489 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
15255779Sxy150489 		 * ------|---------|-------|---------|--------------------
15265779Sxy150489 		 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
15275779Sxy150489 		 */
15285779Sxy150489 		else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
15295779Sxy150489 		    (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
15305779Sxy150489 		    (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
15315779Sxy150489 		    (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1532*8571SChenlu.Chen@Sun.COM 			hw->fc.current_mode = e1000_fc_tx_pause;
15335779Sxy150489 			DEBUGOUT("Flow Control = TX PAUSE frames only.\r\n");
15345779Sxy150489 		}
15355779Sxy150489 		/*
15365779Sxy150489 		 * For transmitting PAUSE frames ONLY.
15375779Sxy150489 		 *
15385779Sxy150489 		 *   LOCAL DEVICE  |   LINK PARTNER
15395779Sxy150489 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
15405779Sxy150489 		 * ------|---------|-------|---------|--------------------
15415779Sxy150489 		 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
15425779Sxy150489 		 */
15435779Sxy150489 		else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
15445779Sxy150489 		    (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
15455779Sxy150489 		    !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
15465779Sxy150489 		    (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
1547*8571SChenlu.Chen@Sun.COM 			hw->fc.current_mode = e1000_fc_rx_pause;
15485779Sxy150489 			DEBUGOUT("Flow Control = RX PAUSE frames only.\r\n");
15495779Sxy150489 		} else {
15505779Sxy150489 			/*
15515779Sxy150489 			 * Per the IEEE spec, at this point flow control
15525779Sxy150489 			 * should be disabled.
15535779Sxy150489 			 */
1554*8571SChenlu.Chen@Sun.COM 			hw->fc.current_mode = e1000_fc_none;
15555779Sxy150489 			DEBUGOUT("Flow Control = NONE.\r\n");
15565779Sxy150489 		}
15575779Sxy150489 
15585779Sxy150489 		/*
15595779Sxy150489 		 * Now we need to do one last check...  If we auto-
15605779Sxy150489 		 * negotiated to HALF DUPLEX, flow control should not be
15615779Sxy150489 		 * enabled per IEEE 802.3 spec.
15625779Sxy150489 		 */
1563*8571SChenlu.Chen@Sun.COM 		ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
15645779Sxy150489 		if (ret_val) {
15655779Sxy150489 			DEBUGOUT("Error getting link speed and duplex\n");
15665779Sxy150489 			goto out;
15675779Sxy150489 		}
15685779Sxy150489 
15695779Sxy150489 		if (duplex == HALF_DUPLEX)
1570*8571SChenlu.Chen@Sun.COM 			hw->fc.current_mode = e1000_fc_none;
15715779Sxy150489 
15725779Sxy150489 		/*
15735779Sxy150489 		 * Now we call a subroutine to actually force the MAC
15745779Sxy150489 		 * controller to use the correct flow control settings.
15755779Sxy150489 		 */
15765779Sxy150489 		ret_val = e1000_force_mac_fc_generic(hw);
15775779Sxy150489 		if (ret_val) {
15785779Sxy150489 			DEBUGOUT("Error forcing flow control settings\n");
15795779Sxy150489 			goto out;
15805779Sxy150489 		}
15815779Sxy150489 	}
15825779Sxy150489 
15835779Sxy150489 out:
15845779Sxy150489 	return (ret_val);
15855779Sxy150489 }
15865779Sxy150489 
15875779Sxy150489 /*
1588*8571SChenlu.Chen@Sun.COM  * e1000_get_speed_and_duplex_copper_generic - Retrieve current speed/duplex
15895779Sxy150489  * @hw: pointer to the HW structure
15905779Sxy150489  * @speed: stores the current speed
15915779Sxy150489  * @duplex: stores the current duplex
15925779Sxy150489  *
15935779Sxy150489  * Read the status register for the current speed/duplex and store the current
15945779Sxy150489  * speed and duplex for copper connections.
15955779Sxy150489  */
15965779Sxy150489 s32
15975779Sxy150489 e1000_get_speed_and_duplex_copper_generic(struct e1000_hw *hw, u16 *speed,
15985779Sxy150489     u16 *duplex)
15995779Sxy150489 {
16005779Sxy150489 	u32 status;
16015779Sxy150489 
16025779Sxy150489 	DEBUGFUNC("e1000_get_speed_and_duplex_copper_generic");
16035779Sxy150489 
16045779Sxy150489 	status = E1000_READ_REG(hw, E1000_STATUS);
16055779Sxy150489 	if (status & E1000_STATUS_SPEED_1000) {
16065779Sxy150489 		*speed = SPEED_1000;
16075779Sxy150489 		DEBUGOUT("1000 Mbs, ");
16085779Sxy150489 	} else if (status & E1000_STATUS_SPEED_100) {
16095779Sxy150489 		*speed = SPEED_100;
16105779Sxy150489 		DEBUGOUT("100 Mbs, ");
16115779Sxy150489 	} else {
16125779Sxy150489 		*speed = SPEED_10;
16135779Sxy150489 		DEBUGOUT("10 Mbs, ");
16145779Sxy150489 	}
16155779Sxy150489 
16165779Sxy150489 	if (status & E1000_STATUS_FD) {
16175779Sxy150489 		*duplex = FULL_DUPLEX;
16185779Sxy150489 		DEBUGOUT("Full Duplex\n");
16195779Sxy150489 	} else {
16205779Sxy150489 		*duplex = HALF_DUPLEX;
16215779Sxy150489 		DEBUGOUT("Half Duplex\n");
16225779Sxy150489 	}
16235779Sxy150489 
16245779Sxy150489 	return (E1000_SUCCESS);
16255779Sxy150489 }
16265779Sxy150489 
16275779Sxy150489 /*
1628*8571SChenlu.Chen@Sun.COM  * e1000_get_speed_and_duplex_fiber_generic - Retrieve current speed/duplex
16295779Sxy150489  * @hw: pointer to the HW structure
16305779Sxy150489  * @speed: stores the current speed
16315779Sxy150489  * @duplex: stores the current duplex
16325779Sxy150489  *
16335779Sxy150489  * Sets the speed and duplex to gigabit full duplex (the only possible option)
16345779Sxy150489  * for fiber/serdes links.
16355779Sxy150489  */
16365779Sxy150489 s32
16375779Sxy150489 e1000_get_speed_and_duplex_fiber_serdes_generic(struct e1000_hw *hw,
16385779Sxy150489     u16 *speed, u16 *duplex)
16395779Sxy150489 {
16405779Sxy150489 	DEBUGFUNC("e1000_get_speed_and_duplex_fiber_serdes_generic");
1641*8571SChenlu.Chen@Sun.COM 	UNREFERENCED_1PARAMETER(hw);
16425779Sxy150489 
16435779Sxy150489 	*speed = SPEED_1000;
16445779Sxy150489 	*duplex = FULL_DUPLEX;
16455779Sxy150489 
16465779Sxy150489 	return (E1000_SUCCESS);
16475779Sxy150489 }
16485779Sxy150489 
16495779Sxy150489 /*
16505779Sxy150489  * e1000_get_hw_semaphore_generic - Acquire hardware semaphore
16515779Sxy150489  * @hw: pointer to the HW structure
16525779Sxy150489  *
16535779Sxy150489  * Acquire the HW semaphore to access the PHY or NVM
16545779Sxy150489  */
16555779Sxy150489 s32
16565779Sxy150489 e1000_get_hw_semaphore_generic(struct e1000_hw *hw)
16575779Sxy150489 {
16585779Sxy150489 	u32 swsm;
16595779Sxy150489 	s32 ret_val = E1000_SUCCESS;
16605779Sxy150489 	s32 timeout = hw->nvm.word_size + 1;
16615779Sxy150489 	s32 i = 0;
16625779Sxy150489 
16635779Sxy150489 	DEBUGFUNC("e1000_get_hw_semaphore_generic");
16645779Sxy150489 
16655779Sxy150489 	/* Get the SW semaphore */
16665779Sxy150489 	while (i < timeout) {
16675779Sxy150489 		swsm = E1000_READ_REG(hw, E1000_SWSM);
16685779Sxy150489 		if (!(swsm & E1000_SWSM_SMBI))
16695779Sxy150489 			break;
16705779Sxy150489 
16715779Sxy150489 		usec_delay(50);
16725779Sxy150489 		i++;
16735779Sxy150489 	}
16745779Sxy150489 
16755779Sxy150489 	if (i == timeout) {
16765779Sxy150489 		DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
16775779Sxy150489 		ret_val = -E1000_ERR_NVM;
16785779Sxy150489 		goto out;
16795779Sxy150489 	}
16805779Sxy150489 
16815779Sxy150489 	/* Get the FW semaphore. */
16825779Sxy150489 	for (i = 0; i < timeout; i++) {
16835779Sxy150489 		swsm = E1000_READ_REG(hw, E1000_SWSM);
16845779Sxy150489 		E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
16855779Sxy150489 
16865779Sxy150489 		/* Semaphore acquired if bit latched */
16875779Sxy150489 		if (E1000_READ_REG(hw, E1000_SWSM) & E1000_SWSM_SWESMBI)
16885779Sxy150489 			break;
16895779Sxy150489 
16905779Sxy150489 		usec_delay(50);
16915779Sxy150489 	}
16925779Sxy150489 
16935779Sxy150489 	if (i == timeout) {
16945779Sxy150489 		/* Release semaphores */
16955779Sxy150489 		e1000_put_hw_semaphore_generic(hw);
16965779Sxy150489 		DEBUGOUT("Driver can't access the NVM\n");
16975779Sxy150489 		ret_val = -E1000_ERR_NVM;
16985779Sxy150489 		goto out;
16995779Sxy150489 	}
17005779Sxy150489 
17015779Sxy150489 out:
17025779Sxy150489 	return (ret_val);
17035779Sxy150489 }
17045779Sxy150489 
17055779Sxy150489 /*
17065779Sxy150489  * e1000_put_hw_semaphore_generic - Release hardware semaphore
17075779Sxy150489  * @hw: pointer to the HW structure
17085779Sxy150489  *
17095779Sxy150489  * Release hardware semaphore used to access the PHY or NVM
17105779Sxy150489  */
17115779Sxy150489 void
17125779Sxy150489 e1000_put_hw_semaphore_generic(struct e1000_hw *hw)
17135779Sxy150489 {
17145779Sxy150489 	u32 swsm;
17155779Sxy150489 
17165779Sxy150489 	DEBUGFUNC("e1000_put_hw_semaphore_generic");
17175779Sxy150489 
17185779Sxy150489 	swsm = E1000_READ_REG(hw, E1000_SWSM);
17195779Sxy150489 
17205779Sxy150489 	swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
17215779Sxy150489 
17225779Sxy150489 	E1000_WRITE_REG(hw, E1000_SWSM, swsm);
17235779Sxy150489 }
17245779Sxy150489 
17255779Sxy150489 /*
17265779Sxy150489  * e1000_get_auto_rd_done_generic - Check for auto read completion
17275779Sxy150489  * @hw: pointer to the HW structure
17285779Sxy150489  *
17295779Sxy150489  * Check EEPROM for Auto Read done bit.
17305779Sxy150489  */
17315779Sxy150489 s32
17325779Sxy150489 e1000_get_auto_rd_done_generic(struct e1000_hw *hw)
17335779Sxy150489 {
17345779Sxy150489 	s32 i = 0;
17355779Sxy150489 	s32 ret_val = E1000_SUCCESS;
17365779Sxy150489 
17375779Sxy150489 	DEBUGFUNC("e1000_get_auto_rd_done_generic");
17385779Sxy150489 
17395779Sxy150489 	while (i < AUTO_READ_DONE_TIMEOUT) {
17405779Sxy150489 		if (E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_AUTO_RD)
17415779Sxy150489 			break;
17425779Sxy150489 		msec_delay(1);
17435779Sxy150489 		i++;
17445779Sxy150489 	}
17455779Sxy150489 
17465779Sxy150489 	if (i == AUTO_READ_DONE_TIMEOUT) {
17475779Sxy150489 		DEBUGOUT("Auto read by HW from NVM has not completed.\n");
17485779Sxy150489 		ret_val = -E1000_ERR_RESET;
17495779Sxy150489 		goto out;
17505779Sxy150489 	}
17515779Sxy150489 
17525779Sxy150489 out:
17535779Sxy150489 	return (ret_val);
17545779Sxy150489 }
17555779Sxy150489 
17565779Sxy150489 /*
17575779Sxy150489  * e1000_valid_led_default_generic - Verify a valid default LED config
17585779Sxy150489  * @hw: pointer to the HW structure
17595779Sxy150489  * @data: pointer to the NVM (EEPROM)
17605779Sxy150489  *
17615779Sxy150489  * Read the EEPROM for the current default LED configuration.  If the
17625779Sxy150489  * LED configuration is not valid, set to a valid LED configuration.
17635779Sxy150489  */
17645779Sxy150489 s32
17655779Sxy150489 e1000_valid_led_default_generic(struct e1000_hw *hw, u16 *data)
17665779Sxy150489 {
17675779Sxy150489 	s32 ret_val;
17685779Sxy150489 
17695779Sxy150489 	DEBUGFUNC("e1000_valid_led_default_generic");
17705779Sxy150489 
1771*8571SChenlu.Chen@Sun.COM 	ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
17725779Sxy150489 	if (ret_val) {
17735779Sxy150489 		DEBUGOUT("NVM Read Error\n");
17745779Sxy150489 		goto out;
17755779Sxy150489 	}
17765779Sxy150489 
17775779Sxy150489 	if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
17785779Sxy150489 		*data = ID_LED_DEFAULT;
17795779Sxy150489 
17805779Sxy150489 out:
17815779Sxy150489 	return (ret_val);
17825779Sxy150489 }
17835779Sxy150489 
17845779Sxy150489 /*
17855779Sxy150489  * e1000_id_led_init_generic -
17865779Sxy150489  * @hw: pointer to the HW structure
17875779Sxy150489  *
17885779Sxy150489  */
17895779Sxy150489 s32
17905779Sxy150489 e1000_id_led_init_generic(struct e1000_hw *hw)
17915779Sxy150489 {
17925779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
17935779Sxy150489 	s32 ret_val;
17945779Sxy150489 	const u32 ledctl_mask = 0x000000FF;
17955779Sxy150489 	const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
17965779Sxy150489 	const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
17975779Sxy150489 	u16 data, i, temp;
17985779Sxy150489 	const u16 led_mask = 0x0F;
17995779Sxy150489 
18005779Sxy150489 	DEBUGFUNC("e1000_id_led_init_generic");
18015779Sxy150489 
1802*8571SChenlu.Chen@Sun.COM 	ret_val = hw->nvm.ops.valid_led_default(hw, &data);
18035779Sxy150489 	if (ret_val)
18045779Sxy150489 		goto out;
18055779Sxy150489 
18065779Sxy150489 	mac->ledctl_default = E1000_READ_REG(hw, E1000_LEDCTL);
18075779Sxy150489 	mac->ledctl_mode1 = mac->ledctl_default;
18085779Sxy150489 	mac->ledctl_mode2 = mac->ledctl_default;
18095779Sxy150489 
18105779Sxy150489 	for (i = 0; i < 4; i++) {
18115779Sxy150489 		temp = (data >> (i << 2)) & led_mask;
18125779Sxy150489 		switch (temp) {
18135779Sxy150489 		case ID_LED_ON1_DEF2:
18145779Sxy150489 		case ID_LED_ON1_ON2:
18155779Sxy150489 		case ID_LED_ON1_OFF2:
18165779Sxy150489 			mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
18175779Sxy150489 			mac->ledctl_mode1 |= ledctl_on << (i << 3);
18185779Sxy150489 			break;
18195779Sxy150489 		case ID_LED_OFF1_DEF2:
18205779Sxy150489 		case ID_LED_OFF1_ON2:
18215779Sxy150489 		case ID_LED_OFF1_OFF2:
18225779Sxy150489 			mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
18235779Sxy150489 			mac->ledctl_mode1 |= ledctl_off << (i << 3);
18245779Sxy150489 			break;
18255779Sxy150489 		default:
18265779Sxy150489 			/* Do nothing */
18275779Sxy150489 			break;
18285779Sxy150489 		}
18295779Sxy150489 		switch (temp) {
18305779Sxy150489 		case ID_LED_DEF1_ON2:
18315779Sxy150489 		case ID_LED_ON1_ON2:
18325779Sxy150489 		case ID_LED_OFF1_ON2:
18335779Sxy150489 			mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
18345779Sxy150489 			mac->ledctl_mode2 |= ledctl_on << (i << 3);
18355779Sxy150489 			break;
18365779Sxy150489 		case ID_LED_DEF1_OFF2:
18375779Sxy150489 		case ID_LED_ON1_OFF2:
18385779Sxy150489 		case ID_LED_OFF1_OFF2:
18395779Sxy150489 			mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
18405779Sxy150489 			mac->ledctl_mode2 |= ledctl_off << (i << 3);
18415779Sxy150489 			break;
18425779Sxy150489 		default:
18435779Sxy150489 			/* Do nothing */
18445779Sxy150489 			break;
18455779Sxy150489 		}
18465779Sxy150489 	}
18475779Sxy150489 
18485779Sxy150489 out:
18495779Sxy150489 	return (ret_val);
18505779Sxy150489 }
18515779Sxy150489 
18525779Sxy150489 /*
18535779Sxy150489  * e1000_setup_led_generic - Configures SW controllable LED
18545779Sxy150489  * @hw: pointer to the HW structure
18555779Sxy150489  *
18565779Sxy150489  * This prepares the SW controllable LED for use and saves the current state
18575779Sxy150489  * of the LED so it can be later restored.
18585779Sxy150489  */
18595779Sxy150489 s32
18605779Sxy150489 e1000_setup_led_generic(struct e1000_hw *hw)
18615779Sxy150489 {
18625779Sxy150489 	u32 ledctl;
18635779Sxy150489 	s32 ret_val = E1000_SUCCESS;
18645779Sxy150489 
18655779Sxy150489 	DEBUGFUNC("e1000_setup_led_generic");
18665779Sxy150489 
1867*8571SChenlu.Chen@Sun.COM 	if (hw->mac.ops.setup_led != e1000_setup_led_generic) {
18685779Sxy150489 		ret_val = -E1000_ERR_CONFIG;
18695779Sxy150489 		goto out;
18705779Sxy150489 	}
18715779Sxy150489 
18725779Sxy150489 	if (hw->phy.media_type == e1000_media_type_fiber) {
18735779Sxy150489 		ledctl = E1000_READ_REG(hw, E1000_LEDCTL);
18745779Sxy150489 		hw->mac.ledctl_default = ledctl;
18755779Sxy150489 		/* Turn off LED0 */
18765779Sxy150489 		ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
18775779Sxy150489 		    E1000_LEDCTL_LED0_BLINK |
18785779Sxy150489 		    E1000_LEDCTL_LED0_MODE_MASK);
18795779Sxy150489 		ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
18805779Sxy150489 		    E1000_LEDCTL_LED0_MODE_SHIFT);
18815779Sxy150489 		E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl);
18825779Sxy150489 	} else if (hw->phy.media_type == e1000_media_type_copper) {
18835779Sxy150489 		E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
18845779Sxy150489 	}
18855779Sxy150489 
18865779Sxy150489 out:
18875779Sxy150489 	return (ret_val);
18885779Sxy150489 }
18895779Sxy150489 
18905779Sxy150489 /*
18915779Sxy150489  * e1000_cleanup_led_generic - Set LED config to default operation
18925779Sxy150489  * @hw: pointer to the HW structure
18935779Sxy150489  *
18945779Sxy150489  * Remove the current LED configuration and set the LED configuration
18955779Sxy150489  * to the default value, saved from the EEPROM.
18965779Sxy150489  */
18975779Sxy150489 s32
18985779Sxy150489 e1000_cleanup_led_generic(struct e1000_hw *hw)
18995779Sxy150489 {
19005779Sxy150489 	s32 ret_val = E1000_SUCCESS;
19015779Sxy150489 
19025779Sxy150489 	DEBUGFUNC("e1000_cleanup_led_generic");
19035779Sxy150489 
1904*8571SChenlu.Chen@Sun.COM 	if (hw->mac.ops.cleanup_led != e1000_cleanup_led_generic) {
19055779Sxy150489 		ret_val = -E1000_ERR_CONFIG;
19065779Sxy150489 		goto out;
19075779Sxy150489 	}
19085779Sxy150489 
19095779Sxy150489 	E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
19105779Sxy150489 
19115779Sxy150489 out:
19125779Sxy150489 	return (ret_val);
19135779Sxy150489 }
19145779Sxy150489 
19155779Sxy150489 /*
19165779Sxy150489  * e1000_blink_led_generic - Blink LED
19175779Sxy150489  * @hw: pointer to the HW structure
19185779Sxy150489  *
1919*8571SChenlu.Chen@Sun.COM  * Blink the LEDs which are set to be on.
19205779Sxy150489  */
19215779Sxy150489 s32
19225779Sxy150489 e1000_blink_led_generic(struct e1000_hw *hw)
19235779Sxy150489 {
19245779Sxy150489 	u32 ledctl_blink = 0;
19255779Sxy150489 	u32 i;
19265779Sxy150489 
19275779Sxy150489 	DEBUGFUNC("e1000_blink_led_generic");
19285779Sxy150489 
19295779Sxy150489 	if (hw->phy.media_type == e1000_media_type_fiber) {
19305779Sxy150489 		/* always blink LED0 for PCI-E fiber */
19315779Sxy150489 		ledctl_blink = E1000_LEDCTL_LED0_BLINK |
19325779Sxy150489 		    (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
19335779Sxy150489 	} else {
19345779Sxy150489 		/*
19355779Sxy150489 		 * set the blink bit for each LED that's "on" (0x0E)
19365779Sxy150489 		 * in ledctl_mode2
19375779Sxy150489 		 */
19385779Sxy150489 		ledctl_blink = hw->mac.ledctl_mode2;
19395779Sxy150489 		for (i = 0; i < 4; i++)
19405779Sxy150489 			if (((hw->mac.ledctl_mode2 >> (i * 8)) & 0xFF) ==
19415779Sxy150489 			    E1000_LEDCTL_MODE_LED_ON)
19425779Sxy150489 				ledctl_blink |= (E1000_LEDCTL_LED0_BLINK <<
19435779Sxy150489 				    (i * 8));
19445779Sxy150489 	}
19455779Sxy150489 
19465779Sxy150489 	E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl_blink);
19475779Sxy150489 
19485779Sxy150489 	return (E1000_SUCCESS);
19495779Sxy150489 }
19505779Sxy150489 
19515779Sxy150489 /*
19525779Sxy150489  * e1000_led_on_generic - Turn LED on
19535779Sxy150489  * @hw: pointer to the HW structure
19545779Sxy150489  *
19555779Sxy150489  * Turn LED on.
19565779Sxy150489  */
19575779Sxy150489 s32
19585779Sxy150489 e1000_led_on_generic(struct e1000_hw *hw)
19595779Sxy150489 {
19605779Sxy150489 	u32 ctrl;
19615779Sxy150489 
19625779Sxy150489 	DEBUGFUNC("e1000_led_on_generic");
19635779Sxy150489 
19645779Sxy150489 	switch (hw->phy.media_type) {
19655779Sxy150489 	case e1000_media_type_fiber:
19665779Sxy150489 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
19675779Sxy150489 		ctrl &= ~E1000_CTRL_SWDPIN0;
19685779Sxy150489 		ctrl |= E1000_CTRL_SWDPIO0;
19695779Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
19705779Sxy150489 		break;
19715779Sxy150489 	case e1000_media_type_copper:
19725779Sxy150489 		E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2);
19735779Sxy150489 		break;
19745779Sxy150489 	default:
19755779Sxy150489 		break;
19765779Sxy150489 	}
19775779Sxy150489 
19785779Sxy150489 	return (E1000_SUCCESS);
19795779Sxy150489 }
19805779Sxy150489 
19815779Sxy150489 /*
19825779Sxy150489  * e1000_led_off_generic - Turn LED off
19835779Sxy150489  * @hw: pointer to the HW structure
19845779Sxy150489  *
19855779Sxy150489  * Turn LED off.
19865779Sxy150489  */
19875779Sxy150489 s32
19885779Sxy150489 e1000_led_off_generic(struct e1000_hw *hw)
19895779Sxy150489 {
19905779Sxy150489 	u32 ctrl;
19915779Sxy150489 
19925779Sxy150489 	DEBUGFUNC("e1000_led_off_generic");
19935779Sxy150489 
19945779Sxy150489 	switch (hw->phy.media_type) {
19955779Sxy150489 	case e1000_media_type_fiber:
19965779Sxy150489 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
19975779Sxy150489 		ctrl |= E1000_CTRL_SWDPIN0;
19985779Sxy150489 		ctrl |= E1000_CTRL_SWDPIO0;
19995779Sxy150489 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
20005779Sxy150489 		break;
20015779Sxy150489 	case e1000_media_type_copper:
20025779Sxy150489 		E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
20035779Sxy150489 		break;
20045779Sxy150489 	default:
20055779Sxy150489 		break;
20065779Sxy150489 	}
20075779Sxy150489 
20085779Sxy150489 	return (E1000_SUCCESS);
20095779Sxy150489 }
20105779Sxy150489 
20115779Sxy150489 /*
20125779Sxy150489  * e1000_set_pcie_no_snoop_generic - Set PCI-express capabilities
20135779Sxy150489  * @hw: pointer to the HW structure
20145779Sxy150489  * @no_snoop: bitmap of snoop events
20155779Sxy150489  *
20165779Sxy150489  * Set the PCI-express register to snoop for events enabled in 'no_snoop'.
20175779Sxy150489  */
20185779Sxy150489 void
20195779Sxy150489 e1000_set_pcie_no_snoop_generic(struct e1000_hw *hw, u32 no_snoop)
20205779Sxy150489 {
20215779Sxy150489 	u32 gcr;
20225779Sxy150489 
20235779Sxy150489 	DEBUGFUNC("e1000_set_pcie_no_snoop_generic");
20245779Sxy150489 
20255779Sxy150489 	if (hw->bus.type != e1000_bus_type_pci_express)
20265779Sxy150489 		return;
20275779Sxy150489 
20285779Sxy150489 	if (no_snoop) {
20295779Sxy150489 		gcr = E1000_READ_REG(hw, E1000_GCR);
20305779Sxy150489 		gcr &= ~(PCIE_NO_SNOOP_ALL);
20315779Sxy150489 		gcr |= no_snoop;
20325779Sxy150489 		E1000_WRITE_REG(hw, E1000_GCR, gcr);
20335779Sxy150489 	}
20345779Sxy150489 }
20355779Sxy150489 
20365779Sxy150489 /*
20375779Sxy150489  * e1000_disable_pcie_master_generic - Disables PCI-express master access
20385779Sxy150489  * @hw: pointer to the HW structure
20395779Sxy150489  *
20405779Sxy150489  * Returns 0 (E1000_SUCCESS) if successful, else returns -10
2041*8571SChenlu.Chen@Sun.COM  * (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
20425779Sxy150489  * the master requests to be disabled.
20435779Sxy150489  *
20445779Sxy150489  * Disables PCI-Express master access and verifies there are no pending
20455779Sxy150489  * requests.
20465779Sxy150489  */
20475779Sxy150489 s32
20485779Sxy150489 e1000_disable_pcie_master_generic(struct e1000_hw *hw)
20495779Sxy150489 {
20505779Sxy150489 	u32 ctrl;
20515779Sxy150489 	s32 timeout = MASTER_DISABLE_TIMEOUT;
20525779Sxy150489 	s32 ret_val = E1000_SUCCESS;
20535779Sxy150489 
20545779Sxy150489 	DEBUGFUNC("e1000_disable_pcie_master_generic");
20555779Sxy150489 
20565779Sxy150489 	if (hw->bus.type != e1000_bus_type_pci_express)
20575779Sxy150489 		goto out;
20585779Sxy150489 
20595779Sxy150489 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
20605779Sxy150489 	ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
20615779Sxy150489 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
20625779Sxy150489 
20635779Sxy150489 	while (timeout) {
20645779Sxy150489 		if (!(E1000_READ_REG(hw, E1000_STATUS) &
20655779Sxy150489 		    E1000_STATUS_GIO_MASTER_ENABLE))
20665779Sxy150489 			break;
20675779Sxy150489 		usec_delay(100);
20685779Sxy150489 		timeout--;
20695779Sxy150489 	}
20705779Sxy150489 
20715779Sxy150489 	if (!timeout) {
20725779Sxy150489 		DEBUGOUT("Master requests are pending.\n");
20735779Sxy150489 		ret_val = -E1000_ERR_MASTER_REQUESTS_PENDING;
20745779Sxy150489 		goto out;
20755779Sxy150489 	}
20765779Sxy150489 
20775779Sxy150489 out:
20785779Sxy150489 	return (ret_val);
20795779Sxy150489 }
20805779Sxy150489 
20815779Sxy150489 /*
20825779Sxy150489  * e1000_reset_adaptive_generic - Reset Adaptive Interframe Spacing
20835779Sxy150489  * @hw: pointer to the HW structure
20845779Sxy150489  *
20855779Sxy150489  * Reset the Adaptive Interframe Spacing throttle to default values.
20865779Sxy150489  */
20875779Sxy150489 void
20885779Sxy150489 e1000_reset_adaptive_generic(struct e1000_hw *hw)
20895779Sxy150489 {
20905779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
20915779Sxy150489 
20925779Sxy150489 	DEBUGFUNC("e1000_reset_adaptive_generic");
20935779Sxy150489 
20945779Sxy150489 	if (!mac->adaptive_ifs) {
20955779Sxy150489 		DEBUGOUT("Not in Adaptive IFS mode!\n");
20965779Sxy150489 		return;
20975779Sxy150489 	}
20985779Sxy150489 
2099*8571SChenlu.Chen@Sun.COM 	mac->current_ifs_val = 0;
2100*8571SChenlu.Chen@Sun.COM 	mac->ifs_min_val = IFS_MIN;
2101*8571SChenlu.Chen@Sun.COM 	mac->ifs_max_val = IFS_MAX;
2102*8571SChenlu.Chen@Sun.COM 	mac->ifs_step_size = IFS_STEP;
2103*8571SChenlu.Chen@Sun.COM 	mac->ifs_ratio = IFS_RATIO;
21045779Sxy150489 
2105*8571SChenlu.Chen@Sun.COM 	mac->in_ifs_mode = false;
21065779Sxy150489 	E1000_WRITE_REG(hw, E1000_AIT, 0);
21075779Sxy150489 }
21085779Sxy150489 
21095779Sxy150489 /*
21105779Sxy150489  * e1000_update_adaptive_generic - Update Adaptive Interframe Spacing
21115779Sxy150489  * @hw: pointer to the HW structure
21125779Sxy150489  *
21135779Sxy150489  * Update the Adaptive Interframe Spacing Throttle value based on the
21145779Sxy150489  * time between transmitted packets and time between collisions.
21155779Sxy150489  */
21165779Sxy150489 void
21175779Sxy150489 e1000_update_adaptive_generic(struct e1000_hw *hw)
21185779Sxy150489 {
21195779Sxy150489 	struct e1000_mac_info *mac = &hw->mac;
21205779Sxy150489 
21215779Sxy150489 	DEBUGFUNC("e1000_update_adaptive_generic");
21225779Sxy150489 
21235779Sxy150489 	if (!mac->adaptive_ifs) {
21245779Sxy150489 		DEBUGOUT("Not in Adaptive IFS mode!\n");
21255779Sxy150489 		return;
21265779Sxy150489 	}
21275779Sxy150489 
21285779Sxy150489 	if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
21295779Sxy150489 		if (mac->tx_packet_delta > MIN_NUM_XMITS) {
2130*8571SChenlu.Chen@Sun.COM 			mac->in_ifs_mode = true;
21315779Sxy150489 			if (mac->current_ifs_val < mac->ifs_max_val) {
21325779Sxy150489 				if (!mac->current_ifs_val)
21335779Sxy150489 					mac->current_ifs_val = mac->ifs_min_val;
21345779Sxy150489 				else
21355779Sxy150489 					mac->current_ifs_val +=
21365779Sxy150489 					    mac->ifs_step_size;
21375779Sxy150489 				E1000_WRITE_REG(hw, E1000_AIT,
21385779Sxy150489 				    mac->current_ifs_val);
21395779Sxy150489 			}
21405779Sxy150489 		}
21415779Sxy150489 	} else {
21425779Sxy150489 		if (mac->in_ifs_mode &&
21435779Sxy150489 		    (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
21445779Sxy150489 			mac->current_ifs_val = 0;
2145*8571SChenlu.Chen@Sun.COM 			mac->in_ifs_mode = false;
21465779Sxy150489 			E1000_WRITE_REG(hw, E1000_AIT, 0);
21475779Sxy150489 		}
21485779Sxy150489 	}
21495779Sxy150489 }
21505779Sxy150489 
21515779Sxy150489 /*
21525779Sxy150489  * e1000_validate_mdi_setting_generic - Verify MDI/MDIx settings
21535779Sxy150489  * @hw: pointer to the HW structure
21545779Sxy150489  *
2155*8571SChenlu.Chen@Sun.COM  * Verify that when not using auto-negotiation that MDI/MDIx is correctly
21565779Sxy150489  * set, which is forced to MDI mode only.
21575779Sxy150489  */
21585779Sxy150489 s32
21595779Sxy150489 e1000_validate_mdi_setting_generic(struct e1000_hw *hw)
21605779Sxy150489 {
21615779Sxy150489 	s32 ret_val = E1000_SUCCESS;
21625779Sxy150489 
21635779Sxy150489 	DEBUGFUNC("e1000_validate_mdi_setting_generic");
21645779Sxy150489 
21655779Sxy150489 	if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
21665779Sxy150489 		DEBUGOUT("Invalid MDI setting detected\n");
21675779Sxy150489 		hw->phy.mdix = 1;
21685779Sxy150489 		ret_val = -E1000_ERR_CONFIG;
21695779Sxy150489 		goto out;
21705779Sxy150489 	}
21715779Sxy150489 
21725779Sxy150489 out:
21735779Sxy150489 	return (ret_val);
21745779Sxy150489 }
21755779Sxy150489 
21765779Sxy150489 /*
21775779Sxy150489  * e1000_write_8bit_ctrl_reg_generic - Write a 8bit CTRL register
21785779Sxy150489  * @hw: pointer to the HW structure
21795779Sxy150489  * @reg: 32bit register offset such as E1000_SCTL
21805779Sxy150489  * @offset: register offset to write to
21815779Sxy150489  * @data: data to write at register offset
21825779Sxy150489  *
21835779Sxy150489  * Writes an address/data control type register.  There are several of these
21845779Sxy150489  * and they all have the format address << 8 | data and bit 31 is polled for
21855779Sxy150489  * completion.
21865779Sxy150489  */
21875779Sxy150489 s32
21885779Sxy150489 e1000_write_8bit_ctrl_reg_generic(struct e1000_hw *hw, u32 reg,
21895779Sxy150489     u32 offset, u8 data)
21905779Sxy150489 {
21915779Sxy150489 	u32 i, regvalue = 0;
21925779Sxy150489 	s32 ret_val = E1000_SUCCESS;
21935779Sxy150489 
21945779Sxy150489 	DEBUGFUNC("e1000_write_8bit_ctrl_reg_generic");
21955779Sxy150489 
21965779Sxy150489 	/* Set up the address and data */
21975779Sxy150489 	regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
21985779Sxy150489 	E1000_WRITE_REG(hw, reg, regvalue);
21995779Sxy150489 
22005779Sxy150489 	/* Poll the ready bit to see if the MDI read completed */
22015779Sxy150489 	for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
22025779Sxy150489 		usec_delay(5);
22035779Sxy150489 		regvalue = E1000_READ_REG(hw, reg);
22045779Sxy150489 		if (regvalue & E1000_GEN_CTL_READY)
22055779Sxy150489 			break;
22065779Sxy150489 	}
22075779Sxy150489 	if (!(regvalue & E1000_GEN_CTL_READY)) {
22085779Sxy150489 		DEBUGOUT1("Reg %08x did not indicate ready\n", reg);
22095779Sxy150489 		ret_val = -E1000_ERR_PHY;
22105779Sxy150489 		goto out;
22115779Sxy150489 	}
22125779Sxy150489 
22135779Sxy150489 out:
22145779Sxy150489 	return (ret_val);
22155779Sxy150489 }
2216