xref: /dflybsd-src/sys/dev/netif/ig_hal/e1000_mac.c (revision 01a55482b42bba8de64caeb8c9ede647a9208734)
19c80d176SSepherosa Ziehau /******************************************************************************
29c80d176SSepherosa Ziehau 
3*01a55482SSepherosa Ziehau   Copyright (c) 2001-2019, Intel Corporation
49c80d176SSepherosa Ziehau   All rights reserved.
59c80d176SSepherosa Ziehau 
69c80d176SSepherosa Ziehau   Redistribution and use in source and binary forms, with or without
79c80d176SSepherosa Ziehau   modification, are permitted provided that the following conditions are met:
89c80d176SSepherosa Ziehau 
99c80d176SSepherosa Ziehau    1. Redistributions of source code must retain the above copyright notice,
109c80d176SSepherosa Ziehau       this list of conditions and the following disclaimer.
119c80d176SSepherosa Ziehau 
129c80d176SSepherosa Ziehau    2. Redistributions in binary form must reproduce the above copyright
139c80d176SSepherosa Ziehau       notice, this list of conditions and the following disclaimer in the
149c80d176SSepherosa Ziehau       documentation and/or other materials provided with the distribution.
159c80d176SSepherosa Ziehau 
169c80d176SSepherosa Ziehau    3. Neither the name of the Intel Corporation nor the names of its
179c80d176SSepherosa Ziehau       contributors may be used to endorse or promote products derived from
189c80d176SSepherosa Ziehau       this software without specific prior written permission.
199c80d176SSepherosa Ziehau 
209c80d176SSepherosa Ziehau   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
219c80d176SSepherosa Ziehau   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
229c80d176SSepherosa Ziehau   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
239c80d176SSepherosa Ziehau   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
249c80d176SSepherosa Ziehau   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
259c80d176SSepherosa Ziehau   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
269c80d176SSepherosa Ziehau   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
279c80d176SSepherosa Ziehau   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
289c80d176SSepherosa Ziehau   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
299c80d176SSepherosa Ziehau   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
309c80d176SSepherosa Ziehau   POSSIBILITY OF SUCH DAMAGE.
319c80d176SSepherosa Ziehau 
329c80d176SSepherosa Ziehau ******************************************************************************/
3374dc3754SSepherosa Ziehau /*$FreeBSD$*/
349c80d176SSepherosa Ziehau 
359c80d176SSepherosa Ziehau #include "e1000_api.h"
369c80d176SSepherosa Ziehau 
379c80d176SSepherosa Ziehau static s32 e1000_validate_mdi_setting_generic(struct e1000_hw *hw);
386a5a645eSSepherosa Ziehau static void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw);
394be59a01SSepherosa Ziehau static void e1000_config_collision_dist_generic(struct e1000_hw *hw);
409c80d176SSepherosa Ziehau 
419c80d176SSepherosa Ziehau /**
429c80d176SSepherosa Ziehau  *  e1000_init_mac_ops_generic - Initialize MAC function pointers
439c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
449c80d176SSepherosa Ziehau  *
459c80d176SSepherosa Ziehau  *  Setups up the function pointers to no-op functions
469c80d176SSepherosa Ziehau  **/
e1000_init_mac_ops_generic(struct e1000_hw * hw)479c80d176SSepherosa Ziehau void e1000_init_mac_ops_generic(struct e1000_hw *hw)
489c80d176SSepherosa Ziehau {
499c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
509c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_init_mac_ops_generic");
519c80d176SSepherosa Ziehau 
529c80d176SSepherosa Ziehau 	/* General Setup */
539c80d176SSepherosa Ziehau 	mac->ops.init_params = e1000_null_ops_generic;
549c80d176SSepherosa Ziehau 	mac->ops.init_hw = e1000_null_ops_generic;
559c80d176SSepherosa Ziehau 	mac->ops.reset_hw = e1000_null_ops_generic;
569c80d176SSepherosa Ziehau 	mac->ops.setup_physical_interface = e1000_null_ops_generic;
579c80d176SSepherosa Ziehau 	mac->ops.get_bus_info = e1000_null_ops_generic;
589c80d176SSepherosa Ziehau 	mac->ops.set_lan_id = e1000_set_lan_id_multi_port_pcie;
599c80d176SSepherosa Ziehau 	mac->ops.read_mac_addr = e1000_read_mac_addr_generic;
609c80d176SSepherosa Ziehau 	mac->ops.config_collision_dist = e1000_config_collision_dist_generic;
619c80d176SSepherosa Ziehau 	mac->ops.clear_hw_cntrs = e1000_null_mac_generic;
629c80d176SSepherosa Ziehau 	/* LED */
639c80d176SSepherosa Ziehau 	mac->ops.cleanup_led = e1000_null_ops_generic;
649c80d176SSepherosa Ziehau 	mac->ops.setup_led = e1000_null_ops_generic;
659c80d176SSepherosa Ziehau 	mac->ops.blink_led = e1000_null_ops_generic;
669c80d176SSepherosa Ziehau 	mac->ops.led_on = e1000_null_ops_generic;
679c80d176SSepherosa Ziehau 	mac->ops.led_off = e1000_null_ops_generic;
689c80d176SSepherosa Ziehau 	/* LINK */
699c80d176SSepherosa Ziehau 	mac->ops.setup_link = e1000_null_ops_generic;
709c80d176SSepherosa Ziehau 	mac->ops.get_link_up_info = e1000_null_link_info;
719c80d176SSepherosa Ziehau 	mac->ops.check_for_link = e1000_null_ops_generic;
72379ebbe7SSepherosa Ziehau 	mac->ops.set_obff_timer = e1000_null_set_obff_timer;
739c80d176SSepherosa Ziehau 	/* Management */
749c80d176SSepherosa Ziehau 	mac->ops.check_mng_mode = e1000_null_mng_mode;
759c80d176SSepherosa Ziehau 	/* VLAN, MC, etc. */
769c80d176SSepherosa Ziehau 	mac->ops.update_mc_addr_list = e1000_null_update_mc;
779c80d176SSepherosa Ziehau 	mac->ops.clear_vfta = e1000_null_mac_generic;
789c80d176SSepherosa Ziehau 	mac->ops.write_vfta = e1000_null_write_vfta;
799c80d176SSepherosa Ziehau 	mac->ops.validate_mdi_setting = e1000_validate_mdi_setting_generic;
80*01a55482SSepherosa Ziehau 	mac->ops.rar_set = e1000_rar_set_generic;
819c80d176SSepherosa Ziehau }
829c80d176SSepherosa Ziehau 
839c80d176SSepherosa Ziehau /**
849c80d176SSepherosa Ziehau  *  e1000_null_ops_generic - No-op function, returns 0
859c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
869c80d176SSepherosa Ziehau  **/
e1000_null_ops_generic(struct e1000_hw E1000_UNUSEDARG * hw)87379ebbe7SSepherosa Ziehau s32 e1000_null_ops_generic(struct e1000_hw E1000_UNUSEDARG *hw)
889c80d176SSepherosa Ziehau {
899c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_null_ops_generic");
909c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
919c80d176SSepherosa Ziehau }
929c80d176SSepherosa Ziehau 
939c80d176SSepherosa Ziehau /**
949c80d176SSepherosa Ziehau  *  e1000_null_mac_generic - No-op function, return void
959c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
969c80d176SSepherosa Ziehau  **/
e1000_null_mac_generic(struct e1000_hw E1000_UNUSEDARG * hw)97379ebbe7SSepherosa Ziehau void e1000_null_mac_generic(struct e1000_hw E1000_UNUSEDARG *hw)
989c80d176SSepherosa Ziehau {
999c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_null_mac_generic");
1009c80d176SSepherosa Ziehau 	return;
1019c80d176SSepherosa Ziehau }
1029c80d176SSepherosa Ziehau 
1039c80d176SSepherosa Ziehau /**
1049c80d176SSepherosa Ziehau  *  e1000_null_link_info - No-op function, return 0
1059c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
106*01a55482SSepherosa Ziehau  *  @s: dummy variable
107*01a55482SSepherosa Ziehau  *  @d: dummy variable
1089c80d176SSepherosa Ziehau  **/
e1000_null_link_info(struct e1000_hw E1000_UNUSEDARG * hw,u16 E1000_UNUSEDARG * s,u16 E1000_UNUSEDARG * d)109379ebbe7SSepherosa Ziehau s32 e1000_null_link_info(struct e1000_hw E1000_UNUSEDARG *hw,
110379ebbe7SSepherosa Ziehau 			 u16 E1000_UNUSEDARG *s, u16 E1000_UNUSEDARG *d)
1119c80d176SSepherosa Ziehau {
1129c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_null_link_info");
1139c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
1149c80d176SSepherosa Ziehau }
1159c80d176SSepherosa Ziehau 
1169c80d176SSepherosa Ziehau /**
1179c80d176SSepherosa Ziehau  *  e1000_null_mng_mode - No-op function, return FALSE
1189c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
1199c80d176SSepherosa Ziehau  **/
e1000_null_mng_mode(struct e1000_hw E1000_UNUSEDARG * hw)120379ebbe7SSepherosa Ziehau bool e1000_null_mng_mode(struct e1000_hw E1000_UNUSEDARG *hw)
1219c80d176SSepherosa Ziehau {
1229c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_null_mng_mode");
1239c80d176SSepherosa Ziehau 	return FALSE;
1249c80d176SSepherosa Ziehau }
1259c80d176SSepherosa Ziehau 
1269c80d176SSepherosa Ziehau /**
1279c80d176SSepherosa Ziehau  *  e1000_null_update_mc - No-op function, return void
1289c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
129*01a55482SSepherosa Ziehau  *  @h: dummy variable
130*01a55482SSepherosa Ziehau  *  @a: dummy variable
1319c80d176SSepherosa Ziehau  **/
e1000_null_update_mc(struct e1000_hw E1000_UNUSEDARG * hw,u8 E1000_UNUSEDARG * h,u32 E1000_UNUSEDARG a)132379ebbe7SSepherosa Ziehau void e1000_null_update_mc(struct e1000_hw E1000_UNUSEDARG *hw,
133379ebbe7SSepherosa Ziehau 			  u8 E1000_UNUSEDARG *h, u32 E1000_UNUSEDARG a)
1349c80d176SSepherosa Ziehau {
1359c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_null_update_mc");
1369c80d176SSepherosa Ziehau 	return;
1379c80d176SSepherosa Ziehau }
1389c80d176SSepherosa Ziehau 
1399c80d176SSepherosa Ziehau /**
1409c80d176SSepherosa Ziehau  *  e1000_null_write_vfta - No-op function, return void
1419c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
142*01a55482SSepherosa Ziehau  *  @a: dummy variable
143*01a55482SSepherosa Ziehau  *  @b: dummy variable
1449c80d176SSepherosa Ziehau  **/
e1000_null_write_vfta(struct e1000_hw E1000_UNUSEDARG * hw,u32 E1000_UNUSEDARG a,u32 E1000_UNUSEDARG b)145379ebbe7SSepherosa Ziehau void e1000_null_write_vfta(struct e1000_hw E1000_UNUSEDARG *hw,
146379ebbe7SSepherosa Ziehau 			   u32 E1000_UNUSEDARG a, u32 E1000_UNUSEDARG b)
1479c80d176SSepherosa Ziehau {
1489c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_null_write_vfta");
1499c80d176SSepherosa Ziehau 	return;
1509c80d176SSepherosa Ziehau }
1519c80d176SSepherosa Ziehau 
1529c80d176SSepherosa Ziehau /**
1534765c386SMichael Neumann  *  e1000_null_rar_set - No-op function, return 0
1549c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
155*01a55482SSepherosa Ziehau  *  @h: dummy variable
156*01a55482SSepherosa Ziehau  *  @a: dummy variable
1579c80d176SSepherosa Ziehau  **/
e1000_null_rar_set(struct e1000_hw E1000_UNUSEDARG * hw,u8 E1000_UNUSEDARG * h,u32 E1000_UNUSEDARG a)1584765c386SMichael Neumann int e1000_null_rar_set(struct e1000_hw E1000_UNUSEDARG *hw,
159379ebbe7SSepherosa Ziehau 			u8 E1000_UNUSEDARG *h, u32 E1000_UNUSEDARG a)
1609c80d176SSepherosa Ziehau {
1619c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_null_rar_set");
1624765c386SMichael Neumann 	return E1000_SUCCESS;
1639c80d176SSepherosa Ziehau }
1649c80d176SSepherosa Ziehau 
1659c80d176SSepherosa Ziehau /**
166379ebbe7SSepherosa Ziehau  *  e1000_null_set_obff_timer - No-op function, return 0
167379ebbe7SSepherosa Ziehau  *  @hw: pointer to the HW structure
168379ebbe7SSepherosa Ziehau  **/
e1000_null_set_obff_timer(struct e1000_hw E1000_UNUSEDARG * hw,u32 E1000_UNUSEDARG a)169379ebbe7SSepherosa Ziehau s32 e1000_null_set_obff_timer(struct e1000_hw E1000_UNUSEDARG *hw,
170379ebbe7SSepherosa Ziehau 			      u32 E1000_UNUSEDARG a)
171379ebbe7SSepherosa Ziehau {
172379ebbe7SSepherosa Ziehau 	DEBUGFUNC("e1000_null_set_obff_timer");
173379ebbe7SSepherosa Ziehau 	return E1000_SUCCESS;
174379ebbe7SSepherosa Ziehau }
175379ebbe7SSepherosa Ziehau 
176379ebbe7SSepherosa Ziehau /**
1779c80d176SSepherosa Ziehau  *  e1000_get_bus_info_pci_generic - Get PCI(x) bus information
1789c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
1799c80d176SSepherosa Ziehau  *
1809c80d176SSepherosa Ziehau  *  Determines and stores the system bus information for a particular
1819c80d176SSepherosa Ziehau  *  network interface.  The following bus information is determined and stored:
1829c80d176SSepherosa Ziehau  *  bus speed, bus width, type (PCI/PCIx), and PCI(-x) function.
1839c80d176SSepherosa Ziehau  **/
e1000_get_bus_info_pci_generic(struct e1000_hw * hw)1849c80d176SSepherosa Ziehau s32 e1000_get_bus_info_pci_generic(struct e1000_hw *hw)
1859c80d176SSepherosa Ziehau {
1869c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
1879c80d176SSepherosa Ziehau 	struct e1000_bus_info *bus = &hw->bus;
1889c80d176SSepherosa Ziehau 	u32 status = E1000_READ_REG(hw, E1000_STATUS);
1899c80d176SSepherosa Ziehau 	s32 ret_val = E1000_SUCCESS;
1909c80d176SSepherosa Ziehau 
1919c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_get_bus_info_pci_generic");
1929c80d176SSepherosa Ziehau 
1939c80d176SSepherosa Ziehau 	/* PCI or PCI-X? */
1949c80d176SSepherosa Ziehau 	bus->type = (status & E1000_STATUS_PCIX_MODE)
1959c80d176SSepherosa Ziehau 			? e1000_bus_type_pcix
1969c80d176SSepherosa Ziehau 			: e1000_bus_type_pci;
1979c80d176SSepherosa Ziehau 
1989c80d176SSepherosa Ziehau 	/* Bus speed */
1999c80d176SSepherosa Ziehau 	if (bus->type == e1000_bus_type_pci) {
2009c80d176SSepherosa Ziehau 		bus->speed = (status & E1000_STATUS_PCI66)
2019c80d176SSepherosa Ziehau 			     ? e1000_bus_speed_66
2029c80d176SSepherosa Ziehau 			     : e1000_bus_speed_33;
2039c80d176SSepherosa Ziehau 	} else {
2049c80d176SSepherosa Ziehau 		switch (status & E1000_STATUS_PCIX_SPEED) {
2059c80d176SSepherosa Ziehau 		case E1000_STATUS_PCIX_SPEED_66:
2069c80d176SSepherosa Ziehau 			bus->speed = e1000_bus_speed_66;
2079c80d176SSepherosa Ziehau 			break;
2089c80d176SSepherosa Ziehau 		case E1000_STATUS_PCIX_SPEED_100:
2099c80d176SSepherosa Ziehau 			bus->speed = e1000_bus_speed_100;
2109c80d176SSepherosa Ziehau 			break;
2119c80d176SSepherosa Ziehau 		case E1000_STATUS_PCIX_SPEED_133:
2129c80d176SSepherosa Ziehau 			bus->speed = e1000_bus_speed_133;
2139c80d176SSepherosa Ziehau 			break;
2149c80d176SSepherosa Ziehau 		default:
2159c80d176SSepherosa Ziehau 			bus->speed = e1000_bus_speed_reserved;
2169c80d176SSepherosa Ziehau 			break;
2179c80d176SSepherosa Ziehau 		}
2189c80d176SSepherosa Ziehau 	}
2199c80d176SSepherosa Ziehau 
2209c80d176SSepherosa Ziehau 	/* Bus width */
2219c80d176SSepherosa Ziehau 	bus->width = (status & E1000_STATUS_BUS64)
2229c80d176SSepherosa Ziehau 		     ? e1000_bus_width_64
2239c80d176SSepherosa Ziehau 		     : e1000_bus_width_32;
2249c80d176SSepherosa Ziehau 
2259c80d176SSepherosa Ziehau 	/* Which PCI(-X) function? */
2269c80d176SSepherosa Ziehau 	mac->ops.set_lan_id(hw);
2279c80d176SSepherosa Ziehau 
2289c80d176SSepherosa Ziehau 	return ret_val;
2299c80d176SSepherosa Ziehau }
2309c80d176SSepherosa Ziehau 
2319c80d176SSepherosa Ziehau /**
2329c80d176SSepherosa Ziehau  *  e1000_get_bus_info_pcie_generic - Get PCIe bus information
2339c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
2349c80d176SSepherosa Ziehau  *
2359c80d176SSepherosa Ziehau  *  Determines and stores the system bus information for a particular
2369c80d176SSepherosa Ziehau  *  network interface.  The following bus information is determined and stored:
2379c80d176SSepherosa Ziehau  *  bus speed, bus width, type (PCIe), and PCIe function.
2389c80d176SSepherosa Ziehau  **/
e1000_get_bus_info_pcie_generic(struct e1000_hw * hw)2399c80d176SSepherosa Ziehau s32 e1000_get_bus_info_pcie_generic(struct e1000_hw *hw)
2409c80d176SSepherosa Ziehau {
2419c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
2429c80d176SSepherosa Ziehau 	struct e1000_bus_info *bus = &hw->bus;
2439c80d176SSepherosa Ziehau 	s32 ret_val;
2449c80d176SSepherosa Ziehau 	u16 pcie_link_status;
2459c80d176SSepherosa Ziehau 
2469c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_get_bus_info_pcie_generic");
2479c80d176SSepherosa Ziehau 
2489c80d176SSepherosa Ziehau 	bus->type = e1000_bus_type_pci_express;
2499c80d176SSepherosa Ziehau 
2504be59a01SSepherosa Ziehau 	ret_val = e1000_read_pcie_cap_reg(hw, PCIE_LINK_STATUS,
2519c80d176SSepherosa Ziehau 					  &pcie_link_status);
2526a5a645eSSepherosa Ziehau 	if (ret_val) {
2539c80d176SSepherosa Ziehau 		bus->width = e1000_bus_width_unknown;
2546a5a645eSSepherosa Ziehau 		bus->speed = e1000_bus_speed_unknown;
2556a5a645eSSepherosa Ziehau 	} else {
2566a5a645eSSepherosa Ziehau 		switch (pcie_link_status & PCIE_LINK_SPEED_MASK) {
2576a5a645eSSepherosa Ziehau 		case PCIE_LINK_SPEED_2500:
2586a5a645eSSepherosa Ziehau 			bus->speed = e1000_bus_speed_2500;
2596a5a645eSSepherosa Ziehau 			break;
2606a5a645eSSepherosa Ziehau 		case PCIE_LINK_SPEED_5000:
2616a5a645eSSepherosa Ziehau 			bus->speed = e1000_bus_speed_5000;
2626a5a645eSSepherosa Ziehau 			break;
2636a5a645eSSepherosa Ziehau 		default:
2646a5a645eSSepherosa Ziehau 			bus->speed = e1000_bus_speed_unknown;
2656a5a645eSSepherosa Ziehau 			break;
2666a5a645eSSepherosa Ziehau 		}
2676a5a645eSSepherosa Ziehau 
2689c80d176SSepherosa Ziehau 		bus->width = (enum e1000_bus_width)((pcie_link_status &
2694be59a01SSepherosa Ziehau 			      PCIE_LINK_WIDTH_MASK) >> PCIE_LINK_WIDTH_SHIFT);
2706a5a645eSSepherosa Ziehau 	}
2719c80d176SSepherosa Ziehau 
2729c80d176SSepherosa Ziehau 	mac->ops.set_lan_id(hw);
2739c80d176SSepherosa Ziehau 
2749c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
2759c80d176SSepherosa Ziehau }
2769c80d176SSepherosa Ziehau 
2779c80d176SSepherosa Ziehau /**
2789c80d176SSepherosa Ziehau  *  e1000_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
2799c80d176SSepherosa Ziehau  *
2809c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
2819c80d176SSepherosa Ziehau  *
2829c80d176SSepherosa Ziehau  *  Determines the LAN function id by reading memory-mapped registers
2839c80d176SSepherosa Ziehau  *  and swaps the port value if requested.
2849c80d176SSepherosa Ziehau  **/
e1000_set_lan_id_multi_port_pcie(struct e1000_hw * hw)2856a5a645eSSepherosa Ziehau static void e1000_set_lan_id_multi_port_pcie(struct e1000_hw *hw)
2869c80d176SSepherosa Ziehau {
2879c80d176SSepherosa Ziehau 	struct e1000_bus_info *bus = &hw->bus;
2889c80d176SSepherosa Ziehau 	u32 reg;
2899c80d176SSepherosa Ziehau 
290379ebbe7SSepherosa Ziehau 	/* The status register reports the correct function number
2916a5a645eSSepherosa Ziehau 	 * for the device regardless of function swap state.
2926a5a645eSSepherosa Ziehau 	 */
2939c80d176SSepherosa Ziehau 	reg = E1000_READ_REG(hw, E1000_STATUS);
2949c80d176SSepherosa Ziehau 	bus->func = (reg & E1000_STATUS_FUNC_MASK) >> E1000_STATUS_FUNC_SHIFT;
2959c80d176SSepherosa Ziehau }
2969c80d176SSepherosa Ziehau 
2979c80d176SSepherosa Ziehau /**
2989c80d176SSepherosa Ziehau  *  e1000_set_lan_id_multi_port_pci - Set LAN id for PCI multiple port devices
2999c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
3009c80d176SSepherosa Ziehau  *
3019c80d176SSepherosa Ziehau  *  Determines the LAN function id by reading PCI config space.
3029c80d176SSepherosa Ziehau  **/
e1000_set_lan_id_multi_port_pci(struct e1000_hw * hw)3039c80d176SSepherosa Ziehau void e1000_set_lan_id_multi_port_pci(struct e1000_hw *hw)
3049c80d176SSepherosa Ziehau {
3059c80d176SSepherosa Ziehau 	struct e1000_bus_info *bus = &hw->bus;
3069c80d176SSepherosa Ziehau 	u16 pci_header_type;
3079c80d176SSepherosa Ziehau 	u32 status;
3089c80d176SSepherosa Ziehau 
3099c80d176SSepherosa Ziehau 	e1000_read_pci_cfg(hw, PCI_HEADER_TYPE_REGISTER, &pci_header_type);
3109c80d176SSepherosa Ziehau 	if (pci_header_type & PCI_HEADER_TYPE_MULTIFUNC) {
3119c80d176SSepherosa Ziehau 		status = E1000_READ_REG(hw, E1000_STATUS);
3129c80d176SSepherosa Ziehau 		bus->func = (status & E1000_STATUS_FUNC_MASK)
3139c80d176SSepherosa Ziehau 			    >> E1000_STATUS_FUNC_SHIFT;
3149c80d176SSepherosa Ziehau 	} else {
3159c80d176SSepherosa Ziehau 		bus->func = 0;
3169c80d176SSepherosa Ziehau 	}
3179c80d176SSepherosa Ziehau }
3189c80d176SSepherosa Ziehau 
3199c80d176SSepherosa Ziehau /**
3209c80d176SSepherosa Ziehau  *  e1000_set_lan_id_single_port - Set LAN id for a single port device
3219c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
3229c80d176SSepherosa Ziehau  *
3239c80d176SSepherosa Ziehau  *  Sets the LAN function id to zero for a single port device.
3249c80d176SSepherosa Ziehau  **/
e1000_set_lan_id_single_port(struct e1000_hw * hw)3259c80d176SSepherosa Ziehau void e1000_set_lan_id_single_port(struct e1000_hw *hw)
3269c80d176SSepherosa Ziehau {
3279c80d176SSepherosa Ziehau 	struct e1000_bus_info *bus = &hw->bus;
3289c80d176SSepherosa Ziehau 
3299c80d176SSepherosa Ziehau 	bus->func = 0;
3309c80d176SSepherosa Ziehau }
3319c80d176SSepherosa Ziehau 
3329c80d176SSepherosa Ziehau /**
3339c80d176SSepherosa Ziehau  *  e1000_clear_vfta_generic - Clear VLAN filter table
3349c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
3359c80d176SSepherosa Ziehau  *
3369c80d176SSepherosa Ziehau  *  Clears the register array which contains the VLAN filter table by
3379c80d176SSepherosa Ziehau  *  setting all the values to 0.
3389c80d176SSepherosa Ziehau  **/
e1000_clear_vfta_generic(struct e1000_hw * hw)3399c80d176SSepherosa Ziehau void e1000_clear_vfta_generic(struct e1000_hw *hw)
3409c80d176SSepherosa Ziehau {
3419c80d176SSepherosa Ziehau 	u32 offset;
3429c80d176SSepherosa Ziehau 
3439c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_clear_vfta_generic");
3449c80d176SSepherosa Ziehau 
3459c80d176SSepherosa Ziehau 	for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
3469c80d176SSepherosa Ziehau 		E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, 0);
3479c80d176SSepherosa Ziehau 		E1000_WRITE_FLUSH(hw);
3489c80d176SSepherosa Ziehau 	}
3499c80d176SSepherosa Ziehau }
3509c80d176SSepherosa Ziehau 
3519c80d176SSepherosa Ziehau /**
3529c80d176SSepherosa Ziehau  *  e1000_write_vfta_generic - Write value to VLAN filter table
3539c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
3549c80d176SSepherosa Ziehau  *  @offset: register offset in VLAN filter table
3559c80d176SSepherosa Ziehau  *  @value: register value written to VLAN filter table
3569c80d176SSepherosa Ziehau  *
3579c80d176SSepherosa Ziehau  *  Writes value at the given offset in the register array which stores
3589c80d176SSepherosa Ziehau  *  the VLAN filter table.
3599c80d176SSepherosa Ziehau  **/
e1000_write_vfta_generic(struct e1000_hw * hw,u32 offset,u32 value)3609c80d176SSepherosa Ziehau void e1000_write_vfta_generic(struct e1000_hw *hw, u32 offset, u32 value)
3619c80d176SSepherosa Ziehau {
3629c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_write_vfta_generic");
3639c80d176SSepherosa Ziehau 
3649c80d176SSepherosa Ziehau 	E1000_WRITE_REG_ARRAY(hw, E1000_VFTA, offset, value);
3659c80d176SSepherosa Ziehau 	E1000_WRITE_FLUSH(hw);
3669c80d176SSepherosa Ziehau }
3679c80d176SSepherosa Ziehau 
3689c80d176SSepherosa Ziehau /**
3699c80d176SSepherosa Ziehau  *  e1000_init_rx_addrs_generic - Initialize receive address's
3709c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
3719c80d176SSepherosa Ziehau  *  @rar_count: receive address registers
3729c80d176SSepherosa Ziehau  *
3736d5e2922SSepherosa Ziehau  *  Setup the receive address registers by setting the base receive address
3749c80d176SSepherosa Ziehau  *  register to the devices MAC address and clearing all the other receive
3759c80d176SSepherosa Ziehau  *  address registers to 0.
3769c80d176SSepherosa Ziehau  **/
e1000_init_rx_addrs_generic(struct e1000_hw * hw,u16 rar_count)3779c80d176SSepherosa Ziehau void e1000_init_rx_addrs_generic(struct e1000_hw *hw, u16 rar_count)
3789c80d176SSepherosa Ziehau {
3799c80d176SSepherosa Ziehau 	u32 i;
3806a5a645eSSepherosa Ziehau 	u8 mac_addr[ETH_ADDR_LEN] = {0};
3819c80d176SSepherosa Ziehau 
3829c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_init_rx_addrs_generic");
3839c80d176SSepherosa Ziehau 
3849c80d176SSepherosa Ziehau 	/* Setup the receive address */
3859c80d176SSepherosa Ziehau 	DEBUGOUT("Programming MAC Address into RAR[0]\n");
3869c80d176SSepherosa Ziehau 
3879c80d176SSepherosa Ziehau 	hw->mac.ops.rar_set(hw, hw->mac.addr, 0);
3889c80d176SSepherosa Ziehau 
3899c80d176SSepherosa Ziehau 	/* Zero out the other (rar_entry_count - 1) receive addresses */
3909c80d176SSepherosa Ziehau 	DEBUGOUT1("Clearing RAR[1-%u]\n", rar_count-1);
3916a5a645eSSepherosa Ziehau 	for (i = 1; i < rar_count; i++)
3926a5a645eSSepherosa Ziehau 		hw->mac.ops.rar_set(hw, mac_addr, i);
3939c80d176SSepherosa Ziehau }
3949c80d176SSepherosa Ziehau 
3959c80d176SSepherosa Ziehau /**
3969c80d176SSepherosa Ziehau  *  e1000_check_alt_mac_addr_generic - Check for alternate MAC addr
3979c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
3989c80d176SSepherosa Ziehau  *
3999c80d176SSepherosa Ziehau  *  Checks the nvm for an alternate MAC address.  An alternate MAC address
4009c80d176SSepherosa Ziehau  *  can be setup by pre-boot software and must be treated like a permanent
4019c80d176SSepherosa Ziehau  *  address and must override the actual permanent MAC address. If an
4026a5a645eSSepherosa Ziehau  *  alternate MAC address is found it is programmed into RAR0, replacing
4036a5a645eSSepherosa Ziehau  *  the permanent address that was installed into RAR0 by the Si on reset.
4046a5a645eSSepherosa Ziehau  *  This function will return SUCCESS unless it encounters an error while
4056a5a645eSSepherosa Ziehau  *  reading the EEPROM.
4069c80d176SSepherosa Ziehau  **/
e1000_check_alt_mac_addr_generic(struct e1000_hw * hw)4079c80d176SSepherosa Ziehau s32 e1000_check_alt_mac_addr_generic(struct e1000_hw *hw)
4089c80d176SSepherosa Ziehau {
4099c80d176SSepherosa Ziehau 	u32 i;
410379ebbe7SSepherosa Ziehau 	s32 ret_val;
4119c80d176SSepherosa Ziehau 	u16 offset, nvm_alt_mac_addr_offset, nvm_data;
4129c80d176SSepherosa Ziehau 	u8 alt_mac_addr[ETH_ADDR_LEN];
4139c80d176SSepherosa Ziehau 
4149c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_check_alt_mac_addr_generic");
4159c80d176SSepherosa Ziehau 
4166a5a645eSSepherosa Ziehau 	ret_val = hw->nvm.ops.read(hw, NVM_COMPAT, 1, &nvm_data);
4176a5a645eSSepherosa Ziehau 	if (ret_val)
4184be59a01SSepherosa Ziehau 		return ret_val;
4196a5a645eSSepherosa Ziehau 
42065aebe9fSSepherosa Ziehau 	/* not supported on older hardware or 82573.
42165aebe9fSSepherosa Ziehau 	 *
42265aebe9fSSepherosa Ziehau 	 * Alternate MAC address is handled by the option ROM for 82580
4234be59a01SSepherosa Ziehau 	 * and newer. SW support not required.
4244be59a01SSepherosa Ziehau 	 */
42565aebe9fSSepherosa Ziehau 	if ((hw->mac.type < e1000_82571) || (hw->mac.type == e1000_82573) ||
42665aebe9fSSepherosa Ziehau 	    hw->mac.type >= e1000_82580)
4274be59a01SSepherosa Ziehau 		return E1000_SUCCESS;
4286a5a645eSSepherosa Ziehau 
4299c80d176SSepherosa Ziehau 	ret_val = hw->nvm.ops.read(hw, NVM_ALT_MAC_ADDR_PTR, 1,
4309c80d176SSepherosa Ziehau 				   &nvm_alt_mac_addr_offset);
4319c80d176SSepherosa Ziehau 	if (ret_val) {
4329c80d176SSepherosa Ziehau 		DEBUGOUT("NVM Read Error\n");
4334be59a01SSepherosa Ziehau 		return ret_val;
4349c80d176SSepherosa Ziehau 	}
4359c80d176SSepherosa Ziehau 
4364be59a01SSepherosa Ziehau 	if ((nvm_alt_mac_addr_offset == 0xFFFF) ||
4374be59a01SSepherosa Ziehau 	    (nvm_alt_mac_addr_offset == 0x0000))
4386a5a645eSSepherosa Ziehau 		/* There is no Alternate MAC Address */
4394be59a01SSepherosa Ziehau 		return E1000_SUCCESS;
4409c80d176SSepherosa Ziehau 
4419c80d176SSepherosa Ziehau 	if (hw->bus.func == E1000_FUNC_1)
4426a5a645eSSepherosa Ziehau 		nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN1;
4436a5a645eSSepherosa Ziehau 	if (hw->bus.func == E1000_FUNC_2)
4446a5a645eSSepherosa Ziehau 		nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN2;
4459c80d176SSepherosa Ziehau 
4466a5a645eSSepherosa Ziehau 	if (hw->bus.func == E1000_FUNC_3)
4476a5a645eSSepherosa Ziehau 		nvm_alt_mac_addr_offset += E1000_ALT_MAC_ADDRESS_OFFSET_LAN3;
4489c80d176SSepherosa Ziehau 	for (i = 0; i < ETH_ADDR_LEN; i += 2) {
4499c80d176SSepherosa Ziehau 		offset = nvm_alt_mac_addr_offset + (i >> 1);
4509c80d176SSepherosa Ziehau 		ret_val = hw->nvm.ops.read(hw, offset, 1, &nvm_data);
4519c80d176SSepherosa Ziehau 		if (ret_val) {
4529c80d176SSepherosa Ziehau 			DEBUGOUT("NVM Read Error\n");
4534be59a01SSepherosa Ziehau 			return ret_val;
4549c80d176SSepherosa Ziehau 		}
4559c80d176SSepherosa Ziehau 
4569c80d176SSepherosa Ziehau 		alt_mac_addr[i] = (u8)(nvm_data & 0xFF);
4579c80d176SSepherosa Ziehau 		alt_mac_addr[i + 1] = (u8)(nvm_data >> 8);
4589c80d176SSepherosa Ziehau 	}
4599c80d176SSepherosa Ziehau 
4609c80d176SSepherosa Ziehau 	/* if multicast bit is set, the alternate address will not be used */
4619c80d176SSepherosa Ziehau 	if (alt_mac_addr[0] & 0x01) {
4626a5a645eSSepherosa Ziehau 		DEBUGOUT("Ignoring Alternate Mac Address with MC bit set\n");
4634be59a01SSepherosa Ziehau 		return E1000_SUCCESS;
4649c80d176SSepherosa Ziehau 	}
4659c80d176SSepherosa Ziehau 
466379ebbe7SSepherosa Ziehau 	/* We have a valid alternate MAC address, and we want to treat it the
4676a5a645eSSepherosa Ziehau 	 * same as the normal permanent MAC address stored by the HW into the
4686a5a645eSSepherosa Ziehau 	 * RAR. Do this by mapping this address into RAR0.
4696a5a645eSSepherosa Ziehau 	 */
4706a5a645eSSepherosa Ziehau 	hw->mac.ops.rar_set(hw, alt_mac_addr, 0);
4719c80d176SSepherosa Ziehau 
4724be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
4739c80d176SSepherosa Ziehau }
4749c80d176SSepherosa Ziehau 
4759c80d176SSepherosa Ziehau /**
4769c80d176SSepherosa Ziehau  *  e1000_rar_set_generic - Set receive address register
4779c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
4789c80d176SSepherosa Ziehau  *  @addr: pointer to the receive address
4799c80d176SSepherosa Ziehau  *  @index: receive address array register
4809c80d176SSepherosa Ziehau  *
4819c80d176SSepherosa Ziehau  *  Sets the receive address array register at index to the address passed
4829c80d176SSepherosa Ziehau  *  in by addr.
4839c80d176SSepherosa Ziehau  **/
e1000_rar_set_generic(struct e1000_hw * hw,u8 * addr,u32 index)484*01a55482SSepherosa Ziehau int e1000_rar_set_generic(struct e1000_hw *hw, u8 *addr, u32 index)
4859c80d176SSepherosa Ziehau {
4869c80d176SSepherosa Ziehau 	u32 rar_low, rar_high;
4879c80d176SSepherosa Ziehau 
4889c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_rar_set_generic");
4899c80d176SSepherosa Ziehau 
490379ebbe7SSepherosa Ziehau 	/* HW expects these in little endian so we reverse the byte order
4919c80d176SSepherosa Ziehau 	 * from network order (big endian) to little endian
4929c80d176SSepherosa Ziehau 	 */
4934be59a01SSepherosa Ziehau 	rar_low = ((u32) addr[0] | ((u32) addr[1] << 8) |
4949c80d176SSepherosa Ziehau 		   ((u32) addr[2] << 16) | ((u32) addr[3] << 24));
4959c80d176SSepherosa Ziehau 
4969c80d176SSepherosa Ziehau 	rar_high = ((u32) addr[4] | ((u32) addr[5] << 8));
4979c80d176SSepherosa Ziehau 
4989c80d176SSepherosa Ziehau 	/* If MAC address zero, no need to set the AV bit */
4999c80d176SSepherosa Ziehau 	if (rar_low || rar_high)
5009c80d176SSepherosa Ziehau 		rar_high |= E1000_RAH_AV;
5019c80d176SSepherosa Ziehau 
502379ebbe7SSepherosa Ziehau 	/* Some bridges will combine consecutive 32-bit writes into
5036a5a645eSSepherosa Ziehau 	 * a single burst write, which will malfunction on some parts.
5046a5a645eSSepherosa Ziehau 	 * The flushes avoid this.
5059c80d176SSepherosa Ziehau 	 */
5066a5a645eSSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_RAL(index), rar_low);
5076a5a645eSSepherosa Ziehau 	E1000_WRITE_FLUSH(hw);
5086a5a645eSSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_RAH(index), rar_high);
5099c80d176SSepherosa Ziehau 	E1000_WRITE_FLUSH(hw);
5104765c386SMichael Neumann 
5114765c386SMichael Neumann 	return E1000_SUCCESS;
5129c80d176SSepherosa Ziehau }
5139c80d176SSepherosa Ziehau 
5149c80d176SSepherosa Ziehau /**
5159c80d176SSepherosa Ziehau  *  e1000_hash_mc_addr_generic - Generate a multicast hash value
5169c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
5179c80d176SSepherosa Ziehau  *  @mc_addr: pointer to a multicast address
5189c80d176SSepherosa Ziehau  *
5199c80d176SSepherosa Ziehau  *  Generates a multicast address hash value which is used to determine
5206a5a645eSSepherosa Ziehau  *  the multicast filter table array address and new table value.
5219c80d176SSepherosa Ziehau  **/
e1000_hash_mc_addr_generic(struct e1000_hw * hw,u8 * mc_addr)5229c80d176SSepherosa Ziehau u32 e1000_hash_mc_addr_generic(struct e1000_hw *hw, u8 *mc_addr)
5239c80d176SSepherosa Ziehau {
5249c80d176SSepherosa Ziehau 	u32 hash_value, hash_mask;
5259c80d176SSepherosa Ziehau 	u8 bit_shift = 0;
5269c80d176SSepherosa Ziehau 
5279c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_hash_mc_addr_generic");
5289c80d176SSepherosa Ziehau 
5299c80d176SSepherosa Ziehau 	/* Register count multiplied by bits per register */
5309c80d176SSepherosa Ziehau 	hash_mask = (hw->mac.mta_reg_count * 32) - 1;
5319c80d176SSepherosa Ziehau 
532379ebbe7SSepherosa Ziehau 	/* For a mc_filter_type of 0, bit_shift is the number of left-shifts
5339c80d176SSepherosa Ziehau 	 * where 0xFF would still fall within the hash mask.
5349c80d176SSepherosa Ziehau 	 */
5359c80d176SSepherosa Ziehau 	while (hash_mask >> bit_shift != 0xFF)
5369c80d176SSepherosa Ziehau 		bit_shift++;
5379c80d176SSepherosa Ziehau 
538379ebbe7SSepherosa Ziehau 	/* The portion of the address that is used for the hash table
5399c80d176SSepherosa Ziehau 	 * is determined by the mc_filter_type setting.
5409c80d176SSepherosa Ziehau 	 * The algorithm is such that there is a total of 8 bits of shifting.
5419c80d176SSepherosa Ziehau 	 * The bit_shift for a mc_filter_type of 0 represents the number of
5429c80d176SSepherosa Ziehau 	 * left-shifts where the MSB of mc_addr[5] would still fall within
5439c80d176SSepherosa Ziehau 	 * the hash_mask.  Case 0 does this exactly.  Since there are a total
5449c80d176SSepherosa Ziehau 	 * of 8 bits of shifting, then mc_addr[4] will shift right the
5459c80d176SSepherosa Ziehau 	 * remaining number of bits. Thus 8 - bit_shift.  The rest of the
5469c80d176SSepherosa Ziehau 	 * cases are a variation of this algorithm...essentially raising the
5479c80d176SSepherosa Ziehau 	 * number of bits to shift mc_addr[5] left, while still keeping the
5489c80d176SSepherosa Ziehau 	 * 8-bit shifting total.
5499c80d176SSepherosa Ziehau 	 *
5509c80d176SSepherosa Ziehau 	 * For example, given the following Destination MAC Address and an
5519c80d176SSepherosa Ziehau 	 * mta register count of 128 (thus a 4096-bit vector and 0xFFF mask),
5529c80d176SSepherosa Ziehau 	 * we can see that the bit_shift for case 0 is 4.  These are the hash
5539c80d176SSepherosa Ziehau 	 * values resulting from each mc_filter_type...
5549c80d176SSepherosa Ziehau 	 * [0] [1] [2] [3] [4] [5]
5559c80d176SSepherosa Ziehau 	 * 01  AA  00  12  34  56
5569c80d176SSepherosa Ziehau 	 * LSB		 MSB
5579c80d176SSepherosa Ziehau 	 *
5589c80d176SSepherosa Ziehau 	 * case 0: hash_value = ((0x34 >> 4) | (0x56 << 4)) & 0xFFF = 0x563
5599c80d176SSepherosa Ziehau 	 * case 1: hash_value = ((0x34 >> 3) | (0x56 << 5)) & 0xFFF = 0xAC6
5609c80d176SSepherosa Ziehau 	 * case 2: hash_value = ((0x34 >> 2) | (0x56 << 6)) & 0xFFF = 0x163
5619c80d176SSepherosa Ziehau 	 * case 3: hash_value = ((0x34 >> 0) | (0x56 << 8)) & 0xFFF = 0x634
5629c80d176SSepherosa Ziehau 	 */
5639c80d176SSepherosa Ziehau 	switch (hw->mac.mc_filter_type) {
5649c80d176SSepherosa Ziehau 	default:
5659c80d176SSepherosa Ziehau 	case 0:
5669c80d176SSepherosa Ziehau 		break;
5679c80d176SSepherosa Ziehau 	case 1:
5689c80d176SSepherosa Ziehau 		bit_shift += 1;
5699c80d176SSepherosa Ziehau 		break;
5709c80d176SSepherosa Ziehau 	case 2:
5719c80d176SSepherosa Ziehau 		bit_shift += 2;
5729c80d176SSepherosa Ziehau 		break;
5739c80d176SSepherosa Ziehau 	case 3:
5749c80d176SSepherosa Ziehau 		bit_shift += 4;
5759c80d176SSepherosa Ziehau 		break;
5769c80d176SSepherosa Ziehau 	}
5779c80d176SSepherosa Ziehau 
5789c80d176SSepherosa Ziehau 	hash_value = hash_mask & (((mc_addr[4] >> (8 - bit_shift)) |
5799c80d176SSepherosa Ziehau 				  (((u16) mc_addr[5]) << bit_shift)));
5809c80d176SSepherosa Ziehau 
5819c80d176SSepherosa Ziehau 	return hash_value;
5829c80d176SSepherosa Ziehau }
5839c80d176SSepherosa Ziehau 
5849c80d176SSepherosa Ziehau /**
5854be59a01SSepherosa Ziehau  *  e1000_update_mc_addr_list_generic - Update Multicast addresses
5864be59a01SSepherosa Ziehau  *  @hw: pointer to the HW structure
5874be59a01SSepherosa Ziehau  *  @mc_addr_list: array of multicast addresses to program
5884be59a01SSepherosa Ziehau  *  @mc_addr_count: number of multicast addresses to program
5894be59a01SSepherosa Ziehau  *
5904be59a01SSepherosa Ziehau  *  Updates entire Multicast Table Array.
5914be59a01SSepherosa Ziehau  *  The caller must have a packed mc_addr_list of multicast addresses.
5924be59a01SSepherosa Ziehau  **/
e1000_update_mc_addr_list_generic(struct e1000_hw * hw,u8 * mc_addr_list,u32 mc_addr_count)5934be59a01SSepherosa Ziehau void e1000_update_mc_addr_list_generic(struct e1000_hw *hw,
5944be59a01SSepherosa Ziehau 				       u8 *mc_addr_list, u32 mc_addr_count)
5954be59a01SSepherosa Ziehau {
5964be59a01SSepherosa Ziehau 	u32 hash_value, hash_bit, hash_reg;
5974be59a01SSepherosa Ziehau 	int i;
5984be59a01SSepherosa Ziehau 
5994be59a01SSepherosa Ziehau 	DEBUGFUNC("e1000_update_mc_addr_list_generic");
6004be59a01SSepherosa Ziehau 
6014be59a01SSepherosa Ziehau 	/* clear mta_shadow */
6024be59a01SSepherosa Ziehau 	memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
6034be59a01SSepherosa Ziehau 
6044be59a01SSepherosa Ziehau 	/* update mta_shadow from mc_addr_list */
6054be59a01SSepherosa Ziehau 	for (i = 0; (u32) i < mc_addr_count; i++) {
6064be59a01SSepherosa Ziehau 		hash_value = e1000_hash_mc_addr_generic(hw, mc_addr_list);
6074be59a01SSepherosa Ziehau 
6084be59a01SSepherosa Ziehau 		hash_reg = (hash_value >> 5) & (hw->mac.mta_reg_count - 1);
6094be59a01SSepherosa Ziehau 		hash_bit = hash_value & 0x1F;
6104be59a01SSepherosa Ziehau 
6114be59a01SSepherosa Ziehau 		hw->mac.mta_shadow[hash_reg] |= (1 << hash_bit);
6124be59a01SSepherosa Ziehau 		mc_addr_list += (ETH_ADDR_LEN);
6134be59a01SSepherosa Ziehau 	}
6144be59a01SSepherosa Ziehau 
6154be59a01SSepherosa Ziehau 	/* replace the entire MTA table */
6164be59a01SSepherosa Ziehau 	for (i = hw->mac.mta_reg_count - 1; i >= 0; i--)
6174be59a01SSepherosa Ziehau 		E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, hw->mac.mta_shadow[i]);
6184be59a01SSepherosa Ziehau 	E1000_WRITE_FLUSH(hw);
6194be59a01SSepherosa Ziehau }
6204be59a01SSepherosa Ziehau 
6214be59a01SSepherosa Ziehau /**
6229c80d176SSepherosa Ziehau  *  e1000_pcix_mmrbc_workaround_generic - Fix incorrect MMRBC value
6239c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
6249c80d176SSepherosa Ziehau  *
6259c80d176SSepherosa Ziehau  *  In certain situations, a system BIOS may report that the PCIx maximum
6269c80d176SSepherosa Ziehau  *  memory read byte count (MMRBC) value is higher than than the actual
6279c80d176SSepherosa Ziehau  *  value. We check the PCIx command register with the current PCIx status
6289c80d176SSepherosa Ziehau  *  register.
6299c80d176SSepherosa Ziehau  **/
e1000_pcix_mmrbc_workaround_generic(struct e1000_hw * hw)6309c80d176SSepherosa Ziehau void e1000_pcix_mmrbc_workaround_generic(struct e1000_hw *hw)
6319c80d176SSepherosa Ziehau {
6329c80d176SSepherosa Ziehau 	u16 cmd_mmrbc;
6339c80d176SSepherosa Ziehau 	u16 pcix_cmd;
6349c80d176SSepherosa Ziehau 	u16 pcix_stat_hi_word;
6359c80d176SSepherosa Ziehau 	u16 stat_mmrbc;
6369c80d176SSepherosa Ziehau 
6379c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_pcix_mmrbc_workaround_generic");
6389c80d176SSepherosa Ziehau 
6399c80d176SSepherosa Ziehau 	/* Workaround for PCI-X issue when BIOS sets MMRBC incorrectly */
6409c80d176SSepherosa Ziehau 	if (hw->bus.type != e1000_bus_type_pcix)
6419c80d176SSepherosa Ziehau 		return;
6429c80d176SSepherosa Ziehau 
6439c80d176SSepherosa Ziehau 	e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd);
6449c80d176SSepherosa Ziehau 	e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI, &pcix_stat_hi_word);
6459c80d176SSepherosa Ziehau 	cmd_mmrbc = (pcix_cmd & PCIX_COMMAND_MMRBC_MASK) >>
6469c80d176SSepherosa Ziehau 		     PCIX_COMMAND_MMRBC_SHIFT;
6479c80d176SSepherosa Ziehau 	stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
6489c80d176SSepherosa Ziehau 		      PCIX_STATUS_HI_MMRBC_SHIFT;
6499c80d176SSepherosa Ziehau 	if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
6509c80d176SSepherosa Ziehau 		stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
6519c80d176SSepherosa Ziehau 	if (cmd_mmrbc > stat_mmrbc) {
6529c80d176SSepherosa Ziehau 		pcix_cmd &= ~PCIX_COMMAND_MMRBC_MASK;
6539c80d176SSepherosa Ziehau 		pcix_cmd |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
6549c80d176SSepherosa Ziehau 		e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd);
6559c80d176SSepherosa Ziehau 	}
6569c80d176SSepherosa Ziehau }
6579c80d176SSepherosa Ziehau 
6589c80d176SSepherosa Ziehau /**
6599c80d176SSepherosa Ziehau  *  e1000_clear_hw_cntrs_base_generic - Clear base hardware counters
6609c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
6619c80d176SSepherosa Ziehau  *
6629c80d176SSepherosa Ziehau  *  Clears the base hardware counters by reading the counter registers.
6639c80d176SSepherosa Ziehau  **/
e1000_clear_hw_cntrs_base_generic(struct e1000_hw * hw)6649c80d176SSepherosa Ziehau void e1000_clear_hw_cntrs_base_generic(struct e1000_hw *hw)
6659c80d176SSepherosa Ziehau {
6669c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_clear_hw_cntrs_base_generic");
6679c80d176SSepherosa Ziehau 
6689c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_CRCERRS);
6699c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_SYMERRS);
6709c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_MPC);
6719c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_SCC);
6729c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_ECOL);
6739c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_MCC);
6749c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_LATECOL);
6759c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_COLC);
6769c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_DC);
6779c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_SEC);
6789c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_RLEC);
6799c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_XONRXC);
6809c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_XONTXC);
6819c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_XOFFRXC);
6829c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_XOFFTXC);
6839c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_FCRUC);
6849c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_GPRC);
6859c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_BPRC);
6869c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_MPRC);
6879c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_GPTC);
6889c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_GORCL);
6899c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_GORCH);
6909c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_GOTCL);
6919c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_GOTCH);
6929c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_RNBC);
6939c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_RUC);
6949c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_RFC);
6959c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_ROC);
6969c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_RJC);
6979c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_TORL);
6989c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_TORH);
6999c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_TOTL);
7009c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_TOTH);
7019c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_TPR);
7029c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_TPT);
7039c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_MPTC);
7049c80d176SSepherosa Ziehau 	E1000_READ_REG(hw, E1000_BPTC);
7059c80d176SSepherosa Ziehau }
7069c80d176SSepherosa Ziehau 
7079c80d176SSepherosa Ziehau /**
7089c80d176SSepherosa Ziehau  *  e1000_check_for_copper_link_generic - Check for link (Copper)
7099c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
7109c80d176SSepherosa Ziehau  *
7119c80d176SSepherosa Ziehau  *  Checks to see of the link status of the hardware has changed.  If a
7129c80d176SSepherosa Ziehau  *  change in link status has been detected, then we read the PHY registers
7139c80d176SSepherosa Ziehau  *  to get the current speed/duplex if link exists.
7149c80d176SSepherosa Ziehau  **/
e1000_check_for_copper_link_generic(struct e1000_hw * hw)7159c80d176SSepherosa Ziehau s32 e1000_check_for_copper_link_generic(struct e1000_hw *hw)
7169c80d176SSepherosa Ziehau {
7179c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
7189c80d176SSepherosa Ziehau 	s32 ret_val;
7199c80d176SSepherosa Ziehau 	bool link;
7209c80d176SSepherosa Ziehau 
7219c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_check_for_copper_link");
7229c80d176SSepherosa Ziehau 
723379ebbe7SSepherosa Ziehau 	/* We only want to go out to the PHY registers to see if Auto-Neg
7249c80d176SSepherosa Ziehau 	 * has completed and/or if our link status has changed.  The
7259c80d176SSepherosa Ziehau 	 * get_link_status flag is set upon receiving a Link Status
7269c80d176SSepherosa Ziehau 	 * Change or Rx Sequence Error interrupt.
7279c80d176SSepherosa Ziehau 	 */
7284be59a01SSepherosa Ziehau 	if (!mac->get_link_status)
7294be59a01SSepherosa Ziehau 		return E1000_SUCCESS;
7309c80d176SSepherosa Ziehau 
731379ebbe7SSepherosa Ziehau 	/* First we want to see if the MII Status Register reports
7329c80d176SSepherosa Ziehau 	 * link.  If so, then we want to get the current speed/duplex
7339c80d176SSepherosa Ziehau 	 * of the PHY.
7349c80d176SSepherosa Ziehau 	 */
7359c80d176SSepherosa Ziehau 	ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
7369c80d176SSepherosa Ziehau 	if (ret_val)
7374be59a01SSepherosa Ziehau 		return ret_val;
7389c80d176SSepherosa Ziehau 
7399c80d176SSepherosa Ziehau 	if (!link)
7404be59a01SSepherosa Ziehau 		return E1000_SUCCESS; /* No link detected */
7419c80d176SSepherosa Ziehau 
7429c80d176SSepherosa Ziehau 	mac->get_link_status = FALSE;
7439c80d176SSepherosa Ziehau 
744379ebbe7SSepherosa Ziehau 	/* Check if there was DownShift, must be checked
7459c80d176SSepherosa Ziehau 	 * immediately after link-up
7469c80d176SSepherosa Ziehau 	 */
7479c80d176SSepherosa Ziehau 	e1000_check_downshift_generic(hw);
7489c80d176SSepherosa Ziehau 
749379ebbe7SSepherosa Ziehau 	/* If we are forcing speed/duplex, then we simply return since
7509c80d176SSepherosa Ziehau 	 * we have already determined whether we have link or not.
7519c80d176SSepherosa Ziehau 	 */
7524be59a01SSepherosa Ziehau 	if (!mac->autoneg)
7534be59a01SSepherosa Ziehau 		return -E1000_ERR_CONFIG;
7549c80d176SSepherosa Ziehau 
755379ebbe7SSepherosa Ziehau 	/* Auto-Neg is enabled.  Auto Speed Detection takes care
7569c80d176SSepherosa Ziehau 	 * of MAC speed/duplex configuration.  So we only need to
7579c80d176SSepherosa Ziehau 	 * configure Collision Distance in the MAC.
7589c80d176SSepherosa Ziehau 	 */
7596a5a645eSSepherosa Ziehau 	mac->ops.config_collision_dist(hw);
7609c80d176SSepherosa Ziehau 
761379ebbe7SSepherosa Ziehau 	/* Configure Flow Control now that Auto-Neg has completed.
7629c80d176SSepherosa Ziehau 	 * First, we need to restore the desired flow control
7639c80d176SSepherosa Ziehau 	 * settings because we may have had to re-autoneg with a
7649c80d176SSepherosa Ziehau 	 * different link partner.
7659c80d176SSepherosa Ziehau 	 */
7669c80d176SSepherosa Ziehau 	ret_val = e1000_config_fc_after_link_up_generic(hw);
7679c80d176SSepherosa Ziehau 	if (ret_val)
7689c80d176SSepherosa Ziehau 		DEBUGOUT("Error configuring flow control\n");
7699c80d176SSepherosa Ziehau 
7709c80d176SSepherosa Ziehau 	return ret_val;
7719c80d176SSepherosa Ziehau }
7729c80d176SSepherosa Ziehau 
7739c80d176SSepherosa Ziehau /**
7749c80d176SSepherosa Ziehau  *  e1000_check_for_fiber_link_generic - Check for link (Fiber)
7759c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
7769c80d176SSepherosa Ziehau  *
7779c80d176SSepherosa Ziehau  *  Checks for link up on the hardware.  If link is not up and we have
7789c80d176SSepherosa Ziehau  *  a signal, then we need to force link up.
7799c80d176SSepherosa Ziehau  **/
e1000_check_for_fiber_link_generic(struct e1000_hw * hw)7809c80d176SSepherosa Ziehau s32 e1000_check_for_fiber_link_generic(struct e1000_hw *hw)
7819c80d176SSepherosa Ziehau {
7829c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
7839c80d176SSepherosa Ziehau 	u32 rxcw;
7849c80d176SSepherosa Ziehau 	u32 ctrl;
7859c80d176SSepherosa Ziehau 	u32 status;
7864be59a01SSepherosa Ziehau 	s32 ret_val;
7879c80d176SSepherosa Ziehau 
7889c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_check_for_fiber_link_generic");
7899c80d176SSepherosa Ziehau 
7909c80d176SSepherosa Ziehau 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
7919c80d176SSepherosa Ziehau 	status = E1000_READ_REG(hw, E1000_STATUS);
7929c80d176SSepherosa Ziehau 	rxcw = E1000_READ_REG(hw, E1000_RXCW);
7939c80d176SSepherosa Ziehau 
794379ebbe7SSepherosa Ziehau 	/* If we don't have link (auto-negotiation failed or link partner
7959c80d176SSepherosa Ziehau 	 * cannot auto-negotiate), the cable is plugged in (we have signal),
7969c80d176SSepherosa Ziehau 	 * and our link partner is not trying to auto-negotiate with us (we
7979c80d176SSepherosa Ziehau 	 * are receiving idles or data), we need to force link up. We also
7989c80d176SSepherosa Ziehau 	 * need to give auto-negotiation time to complete, in case the cable
7999c80d176SSepherosa Ziehau 	 * was just plugged in. The autoneg_failed flag does this.
8009c80d176SSepherosa Ziehau 	 */
8019c80d176SSepherosa Ziehau 	/* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
8024be59a01SSepherosa Ziehau 	if ((ctrl & E1000_CTRL_SWDPIN1) && !(status & E1000_STATUS_LU) &&
8034be59a01SSepherosa Ziehau 	    !(rxcw & E1000_RXCW_C)) {
8044be59a01SSepherosa Ziehau 		if (!mac->autoneg_failed) {
8054be59a01SSepherosa Ziehau 			mac->autoneg_failed = TRUE;
8064be59a01SSepherosa Ziehau 			return E1000_SUCCESS;
8079c80d176SSepherosa Ziehau 		}
8086d5e2922SSepherosa Ziehau 		DEBUGOUT("NOT Rx'ing /C/, disable AutoNeg and force link.\n");
8099c80d176SSepherosa Ziehau 
8109c80d176SSepherosa Ziehau 		/* Disable auto-negotiation in the TXCW register */
8119c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
8129c80d176SSepherosa Ziehau 
8139c80d176SSepherosa Ziehau 		/* Force link-up and also force full-duplex. */
8149c80d176SSepherosa Ziehau 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
8159c80d176SSepherosa Ziehau 		ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
8169c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8179c80d176SSepherosa Ziehau 
8189c80d176SSepherosa Ziehau 		/* Configure Flow Control after forcing link up. */
8199c80d176SSepherosa Ziehau 		ret_val = e1000_config_fc_after_link_up_generic(hw);
8209c80d176SSepherosa Ziehau 		if (ret_val) {
8219c80d176SSepherosa Ziehau 			DEBUGOUT("Error configuring flow control\n");
8224be59a01SSepherosa Ziehau 			return ret_val;
8239c80d176SSepherosa Ziehau 		}
8249c80d176SSepherosa Ziehau 	} else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
825379ebbe7SSepherosa Ziehau 		/* If we are forcing link and we are receiving /C/ ordered
8269c80d176SSepherosa Ziehau 		 * sets, re-enable auto-negotiation in the TXCW register
8279c80d176SSepherosa Ziehau 		 * and disable forced link in the Device Control register
8289c80d176SSepherosa Ziehau 		 * in an attempt to auto-negotiate with our link partner.
8299c80d176SSepherosa Ziehau 		 */
8306d5e2922SSepherosa Ziehau 		DEBUGOUT("Rx'ing /C/, enable AutoNeg and stop forcing link.\n");
8319c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
8329c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
8339c80d176SSepherosa Ziehau 
8349c80d176SSepherosa Ziehau 		mac->serdes_has_link = TRUE;
8359c80d176SSepherosa Ziehau 	}
8369c80d176SSepherosa Ziehau 
8374be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
8389c80d176SSepherosa Ziehau }
8399c80d176SSepherosa Ziehau 
8409c80d176SSepherosa Ziehau /**
8419c80d176SSepherosa Ziehau  *  e1000_check_for_serdes_link_generic - Check for link (Serdes)
8429c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
8439c80d176SSepherosa Ziehau  *
8449c80d176SSepherosa Ziehau  *  Checks for link up on the hardware.  If link is not up and we have
8459c80d176SSepherosa Ziehau  *  a signal, then we need to force link up.
8469c80d176SSepherosa Ziehau  **/
e1000_check_for_serdes_link_generic(struct e1000_hw * hw)8479c80d176SSepherosa Ziehau s32 e1000_check_for_serdes_link_generic(struct e1000_hw *hw)
8489c80d176SSepherosa Ziehau {
8499c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
8509c80d176SSepherosa Ziehau 	u32 rxcw;
8519c80d176SSepherosa Ziehau 	u32 ctrl;
8529c80d176SSepherosa Ziehau 	u32 status;
8534be59a01SSepherosa Ziehau 	s32 ret_val;
8549c80d176SSepherosa Ziehau 
8559c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_check_for_serdes_link_generic");
8569c80d176SSepherosa Ziehau 
8579c80d176SSepherosa Ziehau 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
8589c80d176SSepherosa Ziehau 	status = E1000_READ_REG(hw, E1000_STATUS);
8599c80d176SSepherosa Ziehau 	rxcw = E1000_READ_REG(hw, E1000_RXCW);
8609c80d176SSepherosa Ziehau 
861379ebbe7SSepherosa Ziehau 	/* If we don't have link (auto-negotiation failed or link partner
8629c80d176SSepherosa Ziehau 	 * cannot auto-negotiate), and our link partner is not trying to
8639c80d176SSepherosa Ziehau 	 * auto-negotiate with us (we are receiving idles or data),
8649c80d176SSepherosa Ziehau 	 * we need to force link up. We also need to give auto-negotiation
8659c80d176SSepherosa Ziehau 	 * time to complete.
8669c80d176SSepherosa Ziehau 	 */
8679c80d176SSepherosa Ziehau 	/* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */
8684be59a01SSepherosa Ziehau 	if (!(status & E1000_STATUS_LU) && !(rxcw & E1000_RXCW_C)) {
8694be59a01SSepherosa Ziehau 		if (!mac->autoneg_failed) {
8704be59a01SSepherosa Ziehau 			mac->autoneg_failed = TRUE;
8714be59a01SSepherosa Ziehau 			return E1000_SUCCESS;
8729c80d176SSepherosa Ziehau 		}
8736d5e2922SSepherosa Ziehau 		DEBUGOUT("NOT Rx'ing /C/, disable AutoNeg and force link.\n");
8749c80d176SSepherosa Ziehau 
8759c80d176SSepherosa Ziehau 		/* Disable auto-negotiation in the TXCW register */
8769c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_TXCW, (mac->txcw & ~E1000_TXCW_ANE));
8779c80d176SSepherosa Ziehau 
8789c80d176SSepherosa Ziehau 		/* Force link-up and also force full-duplex. */
8799c80d176SSepherosa Ziehau 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
8809c80d176SSepherosa Ziehau 		ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
8819c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
8829c80d176SSepherosa Ziehau 
8839c80d176SSepherosa Ziehau 		/* Configure Flow Control after forcing link up. */
8849c80d176SSepherosa Ziehau 		ret_val = e1000_config_fc_after_link_up_generic(hw);
8859c80d176SSepherosa Ziehau 		if (ret_val) {
8869c80d176SSepherosa Ziehau 			DEBUGOUT("Error configuring flow control\n");
8874be59a01SSepherosa Ziehau 			return ret_val;
8889c80d176SSepherosa Ziehau 		}
8899c80d176SSepherosa Ziehau 	} else if ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
890379ebbe7SSepherosa Ziehau 		/* If we are forcing link and we are receiving /C/ ordered
8919c80d176SSepherosa Ziehau 		 * sets, re-enable auto-negotiation in the TXCW register
8929c80d176SSepherosa Ziehau 		 * and disable forced link in the Device Control register
8939c80d176SSepherosa Ziehau 		 * in an attempt to auto-negotiate with our link partner.
8949c80d176SSepherosa Ziehau 		 */
8956d5e2922SSepherosa Ziehau 		DEBUGOUT("Rx'ing /C/, enable AutoNeg and stop forcing link.\n");
8969c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_TXCW, mac->txcw);
8979c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_CTRL, (ctrl & ~E1000_CTRL_SLU));
8989c80d176SSepherosa Ziehau 
8999c80d176SSepherosa Ziehau 		mac->serdes_has_link = TRUE;
9009c80d176SSepherosa Ziehau 	} else if (!(E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW))) {
901379ebbe7SSepherosa Ziehau 		/* If we force link for non-auto-negotiation switch, check
9029c80d176SSepherosa Ziehau 		 * link status based on MAC synchronization for internal
9039c80d176SSepherosa Ziehau 		 * serdes media type.
9049c80d176SSepherosa Ziehau 		 */
9059c80d176SSepherosa Ziehau 		/* SYNCH bit and IV bit are sticky. */
9069c80d176SSepherosa Ziehau 		usec_delay(10);
9079c80d176SSepherosa Ziehau 		rxcw = E1000_READ_REG(hw, E1000_RXCW);
9089c80d176SSepherosa Ziehau 		if (rxcw & E1000_RXCW_SYNCH) {
9099c80d176SSepherosa Ziehau 			if (!(rxcw & E1000_RXCW_IV)) {
9109c80d176SSepherosa Ziehau 				mac->serdes_has_link = TRUE;
9119c80d176SSepherosa Ziehau 				DEBUGOUT("SERDES: Link up - forced.\n");
9129c80d176SSepherosa Ziehau 			}
9139c80d176SSepherosa Ziehau 		} else {
9149c80d176SSepherosa Ziehau 			mac->serdes_has_link = FALSE;
9159c80d176SSepherosa Ziehau 			DEBUGOUT("SERDES: Link down - force failed.\n");
9169c80d176SSepherosa Ziehau 		}
9179c80d176SSepherosa Ziehau 	}
9189c80d176SSepherosa Ziehau 
9199c80d176SSepherosa Ziehau 	if (E1000_TXCW_ANE & E1000_READ_REG(hw, E1000_TXCW)) {
9209c80d176SSepherosa Ziehau 		status = E1000_READ_REG(hw, E1000_STATUS);
9219c80d176SSepherosa Ziehau 		if (status & E1000_STATUS_LU) {
9229c80d176SSepherosa Ziehau 			/* SYNCH bit and IV bit are sticky, so reread rxcw. */
9239c80d176SSepherosa Ziehau 			usec_delay(10);
9249c80d176SSepherosa Ziehau 			rxcw = E1000_READ_REG(hw, E1000_RXCW);
9259c80d176SSepherosa Ziehau 			if (rxcw & E1000_RXCW_SYNCH) {
9269c80d176SSepherosa Ziehau 				if (!(rxcw & E1000_RXCW_IV)) {
9279c80d176SSepherosa Ziehau 					mac->serdes_has_link = TRUE;
9284be59a01SSepherosa Ziehau 					DEBUGOUT("SERDES: Link up - autoneg completed successfully.\n");
9299c80d176SSepherosa Ziehau 				} else {
9309c80d176SSepherosa Ziehau 					mac->serdes_has_link = FALSE;
9314be59a01SSepherosa Ziehau 					DEBUGOUT("SERDES: Link down - invalid codewords detected in autoneg.\n");
9329c80d176SSepherosa Ziehau 				}
9339c80d176SSepherosa Ziehau 			} else {
9349c80d176SSepherosa Ziehau 				mac->serdes_has_link = FALSE;
9359c80d176SSepherosa Ziehau 				DEBUGOUT("SERDES: Link down - no sync.\n");
9369c80d176SSepherosa Ziehau 			}
9379c80d176SSepherosa Ziehau 		} else {
9389c80d176SSepherosa Ziehau 			mac->serdes_has_link = FALSE;
9399c80d176SSepherosa Ziehau 			DEBUGOUT("SERDES: Link down - autoneg failed\n");
9409c80d176SSepherosa Ziehau 		}
9419c80d176SSepherosa Ziehau 	}
9429c80d176SSepherosa Ziehau 
9434be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
9444be59a01SSepherosa Ziehau }
9454be59a01SSepherosa Ziehau 
9464be59a01SSepherosa Ziehau /**
9474be59a01SSepherosa Ziehau  *  e1000_set_default_fc_generic - Set flow control default values
9484be59a01SSepherosa Ziehau  *  @hw: pointer to the HW structure
9494be59a01SSepherosa Ziehau  *
9504be59a01SSepherosa Ziehau  *  Read the EEPROM for the default values for flow control and store the
9514be59a01SSepherosa Ziehau  *  values.
9524be59a01SSepherosa Ziehau  **/
e1000_set_default_fc_generic(struct e1000_hw * hw)9534be59a01SSepherosa Ziehau s32 e1000_set_default_fc_generic(struct e1000_hw *hw)
9544be59a01SSepherosa Ziehau {
9554be59a01SSepherosa Ziehau 	s32 ret_val;
9564be59a01SSepherosa Ziehau 	u16 nvm_data;
957ba0123e0SSepherosa Ziehau 	u16 nvm_offset = 0;
9584be59a01SSepherosa Ziehau 
9594be59a01SSepherosa Ziehau 	DEBUGFUNC("e1000_set_default_fc_generic");
9604be59a01SSepherosa Ziehau 
961379ebbe7SSepherosa Ziehau 	/* Read and store word 0x0F of the EEPROM. This word contains bits
9624be59a01SSepherosa Ziehau 	 * that determine the hardware's default PAUSE (flow control) mode,
9634be59a01SSepherosa Ziehau 	 * a bit that determines whether the HW defaults to enabling or
9644be59a01SSepherosa Ziehau 	 * disabling auto-negotiation, and the direction of the
9654be59a01SSepherosa Ziehau 	 * SW defined pins. If there is no SW over-ride of the flow
9664be59a01SSepherosa Ziehau 	 * control setting, then the variable hw->fc will
9674be59a01SSepherosa Ziehau 	 * be initialized based on a value in the EEPROM.
9684be59a01SSepherosa Ziehau 	 */
969ba0123e0SSepherosa Ziehau 	if (hw->mac.type == e1000_i350) {
970ba0123e0SSepherosa Ziehau 		nvm_offset = NVM_82580_LAN_FUNC_OFFSET(hw->bus.func);
971ba0123e0SSepherosa Ziehau 		ret_val = hw->nvm.ops.read(hw,
972ba0123e0SSepherosa Ziehau 					   NVM_INIT_CONTROL2_REG +
973ba0123e0SSepherosa Ziehau 					   nvm_offset,
974ba0123e0SSepherosa Ziehau 					   1, &nvm_data);
975ba0123e0SSepherosa Ziehau 	} else {
976ba0123e0SSepherosa Ziehau 		ret_val = hw->nvm.ops.read(hw,
977ba0123e0SSepherosa Ziehau 					   NVM_INIT_CONTROL2_REG,
978ba0123e0SSepherosa Ziehau 					   1, &nvm_data);
979ba0123e0SSepherosa Ziehau 	}
980ba0123e0SSepherosa Ziehau 
9814be59a01SSepherosa Ziehau 
9824be59a01SSepherosa Ziehau 	if (ret_val) {
9834be59a01SSepherosa Ziehau 		DEBUGOUT("NVM Read Error\n");
9849c80d176SSepherosa Ziehau 		return ret_val;
9859c80d176SSepherosa Ziehau 	}
9869c80d176SSepherosa Ziehau 
9874be59a01SSepherosa Ziehau 	if (!(nvm_data & NVM_WORD0F_PAUSE_MASK))
9884be59a01SSepherosa Ziehau 		hw->fc.requested_mode = e1000_fc_none;
9894be59a01SSepherosa Ziehau 	else if ((nvm_data & NVM_WORD0F_PAUSE_MASK) ==
9904be59a01SSepherosa Ziehau 		 NVM_WORD0F_ASM_DIR)
9914be59a01SSepherosa Ziehau 		hw->fc.requested_mode = e1000_fc_tx_pause;
9924be59a01SSepherosa Ziehau 	else
9934be59a01SSepherosa Ziehau 		hw->fc.requested_mode = e1000_fc_full;
9944be59a01SSepherosa Ziehau 
9954be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
9964be59a01SSepherosa Ziehau }
9974be59a01SSepherosa Ziehau 
9989c80d176SSepherosa Ziehau /**
9999c80d176SSepherosa Ziehau  *  e1000_setup_link_generic - Setup flow control and link settings
10009c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
10019c80d176SSepherosa Ziehau  *
10029c80d176SSepherosa Ziehau  *  Determines which flow control settings to use, then configures flow
10039c80d176SSepherosa Ziehau  *  control.  Calls the appropriate media-specific link configuration
10049c80d176SSepherosa Ziehau  *  function.  Assuming the adapter has a valid link partner, a valid link
10059c80d176SSepherosa Ziehau  *  should be established.  Assumes the hardware has previously been reset
10069c80d176SSepherosa Ziehau  *  and the transmitter and receiver are not enabled.
10079c80d176SSepherosa Ziehau  **/
e1000_setup_link_generic(struct e1000_hw * hw)10089c80d176SSepherosa Ziehau s32 e1000_setup_link_generic(struct e1000_hw *hw)
10099c80d176SSepherosa Ziehau {
10104be59a01SSepherosa Ziehau 	s32 ret_val;
10119c80d176SSepherosa Ziehau 
10129c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_setup_link_generic");
10139c80d176SSepherosa Ziehau 
1014379ebbe7SSepherosa Ziehau 	/* In the case of the phy reset being blocked, we already have a link.
10159c80d176SSepherosa Ziehau 	 * We do not need to set it up again.
10169c80d176SSepherosa Ziehau 	 */
10174be59a01SSepherosa Ziehau 	if (hw->phy.ops.check_reset_block && hw->phy.ops.check_reset_block(hw))
10184be59a01SSepherosa Ziehau 		return E1000_SUCCESS;
10199c80d176SSepherosa Ziehau 
1020379ebbe7SSepherosa Ziehau 	/* If requested flow control is set to default, set flow control
10219c80d176SSepherosa Ziehau 	 * based on the EEPROM flow control settings.
10229c80d176SSepherosa Ziehau 	 */
10239c80d176SSepherosa Ziehau 	if (hw->fc.requested_mode == e1000_fc_default) {
10249c80d176SSepherosa Ziehau 		ret_val = e1000_set_default_fc_generic(hw);
10259c80d176SSepherosa Ziehau 		if (ret_val)
10264be59a01SSepherosa Ziehau 			return ret_val;
10279c80d176SSepherosa Ziehau 	}
10289c80d176SSepherosa Ziehau 
1029379ebbe7SSepherosa Ziehau 	/* Save off the requested flow control mode for use later.  Depending
10309c80d176SSepherosa Ziehau 	 * on the link partner's capabilities, we may or may not use this mode.
10319c80d176SSepherosa Ziehau 	 */
10329c80d176SSepherosa Ziehau 	hw->fc.current_mode = hw->fc.requested_mode;
10339c80d176SSepherosa Ziehau 
10349c80d176SSepherosa Ziehau 	DEBUGOUT1("After fix-ups FlowControl is now = %x\n",
10359c80d176SSepherosa Ziehau 		hw->fc.current_mode);
10369c80d176SSepherosa Ziehau 
10379c80d176SSepherosa Ziehau 	/* Call the necessary media_type subroutine to configure the link. */
10389c80d176SSepherosa Ziehau 	ret_val = hw->mac.ops.setup_physical_interface(hw);
10399c80d176SSepherosa Ziehau 	if (ret_val)
10404be59a01SSepherosa Ziehau 		return ret_val;
10419c80d176SSepherosa Ziehau 
1042379ebbe7SSepherosa Ziehau 	/* Initialize the flow control address, type, and PAUSE timer
10439c80d176SSepherosa Ziehau 	 * registers to their default values.  This is done even if flow
10449c80d176SSepherosa Ziehau 	 * control is disabled, because it does not hurt anything to
10459c80d176SSepherosa Ziehau 	 * initialize these registers.
10469c80d176SSepherosa Ziehau 	 */
10479c80d176SSepherosa Ziehau 	DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
10489c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_FCT, FLOW_CONTROL_TYPE);
10499c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_FCAH, FLOW_CONTROL_ADDRESS_HIGH);
10509c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_FCAL, FLOW_CONTROL_ADDRESS_LOW);
10519c80d176SSepherosa Ziehau 
10529c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
10539c80d176SSepherosa Ziehau 
10544be59a01SSepherosa Ziehau 	return e1000_set_fc_watermarks_generic(hw);
10559c80d176SSepherosa Ziehau }
10569c80d176SSepherosa Ziehau 
10579c80d176SSepherosa Ziehau /**
10589c80d176SSepherosa Ziehau  *  e1000_commit_fc_settings_generic - Configure flow control
10599c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
10609c80d176SSepherosa Ziehau  *
10619c80d176SSepherosa Ziehau  *  Write the flow control settings to the Transmit Config Word Register (TXCW)
10629c80d176SSepherosa Ziehau  *  base on the flow control settings in e1000_mac_info.
10639c80d176SSepherosa Ziehau  **/
e1000_commit_fc_settings_generic(struct e1000_hw * hw)10649c80d176SSepherosa Ziehau s32 e1000_commit_fc_settings_generic(struct e1000_hw *hw)
10659c80d176SSepherosa Ziehau {
10669c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
10679c80d176SSepherosa Ziehau 	u32 txcw;
10689c80d176SSepherosa Ziehau 
10699c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_commit_fc_settings_generic");
10709c80d176SSepherosa Ziehau 
1071379ebbe7SSepherosa Ziehau 	/* Check for a software override of the flow control settings, and
10729c80d176SSepherosa Ziehau 	 * setup the device accordingly.  If auto-negotiation is enabled, then
10739c80d176SSepherosa Ziehau 	 * software will have to set the "PAUSE" bits to the correct value in
10749c80d176SSepherosa Ziehau 	 * the Transmit Config Word Register (TXCW) and re-start auto-
10759c80d176SSepherosa Ziehau 	 * negotiation.  However, if auto-negotiation is disabled, then
10769c80d176SSepherosa Ziehau 	 * software will have to manually configure the two flow control enable
10779c80d176SSepherosa Ziehau 	 * bits in the CTRL register.
10789c80d176SSepherosa Ziehau 	 *
10799c80d176SSepherosa Ziehau 	 * The possible values of the "fc" parameter are:
10809c80d176SSepherosa Ziehau 	 *      0:  Flow control is completely disabled
10819c80d176SSepherosa Ziehau 	 *      1:  Rx flow control is enabled (we can receive pause frames,
10829c80d176SSepherosa Ziehau 	 *          but not send pause frames).
10839c80d176SSepherosa Ziehau 	 *      2:  Tx flow control is enabled (we can send pause frames but we
10849c80d176SSepherosa Ziehau 	 *          do not support receiving pause frames).
10859c80d176SSepherosa Ziehau 	 *      3:  Both Rx and Tx flow control (symmetric) are enabled.
10869c80d176SSepherosa Ziehau 	 */
10879c80d176SSepherosa Ziehau 	switch (hw->fc.current_mode) {
10889c80d176SSepherosa Ziehau 	case e1000_fc_none:
10899c80d176SSepherosa Ziehau 		/* Flow control completely disabled by a software over-ride. */
10909c80d176SSepherosa Ziehau 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
10919c80d176SSepherosa Ziehau 		break;
10929c80d176SSepherosa Ziehau 	case e1000_fc_rx_pause:
1093379ebbe7SSepherosa Ziehau 		/* Rx Flow control is enabled and Tx Flow control is disabled
10949c80d176SSepherosa Ziehau 		 * by a software over-ride. Since there really isn't a way to
10959c80d176SSepherosa Ziehau 		 * advertise that we are capable of Rx Pause ONLY, we will
10966a5a645eSSepherosa Ziehau 		 * advertise that we support both symmetric and asymmetric Rx
10979c80d176SSepherosa Ziehau 		 * PAUSE.  Later, we will disable the adapter's ability to send
10989c80d176SSepherosa Ziehau 		 * PAUSE frames.
10999c80d176SSepherosa Ziehau 		 */
11009c80d176SSepherosa Ziehau 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
11019c80d176SSepherosa Ziehau 		break;
11029c80d176SSepherosa Ziehau 	case e1000_fc_tx_pause:
1103379ebbe7SSepherosa Ziehau 		/* Tx Flow control is enabled, and Rx Flow control is disabled,
11049c80d176SSepherosa Ziehau 		 * by a software over-ride.
11059c80d176SSepherosa Ziehau 		 */
11069c80d176SSepherosa Ziehau 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
11079c80d176SSepherosa Ziehau 		break;
11089c80d176SSepherosa Ziehau 	case e1000_fc_full:
1109379ebbe7SSepherosa Ziehau 		/* Flow control (both Rx and Tx) is enabled by a software
11109c80d176SSepherosa Ziehau 		 * over-ride.
11119c80d176SSepherosa Ziehau 		 */
11129c80d176SSepherosa Ziehau 		txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
11139c80d176SSepherosa Ziehau 		break;
11149c80d176SSepherosa Ziehau 	default:
11159c80d176SSepherosa Ziehau 		DEBUGOUT("Flow control param set incorrectly\n");
11164be59a01SSepherosa Ziehau 		return -E1000_ERR_CONFIG;
11179c80d176SSepherosa Ziehau 		break;
11189c80d176SSepherosa Ziehau 	}
11199c80d176SSepherosa Ziehau 
11209c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_TXCW, txcw);
11219c80d176SSepherosa Ziehau 	mac->txcw = txcw;
11229c80d176SSepherosa Ziehau 
11234be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
11244be59a01SSepherosa Ziehau }
11254be59a01SSepherosa Ziehau 
11264be59a01SSepherosa Ziehau /**
11274be59a01SSepherosa Ziehau  *  e1000_poll_fiber_serdes_link_generic - Poll for link up
11284be59a01SSepherosa Ziehau  *  @hw: pointer to the HW structure
11294be59a01SSepherosa Ziehau  *
11304be59a01SSepherosa Ziehau  *  Polls for link up by reading the status register, if link fails to come
11314be59a01SSepherosa Ziehau  *  up with auto-negotiation, then the link is forced if a signal is detected.
11324be59a01SSepherosa Ziehau  **/
e1000_poll_fiber_serdes_link_generic(struct e1000_hw * hw)11334be59a01SSepherosa Ziehau s32 e1000_poll_fiber_serdes_link_generic(struct e1000_hw *hw)
11344be59a01SSepherosa Ziehau {
11354be59a01SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
11364be59a01SSepherosa Ziehau 	u32 i, status;
11374be59a01SSepherosa Ziehau 	s32 ret_val;
11384be59a01SSepherosa Ziehau 
11394be59a01SSepherosa Ziehau 	DEBUGFUNC("e1000_poll_fiber_serdes_link_generic");
11404be59a01SSepherosa Ziehau 
1141379ebbe7SSepherosa Ziehau 	/* If we have a signal (the cable is plugged in, or assumed TRUE for
11424be59a01SSepherosa Ziehau 	 * serdes media) then poll for a "Link-Up" indication in the Device
11434be59a01SSepherosa Ziehau 	 * Status Register.  Time-out if a link isn't seen in 500 milliseconds
11444be59a01SSepherosa Ziehau 	 * seconds (Auto-negotiation should complete in less than 500
11454be59a01SSepherosa Ziehau 	 * milliseconds even if the other end is doing it in SW).
11464be59a01SSepherosa Ziehau 	 */
11474be59a01SSepherosa Ziehau 	for (i = 0; i < FIBER_LINK_UP_LIMIT; i++) {
11484be59a01SSepherosa Ziehau 		msec_delay(10);
11494be59a01SSepherosa Ziehau 		status = E1000_READ_REG(hw, E1000_STATUS);
11504be59a01SSepherosa Ziehau 		if (status & E1000_STATUS_LU)
11514be59a01SSepherosa Ziehau 			break;
11524be59a01SSepherosa Ziehau 	}
11534be59a01SSepherosa Ziehau 	if (i == FIBER_LINK_UP_LIMIT) {
11544be59a01SSepherosa Ziehau 		DEBUGOUT("Never got a valid link from auto-neg!!!\n");
11554be59a01SSepherosa Ziehau 		mac->autoneg_failed = TRUE;
1156379ebbe7SSepherosa Ziehau 		/* AutoNeg failed to achieve a link, so we'll call
11574be59a01SSepherosa Ziehau 		 * mac->check_for_link. This routine will force the
11584be59a01SSepherosa Ziehau 		 * link up if we detect a signal. This will allow us to
11594be59a01SSepherosa Ziehau 		 * communicate with non-autonegotiating link partners.
11604be59a01SSepherosa Ziehau 		 */
11614be59a01SSepherosa Ziehau 		ret_val = mac->ops.check_for_link(hw);
11624be59a01SSepherosa Ziehau 		if (ret_val) {
11634be59a01SSepherosa Ziehau 			DEBUGOUT("Error while checking for link\n");
11649c80d176SSepherosa Ziehau 			return ret_val;
11659c80d176SSepherosa Ziehau 		}
11664be59a01SSepherosa Ziehau 		mac->autoneg_failed = FALSE;
11674be59a01SSepherosa Ziehau 	} else {
11684be59a01SSepherosa Ziehau 		mac->autoneg_failed = FALSE;
11694be59a01SSepherosa Ziehau 		DEBUGOUT("Valid Link Found\n");
11704be59a01SSepherosa Ziehau 	}
11714be59a01SSepherosa Ziehau 
11724be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
11734be59a01SSepherosa Ziehau }
11744be59a01SSepherosa Ziehau 
11754be59a01SSepherosa Ziehau /**
11764be59a01SSepherosa Ziehau  *  e1000_setup_fiber_serdes_link_generic - Setup link for fiber/serdes
11774be59a01SSepherosa Ziehau  *  @hw: pointer to the HW structure
11784be59a01SSepherosa Ziehau  *
11794be59a01SSepherosa Ziehau  *  Configures collision distance and flow control for fiber and serdes
11804be59a01SSepherosa Ziehau  *  links.  Upon successful setup, poll for link.
11814be59a01SSepherosa Ziehau  **/
e1000_setup_fiber_serdes_link_generic(struct e1000_hw * hw)11824be59a01SSepherosa Ziehau s32 e1000_setup_fiber_serdes_link_generic(struct e1000_hw *hw)
11834be59a01SSepherosa Ziehau {
11844be59a01SSepherosa Ziehau 	u32 ctrl;
11854be59a01SSepherosa Ziehau 	s32 ret_val;
11864be59a01SSepherosa Ziehau 
11874be59a01SSepherosa Ziehau 	DEBUGFUNC("e1000_setup_fiber_serdes_link_generic");
11884be59a01SSepherosa Ziehau 
11894be59a01SSepherosa Ziehau 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
11904be59a01SSepherosa Ziehau 
11914be59a01SSepherosa Ziehau 	/* Take the link out of reset */
11924be59a01SSepherosa Ziehau 	ctrl &= ~E1000_CTRL_LRST;
11934be59a01SSepherosa Ziehau 
11944be59a01SSepherosa Ziehau 	hw->mac.ops.config_collision_dist(hw);
11954be59a01SSepherosa Ziehau 
11964be59a01SSepherosa Ziehau 	ret_val = e1000_commit_fc_settings_generic(hw);
11974be59a01SSepherosa Ziehau 	if (ret_val)
11984be59a01SSepherosa Ziehau 		return ret_val;
11994be59a01SSepherosa Ziehau 
1200379ebbe7SSepherosa Ziehau 	/* Since auto-negotiation is enabled, take the link out of reset (the
12014be59a01SSepherosa Ziehau 	 * link will be in reset, because we previously reset the chip). This
12024be59a01SSepherosa Ziehau 	 * will restart auto-negotiation.  If auto-negotiation is successful
12034be59a01SSepherosa Ziehau 	 * then the link-up status bit will be set and the flow control enable
12044be59a01SSepherosa Ziehau 	 * bits (RFCE and TFCE) will be set according to their negotiated value.
12054be59a01SSepherosa Ziehau 	 */
12064be59a01SSepherosa Ziehau 	DEBUGOUT("Auto-negotiation enabled\n");
12074be59a01SSepherosa Ziehau 
12084be59a01SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
12094be59a01SSepherosa Ziehau 	E1000_WRITE_FLUSH(hw);
12104be59a01SSepherosa Ziehau 	msec_delay(1);
12114be59a01SSepherosa Ziehau 
1212379ebbe7SSepherosa Ziehau 	/* For these adapters, the SW definable pin 1 is set when the optics
12134be59a01SSepherosa Ziehau 	 * detect a signal.  If we have a signal, then poll for a "Link-Up"
12144be59a01SSepherosa Ziehau 	 * indication.
12154be59a01SSepherosa Ziehau 	 */
12164be59a01SSepherosa Ziehau 	if (hw->phy.media_type == e1000_media_type_internal_serdes ||
12174be59a01SSepherosa Ziehau 	    (E1000_READ_REG(hw, E1000_CTRL) & E1000_CTRL_SWDPIN1)) {
12184be59a01SSepherosa Ziehau 		ret_val = e1000_poll_fiber_serdes_link_generic(hw);
12194be59a01SSepherosa Ziehau 	} else {
12204be59a01SSepherosa Ziehau 		DEBUGOUT("No signal detected\n");
12214be59a01SSepherosa Ziehau 	}
12224be59a01SSepherosa Ziehau 
12234be59a01SSepherosa Ziehau 	return ret_val;
12244be59a01SSepherosa Ziehau }
12254be59a01SSepherosa Ziehau 
12264be59a01SSepherosa Ziehau /**
12274be59a01SSepherosa Ziehau  *  e1000_config_collision_dist_generic - Configure collision distance
12284be59a01SSepherosa Ziehau  *  @hw: pointer to the HW structure
12294be59a01SSepherosa Ziehau  *
12304be59a01SSepherosa Ziehau  *  Configures the collision distance to the default value and is used
12314be59a01SSepherosa Ziehau  *  during link setup.
12324be59a01SSepherosa Ziehau  **/
e1000_config_collision_dist_generic(struct e1000_hw * hw)12334be59a01SSepherosa Ziehau static void e1000_config_collision_dist_generic(struct e1000_hw *hw)
12344be59a01SSepherosa Ziehau {
12354be59a01SSepherosa Ziehau 	u32 tctl;
12364be59a01SSepherosa Ziehau 
12374be59a01SSepherosa Ziehau 	DEBUGFUNC("e1000_config_collision_dist_generic");
12384be59a01SSepherosa Ziehau 
12394be59a01SSepherosa Ziehau 	tctl = E1000_READ_REG(hw, E1000_TCTL);
12404be59a01SSepherosa Ziehau 
12414be59a01SSepherosa Ziehau 	tctl &= ~E1000_TCTL_COLD;
12424be59a01SSepherosa Ziehau 	tctl |= E1000_COLLISION_DISTANCE << E1000_COLD_SHIFT;
12434be59a01SSepherosa Ziehau 
12444be59a01SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_TCTL, tctl);
12454be59a01SSepherosa Ziehau 	E1000_WRITE_FLUSH(hw);
12464be59a01SSepherosa Ziehau }
12479c80d176SSepherosa Ziehau 
12489c80d176SSepherosa Ziehau /**
12499c80d176SSepherosa Ziehau  *  e1000_set_fc_watermarks_generic - Set flow control high/low watermarks
12509c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
12519c80d176SSepherosa Ziehau  *
12529c80d176SSepherosa Ziehau  *  Sets the flow control high/low threshold (watermark) registers.  If
12539c80d176SSepherosa Ziehau  *  flow control XON frame transmission is enabled, then set XON frame
12549c80d176SSepherosa Ziehau  *  transmission as well.
12559c80d176SSepherosa Ziehau  **/
e1000_set_fc_watermarks_generic(struct e1000_hw * hw)12569c80d176SSepherosa Ziehau s32 e1000_set_fc_watermarks_generic(struct e1000_hw *hw)
12579c80d176SSepherosa Ziehau {
12589c80d176SSepherosa Ziehau 	u32 fcrtl = 0, fcrth = 0;
12599c80d176SSepherosa Ziehau 
12609c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_set_fc_watermarks_generic");
12619c80d176SSepherosa Ziehau 
1262379ebbe7SSepherosa Ziehau 	/* Set the flow control receive threshold registers.  Normally,
12639c80d176SSepherosa Ziehau 	 * these registers will be set to a default threshold that may be
12649c80d176SSepherosa Ziehau 	 * adjusted later by the driver's runtime code.  However, if the
12659c80d176SSepherosa Ziehau 	 * ability to transmit pause frames is not enabled, then these
12669c80d176SSepherosa Ziehau 	 * registers will be set to 0.
12679c80d176SSepherosa Ziehau 	 */
12689c80d176SSepherosa Ziehau 	if (hw->fc.current_mode & e1000_fc_tx_pause) {
1269379ebbe7SSepherosa Ziehau 		/* We need to set up the Receive Threshold high and low water
12709c80d176SSepherosa Ziehau 		 * marks as well as (optionally) enabling the transmission of
12719c80d176SSepherosa Ziehau 		 * XON frames.
12729c80d176SSepherosa Ziehau 		 */
12739c80d176SSepherosa Ziehau 		fcrtl = hw->fc.low_water;
12749c80d176SSepherosa Ziehau 		if (hw->fc.send_xon)
12759c80d176SSepherosa Ziehau 			fcrtl |= E1000_FCRTL_XONE;
12769c80d176SSepherosa Ziehau 
12779c80d176SSepherosa Ziehau 		fcrth = hw->fc.high_water;
12789c80d176SSepherosa Ziehau 	}
12799c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_FCRTL, fcrtl);
12809c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_FCRTH, fcrth);
12819c80d176SSepherosa Ziehau 
12826a5a645eSSepherosa Ziehau 	return E1000_SUCCESS;
12839c80d176SSepherosa Ziehau }
12849c80d176SSepherosa Ziehau 
12859c80d176SSepherosa Ziehau /**
12869c80d176SSepherosa Ziehau  *  e1000_force_mac_fc_generic - Force the MAC's flow control settings
12879c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
12889c80d176SSepherosa Ziehau  *
12899c80d176SSepherosa Ziehau  *  Force the MAC's flow control settings.  Sets the TFCE and RFCE bits in the
12909c80d176SSepherosa Ziehau  *  device control register to reflect the adapter settings.  TFCE and RFCE
12919c80d176SSepherosa Ziehau  *  need to be explicitly set by software when a copper PHY is used because
12929c80d176SSepherosa Ziehau  *  autonegotiation is managed by the PHY rather than the MAC.  Software must
12939c80d176SSepherosa Ziehau  *  also configure these bits when link is forced on a fiber connection.
12949c80d176SSepherosa Ziehau  **/
e1000_force_mac_fc_generic(struct e1000_hw * hw)12959c80d176SSepherosa Ziehau s32 e1000_force_mac_fc_generic(struct e1000_hw *hw)
12969c80d176SSepherosa Ziehau {
12979c80d176SSepherosa Ziehau 	u32 ctrl;
12989c80d176SSepherosa Ziehau 
12999c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_force_mac_fc_generic");
13009c80d176SSepherosa Ziehau 
13019c80d176SSepherosa Ziehau 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
13029c80d176SSepherosa Ziehau 
1303379ebbe7SSepherosa Ziehau 	/* Because we didn't get link via the internal auto-negotiation
13049c80d176SSepherosa Ziehau 	 * mechanism (we either forced link or we got link via PHY
13059c80d176SSepherosa Ziehau 	 * auto-neg), we have to manually enable/disable transmit an
13069c80d176SSepherosa Ziehau 	 * receive flow control.
13079c80d176SSepherosa Ziehau 	 *
13089c80d176SSepherosa Ziehau 	 * The "Case" statement below enables/disable flow control
13099c80d176SSepherosa Ziehau 	 * according to the "hw->fc.current_mode" parameter.
13109c80d176SSepherosa Ziehau 	 *
13119c80d176SSepherosa Ziehau 	 * The possible values of the "fc" parameter are:
13129c80d176SSepherosa Ziehau 	 *      0:  Flow control is completely disabled
13139c80d176SSepherosa Ziehau 	 *      1:  Rx flow control is enabled (we can receive pause
13149c80d176SSepherosa Ziehau 	 *          frames but not send pause frames).
13159c80d176SSepherosa Ziehau 	 *      2:  Tx flow control is enabled (we can send pause frames
13169c80d176SSepherosa Ziehau 	 *          frames but we do not receive pause frames).
13179c80d176SSepherosa Ziehau 	 *      3:  Both Rx and Tx flow control (symmetric) is enabled.
13189c80d176SSepherosa Ziehau 	 *  other:  No other values should be possible at this point.
13199c80d176SSepherosa Ziehau 	 */
13209c80d176SSepherosa Ziehau 	DEBUGOUT1("hw->fc.current_mode = %u\n", hw->fc.current_mode);
13219c80d176SSepherosa Ziehau 
13229c80d176SSepherosa Ziehau 	switch (hw->fc.current_mode) {
13239c80d176SSepherosa Ziehau 	case e1000_fc_none:
13249c80d176SSepherosa Ziehau 		ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
13259c80d176SSepherosa Ziehau 		break;
13269c80d176SSepherosa Ziehau 	case e1000_fc_rx_pause:
13279c80d176SSepherosa Ziehau 		ctrl &= (~E1000_CTRL_TFCE);
13289c80d176SSepherosa Ziehau 		ctrl |= E1000_CTRL_RFCE;
13299c80d176SSepherosa Ziehau 		break;
13309c80d176SSepherosa Ziehau 	case e1000_fc_tx_pause:
13319c80d176SSepherosa Ziehau 		ctrl &= (~E1000_CTRL_RFCE);
13329c80d176SSepherosa Ziehau 		ctrl |= E1000_CTRL_TFCE;
13339c80d176SSepherosa Ziehau 		break;
13349c80d176SSepherosa Ziehau 	case e1000_fc_full:
13359c80d176SSepherosa Ziehau 		ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
13369c80d176SSepherosa Ziehau 		break;
13379c80d176SSepherosa Ziehau 	default:
13389c80d176SSepherosa Ziehau 		DEBUGOUT("Flow control param set incorrectly\n");
13394be59a01SSepherosa Ziehau 		return -E1000_ERR_CONFIG;
13409c80d176SSepherosa Ziehau 	}
13419c80d176SSepherosa Ziehau 
13429c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
13439c80d176SSepherosa Ziehau 
13444be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
13459c80d176SSepherosa Ziehau }
13469c80d176SSepherosa Ziehau 
13479c80d176SSepherosa Ziehau /**
13489c80d176SSepherosa Ziehau  *  e1000_config_fc_after_link_up_generic - Configures flow control after link
13499c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
13509c80d176SSepherosa Ziehau  *
13519c80d176SSepherosa Ziehau  *  Checks the status of auto-negotiation after link up to ensure that the
13529c80d176SSepherosa Ziehau  *  speed and duplex were not forced.  If the link needed to be forced, then
13539c80d176SSepherosa Ziehau  *  flow control needs to be forced also.  If auto-negotiation is enabled
13549c80d176SSepherosa Ziehau  *  and did not fail, then we configure flow control based on our link
13559c80d176SSepherosa Ziehau  *  partner.
13569c80d176SSepherosa Ziehau  **/
e1000_config_fc_after_link_up_generic(struct e1000_hw * hw)13579c80d176SSepherosa Ziehau s32 e1000_config_fc_after_link_up_generic(struct e1000_hw *hw)
13589c80d176SSepherosa Ziehau {
13599c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
13609c80d176SSepherosa Ziehau 	s32 ret_val = E1000_SUCCESS;
13614be59a01SSepherosa Ziehau 	u32 pcs_status_reg, pcs_adv_reg, pcs_lp_ability_reg, pcs_ctrl_reg;
13629c80d176SSepherosa Ziehau 	u16 mii_status_reg, mii_nway_adv_reg, mii_nway_lp_ability_reg;
13639c80d176SSepherosa Ziehau 	u16 speed, duplex;
13649c80d176SSepherosa Ziehau 
13659c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_config_fc_after_link_up_generic");
13669c80d176SSepherosa Ziehau 
1367379ebbe7SSepherosa Ziehau 	/* Check for the case where we have fiber media and auto-neg failed
13689c80d176SSepherosa Ziehau 	 * so we had to force link.  In this case, we need to force the
13699c80d176SSepherosa Ziehau 	 * configuration of the MAC to match the "fc" parameter.
13709c80d176SSepherosa Ziehau 	 */
13719c80d176SSepherosa Ziehau 	if (mac->autoneg_failed) {
13729c80d176SSepherosa Ziehau 		if (hw->phy.media_type == e1000_media_type_fiber ||
13739c80d176SSepherosa Ziehau 		    hw->phy.media_type == e1000_media_type_internal_serdes)
13749c80d176SSepherosa Ziehau 			ret_val = e1000_force_mac_fc_generic(hw);
13759c80d176SSepherosa Ziehau 	} else {
13769c80d176SSepherosa Ziehau 		if (hw->phy.media_type == e1000_media_type_copper)
13779c80d176SSepherosa Ziehau 			ret_val = e1000_force_mac_fc_generic(hw);
13789c80d176SSepherosa Ziehau 	}
13799c80d176SSepherosa Ziehau 
13809c80d176SSepherosa Ziehau 	if (ret_val) {
13819c80d176SSepherosa Ziehau 		DEBUGOUT("Error forcing flow control settings\n");
13824be59a01SSepherosa Ziehau 		return ret_val;
13839c80d176SSepherosa Ziehau 	}
13849c80d176SSepherosa Ziehau 
1385379ebbe7SSepherosa Ziehau 	/* Check for the case where we have copper media and auto-neg is
13869c80d176SSepherosa Ziehau 	 * enabled.  In this case, we need to check and see if Auto-Neg
13879c80d176SSepherosa Ziehau 	 * has completed, and if so, how the PHY and link partner has
13889c80d176SSepherosa Ziehau 	 * flow control configured.
13899c80d176SSepherosa Ziehau 	 */
13909c80d176SSepherosa Ziehau 	if ((hw->phy.media_type == e1000_media_type_copper) && mac->autoneg) {
1391379ebbe7SSepherosa Ziehau 		/* Read the MII Status Register and check to see if AutoNeg
13929c80d176SSepherosa Ziehau 		 * has completed.  We read this twice because this reg has
13939c80d176SSepherosa Ziehau 		 * some "sticky" (latched) bits.
13949c80d176SSepherosa Ziehau 		 */
13959c80d176SSepherosa Ziehau 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
13969c80d176SSepherosa Ziehau 		if (ret_val)
13974be59a01SSepherosa Ziehau 			return ret_val;
13989c80d176SSepherosa Ziehau 		ret_val = hw->phy.ops.read_reg(hw, PHY_STATUS, &mii_status_reg);
13999c80d176SSepherosa Ziehau 		if (ret_val)
14004be59a01SSepherosa Ziehau 			return ret_val;
14019c80d176SSepherosa Ziehau 
14029c80d176SSepherosa Ziehau 		if (!(mii_status_reg & MII_SR_AUTONEG_COMPLETE)) {
14034be59a01SSepherosa Ziehau 			DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
14044be59a01SSepherosa Ziehau 			return ret_val;
14059c80d176SSepherosa Ziehau 		}
14069c80d176SSepherosa Ziehau 
1407379ebbe7SSepherosa Ziehau 		/* The AutoNeg process has completed, so we now need to
14089c80d176SSepherosa Ziehau 		 * read both the Auto Negotiation Advertisement
14099c80d176SSepherosa Ziehau 		 * Register (Address 4) and the Auto_Negotiation Base
14109c80d176SSepherosa Ziehau 		 * Page Ability Register (Address 5) to determine how
14119c80d176SSepherosa Ziehau 		 * flow control was negotiated.
14129c80d176SSepherosa Ziehau 		 */
14139c80d176SSepherosa Ziehau 		ret_val = hw->phy.ops.read_reg(hw, PHY_AUTONEG_ADV,
14149c80d176SSepherosa Ziehau 					       &mii_nway_adv_reg);
14159c80d176SSepherosa Ziehau 		if (ret_val)
14164be59a01SSepherosa Ziehau 			return ret_val;
14179c80d176SSepherosa Ziehau 		ret_val = hw->phy.ops.read_reg(hw, PHY_LP_ABILITY,
14189c80d176SSepherosa Ziehau 					       &mii_nway_lp_ability_reg);
14199c80d176SSepherosa Ziehau 		if (ret_val)
14204be59a01SSepherosa Ziehau 			return ret_val;
14219c80d176SSepherosa Ziehau 
1422379ebbe7SSepherosa Ziehau 		/* Two bits in the Auto Negotiation Advertisement Register
14239c80d176SSepherosa Ziehau 		 * (Address 4) and two bits in the Auto Negotiation Base
14249c80d176SSepherosa Ziehau 		 * Page Ability Register (Address 5) determine flow control
14259c80d176SSepherosa Ziehau 		 * for both the PHY and the link partner.  The following
14269c80d176SSepherosa Ziehau 		 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
14279c80d176SSepherosa Ziehau 		 * 1999, describes these PAUSE resolution bits and how flow
14289c80d176SSepherosa Ziehau 		 * control is determined based upon these settings.
14299c80d176SSepherosa Ziehau 		 * NOTE:  DC = Don't Care
14309c80d176SSepherosa Ziehau 		 *
14319c80d176SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
14329c80d176SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
14339c80d176SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
14349c80d176SSepherosa Ziehau 		 *   0   |    0    |  DC   |   DC    | e1000_fc_none
14359c80d176SSepherosa Ziehau 		 *   0   |    1    |   0   |   DC    | e1000_fc_none
14369c80d176SSepherosa Ziehau 		 *   0   |    1    |   1   |    0    | e1000_fc_none
14379c80d176SSepherosa Ziehau 		 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
14389c80d176SSepherosa Ziehau 		 *   1   |    0    |   0   |   DC    | e1000_fc_none
14399c80d176SSepherosa Ziehau 		 *   1   |   DC    |   1   |   DC    | e1000_fc_full
14409c80d176SSepherosa Ziehau 		 *   1   |    1    |   0   |    0    | e1000_fc_none
14419c80d176SSepherosa Ziehau 		 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
14429c80d176SSepherosa Ziehau 		 *
14439c80d176SSepherosa Ziehau 		 * Are both PAUSE bits set to 1?  If so, this implies
14449c80d176SSepherosa Ziehau 		 * Symmetric Flow Control is enabled at both ends.  The
14459c80d176SSepherosa Ziehau 		 * ASM_DIR bits are irrelevant per the spec.
14469c80d176SSepherosa Ziehau 		 *
14479c80d176SSepherosa Ziehau 		 * For Symmetric Flow Control:
14489c80d176SSepherosa Ziehau 		 *
14499c80d176SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
14509c80d176SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
14519c80d176SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
14529c80d176SSepherosa Ziehau 		 *   1   |   DC    |   1   |   DC    | E1000_fc_full
14539c80d176SSepherosa Ziehau 		 *
14549c80d176SSepherosa Ziehau 		 */
14559c80d176SSepherosa Ziehau 		if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
14569c80d176SSepherosa Ziehau 		    (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
1457379ebbe7SSepherosa Ziehau 			/* Now we need to check if the user selected Rx ONLY
14589c80d176SSepherosa Ziehau 			 * of pause frames.  In this case, we had to advertise
14596a5a645eSSepherosa Ziehau 			 * FULL flow control because we could not advertise Rx
14609c80d176SSepherosa Ziehau 			 * ONLY. Hence, we must now check to see if we need to
14619c80d176SSepherosa Ziehau 			 * turn OFF the TRANSMISSION of PAUSE frames.
14629c80d176SSepherosa Ziehau 			 */
14639c80d176SSepherosa Ziehau 			if (hw->fc.requested_mode == e1000_fc_full) {
14649c80d176SSepherosa Ziehau 				hw->fc.current_mode = e1000_fc_full;
14654be59a01SSepherosa Ziehau 				DEBUGOUT("Flow Control = FULL.\n");
14669c80d176SSepherosa Ziehau 			} else {
14679c80d176SSepherosa Ziehau 				hw->fc.current_mode = e1000_fc_rx_pause;
14684be59a01SSepherosa Ziehau 				DEBUGOUT("Flow Control = Rx PAUSE frames only.\n");
14699c80d176SSepherosa Ziehau 			}
14709c80d176SSepherosa Ziehau 		}
1471379ebbe7SSepherosa Ziehau 		/* For receiving PAUSE frames ONLY.
14729c80d176SSepherosa Ziehau 		 *
14739c80d176SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
14749c80d176SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
14759c80d176SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
14769c80d176SSepherosa Ziehau 		 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
14779c80d176SSepherosa Ziehau 		 */
14789c80d176SSepherosa Ziehau 		else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
14799c80d176SSepherosa Ziehau 			  (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
14809c80d176SSepherosa Ziehau 			  (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
14819c80d176SSepherosa Ziehau 			  (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
14829c80d176SSepherosa Ziehau 			hw->fc.current_mode = e1000_fc_tx_pause;
14834be59a01SSepherosa Ziehau 			DEBUGOUT("Flow Control = Tx PAUSE frames only.\n");
14849c80d176SSepherosa Ziehau 		}
1485379ebbe7SSepherosa Ziehau 		/* For transmitting PAUSE frames ONLY.
14869c80d176SSepherosa Ziehau 		 *
14879c80d176SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
14889c80d176SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
14899c80d176SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
14909c80d176SSepherosa Ziehau 		 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
14919c80d176SSepherosa Ziehau 		 */
14929c80d176SSepherosa Ziehau 		else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
14939c80d176SSepherosa Ziehau 			 (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
14949c80d176SSepherosa Ziehau 			 !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
14959c80d176SSepherosa Ziehau 			 (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
14969c80d176SSepherosa Ziehau 			hw->fc.current_mode = e1000_fc_rx_pause;
14974be59a01SSepherosa Ziehau 			DEBUGOUT("Flow Control = Rx PAUSE frames only.\n");
14989c80d176SSepherosa Ziehau 		} else {
1499379ebbe7SSepherosa Ziehau 			/* Per the IEEE spec, at this point flow control
15009c80d176SSepherosa Ziehau 			 * should be disabled.
15019c80d176SSepherosa Ziehau 			 */
15029c80d176SSepherosa Ziehau 			hw->fc.current_mode = e1000_fc_none;
15034be59a01SSepherosa Ziehau 			DEBUGOUT("Flow Control = NONE.\n");
15049c80d176SSepherosa Ziehau 		}
15059c80d176SSepherosa Ziehau 
1506379ebbe7SSepherosa Ziehau 		/* Now we need to do one last check...  If we auto-
15079c80d176SSepherosa Ziehau 		 * negotiated to HALF DUPLEX, flow control should not be
15089c80d176SSepherosa Ziehau 		 * enabled per IEEE 802.3 spec.
15099c80d176SSepherosa Ziehau 		 */
15109c80d176SSepherosa Ziehau 		ret_val = mac->ops.get_link_up_info(hw, &speed, &duplex);
15119c80d176SSepherosa Ziehau 		if (ret_val) {
15129c80d176SSepherosa Ziehau 			DEBUGOUT("Error getting link speed and duplex\n");
15134be59a01SSepherosa Ziehau 			return ret_val;
15149c80d176SSepherosa Ziehau 		}
15159c80d176SSepherosa Ziehau 
15169c80d176SSepherosa Ziehau 		if (duplex == HALF_DUPLEX)
15179c80d176SSepherosa Ziehau 			hw->fc.current_mode = e1000_fc_none;
15189c80d176SSepherosa Ziehau 
1519379ebbe7SSepherosa Ziehau 		/* Now we call a subroutine to actually force the MAC
15209c80d176SSepherosa Ziehau 		 * controller to use the correct flow control settings.
15219c80d176SSepherosa Ziehau 		 */
15229c80d176SSepherosa Ziehau 		ret_val = e1000_force_mac_fc_generic(hw);
15239c80d176SSepherosa Ziehau 		if (ret_val) {
15249c80d176SSepherosa Ziehau 			DEBUGOUT("Error forcing flow control settings\n");
15254be59a01SSepherosa Ziehau 			return ret_val;
15269c80d176SSepherosa Ziehau 		}
15279c80d176SSepherosa Ziehau 	}
15289c80d176SSepherosa Ziehau 
1529379ebbe7SSepherosa Ziehau 	/* Check for the case where we have SerDes media and auto-neg is
15304be59a01SSepherosa Ziehau 	 * enabled.  In this case, we need to check and see if Auto-Neg
15314be59a01SSepherosa Ziehau 	 * has completed, and if so, how the PHY and link partner has
15324be59a01SSepherosa Ziehau 	 * flow control configured.
15334be59a01SSepherosa Ziehau 	 */
1534379ebbe7SSepherosa Ziehau 	if ((hw->phy.media_type == e1000_media_type_internal_serdes) &&
1535379ebbe7SSepherosa Ziehau 	    mac->autoneg) {
1536379ebbe7SSepherosa Ziehau 		/* Read the PCS_LSTS and check to see if AutoNeg
15374be59a01SSepherosa Ziehau 		 * has completed.
15384be59a01SSepherosa Ziehau 		 */
15394be59a01SSepherosa Ziehau 		pcs_status_reg = E1000_READ_REG(hw, E1000_PCS_LSTAT);
15404be59a01SSepherosa Ziehau 
15414be59a01SSepherosa Ziehau 		if (!(pcs_status_reg & E1000_PCS_LSTS_AN_COMPLETE)) {
15424be59a01SSepherosa Ziehau 			DEBUGOUT("PCS Auto Neg has not completed.\n");
15439c80d176SSepherosa Ziehau 			return ret_val;
15449c80d176SSepherosa Ziehau 		}
15459c80d176SSepherosa Ziehau 
1546379ebbe7SSepherosa Ziehau 		/* The AutoNeg process has completed, so we now need to
15474be59a01SSepherosa Ziehau 		 * read both the Auto Negotiation Advertisement
15484be59a01SSepherosa Ziehau 		 * Register (PCS_ANADV) and the Auto_Negotiation Base
15494be59a01SSepherosa Ziehau 		 * Page Ability Register (PCS_LPAB) to determine how
15504be59a01SSepherosa Ziehau 		 * flow control was negotiated.
15514be59a01SSepherosa Ziehau 		 */
15524be59a01SSepherosa Ziehau 		pcs_adv_reg = E1000_READ_REG(hw, E1000_PCS_ANADV);
15534be59a01SSepherosa Ziehau 		pcs_lp_ability_reg = E1000_READ_REG(hw, E1000_PCS_LPAB);
15544be59a01SSepherosa Ziehau 
1555379ebbe7SSepherosa Ziehau 		/* Two bits in the Auto Negotiation Advertisement Register
15564be59a01SSepherosa Ziehau 		 * (PCS_ANADV) and two bits in the Auto Negotiation Base
15574be59a01SSepherosa Ziehau 		 * Page Ability Register (PCS_LPAB) determine flow control
15584be59a01SSepherosa Ziehau 		 * for both the PHY and the link partner.  The following
15594be59a01SSepherosa Ziehau 		 * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
15604be59a01SSepherosa Ziehau 		 * 1999, describes these PAUSE resolution bits and how flow
15614be59a01SSepherosa Ziehau 		 * control is determined based upon these settings.
15624be59a01SSepherosa Ziehau 		 * NOTE:  DC = Don't Care
15634be59a01SSepherosa Ziehau 		 *
15644be59a01SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
15654be59a01SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
15664be59a01SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
15674be59a01SSepherosa Ziehau 		 *   0   |    0    |  DC   |   DC    | e1000_fc_none
15684be59a01SSepherosa Ziehau 		 *   0   |    1    |   0   |   DC    | e1000_fc_none
15694be59a01SSepherosa Ziehau 		 *   0   |    1    |   1   |    0    | e1000_fc_none
15704be59a01SSepherosa Ziehau 		 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
15714be59a01SSepherosa Ziehau 		 *   1   |    0    |   0   |   DC    | e1000_fc_none
15724be59a01SSepherosa Ziehau 		 *   1   |   DC    |   1   |   DC    | e1000_fc_full
15734be59a01SSepherosa Ziehau 		 *   1   |    1    |   0   |    0    | e1000_fc_none
15744be59a01SSepherosa Ziehau 		 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
15754be59a01SSepherosa Ziehau 		 *
15764be59a01SSepherosa Ziehau 		 * Are both PAUSE bits set to 1?  If so, this implies
15774be59a01SSepherosa Ziehau 		 * Symmetric Flow Control is enabled at both ends.  The
15784be59a01SSepherosa Ziehau 		 * ASM_DIR bits are irrelevant per the spec.
15794be59a01SSepherosa Ziehau 		 *
15804be59a01SSepherosa Ziehau 		 * For Symmetric Flow Control:
15814be59a01SSepherosa Ziehau 		 *
15824be59a01SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
15834be59a01SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
15844be59a01SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
15854be59a01SSepherosa Ziehau 		 *   1   |   DC    |   1   |   DC    | e1000_fc_full
15864be59a01SSepherosa Ziehau 		 *
15874be59a01SSepherosa Ziehau 		 */
15884be59a01SSepherosa Ziehau 		if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
15894be59a01SSepherosa Ziehau 		    (pcs_lp_ability_reg & E1000_TXCW_PAUSE)) {
1590379ebbe7SSepherosa Ziehau 			/* Now we need to check if the user selected Rx ONLY
15914be59a01SSepherosa Ziehau 			 * of pause frames.  In this case, we had to advertise
15924be59a01SSepherosa Ziehau 			 * FULL flow control because we could not advertise Rx
15934be59a01SSepherosa Ziehau 			 * ONLY. Hence, we must now check to see if we need to
15944be59a01SSepherosa Ziehau 			 * turn OFF the TRANSMISSION of PAUSE frames.
15954be59a01SSepherosa Ziehau 			 */
15964be59a01SSepherosa Ziehau 			if (hw->fc.requested_mode == e1000_fc_full) {
15974be59a01SSepherosa Ziehau 				hw->fc.current_mode = e1000_fc_full;
15984be59a01SSepherosa Ziehau 				DEBUGOUT("Flow Control = FULL.\n");
15994be59a01SSepherosa Ziehau 			} else {
16004be59a01SSepherosa Ziehau 				hw->fc.current_mode = e1000_fc_rx_pause;
16014be59a01SSepherosa Ziehau 				DEBUGOUT("Flow Control = Rx PAUSE frames only.\n");
16024be59a01SSepherosa Ziehau 			}
16034be59a01SSepherosa Ziehau 		}
1604379ebbe7SSepherosa Ziehau 		/* For receiving PAUSE frames ONLY.
16054be59a01SSepherosa Ziehau 		 *
16064be59a01SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
16074be59a01SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
16084be59a01SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
16094be59a01SSepherosa Ziehau 		 *   0   |    1    |   1   |    1    | e1000_fc_tx_pause
16104be59a01SSepherosa Ziehau 		 */
16114be59a01SSepherosa Ziehau 		else if (!(pcs_adv_reg & E1000_TXCW_PAUSE) &&
16124be59a01SSepherosa Ziehau 			  (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
16134be59a01SSepherosa Ziehau 			  (pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
16144be59a01SSepherosa Ziehau 			  (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
16154be59a01SSepherosa Ziehau 			hw->fc.current_mode = e1000_fc_tx_pause;
16164be59a01SSepherosa Ziehau 			DEBUGOUT("Flow Control = Tx PAUSE frames only.\n");
16174be59a01SSepherosa Ziehau 		}
1618379ebbe7SSepherosa Ziehau 		/* For transmitting PAUSE frames ONLY.
16194be59a01SSepherosa Ziehau 		 *
16204be59a01SSepherosa Ziehau 		 *   LOCAL DEVICE  |   LINK PARTNER
16214be59a01SSepherosa Ziehau 		 * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
16224be59a01SSepherosa Ziehau 		 *-------|---------|-------|---------|--------------------
16234be59a01SSepherosa Ziehau 		 *   1   |    1    |   0   |    1    | e1000_fc_rx_pause
16244be59a01SSepherosa Ziehau 		 */
16254be59a01SSepherosa Ziehau 		else if ((pcs_adv_reg & E1000_TXCW_PAUSE) &&
16264be59a01SSepherosa Ziehau 			 (pcs_adv_reg & E1000_TXCW_ASM_DIR) &&
16274be59a01SSepherosa Ziehau 			 !(pcs_lp_ability_reg & E1000_TXCW_PAUSE) &&
16284be59a01SSepherosa Ziehau 			 (pcs_lp_ability_reg & E1000_TXCW_ASM_DIR)) {
16294be59a01SSepherosa Ziehau 			hw->fc.current_mode = e1000_fc_rx_pause;
16304be59a01SSepherosa Ziehau 			DEBUGOUT("Flow Control = Rx PAUSE frames only.\n");
16314be59a01SSepherosa Ziehau 		} else {
1632379ebbe7SSepherosa Ziehau 			/* Per the IEEE spec, at this point flow control
16334be59a01SSepherosa Ziehau 			 * should be disabled.
16344be59a01SSepherosa Ziehau 			 */
16354be59a01SSepherosa Ziehau 			hw->fc.current_mode = e1000_fc_none;
16364be59a01SSepherosa Ziehau 			DEBUGOUT("Flow Control = NONE.\n");
16374be59a01SSepherosa Ziehau 		}
16384be59a01SSepherosa Ziehau 
1639379ebbe7SSepherosa Ziehau 		/* Now we call a subroutine to actually force the MAC
16404be59a01SSepherosa Ziehau 		 * controller to use the correct flow control settings.
16414be59a01SSepherosa Ziehau 		 */
16424be59a01SSepherosa Ziehau 		pcs_ctrl_reg = E1000_READ_REG(hw, E1000_PCS_LCTL);
16434be59a01SSepherosa Ziehau 		pcs_ctrl_reg |= E1000_PCS_LCTL_FORCE_FCTRL;
16444be59a01SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_PCS_LCTL, pcs_ctrl_reg);
16454be59a01SSepherosa Ziehau 
16464be59a01SSepherosa Ziehau 		ret_val = e1000_force_mac_fc_generic(hw);
16474be59a01SSepherosa Ziehau 		if (ret_val) {
16484be59a01SSepherosa Ziehau 			DEBUGOUT("Error forcing flow control settings\n");
16494be59a01SSepherosa Ziehau 			return ret_val;
16504be59a01SSepherosa Ziehau 		}
16514be59a01SSepherosa Ziehau 	}
16524be59a01SSepherosa Ziehau 
16534be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
16544be59a01SSepherosa Ziehau }
16554be59a01SSepherosa Ziehau 
16569c80d176SSepherosa Ziehau /**
16579c80d176SSepherosa Ziehau  *  e1000_get_speed_and_duplex_copper_generic - Retrieve current speed/duplex
16589c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
16599c80d176SSepherosa Ziehau  *  @speed: stores the current speed
16609c80d176SSepherosa Ziehau  *  @duplex: stores the current duplex
16619c80d176SSepherosa Ziehau  *
16629c80d176SSepherosa Ziehau  *  Read the status register for the current speed/duplex and store the current
16639c80d176SSepherosa Ziehau  *  speed and duplex for copper connections.
16649c80d176SSepherosa Ziehau  **/
e1000_get_speed_and_duplex_copper_generic(struct e1000_hw * hw,u16 * speed,u16 * duplex)16659c80d176SSepherosa Ziehau s32 e1000_get_speed_and_duplex_copper_generic(struct e1000_hw *hw, u16 *speed,
16669c80d176SSepherosa Ziehau 					      u16 *duplex)
16679c80d176SSepherosa Ziehau {
16689c80d176SSepherosa Ziehau 	u32 status;
16699c80d176SSepherosa Ziehau 
16709c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_get_speed_and_duplex_copper_generic");
16719c80d176SSepherosa Ziehau 
16729c80d176SSepherosa Ziehau 	status = E1000_READ_REG(hw, E1000_STATUS);
16739c80d176SSepherosa Ziehau 	if (status & E1000_STATUS_SPEED_1000) {
16749c80d176SSepherosa Ziehau 		*speed = SPEED_1000;
16759c80d176SSepherosa Ziehau 		DEBUGOUT("1000 Mbs, ");
16769c80d176SSepherosa Ziehau 	} else if (status & E1000_STATUS_SPEED_100) {
16779c80d176SSepherosa Ziehau 		*speed = SPEED_100;
16789c80d176SSepherosa Ziehau 		DEBUGOUT("100 Mbs, ");
16799c80d176SSepherosa Ziehau 	} else {
16809c80d176SSepherosa Ziehau 		*speed = SPEED_10;
16819c80d176SSepherosa Ziehau 		DEBUGOUT("10 Mbs, ");
16829c80d176SSepherosa Ziehau 	}
16839c80d176SSepherosa Ziehau 
16849c80d176SSepherosa Ziehau 	if (status & E1000_STATUS_FD) {
16859c80d176SSepherosa Ziehau 		*duplex = FULL_DUPLEX;
16869c80d176SSepherosa Ziehau 		DEBUGOUT("Full Duplex\n");
16879c80d176SSepherosa Ziehau 	} else {
16889c80d176SSepherosa Ziehau 		*duplex = HALF_DUPLEX;
16899c80d176SSepherosa Ziehau 		DEBUGOUT("Half Duplex\n");
16909c80d176SSepherosa Ziehau 	}
16919c80d176SSepherosa Ziehau 
16929c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
16939c80d176SSepherosa Ziehau }
16949c80d176SSepherosa Ziehau 
16959c80d176SSepherosa Ziehau /**
16969c80d176SSepherosa Ziehau  *  e1000_get_speed_and_duplex_fiber_generic - Retrieve current speed/duplex
16979c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
16989c80d176SSepherosa Ziehau  *  @speed: stores the current speed
16999c80d176SSepherosa Ziehau  *  @duplex: stores the current duplex
17009c80d176SSepherosa Ziehau  *
17019c80d176SSepherosa Ziehau  *  Sets the speed and duplex to gigabit full duplex (the only possible option)
17029c80d176SSepherosa Ziehau  *  for fiber/serdes links.
17039c80d176SSepherosa Ziehau  **/
e1000_get_speed_and_duplex_fiber_serdes_generic(struct e1000_hw E1000_UNUSEDARG * hw,u16 * speed,u16 * duplex)1704379ebbe7SSepherosa Ziehau s32 e1000_get_speed_and_duplex_fiber_serdes_generic(struct e1000_hw E1000_UNUSEDARG *hw,
17059c80d176SSepherosa Ziehau 						    u16 *speed, u16 *duplex)
17069c80d176SSepherosa Ziehau {
17079c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_get_speed_and_duplex_fiber_serdes_generic");
17089c80d176SSepherosa Ziehau 
17099c80d176SSepherosa Ziehau 	*speed = SPEED_1000;
17109c80d176SSepherosa Ziehau 	*duplex = FULL_DUPLEX;
17119c80d176SSepherosa Ziehau 
17129c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
17139c80d176SSepherosa Ziehau }
17149c80d176SSepherosa Ziehau 
17159c80d176SSepherosa Ziehau /**
17169c80d176SSepherosa Ziehau  *  e1000_get_hw_semaphore_generic - Acquire hardware semaphore
17179c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
17189c80d176SSepherosa Ziehau  *
17199c80d176SSepherosa Ziehau  *  Acquire the HW semaphore to access the PHY or NVM
17209c80d176SSepherosa Ziehau  **/
e1000_get_hw_semaphore_generic(struct e1000_hw * hw)17219c80d176SSepherosa Ziehau s32 e1000_get_hw_semaphore_generic(struct e1000_hw *hw)
17229c80d176SSepherosa Ziehau {
17239c80d176SSepherosa Ziehau 	u32 swsm;
17249c80d176SSepherosa Ziehau 	s32 timeout = hw->nvm.word_size + 1;
17259c80d176SSepherosa Ziehau 	s32 i = 0;
17269c80d176SSepherosa Ziehau 
17279c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_get_hw_semaphore_generic");
17289c80d176SSepherosa Ziehau 
17299c80d176SSepherosa Ziehau 	/* Get the SW semaphore */
17309c80d176SSepherosa Ziehau 	while (i < timeout) {
17319c80d176SSepherosa Ziehau 		swsm = E1000_READ_REG(hw, E1000_SWSM);
17329c80d176SSepherosa Ziehau 		if (!(swsm & E1000_SWSM_SMBI))
17339c80d176SSepherosa Ziehau 			break;
17349c80d176SSepherosa Ziehau 
17359c80d176SSepherosa Ziehau 		usec_delay(50);
17369c80d176SSepherosa Ziehau 		i++;
17379c80d176SSepherosa Ziehau 	}
17389c80d176SSepherosa Ziehau 
17399c80d176SSepherosa Ziehau 	if (i == timeout) {
17409c80d176SSepherosa Ziehau 		DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
17414be59a01SSepherosa Ziehau 		return -E1000_ERR_NVM;
17429c80d176SSepherosa Ziehau 	}
17439c80d176SSepherosa Ziehau 
17449c80d176SSepherosa Ziehau 	/* Get the FW semaphore. */
17459c80d176SSepherosa Ziehau 	for (i = 0; i < timeout; i++) {
17469c80d176SSepherosa Ziehau 		swsm = E1000_READ_REG(hw, E1000_SWSM);
17479c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_SWSM, swsm | E1000_SWSM_SWESMBI);
17489c80d176SSepherosa Ziehau 
17499c80d176SSepherosa Ziehau 		/* Semaphore acquired if bit latched */
17509c80d176SSepherosa Ziehau 		if (E1000_READ_REG(hw, E1000_SWSM) & E1000_SWSM_SWESMBI)
17519c80d176SSepherosa Ziehau 			break;
17529c80d176SSepherosa Ziehau 
17539c80d176SSepherosa Ziehau 		usec_delay(50);
17549c80d176SSepherosa Ziehau 	}
17559c80d176SSepherosa Ziehau 
17569c80d176SSepherosa Ziehau 	if (i == timeout) {
17579c80d176SSepherosa Ziehau 		/* Release semaphores */
17589c80d176SSepherosa Ziehau 		e1000_put_hw_semaphore_generic(hw);
17599c80d176SSepherosa Ziehau 		DEBUGOUT("Driver can't access the NVM\n");
17604be59a01SSepherosa Ziehau 		return -E1000_ERR_NVM;
17619c80d176SSepherosa Ziehau 	}
17629c80d176SSepherosa Ziehau 
17634be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
17649c80d176SSepherosa Ziehau }
17659c80d176SSepherosa Ziehau 
17669c80d176SSepherosa Ziehau /**
17679c80d176SSepherosa Ziehau  *  e1000_put_hw_semaphore_generic - Release hardware semaphore
17689c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
17699c80d176SSepherosa Ziehau  *
17709c80d176SSepherosa Ziehau  *  Release hardware semaphore used to access the PHY or NVM
17719c80d176SSepherosa Ziehau  **/
e1000_put_hw_semaphore_generic(struct e1000_hw * hw)17729c80d176SSepherosa Ziehau void e1000_put_hw_semaphore_generic(struct e1000_hw *hw)
17739c80d176SSepherosa Ziehau {
17749c80d176SSepherosa Ziehau 	u32 swsm;
17759c80d176SSepherosa Ziehau 
17769c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_put_hw_semaphore_generic");
17779c80d176SSepherosa Ziehau 
17789c80d176SSepherosa Ziehau 	swsm = E1000_READ_REG(hw, E1000_SWSM);
17799c80d176SSepherosa Ziehau 
17809c80d176SSepherosa Ziehau 	swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
17819c80d176SSepherosa Ziehau 
17829c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_SWSM, swsm);
17839c80d176SSepherosa Ziehau }
17849c80d176SSepherosa Ziehau 
17859c80d176SSepherosa Ziehau /**
17869c80d176SSepherosa Ziehau  *  e1000_get_auto_rd_done_generic - Check for auto read completion
17879c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
17889c80d176SSepherosa Ziehau  *
17899c80d176SSepherosa Ziehau  *  Check EEPROM for Auto Read done bit.
17909c80d176SSepherosa Ziehau  **/
e1000_get_auto_rd_done_generic(struct e1000_hw * hw)17919c80d176SSepherosa Ziehau s32 e1000_get_auto_rd_done_generic(struct e1000_hw *hw)
17929c80d176SSepherosa Ziehau {
17939c80d176SSepherosa Ziehau 	s32 i = 0;
17949c80d176SSepherosa Ziehau 
17959c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_get_auto_rd_done_generic");
17969c80d176SSepherosa Ziehau 
17979c80d176SSepherosa Ziehau 	while (i < AUTO_READ_DONE_TIMEOUT) {
17989c80d176SSepherosa Ziehau 		if (E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_AUTO_RD)
17999c80d176SSepherosa Ziehau 			break;
18009c80d176SSepherosa Ziehau 		msec_delay(1);
18019c80d176SSepherosa Ziehau 		i++;
18029c80d176SSepherosa Ziehau 	}
18039c80d176SSepherosa Ziehau 
18049c80d176SSepherosa Ziehau 	if (i == AUTO_READ_DONE_TIMEOUT) {
18059c80d176SSepherosa Ziehau 		DEBUGOUT("Auto read by HW from NVM has not completed.\n");
18064be59a01SSepherosa Ziehau 		return -E1000_ERR_RESET;
18079c80d176SSepherosa Ziehau 	}
18089c80d176SSepherosa Ziehau 
18094be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
18109c80d176SSepherosa Ziehau }
18119c80d176SSepherosa Ziehau 
18129c80d176SSepherosa Ziehau /**
18139c80d176SSepherosa Ziehau  *  e1000_valid_led_default_generic - Verify a valid default LED config
18149c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
18159c80d176SSepherosa Ziehau  *  @data: pointer to the NVM (EEPROM)
18169c80d176SSepherosa Ziehau  *
18179c80d176SSepherosa Ziehau  *  Read the EEPROM for the current default LED configuration.  If the
18189c80d176SSepherosa Ziehau  *  LED configuration is not valid, set to a valid LED configuration.
18199c80d176SSepherosa Ziehau  **/
e1000_valid_led_default_generic(struct e1000_hw * hw,u16 * data)18209c80d176SSepherosa Ziehau s32 e1000_valid_led_default_generic(struct e1000_hw *hw, u16 *data)
18219c80d176SSepherosa Ziehau {
18229c80d176SSepherosa Ziehau 	s32 ret_val;
18239c80d176SSepherosa Ziehau 
18249c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_valid_led_default_generic");
18259c80d176SSepherosa Ziehau 
18269c80d176SSepherosa Ziehau 	ret_val = hw->nvm.ops.read(hw, NVM_ID_LED_SETTINGS, 1, data);
18279c80d176SSepherosa Ziehau 	if (ret_val) {
18289c80d176SSepherosa Ziehau 		DEBUGOUT("NVM Read Error\n");
18294be59a01SSepherosa Ziehau 		return ret_val;
18309c80d176SSepherosa Ziehau 	}
18319c80d176SSepherosa Ziehau 
18329c80d176SSepherosa Ziehau 	if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
18339c80d176SSepherosa Ziehau 		*data = ID_LED_DEFAULT;
18349c80d176SSepherosa Ziehau 
18354be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
18369c80d176SSepherosa Ziehau }
18379c80d176SSepherosa Ziehau 
18389c80d176SSepherosa Ziehau /**
18399c80d176SSepherosa Ziehau  *  e1000_id_led_init_generic -
18409c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
18419c80d176SSepherosa Ziehau  *
18429c80d176SSepherosa Ziehau  **/
e1000_id_led_init_generic(struct e1000_hw * hw)18439c80d176SSepherosa Ziehau s32 e1000_id_led_init_generic(struct e1000_hw *hw)
18449c80d176SSepherosa Ziehau {
18459c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
18469c80d176SSepherosa Ziehau 	s32 ret_val;
18479c80d176SSepherosa Ziehau 	const u32 ledctl_mask = 0x000000FF;
18489c80d176SSepherosa Ziehau 	const u32 ledctl_on = E1000_LEDCTL_MODE_LED_ON;
18499c80d176SSepherosa Ziehau 	const u32 ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
18509c80d176SSepherosa Ziehau 	u16 data, i, temp;
18519c80d176SSepherosa Ziehau 	const u16 led_mask = 0x0F;
18529c80d176SSepherosa Ziehau 
18539c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_id_led_init_generic");
18549c80d176SSepherosa Ziehau 
18559c80d176SSepherosa Ziehau 	ret_val = hw->nvm.ops.valid_led_default(hw, &data);
18569c80d176SSepherosa Ziehau 	if (ret_val)
18574be59a01SSepherosa Ziehau 		return ret_val;
18589c80d176SSepherosa Ziehau 
18599c80d176SSepherosa Ziehau 	mac->ledctl_default = E1000_READ_REG(hw, E1000_LEDCTL);
18609c80d176SSepherosa Ziehau 	mac->ledctl_mode1 = mac->ledctl_default;
18619c80d176SSepherosa Ziehau 	mac->ledctl_mode2 = mac->ledctl_default;
18629c80d176SSepherosa Ziehau 
18639c80d176SSepherosa Ziehau 	for (i = 0; i < 4; i++) {
18649c80d176SSepherosa Ziehau 		temp = (data >> (i << 2)) & led_mask;
18659c80d176SSepherosa Ziehau 		switch (temp) {
18669c80d176SSepherosa Ziehau 		case ID_LED_ON1_DEF2:
18679c80d176SSepherosa Ziehau 		case ID_LED_ON1_ON2:
18689c80d176SSepherosa Ziehau 		case ID_LED_ON1_OFF2:
18699c80d176SSepherosa Ziehau 			mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
18709c80d176SSepherosa Ziehau 			mac->ledctl_mode1 |= ledctl_on << (i << 3);
18719c80d176SSepherosa Ziehau 			break;
18729c80d176SSepherosa Ziehau 		case ID_LED_OFF1_DEF2:
18739c80d176SSepherosa Ziehau 		case ID_LED_OFF1_ON2:
18749c80d176SSepherosa Ziehau 		case ID_LED_OFF1_OFF2:
18759c80d176SSepherosa Ziehau 			mac->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
18769c80d176SSepherosa Ziehau 			mac->ledctl_mode1 |= ledctl_off << (i << 3);
18779c80d176SSepherosa Ziehau 			break;
18789c80d176SSepherosa Ziehau 		default:
18799c80d176SSepherosa Ziehau 			/* Do nothing */
18809c80d176SSepherosa Ziehau 			break;
18819c80d176SSepherosa Ziehau 		}
18829c80d176SSepherosa Ziehau 		switch (temp) {
18839c80d176SSepherosa Ziehau 		case ID_LED_DEF1_ON2:
18849c80d176SSepherosa Ziehau 		case ID_LED_ON1_ON2:
18859c80d176SSepherosa Ziehau 		case ID_LED_OFF1_ON2:
18869c80d176SSepherosa Ziehau 			mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
18879c80d176SSepherosa Ziehau 			mac->ledctl_mode2 |= ledctl_on << (i << 3);
18889c80d176SSepherosa Ziehau 			break;
18899c80d176SSepherosa Ziehau 		case ID_LED_DEF1_OFF2:
18909c80d176SSepherosa Ziehau 		case ID_LED_ON1_OFF2:
18919c80d176SSepherosa Ziehau 		case ID_LED_OFF1_OFF2:
18929c80d176SSepherosa Ziehau 			mac->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
18939c80d176SSepherosa Ziehau 			mac->ledctl_mode2 |= ledctl_off << (i << 3);
18949c80d176SSepherosa Ziehau 			break;
18959c80d176SSepherosa Ziehau 		default:
18969c80d176SSepherosa Ziehau 			/* Do nothing */
18979c80d176SSepherosa Ziehau 			break;
18989c80d176SSepherosa Ziehau 		}
18999c80d176SSepherosa Ziehau 	}
19009c80d176SSepherosa Ziehau 
19014be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
19029c80d176SSepherosa Ziehau }
19039c80d176SSepherosa Ziehau 
19049c80d176SSepherosa Ziehau /**
19059c80d176SSepherosa Ziehau  *  e1000_setup_led_generic - Configures SW controllable LED
19069c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
19079c80d176SSepherosa Ziehau  *
19089c80d176SSepherosa Ziehau  *  This prepares the SW controllable LED for use and saves the current state
19099c80d176SSepherosa Ziehau  *  of the LED so it can be later restored.
19109c80d176SSepherosa Ziehau  **/
e1000_setup_led_generic(struct e1000_hw * hw)19119c80d176SSepherosa Ziehau s32 e1000_setup_led_generic(struct e1000_hw *hw)
19129c80d176SSepherosa Ziehau {
19139c80d176SSepherosa Ziehau 	u32 ledctl;
19149c80d176SSepherosa Ziehau 
19159c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_setup_led_generic");
19169c80d176SSepherosa Ziehau 
19174be59a01SSepherosa Ziehau 	if (hw->mac.ops.setup_led != e1000_setup_led_generic)
19184be59a01SSepherosa Ziehau 		return -E1000_ERR_CONFIG;
19199c80d176SSepherosa Ziehau 
19209c80d176SSepherosa Ziehau 	if (hw->phy.media_type == e1000_media_type_fiber) {
19219c80d176SSepherosa Ziehau 		ledctl = E1000_READ_REG(hw, E1000_LEDCTL);
19229c80d176SSepherosa Ziehau 		hw->mac.ledctl_default = ledctl;
19239c80d176SSepherosa Ziehau 		/* Turn off LED0 */
19244be59a01SSepherosa Ziehau 		ledctl &= ~(E1000_LEDCTL_LED0_IVRT | E1000_LEDCTL_LED0_BLINK |
19259c80d176SSepherosa Ziehau 			    E1000_LEDCTL_LED0_MODE_MASK);
19269c80d176SSepherosa Ziehau 		ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
19279c80d176SSepherosa Ziehau 			   E1000_LEDCTL_LED0_MODE_SHIFT);
19289c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl);
19299c80d176SSepherosa Ziehau 	} else if (hw->phy.media_type == e1000_media_type_copper) {
19309c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
19319c80d176SSepherosa Ziehau 	}
19329c80d176SSepherosa Ziehau 
19334be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
19349c80d176SSepherosa Ziehau }
19359c80d176SSepherosa Ziehau 
19369c80d176SSepherosa Ziehau /**
19379c80d176SSepherosa Ziehau  *  e1000_cleanup_led_generic - Set LED config to default operation
19389c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
19399c80d176SSepherosa Ziehau  *
19409c80d176SSepherosa Ziehau  *  Remove the current LED configuration and set the LED configuration
19419c80d176SSepherosa Ziehau  *  to the default value, saved from the EEPROM.
19429c80d176SSepherosa Ziehau  **/
e1000_cleanup_led_generic(struct e1000_hw * hw)19439c80d176SSepherosa Ziehau s32 e1000_cleanup_led_generic(struct e1000_hw *hw)
19449c80d176SSepherosa Ziehau {
19459c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_cleanup_led_generic");
19469c80d176SSepherosa Ziehau 
19479c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
19486a5a645eSSepherosa Ziehau 	return E1000_SUCCESS;
19499c80d176SSepherosa Ziehau }
19509c80d176SSepherosa Ziehau 
19519c80d176SSepherosa Ziehau /**
19529c80d176SSepherosa Ziehau  *  e1000_blink_led_generic - Blink LED
19539c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
19549c80d176SSepherosa Ziehau  *
19559c80d176SSepherosa Ziehau  *  Blink the LEDs which are set to be on.
19569c80d176SSepherosa Ziehau  **/
e1000_blink_led_generic(struct e1000_hw * hw)19579c80d176SSepherosa Ziehau s32 e1000_blink_led_generic(struct e1000_hw *hw)
19589c80d176SSepherosa Ziehau {
19599c80d176SSepherosa Ziehau 	u32 ledctl_blink = 0;
19609c80d176SSepherosa Ziehau 	u32 i;
19619c80d176SSepherosa Ziehau 
19629c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_blink_led_generic");
19639c80d176SSepherosa Ziehau 
19649c80d176SSepherosa Ziehau 	if (hw->phy.media_type == e1000_media_type_fiber) {
19659c80d176SSepherosa Ziehau 		/* always blink LED0 for PCI-E fiber */
19669c80d176SSepherosa Ziehau 		ledctl_blink = E1000_LEDCTL_LED0_BLINK |
19679c80d176SSepherosa Ziehau 		     (E1000_LEDCTL_MODE_LED_ON << E1000_LEDCTL_LED0_MODE_SHIFT);
19689c80d176SSepherosa Ziehau 	} else {
1969379ebbe7SSepherosa Ziehau 		/* Set the blink bit for each LED that's "on" (0x0E)
1970379ebbe7SSepherosa Ziehau 		 * (or "off" if inverted) in ledctl_mode2.  The blink
1971379ebbe7SSepherosa Ziehau 		 * logic in hardware only works when mode is set to "on"
1972379ebbe7SSepherosa Ziehau 		 * so it must be changed accordingly when the mode is
1973379ebbe7SSepherosa Ziehau 		 * "off" and inverted.
19749c80d176SSepherosa Ziehau 		 */
19759c80d176SSepherosa Ziehau 		ledctl_blink = hw->mac.ledctl_mode2;
1976379ebbe7SSepherosa Ziehau 		for (i = 0; i < 32; i += 8) {
1977379ebbe7SSepherosa Ziehau 			u32 mode = (hw->mac.ledctl_mode2 >> i) &
1978379ebbe7SSepherosa Ziehau 			    E1000_LEDCTL_LED0_MODE_MASK;
1979379ebbe7SSepherosa Ziehau 			u32 led_default = hw->mac.ledctl_default >> i;
1980379ebbe7SSepherosa Ziehau 
1981379ebbe7SSepherosa Ziehau 			if ((!(led_default & E1000_LEDCTL_LED0_IVRT) &&
1982379ebbe7SSepherosa Ziehau 			     (mode == E1000_LEDCTL_MODE_LED_ON)) ||
1983379ebbe7SSepherosa Ziehau 			    ((led_default & E1000_LEDCTL_LED0_IVRT) &&
1984379ebbe7SSepherosa Ziehau 			     (mode == E1000_LEDCTL_MODE_LED_OFF))) {
1985379ebbe7SSepherosa Ziehau 				ledctl_blink &=
1986379ebbe7SSepherosa Ziehau 				    ~(E1000_LEDCTL_LED0_MODE_MASK << i);
1987379ebbe7SSepherosa Ziehau 				ledctl_blink |= (E1000_LEDCTL_LED0_BLINK |
1988379ebbe7SSepherosa Ziehau 						 E1000_LEDCTL_MODE_LED_ON) << i;
1989379ebbe7SSepherosa Ziehau 			}
1990379ebbe7SSepherosa Ziehau 		}
19919c80d176SSepherosa Ziehau 	}
19929c80d176SSepherosa Ziehau 
19939c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_LEDCTL, ledctl_blink);
19949c80d176SSepherosa Ziehau 
19959c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
19969c80d176SSepherosa Ziehau }
19979c80d176SSepherosa Ziehau 
19989c80d176SSepherosa Ziehau /**
19999c80d176SSepherosa Ziehau  *  e1000_led_on_generic - Turn LED on
20009c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
20019c80d176SSepherosa Ziehau  *
20029c80d176SSepherosa Ziehau  *  Turn LED on.
20039c80d176SSepherosa Ziehau  **/
e1000_led_on_generic(struct e1000_hw * hw)20049c80d176SSepherosa Ziehau s32 e1000_led_on_generic(struct e1000_hw *hw)
20059c80d176SSepherosa Ziehau {
20069c80d176SSepherosa Ziehau 	u32 ctrl;
20079c80d176SSepherosa Ziehau 
20089c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_led_on_generic");
20099c80d176SSepherosa Ziehau 
20109c80d176SSepherosa Ziehau 	switch (hw->phy.media_type) {
20119c80d176SSepherosa Ziehau 	case e1000_media_type_fiber:
20129c80d176SSepherosa Ziehau 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
20139c80d176SSepherosa Ziehau 		ctrl &= ~E1000_CTRL_SWDPIN0;
20149c80d176SSepherosa Ziehau 		ctrl |= E1000_CTRL_SWDPIO0;
20159c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
20169c80d176SSepherosa Ziehau 		break;
20179c80d176SSepherosa Ziehau 	case e1000_media_type_copper:
20189c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2);
20199c80d176SSepherosa Ziehau 		break;
20209c80d176SSepherosa Ziehau 	default:
20219c80d176SSepherosa Ziehau 		break;
20229c80d176SSepherosa Ziehau 	}
20239c80d176SSepherosa Ziehau 
20249c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
20259c80d176SSepherosa Ziehau }
20269c80d176SSepherosa Ziehau 
20279c80d176SSepherosa Ziehau /**
20289c80d176SSepherosa Ziehau  *  e1000_led_off_generic - Turn LED off
20299c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
20309c80d176SSepherosa Ziehau  *
20319c80d176SSepherosa Ziehau  *  Turn LED off.
20329c80d176SSepherosa Ziehau  **/
e1000_led_off_generic(struct e1000_hw * hw)20339c80d176SSepherosa Ziehau s32 e1000_led_off_generic(struct e1000_hw *hw)
20349c80d176SSepherosa Ziehau {
20359c80d176SSepherosa Ziehau 	u32 ctrl;
20369c80d176SSepherosa Ziehau 
20379c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_led_off_generic");
20389c80d176SSepherosa Ziehau 
20399c80d176SSepherosa Ziehau 	switch (hw->phy.media_type) {
20409c80d176SSepherosa Ziehau 	case e1000_media_type_fiber:
20419c80d176SSepherosa Ziehau 		ctrl = E1000_READ_REG(hw, E1000_CTRL);
20429c80d176SSepherosa Ziehau 		ctrl |= E1000_CTRL_SWDPIN0;
20439c80d176SSepherosa Ziehau 		ctrl |= E1000_CTRL_SWDPIO0;
20449c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
20459c80d176SSepherosa Ziehau 		break;
20469c80d176SSepherosa Ziehau 	case e1000_media_type_copper:
20479c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
20489c80d176SSepherosa Ziehau 		break;
20499c80d176SSepherosa Ziehau 	default:
20509c80d176SSepherosa Ziehau 		break;
20519c80d176SSepherosa Ziehau 	}
20529c80d176SSepherosa Ziehau 
20539c80d176SSepherosa Ziehau 	return E1000_SUCCESS;
20549c80d176SSepherosa Ziehau }
20559c80d176SSepherosa Ziehau 
20569c80d176SSepherosa Ziehau /**
20579c80d176SSepherosa Ziehau  *  e1000_set_pcie_no_snoop_generic - Set PCI-express capabilities
20589c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
20599c80d176SSepherosa Ziehau  *  @no_snoop: bitmap of snoop events
20609c80d176SSepherosa Ziehau  *
20619c80d176SSepherosa Ziehau  *  Set the PCI-express register to snoop for events enabled in 'no_snoop'.
20629c80d176SSepherosa Ziehau  **/
e1000_set_pcie_no_snoop_generic(struct e1000_hw * hw,u32 no_snoop)20639c80d176SSepherosa Ziehau void e1000_set_pcie_no_snoop_generic(struct e1000_hw *hw, u32 no_snoop)
20649c80d176SSepherosa Ziehau {
20659c80d176SSepherosa Ziehau 	u32 gcr;
20669c80d176SSepherosa Ziehau 
20679c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_set_pcie_no_snoop_generic");
20689c80d176SSepherosa Ziehau 
20699c80d176SSepherosa Ziehau 	if (hw->bus.type != e1000_bus_type_pci_express)
20704be59a01SSepherosa Ziehau 		return;
20719c80d176SSepherosa Ziehau 
20729c80d176SSepherosa Ziehau 	if (no_snoop) {
20739c80d176SSepherosa Ziehau 		gcr = E1000_READ_REG(hw, E1000_GCR);
20749c80d176SSepherosa Ziehau 		gcr &= ~(PCIE_NO_SNOOP_ALL);
20759c80d176SSepherosa Ziehau 		gcr |= no_snoop;
20769c80d176SSepherosa Ziehau 		E1000_WRITE_REG(hw, E1000_GCR, gcr);
20779c80d176SSepherosa Ziehau 	}
20789c80d176SSepherosa Ziehau }
20799c80d176SSepherosa Ziehau 
20809c80d176SSepherosa Ziehau /**
20819c80d176SSepherosa Ziehau  *  e1000_disable_pcie_master_generic - Disables PCI-express master access
20829c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
20839c80d176SSepherosa Ziehau  *
20846a5a645eSSepherosa Ziehau  *  Returns E1000_SUCCESS if successful, else returns -10
20859c80d176SSepherosa Ziehau  *  (-E1000_ERR_MASTER_REQUESTS_PENDING) if master disable bit has not caused
20869c80d176SSepherosa Ziehau  *  the master requests to be disabled.
20879c80d176SSepherosa Ziehau  *
20889c80d176SSepherosa Ziehau  *  Disables PCI-Express master access and verifies there are no pending
20899c80d176SSepherosa Ziehau  *  requests.
20909c80d176SSepherosa Ziehau  **/
e1000_disable_pcie_master_generic(struct e1000_hw * hw)20919c80d176SSepherosa Ziehau s32 e1000_disable_pcie_master_generic(struct e1000_hw *hw)
20929c80d176SSepherosa Ziehau {
20939c80d176SSepherosa Ziehau 	u32 ctrl;
20949c80d176SSepherosa Ziehau 	s32 timeout = MASTER_DISABLE_TIMEOUT;
20959c80d176SSepherosa Ziehau 
20969c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_disable_pcie_master_generic");
20979c80d176SSepherosa Ziehau 
20989c80d176SSepherosa Ziehau 	if (hw->bus.type != e1000_bus_type_pci_express)
20994be59a01SSepherosa Ziehau 		return E1000_SUCCESS;
21009c80d176SSepherosa Ziehau 
21019c80d176SSepherosa Ziehau 	ctrl = E1000_READ_REG(hw, E1000_CTRL);
21029c80d176SSepherosa Ziehau 	ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
21039c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
21049c80d176SSepherosa Ziehau 
21059c80d176SSepherosa Ziehau 	while (timeout) {
21069c80d176SSepherosa Ziehau 		if (!(E1000_READ_REG(hw, E1000_STATUS) &
210765aebe9fSSepherosa Ziehau 		      E1000_STATUS_GIO_MASTER_ENABLE) ||
210865aebe9fSSepherosa Ziehau 				E1000_REMOVED(hw->hw_addr))
21099c80d176SSepherosa Ziehau 			break;
21109c80d176SSepherosa Ziehau 		usec_delay(100);
21119c80d176SSepherosa Ziehau 		timeout--;
21129c80d176SSepherosa Ziehau 	}
21139c80d176SSepherosa Ziehau 
21149c80d176SSepherosa Ziehau 	if (!timeout) {
21159c80d176SSepherosa Ziehau 		DEBUGOUT("Master requests are pending.\n");
21164be59a01SSepherosa Ziehau 		return -E1000_ERR_MASTER_REQUESTS_PENDING;
21179c80d176SSepherosa Ziehau 	}
21189c80d176SSepherosa Ziehau 
21194be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
21209c80d176SSepherosa Ziehau }
21219c80d176SSepherosa Ziehau 
21229c80d176SSepherosa Ziehau /**
21239c80d176SSepherosa Ziehau  *  e1000_reset_adaptive_generic - Reset Adaptive Interframe Spacing
21249c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
21259c80d176SSepherosa Ziehau  *
21269c80d176SSepherosa Ziehau  *  Reset the Adaptive Interframe Spacing throttle to default values.
21279c80d176SSepherosa Ziehau  **/
e1000_reset_adaptive_generic(struct e1000_hw * hw)21289c80d176SSepherosa Ziehau void e1000_reset_adaptive_generic(struct e1000_hw *hw)
21299c80d176SSepherosa Ziehau {
21309c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
21319c80d176SSepherosa Ziehau 
21329c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_reset_adaptive_generic");
21339c80d176SSepherosa Ziehau 
21349c80d176SSepherosa Ziehau 	if (!mac->adaptive_ifs) {
21359c80d176SSepherosa Ziehau 		DEBUGOUT("Not in Adaptive IFS mode!\n");
21364be59a01SSepherosa Ziehau 		return;
21379c80d176SSepherosa Ziehau 	}
21389c80d176SSepherosa Ziehau 
21399c80d176SSepherosa Ziehau 	mac->current_ifs_val = 0;
21409c80d176SSepherosa Ziehau 	mac->ifs_min_val = IFS_MIN;
21419c80d176SSepherosa Ziehau 	mac->ifs_max_val = IFS_MAX;
21429c80d176SSepherosa Ziehau 	mac->ifs_step_size = IFS_STEP;
21439c80d176SSepherosa Ziehau 	mac->ifs_ratio = IFS_RATIO;
21449c80d176SSepherosa Ziehau 
21459c80d176SSepherosa Ziehau 	mac->in_ifs_mode = FALSE;
21469c80d176SSepherosa Ziehau 	E1000_WRITE_REG(hw, E1000_AIT, 0);
21479c80d176SSepherosa Ziehau }
21489c80d176SSepherosa Ziehau 
21499c80d176SSepherosa Ziehau /**
21509c80d176SSepherosa Ziehau  *  e1000_update_adaptive_generic - Update Adaptive Interframe Spacing
21519c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
21529c80d176SSepherosa Ziehau  *
21539c80d176SSepherosa Ziehau  *  Update the Adaptive Interframe Spacing Throttle value based on the
21549c80d176SSepherosa Ziehau  *  time between transmitted packets and time between collisions.
21559c80d176SSepherosa Ziehau  **/
e1000_update_adaptive_generic(struct e1000_hw * hw)21569c80d176SSepherosa Ziehau void e1000_update_adaptive_generic(struct e1000_hw *hw)
21579c80d176SSepherosa Ziehau {
21589c80d176SSepherosa Ziehau 	struct e1000_mac_info *mac = &hw->mac;
21599c80d176SSepherosa Ziehau 
21609c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_update_adaptive_generic");
21619c80d176SSepherosa Ziehau 
21629c80d176SSepherosa Ziehau 	if (!mac->adaptive_ifs) {
21639c80d176SSepherosa Ziehau 		DEBUGOUT("Not in Adaptive IFS mode!\n");
21644be59a01SSepherosa Ziehau 		return;
21659c80d176SSepherosa Ziehau 	}
21669c80d176SSepherosa Ziehau 
21679c80d176SSepherosa Ziehau 	if ((mac->collision_delta * mac->ifs_ratio) > mac->tx_packet_delta) {
21689c80d176SSepherosa Ziehau 		if (mac->tx_packet_delta > MIN_NUM_XMITS) {
21699c80d176SSepherosa Ziehau 			mac->in_ifs_mode = TRUE;
21709c80d176SSepherosa Ziehau 			if (mac->current_ifs_val < mac->ifs_max_val) {
21719c80d176SSepherosa Ziehau 				if (!mac->current_ifs_val)
21729c80d176SSepherosa Ziehau 					mac->current_ifs_val = mac->ifs_min_val;
21739c80d176SSepherosa Ziehau 				else
21749c80d176SSepherosa Ziehau 					mac->current_ifs_val +=
21759c80d176SSepherosa Ziehau 						mac->ifs_step_size;
21764be59a01SSepherosa Ziehau 				E1000_WRITE_REG(hw, E1000_AIT,
21774be59a01SSepherosa Ziehau 						mac->current_ifs_val);
21789c80d176SSepherosa Ziehau 			}
21799c80d176SSepherosa Ziehau 		}
21809c80d176SSepherosa Ziehau 	} else {
21819c80d176SSepherosa Ziehau 		if (mac->in_ifs_mode &&
21829c80d176SSepherosa Ziehau 		    (mac->tx_packet_delta <= MIN_NUM_XMITS)) {
21839c80d176SSepherosa Ziehau 			mac->current_ifs_val = 0;
21849c80d176SSepherosa Ziehau 			mac->in_ifs_mode = FALSE;
21859c80d176SSepherosa Ziehau 			E1000_WRITE_REG(hw, E1000_AIT, 0);
21869c80d176SSepherosa Ziehau 		}
21879c80d176SSepherosa Ziehau 	}
21889c80d176SSepherosa Ziehau }
21899c80d176SSepherosa Ziehau 
21909c80d176SSepherosa Ziehau /**
21919c80d176SSepherosa Ziehau  *  e1000_validate_mdi_setting_generic - Verify MDI/MDIx settings
21929c80d176SSepherosa Ziehau  *  @hw: pointer to the HW structure
21939c80d176SSepherosa Ziehau  *
21949c80d176SSepherosa Ziehau  *  Verify that when not using auto-negotiation that MDI/MDIx is correctly
21959c80d176SSepherosa Ziehau  *  set, which is forced to MDI mode only.
21969c80d176SSepherosa Ziehau  **/
e1000_validate_mdi_setting_generic(struct e1000_hw * hw)21976a5a645eSSepherosa Ziehau static s32 e1000_validate_mdi_setting_generic(struct e1000_hw *hw)
21989c80d176SSepherosa Ziehau {
21999c80d176SSepherosa Ziehau 	DEBUGFUNC("e1000_validate_mdi_setting_generic");
22009c80d176SSepherosa Ziehau 
22019c80d176SSepherosa Ziehau 	if (!hw->mac.autoneg && (hw->phy.mdix == 0 || hw->phy.mdix == 3)) {
22029c80d176SSepherosa Ziehau 		DEBUGOUT("Invalid MDI setting detected\n");
22039c80d176SSepherosa Ziehau 		hw->phy.mdix = 1;
22044be59a01SSepherosa Ziehau 		return -E1000_ERR_CONFIG;
22059c80d176SSepherosa Ziehau 	}
22069c80d176SSepherosa Ziehau 
22074be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
22084be59a01SSepherosa Ziehau }
22094be59a01SSepherosa Ziehau 
22104be59a01SSepherosa Ziehau /**
22114be59a01SSepherosa Ziehau  *  e1000_validate_mdi_setting_crossover_generic - Verify MDI/MDIx settings
22124be59a01SSepherosa Ziehau  *  @hw: pointer to the HW structure
22134be59a01SSepherosa Ziehau  *
22144be59a01SSepherosa Ziehau  *  Validate the MDI/MDIx setting, allowing for auto-crossover during forced
22154be59a01SSepherosa Ziehau  *  operation.
22164be59a01SSepherosa Ziehau  **/
e1000_validate_mdi_setting_crossover_generic(struct e1000_hw E1000_UNUSEDARG * hw)2217379ebbe7SSepherosa Ziehau s32 e1000_validate_mdi_setting_crossover_generic(struct e1000_hw E1000_UNUSEDARG *hw)
22184be59a01SSepherosa Ziehau {
22194be59a01SSepherosa Ziehau 	DEBUGFUNC("e1000_validate_mdi_setting_crossover_generic");
22204be59a01SSepherosa Ziehau 
22214be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
22229c80d176SSepherosa Ziehau }
222362583d18SSepherosa Ziehau 
222462583d18SSepherosa Ziehau /**
222562583d18SSepherosa Ziehau  *  e1000_write_8bit_ctrl_reg_generic - Write a 8bit CTRL register
222662583d18SSepherosa Ziehau  *  @hw: pointer to the HW structure
222762583d18SSepherosa Ziehau  *  @reg: 32bit register offset such as E1000_SCTL
222862583d18SSepherosa Ziehau  *  @offset: register offset to write to
222962583d18SSepherosa Ziehau  *  @data: data to write at register offset
223062583d18SSepherosa Ziehau  *
223162583d18SSepherosa Ziehau  *  Writes an address/data control type register.  There are several of these
223262583d18SSepherosa Ziehau  *  and they all have the format address << 8 | data and bit 31 is polled for
223362583d18SSepherosa Ziehau  *  completion.
223462583d18SSepherosa Ziehau  **/
e1000_write_8bit_ctrl_reg_generic(struct e1000_hw * hw,u32 reg,u32 offset,u8 data)223562583d18SSepherosa Ziehau s32 e1000_write_8bit_ctrl_reg_generic(struct e1000_hw *hw, u32 reg,
223662583d18SSepherosa Ziehau 				      u32 offset, u8 data)
223762583d18SSepherosa Ziehau {
223862583d18SSepherosa Ziehau 	u32 i, regvalue = 0;
223962583d18SSepherosa Ziehau 
224062583d18SSepherosa Ziehau 	DEBUGFUNC("e1000_write_8bit_ctrl_reg_generic");
224162583d18SSepherosa Ziehau 
224262583d18SSepherosa Ziehau 	/* Set up the address and data */
224362583d18SSepherosa Ziehau 	regvalue = ((u32)data) | (offset << E1000_GEN_CTL_ADDRESS_SHIFT);
224462583d18SSepherosa Ziehau 	E1000_WRITE_REG(hw, reg, regvalue);
224562583d18SSepherosa Ziehau 
224662583d18SSepherosa Ziehau 	/* Poll the ready bit to see if the MDI read completed */
224762583d18SSepherosa Ziehau 	for (i = 0; i < E1000_GEN_POLL_TIMEOUT; i++) {
224862583d18SSepherosa Ziehau 		usec_delay(5);
224962583d18SSepherosa Ziehau 		regvalue = E1000_READ_REG(hw, reg);
225062583d18SSepherosa Ziehau 		if (regvalue & E1000_GEN_CTL_READY)
225162583d18SSepherosa Ziehau 			break;
225262583d18SSepherosa Ziehau 	}
225362583d18SSepherosa Ziehau 	if (!(regvalue & E1000_GEN_CTL_READY)) {
225462583d18SSepherosa Ziehau 		DEBUGOUT1("Reg %08x did not indicate ready\n", reg);
22554be59a01SSepherosa Ziehau 		return -E1000_ERR_PHY;
225662583d18SSepherosa Ziehau 	}
225762583d18SSepherosa Ziehau 
22584be59a01SSepherosa Ziehau 	return E1000_SUCCESS;
225962583d18SSepherosa Ziehau }
2260