1 /******************************************************************************
2 SPDX-License-Identifier: BSD-3-Clause
4 Copyright (c) 2001-2020, Intel Corporation
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in the
15 documentation and/or other materials provided with the distribution.
17 3. Neither the name of the Intel Corporation nor the names of its
18 contributors may be used to endorse or promote products derived from
19 this software without specific prior written permission.
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
33 ******************************************************************************/
36 #include "ixgbe_common.h"
37 #include "ixgbe_phy.h"
38 #include "ixgbe_dcb.h"
39 #include "ixgbe_dcb_82599.h"
40 #include "ixgbe_api.h"
42 static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw);
43 static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw);
44 static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw);
45 static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw);
46 static void ixgbe_standby_eeprom(struct ixgbe_hw *hw);
47 static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
49 static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count);
50 static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
51 static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec);
52 static void ixgbe_release_eeprom(struct ixgbe_hw *hw);
54 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr);
55 static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
57 static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
58 u16 words, u16 *data);
59 static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
60 u16 words, u16 *data);
61 static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
65 * ixgbe_init_ops_generic - Inits function ptrs
66 * @hw: pointer to the hardware structure
68 * Initialize the function pointers.
70 s32 ixgbe_init_ops_generic(struct ixgbe_hw *hw)
72 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
73 struct ixgbe_mac_info *mac = &hw->mac;
74 u32 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
76 DEBUGFUNC("ixgbe_init_ops_generic");
79 eeprom->ops.init_params = ixgbe_init_eeprom_params_generic;
80 /* If EEPROM is valid (bit 8 = 1), use EERD otherwise use bit bang */
81 if (eec & IXGBE_EEC_PRES) {
82 eeprom->ops.read = ixgbe_read_eerd_generic;
83 eeprom->ops.read_buffer = ixgbe_read_eerd_buffer_generic;
85 eeprom->ops.read = ixgbe_read_eeprom_bit_bang_generic;
86 eeprom->ops.read_buffer =
87 ixgbe_read_eeprom_buffer_bit_bang_generic;
89 eeprom->ops.write = ixgbe_write_eeprom_generic;
90 eeprom->ops.write_buffer = ixgbe_write_eeprom_buffer_bit_bang_generic;
91 eeprom->ops.validate_checksum =
92 ixgbe_validate_eeprom_checksum_generic;
93 eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_generic;
94 eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_generic;
97 mac->ops.init_hw = ixgbe_init_hw_generic;
98 mac->ops.reset_hw = NULL;
99 mac->ops.start_hw = ixgbe_start_hw_generic;
100 mac->ops.clear_hw_cntrs = ixgbe_clear_hw_cntrs_generic;
101 mac->ops.get_media_type = NULL;
102 mac->ops.get_supported_physical_layer = NULL;
103 mac->ops.enable_rx_dma = ixgbe_enable_rx_dma_generic;
104 mac->ops.get_mac_addr = ixgbe_get_mac_addr_generic;
105 mac->ops.stop_adapter = ixgbe_stop_adapter_generic;
106 mac->ops.get_bus_info = ixgbe_get_bus_info_generic;
107 mac->ops.set_lan_id = ixgbe_set_lan_id_multi_port_pcie;
108 mac->ops.acquire_swfw_sync = ixgbe_acquire_swfw_sync;
109 mac->ops.release_swfw_sync = ixgbe_release_swfw_sync;
110 mac->ops.prot_autoc_read = prot_autoc_read_generic;
111 mac->ops.prot_autoc_write = prot_autoc_write_generic;
114 mac->ops.led_on = ixgbe_led_on_generic;
115 mac->ops.led_off = ixgbe_led_off_generic;
116 mac->ops.blink_led_start = ixgbe_blink_led_start_generic;
117 mac->ops.blink_led_stop = ixgbe_blink_led_stop_generic;
118 mac->ops.init_led_link_act = ixgbe_init_led_link_act_generic;
120 /* RAR, Multicast, VLAN */
121 mac->ops.set_rar = ixgbe_set_rar_generic;
122 mac->ops.clear_rar = ixgbe_clear_rar_generic;
123 mac->ops.insert_mac_addr = NULL;
124 mac->ops.set_vmdq = NULL;
125 mac->ops.clear_vmdq = NULL;
126 mac->ops.init_rx_addrs = ixgbe_init_rx_addrs_generic;
127 mac->ops.update_uc_addr_list = ixgbe_update_uc_addr_list_generic;
128 mac->ops.update_mc_addr_list = ixgbe_update_mc_addr_list_generic;
129 mac->ops.enable_mc = ixgbe_enable_mc_generic;
130 mac->ops.disable_mc = ixgbe_disable_mc_generic;
131 mac->ops.clear_vfta = NULL;
132 mac->ops.set_vfta = NULL;
133 mac->ops.set_vlvf = NULL;
134 mac->ops.init_uta_tables = NULL;
135 mac->ops.enable_rx = ixgbe_enable_rx_generic;
136 mac->ops.disable_rx = ixgbe_disable_rx_generic;
139 mac->ops.fc_enable = ixgbe_fc_enable_generic;
140 mac->ops.setup_fc = ixgbe_setup_fc_generic;
141 mac->ops.fc_autoneg = ixgbe_fc_autoneg;
144 mac->ops.get_link_capabilities = NULL;
145 mac->ops.setup_link = NULL;
146 mac->ops.check_link = NULL;
147 mac->ops.dmac_config = NULL;
148 mac->ops.dmac_update_tcs = NULL;
149 mac->ops.dmac_config_tcs = NULL;
151 return IXGBE_SUCCESS;
155 * ixgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
157 * @hw: pointer to hardware structure
159 * This function returns true if the device supports flow control
160 * autonegotiation, and false if it does not.
163 bool ixgbe_device_supports_autoneg_fc(struct ixgbe_hw *hw)
165 bool supported = false;
166 ixgbe_link_speed speed;
169 DEBUGFUNC("ixgbe_device_supports_autoneg_fc");
171 switch (hw->phy.media_type) {
172 case ixgbe_media_type_fiber_fixed:
173 case ixgbe_media_type_fiber_qsfp:
174 case ixgbe_media_type_fiber:
175 /* flow control autoneg black list */
176 switch (hw->device_id) {
177 case IXGBE_DEV_ID_X550EM_A_SFP:
178 case IXGBE_DEV_ID_X550EM_A_SFP_N:
179 case IXGBE_DEV_ID_X550EM_A_QSFP:
180 case IXGBE_DEV_ID_X550EM_A_QSFP_N:
184 hw->mac.ops.check_link(hw, &speed, &link_up, false);
185 /* if link is down, assume supported */
187 supported = speed == IXGBE_LINK_SPEED_1GB_FULL ?
194 case ixgbe_media_type_backplane:
195 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_XFI)
200 case ixgbe_media_type_copper:
201 /* only some copper devices support flow control autoneg */
202 switch (hw->device_id) {
203 case IXGBE_DEV_ID_82599_T3_LOM:
204 case IXGBE_DEV_ID_X540T:
205 case IXGBE_DEV_ID_X540T1:
206 case IXGBE_DEV_ID_X540_BYPASS:
207 case IXGBE_DEV_ID_X550T:
208 case IXGBE_DEV_ID_X550T1:
209 case IXGBE_DEV_ID_X550EM_X_10G_T:
210 case IXGBE_DEV_ID_X550EM_A_10G_T:
211 case IXGBE_DEV_ID_X550EM_A_1G_T:
212 case IXGBE_DEV_ID_X550EM_A_1G_T_L:
223 ERROR_REPORT2(IXGBE_ERROR_UNSUPPORTED,
224 "Device %x does not support flow control autoneg",
231 * ixgbe_setup_fc_generic - Set up flow control
232 * @hw: pointer to hardware structure
234 * Called at init time to set up flow control.
236 s32 ixgbe_setup_fc_generic(struct ixgbe_hw *hw)
238 s32 ret_val = IXGBE_SUCCESS;
239 u32 reg = 0, reg_bp = 0;
243 DEBUGFUNC("ixgbe_setup_fc_generic");
245 /* Validate the requested mode */
246 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
247 ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
248 "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
249 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
254 * 10gig parts do not have a word in the EEPROM to determine the
255 * default flow control setting, so we explicitly set it to full.
257 if (hw->fc.requested_mode == ixgbe_fc_default)
258 hw->fc.requested_mode = ixgbe_fc_full;
261 * Set up the 1G and 10G flow control advertisement registers so the
262 * HW will be able to do fc autoneg once the cable is plugged in. If
263 * we link at 10G, the 1G advertisement is harmless and vice versa.
265 switch (hw->phy.media_type) {
266 case ixgbe_media_type_backplane:
267 /* some MAC's need RMW protection on AUTOC */
268 ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, ®_bp);
269 if (ret_val != IXGBE_SUCCESS)
272 /* only backplane uses autoc */
274 case ixgbe_media_type_fiber_fixed:
275 case ixgbe_media_type_fiber_qsfp:
276 case ixgbe_media_type_fiber:
277 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
280 case ixgbe_media_type_copper:
281 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
282 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®_cu);
289 * The possible values of fc.requested_mode are:
290 * 0: Flow control is completely disabled
291 * 1: Rx flow control is enabled (we can receive pause frames,
292 * but not send pause frames).
293 * 2: Tx flow control is enabled (we can send pause frames but
294 * we do not support receiving pause frames).
295 * 3: Both Rx and Tx flow control (symmetric) are enabled.
298 switch (hw->fc.requested_mode) {
300 /* Flow control completely disabled by software override. */
301 reg &= ~(IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE);
302 if (hw->phy.media_type == ixgbe_media_type_backplane)
303 reg_bp &= ~(IXGBE_AUTOC_SYM_PAUSE |
304 IXGBE_AUTOC_ASM_PAUSE);
305 else if (hw->phy.media_type == ixgbe_media_type_copper)
306 reg_cu &= ~(IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE);
308 case ixgbe_fc_tx_pause:
310 * Tx Flow control is enabled, and Rx Flow control is
311 * disabled by software override.
313 reg |= IXGBE_PCS1GANA_ASM_PAUSE;
314 reg &= ~IXGBE_PCS1GANA_SYM_PAUSE;
315 if (hw->phy.media_type == ixgbe_media_type_backplane) {
316 reg_bp |= IXGBE_AUTOC_ASM_PAUSE;
317 reg_bp &= ~IXGBE_AUTOC_SYM_PAUSE;
318 } else if (hw->phy.media_type == ixgbe_media_type_copper) {
319 reg_cu |= IXGBE_TAF_ASM_PAUSE;
320 reg_cu &= ~IXGBE_TAF_SYM_PAUSE;
323 case ixgbe_fc_rx_pause:
325 * Rx Flow control is enabled and Tx Flow control is
326 * disabled by software override. Since there really
327 * isn't a way to advertise that we are capable of RX
328 * Pause ONLY, we will advertise that we support both
329 * symmetric and asymmetric Rx PAUSE, as such we fall
330 * through to the fc_full statement. Later, we will
331 * disable the adapter's ability to send PAUSE frames.
334 /* Flow control (both Rx and Tx) is enabled by SW override. */
335 reg |= IXGBE_PCS1GANA_SYM_PAUSE | IXGBE_PCS1GANA_ASM_PAUSE;
336 if (hw->phy.media_type == ixgbe_media_type_backplane)
337 reg_bp |= IXGBE_AUTOC_SYM_PAUSE |
338 IXGBE_AUTOC_ASM_PAUSE;
339 else if (hw->phy.media_type == ixgbe_media_type_copper)
340 reg_cu |= IXGBE_TAF_SYM_PAUSE | IXGBE_TAF_ASM_PAUSE;
343 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
344 "Flow control param set incorrectly\n");
345 ret_val = IXGBE_ERR_CONFIG;
350 if (hw->mac.type < ixgbe_mac_X540) {
352 * Enable auto-negotiation between the MAC & PHY;
353 * the MAC will advertise clause 37 flow control.
355 IXGBE_WRITE_REG(hw, IXGBE_PCS1GANA, reg);
356 reg = IXGBE_READ_REG(hw, IXGBE_PCS1GLCTL);
358 /* Disable AN timeout */
359 if (hw->fc.strict_ieee)
360 reg &= ~IXGBE_PCS1GLCTL_AN_1G_TIMEOUT_EN;
362 IXGBE_WRITE_REG(hw, IXGBE_PCS1GLCTL, reg);
363 DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg);
367 * AUTOC restart handles negotiation of 1G and 10G on backplane
368 * and copper. There is no need to set the PCS1GCTL register.
371 if (hw->phy.media_type == ixgbe_media_type_backplane) {
372 reg_bp |= IXGBE_AUTOC_AN_RESTART;
373 ret_val = hw->mac.ops.prot_autoc_write(hw, reg_bp, locked);
376 } else if ((hw->phy.media_type == ixgbe_media_type_copper) &&
377 (ixgbe_device_supports_autoneg_fc(hw))) {
378 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
379 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg_cu);
382 DEBUGOUT1("Set up FC; PCS1GLCTL = 0x%08X\n", reg);
388 * ixgbe_start_hw_generic - Prepare hardware for Tx/Rx
389 * @hw: pointer to hardware structure
391 * Starts the hardware by filling the bus info structure and media type, clears
392 * all on chip counters, initializes receive address registers, multicast
393 * table, VLAN filter table, calls routine to set up link and flow control
394 * settings, and leaves transmit and receive units disabled and uninitialized
396 s32 ixgbe_start_hw_generic(struct ixgbe_hw *hw)
402 DEBUGFUNC("ixgbe_start_hw_generic");
404 /* Set the media type */
405 hw->phy.media_type = hw->mac.ops.get_media_type(hw);
407 /* PHY ops initialization must be done in reset_hw() */
409 /* Clear the VLAN filter table */
410 hw->mac.ops.clear_vfta(hw);
412 /* Clear statistics registers */
413 hw->mac.ops.clear_hw_cntrs(hw);
415 /* Set No Snoop Disable */
416 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
417 ctrl_ext |= IXGBE_CTRL_EXT_NS_DIS;
418 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
419 IXGBE_WRITE_FLUSH(hw);
421 /* Setup flow control */
422 ret_val = ixgbe_setup_fc(hw);
423 if (ret_val != IXGBE_SUCCESS && ret_val != IXGBE_NOT_IMPLEMENTED) {
424 DEBUGOUT1("Flow control setup failed, returning %d\n", ret_val);
428 /* Cache bit indicating need for crosstalk fix */
429 switch (hw->mac.type) {
430 case ixgbe_mac_82599EB:
431 case ixgbe_mac_X550EM_x:
432 case ixgbe_mac_X550EM_a:
433 hw->mac.ops.get_device_caps(hw, &device_caps);
434 if (device_caps & IXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
435 hw->need_crosstalk_fix = false;
437 hw->need_crosstalk_fix = true;
440 hw->need_crosstalk_fix = false;
444 /* Clear adapter stopped flag */
445 hw->adapter_stopped = false;
447 return IXGBE_SUCCESS;
451 * ixgbe_start_hw_gen2 - Init sequence for common device family
452 * @hw: pointer to hw structure
454 * Performs the init sequence common to the second generation
456 * Devices in the second generation:
460 void ixgbe_start_hw_gen2(struct ixgbe_hw *hw)
465 /* Clear the rate limiters */
466 for (i = 0; i < hw->mac.max_tx_queues; i++) {
467 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
468 IXGBE_WRITE_REG(hw, IXGBE_RTTBCNRC, 0);
470 IXGBE_WRITE_FLUSH(hw);
472 /* Disable relaxed ordering */
473 for (i = 0; i < hw->mac.max_tx_queues; i++) {
474 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
475 regval &= ~IXGBE_DCA_TXCTRL_DESC_WRO_EN;
476 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
479 for (i = 0; i < hw->mac.max_rx_queues; i++) {
480 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
481 regval &= ~(IXGBE_DCA_RXCTRL_DATA_WRO_EN |
482 IXGBE_DCA_RXCTRL_HEAD_WRO_EN);
483 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
488 * ixgbe_init_hw_generic - Generic hardware initialization
489 * @hw: pointer to hardware structure
491 * Initialize the hardware by resetting the hardware, filling the bus info
492 * structure and media type, clears all on chip counters, initializes receive
493 * address registers, multicast table, VLAN filter table, calls routine to set
494 * up link and flow control settings, and leaves transmit and receive units
495 * disabled and uninitialized
497 s32 ixgbe_init_hw_generic(struct ixgbe_hw *hw)
501 DEBUGFUNC("ixgbe_init_hw_generic");
503 /* Reset the hardware */
504 status = hw->mac.ops.reset_hw(hw);
506 if (status == IXGBE_SUCCESS || status == IXGBE_ERR_SFP_NOT_PRESENT) {
508 status = hw->mac.ops.start_hw(hw);
511 /* Initialize the LED link active for LED blink support */
512 if (hw->mac.ops.init_led_link_act)
513 hw->mac.ops.init_led_link_act(hw);
515 if (status != IXGBE_SUCCESS)
516 DEBUGOUT1("Failed to initialize HW, STATUS = %d\n", status);
522 * ixgbe_clear_hw_cntrs_generic - Generic clear hardware counters
523 * @hw: pointer to hardware structure
525 * Clears all hardware statistics counters by reading them from the hardware
526 * Statistics counters are clear on read.
528 s32 ixgbe_clear_hw_cntrs_generic(struct ixgbe_hw *hw)
532 DEBUGFUNC("ixgbe_clear_hw_cntrs_generic");
534 IXGBE_READ_REG(hw, IXGBE_CRCERRS);
535 IXGBE_READ_REG(hw, IXGBE_ILLERRC);
536 IXGBE_READ_REG(hw, IXGBE_ERRBC);
537 IXGBE_READ_REG(hw, IXGBE_MSPDC);
538 for (i = 0; i < 8; i++)
539 IXGBE_READ_REG(hw, IXGBE_MPC(i));
541 IXGBE_READ_REG(hw, IXGBE_MLFC);
542 IXGBE_READ_REG(hw, IXGBE_MRFC);
543 IXGBE_READ_REG(hw, IXGBE_RLEC);
544 IXGBE_READ_REG(hw, IXGBE_LXONTXC);
545 IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
546 if (hw->mac.type >= ixgbe_mac_82599EB) {
547 IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
548 IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
550 IXGBE_READ_REG(hw, IXGBE_LXONRXC);
551 IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
554 for (i = 0; i < 8; i++) {
555 IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
556 IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
557 if (hw->mac.type >= ixgbe_mac_82599EB) {
558 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
559 IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
561 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
562 IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
565 if (hw->mac.type >= ixgbe_mac_82599EB)
566 for (i = 0; i < 8; i++)
567 IXGBE_READ_REG(hw, IXGBE_PXON2OFFCNT(i));
568 IXGBE_READ_REG(hw, IXGBE_PRC64);
569 IXGBE_READ_REG(hw, IXGBE_PRC127);
570 IXGBE_READ_REG(hw, IXGBE_PRC255);
571 IXGBE_READ_REG(hw, IXGBE_PRC511);
572 IXGBE_READ_REG(hw, IXGBE_PRC1023);
573 IXGBE_READ_REG(hw, IXGBE_PRC1522);
574 IXGBE_READ_REG(hw, IXGBE_GPRC);
575 IXGBE_READ_REG(hw, IXGBE_BPRC);
576 IXGBE_READ_REG(hw, IXGBE_MPRC);
577 IXGBE_READ_REG(hw, IXGBE_GPTC);
578 IXGBE_READ_REG(hw, IXGBE_GORCL);
579 IXGBE_READ_REG(hw, IXGBE_GORCH);
580 IXGBE_READ_REG(hw, IXGBE_GOTCL);
581 IXGBE_READ_REG(hw, IXGBE_GOTCH);
582 if (hw->mac.type == ixgbe_mac_82598EB)
583 for (i = 0; i < 8; i++)
584 IXGBE_READ_REG(hw, IXGBE_RNBC(i));
585 IXGBE_READ_REG(hw, IXGBE_RUC);
586 IXGBE_READ_REG(hw, IXGBE_RFC);
587 IXGBE_READ_REG(hw, IXGBE_ROC);
588 IXGBE_READ_REG(hw, IXGBE_RJC);
589 IXGBE_READ_REG(hw, IXGBE_MNGPRC);
590 IXGBE_READ_REG(hw, IXGBE_MNGPDC);
591 IXGBE_READ_REG(hw, IXGBE_MNGPTC);
592 IXGBE_READ_REG(hw, IXGBE_TORL);
593 IXGBE_READ_REG(hw, IXGBE_TORH);
594 IXGBE_READ_REG(hw, IXGBE_TPR);
595 IXGBE_READ_REG(hw, IXGBE_TPT);
596 IXGBE_READ_REG(hw, IXGBE_PTC64);
597 IXGBE_READ_REG(hw, IXGBE_PTC127);
598 IXGBE_READ_REG(hw, IXGBE_PTC255);
599 IXGBE_READ_REG(hw, IXGBE_PTC511);
600 IXGBE_READ_REG(hw, IXGBE_PTC1023);
601 IXGBE_READ_REG(hw, IXGBE_PTC1522);
602 IXGBE_READ_REG(hw, IXGBE_MPTC);
603 IXGBE_READ_REG(hw, IXGBE_BPTC);
604 for (i = 0; i < 16; i++) {
605 IXGBE_READ_REG(hw, IXGBE_QPRC(i));
606 IXGBE_READ_REG(hw, IXGBE_QPTC(i));
607 if (hw->mac.type >= ixgbe_mac_82599EB) {
608 IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
609 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i));
610 IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
611 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i));
612 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
614 IXGBE_READ_REG(hw, IXGBE_QBRC(i));
615 IXGBE_READ_REG(hw, IXGBE_QBTC(i));
619 if (hw->mac.type == ixgbe_mac_X550 || hw->mac.type == ixgbe_mac_X540) {
621 ixgbe_identify_phy(hw);
622 hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECL,
623 IXGBE_MDIO_PCS_DEV_TYPE, &i);
624 hw->phy.ops.read_reg(hw, IXGBE_PCRC8ECH,
625 IXGBE_MDIO_PCS_DEV_TYPE, &i);
626 hw->phy.ops.read_reg(hw, IXGBE_LDPCECL,
627 IXGBE_MDIO_PCS_DEV_TYPE, &i);
628 hw->phy.ops.read_reg(hw, IXGBE_LDPCECH,
629 IXGBE_MDIO_PCS_DEV_TYPE, &i);
632 return IXGBE_SUCCESS;
636 * ixgbe_read_pba_string_generic - Reads part number string from EEPROM
637 * @hw: pointer to hardware structure
638 * @pba_num: stores the part number string from the EEPROM
639 * @pba_num_size: part number string buffer length
641 * Reads the part number string from the EEPROM.
643 s32 ixgbe_read_pba_string_generic(struct ixgbe_hw *hw, u8 *pba_num,
652 DEBUGFUNC("ixgbe_read_pba_string_generic");
654 if (pba_num == NULL) {
655 DEBUGOUT("PBA string buffer was null\n");
656 return IXGBE_ERR_INVALID_ARGUMENT;
659 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
661 DEBUGOUT("NVM Read Error\n");
665 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &pba_ptr);
667 DEBUGOUT("NVM Read Error\n");
672 * if data is not ptr guard the PBA must be in legacy format which
673 * means pba_ptr is actually our second data word for the PBA number
674 * and we can decode it into an ascii string
676 if (data != IXGBE_PBANUM_PTR_GUARD) {
677 DEBUGOUT("NVM PBA number is not stored as string\n");
679 /* we will need 11 characters to store the PBA */
680 if (pba_num_size < 11) {
681 DEBUGOUT("PBA string buffer too small\n");
682 return IXGBE_ERR_NO_SPACE;
685 /* extract hex string from data and pba_ptr */
686 pba_num[0] = (data >> 12) & 0xF;
687 pba_num[1] = (data >> 8) & 0xF;
688 pba_num[2] = (data >> 4) & 0xF;
689 pba_num[3] = data & 0xF;
690 pba_num[4] = (pba_ptr >> 12) & 0xF;
691 pba_num[5] = (pba_ptr >> 8) & 0xF;
694 pba_num[8] = (pba_ptr >> 4) & 0xF;
695 pba_num[9] = pba_ptr & 0xF;
697 /* put a null character on the end of our string */
700 /* switch all the data but the '-' to hex char */
701 for (offset = 0; offset < 10; offset++) {
702 if (pba_num[offset] < 0xA)
703 pba_num[offset] += '0';
704 else if (pba_num[offset] < 0x10)
705 pba_num[offset] += 'A' - 0xA;
708 return IXGBE_SUCCESS;
711 ret_val = hw->eeprom.ops.read(hw, pba_ptr, &length);
713 DEBUGOUT("NVM Read Error\n");
717 if (length == 0xFFFF || length == 0) {
718 DEBUGOUT("NVM PBA number section invalid length\n");
719 return IXGBE_ERR_PBA_SECTION;
722 /* check if pba_num buffer is big enough */
723 if (pba_num_size < (((u32)length * 2) - 1)) {
724 DEBUGOUT("PBA string buffer too small\n");
725 return IXGBE_ERR_NO_SPACE;
728 /* trim pba length from start of string */
732 for (offset = 0; offset < length; offset++) {
733 ret_val = hw->eeprom.ops.read(hw, pba_ptr + offset, &data);
735 DEBUGOUT("NVM Read Error\n");
738 pba_num[offset * 2] = (u8)(data >> 8);
739 pba_num[(offset * 2) + 1] = (u8)(data & 0xFF);
741 pba_num[offset * 2] = '\0';
743 return IXGBE_SUCCESS;
747 * ixgbe_read_pba_num_generic - Reads part number from EEPROM
748 * @hw: pointer to hardware structure
749 * @pba_num: stores the part number from the EEPROM
751 * Reads the part number from the EEPROM.
753 s32 ixgbe_read_pba_num_generic(struct ixgbe_hw *hw, u32 *pba_num)
758 DEBUGFUNC("ixgbe_read_pba_num_generic");
760 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM0_PTR, &data);
762 DEBUGOUT("NVM Read Error\n");
764 } else if (data == IXGBE_PBANUM_PTR_GUARD) {
765 DEBUGOUT("NVM Not supported\n");
766 return IXGBE_NOT_IMPLEMENTED;
768 *pba_num = (u32)(data << 16);
770 ret_val = hw->eeprom.ops.read(hw, IXGBE_PBANUM1_PTR, &data);
772 DEBUGOUT("NVM Read Error\n");
775 *pba_num |= (u32)data;
777 return IXGBE_SUCCESS;
782 * @hw: pointer to the HW structure
783 * @eeprom_buf: optional pointer to EEPROM image
784 * @eeprom_buf_size: size of EEPROM image in words
785 * @max_pba_block_size: PBA block size limit
786 * @pba: pointer to output PBA structure
788 * Reads PBA from EEPROM image when eeprom_buf is not NULL.
789 * Reads PBA from physical EEPROM device when eeprom_buf is NULL.
792 s32 ixgbe_read_pba_raw(struct ixgbe_hw *hw, u16 *eeprom_buf,
793 u32 eeprom_buf_size, u16 max_pba_block_size,
794 struct ixgbe_pba *pba)
800 return IXGBE_ERR_PARAM;
802 if (eeprom_buf == NULL) {
803 ret_val = hw->eeprom.ops.read_buffer(hw, IXGBE_PBANUM0_PTR, 2,
808 if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
809 pba->word[0] = eeprom_buf[IXGBE_PBANUM0_PTR];
810 pba->word[1] = eeprom_buf[IXGBE_PBANUM1_PTR];
812 return IXGBE_ERR_PARAM;
816 if (pba->word[0] == IXGBE_PBANUM_PTR_GUARD) {
817 if (pba->pba_block == NULL)
818 return IXGBE_ERR_PARAM;
820 ret_val = ixgbe_get_pba_block_size(hw, eeprom_buf,
826 if (pba_block_size > max_pba_block_size)
827 return IXGBE_ERR_PARAM;
829 if (eeprom_buf == NULL) {
830 ret_val = hw->eeprom.ops.read_buffer(hw, pba->word[1],
836 if (eeprom_buf_size > (u32)(pba->word[1] +
838 memcpy(pba->pba_block,
839 &eeprom_buf[pba->word[1]],
840 pba_block_size * sizeof(u16));
842 return IXGBE_ERR_PARAM;
847 return IXGBE_SUCCESS;
851 * ixgbe_write_pba_raw
852 * @hw: pointer to the HW structure
853 * @eeprom_buf: optional pointer to EEPROM image
854 * @eeprom_buf_size: size of EEPROM image in words
855 * @pba: pointer to PBA structure
857 * Writes PBA to EEPROM image when eeprom_buf is not NULL.
858 * Writes PBA to physical EEPROM device when eeprom_buf is NULL.
861 s32 ixgbe_write_pba_raw(struct ixgbe_hw *hw, u16 *eeprom_buf,
862 u32 eeprom_buf_size, struct ixgbe_pba *pba)
867 return IXGBE_ERR_PARAM;
869 if (eeprom_buf == NULL) {
870 ret_val = hw->eeprom.ops.write_buffer(hw, IXGBE_PBANUM0_PTR, 2,
875 if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
876 eeprom_buf[IXGBE_PBANUM0_PTR] = pba->word[0];
877 eeprom_buf[IXGBE_PBANUM1_PTR] = pba->word[1];
879 return IXGBE_ERR_PARAM;
883 if (pba->word[0] == IXGBE_PBANUM_PTR_GUARD) {
884 if (pba->pba_block == NULL)
885 return IXGBE_ERR_PARAM;
887 if (eeprom_buf == NULL) {
888 ret_val = hw->eeprom.ops.write_buffer(hw, pba->word[1],
894 if (eeprom_buf_size > (u32)(pba->word[1] +
895 pba->pba_block[0])) {
896 memcpy(&eeprom_buf[pba->word[1]],
898 pba->pba_block[0] * sizeof(u16));
900 return IXGBE_ERR_PARAM;
905 return IXGBE_SUCCESS;
909 * ixgbe_get_pba_block_size
910 * @hw: pointer to the HW structure
911 * @eeprom_buf: optional pointer to EEPROM image
912 * @eeprom_buf_size: size of EEPROM image in words
913 * @pba_data_size: pointer to output variable
915 * Returns the size of the PBA block in words. Function operates on EEPROM
916 * image if the eeprom_buf pointer is not NULL otherwise it accesses physical
920 s32 ixgbe_get_pba_block_size(struct ixgbe_hw *hw, u16 *eeprom_buf,
921 u32 eeprom_buf_size, u16 *pba_block_size)
927 DEBUGFUNC("ixgbe_get_pba_block_size");
929 if (eeprom_buf == NULL) {
930 ret_val = hw->eeprom.ops.read_buffer(hw, IXGBE_PBANUM0_PTR, 2,
935 if (eeprom_buf_size > IXGBE_PBANUM1_PTR) {
936 pba_word[0] = eeprom_buf[IXGBE_PBANUM0_PTR];
937 pba_word[1] = eeprom_buf[IXGBE_PBANUM1_PTR];
939 return IXGBE_ERR_PARAM;
943 if (pba_word[0] == IXGBE_PBANUM_PTR_GUARD) {
944 if (eeprom_buf == NULL) {
945 ret_val = hw->eeprom.ops.read(hw, pba_word[1] + 0,
950 if (eeprom_buf_size > pba_word[1])
951 length = eeprom_buf[pba_word[1] + 0];
953 return IXGBE_ERR_PARAM;
956 if (length == 0xFFFF || length == 0)
957 return IXGBE_ERR_PBA_SECTION;
959 /* PBA number in legacy format, there is no PBA Block. */
963 if (pba_block_size != NULL)
964 *pba_block_size = length;
966 return IXGBE_SUCCESS;
970 * ixgbe_get_mac_addr_generic - Generic get MAC address
971 * @hw: pointer to hardware structure
972 * @mac_addr: Adapter MAC address
974 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
975 * A reset of the adapter must be performed prior to calling this function
976 * in order for the MAC address to have been loaded from the EEPROM into RAR0
978 s32 ixgbe_get_mac_addr_generic(struct ixgbe_hw *hw, u8 *mac_addr)
984 DEBUGFUNC("ixgbe_get_mac_addr_generic");
986 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(0));
987 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(0));
989 for (i = 0; i < 4; i++)
990 mac_addr[i] = (u8)(rar_low >> (i*8));
992 for (i = 0; i < 2; i++)
993 mac_addr[i+4] = (u8)(rar_high >> (i*8));
995 return IXGBE_SUCCESS;
999 * ixgbe_set_pci_config_data_generic - Generic store PCI bus info
1000 * @hw: pointer to hardware structure
1001 * @link_status: the link status returned by the PCI config space
1003 * Stores the PCI bus info (speed, width, type) within the ixgbe_hw structure
1005 void ixgbe_set_pci_config_data_generic(struct ixgbe_hw *hw, u16 link_status)
1007 struct ixgbe_mac_info *mac = &hw->mac;
1009 if (hw->bus.type == ixgbe_bus_type_unknown)
1010 hw->bus.type = ixgbe_bus_type_pci_express;
1012 switch (link_status & IXGBE_PCI_LINK_WIDTH) {
1013 case IXGBE_PCI_LINK_WIDTH_1:
1014 hw->bus.width = ixgbe_bus_width_pcie_x1;
1016 case IXGBE_PCI_LINK_WIDTH_2:
1017 hw->bus.width = ixgbe_bus_width_pcie_x2;
1019 case IXGBE_PCI_LINK_WIDTH_4:
1020 hw->bus.width = ixgbe_bus_width_pcie_x4;
1022 case IXGBE_PCI_LINK_WIDTH_8:
1023 hw->bus.width = ixgbe_bus_width_pcie_x8;
1026 hw->bus.width = ixgbe_bus_width_unknown;
1030 switch (link_status & IXGBE_PCI_LINK_SPEED) {
1031 case IXGBE_PCI_LINK_SPEED_2500:
1032 hw->bus.speed = ixgbe_bus_speed_2500;
1034 case IXGBE_PCI_LINK_SPEED_5000:
1035 hw->bus.speed = ixgbe_bus_speed_5000;
1037 case IXGBE_PCI_LINK_SPEED_8000:
1038 hw->bus.speed = ixgbe_bus_speed_8000;
1041 hw->bus.speed = ixgbe_bus_speed_unknown;
1045 mac->ops.set_lan_id(hw);
1049 * ixgbe_get_bus_info_generic - Generic set PCI bus info
1050 * @hw: pointer to hardware structure
1052 * Gets the PCI bus info (speed, width, type) then calls helper function to
1053 * store this data within the ixgbe_hw structure.
1055 s32 ixgbe_get_bus_info_generic(struct ixgbe_hw *hw)
1059 DEBUGFUNC("ixgbe_get_bus_info_generic");
1061 /* Get the negotiated link width and speed from PCI config space */
1062 link_status = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_LINK_STATUS);
1064 ixgbe_set_pci_config_data_generic(hw, link_status);
1066 return IXGBE_SUCCESS;
1070 * ixgbe_set_lan_id_multi_port_pcie - Set LAN id for PCIe multiple port devices
1071 * @hw: pointer to the HW structure
1073 * Determines the LAN function id by reading memory-mapped registers and swaps
1074 * the port value if requested, and set MAC instance for devices that share
1077 void ixgbe_set_lan_id_multi_port_pcie(struct ixgbe_hw *hw)
1079 struct ixgbe_bus_info *bus = &hw->bus;
1083 DEBUGFUNC("ixgbe_set_lan_id_multi_port_pcie");
1085 reg = IXGBE_READ_REG(hw, IXGBE_STATUS);
1086 bus->func = (reg & IXGBE_STATUS_LAN_ID) >> IXGBE_STATUS_LAN_ID_SHIFT;
1087 bus->lan_id = (u8)bus->func;
1089 /* check for a port swap */
1090 reg = IXGBE_READ_REG(hw, IXGBE_FACTPS_BY_MAC(hw));
1091 if (reg & IXGBE_FACTPS_LFS)
1094 /* Get MAC instance from EEPROM for configuring CS4227 */
1095 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SFP) {
1096 hw->eeprom.ops.read(hw, IXGBE_EEPROM_CTRL_4, &ee_ctrl_4);
1097 bus->instance_id = (ee_ctrl_4 & IXGBE_EE_CTRL_4_INST_ID) >>
1098 IXGBE_EE_CTRL_4_INST_ID_SHIFT;
1103 * ixgbe_stop_adapter_generic - Generic stop Tx/Rx units
1104 * @hw: pointer to hardware structure
1106 * Sets the adapter_stopped flag within ixgbe_hw struct. Clears interrupts,
1107 * disables transmit and receive units. The adapter_stopped flag is used by
1108 * the shared code and drivers to determine if the adapter is in a stopped
1109 * state and should not touch the hardware.
1111 s32 ixgbe_stop_adapter_generic(struct ixgbe_hw *hw)
1116 DEBUGFUNC("ixgbe_stop_adapter_generic");
1119 * Set the adapter_stopped flag so other driver functions stop touching
1122 hw->adapter_stopped = true;
1124 /* Disable the receive unit */
1125 ixgbe_disable_rx(hw);
1127 /* Clear interrupt mask to stop interrupts from being generated */
1128 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
1130 /* Clear any pending interrupts, flush previous writes */
1131 IXGBE_READ_REG(hw, IXGBE_EICR);
1133 /* Disable the transmit unit. Each queue must be disabled. */
1134 for (i = 0; i < hw->mac.max_tx_queues; i++)
1135 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(i), IXGBE_TXDCTL_SWFLSH);
1137 /* Disable the receive unit by stopping each queue */
1138 for (i = 0; i < hw->mac.max_rx_queues; i++) {
1139 reg_val = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
1140 reg_val &= ~IXGBE_RXDCTL_ENABLE;
1141 reg_val |= IXGBE_RXDCTL_SWFLSH;
1142 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(i), reg_val);
1145 /* flush all queues disables */
1146 IXGBE_WRITE_FLUSH(hw);
1150 * Prevent the PCI-E bus from hanging by disabling PCI-E master
1151 * access and verify no pending requests
1153 return ixgbe_disable_pcie_master(hw);
1157 * ixgbe_init_led_link_act_generic - Store the LED index link/activity.
1158 * @hw: pointer to hardware structure
1160 * Store the index for the link active LED. This will be used to support
1163 s32 ixgbe_init_led_link_act_generic(struct ixgbe_hw *hw)
1165 struct ixgbe_mac_info *mac = &hw->mac;
1166 u32 led_reg, led_mode;
1169 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1171 /* Get LED link active from the LEDCTL register */
1172 for (i = 0; i < 4; i++) {
1173 led_mode = led_reg >> IXGBE_LED_MODE_SHIFT(i);
1175 if ((led_mode & IXGBE_LED_MODE_MASK_BASE) ==
1176 IXGBE_LED_LINK_ACTIVE) {
1177 mac->led_link_act = i;
1178 return IXGBE_SUCCESS;
1183 * If LEDCTL register does not have the LED link active set, then use
1184 * known MAC defaults.
1186 switch (hw->mac.type) {
1187 case ixgbe_mac_X550EM_a:
1188 case ixgbe_mac_X550EM_x:
1189 mac->led_link_act = 1;
1192 mac->led_link_act = 2;
1194 return IXGBE_SUCCESS;
1198 * ixgbe_led_on_generic - Turns on the software controllable LEDs.
1199 * @hw: pointer to hardware structure
1200 * @index: led number to turn on
1202 s32 ixgbe_led_on_generic(struct ixgbe_hw *hw, u32 index)
1204 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1206 DEBUGFUNC("ixgbe_led_on_generic");
1209 return IXGBE_ERR_PARAM;
1211 /* To turn on the LED, set mode to ON. */
1212 led_reg &= ~IXGBE_LED_MODE_MASK(index);
1213 led_reg |= IXGBE_LED_ON << IXGBE_LED_MODE_SHIFT(index);
1214 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
1215 IXGBE_WRITE_FLUSH(hw);
1217 return IXGBE_SUCCESS;
1221 * ixgbe_led_off_generic - Turns off the software controllable LEDs.
1222 * @hw: pointer to hardware structure
1223 * @index: led number to turn off
1225 s32 ixgbe_led_off_generic(struct ixgbe_hw *hw, u32 index)
1227 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1229 DEBUGFUNC("ixgbe_led_off_generic");
1232 return IXGBE_ERR_PARAM;
1234 /* To turn off the LED, set mode to OFF. */
1235 led_reg &= ~IXGBE_LED_MODE_MASK(index);
1236 led_reg |= IXGBE_LED_OFF << IXGBE_LED_MODE_SHIFT(index);
1237 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
1238 IXGBE_WRITE_FLUSH(hw);
1240 return IXGBE_SUCCESS;
1244 * ixgbe_init_eeprom_params_generic - Initialize EEPROM params
1245 * @hw: pointer to hardware structure
1247 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
1248 * ixgbe_hw struct in order to set up EEPROM access.
1250 s32 ixgbe_init_eeprom_params_generic(struct ixgbe_hw *hw)
1252 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
1256 DEBUGFUNC("ixgbe_init_eeprom_params_generic");
1258 if (eeprom->type == ixgbe_eeprom_uninitialized) {
1259 eeprom->type = ixgbe_eeprom_none;
1260 /* Set default semaphore delay to 10ms which is a well
1262 eeprom->semaphore_delay = 10;
1263 /* Clear EEPROM page size, it will be initialized as needed */
1264 eeprom->word_page_size = 0;
1267 * Check for EEPROM present first.
1268 * If not present leave as none
1270 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
1271 if (eec & IXGBE_EEC_PRES) {
1272 eeprom->type = ixgbe_eeprom_spi;
1275 * SPI EEPROM is assumed here. This code would need to
1276 * change if a future EEPROM is not SPI.
1278 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
1279 IXGBE_EEC_SIZE_SHIFT);
1280 eeprom->word_size = 1 << (eeprom_size +
1281 IXGBE_EEPROM_WORD_SIZE_SHIFT);
1284 if (eec & IXGBE_EEC_ADDR_SIZE)
1285 eeprom->address_bits = 16;
1287 eeprom->address_bits = 8;
1288 DEBUGOUT3("Eeprom params: type = %d, size = %d, address bits: "
1289 "%d\n", eeprom->type, eeprom->word_size,
1290 eeprom->address_bits);
1293 return IXGBE_SUCCESS;
1297 * ixgbe_write_eeprom_buffer_bit_bang_generic - Write EEPROM using bit-bang
1298 * @hw: pointer to hardware structure
1299 * @offset: offset within the EEPROM to write
1300 * @words: number of word(s)
1301 * @data: 16 bit word(s) to write to EEPROM
1303 * Reads 16 bit word(s) from EEPROM through bit-bang method
1305 s32 ixgbe_write_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1306 u16 words, u16 *data)
1308 s32 status = IXGBE_SUCCESS;
1311 DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang_generic");
1313 hw->eeprom.ops.init_params(hw);
1316 status = IXGBE_ERR_INVALID_ARGUMENT;
1320 if (offset + words > hw->eeprom.word_size) {
1321 status = IXGBE_ERR_EEPROM;
1326 * The EEPROM page size cannot be queried from the chip. We do lazy
1327 * initialization. It is worth to do that when we write large buffer.
1329 if ((hw->eeprom.word_page_size == 0) &&
1330 (words > IXGBE_EEPROM_PAGE_SIZE_MAX))
1331 ixgbe_detect_eeprom_page_size_generic(hw, offset);
1334 * We cannot hold synchronization semaphores for too long
1335 * to avoid other entity starvation. However it is more efficient
1336 * to read in bursts than synchronizing access for each word.
1338 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
1339 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
1340 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
1341 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset + i,
1344 if (status != IXGBE_SUCCESS)
1353 * ixgbe_write_eeprom_buffer_bit_bang - Writes 16 bit word(s) to EEPROM
1354 * @hw: pointer to hardware structure
1355 * @offset: offset within the EEPROM to be written to
1356 * @words: number of word(s)
1357 * @data: 16 bit word(s) to be written to the EEPROM
1359 * If ixgbe_eeprom_update_checksum is not called after this function, the
1360 * EEPROM will most likely contain an invalid checksum.
1362 static s32 ixgbe_write_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
1363 u16 words, u16 *data)
1369 u8 write_opcode = IXGBE_EEPROM_WRITE_OPCODE_SPI;
1371 DEBUGFUNC("ixgbe_write_eeprom_buffer_bit_bang");
1373 /* Prepare the EEPROM for writing */
1374 status = ixgbe_acquire_eeprom(hw);
1376 if (status == IXGBE_SUCCESS) {
1377 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
1378 ixgbe_release_eeprom(hw);
1379 status = IXGBE_ERR_EEPROM;
1383 if (status == IXGBE_SUCCESS) {
1384 for (i = 0; i < words; i++) {
1385 ixgbe_standby_eeprom(hw);
1387 /* Send the WRITE ENABLE command (8 bit opcode ) */
1388 ixgbe_shift_out_eeprom_bits(hw,
1389 IXGBE_EEPROM_WREN_OPCODE_SPI,
1390 IXGBE_EEPROM_OPCODE_BITS);
1392 ixgbe_standby_eeprom(hw);
1395 * Some SPI eeproms use the 8th address bit embedded
1398 if ((hw->eeprom.address_bits == 8) &&
1399 ((offset + i) >= 128))
1400 write_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
1402 /* Send the Write command (8-bit opcode + addr) */
1403 ixgbe_shift_out_eeprom_bits(hw, write_opcode,
1404 IXGBE_EEPROM_OPCODE_BITS);
1405 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
1406 hw->eeprom.address_bits);
1408 page_size = hw->eeprom.word_page_size;
1410 /* Send the data in burst via SPI*/
1413 word = (word >> 8) | (word << 8);
1414 ixgbe_shift_out_eeprom_bits(hw, word, 16);
1419 /* do not wrap around page */
1420 if (((offset + i) & (page_size - 1)) ==
1423 } while (++i < words);
1425 ixgbe_standby_eeprom(hw);
1428 /* Done with writing - release the EEPROM */
1429 ixgbe_release_eeprom(hw);
1436 * ixgbe_write_eeprom_generic - Writes 16 bit value to EEPROM
1437 * @hw: pointer to hardware structure
1438 * @offset: offset within the EEPROM to be written to
1439 * @data: 16 bit word to be written to the EEPROM
1441 * If ixgbe_eeprom_update_checksum is not called after this function, the
1442 * EEPROM will most likely contain an invalid checksum.
1444 s32 ixgbe_write_eeprom_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1448 DEBUGFUNC("ixgbe_write_eeprom_generic");
1450 hw->eeprom.ops.init_params(hw);
1452 if (offset >= hw->eeprom.word_size) {
1453 status = IXGBE_ERR_EEPROM;
1457 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset, 1, &data);
1464 * ixgbe_read_eeprom_buffer_bit_bang_generic - Read EEPROM using bit-bang
1465 * @hw: pointer to hardware structure
1466 * @offset: offset within the EEPROM to be read
1467 * @data: read 16 bit words(s) from EEPROM
1468 * @words: number of word(s)
1470 * Reads 16 bit word(s) from EEPROM through bit-bang method
1472 s32 ixgbe_read_eeprom_buffer_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1473 u16 words, u16 *data)
1475 s32 status = IXGBE_SUCCESS;
1478 DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang_generic");
1480 hw->eeprom.ops.init_params(hw);
1483 status = IXGBE_ERR_INVALID_ARGUMENT;
1487 if (offset + words > hw->eeprom.word_size) {
1488 status = IXGBE_ERR_EEPROM;
1493 * We cannot hold synchronization semaphores for too long
1494 * to avoid other entity starvation. However it is more efficient
1495 * to read in bursts than synchronizing access for each word.
1497 for (i = 0; i < words; i += IXGBE_EEPROM_RD_BUFFER_MAX_COUNT) {
1498 count = (words - i) / IXGBE_EEPROM_RD_BUFFER_MAX_COUNT > 0 ?
1499 IXGBE_EEPROM_RD_BUFFER_MAX_COUNT : (words - i);
1501 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset + i,
1504 if (status != IXGBE_SUCCESS)
1513 * ixgbe_read_eeprom_buffer_bit_bang - Read EEPROM using bit-bang
1514 * @hw: pointer to hardware structure
1515 * @offset: offset within the EEPROM to be read
1516 * @words: number of word(s)
1517 * @data: read 16 bit word(s) from EEPROM
1519 * Reads 16 bit word(s) from EEPROM through bit-bang method
1521 static s32 ixgbe_read_eeprom_buffer_bit_bang(struct ixgbe_hw *hw, u16 offset,
1522 u16 words, u16 *data)
1526 u8 read_opcode = IXGBE_EEPROM_READ_OPCODE_SPI;
1529 DEBUGFUNC("ixgbe_read_eeprom_buffer_bit_bang");
1531 /* Prepare the EEPROM for reading */
1532 status = ixgbe_acquire_eeprom(hw);
1534 if (status == IXGBE_SUCCESS) {
1535 if (ixgbe_ready_eeprom(hw) != IXGBE_SUCCESS) {
1536 ixgbe_release_eeprom(hw);
1537 status = IXGBE_ERR_EEPROM;
1541 if (status == IXGBE_SUCCESS) {
1542 for (i = 0; i < words; i++) {
1543 ixgbe_standby_eeprom(hw);
1545 * Some SPI eeproms use the 8th address bit embedded
1548 if ((hw->eeprom.address_bits == 8) &&
1549 ((offset + i) >= 128))
1550 read_opcode |= IXGBE_EEPROM_A8_OPCODE_SPI;
1552 /* Send the READ command (opcode + addr) */
1553 ixgbe_shift_out_eeprom_bits(hw, read_opcode,
1554 IXGBE_EEPROM_OPCODE_BITS);
1555 ixgbe_shift_out_eeprom_bits(hw, (u16)((offset + i) * 2),
1556 hw->eeprom.address_bits);
1558 /* Read the data. */
1559 word_in = ixgbe_shift_in_eeprom_bits(hw, 16);
1560 data[i] = (word_in >> 8) | (word_in << 8);
1563 /* End this read operation */
1564 ixgbe_release_eeprom(hw);
1571 * ixgbe_read_eeprom_bit_bang_generic - Read EEPROM word using bit-bang
1572 * @hw: pointer to hardware structure
1573 * @offset: offset within the EEPROM to be read
1574 * @data: read 16 bit value from EEPROM
1576 * Reads 16 bit value from EEPROM through bit-bang method
1578 s32 ixgbe_read_eeprom_bit_bang_generic(struct ixgbe_hw *hw, u16 offset,
1583 DEBUGFUNC("ixgbe_read_eeprom_bit_bang_generic");
1585 hw->eeprom.ops.init_params(hw);
1587 if (offset >= hw->eeprom.word_size) {
1588 status = IXGBE_ERR_EEPROM;
1592 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1599 * ixgbe_read_eerd_buffer_generic - Read EEPROM word(s) using EERD
1600 * @hw: pointer to hardware structure
1601 * @offset: offset of word in the EEPROM to read
1602 * @words: number of word(s)
1603 * @data: 16 bit word(s) from the EEPROM
1605 * Reads a 16 bit word(s) from the EEPROM using the EERD register.
1607 s32 ixgbe_read_eerd_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1608 u16 words, u16 *data)
1611 s32 status = IXGBE_SUCCESS;
1614 DEBUGFUNC("ixgbe_read_eerd_buffer_generic");
1616 hw->eeprom.ops.init_params(hw);
1619 status = IXGBE_ERR_INVALID_ARGUMENT;
1620 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM words");
1624 if (offset >= hw->eeprom.word_size) {
1625 status = IXGBE_ERR_EEPROM;
1626 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM offset");
1630 for (i = 0; i < words; i++) {
1631 eerd = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1632 IXGBE_EEPROM_RW_REG_START;
1634 IXGBE_WRITE_REG(hw, IXGBE_EERD, eerd);
1635 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_READ);
1637 if (status == IXGBE_SUCCESS) {
1638 data[i] = (IXGBE_READ_REG(hw, IXGBE_EERD) >>
1639 IXGBE_EEPROM_RW_REG_DATA);
1641 DEBUGOUT("Eeprom read timed out\n");
1650 * ixgbe_detect_eeprom_page_size_generic - Detect EEPROM page size
1651 * @hw: pointer to hardware structure
1652 * @offset: offset within the EEPROM to be used as a scratch pad
1654 * Discover EEPROM page size by writing marching data at given offset.
1655 * This function is called only when we are writing a new large buffer
1656 * at given offset so the data would be overwritten anyway.
1658 static s32 ixgbe_detect_eeprom_page_size_generic(struct ixgbe_hw *hw,
1661 u16 data[IXGBE_EEPROM_PAGE_SIZE_MAX];
1662 s32 status = IXGBE_SUCCESS;
1665 DEBUGFUNC("ixgbe_detect_eeprom_page_size_generic");
1667 for (i = 0; i < IXGBE_EEPROM_PAGE_SIZE_MAX; i++)
1670 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX;
1671 status = ixgbe_write_eeprom_buffer_bit_bang(hw, offset,
1672 IXGBE_EEPROM_PAGE_SIZE_MAX, data);
1673 hw->eeprom.word_page_size = 0;
1674 if (status != IXGBE_SUCCESS)
1677 status = ixgbe_read_eeprom_buffer_bit_bang(hw, offset, 1, data);
1678 if (status != IXGBE_SUCCESS)
1682 * When writing in burst more than the actual page size
1683 * EEPROM address wraps around current page.
1685 hw->eeprom.word_page_size = IXGBE_EEPROM_PAGE_SIZE_MAX - data[0];
1687 DEBUGOUT1("Detected EEPROM page size = %d words.",
1688 hw->eeprom.word_page_size);
1694 * ixgbe_read_eerd_generic - Read EEPROM word using EERD
1695 * @hw: pointer to hardware structure
1696 * @offset: offset of word in the EEPROM to read
1697 * @data: word read from the EEPROM
1699 * Reads a 16 bit word from the EEPROM using the EERD register.
1701 s32 ixgbe_read_eerd_generic(struct ixgbe_hw *hw, u16 offset, u16 *data)
1703 return ixgbe_read_eerd_buffer_generic(hw, offset, 1, data);
1707 * ixgbe_write_eewr_buffer_generic - Write EEPROM word(s) using EEWR
1708 * @hw: pointer to hardware structure
1709 * @offset: offset of word in the EEPROM to write
1710 * @words: number of word(s)
1711 * @data: word(s) write to the EEPROM
1713 * Write a 16 bit word(s) to the EEPROM using the EEWR register.
1715 s32 ixgbe_write_eewr_buffer_generic(struct ixgbe_hw *hw, u16 offset,
1716 u16 words, u16 *data)
1719 s32 status = IXGBE_SUCCESS;
1722 DEBUGFUNC("ixgbe_write_eewr_generic");
1724 hw->eeprom.ops.init_params(hw);
1727 status = IXGBE_ERR_INVALID_ARGUMENT;
1728 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM words");
1732 if (offset >= hw->eeprom.word_size) {
1733 status = IXGBE_ERR_EEPROM;
1734 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT, "Invalid EEPROM offset");
1738 for (i = 0; i < words; i++) {
1739 eewr = ((offset + i) << IXGBE_EEPROM_RW_ADDR_SHIFT) |
1740 (data[i] << IXGBE_EEPROM_RW_REG_DATA) |
1741 IXGBE_EEPROM_RW_REG_START;
1743 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1744 if (status != IXGBE_SUCCESS) {
1745 DEBUGOUT("Eeprom write EEWR timed out\n");
1749 IXGBE_WRITE_REG(hw, IXGBE_EEWR, eewr);
1751 status = ixgbe_poll_eerd_eewr_done(hw, IXGBE_NVM_POLL_WRITE);
1752 if (status != IXGBE_SUCCESS) {
1753 DEBUGOUT("Eeprom write EEWR timed out\n");
1763 * ixgbe_write_eewr_generic - Write EEPROM word using EEWR
1764 * @hw: pointer to hardware structure
1765 * @offset: offset of word in the EEPROM to write
1766 * @data: word write to the EEPROM
1768 * Write a 16 bit word to the EEPROM using the EEWR register.
1770 s32 ixgbe_write_eewr_generic(struct ixgbe_hw *hw, u16 offset, u16 data)
1772 return ixgbe_write_eewr_buffer_generic(hw, offset, 1, &data);
1776 * ixgbe_poll_eerd_eewr_done - Poll EERD read or EEWR write status
1777 * @hw: pointer to hardware structure
1778 * @ee_reg: EEPROM flag for polling
1780 * Polls the status bit (bit 1) of the EERD or EEWR to determine when the
1781 * read or write is done respectively.
1783 s32 ixgbe_poll_eerd_eewr_done(struct ixgbe_hw *hw, u32 ee_reg)
1787 s32 status = IXGBE_ERR_EEPROM;
1789 DEBUGFUNC("ixgbe_poll_eerd_eewr_done");
1791 for (i = 0; i < IXGBE_EERD_EEWR_ATTEMPTS; i++) {
1792 if (ee_reg == IXGBE_NVM_POLL_READ)
1793 reg = IXGBE_READ_REG(hw, IXGBE_EERD);
1795 reg = IXGBE_READ_REG(hw, IXGBE_EEWR);
1797 if (reg & IXGBE_EEPROM_RW_REG_DONE) {
1798 status = IXGBE_SUCCESS;
1804 if (i == IXGBE_EERD_EEWR_ATTEMPTS)
1805 ERROR_REPORT1(IXGBE_ERROR_POLLING,
1806 "EEPROM read/write done polling timed out");
1812 * ixgbe_acquire_eeprom - Acquire EEPROM using bit-bang
1813 * @hw: pointer to hardware structure
1815 * Prepares EEPROM for access using bit-bang method. This function should
1816 * be called before issuing a command to the EEPROM.
1818 static s32 ixgbe_acquire_eeprom(struct ixgbe_hw *hw)
1820 s32 status = IXGBE_SUCCESS;
1824 DEBUGFUNC("ixgbe_acquire_eeprom");
1826 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM)
1828 status = IXGBE_ERR_SWFW_SYNC;
1830 if (status == IXGBE_SUCCESS) {
1831 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
1833 /* Request EEPROM Access */
1834 eec |= IXGBE_EEC_REQ;
1835 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
1837 for (i = 0; i < IXGBE_EEPROM_GRANT_ATTEMPTS; i++) {
1838 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
1839 if (eec & IXGBE_EEC_GNT)
1844 /* Release if grant not acquired */
1845 if (!(eec & IXGBE_EEC_GNT)) {
1846 eec &= ~IXGBE_EEC_REQ;
1847 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
1848 DEBUGOUT("Could not acquire EEPROM grant\n");
1850 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
1851 status = IXGBE_ERR_EEPROM;
1854 /* Setup EEPROM for Read/Write */
1855 if (status == IXGBE_SUCCESS) {
1856 /* Clear CS and SK */
1857 eec &= ~(IXGBE_EEC_CS | IXGBE_EEC_SK);
1858 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
1859 IXGBE_WRITE_FLUSH(hw);
1867 * ixgbe_get_eeprom_semaphore - Get hardware semaphore
1868 * @hw: pointer to hardware structure
1870 * Sets the hardware semaphores so EEPROM access can occur for bit-bang method
1872 static s32 ixgbe_get_eeprom_semaphore(struct ixgbe_hw *hw)
1874 s32 status = IXGBE_ERR_EEPROM;
1879 DEBUGFUNC("ixgbe_get_eeprom_semaphore");
1882 /* Get SMBI software semaphore between device drivers first */
1883 for (i = 0; i < timeout; i++) {
1885 * If the SMBI bit is 0 when we read it, then the bit will be
1886 * set and we have the semaphore
1888 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
1889 if (!(swsm & IXGBE_SWSM_SMBI)) {
1890 status = IXGBE_SUCCESS;
1897 DEBUGOUT("Driver can't access the Eeprom - SMBI Semaphore "
1900 * this release is particularly important because our attempts
1901 * above to get the semaphore may have succeeded, and if there
1902 * was a timeout, we should unconditionally clear the semaphore
1903 * bits to free the driver to make progress
1905 ixgbe_release_eeprom_semaphore(hw);
1910 * If the SMBI bit is 0 when we read it, then the bit will be
1911 * set and we have the semaphore
1913 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
1914 if (!(swsm & IXGBE_SWSM_SMBI))
1915 status = IXGBE_SUCCESS;
1918 /* Now get the semaphore between SW/FW through the SWESMBI bit */
1919 if (status == IXGBE_SUCCESS) {
1920 for (i = 0; i < timeout; i++) {
1921 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
1923 /* Set the SW EEPROM semaphore bit to request access */
1924 swsm |= IXGBE_SWSM_SWESMBI;
1925 IXGBE_WRITE_REG(hw, IXGBE_SWSM_BY_MAC(hw), swsm);
1928 * If we set the bit successfully then we got the
1931 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
1932 if (swsm & IXGBE_SWSM_SWESMBI)
1939 * Release semaphores and return error if SW EEPROM semaphore
1940 * was not granted because we don't have access to the EEPROM
1943 ERROR_REPORT1(IXGBE_ERROR_POLLING,
1944 "SWESMBI Software EEPROM semaphore not granted.\n");
1945 ixgbe_release_eeprom_semaphore(hw);
1946 status = IXGBE_ERR_EEPROM;
1949 ERROR_REPORT1(IXGBE_ERROR_POLLING,
1950 "Software semaphore SMBI between device drivers "
1958 * ixgbe_release_eeprom_semaphore - Release hardware semaphore
1959 * @hw: pointer to hardware structure
1961 * This function clears hardware semaphore bits.
1963 static void ixgbe_release_eeprom_semaphore(struct ixgbe_hw *hw)
1967 DEBUGFUNC("ixgbe_release_eeprom_semaphore");
1969 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM);
1971 /* Release both semaphores by writing 0 to the bits SWESMBI and SMBI */
1972 swsm &= ~(IXGBE_SWSM_SWESMBI | IXGBE_SWSM_SMBI);
1973 IXGBE_WRITE_REG(hw, IXGBE_SWSM, swsm);
1974 IXGBE_WRITE_FLUSH(hw);
1978 * ixgbe_ready_eeprom - Polls for EEPROM ready
1979 * @hw: pointer to hardware structure
1981 static s32 ixgbe_ready_eeprom(struct ixgbe_hw *hw)
1983 s32 status = IXGBE_SUCCESS;
1987 DEBUGFUNC("ixgbe_ready_eeprom");
1990 * Read "Status Register" repeatedly until the LSB is cleared. The
1991 * EEPROM will signal that the command has been completed by clearing
1992 * bit 0 of the internal status register. If it's not cleared within
1993 * 5 milliseconds, then error out.
1995 for (i = 0; i < IXGBE_EEPROM_MAX_RETRY_SPI; i += 5) {
1996 ixgbe_shift_out_eeprom_bits(hw, IXGBE_EEPROM_RDSR_OPCODE_SPI,
1997 IXGBE_EEPROM_OPCODE_BITS);
1998 spi_stat_reg = (u8)ixgbe_shift_in_eeprom_bits(hw, 8);
1999 if (!(spi_stat_reg & IXGBE_EEPROM_STATUS_RDY_SPI))
2003 ixgbe_standby_eeprom(hw);
2007 * On some parts, SPI write time could vary from 0-20mSec on 3.3V
2008 * devices (and only 0-5mSec on 5V devices)
2010 if (i >= IXGBE_EEPROM_MAX_RETRY_SPI) {
2011 DEBUGOUT("SPI EEPROM Status error\n");
2012 status = IXGBE_ERR_EEPROM;
2019 * ixgbe_standby_eeprom - Returns EEPROM to a "standby" state
2020 * @hw: pointer to hardware structure
2022 static void ixgbe_standby_eeprom(struct ixgbe_hw *hw)
2026 DEBUGFUNC("ixgbe_standby_eeprom");
2028 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
2030 /* Toggle CS to flush commands */
2031 eec |= IXGBE_EEC_CS;
2032 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
2033 IXGBE_WRITE_FLUSH(hw);
2035 eec &= ~IXGBE_EEC_CS;
2036 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
2037 IXGBE_WRITE_FLUSH(hw);
2042 * ixgbe_shift_out_eeprom_bits - Shift data bits out to the EEPROM.
2043 * @hw: pointer to hardware structure
2044 * @data: data to send to the EEPROM
2045 * @count: number of bits to shift out
2047 static void ixgbe_shift_out_eeprom_bits(struct ixgbe_hw *hw, u16 data,
2054 DEBUGFUNC("ixgbe_shift_out_eeprom_bits");
2056 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
2059 * Mask is used to shift "count" bits of "data" out to the EEPROM
2060 * one bit at a time. Determine the starting bit based on count
2062 mask = 0x01 << (count - 1);
2064 for (i = 0; i < count; i++) {
2066 * A "1" is shifted out to the EEPROM by setting bit "DI" to a
2067 * "1", and then raising and then lowering the clock (the SK
2068 * bit controls the clock input to the EEPROM). A "0" is
2069 * shifted out to the EEPROM by setting "DI" to "0" and then
2070 * raising and then lowering the clock.
2073 eec |= IXGBE_EEC_DI;
2075 eec &= ~IXGBE_EEC_DI;
2077 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
2078 IXGBE_WRITE_FLUSH(hw);
2082 ixgbe_raise_eeprom_clk(hw, &eec);
2083 ixgbe_lower_eeprom_clk(hw, &eec);
2086 * Shift mask to signify next bit of data to shift in to the
2092 /* We leave the "DI" bit set to "0" when we leave this routine. */
2093 eec &= ~IXGBE_EEC_DI;
2094 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
2095 IXGBE_WRITE_FLUSH(hw);
2099 * ixgbe_shift_in_eeprom_bits - Shift data bits in from the EEPROM
2100 * @hw: pointer to hardware structure
2101 * @count: number of bits to shift
2103 static u16 ixgbe_shift_in_eeprom_bits(struct ixgbe_hw *hw, u16 count)
2109 DEBUGFUNC("ixgbe_shift_in_eeprom_bits");
2112 * In order to read a register from the EEPROM, we need to shift
2113 * 'count' bits in from the EEPROM. Bits are "shifted in" by raising
2114 * the clock input to the EEPROM (setting the SK bit), and then reading
2115 * the value of the "DO" bit. During this "shifting in" process the
2116 * "DI" bit should always be clear.
2118 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
2120 eec &= ~(IXGBE_EEC_DO | IXGBE_EEC_DI);
2122 for (i = 0; i < count; i++) {
2124 ixgbe_raise_eeprom_clk(hw, &eec);
2126 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
2128 eec &= ~(IXGBE_EEC_DI);
2129 if (eec & IXGBE_EEC_DO)
2132 ixgbe_lower_eeprom_clk(hw, &eec);
2139 * ixgbe_raise_eeprom_clk - Raises the EEPROM's clock input.
2140 * @hw: pointer to hardware structure
2141 * @eec: EEC register's current value
2143 static void ixgbe_raise_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
2145 DEBUGFUNC("ixgbe_raise_eeprom_clk");
2148 * Raise the clock input to the EEPROM
2149 * (setting the SK bit), then delay
2151 *eec = *eec | IXGBE_EEC_SK;
2152 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), *eec);
2153 IXGBE_WRITE_FLUSH(hw);
2158 * ixgbe_lower_eeprom_clk - Lowers the EEPROM's clock input.
2159 * @hw: pointer to hardware structure
2160 * @eec: EEC's current value
2162 static void ixgbe_lower_eeprom_clk(struct ixgbe_hw *hw, u32 *eec)
2164 DEBUGFUNC("ixgbe_lower_eeprom_clk");
2167 * Lower the clock input to the EEPROM (clearing the SK bit), then
2170 *eec = *eec & ~IXGBE_EEC_SK;
2171 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), *eec);
2172 IXGBE_WRITE_FLUSH(hw);
2177 * ixgbe_release_eeprom - Release EEPROM, release semaphores
2178 * @hw: pointer to hardware structure
2180 static void ixgbe_release_eeprom(struct ixgbe_hw *hw)
2184 DEBUGFUNC("ixgbe_release_eeprom");
2186 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
2188 eec |= IXGBE_EEC_CS; /* Pull CS high */
2189 eec &= ~IXGBE_EEC_SK; /* Lower SCK */
2191 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
2192 IXGBE_WRITE_FLUSH(hw);
2196 /* Stop requesting EEPROM access */
2197 eec &= ~IXGBE_EEC_REQ;
2198 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), eec);
2200 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2202 /* Delay before attempt to obtain semaphore again to allow FW access */
2203 msec_delay(hw->eeprom.semaphore_delay);
2207 * ixgbe_calc_eeprom_checksum_generic - Calculates and returns the checksum
2208 * @hw: pointer to hardware structure
2210 * Returns a negative error code on error, or the 16-bit checksum
2212 s32 ixgbe_calc_eeprom_checksum_generic(struct ixgbe_hw *hw)
2221 DEBUGFUNC("ixgbe_calc_eeprom_checksum_generic");
2223 /* Include 0x0-0x3F in the checksum */
2224 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
2225 if (hw->eeprom.ops.read(hw, i, &word)) {
2226 DEBUGOUT("EEPROM read failed\n");
2227 return IXGBE_ERR_EEPROM;
2232 /* Include all data from pointers except for the fw pointer */
2233 for (i = IXGBE_PCIE_ANALOG_PTR; i < IXGBE_FW_PTR; i++) {
2234 if (hw->eeprom.ops.read(hw, i, &pointer)) {
2235 DEBUGOUT("EEPROM read failed\n");
2236 return IXGBE_ERR_EEPROM;
2239 /* If the pointer seems invalid */
2240 if (pointer == 0xFFFF || pointer == 0)
2243 if (hw->eeprom.ops.read(hw, pointer, &length)) {
2244 DEBUGOUT("EEPROM read failed\n");
2245 return IXGBE_ERR_EEPROM;
2248 if (length == 0xFFFF || length == 0)
2251 for (j = pointer + 1; j <= pointer + length; j++) {
2252 if (hw->eeprom.ops.read(hw, j, &word)) {
2253 DEBUGOUT("EEPROM read failed\n");
2254 return IXGBE_ERR_EEPROM;
2260 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
2262 return (s32)checksum;
2266 * ixgbe_validate_eeprom_checksum_generic - Validate EEPROM checksum
2267 * @hw: pointer to hardware structure
2268 * @checksum_val: calculated checksum
2270 * Performs checksum calculation and validates the EEPROM checksum. If the
2271 * caller does not need checksum_val, the value can be NULL.
2273 s32 ixgbe_validate_eeprom_checksum_generic(struct ixgbe_hw *hw,
2278 u16 read_checksum = 0;
2280 DEBUGFUNC("ixgbe_validate_eeprom_checksum_generic");
2282 /* Read the first word from the EEPROM. If this times out or fails, do
2283 * not continue or we could be in for a very long wait while every
2286 status = hw->eeprom.ops.read(hw, 0, &checksum);
2288 DEBUGOUT("EEPROM read failed\n");
2292 status = hw->eeprom.ops.calc_checksum(hw);
2296 checksum = (u16)(status & 0xffff);
2298 status = hw->eeprom.ops.read(hw, IXGBE_EEPROM_CHECKSUM, &read_checksum);
2300 DEBUGOUT("EEPROM read failed\n");
2304 /* Verify read checksum from EEPROM is the same as
2305 * calculated checksum
2307 if (read_checksum != checksum)
2308 status = IXGBE_ERR_EEPROM_CHECKSUM;
2310 /* If the user cares, return the calculated checksum */
2312 *checksum_val = checksum;
2318 * ixgbe_update_eeprom_checksum_generic - Updates the EEPROM checksum
2319 * @hw: pointer to hardware structure
2321 s32 ixgbe_update_eeprom_checksum_generic(struct ixgbe_hw *hw)
2326 DEBUGFUNC("ixgbe_update_eeprom_checksum_generic");
2328 /* Read the first word from the EEPROM. If this times out or fails, do
2329 * not continue or we could be in for a very long wait while every
2332 status = hw->eeprom.ops.read(hw, 0, &checksum);
2334 DEBUGOUT("EEPROM read failed\n");
2338 status = hw->eeprom.ops.calc_checksum(hw);
2342 checksum = (u16)(status & 0xffff);
2344 status = hw->eeprom.ops.write(hw, IXGBE_EEPROM_CHECKSUM, checksum);
2350 * ixgbe_validate_mac_addr - Validate MAC address
2351 * @mac_addr: pointer to MAC address.
2353 * Tests a MAC address to ensure it is a valid Individual Address.
2355 s32 ixgbe_validate_mac_addr(u8 *mac_addr)
2357 s32 status = IXGBE_SUCCESS;
2359 DEBUGFUNC("ixgbe_validate_mac_addr");
2361 /* Make sure it is not a multicast address */
2362 if (IXGBE_IS_MULTICAST(mac_addr)) {
2363 status = IXGBE_ERR_INVALID_MAC_ADDR;
2364 /* Not a broadcast address */
2365 } else if (IXGBE_IS_BROADCAST(mac_addr)) {
2366 status = IXGBE_ERR_INVALID_MAC_ADDR;
2367 /* Reject the zero address */
2368 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
2369 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
2370 status = IXGBE_ERR_INVALID_MAC_ADDR;
2376 * ixgbe_set_rar_generic - Set Rx address register
2377 * @hw: pointer to hardware structure
2378 * @index: Receive address register to write
2379 * @addr: Address to put into receive address register
2380 * @vmdq: VMDq "set" or "pool" index
2381 * @enable_addr: set flag that address is active
2383 * Puts an ethernet address into a receive address register.
2385 s32 ixgbe_set_rar_generic(struct ixgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
2388 u32 rar_low, rar_high;
2389 u32 rar_entries = hw->mac.num_rar_entries;
2391 DEBUGFUNC("ixgbe_set_rar_generic");
2393 /* Make sure we are using a valid rar index range */
2394 if (index >= rar_entries) {
2395 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
2396 "RAR index %d is out of range.\n", index);
2397 return IXGBE_ERR_INVALID_ARGUMENT;
2400 /* setup VMDq pool selection before this RAR gets enabled */
2401 hw->mac.ops.set_vmdq(hw, index, vmdq);
2404 * HW expects these in little endian so we reverse the byte
2405 * order from network order (big endian) to little endian
2407 rar_low = ((u32)addr[0] |
2408 ((u32)addr[1] << 8) |
2409 ((u32)addr[2] << 16) |
2410 ((u32)addr[3] << 24));
2412 * Some parts put the VMDq setting in the extra RAH bits,
2413 * so save everything except the lower 16 bits that hold part
2414 * of the address and the address valid bit.
2416 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
2417 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
2418 rar_high |= ((u32)addr[4] | ((u32)addr[5] << 8));
2420 if (enable_addr != 0)
2421 rar_high |= IXGBE_RAH_AV;
2423 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), rar_low);
2424 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
2426 return IXGBE_SUCCESS;
2430 * ixgbe_clear_rar_generic - Remove Rx address register
2431 * @hw: pointer to hardware structure
2432 * @index: Receive address register to write
2434 * Clears an ethernet address from a receive address register.
2436 s32 ixgbe_clear_rar_generic(struct ixgbe_hw *hw, u32 index)
2439 u32 rar_entries = hw->mac.num_rar_entries;
2441 DEBUGFUNC("ixgbe_clear_rar_generic");
2443 /* Make sure we are using a valid rar index range */
2444 if (index >= rar_entries) {
2445 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
2446 "RAR index %d is out of range.\n", index);
2447 return IXGBE_ERR_INVALID_ARGUMENT;
2451 * Some parts put the VMDq setting in the extra RAH bits,
2452 * so save everything except the lower 16 bits that hold part
2453 * of the address and the address valid bit.
2455 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(index));
2456 rar_high &= ~(0x0000FFFF | IXGBE_RAH_AV);
2458 IXGBE_WRITE_REG(hw, IXGBE_RAL(index), 0);
2459 IXGBE_WRITE_REG(hw, IXGBE_RAH(index), rar_high);
2461 /* clear VMDq pool/queue selection for this RAR */
2462 hw->mac.ops.clear_vmdq(hw, index, IXGBE_CLEAR_VMDQ_ALL);
2464 return IXGBE_SUCCESS;
2468 * ixgbe_init_rx_addrs_generic - Initializes receive address filters.
2469 * @hw: pointer to hardware structure
2471 * Places the MAC address in receive address register 0 and clears the rest
2472 * of the receive address registers. Clears the multicast table. Assumes
2473 * the receiver is in reset when the routine is called.
2475 s32 ixgbe_init_rx_addrs_generic(struct ixgbe_hw *hw)
2478 u32 rar_entries = hw->mac.num_rar_entries;
2480 DEBUGFUNC("ixgbe_init_rx_addrs_generic");
2483 * If the current mac address is valid, assume it is a software override
2484 * to the permanent address.
2485 * Otherwise, use the permanent address from the eeprom.
2487 if (ixgbe_validate_mac_addr(hw->mac.addr) ==
2488 IXGBE_ERR_INVALID_MAC_ADDR) {
2489 /* Get the MAC address from the RAR0 for later reference */
2490 hw->mac.ops.get_mac_addr(hw, hw->mac.addr);
2492 DEBUGOUT3(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
2493 hw->mac.addr[0], hw->mac.addr[1],
2495 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
2496 hw->mac.addr[4], hw->mac.addr[5]);
2498 /* Setup the receive address. */
2499 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
2500 DEBUGOUT3(" New MAC Addr =%.2X %.2X %.2X ",
2501 hw->mac.addr[0], hw->mac.addr[1],
2503 DEBUGOUT3("%.2X %.2X %.2X\n", hw->mac.addr[3],
2504 hw->mac.addr[4], hw->mac.addr[5]);
2506 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV);
2509 /* clear VMDq pool/queue selection for RAR 0 */
2510 hw->mac.ops.clear_vmdq(hw, 0, IXGBE_CLEAR_VMDQ_ALL);
2512 hw->addr_ctrl.overflow_promisc = 0;
2514 hw->addr_ctrl.rar_used_count = 1;
2516 /* Zero out the other receive addresses. */
2517 DEBUGOUT1("Clearing RAR[1-%d]\n", rar_entries - 1);
2518 for (i = 1; i < rar_entries; i++) {
2519 IXGBE_WRITE_REG(hw, IXGBE_RAL(i), 0);
2520 IXGBE_WRITE_REG(hw, IXGBE_RAH(i), 0);
2524 hw->addr_ctrl.mta_in_use = 0;
2525 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
2527 DEBUGOUT(" Clearing MTA\n");
2528 for (i = 0; i < hw->mac.mcft_size; i++)
2529 IXGBE_WRITE_REG(hw, IXGBE_MTA(i), 0);
2531 ixgbe_init_uta_tables(hw);
2533 return IXGBE_SUCCESS;
2537 * ixgbe_add_uc_addr - Adds a secondary unicast address.
2538 * @hw: pointer to hardware structure
2539 * @addr: new address
2540 * @vmdq: VMDq "set" or "pool" index
2542 * Adds it to unused receive address register or goes into promiscuous mode.
2544 void ixgbe_add_uc_addr(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
2546 u32 rar_entries = hw->mac.num_rar_entries;
2549 DEBUGFUNC("ixgbe_add_uc_addr");
2551 DEBUGOUT6(" UC Addr = %.2X %.2X %.2X %.2X %.2X %.2X\n",
2552 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
2555 * Place this address in the RAR if there is room,
2556 * else put the controller into promiscuous mode
2558 if (hw->addr_ctrl.rar_used_count < rar_entries) {
2559 rar = hw->addr_ctrl.rar_used_count;
2560 hw->mac.ops.set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
2561 DEBUGOUT1("Added a secondary address to RAR[%d]\n", rar);
2562 hw->addr_ctrl.rar_used_count++;
2564 hw->addr_ctrl.overflow_promisc++;
2567 DEBUGOUT("ixgbe_add_uc_addr Complete\n");
2571 * ixgbe_update_uc_addr_list_generic - Updates MAC list of secondary addresses
2572 * @hw: pointer to hardware structure
2573 * @addr_list: the list of new addresses
2574 * @addr_count: number of addresses
2575 * @next: iterator function to walk the address list
2577 * The given list replaces any existing list. Clears the secondary addrs from
2578 * receive address registers. Uses unused receive address registers for the
2579 * first secondary addresses, and falls back to promiscuous mode as needed.
2581 * Drivers using secondary unicast addresses must set user_set_promisc when
2582 * manually putting the device into promiscuous mode.
2584 s32 ixgbe_update_uc_addr_list_generic(struct ixgbe_hw *hw, u8 *addr_list,
2585 u32 addr_count, ixgbe_mc_addr_itr next)
2589 u32 old_promisc_setting = hw->addr_ctrl.overflow_promisc;
2594 DEBUGFUNC("ixgbe_update_uc_addr_list_generic");
2597 * Clear accounting of old secondary address list,
2598 * don't count RAR[0]
2600 uc_addr_in_use = hw->addr_ctrl.rar_used_count - 1;
2601 hw->addr_ctrl.rar_used_count -= uc_addr_in_use;
2602 hw->addr_ctrl.overflow_promisc = 0;
2604 /* Zero out the other receive addresses */
2605 DEBUGOUT1("Clearing RAR[1-%d]\n", uc_addr_in_use+1);
2606 for (i = 0; i < uc_addr_in_use; i++) {
2607 IXGBE_WRITE_REG(hw, IXGBE_RAL(1+i), 0);
2608 IXGBE_WRITE_REG(hw, IXGBE_RAH(1+i), 0);
2611 /* Add the new addresses */
2612 for (i = 0; i < addr_count; i++) {
2613 DEBUGOUT(" Adding the secondary addresses:\n");
2614 addr = next(hw, &addr_list, &vmdq);
2615 ixgbe_add_uc_addr(hw, addr, vmdq);
2618 if (hw->addr_ctrl.overflow_promisc) {
2619 /* enable promisc if not already in overflow or set by user */
2620 if (!old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
2621 DEBUGOUT(" Entering address overflow promisc mode\n");
2622 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2623 fctrl |= IXGBE_FCTRL_UPE;
2624 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2627 /* only disable if set by overflow, not by user */
2628 if (old_promisc_setting && !hw->addr_ctrl.user_set_promisc) {
2629 DEBUGOUT(" Leaving address overflow promisc mode\n");
2630 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
2631 fctrl &= ~IXGBE_FCTRL_UPE;
2632 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
2636 DEBUGOUT("ixgbe_update_uc_addr_list_generic Complete\n");
2637 return IXGBE_SUCCESS;
2641 * ixgbe_mta_vector - Determines bit-vector in multicast table to set
2642 * @hw: pointer to hardware structure
2643 * @mc_addr: the multicast address
2645 * Extracts the 12 bits, from a multicast address, to determine which
2646 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
2647 * incoming rx multicast addresses, to determine the bit-vector to check in
2648 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
2649 * by the MO field of the MCSTCTRL. The MO field is set during initialization
2650 * to mc_filter_type.
2652 static s32 ixgbe_mta_vector(struct ixgbe_hw *hw, u8 *mc_addr)
2656 DEBUGFUNC("ixgbe_mta_vector");
2658 switch (hw->mac.mc_filter_type) {
2659 case 0: /* use bits [47:36] of the address */
2660 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
2662 case 1: /* use bits [46:35] of the address */
2663 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
2665 case 2: /* use bits [45:34] of the address */
2666 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
2668 case 3: /* use bits [43:32] of the address */
2669 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
2671 default: /* Invalid mc_filter_type */
2672 DEBUGOUT("MC filter type param set incorrectly\n");
2677 /* vector can only be 12-bits or boundary will be exceeded */
2683 * ixgbe_set_mta - Set bit-vector in multicast table
2684 * @hw: pointer to hardware structure
2685 * @mc_addr: Multicast address
2687 * Sets the bit-vector in the multicast table.
2689 void ixgbe_set_mta(struct ixgbe_hw *hw, u8 *mc_addr)
2695 DEBUGFUNC("ixgbe_set_mta");
2697 hw->addr_ctrl.mta_in_use++;
2699 vector = ixgbe_mta_vector(hw, mc_addr);
2700 DEBUGOUT1(" bit-vector = 0x%03X\n", vector);
2703 * The MTA is a register array of 128 32-bit registers. It is treated
2704 * like an array of 4096 bits. We want to set bit
2705 * BitArray[vector_value]. So we figure out what register the bit is
2706 * in, read it, OR in the new bit, then write back the new value. The
2707 * register is determined by the upper 7 bits of the vector value and
2708 * the bit within that register are determined by the lower 5 bits of
2711 vector_reg = (vector >> 5) & 0x7F;
2712 vector_bit = vector & 0x1F;
2713 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
2717 * ixgbe_update_mc_addr_list_generic - Updates MAC list of multicast addresses
2718 * @hw: pointer to hardware structure
2719 * @mc_addr_list: the list of new multicast addresses
2720 * @mc_addr_count: number of addresses
2721 * @next: iterator function to walk the multicast address list
2722 * @clear: flag, when set clears the table beforehand
2724 * When the clear flag is set, the given list replaces any existing list.
2725 * Hashes the given addresses into the multicast table.
2727 s32 ixgbe_update_mc_addr_list_generic(struct ixgbe_hw *hw, u8 *mc_addr_list,
2728 u32 mc_addr_count, ixgbe_mc_addr_itr next,
2734 DEBUGFUNC("ixgbe_update_mc_addr_list_generic");
2737 * Set the new number of MC addresses that we are being requested to
2740 hw->addr_ctrl.num_mc_addrs = mc_addr_count;
2741 hw->addr_ctrl.mta_in_use = 0;
2743 /* Clear mta_shadow */
2745 DEBUGOUT(" Clearing MTA\n");
2746 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
2749 /* Update mta_shadow */
2750 for (i = 0; i < mc_addr_count; i++) {
2751 DEBUGOUT(" Adding the multicast addresses:\n");
2752 ixgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
2756 for (i = 0; i < hw->mac.mcft_size; i++)
2757 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_MTA(0), i,
2758 hw->mac.mta_shadow[i]);
2760 if (hw->addr_ctrl.mta_in_use > 0)
2761 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL,
2762 IXGBE_MCSTCTRL_MFE | hw->mac.mc_filter_type);
2764 DEBUGOUT("ixgbe_update_mc_addr_list_generic Complete\n");
2765 return IXGBE_SUCCESS;
2769 * ixgbe_enable_mc_generic - Enable multicast address in RAR
2770 * @hw: pointer to hardware structure
2772 * Enables multicast address in RAR and the use of the multicast hash table.
2774 s32 ixgbe_enable_mc_generic(struct ixgbe_hw *hw)
2776 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2778 DEBUGFUNC("ixgbe_enable_mc_generic");
2780 if (a->mta_in_use > 0)
2781 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, IXGBE_MCSTCTRL_MFE |
2782 hw->mac.mc_filter_type);
2784 return IXGBE_SUCCESS;
2788 * ixgbe_disable_mc_generic - Disable multicast address in RAR
2789 * @hw: pointer to hardware structure
2791 * Disables multicast address in RAR and the use of the multicast hash table.
2793 s32 ixgbe_disable_mc_generic(struct ixgbe_hw *hw)
2795 struct ixgbe_addr_filter_info *a = &hw->addr_ctrl;
2797 DEBUGFUNC("ixgbe_disable_mc_generic");
2799 if (a->mta_in_use > 0)
2800 IXGBE_WRITE_REG(hw, IXGBE_MCSTCTRL, hw->mac.mc_filter_type);
2802 return IXGBE_SUCCESS;
2806 * ixgbe_fc_enable_generic - Enable flow control
2807 * @hw: pointer to hardware structure
2809 * Enable flow control according to the current settings.
2811 s32 ixgbe_fc_enable_generic(struct ixgbe_hw *hw)
2813 s32 ret_val = IXGBE_SUCCESS;
2814 u32 mflcn_reg, fccfg_reg;
2819 DEBUGFUNC("ixgbe_fc_enable_generic");
2821 /* Validate the water mark configuration */
2822 if (!hw->fc.pause_time) {
2823 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2827 /* Low water mark of zero causes XOFF floods */
2828 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2829 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2830 hw->fc.high_water[i]) {
2831 if (!hw->fc.low_water[i] ||
2832 hw->fc.low_water[i] >= hw->fc.high_water[i]) {
2833 DEBUGOUT("Invalid water mark configuration\n");
2834 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2840 /* Negotiate the fc mode to use */
2841 hw->mac.ops.fc_autoneg(hw);
2843 /* Disable any previous flow control settings */
2844 mflcn_reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
2845 mflcn_reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
2847 fccfg_reg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
2848 fccfg_reg &= ~(IXGBE_FCCFG_TFCE_802_3X | IXGBE_FCCFG_TFCE_PRIORITY);
2851 * The possible values of fc.current_mode are:
2852 * 0: Flow control is completely disabled
2853 * 1: Rx flow control is enabled (we can receive pause frames,
2854 * but not send pause frames).
2855 * 2: Tx flow control is enabled (we can send pause frames but
2856 * we do not support receiving pause frames).
2857 * 3: Both Rx and Tx flow control (symmetric) are enabled.
2860 switch (hw->fc.current_mode) {
2863 * Flow control is disabled by software override or autoneg.
2864 * The code below will actually disable it in the HW.
2867 case ixgbe_fc_rx_pause:
2869 * Rx Flow control is enabled and Tx Flow control is
2870 * disabled by software override. Since there really
2871 * isn't a way to advertise that we are capable of RX
2872 * Pause ONLY, we will advertise that we support both
2873 * symmetric and asymmetric Rx PAUSE. Later, we will
2874 * disable the adapter's ability to send PAUSE frames.
2876 mflcn_reg |= IXGBE_MFLCN_RFCE;
2878 case ixgbe_fc_tx_pause:
2880 * Tx Flow control is enabled, and Rx Flow control is
2881 * disabled by software override.
2883 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2886 /* Flow control (both Rx and Tx) is enabled by SW override. */
2887 mflcn_reg |= IXGBE_MFLCN_RFCE;
2888 fccfg_reg |= IXGBE_FCCFG_TFCE_802_3X;
2891 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
2892 "Flow control param set incorrectly\n");
2893 ret_val = IXGBE_ERR_CONFIG;
2898 /* Set 802.3x based flow control settings. */
2899 mflcn_reg |= IXGBE_MFLCN_DPF;
2900 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, mflcn_reg);
2901 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, fccfg_reg);
2904 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
2905 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
2906 if ((hw->fc.current_mode & ixgbe_fc_tx_pause) &&
2907 hw->fc.high_water[i]) {
2908 fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
2909 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
2910 fcrth = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
2912 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
2914 * In order to prevent Tx hangs when the internal Tx
2915 * switch is enabled we must set the high water mark
2916 * to the Rx packet buffer size - 24KB. This allows
2917 * the Tx switch to function even under heavy Rx
2920 fcrth = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 24576;
2923 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), fcrth);
2926 /* Configure pause time (2 TCs per register) */
2927 reg = hw->fc.pause_time * 0x00010001;
2928 for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
2929 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
2931 /* Configure flow control refresh threshold value */
2932 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
2939 * ixgbe_negotiate_fc - Negotiate flow control
2940 * @hw: pointer to hardware structure
2941 * @adv_reg: flow control advertised settings
2942 * @lp_reg: link partner's flow control settings
2943 * @adv_sym: symmetric pause bit in advertisement
2944 * @adv_asm: asymmetric pause bit in advertisement
2945 * @lp_sym: symmetric pause bit in link partner advertisement
2946 * @lp_asm: asymmetric pause bit in link partner advertisement
2948 * Find the intersection between advertised settings and link partner's
2949 * advertised settings
2951 s32 ixgbe_negotiate_fc(struct ixgbe_hw *hw, u32 adv_reg, u32 lp_reg,
2952 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
2954 if ((!(adv_reg)) || (!(lp_reg))) {
2955 ERROR_REPORT3(IXGBE_ERROR_UNSUPPORTED,
2956 "Local or link partner's advertised flow control "
2957 "settings are NULL. Local: %x, link partner: %x\n",
2959 return IXGBE_ERR_FC_NOT_NEGOTIATED;
2962 if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
2964 * Now we need to check if the user selected Rx ONLY
2965 * of pause frames. In this case, we had to advertise
2966 * FULL flow control because we could not advertise RX
2967 * ONLY. Hence, we must now check to see if we need to
2968 * turn OFF the TRANSMISSION of PAUSE frames.
2970 if (hw->fc.requested_mode == ixgbe_fc_full) {
2971 hw->fc.current_mode = ixgbe_fc_full;
2972 DEBUGOUT("Flow Control = FULL.\n");
2974 hw->fc.current_mode = ixgbe_fc_rx_pause;
2975 DEBUGOUT("Flow Control=RX PAUSE frames only\n");
2977 } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2978 (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2979 hw->fc.current_mode = ixgbe_fc_tx_pause;
2980 DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
2981 } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
2982 !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
2983 hw->fc.current_mode = ixgbe_fc_rx_pause;
2984 DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
2986 hw->fc.current_mode = ixgbe_fc_none;
2987 DEBUGOUT("Flow Control = NONE.\n");
2989 return IXGBE_SUCCESS;
2993 * ixgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
2994 * @hw: pointer to hardware structure
2996 * Enable flow control according on 1 gig fiber.
2998 static s32 ixgbe_fc_autoneg_fiber(struct ixgbe_hw *hw)
3000 u32 pcs_anadv_reg, pcs_lpab_reg, linkstat;
3001 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
3004 * On multispeed fiber at 1g, bail out if
3005 * - link is up but AN did not complete, or if
3006 * - link is up and AN completed but timed out
3009 linkstat = IXGBE_READ_REG(hw, IXGBE_PCS1GLSTA);
3010 if ((!!(linkstat & IXGBE_PCS1GLSTA_AN_COMPLETE) == 0) ||
3011 (!!(linkstat & IXGBE_PCS1GLSTA_AN_TIMED_OUT) == 1)) {
3012 DEBUGOUT("Auto-Negotiation did not complete or timed out\n");
3016 pcs_anadv_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANA);
3017 pcs_lpab_reg = IXGBE_READ_REG(hw, IXGBE_PCS1GANLP);
3019 ret_val = ixgbe_negotiate_fc(hw, pcs_anadv_reg,
3020 pcs_lpab_reg, IXGBE_PCS1GANA_SYM_PAUSE,
3021 IXGBE_PCS1GANA_ASM_PAUSE,
3022 IXGBE_PCS1GANA_SYM_PAUSE,
3023 IXGBE_PCS1GANA_ASM_PAUSE);
3030 * ixgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
3031 * @hw: pointer to hardware structure
3033 * Enable flow control according to IEEE clause 37.
3035 static s32 ixgbe_fc_autoneg_backplane(struct ixgbe_hw *hw)
3037 u32 links2, anlp1_reg, autoc_reg, links;
3038 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
3041 * On backplane, bail out if
3042 * - backplane autoneg was not completed, or if
3043 * - we are 82599 and link partner is not AN enabled
3045 links = IXGBE_READ_REG(hw, IXGBE_LINKS);
3046 if ((links & IXGBE_LINKS_KX_AN_COMP) == 0) {
3047 DEBUGOUT("Auto-Negotiation did not complete\n");
3051 if (hw->mac.type == ixgbe_mac_82599EB) {
3052 links2 = IXGBE_READ_REG(hw, IXGBE_LINKS2);
3053 if ((links2 & IXGBE_LINKS2_AN_SUPPORTED) == 0) {
3054 DEBUGOUT("Link partner is not AN enabled\n");
3059 * Read the 10g AN autoc and LP ability registers and resolve
3060 * local flow control settings accordingly
3062 autoc_reg = IXGBE_READ_REG(hw, IXGBE_AUTOC);
3063 anlp1_reg = IXGBE_READ_REG(hw, IXGBE_ANLP1);
3065 ret_val = ixgbe_negotiate_fc(hw, autoc_reg,
3066 anlp1_reg, IXGBE_AUTOC_SYM_PAUSE, IXGBE_AUTOC_ASM_PAUSE,
3067 IXGBE_ANLP1_SYM_PAUSE, IXGBE_ANLP1_ASM_PAUSE);
3074 * ixgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
3075 * @hw: pointer to hardware structure
3077 * Enable flow control according to IEEE clause 37.
3079 static s32 ixgbe_fc_autoneg_copper(struct ixgbe_hw *hw)
3081 u16 technology_ability_reg = 0;
3082 u16 lp_technology_ability_reg = 0;
3084 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_ADVT,
3085 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
3086 &technology_ability_reg);
3087 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_LP,
3088 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
3089 &lp_technology_ability_reg);
3091 return ixgbe_negotiate_fc(hw, (u32)technology_ability_reg,
3092 (u32)lp_technology_ability_reg,
3093 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE,
3094 IXGBE_TAF_SYM_PAUSE, IXGBE_TAF_ASM_PAUSE);
3098 * ixgbe_fc_autoneg - Configure flow control
3099 * @hw: pointer to hardware structure
3101 * Compares our advertised flow control capabilities to those advertised by
3102 * our link partner, and determines the proper flow control mode to use.
3104 void ixgbe_fc_autoneg(struct ixgbe_hw *hw)
3106 s32 ret_val = IXGBE_ERR_FC_NOT_NEGOTIATED;
3107 ixgbe_link_speed speed;
3110 DEBUGFUNC("ixgbe_fc_autoneg");
3113 * AN should have completed when the cable was plugged in.
3114 * Look for reasons to bail out. Bail out if:
3115 * - FC autoneg is disabled, or if
3118 if (hw->fc.disable_fc_autoneg) {
3119 /* TODO: This should be just an informative log */
3120 ERROR_REPORT1(IXGBE_ERROR_CAUTION,
3121 "Flow control autoneg is disabled");
3125 hw->mac.ops.check_link(hw, &speed, &link_up, false);
3127 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE, "The link is down");
3131 switch (hw->phy.media_type) {
3132 /* Autoneg flow control on fiber adapters */
3133 case ixgbe_media_type_fiber_fixed:
3134 case ixgbe_media_type_fiber_qsfp:
3135 case ixgbe_media_type_fiber:
3136 if (speed == IXGBE_LINK_SPEED_1GB_FULL)
3137 ret_val = ixgbe_fc_autoneg_fiber(hw);
3140 /* Autoneg flow control on backplane adapters */
3141 case ixgbe_media_type_backplane:
3142 ret_val = ixgbe_fc_autoneg_backplane(hw);
3145 /* Autoneg flow control on copper adapters */
3146 case ixgbe_media_type_copper:
3147 if (ixgbe_device_supports_autoneg_fc(hw))
3148 ret_val = ixgbe_fc_autoneg_copper(hw);
3156 if (ret_val == IXGBE_SUCCESS) {
3157 hw->fc.fc_was_autonegged = true;
3159 hw->fc.fc_was_autonegged = false;
3160 hw->fc.current_mode = hw->fc.requested_mode;
3165 * ixgbe_pcie_timeout_poll - Return number of times to poll for completion
3166 * @hw: pointer to hardware structure
3168 * System-wide timeout range is encoded in PCIe Device Control2 register.
3170 * Add 10% to specified maximum and return the number of times to poll for
3171 * completion timeout, in units of 100 microsec. Never return less than
3172 * 800 = 80 millisec.
3174 static u32 ixgbe_pcie_timeout_poll(struct ixgbe_hw *hw)
3179 devctl2 = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_CONTROL2);
3180 devctl2 &= IXGBE_PCIDEVCTRL2_TIMEO_MASK;
3183 case IXGBE_PCIDEVCTRL2_65_130ms:
3184 pollcnt = 1300; /* 130 millisec */
3186 case IXGBE_PCIDEVCTRL2_260_520ms:
3187 pollcnt = 5200; /* 520 millisec */
3189 case IXGBE_PCIDEVCTRL2_1_2s:
3190 pollcnt = 20000; /* 2 sec */
3192 case IXGBE_PCIDEVCTRL2_4_8s:
3193 pollcnt = 80000; /* 8 sec */
3195 case IXGBE_PCIDEVCTRL2_17_34s:
3196 pollcnt = 34000; /* 34 sec */
3198 case IXGBE_PCIDEVCTRL2_50_100us: /* 100 microsecs */
3199 case IXGBE_PCIDEVCTRL2_1_2ms: /* 2 millisecs */
3200 case IXGBE_PCIDEVCTRL2_16_32ms: /* 32 millisec */
3201 case IXGBE_PCIDEVCTRL2_16_32ms_def: /* 32 millisec default */
3203 pollcnt = 800; /* 80 millisec minimum */
3207 /* add 10% to spec maximum */
3208 return (pollcnt * 11) / 10;
3212 * ixgbe_disable_pcie_master - Disable PCI-express master access
3213 * @hw: pointer to hardware structure
3215 * Disables PCI-Express master access and verifies there are no pending
3216 * requests. IXGBE_ERR_MASTER_REQUESTS_PENDING is returned if master disable
3217 * bit hasn't caused the master requests to be disabled, else IXGBE_SUCCESS
3218 * is returned signifying master requests disabled.
3220 s32 ixgbe_disable_pcie_master(struct ixgbe_hw *hw)
3222 s32 status = IXGBE_SUCCESS;
3226 DEBUGFUNC("ixgbe_disable_pcie_master");
3228 /* Always set this bit to ensure any future transactions are blocked */
3229 IXGBE_WRITE_REG(hw, IXGBE_CTRL, IXGBE_CTRL_GIO_DIS);
3231 /* Exit if master requests are blocked */
3232 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO) ||
3233 IXGBE_REMOVED(hw->hw_addr))
3236 /* Poll for master request bit to clear */
3237 for (i = 0; i < IXGBE_PCI_MASTER_DISABLE_TIMEOUT; i++) {
3239 if (!(IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_GIO))
3244 * Two consecutive resets are required via CTRL.RST per datasheet
3245 * 5.2.5.3.2 Master Disable. We set a flag to inform the reset routine
3246 * of this need. The first reset prevents new master requests from
3247 * being issued by our device. We then must wait 1usec or more for any
3248 * remaining completions from the PCIe bus to trickle in, and then reset
3249 * again to clear out any effects they may have had on our device.
3251 DEBUGOUT("GIO Master Disable bit didn't clear - requesting resets\n");
3252 hw->mac.flags |= IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
3254 if (hw->mac.type >= ixgbe_mac_X550)
3258 * Before proceeding, make sure that the PCIe block does not have
3259 * transactions pending.
3261 poll = ixgbe_pcie_timeout_poll(hw);
3262 for (i = 0; i < poll; i++) {
3264 value = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS);
3265 if (IXGBE_REMOVED(hw->hw_addr))
3267 if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
3271 ERROR_REPORT1(IXGBE_ERROR_POLLING,
3272 "PCIe transaction pending bit also did not clear.\n");
3273 status = IXGBE_ERR_MASTER_REQUESTS_PENDING;
3280 * ixgbe_acquire_swfw_sync - Acquire SWFW semaphore
3281 * @hw: pointer to hardware structure
3282 * @mask: Mask to specify which semaphore to acquire
3284 * Acquires the SWFW semaphore through the GSSR register for the specified
3285 * function (CSR, PHY0, PHY1, EEPROM, Flash)
3287 s32 ixgbe_acquire_swfw_sync(struct ixgbe_hw *hw, u32 mask)
3291 u32 fwmask = mask << 5;
3295 DEBUGFUNC("ixgbe_acquire_swfw_sync");
3297 for (i = 0; i < timeout; i++) {
3299 * SW NVM semaphore bit is used for access to all
3300 * SW_FW_SYNC bits (not just NVM)
3302 if (ixgbe_get_eeprom_semaphore(hw))
3303 return IXGBE_ERR_SWFW_SYNC;
3305 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
3306 if (!(gssr & (fwmask | swmask))) {
3308 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
3309 ixgbe_release_eeprom_semaphore(hw);
3310 return IXGBE_SUCCESS;
3312 /* Resource is currently in use by FW or SW */
3313 ixgbe_release_eeprom_semaphore(hw);
3318 /* If time expired clear the bits holding the lock and retry */
3319 if (gssr & (fwmask | swmask))
3320 ixgbe_release_swfw_sync(hw, gssr & (fwmask | swmask));
3323 return IXGBE_ERR_SWFW_SYNC;
3327 * ixgbe_release_swfw_sync - Release SWFW semaphore
3328 * @hw: pointer to hardware structure
3329 * @mask: Mask to specify which semaphore to release
3331 * Releases the SWFW semaphore through the GSSR register for the specified
3332 * function (CSR, PHY0, PHY1, EEPROM, Flash)
3334 void ixgbe_release_swfw_sync(struct ixgbe_hw *hw, u32 mask)
3339 DEBUGFUNC("ixgbe_release_swfw_sync");
3341 ixgbe_get_eeprom_semaphore(hw);
3343 gssr = IXGBE_READ_REG(hw, IXGBE_GSSR);
3345 IXGBE_WRITE_REG(hw, IXGBE_GSSR, gssr);
3347 ixgbe_release_eeprom_semaphore(hw);
3351 * ixgbe_disable_sec_rx_path_generic - Stops the receive data path
3352 * @hw: pointer to hardware structure
3354 * Stops the receive data path and waits for the HW to internally empty
3355 * the Rx security block
3357 s32 ixgbe_disable_sec_rx_path_generic(struct ixgbe_hw *hw)
3359 #define IXGBE_MAX_SECRX_POLL 4000
3364 DEBUGFUNC("ixgbe_disable_sec_rx_path_generic");
3367 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
3368 secrxreg |= IXGBE_SECRXCTRL_RX_DIS;
3369 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
3370 for (i = 0; i < IXGBE_MAX_SECRX_POLL; i++) {
3371 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXSTAT);
3372 if (secrxreg & IXGBE_SECRXSTAT_SECRX_RDY)
3375 /* Use interrupt-safe sleep just in case */
3379 /* For informational purposes only */
3380 if (i >= IXGBE_MAX_SECRX_POLL)
3381 DEBUGOUT("Rx unit being enabled before security "
3382 "path fully disabled. Continuing with init.\n");
3384 return IXGBE_SUCCESS;
3388 * prot_autoc_read_generic - Hides MAC differences needed for AUTOC read
3389 * @hw: pointer to hardware structure
3390 * @locked: bool to indicate whether the SW/FW lock was taken
3391 * @reg_val: Value we read from AUTOC
3393 * The default case requires no protection so just to the register read.
3395 s32 prot_autoc_read_generic(struct ixgbe_hw *hw, bool *locked, u32 *reg_val)
3398 *reg_val = IXGBE_READ_REG(hw, IXGBE_AUTOC);
3399 return IXGBE_SUCCESS;
3403 * prot_autoc_write_generic - Hides MAC differences needed for AUTOC write
3404 * @hw: pointer to hardware structure
3405 * @reg_val: value to write to AUTOC
3406 * @locked: bool to indicate whether the SW/FW lock was already taken by
3409 * The default case requires no protection so just to the register write.
3411 s32 prot_autoc_write_generic(struct ixgbe_hw *hw, u32 reg_val, bool locked)
3413 UNREFERENCED_1PARAMETER(locked);
3415 IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_val);
3416 return IXGBE_SUCCESS;
3420 * ixgbe_enable_sec_rx_path_generic - Enables the receive data path
3421 * @hw: pointer to hardware structure
3423 * Enables the receive data path.
3425 s32 ixgbe_enable_sec_rx_path_generic(struct ixgbe_hw *hw)
3429 DEBUGFUNC("ixgbe_enable_sec_rx_path_generic");
3431 secrxreg = IXGBE_READ_REG(hw, IXGBE_SECRXCTRL);
3432 secrxreg &= ~IXGBE_SECRXCTRL_RX_DIS;
3433 IXGBE_WRITE_REG(hw, IXGBE_SECRXCTRL, secrxreg);
3434 IXGBE_WRITE_FLUSH(hw);
3436 return IXGBE_SUCCESS;
3440 * ixgbe_enable_rx_dma_generic - Enable the Rx DMA unit
3441 * @hw: pointer to hardware structure
3442 * @regval: register value to write to RXCTRL
3444 * Enables the Rx DMA unit
3446 s32 ixgbe_enable_rx_dma_generic(struct ixgbe_hw *hw, u32 regval)
3448 DEBUGFUNC("ixgbe_enable_rx_dma_generic");
3450 if (regval & IXGBE_RXCTRL_RXEN)
3451 ixgbe_enable_rx(hw);
3453 ixgbe_disable_rx(hw);
3455 return IXGBE_SUCCESS;
3459 * ixgbe_blink_led_start_generic - Blink LED based on index.
3460 * @hw: pointer to hardware structure
3461 * @index: led number to blink
3463 s32 ixgbe_blink_led_start_generic(struct ixgbe_hw *hw, u32 index)
3465 ixgbe_link_speed speed = 0;
3468 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
3469 s32 ret_val = IXGBE_SUCCESS;
3470 bool locked = false;
3472 DEBUGFUNC("ixgbe_blink_led_start_generic");
3475 return IXGBE_ERR_PARAM;
3478 * Link must be up to auto-blink the LEDs;
3479 * Force it if link is down.
3481 hw->mac.ops.check_link(hw, &speed, &link_up, false);
3484 ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg);
3485 if (ret_val != IXGBE_SUCCESS)
3488 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
3489 autoc_reg |= IXGBE_AUTOC_FLU;
3491 ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked);
3492 if (ret_val != IXGBE_SUCCESS)
3495 IXGBE_WRITE_FLUSH(hw);
3499 led_reg &= ~IXGBE_LED_MODE_MASK(index);
3500 led_reg |= IXGBE_LED_BLINK(index);
3501 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
3502 IXGBE_WRITE_FLUSH(hw);
3509 * ixgbe_blink_led_stop_generic - Stop blinking LED based on index.
3510 * @hw: pointer to hardware structure
3511 * @index: led number to stop blinking
3513 s32 ixgbe_blink_led_stop_generic(struct ixgbe_hw *hw, u32 index)
3516 u32 led_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
3517 s32 ret_val = IXGBE_SUCCESS;
3518 bool locked = false;
3520 DEBUGFUNC("ixgbe_blink_led_stop_generic");
3523 return IXGBE_ERR_PARAM;
3525 ret_val = hw->mac.ops.prot_autoc_read(hw, &locked, &autoc_reg);
3526 if (ret_val != IXGBE_SUCCESS)
3529 autoc_reg &= ~IXGBE_AUTOC_FLU;
3530 autoc_reg |= IXGBE_AUTOC_AN_RESTART;
3532 ret_val = hw->mac.ops.prot_autoc_write(hw, autoc_reg, locked);
3533 if (ret_val != IXGBE_SUCCESS)
3536 led_reg &= ~IXGBE_LED_MODE_MASK(index);
3537 led_reg &= ~IXGBE_LED_BLINK(index);
3538 led_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
3539 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, led_reg);
3540 IXGBE_WRITE_FLUSH(hw);
3547 * ixgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
3548 * @hw: pointer to hardware structure
3549 * @san_mac_offset: SAN MAC address offset
3551 * This function will read the EEPROM location for the SAN MAC address
3552 * pointer, and returns the value at that location. This is used in both
3553 * get and set mac_addr routines.
3555 static s32 ixgbe_get_san_mac_addr_offset(struct ixgbe_hw *hw,
3556 u16 *san_mac_offset)
3560 DEBUGFUNC("ixgbe_get_san_mac_addr_offset");
3563 * First read the EEPROM pointer to see if the MAC addresses are
3566 ret_val = hw->eeprom.ops.read(hw, IXGBE_SAN_MAC_ADDR_PTR,
3569 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
3570 "eeprom at offset %d failed",
3571 IXGBE_SAN_MAC_ADDR_PTR);
3578 * ixgbe_get_san_mac_addr_generic - SAN MAC address retrieval from the EEPROM
3579 * @hw: pointer to hardware structure
3580 * @san_mac_addr: SAN MAC address
3582 * Reads the SAN MAC address from the EEPROM, if it's available. This is
3583 * per-port, so set_lan_id() must be called before reading the addresses.
3584 * set_lan_id() is called by identify_sfp(), but this cannot be relied
3585 * upon for non-SFP connections, so we must call it here.
3587 s32 ixgbe_get_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
3589 u16 san_mac_data, san_mac_offset;
3593 DEBUGFUNC("ixgbe_get_san_mac_addr_generic");
3596 * First read the EEPROM pointer to see if the MAC addresses are
3597 * available. If they're not, no point in calling set_lan_id() here.
3599 ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
3600 if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
3601 goto san_mac_addr_out;
3603 /* make sure we know which port we need to program */
3604 hw->mac.ops.set_lan_id(hw);
3605 /* apply the port offset to the address offset */
3606 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
3607 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
3608 for (i = 0; i < 3; i++) {
3609 ret_val = hw->eeprom.ops.read(hw, san_mac_offset,
3612 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
3613 "eeprom read at offset %d failed",
3615 goto san_mac_addr_out;
3617 san_mac_addr[i * 2] = (u8)(san_mac_data);
3618 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
3621 return IXGBE_SUCCESS;
3625 * No addresses available in this EEPROM. It's not an
3626 * error though, so just wipe the local address and return.
3628 for (i = 0; i < 6; i++)
3629 san_mac_addr[i] = 0xFF;
3630 return IXGBE_SUCCESS;
3634 * ixgbe_set_san_mac_addr_generic - Write the SAN MAC address to the EEPROM
3635 * @hw: pointer to hardware structure
3636 * @san_mac_addr: SAN MAC address
3638 * Write a SAN MAC address to the EEPROM.
3640 s32 ixgbe_set_san_mac_addr_generic(struct ixgbe_hw *hw, u8 *san_mac_addr)
3643 u16 san_mac_data, san_mac_offset;
3646 DEBUGFUNC("ixgbe_set_san_mac_addr_generic");
3648 /* Look for SAN mac address pointer. If not defined, return */
3649 ret_val = ixgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
3650 if (ret_val || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
3651 return IXGBE_ERR_NO_SAN_ADDR_PTR;
3653 /* Make sure we know which port we need to write */
3654 hw->mac.ops.set_lan_id(hw);
3655 /* Apply the port offset to the address offset */
3656 (hw->bus.func) ? (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
3657 (san_mac_offset += IXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
3659 for (i = 0; i < 3; i++) {
3660 san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
3661 san_mac_data |= (u16)(san_mac_addr[i * 2]);
3662 hw->eeprom.ops.write(hw, san_mac_offset, san_mac_data);
3666 return IXGBE_SUCCESS;
3670 * ixgbe_get_pcie_msix_count_generic - Gets MSI-X vector count
3671 * @hw: pointer to hardware structure
3673 * Read PCIe configuration space, and get the MSI-X vector count from
3674 * the capabilities table.
3676 u16 ixgbe_get_pcie_msix_count_generic(struct ixgbe_hw *hw)
3682 switch (hw->mac.type) {
3683 case ixgbe_mac_82598EB:
3684 pcie_offset = IXGBE_PCIE_MSIX_82598_CAPS;
3685 max_msix_count = IXGBE_MAX_MSIX_VECTORS_82598;
3687 case ixgbe_mac_82599EB:
3688 case ixgbe_mac_X540:
3689 case ixgbe_mac_X550:
3690 case ixgbe_mac_X550EM_x:
3691 case ixgbe_mac_X550EM_a:
3692 pcie_offset = IXGBE_PCIE_MSIX_82599_CAPS;
3693 max_msix_count = IXGBE_MAX_MSIX_VECTORS_82599;
3699 DEBUGFUNC("ixgbe_get_pcie_msix_count_generic");
3700 msix_count = IXGBE_READ_PCIE_WORD(hw, pcie_offset);
3701 if (IXGBE_REMOVED(hw->hw_addr))
3703 msix_count &= IXGBE_PCIE_MSIX_TBL_SZ_MASK;
3705 /* MSI-X count is zero-based in HW */
3708 if (msix_count > max_msix_count)
3709 msix_count = max_msix_count;
3715 * ixgbe_insert_mac_addr_generic - Find a RAR for this mac address
3716 * @hw: pointer to hardware structure
3717 * @addr: Address to put into receive address register
3718 * @vmdq: VMDq pool to assign
3720 * Puts an ethernet address into a receive address register, or
3721 * finds the rar that it is already in; adds to the pool list
3723 s32 ixgbe_insert_mac_addr_generic(struct ixgbe_hw *hw, u8 *addr, u32 vmdq)
3725 static const u32 NO_EMPTY_RAR_FOUND = 0xFFFFFFFF;
3726 u32 first_empty_rar = NO_EMPTY_RAR_FOUND;
3728 u32 rar_low, rar_high;
3729 u32 addr_low, addr_high;
3731 DEBUGFUNC("ixgbe_insert_mac_addr_generic");
3733 /* swap bytes for HW little endian */
3734 addr_low = addr[0] | (addr[1] << 8)
3737 addr_high = addr[4] | (addr[5] << 8);
3740 * Either find the mac_id in rar or find the first empty space.
3741 * rar_highwater points to just after the highest currently used
3742 * rar in order to shorten the search. It grows when we add a new
3745 for (rar = 0; rar < hw->mac.rar_highwater; rar++) {
3746 rar_high = IXGBE_READ_REG(hw, IXGBE_RAH(rar));
3748 if (((IXGBE_RAH_AV & rar_high) == 0)
3749 && first_empty_rar == NO_EMPTY_RAR_FOUND) {
3750 first_empty_rar = rar;
3751 } else if ((rar_high & 0xFFFF) == addr_high) {
3752 rar_low = IXGBE_READ_REG(hw, IXGBE_RAL(rar));
3753 if (rar_low == addr_low)
3754 break; /* found it already in the rars */
3758 if (rar < hw->mac.rar_highwater) {
3759 /* already there so just add to the pool bits */
3760 ixgbe_set_vmdq(hw, rar, vmdq);
3761 } else if (first_empty_rar != NO_EMPTY_RAR_FOUND) {
3762 /* stick it into first empty RAR slot we found */
3763 rar = first_empty_rar;
3764 ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
3765 } else if (rar == hw->mac.rar_highwater) {
3766 /* add it to the top of the list and inc the highwater mark */
3767 ixgbe_set_rar(hw, rar, addr, vmdq, IXGBE_RAH_AV);
3768 hw->mac.rar_highwater++;
3769 } else if (rar >= hw->mac.num_rar_entries) {
3770 return IXGBE_ERR_INVALID_MAC_ADDR;
3774 * If we found rar[0], make sure the default pool bit (we use pool 0)
3775 * remains cleared to be sure default pool packets will get delivered
3778 ixgbe_clear_vmdq(hw, rar, 0);
3784 * ixgbe_clear_vmdq_generic - Disassociate a VMDq pool index from a rx address
3785 * @hw: pointer to hardware struct
3786 * @rar: receive address register index to disassociate
3787 * @vmdq: VMDq pool index to remove from the rar
3789 s32 ixgbe_clear_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
3791 u32 mpsar_lo, mpsar_hi;
3792 u32 rar_entries = hw->mac.num_rar_entries;
3794 DEBUGFUNC("ixgbe_clear_vmdq_generic");
3796 /* Make sure we are using a valid rar index range */
3797 if (rar >= rar_entries) {
3798 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
3799 "RAR index %d is out of range.\n", rar);
3800 return IXGBE_ERR_INVALID_ARGUMENT;
3803 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3804 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3806 if (IXGBE_REMOVED(hw->hw_addr))
3809 if (!mpsar_lo && !mpsar_hi)
3812 if (vmdq == IXGBE_CLEAR_VMDQ_ALL) {
3814 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
3815 mpsar_lo = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3818 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
3819 mpsar_hi = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3821 } else if (vmdq < 32) {
3822 mpsar_lo &= ~(1 << vmdq);
3823 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar_lo);
3825 mpsar_hi &= ~(1 << (vmdq - 32));
3826 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar_hi);
3829 /* was that the last pool using this rar? */
3830 if (mpsar_lo == 0 && mpsar_hi == 0 &&
3831 rar != 0 && rar != hw->mac.san_mac_rar_index)
3832 hw->mac.ops.clear_rar(hw, rar);
3834 return IXGBE_SUCCESS;
3838 * ixgbe_set_vmdq_generic - Associate a VMDq pool index with a rx address
3839 * @hw: pointer to hardware struct
3840 * @rar: receive address register index to associate with a VMDq index
3841 * @vmdq: VMDq pool index
3843 s32 ixgbe_set_vmdq_generic(struct ixgbe_hw *hw, u32 rar, u32 vmdq)
3846 u32 rar_entries = hw->mac.num_rar_entries;
3848 DEBUGFUNC("ixgbe_set_vmdq_generic");
3850 /* Make sure we are using a valid rar index range */
3851 if (rar >= rar_entries) {
3852 ERROR_REPORT2(IXGBE_ERROR_ARGUMENT,
3853 "RAR index %d is out of range.\n", rar);
3854 return IXGBE_ERR_INVALID_ARGUMENT;
3858 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_LO(rar));
3860 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), mpsar);
3862 mpsar = IXGBE_READ_REG(hw, IXGBE_MPSAR_HI(rar));
3863 mpsar |= 1 << (vmdq - 32);
3864 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), mpsar);
3866 return IXGBE_SUCCESS;
3870 * This function should only be involved in the IOV mode.
3871 * In IOV mode, Default pool is next pool after the number of
3872 * VFs advertized and not 0.
3873 * MPSAR table needs to be updated for SAN_MAC RAR [hw->mac.san_mac_rar_index]
3875 * ixgbe_set_vmdq_san_mac - Associate default VMDq pool index with a rx address
3876 * @hw: pointer to hardware struct
3877 * @vmdq: VMDq pool index
3879 s32 ixgbe_set_vmdq_san_mac_generic(struct ixgbe_hw *hw, u32 vmdq)
3881 u32 rar = hw->mac.san_mac_rar_index;
3883 DEBUGFUNC("ixgbe_set_vmdq_san_mac");
3886 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 1 << vmdq);
3887 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 0);
3889 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_LO(rar), 0);
3890 IXGBE_WRITE_REG(hw, IXGBE_MPSAR_HI(rar), 1 << (vmdq - 32));
3893 return IXGBE_SUCCESS;
3897 * ixgbe_init_uta_tables_generic - Initialize the Unicast Table Array
3898 * @hw: pointer to hardware structure
3900 s32 ixgbe_init_uta_tables_generic(struct ixgbe_hw *hw)
3904 DEBUGFUNC("ixgbe_init_uta_tables_generic");
3905 DEBUGOUT(" Clearing UTA\n");
3907 for (i = 0; i < 128; i++)
3908 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), 0);
3910 return IXGBE_SUCCESS;
3914 * ixgbe_find_vlvf_slot - find the vlanid or the first empty slot
3915 * @hw: pointer to hardware structure
3916 * @vlan: VLAN id to write to VLAN filter
3917 * @vlvf_bypass: true to find vlanid only, false returns first empty slot if
3921 * return the VLVF index where this VLAN id should be placed
3924 s32 ixgbe_find_vlvf_slot(struct ixgbe_hw *hw, u32 vlan, bool vlvf_bypass)
3926 s32 regindex, first_empty_slot;
3929 /* short cut the special case */
3933 /* if vlvf_bypass is set we don't want to use an empty slot, we
3934 * will simply bypass the VLVF if there are no entries present in the
3935 * VLVF that contain our VLAN
3937 first_empty_slot = vlvf_bypass ? IXGBE_ERR_NO_SPACE : 0;
3939 /* add VLAN enable bit for comparison */
3940 vlan |= IXGBE_VLVF_VIEN;
3942 /* Search for the vlan id in the VLVF entries. Save off the first empty
3943 * slot found along the way.
3945 * pre-decrement loop covering (IXGBE_VLVF_ENTRIES - 1) .. 1
3947 for (regindex = IXGBE_VLVF_ENTRIES; --regindex;) {
3948 bits = IXGBE_READ_REG(hw, IXGBE_VLVF(regindex));
3951 if (!first_empty_slot && !bits)
3952 first_empty_slot = regindex;
3955 /* If we are here then we didn't find the VLAN. Return first empty
3956 * slot we found during our search, else error.
3958 if (!first_empty_slot)
3959 ERROR_REPORT1(IXGBE_ERROR_SOFTWARE, "No space in VLVF.\n");
3961 return first_empty_slot ? first_empty_slot : IXGBE_ERR_NO_SPACE;
3965 * ixgbe_set_vfta_generic - Set VLAN filter table
3966 * @hw: pointer to hardware structure
3967 * @vlan: VLAN id to write to VLAN filter
3968 * @vind: VMDq output index that maps queue to VLAN id in VLVFB
3969 * @vlan_on: boolean flag to turn on/off VLAN
3970 * @vlvf_bypass: boolean flag indicating updating default pool is okay
3972 * Turn on/off specified VLAN in the VLAN filter table.
3974 s32 ixgbe_set_vfta_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
3975 bool vlan_on, bool vlvf_bypass)
3977 u32 regidx, vfta_delta, vfta;
3980 DEBUGFUNC("ixgbe_set_vfta_generic");
3982 if (vlan > 4095 || vind > 63)
3983 return IXGBE_ERR_PARAM;
3986 * this is a 2 part operation - first the VFTA, then the
3987 * VLVF and VLVFB if VT Mode is set
3988 * We don't write the VFTA until we know the VLVF part succeeded.
3992 * The VFTA is a bitstring made up of 128 32-bit registers
3993 * that enable the particular VLAN id, much like the MTA:
3994 * bits[11-5]: which register
3995 * bits[4-0]: which bit in the register
3998 vfta_delta = 1 << (vlan % 32);
3999 vfta = IXGBE_READ_REG(hw, IXGBE_VFTA(regidx));
4002 * vfta_delta represents the difference between the current value
4003 * of vfta and the value we want in the register. Since the diff
4004 * is an XOR mask we can just update the vfta using an XOR
4006 vfta_delta &= vlan_on ? ~vfta : vfta;
4010 * Call ixgbe_set_vlvf_generic to set VLVFB and VLVF
4012 ret_val = ixgbe_set_vlvf_generic(hw, vlan, vind, vlan_on, &vfta_delta,
4014 if (ret_val != IXGBE_SUCCESS) {
4021 /* Update VFTA now that we are ready for traffic */
4023 IXGBE_WRITE_REG(hw, IXGBE_VFTA(regidx), vfta);
4025 return IXGBE_SUCCESS;
4029 * ixgbe_set_vlvf_generic - Set VLAN Pool Filter
4030 * @hw: pointer to hardware structure
4031 * @vlan: VLAN id to write to VLAN filter
4032 * @vind: VMDq output index that maps queue to VLAN id in VLVFB
4033 * @vlan_on: boolean flag to turn on/off VLAN in VLVF
4034 * @vfta_delta: pointer to the difference between the current value of VFTA
4035 * and the desired value
4036 * @vfta: the desired value of the VFTA
4037 * @vlvf_bypass: boolean flag indicating updating default pool is okay
4039 * Turn on/off specified bit in VLVF table.
4041 s32 ixgbe_set_vlvf_generic(struct ixgbe_hw *hw, u32 vlan, u32 vind,
4042 bool vlan_on, u32 *vfta_delta, u32 vfta,
4048 DEBUGFUNC("ixgbe_set_vlvf_generic");
4050 if (vlan > 4095 || vind > 63)
4051 return IXGBE_ERR_PARAM;
4053 /* If VT Mode is set
4055 * make sure the vlan is in VLVF
4056 * set the vind bit in the matching VLVFB
4058 * clear the pool bit and possibly the vind
4060 if (!(IXGBE_READ_REG(hw, IXGBE_VT_CTL) & IXGBE_VT_CTL_VT_ENABLE))
4061 return IXGBE_SUCCESS;
4063 vlvf_index = ixgbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
4067 bits = IXGBE_READ_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32));
4069 /* set the pool bit */
4070 bits |= 1 << (vind % 32);
4074 /* clear the pool bit */
4075 bits ^= 1 << (vind % 32);
4078 !IXGBE_READ_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + 1 - vind / 32))) {
4079 /* Clear VFTA first, then disable VLVF. Otherwise
4080 * we run the risk of stray packets leaking into
4081 * the PF via the default pool
4084 IXGBE_WRITE_REG(hw, IXGBE_VFTA(vlan / 32), vfta);
4086 /* disable VLVF and clear remaining bit from pool */
4087 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), 0);
4088 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32), 0);
4090 return IXGBE_SUCCESS;
4093 /* If there are still bits set in the VLVFB registers
4094 * for the VLAN ID indicated we need to see if the
4095 * caller is requesting that we clear the VFTA entry bit.
4096 * If the caller has requested that we clear the VFTA
4097 * entry bit but there are still pools/VFs using this VLAN
4098 * ID entry then ignore the request. We're not worried
4099 * about the case where we're turning the VFTA VLAN ID
4100 * entry bit on, only when requested to turn it off as
4101 * there may be multiple pools and/or VFs using the
4102 * VLAN ID entry. In that case we cannot clear the
4103 * VFTA bit until all pools/VFs using that VLAN ID have also
4104 * been cleared. This will be indicated by "bits" being
4110 /* record pool change and enable VLAN ID if not already enabled */
4111 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(vlvf_index * 2 + vind / 32), bits);
4112 IXGBE_WRITE_REG(hw, IXGBE_VLVF(vlvf_index), IXGBE_VLVF_VIEN | vlan);
4114 return IXGBE_SUCCESS;
4118 * ixgbe_clear_vfta_generic - Clear VLAN filter table
4119 * @hw: pointer to hardware structure
4121 * Clears the VLAN filer table, and the VMDq index associated with the filter
4123 s32 ixgbe_clear_vfta_generic(struct ixgbe_hw *hw)
4127 DEBUGFUNC("ixgbe_clear_vfta_generic");
4129 for (offset = 0; offset < hw->mac.vft_size; offset++)
4130 IXGBE_WRITE_REG(hw, IXGBE_VFTA(offset), 0);
4132 for (offset = 0; offset < IXGBE_VLVF_ENTRIES; offset++) {
4133 IXGBE_WRITE_REG(hw, IXGBE_VLVF(offset), 0);
4134 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2), 0);
4135 IXGBE_WRITE_REG(hw, IXGBE_VLVFB(offset * 2 + 1), 0);
4138 return IXGBE_SUCCESS;
4142 * ixgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
4143 * @hw: pointer to hardware structure
4145 * Contains the logic to identify if we need to verify link for the
4148 static bool ixgbe_need_crosstalk_fix(struct ixgbe_hw *hw)
4151 /* Does FW say we need the fix */
4152 if (!hw->need_crosstalk_fix)
4155 /* Only consider SFP+ PHYs i.e. media type fiber */
4156 switch (hw->mac.ops.get_media_type(hw)) {
4157 case ixgbe_media_type_fiber:
4158 case ixgbe_media_type_fiber_qsfp:
4168 * ixgbe_check_mac_link_generic - Determine link and speed status
4169 * @hw: pointer to hardware structure
4170 * @speed: pointer to link speed
4171 * @link_up: true when link is up
4172 * @link_up_wait_to_complete: bool used to wait for link up or not
4174 * Reads the links register to determine if link is up and the current speed
4176 s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
4177 bool *link_up, bool link_up_wait_to_complete)
4179 u32 links_reg, links_orig;
4182 DEBUGFUNC("ixgbe_check_mac_link_generic");
4184 /* If Crosstalk fix enabled do the sanity check of making sure
4185 * the SFP+ cage is full.
4187 if (ixgbe_need_crosstalk_fix(hw)) {
4190 switch (hw->mac.type) {
4191 case ixgbe_mac_82599EB:
4192 sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
4195 case ixgbe_mac_X550EM_x:
4196 case ixgbe_mac_X550EM_a:
4197 sfp_cage_full = IXGBE_READ_REG(hw, IXGBE_ESDP) &
4201 /* sanity check - No SFP+ devices here */
4202 sfp_cage_full = false;
4206 if (!sfp_cage_full) {
4208 *speed = IXGBE_LINK_SPEED_UNKNOWN;
4209 return IXGBE_SUCCESS;
4213 /* clear the old state */
4214 links_orig = IXGBE_READ_REG(hw, IXGBE_LINKS);
4216 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
4218 if (links_orig != links_reg) {
4219 DEBUGOUT2("LINKS changed from %08X to %08X\n",
4220 links_orig, links_reg);
4223 if (link_up_wait_to_complete) {
4224 for (i = 0; i < hw->mac.max_link_up_time; i++) {
4225 if (links_reg & IXGBE_LINKS_UP) {
4232 links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
4235 if (links_reg & IXGBE_LINKS_UP)
4241 switch (links_reg & IXGBE_LINKS_SPEED_82599) {
4242 case IXGBE_LINKS_SPEED_10G_82599:
4243 *speed = IXGBE_LINK_SPEED_10GB_FULL;
4244 if (hw->mac.type >= ixgbe_mac_X550) {
4245 if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
4246 *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
4249 case IXGBE_LINKS_SPEED_1G_82599:
4250 *speed = IXGBE_LINK_SPEED_1GB_FULL;
4252 case IXGBE_LINKS_SPEED_100_82599:
4253 *speed = IXGBE_LINK_SPEED_100_FULL;
4254 if (hw->mac.type == ixgbe_mac_X550) {
4255 if (links_reg & IXGBE_LINKS_SPEED_NON_STD)
4256 *speed = IXGBE_LINK_SPEED_5GB_FULL;
4259 case IXGBE_LINKS_SPEED_10_X550EM_A:
4260 *speed = IXGBE_LINK_SPEED_UNKNOWN;
4261 if (hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T ||
4262 hw->device_id == IXGBE_DEV_ID_X550EM_A_1G_T_L)
4263 *speed = IXGBE_LINK_SPEED_10_FULL;
4266 *speed = IXGBE_LINK_SPEED_UNKNOWN;
4269 return IXGBE_SUCCESS;
4273 * ixgbe_get_wwn_prefix_generic - Get alternative WWNN/WWPN prefix from
4275 * @hw: pointer to hardware structure
4276 * @wwnn_prefix: the alternative WWNN prefix
4277 * @wwpn_prefix: the alternative WWPN prefix
4279 * This function will read the EEPROM from the alternative SAN MAC address
4280 * block to check the support for the alternative WWNN/WWPN prefix support.
4282 s32 ixgbe_get_wwn_prefix_generic(struct ixgbe_hw *hw, u16 *wwnn_prefix,
4286 u16 alt_san_mac_blk_offset;
4288 DEBUGFUNC("ixgbe_get_wwn_prefix_generic");
4290 /* clear output first */
4291 *wwnn_prefix = 0xFFFF;
4292 *wwpn_prefix = 0xFFFF;
4294 /* check if alternative SAN MAC is supported */
4295 offset = IXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
4296 if (hw->eeprom.ops.read(hw, offset, &alt_san_mac_blk_offset))
4297 goto wwn_prefix_err;
4299 if ((alt_san_mac_blk_offset == 0) ||
4300 (alt_san_mac_blk_offset == 0xFFFF))
4301 goto wwn_prefix_out;
4303 /* check capability in alternative san mac address block */
4304 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
4305 if (hw->eeprom.ops.read(hw, offset, &caps))
4306 goto wwn_prefix_err;
4307 if (!(caps & IXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
4308 goto wwn_prefix_out;
4310 /* get the corresponding prefix for WWNN/WWPN */
4311 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
4312 if (hw->eeprom.ops.read(hw, offset, wwnn_prefix)) {
4313 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
4314 "eeprom read at offset %d failed", offset);
4317 offset = alt_san_mac_blk_offset + IXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
4318 if (hw->eeprom.ops.read(hw, offset, wwpn_prefix))
4319 goto wwn_prefix_err;
4322 return IXGBE_SUCCESS;
4325 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
4326 "eeprom read at offset %d failed", offset);
4327 return IXGBE_SUCCESS;
4331 * ixgbe_get_fcoe_boot_status_generic - Get FCOE boot status from EEPROM
4332 * @hw: pointer to hardware structure
4333 * @bs: the fcoe boot status
4335 * This function will read the FCOE boot status from the iSCSI FCOE block
4337 s32 ixgbe_get_fcoe_boot_status_generic(struct ixgbe_hw *hw, u16 *bs)
4339 u16 offset, caps, flags;
4342 DEBUGFUNC("ixgbe_get_fcoe_boot_status_generic");
4344 /* clear output first */
4345 *bs = ixgbe_fcoe_bootstatus_unavailable;
4347 /* check if FCOE IBA block is present */
4348 offset = IXGBE_FCOE_IBA_CAPS_BLK_PTR;
4349 status = hw->eeprom.ops.read(hw, offset, &caps);
4350 if (status != IXGBE_SUCCESS)
4353 if (!(caps & IXGBE_FCOE_IBA_CAPS_FCOE))
4356 /* check if iSCSI FCOE block is populated */
4357 status = hw->eeprom.ops.read(hw, IXGBE_ISCSI_FCOE_BLK_PTR, &offset);
4358 if (status != IXGBE_SUCCESS)
4361 if ((offset == 0) || (offset == 0xFFFF))
4364 /* read fcoe flags in iSCSI FCOE block */
4365 offset = offset + IXGBE_ISCSI_FCOE_FLAGS_OFFSET;
4366 status = hw->eeprom.ops.read(hw, offset, &flags);
4367 if (status != IXGBE_SUCCESS)
4370 if (flags & IXGBE_ISCSI_FCOE_FLAGS_ENABLE)
4371 *bs = ixgbe_fcoe_bootstatus_enabled;
4373 *bs = ixgbe_fcoe_bootstatus_disabled;
4380 * ixgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
4381 * @hw: pointer to hardware structure
4382 * @enable: enable or disable switch for MAC anti-spoofing
4383 * @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
4386 void ixgbe_set_mac_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
4388 int vf_target_reg = vf >> 3;
4389 int vf_target_shift = vf % 8;
4392 if (hw->mac.type == ixgbe_mac_82598EB)
4395 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
4397 pfvfspoof |= (1 << vf_target_shift);
4399 pfvfspoof &= ~(1 << vf_target_shift);
4400 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
4404 * ixgbe_set_vlan_anti_spoofing - Enable/Disable VLAN anti-spoofing
4405 * @hw: pointer to hardware structure
4406 * @enable: enable or disable switch for VLAN anti-spoofing
4407 * @vf: Virtual Function pool - VF Pool to set for VLAN anti-spoofing
4410 void ixgbe_set_vlan_anti_spoofing(struct ixgbe_hw *hw, bool enable, int vf)
4412 int vf_target_reg = vf >> 3;
4413 int vf_target_shift = vf % 8 + IXGBE_SPOOF_VLANAS_SHIFT;
4416 if (hw->mac.type == ixgbe_mac_82598EB)
4419 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
4421 pfvfspoof |= (1 << vf_target_shift);
4423 pfvfspoof &= ~(1 << vf_target_shift);
4424 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
4428 * ixgbe_get_device_caps_generic - Get additional device capabilities
4429 * @hw: pointer to hardware structure
4430 * @device_caps: the EEPROM word with the extra device capabilities
4432 * This function will read the EEPROM location for the device capabilities,
4433 * and return the word through device_caps.
4435 s32 ixgbe_get_device_caps_generic(struct ixgbe_hw *hw, u16 *device_caps)
4437 DEBUGFUNC("ixgbe_get_device_caps_generic");
4439 hw->eeprom.ops.read(hw, IXGBE_DEVICE_CAPS, device_caps);
4441 return IXGBE_SUCCESS;
4445 * ixgbe_enable_relaxed_ordering_gen2 - Enable relaxed ordering
4446 * @hw: pointer to hardware structure
4449 void ixgbe_enable_relaxed_ordering_gen2(struct ixgbe_hw *hw)
4454 DEBUGFUNC("ixgbe_enable_relaxed_ordering_gen2");
4456 /* Enable relaxed ordering */
4457 for (i = 0; i < hw->mac.max_tx_queues; i++) {
4458 regval = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(i));
4459 regval |= IXGBE_DCA_TXCTRL_DESC_WRO_EN;
4460 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(i), regval);
4463 for (i = 0; i < hw->mac.max_rx_queues; i++) {
4464 regval = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
4465 regval |= IXGBE_DCA_RXCTRL_DATA_WRO_EN |
4466 IXGBE_DCA_RXCTRL_HEAD_WRO_EN;
4467 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(i), regval);
4473 * ixgbe_calculate_checksum - Calculate checksum for buffer
4474 * @buffer: pointer to EEPROM
4475 * @length: size of EEPROM to calculate a checksum for
4476 * Calculates the checksum for some buffer on a specified length. The
4477 * checksum calculated is returned.
4479 u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
4484 DEBUGFUNC("ixgbe_calculate_checksum");
4489 for (i = 0; i < length; i++)
4492 return (u8) (0 - sum);
4496 * ixgbe_hic_unlocked - Issue command to manageability block unlocked
4497 * @hw: pointer to the HW structure
4498 * @buffer: command to write and where the return status will be placed
4499 * @length: length of buffer, must be multiple of 4 bytes
4500 * @timeout: time in ms to wait for command completion
4502 * Communicates with the manageability block. On success return IXGBE_SUCCESS
4503 * else returns semaphore error when encountering an error acquiring
4504 * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
4506 * This function assumes that the IXGBE_GSSR_SW_MNG_SM semaphore is held
4509 s32 ixgbe_hic_unlocked(struct ixgbe_hw *hw, u32 *buffer, u32 length,
4515 DEBUGFUNC("ixgbe_hic_unlocked");
4517 if (!length || length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
4518 DEBUGOUT1("Buffer length failure buffersize=%d.\n", length);
4519 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
4522 /* Set bit 9 of FWSTS clearing FW reset indication */
4523 fwsts = IXGBE_READ_REG(hw, IXGBE_FWSTS);
4524 IXGBE_WRITE_REG(hw, IXGBE_FWSTS, fwsts | IXGBE_FWSTS_FWRI);
4526 /* Check that the host interface is enabled. */
4527 hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
4528 if (!(hicr & IXGBE_HICR_EN)) {
4529 DEBUGOUT("IXGBE_HOST_EN bit disabled.\n");
4530 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
4533 /* Calculate length in DWORDs. We must be DWORD aligned */
4534 if (length % sizeof(u32)) {
4535 DEBUGOUT("Buffer length failure, not aligned to dword");
4536 return IXGBE_ERR_INVALID_ARGUMENT;
4539 dword_len = length >> 2;
4541 /* The device driver writes the relevant command block
4542 * into the ram area.
4544 for (i = 0; i < dword_len; i++)
4545 IXGBE_WRITE_REG_ARRAY(hw, IXGBE_FLEX_MNG,
4546 i, IXGBE_CPU_TO_LE32(buffer[i]));
4548 /* Setting this bit tells the ARC that a new command is pending. */
4549 IXGBE_WRITE_REG(hw, IXGBE_HICR, hicr | IXGBE_HICR_C);
4551 for (i = 0; i < timeout; i++) {
4552 hicr = IXGBE_READ_REG(hw, IXGBE_HICR);
4553 if (!(hicr & IXGBE_HICR_C))
4558 /* For each command except "Apply Update" perform
4559 * status checks in the HICR registry.
4561 if ((buffer[0] & IXGBE_HOST_INTERFACE_MASK_CMD) ==
4562 IXGBE_HOST_INTERFACE_APPLY_UPDATE_CMD)
4563 return IXGBE_SUCCESS;
4565 /* Check command completion */
4566 if ((timeout && i == timeout) ||
4567 !(IXGBE_READ_REG(hw, IXGBE_HICR) & IXGBE_HICR_SV)) {
4568 ERROR_REPORT1(IXGBE_ERROR_CAUTION,
4569 "Command has failed with no status valid.\n");
4570 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
4573 return IXGBE_SUCCESS;
4577 * ixgbe_host_interface_command - Issue command to manageability block
4578 * @hw: pointer to the HW structure
4579 * @buffer: contains the command to write and where the return status will
4581 * @length: length of buffer, must be multiple of 4 bytes
4582 * @timeout: time in ms to wait for command completion
4583 * @return_data: read and return data from the buffer (true) or not (false)
4584 * Needed because FW structures are big endian and decoding of
4585 * these fields can be 8 bit or 16 bit based on command. Decoding
4586 * is not easily understood without making a table of commands.
4587 * So we will leave this up to the caller to read back the data
4590 * Communicates with the manageability block. On success return IXGBE_SUCCESS
4591 * else returns semaphore error when encountering an error acquiring
4592 * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
4594 s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
4595 u32 length, u32 timeout, bool return_data)
4597 u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
4598 struct ixgbe_hic_hdr *resp = (struct ixgbe_hic_hdr *)buffer;
4604 DEBUGFUNC("ixgbe_host_interface_command");
4606 if (length == 0 || length > IXGBE_HI_MAX_BLOCK_BYTE_LENGTH) {
4607 DEBUGOUT1("Buffer length failure buffersize=%d.\n", length);
4608 return IXGBE_ERR_HOST_INTERFACE_COMMAND;
4611 /* Take management host interface semaphore */
4612 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
4616 status = ixgbe_hic_unlocked(hw, buffer, length, timeout);
4623 /* Calculate length in DWORDs */
4624 dword_len = hdr_size >> 2;
4626 /* first pull in the header so we know the buffer length */
4627 for (bi = 0; bi < dword_len; bi++) {
4628 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
4629 IXGBE_LE32_TO_CPUS((uintptr_t)&buffer[bi]);
4633 * If there is any thing in data position pull it in
4634 * Read Flash command requires reading buffer length from
4635 * two byes instead of one byte
4637 if (resp->cmd == IXGBE_HOST_INTERFACE_FLASH_READ_CMD ||
4638 resp->cmd == IXGBE_HOST_INTERFACE_SHADOW_RAM_READ_CMD) {
4639 for (; bi < dword_len + 2; bi++) {
4640 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
4642 IXGBE_LE32_TO_CPUS(&buffer[bi]);
4644 buf_len = (((u16)(resp->cmd_or_resp.ret_status) << 3)
4645 & 0xF00) | resp->buf_len;
4646 hdr_size += (2 << 2);
4648 buf_len = resp->buf_len;
4653 if (length < buf_len + hdr_size) {
4654 DEBUGOUT("Buffer not large enough for reply message.\n");
4655 status = IXGBE_ERR_HOST_INTERFACE_COMMAND;
4659 /* Calculate length in DWORDs, add 3 for odd lengths */
4660 dword_len = (buf_len + 3) >> 2;
4662 /* Pull in the rest of the buffer (bi is where we left off) */
4663 for (; bi <= dword_len; bi++) {
4664 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
4665 IXGBE_LE32_TO_CPUS((uintptr_t)&buffer[bi]);
4669 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_SW_MNG_SM);
4675 * ixgbe_set_fw_drv_ver_generic - Sends driver version to firmware
4676 * @hw: pointer to the HW structure
4677 * @maj: driver version major number
4678 * @min: driver version minor number
4679 * @build: driver version build number
4680 * @sub: driver version sub build number
4682 * @driver_ver: unused
4684 * Sends driver version number to firmware through the manageability
4685 * block. On success return IXGBE_SUCCESS
4686 * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
4687 * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
4689 s32 ixgbe_set_fw_drv_ver_generic(struct ixgbe_hw *hw, u8 maj, u8 min,
4690 u8 build, u8 sub, u16 len,
4691 const char *driver_ver)
4693 struct ixgbe_hic_drv_info fw_cmd;
4695 s32 ret_val = IXGBE_SUCCESS;
4697 DEBUGFUNC("ixgbe_set_fw_drv_ver_generic");
4698 UNREFERENCED_2PARAMETER(len, driver_ver);
4700 fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
4701 fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN;
4702 fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
4703 fw_cmd.port_num = (u8)hw->bus.func;
4704 fw_cmd.ver_maj = maj;
4705 fw_cmd.ver_min = min;
4706 fw_cmd.ver_build = build;
4707 fw_cmd.ver_sub = sub;
4708 fw_cmd.hdr.checksum = 0;
4711 fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
4712 (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
4714 for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
4715 ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
4717 IXGBE_HI_COMMAND_TIMEOUT,
4719 if (ret_val != IXGBE_SUCCESS)
4722 if (fw_cmd.hdr.cmd_or_resp.ret_status ==
4723 FW_CEM_RESP_STATUS_SUCCESS)
4724 ret_val = IXGBE_SUCCESS;
4726 ret_val = IXGBE_ERR_HOST_INTERFACE_COMMAND;
4735 * ixgbe_set_rxpba_generic - Initialize Rx packet buffer
4736 * @hw: pointer to hardware structure
4737 * @num_pb: number of packet buffers to allocate
4738 * @headroom: reserve n KB of headroom
4739 * @strategy: packet buffer allocation strategy
4741 void ixgbe_set_rxpba_generic(struct ixgbe_hw *hw, int num_pb, u32 headroom,
4744 u32 pbsize = hw->mac.rx_pb_size;
4746 u32 rxpktsize, txpktsize, txpbthresh;
4748 /* Reserve headroom */
4754 /* Divide remaining packet buffer space amongst the number of packet
4755 * buffers requested using supplied strategy.
4758 case PBA_STRATEGY_WEIGHTED:
4759 /* ixgbe_dcb_pba_80_48 strategy weight first half of packet
4760 * buffer with 5/8 of the packet buffer space.
4762 rxpktsize = (pbsize * 5) / (num_pb * 4);
4763 pbsize -= rxpktsize * (num_pb / 2);
4764 rxpktsize <<= IXGBE_RXPBSIZE_SHIFT;
4765 for (; i < (num_pb / 2); i++)
4766 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
4767 /* configure remaining packet buffers */
4769 case PBA_STRATEGY_EQUAL:
4770 rxpktsize = (pbsize / (num_pb - i)) << IXGBE_RXPBSIZE_SHIFT;
4771 for (; i < num_pb; i++)
4772 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), rxpktsize);
4778 /* Only support an equally distributed Tx packet buffer strategy. */
4779 txpktsize = IXGBE_TXPBSIZE_MAX / num_pb;
4780 txpbthresh = (txpktsize / 1024) - IXGBE_TXPKT_SIZE_MAX;
4781 for (i = 0; i < num_pb; i++) {
4782 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), txpktsize);
4783 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), txpbthresh);
4786 /* Clear unused TCs, if any, to zero buffer size*/
4787 for (; i < IXGBE_MAX_PB; i++) {
4788 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(i), 0);
4789 IXGBE_WRITE_REG(hw, IXGBE_TXPBSIZE(i), 0);
4790 IXGBE_WRITE_REG(hw, IXGBE_TXPBTHRESH(i), 0);
4795 * ixgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
4796 * @hw: pointer to the hardware structure
4798 * The 82599 and x540 MACs can experience issues if TX work is still pending
4799 * when a reset occurs. This function prevents this by flushing the PCIe
4800 * buffers on the system.
4802 void ixgbe_clear_tx_pending(struct ixgbe_hw *hw)
4804 u32 gcr_ext, hlreg0, i, poll;
4808 * If double reset is not requested then all transactions should
4809 * already be clear and as such there is no work to do
4811 if (!(hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
4815 * Set loopback enable to prevent any transmits from being sent
4816 * should the link come up. This assumes that the RXCTRL.RXEN bit
4817 * has already been cleared.
4819 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
4820 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0 | IXGBE_HLREG0_LPBK);
4822 /* Wait for a last completion before clearing buffers */
4823 IXGBE_WRITE_FLUSH(hw);
4827 * Before proceeding, make sure that the PCIe block does not have
4828 * transactions pending.
4830 poll = ixgbe_pcie_timeout_poll(hw);
4831 for (i = 0; i < poll; i++) {
4833 value = IXGBE_READ_PCIE_WORD(hw, IXGBE_PCI_DEVICE_STATUS);
4834 if (IXGBE_REMOVED(hw->hw_addr))
4836 if (!(value & IXGBE_PCI_DEVICE_STATUS_TRANSACTION_PENDING))
4841 /* initiate cleaning flow for buffers in the PCIe transaction layer */
4842 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
4843 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT,
4844 gcr_ext | IXGBE_GCR_EXT_BUFFERS_CLEAR);
4846 /* Flush all writes and allow 20usec for all transactions to clear */
4847 IXGBE_WRITE_FLUSH(hw);
4850 /* restore previous register values */
4851 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
4852 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
4855 static const u8 ixgbe_emc_temp_data[4] = {
4856 IXGBE_EMC_INTERNAL_DATA,
4857 IXGBE_EMC_DIODE1_DATA,
4858 IXGBE_EMC_DIODE2_DATA,
4859 IXGBE_EMC_DIODE3_DATA
4861 static const u8 ixgbe_emc_therm_limit[4] = {
4862 IXGBE_EMC_INTERNAL_THERM_LIMIT,
4863 IXGBE_EMC_DIODE1_THERM_LIMIT,
4864 IXGBE_EMC_DIODE2_THERM_LIMIT,
4865 IXGBE_EMC_DIODE3_THERM_LIMIT
4869 * ixgbe_get_thermal_sensor_data - Gathers thermal sensor data
4870 * @hw: pointer to hardware structure
4872 * Returns the thermal sensor data structure
4874 s32 ixgbe_get_thermal_sensor_data_generic(struct ixgbe_hw *hw)
4876 s32 status = IXGBE_SUCCESS;
4884 struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
4886 DEBUGFUNC("ixgbe_get_thermal_sensor_data_generic");
4888 /* Only support thermal sensors attached to 82599 physical port 0 */
4889 if ((hw->mac.type != ixgbe_mac_82599EB) ||
4890 (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1)) {
4891 status = IXGBE_NOT_IMPLEMENTED;
4895 status = hw->eeprom.ops.read(hw, IXGBE_ETS_CFG, &ets_offset);
4899 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF)) {
4900 status = IXGBE_NOT_IMPLEMENTED;
4904 status = hw->eeprom.ops.read(hw, ets_offset, &ets_cfg);
4908 if (((ets_cfg & IXGBE_ETS_TYPE_MASK) >> IXGBE_ETS_TYPE_SHIFT)
4909 != IXGBE_ETS_TYPE_EMC) {
4910 status = IXGBE_NOT_IMPLEMENTED;
4914 num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
4915 if (num_sensors > IXGBE_MAX_SENSORS)
4916 num_sensors = IXGBE_MAX_SENSORS;
4918 for (i = 0; i < num_sensors; i++) {
4919 status = hw->eeprom.ops.read(hw, (ets_offset + 1 + i),
4924 sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
4925 IXGBE_ETS_DATA_INDEX_SHIFT);
4926 sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
4927 IXGBE_ETS_DATA_LOC_SHIFT);
4929 if (sensor_location != 0) {
4930 status = hw->phy.ops.read_i2c_byte(hw,
4931 ixgbe_emc_temp_data[sensor_index],
4932 IXGBE_I2C_THERMAL_SENSOR_ADDR,
4933 &data->sensor[i].temp);
4943 * ixgbe_init_thermal_sensor_thresh_generic - Inits thermal sensor thresholds
4944 * @hw: pointer to hardware structure
4946 * Inits the thermal sensor thresholds according to the NVM map
4947 * and save off the threshold and location values into mac.thermal_sensor_data
4949 s32 ixgbe_init_thermal_sensor_thresh_generic(struct ixgbe_hw *hw)
4951 s32 status = IXGBE_SUCCESS;
4956 u8 low_thresh_delta;
4962 struct ixgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
4964 DEBUGFUNC("ixgbe_init_thermal_sensor_thresh_generic");
4966 memset(data, 0, sizeof(struct ixgbe_thermal_sensor_data));
4968 /* Only support thermal sensors attached to 82599 physical port 0 */
4969 if ((hw->mac.type != ixgbe_mac_82599EB) ||
4970 (IXGBE_READ_REG(hw, IXGBE_STATUS) & IXGBE_STATUS_LAN_ID_1))
4971 return IXGBE_NOT_IMPLEMENTED;
4973 offset = IXGBE_ETS_CFG;
4974 if (hw->eeprom.ops.read(hw, offset, &ets_offset))
4976 if ((ets_offset == 0x0000) || (ets_offset == 0xFFFF))
4977 return IXGBE_NOT_IMPLEMENTED;
4979 offset = ets_offset;
4980 if (hw->eeprom.ops.read(hw, offset, &ets_cfg))
4982 if (((ets_cfg & IXGBE_ETS_TYPE_MASK) >> IXGBE_ETS_TYPE_SHIFT)
4983 != IXGBE_ETS_TYPE_EMC)
4984 return IXGBE_NOT_IMPLEMENTED;
4986 low_thresh_delta = ((ets_cfg & IXGBE_ETS_LTHRES_DELTA_MASK) >>
4987 IXGBE_ETS_LTHRES_DELTA_SHIFT);
4988 num_sensors = (ets_cfg & IXGBE_ETS_NUM_SENSORS_MASK);
4990 for (i = 0; i < num_sensors; i++) {
4991 offset = ets_offset + 1 + i;
4992 if (hw->eeprom.ops.read(hw, offset, &ets_sensor)) {
4993 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
4994 "eeprom read at offset %d failed",
4998 sensor_index = ((ets_sensor & IXGBE_ETS_DATA_INDEX_MASK) >>
4999 IXGBE_ETS_DATA_INDEX_SHIFT);
5000 sensor_location = ((ets_sensor & IXGBE_ETS_DATA_LOC_MASK) >>
5001 IXGBE_ETS_DATA_LOC_SHIFT);
5002 therm_limit = ets_sensor & IXGBE_ETS_DATA_HTHRESH_MASK;
5004 hw->phy.ops.write_i2c_byte(hw,
5005 ixgbe_emc_therm_limit[sensor_index],
5006 IXGBE_I2C_THERMAL_SENSOR_ADDR, therm_limit);
5008 if ((i < IXGBE_MAX_SENSORS) && (sensor_location != 0)) {
5009 data->sensor[i].location = sensor_location;
5010 data->sensor[i].caution_thresh = therm_limit;
5011 data->sensor[i].max_op_thresh = therm_limit -
5018 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
5019 "eeprom read at offset %d failed", offset);
5020 return IXGBE_NOT_IMPLEMENTED;
5024 * ixgbe_bypass_rw_generic - Bit bang data into by_pass FW
5026 * @hw: pointer to hardware structure
5027 * @cmd: Command we send to the FW
5028 * @status: The reply from the FW
5030 * Bit-bangs the cmd to the by_pass FW status points to what is returned.
5032 #define IXGBE_BYPASS_BB_WAIT 1
5033 s32 ixgbe_bypass_rw_generic(struct ixgbe_hw *hw, u32 cmd, u32 *status)
5036 u32 sck, sdi, sdo, dir_sck, dir_sdi, dir_sdo;
5040 return IXGBE_ERR_PARAM;
5044 /* SDP vary by MAC type */
5045 switch (hw->mac.type) {
5046 case ixgbe_mac_82599EB:
5047 sck = IXGBE_ESDP_SDP7;
5048 sdi = IXGBE_ESDP_SDP0;
5049 sdo = IXGBE_ESDP_SDP6;
5050 dir_sck = IXGBE_ESDP_SDP7_DIR;
5051 dir_sdi = IXGBE_ESDP_SDP0_DIR;
5052 dir_sdo = IXGBE_ESDP_SDP6_DIR;
5054 case ixgbe_mac_X540:
5055 sck = IXGBE_ESDP_SDP2;
5056 sdi = IXGBE_ESDP_SDP0;
5057 sdo = IXGBE_ESDP_SDP1;
5058 dir_sck = IXGBE_ESDP_SDP2_DIR;
5059 dir_sdi = IXGBE_ESDP_SDP0_DIR;
5060 dir_sdo = IXGBE_ESDP_SDP1_DIR;
5063 return IXGBE_ERR_DEVICE_NOT_SUPPORTED;
5066 /* Set SDP pins direction */
5067 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5068 esdp |= dir_sck; /* SCK as output */
5069 esdp |= dir_sdi; /* SDI as output */
5070 esdp &= ~dir_sdo; /* SDO as input */
5073 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5074 IXGBE_WRITE_FLUSH(hw);
5075 msec_delay(IXGBE_BYPASS_BB_WAIT);
5077 /* Generate start condition */
5079 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5080 IXGBE_WRITE_FLUSH(hw);
5081 msec_delay(IXGBE_BYPASS_BB_WAIT);
5084 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5085 IXGBE_WRITE_FLUSH(hw);
5086 msec_delay(IXGBE_BYPASS_BB_WAIT);
5088 /* Clock out the new control word and clock in the status */
5089 for (i = 0; i < 32; i++) {
5090 if ((cmd >> (31 - i)) & 0x01) {
5092 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5095 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5097 IXGBE_WRITE_FLUSH(hw);
5098 msec_delay(IXGBE_BYPASS_BB_WAIT);
5101 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5102 IXGBE_WRITE_FLUSH(hw);
5103 msec_delay(IXGBE_BYPASS_BB_WAIT);
5106 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5107 IXGBE_WRITE_FLUSH(hw);
5108 msec_delay(IXGBE_BYPASS_BB_WAIT);
5110 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
5112 *status = (*status << 1) | 0x01;
5114 *status = (*status << 1) | 0x00;
5115 msec_delay(IXGBE_BYPASS_BB_WAIT);
5118 /* stop condition */
5121 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5122 IXGBE_WRITE_FLUSH(hw);
5123 msec_delay(IXGBE_BYPASS_BB_WAIT);
5126 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
5127 IXGBE_WRITE_FLUSH(hw);
5129 /* set the page bits to match the cmd that the status it belongs to */
5130 *status = (*status & 0x3fffffff) | (cmd & 0xc0000000);
5132 return IXGBE_SUCCESS;
5136 * ixgbe_bypass_valid_rd_generic - Verify valid return from bit-bang.
5138 * If we send a write we can't be sure it took until we can read back
5139 * that same register. It can be a problem as some of the feilds may
5140 * for valid reasons change inbetween the time wrote the register and
5141 * we read it again to verify. So this function check everything we
5142 * can check and then assumes it worked.
5144 * @u32 in_reg - The register cmd for the bit-bang read.
5145 * @u32 out_reg - The register returned from a bit-bang read.
5147 bool ixgbe_bypass_valid_rd_generic(u32 in_reg, u32 out_reg)
5151 /* Page must match for all control pages */
5152 if ((in_reg & BYPASS_PAGE_M) != (out_reg & BYPASS_PAGE_M))
5155 switch (in_reg & BYPASS_PAGE_M) {
5156 case BYPASS_PAGE_CTL0:
5157 /* All the following can't change since the last write
5158 * - All the event actions
5159 * - The timeout value
5161 mask = BYPASS_AUX_ON_M | BYPASS_MAIN_ON_M |
5162 BYPASS_MAIN_OFF_M | BYPASS_AUX_OFF_M |
5163 BYPASS_WDTIMEOUT_M |
5165 if ((out_reg & mask) != (in_reg & mask))
5168 /* 0x0 is never a valid value for bypass status */
5169 if (!(out_reg & BYPASS_STATUS_OFF_M))
5172 case BYPASS_PAGE_CTL1:
5173 /* All the following can't change since the last write
5175 * - time we last sent
5177 mask = BYPASS_CTL1_VALID_M | BYPASS_CTL1_TIME_M;
5178 if ((out_reg & mask) != (in_reg & mask))
5181 case BYPASS_PAGE_CTL2:
5182 /* All we can check in this page is control number
5183 * which is already done above.
5188 /* We are as sure as we can be return true */
5193 * ixgbe_bypass_set_generic - Set a bypass field in the FW CTRL Regiter.
5195 * @hw: pointer to hardware structure
5196 * @cmd: The control word we are setting.
5197 * @event: The event we are setting in the FW. This also happens to
5198 * be the mask for the event we are setting (handy)
5199 * @action: The action we set the event to in the FW. This is in a
5200 * bit field that happens to be what we want to put in
5201 * the event spot (also handy)
5203 s32 ixgbe_bypass_set_generic(struct ixgbe_hw *hw, u32 ctrl, u32 event,
5210 /* Get current values */
5211 cmd = ctrl; /* just reading only need control number */
5212 if (ixgbe_bypass_rw_generic(hw, cmd, &by_ctl))
5213 return IXGBE_ERR_INVALID_ARGUMENT;
5215 /* Set to new action */
5216 cmd = (by_ctl & ~event) | BYPASS_WE | action;
5217 if (ixgbe_bypass_rw_generic(hw, cmd, &by_ctl))
5218 return IXGBE_ERR_INVALID_ARGUMENT;
5220 /* Page 0 force a FW eeprom write which is slow so verify */
5221 if ((cmd & BYPASS_PAGE_M) == BYPASS_PAGE_CTL0) {
5222 verify = BYPASS_PAGE_CTL0;
5225 return IXGBE_BYPASS_FW_WRITE_FAILURE;
5227 if (ixgbe_bypass_rw_generic(hw, verify, &by_ctl))
5228 return IXGBE_ERR_INVALID_ARGUMENT;
5229 } while (!ixgbe_bypass_valid_rd_generic(cmd, by_ctl));
5231 /* We have give the FW time for the write to stick */
5235 return IXGBE_SUCCESS;
5239 * ixgbe_bypass_rd_eep_generic - Read the bypass FW eeprom addres.
5241 * @hw: pointer to hardware structure
5242 * @addr: The bypass eeprom address to read.
5243 * @value: The 8b of data at the address above.
5245 s32 ixgbe_bypass_rd_eep_generic(struct ixgbe_hw *hw, u32 addr, u8 *value)
5251 /* send the request */
5252 cmd = BYPASS_PAGE_CTL2 | BYPASS_WE;
5253 cmd |= (addr << BYPASS_CTL2_OFFSET_SHIFT) & BYPASS_CTL2_OFFSET_M;
5254 if (ixgbe_bypass_rw_generic(hw, cmd, &status))
5255 return IXGBE_ERR_INVALID_ARGUMENT;
5257 /* We have give the FW time for the write to stick */
5260 /* now read the results */
5262 if (ixgbe_bypass_rw_generic(hw, cmd, &status))
5263 return IXGBE_ERR_INVALID_ARGUMENT;
5265 *value = status & BYPASS_CTL2_DATA_M;
5267 return IXGBE_SUCCESS;
5271 * ixgbe_get_orom_version - Return option ROM from EEPROM
5273 * @hw: pointer to hardware structure
5274 * @nvm_ver: pointer to output structure
5276 * if valid option ROM version, nvm_ver->or_valid set to true
5277 * else nvm_ver->or_valid is false.
5279 void ixgbe_get_orom_version(struct ixgbe_hw *hw,
5280 struct ixgbe_nvm_version *nvm_ver)
5282 u16 offset, eeprom_cfg_blkh, eeprom_cfg_blkl;
5284 nvm_ver->or_valid = false;
5285 /* Option Rom may or may not be present. Start with pointer */
5286 hw->eeprom.ops.read(hw, NVM_OROM_OFFSET, &offset);
5288 /* make sure offset is valid */
5289 if ((offset == 0x0) || (offset == NVM_INVALID_PTR))
5292 hw->eeprom.ops.read(hw, offset + NVM_OROM_BLK_HI, &eeprom_cfg_blkh);
5293 hw->eeprom.ops.read(hw, offset + NVM_OROM_BLK_LOW, &eeprom_cfg_blkl);
5295 /* option rom exists and is valid */
5296 if ((eeprom_cfg_blkl | eeprom_cfg_blkh) == 0x0 ||
5297 eeprom_cfg_blkl == NVM_VER_INVALID ||
5298 eeprom_cfg_blkh == NVM_VER_INVALID)
5301 nvm_ver->or_valid = true;
5302 nvm_ver->or_major = eeprom_cfg_blkl >> NVM_OROM_SHIFT;
5303 nvm_ver->or_build = (eeprom_cfg_blkl << NVM_OROM_SHIFT) |
5304 (eeprom_cfg_blkh >> NVM_OROM_SHIFT);
5305 nvm_ver->or_patch = eeprom_cfg_blkh & NVM_OROM_PATCH_MASK;
5309 * ixgbe_get_oem_prod_version - Return OEM Product version
5311 * @hw: pointer to hardware structure
5312 * @nvm_ver: pointer to output structure
5314 * if valid OEM product version, nvm_ver->oem_valid set to true
5315 * else nvm_ver->oem_valid is false.
5317 void ixgbe_get_oem_prod_version(struct ixgbe_hw *hw,
5318 struct ixgbe_nvm_version *nvm_ver)
5320 u16 rel_num, prod_ver, mod_len, cap, offset;
5322 nvm_ver->oem_valid = false;
5323 hw->eeprom.ops.read(hw, NVM_OEM_PROD_VER_PTR, &offset);
5325 /* Return if offset to OEM Product Version block is invalid */
5326 if (offset == 0x0 || offset == NVM_INVALID_PTR)
5329 /* Read product version block */
5330 hw->eeprom.ops.read(hw, offset, &mod_len);
5331 hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_CAP_OFF, &cap);
5333 /* Return if OEM product version block is invalid */
5334 if (mod_len != NVM_OEM_PROD_VER_MOD_LEN ||
5335 (cap & NVM_OEM_PROD_VER_CAP_MASK) != 0x0)
5338 hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_OFF_L, &prod_ver);
5339 hw->eeprom.ops.read(hw, offset + NVM_OEM_PROD_VER_OFF_H, &rel_num);
5341 /* Return if version is invalid */
5342 if ((rel_num | prod_ver) == 0x0 ||
5343 rel_num == NVM_VER_INVALID || prod_ver == NVM_VER_INVALID)
5346 nvm_ver->oem_major = prod_ver >> NVM_VER_SHIFT;
5347 nvm_ver->oem_minor = prod_ver & NVM_VER_MASK;
5348 nvm_ver->oem_release = rel_num;
5349 nvm_ver->oem_valid = true;
5353 * ixgbe_get_etk_id - Return Etrack ID from EEPROM
5355 * @hw: pointer to hardware structure
5356 * @nvm_ver: pointer to output structure
5358 * word read errors will return 0xFFFF
5360 void ixgbe_get_etk_id(struct ixgbe_hw *hw, struct ixgbe_nvm_version *nvm_ver)
5362 u16 etk_id_l, etk_id_h;
5364 if (hw->eeprom.ops.read(hw, NVM_ETK_OFF_LOW, &etk_id_l))
5365 etk_id_l = NVM_VER_INVALID;
5366 if (hw->eeprom.ops.read(hw, NVM_ETK_OFF_HI, &etk_id_h))
5367 etk_id_h = NVM_VER_INVALID;
5369 /* The word order for the version format is determined by high order
5372 if ((etk_id_h & NVM_ETK_VALID) == 0) {
5373 nvm_ver->etk_id = etk_id_h;
5374 nvm_ver->etk_id |= (etk_id_l << NVM_ETK_SHIFT);
5376 nvm_ver->etk_id = etk_id_l;
5377 nvm_ver->etk_id |= (etk_id_h << NVM_ETK_SHIFT);
5383 * ixgbe_dcb_get_rtrup2tc_generic - read rtrup2tc reg
5384 * @hw: pointer to hardware structure
5385 * @map: pointer to u8 arr for returning map
5387 * Read the rtrup2tc HW register and resolve its content into map
5389 void ixgbe_dcb_get_rtrup2tc_generic(struct ixgbe_hw *hw, u8 *map)
5393 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
5394 for (i = 0; i < IXGBE_DCB_MAX_USER_PRIORITY; i++)
5395 map[i] = IXGBE_RTRUP2TC_UP_MASK &
5396 (reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT));
5400 void ixgbe_disable_rx_generic(struct ixgbe_hw *hw)
5405 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5406 if (rxctrl & IXGBE_RXCTRL_RXEN) {
5407 if (hw->mac.type != ixgbe_mac_82598EB) {
5408 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
5409 if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
5410 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
5411 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
5412 hw->mac.set_lben = true;
5414 hw->mac.set_lben = false;
5417 rxctrl &= ~IXGBE_RXCTRL_RXEN;
5418 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
5422 void ixgbe_enable_rx_generic(struct ixgbe_hw *hw)
5427 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
5428 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, (rxctrl | IXGBE_RXCTRL_RXEN));
5430 if (hw->mac.type != ixgbe_mac_82598EB) {
5431 if (hw->mac.set_lben) {
5432 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
5433 pfdtxgswc |= IXGBE_PFDTXGSWC_VT_LBEN;
5434 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
5435 hw->mac.set_lben = false;
5441 * ixgbe_mng_present - returns true when management capability is present
5442 * @hw: pointer to hardware structure
5444 bool ixgbe_mng_present(struct ixgbe_hw *hw)
5448 if (hw->mac.type < ixgbe_mac_82599EB)
5451 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM_BY_MAC(hw));
5453 return !!(fwsm & IXGBE_FWSM_FW_MODE_PT);
5457 * ixgbe_mng_enabled - Is the manageability engine enabled?
5458 * @hw: pointer to hardware structure
5460 * Returns true if the manageability engine is enabled.
5462 bool ixgbe_mng_enabled(struct ixgbe_hw *hw)
5464 u32 fwsm, manc, factps;
5466 fwsm = IXGBE_READ_REG(hw, IXGBE_FWSM_BY_MAC(hw));
5467 if ((fwsm & IXGBE_FWSM_MODE_MASK) != IXGBE_FWSM_FW_MODE_PT)
5470 manc = IXGBE_READ_REG(hw, IXGBE_MANC);
5471 if (!(manc & IXGBE_MANC_RCV_TCO_EN))
5474 if (hw->mac.type <= ixgbe_mac_X540) {
5475 factps = IXGBE_READ_REG(hw, IXGBE_FACTPS_BY_MAC(hw));
5476 if (factps & IXGBE_FACTPS_MNGCG)
5484 * ixgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
5485 * @hw: pointer to hardware structure
5486 * @speed: new link speed
5487 * @autoneg_wait_to_complete: true when waiting for completion is needed
5489 * Set the link speed in the MAC and/or PHY register and restarts link.
5491 s32 ixgbe_setup_mac_link_multispeed_fiber(struct ixgbe_hw *hw,
5492 ixgbe_link_speed speed,
5493 bool autoneg_wait_to_complete)
5495 ixgbe_link_speed link_speed = IXGBE_LINK_SPEED_UNKNOWN;
5496 ixgbe_link_speed highest_link_speed = IXGBE_LINK_SPEED_UNKNOWN;
5497 s32 status = IXGBE_SUCCESS;
5500 bool autoneg, link_up = false;
5502 DEBUGFUNC("ixgbe_setup_mac_link_multispeed_fiber");
5504 /* Mask off requested but non-supported speeds */
5505 status = ixgbe_get_link_capabilities(hw, &link_speed, &autoneg);
5506 if (status != IXGBE_SUCCESS)
5509 speed &= link_speed;
5511 /* Try each speed one by one, highest priority first. We do this in
5512 * software because 10Gb fiber doesn't support speed autonegotiation.
5514 if (speed & IXGBE_LINK_SPEED_10GB_FULL) {
5516 highest_link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5518 /* Set the module link speed */
5519 switch (hw->phy.media_type) {
5520 case ixgbe_media_type_fiber_fixed:
5521 case ixgbe_media_type_fiber:
5522 ixgbe_set_rate_select_speed(hw,
5523 IXGBE_LINK_SPEED_10GB_FULL);
5525 case ixgbe_media_type_fiber_qsfp:
5526 /* QSFP module automatically detects MAC link speed */
5529 DEBUGOUT("Unexpected media type.\n");
5533 /* Allow module to change analog characteristics (1G->10G) */
5536 status = ixgbe_setup_mac_link(hw,
5537 IXGBE_LINK_SPEED_10GB_FULL,
5538 autoneg_wait_to_complete);
5539 if (status != IXGBE_SUCCESS)
5542 /* Flap the Tx laser if it has not already been done */
5543 ixgbe_flap_tx_laser(hw);
5545 /* Wait for the controller to acquire link. Per IEEE 802.3ap,
5546 * Section 73.10.2, we may have to wait up to 1000ms if KR is
5547 * attempted. 82599 uses the same timing for 10g SFI.
5549 for (i = 0; i < 10; i++) {
5550 /* Wait for the link partner to also set speed */
5553 /* If we have link, just jump out */
5554 status = ixgbe_check_link(hw, &link_speed,
5556 if (status != IXGBE_SUCCESS)
5564 if (speed & IXGBE_LINK_SPEED_1GB_FULL) {
5566 if (highest_link_speed == IXGBE_LINK_SPEED_UNKNOWN)
5567 highest_link_speed = IXGBE_LINK_SPEED_1GB_FULL;
5569 /* Set the module link speed */
5570 switch (hw->phy.media_type) {
5571 case ixgbe_media_type_fiber_fixed:
5572 case ixgbe_media_type_fiber:
5573 ixgbe_set_rate_select_speed(hw,
5574 IXGBE_LINK_SPEED_1GB_FULL);
5576 case ixgbe_media_type_fiber_qsfp:
5577 /* QSFP module automatically detects link speed */
5580 DEBUGOUT("Unexpected media type.\n");
5584 /* Allow module to change analog characteristics (10G->1G) */
5587 status = ixgbe_setup_mac_link(hw,
5588 IXGBE_LINK_SPEED_1GB_FULL,
5589 autoneg_wait_to_complete);
5590 if (status != IXGBE_SUCCESS)
5593 /* Flap the Tx laser if it has not already been done */
5594 ixgbe_flap_tx_laser(hw);
5596 /* Wait for the link partner to also set speed */
5599 /* If we have link, just jump out */
5600 status = ixgbe_check_link(hw, &link_speed, &link_up, false);
5601 if (status != IXGBE_SUCCESS)
5608 /* We didn't get link. Configure back to the highest speed we tried,
5609 * (if there was more than one). We call ourselves back with just the
5610 * single highest speed that the user requested.
5613 status = ixgbe_setup_mac_link_multispeed_fiber(hw,
5615 autoneg_wait_to_complete);
5618 /* Set autoneg_advertised value based on input link speed */
5619 hw->phy.autoneg_advertised = 0;
5621 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
5622 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_10GB_FULL;
5624 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
5625 hw->phy.autoneg_advertised |= IXGBE_LINK_SPEED_1GB_FULL;
5631 * ixgbe_set_soft_rate_select_speed - Set module link speed
5632 * @hw: pointer to hardware structure
5633 * @speed: link speed to set
5635 * Set module link speed via the soft rate select.
5637 void ixgbe_set_soft_rate_select_speed(struct ixgbe_hw *hw,
5638 ixgbe_link_speed speed)
5644 case IXGBE_LINK_SPEED_10GB_FULL:
5645 /* one bit mask same as setting on */
5646 rs = IXGBE_SFF_SOFT_RS_SELECT_10G;
5648 case IXGBE_LINK_SPEED_1GB_FULL:
5649 rs = IXGBE_SFF_SOFT_RS_SELECT_1G;
5652 DEBUGOUT("Invalid fixed module speed\n");
5657 status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
5658 IXGBE_I2C_EEPROM_DEV_ADDR2,
5661 DEBUGOUT("Failed to read Rx Rate Select RS0\n");
5665 eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) | rs;
5667 status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_OSCB,
5668 IXGBE_I2C_EEPROM_DEV_ADDR2,
5671 DEBUGOUT("Failed to write Rx Rate Select RS0\n");
5676 status = hw->phy.ops.read_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
5677 IXGBE_I2C_EEPROM_DEV_ADDR2,
5680 DEBUGOUT("Failed to read Rx Rate Select RS1\n");
5684 eeprom_data = (eeprom_data & ~IXGBE_SFF_SOFT_RS_SELECT_MASK) | rs;
5686 status = hw->phy.ops.write_i2c_byte(hw, IXGBE_SFF_SFF_8472_ESCB,
5687 IXGBE_I2C_EEPROM_DEV_ADDR2,
5690 DEBUGOUT("Failed to write Rx Rate Select RS1\n");