1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Copyright(c) 1999 - 2018 Intel Corporation. */
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun #include <linux/pci.h>
5*4882a593Smuzhiyun #include <linux/delay.h>
6*4882a593Smuzhiyun #include <linux/sched.h>
7*4882a593Smuzhiyun #include <linux/netdevice.h>
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include "ixgbe.h"
10*4882a593Smuzhiyun #include "ixgbe_common.h"
11*4882a593Smuzhiyun #include "ixgbe_phy.h"
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
14*4882a593Smuzhiyun static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
15*4882a593Smuzhiyun static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
16*4882a593Smuzhiyun static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
17*4882a593Smuzhiyun static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
18*4882a593Smuzhiyun static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
19*4882a593Smuzhiyun u16 count);
20*4882a593Smuzhiyun static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
21*4882a593Smuzhiyun static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
22*4882a593Smuzhiyun static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
23*4882a593Smuzhiyun static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
26*4882a593Smuzhiyun static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg);
27*4882a593Smuzhiyun static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
28*4882a593Smuzhiyun u16 words, u16 *data);
29*4882a593Smuzhiyun static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
30*4882a593Smuzhiyun u16 words, u16 *data);
31*4882a593Smuzhiyun static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
32*4882a593Smuzhiyun u16 offset);
33*4882a593Smuzhiyun static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw);
34*4882a593Smuzhiyun
35*4882a593Smuzhiyun /* Base table for registers values that change by MAC */
36*4882a593Smuzhiyun const u32 ixgbe_mvals_8259X[IXGBE_MVALS_IDX_LIMIT] = {
37*4882a593Smuzhiyun IXGBE_MVALS_INIT(8259X)
38*4882a593Smuzhiyun };
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun /**
41*4882a593Smuzhiyun * ixgbe_device_supports_autoneg_fc - Check if phy supports autoneg flow
42*4882a593Smuzhiyun * control
43*4882a593Smuzhiyun * @hw: pointer to hardware structure
44*4882a593Smuzhiyun *
45*4882a593Smuzhiyun * There are several phys that do not support autoneg flow control. This
46*4882a593Smuzhiyun * function check the device id to see if the associated phy supports
47*4882a593Smuzhiyun * autoneg flow control.
48*4882a593Smuzhiyun **/
ixgbe_device_supports_autoneg_fc(struct ixgbe_hw * hw)49*4882a593Smuzhiyun bool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun bool supported = false;
52*4882a593Smuzhiyun ixgbe_link_speed speed;
53*4882a593Smuzhiyun bool link_up;
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun switch (hw->phy.media_type) {
56*4882a593Smuzhiyun case ixgbe_media_type_fiber:
57*4882a593Smuzhiyun /* flow control autoneg black list */
58*4882a593Smuzhiyun switch (hw->device_id) {
59*4882a593Smuzhiyun case IXGBE_DEV_ID_X550EM_A_SFP:
60*4882a593Smuzhiyun case IXGBE_DEV_ID_X550EM_A_SFP_N:
61*4882a593Smuzhiyun supported = false;
62*4882a593Smuzhiyun break;
63*4882a593Smuzhiyun default:
64*4882a593Smuzhiyun hw->mac.ops.check_link(hw, &speed, &link_up, false);
65*4882a593Smuzhiyun /* if link is down, assume supported */
66*4882a593Smuzhiyun if (link_up)
67*4882a593Smuzhiyun supported = speed == IXGBE_LINK_SPEED_1GB_FULL;
68*4882a593Smuzhiyun else
69*4882a593Smuzhiyun supported = true;
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun break;
73*4882a593Smuzhiyun case ixgbe_media_type_backplane:
74*4882a593Smuzhiyun if (hw->device_id == IXGBE_DEV_ID_X550EM_X_XFI)
75*4882a593Smuzhiyun supported = false;
76*4882a593Smuzhiyun else
77*4882a593Smuzhiyun supported = true;
78*4882a593Smuzhiyun break;
79*4882a593Smuzhiyun case ixgbe_media_type_copper:
80*4882a593Smuzhiyun /* only some copper devices support flow control autoneg */
81*4882a593Smuzhiyun switch (hw->device_id) {
82*4882a593Smuzhiyun case IXGBE_DEV_ID_82599_T3_LOM:
83*4882a593Smuzhiyun case IXGBE_DEV_ID_X540T:
84*4882a593Smuzhiyun case IXGBE_DEV_ID_X540T1:
85*4882a593Smuzhiyun case IXGBE_DEV_ID_X550T:
86*4882a593Smuzhiyun case IXGBE_DEV_ID_X550T1:
87*4882a593Smuzhiyun case IXGBE_DEV_ID_X550EM_X_10G_T:
88*4882a593Smuzhiyun case IXGBE_DEV_ID_X550EM_A_10G_T:
89*4882a593Smuzhiyun case IXGBE_DEV_ID_X550EM_A_1G_T:
90*4882a593Smuzhiyun case IXGBE_DEV_ID_X550EM_A_1G_T_L:
91*4882a593Smuzhiyun supported = true;
92*4882a593Smuzhiyun break;
93*4882a593Smuzhiyun default:
94*4882a593Smuzhiyun break;
95*4882a593Smuzhiyun }
96*4882a593Smuzhiyun default:
97*4882a593Smuzhiyun break;
98*4882a593Smuzhiyun }
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun if (!supported)
101*4882a593Smuzhiyun hw_dbg(hw, "Device %x does not support flow control autoneg\n",
102*4882a593Smuzhiyun hw->device_id);
103*4882a593Smuzhiyun
104*4882a593Smuzhiyun return supported;
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun
107*4882a593Smuzhiyun /**
108*4882a593Smuzhiyun * ixgbe_setup_fc_generic - Set up flow control
109*4882a593Smuzhiyun * @hw: pointer to hardware structure
110*4882a593Smuzhiyun *
111*4882a593Smuzhiyun * Called at init time to set up flow control.
112*4882a593Smuzhiyun **/
ixgbe_setup_fc_generic(struct ixgbe_hw * hw)113*4882a593Smuzhiyun s32 ixgbe_setup_fc_generic(struct ixgbe_hw *hw)
114*4882a593Smuzhiyun {
115*4882a593Smuzhiyun s32 ret_val = 0;
116*4882a593Smuzhiyun u32 reg = 0, reg_bp = 0;
117*4882a593Smuzhiyun u16 reg_cu = 0;
118*4882a593Smuzhiyun bool locked = false;
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun /*
121*4882a593Smuzhiyun * Validate the requested mode. Strict IEEE mode does not allow
122*4882a593Smuzhiyun * ixgbe_fc_rx_pause because it will cause us to fail at UNH.
123*4882a593Smuzhiyun */
124*4882a593Smuzhiyun if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
125*4882a593Smuzhiyun hw_dbg(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
126*4882a593Smuzhiyun return IXGBE_ERR_INVALID_LINK_SETTINGS;
127*4882a593Smuzhiyun }
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun /*
130*4882a593Smuzhiyun * 10gig parts do not have a word in the EEPROM to determine the
131*4882a593Smuzhiyun * default flow control setting, so we explicitly set it to full.
132*4882a593Smuzhiyun */
133*4882a593Smuzhiyun if (hw->fc.requested_mode == ixgbe_fc_default)
134*4882a593Smuzhiyun hw->fc.requested_mode = ixgbe_fc_full;
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun /*
137*4882a593Smuzhiyun * Set up the 1G and 10G flow control advertisement registers so the
138*4882a593Smuzhiyun * HW will be able to do fc autoneg once the cable is plugged in. If
139*4882a593Smuzhiyun * we link at 10G, the 1G advertisement is harmless and vice versa.
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun switch (hw->phy.media_type) {
142*4882a593Smuzhiyun case ixgbe_media_type_backplane:
143*4882a593Smuzhiyun /* some MAC's need RMW protection on AUTOC */
144*4882a593Smuzhiyun ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, ®_bp);
145*4882a593Smuzhiyun if (ret_val)
146*4882a593Smuzhiyun return ret_val;
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun fallthrough; /* only backplane uses autoc */
149*4882a593Smuzhiyun case ixgbe_media_type_fiber:
150*4882a593Smuzhiyun reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun break;
153*4882a593Smuzhiyun case ixgbe_media_type_copper:
154*4882a593Smuzhiyun hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
155*4882a593Smuzhiyun MDIO_MMD_AN, ®_cu);
156*4882a593Smuzhiyun break;
157*4882a593Smuzhiyun default:
158*4882a593Smuzhiyun break;
159*4882a593Smuzhiyun }
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /*
162*4882a593Smuzhiyun * The possible values of fc.requested_mode are:
163*4882a593Smuzhiyun * 0: Flow control is completely disabled
164*4882a593Smuzhiyun * 1: Rx flow control is enabled (we can receive pause frames,
165*4882a593Smuzhiyun * but not send pause frames).
166*4882a593Smuzhiyun * 2: Tx flow control is enabled (we can send pause frames but
167*4882a593Smuzhiyun * we do not support receiving pause frames).
168*4882a593Smuzhiyun * 3: Both Rx and Tx flow control (symmetric) are enabled.
169*4882a593Smuzhiyun * other: Invalid.
170*4882a593Smuzhiyun */
171*4882a593Smuzhiyun switch (hw->fc.requested_mode) {
172*4882a593Smuzhiyun case ixgbe_fc_none:
173*4882a593Smuzhiyun /* Flow control completely disabled by software override. */
174*4882a593Smuzhiyun reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
175*4882a593Smuzhiyun if (hw->phy.media_type == ixgbe_media_type_backplane)
176*4882a593Smuzhiyun reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
177*4882a593Smuzhiyun IXGBE_AUTOC_ASM_PAUSE);
178*4882a593Smuzhiyun else if (hw->phy.media_type == ixgbe_media_type_copper)
179*4882a593Smuzhiyun reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
180*4882a593Smuzhiyun break;
181*4882a593Smuzhiyun case ixgbe_fc_tx_pause:
182*4882a593Smuzhiyun /*
183*4882a593Smuzhiyun * Tx Flow control is enabled, and Rx Flow control is
184*4882a593Smuzhiyun * disabled by software override.
185*4882a593Smuzhiyun */
186*4882a593Smuzhiyun reg |= IXGBE_PCS1GANA_ASM_PAUSE;
187*4882a593Smuzhiyun reg &= ~IXGBE_PCS1GANA_SYM_PAUSE;
188*4882a593Smuzhiyun if (hw->phy.media_type == ixgbe_media_type_backplane) {
189*4882a593Smuzhiyun reg_bp |= IXGBE_AUTOC_ASM_PAUSE;
190*4882a593Smuzhiyun reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE;
191*4882a593Smuzhiyun } else if (hw->phy.media_type == ixgbe_media_type_copper) {
192*4882a593Smuzhiyun reg_cu |= IXGBE_TAF_ASM_PAUSE;
193*4882a593Smuzhiyun reg_cu &= ~IXGBE_TAF_SYM_PAUSE;
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun break;
196*4882a593Smuzhiyun case ixgbe_fc_rx_pause:
197*4882a593Smuzhiyun /*
198*4882a593Smuzhiyun * Rx Flow control is enabled and Tx Flow control is
199*4882a593Smuzhiyun * disabled by software override. Since there really
200*4882a593Smuzhiyun * isn't a way to advertise that we are capable of RX
201*4882a593Smuzhiyun * Pause ONLY, we will advertise that we support both
202*4882a593Smuzhiyun * symmetric and asymmetric Rx PAUSE, as such we fall
203*4882a593Smuzhiyun * through to the fc_full statement. Later, we will
204*4882a593Smuzhiyun * disable the adapter's ability to send PAUSE frames.
205*4882a593Smuzhiyun */
206*4882a593Smuzhiyun case ixgbe_fc_full:
207*4882a593Smuzhiyun /* Flow control (both Rx and Tx) is enabled by SW override. */
208*4882a593Smuzhiyun reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE;
209*4882a593Smuzhiyun if (hw->phy.media_type == ixgbe_media_type_backplane)
210*4882a593Smuzhiyun reg_bp |= IXGBE_AUTOC_SYM_PAUSE |
211*4882a593Smuzhiyun IXGBE_AUTOC_ASM_PAUSE;
212*4882a593Smuzhiyun else if (hw->phy.media_type == ixgbe_media_type_copper)
213*4882a593Smuzhiyun reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE;
214*4882a593Smuzhiyun break;
215*4882a593Smuzhiyun default:
216*4882a593Smuzhiyun hw_dbg(hw, "Flow control param set incorrectly\n");
217*4882a593Smuzhiyun return IXGBE_ERR_CONFIG;
218*4882a593Smuzhiyun }
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun if (hw->mac.type != ixgbe_mac_X540) {
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun * Enable auto-negotiation between the MAC & PHY;
223*4882a593Smuzhiyun * the MAC will advertise clause 37 flow control.
224*4882a593Smuzhiyun */
225*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
226*4882a593Smuzhiyun reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
227*4882a593Smuzhiyun
228*4882a593Smuzhiyun /* Disable AN timeout */
229*4882a593Smuzhiyun if (hw->fc.strict_ieee)
230*4882a593Smuzhiyun reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
233*4882a593Smuzhiyun hw_dbg(hw, "Set up FC; PCS1GLCTL = 0x%08X\n", reg);
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun /*
237*4882a593Smuzhiyun * AUTOC restart handles negotiation of 1G and 10G on backplane
238*4882a593Smuzhiyun * and copper. There is no need to set the PCS1GCTL register.
239*4882a593Smuzhiyun *
240*4882a593Smuzhiyun */
241*4882a593Smuzhiyun if (hw->phy.media_type == ixgbe_media_type_backplane) {
242*4882a593Smuzhiyun /* Need the SW/FW semaphore around AUTOC writes if 82599 and
243*4882a593Smuzhiyun * LESM is on, likewise reset_pipeline requries the lock as
244*4882a593Smuzhiyun * it also writes AUTOC.
245*4882a593Smuzhiyun */
246*4882a593Smuzhiyun ret_val = hw->mac.ops.prot_autoc_write(hw, reg_bp, locked);
247*4882a593Smuzhiyun if (ret_val)
248*4882a593Smuzhiyun return ret_val;
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
251*4882a593Smuzhiyun ixgbe_device_supports_autoneg_fc(hw)) {
252*4882a593Smuzhiyun hw->phy.ops.write_reg(hw, MDIO_AN_ADVERTISE,
253*4882a593Smuzhiyun MDIO_MMD_AN, reg_cu);
254*4882a593Smuzhiyun }
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun hw_dbg(hw, "Set up FC; IXGBE_AUTOC = 0x%08X\n", reg);
257*4882a593Smuzhiyun return ret_val;
258*4882a593Smuzhiyun }
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun /**
261*4882a593Smuzhiyun * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
262*4882a593Smuzhiyun * @hw: pointer to hardware structure
263*4882a593Smuzhiyun *
264*4882a593Smuzhiyun * Starts the hardware by filling the bus info structure and media type, clears
265*4882a593Smuzhiyun * all on chip counters, initializes receive address registers, multicast
266*4882a593Smuzhiyun * table, VLAN filter table, calls routine to set up link and flow control
267*4882a593Smuzhiyun * settings, and leaves transmit and receive units disabled and uninitialized
268*4882a593Smuzhiyun **/
ixgbe_start_hw_generic(struct ixgbe_hw * hw)269*4882a593Smuzhiyun s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
270*4882a593Smuzhiyun {
271*4882a593Smuzhiyun s32 ret_val;
272*4882a593Smuzhiyun u32 ctrl_ext;
273*4882a593Smuzhiyun u16 device_caps;
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun /* Set the media type */
276*4882a593Smuzhiyun hw->phy.media_type = hw->mac.ops.get_media_type(hw);
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun /* Identify the PHY */
279*4882a593Smuzhiyun hw->phy.ops.identify(hw);
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun /* Clear the VLAN filter table */
282*4882a593Smuzhiyun hw->mac.ops.clear_vfta(hw);
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun /* Clear statistics registers */
285*4882a593Smuzhiyun hw->mac.ops.clear_hw_cntrs(hw);
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun /* Set No Snoop Disable */
288*4882a593Smuzhiyun ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
289*4882a593Smuzhiyun ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
290*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
291*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun /* Setup flow control if method for doing so */
294*4882a593Smuzhiyun if (hw->mac.ops.setup_fc) {
295*4882a593Smuzhiyun ret_val = hw->mac.ops.setup_fc(hw);
296*4882a593Smuzhiyun if (ret_val)
297*4882a593Smuzhiyun return ret_val;
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun /* Cashe bit indicating need for crosstalk fix */
301*4882a593Smuzhiyun switch (hw->mac.type) {
302*4882a593Smuzhiyun case ixgbe_mac_82599EB:
303*4882a593Smuzhiyun case ixgbe_mac_X550EM_x:
304*4882a593Smuzhiyun case ixgbe_mac_x550em_a:
305*4882a593Smuzhiyun hw->mac.ops.get_device_caps(hw, &device_caps);
306*4882a593Smuzhiyun if (device_caps & IXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
307*4882a593Smuzhiyun hw->need_crosstalk_fix = false;
308*4882a593Smuzhiyun else
309*4882a593Smuzhiyun hw->need_crosstalk_fix = true;
310*4882a593Smuzhiyun break;
311*4882a593Smuzhiyun default:
312*4882a593Smuzhiyun hw->need_crosstalk_fix = false;
313*4882a593Smuzhiyun break;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun /* Clear adapter stopped flag */
317*4882a593Smuzhiyun hw->adapter_stopped = false;
318*4882a593Smuzhiyun
319*4882a593Smuzhiyun return 0;
320*4882a593Smuzhiyun }
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun /**
323*4882a593Smuzhiyun * ixgbe_start_hw_gen2 - Init sequence for common device family
324*4882a593Smuzhiyun * @hw: pointer to hw structure
325*4882a593Smuzhiyun *
326*4882a593Smuzhiyun * Performs the init sequence common to the second generation
327*4882a593Smuzhiyun * of 10 GbE devices.
328*4882a593Smuzhiyun * Devices in the second generation:
329*4882a593Smuzhiyun * 82599
330*4882a593Smuzhiyun * X540
331*4882a593Smuzhiyun **/
ixgbe_start_hw_gen2(struct ixgbe_hw * hw)332*4882a593Smuzhiyun s32 ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
333*4882a593Smuzhiyun {
334*4882a593Smuzhiyun u32 i;
335*4882a593Smuzhiyun
336*4882a593Smuzhiyun /* Clear the rate limiters */
337*4882a593Smuzhiyun for (i = 0; i < hw->mac.max_tx_queues; i++) {
338*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
339*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
340*4882a593Smuzhiyun }
341*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun return 0;
344*4882a593Smuzhiyun }
345*4882a593Smuzhiyun
346*4882a593Smuzhiyun /**
347*4882a593Smuzhiyun * ixgbe_init_hw_generic - Generic hardware initialization
348*4882a593Smuzhiyun * @hw: pointer to hardware structure
349*4882a593Smuzhiyun *
350*4882a593Smuzhiyun * Initialize the hardware by resetting the hardware, filling the bus info
351*4882a593Smuzhiyun * structure and media type, clears all on chip counters, initializes receive
352*4882a593Smuzhiyun * address registers, multicast table, VLAN filter table, calls routine to set
353*4882a593Smuzhiyun * up link and flow control settings, and leaves transmit and receive units
354*4882a593Smuzhiyun * disabled and uninitialized
355*4882a593Smuzhiyun **/
ixgbe_init_hw_generic(struct ixgbe_hw * hw)356*4882a593Smuzhiyun s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
357*4882a593Smuzhiyun {
358*4882a593Smuzhiyun s32 status;
359*4882a593Smuzhiyun
360*4882a593Smuzhiyun /* Reset the hardware */
361*4882a593Smuzhiyun status = hw->mac.ops.reset_hw(hw);
362*4882a593Smuzhiyun
363*4882a593Smuzhiyun if (status == 0) {
364*4882a593Smuzhiyun /* Start the HW */
365*4882a593Smuzhiyun status = hw->mac.ops.start_hw(hw);
366*4882a593Smuzhiyun }
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun /* Initialize the LED link active for LED blink support */
369*4882a593Smuzhiyun if (hw->mac.ops.init_led_link_act)
370*4882a593Smuzhiyun hw->mac.ops.init_led_link_act(hw);
371*4882a593Smuzhiyun
372*4882a593Smuzhiyun return status;
373*4882a593Smuzhiyun }
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun /**
376*4882a593Smuzhiyun * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
377*4882a593Smuzhiyun * @hw: pointer to hardware structure
378*4882a593Smuzhiyun *
379*4882a593Smuzhiyun * Clears all hardware statistics counters by reading them from the hardware
380*4882a593Smuzhiyun * Statistics counters are clear on read.
381*4882a593Smuzhiyun **/
ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw * hw)382*4882a593Smuzhiyun s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
383*4882a593Smuzhiyun {
384*4882a593Smuzhiyun u16 i = 0;
385*4882a593Smuzhiyun
386*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_CRCERRS);
387*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_ILLERRC);
388*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_ERRBC);
389*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MSPDC);
390*4882a593Smuzhiyun for (i = 0; i < 8; i++)
391*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MPC(i));
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MLFC);
394*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MRFC);
395*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_RLEC);
396*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_LXONTXC);
397*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
398*4882a593Smuzhiyun if (hw->mac.type >= ixgbe_mac_82599EB) {
399*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
400*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
401*4882a593Smuzhiyun } else {
402*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_LXONRXC);
403*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
404*4882a593Smuzhiyun }
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun for (i = 0; i < 8; i++) {
407*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
408*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
409*4882a593Smuzhiyun if (hw->mac.type >= ixgbe_mac_82599EB) {
410*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
411*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
412*4882a593Smuzhiyun } else {
413*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
414*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
415*4882a593Smuzhiyun }
416*4882a593Smuzhiyun }
417*4882a593Smuzhiyun if (hw->mac.type >= ixgbe_mac_82599EB)
418*4882a593Smuzhiyun for (i = 0; i < 8; i++)
419*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
420*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PRC64);
421*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PRC127);
422*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PRC255);
423*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PRC511);
424*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PRC1023);
425*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PRC1522);
426*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_GPRC);
427*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_BPRC);
428*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MPRC);
429*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_GPTC);
430*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_GORCL);
431*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_GORCH);
432*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_GOTCL);
433*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_GOTCH);
434*4882a593Smuzhiyun if (hw->mac.type == ixgbe_mac_82598EB)
435*4882a593Smuzhiyun for (i = 0; i < 8; i++)
436*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_RNBC(i));
437*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_RUC);
438*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_RFC);
439*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_ROC);
440*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_RJC);
441*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MNGPRC);
442*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MNGPDC);
443*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MNGPTC);
444*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_TORL);
445*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_TORH);
446*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_TPR);
447*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_TPT);
448*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PTC64);
449*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PTC127);
450*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PTC255);
451*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PTC511);
452*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PTC1023);
453*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_PTC1522);
454*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_MPTC);
455*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_BPTC);
456*4882a593Smuzhiyun for (i = 0; i < 16; i++) {
457*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QPRC(i));
458*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QPTC(i));
459*4882a593Smuzhiyun if (hw->mac.type >= ixgbe_mac_82599EB) {
460*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
461*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
462*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
463*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
464*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
465*4882a593Smuzhiyun } else {
466*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QBRC(i));
467*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_QBTC(i));
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun }
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun if (hw->mac.type == ixgbe_mac_X550 || hw->mac.type == ixgbe_mac_X540) {
472*4882a593Smuzhiyun if (hw->phy.id == 0)
473*4882a593Smuzhiyun hw->phy.ops.identify(hw);
474*4882a593Smuzhiyun hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECL, MDIO_MMD_PCS, &i);
475*4882a593Smuzhiyun hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECH, MDIO_MMD_PCS, &i);
476*4882a593Smuzhiyun hw->phy.ops.read_reg(hw, IXGBE_LDPCECL, MDIO_MMD_PCS, &i);
477*4882a593Smuzhiyun hw->phy.ops.read_reg(hw, IXGBE_LDPCECH, MDIO_MMD_PCS, &i);
478*4882a593Smuzhiyun }
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun return 0;
481*4882a593Smuzhiyun }
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun /**
484*4882a593Smuzhiyun * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
485*4882a593Smuzhiyun * @hw: pointer to hardware structure
486*4882a593Smuzhiyun * @pba_num: stores the part number string from the EEPROM
487*4882a593Smuzhiyun * @pba_num_size: part number string buffer length
488*4882a593Smuzhiyun *
489*4882a593Smuzhiyun * Reads the part number string from the EEPROM.
490*4882a593Smuzhiyun **/
ixgbe_read_pba_string_generic(struct ixgbe_hw * hw,u8 * pba_num,u32 pba_num_size)491*4882a593Smuzhiyun s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
492*4882a593Smuzhiyun u32 pba_num_size)
493*4882a593Smuzhiyun {
494*4882a593Smuzhiyun s32 ret_val;
495*4882a593Smuzhiyun u16 data;
496*4882a593Smuzhiyun u16 pba_ptr;
497*4882a593Smuzhiyun u16 offset;
498*4882a593Smuzhiyun u16 length;
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun if (pba_num == NULL) {
501*4882a593Smuzhiyun hw_dbg(hw, "PBA string buffer was null\n");
502*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
503*4882a593Smuzhiyun }
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
506*4882a593Smuzhiyun if (ret_val) {
507*4882a593Smuzhiyun hw_dbg(hw, "NVM Read Error\n");
508*4882a593Smuzhiyun return ret_val;
509*4882a593Smuzhiyun }
510*4882a593Smuzhiyun
511*4882a593Smuzhiyun ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
512*4882a593Smuzhiyun if (ret_val) {
513*4882a593Smuzhiyun hw_dbg(hw, "NVM Read Error\n");
514*4882a593Smuzhiyun return ret_val;
515*4882a593Smuzhiyun }
516*4882a593Smuzhiyun
517*4882a593Smuzhiyun /*
518*4882a593Smuzhiyun * if data is not ptr guard the PBA must be in legacy format which
519*4882a593Smuzhiyun * means pba_ptr is actually our second data word for the PBA number
520*4882a593Smuzhiyun * and we can decode it into an ascii string
521*4882a593Smuzhiyun */
522*4882a593Smuzhiyun if (data != IXGBE_PBANUM_PTR_GUARD) {
523*4882a593Smuzhiyun hw_dbg(hw, "NVM PBA number is not stored as string\n");
524*4882a593Smuzhiyun
525*4882a593Smuzhiyun /* we will need 11 characters to store the PBA */
526*4882a593Smuzhiyun if (pba_num_size < 11) {
527*4882a593Smuzhiyun hw_dbg(hw, "PBA string buffer too small\n");
528*4882a593Smuzhiyun return IXGBE_ERR_NO_SPACE;
529*4882a593Smuzhiyun }
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun /* extract hex string from data and pba_ptr */
532*4882a593Smuzhiyun pba_num[0] = (data >> 12) & 0xF;
533*4882a593Smuzhiyun pba_num[1] = (data >> 8) & 0xF;
534*4882a593Smuzhiyun pba_num[2] = (data >> 4) & 0xF;
535*4882a593Smuzhiyun pba_num[3] = data & 0xF;
536*4882a593Smuzhiyun pba_num[4] = (pba_ptr >> 12) & 0xF;
537*4882a593Smuzhiyun pba_num[5] = (pba_ptr >> 8) & 0xF;
538*4882a593Smuzhiyun pba_num[6] = '-';
539*4882a593Smuzhiyun pba_num[7] = 0;
540*4882a593Smuzhiyun pba_num[8] = (pba_ptr >> 4) & 0xF;
541*4882a593Smuzhiyun pba_num[9] = pba_ptr & 0xF;
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun /* put a null character on the end of our string */
544*4882a593Smuzhiyun pba_num[10] = '\0';
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun /* switch all the data but the '-' to hex char */
547*4882a593Smuzhiyun for (offset = 0; offset < 10; offset++) {
548*4882a593Smuzhiyun if (pba_num[offset] < 0xA)
549*4882a593Smuzhiyun pba_num[offset] += '0';
550*4882a593Smuzhiyun else if (pba_num[offset] < 0x10)
551*4882a593Smuzhiyun pba_num[offset] += 'A' - 0xA;
552*4882a593Smuzhiyun }
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun return 0;
555*4882a593Smuzhiyun }
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
558*4882a593Smuzhiyun if (ret_val) {
559*4882a593Smuzhiyun hw_dbg(hw, "NVM Read Error\n");
560*4882a593Smuzhiyun return ret_val;
561*4882a593Smuzhiyun }
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun if (length == 0xFFFF || length == 0) {
564*4882a593Smuzhiyun hw_dbg(hw, "NVM PBA number section invalid length\n");
565*4882a593Smuzhiyun return IXGBE_ERR_PBA_SECTION;
566*4882a593Smuzhiyun }
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun /* check if pba_num buffer is big enough */
569*4882a593Smuzhiyun if (pba_num_size < (((u32)length * 2) - 1)) {
570*4882a593Smuzhiyun hw_dbg(hw, "PBA string buffer too small\n");
571*4882a593Smuzhiyun return IXGBE_ERR_NO_SPACE;
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun /* trim pba length from start of string */
575*4882a593Smuzhiyun pba_ptr++;
576*4882a593Smuzhiyun length--;
577*4882a593Smuzhiyun
578*4882a593Smuzhiyun for (offset = 0; offset < length; offset++) {
579*4882a593Smuzhiyun ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
580*4882a593Smuzhiyun if (ret_val) {
581*4882a593Smuzhiyun hw_dbg(hw, "NVM Read Error\n");
582*4882a593Smuzhiyun return ret_val;
583*4882a593Smuzhiyun }
584*4882a593Smuzhiyun pba_num[offset * 2] = (u8)(data >> 8);
585*4882a593Smuzhiyun pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
586*4882a593Smuzhiyun }
587*4882a593Smuzhiyun pba_num[offset * 2] = '\0';
588*4882a593Smuzhiyun
589*4882a593Smuzhiyun return 0;
590*4882a593Smuzhiyun }
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun /**
593*4882a593Smuzhiyun * ixgbe_get_mac_addr_generic - Generic get MAC address
594*4882a593Smuzhiyun * @hw: pointer to hardware structure
595*4882a593Smuzhiyun * @mac_addr: Adapter MAC address
596*4882a593Smuzhiyun *
597*4882a593Smuzhiyun * Reads the adapter's MAC address from first Receive Address Register (RAR0)
598*4882a593Smuzhiyun * A reset of the adapter must be performed prior to calling this function
599*4882a593Smuzhiyun * in order for the MAC address to have been loaded from the EEPROM into RAR0
600*4882a593Smuzhiyun **/
ixgbe_get_mac_addr_generic(struct ixgbe_hw * hw,u8 * mac_addr)601*4882a593Smuzhiyun s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
602*4882a593Smuzhiyun {
603*4882a593Smuzhiyun u32 rar_high;
604*4882a593Smuzhiyun u32 rar_low;
605*4882a593Smuzhiyun u16 i;
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
608*4882a593Smuzhiyun rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
609*4882a593Smuzhiyun
610*4882a593Smuzhiyun for (i = 0; i < 4; i++)
611*4882a593Smuzhiyun mac_addr[i] = (u8)(rar_low >> (i*8));
612*4882a593Smuzhiyun
613*4882a593Smuzhiyun for (i = 0; i < 2; i++)
614*4882a593Smuzhiyun mac_addr[i+4] = (u8)(rar_high >> (i*8));
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun return 0;
617*4882a593Smuzhiyun }
618*4882a593Smuzhiyun
ixgbe_convert_bus_width(u16 link_status)619*4882a593Smuzhiyun enum ixgbe_bus_width ixgbe_convert_bus_width(u16 link_status)
620*4882a593Smuzhiyun {
621*4882a593Smuzhiyun switch (link_status & IXGBE_PCI_LINK_WIDTH) {
622*4882a593Smuzhiyun case IXGBE_PCI_LINK_WIDTH_1:
623*4882a593Smuzhiyun return ixgbe_bus_width_pcie_x1;
624*4882a593Smuzhiyun case IXGBE_PCI_LINK_WIDTH_2:
625*4882a593Smuzhiyun return ixgbe_bus_width_pcie_x2;
626*4882a593Smuzhiyun case IXGBE_PCI_LINK_WIDTH_4:
627*4882a593Smuzhiyun return ixgbe_bus_width_pcie_x4;
628*4882a593Smuzhiyun case IXGBE_PCI_LINK_WIDTH_8:
629*4882a593Smuzhiyun return ixgbe_bus_width_pcie_x8;
630*4882a593Smuzhiyun default:
631*4882a593Smuzhiyun return ixgbe_bus_width_unknown;
632*4882a593Smuzhiyun }
633*4882a593Smuzhiyun }
634*4882a593Smuzhiyun
ixgbe_convert_bus_speed(u16 link_status)635*4882a593Smuzhiyun enum ixgbe_bus_speed ixgbe_convert_bus_speed(u16 link_status)
636*4882a593Smuzhiyun {
637*4882a593Smuzhiyun switch (link_status & IXGBE_PCI_LINK_SPEED) {
638*4882a593Smuzhiyun case IXGBE_PCI_LINK_SPEED_2500:
639*4882a593Smuzhiyun return ixgbe_bus_speed_2500;
640*4882a593Smuzhiyun case IXGBE_PCI_LINK_SPEED_5000:
641*4882a593Smuzhiyun return ixgbe_bus_speed_5000;
642*4882a593Smuzhiyun case IXGBE_PCI_LINK_SPEED_8000:
643*4882a593Smuzhiyun return ixgbe_bus_speed_8000;
644*4882a593Smuzhiyun default:
645*4882a593Smuzhiyun return ixgbe_bus_speed_unknown;
646*4882a593Smuzhiyun }
647*4882a593Smuzhiyun }
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun /**
650*4882a593Smuzhiyun * ixgbe_get_bus_info_generic - Generic set PCI bus info
651*4882a593Smuzhiyun * @hw: pointer to hardware structure
652*4882a593Smuzhiyun *
653*4882a593Smuzhiyun * Sets the PCI bus info (speed, width, type) within the ixgbe_hw structure
654*4882a593Smuzhiyun **/
ixgbe_get_bus_info_generic(struct ixgbe_hw * hw)655*4882a593Smuzhiyun s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
656*4882a593Smuzhiyun {
657*4882a593Smuzhiyun u16 link_status;
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun hw->bus.type = ixgbe_bus_type_pci_express;
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun /* Get the negotiated link width and speed from PCI config space */
662*4882a593Smuzhiyun link_status = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_LINK_STATUS);
663*4882a593Smuzhiyun
664*4882a593Smuzhiyun hw->bus.width = ixgbe_convert_bus_width(link_status);
665*4882a593Smuzhiyun hw->bus.speed = ixgbe_convert_bus_speed(link_status);
666*4882a593Smuzhiyun
667*4882a593Smuzhiyun hw->mac.ops.set_lan_id(hw);
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun return 0;
670*4882a593Smuzhiyun }
671*4882a593Smuzhiyun
672*4882a593Smuzhiyun /**
673*4882a593Smuzhiyun * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
674*4882a593Smuzhiyun * @hw: pointer to the HW structure
675*4882a593Smuzhiyun *
676*4882a593Smuzhiyun * Determines the LAN function id by reading memory-mapped registers
677*4882a593Smuzhiyun * and swaps the port value if requested.
678*4882a593Smuzhiyun **/
ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw * hw)679*4882a593Smuzhiyun void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
680*4882a593Smuzhiyun {
681*4882a593Smuzhiyun struct ixgbe_bus_info *bus = &hw->bus;
682*4882a593Smuzhiyun u16 ee_ctrl_4;
683*4882a593Smuzhiyun u32 reg;
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
686*4882a593Smuzhiyun bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
687*4882a593Smuzhiyun bus->lan_id = bus->func;
688*4882a593Smuzhiyun
689*4882a593Smuzhiyun /* check for a port swap */
690*4882a593Smuzhiyun reg = IXGBE_READ_REG(hw, IXGBE_FACTPS(hw));
691*4882a593Smuzhiyun if (reg & IXGBE_FACTPS_LFS)
692*4882a593Smuzhiyun bus->func ^= 0x1;
693*4882a593Smuzhiyun
694*4882a593Smuzhiyun /* Get MAC instance from EEPROM for configuring CS4227 */
695*4882a593Smuzhiyun if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP) {
696*4882a593Smuzhiyun hw->eeprom.ops.read(hw, IXGBE_EEPROM_CTRL_4, &ee_ctrl_4);
697*4882a593Smuzhiyun bus->instance_id = (ee_ctrl_4 & IXGBE_EE_CTRL_4_INST_ID) >>
698*4882a593Smuzhiyun IXGBE_EE_CTRL_4_INST_ID_SHIFT;
699*4882a593Smuzhiyun }
700*4882a593Smuzhiyun }
701*4882a593Smuzhiyun
702*4882a593Smuzhiyun /**
703*4882a593Smuzhiyun * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
704*4882a593Smuzhiyun * @hw: pointer to hardware structure
705*4882a593Smuzhiyun *
706*4882a593Smuzhiyun * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
707*4882a593Smuzhiyun * disables transmit and receive units. The adapter_stopped flag is used by
708*4882a593Smuzhiyun * the shared code and drivers to determine if the adapter is in a stopped
709*4882a593Smuzhiyun * state and should not touch the hardware.
710*4882a593Smuzhiyun **/
ixgbe_stop_adapter_generic(struct ixgbe_hw * hw)711*4882a593Smuzhiyun s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
712*4882a593Smuzhiyun {
713*4882a593Smuzhiyun u32 reg_val;
714*4882a593Smuzhiyun u16 i;
715*4882a593Smuzhiyun
716*4882a593Smuzhiyun /*
717*4882a593Smuzhiyun * Set the adapter_stopped flag so other driver functions stop touching
718*4882a593Smuzhiyun * the hardware
719*4882a593Smuzhiyun */
720*4882a593Smuzhiyun hw->adapter_stopped = true;
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun /* Disable the receive unit */
723*4882a593Smuzhiyun hw->mac.ops.disable_rx(hw);
724*4882a593Smuzhiyun
725*4882a593Smuzhiyun /* Clear interrupt mask to stop interrupts from being generated */
726*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
727*4882a593Smuzhiyun
728*4882a593Smuzhiyun /* Clear any pending interrupts, flush previous writes */
729*4882a593Smuzhiyun IXGBE_READ_REG(hw, IXGBE_EICR);
730*4882a593Smuzhiyun
731*4882a593Smuzhiyun /* Disable the transmit unit. Each queue must be disabled. */
732*4882a593Smuzhiyun for (i = 0; i < hw->mac.max_tx_queues; i++)
733*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
734*4882a593Smuzhiyun
735*4882a593Smuzhiyun /* Disable the receive unit by stopping each queue */
736*4882a593Smuzhiyun for (i = 0; i < hw->mac.max_rx_queues; i++) {
737*4882a593Smuzhiyun reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
738*4882a593Smuzhiyun reg_val &= ~IXGBE_RXDCTL_ENABLE;
739*4882a593Smuzhiyun reg_val |= IXGBE_RXDCTL_SWFLSH;
740*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
741*4882a593Smuzhiyun }
742*4882a593Smuzhiyun
743*4882a593Smuzhiyun /* flush all queues disables */
744*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
745*4882a593Smuzhiyun usleep_range(1000, 2000);
746*4882a593Smuzhiyun
747*4882a593Smuzhiyun /*
748*4882a593Smuzhiyun * Prevent the PCI-E bus from from hanging by disabling PCI-E master
749*4882a593Smuzhiyun * access and verify no pending requests
750*4882a593Smuzhiyun */
751*4882a593Smuzhiyun return ixgbe_disable_pcie_master(hw);
752*4882a593Smuzhiyun }
753*4882a593Smuzhiyun
754*4882a593Smuzhiyun /**
755*4882a593Smuzhiyun * ixgbe_init_led_link_act_generic - Store the LED index link/activity.
756*4882a593Smuzhiyun * @hw: pointer to hardware structure
757*4882a593Smuzhiyun *
758*4882a593Smuzhiyun * Store the index for the link active LED. This will be used to support
759*4882a593Smuzhiyun * blinking the LED.
760*4882a593Smuzhiyun **/
ixgbe_init_led_link_act_generic(struct ixgbe_hw * hw)761*4882a593Smuzhiyun s32 ixgbe_init_led_link_act_generic(struct ixgbe_hw *hw)
762*4882a593Smuzhiyun {
763*4882a593Smuzhiyun struct ixgbe_mac_info *mac = &hw->mac;
764*4882a593Smuzhiyun u32 led_reg, led_mode;
765*4882a593Smuzhiyun u16 i;
766*4882a593Smuzhiyun
767*4882a593Smuzhiyun led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
768*4882a593Smuzhiyun
769*4882a593Smuzhiyun /* Get LED link active from the LEDCTL register */
770*4882a593Smuzhiyun for (i = 0; i < 4; i++) {
771*4882a593Smuzhiyun led_mode = led_reg >> IXGBE_LED_MODE_SHIFT(i);
772*4882a593Smuzhiyun
773*4882a593Smuzhiyun if ((led_mode & IXGBE_LED_MODE_MASK_BASE) ==
774*4882a593Smuzhiyun IXGBE_LED_LINK_ACTIVE) {
775*4882a593Smuzhiyun mac->led_link_act = i;
776*4882a593Smuzhiyun return 0;
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun }
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun /* If LEDCTL register does not have the LED link active set, then use
781*4882a593Smuzhiyun * known MAC defaults.
782*4882a593Smuzhiyun */
783*4882a593Smuzhiyun switch (hw->mac.type) {
784*4882a593Smuzhiyun case ixgbe_mac_x550em_a:
785*4882a593Smuzhiyun mac->led_link_act = 0;
786*4882a593Smuzhiyun break;
787*4882a593Smuzhiyun case ixgbe_mac_X550EM_x:
788*4882a593Smuzhiyun mac->led_link_act = 1;
789*4882a593Smuzhiyun break;
790*4882a593Smuzhiyun default:
791*4882a593Smuzhiyun mac->led_link_act = 2;
792*4882a593Smuzhiyun }
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun return 0;
795*4882a593Smuzhiyun }
796*4882a593Smuzhiyun
797*4882a593Smuzhiyun /**
798*4882a593Smuzhiyun * ixgbe_led_on_generic - Turns on the software controllable LEDs.
799*4882a593Smuzhiyun * @hw: pointer to hardware structure
800*4882a593Smuzhiyun * @index: led number to turn on
801*4882a593Smuzhiyun **/
ixgbe_led_on_generic(struct ixgbe_hw * hw,u32 index)802*4882a593Smuzhiyun s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
803*4882a593Smuzhiyun {
804*4882a593Smuzhiyun u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
805*4882a593Smuzhiyun
806*4882a593Smuzhiyun if (index > 3)
807*4882a593Smuzhiyun return IXGBE_ERR_PARAM;
808*4882a593Smuzhiyun
809*4882a593Smuzhiyun /* To turn on the LED, set mode to ON. */
810*4882a593Smuzhiyun led_reg &= ~IXGBE_LED_MODE_MASK(index);
811*4882a593Smuzhiyun led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
812*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
813*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
814*4882a593Smuzhiyun
815*4882a593Smuzhiyun return 0;
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun
818*4882a593Smuzhiyun /**
819*4882a593Smuzhiyun * ixgbe_led_off_generic - Turns off the software controllable LEDs.
820*4882a593Smuzhiyun * @hw: pointer to hardware structure
821*4882a593Smuzhiyun * @index: led number to turn off
822*4882a593Smuzhiyun **/
ixgbe_led_off_generic(struct ixgbe_hw * hw,u32 index)823*4882a593Smuzhiyun s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
824*4882a593Smuzhiyun {
825*4882a593Smuzhiyun u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
826*4882a593Smuzhiyun
827*4882a593Smuzhiyun if (index > 3)
828*4882a593Smuzhiyun return IXGBE_ERR_PARAM;
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun /* To turn off the LED, set mode to OFF. */
831*4882a593Smuzhiyun led_reg &= ~IXGBE_LED_MODE_MASK(index);
832*4882a593Smuzhiyun led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
833*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
834*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
835*4882a593Smuzhiyun
836*4882a593Smuzhiyun return 0;
837*4882a593Smuzhiyun }
838*4882a593Smuzhiyun
839*4882a593Smuzhiyun /**
840*4882a593Smuzhiyun * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
841*4882a593Smuzhiyun * @hw: pointer to hardware structure
842*4882a593Smuzhiyun *
843*4882a593Smuzhiyun * Initializes the EEPROM parameters ixgbe_eeprom_info within the
844*4882a593Smuzhiyun * ixgbe_hw struct in order to set up EEPROM access.
845*4882a593Smuzhiyun **/
ixgbe_init_eeprom_params_generic(struct ixgbe_hw * hw)846*4882a593Smuzhiyun s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
847*4882a593Smuzhiyun {
848*4882a593Smuzhiyun struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
849*4882a593Smuzhiyun u32 eec;
850*4882a593Smuzhiyun u16 eeprom_size;
851*4882a593Smuzhiyun
852*4882a593Smuzhiyun if (eeprom->type == ixgbe_eeprom_uninitialized) {
853*4882a593Smuzhiyun eeprom->type = ixgbe_eeprom_none;
854*4882a593Smuzhiyun /* Set default semaphore delay to 10ms which is a well
855*4882a593Smuzhiyun * tested value */
856*4882a593Smuzhiyun eeprom->semaphore_delay = 10;
857*4882a593Smuzhiyun /* Clear EEPROM page size, it will be initialized as needed */
858*4882a593Smuzhiyun eeprom->word_page_size = 0;
859*4882a593Smuzhiyun
860*4882a593Smuzhiyun /*
861*4882a593Smuzhiyun * Check for EEPROM present first.
862*4882a593Smuzhiyun * If not present leave as none
863*4882a593Smuzhiyun */
864*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
865*4882a593Smuzhiyun if (eec & IXGBE_EEC_PRES) {
866*4882a593Smuzhiyun eeprom->type = ixgbe_eeprom_spi;
867*4882a593Smuzhiyun
868*4882a593Smuzhiyun /*
869*4882a593Smuzhiyun * SPI EEPROM is assumed here. This code would need to
870*4882a593Smuzhiyun * change if a future EEPROM is not SPI.
871*4882a593Smuzhiyun */
872*4882a593Smuzhiyun eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
873*4882a593Smuzhiyun IXGBE_EEC_SIZE_SHIFT);
874*4882a593Smuzhiyun eeprom->word_size = BIT(eeprom_size +
875*4882a593Smuzhiyun IXGBE_EEPROM_WORD_SIZE_SHIFT);
876*4882a593Smuzhiyun }
877*4882a593Smuzhiyun
878*4882a593Smuzhiyun if (eec & IXGBE_EEC_ADDR_SIZE)
879*4882a593Smuzhiyun eeprom->address_bits = 16;
880*4882a593Smuzhiyun else
881*4882a593Smuzhiyun eeprom->address_bits = 8;
882*4882a593Smuzhiyun hw_dbg(hw, "Eeprom params: type = %d, size = %d, address bits: %d\n",
883*4882a593Smuzhiyun eeprom->type, eeprom->word_size, eeprom->address_bits);
884*4882a593Smuzhiyun }
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun return 0;
887*4882a593Smuzhiyun }
888*4882a593Smuzhiyun
889*4882a593Smuzhiyun /**
890*4882a593Smuzhiyun * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
891*4882a593Smuzhiyun * @hw: pointer to hardware structure
892*4882a593Smuzhiyun * @offset: offset within the EEPROM to write
893*4882a593Smuzhiyun * @words: number of words
894*4882a593Smuzhiyun * @data: 16 bit word(s) to write to EEPROM
895*4882a593Smuzhiyun *
896*4882a593Smuzhiyun * Reads 16 bit word(s) from EEPROM through bit-bang method
897*4882a593Smuzhiyun **/
ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw * hw,u16 offset,u16 words,u16 * data)898*4882a593Smuzhiyun s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
899*4882a593Smuzhiyun u16 words, u16 *data)
900*4882a593Smuzhiyun {
901*4882a593Smuzhiyun s32 status;
902*4882a593Smuzhiyun u16 i, count;
903*4882a593Smuzhiyun
904*4882a593Smuzhiyun hw->eeprom.ops.init_params(hw);
905*4882a593Smuzhiyun
906*4882a593Smuzhiyun if (words == 0)
907*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
908*4882a593Smuzhiyun
909*4882a593Smuzhiyun if (offset + words > hw->eeprom.word_size)
910*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
911*4882a593Smuzhiyun
912*4882a593Smuzhiyun /*
913*4882a593Smuzhiyun * The EEPROM page size cannot be queried from the chip. We do lazy
914*4882a593Smuzhiyun * initialization. It is worth to do that when we write large buffer.
915*4882a593Smuzhiyun */
916*4882a593Smuzhiyun if ((hw->eeprom.word_page_size == 0) &&
917*4882a593Smuzhiyun (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
918*4882a593Smuzhiyun ixgbe_detect_eeprom_page_size_generic(hw, offset);
919*4882a593Smuzhiyun
920*4882a593Smuzhiyun /*
921*4882a593Smuzhiyun * We cannot hold synchronization semaphores for too long
922*4882a593Smuzhiyun * to avoid other entity starvation. However it is more efficient
923*4882a593Smuzhiyun * to read in bursts than synchronizing access for each word.
924*4882a593Smuzhiyun */
925*4882a593Smuzhiyun for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
926*4882a593Smuzhiyun count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
927*4882a593Smuzhiyun IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
928*4882a593Smuzhiyun status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
929*4882a593Smuzhiyun count, &data[i]);
930*4882a593Smuzhiyun
931*4882a593Smuzhiyun if (status != 0)
932*4882a593Smuzhiyun break;
933*4882a593Smuzhiyun }
934*4882a593Smuzhiyun
935*4882a593Smuzhiyun return status;
936*4882a593Smuzhiyun }
937*4882a593Smuzhiyun
938*4882a593Smuzhiyun /**
939*4882a593Smuzhiyun * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
940*4882a593Smuzhiyun * @hw: pointer to hardware structure
941*4882a593Smuzhiyun * @offset: offset within the EEPROM to be written to
942*4882a593Smuzhiyun * @words: number of word(s)
943*4882a593Smuzhiyun * @data: 16 bit word(s) to be written to the EEPROM
944*4882a593Smuzhiyun *
945*4882a593Smuzhiyun * If ixgbe_eeprom_update_checksum is not called after this function, the
946*4882a593Smuzhiyun * EEPROM will most likely contain an invalid checksum.
947*4882a593Smuzhiyun **/
ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw * hw,u16 offset,u16 words,u16 * data)948*4882a593Smuzhiyun static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
949*4882a593Smuzhiyun u16 words, u16 *data)
950*4882a593Smuzhiyun {
951*4882a593Smuzhiyun s32 status;
952*4882a593Smuzhiyun u16 word;
953*4882a593Smuzhiyun u16 page_size;
954*4882a593Smuzhiyun u16 i;
955*4882a593Smuzhiyun u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
956*4882a593Smuzhiyun
957*4882a593Smuzhiyun /* Prepare the EEPROM for writing */
958*4882a593Smuzhiyun status = ixgbe_acquire_eeprom(hw);
959*4882a593Smuzhiyun if (status)
960*4882a593Smuzhiyun return status;
961*4882a593Smuzhiyun
962*4882a593Smuzhiyun if (ixgbe_ready_eeprom(hw) != 0) {
963*4882a593Smuzhiyun ixgbe_release_eeprom(hw);
964*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
965*4882a593Smuzhiyun }
966*4882a593Smuzhiyun
967*4882a593Smuzhiyun for (i = 0; i < words; i++) {
968*4882a593Smuzhiyun ixgbe_standby_eeprom(hw);
969*4882a593Smuzhiyun
970*4882a593Smuzhiyun /* Send the WRITE ENABLE command (8 bit opcode) */
971*4882a593Smuzhiyun ixgbe_shift_out_eeprom_bits(hw,
972*4882a593Smuzhiyun IXGBE_EEPROM_WREN_OPCODE_SPI,
973*4882a593Smuzhiyun IXGBE_EEPROM_OPCODE_BITS);
974*4882a593Smuzhiyun
975*4882a593Smuzhiyun ixgbe_standby_eeprom(hw);
976*4882a593Smuzhiyun
977*4882a593Smuzhiyun /* Some SPI eeproms use the 8th address bit embedded
978*4882a593Smuzhiyun * in the opcode
979*4882a593Smuzhiyun */
980*4882a593Smuzhiyun if ((hw->eeprom.address_bits == 8) &&
981*4882a593Smuzhiyun ((offset + i) >= 128))
982*4882a593Smuzhiyun write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
983*4882a593Smuzhiyun
984*4882a593Smuzhiyun /* Send the Write command (8-bit opcode + addr) */
985*4882a593Smuzhiyun ixgbe_shift_out_eeprom_bits(hw, write_opcode,
986*4882a593Smuzhiyun IXGBE_EEPROM_OPCODE_BITS);
987*4882a593Smuzhiyun ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
988*4882a593Smuzhiyun hw->eeprom.address_bits);
989*4882a593Smuzhiyun
990*4882a593Smuzhiyun page_size = hw->eeprom.word_page_size;
991*4882a593Smuzhiyun
992*4882a593Smuzhiyun /* Send the data in burst via SPI */
993*4882a593Smuzhiyun do {
994*4882a593Smuzhiyun word = data[i];
995*4882a593Smuzhiyun word = (word >> 8) | (word << 8);
996*4882a593Smuzhiyun ixgbe_shift_out_eeprom_bits(hw, word, 16);
997*4882a593Smuzhiyun
998*4882a593Smuzhiyun if (page_size == 0)
999*4882a593Smuzhiyun break;
1000*4882a593Smuzhiyun
1001*4882a593Smuzhiyun /* do not wrap around page */
1002*4882a593Smuzhiyun if (((offset + i) & (page_size - 1)) ==
1003*4882a593Smuzhiyun (page_size - 1))
1004*4882a593Smuzhiyun break;
1005*4882a593Smuzhiyun } while (++i < words);
1006*4882a593Smuzhiyun
1007*4882a593Smuzhiyun ixgbe_standby_eeprom(hw);
1008*4882a593Smuzhiyun usleep_range(10000, 20000);
1009*4882a593Smuzhiyun }
1010*4882a593Smuzhiyun /* Done with writing - release the EEPROM */
1011*4882a593Smuzhiyun ixgbe_release_eeprom(hw);
1012*4882a593Smuzhiyun
1013*4882a593Smuzhiyun return 0;
1014*4882a593Smuzhiyun }
1015*4882a593Smuzhiyun
1016*4882a593Smuzhiyun /**
1017*4882a593Smuzhiyun * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
1018*4882a593Smuzhiyun * @hw: pointer to hardware structure
1019*4882a593Smuzhiyun * @offset: offset within the EEPROM to be written to
1020*4882a593Smuzhiyun * @data: 16 bit word to be written to the EEPROM
1021*4882a593Smuzhiyun *
1022*4882a593Smuzhiyun * If ixgbe_eeprom_update_checksum is not called after this function, the
1023*4882a593Smuzhiyun * EEPROM will most likely contain an invalid checksum.
1024*4882a593Smuzhiyun **/
ixgbe_write_eeprom_generic(struct ixgbe_hw * hw,u16 offset,u16 data)1025*4882a593Smuzhiyun s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1026*4882a593Smuzhiyun {
1027*4882a593Smuzhiyun hw->eeprom.ops.init_params(hw);
1028*4882a593Smuzhiyun
1029*4882a593Smuzhiyun if (offset >= hw->eeprom.word_size)
1030*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1031*4882a593Smuzhiyun
1032*4882a593Smuzhiyun return ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
1033*4882a593Smuzhiyun }
1034*4882a593Smuzhiyun
1035*4882a593Smuzhiyun /**
1036*4882a593Smuzhiyun * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
1037*4882a593Smuzhiyun * @hw: pointer to hardware structure
1038*4882a593Smuzhiyun * @offset: offset within the EEPROM to be read
1039*4882a593Smuzhiyun * @words: number of word(s)
1040*4882a593Smuzhiyun * @data: read 16 bit words(s) from EEPROM
1041*4882a593Smuzhiyun *
1042*4882a593Smuzhiyun * Reads 16 bit word(s) from EEPROM through bit-bang method
1043*4882a593Smuzhiyun **/
ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw * hw,u16 offset,u16 words,u16 * data)1044*4882a593Smuzhiyun s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1045*4882a593Smuzhiyun u16 words, u16 *data)
1046*4882a593Smuzhiyun {
1047*4882a593Smuzhiyun s32 status;
1048*4882a593Smuzhiyun u16 i, count;
1049*4882a593Smuzhiyun
1050*4882a593Smuzhiyun hw->eeprom.ops.init_params(hw);
1051*4882a593Smuzhiyun
1052*4882a593Smuzhiyun if (words == 0)
1053*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
1054*4882a593Smuzhiyun
1055*4882a593Smuzhiyun if (offset + words > hw->eeprom.word_size)
1056*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1057*4882a593Smuzhiyun
1058*4882a593Smuzhiyun /*
1059*4882a593Smuzhiyun * We cannot hold synchronization semaphores for too long
1060*4882a593Smuzhiyun * to avoid other entity starvation. However it is more efficient
1061*4882a593Smuzhiyun * to read in bursts than synchronizing access for each word.
1062*4882a593Smuzhiyun */
1063*4882a593Smuzhiyun for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
1064*4882a593Smuzhiyun count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
1065*4882a593Smuzhiyun IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
1066*4882a593Smuzhiyun
1067*4882a593Smuzhiyun status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
1068*4882a593Smuzhiyun count, &data[i]);
1069*4882a593Smuzhiyun
1070*4882a593Smuzhiyun if (status)
1071*4882a593Smuzhiyun return status;
1072*4882a593Smuzhiyun }
1073*4882a593Smuzhiyun
1074*4882a593Smuzhiyun return 0;
1075*4882a593Smuzhiyun }
1076*4882a593Smuzhiyun
1077*4882a593Smuzhiyun /**
1078*4882a593Smuzhiyun * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
1079*4882a593Smuzhiyun * @hw: pointer to hardware structure
1080*4882a593Smuzhiyun * @offset: offset within the EEPROM to be read
1081*4882a593Smuzhiyun * @words: number of word(s)
1082*4882a593Smuzhiyun * @data: read 16 bit word(s) from EEPROM
1083*4882a593Smuzhiyun *
1084*4882a593Smuzhiyun * Reads 16 bit word(s) from EEPROM through bit-bang method
1085*4882a593Smuzhiyun **/
ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw * hw,u16 offset,u16 words,u16 * data)1086*4882a593Smuzhiyun static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
1087*4882a593Smuzhiyun u16 words, u16 *data)
1088*4882a593Smuzhiyun {
1089*4882a593Smuzhiyun s32 status;
1090*4882a593Smuzhiyun u16 word_in;
1091*4882a593Smuzhiyun u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
1092*4882a593Smuzhiyun u16 i;
1093*4882a593Smuzhiyun
1094*4882a593Smuzhiyun /* Prepare the EEPROM for reading */
1095*4882a593Smuzhiyun status = ixgbe_acquire_eeprom(hw);
1096*4882a593Smuzhiyun if (status)
1097*4882a593Smuzhiyun return status;
1098*4882a593Smuzhiyun
1099*4882a593Smuzhiyun if (ixgbe_ready_eeprom(hw) != 0) {
1100*4882a593Smuzhiyun ixgbe_release_eeprom(hw);
1101*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1102*4882a593Smuzhiyun }
1103*4882a593Smuzhiyun
1104*4882a593Smuzhiyun for (i = 0; i < words; i++) {
1105*4882a593Smuzhiyun ixgbe_standby_eeprom(hw);
1106*4882a593Smuzhiyun /* Some SPI eeproms use the 8th address bit embedded
1107*4882a593Smuzhiyun * in the opcode
1108*4882a593Smuzhiyun */
1109*4882a593Smuzhiyun if ((hw->eeprom.address_bits == 8) &&
1110*4882a593Smuzhiyun ((offset + i) >= 128))
1111*4882a593Smuzhiyun read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
1112*4882a593Smuzhiyun
1113*4882a593Smuzhiyun /* Send the READ command (opcode + addr) */
1114*4882a593Smuzhiyun ixgbe_shift_out_eeprom_bits(hw, read_opcode,
1115*4882a593Smuzhiyun IXGBE_EEPROM_OPCODE_BITS);
1116*4882a593Smuzhiyun ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
1117*4882a593Smuzhiyun hw->eeprom.address_bits);
1118*4882a593Smuzhiyun
1119*4882a593Smuzhiyun /* Read the data. */
1120*4882a593Smuzhiyun word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
1121*4882a593Smuzhiyun data[i] = (word_in >> 8) | (word_in << 8);
1122*4882a593Smuzhiyun }
1123*4882a593Smuzhiyun
1124*4882a593Smuzhiyun /* End this read operation */
1125*4882a593Smuzhiyun ixgbe_release_eeprom(hw);
1126*4882a593Smuzhiyun
1127*4882a593Smuzhiyun return 0;
1128*4882a593Smuzhiyun }
1129*4882a593Smuzhiyun
1130*4882a593Smuzhiyun /**
1131*4882a593Smuzhiyun * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
1132*4882a593Smuzhiyun * @hw: pointer to hardware structure
1133*4882a593Smuzhiyun * @offset: offset within the EEPROM to be read
1134*4882a593Smuzhiyun * @data: read 16 bit value from EEPROM
1135*4882a593Smuzhiyun *
1136*4882a593Smuzhiyun * Reads 16 bit value from EEPROM through bit-bang method
1137*4882a593Smuzhiyun **/
ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw * hw,u16 offset,u16 * data)1138*4882a593Smuzhiyun s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1139*4882a593Smuzhiyun u16 *data)
1140*4882a593Smuzhiyun {
1141*4882a593Smuzhiyun hw->eeprom.ops.init_params(hw);
1142*4882a593Smuzhiyun
1143*4882a593Smuzhiyun if (offset >= hw->eeprom.word_size)
1144*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1145*4882a593Smuzhiyun
1146*4882a593Smuzhiyun return ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1147*4882a593Smuzhiyun }
1148*4882a593Smuzhiyun
1149*4882a593Smuzhiyun /**
1150*4882a593Smuzhiyun * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
1151*4882a593Smuzhiyun * @hw: pointer to hardware structure
1152*4882a593Smuzhiyun * @offset: offset of word in the EEPROM to read
1153*4882a593Smuzhiyun * @words: number of word(s)
1154*4882a593Smuzhiyun * @data: 16 bit word(s) from the EEPROM
1155*4882a593Smuzhiyun *
1156*4882a593Smuzhiyun * Reads a 16 bit word(s) from the EEPROM using the EERD register.
1157*4882a593Smuzhiyun **/
ixgbe_read_eerd_buffer_generic(struct ixgbe_hw * hw,u16 offset,u16 words,u16 * data)1158*4882a593Smuzhiyun s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1159*4882a593Smuzhiyun u16 words, u16 *data)
1160*4882a593Smuzhiyun {
1161*4882a593Smuzhiyun u32 eerd;
1162*4882a593Smuzhiyun s32 status;
1163*4882a593Smuzhiyun u32 i;
1164*4882a593Smuzhiyun
1165*4882a593Smuzhiyun hw->eeprom.ops.init_params(hw);
1166*4882a593Smuzhiyun
1167*4882a593Smuzhiyun if (words == 0)
1168*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
1169*4882a593Smuzhiyun
1170*4882a593Smuzhiyun if (offset >= hw->eeprom.word_size)
1171*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1172*4882a593Smuzhiyun
1173*4882a593Smuzhiyun for (i = 0; i < words; i++) {
1174*4882a593Smuzhiyun eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1175*4882a593Smuzhiyun IXGBE_EEPROM_RW_REG_START;
1176*4882a593Smuzhiyun
1177*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
1178*4882a593Smuzhiyun status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
1179*4882a593Smuzhiyun
1180*4882a593Smuzhiyun if (status == 0) {
1181*4882a593Smuzhiyun data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
1182*4882a593Smuzhiyun IXGBE_EEPROM_RW_REG_DATA);
1183*4882a593Smuzhiyun } else {
1184*4882a593Smuzhiyun hw_dbg(hw, "Eeprom read timed out\n");
1185*4882a593Smuzhiyun return status;
1186*4882a593Smuzhiyun }
1187*4882a593Smuzhiyun }
1188*4882a593Smuzhiyun
1189*4882a593Smuzhiyun return 0;
1190*4882a593Smuzhiyun }
1191*4882a593Smuzhiyun
1192*4882a593Smuzhiyun /**
1193*4882a593Smuzhiyun * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
1194*4882a593Smuzhiyun * @hw: pointer to hardware structure
1195*4882a593Smuzhiyun * @offset: offset within the EEPROM to be used as a scratch pad
1196*4882a593Smuzhiyun *
1197*4882a593Smuzhiyun * Discover EEPROM page size by writing marching data at given offset.
1198*4882a593Smuzhiyun * This function is called only when we are writing a new large buffer
1199*4882a593Smuzhiyun * at given offset so the data would be overwritten anyway.
1200*4882a593Smuzhiyun **/
ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw * hw,u16 offset)1201*4882a593Smuzhiyun static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
1202*4882a593Smuzhiyun u16 offset)
1203*4882a593Smuzhiyun {
1204*4882a593Smuzhiyun u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
1205*4882a593Smuzhiyun s32 status;
1206*4882a593Smuzhiyun u16 i;
1207*4882a593Smuzhiyun
1208*4882a593Smuzhiyun for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
1209*4882a593Smuzhiyun data[i] = i;
1210*4882a593Smuzhiyun
1211*4882a593Smuzhiyun hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
1212*4882a593Smuzhiyun status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
1213*4882a593Smuzhiyun IXGBE_EEPROM_PAGE_SIZE_MAX, data);
1214*4882a593Smuzhiyun hw->eeprom.word_page_size = 0;
1215*4882a593Smuzhiyun if (status)
1216*4882a593Smuzhiyun return status;
1217*4882a593Smuzhiyun
1218*4882a593Smuzhiyun status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1219*4882a593Smuzhiyun if (status)
1220*4882a593Smuzhiyun return status;
1221*4882a593Smuzhiyun
1222*4882a593Smuzhiyun /*
1223*4882a593Smuzhiyun * When writing in burst more than the actual page size
1224*4882a593Smuzhiyun * EEPROM address wraps around current page.
1225*4882a593Smuzhiyun */
1226*4882a593Smuzhiyun hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
1227*4882a593Smuzhiyun
1228*4882a593Smuzhiyun hw_dbg(hw, "Detected EEPROM page size = %d words.\n",
1229*4882a593Smuzhiyun hw->eeprom.word_page_size);
1230*4882a593Smuzhiyun return 0;
1231*4882a593Smuzhiyun }
1232*4882a593Smuzhiyun
1233*4882a593Smuzhiyun /**
1234*4882a593Smuzhiyun * ixgbe_read_eerd_generic - Read EEPROM word using EERD
1235*4882a593Smuzhiyun * @hw: pointer to hardware structure
1236*4882a593Smuzhiyun * @offset: offset of word in the EEPROM to read
1237*4882a593Smuzhiyun * @data: word read from the EEPROM
1238*4882a593Smuzhiyun *
1239*4882a593Smuzhiyun * Reads a 16 bit word from the EEPROM using the EERD register.
1240*4882a593Smuzhiyun **/
ixgbe_read_eerd_generic(struct ixgbe_hw * hw,u16 offset,u16 * data)1241*4882a593Smuzhiyun s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
1242*4882a593Smuzhiyun {
1243*4882a593Smuzhiyun return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
1244*4882a593Smuzhiyun }
1245*4882a593Smuzhiyun
1246*4882a593Smuzhiyun /**
1247*4882a593Smuzhiyun * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
1248*4882a593Smuzhiyun * @hw: pointer to hardware structure
1249*4882a593Smuzhiyun * @offset: offset of word in the EEPROM to write
1250*4882a593Smuzhiyun * @words: number of words
1251*4882a593Smuzhiyun * @data: word(s) write to the EEPROM
1252*4882a593Smuzhiyun *
1253*4882a593Smuzhiyun * Write a 16 bit word(s) to the EEPROM using the EEWR register.
1254*4882a593Smuzhiyun **/
ixgbe_write_eewr_buffer_generic(struct ixgbe_hw * hw,u16 offset,u16 words,u16 * data)1255*4882a593Smuzhiyun s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1256*4882a593Smuzhiyun u16 words, u16 *data)
1257*4882a593Smuzhiyun {
1258*4882a593Smuzhiyun u32 eewr;
1259*4882a593Smuzhiyun s32 status;
1260*4882a593Smuzhiyun u16 i;
1261*4882a593Smuzhiyun
1262*4882a593Smuzhiyun hw->eeprom.ops.init_params(hw);
1263*4882a593Smuzhiyun
1264*4882a593Smuzhiyun if (words == 0)
1265*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
1266*4882a593Smuzhiyun
1267*4882a593Smuzhiyun if (offset >= hw->eeprom.word_size)
1268*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1269*4882a593Smuzhiyun
1270*4882a593Smuzhiyun for (i = 0; i < words; i++) {
1271*4882a593Smuzhiyun eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1272*4882a593Smuzhiyun (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
1273*4882a593Smuzhiyun IXGBE_EEPROM_RW_REG_START;
1274*4882a593Smuzhiyun
1275*4882a593Smuzhiyun status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1276*4882a593Smuzhiyun if (status) {
1277*4882a593Smuzhiyun hw_dbg(hw, "Eeprom write EEWR timed out\n");
1278*4882a593Smuzhiyun return status;
1279*4882a593Smuzhiyun }
1280*4882a593Smuzhiyun
1281*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
1282*4882a593Smuzhiyun
1283*4882a593Smuzhiyun status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1284*4882a593Smuzhiyun if (status) {
1285*4882a593Smuzhiyun hw_dbg(hw, "Eeprom write EEWR timed out\n");
1286*4882a593Smuzhiyun return status;
1287*4882a593Smuzhiyun }
1288*4882a593Smuzhiyun }
1289*4882a593Smuzhiyun
1290*4882a593Smuzhiyun return 0;
1291*4882a593Smuzhiyun }
1292*4882a593Smuzhiyun
1293*4882a593Smuzhiyun /**
1294*4882a593Smuzhiyun * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
1295*4882a593Smuzhiyun * @hw: pointer to hardware structure
1296*4882a593Smuzhiyun * @offset: offset of word in the EEPROM to write
1297*4882a593Smuzhiyun * @data: word write to the EEPROM
1298*4882a593Smuzhiyun *
1299*4882a593Smuzhiyun * Write a 16 bit word to the EEPROM using the EEWR register.
1300*4882a593Smuzhiyun **/
ixgbe_write_eewr_generic(struct ixgbe_hw * hw,u16 offset,u16 data)1301*4882a593Smuzhiyun s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1302*4882a593Smuzhiyun {
1303*4882a593Smuzhiyun return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
1304*4882a593Smuzhiyun }
1305*4882a593Smuzhiyun
1306*4882a593Smuzhiyun /**
1307*4882a593Smuzhiyun * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
1308*4882a593Smuzhiyun * @hw: pointer to hardware structure
1309*4882a593Smuzhiyun * @ee_reg: EEPROM flag for polling
1310*4882a593Smuzhiyun *
1311*4882a593Smuzhiyun * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
1312*4882a593Smuzhiyun * read or write is done respectively.
1313*4882a593Smuzhiyun **/
ixgbe_poll_eerd_eewr_done(struct ixgbe_hw * hw,u32 ee_reg)1314*4882a593Smuzhiyun static s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
1315*4882a593Smuzhiyun {
1316*4882a593Smuzhiyun u32 i;
1317*4882a593Smuzhiyun u32 reg;
1318*4882a593Smuzhiyun
1319*4882a593Smuzhiyun for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
1320*4882a593Smuzhiyun if (ee_reg == IXGBE_NVM_POLL_READ)
1321*4882a593Smuzhiyun reg = IXGBE_READ_REG(hw, IXGBE_EERD);
1322*4882a593Smuzhiyun else
1323*4882a593Smuzhiyun reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
1324*4882a593Smuzhiyun
1325*4882a593Smuzhiyun if (reg & IXGBE_EEPROM_RW_REG_DONE) {
1326*4882a593Smuzhiyun return 0;
1327*4882a593Smuzhiyun }
1328*4882a593Smuzhiyun udelay(5);
1329*4882a593Smuzhiyun }
1330*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1331*4882a593Smuzhiyun }
1332*4882a593Smuzhiyun
1333*4882a593Smuzhiyun /**
1334*4882a593Smuzhiyun * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
1335*4882a593Smuzhiyun * @hw: pointer to hardware structure
1336*4882a593Smuzhiyun *
1337*4882a593Smuzhiyun * Prepares EEPROM for access using bit-bang method. This function should
1338*4882a593Smuzhiyun * be called before issuing a command to the EEPROM.
1339*4882a593Smuzhiyun **/
ixgbe_acquire_eeprom(struct ixgbe_hw * hw)1340*4882a593Smuzhiyun static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
1341*4882a593Smuzhiyun {
1342*4882a593Smuzhiyun u32 eec;
1343*4882a593Smuzhiyun u32 i;
1344*4882a593Smuzhiyun
1345*4882a593Smuzhiyun if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) != 0)
1346*4882a593Smuzhiyun return IXGBE_ERR_SWFW_SYNC;
1347*4882a593Smuzhiyun
1348*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
1349*4882a593Smuzhiyun
1350*4882a593Smuzhiyun /* Request EEPROM Access */
1351*4882a593Smuzhiyun eec |= IXGBE_EEC_REQ;
1352*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1353*4882a593Smuzhiyun
1354*4882a593Smuzhiyun for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
1355*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
1356*4882a593Smuzhiyun if (eec & IXGBE_EEC_GNT)
1357*4882a593Smuzhiyun break;
1358*4882a593Smuzhiyun udelay(5);
1359*4882a593Smuzhiyun }
1360*4882a593Smuzhiyun
1361*4882a593Smuzhiyun /* Release if grant not acquired */
1362*4882a593Smuzhiyun if (!(eec & IXGBE_EEC_GNT)) {
1363*4882a593Smuzhiyun eec &= ~IXGBE_EEC_REQ;
1364*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1365*4882a593Smuzhiyun hw_dbg(hw, "Could not acquire EEPROM grant\n");
1366*4882a593Smuzhiyun
1367*4882a593Smuzhiyun hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1368*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1369*4882a593Smuzhiyun }
1370*4882a593Smuzhiyun
1371*4882a593Smuzhiyun /* Setup EEPROM for Read/Write */
1372*4882a593Smuzhiyun /* Clear CS and SK */
1373*4882a593Smuzhiyun eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
1374*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1375*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1376*4882a593Smuzhiyun udelay(1);
1377*4882a593Smuzhiyun return 0;
1378*4882a593Smuzhiyun }
1379*4882a593Smuzhiyun
1380*4882a593Smuzhiyun /**
1381*4882a593Smuzhiyun * ixgbe_get_eeprom_semaphore - Get hardware semaphore
1382*4882a593Smuzhiyun * @hw: pointer to hardware structure
1383*4882a593Smuzhiyun *
1384*4882a593Smuzhiyun * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
1385*4882a593Smuzhiyun **/
ixgbe_get_eeprom_semaphore(struct ixgbe_hw * hw)1386*4882a593Smuzhiyun static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
1387*4882a593Smuzhiyun {
1388*4882a593Smuzhiyun u32 timeout = 2000;
1389*4882a593Smuzhiyun u32 i;
1390*4882a593Smuzhiyun u32 swsm;
1391*4882a593Smuzhiyun
1392*4882a593Smuzhiyun /* Get SMBI software semaphore between device drivers first */
1393*4882a593Smuzhiyun for (i = 0; i < timeout; i++) {
1394*4882a593Smuzhiyun /*
1395*4882a593Smuzhiyun * If the SMBI bit is 0 when we read it, then the bit will be
1396*4882a593Smuzhiyun * set and we have the semaphore
1397*4882a593Smuzhiyun */
1398*4882a593Smuzhiyun swsm = IXGBE_READ_REG(hw, IXGBE_SWSM(hw));
1399*4882a593Smuzhiyun if (!(swsm & IXGBE_SWSM_SMBI))
1400*4882a593Smuzhiyun break;
1401*4882a593Smuzhiyun usleep_range(50, 100);
1402*4882a593Smuzhiyun }
1403*4882a593Smuzhiyun
1404*4882a593Smuzhiyun if (i == timeout) {
1405*4882a593Smuzhiyun hw_dbg(hw, "Driver can't access the Eeprom - SMBI Semaphore not granted.\n");
1406*4882a593Smuzhiyun /* this release is particularly important because our attempts
1407*4882a593Smuzhiyun * above to get the semaphore may have succeeded, and if there
1408*4882a593Smuzhiyun * was a timeout, we should unconditionally clear the semaphore
1409*4882a593Smuzhiyun * bits to free the driver to make progress
1410*4882a593Smuzhiyun */
1411*4882a593Smuzhiyun ixgbe_release_eeprom_semaphore(hw);
1412*4882a593Smuzhiyun
1413*4882a593Smuzhiyun usleep_range(50, 100);
1414*4882a593Smuzhiyun /* one last try
1415*4882a593Smuzhiyun * If the SMBI bit is 0 when we read it, then the bit will be
1416*4882a593Smuzhiyun * set and we have the semaphore
1417*4882a593Smuzhiyun */
1418*4882a593Smuzhiyun swsm = IXGBE_READ_REG(hw, IXGBE_SWSM(hw));
1419*4882a593Smuzhiyun if (swsm & IXGBE_SWSM_SMBI) {
1420*4882a593Smuzhiyun hw_dbg(hw, "Software semaphore SMBI between device drivers not granted.\n");
1421*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1422*4882a593Smuzhiyun }
1423*4882a593Smuzhiyun }
1424*4882a593Smuzhiyun
1425*4882a593Smuzhiyun /* Now get the semaphore between SW/FW through the SWESMBI bit */
1426*4882a593Smuzhiyun for (i = 0; i < timeout; i++) {
1427*4882a593Smuzhiyun swsm = IXGBE_READ_REG(hw, IXGBE_SWSM(hw));
1428*4882a593Smuzhiyun
1429*4882a593Smuzhiyun /* Set the SW EEPROM semaphore bit to request access */
1430*4882a593Smuzhiyun swsm |= IXGBE_SWSM_SWESMBI;
1431*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_SWSM(hw), swsm);
1432*4882a593Smuzhiyun
1433*4882a593Smuzhiyun /* If we set the bit successfully then we got the
1434*4882a593Smuzhiyun * semaphore.
1435*4882a593Smuzhiyun */
1436*4882a593Smuzhiyun swsm = IXGBE_READ_REG(hw, IXGBE_SWSM(hw));
1437*4882a593Smuzhiyun if (swsm & IXGBE_SWSM_SWESMBI)
1438*4882a593Smuzhiyun break;
1439*4882a593Smuzhiyun
1440*4882a593Smuzhiyun usleep_range(50, 100);
1441*4882a593Smuzhiyun }
1442*4882a593Smuzhiyun
1443*4882a593Smuzhiyun /* Release semaphores and return error if SW EEPROM semaphore
1444*4882a593Smuzhiyun * was not granted because we don't have access to the EEPROM
1445*4882a593Smuzhiyun */
1446*4882a593Smuzhiyun if (i >= timeout) {
1447*4882a593Smuzhiyun hw_dbg(hw, "SWESMBI Software EEPROM semaphore not granted.\n");
1448*4882a593Smuzhiyun ixgbe_release_eeprom_semaphore(hw);
1449*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1450*4882a593Smuzhiyun }
1451*4882a593Smuzhiyun
1452*4882a593Smuzhiyun return 0;
1453*4882a593Smuzhiyun }
1454*4882a593Smuzhiyun
1455*4882a593Smuzhiyun /**
1456*4882a593Smuzhiyun * ixgbe_release_eeprom_semaphore - Release hardware semaphore
1457*4882a593Smuzhiyun * @hw: pointer to hardware structure
1458*4882a593Smuzhiyun *
1459*4882a593Smuzhiyun * This function clears hardware semaphore bits.
1460*4882a593Smuzhiyun **/
ixgbe_release_eeprom_semaphore(struct ixgbe_hw * hw)1461*4882a593Smuzhiyun static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
1462*4882a593Smuzhiyun {
1463*4882a593Smuzhiyun u32 swsm;
1464*4882a593Smuzhiyun
1465*4882a593Smuzhiyun swsm = IXGBE_READ_REG(hw, IXGBE_SWSM(hw));
1466*4882a593Smuzhiyun
1467*4882a593Smuzhiyun /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
1468*4882a593Smuzhiyun swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
1469*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_SWSM(hw), swsm);
1470*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1471*4882a593Smuzhiyun }
1472*4882a593Smuzhiyun
1473*4882a593Smuzhiyun /**
1474*4882a593Smuzhiyun * ixgbe_ready_eeprom - Polls for EEPROM ready
1475*4882a593Smuzhiyun * @hw: pointer to hardware structure
1476*4882a593Smuzhiyun **/
ixgbe_ready_eeprom(struct ixgbe_hw * hw)1477*4882a593Smuzhiyun static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
1478*4882a593Smuzhiyun {
1479*4882a593Smuzhiyun u16 i;
1480*4882a593Smuzhiyun u8 spi_stat_reg;
1481*4882a593Smuzhiyun
1482*4882a593Smuzhiyun /*
1483*4882a593Smuzhiyun * Read "Status Register" repeatedly until the LSB is cleared. The
1484*4882a593Smuzhiyun * EEPROM will signal that the command has been completed by clearing
1485*4882a593Smuzhiyun * bit 0 of the internal status register. If it's not cleared within
1486*4882a593Smuzhiyun * 5 milliseconds, then error out.
1487*4882a593Smuzhiyun */
1488*4882a593Smuzhiyun for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
1489*4882a593Smuzhiyun ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
1490*4882a593Smuzhiyun IXGBE_EEPROM_OPCODE_BITS);
1491*4882a593Smuzhiyun spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
1492*4882a593Smuzhiyun if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
1493*4882a593Smuzhiyun break;
1494*4882a593Smuzhiyun
1495*4882a593Smuzhiyun udelay(5);
1496*4882a593Smuzhiyun ixgbe_standby_eeprom(hw);
1497*4882a593Smuzhiyun }
1498*4882a593Smuzhiyun
1499*4882a593Smuzhiyun /*
1500*4882a593Smuzhiyun * On some parts, SPI write time could vary from 0-20mSec on 3.3V
1501*4882a593Smuzhiyun * devices (and only 0-5mSec on 5V devices)
1502*4882a593Smuzhiyun */
1503*4882a593Smuzhiyun if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
1504*4882a593Smuzhiyun hw_dbg(hw, "SPI EEPROM Status error\n");
1505*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1506*4882a593Smuzhiyun }
1507*4882a593Smuzhiyun
1508*4882a593Smuzhiyun return 0;
1509*4882a593Smuzhiyun }
1510*4882a593Smuzhiyun
1511*4882a593Smuzhiyun /**
1512*4882a593Smuzhiyun * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
1513*4882a593Smuzhiyun * @hw: pointer to hardware structure
1514*4882a593Smuzhiyun **/
ixgbe_standby_eeprom(struct ixgbe_hw * hw)1515*4882a593Smuzhiyun static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
1516*4882a593Smuzhiyun {
1517*4882a593Smuzhiyun u32 eec;
1518*4882a593Smuzhiyun
1519*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
1520*4882a593Smuzhiyun
1521*4882a593Smuzhiyun /* Toggle CS to flush commands */
1522*4882a593Smuzhiyun eec |= IXGBE_EEC_CS;
1523*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1524*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1525*4882a593Smuzhiyun udelay(1);
1526*4882a593Smuzhiyun eec &= ~IXGBE_EEC_CS;
1527*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1528*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1529*4882a593Smuzhiyun udelay(1);
1530*4882a593Smuzhiyun }
1531*4882a593Smuzhiyun
1532*4882a593Smuzhiyun /**
1533*4882a593Smuzhiyun * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
1534*4882a593Smuzhiyun * @hw: pointer to hardware structure
1535*4882a593Smuzhiyun * @data: data to send to the EEPROM
1536*4882a593Smuzhiyun * @count: number of bits to shift out
1537*4882a593Smuzhiyun **/
ixgbe_shift_out_eeprom_bits(struct ixgbe_hw * hw,u16 data,u16 count)1538*4882a593Smuzhiyun static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
1539*4882a593Smuzhiyun u16 count)
1540*4882a593Smuzhiyun {
1541*4882a593Smuzhiyun u32 eec;
1542*4882a593Smuzhiyun u32 mask;
1543*4882a593Smuzhiyun u32 i;
1544*4882a593Smuzhiyun
1545*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
1546*4882a593Smuzhiyun
1547*4882a593Smuzhiyun /*
1548*4882a593Smuzhiyun * Mask is used to shift "count" bits of "data" out to the EEPROM
1549*4882a593Smuzhiyun * one bit at a time. Determine the starting bit based on count
1550*4882a593Smuzhiyun */
1551*4882a593Smuzhiyun mask = BIT(count - 1);
1552*4882a593Smuzhiyun
1553*4882a593Smuzhiyun for (i = 0; i < count; i++) {
1554*4882a593Smuzhiyun /*
1555*4882a593Smuzhiyun * A "1" is shifted out to the EEPROM by setting bit "DI" to a
1556*4882a593Smuzhiyun * "1", and then raising and then lowering the clock (the SK
1557*4882a593Smuzhiyun * bit controls the clock input to the EEPROM). A "0" is
1558*4882a593Smuzhiyun * shifted out to the EEPROM by setting "DI" to "0" and then
1559*4882a593Smuzhiyun * raising and then lowering the clock.
1560*4882a593Smuzhiyun */
1561*4882a593Smuzhiyun if (data & mask)
1562*4882a593Smuzhiyun eec |= IXGBE_EEC_DI;
1563*4882a593Smuzhiyun else
1564*4882a593Smuzhiyun eec &= ~IXGBE_EEC_DI;
1565*4882a593Smuzhiyun
1566*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1567*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1568*4882a593Smuzhiyun
1569*4882a593Smuzhiyun udelay(1);
1570*4882a593Smuzhiyun
1571*4882a593Smuzhiyun ixgbe_raise_eeprom_clk(hw, &eec);
1572*4882a593Smuzhiyun ixgbe_lower_eeprom_clk(hw, &eec);
1573*4882a593Smuzhiyun
1574*4882a593Smuzhiyun /*
1575*4882a593Smuzhiyun * Shift mask to signify next bit of data to shift in to the
1576*4882a593Smuzhiyun * EEPROM
1577*4882a593Smuzhiyun */
1578*4882a593Smuzhiyun mask = mask >> 1;
1579*4882a593Smuzhiyun }
1580*4882a593Smuzhiyun
1581*4882a593Smuzhiyun /* We leave the "DI" bit set to "0" when we leave this routine. */
1582*4882a593Smuzhiyun eec &= ~IXGBE_EEC_DI;
1583*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1584*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1585*4882a593Smuzhiyun }
1586*4882a593Smuzhiyun
1587*4882a593Smuzhiyun /**
1588*4882a593Smuzhiyun * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
1589*4882a593Smuzhiyun * @hw: pointer to hardware structure
1590*4882a593Smuzhiyun * @count: number of bits to shift
1591*4882a593Smuzhiyun **/
ixgbe_shift_in_eeprom_bits(struct ixgbe_hw * hw,u16 count)1592*4882a593Smuzhiyun static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
1593*4882a593Smuzhiyun {
1594*4882a593Smuzhiyun u32 eec;
1595*4882a593Smuzhiyun u32 i;
1596*4882a593Smuzhiyun u16 data = 0;
1597*4882a593Smuzhiyun
1598*4882a593Smuzhiyun /*
1599*4882a593Smuzhiyun * In order to read a register from the EEPROM, we need to shift
1600*4882a593Smuzhiyun * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
1601*4882a593Smuzhiyun * the clock input to the EEPROM (setting the SK bit), and then reading
1602*4882a593Smuzhiyun * the value of the "DO" bit. During this "shifting in" process the
1603*4882a593Smuzhiyun * "DI" bit should always be clear.
1604*4882a593Smuzhiyun */
1605*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
1606*4882a593Smuzhiyun
1607*4882a593Smuzhiyun eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
1608*4882a593Smuzhiyun
1609*4882a593Smuzhiyun for (i = 0; i < count; i++) {
1610*4882a593Smuzhiyun data = data << 1;
1611*4882a593Smuzhiyun ixgbe_raise_eeprom_clk(hw, &eec);
1612*4882a593Smuzhiyun
1613*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
1614*4882a593Smuzhiyun
1615*4882a593Smuzhiyun eec &= ~(IXGBE_EEC_DI);
1616*4882a593Smuzhiyun if (eec & IXGBE_EEC_DO)
1617*4882a593Smuzhiyun data |= 1;
1618*4882a593Smuzhiyun
1619*4882a593Smuzhiyun ixgbe_lower_eeprom_clk(hw, &eec);
1620*4882a593Smuzhiyun }
1621*4882a593Smuzhiyun
1622*4882a593Smuzhiyun return data;
1623*4882a593Smuzhiyun }
1624*4882a593Smuzhiyun
1625*4882a593Smuzhiyun /**
1626*4882a593Smuzhiyun * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
1627*4882a593Smuzhiyun * @hw: pointer to hardware structure
1628*4882a593Smuzhiyun * @eec: EEC register's current value
1629*4882a593Smuzhiyun **/
ixgbe_raise_eeprom_clk(struct ixgbe_hw * hw,u32 * eec)1630*4882a593Smuzhiyun static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1631*4882a593Smuzhiyun {
1632*4882a593Smuzhiyun /*
1633*4882a593Smuzhiyun * Raise the clock input to the EEPROM
1634*4882a593Smuzhiyun * (setting the SK bit), then delay
1635*4882a593Smuzhiyun */
1636*4882a593Smuzhiyun *eec = *eec | IXGBE_EEC_SK;
1637*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), *eec);
1638*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1639*4882a593Smuzhiyun udelay(1);
1640*4882a593Smuzhiyun }
1641*4882a593Smuzhiyun
1642*4882a593Smuzhiyun /**
1643*4882a593Smuzhiyun * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
1644*4882a593Smuzhiyun * @hw: pointer to hardware structure
1645*4882a593Smuzhiyun * @eec: EEC's current value
1646*4882a593Smuzhiyun **/
ixgbe_lower_eeprom_clk(struct ixgbe_hw * hw,u32 * eec)1647*4882a593Smuzhiyun static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
1648*4882a593Smuzhiyun {
1649*4882a593Smuzhiyun /*
1650*4882a593Smuzhiyun * Lower the clock input to the EEPROM (clearing the SK bit), then
1651*4882a593Smuzhiyun * delay
1652*4882a593Smuzhiyun */
1653*4882a593Smuzhiyun *eec = *eec & ~IXGBE_EEC_SK;
1654*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), *eec);
1655*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1656*4882a593Smuzhiyun udelay(1);
1657*4882a593Smuzhiyun }
1658*4882a593Smuzhiyun
1659*4882a593Smuzhiyun /**
1660*4882a593Smuzhiyun * ixgbe_release_eeprom - Release EEPROM, release semaphores
1661*4882a593Smuzhiyun * @hw: pointer to hardware structure
1662*4882a593Smuzhiyun **/
ixgbe_release_eeprom(struct ixgbe_hw * hw)1663*4882a593Smuzhiyun static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
1664*4882a593Smuzhiyun {
1665*4882a593Smuzhiyun u32 eec;
1666*4882a593Smuzhiyun
1667*4882a593Smuzhiyun eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
1668*4882a593Smuzhiyun
1669*4882a593Smuzhiyun eec |= IXGBE_EEC_CS; /* Pull CS high */
1670*4882a593Smuzhiyun eec &= ~IXGBE_EEC_SK; /* Lower SCK */
1671*4882a593Smuzhiyun
1672*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1673*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1674*4882a593Smuzhiyun
1675*4882a593Smuzhiyun udelay(1);
1676*4882a593Smuzhiyun
1677*4882a593Smuzhiyun /* Stop requesting EEPROM access */
1678*4882a593Smuzhiyun eec &= ~IXGBE_EEC_REQ;
1679*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_EEC(hw), eec);
1680*4882a593Smuzhiyun
1681*4882a593Smuzhiyun hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1682*4882a593Smuzhiyun
1683*4882a593Smuzhiyun /*
1684*4882a593Smuzhiyun * Delay before attempt to obtain semaphore again to allow FW
1685*4882a593Smuzhiyun * access. semaphore_delay is in ms we need us for usleep_range
1686*4882a593Smuzhiyun */
1687*4882a593Smuzhiyun usleep_range(hw->eeprom.semaphore_delay * 1000,
1688*4882a593Smuzhiyun hw->eeprom.semaphore_delay * 2000);
1689*4882a593Smuzhiyun }
1690*4882a593Smuzhiyun
1691*4882a593Smuzhiyun /**
1692*4882a593Smuzhiyun * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
1693*4882a593Smuzhiyun * @hw: pointer to hardware structure
1694*4882a593Smuzhiyun **/
ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw * hw)1695*4882a593Smuzhiyun s32 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
1696*4882a593Smuzhiyun {
1697*4882a593Smuzhiyun u16 i;
1698*4882a593Smuzhiyun u16 j;
1699*4882a593Smuzhiyun u16 checksum = 0;
1700*4882a593Smuzhiyun u16 length = 0;
1701*4882a593Smuzhiyun u16 pointer = 0;
1702*4882a593Smuzhiyun u16 word = 0;
1703*4882a593Smuzhiyun
1704*4882a593Smuzhiyun /* Include 0x0-0x3F in the checksum */
1705*4882a593Smuzhiyun for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
1706*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, i, &word)) {
1707*4882a593Smuzhiyun hw_dbg(hw, "EEPROM read failed\n");
1708*4882a593Smuzhiyun break;
1709*4882a593Smuzhiyun }
1710*4882a593Smuzhiyun checksum += word;
1711*4882a593Smuzhiyun }
1712*4882a593Smuzhiyun
1713*4882a593Smuzhiyun /* Include all data from pointers except for the fw pointer */
1714*4882a593Smuzhiyun for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
1715*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, i, &pointer)) {
1716*4882a593Smuzhiyun hw_dbg(hw, "EEPROM read failed\n");
1717*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1718*4882a593Smuzhiyun }
1719*4882a593Smuzhiyun
1720*4882a593Smuzhiyun /* If the pointer seems invalid */
1721*4882a593Smuzhiyun if (pointer == 0xFFFF || pointer == 0)
1722*4882a593Smuzhiyun continue;
1723*4882a593Smuzhiyun
1724*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, pointer, &length)) {
1725*4882a593Smuzhiyun hw_dbg(hw, "EEPROM read failed\n");
1726*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1727*4882a593Smuzhiyun }
1728*4882a593Smuzhiyun
1729*4882a593Smuzhiyun if (length == 0xFFFF || length == 0)
1730*4882a593Smuzhiyun continue;
1731*4882a593Smuzhiyun
1732*4882a593Smuzhiyun for (j = pointer + 1; j <= pointer + length; j++) {
1733*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, j, &word)) {
1734*4882a593Smuzhiyun hw_dbg(hw, "EEPROM read failed\n");
1735*4882a593Smuzhiyun return IXGBE_ERR_EEPROM;
1736*4882a593Smuzhiyun }
1737*4882a593Smuzhiyun checksum += word;
1738*4882a593Smuzhiyun }
1739*4882a593Smuzhiyun }
1740*4882a593Smuzhiyun
1741*4882a593Smuzhiyun checksum = (u16)IXGBE_EEPROM_SUM - checksum;
1742*4882a593Smuzhiyun
1743*4882a593Smuzhiyun return (s32)checksum;
1744*4882a593Smuzhiyun }
1745*4882a593Smuzhiyun
1746*4882a593Smuzhiyun /**
1747*4882a593Smuzhiyun * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
1748*4882a593Smuzhiyun * @hw: pointer to hardware structure
1749*4882a593Smuzhiyun * @checksum_val: calculated checksum
1750*4882a593Smuzhiyun *
1751*4882a593Smuzhiyun * Performs checksum calculation and validates the EEPROM checksum. If the
1752*4882a593Smuzhiyun * caller does not need checksum_val, the value can be NULL.
1753*4882a593Smuzhiyun **/
ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw * hw,u16 * checksum_val)1754*4882a593Smuzhiyun s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
1755*4882a593Smuzhiyun u16 *checksum_val)
1756*4882a593Smuzhiyun {
1757*4882a593Smuzhiyun s32 status;
1758*4882a593Smuzhiyun u16 checksum;
1759*4882a593Smuzhiyun u16 read_checksum = 0;
1760*4882a593Smuzhiyun
1761*4882a593Smuzhiyun /*
1762*4882a593Smuzhiyun * Read the first word from the EEPROM. If this times out or fails, do
1763*4882a593Smuzhiyun * not continue or we could be in for a very long wait while every
1764*4882a593Smuzhiyun * EEPROM read fails
1765*4882a593Smuzhiyun */
1766*4882a593Smuzhiyun status = hw->eeprom.ops.read(hw, 0, &checksum);
1767*4882a593Smuzhiyun if (status) {
1768*4882a593Smuzhiyun hw_dbg(hw, "EEPROM read failed\n");
1769*4882a593Smuzhiyun return status;
1770*4882a593Smuzhiyun }
1771*4882a593Smuzhiyun
1772*4882a593Smuzhiyun status = hw->eeprom.ops.calc_checksum(hw);
1773*4882a593Smuzhiyun if (status < 0)
1774*4882a593Smuzhiyun return status;
1775*4882a593Smuzhiyun
1776*4882a593Smuzhiyun checksum = (u16)(status & 0xffff);
1777*4882a593Smuzhiyun
1778*4882a593Smuzhiyun status = hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
1779*4882a593Smuzhiyun if (status) {
1780*4882a593Smuzhiyun hw_dbg(hw, "EEPROM read failed\n");
1781*4882a593Smuzhiyun return status;
1782*4882a593Smuzhiyun }
1783*4882a593Smuzhiyun
1784*4882a593Smuzhiyun /* Verify read checksum from EEPROM is the same as
1785*4882a593Smuzhiyun * calculated checksum
1786*4882a593Smuzhiyun */
1787*4882a593Smuzhiyun if (read_checksum != checksum)
1788*4882a593Smuzhiyun status = IXGBE_ERR_EEPROM_CHECKSUM;
1789*4882a593Smuzhiyun
1790*4882a593Smuzhiyun /* If the user cares, return the calculated checksum */
1791*4882a593Smuzhiyun if (checksum_val)
1792*4882a593Smuzhiyun *checksum_val = checksum;
1793*4882a593Smuzhiyun
1794*4882a593Smuzhiyun return status;
1795*4882a593Smuzhiyun }
1796*4882a593Smuzhiyun
1797*4882a593Smuzhiyun /**
1798*4882a593Smuzhiyun * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
1799*4882a593Smuzhiyun * @hw: pointer to hardware structure
1800*4882a593Smuzhiyun **/
ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw * hw)1801*4882a593Smuzhiyun s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
1802*4882a593Smuzhiyun {
1803*4882a593Smuzhiyun s32 status;
1804*4882a593Smuzhiyun u16 checksum;
1805*4882a593Smuzhiyun
1806*4882a593Smuzhiyun /*
1807*4882a593Smuzhiyun * Read the first word from the EEPROM. If this times out or fails, do
1808*4882a593Smuzhiyun * not continue or we could be in for a very long wait while every
1809*4882a593Smuzhiyun * EEPROM read fails
1810*4882a593Smuzhiyun */
1811*4882a593Smuzhiyun status = hw->eeprom.ops.read(hw, 0, &checksum);
1812*4882a593Smuzhiyun if (status) {
1813*4882a593Smuzhiyun hw_dbg(hw, "EEPROM read failed\n");
1814*4882a593Smuzhiyun return status;
1815*4882a593Smuzhiyun }
1816*4882a593Smuzhiyun
1817*4882a593Smuzhiyun status = hw->eeprom.ops.calc_checksum(hw);
1818*4882a593Smuzhiyun if (status < 0)
1819*4882a593Smuzhiyun return status;
1820*4882a593Smuzhiyun
1821*4882a593Smuzhiyun checksum = (u16)(status & 0xffff);
1822*4882a593Smuzhiyun
1823*4882a593Smuzhiyun status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, checksum);
1824*4882a593Smuzhiyun
1825*4882a593Smuzhiyun return status;
1826*4882a593Smuzhiyun }
1827*4882a593Smuzhiyun
1828*4882a593Smuzhiyun /**
1829*4882a593Smuzhiyun * ixgbe_set_rar_generic - Set Rx address register
1830*4882a593Smuzhiyun * @hw: pointer to hardware structure
1831*4882a593Smuzhiyun * @index: Receive address register to write
1832*4882a593Smuzhiyun * @addr: Address to put into receive address register
1833*4882a593Smuzhiyun * @vmdq: VMDq "set" or "pool" index
1834*4882a593Smuzhiyun * @enable_addr: set flag that address is active
1835*4882a593Smuzhiyun *
1836*4882a593Smuzhiyun * Puts an ethernet address into a receive address register.
1837*4882a593Smuzhiyun **/
ixgbe_set_rar_generic(struct ixgbe_hw * hw,u32 index,u8 * addr,u32 vmdq,u32 enable_addr)1838*4882a593Smuzhiyun s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
1839*4882a593Smuzhiyun u32 enable_addr)
1840*4882a593Smuzhiyun {
1841*4882a593Smuzhiyun u32 rar_low, rar_high;
1842*4882a593Smuzhiyun u32 rar_entries = hw->mac.num_rar_entries;
1843*4882a593Smuzhiyun
1844*4882a593Smuzhiyun /* Make sure we are using a valid rar index range */
1845*4882a593Smuzhiyun if (index >= rar_entries) {
1846*4882a593Smuzhiyun hw_dbg(hw, "RAR index %d is out of range.\n", index);
1847*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
1848*4882a593Smuzhiyun }
1849*4882a593Smuzhiyun
1850*4882a593Smuzhiyun /* setup VMDq pool selection before this RAR gets enabled */
1851*4882a593Smuzhiyun hw->mac.ops.set_vmdq(hw, index, vmdq);
1852*4882a593Smuzhiyun
1853*4882a593Smuzhiyun /*
1854*4882a593Smuzhiyun * HW expects these in little endian so we reverse the byte
1855*4882a593Smuzhiyun * order from network order (big endian) to little endian
1856*4882a593Smuzhiyun */
1857*4882a593Smuzhiyun rar_low = ((u32)addr[0] |
1858*4882a593Smuzhiyun ((u32)addr[1] << 8) |
1859*4882a593Smuzhiyun ((u32)addr[2] << 16) |
1860*4882a593Smuzhiyun ((u32)addr[3] << 24));
1861*4882a593Smuzhiyun /*
1862*4882a593Smuzhiyun * Some parts put the VMDq setting in the extra RAH bits,
1863*4882a593Smuzhiyun * so save everything except the lower 16 bits that hold part
1864*4882a593Smuzhiyun * of the address and the address valid bit.
1865*4882a593Smuzhiyun */
1866*4882a593Smuzhiyun rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1867*4882a593Smuzhiyun rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1868*4882a593Smuzhiyun rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
1869*4882a593Smuzhiyun
1870*4882a593Smuzhiyun if (enable_addr != 0)
1871*4882a593Smuzhiyun rar_high |= IXGBE_RAH_AV;
1872*4882a593Smuzhiyun
1873*4882a593Smuzhiyun /* Record lower 32 bits of MAC address and then make
1874*4882a593Smuzhiyun * sure that write is flushed to hardware before writing
1875*4882a593Smuzhiyun * the upper 16 bits and setting the valid bit.
1876*4882a593Smuzhiyun */
1877*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
1878*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1879*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1880*4882a593Smuzhiyun
1881*4882a593Smuzhiyun return 0;
1882*4882a593Smuzhiyun }
1883*4882a593Smuzhiyun
1884*4882a593Smuzhiyun /**
1885*4882a593Smuzhiyun * ixgbe_clear_rar_generic - Remove Rx address register
1886*4882a593Smuzhiyun * @hw: pointer to hardware structure
1887*4882a593Smuzhiyun * @index: Receive address register to write
1888*4882a593Smuzhiyun *
1889*4882a593Smuzhiyun * Clears an ethernet address from a receive address register.
1890*4882a593Smuzhiyun **/
ixgbe_clear_rar_generic(struct ixgbe_hw * hw,u32 index)1891*4882a593Smuzhiyun s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
1892*4882a593Smuzhiyun {
1893*4882a593Smuzhiyun u32 rar_high;
1894*4882a593Smuzhiyun u32 rar_entries = hw->mac.num_rar_entries;
1895*4882a593Smuzhiyun
1896*4882a593Smuzhiyun /* Make sure we are using a valid rar index range */
1897*4882a593Smuzhiyun if (index >= rar_entries) {
1898*4882a593Smuzhiyun hw_dbg(hw, "RAR index %d is out of range.\n", index);
1899*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
1900*4882a593Smuzhiyun }
1901*4882a593Smuzhiyun
1902*4882a593Smuzhiyun /*
1903*4882a593Smuzhiyun * Some parts put the VMDq setting in the extra RAH bits,
1904*4882a593Smuzhiyun * so save everything except the lower 16 bits that hold part
1905*4882a593Smuzhiyun * of the address and the address valid bit.
1906*4882a593Smuzhiyun */
1907*4882a593Smuzhiyun rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
1908*4882a593Smuzhiyun rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
1909*4882a593Smuzhiyun
1910*4882a593Smuzhiyun /* Clear the address valid bit and upper 16 bits of the address
1911*4882a593Smuzhiyun * before clearing the lower bits. This way we aren't updating
1912*4882a593Smuzhiyun * a live filter.
1913*4882a593Smuzhiyun */
1914*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
1915*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
1916*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
1917*4882a593Smuzhiyun
1918*4882a593Smuzhiyun /* clear VMDq pool/queue selection for this RAR */
1919*4882a593Smuzhiyun hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
1920*4882a593Smuzhiyun
1921*4882a593Smuzhiyun return 0;
1922*4882a593Smuzhiyun }
1923*4882a593Smuzhiyun
1924*4882a593Smuzhiyun /**
1925*4882a593Smuzhiyun * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
1926*4882a593Smuzhiyun * @hw: pointer to hardware structure
1927*4882a593Smuzhiyun *
1928*4882a593Smuzhiyun * Places the MAC address in receive address register 0 and clears the rest
1929*4882a593Smuzhiyun * of the receive address registers. Clears the multicast table. Assumes
1930*4882a593Smuzhiyun * the receiver is in reset when the routine is called.
1931*4882a593Smuzhiyun **/
ixgbe_init_rx_addrs_generic(struct ixgbe_hw * hw)1932*4882a593Smuzhiyun s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
1933*4882a593Smuzhiyun {
1934*4882a593Smuzhiyun u32 i;
1935*4882a593Smuzhiyun u32 rar_entries = hw->mac.num_rar_entries;
1936*4882a593Smuzhiyun
1937*4882a593Smuzhiyun /*
1938*4882a593Smuzhiyun * If the current mac address is valid, assume it is a software override
1939*4882a593Smuzhiyun * to the permanent address.
1940*4882a593Smuzhiyun * Otherwise, use the permanent address from the eeprom.
1941*4882a593Smuzhiyun */
1942*4882a593Smuzhiyun if (!is_valid_ether_addr(hw->mac.addr)) {
1943*4882a593Smuzhiyun /* Get the MAC address from the RAR0 for later reference */
1944*4882a593Smuzhiyun hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
1945*4882a593Smuzhiyun
1946*4882a593Smuzhiyun hw_dbg(hw, " Keeping Current RAR0 Addr =%pM\n", hw->mac.addr);
1947*4882a593Smuzhiyun } else {
1948*4882a593Smuzhiyun /* Setup the receive address. */
1949*4882a593Smuzhiyun hw_dbg(hw, "Overriding MAC Address in RAR[0]\n");
1950*4882a593Smuzhiyun hw_dbg(hw, " New MAC Addr =%pM\n", hw->mac.addr);
1951*4882a593Smuzhiyun
1952*4882a593Smuzhiyun hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
1953*4882a593Smuzhiyun }
1954*4882a593Smuzhiyun
1955*4882a593Smuzhiyun /* clear VMDq pool/queue selection for RAR 0 */
1956*4882a593Smuzhiyun hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
1957*4882a593Smuzhiyun
1958*4882a593Smuzhiyun hw->addr_ctrl.overflow_promisc = 0;
1959*4882a593Smuzhiyun
1960*4882a593Smuzhiyun hw->addr_ctrl.rar_used_count = 1;
1961*4882a593Smuzhiyun
1962*4882a593Smuzhiyun /* Zero out the other receive addresses. */
1963*4882a593Smuzhiyun hw_dbg(hw, "Clearing RAR[1-%d]\n", rar_entries - 1);
1964*4882a593Smuzhiyun for (i = 1; i < rar_entries; i++) {
1965*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
1966*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
1967*4882a593Smuzhiyun }
1968*4882a593Smuzhiyun
1969*4882a593Smuzhiyun /* Clear the MTA */
1970*4882a593Smuzhiyun hw->addr_ctrl.mta_in_use = 0;
1971*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
1972*4882a593Smuzhiyun
1973*4882a593Smuzhiyun hw_dbg(hw, " Clearing MTA\n");
1974*4882a593Smuzhiyun for (i = 0; i < hw->mac.mcft_size; i++)
1975*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
1976*4882a593Smuzhiyun
1977*4882a593Smuzhiyun if (hw->mac.ops.init_uta_tables)
1978*4882a593Smuzhiyun hw->mac.ops.init_uta_tables(hw);
1979*4882a593Smuzhiyun
1980*4882a593Smuzhiyun return 0;
1981*4882a593Smuzhiyun }
1982*4882a593Smuzhiyun
1983*4882a593Smuzhiyun /**
1984*4882a593Smuzhiyun * ixgbe_mta_vector - Determines bit-vector in multicast table to set
1985*4882a593Smuzhiyun * @hw: pointer to hardware structure
1986*4882a593Smuzhiyun * @mc_addr: the multicast address
1987*4882a593Smuzhiyun *
1988*4882a593Smuzhiyun * Extracts the 12 bits, from a multicast address, to determine which
1989*4882a593Smuzhiyun * bit-vector to set in the multicast table. The hardware uses 12 bits, from
1990*4882a593Smuzhiyun * incoming rx multicast addresses, to determine the bit-vector to check in
1991*4882a593Smuzhiyun * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
1992*4882a593Smuzhiyun * by the MO field of the MCSTCTRL. The MO field is set during initialization
1993*4882a593Smuzhiyun * to mc_filter_type.
1994*4882a593Smuzhiyun **/
ixgbe_mta_vector(struct ixgbe_hw * hw,u8 * mc_addr)1995*4882a593Smuzhiyun static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
1996*4882a593Smuzhiyun {
1997*4882a593Smuzhiyun u32 vector = 0;
1998*4882a593Smuzhiyun
1999*4882a593Smuzhiyun switch (hw->mac.mc_filter_type) {
2000*4882a593Smuzhiyun case 0: /* use bits [47:36] of the address */
2001*4882a593Smuzhiyun vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
2002*4882a593Smuzhiyun break;
2003*4882a593Smuzhiyun case 1: /* use bits [46:35] of the address */
2004*4882a593Smuzhiyun vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
2005*4882a593Smuzhiyun break;
2006*4882a593Smuzhiyun case 2: /* use bits [45:34] of the address */
2007*4882a593Smuzhiyun vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
2008*4882a593Smuzhiyun break;
2009*4882a593Smuzhiyun case 3: /* use bits [43:32] of the address */
2010*4882a593Smuzhiyun vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
2011*4882a593Smuzhiyun break;
2012*4882a593Smuzhiyun default: /* Invalid mc_filter_type */
2013*4882a593Smuzhiyun hw_dbg(hw, "MC filter type param set incorrectly\n");
2014*4882a593Smuzhiyun break;
2015*4882a593Smuzhiyun }
2016*4882a593Smuzhiyun
2017*4882a593Smuzhiyun /* vector can only be 12-bits or boundary will be exceeded */
2018*4882a593Smuzhiyun vector &= 0xFFF;
2019*4882a593Smuzhiyun return vector;
2020*4882a593Smuzhiyun }
2021*4882a593Smuzhiyun
2022*4882a593Smuzhiyun /**
2023*4882a593Smuzhiyun * ixgbe_set_mta - Set bit-vector in multicast table
2024*4882a593Smuzhiyun * @hw: pointer to hardware structure
2025*4882a593Smuzhiyun * @mc_addr: Multicast address
2026*4882a593Smuzhiyun *
2027*4882a593Smuzhiyun * Sets the bit-vector in the multicast table.
2028*4882a593Smuzhiyun **/
ixgbe_set_mta(struct ixgbe_hw * hw,u8 * mc_addr)2029*4882a593Smuzhiyun static void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
2030*4882a593Smuzhiyun {
2031*4882a593Smuzhiyun u32 vector;
2032*4882a593Smuzhiyun u32 vector_bit;
2033*4882a593Smuzhiyun u32 vector_reg;
2034*4882a593Smuzhiyun
2035*4882a593Smuzhiyun hw->addr_ctrl.mta_in_use++;
2036*4882a593Smuzhiyun
2037*4882a593Smuzhiyun vector = ixgbe_mta_vector(hw, mc_addr);
2038*4882a593Smuzhiyun hw_dbg(hw, " bit-vector = 0x%03X\n", vector);
2039*4882a593Smuzhiyun
2040*4882a593Smuzhiyun /*
2041*4882a593Smuzhiyun * The MTA is a register array of 128 32-bit registers. It is treated
2042*4882a593Smuzhiyun * like an array of 4096 bits. We want to set bit
2043*4882a593Smuzhiyun * BitArray[vector_value]. So we figure out what register the bit is
2044*4882a593Smuzhiyun * in, read it, OR in the new bit, then write back the new value. The
2045*4882a593Smuzhiyun * register is determined by the upper 7 bits of the vector value and
2046*4882a593Smuzhiyun * the bit within that register are determined by the lower 5 bits of
2047*4882a593Smuzhiyun * the value.
2048*4882a593Smuzhiyun */
2049*4882a593Smuzhiyun vector_reg = (vector >> 5) & 0x7F;
2050*4882a593Smuzhiyun vector_bit = vector & 0x1F;
2051*4882a593Smuzhiyun hw->mac.mta_shadow[vector_reg] |= BIT(vector_bit);
2052*4882a593Smuzhiyun }
2053*4882a593Smuzhiyun
2054*4882a593Smuzhiyun /**
2055*4882a593Smuzhiyun * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
2056*4882a593Smuzhiyun * @hw: pointer to hardware structure
2057*4882a593Smuzhiyun * @netdev: pointer to net device structure
2058*4882a593Smuzhiyun *
2059*4882a593Smuzhiyun * The given list replaces any existing list. Clears the MC addrs from receive
2060*4882a593Smuzhiyun * address registers and the multicast table. Uses unused receive address
2061*4882a593Smuzhiyun * registers for the first multicast addresses, and hashes the rest into the
2062*4882a593Smuzhiyun * multicast table.
2063*4882a593Smuzhiyun **/
ixgbe_update_mc_addr_list_generic(struct ixgbe_hw * hw,struct net_device * netdev)2064*4882a593Smuzhiyun s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw,
2065*4882a593Smuzhiyun struct net_device *netdev)
2066*4882a593Smuzhiyun {
2067*4882a593Smuzhiyun struct netdev_hw_addr *ha;
2068*4882a593Smuzhiyun u32 i;
2069*4882a593Smuzhiyun
2070*4882a593Smuzhiyun /*
2071*4882a593Smuzhiyun * Set the new number of MC addresses that we are being requested to
2072*4882a593Smuzhiyun * use.
2073*4882a593Smuzhiyun */
2074*4882a593Smuzhiyun hw->addr_ctrl.num_mc_addrs = netdev_mc_count(netdev);
2075*4882a593Smuzhiyun hw->addr_ctrl.mta_in_use = 0;
2076*4882a593Smuzhiyun
2077*4882a593Smuzhiyun /* Clear mta_shadow */
2078*4882a593Smuzhiyun hw_dbg(hw, " Clearing MTA\n");
2079*4882a593Smuzhiyun memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
2080*4882a593Smuzhiyun
2081*4882a593Smuzhiyun /* Update mta shadow */
2082*4882a593Smuzhiyun netdev_for_each_mc_addr(ha, netdev) {
2083*4882a593Smuzhiyun hw_dbg(hw, " Adding the multicast addresses:\n");
2084*4882a593Smuzhiyun ixgbe_set_mta(hw, ha->addr);
2085*4882a593Smuzhiyun }
2086*4882a593Smuzhiyun
2087*4882a593Smuzhiyun /* Enable mta */
2088*4882a593Smuzhiyun for (i = 0; i < hw->mac.mcft_size; i++)
2089*4882a593Smuzhiyun IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
2090*4882a593Smuzhiyun hw->mac.mta_shadow[i]);
2091*4882a593Smuzhiyun
2092*4882a593Smuzhiyun if (hw->addr_ctrl.mta_in_use > 0)
2093*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
2094*4882a593Smuzhiyun IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
2095*4882a593Smuzhiyun
2096*4882a593Smuzhiyun hw_dbg(hw, "ixgbe_update_mc_addr_list_generic Complete\n");
2097*4882a593Smuzhiyun return 0;
2098*4882a593Smuzhiyun }
2099*4882a593Smuzhiyun
2100*4882a593Smuzhiyun /**
2101*4882a593Smuzhiyun * ixgbe_enable_mc_generic - Enable multicast address in RAR
2102*4882a593Smuzhiyun * @hw: pointer to hardware structure
2103*4882a593Smuzhiyun *
2104*4882a593Smuzhiyun * Enables multicast address in RAR and the use of the multicast hash table.
2105*4882a593Smuzhiyun **/
ixgbe_enable_mc_generic(struct ixgbe_hw * hw)2106*4882a593Smuzhiyun s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
2107*4882a593Smuzhiyun {
2108*4882a593Smuzhiyun struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2109*4882a593Smuzhiyun
2110*4882a593Smuzhiyun if (a->mta_in_use > 0)
2111*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
2112*4882a593Smuzhiyun hw->mac.mc_filter_type);
2113*4882a593Smuzhiyun
2114*4882a593Smuzhiyun return 0;
2115*4882a593Smuzhiyun }
2116*4882a593Smuzhiyun
2117*4882a593Smuzhiyun /**
2118*4882a593Smuzhiyun * ixgbe_disable_mc_generic - Disable multicast address in RAR
2119*4882a593Smuzhiyun * @hw: pointer to hardware structure
2120*4882a593Smuzhiyun *
2121*4882a593Smuzhiyun * Disables multicast address in RAR and the use of the multicast hash table.
2122*4882a593Smuzhiyun **/
ixgbe_disable_mc_generic(struct ixgbe_hw * hw)2123*4882a593Smuzhiyun s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
2124*4882a593Smuzhiyun {
2125*4882a593Smuzhiyun struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2126*4882a593Smuzhiyun
2127*4882a593Smuzhiyun if (a->mta_in_use > 0)
2128*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
2129*4882a593Smuzhiyun
2130*4882a593Smuzhiyun return 0;
2131*4882a593Smuzhiyun }
2132*4882a593Smuzhiyun
2133*4882a593Smuzhiyun /**
2134*4882a593Smuzhiyun * ixgbe_fc_enable_generic - Enable flow control
2135*4882a593Smuzhiyun * @hw: pointer to hardware structure
2136*4882a593Smuzhiyun *
2137*4882a593Smuzhiyun * Enable flow control according to the current settings.
2138*4882a593Smuzhiyun **/
ixgbe_fc_enable_generic(struct ixgbe_hw * hw)2139*4882a593Smuzhiyun s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw)
2140*4882a593Smuzhiyun {
2141*4882a593Smuzhiyun u32 mflcn_reg, fccfg_reg;
2142*4882a593Smuzhiyun u32 reg;
2143*4882a593Smuzhiyun u32 fcrtl, fcrth;
2144*4882a593Smuzhiyun int i;
2145*4882a593Smuzhiyun
2146*4882a593Smuzhiyun /* Validate the water mark configuration. */
2147*4882a593Smuzhiyun if (!hw->fc.pause_time)
2148*4882a593Smuzhiyun return IXGBE_ERR_INVALID_LINK_SETTINGS;
2149*4882a593Smuzhiyun
2150*4882a593Smuzhiyun /* Low water mark of zero causes XOFF floods */
2151*4882a593Smuzhiyun for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
2152*4882a593Smuzhiyun if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2153*4882a593Smuzhiyun hw->fc.high_water[i]) {
2154*4882a593Smuzhiyun if (!hw->fc.low_water[i] ||
2155*4882a593Smuzhiyun hw->fc.low_water[i] >= hw->fc.high_water[i]) {
2156*4882a593Smuzhiyun hw_dbg(hw, "Invalid water mark configuration\n");
2157*4882a593Smuzhiyun return IXGBE_ERR_INVALID_LINK_SETTINGS;
2158*4882a593Smuzhiyun }
2159*4882a593Smuzhiyun }
2160*4882a593Smuzhiyun }
2161*4882a593Smuzhiyun
2162*4882a593Smuzhiyun /* Negotiate the fc mode to use */
2163*4882a593Smuzhiyun hw->mac.ops.fc_autoneg(hw);
2164*4882a593Smuzhiyun
2165*4882a593Smuzhiyun /* Disable any previous flow control settings */
2166*4882a593Smuzhiyun mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2167*4882a593Smuzhiyun mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
2168*4882a593Smuzhiyun
2169*4882a593Smuzhiyun fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2170*4882a593Smuzhiyun fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
2171*4882a593Smuzhiyun
2172*4882a593Smuzhiyun /*
2173*4882a593Smuzhiyun * The possible values of fc.current_mode are:
2174*4882a593Smuzhiyun * 0: Flow control is completely disabled
2175*4882a593Smuzhiyun * 1: Rx flow control is enabled (we can receive pause frames,
2176*4882a593Smuzhiyun * but not send pause frames).
2177*4882a593Smuzhiyun * 2: Tx flow control is enabled (we can send pause frames but
2178*4882a593Smuzhiyun * we do not support receiving pause frames).
2179*4882a593Smuzhiyun * 3: Both Rx and Tx flow control (symmetric) are enabled.
2180*4882a593Smuzhiyun * other: Invalid.
2181*4882a593Smuzhiyun */
2182*4882a593Smuzhiyun switch (hw->fc.current_mode) {
2183*4882a593Smuzhiyun case ixgbe_fc_none:
2184*4882a593Smuzhiyun /*
2185*4882a593Smuzhiyun * Flow control is disabled by software override or autoneg.
2186*4882a593Smuzhiyun * The code below will actually disable it in the HW.
2187*4882a593Smuzhiyun */
2188*4882a593Smuzhiyun break;
2189*4882a593Smuzhiyun case ixgbe_fc_rx_pause:
2190*4882a593Smuzhiyun /*
2191*4882a593Smuzhiyun * Rx Flow control is enabled and Tx Flow control is
2192*4882a593Smuzhiyun * disabled by software override. Since there really
2193*4882a593Smuzhiyun * isn't a way to advertise that we are capable of RX
2194*4882a593Smuzhiyun * Pause ONLY, we will advertise that we support both
2195*4882a593Smuzhiyun * symmetric and asymmetric Rx PAUSE. Later, we will
2196*4882a593Smuzhiyun * disable the adapter's ability to send PAUSE frames.
2197*4882a593Smuzhiyun */
2198*4882a593Smuzhiyun mflcn_reg |= IXGBE_MFLCN_RFCE;
2199*4882a593Smuzhiyun break;
2200*4882a593Smuzhiyun case ixgbe_fc_tx_pause:
2201*4882a593Smuzhiyun /*
2202*4882a593Smuzhiyun * Tx Flow control is enabled, and Rx Flow control is
2203*4882a593Smuzhiyun * disabled by software override.
2204*4882a593Smuzhiyun */
2205*4882a593Smuzhiyun fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2206*4882a593Smuzhiyun break;
2207*4882a593Smuzhiyun case ixgbe_fc_full:
2208*4882a593Smuzhiyun /* Flow control (both Rx and Tx) is enabled by SW override. */
2209*4882a593Smuzhiyun mflcn_reg |= IXGBE_MFLCN_RFCE;
2210*4882a593Smuzhiyun fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2211*4882a593Smuzhiyun break;
2212*4882a593Smuzhiyun default:
2213*4882a593Smuzhiyun hw_dbg(hw, "Flow control param set incorrectly\n");
2214*4882a593Smuzhiyun return IXGBE_ERR_CONFIG;
2215*4882a593Smuzhiyun }
2216*4882a593Smuzhiyun
2217*4882a593Smuzhiyun /* Set 802.3x based flow control settings. */
2218*4882a593Smuzhiyun mflcn_reg |= IXGBE_MFLCN_DPF;
2219*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
2220*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
2221*4882a593Smuzhiyun
2222*4882a593Smuzhiyun /* Set up and enable Rx high/low water mark thresholds, enable XON. */
2223*4882a593Smuzhiyun for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
2224*4882a593Smuzhiyun if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2225*4882a593Smuzhiyun hw->fc.high_water[i]) {
2226*4882a593Smuzhiyun fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
2227*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
2228*4882a593Smuzhiyun fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
2229*4882a593Smuzhiyun } else {
2230*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
2231*4882a593Smuzhiyun /*
2232*4882a593Smuzhiyun * In order to prevent Tx hangs when the internal Tx
2233*4882a593Smuzhiyun * switch is enabled we must set the high water mark
2234*4882a593Smuzhiyun * to the Rx packet buffer size - 24KB. This allows
2235*4882a593Smuzhiyun * the Tx switch to function even under heavy Rx
2236*4882a593Smuzhiyun * workloads.
2237*4882a593Smuzhiyun */
2238*4882a593Smuzhiyun fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 24576;
2239*4882a593Smuzhiyun }
2240*4882a593Smuzhiyun
2241*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
2242*4882a593Smuzhiyun }
2243*4882a593Smuzhiyun
2244*4882a593Smuzhiyun /* Configure pause time (2 TCs per register) */
2245*4882a593Smuzhiyun reg = hw->fc.pause_time * 0x00010001U;
2246*4882a593Smuzhiyun for (i = 0; i < (MAX_TRAFFIC_CLASS / 2); i++)
2247*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
2248*4882a593Smuzhiyun
2249*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
2250*4882a593Smuzhiyun
2251*4882a593Smuzhiyun return 0;
2252*4882a593Smuzhiyun }
2253*4882a593Smuzhiyun
2254*4882a593Smuzhiyun /**
2255*4882a593Smuzhiyun * ixgbe_negotiate_fc - Negotiate flow control
2256*4882a593Smuzhiyun * @hw: pointer to hardware structure
2257*4882a593Smuzhiyun * @adv_reg: flow control advertised settings
2258*4882a593Smuzhiyun * @lp_reg: link partner's flow control settings
2259*4882a593Smuzhiyun * @adv_sym: symmetric pause bit in advertisement
2260*4882a593Smuzhiyun * @adv_asm: asymmetric pause bit in advertisement
2261*4882a593Smuzhiyun * @lp_sym: symmetric pause bit in link partner advertisement
2262*4882a593Smuzhiyun * @lp_asm: asymmetric pause bit in link partner advertisement
2263*4882a593Smuzhiyun *
2264*4882a593Smuzhiyun * Find the intersection between advertised settings and link partner's
2265*4882a593Smuzhiyun * advertised settings
2266*4882a593Smuzhiyun **/
ixgbe_negotiate_fc(struct ixgbe_hw * hw,u32 adv_reg,u32 lp_reg,u32 adv_sym,u32 adv_asm,u32 lp_sym,u32 lp_asm)2267*4882a593Smuzhiyun s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
2268*4882a593Smuzhiyun u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
2269*4882a593Smuzhiyun {
2270*4882a593Smuzhiyun if ((!(adv_reg)) || (!(lp_reg)))
2271*4882a593Smuzhiyun return IXGBE_ERR_FC_NOT_NEGOTIATED;
2272*4882a593Smuzhiyun
2273*4882a593Smuzhiyun if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
2274*4882a593Smuzhiyun /*
2275*4882a593Smuzhiyun * Now we need to check if the user selected Rx ONLY
2276*4882a593Smuzhiyun * of pause frames. In this case, we had to advertise
2277*4882a593Smuzhiyun * FULL flow control because we could not advertise RX
2278*4882a593Smuzhiyun * ONLY. Hence, we must now check to see if we need to
2279*4882a593Smuzhiyun * turn OFF the TRANSMISSION of PAUSE frames.
2280*4882a593Smuzhiyun */
2281*4882a593Smuzhiyun if (hw->fc.requested_mode == ixgbe_fc_full) {
2282*4882a593Smuzhiyun hw->fc.current_mode = ixgbe_fc_full;
2283*4882a593Smuzhiyun hw_dbg(hw, "Flow Control = FULL.\n");
2284*4882a593Smuzhiyun } else {
2285*4882a593Smuzhiyun hw->fc.current_mode = ixgbe_fc_rx_pause;
2286*4882a593Smuzhiyun hw_dbg(hw, "Flow Control=RX PAUSE frames only\n");
2287*4882a593Smuzhiyun }
2288*4882a593Smuzhiyun } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2289*4882a593Smuzhiyun (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2290*4882a593Smuzhiyun hw->fc.current_mode = ixgbe_fc_tx_pause;
2291*4882a593Smuzhiyun hw_dbg(hw, "Flow Control = TX PAUSE frames only.\n");
2292*4882a593Smuzhiyun } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2293*4882a593Smuzhiyun !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2294*4882a593Smuzhiyun hw->fc.current_mode = ixgbe_fc_rx_pause;
2295*4882a593Smuzhiyun hw_dbg(hw, "Flow Control = RX PAUSE frames only.\n");
2296*4882a593Smuzhiyun } else {
2297*4882a593Smuzhiyun hw->fc.current_mode = ixgbe_fc_none;
2298*4882a593Smuzhiyun hw_dbg(hw, "Flow Control = NONE.\n");
2299*4882a593Smuzhiyun }
2300*4882a593Smuzhiyun return 0;
2301*4882a593Smuzhiyun }
2302*4882a593Smuzhiyun
2303*4882a593Smuzhiyun /**
2304*4882a593Smuzhiyun * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
2305*4882a593Smuzhiyun * @hw: pointer to hardware structure
2306*4882a593Smuzhiyun *
2307*4882a593Smuzhiyun * Enable flow control according on 1 gig fiber.
2308*4882a593Smuzhiyun **/
ixgbe_fc_autoneg_fiber(struct ixgbe_hw * hw)2309*4882a593Smuzhiyun static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
2310*4882a593Smuzhiyun {
2311*4882a593Smuzhiyun u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
2312*4882a593Smuzhiyun s32 ret_val;
2313*4882a593Smuzhiyun
2314*4882a593Smuzhiyun /*
2315*4882a593Smuzhiyun * On multispeed fiber at 1g, bail out if
2316*4882a593Smuzhiyun * - link is up but AN did not complete, or if
2317*4882a593Smuzhiyun * - link is up and AN completed but timed out
2318*4882a593Smuzhiyun */
2319*4882a593Smuzhiyun
2320*4882a593Smuzhiyun linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
2321*4882a593Smuzhiyun if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
2322*4882a593Smuzhiyun (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1))
2323*4882a593Smuzhiyun return IXGBE_ERR_FC_NOT_NEGOTIATED;
2324*4882a593Smuzhiyun
2325*4882a593Smuzhiyun pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
2326*4882a593Smuzhiyun pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
2327*4882a593Smuzhiyun
2328*4882a593Smuzhiyun ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
2329*4882a593Smuzhiyun pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
2330*4882a593Smuzhiyun IXGBE_PCS1GANA_ASM_PAUSE,
2331*4882a593Smuzhiyun IXGBE_PCS1GANA_SYM_PAUSE,
2332*4882a593Smuzhiyun IXGBE_PCS1GANA_ASM_PAUSE);
2333*4882a593Smuzhiyun
2334*4882a593Smuzhiyun return ret_val;
2335*4882a593Smuzhiyun }
2336*4882a593Smuzhiyun
2337*4882a593Smuzhiyun /**
2338*4882a593Smuzhiyun * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
2339*4882a593Smuzhiyun * @hw: pointer to hardware structure
2340*4882a593Smuzhiyun *
2341*4882a593Smuzhiyun * Enable flow control according to IEEE clause 37.
2342*4882a593Smuzhiyun **/
ixgbe_fc_autoneg_backplane(struct ixgbe_hw * hw)2343*4882a593Smuzhiyun static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
2344*4882a593Smuzhiyun {
2345*4882a593Smuzhiyun u32 links2, anlp1_reg, autoc_reg, links;
2346*4882a593Smuzhiyun s32 ret_val;
2347*4882a593Smuzhiyun
2348*4882a593Smuzhiyun /*
2349*4882a593Smuzhiyun * On backplane, bail out if
2350*4882a593Smuzhiyun * - backplane autoneg was not completed, or if
2351*4882a593Smuzhiyun * - we are 82599 and link partner is not AN enabled
2352*4882a593Smuzhiyun */
2353*4882a593Smuzhiyun links = IXGBE_READ_REG(hw, IXGBE_LINKS);
2354*4882a593Smuzhiyun if ((links & IXGBE_LINKS_KX_AN_COMP) == 0)
2355*4882a593Smuzhiyun return IXGBE_ERR_FC_NOT_NEGOTIATED;
2356*4882a593Smuzhiyun
2357*4882a593Smuzhiyun if (hw->mac.type == ixgbe_mac_82599EB) {
2358*4882a593Smuzhiyun links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
2359*4882a593Smuzhiyun if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0)
2360*4882a593Smuzhiyun return IXGBE_ERR_FC_NOT_NEGOTIATED;
2361*4882a593Smuzhiyun }
2362*4882a593Smuzhiyun /*
2363*4882a593Smuzhiyun * Read the 10g AN autoc and LP ability registers and resolve
2364*4882a593Smuzhiyun * local flow control settings accordingly
2365*4882a593Smuzhiyun */
2366*4882a593Smuzhiyun autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2367*4882a593Smuzhiyun anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
2368*4882a593Smuzhiyun
2369*4882a593Smuzhiyun ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
2370*4882a593Smuzhiyun anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
2371*4882a593Smuzhiyun IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
2372*4882a593Smuzhiyun
2373*4882a593Smuzhiyun return ret_val;
2374*4882a593Smuzhiyun }
2375*4882a593Smuzhiyun
2376*4882a593Smuzhiyun /**
2377*4882a593Smuzhiyun * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
2378*4882a593Smuzhiyun * @hw: pointer to hardware structure
2379*4882a593Smuzhiyun *
2380*4882a593Smuzhiyun * Enable flow control according to IEEE clause 37.
2381*4882a593Smuzhiyun **/
ixgbe_fc_autoneg_copper(struct ixgbe_hw * hw)2382*4882a593Smuzhiyun static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
2383*4882a593Smuzhiyun {
2384*4882a593Smuzhiyun u16 technology_ability_reg = 0;
2385*4882a593Smuzhiyun u16 lp_technology_ability_reg = 0;
2386*4882a593Smuzhiyun
2387*4882a593Smuzhiyun hw->phy.ops.read_reg(hw, MDIO_AN_ADVERTISE,
2388*4882a593Smuzhiyun MDIO_MMD_AN,
2389*4882a593Smuzhiyun &technology_ability_reg);
2390*4882a593Smuzhiyun hw->phy.ops.read_reg(hw, MDIO_AN_LPA,
2391*4882a593Smuzhiyun MDIO_MMD_AN,
2392*4882a593Smuzhiyun &lp_technology_ability_reg);
2393*4882a593Smuzhiyun
2394*4882a593Smuzhiyun return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
2395*4882a593Smuzhiyun (u32)lp_technology_ability_reg,
2396*4882a593Smuzhiyun IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
2397*4882a593Smuzhiyun IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
2398*4882a593Smuzhiyun }
2399*4882a593Smuzhiyun
2400*4882a593Smuzhiyun /**
2401*4882a593Smuzhiyun * ixgbe_fc_autoneg - Configure flow control
2402*4882a593Smuzhiyun * @hw: pointer to hardware structure
2403*4882a593Smuzhiyun *
2404*4882a593Smuzhiyun * Compares our advertised flow control capabilities to those advertised by
2405*4882a593Smuzhiyun * our link partner, and determines the proper flow control mode to use.
2406*4882a593Smuzhiyun **/
ixgbe_fc_autoneg(struct ixgbe_hw * hw)2407*4882a593Smuzhiyun void ixgbe_fc_autoneg(struct ixgbe_hw *hw)
2408*4882a593Smuzhiyun {
2409*4882a593Smuzhiyun s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
2410*4882a593Smuzhiyun ixgbe_link_speed speed;
2411*4882a593Smuzhiyun bool link_up;
2412*4882a593Smuzhiyun
2413*4882a593Smuzhiyun /*
2414*4882a593Smuzhiyun * AN should have completed when the cable was plugged in.
2415*4882a593Smuzhiyun * Look for reasons to bail out. Bail out if:
2416*4882a593Smuzhiyun * - FC autoneg is disabled, or if
2417*4882a593Smuzhiyun * - link is not up.
2418*4882a593Smuzhiyun *
2419*4882a593Smuzhiyun * Since we're being called from an LSC, link is already known to be up.
2420*4882a593Smuzhiyun * So use link_up_wait_to_complete=false.
2421*4882a593Smuzhiyun */
2422*4882a593Smuzhiyun if (hw->fc.disable_fc_autoneg)
2423*4882a593Smuzhiyun goto out;
2424*4882a593Smuzhiyun
2425*4882a593Smuzhiyun hw->mac.ops.check_link(hw, &speed, &link_up, false);
2426*4882a593Smuzhiyun if (!link_up)
2427*4882a593Smuzhiyun goto out;
2428*4882a593Smuzhiyun
2429*4882a593Smuzhiyun switch (hw->phy.media_type) {
2430*4882a593Smuzhiyun /* Autoneg flow control on fiber adapters */
2431*4882a593Smuzhiyun case ixgbe_media_type_fiber:
2432*4882a593Smuzhiyun if (speed == IXGBE_LINK_SPEED_1GB_FULL)
2433*4882a593Smuzhiyun ret_val = ixgbe_fc_autoneg_fiber(hw);
2434*4882a593Smuzhiyun break;
2435*4882a593Smuzhiyun
2436*4882a593Smuzhiyun /* Autoneg flow control on backplane adapters */
2437*4882a593Smuzhiyun case ixgbe_media_type_backplane:
2438*4882a593Smuzhiyun ret_val = ixgbe_fc_autoneg_backplane(hw);
2439*4882a593Smuzhiyun break;
2440*4882a593Smuzhiyun
2441*4882a593Smuzhiyun /* Autoneg flow control on copper adapters */
2442*4882a593Smuzhiyun case ixgbe_media_type_copper:
2443*4882a593Smuzhiyun if (ixgbe_device_supports_autoneg_fc(hw))
2444*4882a593Smuzhiyun ret_val = ixgbe_fc_autoneg_copper(hw);
2445*4882a593Smuzhiyun break;
2446*4882a593Smuzhiyun
2447*4882a593Smuzhiyun default:
2448*4882a593Smuzhiyun break;
2449*4882a593Smuzhiyun }
2450*4882a593Smuzhiyun
2451*4882a593Smuzhiyun out:
2452*4882a593Smuzhiyun if (ret_val == 0) {
2453*4882a593Smuzhiyun hw->fc.fc_was_autonegged = true;
2454*4882a593Smuzhiyun } else {
2455*4882a593Smuzhiyun hw->fc.fc_was_autonegged = false;
2456*4882a593Smuzhiyun hw->fc.current_mode = hw->fc.requested_mode;
2457*4882a593Smuzhiyun }
2458*4882a593Smuzhiyun }
2459*4882a593Smuzhiyun
2460*4882a593Smuzhiyun /**
2461*4882a593Smuzhiyun * ixgbe_pcie_timeout_poll - Return number of times to poll for completion
2462*4882a593Smuzhiyun * @hw: pointer to hardware structure
2463*4882a593Smuzhiyun *
2464*4882a593Smuzhiyun * System-wide timeout range is encoded in PCIe Device Control2 register.
2465*4882a593Smuzhiyun *
2466*4882a593Smuzhiyun * Add 10% to specified maximum and return the number of times to poll for
2467*4882a593Smuzhiyun * completion timeout, in units of 100 microsec. Never return less than
2468*4882a593Smuzhiyun * 800 = 80 millisec.
2469*4882a593Smuzhiyun **/
ixgbe_pcie_timeout_poll(struct ixgbe_hw * hw)2470*4882a593Smuzhiyun static u32 ixgbe_pcie_timeout_poll(struct ixgbe_hw *hw)
2471*4882a593Smuzhiyun {
2472*4882a593Smuzhiyun s16 devctl2;
2473*4882a593Smuzhiyun u32 pollcnt;
2474*4882a593Smuzhiyun
2475*4882a593Smuzhiyun devctl2 = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_DEVICE_CONTROL2);
2476*4882a593Smuzhiyun devctl2 &= IXGBE_PCIDEVCTRL2_TIMEO_MASK;
2477*4882a593Smuzhiyun
2478*4882a593Smuzhiyun switch (devctl2) {
2479*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_65_130ms:
2480*4882a593Smuzhiyun pollcnt = 1300; /* 130 millisec */
2481*4882a593Smuzhiyun break;
2482*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_260_520ms:
2483*4882a593Smuzhiyun pollcnt = 5200; /* 520 millisec */
2484*4882a593Smuzhiyun break;
2485*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_1_2s:
2486*4882a593Smuzhiyun pollcnt = 20000; /* 2 sec */
2487*4882a593Smuzhiyun break;
2488*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_4_8s:
2489*4882a593Smuzhiyun pollcnt = 80000; /* 8 sec */
2490*4882a593Smuzhiyun break;
2491*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_17_34s:
2492*4882a593Smuzhiyun pollcnt = 34000; /* 34 sec */
2493*4882a593Smuzhiyun break;
2494*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_50_100us: /* 100 microsecs */
2495*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_1_2ms: /* 2 millisecs */
2496*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_16_32ms: /* 32 millisec */
2497*4882a593Smuzhiyun case IXGBE_PCIDEVCTRL2_16_32ms_def: /* 32 millisec default */
2498*4882a593Smuzhiyun default:
2499*4882a593Smuzhiyun pollcnt = 800; /* 80 millisec minimum */
2500*4882a593Smuzhiyun break;
2501*4882a593Smuzhiyun }
2502*4882a593Smuzhiyun
2503*4882a593Smuzhiyun /* add 10% to spec maximum */
2504*4882a593Smuzhiyun return (pollcnt * 11) / 10;
2505*4882a593Smuzhiyun }
2506*4882a593Smuzhiyun
2507*4882a593Smuzhiyun /**
2508*4882a593Smuzhiyun * ixgbe_disable_pcie_master - Disable PCI-express master access
2509*4882a593Smuzhiyun * @hw: pointer to hardware structure
2510*4882a593Smuzhiyun *
2511*4882a593Smuzhiyun * Disables PCI-Express master access and verifies there are no pending
2512*4882a593Smuzhiyun * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
2513*4882a593Smuzhiyun * bit hasn't caused the master requests to be disabled, else 0
2514*4882a593Smuzhiyun * is returned signifying master requests disabled.
2515*4882a593Smuzhiyun **/
ixgbe_disable_pcie_master(struct ixgbe_hw * hw)2516*4882a593Smuzhiyun static s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
2517*4882a593Smuzhiyun {
2518*4882a593Smuzhiyun u32 i, poll;
2519*4882a593Smuzhiyun u16 value;
2520*4882a593Smuzhiyun
2521*4882a593Smuzhiyun /* Always set this bit to ensure any future transactions are blocked */
2522*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
2523*4882a593Smuzhiyun
2524*4882a593Smuzhiyun /* Poll for bit to read as set */
2525*4882a593Smuzhiyun for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2526*4882a593Smuzhiyun if (IXGBE_READ_REG(hw, IXGBE_CTRL) & IXGBE_CTRL_GIO_DIS)
2527*4882a593Smuzhiyun break;
2528*4882a593Smuzhiyun usleep_range(100, 120);
2529*4882a593Smuzhiyun }
2530*4882a593Smuzhiyun if (i >= IXGBE_PCI_MASTER_DISABLE_TIMEOUT) {
2531*4882a593Smuzhiyun hw_dbg(hw, "GIO disable did not set - requesting resets\n");
2532*4882a593Smuzhiyun goto gio_disable_fail;
2533*4882a593Smuzhiyun }
2534*4882a593Smuzhiyun
2535*4882a593Smuzhiyun /* Exit if master requests are blocked */
2536*4882a593Smuzhiyun if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO) ||
2537*4882a593Smuzhiyun ixgbe_removed(hw->hw_addr))
2538*4882a593Smuzhiyun return 0;
2539*4882a593Smuzhiyun
2540*4882a593Smuzhiyun /* Poll for master request bit to clear */
2541*4882a593Smuzhiyun for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
2542*4882a593Smuzhiyun udelay(100);
2543*4882a593Smuzhiyun if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
2544*4882a593Smuzhiyun return 0;
2545*4882a593Smuzhiyun }
2546*4882a593Smuzhiyun
2547*4882a593Smuzhiyun /*
2548*4882a593Smuzhiyun * Two consecutive resets are required via CTRL.RST per datasheet
2549*4882a593Smuzhiyun * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
2550*4882a593Smuzhiyun * of this need. The first reset prevents new master requests from
2551*4882a593Smuzhiyun * being issued by our device. We then must wait 1usec or more for any
2552*4882a593Smuzhiyun * remaining completions from the PCIe bus to trickle in, and then reset
2553*4882a593Smuzhiyun * again to clear out any effects they may have had on our device.
2554*4882a593Smuzhiyun */
2555*4882a593Smuzhiyun hw_dbg(hw, "GIO Master Disable bit didn't clear - requesting resets\n");
2556*4882a593Smuzhiyun gio_disable_fail:
2557*4882a593Smuzhiyun hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2558*4882a593Smuzhiyun
2559*4882a593Smuzhiyun if (hw->mac.type >= ixgbe_mac_X550)
2560*4882a593Smuzhiyun return 0;
2561*4882a593Smuzhiyun
2562*4882a593Smuzhiyun /*
2563*4882a593Smuzhiyun * Before proceeding, make sure that the PCIe block does not have
2564*4882a593Smuzhiyun * transactions pending.
2565*4882a593Smuzhiyun */
2566*4882a593Smuzhiyun poll = ixgbe_pcie_timeout_poll(hw);
2567*4882a593Smuzhiyun for (i = 0; i < poll; i++) {
2568*4882a593Smuzhiyun udelay(100);
2569*4882a593Smuzhiyun value = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_DEVICE_STATUS);
2570*4882a593Smuzhiyun if (ixgbe_removed(hw->hw_addr))
2571*4882a593Smuzhiyun return 0;
2572*4882a593Smuzhiyun if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
2573*4882a593Smuzhiyun return 0;
2574*4882a593Smuzhiyun }
2575*4882a593Smuzhiyun
2576*4882a593Smuzhiyun hw_dbg(hw, "PCIe transaction pending bit also did not clear.\n");
2577*4882a593Smuzhiyun return IXGBE_ERR_MASTER_REQUESTS_PENDING;
2578*4882a593Smuzhiyun }
2579*4882a593Smuzhiyun
2580*4882a593Smuzhiyun /**
2581*4882a593Smuzhiyun * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
2582*4882a593Smuzhiyun * @hw: pointer to hardware structure
2583*4882a593Smuzhiyun * @mask: Mask to specify which semaphore to acquire
2584*4882a593Smuzhiyun *
2585*4882a593Smuzhiyun * Acquires the SWFW semaphore through the GSSR register for the specified
2586*4882a593Smuzhiyun * function (CSR, PHY0, PHY1, EEPROM, Flash)
2587*4882a593Smuzhiyun **/
ixgbe_acquire_swfw_sync(struct ixgbe_hw * hw,u32 mask)2588*4882a593Smuzhiyun s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u32 mask)
2589*4882a593Smuzhiyun {
2590*4882a593Smuzhiyun u32 gssr = 0;
2591*4882a593Smuzhiyun u32 swmask = mask;
2592*4882a593Smuzhiyun u32 fwmask = mask << 5;
2593*4882a593Smuzhiyun u32 timeout = 200;
2594*4882a593Smuzhiyun u32 i;
2595*4882a593Smuzhiyun
2596*4882a593Smuzhiyun for (i = 0; i < timeout; i++) {
2597*4882a593Smuzhiyun /*
2598*4882a593Smuzhiyun * SW NVM semaphore bit is used for access to all
2599*4882a593Smuzhiyun * SW_FW_SYNC bits (not just NVM)
2600*4882a593Smuzhiyun */
2601*4882a593Smuzhiyun if (ixgbe_get_eeprom_semaphore(hw))
2602*4882a593Smuzhiyun return IXGBE_ERR_SWFW_SYNC;
2603*4882a593Smuzhiyun
2604*4882a593Smuzhiyun gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2605*4882a593Smuzhiyun if (!(gssr & (fwmask | swmask))) {
2606*4882a593Smuzhiyun gssr |= swmask;
2607*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2608*4882a593Smuzhiyun ixgbe_release_eeprom_semaphore(hw);
2609*4882a593Smuzhiyun return 0;
2610*4882a593Smuzhiyun } else {
2611*4882a593Smuzhiyun /* Resource is currently in use by FW or SW */
2612*4882a593Smuzhiyun ixgbe_release_eeprom_semaphore(hw);
2613*4882a593Smuzhiyun usleep_range(5000, 10000);
2614*4882a593Smuzhiyun }
2615*4882a593Smuzhiyun }
2616*4882a593Smuzhiyun
2617*4882a593Smuzhiyun /* If time expired clear the bits holding the lock and retry */
2618*4882a593Smuzhiyun if (gssr & (fwmask | swmask))
2619*4882a593Smuzhiyun ixgbe_release_swfw_sync(hw, gssr & (fwmask | swmask));
2620*4882a593Smuzhiyun
2621*4882a593Smuzhiyun usleep_range(5000, 10000);
2622*4882a593Smuzhiyun return IXGBE_ERR_SWFW_SYNC;
2623*4882a593Smuzhiyun }
2624*4882a593Smuzhiyun
2625*4882a593Smuzhiyun /**
2626*4882a593Smuzhiyun * ixgbe_release_swfw_sync - Release SWFW semaphore
2627*4882a593Smuzhiyun * @hw: pointer to hardware structure
2628*4882a593Smuzhiyun * @mask: Mask to specify which semaphore to release
2629*4882a593Smuzhiyun *
2630*4882a593Smuzhiyun * Releases the SWFW semaphore through the GSSR register for the specified
2631*4882a593Smuzhiyun * function (CSR, PHY0, PHY1, EEPROM, Flash)
2632*4882a593Smuzhiyun **/
ixgbe_release_swfw_sync(struct ixgbe_hw * hw,u32 mask)2633*4882a593Smuzhiyun void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u32 mask)
2634*4882a593Smuzhiyun {
2635*4882a593Smuzhiyun u32 gssr;
2636*4882a593Smuzhiyun u32 swmask = mask;
2637*4882a593Smuzhiyun
2638*4882a593Smuzhiyun ixgbe_get_eeprom_semaphore(hw);
2639*4882a593Smuzhiyun
2640*4882a593Smuzhiyun gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
2641*4882a593Smuzhiyun gssr &= ~swmask;
2642*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
2643*4882a593Smuzhiyun
2644*4882a593Smuzhiyun ixgbe_release_eeprom_semaphore(hw);
2645*4882a593Smuzhiyun }
2646*4882a593Smuzhiyun
2647*4882a593Smuzhiyun /**
2648*4882a593Smuzhiyun * prot_autoc_read_generic - Hides MAC differences needed for AUTOC read
2649*4882a593Smuzhiyun * @hw: pointer to hardware structure
2650*4882a593Smuzhiyun * @reg_val: Value we read from AUTOC
2651*4882a593Smuzhiyun * @locked: bool to indicate whether the SW/FW lock should be taken. Never
2652*4882a593Smuzhiyun * true in this the generic case.
2653*4882a593Smuzhiyun *
2654*4882a593Smuzhiyun * The default case requires no protection so just to the register read.
2655*4882a593Smuzhiyun **/
prot_autoc_read_generic(struct ixgbe_hw * hw,bool * locked,u32 * reg_val)2656*4882a593Smuzhiyun s32 prot_autoc_read_generic(struct ixgbe_hw *hw, bool *locked, u32 *reg_val)
2657*4882a593Smuzhiyun {
2658*4882a593Smuzhiyun *locked = false;
2659*4882a593Smuzhiyun *reg_val = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2660*4882a593Smuzhiyun return 0;
2661*4882a593Smuzhiyun }
2662*4882a593Smuzhiyun
2663*4882a593Smuzhiyun /**
2664*4882a593Smuzhiyun * prot_autoc_write_generic - Hides MAC differences needed for AUTOC write
2665*4882a593Smuzhiyun * @hw: pointer to hardware structure
2666*4882a593Smuzhiyun * @reg_val: value to write to AUTOC
2667*4882a593Smuzhiyun * @locked: bool to indicate whether the SW/FW lock was already taken by
2668*4882a593Smuzhiyun * previous read.
2669*4882a593Smuzhiyun **/
prot_autoc_write_generic(struct ixgbe_hw * hw,u32 reg_val,bool locked)2670*4882a593Smuzhiyun s32 prot_autoc_write_generic(struct ixgbe_hw *hw, u32 reg_val, bool locked)
2671*4882a593Smuzhiyun {
2672*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_val);
2673*4882a593Smuzhiyun return 0;
2674*4882a593Smuzhiyun }
2675*4882a593Smuzhiyun
2676*4882a593Smuzhiyun /**
2677*4882a593Smuzhiyun * ixgbe_disable_rx_buff_generic - Stops the receive data path
2678*4882a593Smuzhiyun * @hw: pointer to hardware structure
2679*4882a593Smuzhiyun *
2680*4882a593Smuzhiyun * Stops the receive data path and waits for the HW to internally
2681*4882a593Smuzhiyun * empty the Rx security block.
2682*4882a593Smuzhiyun **/
ixgbe_disable_rx_buff_generic(struct ixgbe_hw * hw)2683*4882a593Smuzhiyun s32 ixgbe_disable_rx_buff_generic(struct ixgbe_hw *hw)
2684*4882a593Smuzhiyun {
2685*4882a593Smuzhiyun #define IXGBE_MAX_SECRX_POLL 40
2686*4882a593Smuzhiyun int i;
2687*4882a593Smuzhiyun int secrxreg;
2688*4882a593Smuzhiyun
2689*4882a593Smuzhiyun secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2690*4882a593Smuzhiyun secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
2691*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2692*4882a593Smuzhiyun for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
2693*4882a593Smuzhiyun secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
2694*4882a593Smuzhiyun if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
2695*4882a593Smuzhiyun break;
2696*4882a593Smuzhiyun else
2697*4882a593Smuzhiyun /* Use interrupt-safe sleep just in case */
2698*4882a593Smuzhiyun udelay(1000);
2699*4882a593Smuzhiyun }
2700*4882a593Smuzhiyun
2701*4882a593Smuzhiyun /* For informational purposes only */
2702*4882a593Smuzhiyun if (i >= IXGBE_MAX_SECRX_POLL)
2703*4882a593Smuzhiyun hw_dbg(hw, "Rx unit being enabled before security path fully disabled. Continuing with init.\n");
2704*4882a593Smuzhiyun
2705*4882a593Smuzhiyun return 0;
2706*4882a593Smuzhiyun
2707*4882a593Smuzhiyun }
2708*4882a593Smuzhiyun
2709*4882a593Smuzhiyun /**
2710*4882a593Smuzhiyun * ixgbe_enable_rx_buff - Enables the receive data path
2711*4882a593Smuzhiyun * @hw: pointer to hardware structure
2712*4882a593Smuzhiyun *
2713*4882a593Smuzhiyun * Enables the receive data path
2714*4882a593Smuzhiyun **/
ixgbe_enable_rx_buff_generic(struct ixgbe_hw * hw)2715*4882a593Smuzhiyun s32 ixgbe_enable_rx_buff_generic(struct ixgbe_hw *hw)
2716*4882a593Smuzhiyun {
2717*4882a593Smuzhiyun u32 secrxreg;
2718*4882a593Smuzhiyun
2719*4882a593Smuzhiyun secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
2720*4882a593Smuzhiyun secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
2721*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
2722*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
2723*4882a593Smuzhiyun
2724*4882a593Smuzhiyun return 0;
2725*4882a593Smuzhiyun }
2726*4882a593Smuzhiyun
2727*4882a593Smuzhiyun /**
2728*4882a593Smuzhiyun * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
2729*4882a593Smuzhiyun * @hw: pointer to hardware structure
2730*4882a593Smuzhiyun * @regval: register value to write to RXCTRL
2731*4882a593Smuzhiyun *
2732*4882a593Smuzhiyun * Enables the Rx DMA unit
2733*4882a593Smuzhiyun **/
ixgbe_enable_rx_dma_generic(struct ixgbe_hw * hw,u32 regval)2734*4882a593Smuzhiyun s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
2735*4882a593Smuzhiyun {
2736*4882a593Smuzhiyun if (regval & IXGBE_RXCTRL_RXEN)
2737*4882a593Smuzhiyun hw->mac.ops.enable_rx(hw);
2738*4882a593Smuzhiyun else
2739*4882a593Smuzhiyun hw->mac.ops.disable_rx(hw);
2740*4882a593Smuzhiyun
2741*4882a593Smuzhiyun return 0;
2742*4882a593Smuzhiyun }
2743*4882a593Smuzhiyun
2744*4882a593Smuzhiyun /**
2745*4882a593Smuzhiyun * ixgbe_blink_led_start_generic - Blink LED based on index.
2746*4882a593Smuzhiyun * @hw: pointer to hardware structure
2747*4882a593Smuzhiyun * @index: led number to blink
2748*4882a593Smuzhiyun **/
ixgbe_blink_led_start_generic(struct ixgbe_hw * hw,u32 index)2749*4882a593Smuzhiyun s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
2750*4882a593Smuzhiyun {
2751*4882a593Smuzhiyun ixgbe_link_speed speed = 0;
2752*4882a593Smuzhiyun bool link_up = false;
2753*4882a593Smuzhiyun u32 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
2754*4882a593Smuzhiyun u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2755*4882a593Smuzhiyun bool locked = false;
2756*4882a593Smuzhiyun s32 ret_val;
2757*4882a593Smuzhiyun
2758*4882a593Smuzhiyun if (index > 3)
2759*4882a593Smuzhiyun return IXGBE_ERR_PARAM;
2760*4882a593Smuzhiyun
2761*4882a593Smuzhiyun /*
2762*4882a593Smuzhiyun * Link must be up to auto-blink the LEDs;
2763*4882a593Smuzhiyun * Force it if link is down.
2764*4882a593Smuzhiyun */
2765*4882a593Smuzhiyun hw->mac.ops.check_link(hw, &speed, &link_up, false);
2766*4882a593Smuzhiyun
2767*4882a593Smuzhiyun if (!link_up) {
2768*4882a593Smuzhiyun ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg);
2769*4882a593Smuzhiyun if (ret_val)
2770*4882a593Smuzhiyun return ret_val;
2771*4882a593Smuzhiyun
2772*4882a593Smuzhiyun autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2773*4882a593Smuzhiyun autoc_reg |= IXGBE_AUTOC_FLU;
2774*4882a593Smuzhiyun
2775*4882a593Smuzhiyun ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked);
2776*4882a593Smuzhiyun if (ret_val)
2777*4882a593Smuzhiyun return ret_val;
2778*4882a593Smuzhiyun
2779*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
2780*4882a593Smuzhiyun
2781*4882a593Smuzhiyun usleep_range(10000, 20000);
2782*4882a593Smuzhiyun }
2783*4882a593Smuzhiyun
2784*4882a593Smuzhiyun led_reg &= ~IXGBE_LED_MODE_MASK(index);
2785*4882a593Smuzhiyun led_reg |= IXGBE_LED_BLINK(index);
2786*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2787*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
2788*4882a593Smuzhiyun
2789*4882a593Smuzhiyun return 0;
2790*4882a593Smuzhiyun }
2791*4882a593Smuzhiyun
2792*4882a593Smuzhiyun /**
2793*4882a593Smuzhiyun * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
2794*4882a593Smuzhiyun * @hw: pointer to hardware structure
2795*4882a593Smuzhiyun * @index: led number to stop blinking
2796*4882a593Smuzhiyun **/
ixgbe_blink_led_stop_generic(struct ixgbe_hw * hw,u32 index)2797*4882a593Smuzhiyun s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
2798*4882a593Smuzhiyun {
2799*4882a593Smuzhiyun u32 autoc_reg = 0;
2800*4882a593Smuzhiyun u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
2801*4882a593Smuzhiyun bool locked = false;
2802*4882a593Smuzhiyun s32 ret_val;
2803*4882a593Smuzhiyun
2804*4882a593Smuzhiyun if (index > 3)
2805*4882a593Smuzhiyun return IXGBE_ERR_PARAM;
2806*4882a593Smuzhiyun
2807*4882a593Smuzhiyun ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg);
2808*4882a593Smuzhiyun if (ret_val)
2809*4882a593Smuzhiyun return ret_val;
2810*4882a593Smuzhiyun
2811*4882a593Smuzhiyun autoc_reg &= ~IXGBE_AUTOC_FLU;
2812*4882a593Smuzhiyun autoc_reg |= IXGBE_AUTOC_AN_RESTART;
2813*4882a593Smuzhiyun
2814*4882a593Smuzhiyun ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked);
2815*4882a593Smuzhiyun if (ret_val)
2816*4882a593Smuzhiyun return ret_val;
2817*4882a593Smuzhiyun
2818*4882a593Smuzhiyun led_reg &= ~IXGBE_LED_MODE_MASK(index);
2819*4882a593Smuzhiyun led_reg &= ~IXGBE_LED_BLINK(index);
2820*4882a593Smuzhiyun led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
2821*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
2822*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
2823*4882a593Smuzhiyun
2824*4882a593Smuzhiyun return 0;
2825*4882a593Smuzhiyun }
2826*4882a593Smuzhiyun
2827*4882a593Smuzhiyun /**
2828*4882a593Smuzhiyun * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
2829*4882a593Smuzhiyun * @hw: pointer to hardware structure
2830*4882a593Smuzhiyun * @san_mac_offset: SAN MAC address offset
2831*4882a593Smuzhiyun *
2832*4882a593Smuzhiyun * This function will read the EEPROM location for the SAN MAC address
2833*4882a593Smuzhiyun * pointer, and returns the value at that location. This is used in both
2834*4882a593Smuzhiyun * get and set mac_addr routines.
2835*4882a593Smuzhiyun **/
ixgbe_get_san_mac_addr_offset(struct ixgbe_hw * hw,u16 * san_mac_offset)2836*4882a593Smuzhiyun static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
2837*4882a593Smuzhiyun u16 *san_mac_offset)
2838*4882a593Smuzhiyun {
2839*4882a593Smuzhiyun s32 ret_val;
2840*4882a593Smuzhiyun
2841*4882a593Smuzhiyun /*
2842*4882a593Smuzhiyun * First read the EEPROM pointer to see if the MAC addresses are
2843*4882a593Smuzhiyun * available.
2844*4882a593Smuzhiyun */
2845*4882a593Smuzhiyun ret_val = hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR,
2846*4882a593Smuzhiyun san_mac_offset);
2847*4882a593Smuzhiyun if (ret_val)
2848*4882a593Smuzhiyun hw_err(hw, "eeprom read at offset %d failed\n",
2849*4882a593Smuzhiyun IXGBE_SAN_MAC_ADDR_PTR);
2850*4882a593Smuzhiyun
2851*4882a593Smuzhiyun return ret_val;
2852*4882a593Smuzhiyun }
2853*4882a593Smuzhiyun
2854*4882a593Smuzhiyun /**
2855*4882a593Smuzhiyun * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
2856*4882a593Smuzhiyun * @hw: pointer to hardware structure
2857*4882a593Smuzhiyun * @san_mac_addr: SAN MAC address
2858*4882a593Smuzhiyun *
2859*4882a593Smuzhiyun * Reads the SAN MAC address from the EEPROM, if it's available. This is
2860*4882a593Smuzhiyun * per-port, so set_lan_id() must be called before reading the addresses.
2861*4882a593Smuzhiyun * set_lan_id() is called by identify_sfp(), but this cannot be relied
2862*4882a593Smuzhiyun * upon for non-SFP connections, so we must call it here.
2863*4882a593Smuzhiyun **/
ixgbe_get_san_mac_addr_generic(struct ixgbe_hw * hw,u8 * san_mac_addr)2864*4882a593Smuzhiyun s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
2865*4882a593Smuzhiyun {
2866*4882a593Smuzhiyun u16 san_mac_data, san_mac_offset;
2867*4882a593Smuzhiyun u8 i;
2868*4882a593Smuzhiyun s32 ret_val;
2869*4882a593Smuzhiyun
2870*4882a593Smuzhiyun /*
2871*4882a593Smuzhiyun * First read the EEPROM pointer to see if the MAC addresses are
2872*4882a593Smuzhiyun * available. If they're not, no point in calling set_lan_id() here.
2873*4882a593Smuzhiyun */
2874*4882a593Smuzhiyun ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
2875*4882a593Smuzhiyun if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
2876*4882a593Smuzhiyun
2877*4882a593Smuzhiyun goto san_mac_addr_clr;
2878*4882a593Smuzhiyun
2879*4882a593Smuzhiyun /* make sure we know which port we need to program */
2880*4882a593Smuzhiyun hw->mac.ops.set_lan_id(hw);
2881*4882a593Smuzhiyun /* apply the port offset to the address offset */
2882*4882a593Smuzhiyun (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
2883*4882a593Smuzhiyun (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
2884*4882a593Smuzhiyun for (i = 0; i < 3; i++) {
2885*4882a593Smuzhiyun ret_val = hw->eeprom.ops.read(hw, san_mac_offset,
2886*4882a593Smuzhiyun &san_mac_data);
2887*4882a593Smuzhiyun if (ret_val) {
2888*4882a593Smuzhiyun hw_err(hw, "eeprom read at offset %d failed\n",
2889*4882a593Smuzhiyun san_mac_offset);
2890*4882a593Smuzhiyun goto san_mac_addr_clr;
2891*4882a593Smuzhiyun }
2892*4882a593Smuzhiyun san_mac_addr[i * 2] = (u8)(san_mac_data);
2893*4882a593Smuzhiyun san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
2894*4882a593Smuzhiyun san_mac_offset++;
2895*4882a593Smuzhiyun }
2896*4882a593Smuzhiyun return 0;
2897*4882a593Smuzhiyun
2898*4882a593Smuzhiyun san_mac_addr_clr:
2899*4882a593Smuzhiyun /* No addresses available in this EEPROM. It's not necessarily an
2900*4882a593Smuzhiyun * error though, so just wipe the local address and return.
2901*4882a593Smuzhiyun */
2902*4882a593Smuzhiyun for (i = 0; i < 6; i++)
2903*4882a593Smuzhiyun san_mac_addr[i] = 0xFF;
2904*4882a593Smuzhiyun return ret_val;
2905*4882a593Smuzhiyun }
2906*4882a593Smuzhiyun
2907*4882a593Smuzhiyun /**
2908*4882a593Smuzhiyun * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
2909*4882a593Smuzhiyun * @hw: pointer to hardware structure
2910*4882a593Smuzhiyun *
2911*4882a593Smuzhiyun * Read PCIe configuration space, and get the MSI-X vector count from
2912*4882a593Smuzhiyun * the capabilities table.
2913*4882a593Smuzhiyun **/
ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw * hw)2914*4882a593Smuzhiyun u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
2915*4882a593Smuzhiyun {
2916*4882a593Smuzhiyun u16 msix_count;
2917*4882a593Smuzhiyun u16 max_msix_count;
2918*4882a593Smuzhiyun u16 pcie_offset;
2919*4882a593Smuzhiyun
2920*4882a593Smuzhiyun switch (hw->mac.type) {
2921*4882a593Smuzhiyun case ixgbe_mac_82598EB:
2922*4882a593Smuzhiyun pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS;
2923*4882a593Smuzhiyun max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598;
2924*4882a593Smuzhiyun break;
2925*4882a593Smuzhiyun case ixgbe_mac_82599EB:
2926*4882a593Smuzhiyun case ixgbe_mac_X540:
2927*4882a593Smuzhiyun case ixgbe_mac_X550:
2928*4882a593Smuzhiyun case ixgbe_mac_X550EM_x:
2929*4882a593Smuzhiyun case ixgbe_mac_x550em_a:
2930*4882a593Smuzhiyun pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS;
2931*4882a593Smuzhiyun max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
2932*4882a593Smuzhiyun break;
2933*4882a593Smuzhiyun default:
2934*4882a593Smuzhiyun return 1;
2935*4882a593Smuzhiyun }
2936*4882a593Smuzhiyun
2937*4882a593Smuzhiyun msix_count = ixgbe_read_pci_cfg_word(hw, pcie_offset);
2938*4882a593Smuzhiyun if (ixgbe_removed(hw->hw_addr))
2939*4882a593Smuzhiyun msix_count = 0;
2940*4882a593Smuzhiyun msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
2941*4882a593Smuzhiyun
2942*4882a593Smuzhiyun /* MSI-X count is zero-based in HW */
2943*4882a593Smuzhiyun msix_count++;
2944*4882a593Smuzhiyun
2945*4882a593Smuzhiyun if (msix_count > max_msix_count)
2946*4882a593Smuzhiyun msix_count = max_msix_count;
2947*4882a593Smuzhiyun
2948*4882a593Smuzhiyun return msix_count;
2949*4882a593Smuzhiyun }
2950*4882a593Smuzhiyun
2951*4882a593Smuzhiyun /**
2952*4882a593Smuzhiyun * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
2953*4882a593Smuzhiyun * @hw: pointer to hardware struct
2954*4882a593Smuzhiyun * @rar: receive address register index to disassociate
2955*4882a593Smuzhiyun * @vmdq: VMDq pool index to remove from the rar
2956*4882a593Smuzhiyun **/
ixgbe_clear_vmdq_generic(struct ixgbe_hw * hw,u32 rar,u32 vmdq)2957*4882a593Smuzhiyun s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
2958*4882a593Smuzhiyun {
2959*4882a593Smuzhiyun u32 mpsar_lo, mpsar_hi;
2960*4882a593Smuzhiyun u32 rar_entries = hw->mac.num_rar_entries;
2961*4882a593Smuzhiyun
2962*4882a593Smuzhiyun /* Make sure we are using a valid rar index range */
2963*4882a593Smuzhiyun if (rar >= rar_entries) {
2964*4882a593Smuzhiyun hw_dbg(hw, "RAR index %d is out of range.\n", rar);
2965*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
2966*4882a593Smuzhiyun }
2967*4882a593Smuzhiyun
2968*4882a593Smuzhiyun mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
2969*4882a593Smuzhiyun mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
2970*4882a593Smuzhiyun
2971*4882a593Smuzhiyun if (ixgbe_removed(hw->hw_addr))
2972*4882a593Smuzhiyun return 0;
2973*4882a593Smuzhiyun
2974*4882a593Smuzhiyun if (!mpsar_lo && !mpsar_hi)
2975*4882a593Smuzhiyun return 0;
2976*4882a593Smuzhiyun
2977*4882a593Smuzhiyun if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
2978*4882a593Smuzhiyun if (mpsar_lo) {
2979*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
2980*4882a593Smuzhiyun mpsar_lo = 0;
2981*4882a593Smuzhiyun }
2982*4882a593Smuzhiyun if (mpsar_hi) {
2983*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
2984*4882a593Smuzhiyun mpsar_hi = 0;
2985*4882a593Smuzhiyun }
2986*4882a593Smuzhiyun } else if (vmdq < 32) {
2987*4882a593Smuzhiyun mpsar_lo &= ~BIT(vmdq);
2988*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
2989*4882a593Smuzhiyun } else {
2990*4882a593Smuzhiyun mpsar_hi &= ~BIT(vmdq - 32);
2991*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
2992*4882a593Smuzhiyun }
2993*4882a593Smuzhiyun
2994*4882a593Smuzhiyun /* was that the last pool using this rar? */
2995*4882a593Smuzhiyun if (mpsar_lo == 0 && mpsar_hi == 0 &&
2996*4882a593Smuzhiyun rar != 0 && rar != hw->mac.san_mac_rar_index)
2997*4882a593Smuzhiyun hw->mac.ops.clear_rar(hw, rar);
2998*4882a593Smuzhiyun
2999*4882a593Smuzhiyun return 0;
3000*4882a593Smuzhiyun }
3001*4882a593Smuzhiyun
3002*4882a593Smuzhiyun /**
3003*4882a593Smuzhiyun * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
3004*4882a593Smuzhiyun * @hw: pointer to hardware struct
3005*4882a593Smuzhiyun * @rar: receive address register index to associate with a VMDq index
3006*4882a593Smuzhiyun * @vmdq: VMDq pool index
3007*4882a593Smuzhiyun **/
ixgbe_set_vmdq_generic(struct ixgbe_hw * hw,u32 rar,u32 vmdq)3008*4882a593Smuzhiyun s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
3009*4882a593Smuzhiyun {
3010*4882a593Smuzhiyun u32 mpsar;
3011*4882a593Smuzhiyun u32 rar_entries = hw->mac.num_rar_entries;
3012*4882a593Smuzhiyun
3013*4882a593Smuzhiyun /* Make sure we are using a valid rar index range */
3014*4882a593Smuzhiyun if (rar >= rar_entries) {
3015*4882a593Smuzhiyun hw_dbg(hw, "RAR index %d is out of range.\n", rar);
3016*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
3017*4882a593Smuzhiyun }
3018*4882a593Smuzhiyun
3019*4882a593Smuzhiyun if (vmdq < 32) {
3020*4882a593Smuzhiyun mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3021*4882a593Smuzhiyun mpsar |= BIT(vmdq);
3022*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
3023*4882a593Smuzhiyun } else {
3024*4882a593Smuzhiyun mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3025*4882a593Smuzhiyun mpsar |= BIT(vmdq - 32);
3026*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
3027*4882a593Smuzhiyun }
3028*4882a593Smuzhiyun return 0;
3029*4882a593Smuzhiyun }
3030*4882a593Smuzhiyun
3031*4882a593Smuzhiyun /**
3032*4882a593Smuzhiyun * This function should only be involved in the IOV mode.
3033*4882a593Smuzhiyun * In IOV mode, Default pool is next pool after the number of
3034*4882a593Smuzhiyun * VFs advertized and not 0.
3035*4882a593Smuzhiyun * MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index]
3036*4882a593Smuzhiyun *
3037*4882a593Smuzhiyun * ixgbe_set_vmdq_san_mac - Associate default VMDq pool index with a rx address
3038*4882a593Smuzhiyun * @hw: pointer to hardware struct
3039*4882a593Smuzhiyun * @vmdq: VMDq pool index
3040*4882a593Smuzhiyun **/
ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw * hw,u32 vmdq)3041*4882a593Smuzhiyun s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq)
3042*4882a593Smuzhiyun {
3043*4882a593Smuzhiyun u32 rar = hw->mac.san_mac_rar_index;
3044*4882a593Smuzhiyun
3045*4882a593Smuzhiyun if (vmdq < 32) {
3046*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), BIT(vmdq));
3047*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
3048*4882a593Smuzhiyun } else {
3049*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
3050*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), BIT(vmdq - 32));
3051*4882a593Smuzhiyun }
3052*4882a593Smuzhiyun
3053*4882a593Smuzhiyun return 0;
3054*4882a593Smuzhiyun }
3055*4882a593Smuzhiyun
3056*4882a593Smuzhiyun /**
3057*4882a593Smuzhiyun * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
3058*4882a593Smuzhiyun * @hw: pointer to hardware structure
3059*4882a593Smuzhiyun **/
ixgbe_init_uta_tables_generic(struct ixgbe_hw * hw)3060*4882a593Smuzhiyun s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
3061*4882a593Smuzhiyun {
3062*4882a593Smuzhiyun int i;
3063*4882a593Smuzhiyun
3064*4882a593Smuzhiyun for (i = 0; i < 128; i++)
3065*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
3066*4882a593Smuzhiyun
3067*4882a593Smuzhiyun return 0;
3068*4882a593Smuzhiyun }
3069*4882a593Smuzhiyun
3070*4882a593Smuzhiyun /**
3071*4882a593Smuzhiyun * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
3072*4882a593Smuzhiyun * @hw: pointer to hardware structure
3073*4882a593Smuzhiyun * @vlan: VLAN id to write to VLAN filter
3074*4882a593Smuzhiyun * @vlvf_bypass: true to find vlanid only, false returns first empty slot if
3075*4882a593Smuzhiyun * vlanid not found
3076*4882a593Smuzhiyun *
3077*4882a593Smuzhiyun * return the VLVF index where this VLAN id should be placed
3078*4882a593Smuzhiyun *
3079*4882a593Smuzhiyun **/
ixgbe_find_vlvf_slot(struct ixgbe_hw * hw,u32 vlan,bool vlvf_bypass)3080*4882a593Smuzhiyun static s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan, bool vlvf_bypass)
3081*4882a593Smuzhiyun {
3082*4882a593Smuzhiyun s32 regindex, first_empty_slot;
3083*4882a593Smuzhiyun u32 bits;
3084*4882a593Smuzhiyun
3085*4882a593Smuzhiyun /* short cut the special case */
3086*4882a593Smuzhiyun if (vlan == 0)
3087*4882a593Smuzhiyun return 0;
3088*4882a593Smuzhiyun
3089*4882a593Smuzhiyun /* if vlvf_bypass is set we don't want to use an empty slot, we
3090*4882a593Smuzhiyun * will simply bypass the VLVF if there are no entries present in the
3091*4882a593Smuzhiyun * VLVF that contain our VLAN
3092*4882a593Smuzhiyun */
3093*4882a593Smuzhiyun first_empty_slot = vlvf_bypass ? IXGBE_ERR_NO_SPACE : 0;
3094*4882a593Smuzhiyun
3095*4882a593Smuzhiyun /* add VLAN enable bit for comparison */
3096*4882a593Smuzhiyun vlan |= IXGBE_VLVF_VIEN;
3097*4882a593Smuzhiyun
3098*4882a593Smuzhiyun /* Search for the vlan id in the VLVF entries. Save off the first empty
3099*4882a593Smuzhiyun * slot found along the way.
3100*4882a593Smuzhiyun *
3101*4882a593Smuzhiyun * pre-decrement loop covering (IXGBE_VLVF_ENTRIES - 1) .. 1
3102*4882a593Smuzhiyun */
3103*4882a593Smuzhiyun for (regindex = IXGBE_VLVF_ENTRIES; --regindex;) {
3104*4882a593Smuzhiyun bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
3105*4882a593Smuzhiyun if (bits == vlan)
3106*4882a593Smuzhiyun return regindex;
3107*4882a593Smuzhiyun if (!first_empty_slot && !bits)
3108*4882a593Smuzhiyun first_empty_slot = regindex;
3109*4882a593Smuzhiyun }
3110*4882a593Smuzhiyun
3111*4882a593Smuzhiyun /* If we are here then we didn't find the VLAN. Return first empty
3112*4882a593Smuzhiyun * slot we found during our search, else error.
3113*4882a593Smuzhiyun */
3114*4882a593Smuzhiyun if (!first_empty_slot)
3115*4882a593Smuzhiyun hw_dbg(hw, "No space in VLVF.\n");
3116*4882a593Smuzhiyun
3117*4882a593Smuzhiyun return first_empty_slot ? : IXGBE_ERR_NO_SPACE;
3118*4882a593Smuzhiyun }
3119*4882a593Smuzhiyun
3120*4882a593Smuzhiyun /**
3121*4882a593Smuzhiyun * ixgbe_set_vfta_generic - Set VLAN filter table
3122*4882a593Smuzhiyun * @hw: pointer to hardware structure
3123*4882a593Smuzhiyun * @vlan: VLAN id to write to VLAN filter
3124*4882a593Smuzhiyun * @vind: VMDq output index that maps queue to VLAN id in VFVFB
3125*4882a593Smuzhiyun * @vlan_on: boolean flag to turn on/off VLAN in VFVF
3126*4882a593Smuzhiyun * @vlvf_bypass: boolean flag indicating updating default pool is okay
3127*4882a593Smuzhiyun *
3128*4882a593Smuzhiyun * Turn on/off specified VLAN in the VLAN filter table.
3129*4882a593Smuzhiyun **/
ixgbe_set_vfta_generic(struct ixgbe_hw * hw,u32 vlan,u32 vind,bool vlan_on,bool vlvf_bypass)3130*4882a593Smuzhiyun s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
3131*4882a593Smuzhiyun bool vlan_on, bool vlvf_bypass)
3132*4882a593Smuzhiyun {
3133*4882a593Smuzhiyun u32 regidx, vfta_delta, vfta, bits;
3134*4882a593Smuzhiyun s32 vlvf_index;
3135*4882a593Smuzhiyun
3136*4882a593Smuzhiyun if ((vlan > 4095) || (vind > 63))
3137*4882a593Smuzhiyun return IXGBE_ERR_PARAM;
3138*4882a593Smuzhiyun
3139*4882a593Smuzhiyun /*
3140*4882a593Smuzhiyun * this is a 2 part operation - first the VFTA, then the
3141*4882a593Smuzhiyun * VLVF and VLVFB if VT Mode is set
3142*4882a593Smuzhiyun * We don't write the VFTA until we know the VLVF part succeeded.
3143*4882a593Smuzhiyun */
3144*4882a593Smuzhiyun
3145*4882a593Smuzhiyun /* Part 1
3146*4882a593Smuzhiyun * The VFTA is a bitstring made up of 128 32-bit registers
3147*4882a593Smuzhiyun * that enable the particular VLAN id, much like the MTA:
3148*4882a593Smuzhiyun * bits[11-5]: which register
3149*4882a593Smuzhiyun * bits[4-0]: which bit in the register
3150*4882a593Smuzhiyun */
3151*4882a593Smuzhiyun regidx = vlan / 32;
3152*4882a593Smuzhiyun vfta_delta = BIT(vlan % 32);
3153*4882a593Smuzhiyun vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regidx));
3154*4882a593Smuzhiyun
3155*4882a593Smuzhiyun /* vfta_delta represents the difference between the current value
3156*4882a593Smuzhiyun * of vfta and the value we want in the register. Since the diff
3157*4882a593Smuzhiyun * is an XOR mask we can just update vfta using an XOR.
3158*4882a593Smuzhiyun */
3159*4882a593Smuzhiyun vfta_delta &= vlan_on ? ~vfta : vfta;
3160*4882a593Smuzhiyun vfta ^= vfta_delta;
3161*4882a593Smuzhiyun
3162*4882a593Smuzhiyun /* Part 2
3163*4882a593Smuzhiyun * If VT Mode is set
3164*4882a593Smuzhiyun * Either vlan_on
3165*4882a593Smuzhiyun * make sure the vlan is in VLVF
3166*4882a593Smuzhiyun * set the vind bit in the matching VLVFB
3167*4882a593Smuzhiyun * Or !vlan_on
3168*4882a593Smuzhiyun * clear the pool bit and possibly the vind
3169*4882a593Smuzhiyun */
3170*4882a593Smuzhiyun if (!(IXGBE_READ_REG(hw, IXGBE_VT_CTL) & IXGBE_VT_CTL_VT_ENABLE))
3171*4882a593Smuzhiyun goto vfta_update;
3172*4882a593Smuzhiyun
3173*4882a593Smuzhiyun vlvf_index = ixgbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
3174*4882a593Smuzhiyun if (vlvf_index < 0) {
3175*4882a593Smuzhiyun if (vlvf_bypass)
3176*4882a593Smuzhiyun goto vfta_update;
3177*4882a593Smuzhiyun return vlvf_index;
3178*4882a593Smuzhiyun }
3179*4882a593Smuzhiyun
3180*4882a593Smuzhiyun bits = IXGBE_READ_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32));
3181*4882a593Smuzhiyun
3182*4882a593Smuzhiyun /* set the pool bit */
3183*4882a593Smuzhiyun bits |= BIT(vind % 32);
3184*4882a593Smuzhiyun if (vlan_on)
3185*4882a593Smuzhiyun goto vlvf_update;
3186*4882a593Smuzhiyun
3187*4882a593Smuzhiyun /* clear the pool bit */
3188*4882a593Smuzhiyun bits ^= BIT(vind % 32);
3189*4882a593Smuzhiyun
3190*4882a593Smuzhiyun if (!bits &&
3191*4882a593Smuzhiyun !IXGBE_READ_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + 1 - vind / 32))) {
3192*4882a593Smuzhiyun /* Clear VFTA first, then disable VLVF. Otherwise
3193*4882a593Smuzhiyun * we run the risk of stray packets leaking into
3194*4882a593Smuzhiyun * the PF via the default pool
3195*4882a593Smuzhiyun */
3196*4882a593Smuzhiyun if (vfta_delta)
3197*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VFTA(regidx), vfta);
3198*4882a593Smuzhiyun
3199*4882a593Smuzhiyun /* disable VLVF and clear remaining bit from pool */
3200*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
3201*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32), 0);
3202*4882a593Smuzhiyun
3203*4882a593Smuzhiyun return 0;
3204*4882a593Smuzhiyun }
3205*4882a593Smuzhiyun
3206*4882a593Smuzhiyun /* If there are still bits set in the VLVFB registers
3207*4882a593Smuzhiyun * for the VLAN ID indicated we need to see if the
3208*4882a593Smuzhiyun * caller is requesting that we clear the VFTA entry bit.
3209*4882a593Smuzhiyun * If the caller has requested that we clear the VFTA
3210*4882a593Smuzhiyun * entry bit but there are still pools/VFs using this VLAN
3211*4882a593Smuzhiyun * ID entry then ignore the request. We're not worried
3212*4882a593Smuzhiyun * about the case where we're turning the VFTA VLAN ID
3213*4882a593Smuzhiyun * entry bit on, only when requested to turn it off as
3214*4882a593Smuzhiyun * there may be multiple pools and/or VFs using the
3215*4882a593Smuzhiyun * VLAN ID entry. In that case we cannot clear the
3216*4882a593Smuzhiyun * VFTA bit until all pools/VFs using that VLAN ID have also
3217*4882a593Smuzhiyun * been cleared. This will be indicated by "bits" being
3218*4882a593Smuzhiyun * zero.
3219*4882a593Smuzhiyun */
3220*4882a593Smuzhiyun vfta_delta = 0;
3221*4882a593Smuzhiyun
3222*4882a593Smuzhiyun vlvf_update:
3223*4882a593Smuzhiyun /* record pool change and enable VLAN ID if not already enabled */
3224*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32), bits);
3225*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), IXGBE_VLVF_VIEN | vlan);
3226*4882a593Smuzhiyun
3227*4882a593Smuzhiyun vfta_update:
3228*4882a593Smuzhiyun /* Update VFTA now that we are ready for traffic */
3229*4882a593Smuzhiyun if (vfta_delta)
3230*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VFTA(regidx), vfta);
3231*4882a593Smuzhiyun
3232*4882a593Smuzhiyun return 0;
3233*4882a593Smuzhiyun }
3234*4882a593Smuzhiyun
3235*4882a593Smuzhiyun /**
3236*4882a593Smuzhiyun * ixgbe_clear_vfta_generic - Clear VLAN filter table
3237*4882a593Smuzhiyun * @hw: pointer to hardware structure
3238*4882a593Smuzhiyun *
3239*4882a593Smuzhiyun * Clears the VLAN filer table, and the VMDq index associated with the filter
3240*4882a593Smuzhiyun **/
ixgbe_clear_vfta_generic(struct ixgbe_hw * hw)3241*4882a593Smuzhiyun s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
3242*4882a593Smuzhiyun {
3243*4882a593Smuzhiyun u32 offset;
3244*4882a593Smuzhiyun
3245*4882a593Smuzhiyun for (offset = 0; offset < hw->mac.vft_size; offset++)
3246*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
3247*4882a593Smuzhiyun
3248*4882a593Smuzhiyun for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
3249*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
3250*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
3251*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2 + 1), 0);
3252*4882a593Smuzhiyun }
3253*4882a593Smuzhiyun
3254*4882a593Smuzhiyun return 0;
3255*4882a593Smuzhiyun }
3256*4882a593Smuzhiyun
3257*4882a593Smuzhiyun /**
3258*4882a593Smuzhiyun * ixgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
3259*4882a593Smuzhiyun * @hw: pointer to hardware structure
3260*4882a593Smuzhiyun *
3261*4882a593Smuzhiyun * Contains the logic to identify if we need to verify link for the
3262*4882a593Smuzhiyun * crosstalk fix
3263*4882a593Smuzhiyun **/
ixgbe_need_crosstalk_fix(struct ixgbe_hw * hw)3264*4882a593Smuzhiyun static bool ixgbe_need_crosstalk_fix(struct ixgbe_hw *hw)
3265*4882a593Smuzhiyun {
3266*4882a593Smuzhiyun /* Does FW say we need the fix */
3267*4882a593Smuzhiyun if (!hw->need_crosstalk_fix)
3268*4882a593Smuzhiyun return false;
3269*4882a593Smuzhiyun
3270*4882a593Smuzhiyun /* Only consider SFP+ PHYs i.e. media type fiber */
3271*4882a593Smuzhiyun switch (hw->mac.ops.get_media_type(hw)) {
3272*4882a593Smuzhiyun case ixgbe_media_type_fiber:
3273*4882a593Smuzhiyun case ixgbe_media_type_fiber_qsfp:
3274*4882a593Smuzhiyun break;
3275*4882a593Smuzhiyun default:
3276*4882a593Smuzhiyun return false;
3277*4882a593Smuzhiyun }
3278*4882a593Smuzhiyun
3279*4882a593Smuzhiyun return true;
3280*4882a593Smuzhiyun }
3281*4882a593Smuzhiyun
3282*4882a593Smuzhiyun /**
3283*4882a593Smuzhiyun * ixgbe_check_mac_link_generic - Determine link and speed status
3284*4882a593Smuzhiyun * @hw: pointer to hardware structure
3285*4882a593Smuzhiyun * @speed: pointer to link speed
3286*4882a593Smuzhiyun * @link_up: true when link is up
3287*4882a593Smuzhiyun * @link_up_wait_to_complete: bool used to wait for link up or not
3288*4882a593Smuzhiyun *
3289*4882a593Smuzhiyun * Reads the links register to determine if link is up and the current speed
3290*4882a593Smuzhiyun **/
ixgbe_check_mac_link_generic(struct ixgbe_hw * hw,ixgbe_link_speed * speed,bool * link_up,bool link_up_wait_to_complete)3291*4882a593Smuzhiyun s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
3292*4882a593Smuzhiyun bool *link_up, bool link_up_wait_to_complete)
3293*4882a593Smuzhiyun {
3294*4882a593Smuzhiyun u32 links_reg, links_orig;
3295*4882a593Smuzhiyun u32 i;
3296*4882a593Smuzhiyun
3297*4882a593Smuzhiyun /* If Crosstalk fix enabled do the sanity check of making sure
3298*4882a593Smuzhiyun * the SFP+ cage is full.
3299*4882a593Smuzhiyun */
3300*4882a593Smuzhiyun if (ixgbe_need_crosstalk_fix(hw)) {
3301*4882a593Smuzhiyun u32 sfp_cage_full;
3302*4882a593Smuzhiyun
3303*4882a593Smuzhiyun switch (hw->mac.type) {
3304*4882a593Smuzhiyun case ixgbe_mac_82599EB:
3305*4882a593Smuzhiyun sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
3306*4882a593Smuzhiyun IXGBE_ESDP_SDP2;
3307*4882a593Smuzhiyun break;
3308*4882a593Smuzhiyun case ixgbe_mac_X550EM_x:
3309*4882a593Smuzhiyun case ixgbe_mac_x550em_a:
3310*4882a593Smuzhiyun sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
3311*4882a593Smuzhiyun IXGBE_ESDP_SDP0;
3312*4882a593Smuzhiyun break;
3313*4882a593Smuzhiyun default:
3314*4882a593Smuzhiyun /* sanity check - No SFP+ devices here */
3315*4882a593Smuzhiyun sfp_cage_full = false;
3316*4882a593Smuzhiyun break;
3317*4882a593Smuzhiyun }
3318*4882a593Smuzhiyun
3319*4882a593Smuzhiyun if (!sfp_cage_full) {
3320*4882a593Smuzhiyun *link_up = false;
3321*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_UNKNOWN;
3322*4882a593Smuzhiyun return 0;
3323*4882a593Smuzhiyun }
3324*4882a593Smuzhiyun }
3325*4882a593Smuzhiyun
3326*4882a593Smuzhiyun /* clear the old state */
3327*4882a593Smuzhiyun links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
3328*4882a593Smuzhiyun
3329*4882a593Smuzhiyun links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
3330*4882a593Smuzhiyun
3331*4882a593Smuzhiyun if (links_orig != links_reg) {
3332*4882a593Smuzhiyun hw_dbg(hw, "LINKS changed from %08X to %08X\n",
3333*4882a593Smuzhiyun links_orig, links_reg);
3334*4882a593Smuzhiyun }
3335*4882a593Smuzhiyun
3336*4882a593Smuzhiyun if (link_up_wait_to_complete) {
3337*4882a593Smuzhiyun for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
3338*4882a593Smuzhiyun if (links_reg & IXGBE_LINKS_UP) {
3339*4882a593Smuzhiyun *link_up = true;
3340*4882a593Smuzhiyun break;
3341*4882a593Smuzhiyun } else {
3342*4882a593Smuzhiyun *link_up = false;
3343*4882a593Smuzhiyun }
3344*4882a593Smuzhiyun msleep(100);
3345*4882a593Smuzhiyun links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
3346*4882a593Smuzhiyun }
3347*4882a593Smuzhiyun } else {
3348*4882a593Smuzhiyun if (links_reg & IXGBE_LINKS_UP)
3349*4882a593Smuzhiyun *link_up = true;
3350*4882a593Smuzhiyun else
3351*4882a593Smuzhiyun *link_up = false;
3352*4882a593Smuzhiyun }
3353*4882a593Smuzhiyun
3354*4882a593Smuzhiyun switch (links_reg & IXGBE_LINKS_SPEED_82599) {
3355*4882a593Smuzhiyun case IXGBE_LINKS_SPEED_10G_82599:
3356*4882a593Smuzhiyun if ((hw->mac.type >= ixgbe_mac_X550) &&
3357*4882a593Smuzhiyun (links_reg & IXGBE_LINKS_SPEED_NON_STD))
3358*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
3359*4882a593Smuzhiyun else
3360*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_10GB_FULL;
3361*4882a593Smuzhiyun break;
3362*4882a593Smuzhiyun case IXGBE_LINKS_SPEED_1G_82599:
3363*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_1GB_FULL;
3364*4882a593Smuzhiyun break;
3365*4882a593Smuzhiyun case IXGBE_LINKS_SPEED_100_82599:
3366*4882a593Smuzhiyun if ((hw->mac.type >= ixgbe_mac_X550) &&
3367*4882a593Smuzhiyun (links_reg & IXGBE_LINKS_SPEED_NON_STD))
3368*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_5GB_FULL;
3369*4882a593Smuzhiyun else
3370*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_100_FULL;
3371*4882a593Smuzhiyun break;
3372*4882a593Smuzhiyun case IXGBE_LINKS_SPEED_10_X550EM_A:
3373*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_UNKNOWN;
3374*4882a593Smuzhiyun if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
3375*4882a593Smuzhiyun hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L) {
3376*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_10_FULL;
3377*4882a593Smuzhiyun }
3378*4882a593Smuzhiyun break;
3379*4882a593Smuzhiyun default:
3380*4882a593Smuzhiyun *speed = IXGBE_LINK_SPEED_UNKNOWN;
3381*4882a593Smuzhiyun }
3382*4882a593Smuzhiyun
3383*4882a593Smuzhiyun return 0;
3384*4882a593Smuzhiyun }
3385*4882a593Smuzhiyun
3386*4882a593Smuzhiyun /**
3387*4882a593Smuzhiyun * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
3388*4882a593Smuzhiyun * the EEPROM
3389*4882a593Smuzhiyun * @hw: pointer to hardware structure
3390*4882a593Smuzhiyun * @wwnn_prefix: the alternative WWNN prefix
3391*4882a593Smuzhiyun * @wwpn_prefix: the alternative WWPN prefix
3392*4882a593Smuzhiyun *
3393*4882a593Smuzhiyun * This function will read the EEPROM from the alternative SAN MAC address
3394*4882a593Smuzhiyun * block to check the support for the alternative WWNN/WWPN prefix support.
3395*4882a593Smuzhiyun **/
ixgbe_get_wwn_prefix_generic(struct ixgbe_hw * hw,u16 * wwnn_prefix,u16 * wwpn_prefix)3396*4882a593Smuzhiyun s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
3397*4882a593Smuzhiyun u16 *wwpn_prefix)
3398*4882a593Smuzhiyun {
3399*4882a593Smuzhiyun u16 offset, caps;
3400*4882a593Smuzhiyun u16 alt_san_mac_blk_offset;
3401*4882a593Smuzhiyun
3402*4882a593Smuzhiyun /* clear output first */
3403*4882a593Smuzhiyun *wwnn_prefix = 0xFFFF;
3404*4882a593Smuzhiyun *wwpn_prefix = 0xFFFF;
3405*4882a593Smuzhiyun
3406*4882a593Smuzhiyun /* check if alternative SAN MAC is supported */
3407*4882a593Smuzhiyun offset = IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
3408*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, offset, &alt_san_mac_blk_offset))
3409*4882a593Smuzhiyun goto wwn_prefix_err;
3410*4882a593Smuzhiyun
3411*4882a593Smuzhiyun if ((alt_san_mac_blk_offset == 0) ||
3412*4882a593Smuzhiyun (alt_san_mac_blk_offset == 0xFFFF))
3413*4882a593Smuzhiyun return 0;
3414*4882a593Smuzhiyun
3415*4882a593Smuzhiyun /* check capability in alternative san mac address block */
3416*4882a593Smuzhiyun offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
3417*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, offset, &caps))
3418*4882a593Smuzhiyun goto wwn_prefix_err;
3419*4882a593Smuzhiyun if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
3420*4882a593Smuzhiyun return 0;
3421*4882a593Smuzhiyun
3422*4882a593Smuzhiyun /* get the corresponding prefix for WWNN/WWPN */
3423*4882a593Smuzhiyun offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
3424*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, offset, wwnn_prefix))
3425*4882a593Smuzhiyun hw_err(hw, "eeprom read at offset %d failed\n", offset);
3426*4882a593Smuzhiyun
3427*4882a593Smuzhiyun offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
3428*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, offset, wwpn_prefix))
3429*4882a593Smuzhiyun goto wwn_prefix_err;
3430*4882a593Smuzhiyun
3431*4882a593Smuzhiyun return 0;
3432*4882a593Smuzhiyun
3433*4882a593Smuzhiyun wwn_prefix_err:
3434*4882a593Smuzhiyun hw_err(hw, "eeprom read at offset %d failed\n", offset);
3435*4882a593Smuzhiyun return 0;
3436*4882a593Smuzhiyun }
3437*4882a593Smuzhiyun
3438*4882a593Smuzhiyun /**
3439*4882a593Smuzhiyun * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
3440*4882a593Smuzhiyun * @hw: pointer to hardware structure
3441*4882a593Smuzhiyun * @enable: enable or disable switch for MAC anti-spoofing
3442*4882a593Smuzhiyun * @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
3443*4882a593Smuzhiyun *
3444*4882a593Smuzhiyun **/
ixgbe_set_mac_anti_spoofing(struct ixgbe_hw * hw,bool enable,int vf)3445*4882a593Smuzhiyun void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
3446*4882a593Smuzhiyun {
3447*4882a593Smuzhiyun int vf_target_reg = vf >> 3;
3448*4882a593Smuzhiyun int vf_target_shift = vf % 8;
3449*4882a593Smuzhiyun u32 pfvfspoof;
3450*4882a593Smuzhiyun
3451*4882a593Smuzhiyun if (hw->mac.type == ixgbe_mac_82598EB)
3452*4882a593Smuzhiyun return;
3453*4882a593Smuzhiyun
3454*4882a593Smuzhiyun pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
3455*4882a593Smuzhiyun if (enable)
3456*4882a593Smuzhiyun pfvfspoof |= BIT(vf_target_shift);
3457*4882a593Smuzhiyun else
3458*4882a593Smuzhiyun pfvfspoof &= ~BIT(vf_target_shift);
3459*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
3460*4882a593Smuzhiyun }
3461*4882a593Smuzhiyun
3462*4882a593Smuzhiyun /**
3463*4882a593Smuzhiyun * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
3464*4882a593Smuzhiyun * @hw: pointer to hardware structure
3465*4882a593Smuzhiyun * @enable: enable or disable switch for VLAN anti-spoofing
3466*4882a593Smuzhiyun * @vf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
3467*4882a593Smuzhiyun *
3468*4882a593Smuzhiyun **/
ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw * hw,bool enable,int vf)3469*4882a593Smuzhiyun void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
3470*4882a593Smuzhiyun {
3471*4882a593Smuzhiyun int vf_target_reg = vf >> 3;
3472*4882a593Smuzhiyun int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
3473*4882a593Smuzhiyun u32 pfvfspoof;
3474*4882a593Smuzhiyun
3475*4882a593Smuzhiyun if (hw->mac.type == ixgbe_mac_82598EB)
3476*4882a593Smuzhiyun return;
3477*4882a593Smuzhiyun
3478*4882a593Smuzhiyun pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
3479*4882a593Smuzhiyun if (enable)
3480*4882a593Smuzhiyun pfvfspoof |= BIT(vf_target_shift);
3481*4882a593Smuzhiyun else
3482*4882a593Smuzhiyun pfvfspoof &= ~BIT(vf_target_shift);
3483*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
3484*4882a593Smuzhiyun }
3485*4882a593Smuzhiyun
3486*4882a593Smuzhiyun /**
3487*4882a593Smuzhiyun * ixgbe_get_device_caps_generic - Get additional device capabilities
3488*4882a593Smuzhiyun * @hw: pointer to hardware structure
3489*4882a593Smuzhiyun * @device_caps: the EEPROM word with the extra device capabilities
3490*4882a593Smuzhiyun *
3491*4882a593Smuzhiyun * This function will read the EEPROM location for the device capabilities,
3492*4882a593Smuzhiyun * and return the word through device_caps.
3493*4882a593Smuzhiyun **/
ixgbe_get_device_caps_generic(struct ixgbe_hw * hw,u16 * device_caps)3494*4882a593Smuzhiyun s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
3495*4882a593Smuzhiyun {
3496*4882a593Smuzhiyun hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
3497*4882a593Smuzhiyun
3498*4882a593Smuzhiyun return 0;
3499*4882a593Smuzhiyun }
3500*4882a593Smuzhiyun
3501*4882a593Smuzhiyun /**
3502*4882a593Smuzhiyun * ixgbe_set_rxpba_generic - Initialize RX packet buffer
3503*4882a593Smuzhiyun * @hw: pointer to hardware structure
3504*4882a593Smuzhiyun * @num_pb: number of packet buffers to allocate
3505*4882a593Smuzhiyun * @headroom: reserve n KB of headroom
3506*4882a593Smuzhiyun * @strategy: packet buffer allocation strategy
3507*4882a593Smuzhiyun **/
ixgbe_set_rxpba_generic(struct ixgbe_hw * hw,int num_pb,u32 headroom,int strategy)3508*4882a593Smuzhiyun void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw,
3509*4882a593Smuzhiyun int num_pb,
3510*4882a593Smuzhiyun u32 headroom,
3511*4882a593Smuzhiyun int strategy)
3512*4882a593Smuzhiyun {
3513*4882a593Smuzhiyun u32 pbsize = hw->mac.rx_pb_size;
3514*4882a593Smuzhiyun int i = 0;
3515*4882a593Smuzhiyun u32 rxpktsize, txpktsize, txpbthresh;
3516*4882a593Smuzhiyun
3517*4882a593Smuzhiyun /* Reserve headroom */
3518*4882a593Smuzhiyun pbsize -= headroom;
3519*4882a593Smuzhiyun
3520*4882a593Smuzhiyun if (!num_pb)
3521*4882a593Smuzhiyun num_pb = 1;
3522*4882a593Smuzhiyun
3523*4882a593Smuzhiyun /* Divide remaining packet buffer space amongst the number
3524*4882a593Smuzhiyun * of packet buffers requested using supplied strategy.
3525*4882a593Smuzhiyun */
3526*4882a593Smuzhiyun switch (strategy) {
3527*4882a593Smuzhiyun case (PBA_STRATEGY_WEIGHTED):
3528*4882a593Smuzhiyun /* pba_80_48 strategy weight first half of packet buffer with
3529*4882a593Smuzhiyun * 5/8 of the packet buffer space.
3530*4882a593Smuzhiyun */
3531*4882a593Smuzhiyun rxpktsize = ((pbsize * 5 * 2) / (num_pb * 8));
3532*4882a593Smuzhiyun pbsize -= rxpktsize * (num_pb / 2);
3533*4882a593Smuzhiyun rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
3534*4882a593Smuzhiyun for (; i < (num_pb / 2); i++)
3535*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
3536*4882a593Smuzhiyun fallthrough; /* configure remaining packet buffers */
3537*4882a593Smuzhiyun case (PBA_STRATEGY_EQUAL):
3538*4882a593Smuzhiyun /* Divide the remaining Rx packet buffer evenly among the TCs */
3539*4882a593Smuzhiyun rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
3540*4882a593Smuzhiyun for (; i < num_pb; i++)
3541*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
3542*4882a593Smuzhiyun break;
3543*4882a593Smuzhiyun default:
3544*4882a593Smuzhiyun break;
3545*4882a593Smuzhiyun }
3546*4882a593Smuzhiyun
3547*4882a593Smuzhiyun /*
3548*4882a593Smuzhiyun * Setup Tx packet buffer and threshold equally for all TCs
3549*4882a593Smuzhiyun * TXPBTHRESH register is set in K so divide by 1024 and subtract
3550*4882a593Smuzhiyun * 10 since the largest packet we support is just over 9K.
3551*4882a593Smuzhiyun */
3552*4882a593Smuzhiyun txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
3553*4882a593Smuzhiyun txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
3554*4882a593Smuzhiyun for (i = 0; i < num_pb; i++) {
3555*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
3556*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
3557*4882a593Smuzhiyun }
3558*4882a593Smuzhiyun
3559*4882a593Smuzhiyun /* Clear unused TCs, if any, to zero buffer size*/
3560*4882a593Smuzhiyun for (; i < IXGBE_MAX_PB; i++) {
3561*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
3562*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
3563*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
3564*4882a593Smuzhiyun }
3565*4882a593Smuzhiyun }
3566*4882a593Smuzhiyun
3567*4882a593Smuzhiyun /**
3568*4882a593Smuzhiyun * ixgbe_calculate_checksum - Calculate checksum for buffer
3569*4882a593Smuzhiyun * @buffer: pointer to EEPROM
3570*4882a593Smuzhiyun * @length: size of EEPROM to calculate a checksum for
3571*4882a593Smuzhiyun *
3572*4882a593Smuzhiyun * Calculates the checksum for some buffer on a specified length. The
3573*4882a593Smuzhiyun * checksum calculated is returned.
3574*4882a593Smuzhiyun **/
ixgbe_calculate_checksum(u8 * buffer,u32 length)3575*4882a593Smuzhiyun u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
3576*4882a593Smuzhiyun {
3577*4882a593Smuzhiyun u32 i;
3578*4882a593Smuzhiyun u8 sum = 0;
3579*4882a593Smuzhiyun
3580*4882a593Smuzhiyun if (!buffer)
3581*4882a593Smuzhiyun return 0;
3582*4882a593Smuzhiyun
3583*4882a593Smuzhiyun for (i = 0; i < length; i++)
3584*4882a593Smuzhiyun sum += buffer[i];
3585*4882a593Smuzhiyun
3586*4882a593Smuzhiyun return (u8) (0 - sum);
3587*4882a593Smuzhiyun }
3588*4882a593Smuzhiyun
3589*4882a593Smuzhiyun /**
3590*4882a593Smuzhiyun * ixgbe_hic_unlocked - Issue command to manageability block unlocked
3591*4882a593Smuzhiyun * @hw: pointer to the HW structure
3592*4882a593Smuzhiyun * @buffer: command to write and where the return status will be placed
3593*4882a593Smuzhiyun * @length: length of buffer, must be multiple of 4 bytes
3594*4882a593Smuzhiyun * @timeout: time in ms to wait for command completion
3595*4882a593Smuzhiyun *
3596*4882a593Smuzhiyun * Communicates with the manageability block. On success return 0
3597*4882a593Smuzhiyun * else returns semaphore error when encountering an error acquiring
3598*4882a593Smuzhiyun * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
3599*4882a593Smuzhiyun *
3600*4882a593Smuzhiyun * This function assumes that the IXGBE_GSSR_SW_MNG_SM semaphore is held
3601*4882a593Smuzhiyun * by the caller.
3602*4882a593Smuzhiyun **/
ixgbe_hic_unlocked(struct ixgbe_hw * hw,u32 * buffer,u32 length,u32 timeout)3603*4882a593Smuzhiyun s32 ixgbe_hic_unlocked(struct ixgbe_hw *hw, u32 *buffer, u32 length,
3604*4882a593Smuzhiyun u32 timeout)
3605*4882a593Smuzhiyun {
3606*4882a593Smuzhiyun u32 hicr, i, fwsts;
3607*4882a593Smuzhiyun u16 dword_len;
3608*4882a593Smuzhiyun
3609*4882a593Smuzhiyun if (!length || length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
3610*4882a593Smuzhiyun hw_dbg(hw, "Buffer length failure buffersize-%d.\n", length);
3611*4882a593Smuzhiyun return IXGBE_ERR_HOST_INTERFACE_COMMAND;
3612*4882a593Smuzhiyun }
3613*4882a593Smuzhiyun
3614*4882a593Smuzhiyun /* Set bit 9 of FWSTS clearing FW reset indication */
3615*4882a593Smuzhiyun fwsts = IXGBE_READ_REG(hw, IXGBE_FWSTS);
3616*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_FWSTS, fwsts | IXGBE_FWSTS_FWRI);
3617*4882a593Smuzhiyun
3618*4882a593Smuzhiyun /* Check that the host interface is enabled. */
3619*4882a593Smuzhiyun hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
3620*4882a593Smuzhiyun if (!(hicr & IXGBE_HICR_EN)) {
3621*4882a593Smuzhiyun hw_dbg(hw, "IXGBE_HOST_EN bit disabled.\n");
3622*4882a593Smuzhiyun return IXGBE_ERR_HOST_INTERFACE_COMMAND;
3623*4882a593Smuzhiyun }
3624*4882a593Smuzhiyun
3625*4882a593Smuzhiyun /* Calculate length in DWORDs. We must be DWORD aligned */
3626*4882a593Smuzhiyun if (length % sizeof(u32)) {
3627*4882a593Smuzhiyun hw_dbg(hw, "Buffer length failure, not aligned to dword");
3628*4882a593Smuzhiyun return IXGBE_ERR_INVALID_ARGUMENT;
3629*4882a593Smuzhiyun }
3630*4882a593Smuzhiyun
3631*4882a593Smuzhiyun dword_len = length >> 2;
3632*4882a593Smuzhiyun
3633*4882a593Smuzhiyun /* The device driver writes the relevant command block
3634*4882a593Smuzhiyun * into the ram area.
3635*4882a593Smuzhiyun */
3636*4882a593Smuzhiyun for (i = 0; i < dword_len; i++)
3637*4882a593Smuzhiyun IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
3638*4882a593Smuzhiyun i, (__force u32)cpu_to_le32(buffer[i]));
3639*4882a593Smuzhiyun
3640*4882a593Smuzhiyun /* Setting this bit tells the ARC that a new command is pending. */
3641*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
3642*4882a593Smuzhiyun
3643*4882a593Smuzhiyun for (i = 0; i < timeout; i++) {
3644*4882a593Smuzhiyun hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
3645*4882a593Smuzhiyun if (!(hicr & IXGBE_HICR_C))
3646*4882a593Smuzhiyun break;
3647*4882a593Smuzhiyun usleep_range(1000, 2000);
3648*4882a593Smuzhiyun }
3649*4882a593Smuzhiyun
3650*4882a593Smuzhiyun /* Check command successful completion. */
3651*4882a593Smuzhiyun if ((timeout && i == timeout) ||
3652*4882a593Smuzhiyun !(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV))
3653*4882a593Smuzhiyun return IXGBE_ERR_HOST_INTERFACE_COMMAND;
3654*4882a593Smuzhiyun
3655*4882a593Smuzhiyun return 0;
3656*4882a593Smuzhiyun }
3657*4882a593Smuzhiyun
3658*4882a593Smuzhiyun /**
3659*4882a593Smuzhiyun * ixgbe_host_interface_command - Issue command to manageability block
3660*4882a593Smuzhiyun * @hw: pointer to the HW structure
3661*4882a593Smuzhiyun * @buffer: contains the command to write and where the return status will
3662*4882a593Smuzhiyun * be placed
3663*4882a593Smuzhiyun * @length: length of buffer, must be multiple of 4 bytes
3664*4882a593Smuzhiyun * @timeout: time in ms to wait for command completion
3665*4882a593Smuzhiyun * @return_data: read and return data from the buffer (true) or not (false)
3666*4882a593Smuzhiyun * Needed because FW structures are big endian and decoding of
3667*4882a593Smuzhiyun * these fields can be 8 bit or 16 bit based on command. Decoding
3668*4882a593Smuzhiyun * is not easily understood without making a table of commands.
3669*4882a593Smuzhiyun * So we will leave this up to the caller to read back the data
3670*4882a593Smuzhiyun * in these cases.
3671*4882a593Smuzhiyun *
3672*4882a593Smuzhiyun * Communicates with the manageability block. On success return 0
3673*4882a593Smuzhiyun * else return IXGBE_ERR_HOST_INTERFACE_COMMAND.
3674*4882a593Smuzhiyun **/
ixgbe_host_interface_command(struct ixgbe_hw * hw,void * buffer,u32 length,u32 timeout,bool return_data)3675*4882a593Smuzhiyun s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, void *buffer,
3676*4882a593Smuzhiyun u32 length, u32 timeout,
3677*4882a593Smuzhiyun bool return_data)
3678*4882a593Smuzhiyun {
3679*4882a593Smuzhiyun u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
3680*4882a593Smuzhiyun union {
3681*4882a593Smuzhiyun struct ixgbe_hic_hdr hdr;
3682*4882a593Smuzhiyun u32 u32arr[1];
3683*4882a593Smuzhiyun } *bp = buffer;
3684*4882a593Smuzhiyun u16 buf_len, dword_len;
3685*4882a593Smuzhiyun s32 status;
3686*4882a593Smuzhiyun u32 bi;
3687*4882a593Smuzhiyun
3688*4882a593Smuzhiyun if (!length || length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
3689*4882a593Smuzhiyun hw_dbg(hw, "Buffer length failure buffersize-%d.\n", length);
3690*4882a593Smuzhiyun return IXGBE_ERR_HOST_INTERFACE_COMMAND;
3691*4882a593Smuzhiyun }
3692*4882a593Smuzhiyun /* Take management host interface semaphore */
3693*4882a593Smuzhiyun status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
3694*4882a593Smuzhiyun if (status)
3695*4882a593Smuzhiyun return status;
3696*4882a593Smuzhiyun
3697*4882a593Smuzhiyun status = ixgbe_hic_unlocked(hw, buffer, length, timeout);
3698*4882a593Smuzhiyun if (status)
3699*4882a593Smuzhiyun goto rel_out;
3700*4882a593Smuzhiyun
3701*4882a593Smuzhiyun if (!return_data)
3702*4882a593Smuzhiyun goto rel_out;
3703*4882a593Smuzhiyun
3704*4882a593Smuzhiyun /* Calculate length in DWORDs */
3705*4882a593Smuzhiyun dword_len = hdr_size >> 2;
3706*4882a593Smuzhiyun
3707*4882a593Smuzhiyun /* first pull in the header so we know the buffer length */
3708*4882a593Smuzhiyun for (bi = 0; bi < dword_len; bi++) {
3709*4882a593Smuzhiyun bp->u32arr[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
3710*4882a593Smuzhiyun le32_to_cpus(&bp->u32arr[bi]);
3711*4882a593Smuzhiyun }
3712*4882a593Smuzhiyun
3713*4882a593Smuzhiyun /* If there is any thing in data position pull it in */
3714*4882a593Smuzhiyun buf_len = bp->hdr.buf_len;
3715*4882a593Smuzhiyun if (!buf_len)
3716*4882a593Smuzhiyun goto rel_out;
3717*4882a593Smuzhiyun
3718*4882a593Smuzhiyun if (length < round_up(buf_len, 4) + hdr_size) {
3719*4882a593Smuzhiyun hw_dbg(hw, "Buffer not large enough for reply message.\n");
3720*4882a593Smuzhiyun status = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3721*4882a593Smuzhiyun goto rel_out;
3722*4882a593Smuzhiyun }
3723*4882a593Smuzhiyun
3724*4882a593Smuzhiyun /* Calculate length in DWORDs, add 3 for odd lengths */
3725*4882a593Smuzhiyun dword_len = (buf_len + 3) >> 2;
3726*4882a593Smuzhiyun
3727*4882a593Smuzhiyun /* Pull in the rest of the buffer (bi is where we left off) */
3728*4882a593Smuzhiyun for (; bi <= dword_len; bi++) {
3729*4882a593Smuzhiyun bp->u32arr[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
3730*4882a593Smuzhiyun le32_to_cpus(&bp->u32arr[bi]);
3731*4882a593Smuzhiyun }
3732*4882a593Smuzhiyun
3733*4882a593Smuzhiyun rel_out:
3734*4882a593Smuzhiyun hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
3735*4882a593Smuzhiyun
3736*4882a593Smuzhiyun return status;
3737*4882a593Smuzhiyun }
3738*4882a593Smuzhiyun
3739*4882a593Smuzhiyun /**
3740*4882a593Smuzhiyun * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
3741*4882a593Smuzhiyun * @hw: pointer to the HW structure
3742*4882a593Smuzhiyun * @maj: driver version major number
3743*4882a593Smuzhiyun * @min: driver version minor number
3744*4882a593Smuzhiyun * @build: driver version build number
3745*4882a593Smuzhiyun * @sub: driver version sub build number
3746*4882a593Smuzhiyun * @len: length of driver_ver string
3747*4882a593Smuzhiyun * @driver_ver: driver string
3748*4882a593Smuzhiyun *
3749*4882a593Smuzhiyun * Sends driver version number to firmware through the manageability
3750*4882a593Smuzhiyun * block. On success return 0
3751*4882a593Smuzhiyun * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
3752*4882a593Smuzhiyun * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
3753*4882a593Smuzhiyun **/
ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw * hw,u8 maj,u8 min,u8 build,u8 sub,__always_unused u16 len,__always_unused const char * driver_ver)3754*4882a593Smuzhiyun s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
3755*4882a593Smuzhiyun u8 build, u8 sub, __always_unused u16 len,
3756*4882a593Smuzhiyun __always_unused const char *driver_ver)
3757*4882a593Smuzhiyun {
3758*4882a593Smuzhiyun struct ixgbe_hic_drv_info fw_cmd;
3759*4882a593Smuzhiyun int i;
3760*4882a593Smuzhiyun s32 ret_val;
3761*4882a593Smuzhiyun
3762*4882a593Smuzhiyun fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
3763*4882a593Smuzhiyun fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
3764*4882a593Smuzhiyun fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
3765*4882a593Smuzhiyun fw_cmd.port_num = hw->bus.func;
3766*4882a593Smuzhiyun fw_cmd.ver_maj = maj;
3767*4882a593Smuzhiyun fw_cmd.ver_min = min;
3768*4882a593Smuzhiyun fw_cmd.ver_build = build;
3769*4882a593Smuzhiyun fw_cmd.ver_sub = sub;
3770*4882a593Smuzhiyun fw_cmd.hdr.checksum = 0;
3771*4882a593Smuzhiyun fw_cmd.pad = 0;
3772*4882a593Smuzhiyun fw_cmd.pad2 = 0;
3773*4882a593Smuzhiyun fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
3774*4882a593Smuzhiyun (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
3775*4882a593Smuzhiyun
3776*4882a593Smuzhiyun for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
3777*4882a593Smuzhiyun ret_val = ixgbe_host_interface_command(hw, &fw_cmd,
3778*4882a593Smuzhiyun sizeof(fw_cmd),
3779*4882a593Smuzhiyun IXGBE_HI_COMMAND_TIMEOUT,
3780*4882a593Smuzhiyun true);
3781*4882a593Smuzhiyun if (ret_val != 0)
3782*4882a593Smuzhiyun continue;
3783*4882a593Smuzhiyun
3784*4882a593Smuzhiyun if (fw_cmd.hdr.cmd_or_resp.ret_status ==
3785*4882a593Smuzhiyun FW_CEM_RESP_STATUS_SUCCESS)
3786*4882a593Smuzhiyun ret_val = 0;
3787*4882a593Smuzhiyun else
3788*4882a593Smuzhiyun ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
3789*4882a593Smuzhiyun
3790*4882a593Smuzhiyun break;
3791*4882a593Smuzhiyun }
3792*4882a593Smuzhiyun
3793*4882a593Smuzhiyun return ret_val;
3794*4882a593Smuzhiyun }
3795*4882a593Smuzhiyun
3796*4882a593Smuzhiyun /**
3797*4882a593Smuzhiyun * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
3798*4882a593Smuzhiyun * @hw: pointer to the hardware structure
3799*4882a593Smuzhiyun *
3800*4882a593Smuzhiyun * The 82599 and x540 MACs can experience issues if TX work is still pending
3801*4882a593Smuzhiyun * when a reset occurs. This function prevents this by flushing the PCIe
3802*4882a593Smuzhiyun * buffers on the system.
3803*4882a593Smuzhiyun **/
ixgbe_clear_tx_pending(struct ixgbe_hw * hw)3804*4882a593Smuzhiyun void ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
3805*4882a593Smuzhiyun {
3806*4882a593Smuzhiyun u32 gcr_ext, hlreg0, i, poll;
3807*4882a593Smuzhiyun u16 value;
3808*4882a593Smuzhiyun
3809*4882a593Smuzhiyun /*
3810*4882a593Smuzhiyun * If double reset is not requested then all transactions should
3811*4882a593Smuzhiyun * already be clear and as such there is no work to do
3812*4882a593Smuzhiyun */
3813*4882a593Smuzhiyun if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
3814*4882a593Smuzhiyun return;
3815*4882a593Smuzhiyun
3816*4882a593Smuzhiyun /*
3817*4882a593Smuzhiyun * Set loopback enable to prevent any transmits from being sent
3818*4882a593Smuzhiyun * should the link come up. This assumes that the RXCTRL.RXEN bit
3819*4882a593Smuzhiyun * has already been cleared.
3820*4882a593Smuzhiyun */
3821*4882a593Smuzhiyun hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
3822*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
3823*4882a593Smuzhiyun
3824*4882a593Smuzhiyun /* wait for a last completion before clearing buffers */
3825*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
3826*4882a593Smuzhiyun usleep_range(3000, 6000);
3827*4882a593Smuzhiyun
3828*4882a593Smuzhiyun /* Before proceeding, make sure that the PCIe block does not have
3829*4882a593Smuzhiyun * transactions pending.
3830*4882a593Smuzhiyun */
3831*4882a593Smuzhiyun poll = ixgbe_pcie_timeout_poll(hw);
3832*4882a593Smuzhiyun for (i = 0; i < poll; i++) {
3833*4882a593Smuzhiyun usleep_range(100, 200);
3834*4882a593Smuzhiyun value = ixgbe_read_pci_cfg_word(hw, IXGBE_PCI_DEVICE_STATUS);
3835*4882a593Smuzhiyun if (ixgbe_removed(hw->hw_addr))
3836*4882a593Smuzhiyun break;
3837*4882a593Smuzhiyun if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
3838*4882a593Smuzhiyun break;
3839*4882a593Smuzhiyun }
3840*4882a593Smuzhiyun
3841*4882a593Smuzhiyun /* initiate cleaning flow for buffers in the PCIe transaction layer */
3842*4882a593Smuzhiyun gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3843*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
3844*4882a593Smuzhiyun gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
3845*4882a593Smuzhiyun
3846*4882a593Smuzhiyun /* Flush all writes and allow 20usec for all transactions to clear */
3847*4882a593Smuzhiyun IXGBE_WRITE_FLUSH(hw);
3848*4882a593Smuzhiyun udelay(20);
3849*4882a593Smuzhiyun
3850*4882a593Smuzhiyun /* restore previous register values */
3851*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3852*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3853*4882a593Smuzhiyun }
3854*4882a593Smuzhiyun
3855*4882a593Smuzhiyun static const u8 ixgbe_emc_temp_data[4] = {
3856*4882a593Smuzhiyun IXGBE_EMC_INTERNAL_DATA,
3857*4882a593Smuzhiyun IXGBE_EMC_DIODE1_DATA,
3858*4882a593Smuzhiyun IXGBE_EMC_DIODE2_DATA,
3859*4882a593Smuzhiyun IXGBE_EMC_DIODE3_DATA
3860*4882a593Smuzhiyun };
3861*4882a593Smuzhiyun static const u8 ixgbe_emc_therm_limit[4] = {
3862*4882a593Smuzhiyun IXGBE_EMC_INTERNAL_THERM_LIMIT,
3863*4882a593Smuzhiyun IXGBE_EMC_DIODE1_THERM_LIMIT,
3864*4882a593Smuzhiyun IXGBE_EMC_DIODE2_THERM_LIMIT,
3865*4882a593Smuzhiyun IXGBE_EMC_DIODE3_THERM_LIMIT
3866*4882a593Smuzhiyun };
3867*4882a593Smuzhiyun
3868*4882a593Smuzhiyun /**
3869*4882a593Smuzhiyun * ixgbe_get_ets_data - Extracts the ETS bit data
3870*4882a593Smuzhiyun * @hw: pointer to hardware structure
3871*4882a593Smuzhiyun * @ets_cfg: extected ETS data
3872*4882a593Smuzhiyun * @ets_offset: offset of ETS data
3873*4882a593Smuzhiyun *
3874*4882a593Smuzhiyun * Returns error code.
3875*4882a593Smuzhiyun **/
ixgbe_get_ets_data(struct ixgbe_hw * hw,u16 * ets_cfg,u16 * ets_offset)3876*4882a593Smuzhiyun static s32 ixgbe_get_ets_data(struct ixgbe_hw *hw, u16 *ets_cfg,
3877*4882a593Smuzhiyun u16 *ets_offset)
3878*4882a593Smuzhiyun {
3879*4882a593Smuzhiyun s32 status;
3880*4882a593Smuzhiyun
3881*4882a593Smuzhiyun status = hw->eeprom.ops.read(hw, IXGBE_ETS_CFG, ets_offset);
3882*4882a593Smuzhiyun if (status)
3883*4882a593Smuzhiyun return status;
3884*4882a593Smuzhiyun
3885*4882a593Smuzhiyun if ((*ets_offset == 0x0000) || (*ets_offset == 0xFFFF))
3886*4882a593Smuzhiyun return IXGBE_NOT_IMPLEMENTED;
3887*4882a593Smuzhiyun
3888*4882a593Smuzhiyun status = hw->eeprom.ops.read(hw, *ets_offset, ets_cfg);
3889*4882a593Smuzhiyun if (status)
3890*4882a593Smuzhiyun return status;
3891*4882a593Smuzhiyun
3892*4882a593Smuzhiyun if ((*ets_cfg & IXGBE_ETS_TYPE_MASK) != IXGBE_ETS_TYPE_EMC_SHIFTED)
3893*4882a593Smuzhiyun return IXGBE_NOT_IMPLEMENTED;
3894*4882a593Smuzhiyun
3895*4882a593Smuzhiyun return 0;
3896*4882a593Smuzhiyun }
3897*4882a593Smuzhiyun
3898*4882a593Smuzhiyun /**
3899*4882a593Smuzhiyun * ixgbe_get_thermal_sensor_data - Gathers thermal sensor data
3900*4882a593Smuzhiyun * @hw: pointer to hardware structure
3901*4882a593Smuzhiyun *
3902*4882a593Smuzhiyun * Returns the thermal sensor data structure
3903*4882a593Smuzhiyun **/
ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw * hw)3904*4882a593Smuzhiyun s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw)
3905*4882a593Smuzhiyun {
3906*4882a593Smuzhiyun s32 status;
3907*4882a593Smuzhiyun u16 ets_offset;
3908*4882a593Smuzhiyun u16 ets_cfg;
3909*4882a593Smuzhiyun u16 ets_sensor;
3910*4882a593Smuzhiyun u8 num_sensors;
3911*4882a593Smuzhiyun u8 i;
3912*4882a593Smuzhiyun struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
3913*4882a593Smuzhiyun
3914*4882a593Smuzhiyun /* Only support thermal sensors attached to physical port 0 */
3915*4882a593Smuzhiyun if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1))
3916*4882a593Smuzhiyun return IXGBE_NOT_IMPLEMENTED;
3917*4882a593Smuzhiyun
3918*4882a593Smuzhiyun status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
3919*4882a593Smuzhiyun if (status)
3920*4882a593Smuzhiyun return status;
3921*4882a593Smuzhiyun
3922*4882a593Smuzhiyun num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
3923*4882a593Smuzhiyun if (num_sensors > IXGBE_MAX_SENSORS)
3924*4882a593Smuzhiyun num_sensors = IXGBE_MAX_SENSORS;
3925*4882a593Smuzhiyun
3926*4882a593Smuzhiyun for (i = 0; i < num_sensors; i++) {
3927*4882a593Smuzhiyun u8 sensor_index;
3928*4882a593Smuzhiyun u8 sensor_location;
3929*4882a593Smuzhiyun
3930*4882a593Smuzhiyun status = hw->eeprom.ops.read(hw, (ets_offset + 1 + i),
3931*4882a593Smuzhiyun &ets_sensor);
3932*4882a593Smuzhiyun if (status)
3933*4882a593Smuzhiyun return status;
3934*4882a593Smuzhiyun
3935*4882a593Smuzhiyun sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
3936*4882a593Smuzhiyun IXGBE_ETS_DATA_INDEX_SHIFT);
3937*4882a593Smuzhiyun sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
3938*4882a593Smuzhiyun IXGBE_ETS_DATA_LOC_SHIFT);
3939*4882a593Smuzhiyun
3940*4882a593Smuzhiyun if (sensor_location != 0) {
3941*4882a593Smuzhiyun status = hw->phy.ops.read_i2c_byte(hw,
3942*4882a593Smuzhiyun ixgbe_emc_temp_data[sensor_index],
3943*4882a593Smuzhiyun IXGBE_I2C_THERMAL_SENSOR_ADDR,
3944*4882a593Smuzhiyun &data->sensor[i].temp);
3945*4882a593Smuzhiyun if (status)
3946*4882a593Smuzhiyun return status;
3947*4882a593Smuzhiyun }
3948*4882a593Smuzhiyun }
3949*4882a593Smuzhiyun
3950*4882a593Smuzhiyun return 0;
3951*4882a593Smuzhiyun }
3952*4882a593Smuzhiyun
3953*4882a593Smuzhiyun /**
3954*4882a593Smuzhiyun * ixgbe_init_thermal_sensor_thresh_generic - Inits thermal sensor thresholds
3955*4882a593Smuzhiyun * @hw: pointer to hardware structure
3956*4882a593Smuzhiyun *
3957*4882a593Smuzhiyun * Inits the thermal sensor thresholds according to the NVM map
3958*4882a593Smuzhiyun * and save off the threshold and location values into mac.thermal_sensor_data
3959*4882a593Smuzhiyun **/
ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw * hw)3960*4882a593Smuzhiyun s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
3961*4882a593Smuzhiyun {
3962*4882a593Smuzhiyun s32 status;
3963*4882a593Smuzhiyun u16 ets_offset;
3964*4882a593Smuzhiyun u16 ets_cfg;
3965*4882a593Smuzhiyun u16 ets_sensor;
3966*4882a593Smuzhiyun u8 low_thresh_delta;
3967*4882a593Smuzhiyun u8 num_sensors;
3968*4882a593Smuzhiyun u8 therm_limit;
3969*4882a593Smuzhiyun u8 i;
3970*4882a593Smuzhiyun struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
3971*4882a593Smuzhiyun
3972*4882a593Smuzhiyun memset(data, 0, sizeof(struct ixgbe_thermal_sensor_data));
3973*4882a593Smuzhiyun
3974*4882a593Smuzhiyun /* Only support thermal sensors attached to physical port 0 */
3975*4882a593Smuzhiyun if ((IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1))
3976*4882a593Smuzhiyun return IXGBE_NOT_IMPLEMENTED;
3977*4882a593Smuzhiyun
3978*4882a593Smuzhiyun status = ixgbe_get_ets_data(hw, &ets_cfg, &ets_offset);
3979*4882a593Smuzhiyun if (status)
3980*4882a593Smuzhiyun return status;
3981*4882a593Smuzhiyun
3982*4882a593Smuzhiyun low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >>
3983*4882a593Smuzhiyun IXGBE_ETS_LTHRES_DELTA_SHIFT);
3984*4882a593Smuzhiyun num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
3985*4882a593Smuzhiyun if (num_sensors > IXGBE_MAX_SENSORS)
3986*4882a593Smuzhiyun num_sensors = IXGBE_MAX_SENSORS;
3987*4882a593Smuzhiyun
3988*4882a593Smuzhiyun for (i = 0; i < num_sensors; i++) {
3989*4882a593Smuzhiyun u8 sensor_index;
3990*4882a593Smuzhiyun u8 sensor_location;
3991*4882a593Smuzhiyun
3992*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, ets_offset + 1 + i, &ets_sensor)) {
3993*4882a593Smuzhiyun hw_err(hw, "eeprom read at offset %d failed\n",
3994*4882a593Smuzhiyun ets_offset + 1 + i);
3995*4882a593Smuzhiyun continue;
3996*4882a593Smuzhiyun }
3997*4882a593Smuzhiyun sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
3998*4882a593Smuzhiyun IXGBE_ETS_DATA_INDEX_SHIFT);
3999*4882a593Smuzhiyun sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
4000*4882a593Smuzhiyun IXGBE_ETS_DATA_LOC_SHIFT);
4001*4882a593Smuzhiyun therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK;
4002*4882a593Smuzhiyun
4003*4882a593Smuzhiyun hw->phy.ops.write_i2c_byte(hw,
4004*4882a593Smuzhiyun ixgbe_emc_therm_limit[sensor_index],
4005*4882a593Smuzhiyun IXGBE_I2C_THERMAL_SENSOR_ADDR, therm_limit);
4006*4882a593Smuzhiyun
4007*4882a593Smuzhiyun if (sensor_location == 0)
4008*4882a593Smuzhiyun continue;
4009*4882a593Smuzhiyun
4010*4882a593Smuzhiyun data->sensor[i].location = sensor_location;
4011*4882a593Smuzhiyun data->sensor[i].caution_thresh = therm_limit;
4012*4882a593Smuzhiyun data->sensor[i].max_op_thresh = therm_limit - low_thresh_delta;
4013*4882a593Smuzhiyun }
4014*4882a593Smuzhiyun
4015*4882a593Smuzhiyun return 0;
4016*4882a593Smuzhiyun }
4017*4882a593Smuzhiyun
4018*4882a593Smuzhiyun /**
4019*4882a593Smuzhiyun * ixgbe_get_orom_version - Return option ROM from EEPROM
4020*4882a593Smuzhiyun *
4021*4882a593Smuzhiyun * @hw: pointer to hardware structure
4022*4882a593Smuzhiyun * @nvm_ver: pointer to output structure
4023*4882a593Smuzhiyun *
4024*4882a593Smuzhiyun * if valid option ROM version, nvm_ver->or_valid set to true
4025*4882a593Smuzhiyun * else nvm_ver->or_valid is false.
4026*4882a593Smuzhiyun **/
ixgbe_get_orom_version(struct ixgbe_hw * hw,struct ixgbe_nvm_version * nvm_ver)4027*4882a593Smuzhiyun void ixgbe_get_orom_version(struct ixgbe_hw *hw,
4028*4882a593Smuzhiyun struct ixgbe_nvm_version *nvm_ver)
4029*4882a593Smuzhiyun {
4030*4882a593Smuzhiyun u16 offset, eeprom_cfg_blkh, eeprom_cfg_blkl;
4031*4882a593Smuzhiyun
4032*4882a593Smuzhiyun nvm_ver->or_valid = false;
4033*4882a593Smuzhiyun /* Option Rom may or may not be present. Start with pointer */
4034*4882a593Smuzhiyun hw->eeprom.ops.read(hw, NVM_OROM_OFFSET, &offset);
4035*4882a593Smuzhiyun
4036*4882a593Smuzhiyun /* make sure offset is valid */
4037*4882a593Smuzhiyun if (offset == 0x0 || offset == NVM_INVALID_PTR)
4038*4882a593Smuzhiyun return;
4039*4882a593Smuzhiyun
4040*4882a593Smuzhiyun hw->eeprom.ops.read(hw, offset + NVM_OROM_BLK_HI, &eeprom_cfg_blkh);
4041*4882a593Smuzhiyun hw->eeprom.ops.read(hw, offset + NVM_OROM_BLK_LOW, &eeprom_cfg_blkl);
4042*4882a593Smuzhiyun
4043*4882a593Smuzhiyun /* option rom exists and is valid */
4044*4882a593Smuzhiyun if ((eeprom_cfg_blkl | eeprom_cfg_blkh) == 0x0 ||
4045*4882a593Smuzhiyun eeprom_cfg_blkl == NVM_VER_INVALID ||
4046*4882a593Smuzhiyun eeprom_cfg_blkh == NVM_VER_INVALID)
4047*4882a593Smuzhiyun return;
4048*4882a593Smuzhiyun
4049*4882a593Smuzhiyun nvm_ver->or_valid = true;
4050*4882a593Smuzhiyun nvm_ver->or_major = eeprom_cfg_blkl >> NVM_OROM_SHIFT;
4051*4882a593Smuzhiyun nvm_ver->or_build = (eeprom_cfg_blkl << NVM_OROM_SHIFT) |
4052*4882a593Smuzhiyun (eeprom_cfg_blkh >> NVM_OROM_SHIFT);
4053*4882a593Smuzhiyun nvm_ver->or_patch = eeprom_cfg_blkh & NVM_OROM_PATCH_MASK;
4054*4882a593Smuzhiyun }
4055*4882a593Smuzhiyun
4056*4882a593Smuzhiyun /**
4057*4882a593Smuzhiyun * ixgbe_get_oem_prod_version Etrack ID from EEPROM
4058*4882a593Smuzhiyun *
4059*4882a593Smuzhiyun * @hw: pointer to hardware structure
4060*4882a593Smuzhiyun * @nvm_ver: pointer to output structure
4061*4882a593Smuzhiyun *
4062*4882a593Smuzhiyun * if valid OEM product version, nvm_ver->oem_valid set to true
4063*4882a593Smuzhiyun * else nvm_ver->oem_valid is false.
4064*4882a593Smuzhiyun **/
ixgbe_get_oem_prod_version(struct ixgbe_hw * hw,struct ixgbe_nvm_version * nvm_ver)4065*4882a593Smuzhiyun void ixgbe_get_oem_prod_version(struct ixgbe_hw *hw,
4066*4882a593Smuzhiyun struct ixgbe_nvm_version *nvm_ver)
4067*4882a593Smuzhiyun {
4068*4882a593Smuzhiyun u16 rel_num, prod_ver, mod_len, cap, offset;
4069*4882a593Smuzhiyun
4070*4882a593Smuzhiyun nvm_ver->oem_valid = false;
4071*4882a593Smuzhiyun hw->eeprom.ops.read(hw, NVM_OEM_PROD_VER_PTR, &offset);
4072*4882a593Smuzhiyun
4073*4882a593Smuzhiyun /* Return is offset to OEM Product Version block is invalid */
4074*4882a593Smuzhiyun if (offset == 0x0 || offset == NVM_INVALID_PTR)
4075*4882a593Smuzhiyun return;
4076*4882a593Smuzhiyun
4077*4882a593Smuzhiyun /* Read product version block */
4078*4882a593Smuzhiyun hw->eeprom.ops.read(hw, offset, &mod_len);
4079*4882a593Smuzhiyun hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_CAP_OFF, &cap);
4080*4882a593Smuzhiyun
4081*4882a593Smuzhiyun /* Return if OEM product version block is invalid */
4082*4882a593Smuzhiyun if (mod_len != NVM_OEM_PROD_VER_MOD_LEN ||
4083*4882a593Smuzhiyun (cap & NVM_OEM_PROD_VER_CAP_MASK) != 0x0)
4084*4882a593Smuzhiyun return;
4085*4882a593Smuzhiyun
4086*4882a593Smuzhiyun hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_OFF_L, &prod_ver);
4087*4882a593Smuzhiyun hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_OFF_H, &rel_num);
4088*4882a593Smuzhiyun
4089*4882a593Smuzhiyun /* Return if version is invalid */
4090*4882a593Smuzhiyun if ((rel_num | prod_ver) == 0x0 ||
4091*4882a593Smuzhiyun rel_num == NVM_VER_INVALID || prod_ver == NVM_VER_INVALID)
4092*4882a593Smuzhiyun return;
4093*4882a593Smuzhiyun
4094*4882a593Smuzhiyun nvm_ver->oem_major = prod_ver >> NVM_VER_SHIFT;
4095*4882a593Smuzhiyun nvm_ver->oem_minor = prod_ver & NVM_VER_MASK;
4096*4882a593Smuzhiyun nvm_ver->oem_release = rel_num;
4097*4882a593Smuzhiyun nvm_ver->oem_valid = true;
4098*4882a593Smuzhiyun }
4099*4882a593Smuzhiyun
4100*4882a593Smuzhiyun /**
4101*4882a593Smuzhiyun * ixgbe_get_etk_id - Return Etrack ID from EEPROM
4102*4882a593Smuzhiyun *
4103*4882a593Smuzhiyun * @hw: pointer to hardware structure
4104*4882a593Smuzhiyun * @nvm_ver: pointer to output structure
4105*4882a593Smuzhiyun *
4106*4882a593Smuzhiyun * word read errors will return 0xFFFF
4107*4882a593Smuzhiyun **/
ixgbe_get_etk_id(struct ixgbe_hw * hw,struct ixgbe_nvm_version * nvm_ver)4108*4882a593Smuzhiyun void ixgbe_get_etk_id(struct ixgbe_hw *hw,
4109*4882a593Smuzhiyun struct ixgbe_nvm_version *nvm_ver)
4110*4882a593Smuzhiyun {
4111*4882a593Smuzhiyun u16 etk_id_l, etk_id_h;
4112*4882a593Smuzhiyun
4113*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, NVM_ETK_OFF_LOW, &etk_id_l))
4114*4882a593Smuzhiyun etk_id_l = NVM_VER_INVALID;
4115*4882a593Smuzhiyun if (hw->eeprom.ops.read(hw, NVM_ETK_OFF_HI, &etk_id_h))
4116*4882a593Smuzhiyun etk_id_h = NVM_VER_INVALID;
4117*4882a593Smuzhiyun
4118*4882a593Smuzhiyun /* The word order for the version format is determined by high order
4119*4882a593Smuzhiyun * word bit 15.
4120*4882a593Smuzhiyun */
4121*4882a593Smuzhiyun if ((etk_id_h & NVM_ETK_VALID) == 0) {
4122*4882a593Smuzhiyun nvm_ver->etk_id = etk_id_h;
4123*4882a593Smuzhiyun nvm_ver->etk_id |= (etk_id_l << NVM_ETK_SHIFT);
4124*4882a593Smuzhiyun } else {
4125*4882a593Smuzhiyun nvm_ver->etk_id = etk_id_l;
4126*4882a593Smuzhiyun nvm_ver->etk_id |= (etk_id_h << NVM_ETK_SHIFT);
4127*4882a593Smuzhiyun }
4128*4882a593Smuzhiyun }
4129*4882a593Smuzhiyun
ixgbe_disable_rx_generic(struct ixgbe_hw * hw)4130*4882a593Smuzhiyun void ixgbe_disable_rx_generic(struct ixgbe_hw *hw)
4131*4882a593Smuzhiyun {
4132*4882a593Smuzhiyun u32 rxctrl;
4133*4882a593Smuzhiyun
4134*4882a593Smuzhiyun rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4135*4882a593Smuzhiyun if (rxctrl & IXGBE_RXCTRL_RXEN) {
4136*4882a593Smuzhiyun if (hw->mac.type != ixgbe_mac_82598EB) {
4137*4882a593Smuzhiyun u32 pfdtxgswc;
4138*4882a593Smuzhiyun
4139*4882a593Smuzhiyun pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
4140*4882a593Smuzhiyun if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
4141*4882a593Smuzhiyun pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
4142*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
4143*4882a593Smuzhiyun hw->mac.set_lben = true;
4144*4882a593Smuzhiyun } else {
4145*4882a593Smuzhiyun hw->mac.set_lben = false;
4146*4882a593Smuzhiyun }
4147*4882a593Smuzhiyun }
4148*4882a593Smuzhiyun rxctrl &= ~IXGBE_RXCTRL_RXEN;
4149*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
4150*4882a593Smuzhiyun }
4151*4882a593Smuzhiyun }
4152*4882a593Smuzhiyun
ixgbe_enable_rx_generic(struct ixgbe_hw * hw)4153*4882a593Smuzhiyun void ixgbe_enable_rx_generic(struct ixgbe_hw *hw)
4154*4882a593Smuzhiyun {
4155*4882a593Smuzhiyun u32 rxctrl;
4156*4882a593Smuzhiyun
4157*4882a593Smuzhiyun rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4158*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, (rxctrl | IXGBE_RXCTRL_RXEN));
4159*4882a593Smuzhiyun
4160*4882a593Smuzhiyun if (hw->mac.type != ixgbe_mac_82598EB) {
4161*4882a593Smuzhiyun if (hw->mac.set_lben) {
4162*4882a593Smuzhiyun u32 pfdtxgswc;
4163*4882a593Smuzhiyun
4164*4882a593Smuzhiyun pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
4165*4882a593Smuzhiyun pfdtxgswc |= IXGBE_PFDTXGSWC_VT_LBEN;
4166*4882a593Smuzhiyun IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
4167*4882a593Smuzhiyun hw->mac.set_lben = false;
4168*4882a593Smuzhiyun }
4169*4882a593Smuzhiyun }
4170*4882a593Smuzhiyun }
4171*4882a593Smuzhiyun
4172*4882a593Smuzhiyun /** ixgbe_mng_present - returns true when management capability is present
4173*4882a593Smuzhiyun * @hw: pointer to hardware structure
4174*4882a593Smuzhiyun **/
ixgbe_mng_present(struct ixgbe_hw * hw)4175*4882a593Smuzhiyun bool ixgbe_mng_present(struct ixgbe_hw *hw)
4176*4882a593Smuzhiyun {
4177*4882a593Smuzhiyun u32 fwsm;
4178*4882a593Smuzhiyun
4179*4882a593Smuzhiyun if (hw->mac.type < ixgbe_mac_82599EB)
4180*4882a593Smuzhiyun return false;
4181*4882a593Smuzhiyun
4182*4882a593Smuzhiyun fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM(hw));
4183*4882a593Smuzhiyun
4184*4882a593Smuzhiyun return !!(fwsm & IXGBE_FWSM_FW_MODE_PT);
4185*4882a593Smuzhiyun }
4186*4882a593Smuzhiyun
4187*4882a593Smuzhiyun /**
4188*4882a593Smuzhiyun * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
4189*4882a593Smuzhiyun * @hw: pointer to hardware structure
4190*4882a593Smuzhiyun * @speed: new link speed
4191*4882a593Smuzhiyun * @autoneg_wait_to_complete: true when waiting for completion is needed
4192*4882a593Smuzhiyun *
4193*4882a593Smuzhiyun * Set the link speed in the MAC and/or PHY register and restarts link.
4194*4882a593Smuzhiyun */
ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw * hw,ixgbe_link_speed speed,bool autoneg_wait_to_complete)4195*4882a593Smuzhiyun s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
4196*4882a593Smuzhiyun ixgbe_link_speed speed,
4197*4882a593Smuzhiyun bool autoneg_wait_to_complete)
4198*4882a593Smuzhiyun {
4199*4882a593Smuzhiyun ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
4200*4882a593Smuzhiyun ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
4201*4882a593Smuzhiyun s32 status = 0;
4202*4882a593Smuzhiyun u32 speedcnt = 0;
4203*4882a593Smuzhiyun u32 i = 0;
4204*4882a593Smuzhiyun bool autoneg, link_up = false;
4205*4882a593Smuzhiyun
4206*4882a593Smuzhiyun /* Mask off requested but non-supported speeds */
4207*4882a593Smuzhiyun status = hw->mac.ops.get_link_capabilities(hw, &link_speed, &autoneg);
4208*4882a593Smuzhiyun if (status)
4209*4882a593Smuzhiyun return status;
4210*4882a593Smuzhiyun
4211*4882a593Smuzhiyun speed &= link_speed;
4212*4882a593Smuzhiyun
4213*4882a593Smuzhiyun /* Try each speed one by one, highest priority first. We do this in
4214*4882a593Smuzhiyun * software because 10Gb fiber doesn't support speed autonegotiation.
4215*4882a593Smuzhiyun */
4216*4882a593Smuzhiyun if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
4217*4882a593Smuzhiyun speedcnt++;
4218*4882a593Smuzhiyun highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
4219*4882a593Smuzhiyun
4220*4882a593Smuzhiyun /* Set the module link speed */
4221*4882a593Smuzhiyun switch (hw->phy.media_type) {
4222*4882a593Smuzhiyun case ixgbe_media_type_fiber:
4223*4882a593Smuzhiyun hw->mac.ops.set_rate_select_speed(hw,
4224*4882a593Smuzhiyun IXGBE_LINK_SPEED_10GB_FULL);
4225*4882a593Smuzhiyun break;
4226*4882a593Smuzhiyun case ixgbe_media_type_fiber_qsfp:
4227*4882a593Smuzhiyun /* QSFP module automatically detects MAC link speed */
4228*4882a593Smuzhiyun break;
4229*4882a593Smuzhiyun default:
4230*4882a593Smuzhiyun hw_dbg(hw, "Unexpected media type\n");
4231*4882a593Smuzhiyun break;
4232*4882a593Smuzhiyun }
4233*4882a593Smuzhiyun
4234*4882a593Smuzhiyun /* Allow module to change analog characteristics (1G->10G) */
4235*4882a593Smuzhiyun msleep(40);
4236*4882a593Smuzhiyun
4237*4882a593Smuzhiyun status = hw->mac.ops.setup_mac_link(hw,
4238*4882a593Smuzhiyun IXGBE_LINK_SPEED_10GB_FULL,
4239*4882a593Smuzhiyun autoneg_wait_to_complete);
4240*4882a593Smuzhiyun if (status)
4241*4882a593Smuzhiyun return status;
4242*4882a593Smuzhiyun
4243*4882a593Smuzhiyun /* Flap the Tx laser if it has not already been done */
4244*4882a593Smuzhiyun if (hw->mac.ops.flap_tx_laser)
4245*4882a593Smuzhiyun hw->mac.ops.flap_tx_laser(hw);
4246*4882a593Smuzhiyun
4247*4882a593Smuzhiyun /* Wait for the controller to acquire link. Per IEEE 802.3ap,
4248*4882a593Smuzhiyun * Section 73.10.2, we may have to wait up to 500ms if KR is
4249*4882a593Smuzhiyun * attempted. 82599 uses the same timing for 10g SFI.
4250*4882a593Smuzhiyun */
4251*4882a593Smuzhiyun for (i = 0; i < 5; i++) {
4252*4882a593Smuzhiyun /* Wait for the link partner to also set speed */
4253*4882a593Smuzhiyun msleep(100);
4254*4882a593Smuzhiyun
4255*4882a593Smuzhiyun /* If we have link, just jump out */
4256*4882a593Smuzhiyun status = hw->mac.ops.check_link(hw, &link_speed,
4257*4882a593Smuzhiyun &link_up, false);
4258*4882a593Smuzhiyun if (status)
4259*4882a593Smuzhiyun return status;
4260*4882a593Smuzhiyun
4261*4882a593Smuzhiyun if (link_up)
4262*4882a593Smuzhiyun goto out;
4263*4882a593Smuzhiyun }
4264*4882a593Smuzhiyun }
4265*4882a593Smuzhiyun
4266*4882a593Smuzhiyun if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
4267*4882a593Smuzhiyun speedcnt++;
4268*4882a593Smuzhiyun if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
4269*4882a593Smuzhiyun highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
4270*4882a593Smuzhiyun
4271*4882a593Smuzhiyun /* Set the module link speed */
4272*4882a593Smuzhiyun switch (hw->phy.media_type) {
4273*4882a593Smuzhiyun case ixgbe_media_type_fiber:
4274*4882a593Smuzhiyun hw->mac.ops.set_rate_select_speed(hw,
4275*4882a593Smuzhiyun IXGBE_LINK_SPEED_1GB_FULL);
4276*4882a593Smuzhiyun break;
4277*4882a593Smuzhiyun case ixgbe_media_type_fiber_qsfp:
4278*4882a593Smuzhiyun /* QSFP module automatically detects link speed */
4279*4882a593Smuzhiyun break;
4280*4882a593Smuzhiyun default:
4281*4882a593Smuzhiyun hw_dbg(hw, "Unexpected media type\n");
4282*4882a593Smuzhiyun break;
4283*4882a593Smuzhiyun }
4284*4882a593Smuzhiyun
4285*4882a593Smuzhiyun /* Allow module to change analog characteristics (10G->1G) */
4286*4882a593Smuzhiyun msleep(40);
4287*4882a593Smuzhiyun
4288*4882a593Smuzhiyun status = hw->mac.ops.setup_mac_link(hw,
4289*4882a593Smuzhiyun IXGBE_LINK_SPEED_1GB_FULL,
4290*4882a593Smuzhiyun autoneg_wait_to_complete);
4291*4882a593Smuzhiyun if (status)
4292*4882a593Smuzhiyun return status;
4293*4882a593Smuzhiyun
4294*4882a593Smuzhiyun /* Flap the Tx laser if it has not already been done */
4295*4882a593Smuzhiyun if (hw->mac.ops.flap_tx_laser)
4296*4882a593Smuzhiyun hw->mac.ops.flap_tx_laser(hw);
4297*4882a593Smuzhiyun
4298*4882a593Smuzhiyun /* Wait for the link partner to also set speed */
4299*4882a593Smuzhiyun msleep(100);
4300*4882a593Smuzhiyun
4301*4882a593Smuzhiyun /* If we have link, just jump out */
4302*4882a593Smuzhiyun status = hw->mac.ops.check_link(hw, &link_speed, &link_up,
4303*4882a593Smuzhiyun false);
4304*4882a593Smuzhiyun if (status)
4305*4882a593Smuzhiyun return status;
4306*4882a593Smuzhiyun
4307*4882a593Smuzhiyun if (link_up)
4308*4882a593Smuzhiyun goto out;
4309*4882a593Smuzhiyun }
4310*4882a593Smuzhiyun
4311*4882a593Smuzhiyun /* We didn't get link. Configure back to the highest speed we tried,
4312*4882a593Smuzhiyun * (if there was more than one). We call ourselves back with just the
4313*4882a593Smuzhiyun * single highest speed that the user requested.
4314*4882a593Smuzhiyun */
4315*4882a593Smuzhiyun if (speedcnt > 1)
4316*4882a593Smuzhiyun status = ixgbe_setup_mac_link_multispeed_fiber(hw,
4317*4882a593Smuzhiyun highest_link_speed,
4318*4882a593Smuzhiyun autoneg_wait_to_complete);
4319*4882a593Smuzhiyun
4320*4882a593Smuzhiyun out:
4321*4882a593Smuzhiyun /* Set autoneg_advertised value based on input link speed */
4322*4882a593Smuzhiyun hw->phy.autoneg_advertised = 0;
4323*4882a593Smuzhiyun
4324*4882a593Smuzhiyun if (speed & IXGBE_LINK_SPEED_10GB_FULL)
4325*4882a593Smuzhiyun hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
4326*4882a593Smuzhiyun
4327*4882a593Smuzhiyun if (speed & IXGBE_LINK_SPEED_1GB_FULL)
4328*4882a593Smuzhiyun hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
4329*4882a593Smuzhiyun
4330*4882a593Smuzhiyun return status;
4331*4882a593Smuzhiyun }
4332*4882a593Smuzhiyun
4333*4882a593Smuzhiyun /**
4334*4882a593Smuzhiyun * ixgbe_set_soft_rate_select_speed - Set module link speed
4335*4882a593Smuzhiyun * @hw: pointer to hardware structure
4336*4882a593Smuzhiyun * @speed: link speed to set
4337*4882a593Smuzhiyun *
4338*4882a593Smuzhiyun * Set module link speed via the soft rate select.
4339*4882a593Smuzhiyun */
ixgbe_set_soft_rate_select_speed(struct ixgbe_hw * hw,ixgbe_link_speed speed)4340*4882a593Smuzhiyun void ixgbe_set_soft_rate_select_speed(struct ixgbe_hw *hw,
4341*4882a593Smuzhiyun ixgbe_link_speed speed)
4342*4882a593Smuzhiyun {
4343*4882a593Smuzhiyun s32 status;
4344*4882a593Smuzhiyun u8 rs, eeprom_data;
4345*4882a593Smuzhiyun
4346*4882a593Smuzhiyun switch (speed) {
4347*4882a593Smuzhiyun case IXGBE_LINK_SPEED_10GB_FULL:
4348*4882a593Smuzhiyun /* one bit mask same as setting on */
4349*4882a593Smuzhiyun rs = IXGBE_SFF_SOFT_RS_SELECT_10G;
4350*4882a593Smuzhiyun break;
4351*4882a593Smuzhiyun case IXGBE_LINK_SPEED_1GB_FULL:
4352*4882a593Smuzhiyun rs = IXGBE_SFF_SOFT_RS_SELECT_1G;
4353*4882a593Smuzhiyun break;
4354*4882a593Smuzhiyun default:
4355*4882a593Smuzhiyun hw_dbg(hw, "Invalid fixed module speed\n");
4356*4882a593Smuzhiyun return;
4357*4882a593Smuzhiyun }
4358*4882a593Smuzhiyun
4359*4882a593Smuzhiyun /* Set RS0 */
4360*4882a593Smuzhiyun status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
4361*4882a593Smuzhiyun IXGBE_I2C_EEPROM_DEV_ADDR2,
4362*4882a593Smuzhiyun &eeprom_data);
4363*4882a593Smuzhiyun if (status) {
4364*4882a593Smuzhiyun hw_dbg(hw, "Failed to read Rx Rate Select RS0\n");
4365*4882a593Smuzhiyun return;
4366*4882a593Smuzhiyun }
4367*4882a593Smuzhiyun
4368*4882a593Smuzhiyun eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) | rs;
4369*4882a593Smuzhiyun
4370*4882a593Smuzhiyun status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
4371*4882a593Smuzhiyun IXGBE_I2C_EEPROM_DEV_ADDR2,
4372*4882a593Smuzhiyun eeprom_data);
4373*4882a593Smuzhiyun if (status) {
4374*4882a593Smuzhiyun hw_dbg(hw, "Failed to write Rx Rate Select RS0\n");
4375*4882a593Smuzhiyun return;
4376*4882a593Smuzhiyun }
4377*4882a593Smuzhiyun
4378*4882a593Smuzhiyun /* Set RS1 */
4379*4882a593Smuzhiyun status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
4380*4882a593Smuzhiyun IXGBE_I2C_EEPROM_DEV_ADDR2,
4381*4882a593Smuzhiyun &eeprom_data);
4382*4882a593Smuzhiyun if (status) {
4383*4882a593Smuzhiyun hw_dbg(hw, "Failed to read Rx Rate Select RS1\n");
4384*4882a593Smuzhiyun return;
4385*4882a593Smuzhiyun }
4386*4882a593Smuzhiyun
4387*4882a593Smuzhiyun eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) | rs;
4388*4882a593Smuzhiyun
4389*4882a593Smuzhiyun status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
4390*4882a593Smuzhiyun IXGBE_I2C_EEPROM_DEV_ADDR2,
4391*4882a593Smuzhiyun eeprom_data);
4392*4882a593Smuzhiyun if (status) {
4393*4882a593Smuzhiyun hw_dbg(hw, "Failed to write Rx Rate Select RS1\n");
4394*4882a593Smuzhiyun return;
4395*4882a593Smuzhiyun }
4396*4882a593Smuzhiyun }
4397