xref: /onnv-gate/usr/src/uts/common/io/ixgbe/ixgbe_common.c (revision 13006:22e6d3edaab5)
16621Sbt150084 /*
26621Sbt150084  * CDDL HEADER START
36621Sbt150084  *
46621Sbt150084  * The contents of this file are subject to the terms of the
56621Sbt150084  * Common Development and Distribution License (the "License").
66621Sbt150084  * You may not use this file except in compliance with the License.
76621Sbt150084  *
88275SEric Cheng  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
98275SEric Cheng  * or http://www.opensolaris.org/os/licensing.
106621Sbt150084  * See the License for the specific language governing permissions
116621Sbt150084  * and limitations under the License.
126621Sbt150084  *
138275SEric Cheng  * When distributing Covered Code, include this CDDL HEADER in each
148275SEric Cheng  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156621Sbt150084  * If applicable, add the following below this CDDL HEADER, with the
166621Sbt150084  * fields enclosed by brackets "[]" replaced with your own identifying
176621Sbt150084  * information: Portions Copyright [yyyy] [name of copyright owner]
186621Sbt150084  *
196621Sbt150084  * CDDL HEADER END
206621Sbt150084  */
216621Sbt150084 
226621Sbt150084 /*
23*13006SChenlu.Chen@Sun.COM  * Copyright(c) 2007-2010 Intel Corporation. All rights reserved.
246621Sbt150084  */
256621Sbt150084 
26*13006SChenlu.Chen@Sun.COM /*
27*13006SChenlu.Chen@Sun.COM  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28*13006SChenlu.Chen@Sun.COM  */
29*13006SChenlu.Chen@Sun.COM 
30*13006SChenlu.Chen@Sun.COM /* IntelVersion: 1.238 scm_061610_003709 */
316621Sbt150084 
326621Sbt150084 #include "ixgbe_common.h"
33*13006SChenlu.Chen@Sun.COM #include "ixgbe_phy.h"
346621Sbt150084 #include "ixgbe_api.h"
356621Sbt150084 
366621Sbt150084 static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
376621Sbt150084 static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
386621Sbt150084 static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
396621Sbt150084 static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
406621Sbt150084 static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
416621Sbt150084 static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
426621Sbt150084     u16 count);
436621Sbt150084 static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
446621Sbt150084 static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
456621Sbt150084 static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
466621Sbt150084 static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
476621Sbt150084 
486621Sbt150084 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
4910998SChenlu.Chen@Sun.COM static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
5010998SChenlu.Chen@Sun.COM     u16 *san_mac_offset);
51*13006SChenlu.Chen@Sun.COM static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw);
52*13006SChenlu.Chen@Sun.COM static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw);
53*13006SChenlu.Chen@Sun.COM static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw);
54*13006SChenlu.Chen@Sun.COM static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw);
55*13006SChenlu.Chen@Sun.COM static s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
56*13006SChenlu.Chen@Sun.COM     u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm);
5710998SChenlu.Chen@Sun.COM s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan);
586621Sbt150084 
596621Sbt150084 /*
606621Sbt150084  * ixgbe_init_ops_generic - Inits function ptrs
616621Sbt150084  * @hw: pointer to the hardware structure
626621Sbt150084  *
636621Sbt150084  * Initialize the function pointers.
646621Sbt150084  */
656621Sbt150084 s32
ixgbe_init_ops_generic(struct ixgbe_hw * hw)666621Sbt150084 ixgbe_init_ops_generic(struct ixgbe_hw *hw)
676621Sbt150084 {
686621Sbt150084 	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
696621Sbt150084 	struct ixgbe_mac_info *mac = &hw->mac;
708490SPaul.Guo@Sun.COM 	u32 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
716621Sbt150084 
7210998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_init_ops_generic");
7310998SChenlu.Chen@Sun.COM 
746621Sbt150084 	/* EEPROM */
756621Sbt150084 	eeprom->ops.init_params = &ixgbe_init_eeprom_params_generic;
768490SPaul.Guo@Sun.COM 	/* If EEPROM is valid (bit 8 = 1), use EERD otherwise use bit bang */
778490SPaul.Guo@Sun.COM 	if (eec & (1 << 8))
7810998SChenlu.Chen@Sun.COM 		eeprom->ops.read = &ixgbe_read_eerd_generic;
798490SPaul.Guo@Sun.COM 	else
808490SPaul.Guo@Sun.COM 		eeprom->ops.read = &ixgbe_read_eeprom_bit_bang_generic;
816621Sbt150084 	eeprom->ops.write = &ixgbe_write_eeprom_generic;
826621Sbt150084 	eeprom->ops.validate_checksum =
836621Sbt150084 	    &ixgbe_validate_eeprom_checksum_generic;
846621Sbt150084 	eeprom->ops.update_checksum = &ixgbe_update_eeprom_checksum_generic;
8512003SPaul.Guo@Sun.COM 	eeprom->ops.calc_checksum = &ixgbe_calc_eeprom_checksum_generic;
866621Sbt150084 
876621Sbt150084 	/* MAC */
886621Sbt150084 	mac->ops.init_hw = &ixgbe_init_hw_generic;
896621Sbt150084 	mac->ops.reset_hw = NULL;
906621Sbt150084 	mac->ops.start_hw = &ixgbe_start_hw_generic;
916621Sbt150084 	mac->ops.clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic;
926621Sbt150084 	mac->ops.get_media_type = NULL;
938490SPaul.Guo@Sun.COM 	mac->ops.get_supported_physical_layer = NULL;
949353SSamuel.Tu@Sun.COM 	mac->ops.enable_rx_dma = &ixgbe_enable_rx_dma_generic;
956621Sbt150084 	mac->ops.get_mac_addr = &ixgbe_get_mac_addr_generic;
966621Sbt150084 	mac->ops.stop_adapter = &ixgbe_stop_adapter_generic;
976621Sbt150084 	mac->ops.get_bus_info = &ixgbe_get_bus_info_generic;
989353SSamuel.Tu@Sun.COM 	mac->ops.set_lan_id = &ixgbe_set_lan_id_multi_port_pcie;
9910305SPaul.Guo@Sun.COM 	mac->ops.acquire_swfw_sync = &ixgbe_acquire_swfw_sync;
10010305SPaul.Guo@Sun.COM 	mac->ops.release_swfw_sync = &ixgbe_release_swfw_sync;
1016621Sbt150084 
1026621Sbt150084 	/* LEDs */
1036621Sbt150084 	mac->ops.led_on = &ixgbe_led_on_generic;
1046621Sbt150084 	mac->ops.led_off = &ixgbe_led_off_generic;
1059353SSamuel.Tu@Sun.COM 	mac->ops.blink_led_start = &ixgbe_blink_led_start_generic;
1069353SSamuel.Tu@Sun.COM 	mac->ops.blink_led_stop = &ixgbe_blink_led_stop_generic;
1076621Sbt150084 
1086621Sbt150084 	/* RAR, Multicast, VLAN */
1096621Sbt150084 	mac->ops.set_rar = &ixgbe_set_rar_generic;
1108490SPaul.Guo@Sun.COM 	mac->ops.clear_rar = &ixgbe_clear_rar_generic;
1119353SSamuel.Tu@Sun.COM 	mac->ops.insert_mac_addr = NULL;
1126621Sbt150084 	mac->ops.set_vmdq = NULL;
1138490SPaul.Guo@Sun.COM 	mac->ops.clear_vmdq = NULL;
1146621Sbt150084 	mac->ops.init_rx_addrs = &ixgbe_init_rx_addrs_generic;
1156621Sbt150084 	mac->ops.update_uc_addr_list = &ixgbe_update_uc_addr_list_generic;
1166621Sbt150084 	mac->ops.update_mc_addr_list = &ixgbe_update_mc_addr_list_generic;
1176621Sbt150084 	mac->ops.enable_mc = &ixgbe_enable_mc_generic;
1186621Sbt150084 	mac->ops.disable_mc = &ixgbe_disable_mc_generic;
1198490SPaul.Guo@Sun.COM 	mac->ops.clear_vfta = NULL;
1208490SPaul.Guo@Sun.COM 	mac->ops.set_vfta = NULL;
1218490SPaul.Guo@Sun.COM 	mac->ops.init_uta_tables = NULL;
1226621Sbt150084 
1236621Sbt150084 	/* Flow Control */
1249353SSamuel.Tu@Sun.COM 	mac->ops.fc_enable = &ixgbe_fc_enable_generic;
1256621Sbt150084 
1266621Sbt150084 	/* Link */
1276621Sbt150084 	mac->ops.get_link_capabilities = NULL;
1286621Sbt150084 	mac->ops.setup_link = NULL;
1296621Sbt150084 	mac->ops.check_link = NULL;
1306621Sbt150084 
1316621Sbt150084 	return (IXGBE_SUCCESS);
1326621Sbt150084 }
1336621Sbt150084 
1346621Sbt150084 /*
1356621Sbt150084  * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
1366621Sbt150084  * @hw: pointer to hardware structure
1376621Sbt150084  *
1386621Sbt150084  * Starts the hardware by filling the bus info structure and media type, clears
1396621Sbt150084  * all on chip counters, initializes receive address registers, multicast
1406621Sbt150084  * table, VLAN filter table, calls routine to set up link and flow control
1416621Sbt150084  * settings, and leaves transmit and receive units disabled and uninitialized
1426621Sbt150084  */
1436621Sbt150084 s32
ixgbe_start_hw_generic(struct ixgbe_hw * hw)1446621Sbt150084 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
1456621Sbt150084 {
1466621Sbt150084 	u32 ctrl_ext;
1476621Sbt150084 
14810998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_start_hw_generic");
14910998SChenlu.Chen@Sun.COM 
1506621Sbt150084 	/* Set the media type */
1516621Sbt150084 	hw->phy.media_type = hw->mac.ops.get_media_type(hw);
1526621Sbt150084 
1539353SSamuel.Tu@Sun.COM 	/* PHY ops initialization must be done in reset_hw() */
1546621Sbt150084 
1556621Sbt150084 	/* Clear the VLAN filter table */
1566621Sbt150084 	hw->mac.ops.clear_vfta(hw);
1576621Sbt150084 
1586621Sbt150084 	/* Clear statistics registers */
1596621Sbt150084 	hw->mac.ops.clear_hw_cntrs(hw);
1606621Sbt150084 
1616621Sbt150084 	/* Set No Snoop Disable */
1626621Sbt150084 	ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
1636621Sbt150084 	ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
1646621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
1656621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
1666621Sbt150084 
1679353SSamuel.Tu@Sun.COM 	/* Setup flow control */
1689353SSamuel.Tu@Sun.COM 	(void) ixgbe_setup_fc(hw, 0);
1699353SSamuel.Tu@Sun.COM 
1706621Sbt150084 	/* Clear adapter stopped flag */
1718490SPaul.Guo@Sun.COM 	hw->adapter_stopped = false;
1726621Sbt150084 
1736621Sbt150084 	return (IXGBE_SUCCESS);
1746621Sbt150084 }
1756621Sbt150084 
1766621Sbt150084 /*
1776621Sbt150084  * ixgbe_init_hw_generic - Generic hardware initialization
1786621Sbt150084  * @hw: pointer to hardware structure
1796621Sbt150084  *
1806621Sbt150084  * Initialize the hardware by resetting the hardware, filling the bus info
1816621Sbt150084  * structure and media type, clears all on chip counters, initializes receive
1826621Sbt150084  * address registers, multicast table, VLAN filter table, calls routine to set
1836621Sbt150084  * up link and flow control settings, and leaves transmit and receive units
1846621Sbt150084  * disabled and uninitialized
1856621Sbt150084  */
1866621Sbt150084 s32
ixgbe_init_hw_generic(struct ixgbe_hw * hw)1876621Sbt150084 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
1886621Sbt150084 {
1899353SSamuel.Tu@Sun.COM 	s32 status = IXGBE_SUCCESS;
1909353SSamuel.Tu@Sun.COM 
19110998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_init_hw_generic");
19210998SChenlu.Chen@Sun.COM 
1936621Sbt150084 	/* Reset the hardware */
1949353SSamuel.Tu@Sun.COM 	status = hw->mac.ops.reset_hw(hw);
1956621Sbt150084 
1969353SSamuel.Tu@Sun.COM 	if (status == IXGBE_SUCCESS) {
1979353SSamuel.Tu@Sun.COM 		/* Start the HW */
1989353SSamuel.Tu@Sun.COM 		status = hw->mac.ops.start_hw(hw);
1999353SSamuel.Tu@Sun.COM 	}
2006621Sbt150084 
2019353SSamuel.Tu@Sun.COM 	return (status);
2026621Sbt150084 }
2036621Sbt150084 
2046621Sbt150084 /*
2056621Sbt150084  * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
2066621Sbt150084  * @hw: pointer to hardware structure
2076621Sbt150084  *
2086621Sbt150084  * Clears all hardware statistics counters by reading them from the hardware
2096621Sbt150084  * Statistics counters are clear on read.
2106621Sbt150084  */
2116621Sbt150084 s32
ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw * hw)2126621Sbt150084 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
2136621Sbt150084 {
2146621Sbt150084 	u16 i = 0;
2156621Sbt150084 
21610998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_clear_hw_cntrs_generic");
21710998SChenlu.Chen@Sun.COM 
2186621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_CRCERRS);
2196621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_ILLERRC);
2206621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_ERRBC);
2216621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MSPDC);
2226621Sbt150084 	for (i = 0; i < 8; i++)
2236621Sbt150084 		(void) IXGBE_READ_REG(hw, IXGBE_MPC(i));
2246621Sbt150084 
2256621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MLFC);
2266621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MRFC);
2276621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_RLEC);
2286621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_LXONTXC);
2296621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
2309353SSamuel.Tu@Sun.COM 	if (hw->mac.type >= ixgbe_mac_82599EB) {
2319353SSamuel.Tu@Sun.COM 		(void) IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
2329353SSamuel.Tu@Sun.COM 		(void) IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
2339353SSamuel.Tu@Sun.COM 	} else {
2349353SSamuel.Tu@Sun.COM 		(void) IXGBE_READ_REG(hw, IXGBE_LXONRXC);
2359353SSamuel.Tu@Sun.COM 		(void) IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
2369353SSamuel.Tu@Sun.COM 	}
2376621Sbt150084 
2386621Sbt150084 	for (i = 0; i < 8; i++) {
2396621Sbt150084 		(void) IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
2406621Sbt150084 		(void) IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
2419353SSamuel.Tu@Sun.COM 		if (hw->mac.type >= ixgbe_mac_82599EB) {
2429353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
2439353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
2449353SSamuel.Tu@Sun.COM 		} else {
2459353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
2469353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
2479353SSamuel.Tu@Sun.COM 		}
2486621Sbt150084 	}
2499353SSamuel.Tu@Sun.COM 	if (hw->mac.type >= ixgbe_mac_82599EB)
2509353SSamuel.Tu@Sun.COM 		for (i = 0; i < 8; i++)
2519353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
2526621Sbt150084 
2536621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PRC64);
2546621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PRC127);
2556621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PRC255);
2566621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PRC511);
2576621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PRC1023);
2586621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PRC1522);
2596621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_GPRC);
2606621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_BPRC);
2616621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MPRC);
2626621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_GPTC);
2636621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_GORCL);
2646621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_GORCH);
2656621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_GOTCL);
2666621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_GOTCH);
2676621Sbt150084 	for (i = 0; i < 8; i++)
2686621Sbt150084 		(void) IXGBE_READ_REG(hw, IXGBE_RNBC(i));
2696621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_RUC);
2706621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_RFC);
2716621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_ROC);
2726621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_RJC);
2736621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MNGPRC);
2746621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MNGPDC);
2756621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MNGPTC);
2766621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_TORL);
2776621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_TORH);
2786621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_TPR);
2796621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_TPT);
2806621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PTC64);
2816621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PTC127);
2826621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PTC255);
2836621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PTC511);
2846621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PTC1023);
2856621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_PTC1522);
2866621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_MPTC);
2876621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_BPTC);
2886621Sbt150084 	for (i = 0; i < 16; i++) {
2896621Sbt150084 		(void) IXGBE_READ_REG(hw, IXGBE_QPRC(i));
2906621Sbt150084 		(void) IXGBE_READ_REG(hw, IXGBE_QPTC(i));
2919353SSamuel.Tu@Sun.COM 		if (hw->mac.type >= ixgbe_mac_82599EB) {
292*13006SChenlu.Chen@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
293*13006SChenlu.Chen@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
2949353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
2959353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
296*13006SChenlu.Chen@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
2979353SSamuel.Tu@Sun.COM 		} else {
298*13006SChenlu.Chen@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_QBRC(i));
2999353SSamuel.Tu@Sun.COM 			(void) IXGBE_READ_REG(hw, IXGBE_QBTC(i));
3009353SSamuel.Tu@Sun.COM 		}
3016621Sbt150084 	}
3026621Sbt150084 
3036621Sbt150084 	return (IXGBE_SUCCESS);
3046621Sbt150084 }
3056621Sbt150084 
3066621Sbt150084 /*
3078490SPaul.Guo@Sun.COM  * ixgbe_read_pba_num_generic - Reads part number from EEPROM
3086621Sbt150084  * @hw: pointer to hardware structure
3096621Sbt150084  * @pba_num: stores the part number from the EEPROM
3106621Sbt150084  *
3116621Sbt150084  * Reads the part number from the EEPROM.
3126621Sbt150084  */
3136621Sbt150084 s32
ixgbe_read_pba_num_generic(struct ixgbe_hw * hw,u32 * pba_num)3146621Sbt150084 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
3156621Sbt150084 {
3166621Sbt150084 	s32 ret_val;
3176621Sbt150084 	u16 data;
3186621Sbt150084 
3196621Sbt150084 	DEBUGFUNC("ixgbe_read_pba_num_generic");
3206621Sbt150084 
3216621Sbt150084 	ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
3226621Sbt150084 	if (ret_val) {
3236621Sbt150084 		DEBUGOUT("NVM Read Error\n");
3246621Sbt150084 		return (ret_val);
3256621Sbt150084 	}
3266621Sbt150084 	*pba_num = (u32)(data << 16);
3276621Sbt150084 
3286621Sbt150084 	ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
3296621Sbt150084 	if (ret_val) {
3306621Sbt150084 		DEBUGOUT("NVM Read Error\n");
3316621Sbt150084 		return (ret_val);
3326621Sbt150084 	}
3336621Sbt150084 	*pba_num |= data;
3346621Sbt150084 
3356621Sbt150084 	return (IXGBE_SUCCESS);
3366621Sbt150084 }
3376621Sbt150084 
3386621Sbt150084 /*
3396621Sbt150084  * ixgbe_get_mac_addr_generic - Generic get MAC address
3406621Sbt150084  * @hw: pointer to hardware structure
3416621Sbt150084  * @mac_addr: Adapter MAC address
3426621Sbt150084  *
3436621Sbt150084  * Reads the adapter's MAC address from first Receive Address Register (RAR0)
3446621Sbt150084  * A reset of the adapter must be performed prior to calling this function
3456621Sbt150084  * in order for the MAC address to have been loaded from the EEPROM into RAR0
3466621Sbt150084  */
3476621Sbt150084 s32
ixgbe_get_mac_addr_generic(struct ixgbe_hw * hw,u8 * mac_addr)3486621Sbt150084 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
3496621Sbt150084 {
3506621Sbt150084 	u32 rar_high;
3516621Sbt150084 	u32 rar_low;
3526621Sbt150084 	u16 i;
3536621Sbt150084 
35410998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_mac_addr_generic");
35510998SChenlu.Chen@Sun.COM 
3566621Sbt150084 	rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
3576621Sbt150084 	rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
3586621Sbt150084 
3596621Sbt150084 	for (i = 0; i < 4; i++)
3606621Sbt150084 		mac_addr[i] = (u8)(rar_low >> (i*8));
3616621Sbt150084 
3626621Sbt150084 	for (i = 0; i < 2; i++)
3636621Sbt150084 		mac_addr[i+4] = (u8)(rar_high >> (i*8));
3646621Sbt150084 
3656621Sbt150084 	return (IXGBE_SUCCESS);
3666621Sbt150084 }
3676621Sbt150084 
3686621Sbt150084 /*
3696621Sbt150084  * ixgbe_get_bus_info_generic - Generic set PCI bus info
3706621Sbt150084  * @hw: pointer to hardware structure
3716621Sbt150084  *
3726621Sbt150084  * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
3736621Sbt150084  */
3746621Sbt150084 s32
ixgbe_get_bus_info_generic(struct ixgbe_hw * hw)3756621Sbt150084 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
3766621Sbt150084 {
3779353SSamuel.Tu@Sun.COM 	struct ixgbe_mac_info *mac = &hw->mac;
3786621Sbt150084 	u16 link_status;
3796621Sbt150084 
38010998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_bus_info_generic");
38110998SChenlu.Chen@Sun.COM 
3826621Sbt150084 	hw->bus.type = ixgbe_bus_type_pci_express;
3836621Sbt150084 
3846621Sbt150084 	/* Get the negotiated link width and speed from PCI config space */
3856621Sbt150084 	link_status = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_LINK_STATUS);
3866621Sbt150084 
3876621Sbt150084 	switch (link_status & IXGBE_PCI_LINK_WIDTH) {
3886621Sbt150084 	case IXGBE_PCI_LINK_WIDTH_1:
3896621Sbt150084 		hw->bus.width = ixgbe_bus_width_pcie_x1;
3906621Sbt150084 		break;
3916621Sbt150084 	case IXGBE_PCI_LINK_WIDTH_2:
3926621Sbt150084 		hw->bus.width = ixgbe_bus_width_pcie_x2;
3936621Sbt150084 		break;
3946621Sbt150084 	case IXGBE_PCI_LINK_WIDTH_4:
3956621Sbt150084 		hw->bus.width = ixgbe_bus_width_pcie_x4;
3966621Sbt150084 		break;
3976621Sbt150084 	case IXGBE_PCI_LINK_WIDTH_8:
3986621Sbt150084 		hw->bus.width = ixgbe_bus_width_pcie_x8;
3996621Sbt150084 		break;
4006621Sbt150084 	default:
4016621Sbt150084 		hw->bus.width = ixgbe_bus_width_unknown;
4026621Sbt150084 		break;
4036621Sbt150084 	}
4046621Sbt150084 
4056621Sbt150084 	switch (link_status & IXGBE_PCI_LINK_SPEED) {
4066621Sbt150084 	case IXGBE_PCI_LINK_SPEED_2500:
4076621Sbt150084 		hw->bus.speed = ixgbe_bus_speed_2500;
4086621Sbt150084 		break;
4096621Sbt150084 	case IXGBE_PCI_LINK_SPEED_5000:
4106621Sbt150084 		hw->bus.speed = ixgbe_bus_speed_5000;
4116621Sbt150084 		break;
4126621Sbt150084 	default:
4136621Sbt150084 		hw->bus.speed = ixgbe_bus_speed_unknown;
4146621Sbt150084 		break;
4156621Sbt150084 	}
4166621Sbt150084 
4179353SSamuel.Tu@Sun.COM 	mac->ops.set_lan_id(hw);
4189353SSamuel.Tu@Sun.COM 
4196621Sbt150084 	return (IXGBE_SUCCESS);
4206621Sbt150084 }
4216621Sbt150084 
4229353SSamuel.Tu@Sun.COM 
4239353SSamuel.Tu@Sun.COM /*
4249353SSamuel.Tu@Sun.COM  * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
4259353SSamuel.Tu@Sun.COM  * @hw: pointer to the HW structure
4269353SSamuel.Tu@Sun.COM  *
4279353SSamuel.Tu@Sun.COM  * Determines the LAN function id by reading memory-mapped registers
4289353SSamuel.Tu@Sun.COM  * and swaps the port value if requested.
4299353SSamuel.Tu@Sun.COM  */
4309353SSamuel.Tu@Sun.COM void
ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw * hw)4319353SSamuel.Tu@Sun.COM ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
4329353SSamuel.Tu@Sun.COM {
4339353SSamuel.Tu@Sun.COM 	struct ixgbe_bus_info *bus = &hw->bus;
4349353SSamuel.Tu@Sun.COM 	u32 reg;
4359353SSamuel.Tu@Sun.COM 
43610998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_set_lan_id_multi_port_pcie");
43710998SChenlu.Chen@Sun.COM 
4389353SSamuel.Tu@Sun.COM 	reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
4399353SSamuel.Tu@Sun.COM 	bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
4409353SSamuel.Tu@Sun.COM 	bus->lan_id = bus->func;
4419353SSamuel.Tu@Sun.COM 
4429353SSamuel.Tu@Sun.COM 	/* check for a port swap */
4439353SSamuel.Tu@Sun.COM 	reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
4449353SSamuel.Tu@Sun.COM 	if (reg & IXGBE_FACTPS_LFS)
4459353SSamuel.Tu@Sun.COM 		bus->func ^= 0x1;
4469353SSamuel.Tu@Sun.COM }
4479353SSamuel.Tu@Sun.COM 
4486621Sbt150084 /*
4496621Sbt150084  * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
4506621Sbt150084  * @hw: pointer to hardware structure
4516621Sbt150084  *
4526621Sbt150084  * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
4536621Sbt150084  * disables transmit and receive units. The adapter_stopped flag is used by
4546621Sbt150084  * the shared code and drivers to determine if the adapter is in a stopped
4556621Sbt150084  * state and should not touch the hardware.
4566621Sbt150084  */
4576621Sbt150084 s32
ixgbe_stop_adapter_generic(struct ixgbe_hw * hw)4586621Sbt150084 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
4596621Sbt150084 {
4606621Sbt150084 	u32 number_of_queues;
4616621Sbt150084 	u32 reg_val;
4626621Sbt150084 	u16 i;
4636621Sbt150084 
46410998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_stop_adapter_generic");
46510998SChenlu.Chen@Sun.COM 
4666621Sbt150084 	/*
4676621Sbt150084 	 * Set the adapter_stopped flag so other driver functions stop touching
4686621Sbt150084 	 * the hardware
4696621Sbt150084 	 */
4708490SPaul.Guo@Sun.COM 	hw->adapter_stopped = true;
4716621Sbt150084 
4726621Sbt150084 	/* Disable the receive unit */
4736621Sbt150084 	reg_val = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4746621Sbt150084 	reg_val &= ~(IXGBE_RXCTRL_RXEN);
4756621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg_val);
4766621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
4776621Sbt150084 	msec_delay(2);
4786621Sbt150084 
4796621Sbt150084 	/* Clear interrupt mask to stop from interrupts being generated */
4806621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
4816621Sbt150084 
4826621Sbt150084 	/* Clear any pending interrupts */
4836621Sbt150084 	(void) IXGBE_READ_REG(hw, IXGBE_EICR);
4846621Sbt150084 
4856621Sbt150084 	/* Disable the transmit unit.  Each queue must be disabled. */
4866621Sbt150084 	number_of_queues = hw->mac.max_tx_queues;
4876621Sbt150084 	for (i = 0; i < number_of_queues; i++) {
4886621Sbt150084 		reg_val = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
4896621Sbt150084 		if (reg_val & IXGBE_TXDCTL_ENABLE) {
4906621Sbt150084 			reg_val &= ~IXGBE_TXDCTL_ENABLE;
4916621Sbt150084 			IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), reg_val);
4926621Sbt150084 		}
4936621Sbt150084 	}
4946621Sbt150084 
4956621Sbt150084 	/*
4966621Sbt150084 	 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
4976621Sbt150084 	 * access and verify no pending requests
4986621Sbt150084 	 */
49912003SPaul.Guo@Sun.COM 	(void) ixgbe_disable_pcie_master(hw);
5006621Sbt150084 
5016621Sbt150084 	return (IXGBE_SUCCESS);
5026621Sbt150084 }
5036621Sbt150084 
5046621Sbt150084 /*
5056621Sbt150084  * ixgbe_led_on_generic - Turns on the software controllable LEDs.
5066621Sbt150084  * @hw: pointer to hardware structure
5076621Sbt150084  * @index: led number to turn on
5086621Sbt150084  */
5096621Sbt150084 s32
ixgbe_led_on_generic(struct ixgbe_hw * hw,u32 index)5106621Sbt150084 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
5116621Sbt150084 {
5126621Sbt150084 	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
5136621Sbt150084 
51410998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_led_on_generic");
51510998SChenlu.Chen@Sun.COM 
5166621Sbt150084 	/* To turn on the LED, set mode to ON. */
5176621Sbt150084 	led_reg &= ~IXGBE_LED_MODE_MASK(index);
5186621Sbt150084 	led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
5196621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
5206621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
5216621Sbt150084 
5226621Sbt150084 	return (IXGBE_SUCCESS);
5236621Sbt150084 }
5246621Sbt150084 
5256621Sbt150084 /*
5266621Sbt150084  * ixgbe_led_off_generic - Turns off the software controllable LEDs.
5276621Sbt150084  * @hw: pointer to hardware structure
5286621Sbt150084  * @index: led number to turn off
5296621Sbt150084  */
5306621Sbt150084 s32
ixgbe_led_off_generic(struct ixgbe_hw * hw,u32 index)5316621Sbt150084 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
5326621Sbt150084 {
5336621Sbt150084 	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
5346621Sbt150084 
53510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_led_off_generic");
53610998SChenlu.Chen@Sun.COM 
5376621Sbt150084 	/* To turn off the LED, set mode to OFF. */
5386621Sbt150084 	led_reg &= ~IXGBE_LED_MODE_MASK(index);
5396621Sbt150084 	led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
5406621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
5416621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
5426621Sbt150084 
5436621Sbt150084 	return (IXGBE_SUCCESS);
5446621Sbt150084 }
5456621Sbt150084 
5466621Sbt150084 /*
5476621Sbt150084  * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
5486621Sbt150084  * @hw: pointer to hardware structure
5496621Sbt150084  *
5506621Sbt150084  * Initializes the EEPROM parameters ixgbe_eeprom_info within the
5516621Sbt150084  * ixgbe_hw struct in order to set up EEPROM access.
5526621Sbt150084  */
5536621Sbt150084 s32
ixgbe_init_eeprom_params_generic(struct ixgbe_hw * hw)5546621Sbt150084 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
5556621Sbt150084 {
5566621Sbt150084 	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
5576621Sbt150084 	u32 eec;
5586621Sbt150084 	u16 eeprom_size;
5596621Sbt150084 
56010998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_init_eeprom_params_generic");
56110998SChenlu.Chen@Sun.COM 
5626621Sbt150084 	if (eeprom->type == ixgbe_eeprom_uninitialized) {
5636621Sbt150084 		eeprom->type = ixgbe_eeprom_none;
5648490SPaul.Guo@Sun.COM 		/*
5658490SPaul.Guo@Sun.COM 		 * Set default semaphore delay to 10ms which is a well
5668490SPaul.Guo@Sun.COM 		 * tested value
5678490SPaul.Guo@Sun.COM 		 */
5688490SPaul.Guo@Sun.COM 		eeprom->semaphore_delay = 10;
5696621Sbt150084 
5706621Sbt150084 		/*
5716621Sbt150084 		 * Check for EEPROM present first.
5726621Sbt150084 		 * If not present leave as none
5736621Sbt150084 		 */
5746621Sbt150084 		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
5756621Sbt150084 		if (eec & IXGBE_EEC_PRES) {
5766621Sbt150084 			eeprom->type = ixgbe_eeprom_spi;
5776621Sbt150084 
5786621Sbt150084 			/*
5796621Sbt150084 			 * SPI EEPROM is assumed here.  This code would need to
5806621Sbt150084 			 * change if a future EEPROM is not SPI.
5816621Sbt150084 			 */
5826621Sbt150084 			eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
5836621Sbt150084 			    IXGBE_EEC_SIZE_SHIFT);
5846621Sbt150084 			eeprom->word_size = 1 << (eeprom_size +
58510998SChenlu.Chen@Sun.COM 			    IXGBE_EEPROM_WORD_SIZE_BASE_SHIFT);
5866621Sbt150084 		}
5876621Sbt150084 
5886621Sbt150084 		if (eec & IXGBE_EEC_ADDR_SIZE)
5896621Sbt150084 			eeprom->address_bits = 16;
5906621Sbt150084 		else
5916621Sbt150084 			eeprom->address_bits = 8;
5926621Sbt150084 		DEBUGOUT3("Eeprom params: type = %d, size = %d, address bits: "
5936621Sbt150084 		    "%d\n", eeprom->type, eeprom->word_size,
5946621Sbt150084 		    eeprom->address_bits);
5956621Sbt150084 	}
5966621Sbt150084 
5976621Sbt150084 	return (IXGBE_SUCCESS);
5986621Sbt150084 }
5996621Sbt150084 
6006621Sbt150084 /*
6016621Sbt150084  * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
6026621Sbt150084  * @hw: pointer to hardware structure
6036621Sbt150084  * @offset: offset within the EEPROM to be written to
6046621Sbt150084  * @data: 16 bit word to be written to the EEPROM
6056621Sbt150084  *
6066621Sbt150084  * If ixgbe_eeprom_update_checksum is not called after this function, the
6076621Sbt150084  * EEPROM will most likely contain an invalid checksum.
6086621Sbt150084  */
6096621Sbt150084 s32
ixgbe_write_eeprom_generic(struct ixgbe_hw * hw,u16 offset,u16 data)6106621Sbt150084 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
6116621Sbt150084 {
6126621Sbt150084 	s32 status;
6136621Sbt150084 	u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
6146621Sbt150084 
61510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_write_eeprom_generic");
61610998SChenlu.Chen@Sun.COM 
6176621Sbt150084 	hw->eeprom.ops.init_params(hw);
6186621Sbt150084 
6196621Sbt150084 	if (offset >= hw->eeprom.word_size) {
6206621Sbt150084 		status = IXGBE_ERR_EEPROM;
6216621Sbt150084 		goto out;
6226621Sbt150084 	}
6236621Sbt150084 
6246621Sbt150084 	/* Prepare the EEPROM for writing  */
6256621Sbt150084 	status = ixgbe_acquire_eeprom(hw);
6266621Sbt150084 
6276621Sbt150084 	if (status == IXGBE_SUCCESS) {
6286621Sbt150084 		if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
6296621Sbt150084 			ixgbe_release_eeprom(hw);
6306621Sbt150084 			status = IXGBE_ERR_EEPROM;
6316621Sbt150084 		}
6326621Sbt150084 	}
6336621Sbt150084 
6346621Sbt150084 	if (status == IXGBE_SUCCESS) {
6356621Sbt150084 		ixgbe_standby_eeprom(hw);
6366621Sbt150084 
6376621Sbt150084 		/*  Send the WRITE ENABLE command (8 bit opcode )  */
6386621Sbt150084 		ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_WREN_OPCODE_SPI,
6396621Sbt150084 		    IXGBE_EEPROM_OPCODE_BITS);
6406621Sbt150084 
6416621Sbt150084 		ixgbe_standby_eeprom(hw);
6426621Sbt150084 
6436621Sbt150084 		/*
6446621Sbt150084 		 * Some SPI eeproms use the 8th address bit embedded in the
6456621Sbt150084 		 * opcode
6466621Sbt150084 		 */
6476621Sbt150084 		if ((hw->eeprom.address_bits == 8) && (offset >= 128))
6486621Sbt150084 			write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
6496621Sbt150084 
6506621Sbt150084 		/* Send the Write command (8-bit opcode + addr) */
6516621Sbt150084 		ixgbe_shift_out_eeprom_bits(hw, write_opcode,
6526621Sbt150084 		    IXGBE_EEPROM_OPCODE_BITS);
6536621Sbt150084 		ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
6546621Sbt150084 		    hw->eeprom.address_bits);
6556621Sbt150084 
6566621Sbt150084 		/* Send the data */
6576621Sbt150084 		data = (data >> 8) | (data << 8);
6586621Sbt150084 		ixgbe_shift_out_eeprom_bits(hw, data, 16);
6596621Sbt150084 		ixgbe_standby_eeprom(hw);
6606621Sbt150084 
6616621Sbt150084 		/* Done with writing - release the EEPROM */
6626621Sbt150084 		ixgbe_release_eeprom(hw);
6636621Sbt150084 	}
6646621Sbt150084 
6656621Sbt150084 out:
6666621Sbt150084 	return (status);
6676621Sbt150084 }
6686621Sbt150084 
6696621Sbt150084 /*
6706621Sbt150084  * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
6716621Sbt150084  * @hw: pointer to hardware structure
6726621Sbt150084  * @offset: offset within the EEPROM to be read
6736621Sbt150084  * @data: read 16 bit value from EEPROM
6746621Sbt150084  *
6756621Sbt150084  * Reads 16 bit value from EEPROM through bit-bang method
6766621Sbt150084  */
6776621Sbt150084 s32
ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw * hw,u16 offset,u16 * data)6786621Sbt150084 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
6796621Sbt150084 	u16 *data)
6806621Sbt150084 {
6816621Sbt150084 	s32 status;
6826621Sbt150084 	u16 word_in;
6836621Sbt150084 	u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
6846621Sbt150084 
68510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_read_eeprom_bit_bang_generic");
68610998SChenlu.Chen@Sun.COM 
6876621Sbt150084 	hw->eeprom.ops.init_params(hw);
6886621Sbt150084 
6896621Sbt150084 	if (offset >= hw->eeprom.word_size) {
6906621Sbt150084 		status = IXGBE_ERR_EEPROM;
6916621Sbt150084 		goto out;
6926621Sbt150084 	}
6936621Sbt150084 
6946621Sbt150084 	/* Prepare the EEPROM for reading  */
6956621Sbt150084 	status = ixgbe_acquire_eeprom(hw);
6966621Sbt150084 
6976621Sbt150084 	if (status == IXGBE_SUCCESS) {
6986621Sbt150084 		if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
6996621Sbt150084 			ixgbe_release_eeprom(hw);
7006621Sbt150084 			status = IXGBE_ERR_EEPROM;
7016621Sbt150084 		}
7026621Sbt150084 	}
7036621Sbt150084 
7046621Sbt150084 	if (status == IXGBE_SUCCESS) {
7056621Sbt150084 		ixgbe_standby_eeprom(hw);
7066621Sbt150084 
7076621Sbt150084 		/*
7086621Sbt150084 		 * Some SPI eeproms use the 8th address bit embedded in the
7096621Sbt150084 		 * opcode
7106621Sbt150084 		 */
7116621Sbt150084 		if ((hw->eeprom.address_bits == 8) && (offset >= 128))
7126621Sbt150084 			read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
7136621Sbt150084 
7146621Sbt150084 		/* Send the READ command (opcode + addr) */
7156621Sbt150084 		ixgbe_shift_out_eeprom_bits(hw, read_opcode,
7166621Sbt150084 		    IXGBE_EEPROM_OPCODE_BITS);
7176621Sbt150084 		ixgbe_shift_out_eeprom_bits(hw, (u16)(offset*2),
7186621Sbt150084 		    hw->eeprom.address_bits);
7196621Sbt150084 
7206621Sbt150084 		/* Read the data. */
7216621Sbt150084 		word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
7226621Sbt150084 		*data = (word_in >> 8) | (word_in << 8);
7236621Sbt150084 
7246621Sbt150084 		/* End this read operation */
7256621Sbt150084 		ixgbe_release_eeprom(hw);
7266621Sbt150084 	}
7276621Sbt150084 
7286621Sbt150084 out:
7296621Sbt150084 	return (status);
7306621Sbt150084 }
7316621Sbt150084 
7326621Sbt150084 /*
73310998SChenlu.Chen@Sun.COM  * ixgbe_read_eerd_generic - Read EEPROM word using EERD
7346621Sbt150084  * @hw: pointer to hardware structure
7356621Sbt150084  * @offset: offset of  word in the EEPROM to read
7366621Sbt150084  * @data: word read from the EEPROM
7376621Sbt150084  *
7386621Sbt150084  * Reads a 16 bit word from the EEPROM using the EERD register.
7396621Sbt150084  */
7406621Sbt150084 s32
ixgbe_read_eerd_generic(struct ixgbe_hw * hw,u16 offset,u16 * data)74110998SChenlu.Chen@Sun.COM ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
7426621Sbt150084 {
7436621Sbt150084 	u32 eerd;
7446621Sbt150084 	s32 status;
7456621Sbt150084 
74610998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_read_eerd_generic");
74710998SChenlu.Chen@Sun.COM 
7486621Sbt150084 	hw->eeprom.ops.init_params(hw);
7496621Sbt150084 
7506621Sbt150084 	if (offset >= hw->eeprom.word_size) {
7516621Sbt150084 		status = IXGBE_ERR_EEPROM;
7526621Sbt150084 		goto out;
7536621Sbt150084 	}
7546621Sbt150084 
75510998SChenlu.Chen@Sun.COM 	eerd = (offset << IXGBE_EEPROM_RW_ADDR_SHIFT) +
75610998SChenlu.Chen@Sun.COM 	    IXGBE_EEPROM_RW_REG_START;
7576621Sbt150084 
7586621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
75910998SChenlu.Chen@Sun.COM 	status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
76010998SChenlu.Chen@Sun.COM 
76110998SChenlu.Chen@Sun.COM 	if (status == IXGBE_SUCCESS)
7626621Sbt150084 		*data = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
76310998SChenlu.Chen@Sun.COM 		    IXGBE_EEPROM_RW_REG_DATA);
76410998SChenlu.Chen@Sun.COM 	else
7656621Sbt150084 		DEBUGOUT("Eeprom read timed out\n");
7666621Sbt150084 
7676621Sbt150084 out:
7686621Sbt150084 	return (status);
7696621Sbt150084 }
7706621Sbt150084 
7716621Sbt150084 /*
77210998SChenlu.Chen@Sun.COM  * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
7736621Sbt150084  * @hw: pointer to hardware structure
77410998SChenlu.Chen@Sun.COM  * @ee_reg: EEPROM flag for polling
7756621Sbt150084  *
77610998SChenlu.Chen@Sun.COM  * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
77710998SChenlu.Chen@Sun.COM  * read or write is done respectively.
7786621Sbt150084  */
77910998SChenlu.Chen@Sun.COM s32
ixgbe_poll_eerd_eewr_done(struct ixgbe_hw * hw,u32 ee_reg)78010998SChenlu.Chen@Sun.COM ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
7816621Sbt150084 {
7826621Sbt150084 	u32 i;
7836621Sbt150084 	u32 reg;
7846621Sbt150084 	s32 status = IXGBE_ERR_EEPROM;
7856621Sbt150084 
78610998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_poll_eerd_eewr_done");
78710998SChenlu.Chen@Sun.COM 
78810998SChenlu.Chen@Sun.COM 	for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
78910998SChenlu.Chen@Sun.COM 		if (ee_reg == IXGBE_NVM_POLL_READ)
79010998SChenlu.Chen@Sun.COM 			reg = IXGBE_READ_REG(hw, IXGBE_EERD);
79110998SChenlu.Chen@Sun.COM 		else
79210998SChenlu.Chen@Sun.COM 			reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
79310998SChenlu.Chen@Sun.COM 
79410998SChenlu.Chen@Sun.COM 		if (reg & IXGBE_EEPROM_RW_REG_DONE) {
7956621Sbt150084 			status = IXGBE_SUCCESS;
7966621Sbt150084 			break;
7976621Sbt150084 		}
7986621Sbt150084 		usec_delay(5);
7996621Sbt150084 	}
8006621Sbt150084 	return (status);
8016621Sbt150084 }
8026621Sbt150084 
8036621Sbt150084 /*
8046621Sbt150084  * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
8056621Sbt150084  * @hw: pointer to hardware structure
8066621Sbt150084  *
8076621Sbt150084  * Prepares EEPROM for access using bit-bang method. This function should
8086621Sbt150084  * be called before issuing a command to the EEPROM.
8096621Sbt150084  */
8106621Sbt150084 static s32
ixgbe_acquire_eeprom(struct ixgbe_hw * hw)8116621Sbt150084 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
8126621Sbt150084 {
8136621Sbt150084 	s32 status = IXGBE_SUCCESS;
8146621Sbt150084 	u32 eec;
8156621Sbt150084 	u32 i;
8166621Sbt150084 
81710998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_acquire_eeprom");
81810998SChenlu.Chen@Sun.COM 
8196621Sbt150084 	if (ixgbe_acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != IXGBE_SUCCESS)
8206621Sbt150084 		status = IXGBE_ERR_SWFW_SYNC;
8216621Sbt150084 
8226621Sbt150084 	if (status == IXGBE_SUCCESS) {
8236621Sbt150084 		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
8246621Sbt150084 
8256621Sbt150084 		/* Request EEPROM Access */
8266621Sbt150084 		eec |= IXGBE_EEC_REQ;
8276621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
8286621Sbt150084 
8296621Sbt150084 		for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
8306621Sbt150084 			eec = IXGBE_READ_REG(hw, IXGBE_EEC);
8316621Sbt150084 			if (eec & IXGBE_EEC_GNT)
8326621Sbt150084 				break;
8336621Sbt150084 			usec_delay(5);
8346621Sbt150084 		}
8356621Sbt150084 
8366621Sbt150084 		/* Release if grant not acquired */
8376621Sbt150084 		if (!(eec & IXGBE_EEC_GNT)) {
8386621Sbt150084 			eec &= ~IXGBE_EEC_REQ;
8396621Sbt150084 			IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
8406621Sbt150084 			DEBUGOUT("Could not acquire EEPROM grant\n");
8416621Sbt150084 
8426621Sbt150084 			ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
8436621Sbt150084 			status = IXGBE_ERR_EEPROM;
8446621Sbt150084 		}
8456621Sbt150084 	}
8466621Sbt150084 
8476621Sbt150084 	/* Setup EEPROM for Read/Write */
8486621Sbt150084 	if (status == IXGBE_SUCCESS) {
8496621Sbt150084 		/* Clear CS and SK */
8506621Sbt150084 		eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
8516621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
8526621Sbt150084 		IXGBE_WRITE_FLUSH(hw);
8536621Sbt150084 		usec_delay(1);
8546621Sbt150084 	}
8556621Sbt150084 	return (status);
8566621Sbt150084 }
8576621Sbt150084 
8586621Sbt150084 /*
8596621Sbt150084  * ixgbe_get_eeprom_semaphore - Get hardware semaphore
8606621Sbt150084  * @hw: pointer to hardware structure
8616621Sbt150084  *
8626621Sbt150084  * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
8636621Sbt150084  */
8646621Sbt150084 static s32
ixgbe_get_eeprom_semaphore(struct ixgbe_hw * hw)8656621Sbt150084 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
8666621Sbt150084 {
8676621Sbt150084 	s32 status = IXGBE_ERR_EEPROM;
86810305SPaul.Guo@Sun.COM 	u32 timeout = 2000;
8696621Sbt150084 	u32 i;
8706621Sbt150084 	u32 swsm;
8716621Sbt150084 
87210998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_eeprom_semaphore");
87310998SChenlu.Chen@Sun.COM 
8746621Sbt150084 	/* Get SMBI software semaphore between device drivers first */
8756621Sbt150084 	for (i = 0; i < timeout; i++) {
8766621Sbt150084 		/*
8776621Sbt150084 		 * If the SMBI bit is 0 when we read it, then the bit will be
8786621Sbt150084 		 * set and we have the semaphore
8796621Sbt150084 		 */
8806621Sbt150084 		swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
8816621Sbt150084 		if (!(swsm & IXGBE_SWSM_SMBI)) {
8826621Sbt150084 			status = IXGBE_SUCCESS;
8836621Sbt150084 			break;
8846621Sbt150084 		}
88510305SPaul.Guo@Sun.COM 		usec_delay(50);
8866621Sbt150084 	}
8876621Sbt150084 
8886621Sbt150084 	/* Now get the semaphore between SW/FW through the SWESMBI bit */
8896621Sbt150084 	if (status == IXGBE_SUCCESS) {
8906621Sbt150084 		for (i = 0; i < timeout; i++) {
8916621Sbt150084 			swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
8926621Sbt150084 
8936621Sbt150084 			/* Set the SW EEPROM semaphore bit to request access */
8946621Sbt150084 			swsm |= IXGBE_SWSM_SWESMBI;
8956621Sbt150084 			IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
8966621Sbt150084 
8976621Sbt150084 			/*
8986621Sbt150084 			 * If we set the bit successfully then we got the
8996621Sbt150084 			 * semaphore.
9006621Sbt150084 			 */
9016621Sbt150084 			swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
9026621Sbt150084 			if (swsm & IXGBE_SWSM_SWESMBI)
9036621Sbt150084 				break;
9046621Sbt150084 
9056621Sbt150084 			usec_delay(50);
9066621Sbt150084 		}
9076621Sbt150084 
9086621Sbt150084 		/*
9096621Sbt150084 		 * Release semaphores and return error if SW EEPROM semaphore
9106621Sbt150084 		 * was not granted because we don't have access to the EEPROM
9116621Sbt150084 		 */
9126621Sbt150084 		if (i >= timeout) {
9139353SSamuel.Tu@Sun.COM 			DEBUGOUT("SWESMBI Software EEPROM semaphore "
9146621Sbt150084 			    "not granted.\n");
9156621Sbt150084 			ixgbe_release_eeprom_semaphore(hw);
9166621Sbt150084 			status = IXGBE_ERR_EEPROM;
9176621Sbt150084 		}
9189353SSamuel.Tu@Sun.COM 	} else {
9199353SSamuel.Tu@Sun.COM 		DEBUGOUT("Software semaphore SMBI between device drivers "
9209353SSamuel.Tu@Sun.COM 		    "not granted.\n");
9216621Sbt150084 	}
9226621Sbt150084 
9236621Sbt150084 	return (status);
9246621Sbt150084 }
9256621Sbt150084 
9266621Sbt150084 /*
9276621Sbt150084  * ixgbe_release_eeprom_semaphore - Release hardware semaphore
9286621Sbt150084  * @hw: pointer to hardware structure
9296621Sbt150084  *
9306621Sbt150084  * This function clears hardware semaphore bits.
9316621Sbt150084  */
9326621Sbt150084 static void
ixgbe_release_eeprom_semaphore(struct ixgbe_hw * hw)9336621Sbt150084 ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
9346621Sbt150084 {
9356621Sbt150084 	u32 swsm;
9366621Sbt150084 
93710998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_release_eeprom_semaphore");
93810998SChenlu.Chen@Sun.COM 
9396621Sbt150084 	swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
9406621Sbt150084 
9416621Sbt150084 	/* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
9426621Sbt150084 	swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
9436621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
9446621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
9456621Sbt150084 }
9466621Sbt150084 
9476621Sbt150084 /*
9486621Sbt150084  * ixgbe_ready_eeprom - Polls for EEPROM ready
9496621Sbt150084  * @hw: pointer to hardware structure
9506621Sbt150084  */
9516621Sbt150084 static s32
ixgbe_ready_eeprom(struct ixgbe_hw * hw)9526621Sbt150084 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
9536621Sbt150084 {
9546621Sbt150084 	s32 status = IXGBE_SUCCESS;
9556621Sbt150084 	u16 i;
9566621Sbt150084 	u8 spi_stat_reg;
9576621Sbt150084 
95810998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_ready_eeprom");
95910998SChenlu.Chen@Sun.COM 
9606621Sbt150084 	/*
9616621Sbt150084 	 * Read "Status Register" repeatedly until the LSB is cleared.  The
9626621Sbt150084 	 * EEPROM will signal that the command has been completed by clearing
9636621Sbt150084 	 * bit 0 of the internal status register.  If it's not cleared within
9646621Sbt150084 	 * 5 milliseconds, then error out.
9656621Sbt150084 	 */
9666621Sbt150084 	for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
9676621Sbt150084 		ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
9686621Sbt150084 		    IXGBE_EEPROM_OPCODE_BITS);
9696621Sbt150084 		spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
9706621Sbt150084 		if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
9716621Sbt150084 			break;
9726621Sbt150084 
9736621Sbt150084 		usec_delay(5);
9746621Sbt150084 		ixgbe_standby_eeprom(hw);
9756621Sbt150084 	};
9766621Sbt150084 
9776621Sbt150084 	/*
9786621Sbt150084 	 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
9796621Sbt150084 	 * devices (and only 0-5mSec on 5V devices)
9806621Sbt150084 	 */
9816621Sbt150084 	if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
9826621Sbt150084 		DEBUGOUT("SPI EEPROM Status error\n");
9836621Sbt150084 		status = IXGBE_ERR_EEPROM;
9846621Sbt150084 	}
9856621Sbt150084 
9866621Sbt150084 	return (status);
9876621Sbt150084 }
9886621Sbt150084 
9896621Sbt150084 /*
9906621Sbt150084  * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
9916621Sbt150084  * @hw: pointer to hardware structure
9926621Sbt150084  */
9936621Sbt150084 static void
ixgbe_standby_eeprom(struct ixgbe_hw * hw)9946621Sbt150084 ixgbe_standby_eeprom(struct ixgbe_hw *hw)
9956621Sbt150084 {
9966621Sbt150084 	u32 eec;
9976621Sbt150084 
99810998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_standby_eeprom");
99910998SChenlu.Chen@Sun.COM 
10006621Sbt150084 	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
10016621Sbt150084 
10026621Sbt150084 	/* Toggle CS to flush commands */
10036621Sbt150084 	eec |= IXGBE_EEC_CS;
10046621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
10056621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
10066621Sbt150084 	usec_delay(1);
10076621Sbt150084 	eec &= ~IXGBE_EEC_CS;
10086621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
10096621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
10106621Sbt150084 	usec_delay(1);
10116621Sbt150084 }
10126621Sbt150084 
10136621Sbt150084 /*
10146621Sbt150084  * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
10156621Sbt150084  * @hw: pointer to hardware structure
10166621Sbt150084  * @data: data to send to the EEPROM
10176621Sbt150084  * @count: number of bits to shift out
10186621Sbt150084  */
10196621Sbt150084 static void
ixgbe_shift_out_eeprom_bits(struct ixgbe_hw * hw,u16 data,u16 count)10206621Sbt150084 ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
10216621Sbt150084     u16 count)
10226621Sbt150084 {
10236621Sbt150084 	u32 eec;
10246621Sbt150084 	u32 mask;
10256621Sbt150084 	u32 i;
10266621Sbt150084 
102710998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_shift_out_eeprom_bits");
102810998SChenlu.Chen@Sun.COM 
10296621Sbt150084 	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
10306621Sbt150084 
10316621Sbt150084 	/*
10326621Sbt150084 	 * Mask is used to shift "count" bits of "data" out to the EEPROM
10336621Sbt150084 	 * one bit at a time.  Determine the starting bit based on count
10346621Sbt150084 	 */
10356621Sbt150084 	mask = 0x01 << (count - 1);
10366621Sbt150084 
10376621Sbt150084 	for (i = 0; i < count; i++) {
10386621Sbt150084 		/*
10396621Sbt150084 		 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
10406621Sbt150084 		 * "1", and then raising and then lowering the clock (the SK
10416621Sbt150084 		 * bit controls the clock input to the EEPROM).  A "0" is
10426621Sbt150084 		 * shifted out to the EEPROM by setting "DI" to "0" and then
10436621Sbt150084 		 * raising and then lowering the clock.
10446621Sbt150084 		 */
10456621Sbt150084 		if (data & mask)
10466621Sbt150084 			eec |= IXGBE_EEC_DI;
10476621Sbt150084 		else
10486621Sbt150084 			eec &= ~IXGBE_EEC_DI;
10496621Sbt150084 
10506621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
10516621Sbt150084 		IXGBE_WRITE_FLUSH(hw);
10526621Sbt150084 
10536621Sbt150084 		usec_delay(1);
10546621Sbt150084 
10556621Sbt150084 		ixgbe_raise_eeprom_clk(hw, &eec);
10566621Sbt150084 		ixgbe_lower_eeprom_clk(hw, &eec);
10576621Sbt150084 
10586621Sbt150084 		/*
10596621Sbt150084 		 * Shift mask to signify next bit of data to shift in to the
10606621Sbt150084 		 * EEPROM
10616621Sbt150084 		 */
10626621Sbt150084 		mask = mask >> 1;
10636621Sbt150084 	};
10646621Sbt150084 
10656621Sbt150084 	/* We leave the "DI" bit set to "0" when we leave this routine. */
10666621Sbt150084 	eec &= ~IXGBE_EEC_DI;
10676621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
10686621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
10696621Sbt150084 }
10706621Sbt150084 
10716621Sbt150084 /*
10726621Sbt150084  * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
10736621Sbt150084  * @hw: pointer to hardware structure
10746621Sbt150084  */
10756621Sbt150084 static u16
ixgbe_shift_in_eeprom_bits(struct ixgbe_hw * hw,u16 count)10766621Sbt150084 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
10776621Sbt150084 {
10786621Sbt150084 	u32 eec;
10796621Sbt150084 	u32 i;
10806621Sbt150084 	u16 data = 0;
10816621Sbt150084 
108210998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_shift_in_eeprom_bits");
108310998SChenlu.Chen@Sun.COM 
10846621Sbt150084 	/*
10856621Sbt150084 	 * In order to read a register from the EEPROM, we need to shift
10866621Sbt150084 	 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
10876621Sbt150084 	 * the clock input to the EEPROM (setting the SK bit), and then reading
10886621Sbt150084 	 * the value of the "DO" bit.  During this "shifting in" process the
10896621Sbt150084 	 * "DI" bit should always be clear.
10906621Sbt150084 	 */
10916621Sbt150084 	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
10926621Sbt150084 
10936621Sbt150084 	eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
10946621Sbt150084 
10956621Sbt150084 	for (i = 0; i < count; i++) {
10966621Sbt150084 		data = data << 1;
10976621Sbt150084 		ixgbe_raise_eeprom_clk(hw, &eec);
10986621Sbt150084 
10996621Sbt150084 		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
11006621Sbt150084 
11016621Sbt150084 		eec &= ~(IXGBE_EEC_DI);
11026621Sbt150084 		if (eec & IXGBE_EEC_DO)
11036621Sbt150084 			data |= 1;
11046621Sbt150084 
11056621Sbt150084 		ixgbe_lower_eeprom_clk(hw, &eec);
11066621Sbt150084 	}
11076621Sbt150084 
11086621Sbt150084 	return (data);
11096621Sbt150084 }
11106621Sbt150084 
11116621Sbt150084 /*
11126621Sbt150084  * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
11136621Sbt150084  * @hw: pointer to hardware structure
11146621Sbt150084  * @eec: EEC register's current value
11156621Sbt150084  */
11166621Sbt150084 static void
ixgbe_raise_eeprom_clk(struct ixgbe_hw * hw,u32 * eec)11176621Sbt150084 ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
11186621Sbt150084 {
111910998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_raise_eeprom_clk");
112010998SChenlu.Chen@Sun.COM 
11216621Sbt150084 	/*
11226621Sbt150084 	 * Raise the clock input to the EEPROM
11236621Sbt150084 	 * (setting the SK bit), then delay
11246621Sbt150084 	 */
11256621Sbt150084 	*eec = *eec | IXGBE_EEC_SK;
11266621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
11276621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
11286621Sbt150084 	usec_delay(1);
11296621Sbt150084 }
11306621Sbt150084 
11316621Sbt150084 /*
11326621Sbt150084  * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
11336621Sbt150084  * @hw: pointer to hardware structure
11346621Sbt150084  * @eecd: EECD's current value
11356621Sbt150084  */
11366621Sbt150084 static void
ixgbe_lower_eeprom_clk(struct ixgbe_hw * hw,u32 * eec)11376621Sbt150084 ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
11386621Sbt150084 {
113910998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_lower_eeprom_clk");
114010998SChenlu.Chen@Sun.COM 
11416621Sbt150084 	/*
11426621Sbt150084 	 * Lower the clock input to the EEPROM (clearing the SK bit), then
11436621Sbt150084 	 * delay
11446621Sbt150084 	 */
11456621Sbt150084 	*eec = *eec & ~IXGBE_EEC_SK;
11466621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
11476621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
11486621Sbt150084 	usec_delay(1);
11496621Sbt150084 }
11506621Sbt150084 
11516621Sbt150084 /*
11526621Sbt150084  * ixgbe_release_eeprom - Release EEPROM, release semaphores
11536621Sbt150084  * @hw: pointer to hardware structure
11546621Sbt150084  */
11556621Sbt150084 static void
ixgbe_release_eeprom(struct ixgbe_hw * hw)11566621Sbt150084 ixgbe_release_eeprom(struct ixgbe_hw *hw)
11576621Sbt150084 {
11586621Sbt150084 	u32 eec;
11596621Sbt150084 
116010998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_release_eeprom");
116110998SChenlu.Chen@Sun.COM 
11626621Sbt150084 	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
11636621Sbt150084 
11646621Sbt150084 	eec |= IXGBE_EEC_CS;  /* Pull CS high */
11656621Sbt150084 	eec &= ~IXGBE_EEC_SK; /* Lower SCK */
11666621Sbt150084 
11676621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
11686621Sbt150084 	IXGBE_WRITE_FLUSH(hw);
11696621Sbt150084 
11706621Sbt150084 	usec_delay(1);
11716621Sbt150084 
11726621Sbt150084 	/* Stop requesting EEPROM access */
11736621Sbt150084 	eec &= ~IXGBE_EEC_REQ;
11746621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
11756621Sbt150084 
11766621Sbt150084 	ixgbe_release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
117710305SPaul.Guo@Sun.COM 
117810305SPaul.Guo@Sun.COM 	/* Delay before attempt to obtain semaphore again to allow FW access */
117910305SPaul.Guo@Sun.COM 	msec_delay(hw->eeprom.semaphore_delay);
11806621Sbt150084 }
11816621Sbt150084 
11826621Sbt150084 /*
118312003SPaul.Guo@Sun.COM  * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
11846621Sbt150084  * @hw: pointer to hardware structure
11856621Sbt150084  */
118612003SPaul.Guo@Sun.COM u16
ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw * hw)118712003SPaul.Guo@Sun.COM ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
11886621Sbt150084 {
11896621Sbt150084 	u16 i;
11906621Sbt150084 	u16 j;
11916621Sbt150084 	u16 checksum = 0;
11926621Sbt150084 	u16 length = 0;
11936621Sbt150084 	u16 pointer = 0;
11946621Sbt150084 	u16 word = 0;
11956621Sbt150084 
119612003SPaul.Guo@Sun.COM 	DEBUGFUNC("ixgbe_calc_eeprom_checksum_generic");
119710998SChenlu.Chen@Sun.COM 
11986621Sbt150084 	/* Include 0x0-0x3F in the checksum */
11996621Sbt150084 	for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
12006621Sbt150084 		if (hw->eeprom.ops.read(hw, i, &word) != IXGBE_SUCCESS) {
12016621Sbt150084 			DEBUGOUT("EEPROM read failed\n");
12026621Sbt150084 			break;
12036621Sbt150084 		}
12046621Sbt150084 		checksum += word;
12056621Sbt150084 	}
12066621Sbt150084 
12076621Sbt150084 	/* Include all data from pointers except for the fw pointer */
12086621Sbt150084 	for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
12096621Sbt150084 		hw->eeprom.ops.read(hw, i, &pointer);
12106621Sbt150084 
12116621Sbt150084 		/* Make sure the pointer seems valid */
12126621Sbt150084 		if (pointer != 0xFFFF && pointer != 0) {
12136621Sbt150084 			hw->eeprom.ops.read(hw, pointer, &length);
12146621Sbt150084 
12156621Sbt150084 			if (length != 0xFFFF && length != 0) {
12166621Sbt150084 				for (j = pointer+1; j <= pointer+length; j++) {
12176621Sbt150084 					hw->eeprom.ops.read(hw, j, &word);
12186621Sbt150084 					checksum += word;
12196621Sbt150084 				}
12206621Sbt150084 			}
12216621Sbt150084 		}
12226621Sbt150084 	}
12236621Sbt150084 
12246621Sbt150084 	checksum = (u16)IXGBE_EEPROM_SUM - checksum;
12256621Sbt150084 
12266621Sbt150084 	return (checksum);
12276621Sbt150084 }
12286621Sbt150084 
12296621Sbt150084 /*
12306621Sbt150084  * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
12316621Sbt150084  * @hw: pointer to hardware structure
12326621Sbt150084  * @checksum_val: calculated checksum
12336621Sbt150084  *
12346621Sbt150084  * Performs checksum calculation and validates the EEPROM checksum.  If the
12356621Sbt150084  * caller does not need checksum_val, the value can be NULL.
12366621Sbt150084  */
12376621Sbt150084 s32
ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw * hw,u16 * checksum_val)12386621Sbt150084 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
12396621Sbt150084     u16 *checksum_val)
12406621Sbt150084 {
12416621Sbt150084 	s32 status;
12426621Sbt150084 	u16 checksum;
12436621Sbt150084 	u16 read_checksum = 0;
12446621Sbt150084 
124510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_validate_eeprom_checksum_generic");
124610998SChenlu.Chen@Sun.COM 
12476621Sbt150084 	/*
12486621Sbt150084 	 * Read the first word from the EEPROM. If this times out or fails, do
12496621Sbt150084 	 * not continue or we could be in for a very long wait while every
12506621Sbt150084 	 * EEPROM read fails
12516621Sbt150084 	 */
12526621Sbt150084 	status = hw->eeprom.ops.read(hw, 0, &checksum);
12536621Sbt150084 
12546621Sbt150084 	if (status == IXGBE_SUCCESS) {
125512003SPaul.Guo@Sun.COM 		checksum = hw->eeprom.ops.calc_checksum(hw);
12566621Sbt150084 
12576621Sbt150084 		hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
12586621Sbt150084 
12596621Sbt150084 		/*
12606621Sbt150084 		 * Verify read checksum from EEPROM is the same as
12616621Sbt150084 		 * calculated checksum
12626621Sbt150084 		 */
12636621Sbt150084 		if (read_checksum != checksum)
12646621Sbt150084 			status = IXGBE_ERR_EEPROM_CHECKSUM;
12656621Sbt150084 
12666621Sbt150084 		/* If the user cares, return the calculated checksum */
12676621Sbt150084 		if (checksum_val)
12686621Sbt150084 			*checksum_val = checksum;
12696621Sbt150084 	} else {
12706621Sbt150084 		DEBUGOUT("EEPROM read failed\n");
12716621Sbt150084 	}
12726621Sbt150084 
12736621Sbt150084 	return (status);
12746621Sbt150084 }
12756621Sbt150084 
12766621Sbt150084 /*
12776621Sbt150084  * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
12786621Sbt150084  * @hw: pointer to hardware structure
12796621Sbt150084  */
12806621Sbt150084 s32
ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw * hw)12816621Sbt150084 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
12826621Sbt150084 {
12836621Sbt150084 	s32 status;
12846621Sbt150084 	u16 checksum;
12856621Sbt150084 
128610998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_update_eeprom_checksum_generic");
128710998SChenlu.Chen@Sun.COM 
12886621Sbt150084 	/*
12896621Sbt150084 	 * Read the first word from the EEPROM. If this times out or fails, do
12906621Sbt150084 	 * not continue or we could be in for a very long wait while every
12916621Sbt150084 	 * EEPROM read fails
12926621Sbt150084 	 */
12936621Sbt150084 	status = hw->eeprom.ops.read(hw, 0, &checksum);
12946621Sbt150084 
12956621Sbt150084 	if (status == IXGBE_SUCCESS) {
129612003SPaul.Guo@Sun.COM 		checksum = hw->eeprom.ops.calc_checksum(hw);
12976621Sbt150084 		status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
12986621Sbt150084 		    checksum);
12996621Sbt150084 	} else {
13006621Sbt150084 		DEBUGOUT("EEPROM read failed\n");
13016621Sbt150084 	}
13026621Sbt150084 
13036621Sbt150084 	return (status);
13046621Sbt150084 }
13056621Sbt150084 
13066621Sbt150084 /*
13076621Sbt150084  * ixgbe_validate_mac_addr - Validate MAC address
13086621Sbt150084  * @mac_addr: pointer to MAC address.
13096621Sbt150084  *
13106621Sbt150084  * Tests a MAC address to ensure it is a valid Individual Address
13116621Sbt150084  */
13126621Sbt150084 s32
ixgbe_validate_mac_addr(u8 * mac_addr)13136621Sbt150084 ixgbe_validate_mac_addr(u8 *mac_addr)
13146621Sbt150084 {
13156621Sbt150084 	s32 status = IXGBE_SUCCESS;
13166621Sbt150084 
131710998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_validate_mac_addr");
131810998SChenlu.Chen@Sun.COM 
13196621Sbt150084 	/* Make sure it is not a multicast address */
13206621Sbt150084 	if (IXGBE_IS_MULTICAST(mac_addr)) {
13216621Sbt150084 		DEBUGOUT("MAC address is multicast\n");
13226621Sbt150084 		status = IXGBE_ERR_INVALID_MAC_ADDR;
13236621Sbt150084 	/* Not a broadcast address */
13246621Sbt150084 	} else if (IXGBE_IS_BROADCAST(mac_addr)) {
13256621Sbt150084 		DEBUGOUT("MAC address is broadcast\n");
13266621Sbt150084 		status = IXGBE_ERR_INVALID_MAC_ADDR;
13276621Sbt150084 	/* Reject the zero address */
13286621Sbt150084 	} else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
13296621Sbt150084 	    mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
13306621Sbt150084 		DEBUGOUT("MAC address is all zeros\n");
13316621Sbt150084 		status = IXGBE_ERR_INVALID_MAC_ADDR;
13326621Sbt150084 	}
13336621Sbt150084 	return (status);
13346621Sbt150084 }
13356621Sbt150084 
13366621Sbt150084 /*
13376621Sbt150084  * ixgbe_set_rar_generic - Set Rx address register
13386621Sbt150084  * @hw: pointer to hardware structure
13396621Sbt150084  * @index: Receive address register to write
13406621Sbt150084  * @addr: Address to put into receive address register
13416621Sbt150084  * @vmdq: VMDq "set" or "pool" index
13426621Sbt150084  * @enable_addr: set flag that address is active
13436621Sbt150084  *
13446621Sbt150084  * Puts an ethernet address into a receive address register.
13456621Sbt150084  */
13466621Sbt150084 s32
ixgbe_set_rar_generic(struct ixgbe_hw * hw,u32 index,u8 * addr,u32 vmdq,u32 enable_addr)13476621Sbt150084 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
13486621Sbt150084     u32 enable_addr)
13496621Sbt150084 {
13506621Sbt150084 	u32 rar_low, rar_high;
13516621Sbt150084 	u32 rar_entries = hw->mac.num_rar_entries;
13526621Sbt150084 
135310998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_set_rar_generic");
135410998SChenlu.Chen@Sun.COM 
13556621Sbt150084 	/* setup VMDq pool selection before this RAR gets enabled */
13566621Sbt150084 	hw->mac.ops.set_vmdq(hw, index, vmdq);
13576621Sbt150084 
13586621Sbt150084 	/* Make sure we are using a valid rar index range */
13596621Sbt150084 	if (index < rar_entries) {
13606621Sbt150084 		/*
13616621Sbt150084 		 * HW expects these in little endian so we reverse the byte
13626621Sbt150084 		 * order from network order (big endian) to little endian
13636621Sbt150084 		 */
13646621Sbt150084 		rar_low = ((u32)addr[0] |
13656621Sbt150084 		    ((u32)addr[1] << 8) |
13666621Sbt150084 		    ((u32)addr[2] << 16) |
13676621Sbt150084 		    ((u32)addr[3] << 24));
13686621Sbt150084 		/*
13696621Sbt150084 		 * Some parts put the VMDq setting in the extra RAH bits,
13706621Sbt150084 		 * so save everything except the lower 16 bits that hold part
13716621Sbt150084 		 * of the address and the address valid bit.
13726621Sbt150084 		 */
13736621Sbt150084 		rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
13746621Sbt150084 		rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
13756621Sbt150084 		rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
13766621Sbt150084 
13776621Sbt150084 		if (enable_addr != 0)
13786621Sbt150084 			rar_high |= IXGBE_RAH_AV;
13796621Sbt150084 
13806621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
13816621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
13826621Sbt150084 	} else {
13838490SPaul.Guo@Sun.COM 		DEBUGOUT1("RAR index %d is out of range.\n", index);
13846621Sbt150084 	}
13856621Sbt150084 
13866621Sbt150084 	return (IXGBE_SUCCESS);
13876621Sbt150084 }
13886621Sbt150084 
13896621Sbt150084 /*
13908490SPaul.Guo@Sun.COM  * ixgbe_clear_rar_generic - Remove Rx address register
13918490SPaul.Guo@Sun.COM  * @hw: pointer to hardware structure
13928490SPaul.Guo@Sun.COM  * @index: Receive address register to write
13938490SPaul.Guo@Sun.COM  *
13948490SPaul.Guo@Sun.COM  * Clears an ethernet address from a receive address register.
13958490SPaul.Guo@Sun.COM  */
13968490SPaul.Guo@Sun.COM s32
ixgbe_clear_rar_generic(struct ixgbe_hw * hw,u32 index)13978490SPaul.Guo@Sun.COM ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
13988490SPaul.Guo@Sun.COM {
13998490SPaul.Guo@Sun.COM 	u32 rar_high;
14008490SPaul.Guo@Sun.COM 	u32 rar_entries = hw->mac.num_rar_entries;
14018490SPaul.Guo@Sun.COM 
140210998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_clear_rar_generic");
140310998SChenlu.Chen@Sun.COM 
14048490SPaul.Guo@Sun.COM 	/* Make sure we are using a valid rar index range */
14058490SPaul.Guo@Sun.COM 	if (index < rar_entries) {
14068490SPaul.Guo@Sun.COM 		/*
14078490SPaul.Guo@Sun.COM 		 * Some parts put the VMDq setting in the extra RAH bits,
14088490SPaul.Guo@Sun.COM 		 * so save everything except the lower 16 bits that hold part
14098490SPaul.Guo@Sun.COM 		 * of the address and the address valid bit.
14108490SPaul.Guo@Sun.COM 		 */
14118490SPaul.Guo@Sun.COM 		rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
14128490SPaul.Guo@Sun.COM 		rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
14138490SPaul.Guo@Sun.COM 
14148490SPaul.Guo@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
14158490SPaul.Guo@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
14168490SPaul.Guo@Sun.COM 	} else {
14178490SPaul.Guo@Sun.COM 		DEBUGOUT1("RAR index %d is out of range.\n", index);
14188490SPaul.Guo@Sun.COM 	}
14198490SPaul.Guo@Sun.COM 
14208490SPaul.Guo@Sun.COM 	/* clear VMDq pool/queue selection for this RAR */
14218490SPaul.Guo@Sun.COM 	hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
14228490SPaul.Guo@Sun.COM 
14238490SPaul.Guo@Sun.COM 	return (IXGBE_SUCCESS);
14248490SPaul.Guo@Sun.COM }
14258490SPaul.Guo@Sun.COM 
14268490SPaul.Guo@Sun.COM /*
14276621Sbt150084  * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
14286621Sbt150084  * @hw: pointer to hardware structure
14296621Sbt150084  *
14306621Sbt150084  * Places the MAC address in receive address register 0 and clears the rest
14316621Sbt150084  * of the receive address registers. Clears the multicast table. Assumes
14326621Sbt150084  * the receiver is in reset when the routine is called.
14336621Sbt150084  */
14346621Sbt150084 s32
ixgbe_init_rx_addrs_generic(struct ixgbe_hw * hw)14356621Sbt150084 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
14366621Sbt150084 {
14376621Sbt150084 	u32 i;
14386621Sbt150084 	u32 rar_entries = hw->mac.num_rar_entries;
14396621Sbt150084 
144010998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_init_rx_addrs_generic");
144110998SChenlu.Chen@Sun.COM 
14426621Sbt150084 	/*
14436621Sbt150084 	 * If the current mac address is valid, assume it is a software override
14446621Sbt150084 	 * to the permanent address.
14456621Sbt150084 	 * Otherwise, use the permanent address from the eeprom.
14466621Sbt150084 	 */
14476621Sbt150084 	if (ixgbe_validate_mac_addr(hw->mac.addr) ==
14486621Sbt150084 	    IXGBE_ERR_INVALID_MAC_ADDR) {
14496621Sbt150084 		/* Get the MAC address from the RAR0 for later reference */
14506621Sbt150084 		hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
14516621Sbt150084 
14526621Sbt150084 		DEBUGOUT3(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
14536621Sbt150084 		    hw->mac.addr[0], hw->mac.addr[1],
14546621Sbt150084 		    hw->mac.addr[2]);
14556621Sbt150084 		DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
14566621Sbt150084 		    hw->mac.addr[4], hw->mac.addr[5]);
14576621Sbt150084 	} else {
14586621Sbt150084 		/* Setup the receive address. */
14596621Sbt150084 		DEBUGOUT("Overriding MAC Address in RAR[0]\n");
14606621Sbt150084 		DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ",
14616621Sbt150084 		    hw->mac.addr[0], hw->mac.addr[1],
14626621Sbt150084 		    hw->mac.addr[2]);
14636621Sbt150084 		DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
14646621Sbt150084 		    hw->mac.addr[4], hw->mac.addr[5]);
14656621Sbt150084 
14666621Sbt150084 		hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
14676621Sbt150084 	}
14686621Sbt150084 	hw->addr_ctrl.overflow_promisc = 0;
14696621Sbt150084 
14706621Sbt150084 	hw->addr_ctrl.rar_used_count = 1;
14716621Sbt150084 
14726621Sbt150084 	/* Zero out the other receive addresses. */
14736621Sbt150084 	DEBUGOUT1("Clearing RAR[1-%d]\n", rar_entries - 1);
14746621Sbt150084 	for (i = 1; i < rar_entries; i++) {
14756621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
14766621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
14776621Sbt150084 	}
14786621Sbt150084 
14796621Sbt150084 	/* Clear the MTA */
14806621Sbt150084 	hw->addr_ctrl.mta_in_use = 0;
14816621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
14826621Sbt150084 
14836621Sbt150084 	DEBUGOUT(" Clearing MTA\n");
14846621Sbt150084 	for (i = 0; i < hw->mac.mcft_size; i++)
14856621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
14866621Sbt150084 
14879353SSamuel.Tu@Sun.COM 	(void) ixgbe_init_uta_tables(hw);
14888490SPaul.Guo@Sun.COM 
14896621Sbt150084 	return (IXGBE_SUCCESS);
14906621Sbt150084 }
14916621Sbt150084 
14929353SSamuel.Tu@Sun.COM 
14936621Sbt150084 /*
14946621Sbt150084  * ixgbe_add_uc_addr - Adds a secondary unicast address.
14956621Sbt150084  * @hw: pointer to hardware structure
14966621Sbt150084  * @addr: new address
14976621Sbt150084  *
14986621Sbt150084  * Adds it to unused receive address register or goes into promiscuous mode.
14996621Sbt150084  */
15006621Sbt150084 void
ixgbe_add_uc_addr(struct ixgbe_hw * hw,u8 * addr,u32 vmdq)15016621Sbt150084 ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
15026621Sbt150084 {
15036621Sbt150084 	u32 rar_entries = hw->mac.num_rar_entries;
15046621Sbt150084 	u32 rar;
15056621Sbt150084 
150610998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_add_uc_addr");
150710998SChenlu.Chen@Sun.COM 
15086621Sbt150084 	DEBUGOUT6(" UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
15096621Sbt150084 	    addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
15106621Sbt150084 
15116621Sbt150084 	/*
15126621Sbt150084 	 * Place this address in the RAR if there is room,
15136621Sbt150084 	 * else put the controller into promiscuous mode
15146621Sbt150084 	 */
15156621Sbt150084 	if (hw->addr_ctrl.rar_used_count < rar_entries) {
15169353SSamuel.Tu@Sun.COM 		rar = hw->addr_ctrl.rar_used_count;
15176621Sbt150084 		hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
15186621Sbt150084 		DEBUGOUT1("Added a secondary address to RAR[%d]\n", rar);
15196621Sbt150084 		hw->addr_ctrl.rar_used_count++;
15206621Sbt150084 	} else {
15216621Sbt150084 		hw->addr_ctrl.overflow_promisc++;
15226621Sbt150084 	}
15236621Sbt150084 
15246621Sbt150084 	DEBUGOUT("ixgbe_add_uc_addr Complete\n");
15256621Sbt150084 }
15266621Sbt150084 
15276621Sbt150084 /*
15286621Sbt150084  * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
15296621Sbt150084  * @hw: pointer to hardware structure
15306621Sbt150084  * @addr_list: the list of new addresses
15316621Sbt150084  * @addr_count: number of addresses
15326621Sbt150084  * @next: iterator function to walk the address list
15336621Sbt150084  *
15346621Sbt150084  * The given list replaces any existing list.  Clears the secondary addrs from
15356621Sbt150084  * receive address registers.  Uses unused receive address registers for the
15366621Sbt150084  * first secondary addresses, and falls back to promiscuous mode as needed.
15376621Sbt150084  *
15386621Sbt150084  * Drivers using secondary unicast addresses must set user_set_promisc when
15396621Sbt150084  * manually putting the device into promiscuous mode.
15406621Sbt150084  */
15416621Sbt150084 s32
ixgbe_update_uc_addr_list_generic(struct ixgbe_hw * hw,u8 * addr_list,u32 addr_count,ixgbe_mc_addr_itr next)15426621Sbt150084 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
15436621Sbt150084     u32 addr_count, ixgbe_mc_addr_itr next)
15446621Sbt150084 {
15456621Sbt150084 	u8 *addr;
15466621Sbt150084 	u32 i;
15476621Sbt150084 	u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
15486621Sbt150084 	u32 uc_addr_in_use;
15496621Sbt150084 	u32 fctrl;
15506621Sbt150084 	u32 vmdq;
15516621Sbt150084 
155210998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_update_uc_addr_list_generic");
155310998SChenlu.Chen@Sun.COM 
15546621Sbt150084 	/*
15556621Sbt150084 	 * Clear accounting of old secondary address list,
15566621Sbt150084 	 * don't count RAR[0]
15576621Sbt150084 	 */
15589353SSamuel.Tu@Sun.COM 	uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
15596621Sbt150084 	hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
15606621Sbt150084 	hw->addr_ctrl.overflow_promisc = 0;
15616621Sbt150084 
15626621Sbt150084 	/* Zero out the other receive addresses */
156312003SPaul.Guo@Sun.COM 	DEBUGOUT1("Clearing RAR[1-%d]\n", uc_addr_in_use + 1);
156412003SPaul.Guo@Sun.COM 	for (i = 0; i < uc_addr_in_use; i++) {
156512003SPaul.Guo@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_RAL(i + 1), 0);
156612003SPaul.Guo@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_RAH(i + 1), 0);
15676621Sbt150084 	}
15686621Sbt150084 
15696621Sbt150084 	/* Add the new addresses */
15706621Sbt150084 	for (i = 0; i < addr_count; i++) {
15716621Sbt150084 		DEBUGOUT(" Adding the secondary addresses:\n");
15726621Sbt150084 		addr = next(hw, &addr_list, &vmdq);
15736621Sbt150084 		ixgbe_add_uc_addr(hw, addr, vmdq);
15746621Sbt150084 	}
15756621Sbt150084 
15766621Sbt150084 	if (hw->addr_ctrl.overflow_promisc) {
15776621Sbt150084 		/* enable promisc if not already in overflow or set by user */
15786621Sbt150084 		if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
15796621Sbt150084 			DEBUGOUT(" Entering address overflow promisc mode\n");
15806621Sbt150084 			fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
15816621Sbt150084 			fctrl |= IXGBE_FCTRL_UPE;
15826621Sbt150084 			IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
15836621Sbt150084 		}
15846621Sbt150084 	} else {
15856621Sbt150084 		/* only disable if set by overflow, not by user */
15866621Sbt150084 		if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
15876621Sbt150084 			DEBUGOUT(" Leaving address overflow promisc mode\n");
15886621Sbt150084 			fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
15896621Sbt150084 			fctrl &= ~IXGBE_FCTRL_UPE;
15906621Sbt150084 			IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
15916621Sbt150084 		}
15926621Sbt150084 	}
15936621Sbt150084 
15946621Sbt150084 	DEBUGOUT("ixgbe_update_uc_addr_list_generic Complete\n");
15956621Sbt150084 	return (IXGBE_SUCCESS);
15966621Sbt150084 }
15976621Sbt150084 
15986621Sbt150084 /*
15996621Sbt150084  * ixgbe_mta_vector - Determines bit-vector in multicast table to set
16006621Sbt150084  * @hw: pointer to hardware structure
16016621Sbt150084  * @mc_addr: the multicast address
16026621Sbt150084  *
16036621Sbt150084  * Extracts the 12 bits, from a multicast address, to determine which
16046621Sbt150084  * bit-vector to set in the multicast table. The hardware uses 12 bits, from
16056621Sbt150084  * incoming rx multicast addresses, to determine the bit-vector to check in
16066621Sbt150084  * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
16076621Sbt150084  * by the MO field of the MCSTCTRL. The MO field is set during initialization
16086621Sbt150084  * to mc_filter_type.
16096621Sbt150084  */
16106621Sbt150084 static s32
ixgbe_mta_vector(struct ixgbe_hw * hw,u8 * mc_addr)16116621Sbt150084 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
16126621Sbt150084 {
16136621Sbt150084 	u32 vector = 0;
16146621Sbt150084 
161510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_mta_vector");
161610998SChenlu.Chen@Sun.COM 
16176621Sbt150084 	switch (hw->mac.mc_filter_type) {
16186621Sbt150084 	case 0:   /* use bits [47:36] of the address */
16196621Sbt150084 		vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
16206621Sbt150084 		break;
16216621Sbt150084 	case 1:   /* use bits [46:35] of the address */
16226621Sbt150084 		vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
16236621Sbt150084 		break;
16246621Sbt150084 	case 2:   /* use bits [45:34] of the address */
16256621Sbt150084 		vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
16266621Sbt150084 		break;
16276621Sbt150084 	case 3:   /* use bits [43:32] of the address */
16286621Sbt150084 		vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
16296621Sbt150084 		break;
16306621Sbt150084 	default:  /* Invalid mc_filter_type */
16316621Sbt150084 		DEBUGOUT("MC filter type param set incorrectly\n");
16326621Sbt150084 		ASSERT(0);
16336621Sbt150084 		break;
16346621Sbt150084 	}
16356621Sbt150084 
16366621Sbt150084 	/* vector can only be 12-bits or boundary will be exceeded */
16376621Sbt150084 	vector &= 0xFFF;
16386621Sbt150084 	return (vector);
16396621Sbt150084 }
16406621Sbt150084 
16416621Sbt150084 /*
16426621Sbt150084  * ixgbe_set_mta - Set bit-vector in multicast table
16436621Sbt150084  * @hw: pointer to hardware structure
16446621Sbt150084  * @hash_value: Multicast address hash value
16456621Sbt150084  *
16466621Sbt150084  * Sets the bit-vector in the multicast table.
16476621Sbt150084  */
16486621Sbt150084 void
ixgbe_set_mta(struct ixgbe_hw * hw,u8 * mc_addr)16496621Sbt150084 ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
16506621Sbt150084 {
16516621Sbt150084 	u32 vector;
16526621Sbt150084 	u32 vector_bit;
16536621Sbt150084 	u32 vector_reg;
16546621Sbt150084 
165510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_set_mta");
165610998SChenlu.Chen@Sun.COM 
16576621Sbt150084 	hw->addr_ctrl.mta_in_use++;
16586621Sbt150084 
16596621Sbt150084 	vector = ixgbe_mta_vector(hw, mc_addr);
16606621Sbt150084 	DEBUGOUT1(" bit-vector = 0x%03X\n", vector);
16616621Sbt150084 
16626621Sbt150084 	/*
16636621Sbt150084 	 * The MTA is a register array of 128 32-bit registers. It is treated
16646621Sbt150084 	 * like an array of 4096 bits.  We want to set bit
16656621Sbt150084 	 * BitArray[vector_value]. So we figure out what register the bit is
16666621Sbt150084 	 * in, read it, OR in the new bit, then write back the new value.  The
16676621Sbt150084 	 * register is determined by the upper 7 bits of the vector value and
16686621Sbt150084 	 * the bit within that register are determined by the lower 5 bits of
16696621Sbt150084 	 * the value.
16706621Sbt150084 	 */
16716621Sbt150084 	vector_reg = (vector >> 5) & 0x7F;
16726621Sbt150084 	vector_bit = vector & 0x1F;
1673*13006SChenlu.Chen@Sun.COM 	hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
16746621Sbt150084 }
16756621Sbt150084 
16766621Sbt150084 /*
16776621Sbt150084  * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
16786621Sbt150084  * @hw: pointer to hardware structure
16796621Sbt150084  * @mc_addr_list: the list of new multicast addresses
16806621Sbt150084  * @mc_addr_count: number of addresses
16816621Sbt150084  * @next: iterator function to walk the multicast address list
16826621Sbt150084  *
16836621Sbt150084  * The given list replaces any existing list. Clears the MC addrs from receive
16846621Sbt150084  * address registers and the multicast table. Uses unused receive address
16856621Sbt150084  * registers for the first multicast addresses, and hashes the rest into the
16866621Sbt150084  * multicast table.
16876621Sbt150084  */
16886621Sbt150084 s32
ixgbe_update_mc_addr_list_generic(struct ixgbe_hw * hw,u8 * mc_addr_list,u32 mc_addr_count,ixgbe_mc_addr_itr next)16896621Sbt150084 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
16906621Sbt150084     u32 mc_addr_count, ixgbe_mc_addr_itr next)
16916621Sbt150084 {
16926621Sbt150084 	u32 i;
16936621Sbt150084 	u32 vmdq;
16946621Sbt150084 
169510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_update_mc_addr_list_generic");
169610998SChenlu.Chen@Sun.COM 
16976621Sbt150084 	/*
16986621Sbt150084 	 * Set the new number of MC addresses that we are being requested to
16996621Sbt150084 	 * use.
17006621Sbt150084 	 */
17016621Sbt150084 	hw->addr_ctrl.num_mc_addrs = mc_addr_count;
17026621Sbt150084 	hw->addr_ctrl.mta_in_use = 0;
17036621Sbt150084 
1704*13006SChenlu.Chen@Sun.COM 	/* Clear mta_shadow */
17056621Sbt150084 	DEBUGOUT(" Clearing MTA\n");
1706*13006SChenlu.Chen@Sun.COM 	(void) memset(&hw->mac.mta_shadow, 0, sizeof (hw->mac.mta_shadow));
1707*13006SChenlu.Chen@Sun.COM 
1708*13006SChenlu.Chen@Sun.COM 	/* Update mta_shadow */
17096621Sbt150084 	for (i = 0; i < mc_addr_count; i++) {
17106621Sbt150084 		DEBUGOUT(" Adding the multicast addresses:\n");
17119353SSamuel.Tu@Sun.COM 		ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
17126621Sbt150084 	}
17136621Sbt150084 
17146621Sbt150084 	/* Enable mta */
1715*13006SChenlu.Chen@Sun.COM 	for (i = 0; i < hw->mac.mcft_size; i++)
1716*13006SChenlu.Chen@Sun.COM 		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
1717*13006SChenlu.Chen@Sun.COM 		    hw->mac.mta_shadow[i]);
1718*13006SChenlu.Chen@Sun.COM 
17196621Sbt150084 	if (hw->addr_ctrl.mta_in_use > 0)
17206621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
17216621Sbt150084 		    IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
17226621Sbt150084 
17236621Sbt150084 	DEBUGOUT("ixgbe_update_mc_addr_list_generic Complete\n");
17246621Sbt150084 	return (IXGBE_SUCCESS);
17256621Sbt150084 }
17266621Sbt150084 
17276621Sbt150084 /*
17286621Sbt150084  * ixgbe_enable_mc_generic - Enable multicast address in RAR
17296621Sbt150084  * @hw: pointer to hardware structure
17306621Sbt150084  *
17316621Sbt150084  * Enables multicast address in RAR and the use of the multicast hash table.
17326621Sbt150084  */
17336621Sbt150084 s32
ixgbe_enable_mc_generic(struct ixgbe_hw * hw)17346621Sbt150084 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
17356621Sbt150084 {
17366621Sbt150084 	struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
17376621Sbt150084 
173810998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_enable_mc_generic");
173910998SChenlu.Chen@Sun.COM 
17406621Sbt150084 	if (a->mta_in_use > 0)
17416621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
17426621Sbt150084 		    hw->mac.mc_filter_type);
17436621Sbt150084 
17446621Sbt150084 	return (IXGBE_SUCCESS);
17456621Sbt150084 }
17466621Sbt150084 
17476621Sbt150084 /*
17486621Sbt150084  * ixgbe_disable_mc_generic - Disable multicast address in RAR
17496621Sbt150084  * @hw: pointer to hardware structure
17506621Sbt150084  *
17516621Sbt150084  * Disables multicast address in RAR and the use of the multicast hash table.
17526621Sbt150084  */
17536621Sbt150084 s32
ixgbe_disable_mc_generic(struct ixgbe_hw * hw)17546621Sbt150084 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
17556621Sbt150084 {
17566621Sbt150084 	struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
17576621Sbt150084 
175810998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_disable_mc_generic");
175910998SChenlu.Chen@Sun.COM 
17606621Sbt150084 	if (a->mta_in_use > 0)
17616621Sbt150084 		IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
17626621Sbt150084 
17636621Sbt150084 	return (IXGBE_SUCCESS);
17646621Sbt150084 }
17656621Sbt150084 
17666621Sbt150084 /*
17679353SSamuel.Tu@Sun.COM  * ixgbe_fc_enable_generic - Enable flow control
17689353SSamuel.Tu@Sun.COM  * @hw: pointer to hardware structure
17699353SSamuel.Tu@Sun.COM  * @packetbuf_num: packet buffer number (0-7)
17709353SSamuel.Tu@Sun.COM  *
17719353SSamuel.Tu@Sun.COM  * Enable flow control according to the current settings.
17729353SSamuel.Tu@Sun.COM  */
17739353SSamuel.Tu@Sun.COM s32
ixgbe_fc_enable_generic(struct ixgbe_hw * hw,s32 packetbuf_num)17749353SSamuel.Tu@Sun.COM ixgbe_fc_enable_generic(struct ixgbe_hw *hw, s32 packetbuf_num)
17759353SSamuel.Tu@Sun.COM {
17769353SSamuel.Tu@Sun.COM 	s32 ret_val = IXGBE_SUCCESS;
17779353SSamuel.Tu@Sun.COM 	u32 mflcn_reg, fccfg_reg;
17789353SSamuel.Tu@Sun.COM 	u32 reg;
177910305SPaul.Guo@Sun.COM 	u32 rx_pba_size;
17809353SSamuel.Tu@Sun.COM 
17819353SSamuel.Tu@Sun.COM 	DEBUGFUNC("ixgbe_fc_enable_generic");
17829353SSamuel.Tu@Sun.COM 
17839353SSamuel.Tu@Sun.COM 	/* Negotiate the fc mode to use */
17849353SSamuel.Tu@Sun.COM 	ret_val = ixgbe_fc_autoneg(hw);
1785*13006SChenlu.Chen@Sun.COM 	if (ret_val == IXGBE_ERR_FLOW_CONTROL)
17869353SSamuel.Tu@Sun.COM 		goto out;
17879353SSamuel.Tu@Sun.COM 
17889353SSamuel.Tu@Sun.COM 	/* Disable any previous flow control settings */
17899353SSamuel.Tu@Sun.COM 	mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
17909353SSamuel.Tu@Sun.COM 	mflcn_reg &= ~(IXGBE_MFLCN_RFCE | IXGBE_MFLCN_RPFCE);
17919353SSamuel.Tu@Sun.COM 
17929353SSamuel.Tu@Sun.COM 	fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
17939353SSamuel.Tu@Sun.COM 	fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
17949353SSamuel.Tu@Sun.COM 
17959353SSamuel.Tu@Sun.COM 	/*
17969353SSamuel.Tu@Sun.COM 	 * The possible values of fc.current_mode are:
17979353SSamuel.Tu@Sun.COM 	 * 0: Flow control is completely disabled
17989353SSamuel.Tu@Sun.COM 	 * 1: Rx flow control is enabled (we can receive pause frames,
17999353SSamuel.Tu@Sun.COM 	 *    but not send pause frames).
18009353SSamuel.Tu@Sun.COM 	 * 2: Tx flow control is enabled (we can send pause frames but
18019353SSamuel.Tu@Sun.COM 	 *    we do not support receiving pause frames).
18029353SSamuel.Tu@Sun.COM 	 * 3: Both Rx and Tx flow control (symmetric) are enabled.
18039353SSamuel.Tu@Sun.COM 	 * other: Invalid.
18049353SSamuel.Tu@Sun.COM 	 */
18059353SSamuel.Tu@Sun.COM 	switch (hw->fc.current_mode) {
18069353SSamuel.Tu@Sun.COM 	case ixgbe_fc_none:
18079353SSamuel.Tu@Sun.COM 		/*
18089353SSamuel.Tu@Sun.COM 		 * Flow control is disabled by software override or autoneg.
18099353SSamuel.Tu@Sun.COM 		 * The code below will actually disable it in the HW.
18109353SSamuel.Tu@Sun.COM 		 */
18119353SSamuel.Tu@Sun.COM 		break;
18129353SSamuel.Tu@Sun.COM 	case ixgbe_fc_rx_pause:
18139353SSamuel.Tu@Sun.COM 		/*
18149353SSamuel.Tu@Sun.COM 		 * Rx Flow control is enabled and Tx Flow control is
18159353SSamuel.Tu@Sun.COM 		 * disabled by software override. Since there really
18169353SSamuel.Tu@Sun.COM 		 * isn't a way to advertise that we are capable of RX
18179353SSamuel.Tu@Sun.COM 		 * Pause ONLY, we will advertise that we support both
18189353SSamuel.Tu@Sun.COM 		 * symmetric and asymmetric Rx PAUSE.  Later, we will
18199353SSamuel.Tu@Sun.COM 		 * disable the adapter's ability to send PAUSE frames.
18209353SSamuel.Tu@Sun.COM 		 */
18219353SSamuel.Tu@Sun.COM 		mflcn_reg |= IXGBE_MFLCN_RFCE;
18229353SSamuel.Tu@Sun.COM 		break;
18239353SSamuel.Tu@Sun.COM 	case ixgbe_fc_tx_pause:
18249353SSamuel.Tu@Sun.COM 		/*
18259353SSamuel.Tu@Sun.COM 		 * Tx Flow control is enabled, and Rx Flow control is
18269353SSamuel.Tu@Sun.COM 		 * disabled by software override.
18279353SSamuel.Tu@Sun.COM 		 */
18289353SSamuel.Tu@Sun.COM 		fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
18299353SSamuel.Tu@Sun.COM 		break;
18309353SSamuel.Tu@Sun.COM 	case ixgbe_fc_full:
18319353SSamuel.Tu@Sun.COM 		/* Flow control (both Rx and Tx) is enabled by SW override. */
18329353SSamuel.Tu@Sun.COM 		mflcn_reg |= IXGBE_MFLCN_RFCE;
18339353SSamuel.Tu@Sun.COM 		fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
18349353SSamuel.Tu@Sun.COM 		break;
18359353SSamuel.Tu@Sun.COM 	default:
18369353SSamuel.Tu@Sun.COM 		DEBUGOUT("Flow control param set incorrectly\n");
183710998SChenlu.Chen@Sun.COM 		ret_val = IXGBE_ERR_CONFIG;
18389353SSamuel.Tu@Sun.COM 		goto out;
18399353SSamuel.Tu@Sun.COM 	}
18409353SSamuel.Tu@Sun.COM 
18419353SSamuel.Tu@Sun.COM 	/* Set 802.3x based flow control settings. */
18429353SSamuel.Tu@Sun.COM 	mflcn_reg |= IXGBE_MFLCN_DPF;
18439353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
18449353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
18459353SSamuel.Tu@Sun.COM 
184610305SPaul.Guo@Sun.COM 	reg = IXGBE_READ_REG(hw, IXGBE_MTQC);
184710305SPaul.Guo@Sun.COM 	/* Thresholds are different for link flow control when in DCB mode */
184810305SPaul.Guo@Sun.COM 	if (reg & IXGBE_MTQC_RT_ENA) {
184910305SPaul.Guo@Sun.COM 		rx_pba_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(packetbuf_num));
185010305SPaul.Guo@Sun.COM 
185110305SPaul.Guo@Sun.COM 		/* Always disable XON for LFC when in DCB mode */
185210305SPaul.Guo@Sun.COM 		reg = (rx_pba_size >> 5) & 0xFFE0;
185310305SPaul.Guo@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(packetbuf_num), reg);
185410305SPaul.Guo@Sun.COM 
185510305SPaul.Guo@Sun.COM 		reg = (rx_pba_size >> 2) & 0xFFE0;
185610305SPaul.Guo@Sun.COM 		if (hw->fc.current_mode & ixgbe_fc_tx_pause)
185710305SPaul.Guo@Sun.COM 			reg |= IXGBE_FCRTH_FCEN;
185810305SPaul.Guo@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num), reg);
185910305SPaul.Guo@Sun.COM 	} else {
186010305SPaul.Guo@Sun.COM 		/*
186110305SPaul.Guo@Sun.COM 		 * Set up and enable Rx high/low water mark thresholds,
186210305SPaul.Guo@Sun.COM 		 * enable XON.
186310305SPaul.Guo@Sun.COM 		 */
186410305SPaul.Guo@Sun.COM 		if (hw->fc.current_mode & ixgbe_fc_tx_pause) {
186510305SPaul.Guo@Sun.COM 			if (hw->fc.send_xon) {
186610305SPaul.Guo@Sun.COM 				IXGBE_WRITE_REG(hw,
186710305SPaul.Guo@Sun.COM 				    IXGBE_FCRTL_82599(packetbuf_num),
186810305SPaul.Guo@Sun.COM 				    (hw->fc.low_water | IXGBE_FCRTL_XONE));
186910305SPaul.Guo@Sun.COM 			} else {
187010305SPaul.Guo@Sun.COM 				IXGBE_WRITE_REG(hw,
187110305SPaul.Guo@Sun.COM 				    IXGBE_FCRTL_82599(packetbuf_num),
187210305SPaul.Guo@Sun.COM 				    hw->fc.low_water);
187310305SPaul.Guo@Sun.COM 			}
187410305SPaul.Guo@Sun.COM 
187510305SPaul.Guo@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(packetbuf_num),
187610305SPaul.Guo@Sun.COM 			    (hw->fc.high_water | IXGBE_FCRTH_FCEN));
18779353SSamuel.Tu@Sun.COM 		}
18789353SSamuel.Tu@Sun.COM 	}
18799353SSamuel.Tu@Sun.COM 
18809353SSamuel.Tu@Sun.COM 	/* Configure pause time (2 TCs per register) */
188110305SPaul.Guo@Sun.COM 	reg = IXGBE_READ_REG(hw, IXGBE_FCTTV(packetbuf_num / 2));
18829353SSamuel.Tu@Sun.COM 	if ((packetbuf_num & 1) == 0)
18839353SSamuel.Tu@Sun.COM 		reg = (reg & 0xFFFF0000) | hw->fc.pause_time;
18849353SSamuel.Tu@Sun.COM 	else
18859353SSamuel.Tu@Sun.COM 		reg = (reg & 0x0000FFFF) | (hw->fc.pause_time << 16);
18869353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_FCTTV(packetbuf_num / 2), reg);
18879353SSamuel.Tu@Sun.COM 
18889353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_FCRTV, (hw->fc.pause_time >> 1));
18899353SSamuel.Tu@Sun.COM 
18909353SSamuel.Tu@Sun.COM out:
18919353SSamuel.Tu@Sun.COM 	return (ret_val);
18929353SSamuel.Tu@Sun.COM }
18939353SSamuel.Tu@Sun.COM 
18949353SSamuel.Tu@Sun.COM /*
18959353SSamuel.Tu@Sun.COM  * ixgbe_fc_autoneg - Configure flow control
18969353SSamuel.Tu@Sun.COM  * @hw: pointer to hardware structure
18979353SSamuel.Tu@Sun.COM  *
18989353SSamuel.Tu@Sun.COM  * Compares our advertised flow control capabilities to those advertised by
18999353SSamuel.Tu@Sun.COM  * our link partner, and determines the proper flow control mode to use.
19009353SSamuel.Tu@Sun.COM  */
19019353SSamuel.Tu@Sun.COM s32
ixgbe_fc_autoneg(struct ixgbe_hw * hw)19029353SSamuel.Tu@Sun.COM ixgbe_fc_autoneg(struct ixgbe_hw *hw)
19039353SSamuel.Tu@Sun.COM {
1904*13006SChenlu.Chen@Sun.COM 	s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
19059353SSamuel.Tu@Sun.COM 	ixgbe_link_speed speed;
19069353SSamuel.Tu@Sun.COM 	bool link_up;
19079353SSamuel.Tu@Sun.COM 
19089353SSamuel.Tu@Sun.COM 	DEBUGFUNC("ixgbe_fc_autoneg");
19099353SSamuel.Tu@Sun.COM 
1910*13006SChenlu.Chen@Sun.COM 	if (hw->fc.disable_fc_autoneg)
1911*13006SChenlu.Chen@Sun.COM 		goto out;
1912*13006SChenlu.Chen@Sun.COM 
19139353SSamuel.Tu@Sun.COM 	/*
19149353SSamuel.Tu@Sun.COM 	 * AN should have completed when the cable was plugged in.
19159353SSamuel.Tu@Sun.COM 	 * Look for reasons to bail out.  Bail out if:
19169353SSamuel.Tu@Sun.COM 	 * - FC autoneg is disabled, or if
191710998SChenlu.Chen@Sun.COM 	 * - link is not up.
19189353SSamuel.Tu@Sun.COM 	 *
191910998SChenlu.Chen@Sun.COM 	 * Since we're being called from an LSC, link is already known to be up.
19209353SSamuel.Tu@Sun.COM 	 * So use link_up_wait_to_complete=false.
19219353SSamuel.Tu@Sun.COM 	 */
19229353SSamuel.Tu@Sun.COM 	hw->mac.ops.check_link(hw, &speed, &link_up, false);
1923*13006SChenlu.Chen@Sun.COM 	if (!link_up) {
1924*13006SChenlu.Chen@Sun.COM 		ret_val = IXGBE_ERR_FLOW_CONTROL;
192510998SChenlu.Chen@Sun.COM 		goto out;
192610998SChenlu.Chen@Sun.COM 	}
192710998SChenlu.Chen@Sun.COM 
1928*13006SChenlu.Chen@Sun.COM 	switch (hw->phy.media_type) {
1929*13006SChenlu.Chen@Sun.COM 	/* Autoneg flow control on fiber adapters */
1930*13006SChenlu.Chen@Sun.COM 	case ixgbe_media_type_fiber:
1931*13006SChenlu.Chen@Sun.COM 		if (speed == IXGBE_LINK_SPEED_1GB_FULL)
1932*13006SChenlu.Chen@Sun.COM 			ret_val = ixgbe_fc_autoneg_fiber(hw);
1933*13006SChenlu.Chen@Sun.COM 		break;
1934*13006SChenlu.Chen@Sun.COM 
1935*13006SChenlu.Chen@Sun.COM 	/* Autoneg flow control on backplane adapters */
1936*13006SChenlu.Chen@Sun.COM 	case ixgbe_media_type_backplane:
1937*13006SChenlu.Chen@Sun.COM 		ret_val = ixgbe_fc_autoneg_backplane(hw);
1938*13006SChenlu.Chen@Sun.COM 		break;
1939*13006SChenlu.Chen@Sun.COM 
1940*13006SChenlu.Chen@Sun.COM 	/* Autoneg flow control on copper adapters */
1941*13006SChenlu.Chen@Sun.COM 	case ixgbe_media_type_copper:
1942*13006SChenlu.Chen@Sun.COM 		if (ixgbe_device_supports_autoneg_fc(hw) == IXGBE_SUCCESS)
1943*13006SChenlu.Chen@Sun.COM 			ret_val = ixgbe_fc_autoneg_copper(hw);
1944*13006SChenlu.Chen@Sun.COM 		break;
1945*13006SChenlu.Chen@Sun.COM 
1946*13006SChenlu.Chen@Sun.COM 	default:
1947*13006SChenlu.Chen@Sun.COM 		break;
194810998SChenlu.Chen@Sun.COM 	}
194910998SChenlu.Chen@Sun.COM 
1950*13006SChenlu.Chen@Sun.COM out:
1951*13006SChenlu.Chen@Sun.COM 	if (ret_val == IXGBE_SUCCESS) {
1952*13006SChenlu.Chen@Sun.COM 		hw->fc.fc_was_autonegged = true;
1953*13006SChenlu.Chen@Sun.COM 	} else {
1954*13006SChenlu.Chen@Sun.COM 		hw->fc.fc_was_autonegged = false;
1955*13006SChenlu.Chen@Sun.COM 		hw->fc.current_mode = hw->fc.requested_mode;
1956*13006SChenlu.Chen@Sun.COM 	}
1957*13006SChenlu.Chen@Sun.COM 	return (ret_val);
1958*13006SChenlu.Chen@Sun.COM }
1959*13006SChenlu.Chen@Sun.COM 
1960*13006SChenlu.Chen@Sun.COM /*
1961*13006SChenlu.Chen@Sun.COM  * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
1962*13006SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
1963*13006SChenlu.Chen@Sun.COM  * @speed:
1964*13006SChenlu.Chen@Sun.COM  * @link_up
1965*13006SChenlu.Chen@Sun.COM  *
1966*13006SChenlu.Chen@Sun.COM  * Enable flow control according on 1 gig fiber.
1967*13006SChenlu.Chen@Sun.COM  */
1968*13006SChenlu.Chen@Sun.COM static s32
ixgbe_fc_autoneg_fiber(struct ixgbe_hw * hw)1969*13006SChenlu.Chen@Sun.COM ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
1970*13006SChenlu.Chen@Sun.COM {
1971*13006SChenlu.Chen@Sun.COM 	u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
1972*13006SChenlu.Chen@Sun.COM 	s32 ret_val;
1973*13006SChenlu.Chen@Sun.COM 
197410998SChenlu.Chen@Sun.COM 	/*
197510998SChenlu.Chen@Sun.COM 	 * On multispeed fiber at 1g, bail out if
197610998SChenlu.Chen@Sun.COM 	 * - link is up but AN did not complete, or if
197710998SChenlu.Chen@Sun.COM 	 * - link is up and AN completed but timed out
197810998SChenlu.Chen@Sun.COM 	 */
1979*13006SChenlu.Chen@Sun.COM 
1980*13006SChenlu.Chen@Sun.COM 	linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
1981*13006SChenlu.Chen@Sun.COM 	if (((linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
1982*13006SChenlu.Chen@Sun.COM 	    ((linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
1983*13006SChenlu.Chen@Sun.COM 		ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
1984*13006SChenlu.Chen@Sun.COM 		goto out;
1985*13006SChenlu.Chen@Sun.COM 	}
1986*13006SChenlu.Chen@Sun.COM 
1987*13006SChenlu.Chen@Sun.COM 	pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
1988*13006SChenlu.Chen@Sun.COM 	pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
1989*13006SChenlu.Chen@Sun.COM 
1990*13006SChenlu.Chen@Sun.COM 	ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
1991*13006SChenlu.Chen@Sun.COM 	    pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
1992*13006SChenlu.Chen@Sun.COM 	    IXGBE_PCS1GANA_ASM_PAUSE,
1993*13006SChenlu.Chen@Sun.COM 	    IXGBE_PCS1GANA_SYM_PAUSE,
1994*13006SChenlu.Chen@Sun.COM 	    IXGBE_PCS1GANA_ASM_PAUSE);
1995*13006SChenlu.Chen@Sun.COM 
1996*13006SChenlu.Chen@Sun.COM out:
1997*13006SChenlu.Chen@Sun.COM 	return (ret_val);
1998*13006SChenlu.Chen@Sun.COM }
1999*13006SChenlu.Chen@Sun.COM 
2000*13006SChenlu.Chen@Sun.COM /*
2001*13006SChenlu.Chen@Sun.COM  * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
2002*13006SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
2003*13006SChenlu.Chen@Sun.COM  *
2004*13006SChenlu.Chen@Sun.COM  * Enable flow control according to IEEE clause 37.
2005*13006SChenlu.Chen@Sun.COM  */
2006*13006SChenlu.Chen@Sun.COM static s32
ixgbe_fc_autoneg_backplane(struct ixgbe_hw * hw)2007*13006SChenlu.Chen@Sun.COM ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
2008*13006SChenlu.Chen@Sun.COM {
2009*13006SChenlu.Chen@Sun.COM 	u32 links2, anlp1_reg, autoc_reg, links;
2010*13006SChenlu.Chen@Sun.COM 	s32 ret_val;
2011*13006SChenlu.Chen@Sun.COM 
2012*13006SChenlu.Chen@Sun.COM 	/*
2013*13006SChenlu.Chen@Sun.COM 	 * On backplane, bail out if
2014*13006SChenlu.Chen@Sun.COM 	 * - backplane autoneg was not completed, or if
2015*13006SChenlu.Chen@Sun.COM 	 * - we are 82599 and link partner is not AN enabled
2016*13006SChenlu.Chen@Sun.COM 	 */
2017*13006SChenlu.Chen@Sun.COM 	links = IXGBE_READ_REG(hw, IXGBE_LINKS);
2018*13006SChenlu.Chen@Sun.COM 	if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
2019*13006SChenlu.Chen@Sun.COM 		hw->fc.fc_was_autonegged = false;
2020*13006SChenlu.Chen@Sun.COM 		hw->fc.current_mode = hw->fc.requested_mode;
2021*13006SChenlu.Chen@Sun.COM 		ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2022*13006SChenlu.Chen@Sun.COM 		goto out;
2023*13006SChenlu.Chen@Sun.COM 	}
2024*13006SChenlu.Chen@Sun.COM 
2025*13006SChenlu.Chen@Sun.COM 	if (hw->mac.type == ixgbe_mac_82599EB) {
2026*13006SChenlu.Chen@Sun.COM 		links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
2027*13006SChenlu.Chen@Sun.COM 		if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
202810998SChenlu.Chen@Sun.COM 			hw->fc.fc_was_autonegged = false;
202910998SChenlu.Chen@Sun.COM 			hw->fc.current_mode = hw->fc.requested_mode;
2030*13006SChenlu.Chen@Sun.COM 			ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
203110998SChenlu.Chen@Sun.COM 			goto out;
203210998SChenlu.Chen@Sun.COM 		}
203310998SChenlu.Chen@Sun.COM 	}
203410998SChenlu.Chen@Sun.COM 	/*
2035*13006SChenlu.Chen@Sun.COM 	 * Read the 10g AN autoc and LP ability registers and resolve
20369353SSamuel.Tu@Sun.COM 	 * local flow control settings accordingly
20379353SSamuel.Tu@Sun.COM 	 */
2038*13006SChenlu.Chen@Sun.COM 	autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2039*13006SChenlu.Chen@Sun.COM 	anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
2040*13006SChenlu.Chen@Sun.COM 
2041*13006SChenlu.Chen@Sun.COM 	ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
2042*13006SChenlu.Chen@Sun.COM 	    anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
2043*13006SChenlu.Chen@Sun.COM 	    IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
20449353SSamuel.Tu@Sun.COM 
20459353SSamuel.Tu@Sun.COM out:
20469353SSamuel.Tu@Sun.COM 	return (ret_val);
20479353SSamuel.Tu@Sun.COM }
20489353SSamuel.Tu@Sun.COM 
20499353SSamuel.Tu@Sun.COM /*
2050*13006SChenlu.Chen@Sun.COM  * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
2051*13006SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
2052*13006SChenlu.Chen@Sun.COM  *
2053*13006SChenlu.Chen@Sun.COM  * Enable flow control according to IEEE clause 37.
2054*13006SChenlu.Chen@Sun.COM  */
2055*13006SChenlu.Chen@Sun.COM static s32
ixgbe_fc_autoneg_copper(struct ixgbe_hw * hw)2056*13006SChenlu.Chen@Sun.COM ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
2057*13006SChenlu.Chen@Sun.COM {
2058*13006SChenlu.Chen@Sun.COM 	u16 technology_ability_reg = 0;
2059*13006SChenlu.Chen@Sun.COM 	u16 lp_technology_ability_reg = 0;
2060*13006SChenlu.Chen@Sun.COM 
2061*13006SChenlu.Chen@Sun.COM 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
2062*13006SChenlu.Chen@Sun.COM 	    IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &technology_ability_reg);
2063*13006SChenlu.Chen@Sun.COM 	hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_LP,
2064*13006SChenlu.Chen@Sun.COM 	    IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &lp_technology_ability_reg);
2065*13006SChenlu.Chen@Sun.COM 
2066*13006SChenlu.Chen@Sun.COM 	return (ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
2067*13006SChenlu.Chen@Sun.COM 	    (u32)lp_technology_ability_reg,
2068*13006SChenlu.Chen@Sun.COM 	    IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
2069*13006SChenlu.Chen@Sun.COM 	    IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE));
2070*13006SChenlu.Chen@Sun.COM }
2071*13006SChenlu.Chen@Sun.COM 
2072*13006SChenlu.Chen@Sun.COM /*
2073*13006SChenlu.Chen@Sun.COM  * ixgbe_negotiate_fc - Negotiate flow control
2074*13006SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
2075*13006SChenlu.Chen@Sun.COM  * @adv_reg: flow control advertised settings
2076*13006SChenlu.Chen@Sun.COM  * @lp_reg: link partner's flow control settings
2077*13006SChenlu.Chen@Sun.COM  * @adv_sym: symmetric pause bit in advertisement
2078*13006SChenlu.Chen@Sun.COM  * @adv_asm: asymmetric pause bit in advertisement
2079*13006SChenlu.Chen@Sun.COM  * @lp_sym: symmetric pause bit in link partner advertisement
2080*13006SChenlu.Chen@Sun.COM  * @lp_asm: asymmetric pause bit in link partner advertisement
2081*13006SChenlu.Chen@Sun.COM  *
2082*13006SChenlu.Chen@Sun.COM  * Find the intersection between advertised settings and link partner's
2083*13006SChenlu.Chen@Sun.COM  * advertised settings
2084*13006SChenlu.Chen@Sun.COM  */
2085*13006SChenlu.Chen@Sun.COM static s32
ixgbe_negotiate_fc(struct ixgbe_hw * hw,u32 adv_reg,u32 lp_reg,u32 adv_sym,u32 adv_asm,u32 lp_sym,u32 lp_asm)2086*13006SChenlu.Chen@Sun.COM ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
2087*13006SChenlu.Chen@Sun.COM     u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
2088*13006SChenlu.Chen@Sun.COM {
2089*13006SChenlu.Chen@Sun.COM 	if ((!(adv_reg)) || (!(lp_reg)))
2090*13006SChenlu.Chen@Sun.COM 		return (IXGBE_ERR_FC_NOT_NEGOTIATED);
2091*13006SChenlu.Chen@Sun.COM 
2092*13006SChenlu.Chen@Sun.COM 	if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
2093*13006SChenlu.Chen@Sun.COM 		/*
2094*13006SChenlu.Chen@Sun.COM 		 * Now we need to check if the user selected Rx ONLY
2095*13006SChenlu.Chen@Sun.COM 		 * of pause frames.  In this case, we had to advertise
2096*13006SChenlu.Chen@Sun.COM 		 * FULL flow control because we could not advertise RX
2097*13006SChenlu.Chen@Sun.COM 		 * ONLY. Hence, we must now check to see if we need to
2098*13006SChenlu.Chen@Sun.COM 		 * turn OFF the TRANSMISSION of PAUSE frames.
2099*13006SChenlu.Chen@Sun.COM 		 */
2100*13006SChenlu.Chen@Sun.COM 		if (hw->fc.requested_mode == ixgbe_fc_full) {
2101*13006SChenlu.Chen@Sun.COM 			hw->fc.current_mode = ixgbe_fc_full;
2102*13006SChenlu.Chen@Sun.COM 			DEBUGOUT("Flow Control = FULL.\n");
2103*13006SChenlu.Chen@Sun.COM 		} else {
2104*13006SChenlu.Chen@Sun.COM 			hw->fc.current_mode = ixgbe_fc_rx_pause;
2105*13006SChenlu.Chen@Sun.COM 			DEBUGOUT("Flow Control=RX PAUSE frames only\n");
2106*13006SChenlu.Chen@Sun.COM 		}
2107*13006SChenlu.Chen@Sun.COM 	} else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2108*13006SChenlu.Chen@Sun.COM 	    (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2109*13006SChenlu.Chen@Sun.COM 		hw->fc.current_mode = ixgbe_fc_tx_pause;
2110*13006SChenlu.Chen@Sun.COM 		DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2111*13006SChenlu.Chen@Sun.COM 	} else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2112*13006SChenlu.Chen@Sun.COM 	    !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2113*13006SChenlu.Chen@Sun.COM 		hw->fc.current_mode = ixgbe_fc_rx_pause;
2114*13006SChenlu.Chen@Sun.COM 		DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2115*13006SChenlu.Chen@Sun.COM 	} else {
2116*13006SChenlu.Chen@Sun.COM 		hw->fc.current_mode = ixgbe_fc_none;
2117*13006SChenlu.Chen@Sun.COM 		DEBUGOUT("Flow Control = NONE.\n");
2118*13006SChenlu.Chen@Sun.COM 	}
2119*13006SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
2120*13006SChenlu.Chen@Sun.COM }
2121*13006SChenlu.Chen@Sun.COM 
2122*13006SChenlu.Chen@Sun.COM /*
21239353SSamuel.Tu@Sun.COM  * ixgbe_setup_fc - Set up flow control
21249353SSamuel.Tu@Sun.COM  * @hw: pointer to hardware structure
21259353SSamuel.Tu@Sun.COM  *
21269353SSamuel.Tu@Sun.COM  * Called at init time to set up flow control.
21279353SSamuel.Tu@Sun.COM  */
21289353SSamuel.Tu@Sun.COM s32
ixgbe_setup_fc(struct ixgbe_hw * hw,s32 packetbuf_num)21299353SSamuel.Tu@Sun.COM ixgbe_setup_fc(struct ixgbe_hw *hw, s32 packetbuf_num)
21309353SSamuel.Tu@Sun.COM {
21319353SSamuel.Tu@Sun.COM 	s32 ret_val = IXGBE_SUCCESS;
2132*13006SChenlu.Chen@Sun.COM 	u32 reg = 0, reg_bp = 0;
2133*13006SChenlu.Chen@Sun.COM 	u16 reg_cu = 0;
21349353SSamuel.Tu@Sun.COM 
213510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_setup_fc");
213610998SChenlu.Chen@Sun.COM 
21379353SSamuel.Tu@Sun.COM 	/* Validate the packetbuf configuration */
21389353SSamuel.Tu@Sun.COM 	if (packetbuf_num < 0 || packetbuf_num > 7) {
21399353SSamuel.Tu@Sun.COM 		DEBUGOUT1("Invalid packet buffer number [%d], expected range is"
21409353SSamuel.Tu@Sun.COM 		    " 0-7\n", packetbuf_num);
21419353SSamuel.Tu@Sun.COM 		ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
21429353SSamuel.Tu@Sun.COM 		goto out;
21439353SSamuel.Tu@Sun.COM 	}
21449353SSamuel.Tu@Sun.COM 
21459353SSamuel.Tu@Sun.COM 	/*
21469353SSamuel.Tu@Sun.COM 	 * Validate the water mark configuration.  Zero water marks are invalid
21479353SSamuel.Tu@Sun.COM 	 * because it causes the controller to just blast out fc packets.
21489353SSamuel.Tu@Sun.COM 	 */
21499353SSamuel.Tu@Sun.COM 	if (!hw->fc.low_water || !hw->fc.high_water || !hw->fc.pause_time) {
21509353SSamuel.Tu@Sun.COM 		DEBUGOUT("Invalid water mark configuration\n");
21519353SSamuel.Tu@Sun.COM 		ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
21529353SSamuel.Tu@Sun.COM 		goto out;
21539353SSamuel.Tu@Sun.COM 	}
21549353SSamuel.Tu@Sun.COM 
21559353SSamuel.Tu@Sun.COM 	/*
21569353SSamuel.Tu@Sun.COM 	 * Validate the requested mode.  Strict IEEE mode does not allow
21579353SSamuel.Tu@Sun.COM 	 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
21589353SSamuel.Tu@Sun.COM 	 */
21599353SSamuel.Tu@Sun.COM 	if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
21609353SSamuel.Tu@Sun.COM 		DEBUGOUT("ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
21619353SSamuel.Tu@Sun.COM 		ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
21629353SSamuel.Tu@Sun.COM 		goto out;
21639353SSamuel.Tu@Sun.COM 	}
21649353SSamuel.Tu@Sun.COM 
21659353SSamuel.Tu@Sun.COM 	/*
21669353SSamuel.Tu@Sun.COM 	 * 10gig parts do not have a word in the EEPROM to determine the
21679353SSamuel.Tu@Sun.COM 	 * default flow control setting, so we explicitly set it to full.
21689353SSamuel.Tu@Sun.COM 	 */
21699353SSamuel.Tu@Sun.COM 	if (hw->fc.requested_mode == ixgbe_fc_default)
21709353SSamuel.Tu@Sun.COM 		hw->fc.requested_mode = ixgbe_fc_full;
21719353SSamuel.Tu@Sun.COM 
21729353SSamuel.Tu@Sun.COM 	/*
2173*13006SChenlu.Chen@Sun.COM 	 * Set up the 1G and 10G flow control advertisement registers so the
2174*13006SChenlu.Chen@Sun.COM 	 * HW will be able to do fc autoneg once the cable is plugged in.  If
2175*13006SChenlu.Chen@Sun.COM 	 * we link at 10G, the 1G advertisement is harmless and vice versa.
21769353SSamuel.Tu@Sun.COM 	 */
2177*13006SChenlu.Chen@Sun.COM 	switch (hw->phy.media_type) {
2178*13006SChenlu.Chen@Sun.COM 	case ixgbe_media_type_fiber:
2179*13006SChenlu.Chen@Sun.COM 	case ixgbe_media_type_backplane:
2180*13006SChenlu.Chen@Sun.COM 		reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2181*13006SChenlu.Chen@Sun.COM 		reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2182*13006SChenlu.Chen@Sun.COM 		break;
2183*13006SChenlu.Chen@Sun.COM 
2184*13006SChenlu.Chen@Sun.COM 	case ixgbe_media_type_copper:
2185*13006SChenlu.Chen@Sun.COM 		hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
2186*13006SChenlu.Chen@Sun.COM 		    IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg_cu);
2187*13006SChenlu.Chen@Sun.COM 		break;
2188*13006SChenlu.Chen@Sun.COM 
2189*13006SChenlu.Chen@Sun.COM 	default:
2190*13006SChenlu.Chen@Sun.COM 		;
2191*13006SChenlu.Chen@Sun.COM 	}
21929353SSamuel.Tu@Sun.COM 
21939353SSamuel.Tu@Sun.COM 	/*
21949353SSamuel.Tu@Sun.COM 	 * The possible values of fc.requested_mode are:
21959353SSamuel.Tu@Sun.COM 	 * 0: Flow control is completely disabled
21969353SSamuel.Tu@Sun.COM 	 * 1: Rx flow control is enabled (we can receive pause frames,
21979353SSamuel.Tu@Sun.COM 	 *    but not send pause frames).
21989353SSamuel.Tu@Sun.COM 	 * 2: Tx flow control is enabled (we can send pause frames but
21999353SSamuel.Tu@Sun.COM 	 *    we do not support receiving pause frames).
22009353SSamuel.Tu@Sun.COM 	 * 3: Both Rx and Tx flow control (symmetric) are enabled.
22019353SSamuel.Tu@Sun.COM 	 * other: Invalid.
22029353SSamuel.Tu@Sun.COM 	 */
22039353SSamuel.Tu@Sun.COM 	switch (hw->fc.requested_mode) {
22049353SSamuel.Tu@Sun.COM 	case ixgbe_fc_none:
22059353SSamuel.Tu@Sun.COM 		/* Flow control completely disabled by software override. */
22069353SSamuel.Tu@Sun.COM 		reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2207*13006SChenlu.Chen@Sun.COM 		if (hw->phy.media_type == ixgbe_media_type_backplane)
2208*13006SChenlu.Chen@Sun.COM 			reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
2209*13006SChenlu.Chen@Sun.COM 			    IXGBE_AUTOC_ASM_PAUSE);
2210*13006SChenlu.Chen@Sun.COM 		else if (hw->phy.media_type == ixgbe_media_type_copper)
2211*13006SChenlu.Chen@Sun.COM 			reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
22129353SSamuel.Tu@Sun.COM 		break;
22139353SSamuel.Tu@Sun.COM 	case ixgbe_fc_rx_pause:
22149353SSamuel.Tu@Sun.COM 		/*
22159353SSamuel.Tu@Sun.COM 		 * Rx Flow control is enabled and Tx Flow control is
22169353SSamuel.Tu@Sun.COM 		 * disabled by software override. Since there really
22179353SSamuel.Tu@Sun.COM 		 * isn't a way to advertise that we are capable of RX
22189353SSamuel.Tu@Sun.COM 		 * Pause ONLY, we will advertise that we support both
22199353SSamuel.Tu@Sun.COM 		 * symmetric and asymmetric Rx PAUSE.  Later, we will
22209353SSamuel.Tu@Sun.COM 		 * disable the adapter's ability to send PAUSE frames.
22219353SSamuel.Tu@Sun.COM 		 */
22229353SSamuel.Tu@Sun.COM 		reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2223*13006SChenlu.Chen@Sun.COM 		if (hw->phy.media_type == ixgbe_media_type_backplane)
2224*13006SChenlu.Chen@Sun.COM 			reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2225*13006SChenlu.Chen@Sun.COM 			    IXGBE_AUTOC_ASM_PAUSE);
2226*13006SChenlu.Chen@Sun.COM 		else if (hw->phy.media_type == ixgbe_media_type_copper)
2227*13006SChenlu.Chen@Sun.COM 			reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
22289353SSamuel.Tu@Sun.COM 		break;
22299353SSamuel.Tu@Sun.COM 	case ixgbe_fc_tx_pause:
22309353SSamuel.Tu@Sun.COM 		/*
22319353SSamuel.Tu@Sun.COM 		 * Tx Flow control is enabled, and Rx Flow control is
22329353SSamuel.Tu@Sun.COM 		 * disabled by software override.
22339353SSamuel.Tu@Sun.COM 		 */
22349353SSamuel.Tu@Sun.COM 		reg |= (IXGBE_PCS1GANA_ASM_PAUSE);
22359353SSamuel.Tu@Sun.COM 		reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE);
2236*13006SChenlu.Chen@Sun.COM 		if (hw->phy.media_type == ixgbe_media_type_backplane) {
2237*13006SChenlu.Chen@Sun.COM 			reg_bp |= (IXGBE_AUTOC_ASM_PAUSE);
2238*13006SChenlu.Chen@Sun.COM 			reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE);
2239*13006SChenlu.Chen@Sun.COM 		} else if (hw->phy.media_type == ixgbe_media_type_copper) {
2240*13006SChenlu.Chen@Sun.COM 			reg_cu |= (IXGBE_TAF_ASM_PAUSE);
2241*13006SChenlu.Chen@Sun.COM 			reg_cu &= ~(IXGBE_TAF_SYM_PAUSE);
2242*13006SChenlu.Chen@Sun.COM 		}
22439353SSamuel.Tu@Sun.COM 		break;
22449353SSamuel.Tu@Sun.COM 	case ixgbe_fc_full:
22459353SSamuel.Tu@Sun.COM 		/* Flow control (both Rx and Tx) is enabled by SW override. */
22469353SSamuel.Tu@Sun.COM 		reg |= (IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
2247*13006SChenlu.Chen@Sun.COM 		if (hw->phy.media_type == ixgbe_media_type_backplane)
2248*13006SChenlu.Chen@Sun.COM 			reg_bp |= (IXGBE_AUTOC_SYM_PAUSE |
2249*13006SChenlu.Chen@Sun.COM 			    IXGBE_AUTOC_ASM_PAUSE);
2250*13006SChenlu.Chen@Sun.COM 		else if (hw->phy.media_type == ixgbe_media_type_copper)
2251*13006SChenlu.Chen@Sun.COM 			reg_cu |= (IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
22529353SSamuel.Tu@Sun.COM 		break;
22539353SSamuel.Tu@Sun.COM 	default:
22549353SSamuel.Tu@Sun.COM 		DEBUGOUT("Flow control param set incorrectly\n");
225510998SChenlu.Chen@Sun.COM 		ret_val = IXGBE_ERR_CONFIG;
22569353SSamuel.Tu@Sun.COM 		goto out;
22579353SSamuel.Tu@Sun.COM 	}
22589353SSamuel.Tu@Sun.COM 
22599353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
22609353SSamuel.Tu@Sun.COM 	reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
22619353SSamuel.Tu@Sun.COM 
22629353SSamuel.Tu@Sun.COM 	/* Disable AN timeout */
22639353SSamuel.Tu@Sun.COM 	if (hw->fc.strict_ieee)
22649353SSamuel.Tu@Sun.COM 		reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
22659353SSamuel.Tu@Sun.COM 
22669353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
22679353SSamuel.Tu@Sun.COM 	DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg);
22689353SSamuel.Tu@Sun.COM 
226910998SChenlu.Chen@Sun.COM 	/*
227010998SChenlu.Chen@Sun.COM 	 * AUTOC restart handles negotiation of 1G and 10G. There is
227110998SChenlu.Chen@Sun.COM 	 * no need to set the PCS1GCTL register.
227210998SChenlu.Chen@Sun.COM 	 */
2273*13006SChenlu.Chen@Sun.COM 	if (hw->phy.media_type == ixgbe_media_type_backplane) {
2274*13006SChenlu.Chen@Sun.COM 		reg_bp |= IXGBE_AUTOC_AN_RESTART;
2275*13006SChenlu.Chen@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
2276*13006SChenlu.Chen@Sun.COM 	} else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
2277*13006SChenlu.Chen@Sun.COM 	    (ixgbe_device_supports_autoneg_fc(hw) == IXGBE_SUCCESS)) {
2278*13006SChenlu.Chen@Sun.COM 		hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
2279*13006SChenlu.Chen@Sun.COM 		    IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg_cu);
2280*13006SChenlu.Chen@Sun.COM 	}
2281*13006SChenlu.Chen@Sun.COM 
228210998SChenlu.Chen@Sun.COM 	DEBUGOUT1("Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
228310998SChenlu.Chen@Sun.COM 
22849353SSamuel.Tu@Sun.COM out:
22859353SSamuel.Tu@Sun.COM 	return (ret_val);
22869353SSamuel.Tu@Sun.COM }
22879353SSamuel.Tu@Sun.COM 
22889353SSamuel.Tu@Sun.COM /*
22896621Sbt150084  * ixgbe_disable_pcie_master - Disable PCI-express master access
22906621Sbt150084  * @hw: pointer to hardware structure
22916621Sbt150084  *
22926621Sbt150084  * Disables PCI-Express master access and verifies there are no pending
22936621Sbt150084  * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
22946621Sbt150084  * bit hasn't caused the master requests to be disabled, else IXGBE_SUCCESS
22956621Sbt150084  * is returned signifying master requests disabled.
22966621Sbt150084  */
22976621Sbt150084 s32
ixgbe_disable_pcie_master(struct ixgbe_hw * hw)22986621Sbt150084 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
22996621Sbt150084 {
23008490SPaul.Guo@Sun.COM 	u32 i;
23018490SPaul.Guo@Sun.COM 	u32 reg_val;
23028490SPaul.Guo@Sun.COM 	u32 number_of_queues;
230312003SPaul.Guo@Sun.COM 	s32 status = IXGBE_SUCCESS;
23046621Sbt150084 
230510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_disable_pcie_master");
230610998SChenlu.Chen@Sun.COM 
230712003SPaul.Guo@Sun.COM 	/* Just jump out if bus mastering is already disabled */
230812003SPaul.Guo@Sun.COM 	if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
230912003SPaul.Guo@Sun.COM 		goto out;
231012003SPaul.Guo@Sun.COM 
23118490SPaul.Guo@Sun.COM 	/* Disable the receive unit by stopping each queue */
23128490SPaul.Guo@Sun.COM 	number_of_queues = hw->mac.max_rx_queues;
23138490SPaul.Guo@Sun.COM 	for (i = 0; i < number_of_queues; i++) {
23148490SPaul.Guo@Sun.COM 		reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
23158490SPaul.Guo@Sun.COM 		if (reg_val & IXGBE_RXDCTL_ENABLE) {
23168490SPaul.Guo@Sun.COM 			reg_val &= ~IXGBE_RXDCTL_ENABLE;
23178490SPaul.Guo@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
23188490SPaul.Guo@Sun.COM 		}
23198490SPaul.Guo@Sun.COM 	}
23208490SPaul.Guo@Sun.COM 
23218490SPaul.Guo@Sun.COM 	reg_val = IXGBE_READ_REG(hw, IXGBE_CTRL);
23228490SPaul.Guo@Sun.COM 	reg_val |= IXGBE_CTRL_GIO_DIS;
23238490SPaul.Guo@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_CTRL, reg_val);
23246621Sbt150084 
23256621Sbt150084 	for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
232612003SPaul.Guo@Sun.COM 		if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
232712003SPaul.Guo@Sun.COM 			goto out;
23286621Sbt150084 		usec_delay(100);
23296621Sbt150084 	}
23306621Sbt150084 
233112003SPaul.Guo@Sun.COM 	DEBUGOUT("GIO Master Disable bit didn't clear - requesting resets\n");
233212003SPaul.Guo@Sun.COM 	status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
233312003SPaul.Guo@Sun.COM 
233412003SPaul.Guo@Sun.COM 	/*
233512003SPaul.Guo@Sun.COM 	 * The GIO Master Disable bit didn't clear.  There are multiple reasons
233612003SPaul.Guo@Sun.COM 	 * for this listed in the datasheet 5.2.5.3.2 Master Disable, and they
233712003SPaul.Guo@Sun.COM 	 * all require a double reset to recover from.  Before proceeding, we
233812003SPaul.Guo@Sun.COM 	 * first wait a little more to try to ensure that, at a minimum, the
233912003SPaul.Guo@Sun.COM 	 * PCIe block has no transactions pending.
234012003SPaul.Guo@Sun.COM 	 */
234112003SPaul.Guo@Sun.COM 	for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
234212003SPaul.Guo@Sun.COM 		if (!(IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS) &
234312003SPaul.Guo@Sun.COM 		    IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
234412003SPaul.Guo@Sun.COM 			break;
234512003SPaul.Guo@Sun.COM 		usec_delay(100);
234612003SPaul.Guo@Sun.COM 	}
234712003SPaul.Guo@Sun.COM 
234812003SPaul.Guo@Sun.COM 	if (i == IXGBE_PCI_MASTER_DISABLE_TIMEOUT)
234912003SPaul.Guo@Sun.COM 		DEBUGOUT("PCIe transaction pending bit also did not clear.\n");
235012003SPaul.Guo@Sun.COM 
235112003SPaul.Guo@Sun.COM 	/*
235212003SPaul.Guo@Sun.COM 	 * Two consecutive resets are required via CTRL.RST per datasheet
235312003SPaul.Guo@Sun.COM 	 * 5.2.5.3.2 Master Disable.  We set a flag to inform the reset routine
235412003SPaul.Guo@Sun.COM 	 * of this need.  The first reset prevents new master requests from
235512003SPaul.Guo@Sun.COM 	 * being issued by our device.  We then must wait 1usec for any
235612003SPaul.Guo@Sun.COM 	 * remaining completions from the PCIe bus to trickle in, and then reset
235712003SPaul.Guo@Sun.COM 	 * again to clear out any effects they may have had on our device.
235812003SPaul.Guo@Sun.COM 	 */
235912003SPaul.Guo@Sun.COM 	hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
236012003SPaul.Guo@Sun.COM 
236112003SPaul.Guo@Sun.COM out:
23626621Sbt150084 	return (status);
23636621Sbt150084 }
23646621Sbt150084 
23656621Sbt150084 /*
23666621Sbt150084  * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
23676621Sbt150084  * @hw: pointer to hardware structure
23686621Sbt150084  * @mask: Mask to specify which semaphore to acquire
23696621Sbt150084  *
23706621Sbt150084  * Acquires the SWFW semaphore thought the GSSR register for the specified
23716621Sbt150084  * function (CSR, PHY0, PHY1, EEPROM, Flash)
23726621Sbt150084  */
23736621Sbt150084 s32
ixgbe_acquire_swfw_sync(struct ixgbe_hw * hw,u16 mask)23746621Sbt150084 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
23756621Sbt150084 {
23766621Sbt150084 	u32 gssr;
23776621Sbt150084 	u32 swmask = mask;
23786621Sbt150084 	u32 fwmask = mask << 5;
23796621Sbt150084 	s32 timeout = 200;
23806621Sbt150084 
238110998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_acquire_swfw_sync");
238210998SChenlu.Chen@Sun.COM 
23836621Sbt150084 	while (timeout) {
23849353SSamuel.Tu@Sun.COM 		/*
23859353SSamuel.Tu@Sun.COM 		 * SW EEPROM semaphore bit is used for access to all
23869353SSamuel.Tu@Sun.COM 		 * SW_FW_SYNC/GSSR bits (not just EEPROM)
23879353SSamuel.Tu@Sun.COM 		 */
23886621Sbt150084 		if (ixgbe_get_eeprom_semaphore(hw))
238910998SChenlu.Chen@Sun.COM 			return (IXGBE_ERR_SWFW_SYNC);
23906621Sbt150084 
23916621Sbt150084 		gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
23926621Sbt150084 		if (!(gssr & (fwmask | swmask)))
23936621Sbt150084 			break;
23946621Sbt150084 
23956621Sbt150084 		/*
23966621Sbt150084 		 * Firmware currently using resource (fwmask) or other software
23976621Sbt150084 		 * thread currently using resource (swmask)
23986621Sbt150084 		 */
23996621Sbt150084 		ixgbe_release_eeprom_semaphore(hw);
24006621Sbt150084 		msec_delay(5);
24016621Sbt150084 		timeout--;
24026621Sbt150084 	}
24036621Sbt150084 
24046621Sbt150084 	if (!timeout) {
24059353SSamuel.Tu@Sun.COM 		DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
240610998SChenlu.Chen@Sun.COM 		return (IXGBE_ERR_SWFW_SYNC);
24076621Sbt150084 	}
24086621Sbt150084 
24096621Sbt150084 	gssr |= swmask;
24106621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
24116621Sbt150084 
24126621Sbt150084 	ixgbe_release_eeprom_semaphore(hw);
24136621Sbt150084 	return (IXGBE_SUCCESS);
24146621Sbt150084 }
24156621Sbt150084 
24166621Sbt150084 /*
24176621Sbt150084  * ixgbe_release_swfw_sync - Release SWFW semaphore
24186621Sbt150084  * @hw: pointer to hardware structure
24196621Sbt150084  * @mask: Mask to specify which semaphore to release
24206621Sbt150084  *
24216621Sbt150084  * Releases the SWFW semaphore thought the GSSR register for the specified
24226621Sbt150084  * function (CSR, PHY0, PHY1, EEPROM, Flash)
24236621Sbt150084  */
24246621Sbt150084 void
ixgbe_release_swfw_sync(struct ixgbe_hw * hw,u16 mask)24256621Sbt150084 ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
24266621Sbt150084 {
24276621Sbt150084 	u32 gssr;
24286621Sbt150084 	u32 swmask = mask;
24296621Sbt150084 
243010998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_release_swfw_sync");
243110998SChenlu.Chen@Sun.COM 
24326621Sbt150084 	(void) ixgbe_get_eeprom_semaphore(hw);
24336621Sbt150084 
24346621Sbt150084 	gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
24356621Sbt150084 	gssr &= ~swmask;
24366621Sbt150084 	IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
24376621Sbt150084 
24386621Sbt150084 	ixgbe_release_eeprom_semaphore(hw);
24396621Sbt150084 }
24409353SSamuel.Tu@Sun.COM 
24419353SSamuel.Tu@Sun.COM /*
24429353SSamuel.Tu@Sun.COM  * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
24439353SSamuel.Tu@Sun.COM  * @hw: pointer to hardware structure
24449353SSamuel.Tu@Sun.COM  * @regval: register value to write to RXCTRL
24459353SSamuel.Tu@Sun.COM  *
24469353SSamuel.Tu@Sun.COM  * Enables the Rx DMA unit
24479353SSamuel.Tu@Sun.COM  */
24489353SSamuel.Tu@Sun.COM s32
ixgbe_enable_rx_dma_generic(struct ixgbe_hw * hw,u32 regval)24499353SSamuel.Tu@Sun.COM ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
24509353SSamuel.Tu@Sun.COM {
245110998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_enable_rx_dma_generic");
245210998SChenlu.Chen@Sun.COM 
24539353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
24549353SSamuel.Tu@Sun.COM 
24559353SSamuel.Tu@Sun.COM 	return (IXGBE_SUCCESS);
24569353SSamuel.Tu@Sun.COM }
24579353SSamuel.Tu@Sun.COM 
24589353SSamuel.Tu@Sun.COM /*
24599353SSamuel.Tu@Sun.COM  * ixgbe_blink_led_start_generic - Blink LED based on index.
24609353SSamuel.Tu@Sun.COM  * @hw: pointer to hardware structure
24619353SSamuel.Tu@Sun.COM  * @index: led number to blink
24629353SSamuel.Tu@Sun.COM  */
24639353SSamuel.Tu@Sun.COM s32
ixgbe_blink_led_start_generic(struct ixgbe_hw * hw,u32 index)24649353SSamuel.Tu@Sun.COM ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
24659353SSamuel.Tu@Sun.COM {
24669353SSamuel.Tu@Sun.COM 	ixgbe_link_speed speed = 0;
24679353SSamuel.Tu@Sun.COM 	bool link_up = 0;
24689353SSamuel.Tu@Sun.COM 	u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
24699353SSamuel.Tu@Sun.COM 	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
24709353SSamuel.Tu@Sun.COM 
247110998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_blink_led_start_generic");
247210998SChenlu.Chen@Sun.COM 
24739353SSamuel.Tu@Sun.COM 	/*
24749353SSamuel.Tu@Sun.COM 	 * Link must be up to auto-blink the LEDs;
24759353SSamuel.Tu@Sun.COM 	 * Force it if link is down.
24769353SSamuel.Tu@Sun.COM 	 */
24779353SSamuel.Tu@Sun.COM 	hw->mac.ops.check_link(hw, &speed, &link_up, false);
24789353SSamuel.Tu@Sun.COM 
24799353SSamuel.Tu@Sun.COM 	if (!link_up) {
248010305SPaul.Guo@Sun.COM 		autoc_reg |= IXGBE_AUTOC_AN_RESTART;
24819353SSamuel.Tu@Sun.COM 		autoc_reg |= IXGBE_AUTOC_FLU;
24829353SSamuel.Tu@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
24839353SSamuel.Tu@Sun.COM 		msec_delay(10);
24849353SSamuel.Tu@Sun.COM 	}
24859353SSamuel.Tu@Sun.COM 
24869353SSamuel.Tu@Sun.COM 	led_reg &= ~IXGBE_LED_MODE_MASK(index);
24879353SSamuel.Tu@Sun.COM 	led_reg |= IXGBE_LED_BLINK(index);
24889353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
24899353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_FLUSH(hw);
24909353SSamuel.Tu@Sun.COM 
24919353SSamuel.Tu@Sun.COM 	return (IXGBE_SUCCESS);
24929353SSamuel.Tu@Sun.COM }
24939353SSamuel.Tu@Sun.COM 
24949353SSamuel.Tu@Sun.COM /*
24959353SSamuel.Tu@Sun.COM  * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
24969353SSamuel.Tu@Sun.COM  * @hw: pointer to hardware structure
24979353SSamuel.Tu@Sun.COM  * @index: led number to stop blinking
24989353SSamuel.Tu@Sun.COM  */
24999353SSamuel.Tu@Sun.COM s32
ixgbe_blink_led_stop_generic(struct ixgbe_hw * hw,u32 index)25009353SSamuel.Tu@Sun.COM ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
25019353SSamuel.Tu@Sun.COM {
25029353SSamuel.Tu@Sun.COM 	u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
25039353SSamuel.Tu@Sun.COM 	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
25049353SSamuel.Tu@Sun.COM 
250510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_blink_led_stop_generic");
250610998SChenlu.Chen@Sun.COM 
25079353SSamuel.Tu@Sun.COM 	autoc_reg &= ~IXGBE_AUTOC_FLU;
25089353SSamuel.Tu@Sun.COM 	autoc_reg |= IXGBE_AUTOC_AN_RESTART;
25099353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
25109353SSamuel.Tu@Sun.COM 
25119353SSamuel.Tu@Sun.COM 	led_reg &= ~IXGBE_LED_MODE_MASK(index);
25129353SSamuel.Tu@Sun.COM 	led_reg &= ~IXGBE_LED_BLINK(index);
25139353SSamuel.Tu@Sun.COM 	led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
25149353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
25159353SSamuel.Tu@Sun.COM 	IXGBE_WRITE_FLUSH(hw);
25169353SSamuel.Tu@Sun.COM 
25179353SSamuel.Tu@Sun.COM 	return (IXGBE_SUCCESS);
25189353SSamuel.Tu@Sun.COM }
251910998SChenlu.Chen@Sun.COM 
252010998SChenlu.Chen@Sun.COM /*
252110998SChenlu.Chen@Sun.COM  * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
252210998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
252310998SChenlu.Chen@Sun.COM  * @san_mac_offset: SAN MAC address offset
252410998SChenlu.Chen@Sun.COM  *
252510998SChenlu.Chen@Sun.COM  * This function will read the EEPROM location for the SAN MAC address
252610998SChenlu.Chen@Sun.COM  * pointer, and returns the value at that location.  This is used in both
252710998SChenlu.Chen@Sun.COM  * get and set mac_addr routines.
252810998SChenlu.Chen@Sun.COM  */
252910998SChenlu.Chen@Sun.COM static s32
ixgbe_get_san_mac_addr_offset(struct ixgbe_hw * hw,u16 * san_mac_offset)253010998SChenlu.Chen@Sun.COM ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw, u16 *san_mac_offset)
253110998SChenlu.Chen@Sun.COM {
253210998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_san_mac_addr_offset");
253310998SChenlu.Chen@Sun.COM 
253410998SChenlu.Chen@Sun.COM 	/*
253510998SChenlu.Chen@Sun.COM 	 * First read the EEPROM pointer to see if the MAC addresses are
253610998SChenlu.Chen@Sun.COM 	 * available.
253710998SChenlu.Chen@Sun.COM 	 */
253810998SChenlu.Chen@Sun.COM 	hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR, san_mac_offset);
253910998SChenlu.Chen@Sun.COM 
254010998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
254110998SChenlu.Chen@Sun.COM }
254210998SChenlu.Chen@Sun.COM 
254310998SChenlu.Chen@Sun.COM /*
254410998SChenlu.Chen@Sun.COM  * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
254510998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
254610998SChenlu.Chen@Sun.COM  * @san_mac_addr: SAN MAC address
254710998SChenlu.Chen@Sun.COM  *
254810998SChenlu.Chen@Sun.COM  * Reads the SAN MAC address from the EEPROM, if it's available.  This is
254910998SChenlu.Chen@Sun.COM  * per-port, so set_lan_id() must be called before reading the addresses.
255010998SChenlu.Chen@Sun.COM  * set_lan_id() is called by identify_sfp(), but this cannot be relied
255110998SChenlu.Chen@Sun.COM  * upon for non-SFP connections, so we must call it here.
255210998SChenlu.Chen@Sun.COM  */
255310998SChenlu.Chen@Sun.COM s32
ixgbe_get_san_mac_addr_generic(struct ixgbe_hw * hw,u8 * san_mac_addr)255410998SChenlu.Chen@Sun.COM ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
255510998SChenlu.Chen@Sun.COM {
255610998SChenlu.Chen@Sun.COM 	u16 san_mac_data, san_mac_offset;
255710998SChenlu.Chen@Sun.COM 	u8 i;
255810998SChenlu.Chen@Sun.COM 
255910998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_san_mac_addr_generic");
256010998SChenlu.Chen@Sun.COM 
256110998SChenlu.Chen@Sun.COM 	/*
256210998SChenlu.Chen@Sun.COM 	 * First read the EEPROM pointer to see if the MAC addresses are
256310998SChenlu.Chen@Sun.COM 	 * available.  If they're not, no point in calling set_lan_id() here.
256410998SChenlu.Chen@Sun.COM 	 */
256510998SChenlu.Chen@Sun.COM 	(void) ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
256610998SChenlu.Chen@Sun.COM 
256710998SChenlu.Chen@Sun.COM 	if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
256810998SChenlu.Chen@Sun.COM 		/*
256910998SChenlu.Chen@Sun.COM 		 * No addresses available in this EEPROM.  It's not an
257010998SChenlu.Chen@Sun.COM 		 * error though, so just wipe the local address and return.
257110998SChenlu.Chen@Sun.COM 		 */
257210998SChenlu.Chen@Sun.COM 		for (i = 0; i < 6; i++)
257310998SChenlu.Chen@Sun.COM 			san_mac_addr[i] = 0xFF;
257410998SChenlu.Chen@Sun.COM 
257510998SChenlu.Chen@Sun.COM 		goto san_mac_addr_out;
257610998SChenlu.Chen@Sun.COM 	}
257710998SChenlu.Chen@Sun.COM 
257810998SChenlu.Chen@Sun.COM 	/* make sure we know which port we need to program */
257910998SChenlu.Chen@Sun.COM 	hw->mac.ops.set_lan_id(hw);
258010998SChenlu.Chen@Sun.COM 	/* apply the port offset to the address offset */
258110998SChenlu.Chen@Sun.COM 	(hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
258210998SChenlu.Chen@Sun.COM 	    (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
258310998SChenlu.Chen@Sun.COM 	for (i = 0; i < 3; i++) {
258410998SChenlu.Chen@Sun.COM 		hw->eeprom.ops.read(hw, san_mac_offset, &san_mac_data);
258510998SChenlu.Chen@Sun.COM 		san_mac_addr[i * 2] = (u8)(san_mac_data);
258610998SChenlu.Chen@Sun.COM 		san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
258710998SChenlu.Chen@Sun.COM 		san_mac_offset++;
258810998SChenlu.Chen@Sun.COM 	}
258910998SChenlu.Chen@Sun.COM 
259010998SChenlu.Chen@Sun.COM san_mac_addr_out:
259110998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
259210998SChenlu.Chen@Sun.COM }
259310998SChenlu.Chen@Sun.COM 
259410998SChenlu.Chen@Sun.COM /*
259510998SChenlu.Chen@Sun.COM  * ixgbe_set_san_mac_addr_generic - Write the SAN MAC address to the EEPROM
259610998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
259710998SChenlu.Chen@Sun.COM  * @san_mac_addr: SAN MAC address
259810998SChenlu.Chen@Sun.COM  *
259910998SChenlu.Chen@Sun.COM  * Write a SAN MAC address to the EEPROM.
260010998SChenlu.Chen@Sun.COM  */
260110998SChenlu.Chen@Sun.COM s32
ixgbe_set_san_mac_addr_generic(struct ixgbe_hw * hw,u8 * san_mac_addr)260210998SChenlu.Chen@Sun.COM ixgbe_set_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
260310998SChenlu.Chen@Sun.COM {
260410998SChenlu.Chen@Sun.COM 	s32 status = IXGBE_SUCCESS;
260510998SChenlu.Chen@Sun.COM 	u16 san_mac_data, san_mac_offset;
260610998SChenlu.Chen@Sun.COM 	u8 i;
260710998SChenlu.Chen@Sun.COM 
260810998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_set_san_mac_addr_generic");
260910998SChenlu.Chen@Sun.COM 
261010998SChenlu.Chen@Sun.COM 	/* Look for SAN mac address pointer.  If not defined, return */
261110998SChenlu.Chen@Sun.COM 	(void) ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
261210998SChenlu.Chen@Sun.COM 
261310998SChenlu.Chen@Sun.COM 	if ((san_mac_offset == 0) || (san_mac_offset == 0xFFFF)) {
261410998SChenlu.Chen@Sun.COM 		status = IXGBE_ERR_NO_SAN_ADDR_PTR;
261510998SChenlu.Chen@Sun.COM 		goto san_mac_addr_out;
261610998SChenlu.Chen@Sun.COM 	}
261710998SChenlu.Chen@Sun.COM 
261810998SChenlu.Chen@Sun.COM 	/* Make sure we know which port we need to write */
261910998SChenlu.Chen@Sun.COM 	hw->mac.ops.set_lan_id(hw);
262010998SChenlu.Chen@Sun.COM 	/* Apply the port offset to the address offset */
262110998SChenlu.Chen@Sun.COM 	(hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
262210998SChenlu.Chen@Sun.COM 	    (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
262310998SChenlu.Chen@Sun.COM 
262410998SChenlu.Chen@Sun.COM 	for (i = 0; i < 3; i++) {
262510998SChenlu.Chen@Sun.COM 		san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
262610998SChenlu.Chen@Sun.COM 		san_mac_data |= (u16)(san_mac_addr[i * 2]);
262710998SChenlu.Chen@Sun.COM 		hw->eeprom.ops.write(hw, san_mac_offset, san_mac_data);
262810998SChenlu.Chen@Sun.COM 		san_mac_offset++;
262910998SChenlu.Chen@Sun.COM 	}
263010998SChenlu.Chen@Sun.COM 
263110998SChenlu.Chen@Sun.COM san_mac_addr_out:
263210998SChenlu.Chen@Sun.COM 	return (status);
263310998SChenlu.Chen@Sun.COM }
263410998SChenlu.Chen@Sun.COM 
263510998SChenlu.Chen@Sun.COM /*
263610998SChenlu.Chen@Sun.COM  * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
263710998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
263810998SChenlu.Chen@Sun.COM  *
263910998SChenlu.Chen@Sun.COM  * Read PCIe configuration space, and get the MSI-X vector count from
264010998SChenlu.Chen@Sun.COM  * the capabilities table.
264110998SChenlu.Chen@Sun.COM  */
264210998SChenlu.Chen@Sun.COM u32
ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw * hw)264310998SChenlu.Chen@Sun.COM ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
264410998SChenlu.Chen@Sun.COM {
264510998SChenlu.Chen@Sun.COM 	u32 msix_count = 64;
264610998SChenlu.Chen@Sun.COM 
264710998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_pcie_msix_count_generic");
264810998SChenlu.Chen@Sun.COM 	if (hw->mac.msix_vectors_from_pcie) {
264910998SChenlu.Chen@Sun.COM 		msix_count = IXGBE_READ_PCIE_WORD(hw,
265010998SChenlu.Chen@Sun.COM 		    IXGBE_PCIE_MSIX_82599_CAPS);
265110998SChenlu.Chen@Sun.COM 		msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
265210998SChenlu.Chen@Sun.COM 
265310998SChenlu.Chen@Sun.COM 		/*
265410998SChenlu.Chen@Sun.COM 		 * MSI-X count is zero-based in HW, so increment to give
265510998SChenlu.Chen@Sun.COM 		 * proper value.
265610998SChenlu.Chen@Sun.COM 		 */
265710998SChenlu.Chen@Sun.COM 		msix_count++;
265810998SChenlu.Chen@Sun.COM 	}
265910998SChenlu.Chen@Sun.COM 
266010998SChenlu.Chen@Sun.COM 	return (msix_count);
266110998SChenlu.Chen@Sun.COM }
266210998SChenlu.Chen@Sun.COM 
266310998SChenlu.Chen@Sun.COM /*
266410998SChenlu.Chen@Sun.COM  * ixgbe_insert_mac_addr_generic - Find a RAR for this mac address
266510998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
266610998SChenlu.Chen@Sun.COM  * @addr: Address to put into receive address register
266710998SChenlu.Chen@Sun.COM  * @vmdq: VMDq pool to assign
266810998SChenlu.Chen@Sun.COM  *
266910998SChenlu.Chen@Sun.COM  * Puts an ethernet address into a receive address register, or
267010998SChenlu.Chen@Sun.COM  * finds the rar that it is aleady in; adds to the pool list
267110998SChenlu.Chen@Sun.COM  */
267210998SChenlu.Chen@Sun.COM s32
ixgbe_insert_mac_addr_generic(struct ixgbe_hw * hw,u8 * addr,u32 vmdq)267310998SChenlu.Chen@Sun.COM ixgbe_insert_mac_addr_generic(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
267410998SChenlu.Chen@Sun.COM {
267510998SChenlu.Chen@Sun.COM 	static const u32 NO_EMPTY_RAR_FOUND = 0xFFFFFFFF;
267610998SChenlu.Chen@Sun.COM 	u32 first_empty_rar = NO_EMPTY_RAR_FOUND;
267710998SChenlu.Chen@Sun.COM 	u32 rar;
267810998SChenlu.Chen@Sun.COM 	u32 rar_low, rar_high;
267910998SChenlu.Chen@Sun.COM 	u32 addr_low, addr_high;
268010998SChenlu.Chen@Sun.COM 
268110998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_insert_mac_addr_generic");
268210998SChenlu.Chen@Sun.COM 
268310998SChenlu.Chen@Sun.COM 	/* swap bytes for HW little endian */
268410998SChenlu.Chen@Sun.COM 	addr_low  = addr[0] | (addr[1] << 8)
268510998SChenlu.Chen@Sun.COM 	    | (addr[2] << 16)
268610998SChenlu.Chen@Sun.COM 	    | (addr[3] << 24);
268710998SChenlu.Chen@Sun.COM 	addr_high = addr[4] | (addr[5] << 8);
268810998SChenlu.Chen@Sun.COM 
268910998SChenlu.Chen@Sun.COM 	/*
269010998SChenlu.Chen@Sun.COM 	 * Either find the mac_id in rar or find the first empty space.
269110998SChenlu.Chen@Sun.COM 	 * rar_highwater points to just after the highest currently used
269210998SChenlu.Chen@Sun.COM 	 * rar in order to shorten the search.  It grows when we add a new
269310998SChenlu.Chen@Sun.COM 	 * rar to the top.
269410998SChenlu.Chen@Sun.COM 	 */
269510998SChenlu.Chen@Sun.COM 	for (rar = 0; rar < hw->mac.rar_highwater; rar++) {
269610998SChenlu.Chen@Sun.COM 		rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
269710998SChenlu.Chen@Sun.COM 
269810998SChenlu.Chen@Sun.COM 		if (((IXGBE_RAH_AV & rar_high) == 0) &&
269910998SChenlu.Chen@Sun.COM 		    first_empty_rar == NO_EMPTY_RAR_FOUND) {
270010998SChenlu.Chen@Sun.COM 			first_empty_rar = rar;
270110998SChenlu.Chen@Sun.COM 		} else if ((rar_high & 0xFFFF) == addr_high) {
270210998SChenlu.Chen@Sun.COM 			rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(rar));
270310998SChenlu.Chen@Sun.COM 			if (rar_low == addr_low)
270410998SChenlu.Chen@Sun.COM 				break;    /* found it already in the rars */
270510998SChenlu.Chen@Sun.COM 		}
270610998SChenlu.Chen@Sun.COM 	}
270710998SChenlu.Chen@Sun.COM 
270810998SChenlu.Chen@Sun.COM 	if (rar < hw->mac.rar_highwater) {
270910998SChenlu.Chen@Sun.COM 		/* already there so just add to the pool bits */
271010998SChenlu.Chen@Sun.COM 		(void) ixgbe_set_vmdq(hw, rar, vmdq);
271110998SChenlu.Chen@Sun.COM 	} else if (first_empty_rar != NO_EMPTY_RAR_FOUND) {
271210998SChenlu.Chen@Sun.COM 		/* stick it into first empty RAR slot we found */
271310998SChenlu.Chen@Sun.COM 		rar = first_empty_rar;
271410998SChenlu.Chen@Sun.COM 		(void) ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
271510998SChenlu.Chen@Sun.COM 	} else if (rar == hw->mac.rar_highwater) {
271610998SChenlu.Chen@Sun.COM 		/* add it to the top of the list and inc the highwater mark */
271710998SChenlu.Chen@Sun.COM 		(void) ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
271810998SChenlu.Chen@Sun.COM 		hw->mac.rar_highwater++;
271910998SChenlu.Chen@Sun.COM 	} else if (rar >= hw->mac.num_rar_entries) {
272010998SChenlu.Chen@Sun.COM 		return (IXGBE_ERR_INVALID_MAC_ADDR);
272110998SChenlu.Chen@Sun.COM 	}
272210998SChenlu.Chen@Sun.COM 
272310998SChenlu.Chen@Sun.COM 	/*
272410998SChenlu.Chen@Sun.COM 	 * If we found rar[0], make sure the default pool bit (we use pool 0)
272510998SChenlu.Chen@Sun.COM 	 * remains cleared to be sure default pool packets will get delivered
272610998SChenlu.Chen@Sun.COM 	 */
272710998SChenlu.Chen@Sun.COM 	if (rar == 0)
272810998SChenlu.Chen@Sun.COM 		(void) ixgbe_clear_vmdq(hw, rar, 0);
272910998SChenlu.Chen@Sun.COM 
273010998SChenlu.Chen@Sun.COM 	return (rar);
273110998SChenlu.Chen@Sun.COM }
273210998SChenlu.Chen@Sun.COM 
273310998SChenlu.Chen@Sun.COM /*
273410998SChenlu.Chen@Sun.COM  * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
273510998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware struct
273610998SChenlu.Chen@Sun.COM  * @rar: receive address register index to disassociate
273710998SChenlu.Chen@Sun.COM  * @vmdq: VMDq pool index to remove from the rar
273810998SChenlu.Chen@Sun.COM  */
273910998SChenlu.Chen@Sun.COM s32
ixgbe_clear_vmdq_generic(struct ixgbe_hw * hw,u32 rar,u32 vmdq)274010998SChenlu.Chen@Sun.COM ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
274110998SChenlu.Chen@Sun.COM {
274210998SChenlu.Chen@Sun.COM 	u32 mpsar_lo, mpsar_hi;
274310998SChenlu.Chen@Sun.COM 	u32 rar_entries = hw->mac.num_rar_entries;
274410998SChenlu.Chen@Sun.COM 
274510998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_clear_vmdq_generic");
274610998SChenlu.Chen@Sun.COM 
274710998SChenlu.Chen@Sun.COM 	if (rar < rar_entries) {
274810998SChenlu.Chen@Sun.COM 		mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
274910998SChenlu.Chen@Sun.COM 		mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
275010998SChenlu.Chen@Sun.COM 
275110998SChenlu.Chen@Sun.COM 		if (!mpsar_lo && !mpsar_hi)
275210998SChenlu.Chen@Sun.COM 			goto done;
275310998SChenlu.Chen@Sun.COM 
275410998SChenlu.Chen@Sun.COM 		if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
275510998SChenlu.Chen@Sun.COM 			if (mpsar_lo) {
275610998SChenlu.Chen@Sun.COM 				IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
275710998SChenlu.Chen@Sun.COM 				mpsar_lo = 0;
275810998SChenlu.Chen@Sun.COM 			}
275910998SChenlu.Chen@Sun.COM 			if (mpsar_hi) {
276010998SChenlu.Chen@Sun.COM 				IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
276110998SChenlu.Chen@Sun.COM 				mpsar_hi = 0;
276210998SChenlu.Chen@Sun.COM 			}
276310998SChenlu.Chen@Sun.COM 		} else if (vmdq < 32) {
276410998SChenlu.Chen@Sun.COM 			mpsar_lo &= ~(1 << vmdq);
276510998SChenlu.Chen@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
276610998SChenlu.Chen@Sun.COM 		} else {
276710998SChenlu.Chen@Sun.COM 			mpsar_hi &= ~(1 << (vmdq - 32));
276810998SChenlu.Chen@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
276910998SChenlu.Chen@Sun.COM 		}
277010998SChenlu.Chen@Sun.COM 
277110998SChenlu.Chen@Sun.COM 		/* was that the last pool using this rar? */
277210998SChenlu.Chen@Sun.COM 		if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
277310998SChenlu.Chen@Sun.COM 			hw->mac.ops.clear_rar(hw, rar);
277410998SChenlu.Chen@Sun.COM 	} else {
277510998SChenlu.Chen@Sun.COM 		DEBUGOUT1("RAR index %d is out of range.\n", rar);
277610998SChenlu.Chen@Sun.COM 	}
277710998SChenlu.Chen@Sun.COM 
277810998SChenlu.Chen@Sun.COM done:
277910998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
278010998SChenlu.Chen@Sun.COM }
278110998SChenlu.Chen@Sun.COM 
278210998SChenlu.Chen@Sun.COM /*
278310998SChenlu.Chen@Sun.COM  * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
278410998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware struct
278510998SChenlu.Chen@Sun.COM  * @rar: receive address register index to associate with a VMDq index
278610998SChenlu.Chen@Sun.COM  * @vmdq: VMDq pool index
278710998SChenlu.Chen@Sun.COM  */
278810998SChenlu.Chen@Sun.COM s32
ixgbe_set_vmdq_generic(struct ixgbe_hw * hw,u32 rar,u32 vmdq)278910998SChenlu.Chen@Sun.COM ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
279010998SChenlu.Chen@Sun.COM {
279110998SChenlu.Chen@Sun.COM 	u32 mpsar;
279210998SChenlu.Chen@Sun.COM 	u32 rar_entries = hw->mac.num_rar_entries;
279310998SChenlu.Chen@Sun.COM 
279410998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_set_vmdq_generic");
279510998SChenlu.Chen@Sun.COM 
279610998SChenlu.Chen@Sun.COM 	if (rar < rar_entries) {
279710998SChenlu.Chen@Sun.COM 		if (vmdq < 32) {
279810998SChenlu.Chen@Sun.COM 			mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
279910998SChenlu.Chen@Sun.COM 			mpsar |= 1 << vmdq;
280010998SChenlu.Chen@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
280110998SChenlu.Chen@Sun.COM 		} else {
280210998SChenlu.Chen@Sun.COM 			mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
280310998SChenlu.Chen@Sun.COM 			mpsar |= 1 << (vmdq - 32);
280410998SChenlu.Chen@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
280510998SChenlu.Chen@Sun.COM 		}
280610998SChenlu.Chen@Sun.COM 	} else {
280710998SChenlu.Chen@Sun.COM 		DEBUGOUT1("RAR index %d is out of range.\n", rar);
280810998SChenlu.Chen@Sun.COM 	}
280910998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
281010998SChenlu.Chen@Sun.COM }
281110998SChenlu.Chen@Sun.COM 
281210998SChenlu.Chen@Sun.COM /*
281310998SChenlu.Chen@Sun.COM  * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
281410998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
281510998SChenlu.Chen@Sun.COM  */
281610998SChenlu.Chen@Sun.COM s32
ixgbe_init_uta_tables_generic(struct ixgbe_hw * hw)281710998SChenlu.Chen@Sun.COM ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
281810998SChenlu.Chen@Sun.COM {
281910998SChenlu.Chen@Sun.COM 	int i;
282010998SChenlu.Chen@Sun.COM 
282110998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_init_uta_tables_generic");
282210998SChenlu.Chen@Sun.COM 	DEBUGOUT(" Clearing UTA\n");
282310998SChenlu.Chen@Sun.COM 
282410998SChenlu.Chen@Sun.COM 	for (i = 0; i < 128; i++)
282510998SChenlu.Chen@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
282610998SChenlu.Chen@Sun.COM 
282710998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
282810998SChenlu.Chen@Sun.COM }
282910998SChenlu.Chen@Sun.COM 
283010998SChenlu.Chen@Sun.COM /*
283110998SChenlu.Chen@Sun.COM  * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
283210998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
283310998SChenlu.Chen@Sun.COM  * @vlan: VLAN id to write to VLAN filter
283410998SChenlu.Chen@Sun.COM  *
283510998SChenlu.Chen@Sun.COM  * return the VLVF index where this VLAN id should be placed
283610998SChenlu.Chen@Sun.COM  *
283710998SChenlu.Chen@Sun.COM  */
283810998SChenlu.Chen@Sun.COM s32
ixgbe_find_vlvf_slot(struct ixgbe_hw * hw,u32 vlan)283910998SChenlu.Chen@Sun.COM ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
284010998SChenlu.Chen@Sun.COM {
284110998SChenlu.Chen@Sun.COM 	u32 bits = 0;
284210998SChenlu.Chen@Sun.COM 	u32 first_empty_slot = 0;
284310998SChenlu.Chen@Sun.COM 	s32 regindex;
284410998SChenlu.Chen@Sun.COM 
284512003SPaul.Guo@Sun.COM 	/* short cut the special case */
284612003SPaul.Guo@Sun.COM 	if (vlan == 0)
284712003SPaul.Guo@Sun.COM 		return (0);
284812003SPaul.Guo@Sun.COM 
284910998SChenlu.Chen@Sun.COM 	/*
285010998SChenlu.Chen@Sun.COM 	 * Search for the vlan id in the VLVF entries. Save off the first empty
285110998SChenlu.Chen@Sun.COM 	 * slot found along the way
285210998SChenlu.Chen@Sun.COM 	 */
285310998SChenlu.Chen@Sun.COM 	for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
285410998SChenlu.Chen@Sun.COM 		bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
285510998SChenlu.Chen@Sun.COM 		if (!bits && !(first_empty_slot))
285610998SChenlu.Chen@Sun.COM 			first_empty_slot = regindex;
285710998SChenlu.Chen@Sun.COM 		else if ((bits & 0x0FFF) == vlan)
285810998SChenlu.Chen@Sun.COM 			break;
285910998SChenlu.Chen@Sun.COM 	}
286010998SChenlu.Chen@Sun.COM 
286110998SChenlu.Chen@Sun.COM 	/*
286210998SChenlu.Chen@Sun.COM 	 * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
286310998SChenlu.Chen@Sun.COM 	 * in the VLVF. Else use the first empty VLVF register for this
286410998SChenlu.Chen@Sun.COM 	 * vlan id.
286510998SChenlu.Chen@Sun.COM 	 */
286610998SChenlu.Chen@Sun.COM 	if (regindex >= IXGBE_VLVF_ENTRIES) {
286710998SChenlu.Chen@Sun.COM 		if (first_empty_slot)
286810998SChenlu.Chen@Sun.COM 			regindex = first_empty_slot;
286910998SChenlu.Chen@Sun.COM 		else {
287010998SChenlu.Chen@Sun.COM 			DEBUGOUT("No space in VLVF.\n");
287112003SPaul.Guo@Sun.COM 			regindex = IXGBE_ERR_NO_SPACE;
287210998SChenlu.Chen@Sun.COM 		}
287310998SChenlu.Chen@Sun.COM 	}
287410998SChenlu.Chen@Sun.COM 
287510998SChenlu.Chen@Sun.COM 	return (regindex);
287610998SChenlu.Chen@Sun.COM }
287710998SChenlu.Chen@Sun.COM 
287810998SChenlu.Chen@Sun.COM /*
287910998SChenlu.Chen@Sun.COM  * ixgbe_set_vfta_generic - Set VLAN filter table
288010998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
288110998SChenlu.Chen@Sun.COM  * @vlan: VLAN id to write to VLAN filter
288210998SChenlu.Chen@Sun.COM  * @vind: VMDq output index that maps queue to VLAN id in VFVFB
288310998SChenlu.Chen@Sun.COM  * @vlan_on: boolean flag to turn on/off VLAN in VFVF
288410998SChenlu.Chen@Sun.COM  *
288510998SChenlu.Chen@Sun.COM  * Turn on/off specified VLAN in the VLAN filter table.
288610998SChenlu.Chen@Sun.COM  */
288710998SChenlu.Chen@Sun.COM s32
ixgbe_set_vfta_generic(struct ixgbe_hw * hw,u32 vlan,u32 vind,bool vlan_on)288810998SChenlu.Chen@Sun.COM ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind, bool vlan_on)
288910998SChenlu.Chen@Sun.COM {
289010998SChenlu.Chen@Sun.COM 	s32 regindex;
289110998SChenlu.Chen@Sun.COM 	u32 bitindex;
289212003SPaul.Guo@Sun.COM 	u32 vfta;
289310998SChenlu.Chen@Sun.COM 	u32 bits;
289410998SChenlu.Chen@Sun.COM 	u32 vt;
289512003SPaul.Guo@Sun.COM 	u32 targetbit;
289612003SPaul.Guo@Sun.COM 	bool vfta_changed = false;
289710998SChenlu.Chen@Sun.COM 
289810998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_set_vfta_generic");
289910998SChenlu.Chen@Sun.COM 
290010998SChenlu.Chen@Sun.COM 	if (vlan > 4095)
290110998SChenlu.Chen@Sun.COM 		return (IXGBE_ERR_PARAM);
290210998SChenlu.Chen@Sun.COM 
290310998SChenlu.Chen@Sun.COM 	/*
290410998SChenlu.Chen@Sun.COM 	 * this is a 2 part operation - first the VFTA, then the
290510998SChenlu.Chen@Sun.COM 	 * VLVF and VLVFB if VT Mode is set
290612003SPaul.Guo@Sun.COM 	 * We don't write the VFTA until we know the VLVF part succeeded.
290710998SChenlu.Chen@Sun.COM 	 */
290810998SChenlu.Chen@Sun.COM 
290910998SChenlu.Chen@Sun.COM 	/*
291010998SChenlu.Chen@Sun.COM 	 * Part 1
291110998SChenlu.Chen@Sun.COM 	 * The VFTA is a bitstring made up of 128 32-bit registers
291210998SChenlu.Chen@Sun.COM 	 * that enable the particular VLAN id, much like the MTA:
291310998SChenlu.Chen@Sun.COM 	 *    bits[11-5]: which register
291410998SChenlu.Chen@Sun.COM 	 *    bits[4-0]:  which bit in the register
291510998SChenlu.Chen@Sun.COM 	 */
291610998SChenlu.Chen@Sun.COM 	regindex = (vlan >> 5) & 0x7F;
291710998SChenlu.Chen@Sun.COM 	bitindex = vlan & 0x1F;
291812003SPaul.Guo@Sun.COM 	targetbit = (1 << bitindex);
291912003SPaul.Guo@Sun.COM 	vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
292012003SPaul.Guo@Sun.COM 
292112003SPaul.Guo@Sun.COM 	if (vlan_on) {
292212003SPaul.Guo@Sun.COM 		if (!(vfta & targetbit)) {
292312003SPaul.Guo@Sun.COM 			vfta |= targetbit;
292412003SPaul.Guo@Sun.COM 			vfta_changed = true;
292512003SPaul.Guo@Sun.COM 		}
292612003SPaul.Guo@Sun.COM 	} else {
292712003SPaul.Guo@Sun.COM 		if ((vfta & targetbit)) {
292812003SPaul.Guo@Sun.COM 			vfta &= ~targetbit;
292912003SPaul.Guo@Sun.COM 			vfta_changed = true;
293012003SPaul.Guo@Sun.COM 		}
293112003SPaul.Guo@Sun.COM 	}
293210998SChenlu.Chen@Sun.COM 
293310998SChenlu.Chen@Sun.COM 
293410998SChenlu.Chen@Sun.COM 	/*
293510998SChenlu.Chen@Sun.COM 	 * Part 2
293610998SChenlu.Chen@Sun.COM 	 * If VT Mode is set
293710998SChenlu.Chen@Sun.COM 	 *  Either vlan_on
293810998SChenlu.Chen@Sun.COM 	 *   make sure the vlan is in VLVF
293910998SChenlu.Chen@Sun.COM 	 *   set the vind bit in the matching VLVFB
294010998SChenlu.Chen@Sun.COM 	 *  Or !vlan_on
294110998SChenlu.Chen@Sun.COM 	 *   clear the pool bit and possibly the vind
294210998SChenlu.Chen@Sun.COM 	 */
294310998SChenlu.Chen@Sun.COM 	vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
294410998SChenlu.Chen@Sun.COM 	if (vt & IXGBE_VT_CTL_VT_ENABLE) {
294512003SPaul.Guo@Sun.COM 		s32 vlvf_index;
294612003SPaul.Guo@Sun.COM 
294712003SPaul.Guo@Sun.COM 		vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
294812003SPaul.Guo@Sun.COM 		if (vlvf_index < 0)
294912003SPaul.Guo@Sun.COM 			return (vlvf_index);
295010998SChenlu.Chen@Sun.COM 
295110998SChenlu.Chen@Sun.COM 		if (vlan_on) {
295210998SChenlu.Chen@Sun.COM 			/* set the pool bit */
295310998SChenlu.Chen@Sun.COM 			if (vind < 32) {
295410998SChenlu.Chen@Sun.COM 				bits = IXGBE_READ_REG(hw,
295512003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB(vlvf_index * 2));
295610998SChenlu.Chen@Sun.COM 				bits |= (1 << vind);
295710998SChenlu.Chen@Sun.COM 				IXGBE_WRITE_REG(hw,
295812003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB(vlvf_index * 2),
295910998SChenlu.Chen@Sun.COM 				    bits);
296010998SChenlu.Chen@Sun.COM 			} else {
296110998SChenlu.Chen@Sun.COM 				bits = IXGBE_READ_REG(hw,
296212003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB((vlvf_index * 2) + 1));
296312003SPaul.Guo@Sun.COM 				bits |= (1 << (vind - 32));
296410998SChenlu.Chen@Sun.COM 				IXGBE_WRITE_REG(hw,
296512003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB((vlvf_index * 2) + 1),
296610998SChenlu.Chen@Sun.COM 				    bits);
296710998SChenlu.Chen@Sun.COM 			}
296810998SChenlu.Chen@Sun.COM 		} else {
296910998SChenlu.Chen@Sun.COM 			/* clear the pool bit */
297010998SChenlu.Chen@Sun.COM 			if (vind < 32) {
297110998SChenlu.Chen@Sun.COM 				bits = IXGBE_READ_REG(hw,
297212003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB(vlvf_index * 2));
297310998SChenlu.Chen@Sun.COM 				bits &= ~(1 << vind);
297410998SChenlu.Chen@Sun.COM 				IXGBE_WRITE_REG(hw,
297512003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB(vlvf_index * 2),
297610998SChenlu.Chen@Sun.COM 				    bits);
297710998SChenlu.Chen@Sun.COM 				bits |= IXGBE_READ_REG(hw,
297812003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB((vlvf_index * 2) + 1));
297912003SPaul.Guo@Sun.COM 			} else {
298012003SPaul.Guo@Sun.COM 				bits = IXGBE_READ_REG(hw,
298112003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB((vlvf_index * 2) + 1));
298212003SPaul.Guo@Sun.COM 				bits &= ~(1 << (vind - 32));
298312003SPaul.Guo@Sun.COM 				IXGBE_WRITE_REG(hw,
298412003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB((vlvf_index * 2) + 1),
298512003SPaul.Guo@Sun.COM 				    bits);
298612003SPaul.Guo@Sun.COM 				bits |= IXGBE_READ_REG(hw,
298712003SPaul.Guo@Sun.COM 				    IXGBE_VLVFB(vlvf_index * 2));
298810998SChenlu.Chen@Sun.COM 			}
298910998SChenlu.Chen@Sun.COM 		}
299010998SChenlu.Chen@Sun.COM 
299112003SPaul.Guo@Sun.COM 		/*
299212003SPaul.Guo@Sun.COM 		 * If there are still bits set in the VLVFB registers
299312003SPaul.Guo@Sun.COM 		 * for the VLAN ID indicated we need to see if the
299412003SPaul.Guo@Sun.COM 		 * caller is requesting that we clear the VFTA entry bit.
299512003SPaul.Guo@Sun.COM 		 * If the caller has requested that we clear the VFTA
299612003SPaul.Guo@Sun.COM 		 * entry bit but there are still pools/VFs using this VLAN
299712003SPaul.Guo@Sun.COM 		 * ID entry then ignore the request.  We're not worried
299812003SPaul.Guo@Sun.COM 		 * about the case where we're turning the VFTA VLAN ID
299912003SPaul.Guo@Sun.COM 		 * entry bit on, only when requested to turn it off as
300012003SPaul.Guo@Sun.COM 		 * there may be multiple pools and/or VFs using the
300112003SPaul.Guo@Sun.COM 		 * VLAN ID entry.  In that case we cannot clear the
300212003SPaul.Guo@Sun.COM 		 * VFTA bit until all pools/VFs using that VLAN ID have also
300312003SPaul.Guo@Sun.COM 		 * been cleared.  This will be indicated by "bits" being
300412003SPaul.Guo@Sun.COM 		 * zero.
300512003SPaul.Guo@Sun.COM 		 */
300612003SPaul.Guo@Sun.COM 		if (bits) {
300712003SPaul.Guo@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
300810998SChenlu.Chen@Sun.COM 			    (IXGBE_VLVF_VIEN | vlan));
300912003SPaul.Guo@Sun.COM 			if (!vlan_on) {
301012003SPaul.Guo@Sun.COM 				/*
301112003SPaul.Guo@Sun.COM 				 * someone wants to clear the vfta entry
301212003SPaul.Guo@Sun.COM 				 * but some pools/VFs are still using it.
301312003SPaul.Guo@Sun.COM 				 * Ignore it.
301412003SPaul.Guo@Sun.COM 				 */
301512003SPaul.Guo@Sun.COM 				vfta_changed = false;
301612003SPaul.Guo@Sun.COM 			}
301712003SPaul.Guo@Sun.COM 		} else {
301812003SPaul.Guo@Sun.COM 			IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
301912003SPaul.Guo@Sun.COM 		}
302010998SChenlu.Chen@Sun.COM 	}
302112003SPaul.Guo@Sun.COM 
302212003SPaul.Guo@Sun.COM 	if (vfta_changed)
302312003SPaul.Guo@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
302412003SPaul.Guo@Sun.COM 
302510998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
302610998SChenlu.Chen@Sun.COM }
302710998SChenlu.Chen@Sun.COM 
302810998SChenlu.Chen@Sun.COM /*
302910998SChenlu.Chen@Sun.COM  * ixgbe_clear_vfta_generic - Clear VLAN filter table
303010998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
303110998SChenlu.Chen@Sun.COM  *
303210998SChenlu.Chen@Sun.COM  * Clears the VLAN filer table, and the VMDq index associated with the filter
303310998SChenlu.Chen@Sun.COM  */
303410998SChenlu.Chen@Sun.COM s32
ixgbe_clear_vfta_generic(struct ixgbe_hw * hw)303510998SChenlu.Chen@Sun.COM ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
303610998SChenlu.Chen@Sun.COM {
303710998SChenlu.Chen@Sun.COM 	u32 offset;
303810998SChenlu.Chen@Sun.COM 
303910998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_clear_vfta_generic");
304010998SChenlu.Chen@Sun.COM 
304110998SChenlu.Chen@Sun.COM 	for (offset = 0; offset < hw->mac.vft_size; offset++)
304210998SChenlu.Chen@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
304310998SChenlu.Chen@Sun.COM 
304410998SChenlu.Chen@Sun.COM 	for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
304510998SChenlu.Chen@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
304610998SChenlu.Chen@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset*2), 0);
304710998SChenlu.Chen@Sun.COM 		IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset*2)+1), 0);
304810998SChenlu.Chen@Sun.COM 	}
304910998SChenlu.Chen@Sun.COM 
305010998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
305110998SChenlu.Chen@Sun.COM }
305210998SChenlu.Chen@Sun.COM 
305310998SChenlu.Chen@Sun.COM /*
305410998SChenlu.Chen@Sun.COM  * ixgbe_check_mac_link_generic - Determine link and speed status
305510998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
305610998SChenlu.Chen@Sun.COM  * @speed: pointer to link speed
305710998SChenlu.Chen@Sun.COM  * @link_up: true when link is up
305810998SChenlu.Chen@Sun.COM  * @link_up_wait_to_complete: bool used to wait for link up or not
305910998SChenlu.Chen@Sun.COM  *
306010998SChenlu.Chen@Sun.COM  * Reads the links register to determine if link is up and the current speed
306110998SChenlu.Chen@Sun.COM  */
306210998SChenlu.Chen@Sun.COM s32
ixgbe_check_mac_link_generic(struct ixgbe_hw * hw,ixgbe_link_speed * speed,bool * link_up,bool link_up_wait_to_complete)306310998SChenlu.Chen@Sun.COM ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
306410998SChenlu.Chen@Sun.COM     bool *link_up, bool link_up_wait_to_complete)
306510998SChenlu.Chen@Sun.COM {
3066*13006SChenlu.Chen@Sun.COM 	u32 links_reg, links_orig;
306710998SChenlu.Chen@Sun.COM 	u32 i;
306810998SChenlu.Chen@Sun.COM 
306910998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_check_mac_link_generic");
307010998SChenlu.Chen@Sun.COM 
3071*13006SChenlu.Chen@Sun.COM 	/* clear the old state */
3072*13006SChenlu.Chen@Sun.COM 	links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
3073*13006SChenlu.Chen@Sun.COM 
307410998SChenlu.Chen@Sun.COM 	links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
3075*13006SChenlu.Chen@Sun.COM 
3076*13006SChenlu.Chen@Sun.COM 	if (links_orig != links_reg) {
3077*13006SChenlu.Chen@Sun.COM 		DEBUGOUT2("LINKS changed from %08X to %08X\n",
3078*13006SChenlu.Chen@Sun.COM 		    links_orig, links_reg);
3079*13006SChenlu.Chen@Sun.COM 	}
3080*13006SChenlu.Chen@Sun.COM 
308110998SChenlu.Chen@Sun.COM 	if (link_up_wait_to_complete) {
308210998SChenlu.Chen@Sun.COM 		for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
308310998SChenlu.Chen@Sun.COM 			if (links_reg & IXGBE_LINKS_UP) {
308410998SChenlu.Chen@Sun.COM 				*link_up = true;
308510998SChenlu.Chen@Sun.COM 				break;
308610998SChenlu.Chen@Sun.COM 			} else {
308710998SChenlu.Chen@Sun.COM 				*link_up = false;
308810998SChenlu.Chen@Sun.COM 			}
308910998SChenlu.Chen@Sun.COM 			msec_delay(100);
309010998SChenlu.Chen@Sun.COM 			links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
309110998SChenlu.Chen@Sun.COM 		}
309210998SChenlu.Chen@Sun.COM 	} else {
309310998SChenlu.Chen@Sun.COM 		if (links_reg & IXGBE_LINKS_UP)
309410998SChenlu.Chen@Sun.COM 			*link_up = true;
309510998SChenlu.Chen@Sun.COM 		else
309610998SChenlu.Chen@Sun.COM 			*link_up = false;
309710998SChenlu.Chen@Sun.COM 	}
309810998SChenlu.Chen@Sun.COM 
309910998SChenlu.Chen@Sun.COM 	if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
310010998SChenlu.Chen@Sun.COM 	    IXGBE_LINKS_SPEED_10G_82599)
310110998SChenlu.Chen@Sun.COM 		*speed = IXGBE_LINK_SPEED_10GB_FULL;
310210998SChenlu.Chen@Sun.COM 	else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
310310998SChenlu.Chen@Sun.COM 	    IXGBE_LINKS_SPEED_1G_82599)
310410998SChenlu.Chen@Sun.COM 		*speed = IXGBE_LINK_SPEED_1GB_FULL;
3105*13006SChenlu.Chen@Sun.COM 	else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
3106*13006SChenlu.Chen@Sun.COM 	    IXGBE_LINKS_SPEED_100_82599)
3107*13006SChenlu.Chen@Sun.COM 		*speed = IXGBE_LINK_SPEED_100_FULL;
310810998SChenlu.Chen@Sun.COM 	else
3109*13006SChenlu.Chen@Sun.COM 		*speed = IXGBE_LINK_SPEED_UNKNOWN;
311010998SChenlu.Chen@Sun.COM 
311110998SChenlu.Chen@Sun.COM 	/* if link is down, zero out the current_mode */
311210998SChenlu.Chen@Sun.COM 	if (*link_up == false) {
311310998SChenlu.Chen@Sun.COM 		hw->fc.current_mode = ixgbe_fc_none;
311410998SChenlu.Chen@Sun.COM 		hw->fc.fc_was_autonegged = false;
311510998SChenlu.Chen@Sun.COM 	}
311610998SChenlu.Chen@Sun.COM 
311710998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
311810998SChenlu.Chen@Sun.COM }
311910998SChenlu.Chen@Sun.COM 
312010998SChenlu.Chen@Sun.COM /*
312110998SChenlu.Chen@Sun.COM  * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
312210998SChenlu.Chen@Sun.COM  * the EEPROM
312310998SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
312410998SChenlu.Chen@Sun.COM  * @wwnn_prefix: the alternative WWNN prefix
312510998SChenlu.Chen@Sun.COM  * @wwpn_prefix: the alternative WWPN prefix
312610998SChenlu.Chen@Sun.COM  *
312710998SChenlu.Chen@Sun.COM  * This function will read the EEPROM from the alternative SAN MAC address
312810998SChenlu.Chen@Sun.COM  * block to check the support for the alternative WWNN/WWPN prefix support.
312910998SChenlu.Chen@Sun.COM  */
313010998SChenlu.Chen@Sun.COM s32
ixgbe_get_wwn_prefix_generic(struct ixgbe_hw * hw,u16 * wwnn_prefix,u16 * wwpn_prefix)313110998SChenlu.Chen@Sun.COM ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
313210998SChenlu.Chen@Sun.COM     u16 *wwpn_prefix)
313310998SChenlu.Chen@Sun.COM {
313410998SChenlu.Chen@Sun.COM 	u16 offset, caps;
313510998SChenlu.Chen@Sun.COM 	u16 alt_san_mac_blk_offset;
313610998SChenlu.Chen@Sun.COM 
313710998SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_wwn_prefix_generic");
313810998SChenlu.Chen@Sun.COM 
313910998SChenlu.Chen@Sun.COM 	/* clear output first */
314010998SChenlu.Chen@Sun.COM 	*wwnn_prefix = 0xFFFF;
314110998SChenlu.Chen@Sun.COM 	*wwpn_prefix = 0xFFFF;
314210998SChenlu.Chen@Sun.COM 
314310998SChenlu.Chen@Sun.COM 	/* check if alternative SAN MAC is supported */
314410998SChenlu.Chen@Sun.COM 	hw->eeprom.ops.read(hw, IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR,
314510998SChenlu.Chen@Sun.COM 	    &alt_san_mac_blk_offset);
314610998SChenlu.Chen@Sun.COM 
314710998SChenlu.Chen@Sun.COM 	if ((alt_san_mac_blk_offset == 0) ||
314810998SChenlu.Chen@Sun.COM 	    (alt_san_mac_blk_offset == 0xFFFF))
314910998SChenlu.Chen@Sun.COM 		goto wwn_prefix_out;
315010998SChenlu.Chen@Sun.COM 
315110998SChenlu.Chen@Sun.COM 	/* check capability in alternative san mac address block */
315210998SChenlu.Chen@Sun.COM 	offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
315310998SChenlu.Chen@Sun.COM 	hw->eeprom.ops.read(hw, offset, &caps);
315410998SChenlu.Chen@Sun.COM 	if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
315510998SChenlu.Chen@Sun.COM 		goto wwn_prefix_out;
315610998SChenlu.Chen@Sun.COM 
315710998SChenlu.Chen@Sun.COM 	/* get the corresponding prefix for WWNN/WWPN */
315810998SChenlu.Chen@Sun.COM 	offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
315910998SChenlu.Chen@Sun.COM 	hw->eeprom.ops.read(hw, offset, wwnn_prefix);
316010998SChenlu.Chen@Sun.COM 
316110998SChenlu.Chen@Sun.COM 	offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
316210998SChenlu.Chen@Sun.COM 	hw->eeprom.ops.read(hw, offset, wwpn_prefix);
316310998SChenlu.Chen@Sun.COM 
316410998SChenlu.Chen@Sun.COM wwn_prefix_out:
316510998SChenlu.Chen@Sun.COM 	return (IXGBE_SUCCESS);
316610998SChenlu.Chen@Sun.COM }
3167*13006SChenlu.Chen@Sun.COM 
3168*13006SChenlu.Chen@Sun.COM /*
3169*13006SChenlu.Chen@Sun.COM  * ixgbe_get_fcoe_boot_status_generic - Get FCOE boot status from EEPROM
3170*13006SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
3171*13006SChenlu.Chen@Sun.COM  * @bs: the fcoe boot status
3172*13006SChenlu.Chen@Sun.COM  *
3173*13006SChenlu.Chen@Sun.COM  * This function will read the FCOE boot status from the iSCSI FCOE block
3174*13006SChenlu.Chen@Sun.COM  */
3175*13006SChenlu.Chen@Sun.COM s32
ixgbe_get_fcoe_boot_status_generic(struct ixgbe_hw * hw,u16 * bs)3176*13006SChenlu.Chen@Sun.COM ixgbe_get_fcoe_boot_status_generic(struct ixgbe_hw *hw, u16 *bs)
3177*13006SChenlu.Chen@Sun.COM {
3178*13006SChenlu.Chen@Sun.COM 	u16 offset, caps, flags;
3179*13006SChenlu.Chen@Sun.COM 	s32 status;
3180*13006SChenlu.Chen@Sun.COM 
3181*13006SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_get_fcoe_boot_status_generic");
3182*13006SChenlu.Chen@Sun.COM 
3183*13006SChenlu.Chen@Sun.COM 	/* clear output first */
3184*13006SChenlu.Chen@Sun.COM 	*bs = ixgbe_fcoe_bootstatus_unavailable;
3185*13006SChenlu.Chen@Sun.COM 
3186*13006SChenlu.Chen@Sun.COM 	/* check if FCOE IBA block is present */
3187*13006SChenlu.Chen@Sun.COM 	offset = IXGBE_FCOE_IBA_CAPS_BLK_PTR;
3188*13006SChenlu.Chen@Sun.COM 	status = hw->eeprom.ops.read(hw, offset, &caps);
3189*13006SChenlu.Chen@Sun.COM 	if (status != IXGBE_SUCCESS)
3190*13006SChenlu.Chen@Sun.COM 		goto out;
3191*13006SChenlu.Chen@Sun.COM 
3192*13006SChenlu.Chen@Sun.COM 	if (!(caps & IXGBE_FCOE_IBA_CAPS_FCOE))
3193*13006SChenlu.Chen@Sun.COM 		goto out;
3194*13006SChenlu.Chen@Sun.COM 
3195*13006SChenlu.Chen@Sun.COM 	/* check if iSCSI FCOE block is populated */
3196*13006SChenlu.Chen@Sun.COM 	status = hw->eeprom.ops.read(hw, IXGBE_ISCSI_FCOE_BLK_PTR, &offset);
3197*13006SChenlu.Chen@Sun.COM 	if (status != IXGBE_SUCCESS)
3198*13006SChenlu.Chen@Sun.COM 		goto out;
3199*13006SChenlu.Chen@Sun.COM 
3200*13006SChenlu.Chen@Sun.COM 	if ((offset == 0) || (offset == 0xFFFF))
3201*13006SChenlu.Chen@Sun.COM 		goto out;
3202*13006SChenlu.Chen@Sun.COM 
3203*13006SChenlu.Chen@Sun.COM 	/* read fcoe flags in iSCSI FCOE block */
3204*13006SChenlu.Chen@Sun.COM 	offset = offset + IXGBE_ISCSI_FCOE_FLAGS_OFFSET;
3205*13006SChenlu.Chen@Sun.COM 	status = hw->eeprom.ops.read(hw, offset, &flags);
3206*13006SChenlu.Chen@Sun.COM 	if (status != IXGBE_SUCCESS)
3207*13006SChenlu.Chen@Sun.COM 		goto out;
3208*13006SChenlu.Chen@Sun.COM 
3209*13006SChenlu.Chen@Sun.COM 	if (flags & IXGBE_ISCSI_FCOE_FLAGS_ENABLE)
3210*13006SChenlu.Chen@Sun.COM 		*bs = ixgbe_fcoe_bootstatus_enabled;
3211*13006SChenlu.Chen@Sun.COM 	else
3212*13006SChenlu.Chen@Sun.COM 		*bs = ixgbe_fcoe_bootstatus_disabled;
3213*13006SChenlu.Chen@Sun.COM 
3214*13006SChenlu.Chen@Sun.COM out:
3215*13006SChenlu.Chen@Sun.COM 	return (status);
3216*13006SChenlu.Chen@Sun.COM }
3217*13006SChenlu.Chen@Sun.COM 
3218*13006SChenlu.Chen@Sun.COM /*
3219*13006SChenlu.Chen@Sun.COM  * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
3220*13006SChenlu.Chen@Sun.COM  * control
3221*13006SChenlu.Chen@Sun.COM  * @hw: pointer to hardware structure
3222*13006SChenlu.Chen@Sun.COM  *
3223*13006SChenlu.Chen@Sun.COM  * There are several phys that do not support autoneg flow control. This
3224*13006SChenlu.Chen@Sun.COM  * function check the device id to see if the associated phy supports
3225*13006SChenlu.Chen@Sun.COM  * autoneg flow control.
3226*13006SChenlu.Chen@Sun.COM  */
ixgbe_device_supports_autoneg_fc(struct ixgbe_hw * hw)3227*13006SChenlu.Chen@Sun.COM static s32 ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
3228*13006SChenlu.Chen@Sun.COM {
3229*13006SChenlu.Chen@Sun.COM 
3230*13006SChenlu.Chen@Sun.COM 	DEBUGFUNC("ixgbe_device_supports_autoneg_fc");
3231*13006SChenlu.Chen@Sun.COM 
3232*13006SChenlu.Chen@Sun.COM 	switch (hw->device_id) {
3233*13006SChenlu.Chen@Sun.COM 	case IXGBE_DEV_ID_82599_T3_LOM:
3234*13006SChenlu.Chen@Sun.COM 		return (IXGBE_SUCCESS);
3235*13006SChenlu.Chen@Sun.COM 	default:
3236*13006SChenlu.Chen@Sun.COM 		return (IXGBE_ERR_FC_NOT_SUPPORTED);
3237*13006SChenlu.Chen@Sun.COM 	}
3238*13006SChenlu.Chen@Sun.COM }
3239