1179055Sjfv/******************************************************************************
2171384Sjfv
3248287Sjfv  Copyright (c) 2001-2013, Intel Corporation
4171384Sjfv  All rights reserved.
5171384Sjfv
6171384Sjfv  Redistribution and use in source and binary forms, with or without
7171384Sjfv  modification, are permitted provided that the following conditions are met:
8171384Sjfv
9171384Sjfv   1. Redistributions of source code must retain the above copyright notice,
10171384Sjfv      this list of conditions and the following disclaimer.
11171384Sjfv
12171384Sjfv   2. Redistributions in binary form must reproduce the above copyright
13171384Sjfv      notice, this list of conditions and the following disclaimer in the
14171384Sjfv      documentation and/or other materials provided with the distribution.
15171384Sjfv
16171384Sjfv   3. Neither the name of the Intel Corporation nor the names of its
17171384Sjfv      contributors may be used to endorse or promote products derived from
18171384Sjfv      this software without specific prior written permission.
19171384Sjfv
20171384Sjfv  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21171384Sjfv  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22171384Sjfv  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23171384Sjfv  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24171384Sjfv  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25171384Sjfv  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26171384Sjfv  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27171384Sjfv  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28171384Sjfv  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29171384Sjfv  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30171384Sjfv  POSSIBILITY OF SUCH DAMAGE.
31171384Sjfv
32179055Sjfv******************************************************************************/
33179055Sjfv/*$FreeBSD$*/
34171384Sjfv
35171384Sjfv#include "ixgbe_common.h"
36215911Sjfv#include "ixgbe_phy.h"
37252898Sjfv#include "ixgbe_dcb.h"
38252898Sjfv#include "ixgbe_dcb_82599.h"
39171384Sjfv#include "ixgbe_api.h"
40171384Sjfv
41171384Sjfvstatic s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
42171384Sjfvstatic s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
43171384Sjfvstatic void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
44171384Sjfvstatic s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
45171384Sjfvstatic void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
46171384Sjfvstatic void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
47235528Sjfv					u16 count);
48171384Sjfvstatic u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
49171384Sjfvstatic void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
50171384Sjfvstatic void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
51171384Sjfvstatic void ixgbe_release_eeprom(struct ixgbe_hw *hw);
52171384Sjfv
53171384Sjfvstatic s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
54200239Sjfvstatic s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
55235528Sjfv					 u16 *san_mac_offset);
56235528Sjfvstatic s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
57235528Sjfv					     u16 words, u16 *data);
58235528Sjfvstatic s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
59235528Sjfv					      u16 words, u16 *data);
60235528Sjfvstatic s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
61235528Sjfv						 u16 offset);
62215911Sjfv
63171384Sjfv/**
64179055Sjfv *  ixgbe_init_ops_generic - Inits function ptrs
65179055Sjfv *  @hw: pointer to the hardware structure
66171384Sjfv *
67179055Sjfv *  Initialize the function pointers.
68171384Sjfv **/
69179055Sjfvs32 ixgbe_init_ops_generic(struct ixgbe_hw *hw)
70171384Sjfv{
71179055Sjfv	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
72179055Sjfv	struct ixgbe_mac_info *mac = &hw->mac;
73179055Sjfv	u32 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
74171384Sjfv
75200239Sjfv	DEBUGFUNC("ixgbe_init_ops_generic");
76200239Sjfv
77171384Sjfv	/* EEPROM */
78179055Sjfv	eeprom->ops.init_params = &ixgbe_init_eeprom_params_generic;
79179055Sjfv	/* If EEPROM is valid (bit 8 = 1), use EERD otherwise use bit bang */
80235528Sjfv	if (eec & IXGBE_EEC_PRES) {
81200239Sjfv		eeprom->ops.read = &ixgbe_read_eerd_generic;
82235528Sjfv		eeprom->ops.read_buffer = &ixgbe_read_eerd_buffer_generic;
83235528Sjfv	} else {
84179055Sjfv		eeprom->ops.read = &ixgbe_read_eeprom_bit_bang_generic;
85235528Sjfv		eeprom->ops.read_buffer =
86235528Sjfv				 &ixgbe_read_eeprom_buffer_bit_bang_generic;
87235528Sjfv	}
88179055Sjfv	eeprom->ops.write = &ixgbe_write_eeprom_generic;
89235528Sjfv	eeprom->ops.write_buffer = &ixgbe_write_eeprom_buffer_bit_bang_generic;
90179055Sjfv	eeprom->ops.validate_checksum =
91235528Sjfv				      &ixgbe_validate_eeprom_checksum_generic;
92179055Sjfv	eeprom->ops.update_checksum = &ixgbe_update_eeprom_checksum_generic;
93200239Sjfv	eeprom->ops.calc_checksum = &ixgbe_calc_eeprom_checksum_generic;
94179055Sjfv
95179055Sjfv	/* MAC */
96179055Sjfv	mac->ops.init_hw = &ixgbe_init_hw_generic;
97179055Sjfv	mac->ops.reset_hw = NULL;
98179055Sjfv	mac->ops.start_hw = &ixgbe_start_hw_generic;
99179055Sjfv	mac->ops.clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic;
100179055Sjfv	mac->ops.get_media_type = NULL;
101185352Sjfv	mac->ops.get_supported_physical_layer = NULL;
102190873Sjfv	mac->ops.enable_rx_dma = &ixgbe_enable_rx_dma_generic;
103179055Sjfv	mac->ops.get_mac_addr = &ixgbe_get_mac_addr_generic;
104179055Sjfv	mac->ops.stop_adapter = &ixgbe_stop_adapter_generic;
105179055Sjfv	mac->ops.get_bus_info = &ixgbe_get_bus_info_generic;
106185352Sjfv	mac->ops.set_lan_id = &ixgbe_set_lan_id_multi_port_pcie;
107194875Sjfv	mac->ops.acquire_swfw_sync = &ixgbe_acquire_swfw_sync;
108194875Sjfv	mac->ops.release_swfw_sync = &ixgbe_release_swfw_sync;
109179055Sjfv
110179055Sjfv	/* LEDs */
111179055Sjfv	mac->ops.led_on = &ixgbe_led_on_generic;
112179055Sjfv	mac->ops.led_off = &ixgbe_led_off_generic;
113190873Sjfv	mac->ops.blink_led_start = &ixgbe_blink_led_start_generic;
114190873Sjfv	mac->ops.blink_led_stop = &ixgbe_blink_led_stop_generic;
115179055Sjfv
116171384Sjfv	/* RAR, Multicast, VLAN */
117179055Sjfv	mac->ops.set_rar = &ixgbe_set_rar_generic;
118181003Sjfv	mac->ops.clear_rar = &ixgbe_clear_rar_generic;
119190873Sjfv	mac->ops.insert_mac_addr = NULL;
120179055Sjfv	mac->ops.set_vmdq = NULL;
121181003Sjfv	mac->ops.clear_vmdq = NULL;
122179055Sjfv	mac->ops.init_rx_addrs = &ixgbe_init_rx_addrs_generic;
123179055Sjfv	mac->ops.update_uc_addr_list = &ixgbe_update_uc_addr_list_generic;
124179055Sjfv	mac->ops.update_mc_addr_list = &ixgbe_update_mc_addr_list_generic;
125179055Sjfv	mac->ops.enable_mc = &ixgbe_enable_mc_generic;
126179055Sjfv	mac->ops.disable_mc = &ixgbe_disable_mc_generic;
127181003Sjfv	mac->ops.clear_vfta = NULL;
128181003Sjfv	mac->ops.set_vfta = NULL;
129235528Sjfv	mac->ops.set_vlvf = NULL;
130181003Sjfv	mac->ops.init_uta_tables = NULL;
131171384Sjfv
132190873Sjfv	/* Flow Control */
133190873Sjfv	mac->ops.fc_enable = &ixgbe_fc_enable_generic;
134179055Sjfv
135179055Sjfv	/* Link */
136179055Sjfv	mac->ops.get_link_capabilities = NULL;
137179055Sjfv	mac->ops.setup_link = NULL;
138179055Sjfv	mac->ops.check_link = NULL;
139252898Sjfv	mac->ops.dmac_config = NULL;
140252898Sjfv	mac->ops.dmac_update_tcs = NULL;
141252898Sjfv	mac->ops.dmac_config_tcs = NULL;
142179055Sjfv
143171384Sjfv	return IXGBE_SUCCESS;
144171384Sjfv}
145171384Sjfv
146171384Sjfv/**
147252898Sjfv * ixgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
148252898Sjfv * of flow control
149252898Sjfv * @hw: pointer to hardware structure
150238263Sjfv *
151252898Sjfv * This function returns TRUE if the device supports flow control
152252898Sjfv * autonegotiation, and FALSE if it does not.
153252898Sjfv *
154238263Sjfv **/
155252898Sjfvbool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
156238263Sjfv{
157252898Sjfv	bool supported = FALSE;
158252898Sjfv	ixgbe_link_speed speed;
159252898Sjfv	bool link_up;
160238263Sjfv
161238263Sjfv	DEBUGFUNC("ixgbe_device_supports_autoneg_fc");
162238263Sjfv
163252898Sjfv	switch (hw->phy.media_type) {
164252898Sjfv	case ixgbe_media_type_fiber_fixed:
165252898Sjfv	case ixgbe_media_type_fiber:
166252898Sjfv		hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
167252898Sjfv		/* if link is down, assume supported */
168252898Sjfv		if (link_up)
169252898Sjfv			supported = speed == IXGBE_LINK_SPEED_1GB_FULL ?
170252898Sjfv				TRUE : FALSE;
171252898Sjfv		else
172252898Sjfv			supported = TRUE;
173252898Sjfv		break;
174252898Sjfv	case ixgbe_media_type_backplane:
175252898Sjfv		supported = TRUE;
176252898Sjfv		break;
177252898Sjfv	case ixgbe_media_type_copper:
178252898Sjfv		/* only some copper devices support flow control autoneg */
179252898Sjfv		switch (hw->device_id) {
180252898Sjfv		case IXGBE_DEV_ID_82599_T3_LOM:
181252898Sjfv		case IXGBE_DEV_ID_X540T:
182252898Sjfv		case IXGBE_DEV_ID_X540_BYPASS:
183252898Sjfv			supported = TRUE;
184252898Sjfv			break;
185252898Sjfv		default:
186252898Sjfv			supported = FALSE;
187252898Sjfv		}
188238263Sjfv	default:
189252898Sjfv		break;
190238263Sjfv	}
191252898Sjfv
192252898Sjfv	ERROR_REPORT2(IXGBE_ERROR_UNSUPPORTED,
193252898Sjfv		      "Device %x does not support flow control autoneg",
194252898Sjfv		      hw->device_id);
195252898Sjfv	return supported;
196238263Sjfv}
197238263Sjfv
198238263Sjfv/**
199238263Sjfv *  ixgbe_setup_fc - Set up flow control
200238263Sjfv *  @hw: pointer to hardware structure
201238263Sjfv *
202238263Sjfv *  Called at init time to set up flow control.
203238263Sjfv **/
204238263Sjfvstatic s32 ixgbe_setup_fc(struct ixgbe_hw *hw)
205238263Sjfv{
206238263Sjfv	s32 ret_val = IXGBE_SUCCESS;
207238263Sjfv	u32 reg = 0, reg_bp = 0;
208238263Sjfv	u16 reg_cu = 0;
209248287Sjfv	bool got_lock = FALSE;
210238263Sjfv
211238263Sjfv	DEBUGFUNC("ixgbe_setup_fc");
212238263Sjfv
213238263Sjfv	/*
214238263Sjfv	 * Validate the requested mode.  Strict IEEE mode does not allow
215238263Sjfv	 * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
216238263Sjfv	 */
217238263Sjfv	if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
218252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
219252898Sjfv			   "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
220238263Sjfv		ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
221238263Sjfv		goto out;
222238263Sjfv	}
223238263Sjfv
224238263Sjfv	/*
225238263Sjfv	 * 10gig parts do not have a word in the EEPROM to determine the
226238263Sjfv	 * default flow control setting, so we explicitly set it to full.
227238263Sjfv	 */
228238263Sjfv	if (hw->fc.requested_mode == ixgbe_fc_default)
229238263Sjfv		hw->fc.requested_mode = ixgbe_fc_full;
230238263Sjfv
231238263Sjfv	/*
232238263Sjfv	 * Set up the 1G and 10G flow control advertisement registers so the
233238263Sjfv	 * HW will be able to do fc autoneg once the cable is plugged in.  If
234238263Sjfv	 * we link at 10G, the 1G advertisement is harmless and vice versa.
235238263Sjfv	 */
236238263Sjfv	switch (hw->phy.media_type) {
237248287Sjfv	case ixgbe_media_type_fiber_fixed:
238238263Sjfv	case ixgbe_media_type_fiber:
239238263Sjfv	case ixgbe_media_type_backplane:
240238263Sjfv		reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
241238263Sjfv		reg_bp = IXGBE_READ_REG(hw, IXGBE_AUTOC);
242238263Sjfv		break;
243238263Sjfv	case ixgbe_media_type_copper:
244238263Sjfv		hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
245238263Sjfv				     IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &reg_cu);
246238263Sjfv		break;
247238263Sjfv	default:
248238263Sjfv		break;
249238263Sjfv	}
250238263Sjfv
251238263Sjfv	/*
252238263Sjfv	 * The possible values of fc.requested_mode are:
253238263Sjfv	 * 0: Flow control is completely disabled
254238263Sjfv	 * 1: Rx flow control is enabled (we can receive pause frames,
255238263Sjfv	 *    but not send pause frames).
256238263Sjfv	 * 2: Tx flow control is enabled (we can send pause frames but
257238263Sjfv	 *    we do not support receiving pause frames).
258238263Sjfv	 * 3: Both Rx and Tx flow control (symmetric) are enabled.
259238263Sjfv	 * other: Invalid.
260238263Sjfv	 */
261238263Sjfv	switch (hw->fc.requested_mode) {
262238263Sjfv	case ixgbe_fc_none:
263238263Sjfv		/* Flow control completely disabled by software override. */
264238263Sjfv		reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
265238263Sjfv		if (hw->phy.media_type == ixgbe_media_type_backplane)
266238263Sjfv			reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
267238263Sjfv				    IXGBE_AUTOC_ASM_PAUSE);
268238263Sjfv		else if (hw->phy.media_type == ixgbe_media_type_copper)
269238263Sjfv			reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
270238263Sjfv		break;
271238263Sjfv	case ixgbe_fc_tx_pause:
272238263Sjfv		/*
273238263Sjfv		 * Tx Flow control is enabled, and Rx Flow control is
274238263Sjfv		 * disabled by software override.
275238263Sjfv		 */
276238263Sjfv		reg |= IXGBE_PCS1GANA_ASM_PAUSE;
277238263Sjfv		reg &= ~IXGBE_PCS1GANA_SYM_PAUSE;
278238263Sjfv		if (hw->phy.media_type == ixgbe_media_type_backplane) {
279238263Sjfv			reg_bp |= IXGBE_AUTOC_ASM_PAUSE;
280238263Sjfv			reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE;
281238263Sjfv		} else if (hw->phy.media_type == ixgbe_media_type_copper) {
282238263Sjfv			reg_cu |= IXGBE_TAF_ASM_PAUSE;
283238263Sjfv			reg_cu &= ~IXGBE_TAF_SYM_PAUSE;
284238263Sjfv		}
285238263Sjfv		break;
286238263Sjfv	case ixgbe_fc_rx_pause:
287238263Sjfv		/*
288238263Sjfv		 * Rx Flow control is enabled and Tx Flow control is
289238263Sjfv		 * disabled by software override. Since there really
290238263Sjfv		 * isn't a way to advertise that we are capable of RX
291238263Sjfv		 * Pause ONLY, we will advertise that we support both
292238263Sjfv		 * symmetric and asymmetric Rx PAUSE, as such we fall
293238263Sjfv		 * through to the fc_full statement.  Later, we will
294238263Sjfv		 * disable the adapter's ability to send PAUSE frames.
295238263Sjfv		 */
296238263Sjfv	case ixgbe_fc_full:
297238263Sjfv		/* Flow control (both Rx and Tx) is enabled by SW override. */
298238263Sjfv		reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE;
299238263Sjfv		if (hw->phy.media_type == ixgbe_media_type_backplane)
300238263Sjfv			reg_bp |= IXGBE_AUTOC_SYM_PAUSE |
301238263Sjfv				  IXGBE_AUTOC_ASM_PAUSE;
302238263Sjfv		else if (hw->phy.media_type == ixgbe_media_type_copper)
303238263Sjfv			reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE;
304238263Sjfv		break;
305238263Sjfv	default:
306252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
307252898Sjfv			     "Flow control param set incorrectly\n");
308238263Sjfv		ret_val = IXGBE_ERR_CONFIG;
309238263Sjfv		goto out;
310238263Sjfv		break;
311238263Sjfv	}
312238263Sjfv
313238263Sjfv	if (hw->mac.type != ixgbe_mac_X540) {
314238263Sjfv		/*
315238263Sjfv		 * Enable auto-negotiation between the MAC & PHY;
316238263Sjfv		 * the MAC will advertise clause 37 flow control.
317238263Sjfv		 */
318238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
319238263Sjfv		reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
320238263Sjfv
321238263Sjfv		/* Disable AN timeout */
322238263Sjfv		if (hw->fc.strict_ieee)
323238263Sjfv			reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
324238263Sjfv
325238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
326238263Sjfv		DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg);
327238263Sjfv	}
328238263Sjfv
329238263Sjfv	/*
330238263Sjfv	 * AUTOC restart handles negotiation of 1G and 10G on backplane
331238263Sjfv	 * and copper. There is no need to set the PCS1GCTL register.
332238263Sjfv	 *
333238263Sjfv	 */
334238263Sjfv	if (hw->phy.media_type == ixgbe_media_type_backplane) {
335238263Sjfv		reg_bp |= IXGBE_AUTOC_AN_RESTART;
336248287Sjfv		/* Need the SW/FW semaphore around AUTOC writes if 82599 and
337248287Sjfv		 * LESM is on, likewise reset_pipeline requries the lock as
338248287Sjfv		 * it also writes AUTOC.
339248287Sjfv		 */
340248287Sjfv		if ((hw->mac.type == ixgbe_mac_82599EB) &&
341248287Sjfv		    ixgbe_verify_lesm_fw_enabled_82599(hw)) {
342248287Sjfv			ret_val = hw->mac.ops.acquire_swfw_sync(hw,
343248287Sjfv							IXGBE_GSSR_MAC_CSR_SM);
344248287Sjfv			if (ret_val != IXGBE_SUCCESS) {
345248287Sjfv				ret_val = IXGBE_ERR_SWFW_SYNC;
346248287Sjfv				goto out;
347248287Sjfv			}
348248287Sjfv			got_lock = TRUE;
349248287Sjfv		}
350248287Sjfv
351238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_bp);
352248287Sjfv		if (hw->mac.type == ixgbe_mac_82599EB)
353248287Sjfv			ixgbe_reset_pipeline_82599(hw);
354248287Sjfv
355248287Sjfv		if (got_lock)
356248287Sjfv			hw->mac.ops.release_swfw_sync(hw,
357248287Sjfv						      IXGBE_GSSR_MAC_CSR_SM);
358238263Sjfv	} else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
359252898Sjfv		    (ixgbe_device_supports_autoneg_fc(hw))) {
360238263Sjfv		hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
361238263Sjfv				      IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg_cu);
362238263Sjfv	}
363238263Sjfv
364238263Sjfv	DEBUGOUT1("Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
365238263Sjfvout:
366238263Sjfv	return ret_val;
367238263Sjfv}
368238263Sjfv
369238263Sjfv/**
370179055Sjfv *  ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
371171384Sjfv *  @hw: pointer to hardware structure
372171384Sjfv *
373171384Sjfv *  Starts the hardware by filling the bus info structure and media type, clears
374171384Sjfv *  all on chip counters, initializes receive address registers, multicast
375171384Sjfv *  table, VLAN filter table, calls routine to set up link and flow control
376171384Sjfv *  settings, and leaves transmit and receive units disabled and uninitialized
377171384Sjfv **/
378171384Sjfvs32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
379171384Sjfv{
380238263Sjfv	s32 ret_val;
381171384Sjfv	u32 ctrl_ext;
382171384Sjfv
383200239Sjfv	DEBUGFUNC("ixgbe_start_hw_generic");
384200239Sjfv
385171384Sjfv	/* Set the media type */
386179055Sjfv	hw->phy.media_type = hw->mac.ops.get_media_type(hw);
387171384Sjfv
388190873Sjfv	/* PHY ops initialization must be done in reset_hw() */
389171384Sjfv
390171384Sjfv	/* Clear the VLAN filter table */
391179055Sjfv	hw->mac.ops.clear_vfta(hw);
392171384Sjfv
393171384Sjfv	/* Clear statistics registers */
394179055Sjfv	hw->mac.ops.clear_hw_cntrs(hw);
395171384Sjfv
396171384Sjfv	/* Set No Snoop Disable */
397171384Sjfv	ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
398171384Sjfv	ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
399171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
400179055Sjfv	IXGBE_WRITE_FLUSH(hw);
401171384Sjfv
402190873Sjfv	/* Setup flow control */
403238263Sjfv	ret_val = ixgbe_setup_fc(hw);
404238263Sjfv	if (ret_val != IXGBE_SUCCESS)
405238263Sjfv		goto out;
406190873Sjfv
407171384Sjfv	/* Clear adapter stopped flag */
408171384Sjfv	hw->adapter_stopped = FALSE;
409171384Sjfv
410238263Sjfvout:
411238263Sjfv	return ret_val;
412171384Sjfv}
413171384Sjfv
414171384Sjfv/**
415215911Sjfv *  ixgbe_start_hw_gen2 - Init sequence for common device family
416215911Sjfv *  @hw: pointer to hw structure
417215911Sjfv *
418215911Sjfv * Performs the init sequence common to the second generation
419215911Sjfv * of 10 GbE devices.
420215911Sjfv * Devices in the second generation:
421215911Sjfv *     82599
422217593Sjfv *     X540
423215911Sjfv **/
424215911Sjfvs32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
425215911Sjfv{
426215911Sjfv	u32 i;
427215911Sjfv	u32 regval;
428215911Sjfv
429215911Sjfv	/* Clear the rate limiters */
430215911Sjfv	for (i = 0; i < hw->mac.max_tx_queues; i++) {
431215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
432215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
433215911Sjfv	}
434215911Sjfv	IXGBE_WRITE_FLUSH(hw);
435215911Sjfv
436215911Sjfv	/* Disable relaxed ordering */
437215911Sjfv	for (i = 0; i < hw->mac.max_tx_queues; i++) {
438215911Sjfv		regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
439238263Sjfv		regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
440215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
441215911Sjfv	}
442215911Sjfv
443215911Sjfv	for (i = 0; i < hw->mac.max_rx_queues; i++) {
444215911Sjfv		regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
445238263Sjfv		regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
446238263Sjfv			    IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
447215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
448215911Sjfv	}
449215911Sjfv
450215911Sjfv	return IXGBE_SUCCESS;
451215911Sjfv}
452215911Sjfv
453215911Sjfv/**
454171384Sjfv *  ixgbe_init_hw_generic - Generic hardware initialization
455171384Sjfv *  @hw: pointer to hardware structure
456171384Sjfv *
457179055Sjfv *  Initialize the hardware by resetting the hardware, filling the bus info
458171384Sjfv *  structure and media type, clears all on chip counters, initializes receive
459171384Sjfv *  address registers, multicast table, VLAN filter table, calls routine to set
460171384Sjfv *  up link and flow control settings, and leaves transmit and receive units
461171384Sjfv *  disabled and uninitialized
462171384Sjfv **/
463171384Sjfvs32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
464171384Sjfv{
465215911Sjfv	s32 status;
466190873Sjfv
467200239Sjfv	DEBUGFUNC("ixgbe_init_hw_generic");
468200239Sjfv
469171384Sjfv	/* Reset the hardware */
470190873Sjfv	status = hw->mac.ops.reset_hw(hw);
471171384Sjfv
472190873Sjfv	if (status == IXGBE_SUCCESS) {
473190873Sjfv		/* Start the HW */
474190873Sjfv		status = hw->mac.ops.start_hw(hw);
475190873Sjfv	}
476171384Sjfv
477190873Sjfv	return status;
478171384Sjfv}
479171384Sjfv
480171384Sjfv/**
481171384Sjfv *  ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
482171384Sjfv *  @hw: pointer to hardware structure
483171384Sjfv *
484171384Sjfv *  Clears all hardware statistics counters by reading them from the hardware
485171384Sjfv *  Statistics counters are clear on read.
486171384Sjfv **/
487171384Sjfvs32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
488171384Sjfv{
489171384Sjfv	u16 i = 0;
490171384Sjfv
491200239Sjfv	DEBUGFUNC("ixgbe_clear_hw_cntrs_generic");
492200239Sjfv
493171384Sjfv	IXGBE_READ_REG(hw, IXGBE_CRCERRS);
494171384Sjfv	IXGBE_READ_REG(hw, IXGBE_ILLERRC);
495171384Sjfv	IXGBE_READ_REG(hw, IXGBE_ERRBC);
496171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MSPDC);
497171384Sjfv	for (i = 0; i < 8; i++)
498171384Sjfv		IXGBE_READ_REG(hw, IXGBE_MPC(i));
499171384Sjfv
500171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MLFC);
501171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MRFC);
502171384Sjfv	IXGBE_READ_REG(hw, IXGBE_RLEC);
503171384Sjfv	IXGBE_READ_REG(hw, IXGBE_LXONTXC);
504185352Sjfv	IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
505190873Sjfv	if (hw->mac.type >= ixgbe_mac_82599EB) {
506190873Sjfv		IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
507190873Sjfv		IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
508190873Sjfv	} else {
509190873Sjfv		IXGBE_READ_REG(hw, IXGBE_LXONRXC);
510190873Sjfv		IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
511190873Sjfv	}
512171384Sjfv
513171384Sjfv	for (i = 0; i < 8; i++) {
514171384Sjfv		IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
515185352Sjfv		IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
516190873Sjfv		if (hw->mac.type >= ixgbe_mac_82599EB) {
517190873Sjfv			IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
518190873Sjfv			IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
519190873Sjfv		} else {
520190873Sjfv			IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
521190873Sjfv			IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
522190873Sjfv		}
523171384Sjfv	}
524190873Sjfv	if (hw->mac.type >= ixgbe_mac_82599EB)
525190873Sjfv		for (i = 0; i < 8; i++)
526190873Sjfv			IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
527171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PRC64);
528171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PRC127);
529171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PRC255);
530171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PRC511);
531171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PRC1023);
532171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PRC1522);
533171384Sjfv	IXGBE_READ_REG(hw, IXGBE_GPRC);
534171384Sjfv	IXGBE_READ_REG(hw, IXGBE_BPRC);
535171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MPRC);
536171384Sjfv	IXGBE_READ_REG(hw, IXGBE_GPTC);
537171384Sjfv	IXGBE_READ_REG(hw, IXGBE_GORCL);
538171384Sjfv	IXGBE_READ_REG(hw, IXGBE_GORCH);
539171384Sjfv	IXGBE_READ_REG(hw, IXGBE_GOTCL);
540171384Sjfv	IXGBE_READ_REG(hw, IXGBE_GOTCH);
541235528Sjfv	if (hw->mac.type == ixgbe_mac_82598EB)
542235528Sjfv		for (i = 0; i < 8; i++)
543235528Sjfv			IXGBE_READ_REG(hw, IXGBE_RNBC(i));
544171384Sjfv	IXGBE_READ_REG(hw, IXGBE_RUC);
545171384Sjfv	IXGBE_READ_REG(hw, IXGBE_RFC);
546171384Sjfv	IXGBE_READ_REG(hw, IXGBE_ROC);
547171384Sjfv	IXGBE_READ_REG(hw, IXGBE_RJC);
548171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MNGPRC);
549171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MNGPDC);
550171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MNGPTC);
551171384Sjfv	IXGBE_READ_REG(hw, IXGBE_TORL);
552171384Sjfv	IXGBE_READ_REG(hw, IXGBE_TORH);
553171384Sjfv	IXGBE_READ_REG(hw, IXGBE_TPR);
554171384Sjfv	IXGBE_READ_REG(hw, IXGBE_TPT);
555171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PTC64);
556171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PTC127);
557171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PTC255);
558171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PTC511);
559171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PTC1023);
560171384Sjfv	IXGBE_READ_REG(hw, IXGBE_PTC1522);
561171384Sjfv	IXGBE_READ_REG(hw, IXGBE_MPTC);
562171384Sjfv	IXGBE_READ_REG(hw, IXGBE_BPTC);
563171384Sjfv	for (i = 0; i < 16; i++) {
564171384Sjfv		IXGBE_READ_REG(hw, IXGBE_QPRC(i));
565171384Sjfv		IXGBE_READ_REG(hw, IXGBE_QPTC(i));
566215911Sjfv		if (hw->mac.type >= ixgbe_mac_82599EB) {
567215911Sjfv			IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
568215911Sjfv			IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
569215911Sjfv			IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
570215911Sjfv			IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
571215911Sjfv			IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
572215911Sjfv		} else {
573215911Sjfv			IXGBE_READ_REG(hw, IXGBE_QBRC(i));
574215911Sjfv			IXGBE_READ_REG(hw, IXGBE_QBTC(i));
575215911Sjfv		}
576171384Sjfv	}
577171384Sjfv
578235528Sjfv	if (hw->mac.type == ixgbe_mac_X540) {
579235528Sjfv		if (hw->phy.id == 0)
580235528Sjfv			ixgbe_identify_phy(hw);
581235528Sjfv		hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECL,
582235528Sjfv				     IXGBE_MDIO_PCS_DEV_TYPE, &i);
583235528Sjfv		hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECH,
584235528Sjfv				     IXGBE_MDIO_PCS_DEV_TYPE, &i);
585235528Sjfv		hw->phy.ops.read_reg(hw, IXGBE_LDPCECL,
586235528Sjfv				     IXGBE_MDIO_PCS_DEV_TYPE, &i);
587235528Sjfv		hw->phy.ops.read_reg(hw, IXGBE_LDPCECH,
588235528Sjfv				     IXGBE_MDIO_PCS_DEV_TYPE, &i);
589235528Sjfv	}
590235528Sjfv
591171384Sjfv	return IXGBE_SUCCESS;
592171384Sjfv}
593171384Sjfv
594171384Sjfv/**
595215911Sjfv *  ixgbe_read_pba_string_generic - Reads part number string from EEPROM
596215911Sjfv *  @hw: pointer to hardware structure
597215911Sjfv *  @pba_num: stores the part number string from the EEPROM
598215911Sjfv *  @pba_num_size: part number string buffer length
599215911Sjfv *
600215911Sjfv *  Reads the part number string from the EEPROM.
601215911Sjfv **/
602215911Sjfvs32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
603235528Sjfv				  u32 pba_num_size)
604215911Sjfv{
605215911Sjfv	s32 ret_val;
606215911Sjfv	u16 data;
607215911Sjfv	u16 pba_ptr;
608215911Sjfv	u16 offset;
609215911Sjfv	u16 length;
610215911Sjfv
611215911Sjfv	DEBUGFUNC("ixgbe_read_pba_string_generic");
612215911Sjfv
613215911Sjfv	if (pba_num == NULL) {
614215911Sjfv		DEBUGOUT("PBA string buffer was null\n");
615215911Sjfv		return IXGBE_ERR_INVALID_ARGUMENT;
616215911Sjfv	}
617215911Sjfv
618215911Sjfv	ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
619215911Sjfv	if (ret_val) {
620215911Sjfv		DEBUGOUT("NVM Read Error\n");
621215911Sjfv		return ret_val;
622215911Sjfv	}
623215911Sjfv
624215911Sjfv	ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
625215911Sjfv	if (ret_val) {
626215911Sjfv		DEBUGOUT("NVM Read Error\n");
627215911Sjfv		return ret_val;
628215911Sjfv	}
629215911Sjfv
630215911Sjfv	/*
631215911Sjfv	 * if data is not ptr guard the PBA must be in legacy format which
632215911Sjfv	 * means pba_ptr is actually our second data word for the PBA number
633215911Sjfv	 * and we can decode it into an ascii string
634215911Sjfv	 */
635215911Sjfv	if (data != IXGBE_PBANUM_PTR_GUARD) {
636215911Sjfv		DEBUGOUT("NVM PBA number is not stored as string\n");
637215911Sjfv
638215911Sjfv		/* we will need 11 characters to store the PBA */
639215911Sjfv		if (pba_num_size < 11) {
640215911Sjfv			DEBUGOUT("PBA string buffer too small\n");
641215911Sjfv			return IXGBE_ERR_NO_SPACE;
642215911Sjfv		}
643215911Sjfv
644215911Sjfv		/* extract hex string from data and pba_ptr */
645215911Sjfv		pba_num[0] = (data >> 12) & 0xF;
646215911Sjfv		pba_num[1] = (data >> 8) & 0xF;
647215911Sjfv		pba_num[2] = (data >> 4) & 0xF;
648215911Sjfv		pba_num[3] = data & 0xF;
649215911Sjfv		pba_num[4] = (pba_ptr >> 12) & 0xF;
650215911Sjfv		pba_num[5] = (pba_ptr >> 8) & 0xF;
651215911Sjfv		pba_num[6] = '-';
652215911Sjfv		pba_num[7] = 0;
653215911Sjfv		pba_num[8] = (pba_ptr >> 4) & 0xF;
654215911Sjfv		pba_num[9] = pba_ptr & 0xF;
655215911Sjfv
656215911Sjfv		/* put a null character on the end of our string */
657215911Sjfv		pba_num[10] = '\0';
658215911Sjfv
659215911Sjfv		/* switch all the data but the '-' to hex char */
660215911Sjfv		for (offset = 0; offset < 10; offset++) {
661215911Sjfv			if (pba_num[offset] < 0xA)
662215911Sjfv				pba_num[offset] += '0';
663215911Sjfv			else if (pba_num[offset] < 0x10)
664215911Sjfv				pba_num[offset] += 'A' - 0xA;
665215911Sjfv		}
666215911Sjfv
667215911Sjfv		return IXGBE_SUCCESS;
668215911Sjfv	}
669215911Sjfv
670215911Sjfv	ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
671215911Sjfv	if (ret_val) {
672215911Sjfv		DEBUGOUT("NVM Read Error\n");
673215911Sjfv		return ret_val;
674215911Sjfv	}
675215911Sjfv
676215911Sjfv	if (length == 0xFFFF || length == 0) {
677215911Sjfv		DEBUGOUT("NVM PBA number section invalid length\n");
678215911Sjfv		return IXGBE_ERR_PBA_SECTION;
679215911Sjfv	}
680215911Sjfv
681215911Sjfv	/* check if pba_num buffer is big enough */
682215911Sjfv	if (pba_num_size  < (((u32)length * 2) - 1)) {
683215911Sjfv		DEBUGOUT("PBA string buffer too small\n");
684215911Sjfv		return IXGBE_ERR_NO_SPACE;
685215911Sjfv	}
686215911Sjfv
687215911Sjfv	/* trim pba length from start of string */
688215911Sjfv	pba_ptr++;
689215911Sjfv	length--;
690215911Sjfv
691215911Sjfv	for (offset = 0; offset < length; offset++) {
692215911Sjfv		ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
693215911Sjfv		if (ret_val) {
694215911Sjfv			DEBUGOUT("NVM Read Error\n");
695215911Sjfv			return ret_val;
696215911Sjfv		}
697215911Sjfv		pba_num[offset * 2] = (u8)(data >> 8);
698215911Sjfv		pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
699215911Sjfv	}
700215911Sjfv	pba_num[offset * 2] = '\0';
701215911Sjfv
702215911Sjfv	return IXGBE_SUCCESS;
703215911Sjfv}
704215911Sjfv
705215911Sjfv/**
706185352Sjfv *  ixgbe_read_pba_num_generic - Reads part number from EEPROM
707179055Sjfv *  @hw: pointer to hardware structure
708179055Sjfv *  @pba_num: stores the part number from the EEPROM
709179055Sjfv *
710179055Sjfv *  Reads the part number from the EEPROM.
711179055Sjfv **/
712179055Sjfvs32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
713179055Sjfv{
714179055Sjfv	s32 ret_val;
715179055Sjfv	u16 data;
716179055Sjfv
717179055Sjfv	DEBUGFUNC("ixgbe_read_pba_num_generic");
718179055Sjfv
719179055Sjfv	ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
720179055Sjfv	if (ret_val) {
721179055Sjfv		DEBUGOUT("NVM Read Error\n");
722179055Sjfv		return ret_val;
723215911Sjfv	} else if (data == IXGBE_PBANUM_PTR_GUARD) {
724215911Sjfv		DEBUGOUT("NVM Not supported\n");
725215911Sjfv		return IXGBE_NOT_IMPLEMENTED;
726179055Sjfv	}
727179055Sjfv	*pba_num = (u32)(data << 16);
728179055Sjfv
729179055Sjfv	ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
730179055Sjfv	if (ret_val) {
731179055Sjfv		DEBUGOUT("NVM Read Error\n");
732179055Sjfv		return ret_val;
733179055Sjfv	}
734179055Sjfv	*pba_num |= data;
735179055Sjfv
736179055Sjfv	return IXGBE_SUCCESS;
737179055Sjfv}
738179055Sjfv
739179055Sjfv/**
740248287Sjfv *  ixgbe_read_pba_raw
741248287Sjfv *  @hw: pointer to the HW structure
742248287Sjfv *  @eeprom_buf: optional pointer to EEPROM image
743248287Sjfv *  @eeprom_buf_size: size of EEPROM image in words
744248287Sjfv *  @max_pba_block_size: PBA block size limit
745248287Sjfv *  @pba: pointer to output PBA structure
746248287Sjfv *
747248287Sjfv *  Reads PBA from EEPROM image when eeprom_buf is not NULL.
748248287Sjfv *  Reads PBA from physical EEPROM device when eeprom_buf is NULL.
749248287Sjfv *
750248287Sjfv **/
751248287Sjfvs32 ixgbe_read_pba_raw(struct ixgbe_hw *hw, u16 *eeprom_buf,
752248287Sjfv		       u32 eeprom_buf_size, u16 max_pba_block_size,
753248287Sjfv		       struct ixgbe_pba *pba)
754248287Sjfv{
755248287Sjfv	s32 ret_val;
756248287Sjfv	u16 pba_block_size;
757248287Sjfv
758248287Sjfv	if (pba == NULL)
759248287Sjfv		return IXGBE_ERR_PARAM;
760248287Sjfv
761248287Sjfv	if (eeprom_buf == NULL) {
762248287Sjfv		ret_val = hw->eeprom.ops.read_buffer(hw, IXGBE_PBANUM0_PTR, 2,
763248287Sjfv						     &pba->word[0]);
764248287Sjfv		if (ret_val)
765248287Sjfv			return ret_val;
766248287Sjfv	} else {
767248287Sjfv		if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
768248287Sjfv			pba->word[0] = eeprom_buf[IXGBE_PBANUM0_PTR];
769248287Sjfv			pba->word[1] = eeprom_buf[IXGBE_PBANUM1_PTR];
770248287Sjfv		} else {
771248287Sjfv			return IXGBE_ERR_PARAM;
772248287Sjfv		}
773248287Sjfv	}
774248287Sjfv
775248287Sjfv	if (pba->word[0] == IXGBE_PBANUM_PTR_GUARD) {
776248287Sjfv		if (pba->pba_block == NULL)
777248287Sjfv			return IXGBE_ERR_PARAM;
778248287Sjfv
779248287Sjfv		ret_val = ixgbe_get_pba_block_size(hw, eeprom_buf,
780248287Sjfv						   eeprom_buf_size,
781248287Sjfv						   &pba_block_size);
782248287Sjfv		if (ret_val)
783248287Sjfv			return ret_val;
784248287Sjfv
785248287Sjfv		if (pba_block_size > max_pba_block_size)
786248287Sjfv			return IXGBE_ERR_PARAM;
787248287Sjfv
788248287Sjfv		if (eeprom_buf == NULL) {
789248287Sjfv			ret_val = hw->eeprom.ops.read_buffer(hw, pba->word[1],
790248287Sjfv							     pba_block_size,
791248287Sjfv							     pba->pba_block);
792248287Sjfv			if (ret_val)
793248287Sjfv				return ret_val;
794248287Sjfv		} else {
795248287Sjfv			if (eeprom_buf_size > (u32)(pba->word[1] +
796248287Sjfv					      pba->pba_block[0])) {
797248287Sjfv				memcpy(pba->pba_block,
798248287Sjfv				       &eeprom_buf[pba->word[1]],
799248287Sjfv				       pba_block_size * sizeof(u16));
800248287Sjfv			} else {
801248287Sjfv				return IXGBE_ERR_PARAM;
802248287Sjfv			}
803248287Sjfv		}
804248287Sjfv	}
805248287Sjfv
806248287Sjfv	return IXGBE_SUCCESS;
807248287Sjfv}
808248287Sjfv
809248287Sjfv/**
810248287Sjfv *  ixgbe_write_pba_raw
811248287Sjfv *  @hw: pointer to the HW structure
812248287Sjfv *  @eeprom_buf: optional pointer to EEPROM image
813248287Sjfv *  @eeprom_buf_size: size of EEPROM image in words
814248287Sjfv *  @pba: pointer to PBA structure
815248287Sjfv *
816248287Sjfv *  Writes PBA to EEPROM image when eeprom_buf is not NULL.
817248287Sjfv *  Writes PBA to physical EEPROM device when eeprom_buf is NULL.
818248287Sjfv *
819248287Sjfv **/
820248287Sjfvs32 ixgbe_write_pba_raw(struct ixgbe_hw *hw, u16 *eeprom_buf,
821248287Sjfv			u32 eeprom_buf_size, struct ixgbe_pba *pba)
822248287Sjfv{
823248287Sjfv	s32 ret_val;
824248287Sjfv
825248287Sjfv	if (pba == NULL)
826248287Sjfv		return IXGBE_ERR_PARAM;
827248287Sjfv
828248287Sjfv	if (eeprom_buf == NULL) {
829248287Sjfv		ret_val = hw->eeprom.ops.write_buffer(hw, IXGBE_PBANUM0_PTR, 2,
830248287Sjfv						      &pba->word[0]);
831248287Sjfv		if (ret_val)
832248287Sjfv			return ret_val;
833248287Sjfv	} else {
834248287Sjfv		if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
835248287Sjfv			eeprom_buf[IXGBE_PBANUM0_PTR] = pba->word[0];
836248287Sjfv			eeprom_buf[IXGBE_PBANUM1_PTR] = pba->word[1];
837248287Sjfv		} else {
838248287Sjfv			return IXGBE_ERR_PARAM;
839248287Sjfv		}
840248287Sjfv	}
841248287Sjfv
842248287Sjfv	if (pba->word[0] == IXGBE_PBANUM_PTR_GUARD) {
843248287Sjfv		if (pba->pba_block == NULL)
844248287Sjfv			return IXGBE_ERR_PARAM;
845248287Sjfv
846248287Sjfv		if (eeprom_buf == NULL) {
847248287Sjfv			ret_val = hw->eeprom.ops.write_buffer(hw, pba->word[1],
848248287Sjfv							      pba->pba_block[0],
849248287Sjfv							      pba->pba_block);
850248287Sjfv			if (ret_val)
851248287Sjfv				return ret_val;
852248287Sjfv		} else {
853248287Sjfv			if (eeprom_buf_size > (u32)(pba->word[1] +
854248287Sjfv					      pba->pba_block[0])) {
855248287Sjfv				memcpy(&eeprom_buf[pba->word[1]],
856248287Sjfv				       pba->pba_block,
857248287Sjfv				       pba->pba_block[0] * sizeof(u16));
858248287Sjfv			} else {
859248287Sjfv				return IXGBE_ERR_PARAM;
860248287Sjfv			}
861248287Sjfv		}
862248287Sjfv	}
863248287Sjfv
864248287Sjfv	return IXGBE_SUCCESS;
865248287Sjfv}
866248287Sjfv
867248287Sjfv/**
868248287Sjfv *  ixgbe_get_pba_block_size
869248287Sjfv *  @hw: pointer to the HW structure
870248287Sjfv *  @eeprom_buf: optional pointer to EEPROM image
871248287Sjfv *  @eeprom_buf_size: size of EEPROM image in words
872248287Sjfv *  @pba_data_size: pointer to output variable
873248287Sjfv *
874248287Sjfv *  Returns the size of the PBA block in words. Function operates on EEPROM
875248287Sjfv *  image if the eeprom_buf pointer is not NULL otherwise it accesses physical
876248287Sjfv *  EEPROM device.
877248287Sjfv *
878248287Sjfv **/
879248287Sjfvs32 ixgbe_get_pba_block_size(struct ixgbe_hw *hw, u16 *eeprom_buf,
880248287Sjfv			     u32 eeprom_buf_size, u16 *pba_block_size)
881248287Sjfv{
882248287Sjfv	s32 ret_val;
883248287Sjfv	u16 pba_word[2];
884248287Sjfv	u16 length;
885248287Sjfv
886248287Sjfv	DEBUGFUNC("ixgbe_get_pba_block_size");
887248287Sjfv
888248287Sjfv	if (eeprom_buf == NULL) {
889248287Sjfv		ret_val = hw->eeprom.ops.read_buffer(hw, IXGBE_PBANUM0_PTR, 2,
890248287Sjfv						     &pba_word[0]);
891248287Sjfv		if (ret_val)
892248287Sjfv			return ret_val;
893248287Sjfv	} else {
894248287Sjfv		if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
895248287Sjfv			pba_word[0] = eeprom_buf[IXGBE_PBANUM0_PTR];
896248287Sjfv			pba_word[1] = eeprom_buf[IXGBE_PBANUM1_PTR];
897248287Sjfv		} else {
898248287Sjfv			return IXGBE_ERR_PARAM;
899248287Sjfv		}
900248287Sjfv	}
901248287Sjfv
902248287Sjfv	if (pba_word[0] == IXGBE_PBANUM_PTR_GUARD) {
903248287Sjfv		if (eeprom_buf == NULL) {
904248287Sjfv			ret_val = hw->eeprom.ops.read(hw, pba_word[1] + 0,
905248287Sjfv						      &length);
906248287Sjfv			if (ret_val)
907248287Sjfv				return ret_val;
908248287Sjfv		} else {
909248287Sjfv			if (eeprom_buf_size > pba_word[1])
910248287Sjfv				length = eeprom_buf[pba_word[1] + 0];
911248287Sjfv			else
912248287Sjfv				return IXGBE_ERR_PARAM;
913248287Sjfv		}
914248287Sjfv
915248287Sjfv		if (length == 0xFFFF || length == 0)
916248287Sjfv			return IXGBE_ERR_PBA_SECTION;
917248287Sjfv	} else {
918248287Sjfv		/* PBA number in legacy format, there is no PBA Block. */
919248287Sjfv		length = 0;
920248287Sjfv	}
921248287Sjfv
922248287Sjfv	if (pba_block_size != NULL)
923248287Sjfv		*pba_block_size = length;
924248287Sjfv
925248287Sjfv	return IXGBE_SUCCESS;
926248287Sjfv}
927248287Sjfv
928248287Sjfv/**
929171384Sjfv *  ixgbe_get_mac_addr_generic - Generic get MAC address
930171384Sjfv *  @hw: pointer to hardware structure
931171384Sjfv *  @mac_addr: Adapter MAC address
932171384Sjfv *
933171384Sjfv *  Reads the adapter's MAC address from first Receive Address Register (RAR0)
934171384Sjfv *  A reset of the adapter must be performed prior to calling this function
935171384Sjfv *  in order for the MAC address to have been loaded from the EEPROM into RAR0
936171384Sjfv **/
937171384Sjfvs32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
938171384Sjfv{
939171384Sjfv	u32 rar_high;
940171384Sjfv	u32 rar_low;
941171384Sjfv	u16 i;
942171384Sjfv
943200239Sjfv	DEBUGFUNC("ixgbe_get_mac_addr_generic");
944200239Sjfv
945171384Sjfv	rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
946171384Sjfv	rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
947171384Sjfv
948171384Sjfv	for (i = 0; i < 4; i++)
949171384Sjfv		mac_addr[i] = (u8)(rar_low >> (i*8));
950171384Sjfv
951171384Sjfv	for (i = 0; i < 2; i++)
952171384Sjfv		mac_addr[i+4] = (u8)(rar_high >> (i*8));
953171384Sjfv
954171384Sjfv	return IXGBE_SUCCESS;
955171384Sjfv}
956171384Sjfv
957171384Sjfv/**
958252898Sjfv *  ixgbe_set_pci_config_data_generic - Generic store PCI bus info
959171384Sjfv *  @hw: pointer to hardware structure
960252898Sjfv *  @link_status: the link status returned by the PCI config space
961171384Sjfv *
962252898Sjfv *  Stores the PCI bus info (speed, width, type) within the ixgbe_hw structure
963171384Sjfv **/
964252898Sjfvvoid ixgbe_set_pci_config_data_generic(struct ixgbe_hw *hw, u16 link_status)
965171384Sjfv{
966185352Sjfv	struct ixgbe_mac_info *mac = &hw->mac;
967171384Sjfv
968171384Sjfv	hw->bus.type = ixgbe_bus_type_pci_express;
969171384Sjfv
970171384Sjfv	switch (link_status & IXGBE_PCI_LINK_WIDTH) {
971171384Sjfv	case IXGBE_PCI_LINK_WIDTH_1:
972171384Sjfv		hw->bus.width = ixgbe_bus_width_pcie_x1;
973171384Sjfv		break;
974171384Sjfv	case IXGBE_PCI_LINK_WIDTH_2:
975171384Sjfv		hw->bus.width = ixgbe_bus_width_pcie_x2;
976171384Sjfv		break;
977171384Sjfv	case IXGBE_PCI_LINK_WIDTH_4:
978171384Sjfv		hw->bus.width = ixgbe_bus_width_pcie_x4;
979171384Sjfv		break;
980171384Sjfv	case IXGBE_PCI_LINK_WIDTH_8:
981171384Sjfv		hw->bus.width = ixgbe_bus_width_pcie_x8;
982171384Sjfv		break;
983171384Sjfv	default:
984171384Sjfv		hw->bus.width = ixgbe_bus_width_unknown;
985171384Sjfv		break;
986171384Sjfv	}
987171384Sjfv
988171384Sjfv	switch (link_status & IXGBE_PCI_LINK_SPEED) {
989171384Sjfv	case IXGBE_PCI_LINK_SPEED_2500:
990171384Sjfv		hw->bus.speed = ixgbe_bus_speed_2500;
991171384Sjfv		break;
992171384Sjfv	case IXGBE_PCI_LINK_SPEED_5000:
993171384Sjfv		hw->bus.speed = ixgbe_bus_speed_5000;
994171384Sjfv		break;
995238263Sjfv	case IXGBE_PCI_LINK_SPEED_8000:
996238263Sjfv		hw->bus.speed = ixgbe_bus_speed_8000;
997238263Sjfv		break;
998171384Sjfv	default:
999171384Sjfv		hw->bus.speed = ixgbe_bus_speed_unknown;
1000171384Sjfv		break;
1001171384Sjfv	}
1002171384Sjfv
1003185352Sjfv	mac->ops.set_lan_id(hw);
1004252898Sjfv}
1005185352Sjfv
1006252898Sjfv/**
1007252898Sjfv *  ixgbe_get_bus_info_generic - Generic set PCI bus info
1008252898Sjfv *  @hw: pointer to hardware structure
1009252898Sjfv *
1010252898Sjfv *  Gets the PCI bus info (speed, width, type) then calls helper function to
1011252898Sjfv *  store this data within the ixgbe_hw structure.
1012252898Sjfv **/
1013252898Sjfvs32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
1014252898Sjfv{
1015252898Sjfv	u16 link_status;
1016252898Sjfv
1017252898Sjfv	DEBUGFUNC("ixgbe_get_bus_info_generic");
1018252898Sjfv
1019252898Sjfv	/* Get the negotiated link width and speed from PCI config space */
1020252898Sjfv	link_status = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_LINK_STATUS);
1021252898Sjfv
1022252898Sjfv	ixgbe_set_pci_config_data_generic(hw, link_status);
1023252898Sjfv
1024171384Sjfv	return IXGBE_SUCCESS;
1025171384Sjfv}
1026171384Sjfv
1027171384Sjfv/**
1028185352Sjfv *  ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
1029185352Sjfv *  @hw: pointer to the HW structure
1030185352Sjfv *
1031185352Sjfv *  Determines the LAN function id by reading memory-mapped registers
1032185352Sjfv *  and swaps the port value if requested.
1033185352Sjfv **/
1034185352Sjfvvoid ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
1035185352Sjfv{
1036185352Sjfv	struct ixgbe_bus_info *bus = &hw->bus;
1037185352Sjfv	u32 reg;
1038185352Sjfv
1039200239Sjfv	DEBUGFUNC("ixgbe_set_lan_id_multi_port_pcie");
1040200239Sjfv
1041185352Sjfv	reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
1042185352Sjfv	bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
1043190873Sjfv	bus->lan_id = bus->func;
1044185352Sjfv
1045185352Sjfv	/* check for a port swap */
1046185352Sjfv	reg = IXGBE_READ_REG(hw, IXGBE_FACTPS);
1047185352Sjfv	if (reg & IXGBE_FACTPS_LFS)
1048185352Sjfv		bus->func ^= 0x1;
1049185352Sjfv}
1050185352Sjfv
1051185352Sjfv/**
1052179055Sjfv *  ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
1053171384Sjfv *  @hw: pointer to hardware structure
1054171384Sjfv *
1055171384Sjfv *  Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
1056171384Sjfv *  disables transmit and receive units. The adapter_stopped flag is used by
1057171384Sjfv *  the shared code and drivers to determine if the adapter is in a stopped
1058171384Sjfv *  state and should not touch the hardware.
1059171384Sjfv **/
1060171384Sjfvs32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
1061171384Sjfv{
1062171384Sjfv	u32 reg_val;
1063171384Sjfv	u16 i;
1064171384Sjfv
1065200239Sjfv	DEBUGFUNC("ixgbe_stop_adapter_generic");
1066200239Sjfv
1067171384Sjfv	/*
1068171384Sjfv	 * Set the adapter_stopped flag so other driver functions stop touching
1069171384Sjfv	 * the hardware
1070171384Sjfv	 */
1071171384Sjfv	hw->adapter_stopped = TRUE;
1072171384Sjfv
1073171384Sjfv	/* Disable the receive unit */
1074235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, 0);
1075171384Sjfv
1076235528Sjfv	/* Clear interrupt mask to stop interrupts from being generated */
1077171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1078171384Sjfv
1079235528Sjfv	/* Clear any pending interrupts, flush previous writes */
1080171384Sjfv	IXGBE_READ_REG(hw, IXGBE_EICR);
1081171384Sjfv
1082171384Sjfv	/* Disable the transmit unit.  Each queue must be disabled. */
1083235528Sjfv	for (i = 0; i < hw->mac.max_tx_queues; i++)
1084235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
1085235528Sjfv
1086235528Sjfv	/* Disable the receive unit by stopping each queue */
1087235528Sjfv	for (i = 0; i < hw->mac.max_rx_queues; i++) {
1088235528Sjfv		reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1089235528Sjfv		reg_val &= ~IXGBE_RXDCTL_ENABLE;
1090235528Sjfv		reg_val |= IXGBE_RXDCTL_SWFLSH;
1091235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
1092171384Sjfv	}
1093171384Sjfv
1094235528Sjfv	/* flush all queues disables */
1095235528Sjfv	IXGBE_WRITE_FLUSH(hw);
1096235528Sjfv	msec_delay(2);
1097235528Sjfv
1098179055Sjfv	/*
1099179055Sjfv	 * Prevent the PCI-E bus from from hanging by disabling PCI-E master
1100179055Sjfv	 * access and verify no pending requests
1101179055Sjfv	 */
1102235528Sjfv	return ixgbe_disable_pcie_master(hw);
1103171384Sjfv}
1104171384Sjfv
1105171384Sjfv/**
1106171384Sjfv *  ixgbe_led_on_generic - Turns on the software controllable LEDs.
1107171384Sjfv *  @hw: pointer to hardware structure
1108171384Sjfv *  @index: led number to turn on
1109171384Sjfv **/
1110171384Sjfvs32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
1111171384Sjfv{
1112171384Sjfv	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1113171384Sjfv
1114200239Sjfv	DEBUGFUNC("ixgbe_led_on_generic");
1115200239Sjfv
1116171384Sjfv	/* To turn on the LED, set mode to ON. */
1117171384Sjfv	led_reg &= ~IXGBE_LED_MODE_MASK(index);
1118171384Sjfv	led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
1119171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
1120179055Sjfv	IXGBE_WRITE_FLUSH(hw);
1121171384Sjfv
1122171384Sjfv	return IXGBE_SUCCESS;
1123171384Sjfv}
1124171384Sjfv
1125171384Sjfv/**
1126171384Sjfv *  ixgbe_led_off_generic - Turns off the software controllable LEDs.
1127171384Sjfv *  @hw: pointer to hardware structure
1128171384Sjfv *  @index: led number to turn off
1129171384Sjfv **/
1130171384Sjfvs32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
1131171384Sjfv{
1132171384Sjfv	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1133171384Sjfv
1134200239Sjfv	DEBUGFUNC("ixgbe_led_off_generic");
1135200239Sjfv
1136171384Sjfv	/* To turn off the LED, set mode to OFF. */
1137171384Sjfv	led_reg &= ~IXGBE_LED_MODE_MASK(index);
1138171384Sjfv	led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
1139171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
1140179055Sjfv	IXGBE_WRITE_FLUSH(hw);
1141171384Sjfv
1142171384Sjfv	return IXGBE_SUCCESS;
1143171384Sjfv}
1144171384Sjfv
1145171384Sjfv/**
1146171384Sjfv *  ixgbe_init_eeprom_params_generic - Initialize EEPROM params
1147171384Sjfv *  @hw: pointer to hardware structure
1148171384Sjfv *
1149171384Sjfv *  Initializes the EEPROM parameters ixgbe_eeprom_info within the
1150171384Sjfv *  ixgbe_hw struct in order to set up EEPROM access.
1151171384Sjfv **/
1152171384Sjfvs32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
1153171384Sjfv{
1154171384Sjfv	struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
1155171384Sjfv	u32 eec;
1156171384Sjfv	u16 eeprom_size;
1157171384Sjfv
1158200239Sjfv	DEBUGFUNC("ixgbe_init_eeprom_params_generic");
1159200239Sjfv
1160171384Sjfv	if (eeprom->type == ixgbe_eeprom_uninitialized) {
1161171384Sjfv		eeprom->type = ixgbe_eeprom_none;
1162181003Sjfv		/* Set default semaphore delay to 10ms which is a well
1163181003Sjfv		 * tested value */
1164181003Sjfv		eeprom->semaphore_delay = 10;
1165235528Sjfv		/* Clear EEPROM page size, it will be initialized as needed */
1166235528Sjfv		eeprom->word_page_size = 0;
1167171384Sjfv
1168171384Sjfv		/*
1169171384Sjfv		 * Check for EEPROM present first.
1170171384Sjfv		 * If not present leave as none
1171171384Sjfv		 */
1172171384Sjfv		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1173171384Sjfv		if (eec & IXGBE_EEC_PRES) {
1174171384Sjfv			eeprom->type = ixgbe_eeprom_spi;
1175171384Sjfv
1176171384Sjfv			/*
1177171384Sjfv			 * SPI EEPROM is assumed here.  This code would need to
1178171384Sjfv			 * change if a future EEPROM is not SPI.
1179171384Sjfv			 */
1180171384Sjfv			eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
1181235528Sjfv					    IXGBE_EEC_SIZE_SHIFT);
1182171384Sjfv			eeprom->word_size = 1 << (eeprom_size +
1183235528Sjfv					     IXGBE_EEPROM_WORD_SIZE_SHIFT);
1184171384Sjfv		}
1185171384Sjfv
1186171384Sjfv		if (eec & IXGBE_EEC_ADDR_SIZE)
1187171384Sjfv			eeprom->address_bits = 16;
1188171384Sjfv		else
1189171384Sjfv			eeprom->address_bits = 8;
1190171384Sjfv		DEBUGOUT3("Eeprom params: type = %d, size = %d, address bits: "
1191235528Sjfv			  "%d\n", eeprom->type, eeprom->word_size,
1192235528Sjfv			  eeprom->address_bits);
1193171384Sjfv	}
1194171384Sjfv
1195171384Sjfv	return IXGBE_SUCCESS;
1196171384Sjfv}
1197171384Sjfv
1198171384Sjfv/**
1199235528Sjfv *  ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
1200171384Sjfv *  @hw: pointer to hardware structure
1201235528Sjfv *  @offset: offset within the EEPROM to write
1202235528Sjfv *  @words: number of word(s)
1203235528Sjfv *  @data: 16 bit word(s) to write to EEPROM
1204171384Sjfv *
1205235528Sjfv *  Reads 16 bit word(s) from EEPROM through bit-bang method
1206171384Sjfv **/
1207235528Sjfvs32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1208235528Sjfv					       u16 words, u16 *data)
1209171384Sjfv{
1210235528Sjfv	s32 status = IXGBE_SUCCESS;
1211235528Sjfv	u16 i, count;
1212171384Sjfv
1213235528Sjfv	DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang_generic");
1214200239Sjfv
1215179055Sjfv	hw->eeprom.ops.init_params(hw);
1216179055Sjfv
1217235528Sjfv	if (words == 0) {
1218235528Sjfv		status = IXGBE_ERR_INVALID_ARGUMENT;
1219235528Sjfv		goto out;
1220235528Sjfv	}
1221235528Sjfv
1222235528Sjfv	if (offset + words > hw->eeprom.word_size) {
1223179055Sjfv		status = IXGBE_ERR_EEPROM;
1224179055Sjfv		goto out;
1225179055Sjfv	}
1226179055Sjfv
1227235528Sjfv	/*
1228235528Sjfv	 * The EEPROM page size cannot be queried from the chip. We do lazy
1229235528Sjfv	 * initialization. It is worth to do that when we write large buffer.
1230235528Sjfv	 */
1231235528Sjfv	if ((hw->eeprom.word_page_size == 0) &&
1232235528Sjfv	    (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
1233235528Sjfv		ixgbe_detect_eeprom_page_size_generic(hw, offset);
1234235528Sjfv
1235235528Sjfv	/*
1236235528Sjfv	 * We cannot hold synchronization semaphores for too long
1237235528Sjfv	 * to avoid other entity starvation. However it is more efficient
1238235528Sjfv	 * to read in bursts than synchronizing access for each word.
1239235528Sjfv	 */
1240235528Sjfv	for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
1241235528Sjfv		count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
1242235528Sjfv			IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
1243235528Sjfv		status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
1244235528Sjfv							    count, &data[i]);
1245235528Sjfv
1246235528Sjfv		if (status != IXGBE_SUCCESS)
1247235528Sjfv			break;
1248235528Sjfv	}
1249235528Sjfv
1250235528Sjfvout:
1251235528Sjfv	return status;
1252235528Sjfv}
1253235528Sjfv
1254235528Sjfv/**
1255235528Sjfv *  ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
1256235528Sjfv *  @hw: pointer to hardware structure
1257235528Sjfv *  @offset: offset within the EEPROM to be written to
1258235528Sjfv *  @words: number of word(s)
1259235528Sjfv *  @data: 16 bit word(s) to be written to the EEPROM
1260235528Sjfv *
1261235528Sjfv *  If ixgbe_eeprom_update_checksum is not called after this function, the
1262235528Sjfv *  EEPROM will most likely contain an invalid checksum.
1263235528Sjfv **/
1264235528Sjfvstatic s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
1265235528Sjfv					      u16 words, u16 *data)
1266235528Sjfv{
1267235528Sjfv	s32 status;
1268235528Sjfv	u16 word;
1269235528Sjfv	u16 page_size;
1270235528Sjfv	u16 i;
1271235528Sjfv	u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
1272235528Sjfv
1273235528Sjfv	DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang");
1274235528Sjfv
1275171384Sjfv	/* Prepare the EEPROM for writing  */
1276171384Sjfv	status = ixgbe_acquire_eeprom(hw);
1277171384Sjfv
1278171384Sjfv	if (status == IXGBE_SUCCESS) {
1279171384Sjfv		if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
1280171384Sjfv			ixgbe_release_eeprom(hw);
1281171384Sjfv			status = IXGBE_ERR_EEPROM;
1282171384Sjfv		}
1283171384Sjfv	}
1284171384Sjfv
1285171384Sjfv	if (status == IXGBE_SUCCESS) {
1286235528Sjfv		for (i = 0; i < words; i++) {
1287235528Sjfv			ixgbe_standby_eeprom(hw);
1288171384Sjfv
1289235528Sjfv			/*  Send the WRITE ENABLE command (8 bit opcode )  */
1290235528Sjfv			ixgbe_shift_out_eeprom_bits(hw,
1291235528Sjfv						   IXGBE_EEPROM_WREN_OPCODE_SPI,
1292235528Sjfv						   IXGBE_EEPROM_OPCODE_BITS);
1293171384Sjfv
1294235528Sjfv			ixgbe_standby_eeprom(hw);
1295171384Sjfv
1296235528Sjfv			/*
1297235528Sjfv			 * Some SPI eeproms use the 8th address bit embedded
1298235528Sjfv			 * in the opcode
1299235528Sjfv			 */
1300235528Sjfv			if ((hw->eeprom.address_bits == 8) &&
1301235528Sjfv			    ((offset + i) >= 128))
1302235528Sjfv				write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
1303171384Sjfv
1304235528Sjfv			/* Send the Write command (8-bit opcode + addr) */
1305235528Sjfv			ixgbe_shift_out_eeprom_bits(hw, write_opcode,
1306235528Sjfv						    IXGBE_EEPROM_OPCODE_BITS);
1307235528Sjfv			ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
1308235528Sjfv						    hw->eeprom.address_bits);
1309171384Sjfv
1310235528Sjfv			page_size = hw->eeprom.word_page_size;
1311171384Sjfv
1312235528Sjfv			/* Send the data in burst via SPI*/
1313235528Sjfv			do {
1314235528Sjfv				word = data[i];
1315235528Sjfv				word = (word >> 8) | (word << 8);
1316235528Sjfv				ixgbe_shift_out_eeprom_bits(hw, word, 16);
1317235528Sjfv
1318235528Sjfv				if (page_size == 0)
1319235528Sjfv					break;
1320235528Sjfv
1321235528Sjfv				/* do not wrap around page */
1322235528Sjfv				if (((offset + i) & (page_size - 1)) ==
1323235528Sjfv				    (page_size - 1))
1324235528Sjfv					break;
1325235528Sjfv			} while (++i < words);
1326235528Sjfv
1327235528Sjfv			ixgbe_standby_eeprom(hw);
1328235528Sjfv			msec_delay(10);
1329235528Sjfv		}
1330171384Sjfv		/* Done with writing - release the EEPROM */
1331171384Sjfv		ixgbe_release_eeprom(hw);
1332171384Sjfv	}
1333171384Sjfv
1334171384Sjfv	return status;
1335171384Sjfv}
1336171384Sjfv
1337171384Sjfv/**
1338235528Sjfv *  ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
1339171384Sjfv *  @hw: pointer to hardware structure
1340235528Sjfv *  @offset: offset within the EEPROM to be written to
1341235528Sjfv *  @data: 16 bit word to be written to the EEPROM
1342171384Sjfv *
1343235528Sjfv *  If ixgbe_eeprom_update_checksum is not called after this function, the
1344235528Sjfv *  EEPROM will most likely contain an invalid checksum.
1345171384Sjfv **/
1346235528Sjfvs32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1347171384Sjfv{
1348171384Sjfv	s32 status;
1349171384Sjfv
1350235528Sjfv	DEBUGFUNC("ixgbe_write_eeprom_generic");
1351200239Sjfv
1352179055Sjfv	hw->eeprom.ops.init_params(hw);
1353179055Sjfv
1354179055Sjfv	if (offset >= hw->eeprom.word_size) {
1355179055Sjfv		status = IXGBE_ERR_EEPROM;
1356179055Sjfv		goto out;
1357179055Sjfv	}
1358179055Sjfv
1359235528Sjfv	status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
1360235528Sjfv
1361235528Sjfvout:
1362235528Sjfv	return status;
1363235528Sjfv}
1364235528Sjfv
1365235528Sjfv/**
1366235528Sjfv *  ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
1367235528Sjfv *  @hw: pointer to hardware structure
1368235528Sjfv *  @offset: offset within the EEPROM to be read
1369235528Sjfv *  @data: read 16 bit words(s) from EEPROM
1370235528Sjfv *  @words: number of word(s)
1371235528Sjfv *
1372235528Sjfv *  Reads 16 bit word(s) from EEPROM through bit-bang method
1373235528Sjfv **/
1374235528Sjfvs32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1375235528Sjfv					      u16 words, u16 *data)
1376235528Sjfv{
1377235528Sjfv	s32 status = IXGBE_SUCCESS;
1378235528Sjfv	u16 i, count;
1379235528Sjfv
1380235528Sjfv	DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang_generic");
1381235528Sjfv
1382235528Sjfv	hw->eeprom.ops.init_params(hw);
1383235528Sjfv
1384235528Sjfv	if (words == 0) {
1385235528Sjfv		status = IXGBE_ERR_INVALID_ARGUMENT;
1386235528Sjfv		goto out;
1387235528Sjfv	}
1388235528Sjfv
1389235528Sjfv	if (offset + words > hw->eeprom.word_size) {
1390235528Sjfv		status = IXGBE_ERR_EEPROM;
1391235528Sjfv		goto out;
1392235528Sjfv	}
1393235528Sjfv
1394235528Sjfv	/*
1395235528Sjfv	 * We cannot hold synchronization semaphores for too long
1396235528Sjfv	 * to avoid other entity starvation. However it is more efficient
1397235528Sjfv	 * to read in bursts than synchronizing access for each word.
1398235528Sjfv	 */
1399235528Sjfv	for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
1400235528Sjfv		count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
1401235528Sjfv			IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
1402235528Sjfv
1403235528Sjfv		status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
1404235528Sjfv							   count, &data[i]);
1405235528Sjfv
1406235528Sjfv		if (status != IXGBE_SUCCESS)
1407235528Sjfv			break;
1408235528Sjfv	}
1409235528Sjfv
1410235528Sjfvout:
1411235528Sjfv	return status;
1412235528Sjfv}
1413235528Sjfv
1414235528Sjfv/**
1415235528Sjfv *  ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
1416235528Sjfv *  @hw: pointer to hardware structure
1417235528Sjfv *  @offset: offset within the EEPROM to be read
1418235528Sjfv *  @words: number of word(s)
1419235528Sjfv *  @data: read 16 bit word(s) from EEPROM
1420235528Sjfv *
1421235528Sjfv *  Reads 16 bit word(s) from EEPROM through bit-bang method
1422235528Sjfv **/
1423235528Sjfvstatic s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
1424235528Sjfv					     u16 words, u16 *data)
1425235528Sjfv{
1426235528Sjfv	s32 status;
1427235528Sjfv	u16 word_in;
1428235528Sjfv	u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
1429235528Sjfv	u16 i;
1430235528Sjfv
1431235528Sjfv	DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang");
1432235528Sjfv
1433171384Sjfv	/* Prepare the EEPROM for reading  */
1434171384Sjfv	status = ixgbe_acquire_eeprom(hw);
1435171384Sjfv
1436171384Sjfv	if (status == IXGBE_SUCCESS) {
1437171384Sjfv		if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
1438171384Sjfv			ixgbe_release_eeprom(hw);
1439171384Sjfv			status = IXGBE_ERR_EEPROM;
1440171384Sjfv		}
1441171384Sjfv	}
1442171384Sjfv
1443171384Sjfv	if (status == IXGBE_SUCCESS) {
1444235528Sjfv		for (i = 0; i < words; i++) {
1445235528Sjfv			ixgbe_standby_eeprom(hw);
1446235528Sjfv			/*
1447235528Sjfv			 * Some SPI eeproms use the 8th address bit embedded
1448235528Sjfv			 * in the opcode
1449235528Sjfv			 */
1450235528Sjfv			if ((hw->eeprom.address_bits == 8) &&
1451235528Sjfv			    ((offset + i) >= 128))
1452235528Sjfv				read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
1453171384Sjfv
1454235528Sjfv			/* Send the READ command (opcode + addr) */
1455235528Sjfv			ixgbe_shift_out_eeprom_bits(hw, read_opcode,
1456235528Sjfv						    IXGBE_EEPROM_OPCODE_BITS);
1457235528Sjfv			ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
1458235528Sjfv						    hw->eeprom.address_bits);
1459171384Sjfv
1460235528Sjfv			/* Read the data. */
1461235528Sjfv			word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
1462235528Sjfv			data[i] = (word_in >> 8) | (word_in << 8);
1463235528Sjfv		}
1464171384Sjfv
1465171384Sjfv		/* End this read operation */
1466171384Sjfv		ixgbe_release_eeprom(hw);
1467171384Sjfv	}
1468171384Sjfv
1469235528Sjfv	return status;
1470235528Sjfv}
1471235528Sjfv
1472235528Sjfv/**
1473235528Sjfv *  ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
1474235528Sjfv *  @hw: pointer to hardware structure
1475235528Sjfv *  @offset: offset within the EEPROM to be read
1476235528Sjfv *  @data: read 16 bit value from EEPROM
1477235528Sjfv *
1478235528Sjfv *  Reads 16 bit value from EEPROM through bit-bang method
1479235528Sjfv **/
1480235528Sjfvs32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1481235528Sjfv				       u16 *data)
1482235528Sjfv{
1483235528Sjfv	s32 status;
1484235528Sjfv
1485235528Sjfv	DEBUGFUNC("ixgbe_read_eeprom_bit_bang_generic");
1486235528Sjfv
1487235528Sjfv	hw->eeprom.ops.init_params(hw);
1488235528Sjfv
1489235528Sjfv	if (offset >= hw->eeprom.word_size) {
1490235528Sjfv		status = IXGBE_ERR_EEPROM;
1491235528Sjfv		goto out;
1492235528Sjfv	}
1493235528Sjfv
1494235528Sjfv	status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1495235528Sjfv
1496179055Sjfvout:
1497171384Sjfv	return status;
1498171384Sjfv}
1499171384Sjfv
1500171384Sjfv/**
1501235528Sjfv *  ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
1502171384Sjfv *  @hw: pointer to hardware structure
1503235528Sjfv *  @offset: offset of word in the EEPROM to read
1504235528Sjfv *  @words: number of word(s)
1505235528Sjfv *  @data: 16 bit word(s) from the EEPROM
1506171384Sjfv *
1507235528Sjfv *  Reads a 16 bit word(s) from the EEPROM using the EERD register.
1508171384Sjfv **/
1509235528Sjfvs32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1510235528Sjfv				   u16 words, u16 *data)
1511171384Sjfv{
1512171384Sjfv	u32 eerd;
1513235528Sjfv	s32 status = IXGBE_SUCCESS;
1514235528Sjfv	u32 i;
1515171384Sjfv
1516235528Sjfv	DEBUGFUNC("ixgbe_read_eerd_buffer_generic");
1517200239Sjfv
1518179055Sjfv	hw->eeprom.ops.init_params(hw);
1519179055Sjfv
1520235528Sjfv	if (words == 0) {
1521235528Sjfv		status = IXGBE_ERR_INVALID_ARGUMENT;
1522252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM words");
1523235528Sjfv		goto out;
1524235528Sjfv	}
1525235528Sjfv
1526179055Sjfv	if (offset >= hw->eeprom.word_size) {
1527179055Sjfv		status = IXGBE_ERR_EEPROM;
1528252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM offset");
1529179055Sjfv		goto out;
1530179055Sjfv	}
1531179055Sjfv
1532235528Sjfv	for (i = 0; i < words; i++) {
1533248287Sjfv		eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1534235528Sjfv		       IXGBE_EEPROM_RW_REG_START;
1535171384Sjfv
1536235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
1537235528Sjfv		status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
1538171384Sjfv
1539235528Sjfv		if (status == IXGBE_SUCCESS) {
1540235528Sjfv			data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
1541235528Sjfv				   IXGBE_EEPROM_RW_REG_DATA);
1542235528Sjfv		} else {
1543235528Sjfv			DEBUGOUT("Eeprom read timed out\n");
1544235528Sjfv			goto out;
1545235528Sjfv		}
1546235528Sjfv	}
1547235528Sjfvout:
1548235528Sjfv	return status;
1549235528Sjfv}
1550171384Sjfv
1551235528Sjfv/**
1552235528Sjfv *  ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
1553235528Sjfv *  @hw: pointer to hardware structure
1554235528Sjfv *  @offset: offset within the EEPROM to be used as a scratch pad
1555235528Sjfv *
1556235528Sjfv *  Discover EEPROM page size by writing marching data at given offset.
1557235528Sjfv *  This function is called only when we are writing a new large buffer
1558235528Sjfv *  at given offset so the data would be overwritten anyway.
1559235528Sjfv **/
1560235528Sjfvstatic s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
1561235528Sjfv						 u16 offset)
1562235528Sjfv{
1563235528Sjfv	u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
1564235528Sjfv	s32 status = IXGBE_SUCCESS;
1565235528Sjfv	u16 i;
1566235528Sjfv
1567235528Sjfv	DEBUGFUNC("ixgbe_detect_eeprom_page_size_generic");
1568235528Sjfv
1569235528Sjfv	for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
1570235528Sjfv		data[i] = i;
1571235528Sjfv
1572235528Sjfv	hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
1573235528Sjfv	status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
1574235528Sjfv					     IXGBE_EEPROM_PAGE_SIZE_MAX, data);
1575235528Sjfv	hw->eeprom.word_page_size = 0;
1576235528Sjfv	if (status != IXGBE_SUCCESS)
1577235528Sjfv		goto out;
1578235528Sjfv
1579235528Sjfv	status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1580235528Sjfv	if (status != IXGBE_SUCCESS)
1581235528Sjfv		goto out;
1582235528Sjfv
1583235528Sjfv	/*
1584235528Sjfv	 * When writing in burst more than the actual page size
1585235528Sjfv	 * EEPROM address wraps around current page.
1586235528Sjfv	 */
1587235528Sjfv	hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
1588235528Sjfv
1589235528Sjfv	DEBUGOUT1("Detected EEPROM page size = %d words.",
1590235528Sjfv		  hw->eeprom.word_page_size);
1591179055Sjfvout:
1592171384Sjfv	return status;
1593171384Sjfv}
1594171384Sjfv
1595171384Sjfv/**
1596235528Sjfv *  ixgbe_read_eerd_generic - Read EEPROM word using EERD
1597215911Sjfv *  @hw: pointer to hardware structure
1598235528Sjfv *  @offset: offset of  word in the EEPROM to read
1599235528Sjfv *  @data: word read from the EEPROM
1600235528Sjfv *
1601235528Sjfv *  Reads a 16 bit word from the EEPROM using the EERD register.
1602235528Sjfv **/
1603235528Sjfvs32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
1604235528Sjfv{
1605235528Sjfv	return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
1606235528Sjfv}
1607235528Sjfv
1608235528Sjfv/**
1609235528Sjfv *  ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
1610235528Sjfv *  @hw: pointer to hardware structure
1611215911Sjfv *  @offset: offset of  word in the EEPROM to write
1612235528Sjfv *  @words: number of word(s)
1613235528Sjfv *  @data: word(s) write to the EEPROM
1614215911Sjfv *
1615235528Sjfv *  Write a 16 bit word(s) to the EEPROM using the EEWR register.
1616215911Sjfv **/
1617235528Sjfvs32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1618235528Sjfv				    u16 words, u16 *data)
1619215911Sjfv{
1620215911Sjfv	u32 eewr;
1621235528Sjfv	s32 status = IXGBE_SUCCESS;
1622235528Sjfv	u16 i;
1623215911Sjfv
1624215911Sjfv	DEBUGFUNC("ixgbe_write_eewr_generic");
1625215911Sjfv
1626215911Sjfv	hw->eeprom.ops.init_params(hw);
1627215911Sjfv
1628235528Sjfv	if (words == 0) {
1629235528Sjfv		status = IXGBE_ERR_INVALID_ARGUMENT;
1630252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM words");
1631235528Sjfv		goto out;
1632235528Sjfv	}
1633235528Sjfv
1634215911Sjfv	if (offset >= hw->eeprom.word_size) {
1635215911Sjfv		status = IXGBE_ERR_EEPROM;
1636252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM offset");
1637215911Sjfv		goto out;
1638215911Sjfv	}
1639215911Sjfv
1640235528Sjfv	for (i = 0; i < words; i++) {
1641235528Sjfv		eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1642235528Sjfv			(data[i] << IXGBE_EEPROM_RW_REG_DATA) |
1643235528Sjfv			IXGBE_EEPROM_RW_REG_START;
1644215911Sjfv
1645235528Sjfv		status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1646235528Sjfv		if (status != IXGBE_SUCCESS) {
1647235528Sjfv			DEBUGOUT("Eeprom write EEWR timed out\n");
1648235528Sjfv			goto out;
1649235528Sjfv		}
1650215911Sjfv
1651235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
1652215911Sjfv
1653235528Sjfv		status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1654235528Sjfv		if (status != IXGBE_SUCCESS) {
1655235528Sjfv			DEBUGOUT("Eeprom write EEWR timed out\n");
1656235528Sjfv			goto out;
1657235528Sjfv		}
1658215911Sjfv	}
1659215911Sjfv
1660215911Sjfvout:
1661215911Sjfv	return status;
1662215911Sjfv}
1663215911Sjfv
1664215911Sjfv/**
1665235528Sjfv *  ixgbe_write_eewr_generic - Write EEPROM word using EEWR
1666235528Sjfv *  @hw: pointer to hardware structure
1667235528Sjfv *  @offset: offset of  word in the EEPROM to write
1668235528Sjfv *  @data: word write to the EEPROM
1669235528Sjfv *
1670235528Sjfv *  Write a 16 bit word to the EEPROM using the EEWR register.
1671235528Sjfv **/
1672235528Sjfvs32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1673235528Sjfv{
1674235528Sjfv	return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
1675235528Sjfv}
1676235528Sjfv
1677235528Sjfv/**
1678200239Sjfv *  ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
1679171384Sjfv *  @hw: pointer to hardware structure
1680200239Sjfv *  @ee_reg: EEPROM flag for polling
1681171384Sjfv *
1682200239Sjfv *  Polls the status bit (bit 1) of the EERD or EEWR to determine when the
1683200239Sjfv *  read or write is done respectively.
1684171384Sjfv **/
1685200239Sjfvs32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
1686171384Sjfv{
1687171384Sjfv	u32 i;
1688171384Sjfv	u32 reg;
1689171384Sjfv	s32 status = IXGBE_ERR_EEPROM;
1690171384Sjfv
1691200239Sjfv	DEBUGFUNC("ixgbe_poll_eerd_eewr_done");
1692200239Sjfv
1693200239Sjfv	for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
1694200239Sjfv		if (ee_reg == IXGBE_NVM_POLL_READ)
1695200239Sjfv			reg = IXGBE_READ_REG(hw, IXGBE_EERD);
1696200239Sjfv		else
1697200239Sjfv			reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
1698200239Sjfv
1699200239Sjfv		if (reg & IXGBE_EEPROM_RW_REG_DONE) {
1700171384Sjfv			status = IXGBE_SUCCESS;
1701171384Sjfv			break;
1702171384Sjfv		}
1703171384Sjfv		usec_delay(5);
1704171384Sjfv	}
1705252898Sjfv
1706252898Sjfv	if (i == IXGBE_EERD_EEWR_ATTEMPTS)
1707252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_POLLING,
1708252898Sjfv			     "EEPROM read/write done polling timed out");
1709252898Sjfv
1710171384Sjfv	return status;
1711171384Sjfv}
1712171384Sjfv
1713171384Sjfv/**
1714171384Sjfv *  ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
1715171384Sjfv *  @hw: pointer to hardware structure
1716171384Sjfv *
1717171384Sjfv *  Prepares EEPROM for access using bit-bang method. This function should
1718171384Sjfv *  be called before issuing a command to the EEPROM.
1719171384Sjfv **/
1720171384Sjfvstatic s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
1721171384Sjfv{
1722171384Sjfv	s32 status = IXGBE_SUCCESS;
1723171384Sjfv	u32 eec;
1724171384Sjfv	u32 i;
1725171384Sjfv
1726200239Sjfv	DEBUGFUNC("ixgbe_acquire_eeprom");
1727200239Sjfv
1728235528Sjfv	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM)
1729235528Sjfv	    != IXGBE_SUCCESS)
1730171384Sjfv		status = IXGBE_ERR_SWFW_SYNC;
1731171384Sjfv
1732171384Sjfv	if (status == IXGBE_SUCCESS) {
1733171384Sjfv		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1734171384Sjfv
1735171384Sjfv		/* Request EEPROM Access */
1736171384Sjfv		eec |= IXGBE_EEC_REQ;
1737171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1738171384Sjfv
1739171384Sjfv		for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
1740171384Sjfv			eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1741171384Sjfv			if (eec & IXGBE_EEC_GNT)
1742171384Sjfv				break;
1743171384Sjfv			usec_delay(5);
1744171384Sjfv		}
1745171384Sjfv
1746179055Sjfv		/* Release if grant not acquired */
1747171384Sjfv		if (!(eec & IXGBE_EEC_GNT)) {
1748171384Sjfv			eec &= ~IXGBE_EEC_REQ;
1749171384Sjfv			IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1750171384Sjfv			DEBUGOUT("Could not acquire EEPROM grant\n");
1751171384Sjfv
1752235528Sjfv			hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1753171384Sjfv			status = IXGBE_ERR_EEPROM;
1754171384Sjfv		}
1755171384Sjfv
1756215911Sjfv		/* Setup EEPROM for Read/Write */
1757215911Sjfv		if (status == IXGBE_SUCCESS) {
1758215911Sjfv			/* Clear CS and SK */
1759215911Sjfv			eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
1760215911Sjfv			IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1761215911Sjfv			IXGBE_WRITE_FLUSH(hw);
1762215911Sjfv			usec_delay(1);
1763215911Sjfv		}
1764171384Sjfv	}
1765171384Sjfv	return status;
1766171384Sjfv}
1767171384Sjfv
1768171384Sjfv/**
1769171384Sjfv *  ixgbe_get_eeprom_semaphore - Get hardware semaphore
1770171384Sjfv *  @hw: pointer to hardware structure
1771171384Sjfv *
1772171384Sjfv *  Sets the hardware semaphores so EEPROM access can occur for bit-bang method
1773171384Sjfv **/
1774171384Sjfvstatic s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
1775171384Sjfv{
1776171384Sjfv	s32 status = IXGBE_ERR_EEPROM;
1777194875Sjfv	u32 timeout = 2000;
1778171384Sjfv	u32 i;
1779171384Sjfv	u32 swsm;
1780171384Sjfv
1781200239Sjfv	DEBUGFUNC("ixgbe_get_eeprom_semaphore");
1782200239Sjfv
1783215911Sjfv
1784171384Sjfv	/* Get SMBI software semaphore between device drivers first */
1785171384Sjfv	for (i = 0; i < timeout; i++) {
1786171384Sjfv		/*
1787171384Sjfv		 * If the SMBI bit is 0 when we read it, then the bit will be
1788171384Sjfv		 * set and we have the semaphore
1789171384Sjfv		 */
1790171384Sjfv		swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1791171384Sjfv		if (!(swsm & IXGBE_SWSM_SMBI)) {
1792171384Sjfv			status = IXGBE_SUCCESS;
1793171384Sjfv			break;
1794171384Sjfv		}
1795190873Sjfv		usec_delay(50);
1796171384Sjfv	}
1797171384Sjfv
1798235528Sjfv	if (i == timeout) {
1799235528Sjfv		DEBUGOUT("Driver can't access the Eeprom - SMBI Semaphore "
1800235528Sjfv			 "not granted.\n");
1801235528Sjfv		/*
1802235528Sjfv		 * this release is particularly important because our attempts
1803235528Sjfv		 * above to get the semaphore may have succeeded, and if there
1804235528Sjfv		 * was a timeout, we should unconditionally clear the semaphore
1805235528Sjfv		 * bits to free the driver to make progress
1806235528Sjfv		 */
1807235528Sjfv		ixgbe_release_eeprom_semaphore(hw);
1808235528Sjfv
1809235528Sjfv		usec_delay(50);
1810235528Sjfv		/*
1811235528Sjfv		 * one last try
1812235528Sjfv		 * If the SMBI bit is 0 when we read it, then the bit will be
1813235528Sjfv		 * set and we have the semaphore
1814235528Sjfv		 */
1815235528Sjfv		swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1816235528Sjfv		if (!(swsm & IXGBE_SWSM_SMBI))
1817235528Sjfv			status = IXGBE_SUCCESS;
1818235528Sjfv	}
1819235528Sjfv
1820171384Sjfv	/* Now get the semaphore between SW/FW through the SWESMBI bit */
1821171384Sjfv	if (status == IXGBE_SUCCESS) {
1822171384Sjfv		for (i = 0; i < timeout; i++) {
1823171384Sjfv			swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1824171384Sjfv
1825171384Sjfv			/* Set the SW EEPROM semaphore bit to request access */
1826171384Sjfv			swsm |= IXGBE_SWSM_SWESMBI;
1827171384Sjfv			IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
1828171384Sjfv
1829171384Sjfv			/*
1830171384Sjfv			 * If we set the bit successfully then we got the
1831171384Sjfv			 * semaphore.
1832171384Sjfv			 */
1833171384Sjfv			swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1834171384Sjfv			if (swsm & IXGBE_SWSM_SWESMBI)
1835171384Sjfv				break;
1836171384Sjfv
1837171384Sjfv			usec_delay(50);
1838171384Sjfv		}
1839171384Sjfv
1840171384Sjfv		/*
1841171384Sjfv		 * Release semaphores and return error if SW EEPROM semaphore
1842171384Sjfv		 * was not granted because we don't have access to the EEPROM
1843171384Sjfv		 */
1844171384Sjfv		if (i >= timeout) {
1845252898Sjfv			ERROR_REPORT1(IXGBE_ERROR_POLLING,
1846252898Sjfv			    "SWESMBI Software EEPROM semaphore not granted.\n");
1847171384Sjfv			ixgbe_release_eeprom_semaphore(hw);
1848171384Sjfv			status = IXGBE_ERR_EEPROM;
1849171384Sjfv		}
1850190873Sjfv	} else {
1851252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_POLLING,
1852252898Sjfv			     "Software semaphore SMBI between device drivers "
1853252898Sjfv			     "not granted.\n");
1854171384Sjfv	}
1855171384Sjfv
1856171384Sjfv	return status;
1857171384Sjfv}
1858171384Sjfv
1859171384Sjfv/**
1860171384Sjfv *  ixgbe_release_eeprom_semaphore - Release hardware semaphore
1861171384Sjfv *  @hw: pointer to hardware structure
1862171384Sjfv *
1863171384Sjfv *  This function clears hardware semaphore bits.
1864171384Sjfv **/
1865171384Sjfvstatic void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
1866171384Sjfv{
1867171384Sjfv	u32 swsm;
1868171384Sjfv
1869200239Sjfv	DEBUGFUNC("ixgbe_release_eeprom_semaphore");
1870200239Sjfv
1871171384Sjfv	swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1872171384Sjfv
1873171384Sjfv	/* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
1874171384Sjfv	swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
1875171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
1876179055Sjfv	IXGBE_WRITE_FLUSH(hw);
1877171384Sjfv}
1878171384Sjfv
1879171384Sjfv/**
1880171384Sjfv *  ixgbe_ready_eeprom - Polls for EEPROM ready
1881171384Sjfv *  @hw: pointer to hardware structure
1882171384Sjfv **/
1883171384Sjfvstatic s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
1884171384Sjfv{
1885171384Sjfv	s32 status = IXGBE_SUCCESS;
1886171384Sjfv	u16 i;
1887171384Sjfv	u8 spi_stat_reg;
1888171384Sjfv
1889200239Sjfv	DEBUGFUNC("ixgbe_ready_eeprom");
1890200239Sjfv
1891171384Sjfv	/*
1892171384Sjfv	 * Read "Status Register" repeatedly until the LSB is cleared.  The
1893171384Sjfv	 * EEPROM will signal that the command has been completed by clearing
1894171384Sjfv	 * bit 0 of the internal status register.  If it's not cleared within
1895171384Sjfv	 * 5 milliseconds, then error out.
1896171384Sjfv	 */
1897171384Sjfv	for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
1898171384Sjfv		ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
1899235528Sjfv					    IXGBE_EEPROM_OPCODE_BITS);
1900171384Sjfv		spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
1901171384Sjfv		if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
1902171384Sjfv			break;
1903171384Sjfv
1904171384Sjfv		usec_delay(5);
1905171384Sjfv		ixgbe_standby_eeprom(hw);
1906171384Sjfv	};
1907171384Sjfv
1908171384Sjfv	/*
1909171384Sjfv	 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
1910171384Sjfv	 * devices (and only 0-5mSec on 5V devices)
1911171384Sjfv	 */
1912171384Sjfv	if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
1913171384Sjfv		DEBUGOUT("SPI EEPROM Status error\n");
1914171384Sjfv		status = IXGBE_ERR_EEPROM;
1915171384Sjfv	}
1916171384Sjfv
1917171384Sjfv	return status;
1918171384Sjfv}
1919171384Sjfv
1920171384Sjfv/**
1921171384Sjfv *  ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
1922171384Sjfv *  @hw: pointer to hardware structure
1923171384Sjfv **/
1924171384Sjfvstatic void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
1925171384Sjfv{
1926171384Sjfv	u32 eec;
1927171384Sjfv
1928200239Sjfv	DEBUGFUNC("ixgbe_standby_eeprom");
1929200239Sjfv
1930171384Sjfv	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1931171384Sjfv
1932171384Sjfv	/* Toggle CS to flush commands */
1933171384Sjfv	eec |= IXGBE_EEC_CS;
1934171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1935171384Sjfv	IXGBE_WRITE_FLUSH(hw);
1936171384Sjfv	usec_delay(1);
1937171384Sjfv	eec &= ~IXGBE_EEC_CS;
1938171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1939171384Sjfv	IXGBE_WRITE_FLUSH(hw);
1940171384Sjfv	usec_delay(1);
1941171384Sjfv}
1942171384Sjfv
1943171384Sjfv/**
1944171384Sjfv *  ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
1945171384Sjfv *  @hw: pointer to hardware structure
1946171384Sjfv *  @data: data to send to the EEPROM
1947171384Sjfv *  @count: number of bits to shift out
1948171384Sjfv **/
1949171384Sjfvstatic void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
1950235528Sjfv					u16 count)
1951171384Sjfv{
1952171384Sjfv	u32 eec;
1953171384Sjfv	u32 mask;
1954171384Sjfv	u32 i;
1955171384Sjfv
1956200239Sjfv	DEBUGFUNC("ixgbe_shift_out_eeprom_bits");
1957200239Sjfv
1958171384Sjfv	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
1959171384Sjfv
1960171384Sjfv	/*
1961171384Sjfv	 * Mask is used to shift "count" bits of "data" out to the EEPROM
1962171384Sjfv	 * one bit at a time.  Determine the starting bit based on count
1963171384Sjfv	 */
1964171384Sjfv	mask = 0x01 << (count - 1);
1965171384Sjfv
1966171384Sjfv	for (i = 0; i < count; i++) {
1967171384Sjfv		/*
1968171384Sjfv		 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
1969171384Sjfv		 * "1", and then raising and then lowering the clock (the SK
1970171384Sjfv		 * bit controls the clock input to the EEPROM).  A "0" is
1971171384Sjfv		 * shifted out to the EEPROM by setting "DI" to "0" and then
1972171384Sjfv		 * raising and then lowering the clock.
1973171384Sjfv		 */
1974171384Sjfv		if (data & mask)
1975171384Sjfv			eec |= IXGBE_EEC_DI;
1976171384Sjfv		else
1977171384Sjfv			eec &= ~IXGBE_EEC_DI;
1978171384Sjfv
1979171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1980171384Sjfv		IXGBE_WRITE_FLUSH(hw);
1981171384Sjfv
1982171384Sjfv		usec_delay(1);
1983171384Sjfv
1984171384Sjfv		ixgbe_raise_eeprom_clk(hw, &eec);
1985171384Sjfv		ixgbe_lower_eeprom_clk(hw, &eec);
1986171384Sjfv
1987171384Sjfv		/*
1988171384Sjfv		 * Shift mask to signify next bit of data to shift in to the
1989171384Sjfv		 * EEPROM
1990171384Sjfv		 */
1991171384Sjfv		mask = mask >> 1;
1992171384Sjfv	};
1993171384Sjfv
1994171384Sjfv	/* We leave the "DI" bit set to "0" when we leave this routine. */
1995171384Sjfv	eec &= ~IXGBE_EEC_DI;
1996171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
1997171384Sjfv	IXGBE_WRITE_FLUSH(hw);
1998171384Sjfv}
1999171384Sjfv
2000171384Sjfv/**
2001171384Sjfv *  ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
2002171384Sjfv *  @hw: pointer to hardware structure
2003171384Sjfv **/
2004171384Sjfvstatic u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
2005171384Sjfv{
2006171384Sjfv	u32 eec;
2007171384Sjfv	u32 i;
2008171384Sjfv	u16 data = 0;
2009171384Sjfv
2010200239Sjfv	DEBUGFUNC("ixgbe_shift_in_eeprom_bits");
2011200239Sjfv
2012171384Sjfv	/*
2013171384Sjfv	 * In order to read a register from the EEPROM, we need to shift
2014171384Sjfv	 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
2015171384Sjfv	 * the clock input to the EEPROM (setting the SK bit), and then reading
2016171384Sjfv	 * the value of the "DO" bit.  During this "shifting in" process the
2017171384Sjfv	 * "DI" bit should always be clear.
2018171384Sjfv	 */
2019171384Sjfv	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
2020171384Sjfv
2021171384Sjfv	eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
2022171384Sjfv
2023171384Sjfv	for (i = 0; i < count; i++) {
2024171384Sjfv		data = data << 1;
2025171384Sjfv		ixgbe_raise_eeprom_clk(hw, &eec);
2026171384Sjfv
2027171384Sjfv		eec = IXGBE_READ_REG(hw, IXGBE_EEC);
2028171384Sjfv
2029171384Sjfv		eec &= ~(IXGBE_EEC_DI);
2030171384Sjfv		if (eec & IXGBE_EEC_DO)
2031171384Sjfv			data |= 1;
2032171384Sjfv
2033171384Sjfv		ixgbe_lower_eeprom_clk(hw, &eec);
2034171384Sjfv	}
2035171384Sjfv
2036171384Sjfv	return data;
2037171384Sjfv}
2038171384Sjfv
2039171384Sjfv/**
2040171384Sjfv *  ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
2041171384Sjfv *  @hw: pointer to hardware structure
2042171384Sjfv *  @eec: EEC register's current value
2043171384Sjfv **/
2044171384Sjfvstatic void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
2045171384Sjfv{
2046200239Sjfv	DEBUGFUNC("ixgbe_raise_eeprom_clk");
2047200239Sjfv
2048171384Sjfv	/*
2049171384Sjfv	 * Raise the clock input to the EEPROM
2050171384Sjfv	 * (setting the SK bit), then delay
2051171384Sjfv	 */
2052171384Sjfv	*eec = *eec | IXGBE_EEC_SK;
2053171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
2054171384Sjfv	IXGBE_WRITE_FLUSH(hw);
2055171384Sjfv	usec_delay(1);
2056171384Sjfv}
2057171384Sjfv
2058171384Sjfv/**
2059171384Sjfv *  ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
2060171384Sjfv *  @hw: pointer to hardware structure
2061171384Sjfv *  @eecd: EECD's current value
2062171384Sjfv **/
2063171384Sjfvstatic void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
2064171384Sjfv{
2065200239Sjfv	DEBUGFUNC("ixgbe_lower_eeprom_clk");
2066200239Sjfv
2067171384Sjfv	/*
2068171384Sjfv	 * Lower the clock input to the EEPROM (clearing the SK bit), then
2069171384Sjfv	 * delay
2070171384Sjfv	 */
2071171384Sjfv	*eec = *eec & ~IXGBE_EEC_SK;
2072171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EEC, *eec);
2073171384Sjfv	IXGBE_WRITE_FLUSH(hw);
2074171384Sjfv	usec_delay(1);
2075171384Sjfv}
2076171384Sjfv
2077171384Sjfv/**
2078171384Sjfv *  ixgbe_release_eeprom - Release EEPROM, release semaphores
2079171384Sjfv *  @hw: pointer to hardware structure
2080171384Sjfv **/
2081171384Sjfvstatic void ixgbe_release_eeprom(struct ixgbe_hw *hw)
2082171384Sjfv{
2083171384Sjfv	u32 eec;
2084171384Sjfv
2085200239Sjfv	DEBUGFUNC("ixgbe_release_eeprom");
2086200239Sjfv
2087171384Sjfv	eec = IXGBE_READ_REG(hw, IXGBE_EEC);
2088171384Sjfv
2089171384Sjfv	eec |= IXGBE_EEC_CS;  /* Pull CS high */
2090171384Sjfv	eec &= ~IXGBE_EEC_SK; /* Lower SCK */
2091171384Sjfv
2092171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
2093171384Sjfv	IXGBE_WRITE_FLUSH(hw);
2094171384Sjfv
2095171384Sjfv	usec_delay(1);
2096171384Sjfv
2097171384Sjfv	/* Stop requesting EEPROM access */
2098171384Sjfv	eec &= ~IXGBE_EEC_REQ;
2099171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_EEC, eec);
2100171384Sjfv
2101235528Sjfv	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2102194875Sjfv
2103194875Sjfv	/* Delay before attempt to obtain semaphore again to allow FW access */
2104194875Sjfv	msec_delay(hw->eeprom.semaphore_delay);
2105171384Sjfv}
2106171384Sjfv
2107171384Sjfv/**
2108200239Sjfv *  ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
2109171384Sjfv *  @hw: pointer to hardware structure
2110171384Sjfv **/
2111200239Sjfvu16 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
2112171384Sjfv{
2113171384Sjfv	u16 i;
2114171384Sjfv	u16 j;
2115171384Sjfv	u16 checksum = 0;
2116171384Sjfv	u16 length = 0;
2117171384Sjfv	u16 pointer = 0;
2118171384Sjfv	u16 word = 0;
2119171384Sjfv
2120200239Sjfv	DEBUGFUNC("ixgbe_calc_eeprom_checksum_generic");
2121200239Sjfv
2122171384Sjfv	/* Include 0x0-0x3F in the checksum */
2123171384Sjfv	for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
2124179055Sjfv		if (hw->eeprom.ops.read(hw, i, &word) != IXGBE_SUCCESS) {
2125171384Sjfv			DEBUGOUT("EEPROM read failed\n");
2126171384Sjfv			break;
2127171384Sjfv		}
2128171384Sjfv		checksum += word;
2129171384Sjfv	}
2130171384Sjfv
2131171384Sjfv	/* Include all data from pointers except for the fw pointer */
2132171384Sjfv	for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
2133179055Sjfv		hw->eeprom.ops.read(hw, i, &pointer);
2134171384Sjfv
2135171384Sjfv		/* Make sure the pointer seems valid */
2136171384Sjfv		if (pointer != 0xFFFF && pointer != 0) {
2137179055Sjfv			hw->eeprom.ops.read(hw, pointer, &length);
2138171384Sjfv
2139171384Sjfv			if (length != 0xFFFF && length != 0) {
2140171384Sjfv				for (j = pointer+1; j <= pointer+length; j++) {
2141179055Sjfv					hw->eeprom.ops.read(hw, j, &word);
2142171384Sjfv					checksum += word;
2143171384Sjfv				}
2144171384Sjfv			}
2145171384Sjfv		}
2146171384Sjfv	}
2147171384Sjfv
2148171384Sjfv	checksum = (u16)IXGBE_EEPROM_SUM - checksum;
2149171384Sjfv
2150171384Sjfv	return checksum;
2151171384Sjfv}
2152171384Sjfv
2153171384Sjfv/**
2154171384Sjfv *  ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
2155171384Sjfv *  @hw: pointer to hardware structure
2156171384Sjfv *  @checksum_val: calculated checksum
2157171384Sjfv *
2158171384Sjfv *  Performs checksum calculation and validates the EEPROM checksum.  If the
2159171384Sjfv *  caller does not need checksum_val, the value can be NULL.
2160171384Sjfv **/
2161171384Sjfvs32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
2162235528Sjfv					   u16 *checksum_val)
2163171384Sjfv{
2164171384Sjfv	s32 status;
2165171384Sjfv	u16 checksum;
2166171384Sjfv	u16 read_checksum = 0;
2167171384Sjfv
2168200239Sjfv	DEBUGFUNC("ixgbe_validate_eeprom_checksum_generic");
2169200239Sjfv
2170171384Sjfv	/*
2171171384Sjfv	 * Read the first word from the EEPROM. If this times out or fails, do
2172171384Sjfv	 * not continue or we could be in for a very long wait while every
2173171384Sjfv	 * EEPROM read fails
2174171384Sjfv	 */
2175179055Sjfv	status = hw->eeprom.ops.read(hw, 0, &checksum);
2176171384Sjfv
2177171384Sjfv	if (status == IXGBE_SUCCESS) {
2178200239Sjfv		checksum = hw->eeprom.ops.calc_checksum(hw);
2179171384Sjfv
2180179055Sjfv		hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
2181171384Sjfv
2182171384Sjfv		/*
2183171384Sjfv		 * Verify read checksum from EEPROM is the same as
2184171384Sjfv		 * calculated checksum
2185171384Sjfv		 */
2186179055Sjfv		if (read_checksum != checksum)
2187171384Sjfv			status = IXGBE_ERR_EEPROM_CHECKSUM;
2188171384Sjfv
2189171384Sjfv		/* If the user cares, return the calculated checksum */
2190179055Sjfv		if (checksum_val)
2191171384Sjfv			*checksum_val = checksum;
2192171384Sjfv	} else {
2193171384Sjfv		DEBUGOUT("EEPROM read failed\n");
2194171384Sjfv	}
2195171384Sjfv
2196171384Sjfv	return status;
2197171384Sjfv}
2198171384Sjfv
2199171384Sjfv/**
2200179055Sjfv *  ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
2201171384Sjfv *  @hw: pointer to hardware structure
2202171384Sjfv **/
2203171384Sjfvs32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
2204171384Sjfv{
2205171384Sjfv	s32 status;
2206171384Sjfv	u16 checksum;
2207171384Sjfv
2208200239Sjfv	DEBUGFUNC("ixgbe_update_eeprom_checksum_generic");
2209200239Sjfv
2210171384Sjfv	/*
2211171384Sjfv	 * Read the first word from the EEPROM. If this times out or fails, do
2212171384Sjfv	 * not continue or we could be in for a very long wait while every
2213171384Sjfv	 * EEPROM read fails
2214171384Sjfv	 */
2215179055Sjfv	status = hw->eeprom.ops.read(hw, 0, &checksum);
2216171384Sjfv
2217171384Sjfv	if (status == IXGBE_SUCCESS) {
2218200239Sjfv		checksum = hw->eeprom.ops.calc_checksum(hw);
2219179055Sjfv		status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM,
2220235528Sjfv					      checksum);
2221171384Sjfv	} else {
2222171384Sjfv		DEBUGOUT("EEPROM read failed\n");
2223171384Sjfv	}
2224171384Sjfv
2225171384Sjfv	return status;
2226171384Sjfv}
2227171384Sjfv
2228171384Sjfv/**
2229171384Sjfv *  ixgbe_validate_mac_addr - Validate MAC address
2230171384Sjfv *  @mac_addr: pointer to MAC address.
2231171384Sjfv *
2232171384Sjfv *  Tests a MAC address to ensure it is a valid Individual Address
2233171384Sjfv **/
2234171384Sjfvs32 ixgbe_validate_mac_addr(u8 *mac_addr)
2235171384Sjfv{
2236171384Sjfv	s32 status = IXGBE_SUCCESS;
2237171384Sjfv
2238200239Sjfv	DEBUGFUNC("ixgbe_validate_mac_addr");
2239200239Sjfv
2240171384Sjfv	/* Make sure it is not a multicast address */
2241171384Sjfv	if (IXGBE_IS_MULTICAST(mac_addr)) {
2242171384Sjfv		DEBUGOUT("MAC address is multicast\n");
2243171384Sjfv		status = IXGBE_ERR_INVALID_MAC_ADDR;
2244171384Sjfv	/* Not a broadcast address */
2245171384Sjfv	} else if (IXGBE_IS_BROADCAST(mac_addr)) {
2246171384Sjfv		DEBUGOUT("MAC address is broadcast\n");
2247171384Sjfv		status = IXGBE_ERR_INVALID_MAC_ADDR;
2248171384Sjfv	/* Reject the zero address */
2249171384Sjfv	} else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
2250235528Sjfv		   mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
2251171384Sjfv		DEBUGOUT("MAC address is all zeros\n");
2252171384Sjfv		status = IXGBE_ERR_INVALID_MAC_ADDR;
2253171384Sjfv	}
2254171384Sjfv	return status;
2255171384Sjfv}
2256171384Sjfv
2257171384Sjfv/**
2258179055Sjfv *  ixgbe_set_rar_generic - Set Rx address register
2259171384Sjfv *  @hw: pointer to hardware structure
2260179055Sjfv *  @index: Receive address register to write
2261171384Sjfv *  @addr: Address to put into receive address register
2262179055Sjfv *  @vmdq: VMDq "set" or "pool" index
2263171384Sjfv *  @enable_addr: set flag that address is active
2264171384Sjfv *
2265171384Sjfv *  Puts an ethernet address into a receive address register.
2266171384Sjfv **/
2267179055Sjfvs32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
2268235528Sjfv			  u32 enable_addr)
2269171384Sjfv{
2270171384Sjfv	u32 rar_low, rar_high;
2271179055Sjfv	u32 rar_entries = hw->mac.num_rar_entries;
2272171384Sjfv
2273200239Sjfv	DEBUGFUNC("ixgbe_set_rar_generic");
2274200239Sjfv
2275215911Sjfv	/* Make sure we are using a valid rar index range */
2276215911Sjfv	if (index >= rar_entries) {
2277252898Sjfv		ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
2278252898Sjfv			     "RAR index %d is out of range.\n", index);
2279215911Sjfv		return IXGBE_ERR_INVALID_ARGUMENT;
2280215911Sjfv	}
2281215911Sjfv
2282179055Sjfv	/* setup VMDq pool selection before this RAR gets enabled */
2283179055Sjfv	hw->mac.ops.set_vmdq(hw, index, vmdq);
2284171384Sjfv
2285215911Sjfv	/*
2286215911Sjfv	 * HW expects these in little endian so we reverse the byte
2287215911Sjfv	 * order from network order (big endian) to little endian
2288215911Sjfv	 */
2289215911Sjfv	rar_low = ((u32)addr[0] |
2290235528Sjfv		   ((u32)addr[1] << 8) |
2291235528Sjfv		   ((u32)addr[2] << 16) |
2292235528Sjfv		   ((u32)addr[3] << 24));
2293215911Sjfv	/*
2294215911Sjfv	 * Some parts put the VMDq setting in the extra RAH bits,
2295215911Sjfv	 * so save everything except the lower 16 bits that hold part
2296215911Sjfv	 * of the address and the address valid bit.
2297215911Sjfv	 */
2298215911Sjfv	rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
2299215911Sjfv	rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
2300215911Sjfv	rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
2301171384Sjfv
2302215911Sjfv	if (enable_addr != 0)
2303215911Sjfv		rar_high |= IXGBE_RAH_AV;
2304171384Sjfv
2305215911Sjfv	IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
2306215911Sjfv	IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
2307171384Sjfv
2308171384Sjfv	return IXGBE_SUCCESS;
2309171384Sjfv}
2310171384Sjfv
2311171384Sjfv/**
2312181003Sjfv *  ixgbe_clear_rar_generic - Remove Rx address register
2313181003Sjfv *  @hw: pointer to hardware structure
2314181003Sjfv *  @index: Receive address register to write
2315181003Sjfv *
2316181003Sjfv *  Clears an ethernet address from a receive address register.
2317181003Sjfv **/
2318181003Sjfvs32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
2319181003Sjfv{
2320181003Sjfv	u32 rar_high;
2321181003Sjfv	u32 rar_entries = hw->mac.num_rar_entries;
2322181003Sjfv
2323200239Sjfv	DEBUGFUNC("ixgbe_clear_rar_generic");
2324200239Sjfv
2325181003Sjfv	/* Make sure we are using a valid rar index range */
2326215911Sjfv	if (index >= rar_entries) {
2327252898Sjfv		ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
2328252898Sjfv			     "RAR index %d is out of range.\n", index);
2329215911Sjfv		return IXGBE_ERR_INVALID_ARGUMENT;
2330181003Sjfv	}
2331181003Sjfv
2332215911Sjfv	/*
2333215911Sjfv	 * Some parts put the VMDq setting in the extra RAH bits,
2334215911Sjfv	 * so save everything except the lower 16 bits that hold part
2335215911Sjfv	 * of the address and the address valid bit.
2336215911Sjfv	 */
2337215911Sjfv	rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
2338215911Sjfv	rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
2339215911Sjfv
2340215911Sjfv	IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
2341215911Sjfv	IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
2342215911Sjfv
2343181003Sjfv	/* clear VMDq pool/queue selection for this RAR */
2344181003Sjfv	hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
2345181003Sjfv
2346181003Sjfv	return IXGBE_SUCCESS;
2347181003Sjfv}
2348181003Sjfv
2349181003Sjfv/**
2350171384Sjfv *  ixgbe_init_rx_addrs_generic - Initializes receive address filters.
2351171384Sjfv *  @hw: pointer to hardware structure
2352171384Sjfv *
2353171384Sjfv *  Places the MAC address in receive address register 0 and clears the rest
2354179055Sjfv *  of the receive address registers. Clears the multicast table. Assumes
2355171384Sjfv *  the receiver is in reset when the routine is called.
2356171384Sjfv **/
2357171384Sjfvs32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
2358171384Sjfv{
2359171384Sjfv	u32 i;
2360179055Sjfv	u32 rar_entries = hw->mac.num_rar_entries;
2361171384Sjfv
2362200239Sjfv	DEBUGFUNC("ixgbe_init_rx_addrs_generic");
2363200239Sjfv
2364171384Sjfv	/*
2365171384Sjfv	 * If the current mac address is valid, assume it is a software override
2366171384Sjfv	 * to the permanent address.
2367171384Sjfv	 * Otherwise, use the permanent address from the eeprom.
2368171384Sjfv	 */
2369171384Sjfv	if (ixgbe_validate_mac_addr(hw->mac.addr) ==
2370171384Sjfv	    IXGBE_ERR_INVALID_MAC_ADDR) {
2371171384Sjfv		/* Get the MAC address from the RAR0 for later reference */
2372179055Sjfv		hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
2373171384Sjfv
2374171384Sjfv		DEBUGOUT3(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
2375235528Sjfv			  hw->mac.addr[0], hw->mac.addr[1],
2376235528Sjfv			  hw->mac.addr[2]);
2377171384Sjfv		DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
2378235528Sjfv			  hw->mac.addr[4], hw->mac.addr[5]);
2379171384Sjfv	} else {
2380171384Sjfv		/* Setup the receive address. */
2381171384Sjfv		DEBUGOUT("Overriding MAC Address in RAR[0]\n");
2382171384Sjfv		DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ",
2383235528Sjfv			  hw->mac.addr[0], hw->mac.addr[1],
2384235528Sjfv			  hw->mac.addr[2]);
2385171384Sjfv		DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
2386235528Sjfv			  hw->mac.addr[4], hw->mac.addr[5]);
2387171384Sjfv
2388179055Sjfv		hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2389217593Sjfv
2390217593Sjfv		/* clear VMDq pool/queue selection for RAR 0 */
2391217593Sjfv		hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
2392171384Sjfv	}
2393179055Sjfv	hw->addr_ctrl.overflow_promisc = 0;
2394171384Sjfv
2395171384Sjfv	hw->addr_ctrl.rar_used_count = 1;
2396171384Sjfv
2397171384Sjfv	/* Zero out the other receive addresses. */
2398179055Sjfv	DEBUGOUT1("Clearing RAR[1-%d]\n", rar_entries - 1);
2399171384Sjfv	for (i = 1; i < rar_entries; i++) {
2400171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
2401171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
2402171384Sjfv	}
2403171384Sjfv
2404171384Sjfv	/* Clear the MTA */
2405171384Sjfv	hw->addr_ctrl.mta_in_use = 0;
2406171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
2407171384Sjfv
2408171384Sjfv	DEBUGOUT(" Clearing MTA\n");
2409179055Sjfv	for (i = 0; i < hw->mac.mcft_size; i++)
2410171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
2411171384Sjfv
2412181003Sjfv	ixgbe_init_uta_tables(hw);
2413181003Sjfv
2414171384Sjfv	return IXGBE_SUCCESS;
2415171384Sjfv}
2416171384Sjfv
2417171384Sjfv/**
2418179055Sjfv *  ixgbe_add_uc_addr - Adds a secondary unicast address.
2419179055Sjfv *  @hw: pointer to hardware structure
2420179055Sjfv *  @addr: new address
2421179055Sjfv *
2422179055Sjfv *  Adds it to unused receive address register or goes into promiscuous mode.
2423179055Sjfv **/
2424179055Sjfvvoid ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
2425179055Sjfv{
2426179055Sjfv	u32 rar_entries = hw->mac.num_rar_entries;
2427179055Sjfv	u32 rar;
2428179055Sjfv
2429200239Sjfv	DEBUGFUNC("ixgbe_add_uc_addr");
2430200239Sjfv
2431179055Sjfv	DEBUGOUT6(" UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
2432235528Sjfv		  addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
2433179055Sjfv
2434179055Sjfv	/*
2435179055Sjfv	 * Place this address in the RAR if there is room,
2436179055Sjfv	 * else put the controller into promiscuous mode
2437179055Sjfv	 */
2438179055Sjfv	if (hw->addr_ctrl.rar_used_count < rar_entries) {
2439190873Sjfv		rar = hw->addr_ctrl.rar_used_count;
2440179055Sjfv		hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
2441179055Sjfv		DEBUGOUT1("Added a secondary address to RAR[%d]\n", rar);
2442179055Sjfv		hw->addr_ctrl.rar_used_count++;
2443179055Sjfv	} else {
2444179055Sjfv		hw->addr_ctrl.overflow_promisc++;
2445179055Sjfv	}
2446179055Sjfv
2447179055Sjfv	DEBUGOUT("ixgbe_add_uc_addr Complete\n");
2448179055Sjfv}
2449179055Sjfv
2450179055Sjfv/**
2451179055Sjfv *  ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
2452179055Sjfv *  @hw: pointer to hardware structure
2453179055Sjfv *  @addr_list: the list of new addresses
2454179055Sjfv *  @addr_count: number of addresses
2455179055Sjfv *  @next: iterator function to walk the address list
2456179055Sjfv *
2457179055Sjfv *  The given list replaces any existing list.  Clears the secondary addrs from
2458179055Sjfv *  receive address registers.  Uses unused receive address registers for the
2459179055Sjfv *  first secondary addresses, and falls back to promiscuous mode as needed.
2460179055Sjfv *
2461179055Sjfv *  Drivers using secondary unicast addresses must set user_set_promisc when
2462179055Sjfv *  manually putting the device into promiscuous mode.
2463179055Sjfv **/
2464179055Sjfvs32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
2465235528Sjfv				      u32 addr_count, ixgbe_mc_addr_itr next)
2466179055Sjfv{
2467179055Sjfv	u8 *addr;
2468179055Sjfv	u32 i;
2469179055Sjfv	u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
2470179055Sjfv	u32 uc_addr_in_use;
2471179055Sjfv	u32 fctrl;
2472179055Sjfv	u32 vmdq;
2473179055Sjfv
2474200239Sjfv	DEBUGFUNC("ixgbe_update_uc_addr_list_generic");
2475200239Sjfv
2476179055Sjfv	/*
2477179055Sjfv	 * Clear accounting of old secondary address list,
2478179055Sjfv	 * don't count RAR[0]
2479179055Sjfv	 */
2480190873Sjfv	uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
2481179055Sjfv	hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
2482179055Sjfv	hw->addr_ctrl.overflow_promisc = 0;
2483179055Sjfv
2484179055Sjfv	/* Zero out the other receive addresses */
2485200239Sjfv	DEBUGOUT1("Clearing RAR[1-%d]\n", uc_addr_in_use+1);
2486200239Sjfv	for (i = 0; i < uc_addr_in_use; i++) {
2487200239Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
2488200239Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
2489179055Sjfv	}
2490179055Sjfv
2491179055Sjfv	/* Add the new addresses */
2492179055Sjfv	for (i = 0; i < addr_count; i++) {
2493179055Sjfv		DEBUGOUT(" Adding the secondary addresses:\n");
2494179055Sjfv		addr = next(hw, &addr_list, &vmdq);
2495179055Sjfv		ixgbe_add_uc_addr(hw, addr, vmdq);
2496179055Sjfv	}
2497179055Sjfv
2498179055Sjfv	if (hw->addr_ctrl.overflow_promisc) {
2499179055Sjfv		/* enable promisc if not already in overflow or set by user */
2500179055Sjfv		if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
2501185352Sjfv			DEBUGOUT(" Entering address overflow promisc mode\n");
2502179055Sjfv			fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2503179055Sjfv			fctrl |= IXGBE_FCTRL_UPE;
2504179055Sjfv			IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2505179055Sjfv		}
2506179055Sjfv	} else {
2507179055Sjfv		/* only disable if set by overflow, not by user */
2508179055Sjfv		if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
2509179055Sjfv			DEBUGOUT(" Leaving address overflow promisc mode\n");
2510179055Sjfv			fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2511179055Sjfv			fctrl &= ~IXGBE_FCTRL_UPE;
2512179055Sjfv			IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2513179055Sjfv		}
2514179055Sjfv	}
2515179055Sjfv
2516179055Sjfv	DEBUGOUT("ixgbe_update_uc_addr_list_generic Complete\n");
2517179055Sjfv	return IXGBE_SUCCESS;
2518179055Sjfv}
2519179055Sjfv
2520179055Sjfv/**
2521171384Sjfv *  ixgbe_mta_vector - Determines bit-vector in multicast table to set
2522171384Sjfv *  @hw: pointer to hardware structure
2523171384Sjfv *  @mc_addr: the multicast address
2524171384Sjfv *
2525171384Sjfv *  Extracts the 12 bits, from a multicast address, to determine which
2526171384Sjfv *  bit-vector to set in the multicast table. The hardware uses 12 bits, from
2527171384Sjfv *  incoming rx multicast addresses, to determine the bit-vector to check in
2528171384Sjfv *  the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
2529179055Sjfv *  by the MO field of the MCSTCTRL. The MO field is set during initialization
2530171384Sjfv *  to mc_filter_type.
2531171384Sjfv **/
2532171384Sjfvstatic s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
2533171384Sjfv{
2534171384Sjfv	u32 vector = 0;
2535171384Sjfv
2536200239Sjfv	DEBUGFUNC("ixgbe_mta_vector");
2537200239Sjfv
2538171384Sjfv	switch (hw->mac.mc_filter_type) {
2539179055Sjfv	case 0:   /* use bits [47:36] of the address */
2540171384Sjfv		vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
2541171384Sjfv		break;
2542179055Sjfv	case 1:   /* use bits [46:35] of the address */
2543171384Sjfv		vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
2544171384Sjfv		break;
2545179055Sjfv	case 2:   /* use bits [45:34] of the address */
2546171384Sjfv		vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
2547171384Sjfv		break;
2548179055Sjfv	case 3:   /* use bits [43:32] of the address */
2549171384Sjfv		vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
2550171384Sjfv		break;
2551179055Sjfv	default:  /* Invalid mc_filter_type */
2552171384Sjfv		DEBUGOUT("MC filter type param set incorrectly\n");
2553171384Sjfv		ASSERT(0);
2554171384Sjfv		break;
2555171384Sjfv	}
2556171384Sjfv
2557171384Sjfv	/* vector can only be 12-bits or boundary will be exceeded */
2558171384Sjfv	vector &= 0xFFF;
2559171384Sjfv	return vector;
2560171384Sjfv}
2561171384Sjfv
2562171384Sjfv/**
2563171384Sjfv *  ixgbe_set_mta - Set bit-vector in multicast table
2564171384Sjfv *  @hw: pointer to hardware structure
2565171384Sjfv *  @hash_value: Multicast address hash value
2566171384Sjfv *
2567171384Sjfv *  Sets the bit-vector in the multicast table.
2568171384Sjfv **/
2569171384Sjfvvoid ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
2570171384Sjfv{
2571171384Sjfv	u32 vector;
2572171384Sjfv	u32 vector_bit;
2573171384Sjfv	u32 vector_reg;
2574171384Sjfv
2575200239Sjfv	DEBUGFUNC("ixgbe_set_mta");
2576200239Sjfv
2577171384Sjfv	hw->addr_ctrl.mta_in_use++;
2578171384Sjfv
2579171384Sjfv	vector = ixgbe_mta_vector(hw, mc_addr);
2580171384Sjfv	DEBUGOUT1(" bit-vector = 0x%03X\n", vector);
2581171384Sjfv
2582171384Sjfv	/*
2583171384Sjfv	 * The MTA is a register array of 128 32-bit registers. It is treated
2584171384Sjfv	 * like an array of 4096 bits.  We want to set bit
2585171384Sjfv	 * BitArray[vector_value]. So we figure out what register the bit is
2586171384Sjfv	 * in, read it, OR in the new bit, then write back the new value.  The
2587171384Sjfv	 * register is determined by the upper 7 bits of the vector value and
2588171384Sjfv	 * the bit within that register are determined by the lower 5 bits of
2589171384Sjfv	 * the value.
2590171384Sjfv	 */
2591171384Sjfv	vector_reg = (vector >> 5) & 0x7F;
2592171384Sjfv	vector_bit = vector & 0x1F;
2593215911Sjfv	hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
2594171384Sjfv}
2595171384Sjfv
2596171384Sjfv/**
2597171384Sjfv *  ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
2598171384Sjfv *  @hw: pointer to hardware structure
2599171384Sjfv *  @mc_addr_list: the list of new multicast addresses
2600171384Sjfv *  @mc_addr_count: number of addresses
2601179055Sjfv *  @next: iterator function to walk the multicast address list
2602235528Sjfv *  @clear: flag, when set clears the table beforehand
2603171384Sjfv *
2604235528Sjfv *  When the clear flag is set, the given list replaces any existing list.
2605235528Sjfv *  Hashes the given addresses into the multicast table.
2606171384Sjfv **/
2607171384Sjfvs32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
2608235528Sjfv				      u32 mc_addr_count, ixgbe_mc_addr_itr next,
2609235528Sjfv				      bool clear)
2610171384Sjfv{
2611171384Sjfv	u32 i;
2612179055Sjfv	u32 vmdq;
2613171384Sjfv
2614200239Sjfv	DEBUGFUNC("ixgbe_update_mc_addr_list_generic");
2615200239Sjfv
2616171384Sjfv	/*
2617171384Sjfv	 * Set the new number of MC addresses that we are being requested to
2618171384Sjfv	 * use.
2619171384Sjfv	 */
2620171384Sjfv	hw->addr_ctrl.num_mc_addrs = mc_addr_count;
2621171384Sjfv	hw->addr_ctrl.mta_in_use = 0;
2622171384Sjfv
2623215911Sjfv	/* Clear mta_shadow */
2624235528Sjfv	if (clear) {
2625235528Sjfv		DEBUGOUT(" Clearing MTA\n");
2626235528Sjfv		memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
2627235528Sjfv	}
2628171384Sjfv
2629215911Sjfv	/* Update mta_shadow */
2630171384Sjfv	for (i = 0; i < mc_addr_count; i++) {
2631171384Sjfv		DEBUGOUT(" Adding the multicast addresses:\n");
2632190873Sjfv		ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
2633171384Sjfv	}
2634171384Sjfv
2635171384Sjfv	/* Enable mta */
2636215911Sjfv	for (i = 0; i < hw->mac.mcft_size; i++)
2637215911Sjfv		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
2638215911Sjfv				      hw->mac.mta_shadow[i]);
2639215911Sjfv
2640171384Sjfv	if (hw->addr_ctrl.mta_in_use > 0)
2641171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
2642235528Sjfv				IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
2643171384Sjfv
2644171384Sjfv	DEBUGOUT("ixgbe_update_mc_addr_list_generic Complete\n");
2645171384Sjfv	return IXGBE_SUCCESS;
2646171384Sjfv}
2647171384Sjfv
2648171384Sjfv/**
2649171384Sjfv *  ixgbe_enable_mc_generic - Enable multicast address in RAR
2650171384Sjfv *  @hw: pointer to hardware structure
2651171384Sjfv *
2652171384Sjfv *  Enables multicast address in RAR and the use of the multicast hash table.
2653171384Sjfv **/
2654171384Sjfvs32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
2655171384Sjfv{
2656171384Sjfv	struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2657171384Sjfv
2658200239Sjfv	DEBUGFUNC("ixgbe_enable_mc_generic");
2659200239Sjfv
2660171384Sjfv	if (a->mta_in_use > 0)
2661171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
2662235528Sjfv				hw->mac.mc_filter_type);
2663171384Sjfv
2664171384Sjfv	return IXGBE_SUCCESS;
2665171384Sjfv}
2666171384Sjfv
2667171384Sjfv/**
2668179055Sjfv *  ixgbe_disable_mc_generic - Disable multicast address in RAR
2669171384Sjfv *  @hw: pointer to hardware structure
2670171384Sjfv *
2671171384Sjfv *  Disables multicast address in RAR and the use of the multicast hash table.
2672171384Sjfv **/
2673171384Sjfvs32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
2674171384Sjfv{
2675171384Sjfv	struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2676171384Sjfv
2677200239Sjfv	DEBUGFUNC("ixgbe_disable_mc_generic");
2678200239Sjfv
2679171384Sjfv	if (a->mta_in_use > 0)
2680171384Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
2681171384Sjfv
2682171384Sjfv	return IXGBE_SUCCESS;
2683171384Sjfv}
2684171384Sjfv
2685171384Sjfv/**
2686190873Sjfv *  ixgbe_fc_enable_generic - Enable flow control
2687185352Sjfv *  @hw: pointer to hardware structure
2688185352Sjfv *
2689190873Sjfv *  Enable flow control according to the current settings.
2690185352Sjfv **/
2691238263Sjfvs32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw)
2692185352Sjfv{
2693185352Sjfv	s32 ret_val = IXGBE_SUCCESS;
2694190873Sjfv	u32 mflcn_reg, fccfg_reg;
2695190873Sjfv	u32 reg;
2696215911Sjfv	u32 fcrtl, fcrth;
2697238263Sjfv	int i;
2698185352Sjfv
2699190873Sjfv	DEBUGFUNC("ixgbe_fc_enable_generic");
2700185352Sjfv
2701238263Sjfv	/* Validate the water mark configuration */
2702238263Sjfv	if (!hw->fc.pause_time) {
2703238263Sjfv		ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2704190873Sjfv		goto out;
2705238263Sjfv	}
2706185352Sjfv
2707238263Sjfv	/* Low water mark of zero causes XOFF floods */
2708238263Sjfv	for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2709238263Sjfv		if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2710238263Sjfv		    hw->fc.high_water[i]) {
2711238263Sjfv			if (!hw->fc.low_water[i] ||
2712238263Sjfv			    hw->fc.low_water[i] >= hw->fc.high_water[i]) {
2713238263Sjfv				DEBUGOUT("Invalid water mark configuration\n");
2714238263Sjfv				ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2715238263Sjfv				goto out;
2716238263Sjfv			}
2717238263Sjfv		}
2718238263Sjfv	}
2719238263Sjfv
2720238263Sjfv	/* Negotiate the fc mode to use */
2721238263Sjfv	ixgbe_fc_autoneg(hw);
2722238263Sjfv
2723190873Sjfv	/* Disable any previous flow control settings */
2724190873Sjfv	mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2725238263Sjfv	mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
2726190873Sjfv
2727190873Sjfv	fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2728190873Sjfv	fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
2729190873Sjfv
2730185352Sjfv	/*
2731185352Sjfv	 * The possible values of fc.current_mode are:
2732190873Sjfv	 * 0: Flow control is completely disabled
2733190873Sjfv	 * 1: Rx flow control is enabled (we can receive pause frames,
2734190873Sjfv	 *    but not send pause frames).
2735190873Sjfv	 * 2: Tx flow control is enabled (we can send pause frames but
2736190873Sjfv	 *    we do not support receiving pause frames).
2737190873Sjfv	 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2738185352Sjfv	 * other: Invalid.
2739185352Sjfv	 */
2740185352Sjfv	switch (hw->fc.current_mode) {
2741185352Sjfv	case ixgbe_fc_none:
2742215911Sjfv		/*
2743215911Sjfv		 * Flow control is disabled by software override or autoneg.
2744190873Sjfv		 * The code below will actually disable it in the HW.
2745190873Sjfv		 */
2746185352Sjfv		break;
2747185352Sjfv	case ixgbe_fc_rx_pause:
2748185352Sjfv		/*
2749185352Sjfv		 * Rx Flow control is enabled and Tx Flow control is
2750185352Sjfv		 * disabled by software override. Since there really
2751185352Sjfv		 * isn't a way to advertise that we are capable of RX
2752185352Sjfv		 * Pause ONLY, we will advertise that we support both
2753185352Sjfv		 * symmetric and asymmetric Rx PAUSE.  Later, we will
2754185352Sjfv		 * disable the adapter's ability to send PAUSE frames.
2755185352Sjfv		 */
2756190873Sjfv		mflcn_reg |= IXGBE_MFLCN_RFCE;
2757185352Sjfv		break;
2758185352Sjfv	case ixgbe_fc_tx_pause:
2759185352Sjfv		/*
2760185352Sjfv		 * Tx Flow control is enabled, and Rx Flow control is
2761185352Sjfv		 * disabled by software override.
2762185352Sjfv		 */
2763190873Sjfv		fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2764185352Sjfv		break;
2765185352Sjfv	case ixgbe_fc_full:
2766185352Sjfv		/* Flow control (both Rx and Tx) is enabled by SW override. */
2767190873Sjfv		mflcn_reg |= IXGBE_MFLCN_RFCE;
2768190873Sjfv		fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2769185352Sjfv		break;
2770185352Sjfv	default:
2771252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
2772252898Sjfv			     "Flow control param set incorrectly\n");
2773200239Sjfv		ret_val = IXGBE_ERR_CONFIG;
2774185352Sjfv		goto out;
2775185352Sjfv		break;
2776185352Sjfv	}
2777185352Sjfv
2778190873Sjfv	/* Set 802.3x based flow control settings. */
2779190873Sjfv	mflcn_reg |= IXGBE_MFLCN_DPF;
2780190873Sjfv	IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
2781190873Sjfv	IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
2782185352Sjfv
2783194875Sjfv
2784238263Sjfv	/* Set up and enable Rx high/low water mark thresholds, enable XON. */
2785238263Sjfv	for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2786238263Sjfv		if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2787238263Sjfv		    hw->fc.high_water[i]) {
2788238263Sjfv			fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
2789238263Sjfv			IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
2790238263Sjfv			fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
2791238263Sjfv		} else {
2792238263Sjfv			IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
2793238263Sjfv			/*
2794238263Sjfv			 * In order to prevent Tx hangs when the internal Tx
2795238263Sjfv			 * switch is enabled we must set the high water mark
2796238263Sjfv			 * to the maximum FCRTH value.  This allows the Tx
2797238263Sjfv			 * switch to function even under heavy Rx workloads.
2798238263Sjfv			 */
2799238263Sjfv			fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
2800238263Sjfv		}
2801238263Sjfv
2802238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
2803190873Sjfv	}
2804185352Sjfv
2805190873Sjfv	/* Configure pause time (2 TCs per register) */
2806238263Sjfv	reg = hw->fc.pause_time * 0x00010001;
2807238263Sjfv	for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
2808238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
2809185352Sjfv
2810238263Sjfv	/* Configure flow control refresh threshold value */
2811238263Sjfv	IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
2812185352Sjfv
2813190873Sjfvout:
2814190873Sjfv	return ret_val;
2815190873Sjfv}
2816190873Sjfv
2817190873Sjfv/**
2818238263Sjfv *  ixgbe_negotiate_fc - Negotiate flow control
2819190873Sjfv *  @hw: pointer to hardware structure
2820238263Sjfv *  @adv_reg: flow control advertised settings
2821238263Sjfv *  @lp_reg: link partner's flow control settings
2822238263Sjfv *  @adv_sym: symmetric pause bit in advertisement
2823238263Sjfv *  @adv_asm: asymmetric pause bit in advertisement
2824238263Sjfv *  @lp_sym: symmetric pause bit in link partner advertisement
2825238263Sjfv *  @lp_asm: asymmetric pause bit in link partner advertisement
2826190873Sjfv *
2827238263Sjfv *  Find the intersection between advertised settings and link partner's
2828238263Sjfv *  advertised settings
2829190873Sjfv **/
2830238263Sjfvstatic s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
2831238263Sjfv			      u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
2832190873Sjfv{
2833252898Sjfv	if ((!(adv_reg)) ||  (!(lp_reg))) {
2834252898Sjfv		ERROR_REPORT3(IXGBE_ERROR_UNSUPPORTED,
2835252898Sjfv			     "Local or link partner's advertised flow control "
2836252898Sjfv			     "settings are NULL. Local: %x, link partner: %x\n",
2837252898Sjfv			     adv_reg, lp_reg);
2838238263Sjfv		return IXGBE_ERR_FC_NOT_NEGOTIATED;
2839252898Sjfv	}
2840190873Sjfv
2841238263Sjfv	if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
2842238263Sjfv		/*
2843238263Sjfv		 * Now we need to check if the user selected Rx ONLY
2844238263Sjfv		 * of pause frames.  In this case, we had to advertise
2845238263Sjfv		 * FULL flow control because we could not advertise RX
2846238263Sjfv		 * ONLY. Hence, we must now check to see if we need to
2847238263Sjfv		 * turn OFF the TRANSMISSION of PAUSE frames.
2848238263Sjfv		 */
2849238263Sjfv		if (hw->fc.requested_mode == ixgbe_fc_full) {
2850238263Sjfv			hw->fc.current_mode = ixgbe_fc_full;
2851238263Sjfv			DEBUGOUT("Flow Control = FULL.\n");
2852238263Sjfv		} else {
2853238263Sjfv			hw->fc.current_mode = ixgbe_fc_rx_pause;
2854238263Sjfv			DEBUGOUT("Flow Control=RX PAUSE frames only\n");
2855238263Sjfv		}
2856238263Sjfv	} else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2857238263Sjfv		   (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2858238263Sjfv		hw->fc.current_mode = ixgbe_fc_tx_pause;
2859238263Sjfv		DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2860238263Sjfv	} else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2861238263Sjfv		   !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2862238263Sjfv		hw->fc.current_mode = ixgbe_fc_rx_pause;
2863238263Sjfv		DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2864215911Sjfv	} else {
2865238263Sjfv		hw->fc.current_mode = ixgbe_fc_none;
2866238263Sjfv		DEBUGOUT("Flow Control = NONE.\n");
2867185352Sjfv	}
2868238263Sjfv	return IXGBE_SUCCESS;
2869215911Sjfv}
2870185352Sjfv
2871215911Sjfv/**
2872215911Sjfv *  ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
2873215911Sjfv *  @hw: pointer to hardware structure
2874215911Sjfv *
2875215911Sjfv *  Enable flow control according on 1 gig fiber.
2876215911Sjfv **/
2877215911Sjfvstatic s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
2878215911Sjfv{
2879215911Sjfv	u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
2880238263Sjfv	s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2881200239Sjfv
2882200239Sjfv	/*
2883200239Sjfv	 * On multispeed fiber at 1g, bail out if
2884200239Sjfv	 * - link is up but AN did not complete, or if
2885200239Sjfv	 * - link is up and AN completed but timed out
2886200239Sjfv	 */
2887215911Sjfv
2888215911Sjfv	linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
2889235528Sjfv	if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
2890252898Sjfv	    (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
2891252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_POLLING,
2892252898Sjfv			     "Auto-Negotiation did not complete or timed out");
2893215911Sjfv		goto out;
2894252898Sjfv	}
2895200239Sjfv
2896215911Sjfv	pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2897215911Sjfv	pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
2898215911Sjfv
2899215911Sjfv	ret_val =  ixgbe_negotiate_fc(hw, pcs_anadv_reg,
2900235528Sjfv				      pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
2901235528Sjfv				      IXGBE_PCS1GANA_ASM_PAUSE,
2902235528Sjfv				      IXGBE_PCS1GANA_SYM_PAUSE,
2903235528Sjfv				      IXGBE_PCS1GANA_ASM_PAUSE);
2904215911Sjfv
2905215911Sjfvout:
2906215911Sjfv	return ret_val;
2907215911Sjfv}
2908215911Sjfv
2909215911Sjfv/**
2910215911Sjfv *  ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
2911215911Sjfv *  @hw: pointer to hardware structure
2912215911Sjfv *
2913215911Sjfv *  Enable flow control according to IEEE clause 37.
2914215911Sjfv **/
2915215911Sjfvstatic s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
2916215911Sjfv{
2917215911Sjfv	u32 links2, anlp1_reg, autoc_reg, links;
2918238263Sjfv	s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2919215911Sjfv
2920200239Sjfv	/*
2921215911Sjfv	 * On backplane, bail out if
2922215911Sjfv	 * - backplane autoneg was not completed, or if
2923215911Sjfv	 * - we are 82599 and link partner is not AN enabled
2924200239Sjfv	 */
2925215911Sjfv	links = IXGBE_READ_REG(hw, IXGBE_LINKS);
2926252898Sjfv	if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
2927252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_POLLING,
2928252898Sjfv			     "Auto-Negotiation did not complete");
2929200239Sjfv		goto out;
2930252898Sjfv	}
2931200239Sjfv
2932215911Sjfv	if (hw->mac.type == ixgbe_mac_82599EB) {
2933215911Sjfv		links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
2934252898Sjfv		if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
2935252898Sjfv			ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
2936252898Sjfv				     "Link partner is not AN enabled");
2937215911Sjfv			goto out;
2938252898Sjfv		}
2939215911Sjfv	}
2940200239Sjfv	/*
2941215911Sjfv	 * Read the 10g AN autoc and LP ability registers and resolve
2942185352Sjfv	 * local flow control settings accordingly
2943185352Sjfv	 */
2944215911Sjfv	autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2945215911Sjfv	anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
2946200239Sjfv
2947215911Sjfv	ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
2948215911Sjfv		anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
2949215911Sjfv		IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
2950215911Sjfv
2951215911Sjfvout:
2952215911Sjfv	return ret_val;
2953215911Sjfv}
2954215911Sjfv
2955215911Sjfv/**
2956215911Sjfv *  ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
2957215911Sjfv *  @hw: pointer to hardware structure
2958215911Sjfv *
2959215911Sjfv *  Enable flow control according to IEEE clause 37.
2960215911Sjfv **/
2961215911Sjfvstatic s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
2962215911Sjfv{
2963215911Sjfv	u16 technology_ability_reg = 0;
2964215911Sjfv	u16 lp_technology_ability_reg = 0;
2965215911Sjfv
2966215911Sjfv	hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
2967215911Sjfv			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2968215911Sjfv			     &technology_ability_reg);
2969215911Sjfv	hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_LP,
2970215911Sjfv			     IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2971215911Sjfv			     &lp_technology_ability_reg);
2972215911Sjfv
2973215911Sjfv	return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
2974215911Sjfv				  (u32)lp_technology_ability_reg,
2975215911Sjfv				  IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
2976215911Sjfv				  IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
2977215911Sjfv}
2978215911Sjfv
2979215911Sjfv/**
2980238263Sjfv *  ixgbe_fc_autoneg - Configure flow control
2981215911Sjfv *  @hw: pointer to hardware structure
2982215911Sjfv *
2983238263Sjfv *  Compares our advertised flow control capabilities to those advertised by
2984238263Sjfv *  our link partner, and determines the proper flow control mode to use.
2985215911Sjfv **/
2986238263Sjfvvoid ixgbe_fc_autoneg(struct ixgbe_hw *hw)
2987215911Sjfv{
2988238263Sjfv	s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2989238263Sjfv	ixgbe_link_speed speed;
2990238263Sjfv	bool link_up;
2991215911Sjfv
2992238263Sjfv	DEBUGFUNC("ixgbe_fc_autoneg");
2993185352Sjfv
2994190873Sjfv	/*
2995238263Sjfv	 * AN should have completed when the cable was plugged in.
2996238263Sjfv	 * Look for reasons to bail out.  Bail out if:
2997238263Sjfv	 * - FC autoneg is disabled, or if
2998238263Sjfv	 * - link is not up.
2999190873Sjfv	 */
3000252898Sjfv	if (hw->fc.disable_fc_autoneg) {
3001252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
3002252898Sjfv			     "Flow control autoneg is disabled");
3003190873Sjfv		goto out;
3004252898Sjfv	}
3005190873Sjfv
3006238263Sjfv	hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
3007252898Sjfv	if (!link_up) {
3008252898Sjfv		ERROR_REPORT1(IXGBE_ERROR_SOFTWARE, "The link is down");
3009190873Sjfv		goto out;
3010252898Sjfv	}
3011190873Sjfv
3012215911Sjfv	switch (hw->phy.media_type) {
3013238263Sjfv	/* Autoneg flow control on fiber adapters */
3014248287Sjfv	case ixgbe_media_type_fiber_fixed:
3015215911Sjfv	case ixgbe_media_type_fiber:
3016238263Sjfv		if (speed == IXGBE_LINK_SPEED_1GB_FULL)
3017238263Sjfv			ret_val = ixgbe_fc_autoneg_fiber(hw);
3018238263Sjfv		break;
3019238263Sjfv
3020238263Sjfv	/* Autoneg flow control on backplane adapters */
3021215911Sjfv	case ixgbe_media_type_backplane:
3022238263Sjfv		ret_val = ixgbe_fc_autoneg_backplane(hw);
3023215911Sjfv		break;
3024215911Sjfv
3025238263Sjfv	/* Autoneg flow control on copper adapters */
3026215911Sjfv	case ixgbe_media_type_copper:
3027252898Sjfv		if (ixgbe_device_supports_autoneg_fc(hw))
3028238263Sjfv			ret_val = ixgbe_fc_autoneg_copper(hw);
3029215911Sjfv		break;
3030215911Sjfv
3031215911Sjfv	default:
3032190873Sjfv		break;
3033190873Sjfv	}
3034190873Sjfv
3035238263Sjfvout:
3036238263Sjfv	if (ret_val == IXGBE_SUCCESS) {
3037238263Sjfv		hw->fc.fc_was_autonegged = TRUE;
3038238263Sjfv	} else {
3039238263Sjfv		hw->fc.fc_was_autonegged = FALSE;
3040238263Sjfv		hw->fc.current_mode = hw->fc.requested_mode;
3041235528Sjfv	}
3042190873Sjfv}
3043190873Sjfv
3044252898Sjfv/*
3045252898Sjfv * ixgbe_pcie_timeout_poll - Return number of times to poll for completion
3046252898Sjfv * @hw: pointer to hardware structure
3047252898Sjfv *
3048252898Sjfv * System-wide timeout range is encoded in PCIe Device Control2 register.
3049252898Sjfv *
3050252898Sjfv * Add 10% to specified maximum and return the number of times to poll for
3051252898Sjfv * completion timeout, in units of 100 microsec.  Never return less than
3052252898Sjfv * 800 = 80 millisec.
3053252898Sjfv */
3054252898Sjfvstatic u32 ixgbe_pcie_timeout_poll(struct ixgbe_hw *hw)
3055252898Sjfv{
3056252898Sjfv	s16 devctl2;
3057252898Sjfv	u32 pollcnt;
3058252898Sjfv
3059252898Sjfv	devctl2 = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_CONTROL2);
3060252898Sjfv	devctl2 &= IXGBE_PCIDEVCTRL2_TIMEO_MASK;
3061252898Sjfv
3062252898Sjfv	switch (devctl2) {
3063252898Sjfv	case IXGBE_PCIDEVCTRL2_65_130ms:
3064252898Sjfv		pollcnt = 1300;		/* 130 millisec */
3065252898Sjfv		break;
3066252898Sjfv	case IXGBE_PCIDEVCTRL2_260_520ms:
3067252898Sjfv		pollcnt = 5200;		/* 520 millisec */
3068252898Sjfv		break;
3069252898Sjfv	case IXGBE_PCIDEVCTRL2_1_2s:
3070252898Sjfv		pollcnt = 20000;	/* 2 sec */
3071252898Sjfv		break;
3072252898Sjfv	case IXGBE_PCIDEVCTRL2_4_8s:
3073252898Sjfv		pollcnt = 80000;	/* 8 sec */
3074252898Sjfv		break;
3075252898Sjfv	case IXGBE_PCIDEVCTRL2_17_34s:
3076252898Sjfv		pollcnt = 34000;	/* 34 sec */
3077252898Sjfv		break;
3078252898Sjfv	case IXGBE_PCIDEVCTRL2_50_100us:	/* 100 microsecs */
3079252898Sjfv	case IXGBE_PCIDEVCTRL2_1_2ms:		/* 2 millisecs */
3080252898Sjfv	case IXGBE_PCIDEVCTRL2_16_32ms:		/* 32 millisec */
3081252898Sjfv	case IXGBE_PCIDEVCTRL2_16_32ms_def:	/* 32 millisec default */
3082252898Sjfv	default:
3083252898Sjfv		pollcnt = 800;		/* 80 millisec minimum */
3084252898Sjfv		break;
3085252898Sjfv	}
3086252898Sjfv
3087252898Sjfv	/* add 10% to spec maximum */
3088252898Sjfv	return (pollcnt * 11) / 10;
3089252898Sjfv}
3090252898Sjfv
3091185352Sjfv/**
3092171384Sjfv *  ixgbe_disable_pcie_master - Disable PCI-express master access
3093171384Sjfv *  @hw: pointer to hardware structure
3094171384Sjfv *
3095171384Sjfv *  Disables PCI-Express master access and verifies there are no pending
3096171384Sjfv *  requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
3097171384Sjfv *  bit hasn't caused the master requests to be disabled, else IXGBE_SUCCESS
3098171384Sjfv *  is returned signifying master requests disabled.
3099171384Sjfv **/
3100171384Sjfvs32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
3101171384Sjfv{
3102235528Sjfv	s32 status = IXGBE_SUCCESS;
3103252898Sjfv	u32 i, poll;
3104171384Sjfv
3105200239Sjfv	DEBUGFUNC("ixgbe_disable_pcie_master");
3106200239Sjfv
3107235528Sjfv	/* Always set this bit to ensure any future transactions are blocked */
3108235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
3109235528Sjfv
3110252898Sjfv	/* Exit if master requests are blocked */
3111205720Sjfv	if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
3112205720Sjfv		goto out;
3113205720Sjfv
3114235528Sjfv	/* Poll for master request bit to clear */
3115171384Sjfv	for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
3116235528Sjfv		usec_delay(100);
3117205720Sjfv		if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
3118235528Sjfv			goto out;
3119205720Sjfv	}
3120205720Sjfv
3121235528Sjfv	/*
3122235528Sjfv	 * Two consecutive resets are required via CTRL.RST per datasheet
3123235528Sjfv	 * 5.2.5.3.2 Master Disable.  We set a flag to inform the reset routine
3124235528Sjfv	 * of this need.  The first reset prevents new master requests from
3125235528Sjfv	 * being issued by our device.  We then must wait 1usec or more for any
3126235528Sjfv	 * remaining completions from the PCIe bus to trickle in, and then reset
3127235528Sjfv	 * again to clear out any effects they may have had on our device.
3128235528Sjfv	 */
3129205720Sjfv	DEBUGOUT("GIO Master Disable bit didn't clear - requesting resets\n");
3130235528Sjfv	hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
3131205720Sjfv
3132205720Sjfv	/*
3133217593Sjfv	 * Before proceeding, make sure that the PCIe block does not have
3134217593Sjfv	 * transactions pending.
3135205720Sjfv	 */
3136252898Sjfv	poll = ixgbe_pcie_timeout_poll(hw);
3137252898Sjfv	for (i = 0; i < poll; i++) {
3138235528Sjfv		usec_delay(100);
3139205720Sjfv		if (!(IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS) &
3140235528Sjfv		    IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
3141235528Sjfv			goto out;
3142171384Sjfv	}
3143171384Sjfv
3144252898Sjfv	ERROR_REPORT1(IXGBE_ERROR_POLLING,
3145252898Sjfv		     "PCIe transaction pending bit also did not clear.\n");
3146235528Sjfv	status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
3147205720Sjfv
3148205720Sjfvout:
3149171384Sjfv	return status;
3150171384Sjfv}
3151171384Sjfv
3152171384Sjfv/**
3153179055Sjfv *  ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
3154171384Sjfv *  @hw: pointer to hardware structure
3155179055Sjfv *  @mask: Mask to specify which semaphore to acquire
3156171384Sjfv *
3157235528Sjfv *  Acquires the SWFW semaphore through the GSSR register for the specified
3158171384Sjfv *  function (CSR, PHY0, PHY1, EEPROM, Flash)
3159171384Sjfv **/
3160171384Sjfvs32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u16 mask)
3161171384Sjfv{
3162252898Sjfv	u32 gssr = 0;
3163171384Sjfv	u32 swmask = mask;
3164171384Sjfv	u32 fwmask = mask << 5;
3165252898Sjfv	u32 timeout = 200;
3166252898Sjfv	u32 i;
3167171384Sjfv
3168200239Sjfv	DEBUGFUNC("ixgbe_acquire_swfw_sync");
3169200239Sjfv
3170252898Sjfv	for (i = 0; i < timeout; i++) {
3171190873Sjfv		/*
3172252898Sjfv		 * SW NVM semaphore bit is used for access to all
3173252898Sjfv		 * SW_FW_SYNC bits (not just NVM)
3174190873Sjfv		 */
3175171384Sjfv		if (ixgbe_get_eeprom_semaphore(hw))
3176200239Sjfv			return IXGBE_ERR_SWFW_SYNC;
3177171384Sjfv
3178171384Sjfv		gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
3179252898Sjfv		if (!(gssr & (fwmask | swmask))) {
3180252898Sjfv			gssr |= swmask;
3181252898Sjfv			IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
3182252898Sjfv			ixgbe_release_eeprom_semaphore(hw);
3183252898Sjfv			return IXGBE_SUCCESS;
3184252898Sjfv		} else {
3185252898Sjfv			/* Resource is currently in use by FW or SW */
3186252898Sjfv			ixgbe_release_eeprom_semaphore(hw);
3187252898Sjfv			msec_delay(5);
3188252898Sjfv		}
3189171384Sjfv	}
3190171384Sjfv
3191252898Sjfv	/* If time expired clear the bits holding the lock and retry */
3192252898Sjfv	if (gssr & (fwmask | swmask))
3193252898Sjfv		ixgbe_release_swfw_sync(hw, gssr & (fwmask | swmask));
3194171384Sjfv
3195252898Sjfv	msec_delay(5);
3196252898Sjfv	return IXGBE_ERR_SWFW_SYNC;
3197171384Sjfv}
3198171384Sjfv
3199171384Sjfv/**
3200171384Sjfv *  ixgbe_release_swfw_sync - Release SWFW semaphore
3201171384Sjfv *  @hw: pointer to hardware structure
3202179055Sjfv *  @mask: Mask to specify which semaphore to release
3203171384Sjfv *
3204235528Sjfv *  Releases the SWFW semaphore through the GSSR register for the specified
3205171384Sjfv *  function (CSR, PHY0, PHY1, EEPROM, Flash)
3206171384Sjfv **/
3207171384Sjfvvoid ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u16 mask)
3208171384Sjfv{
3209171384Sjfv	u32 gssr;
3210171384Sjfv	u32 swmask = mask;
3211171384Sjfv
3212200239Sjfv	DEBUGFUNC("ixgbe_release_swfw_sync");
3213200239Sjfv
3214171384Sjfv	ixgbe_get_eeprom_semaphore(hw);
3215171384Sjfv
3216171384Sjfv	gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
3217171384Sjfv	gssr &= ~swmask;
3218171384Sjfv	IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
3219171384Sjfv
3220171384Sjfv	ixgbe_release_eeprom_semaphore(hw);
3221171384Sjfv}
3222171384Sjfv
3223190873Sjfv/**
3224235528Sjfv *  ixgbe_disable_sec_rx_path_generic - Stops the receive data path
3225235528Sjfv *  @hw: pointer to hardware structure
3226235528Sjfv *
3227235528Sjfv *  Stops the receive data path and waits for the HW to internally empty
3228235528Sjfv *  the Rx security block
3229235528Sjfv **/
3230235528Sjfvs32 ixgbe_disable_sec_rx_path_generic(struct ixgbe_hw *hw)
3231235528Sjfv{
3232235528Sjfv#define IXGBE_MAX_SECRX_POLL 40
3233235528Sjfv
3234235528Sjfv	int i;
3235235528Sjfv	int secrxreg;
3236235528Sjfv
3237235528Sjfv	DEBUGFUNC("ixgbe_disable_sec_rx_path_generic");
3238235528Sjfv
3239235528Sjfv
3240235528Sjfv	secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
3241235528Sjfv	secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
3242235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
3243235528Sjfv	for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
3244235528Sjfv		secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
3245235528Sjfv		if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
3246235528Sjfv			break;
3247235528Sjfv		else
3248235528Sjfv			/* Use interrupt-safe sleep just in case */
3249235528Sjfv			usec_delay(1000);
3250235528Sjfv	}
3251235528Sjfv
3252235528Sjfv	/* For informational purposes only */
3253235528Sjfv	if (i >= IXGBE_MAX_SECRX_POLL)
3254235528Sjfv		DEBUGOUT("Rx unit being enabled before security "
3255235528Sjfv			 "path fully disabled.  Continuing with init.\n");
3256235528Sjfv
3257235528Sjfv	return IXGBE_SUCCESS;
3258235528Sjfv}
3259235528Sjfv
3260235528Sjfv/**
3261235528Sjfv *  ixgbe_enable_sec_rx_path_generic - Enables the receive data path
3262235528Sjfv *  @hw: pointer to hardware structure
3263235528Sjfv *
3264235528Sjfv *  Enables the receive data path.
3265235528Sjfv **/
3266235528Sjfvs32 ixgbe_enable_sec_rx_path_generic(struct ixgbe_hw *hw)
3267235528Sjfv{
3268235528Sjfv	int secrxreg;
3269235528Sjfv
3270235528Sjfv	DEBUGFUNC("ixgbe_enable_sec_rx_path_generic");
3271235528Sjfv
3272235528Sjfv	secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
3273235528Sjfv	secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
3274235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
3275235528Sjfv	IXGBE_WRITE_FLUSH(hw);
3276235528Sjfv
3277235528Sjfv	return IXGBE_SUCCESS;
3278235528Sjfv}
3279235528Sjfv
3280235528Sjfv/**
3281190873Sjfv *  ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
3282190873Sjfv *  @hw: pointer to hardware structure
3283190873Sjfv *  @regval: register value to write to RXCTRL
3284190873Sjfv *
3285190873Sjfv *  Enables the Rx DMA unit
3286190873Sjfv **/
3287190873Sjfvs32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
3288190873Sjfv{
3289200239Sjfv	DEBUGFUNC("ixgbe_enable_rx_dma_generic");
3290200239Sjfv
3291190873Sjfv	IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, regval);
3292190873Sjfv
3293190873Sjfv	return IXGBE_SUCCESS;
3294190873Sjfv}
3295190873Sjfv
3296190873Sjfv/**
3297190873Sjfv *  ixgbe_blink_led_start_generic - Blink LED based on index.
3298190873Sjfv *  @hw: pointer to hardware structure
3299190873Sjfv *  @index: led number to blink
3300190873Sjfv **/
3301190873Sjfvs32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
3302190873Sjfv{
3303190873Sjfv	ixgbe_link_speed speed = 0;
3304190873Sjfv	bool link_up = 0;
3305190873Sjfv	u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
3306190873Sjfv	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
3307248287Sjfv	s32 ret_val = IXGBE_SUCCESS;
3308190873Sjfv
3309200239Sjfv	DEBUGFUNC("ixgbe_blink_led_start_generic");
3310200239Sjfv
3311190873Sjfv	/*
3312190873Sjfv	 * Link must be up to auto-blink the LEDs;
3313190873Sjfv	 * Force it if link is down.
3314190873Sjfv	 */
3315190873Sjfv	hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
3316190873Sjfv
3317190873Sjfv	if (!link_up) {
3318248287Sjfv		/* Need the SW/FW semaphore around AUTOC writes if 82599 and
3319248287Sjfv		 * LESM is on.
3320248287Sjfv		 */
3321248287Sjfv		bool got_lock = FALSE;
3322248287Sjfv		if ((hw->mac.type == ixgbe_mac_82599EB) &&
3323248287Sjfv		    ixgbe_verify_lesm_fw_enabled_82599(hw)) {
3324248287Sjfv			ret_val = hw->mac.ops.acquire_swfw_sync(hw,
3325248287Sjfv							IXGBE_GSSR_MAC_CSR_SM);
3326248287Sjfv			if (ret_val != IXGBE_SUCCESS) {
3327248287Sjfv				ret_val = IXGBE_ERR_SWFW_SYNC;
3328248287Sjfv				goto out;
3329248287Sjfv			}
3330248287Sjfv			got_lock = TRUE;
3331248287Sjfv		}
3332248287Sjfv
3333194875Sjfv		autoc_reg |= IXGBE_AUTOC_AN_RESTART;
3334190873Sjfv		autoc_reg |= IXGBE_AUTOC_FLU;
3335190873Sjfv		IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
3336235528Sjfv		IXGBE_WRITE_FLUSH(hw);
3337248287Sjfv
3338248287Sjfv		if (got_lock)
3339248287Sjfv			hw->mac.ops.release_swfw_sync(hw,
3340248287Sjfv						      IXGBE_GSSR_MAC_CSR_SM);
3341190873Sjfv		msec_delay(10);
3342190873Sjfv	}
3343190873Sjfv
3344190873Sjfv	led_reg &= ~IXGBE_LED_MODE_MASK(index);
3345190873Sjfv	led_reg |= IXGBE_LED_BLINK(index);
3346190873Sjfv	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
3347190873Sjfv	IXGBE_WRITE_FLUSH(hw);
3348190873Sjfv
3349248287Sjfvout:
3350248287Sjfv	return ret_val;
3351190873Sjfv}
3352190873Sjfv
3353190873Sjfv/**
3354190873Sjfv *  ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
3355190873Sjfv *  @hw: pointer to hardware structure
3356190873Sjfv *  @index: led number to stop blinking
3357190873Sjfv **/
3358190873Sjfvs32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
3359190873Sjfv{
3360190873Sjfv	u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
3361190873Sjfv	u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
3362248287Sjfv	s32 ret_val = IXGBE_SUCCESS;
3363248287Sjfv	bool got_lock = FALSE;
3364190873Sjfv
3365200239Sjfv	DEBUGFUNC("ixgbe_blink_led_stop_generic");
3366248287Sjfv	/* Need the SW/FW semaphore around AUTOC writes if 82599 and
3367248287Sjfv	 * LESM is on.
3368248287Sjfv	 */
3369248287Sjfv	if ((hw->mac.type == ixgbe_mac_82599EB) &&
3370248287Sjfv	    ixgbe_verify_lesm_fw_enabled_82599(hw)) {
3371248287Sjfv		ret_val = hw->mac.ops.acquire_swfw_sync(hw,
3372248287Sjfv						IXGBE_GSSR_MAC_CSR_SM);
3373248287Sjfv		if (ret_val != IXGBE_SUCCESS) {
3374248287Sjfv			ret_val = IXGBE_ERR_SWFW_SYNC;
3375248287Sjfv			goto out;
3376248287Sjfv		}
3377248287Sjfv		got_lock = TRUE;
3378248287Sjfv	}
3379194875Sjfv
3380200239Sjfv
3381190873Sjfv	autoc_reg &= ~IXGBE_AUTOC_FLU;
3382190873Sjfv	autoc_reg |= IXGBE_AUTOC_AN_RESTART;
3383190873Sjfv	IXGBE_WRITE_REG(hw, IXGBE_AUTOC, autoc_reg);
3384190873Sjfv
3385248287Sjfv	if (hw->mac.type == ixgbe_mac_82599EB)
3386248287Sjfv		ixgbe_reset_pipeline_82599(hw);
3387248287Sjfv
3388248287Sjfv	if (got_lock)
3389248287Sjfv		hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_MAC_CSR_SM);
3390248287Sjfv
3391190873Sjfv	led_reg &= ~IXGBE_LED_MODE_MASK(index);
3392190873Sjfv	led_reg &= ~IXGBE_LED_BLINK(index);
3393190873Sjfv	led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
3394190873Sjfv	IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
3395190873Sjfv	IXGBE_WRITE_FLUSH(hw);
3396190873Sjfv
3397248287Sjfvout:
3398248287Sjfv	return ret_val;
3399190873Sjfv}
3400190873Sjfv
3401200239Sjfv/**
3402200239Sjfv *  ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
3403200239Sjfv *  @hw: pointer to hardware structure
3404200239Sjfv *  @san_mac_offset: SAN MAC address offset
3405200239Sjfv *
3406200239Sjfv *  This function will read the EEPROM location for the SAN MAC address
3407200239Sjfv *  pointer, and returns the value at that location.  This is used in both
3408200239Sjfv *  get and set mac_addr routines.
3409200239Sjfv **/
3410200239Sjfvstatic s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
3411235528Sjfv					 u16 *san_mac_offset)
3412200239Sjfv{
3413252898Sjfv	s32 ret_val;
3414252898Sjfv
3415200239Sjfv	DEBUGFUNC("ixgbe_get_san_mac_addr_offset");
3416200239Sjfv
3417200239Sjfv	/*
3418200239Sjfv	 * First read the EEPROM pointer to see if the MAC addresses are
3419200239Sjfv	 * available.
3420200239Sjfv	 */
3421252898Sjfv	ret_val = hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR,
3422252898Sjfv				      san_mac_offset);
3423252898Sjfv	if (ret_val) {
3424252898Sjfv		ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
3425252898Sjfv			      "eeprom at offset %d failed",
3426252898Sjfv			      IXGBE_SAN_MAC_ADDR_PTR);
3427252898Sjfv	}
3428200239Sjfv
3429252898Sjfv	return ret_val;
3430200239Sjfv}
3431200239Sjfv
3432200239Sjfv/**
3433200239Sjfv *  ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
3434200239Sjfv *  @hw: pointer to hardware structure
3435200239Sjfv *  @san_mac_addr: SAN MAC address
3436200239Sjfv *
3437200239Sjfv *  Reads the SAN MAC address from the EEPROM, if it's available.  This is
3438200239Sjfv *  per-port, so set_lan_id() must be called before reading the addresses.
3439200239Sjfv *  set_lan_id() is called by identify_sfp(), but this cannot be relied
3440200239Sjfv *  upon for non-SFP connections, so we must call it here.
3441200239Sjfv **/
3442200239Sjfvs32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
3443200239Sjfv{
3444200239Sjfv	u16 san_mac_data, san_mac_offset;
3445200239Sjfv	u8 i;
3446252898Sjfv	s32 ret_val;
3447200239Sjfv
3448200239Sjfv	DEBUGFUNC("ixgbe_get_san_mac_addr_generic");
3449200239Sjfv
3450200239Sjfv	/*
3451200239Sjfv	 * First read the EEPROM pointer to see if the MAC addresses are
3452200239Sjfv	 * available.  If they're not, no point in calling set_lan_id() here.
3453200239Sjfv	 */
3454252898Sjfv	ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
3455252898Sjfv	if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
3456200239Sjfv		goto san_mac_addr_out;
3457200239Sjfv
3458200239Sjfv	/* make sure we know which port we need to program */
3459200239Sjfv	hw->mac.ops.set_lan_id(hw);
3460200239Sjfv	/* apply the port offset to the address offset */
3461200239Sjfv	(hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
3462235528Sjfv			 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
3463200239Sjfv	for (i = 0; i < 3; i++) {
3464252898Sjfv		ret_val = hw->eeprom.ops.read(hw, san_mac_offset,
3465252898Sjfv					      &san_mac_data);
3466252898Sjfv		if (ret_val) {
3467252898Sjfv			ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
3468252898Sjfv				      "eeprom read at offset %d failed",
3469252898Sjfv				      san_mac_offset);
3470252898Sjfv			goto san_mac_addr_out;
3471252898Sjfv		}
3472200239Sjfv		san_mac_addr[i * 2] = (u8)(san_mac_data);
3473200239Sjfv		san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
3474200239Sjfv		san_mac_offset++;
3475200239Sjfv	}
3476252898Sjfv	return IXGBE_SUCCESS;
3477200239Sjfv
3478200239Sjfvsan_mac_addr_out:
3479252898Sjfv	/*
3480252898Sjfv	 * No addresses available in this EEPROM.  It's not an
3481252898Sjfv	 * error though, so just wipe the local address and return.
3482252898Sjfv	 */
3483252898Sjfv	for (i = 0; i < 6; i++)
3484252898Sjfv		san_mac_addr[i] = 0xFF;
3485200239Sjfv	return IXGBE_SUCCESS;
3486200239Sjfv}
3487200239Sjfv
3488200239Sjfv/**
3489200239Sjfv *  ixgbe_set_san_mac_addr_generic - Write the SAN MAC address to the EEPROM
3490200239Sjfv *  @hw: pointer to hardware structure
3491200239Sjfv *  @san_mac_addr: SAN MAC address
3492200239Sjfv *
3493200239Sjfv *  Write a SAN MAC address to the EEPROM.
3494200239Sjfv **/
3495200239Sjfvs32 ixgbe_set_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
3496200239Sjfv{
3497252898Sjfv	s32 ret_val;
3498200239Sjfv	u16 san_mac_data, san_mac_offset;
3499200239Sjfv	u8 i;
3500200239Sjfv
3501200239Sjfv	DEBUGFUNC("ixgbe_set_san_mac_addr_generic");
3502200239Sjfv
3503200239Sjfv	/* Look for SAN mac address pointer.  If not defined, return */
3504252898Sjfv	ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
3505252898Sjfv	if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
3506252898Sjfv		return IXGBE_ERR_NO_SAN_ADDR_PTR;
3507200239Sjfv
3508200239Sjfv	/* Make sure we know which port we need to write */
3509200239Sjfv	hw->mac.ops.set_lan_id(hw);
3510200239Sjfv	/* Apply the port offset to the address offset */
3511200239Sjfv	(hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
3512235528Sjfv			 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
3513200239Sjfv
3514200239Sjfv	for (i = 0; i < 3; i++) {
3515200239Sjfv		san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
3516200239Sjfv		san_mac_data |= (u16)(san_mac_addr[i * 2]);
3517200239Sjfv		hw->eeprom.ops.write(hw, san_mac_offset, san_mac_data);
3518200239Sjfv		san_mac_offset++;
3519200239Sjfv	}
3520200239Sjfv
3521252898Sjfv	return IXGBE_SUCCESS;
3522200239Sjfv}
3523200239Sjfv
3524200239Sjfv/**
3525200239Sjfv *  ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
3526200239Sjfv *  @hw: pointer to hardware structure
3527200239Sjfv *
3528200239Sjfv *  Read PCIe configuration space, and get the MSI-X vector count from
3529200239Sjfv *  the capabilities table.
3530200239Sjfv **/
3531238263Sjfvu16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
3532200239Sjfv{
3533238263Sjfv	u16 msix_count = 1;
3534238263Sjfv	u16 max_msix_count;
3535238263Sjfv	u16 pcie_offset;
3536200239Sjfv
3537238263Sjfv	switch (hw->mac.type) {
3538238263Sjfv	case ixgbe_mac_82598EB:
3539238263Sjfv		pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS;
3540238263Sjfv		max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598;
3541238263Sjfv		break;
3542238263Sjfv	case ixgbe_mac_82599EB:
3543238263Sjfv	case ixgbe_mac_X540:
3544238263Sjfv		pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS;
3545238263Sjfv		max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
3546238263Sjfv		break;
3547238263Sjfv	default:
3548238263Sjfv		return msix_count;
3549238263Sjfv	}
3550238263Sjfv
3551200239Sjfv	DEBUGFUNC("ixgbe_get_pcie_msix_count_generic");
3552238263Sjfv	msix_count = IXGBE_READ_PCIE_WORD(hw, pcie_offset);
3553238263Sjfv	msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
3554200239Sjfv
3555238263Sjfv	/* MSI-X count is zero-based in HW */
3556238263Sjfv	msix_count++;
3557200239Sjfv
3558238263Sjfv	if (msix_count > max_msix_count)
3559238263Sjfv		msix_count = max_msix_count;
3560238263Sjfv
3561200239Sjfv	return msix_count;
3562200239Sjfv}
3563200239Sjfv
3564200239Sjfv/**
3565200239Sjfv *  ixgbe_insert_mac_addr_generic - Find a RAR for this mac address
3566200239Sjfv *  @hw: pointer to hardware structure
3567200239Sjfv *  @addr: Address to put into receive address register
3568200239Sjfv *  @vmdq: VMDq pool to assign
3569200239Sjfv *
3570200239Sjfv *  Puts an ethernet address into a receive address register, or
3571200239Sjfv *  finds the rar that it is aleady in; adds to the pool list
3572200239Sjfv **/
3573200239Sjfvs32 ixgbe_insert_mac_addr_generic(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
3574200239Sjfv{
3575200239Sjfv	static const u32 NO_EMPTY_RAR_FOUND = 0xFFFFFFFF;
3576200239Sjfv	u32 first_empty_rar = NO_EMPTY_RAR_FOUND;
3577200239Sjfv	u32 rar;
3578200239Sjfv	u32 rar_low, rar_high;
3579200239Sjfv	u32 addr_low, addr_high;
3580200239Sjfv
3581200239Sjfv	DEBUGFUNC("ixgbe_insert_mac_addr_generic");
3582200239Sjfv
3583200239Sjfv	/* swap bytes for HW little endian */
3584200239Sjfv	addr_low  = addr[0] | (addr[1] << 8)
3585200239Sjfv			    | (addr[2] << 16)
3586200239Sjfv			    | (addr[3] << 24);
3587200239Sjfv	addr_high = addr[4] | (addr[5] << 8);
3588200239Sjfv
3589200239Sjfv	/*
3590200239Sjfv	 * Either find the mac_id in rar or find the first empty space.
3591200239Sjfv	 * rar_highwater points to just after the highest currently used
3592200239Sjfv	 * rar in order to shorten the search.  It grows when we add a new
3593200239Sjfv	 * rar to the top.
3594200239Sjfv	 */
3595200239Sjfv	for (rar = 0; rar < hw->mac.rar_highwater; rar++) {
3596200239Sjfv		rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
3597200239Sjfv
3598200239Sjfv		if (((IXGBE_RAH_AV & rar_high) == 0)
3599200239Sjfv		    && first_empty_rar == NO_EMPTY_RAR_FOUND) {
3600200239Sjfv			first_empty_rar = rar;
3601200239Sjfv		} else if ((rar_high & 0xFFFF) == addr_high) {
3602200239Sjfv			rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(rar));
3603200239Sjfv			if (rar_low == addr_low)
3604200239Sjfv				break;    /* found it already in the rars */
3605200239Sjfv		}
3606200239Sjfv	}
3607200239Sjfv
3608200239Sjfv	if (rar < hw->mac.rar_highwater) {
3609200239Sjfv		/* already there so just add to the pool bits */
3610200239Sjfv		ixgbe_set_vmdq(hw, rar, vmdq);
3611200239Sjfv	} else if (first_empty_rar != NO_EMPTY_RAR_FOUND) {
3612200239Sjfv		/* stick it into first empty RAR slot we found */
3613200239Sjfv		rar = first_empty_rar;
3614200239Sjfv		ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
3615200239Sjfv	} else if (rar == hw->mac.rar_highwater) {
3616200239Sjfv		/* add it to the top of the list and inc the highwater mark */
3617200239Sjfv		ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
3618200239Sjfv		hw->mac.rar_highwater++;
3619200239Sjfv	} else if (rar >= hw->mac.num_rar_entries) {
3620200239Sjfv		return IXGBE_ERR_INVALID_MAC_ADDR;
3621200239Sjfv	}
3622200239Sjfv
3623200239Sjfv	/*
3624200239Sjfv	 * If we found rar[0], make sure the default pool bit (we use pool 0)
3625200239Sjfv	 * remains cleared to be sure default pool packets will get delivered
3626200239Sjfv	 */
3627200239Sjfv	if (rar == 0)
3628200239Sjfv		ixgbe_clear_vmdq(hw, rar, 0);
3629200239Sjfv
3630200239Sjfv	return rar;
3631200239Sjfv}
3632200239Sjfv
3633200239Sjfv/**
3634200239Sjfv *  ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
3635200239Sjfv *  @hw: pointer to hardware struct
3636200239Sjfv *  @rar: receive address register index to disassociate
3637200239Sjfv *  @vmdq: VMDq pool index to remove from the rar
3638200239Sjfv **/
3639200239Sjfvs32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
3640200239Sjfv{
3641200239Sjfv	u32 mpsar_lo, mpsar_hi;
3642200239Sjfv	u32 rar_entries = hw->mac.num_rar_entries;
3643200239Sjfv
3644200239Sjfv	DEBUGFUNC("ixgbe_clear_vmdq_generic");
3645200239Sjfv
3646215911Sjfv	/* Make sure we are using a valid rar index range */
3647215911Sjfv	if (rar >= rar_entries) {
3648252898Sjfv		ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
3649252898Sjfv			     "RAR index %d is out of range.\n", rar);
3650215911Sjfv		return IXGBE_ERR_INVALID_ARGUMENT;
3651215911Sjfv	}
3652200239Sjfv
3653215911Sjfv	mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3654215911Sjfv	mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3655200239Sjfv
3656215911Sjfv	if (!mpsar_lo && !mpsar_hi)
3657215911Sjfv		goto done;
3658215911Sjfv
3659215911Sjfv	if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
3660215911Sjfv		if (mpsar_lo) {
3661215911Sjfv			IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
3662215911Sjfv			mpsar_lo = 0;
3663200239Sjfv		}
3664215911Sjfv		if (mpsar_hi) {
3665215911Sjfv			IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
3666215911Sjfv			mpsar_hi = 0;
3667215911Sjfv		}
3668215911Sjfv	} else if (vmdq < 32) {
3669215911Sjfv		mpsar_lo &= ~(1 << vmdq);
3670215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
3671200239Sjfv	} else {
3672215911Sjfv		mpsar_hi &= ~(1 << (vmdq - 32));
3673215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
3674200239Sjfv	}
3675200239Sjfv
3676215911Sjfv	/* was that the last pool using this rar? */
3677215911Sjfv	if (mpsar_lo == 0 && mpsar_hi == 0 && rar != 0)
3678215911Sjfv		hw->mac.ops.clear_rar(hw, rar);
3679200239Sjfvdone:
3680200239Sjfv	return IXGBE_SUCCESS;
3681200239Sjfv}
3682200239Sjfv
3683200239Sjfv/**
3684200239Sjfv *  ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
3685200239Sjfv *  @hw: pointer to hardware struct
3686200239Sjfv *  @rar: receive address register index to associate with a VMDq index
3687200239Sjfv *  @vmdq: VMDq pool index
3688200239Sjfv **/
3689200239Sjfvs32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
3690200239Sjfv{
3691200239Sjfv	u32 mpsar;
3692200239Sjfv	u32 rar_entries = hw->mac.num_rar_entries;
3693200239Sjfv
3694200239Sjfv	DEBUGFUNC("ixgbe_set_vmdq_generic");
3695200239Sjfv
3696215911Sjfv	/* Make sure we are using a valid rar index range */
3697215911Sjfv	if (rar >= rar_entries) {
3698252898Sjfv		ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
3699252898Sjfv			     "RAR index %d is out of range.\n", rar);
3700215911Sjfv		return IXGBE_ERR_INVALID_ARGUMENT;
3701200239Sjfv	}
3702215911Sjfv
3703215911Sjfv	if (vmdq < 32) {
3704215911Sjfv		mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3705215911Sjfv		mpsar |= 1 << vmdq;
3706215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
3707215911Sjfv	} else {
3708215911Sjfv		mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3709215911Sjfv		mpsar |= 1 << (vmdq - 32);
3710215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
3711215911Sjfv	}
3712200239Sjfv	return IXGBE_SUCCESS;
3713200239Sjfv}
3714200239Sjfv
3715200239Sjfv/**
3716238263Sjfv *  This function should only be involved in the IOV mode.
3717238263Sjfv *  In IOV mode, Default pool is next pool after the number of
3718238263Sjfv *  VFs advertized and not 0.
3719238263Sjfv *  MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index]
3720238263Sjfv *
3721238263Sjfv *  ixgbe_set_vmdq_san_mac - Associate default VMDq pool index with a rx address
3722238263Sjfv *  @hw: pointer to hardware struct
3723238263Sjfv *  @vmdq: VMDq pool index
3724238263Sjfv **/
3725238263Sjfvs32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq)
3726238263Sjfv{
3727238263Sjfv	u32 rar = hw->mac.san_mac_rar_index;
3728238263Sjfv
3729238263Sjfv	DEBUGFUNC("ixgbe_set_vmdq_san_mac");
3730238263Sjfv
3731238263Sjfv	if (vmdq < 32) {
3732238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 1 << vmdq);
3733238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
3734238263Sjfv	} else {
3735238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
3736238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 1 << (vmdq - 32));
3737238263Sjfv	}
3738238263Sjfv
3739238263Sjfv	return IXGBE_SUCCESS;
3740238263Sjfv}
3741238263Sjfv
3742238263Sjfv/**
3743200239Sjfv *  ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
3744200239Sjfv *  @hw: pointer to hardware structure
3745200239Sjfv **/
3746200239Sjfvs32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
3747200239Sjfv{
3748200239Sjfv	int i;
3749200239Sjfv
3750200239Sjfv	DEBUGFUNC("ixgbe_init_uta_tables_generic");
3751200239Sjfv	DEBUGOUT(" Clearing UTA\n");
3752200239Sjfv
3753200239Sjfv	for (i = 0; i < 128; i++)
3754200239Sjfv		IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
3755200239Sjfv
3756200239Sjfv	return IXGBE_SUCCESS;
3757200239Sjfv}
3758200239Sjfv
3759200239Sjfv/**
3760200239Sjfv *  ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
3761200239Sjfv *  @hw: pointer to hardware structure
3762200239Sjfv *  @vlan: VLAN id to write to VLAN filter
3763200239Sjfv *
3764200239Sjfv *  return the VLVF index where this VLAN id should be placed
3765200239Sjfv *
3766200239Sjfv **/
3767200239Sjfvs32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan)
3768200239Sjfv{
3769200239Sjfv	u32 bits = 0;
3770200239Sjfv	u32 first_empty_slot = 0;
3771200239Sjfv	s32 regindex;
3772200239Sjfv
3773205720Sjfv	/* short cut the special case */
3774205720Sjfv	if (vlan == 0)
3775205720Sjfv		return 0;
3776205720Sjfv
3777200239Sjfv	/*
3778200239Sjfv	  * Search for the vlan id in the VLVF entries. Save off the first empty
3779200239Sjfv	  * slot found along the way
3780200239Sjfv	  */
3781200239Sjfv	for (regindex = 1; regindex < IXGBE_VLVF_ENTRIES; regindex++) {
3782200239Sjfv		bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
3783200239Sjfv		if (!bits && !(first_empty_slot))
3784200239Sjfv			first_empty_slot = regindex;
3785200239Sjfv		else if ((bits & 0x0FFF) == vlan)
3786200239Sjfv			break;
3787200239Sjfv	}
3788200239Sjfv
3789200239Sjfv	/*
3790200239Sjfv	  * If regindex is less than IXGBE_VLVF_ENTRIES, then we found the vlan
3791200239Sjfv	  * in the VLVF. Else use the first empty VLVF register for this
3792200239Sjfv	  * vlan id.
3793200239Sjfv	  */
3794200239Sjfv	if (regindex >= IXGBE_VLVF_ENTRIES) {
3795200239Sjfv		if (first_empty_slot)
3796200239Sjfv			regindex = first_empty_slot;
3797200239Sjfv		else {
3798252898Sjfv			ERROR_REPORT1(IXGBE_ERROR_SOFTWARE,
3799252898Sjfv				     "No space in VLVF.\n");
3800205720Sjfv			regindex = IXGBE_ERR_NO_SPACE;
3801200239Sjfv		}
3802200239Sjfv	}
3803200239Sjfv
3804200239Sjfv	return regindex;
3805200239Sjfv}
3806200239Sjfv
3807200239Sjfv/**
3808200239Sjfv *  ixgbe_set_vfta_generic - Set VLAN filter table
3809200239Sjfv *  @hw: pointer to hardware structure
3810200239Sjfv *  @vlan: VLAN id to write to VLAN filter
3811200239Sjfv *  @vind: VMDq output index that maps queue to VLAN id in VFVFB
3812200239Sjfv *  @vlan_on: boolean flag to turn on/off VLAN in VFVF
3813200239Sjfv *
3814200239Sjfv *  Turn on/off specified VLAN in the VLAN filter table.
3815200239Sjfv **/
3816200239Sjfvs32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
3817235528Sjfv			   bool vlan_on)
3818200239Sjfv{
3819200239Sjfv	s32 regindex;
3820200239Sjfv	u32 bitindex;
3821205720Sjfv	u32 vfta;
3822205720Sjfv	u32 targetbit;
3823235528Sjfv	s32 ret_val = IXGBE_SUCCESS;
3824205720Sjfv	bool vfta_changed = FALSE;
3825200239Sjfv
3826200239Sjfv	DEBUGFUNC("ixgbe_set_vfta_generic");
3827200239Sjfv
3828200239Sjfv	if (vlan > 4095)
3829200239Sjfv		return IXGBE_ERR_PARAM;
3830200239Sjfv
3831200239Sjfv	/*
3832200239Sjfv	 * this is a 2 part operation - first the VFTA, then the
3833200239Sjfv	 * VLVF and VLVFB if VT Mode is set
3834205720Sjfv	 * We don't write the VFTA until we know the VLVF part succeeded.
3835200239Sjfv	 */
3836200239Sjfv
3837200239Sjfv	/* Part 1
3838200239Sjfv	 * The VFTA is a bitstring made up of 128 32-bit registers
3839200239Sjfv	 * that enable the particular VLAN id, much like the MTA:
3840200239Sjfv	 *    bits[11-5]: which register
3841200239Sjfv	 *    bits[4-0]:  which bit in the register
3842200239Sjfv	 */
3843200239Sjfv	regindex = (vlan >> 5) & 0x7F;
3844200239Sjfv	bitindex = vlan & 0x1F;
3845205720Sjfv	targetbit = (1 << bitindex);
3846205720Sjfv	vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regindex));
3847200239Sjfv
3848205720Sjfv	if (vlan_on) {
3849205720Sjfv		if (!(vfta & targetbit)) {
3850205720Sjfv			vfta |= targetbit;
3851205720Sjfv			vfta_changed = TRUE;
3852205720Sjfv		}
3853205720Sjfv	} else {
3854205720Sjfv		if ((vfta & targetbit)) {
3855205720Sjfv			vfta &= ~targetbit;
3856205720Sjfv			vfta_changed = TRUE;
3857205720Sjfv		}
3858205720Sjfv	}
3859200239Sjfv
3860200239Sjfv	/* Part 2
3861235528Sjfv	 * Call ixgbe_set_vlvf_generic to set VLVFB and VLVF
3862235528Sjfv	 */
3863235528Sjfv	ret_val = ixgbe_set_vlvf_generic(hw, vlan, vind, vlan_on,
3864235528Sjfv					 &vfta_changed);
3865235528Sjfv	if (ret_val != IXGBE_SUCCESS)
3866235528Sjfv		return ret_val;
3867235528Sjfv
3868235528Sjfv	if (vfta_changed)
3869235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_VFTA(regindex), vfta);
3870235528Sjfv
3871235528Sjfv	return IXGBE_SUCCESS;
3872235528Sjfv}
3873235528Sjfv
3874235528Sjfv/**
3875235528Sjfv *  ixgbe_set_vlvf_generic - Set VLAN Pool Filter
3876235528Sjfv *  @hw: pointer to hardware structure
3877235528Sjfv *  @vlan: VLAN id to write to VLAN filter
3878235528Sjfv *  @vind: VMDq output index that maps queue to VLAN id in VFVFB
3879235528Sjfv *  @vlan_on: boolean flag to turn on/off VLAN in VFVF
3880235528Sjfv *  @vfta_changed: pointer to boolean flag which indicates whether VFTA
3881235528Sjfv *                 should be changed
3882235528Sjfv *
3883235528Sjfv *  Turn on/off specified bit in VLVF table.
3884235528Sjfv **/
3885235528Sjfvs32 ixgbe_set_vlvf_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
3886235528Sjfv			    bool vlan_on, bool *vfta_changed)
3887235528Sjfv{
3888235528Sjfv	u32 vt;
3889235528Sjfv
3890235528Sjfv	DEBUGFUNC("ixgbe_set_vlvf_generic");
3891235528Sjfv
3892235528Sjfv	if (vlan > 4095)
3893235528Sjfv		return IXGBE_ERR_PARAM;
3894235528Sjfv
3895235528Sjfv	/* If VT Mode is set
3896200239Sjfv	 *   Either vlan_on
3897200239Sjfv	 *     make sure the vlan is in VLVF
3898200239Sjfv	 *     set the vind bit in the matching VLVFB
3899200239Sjfv	 *   Or !vlan_on
3900200239Sjfv	 *     clear the pool bit and possibly the vind
3901200239Sjfv	 */
3902200239Sjfv	vt = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3903200239Sjfv	if (vt & IXGBE_VT_CTL_VT_ENABLE) {
3904205720Sjfv		s32 vlvf_index;
3905235528Sjfv		u32 bits;
3906200239Sjfv
3907205720Sjfv		vlvf_index = ixgbe_find_vlvf_slot(hw, vlan);
3908205720Sjfv		if (vlvf_index < 0)
3909205720Sjfv			return vlvf_index;
3910205720Sjfv
3911200239Sjfv		if (vlan_on) {
3912200239Sjfv			/* set the pool bit */
3913200239Sjfv			if (vind < 32) {
3914200239Sjfv				bits = IXGBE_READ_REG(hw,
3915235528Sjfv						IXGBE_VLVFB(vlvf_index * 2));
3916200239Sjfv				bits |= (1 << vind);
3917200239Sjfv				IXGBE_WRITE_REG(hw,
3918235528Sjfv						IXGBE_VLVFB(vlvf_index * 2),
3919200239Sjfv						bits);
3920200239Sjfv			} else {
3921200239Sjfv				bits = IXGBE_READ_REG(hw,
3922235528Sjfv					IXGBE_VLVFB((vlvf_index * 2) + 1));
3923235528Sjfv				bits |= (1 << (vind - 32));
3924200239Sjfv				IXGBE_WRITE_REG(hw,
3925235528Sjfv					IXGBE_VLVFB((vlvf_index * 2) + 1),
3926235528Sjfv					bits);
3927200239Sjfv			}
3928200239Sjfv		} else {
3929200239Sjfv			/* clear the pool bit */
3930200239Sjfv			if (vind < 32) {
3931200239Sjfv				bits = IXGBE_READ_REG(hw,
3932235528Sjfv						IXGBE_VLVFB(vlvf_index * 2));
3933200239Sjfv				bits &= ~(1 << vind);
3934200239Sjfv				IXGBE_WRITE_REG(hw,
3935235528Sjfv						IXGBE_VLVFB(vlvf_index * 2),
3936200239Sjfv						bits);
3937200239Sjfv				bits |= IXGBE_READ_REG(hw,
3938235528Sjfv					IXGBE_VLVFB((vlvf_index * 2) + 1));
3939200239Sjfv			} else {
3940200239Sjfv				bits = IXGBE_READ_REG(hw,
3941235528Sjfv					IXGBE_VLVFB((vlvf_index * 2) + 1));
3942235528Sjfv				bits &= ~(1 << (vind - 32));
3943200239Sjfv				IXGBE_WRITE_REG(hw,
3944235528Sjfv					IXGBE_VLVFB((vlvf_index * 2) + 1),
3945235528Sjfv					bits);
3946200239Sjfv				bits |= IXGBE_READ_REG(hw,
3947235528Sjfv						IXGBE_VLVFB(vlvf_index * 2));
3948200239Sjfv			}
3949200239Sjfv		}
3950200239Sjfv
3951205720Sjfv		/*
3952205720Sjfv		 * If there are still bits set in the VLVFB registers
3953205720Sjfv		 * for the VLAN ID indicated we need to see if the
3954205720Sjfv		 * caller is requesting that we clear the VFTA entry bit.
3955205720Sjfv		 * If the caller has requested that we clear the VFTA
3956205720Sjfv		 * entry bit but there are still pools/VFs using this VLAN
3957205720Sjfv		 * ID entry then ignore the request.  We're not worried
3958205720Sjfv		 * about the case where we're turning the VFTA VLAN ID
3959205720Sjfv		 * entry bit on, only when requested to turn it off as
3960205720Sjfv		 * there may be multiple pools and/or VFs using the
3961205720Sjfv		 * VLAN ID entry.  In that case we cannot clear the
3962205720Sjfv		 * VFTA bit until all pools/VFs using that VLAN ID have also
3963205720Sjfv		 * been cleared.  This will be indicated by "bits" being
3964205720Sjfv		 * zero.
3965205720Sjfv		 */
3966205720Sjfv		if (bits) {
3967205720Sjfv			IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index),
3968200239Sjfv					(IXGBE_VLVF_VIEN | vlan));
3969235528Sjfv			if ((!vlan_on) && (vfta_changed != NULL)) {
3970205720Sjfv				/* someone wants to clear the vfta entry
3971205720Sjfv				 * but some pools/VFs are still using it.
3972205720Sjfv				 * Ignore it. */
3973235528Sjfv				*vfta_changed = FALSE;
3974205720Sjfv			}
3975235528Sjfv		} else
3976205720Sjfv			IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
3977200239Sjfv	}
3978205720Sjfv
3979200239Sjfv	return IXGBE_SUCCESS;
3980200239Sjfv}
3981200239Sjfv
3982200239Sjfv/**
3983200239Sjfv *  ixgbe_clear_vfta_generic - Clear VLAN filter table
3984200239Sjfv *  @hw: pointer to hardware structure
3985200239Sjfv *
3986200239Sjfv *  Clears the VLAN filer table, and the VMDq index associated with the filter
3987200239Sjfv **/
3988200239Sjfvs32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
3989200239Sjfv{
3990200239Sjfv	u32 offset;
3991200239Sjfv
3992200239Sjfv	DEBUGFUNC("ixgbe_clear_vfta_generic");
3993200239Sjfv
3994200239Sjfv	for (offset = 0; offset < hw->mac.vft_size; offset++)
3995200239Sjfv		IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
3996200239Sjfv
3997200239Sjfv	for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
3998200239Sjfv		IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
3999235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
4000235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_VLVFB((offset * 2) + 1), 0);
4001200239Sjfv	}
4002200239Sjfv
4003200239Sjfv	return IXGBE_SUCCESS;
4004200239Sjfv}
4005200239Sjfv
4006200239Sjfv/**
4007200239Sjfv *  ixgbe_check_mac_link_generic - Determine link and speed status
4008200239Sjfv *  @hw: pointer to hardware structure
4009200239Sjfv *  @speed: pointer to link speed
4010200239Sjfv *  @link_up: TRUE when link is up
4011200239Sjfv *  @link_up_wait_to_complete: bool used to wait for link up or not
4012200239Sjfv *
4013200239Sjfv *  Reads the links register to determine if link is up and the current speed
4014200239Sjfv **/
4015200239Sjfvs32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
4016235528Sjfv				 bool *link_up, bool link_up_wait_to_complete)
4017200239Sjfv{
4018205720Sjfv	u32 links_reg, links_orig;
4019200239Sjfv	u32 i;
4020200239Sjfv
4021200239Sjfv	DEBUGFUNC("ixgbe_check_mac_link_generic");
4022200239Sjfv
4023205720Sjfv	/* clear the old state */
4024205720Sjfv	links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
4025205720Sjfv
4026200239Sjfv	links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
4027205720Sjfv
4028205720Sjfv	if (links_orig != links_reg) {
4029205720Sjfv		DEBUGOUT2("LINKS changed from %08X to %08X\n",
4030235528Sjfv			  links_orig, links_reg);
4031205720Sjfv	}
4032205720Sjfv
4033200239Sjfv	if (link_up_wait_to_complete) {
4034200239Sjfv		for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
4035200239Sjfv			if (links_reg & IXGBE_LINKS_UP) {
4036200239Sjfv				*link_up = TRUE;
4037200239Sjfv				break;
4038200239Sjfv			} else {
4039200239Sjfv				*link_up = FALSE;
4040200239Sjfv			}
4041200239Sjfv			msec_delay(100);
4042200239Sjfv			links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
4043200239Sjfv		}
4044200239Sjfv	} else {
4045200239Sjfv		if (links_reg & IXGBE_LINKS_UP)
4046200239Sjfv			*link_up = TRUE;
4047200239Sjfv		else
4048200239Sjfv			*link_up = FALSE;
4049200239Sjfv	}
4050200239Sjfv
4051200239Sjfv	if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
4052200239Sjfv	    IXGBE_LINKS_SPEED_10G_82599)
4053200239Sjfv		*speed = IXGBE_LINK_SPEED_10GB_FULL;
4054200239Sjfv	else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
4055235528Sjfv		 IXGBE_LINKS_SPEED_1G_82599)
4056200239Sjfv		*speed = IXGBE_LINK_SPEED_1GB_FULL;
4057215911Sjfv	else if ((links_reg & IXGBE_LINKS_SPEED_82599) ==
4058235528Sjfv		 IXGBE_LINKS_SPEED_100_82599)
4059215911Sjfv		*speed = IXGBE_LINK_SPEED_100_FULL;
4060200239Sjfv	else
4061215911Sjfv		*speed = IXGBE_LINK_SPEED_UNKNOWN;
4062200239Sjfv
4063200239Sjfv	return IXGBE_SUCCESS;
4064200239Sjfv}
4065200239Sjfv
4066200239Sjfv/**
4067200239Sjfv *  ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
4068200239Sjfv *  the EEPROM
4069200239Sjfv *  @hw: pointer to hardware structure
4070200239Sjfv *  @wwnn_prefix: the alternative WWNN prefix
4071200239Sjfv *  @wwpn_prefix: the alternative WWPN prefix
4072200239Sjfv *
4073200239Sjfv *  This function will read the EEPROM from the alternative SAN MAC address
4074200239Sjfv *  block to check the support for the alternative WWNN/WWPN prefix support.
4075200239Sjfv **/
4076200239Sjfvs32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
4077235528Sjfv				 u16 *wwpn_prefix)
4078200239Sjfv{
4079200239Sjfv	u16 offset, caps;
4080200239Sjfv	u16 alt_san_mac_blk_offset;
4081200239Sjfv
4082200239Sjfv	DEBUGFUNC("ixgbe_get_wwn_prefix_generic");
4083200239Sjfv
4084200239Sjfv	/* clear output first */
4085200239Sjfv	*wwnn_prefix = 0xFFFF;
4086200239Sjfv	*wwpn_prefix = 0xFFFF;
4087200239Sjfv
4088200239Sjfv	/* check if alternative SAN MAC is supported */
4089252898Sjfv	offset = IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
4090252898Sjfv	if (hw->eeprom.ops.read(hw, offset, &alt_san_mac_blk_offset))
4091252898Sjfv		goto wwn_prefix_err;
4092200239Sjfv
4093200239Sjfv	if ((alt_san_mac_blk_offset == 0) ||
4094200239Sjfv	    (alt_san_mac_blk_offset == 0xFFFF))
4095200239Sjfv		goto wwn_prefix_out;
4096200239Sjfv
4097200239Sjfv	/* check capability in alternative san mac address block */
4098200239Sjfv	offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
4099252898Sjfv	if (hw->eeprom.ops.read(hw, offset, &caps))
4100252898Sjfv		goto wwn_prefix_err;
4101200239Sjfv	if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
4102200239Sjfv		goto wwn_prefix_out;
4103200239Sjfv
4104200239Sjfv	/* get the corresponding prefix for WWNN/WWPN */
4105200239Sjfv	offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
4106252898Sjfv	if (hw->eeprom.ops.read(hw, offset, wwnn_prefix)) {
4107252898Sjfv		ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
4108252898Sjfv			      "eeprom read at offset %d failed", offset);
4109252898Sjfv	}
4110200239Sjfv
4111200239Sjfv	offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
4112252898Sjfv	if (hw->eeprom.ops.read(hw, offset, wwpn_prefix))
4113252898Sjfv		goto wwn_prefix_err;
4114200239Sjfv
4115200239Sjfvwwn_prefix_out:
4116200239Sjfv	return IXGBE_SUCCESS;
4117252898Sjfv
4118252898Sjfvwwn_prefix_err:
4119252898Sjfv	ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
4120252898Sjfv		      "eeprom read at offset %d failed", offset);
4121252898Sjfv	return IXGBE_SUCCESS;
4122200239Sjfv}
4123215911Sjfv
4124215911Sjfv/**
4125215911Sjfv *  ixgbe_get_fcoe_boot_status_generic - Get FCOE boot status from EEPROM
4126215911Sjfv *  @hw: pointer to hardware structure
4127215911Sjfv *  @bs: the fcoe boot status
4128215911Sjfv *
4129215911Sjfv *  This function will read the FCOE boot status from the iSCSI FCOE block
4130215911Sjfv **/
4131215911Sjfvs32 ixgbe_get_fcoe_boot_status_generic(struct ixgbe_hw *hw, u16 *bs)
4132215911Sjfv{
4133215911Sjfv	u16 offset, caps, flags;
4134215911Sjfv	s32 status;
4135215911Sjfv
4136215911Sjfv	DEBUGFUNC("ixgbe_get_fcoe_boot_status_generic");
4137215911Sjfv
4138215911Sjfv	/* clear output first */
4139215911Sjfv	*bs = ixgbe_fcoe_bootstatus_unavailable;
4140215911Sjfv
4141215911Sjfv	/* check if FCOE IBA block is present */
4142215911Sjfv	offset = IXGBE_FCOE_IBA_CAPS_BLK_PTR;
4143215911Sjfv	status = hw->eeprom.ops.read(hw, offset, &caps);
4144215911Sjfv	if (status != IXGBE_SUCCESS)
4145215911Sjfv		goto out;
4146215911Sjfv
4147215911Sjfv	if (!(caps & IXGBE_FCOE_IBA_CAPS_FCOE))
4148215911Sjfv		goto out;
4149215911Sjfv
4150215911Sjfv	/* check if iSCSI FCOE block is populated */
4151215911Sjfv	status = hw->eeprom.ops.read(hw, IXGBE_ISCSI_FCOE_BLK_PTR, &offset);
4152215911Sjfv	if (status != IXGBE_SUCCESS)
4153215911Sjfv		goto out;
4154215911Sjfv
4155215911Sjfv	if ((offset == 0) || (offset == 0xFFFF))
4156215911Sjfv		goto out;
4157215911Sjfv
4158215911Sjfv	/* read fcoe flags in iSCSI FCOE block */
4159215911Sjfv	offset = offset + IXGBE_ISCSI_FCOE_FLAGS_OFFSET;
4160215911Sjfv	status = hw->eeprom.ops.read(hw, offset, &flags);
4161215911Sjfv	if (status != IXGBE_SUCCESS)
4162215911Sjfv		goto out;
4163215911Sjfv
4164215911Sjfv	if (flags & IXGBE_ISCSI_FCOE_FLAGS_ENABLE)
4165215911Sjfv		*bs = ixgbe_fcoe_bootstatus_enabled;
4166215911Sjfv	else
4167215911Sjfv		*bs = ixgbe_fcoe_bootstatus_disabled;
4168215911Sjfv
4169215911Sjfvout:
4170215911Sjfv	return status;
4171215911Sjfv}
4172215911Sjfv
4173215911Sjfv/**
4174215911Sjfv *  ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
4175215911Sjfv *  @hw: pointer to hardware structure
4176215911Sjfv *  @enable: enable or disable switch for anti-spoofing
4177215911Sjfv *  @pf: Physical Function pool - do not enable anti-spoofing for the PF
4178215911Sjfv *
4179215911Sjfv **/
4180215911Sjfvvoid ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int pf)
4181215911Sjfv{
4182215911Sjfv	int j;
4183215911Sjfv	int pf_target_reg = pf >> 3;
4184215911Sjfv	int pf_target_shift = pf % 8;
4185215911Sjfv	u32 pfvfspoof = 0;
4186215911Sjfv
4187215911Sjfv	if (hw->mac.type == ixgbe_mac_82598EB)
4188215911Sjfv		return;
4189215911Sjfv
4190215911Sjfv	if (enable)
4191215911Sjfv		pfvfspoof = IXGBE_SPOOF_MACAS_MASK;
4192215911Sjfv
4193215911Sjfv	/*
4194215911Sjfv	 * PFVFSPOOF register array is size 8 with 8 bits assigned to
4195215911Sjfv	 * MAC anti-spoof enables in each register array element.
4196215911Sjfv	 */
4197238263Sjfv	for (j = 0; j < pf_target_reg; j++)
4198215911Sjfv		IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
4199215911Sjfv
4200215911Sjfv	/*
4201215911Sjfv	 * The PF should be allowed to spoof so that it can support
4202238263Sjfv	 * emulation mode NICs.  Do not set the bits assigned to the PF
4203215911Sjfv	 */
4204238263Sjfv	pfvfspoof &= (1 << pf_target_shift) - 1;
4205238263Sjfv	IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), pfvfspoof);
4206238263Sjfv
4207238263Sjfv	/*
4208238263Sjfv	 * Remaining pools belong to the PF so they do not need to have
4209238263Sjfv	 * anti-spoofing enabled.
4210238263Sjfv	 */
4211238263Sjfv	for (j++; j < IXGBE_PFVFSPOOF_REG_COUNT; j++)
4212238263Sjfv		IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(j), 0);
4213215911Sjfv}
4214215911Sjfv
4215215911Sjfv/**
4216215911Sjfv *  ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
4217215911Sjfv *  @hw: pointer to hardware structure
4218215911Sjfv *  @enable: enable or disable switch for VLAN anti-spoofing
4219215911Sjfv *  @pf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
4220215911Sjfv *
4221215911Sjfv **/
4222215911Sjfvvoid ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
4223215911Sjfv{
4224215911Sjfv	int vf_target_reg = vf >> 3;
4225215911Sjfv	int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
4226215911Sjfv	u32 pfvfspoof;
4227215911Sjfv
4228215911Sjfv	if (hw->mac.type == ixgbe_mac_82598EB)
4229215911Sjfv		return;
4230215911Sjfv
4231215911Sjfv	pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
4232215911Sjfv	if (enable)
4233215911Sjfv		pfvfspoof |= (1 << vf_target_shift);
4234215911Sjfv	else
4235215911Sjfv		pfvfspoof &= ~(1 << vf_target_shift);
4236215911Sjfv	IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
4237215911Sjfv}
4238217593Sjfv
4239217593Sjfv/**
4240217593Sjfv *  ixgbe_get_device_caps_generic - Get additional device capabilities
4241217593Sjfv *  @hw: pointer to hardware structure
4242217593Sjfv *  @device_caps: the EEPROM word with the extra device capabilities
4243217593Sjfv *
4244217593Sjfv *  This function will read the EEPROM location for the device capabilities,
4245217593Sjfv *  and return the word through device_caps.
4246217593Sjfv **/
4247217593Sjfvs32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
4248217593Sjfv{
4249217593Sjfv	DEBUGFUNC("ixgbe_get_device_caps_generic");
4250217593Sjfv
4251217593Sjfv	hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
4252217593Sjfv
4253217593Sjfv	return IXGBE_SUCCESS;
4254217593Sjfv}
4255217593Sjfv
4256217593Sjfv/**
4257217593Sjfv *  ixgbe_enable_relaxed_ordering_gen2 - Enable relaxed ordering
4258217593Sjfv *  @hw: pointer to hardware structure
4259217593Sjfv *
4260217593Sjfv **/
4261217593Sjfvvoid ixgbe_enable_relaxed_ordering_gen2(struct ixgbe_hw *hw)
4262217593Sjfv{
4263217593Sjfv	u32 regval;
4264217593Sjfv	u32 i;
4265217593Sjfv
4266217593Sjfv	DEBUGFUNC("ixgbe_enable_relaxed_ordering_gen2");
4267217593Sjfv
4268217593Sjfv	/* Enable relaxed ordering */
4269217593Sjfv	for (i = 0; i < hw->mac.max_tx_queues; i++) {
4270217593Sjfv		regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
4271238263Sjfv		regval |= IXGBE_DCA_TXCTRL_DESC_WRO_EN;
4272217593Sjfv		IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
4273217593Sjfv	}
4274217593Sjfv
4275217593Sjfv	for (i = 0; i < hw->mac.max_rx_queues; i++) {
4276217593Sjfv		regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
4277238263Sjfv		regval |= IXGBE_DCA_RXCTRL_DATA_WRO_EN |
4278238263Sjfv			  IXGBE_DCA_RXCTRL_HEAD_WRO_EN;
4279217593Sjfv		IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
4280217593Sjfv	}
4281217593Sjfv
4282217593Sjfv}
4283235528Sjfv
4284235528Sjfv/**
4285235528Sjfv *  ixgbe_calculate_checksum - Calculate checksum for buffer
4286235528Sjfv *  @buffer: pointer to EEPROM
4287235528Sjfv *  @length: size of EEPROM to calculate a checksum for
4288235528Sjfv *  Calculates the checksum for some buffer on a specified length.  The
4289235528Sjfv *  checksum calculated is returned.
4290235528Sjfv **/
4291248287Sjfvu8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
4292235528Sjfv{
4293235528Sjfv	u32 i;
4294235528Sjfv	u8 sum = 0;
4295235528Sjfv
4296235528Sjfv	DEBUGFUNC("ixgbe_calculate_checksum");
4297235528Sjfv
4298235528Sjfv	if (!buffer)
4299235528Sjfv		return 0;
4300235528Sjfv
4301235528Sjfv	for (i = 0; i < length; i++)
4302235528Sjfv		sum += buffer[i];
4303235528Sjfv
4304235528Sjfv	return (u8) (0 - sum);
4305235528Sjfv}
4306235528Sjfv
4307235528Sjfv/**
4308235528Sjfv *  ixgbe_host_interface_command - Issue command to manageability block
4309235528Sjfv *  @hw: pointer to the HW structure
4310235528Sjfv *  @buffer: contains the command to write and where the return status will
4311235528Sjfv *   be placed
4312238263Sjfv *  @length: length of buffer, must be multiple of 4 bytes
4313235528Sjfv *
4314235528Sjfv *  Communicates with the manageability block.  On success return IXGBE_SUCCESS
4315235528Sjfv *  else return IXGBE_ERR_HOST_INTERFACE_COMMAND.
4316235528Sjfv **/
4317248287Sjfvs32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
4318248287Sjfv				 u32 length)
4319235528Sjfv{
4320235528Sjfv	u32 hicr, i, bi;
4321235528Sjfv	u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
4322235528Sjfv	u8 buf_len, dword_len;
4323235528Sjfv
4324235528Sjfv	s32 ret_val = IXGBE_SUCCESS;
4325235528Sjfv
4326235528Sjfv	DEBUGFUNC("ixgbe_host_interface_command");
4327235528Sjfv
4328235528Sjfv	if (length == 0 || length & 0x3 ||
4329235528Sjfv	    length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
4330235528Sjfv		DEBUGOUT("Buffer length failure.\n");
4331235528Sjfv		ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
4332235528Sjfv		goto out;
4333235528Sjfv	}
4334235528Sjfv
4335235528Sjfv	/* Check that the host interface is enabled. */
4336235528Sjfv	hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
4337235528Sjfv	if ((hicr & IXGBE_HICR_EN) == 0) {
4338235528Sjfv		DEBUGOUT("IXGBE_HOST_EN bit disabled.\n");
4339235528Sjfv		ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
4340235528Sjfv		goto out;
4341235528Sjfv	}
4342235528Sjfv
4343235528Sjfv	/* Calculate length in DWORDs */
4344235528Sjfv	dword_len = length >> 2;
4345235528Sjfv
4346235528Sjfv	/*
4347235528Sjfv	 * The device driver writes the relevant command block
4348235528Sjfv	 * into the ram area.
4349235528Sjfv	 */
4350235528Sjfv	for (i = 0; i < dword_len; i++)
4351235528Sjfv		IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
4352235528Sjfv				      i, IXGBE_CPU_TO_LE32(buffer[i]));
4353235528Sjfv
4354235528Sjfv	/* Setting this bit tells the ARC that a new command is pending. */
4355235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
4356235528Sjfv
4357235528Sjfv	for (i = 0; i < IXGBE_HI_COMMAND_TIMEOUT; i++) {
4358235528Sjfv		hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
4359235528Sjfv		if (!(hicr & IXGBE_HICR_C))
4360235528Sjfv			break;
4361235528Sjfv		msec_delay(1);
4362235528Sjfv	}
4363235528Sjfv
4364235528Sjfv	/* Check command successful completion. */
4365235528Sjfv	if (i == IXGBE_HI_COMMAND_TIMEOUT ||
4366235528Sjfv	    (!(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))) {
4367235528Sjfv		DEBUGOUT("Command has failed with no status valid.\n");
4368235528Sjfv		ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
4369235528Sjfv		goto out;
4370235528Sjfv	}
4371235528Sjfv
4372235528Sjfv	/* Calculate length in DWORDs */
4373235528Sjfv	dword_len = hdr_size >> 2;
4374235528Sjfv
4375235528Sjfv	/* first pull in the header so we know the buffer length */
4376235528Sjfv	for (bi = 0; bi < dword_len; bi++) {
4377235528Sjfv		buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
4378235528Sjfv		IXGBE_LE32_TO_CPUS(&buffer[bi]);
4379235528Sjfv	}
4380235528Sjfv
4381235528Sjfv	/* If there is any thing in data position pull it in */
4382235528Sjfv	buf_len = ((struct ixgbe_hic_hdr *)buffer)->buf_len;
4383235528Sjfv	if (buf_len == 0)
4384235528Sjfv		goto out;
4385235528Sjfv
4386235528Sjfv	if (length < (buf_len + hdr_size)) {
4387235528Sjfv		DEBUGOUT("Buffer not large enough for reply message.\n");
4388235528Sjfv		ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
4389235528Sjfv		goto out;
4390235528Sjfv	}
4391235528Sjfv
4392235528Sjfv	/* Calculate length in DWORDs, add 3 for odd lengths */
4393235528Sjfv	dword_len = (buf_len + 3) >> 2;
4394235528Sjfv
4395235528Sjfv	/* Pull in the rest of the buffer (bi is where we left off)*/
4396235528Sjfv	for (; bi <= dword_len; bi++) {
4397235528Sjfv		buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
4398235528Sjfv		IXGBE_LE32_TO_CPUS(&buffer[bi]);
4399235528Sjfv	}
4400235528Sjfv
4401235528Sjfvout:
4402235528Sjfv	return ret_val;
4403235528Sjfv}
4404235528Sjfv
4405235528Sjfv/**
4406235528Sjfv *  ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
4407235528Sjfv *  @hw: pointer to the HW structure
4408235528Sjfv *  @maj: driver version major number
4409235528Sjfv *  @min: driver version minor number
4410235528Sjfv *  @build: driver version build number
4411235528Sjfv *  @sub: driver version sub build number
4412235528Sjfv *
4413235528Sjfv *  Sends driver version number to firmware through the manageability
4414235528Sjfv *  block.  On success return IXGBE_SUCCESS
4415235528Sjfv *  else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
4416235528Sjfv *  semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
4417235528Sjfv **/
4418235528Sjfvs32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
4419235528Sjfv				 u8 build, u8 sub)
4420235528Sjfv{
4421235528Sjfv	struct ixgbe_hic_drv_info fw_cmd;
4422235528Sjfv	int i;
4423235528Sjfv	s32 ret_val = IXGBE_SUCCESS;
4424235528Sjfv
4425235528Sjfv	DEBUGFUNC("ixgbe_set_fw_drv_ver_generic");
4426235528Sjfv
4427235528Sjfv	if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM)
4428235528Sjfv	    != IXGBE_SUCCESS) {
4429235528Sjfv		ret_val = IXGBE_ERR_SWFW_SYNC;
4430235528Sjfv		goto out;
4431235528Sjfv	}
4432235528Sjfv
4433235528Sjfv	fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
4434235528Sjfv	fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
4435235528Sjfv	fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
4436235528Sjfv	fw_cmd.port_num = (u8)hw->bus.func;
4437235528Sjfv	fw_cmd.ver_maj = maj;
4438235528Sjfv	fw_cmd.ver_min = min;
4439235528Sjfv	fw_cmd.ver_build = build;
4440235528Sjfv	fw_cmd.ver_sub = sub;
4441235528Sjfv	fw_cmd.hdr.checksum = 0;
4442235528Sjfv	fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
4443235528Sjfv				(FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
4444235528Sjfv	fw_cmd.pad = 0;
4445235528Sjfv	fw_cmd.pad2 = 0;
4446235528Sjfv
4447235528Sjfv	for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
4448235528Sjfv		ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
4449235528Sjfv						       sizeof(fw_cmd));
4450235528Sjfv		if (ret_val != IXGBE_SUCCESS)
4451235528Sjfv			continue;
4452235528Sjfv
4453235528Sjfv		if (fw_cmd.hdr.cmd_or_resp.ret_status ==
4454235528Sjfv		    FW_CEM_RESP_STATUS_SUCCESS)
4455235528Sjfv			ret_val = IXGBE_SUCCESS;
4456235528Sjfv		else
4457235528Sjfv			ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
4458235528Sjfv
4459235528Sjfv		break;
4460235528Sjfv	}
4461235528Sjfv
4462235528Sjfv	hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
4463235528Sjfvout:
4464235528Sjfv	return ret_val;
4465235528Sjfv}
4466235528Sjfv
4467235528Sjfv/**
4468235528Sjfv * ixgbe_set_rxpba_generic - Initialize Rx packet buffer
4469235528Sjfv * @hw: pointer to hardware structure
4470235528Sjfv * @num_pb: number of packet buffers to allocate
4471235528Sjfv * @headroom: reserve n KB of headroom
4472235528Sjfv * @strategy: packet buffer allocation strategy
4473235528Sjfv **/
4474235528Sjfvvoid ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, int num_pb, u32 headroom,
4475235528Sjfv			     int strategy)
4476235528Sjfv{
4477235528Sjfv	u32 pbsize = hw->mac.rx_pb_size;
4478235528Sjfv	int i = 0;
4479235528Sjfv	u32 rxpktsize, txpktsize, txpbthresh;
4480235528Sjfv
4481235528Sjfv	/* Reserve headroom */
4482235528Sjfv	pbsize -= headroom;
4483235528Sjfv
4484235528Sjfv	if (!num_pb)
4485235528Sjfv		num_pb = 1;
4486235528Sjfv
4487235528Sjfv	/* Divide remaining packet buffer space amongst the number of packet
4488235528Sjfv	 * buffers requested using supplied strategy.
4489235528Sjfv	 */
4490235528Sjfv	switch (strategy) {
4491238263Sjfv	case PBA_STRATEGY_WEIGHTED:
4492235528Sjfv		/* ixgbe_dcb_pba_80_48 strategy weight first half of packet
4493235528Sjfv		 * buffer with 5/8 of the packet buffer space.
4494235528Sjfv		 */
4495238263Sjfv		rxpktsize = (pbsize * 5) / (num_pb * 4);
4496235528Sjfv		pbsize -= rxpktsize * (num_pb / 2);
4497235528Sjfv		rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
4498235528Sjfv		for (; i < (num_pb / 2); i++)
4499235528Sjfv			IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
4500235528Sjfv		/* Fall through to configure remaining packet buffers */
4501238263Sjfv	case PBA_STRATEGY_EQUAL:
4502235528Sjfv		rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
4503235528Sjfv		for (; i < num_pb; i++)
4504235528Sjfv			IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
4505235528Sjfv		break;
4506235528Sjfv	default:
4507235528Sjfv		break;
4508235528Sjfv	}
4509235528Sjfv
4510235528Sjfv	/* Only support an equally distributed Tx packet buffer strategy. */
4511235528Sjfv	txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
4512235528Sjfv	txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
4513235528Sjfv	for (i = 0; i < num_pb; i++) {
4514235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
4515235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
4516235528Sjfv	}
4517235528Sjfv
4518235528Sjfv	/* Clear unused TCs, if any, to zero buffer size*/
4519235528Sjfv	for (; i < IXGBE_MAX_PB; i++) {
4520235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
4521235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
4522235528Sjfv		IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
4523235528Sjfv	}
4524235528Sjfv}
4525235528Sjfv
4526235528Sjfv/**
4527235528Sjfv * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
4528235528Sjfv * @hw: pointer to the hardware structure
4529235528Sjfv *
4530235528Sjfv * The 82599 and x540 MACs can experience issues if TX work is still pending
4531235528Sjfv * when a reset occurs.  This function prevents this by flushing the PCIe
4532235528Sjfv * buffers on the system.
4533235528Sjfv **/
4534235528Sjfvvoid ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
4535235528Sjfv{
4536235528Sjfv	u32 gcr_ext, hlreg0;
4537235528Sjfv
4538235528Sjfv	/*
4539235528Sjfv	 * If double reset is not requested then all transactions should
4540235528Sjfv	 * already be clear and as such there is no work to do
4541235528Sjfv	 */
4542235528Sjfv	if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
4543235528Sjfv		return;
4544235528Sjfv
4545235528Sjfv	/*
4546235528Sjfv	 * Set loopback enable to prevent any transmits from being sent
4547235528Sjfv	 * should the link come up.  This assumes that the RXCTRL.RXEN bit
4548235528Sjfv	 * has already been cleared.
4549235528Sjfv	 */
4550235528Sjfv	hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4551235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
4552235528Sjfv
4553235528Sjfv	/* initiate cleaning flow for buffers in the PCIe transaction layer */
4554235528Sjfv	gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
4555235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
4556235528Sjfv			gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
4557235528Sjfv
4558235528Sjfv	/* Flush all writes and allow 20usec for all transactions to clear */
4559235528Sjfv	IXGBE_WRITE_FLUSH(hw);
4560235528Sjfv	usec_delay(20);
4561235528Sjfv
4562235528Sjfv	/* restore previous register values */
4563235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4564235528Sjfv	IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4565235528Sjfv}
4566235528Sjfv
4567252898Sjfv
4568252898Sjfv/**
4569252898Sjfv * ixgbe_dcb_get_rtrup2tc_generic - read rtrup2tc reg
4570252898Sjfv * @hw: pointer to hardware structure
4571252898Sjfv * @map: pointer to u8 arr for returning map
4572252898Sjfv *
4573252898Sjfv * Read the rtrup2tc HW register and resolve its content into map
4574252898Sjfv **/
4575252898Sjfvvoid ixgbe_dcb_get_rtrup2tc_generic(struct ixgbe_hw *hw, u8 *map)
4576252898Sjfv{
4577252898Sjfv	u32 reg, i;
4578252898Sjfv
4579252898Sjfv	reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
4580252898Sjfv	for (i = 0; i < IXGBE_DCB_MAX_USER_PRIORITY; i++)
4581252898Sjfv		map[i] = IXGBE_RTRUP2TC_UP_MASK &
4582252898Sjfv			(reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT));
4583252898Sjfv	return;
4584252898Sjfv}
4585