1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
6 #include "txgbe_type.h"
11 #include "txgbe_eeprom.h"
12 #include "txgbe_mng.h"
15 #define TXGBE_RAPTOR_MAX_TX_QUEUES 128
16 #define TXGBE_RAPTOR_MAX_RX_QUEUES 128
17 #define TXGBE_RAPTOR_RAR_ENTRIES 128
18 #define TXGBE_RAPTOR_MC_TBL_SIZE 128
19 #define TXGBE_RAPTOR_VFT_TBL_SIZE 128
20 #define TXGBE_RAPTOR_RX_PB_SIZE 512 /*KB*/
22 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
24 bool autoneg_wait_to_complete);
26 static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr);
27 static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
31 * txgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
33 * @hw: pointer to hardware structure
35 * This function returns true if the device supports flow control
36 * autonegotiation, and false if it does not.
39 bool txgbe_device_supports_autoneg_fc(struct txgbe_hw *hw)
41 bool supported = false;
45 switch (hw->phy.media_type) {
46 case txgbe_media_type_fiber_qsfp:
47 case txgbe_media_type_fiber:
48 hw->mac.check_link(hw, &speed, &link_up, false);
49 /* if link is down, assume supported */
51 supported = speed == TXGBE_LINK_SPEED_1GB_FULL ?
57 case txgbe_media_type_backplane:
60 case txgbe_media_type_copper:
61 /* only some copper devices support flow control autoneg */
62 switch (hw->subsystem_device_id & 0xFF) {
63 case TXGBE_DEV_ID_XAUI:
64 case TXGBE_DEV_ID_SGMII:
75 DEBUGOUT("Device %x does not support flow control autoneg",
81 * txgbe_setup_fc - Set up flow control
82 * @hw: pointer to hardware structure
84 * Called at init time to set up flow control.
86 s32 txgbe_setup_fc(struct txgbe_hw *hw)
94 /* Validate the requested mode */
95 if (hw->fc.strict_ieee && hw->fc.requested_mode == txgbe_fc_rx_pause) {
96 DEBUGOUT("txgbe_fc_rx_pause not valid in strict IEEE mode");
97 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
102 * 10gig parts do not have a word in the EEPROM to determine the
103 * default flow control setting, so we explicitly set it to full.
105 if (hw->fc.requested_mode == txgbe_fc_default)
106 hw->fc.requested_mode = txgbe_fc_full;
109 * The possible values of fc.requested_mode are:
110 * 0: Flow control is completely disabled
111 * 1: Rx flow control is enabled (we can receive pause frames,
112 * but not send pause frames).
113 * 2: Tx flow control is enabled (we can send pause frames but
114 * we do not support receiving pause frames).
115 * 3: Both Rx and Tx flow control (symmetric) are enabled.
118 switch (hw->fc.requested_mode) {
120 /* Flow control completely disabled by software override. */
122 case txgbe_fc_tx_pause:
124 * Tx Flow control is enabled, and Rx Flow control is
125 * disabled by software override.
127 reg |= SR_MII_MMD_AN_ADV_PAUSE_ASM;
128 reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_ASM;
130 case txgbe_fc_rx_pause:
132 * Rx Flow control is enabled and Tx Flow control is
133 * disabled by software override. Since there really
134 * isn't a way to advertise that we are capable of RX
135 * Pause ONLY, we will advertise that we support both
136 * symmetric and asymmetric Rx PAUSE, as such we fall
137 * through to the fc_full statement. Later, we will
138 * disable the adapter's ability to send PAUSE frames.
141 /* Flow control (both Rx and Tx) is enabled by SW override. */
142 reg |= SR_MII_MMD_AN_ADV_PAUSE_SYM |
143 SR_MII_MMD_AN_ADV_PAUSE_ASM;
144 reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_SYM |
145 SR_AN_MMD_ADV_REG1_PAUSE_ASM;
148 DEBUGOUT("Flow control param set incorrectly");
149 err = TXGBE_ERR_CONFIG;
154 * Enable auto-negotiation between the MAC & PHY;
155 * the MAC will advertise clause 37 flow control.
157 value = rd32_epcs(hw, SR_MII_MMD_AN_ADV);
158 value = (value & ~(SR_MII_MMD_AN_ADV_PAUSE_ASM |
159 SR_MII_MMD_AN_ADV_PAUSE_SYM)) | reg;
160 wr32_epcs(hw, SR_MII_MMD_AN_ADV, value);
163 * AUTOC restart handles negotiation of 1G and 10G on backplane
164 * and copper. There is no need to set the PCS1GCTL register.
167 if (hw->phy.media_type == txgbe_media_type_backplane) {
168 value = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
169 value = (value & ~(SR_AN_MMD_ADV_REG1_PAUSE_ASM |
170 SR_AN_MMD_ADV_REG1_PAUSE_SYM)) |
172 wr32_epcs(hw, SR_AN_MMD_ADV_REG1, value);
173 } else if ((hw->phy.media_type == txgbe_media_type_copper) &&
174 (txgbe_device_supports_autoneg_fc(hw))) {
175 hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
176 TXGBE_MD_DEV_AUTO_NEG, reg_cu);
179 DEBUGOUT("Set up FC; reg = 0x%08X", reg);
185 * txgbe_start_hw - Prepare hardware for Tx/Rx
186 * @hw: pointer to hardware structure
188 * Starts the hardware by filling the bus info structure and media type, clears
189 * all on chip counters, initializes receive address registers, multicast
190 * table, VLAN filter table, calls routine to set up link and flow control
191 * settings, and leaves transmit and receive units disabled and uninitialized
193 s32 txgbe_start_hw(struct txgbe_hw *hw)
198 /* Set the media type */
199 hw->phy.media_type = hw->phy.get_media_type(hw);
201 /* Clear the VLAN filter table */
202 hw->mac.clear_vfta(hw);
204 /* Clear statistics registers */
205 hw->mac.clear_hw_cntrs(hw);
207 /* Setup flow control */
208 err = txgbe_setup_fc(hw);
209 if (err != 0 && err != TXGBE_NOT_IMPLEMENTED) {
210 DEBUGOUT("Flow control setup failed, returning %d", err);
214 /* Cache bit indicating need for crosstalk fix */
215 switch (hw->mac.type) {
216 case txgbe_mac_raptor:
217 hw->mac.get_device_caps(hw, &device_caps);
218 if (device_caps & TXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
219 hw->need_crosstalk_fix = false;
221 hw->need_crosstalk_fix = true;
224 hw->need_crosstalk_fix = false;
228 /* Clear adapter stopped flag */
229 hw->adapter_stopped = false;
235 * txgbe_start_hw_gen2 - Init sequence for common device family
236 * @hw: pointer to hw structure
238 * Performs the init sequence common to the second generation
241 s32 txgbe_start_hw_gen2(struct txgbe_hw *hw)
245 /* Clear the rate limiters */
246 for (i = 0; i < hw->mac.max_tx_queues; i++) {
247 wr32(hw, TXGBE_ARBPOOLIDX, i);
248 wr32(hw, TXGBE_ARBTXRATE, 0);
252 /* We need to run link autotry after the driver loads */
253 hw->mac.autotry_restart = true;
259 * txgbe_init_hw - Generic hardware initialization
260 * @hw: pointer to hardware structure
262 * Initialize the hardware by resetting the hardware, filling the bus info
263 * structure and media type, clears all on chip counters, initializes receive
264 * address registers, multicast table, VLAN filter table, calls routine to set
265 * up link and flow control settings, and leaves transmit and receive units
266 * disabled and uninitialized
268 s32 txgbe_init_hw(struct txgbe_hw *hw)
272 /* Get firmware version */
273 hw->phy.get_fw_version(hw, &hw->fw_version);
275 /* Reset the hardware */
276 status = hw->mac.reset_hw(hw);
277 if (status == 0 || status == TXGBE_ERR_SFP_NOT_PRESENT) {
279 status = hw->mac.start_hw(hw);
283 DEBUGOUT("Failed to initialize HW, STATUS = %d", status);
289 * txgbe_clear_hw_cntrs - Generic clear hardware counters
290 * @hw: pointer to hardware structure
292 * Clears all hardware statistics counters by reading them from the hardware
293 * Statistics counters are clear on read.
295 s32 txgbe_clear_hw_cntrs(struct txgbe_hw *hw)
300 /* don't write clear queue stats */
301 for (i = 0; i < TXGBE_MAX_QP; i++) {
302 hw->qp_last[i].rx_qp_packets = 0;
303 hw->qp_last[i].tx_qp_packets = 0;
304 hw->qp_last[i].rx_qp_bytes = 0;
305 hw->qp_last[i].tx_qp_bytes = 0;
306 hw->qp_last[i].rx_qp_mc_packets = 0;
310 for (i = 0; i < TXGBE_MAX_UP; i++) {
311 rd32(hw, TXGBE_PBRXUPXON(i));
312 rd32(hw, TXGBE_PBRXUPXOFF(i));
313 rd32(hw, TXGBE_PBTXUPXON(i));
314 rd32(hw, TXGBE_PBTXUPXOFF(i));
315 rd32(hw, TXGBE_PBTXUPOFF(i));
317 rd32(hw, TXGBE_PBRXMISS(i));
319 rd32(hw, TXGBE_PBRXLNKXON);
320 rd32(hw, TXGBE_PBRXLNKXOFF);
321 rd32(hw, TXGBE_PBTXLNKXON);
322 rd32(hw, TXGBE_PBTXLNKXOFF);
325 rd32(hw, TXGBE_DMARXPKT);
326 rd32(hw, TXGBE_DMATXPKT);
328 rd64(hw, TXGBE_DMARXOCTL);
329 rd64(hw, TXGBE_DMATXOCTL);
332 rd64(hw, TXGBE_MACRXERRCRCL);
333 rd64(hw, TXGBE_MACRXMPKTL);
334 rd64(hw, TXGBE_MACTXMPKTL);
336 rd64(hw, TXGBE_MACRXPKTL);
337 rd64(hw, TXGBE_MACTXPKTL);
338 rd64(hw, TXGBE_MACRXGBOCTL);
340 rd64(hw, TXGBE_MACRXOCTL);
341 rd32(hw, TXGBE_MACTXOCTL);
343 rd64(hw, TXGBE_MACRX1TO64L);
344 rd64(hw, TXGBE_MACRX65TO127L);
345 rd64(hw, TXGBE_MACRX128TO255L);
346 rd64(hw, TXGBE_MACRX256TO511L);
347 rd64(hw, TXGBE_MACRX512TO1023L);
348 rd64(hw, TXGBE_MACRX1024TOMAXL);
349 rd64(hw, TXGBE_MACTX1TO64L);
350 rd64(hw, TXGBE_MACTX65TO127L);
351 rd64(hw, TXGBE_MACTX128TO255L);
352 rd64(hw, TXGBE_MACTX256TO511L);
353 rd64(hw, TXGBE_MACTX512TO1023L);
354 rd64(hw, TXGBE_MACTX1024TOMAXL);
356 rd64(hw, TXGBE_MACRXERRLENL);
357 rd32(hw, TXGBE_MACRXOVERSIZE);
358 rd32(hw, TXGBE_MACRXJABBER);
361 rd32(hw, TXGBE_FCOECRC);
362 rd32(hw, TXGBE_FCOELAST);
363 rd32(hw, TXGBE_FCOERPDC);
364 rd32(hw, TXGBE_FCOEPRC);
365 rd32(hw, TXGBE_FCOEPTC);
366 rd32(hw, TXGBE_FCOEDWRC);
367 rd32(hw, TXGBE_FCOEDWTC);
369 /* Flow Director Stats */
370 rd32(hw, TXGBE_FDIRMATCH);
371 rd32(hw, TXGBE_FDIRMISS);
372 rd32(hw, TXGBE_FDIRUSED);
373 rd32(hw, TXGBE_FDIRUSED);
374 rd32(hw, TXGBE_FDIRFAIL);
375 rd32(hw, TXGBE_FDIRFAIL);
378 rd32(hw, TXGBE_LSECTX_UTPKT);
379 rd32(hw, TXGBE_LSECTX_ENCPKT);
380 rd32(hw, TXGBE_LSECTX_PROTPKT);
381 rd32(hw, TXGBE_LSECTX_ENCOCT);
382 rd32(hw, TXGBE_LSECTX_PROTOCT);
383 rd32(hw, TXGBE_LSECRX_UTPKT);
384 rd32(hw, TXGBE_LSECRX_BTPKT);
385 rd32(hw, TXGBE_LSECRX_NOSCIPKT);
386 rd32(hw, TXGBE_LSECRX_UNSCIPKT);
387 rd32(hw, TXGBE_LSECRX_DECOCT);
388 rd32(hw, TXGBE_LSECRX_VLDOCT);
389 rd32(hw, TXGBE_LSECRX_UNCHKPKT);
390 rd32(hw, TXGBE_LSECRX_DLYPKT);
391 rd32(hw, TXGBE_LSECRX_LATEPKT);
392 for (i = 0; i < 2; i++) {
393 rd32(hw, TXGBE_LSECRX_OKPKT(i));
394 rd32(hw, TXGBE_LSECRX_INVPKT(i));
395 rd32(hw, TXGBE_LSECRX_BADPKT(i));
397 rd32(hw, TXGBE_LSECRX_INVSAPKT);
398 rd32(hw, TXGBE_LSECRX_BADSAPKT);
404 * txgbe_get_mac_addr - Generic get MAC address
405 * @hw: pointer to hardware structure
406 * @mac_addr: Adapter MAC address
408 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
409 * A reset of the adapter must be performed prior to calling this function
410 * in order for the MAC address to have been loaded from the EEPROM into RAR0
412 s32 txgbe_get_mac_addr(struct txgbe_hw *hw, u8 *mac_addr)
418 wr32(hw, TXGBE_ETHADDRIDX, 0);
419 rar_high = rd32(hw, TXGBE_ETHADDRH);
420 rar_low = rd32(hw, TXGBE_ETHADDRL);
422 for (i = 0; i < 2; i++)
423 mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
425 for (i = 0; i < 4; i++)
426 mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
432 * txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
433 * @hw: pointer to the HW structure
435 * Determines the LAN function id by reading memory-mapped registers and swaps
436 * the port value if requested, and set MAC instance for devices.
438 void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
440 struct txgbe_bus_info *bus = &hw->bus;
443 reg = rd32(hw, TXGBE_PORTSTAT);
444 bus->lan_id = TXGBE_PORTSTAT_ID(reg);
446 /* check for single port */
447 reg = rd32(hw, TXGBE_PWR);
448 if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
451 bus->func = bus->lan_id;
455 * txgbe_stop_hw - Generic stop Tx/Rx units
456 * @hw: pointer to hardware structure
458 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
459 * disables transmit and receive units. The adapter_stopped flag is used by
460 * the shared code and drivers to determine if the adapter is in a stopped
461 * state and should not touch the hardware.
463 s32 txgbe_stop_hw(struct txgbe_hw *hw)
469 * Set the adapter_stopped flag so other driver functions stop touching
472 hw->adapter_stopped = true;
474 /* Disable the receive unit */
475 txgbe_disable_rx(hw);
477 /* Clear interrupt mask to stop interrupts from being generated */
478 wr32(hw, TXGBE_IENMISC, 0);
479 wr32(hw, TXGBE_IMS(0), TXGBE_IMS_MASK);
480 wr32(hw, TXGBE_IMS(1), TXGBE_IMS_MASK);
482 /* Clear any pending interrupts, flush previous writes */
483 wr32(hw, TXGBE_ICRMISC, TXGBE_ICRMISC_MASK);
484 wr32(hw, TXGBE_ICR(0), TXGBE_ICR_MASK);
485 wr32(hw, TXGBE_ICR(1), TXGBE_ICR_MASK);
487 /* Disable the transmit unit. Each queue must be disabled. */
488 for (i = 0; i < hw->mac.max_tx_queues; i++)
489 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
491 /* Disable the receive unit by stopping each queue */
492 for (i = 0; i < hw->mac.max_rx_queues; i++) {
493 reg_val = rd32(hw, TXGBE_RXCFG(i));
494 reg_val &= ~TXGBE_RXCFG_ENA;
495 wr32(hw, TXGBE_RXCFG(i), reg_val);
498 /* flush all queues disables */
506 * txgbe_led_on - Turns on the software controllable LEDs.
507 * @hw: pointer to hardware structure
508 * @index: led number to turn on
510 s32 txgbe_led_on(struct txgbe_hw *hw, u32 index)
512 u32 led_reg = rd32(hw, TXGBE_LEDCTL);
514 /* To turn on the LED, set mode to ON. */
515 led_reg |= index << TXGBE_LEDCTL_ORD_SHIFT;
517 wr32(hw, TXGBE_LEDCTL, led_reg);
524 * txgbe_led_off - Turns off the software controllable LEDs.
525 * @hw: pointer to hardware structure
526 * @index: led number to turn off
528 s32 txgbe_led_off(struct txgbe_hw *hw, u32 index)
530 u32 led_reg = rd32(hw, TXGBE_LEDCTL);
532 /* To turn off the LED, set mode to OFF. */
533 led_reg &= ~(index << TXGBE_LEDCTL_ORD_SHIFT);
535 wr32(hw, TXGBE_LEDCTL, led_reg);
542 * txgbe_validate_mac_addr - Validate MAC address
543 * @mac_addr: pointer to MAC address.
545 * Tests a MAC address to ensure it is a valid Individual Address.
547 s32 txgbe_validate_mac_addr(u8 *mac_addr)
551 /* Make sure it is not a multicast address */
552 if (TXGBE_IS_MULTICAST(mac_addr)) {
553 status = TXGBE_ERR_INVALID_MAC_ADDR;
554 /* Not a broadcast address */
555 } else if (TXGBE_IS_BROADCAST(mac_addr)) {
556 status = TXGBE_ERR_INVALID_MAC_ADDR;
557 /* Reject the zero address */
558 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
559 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
560 status = TXGBE_ERR_INVALID_MAC_ADDR;
566 * txgbe_set_rar - Set Rx address register
567 * @hw: pointer to hardware structure
568 * @index: Receive address register to write
569 * @addr: Address to put into receive address register
570 * @vmdq: VMDq "set" or "pool" index
571 * @enable_addr: set flag that address is active
573 * Puts an ethernet address into a receive address register.
575 s32 txgbe_set_rar(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
578 u32 rar_low, rar_high;
579 u32 rar_entries = hw->mac.num_rar_entries;
581 /* Make sure we are using a valid rar index range */
582 if (index >= rar_entries) {
583 DEBUGOUT("RAR index %d is out of range.", index);
584 return TXGBE_ERR_INVALID_ARGUMENT;
587 /* setup VMDq pool selection before this RAR gets enabled */
588 hw->mac.set_vmdq(hw, index, vmdq);
591 * HW expects these in little endian so we reverse the byte
592 * order from network order (big endian) to little endian
594 rar_low = TXGBE_ETHADDRL_AD0(addr[5]) |
595 TXGBE_ETHADDRL_AD1(addr[4]) |
596 TXGBE_ETHADDRL_AD2(addr[3]) |
597 TXGBE_ETHADDRL_AD3(addr[2]);
599 * Some parts put the VMDq setting in the extra RAH bits,
600 * so save everything except the lower 16 bits that hold part
601 * of the address and the address valid bit.
603 rar_high = rd32(hw, TXGBE_ETHADDRH);
604 rar_high &= ~TXGBE_ETHADDRH_AD_MASK;
605 rar_high |= (TXGBE_ETHADDRH_AD4(addr[1]) |
606 TXGBE_ETHADDRH_AD5(addr[0]));
608 rar_high &= ~TXGBE_ETHADDRH_VLD;
609 if (enable_addr != 0)
610 rar_high |= TXGBE_ETHADDRH_VLD;
612 wr32(hw, TXGBE_ETHADDRIDX, index);
613 wr32(hw, TXGBE_ETHADDRL, rar_low);
614 wr32(hw, TXGBE_ETHADDRH, rar_high);
620 * txgbe_clear_rar - Remove Rx address register
621 * @hw: pointer to hardware structure
622 * @index: Receive address register to write
624 * Clears an ethernet address from a receive address register.
626 s32 txgbe_clear_rar(struct txgbe_hw *hw, u32 index)
629 u32 rar_entries = hw->mac.num_rar_entries;
631 /* Make sure we are using a valid rar index range */
632 if (index >= rar_entries) {
633 DEBUGOUT("RAR index %d is out of range.", index);
634 return TXGBE_ERR_INVALID_ARGUMENT;
638 * Some parts put the VMDq setting in the extra RAH bits,
639 * so save everything except the lower 16 bits that hold part
640 * of the address and the address valid bit.
642 wr32(hw, TXGBE_ETHADDRIDX, index);
643 rar_high = rd32(hw, TXGBE_ETHADDRH);
644 rar_high &= ~(TXGBE_ETHADDRH_AD_MASK | TXGBE_ETHADDRH_VLD);
646 wr32(hw, TXGBE_ETHADDRL, 0);
647 wr32(hw, TXGBE_ETHADDRH, rar_high);
649 /* clear VMDq pool/queue selection for this RAR */
650 hw->mac.clear_vmdq(hw, index, BIT_MASK32);
656 * txgbe_init_rx_addrs - Initializes receive address filters.
657 * @hw: pointer to hardware structure
659 * Places the MAC address in receive address register 0 and clears the rest
660 * of the receive address registers. Clears the multicast table. Assumes
661 * the receiver is in reset when the routine is called.
663 s32 txgbe_init_rx_addrs(struct txgbe_hw *hw)
667 u32 rar_entries = hw->mac.num_rar_entries;
670 * If the current mac address is valid, assume it is a software override
671 * to the permanent address.
672 * Otherwise, use the permanent address from the eeprom.
674 if (txgbe_validate_mac_addr(hw->mac.addr) ==
675 TXGBE_ERR_INVALID_MAC_ADDR) {
676 /* Get the MAC address from the RAR0 for later reference */
677 hw->mac.get_mac_addr(hw, hw->mac.addr);
679 DEBUGOUT(" Keeping Current RAR0 Addr = "
680 RTE_ETHER_ADDR_PRT_FMT,
681 hw->mac.addr[0], hw->mac.addr[1],
682 hw->mac.addr[2], hw->mac.addr[3],
683 hw->mac.addr[4], hw->mac.addr[5]);
685 /* Setup the receive address. */
686 DEBUGOUT("Overriding MAC Address in RAR[0]");
687 DEBUGOUT(" New MAC Addr = "
688 RTE_ETHER_ADDR_PRT_FMT,
689 hw->mac.addr[0], hw->mac.addr[1],
690 hw->mac.addr[2], hw->mac.addr[3],
691 hw->mac.addr[4], hw->mac.addr[5]);
693 hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
696 /* clear VMDq pool/queue selection for RAR 0 */
697 hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
699 hw->addr_ctrl.overflow_promisc = 0;
701 hw->addr_ctrl.rar_used_count = 1;
703 /* Zero out the other receive addresses. */
704 DEBUGOUT("Clearing RAR[1-%d]", rar_entries - 1);
705 for (i = 1; i < rar_entries; i++) {
706 wr32(hw, TXGBE_ETHADDRIDX, i);
707 wr32(hw, TXGBE_ETHADDRL, 0);
708 wr32(hw, TXGBE_ETHADDRH, 0);
712 hw->addr_ctrl.mta_in_use = 0;
713 psrctl = rd32(hw, TXGBE_PSRCTL);
714 psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
715 psrctl |= TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
716 wr32(hw, TXGBE_PSRCTL, psrctl);
718 DEBUGOUT(" Clearing MTA");
719 for (i = 0; i < hw->mac.mcft_size; i++)
720 wr32(hw, TXGBE_MCADDRTBL(i), 0);
722 txgbe_init_uta_tables(hw);
728 * txgbe_mta_vector - Determines bit-vector in multicast table to set
729 * @hw: pointer to hardware structure
730 * @mc_addr: the multicast address
732 * Extracts the 12 bits, from a multicast address, to determine which
733 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
734 * incoming rx multicast addresses, to determine the bit-vector to check in
735 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
736 * by the MO field of the PSRCTRL. The MO field is set during initialization
739 static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
743 switch (hw->mac.mc_filter_type) {
744 case 0: /* use bits [47:36] of the address */
745 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
747 case 1: /* use bits [46:35] of the address */
748 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
750 case 2: /* use bits [45:34] of the address */
751 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
753 case 3: /* use bits [43:32] of the address */
754 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
756 default: /* Invalid mc_filter_type */
757 DEBUGOUT("MC filter type param set incorrectly");
762 /* vector can only be 12-bits or boundary will be exceeded */
768 * txgbe_set_mta - Set bit-vector in multicast table
769 * @hw: pointer to hardware structure
770 * @mc_addr: Multicast address
772 * Sets the bit-vector in the multicast table.
774 void txgbe_set_mta(struct txgbe_hw *hw, u8 *mc_addr)
780 hw->addr_ctrl.mta_in_use++;
782 vector = txgbe_mta_vector(hw, mc_addr);
783 DEBUGOUT(" bit-vector = 0x%03X", vector);
786 * The MTA is a register array of 128 32-bit registers. It is treated
787 * like an array of 4096 bits. We want to set bit
788 * BitArray[vector_value]. So we figure out what register the bit is
789 * in, read it, OR in the new bit, then write back the new value. The
790 * register is determined by the upper 7 bits of the vector value and
791 * the bit within that register are determined by the lower 5 bits of
794 vector_reg = (vector >> 5) & 0x7F;
795 vector_bit = vector & 0x1F;
796 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
800 * txgbe_update_mc_addr_list - Updates MAC list of multicast addresses
801 * @hw: pointer to hardware structure
802 * @mc_addr_list: the list of new multicast addresses
803 * @mc_addr_count: number of addresses
804 * @next: iterator function to walk the multicast address list
805 * @clear: flag, when set clears the table beforehand
807 * When the clear flag is set, the given list replaces any existing list.
808 * Hashes the given addresses into the multicast table.
810 s32 txgbe_update_mc_addr_list(struct txgbe_hw *hw, u8 *mc_addr_list,
811 u32 mc_addr_count, txgbe_mc_addr_itr next,
818 * Set the new number of MC addresses that we are being requested to
821 hw->addr_ctrl.num_mc_addrs = mc_addr_count;
822 hw->addr_ctrl.mta_in_use = 0;
824 /* Clear mta_shadow */
826 DEBUGOUT(" Clearing MTA");
827 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
830 /* Update mta_shadow */
831 for (i = 0; i < mc_addr_count; i++) {
832 DEBUGOUT(" Adding the multicast addresses:");
833 txgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
837 for (i = 0; i < hw->mac.mcft_size; i++)
838 wr32a(hw, TXGBE_MCADDRTBL(0), i,
839 hw->mac.mta_shadow[i]);
841 if (hw->addr_ctrl.mta_in_use > 0) {
842 u32 psrctl = rd32(hw, TXGBE_PSRCTL);
843 psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
844 psrctl |= TXGBE_PSRCTL_MCHFENA |
845 TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
846 wr32(hw, TXGBE_PSRCTL, psrctl);
849 DEBUGOUT("txgbe update mc addr list complete");
854 * txgbe_fc_enable - Enable flow control
855 * @hw: pointer to hardware structure
857 * Enable flow control according to the current settings.
859 s32 txgbe_fc_enable(struct txgbe_hw *hw)
862 u32 mflcn_reg, fccfg_reg;
867 /* Validate the water mark configuration */
868 if (!hw->fc.pause_time) {
869 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
873 /* Low water mark of zero causes XOFF floods */
874 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
875 if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
876 hw->fc.high_water[i]) {
877 if (!hw->fc.low_water[i] ||
878 hw->fc.low_water[i] >= hw->fc.high_water[i]) {
879 DEBUGOUT("Invalid water mark configuration");
880 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
886 /* Negotiate the fc mode to use */
887 hw->mac.fc_autoneg(hw);
889 /* Disable any previous flow control settings */
890 mflcn_reg = rd32(hw, TXGBE_RXFCCFG);
891 mflcn_reg &= ~(TXGBE_RXFCCFG_FC | TXGBE_RXFCCFG_PFC);
893 fccfg_reg = rd32(hw, TXGBE_TXFCCFG);
894 fccfg_reg &= ~(TXGBE_TXFCCFG_FC | TXGBE_TXFCCFG_PFC);
897 * The possible values of fc.current_mode are:
898 * 0: Flow control is completely disabled
899 * 1: Rx flow control is enabled (we can receive pause frames,
900 * but not send pause frames).
901 * 2: Tx flow control is enabled (we can send pause frames but
902 * we do not support receiving pause frames).
903 * 3: Both Rx and Tx flow control (symmetric) are enabled.
906 switch (hw->fc.current_mode) {
909 * Flow control is disabled by software override or autoneg.
910 * The code below will actually disable it in the HW.
913 case txgbe_fc_rx_pause:
915 * Rx Flow control is enabled and Tx Flow control is
916 * disabled by software override. Since there really
917 * isn't a way to advertise that we are capable of RX
918 * Pause ONLY, we will advertise that we support both
919 * symmetric and asymmetric Rx PAUSE. Later, we will
920 * disable the adapter's ability to send PAUSE frames.
922 mflcn_reg |= TXGBE_RXFCCFG_FC;
924 case txgbe_fc_tx_pause:
926 * Tx Flow control is enabled, and Rx Flow control is
927 * disabled by software override.
929 fccfg_reg |= TXGBE_TXFCCFG_FC;
932 /* Flow control (both Rx and Tx) is enabled by SW override. */
933 mflcn_reg |= TXGBE_RXFCCFG_FC;
934 fccfg_reg |= TXGBE_TXFCCFG_FC;
937 DEBUGOUT("Flow control param set incorrectly");
938 err = TXGBE_ERR_CONFIG;
942 /* Set 802.3x based flow control settings. */
943 wr32(hw, TXGBE_RXFCCFG, mflcn_reg);
944 wr32(hw, TXGBE_TXFCCFG, fccfg_reg);
946 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
947 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
948 if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
949 hw->fc.high_water[i]) {
950 fcrtl = TXGBE_FCWTRLO_TH(hw->fc.low_water[i]) |
952 fcrth = TXGBE_FCWTRHI_TH(hw->fc.high_water[i]) |
956 * In order to prevent Tx hangs when the internal Tx
957 * switch is enabled we must set the high water mark
958 * to the Rx packet buffer size - 24KB. This allows
959 * the Tx switch to function even under heavy Rx
963 fcrth = rd32(hw, TXGBE_PBRXSIZE(i)) - 24576;
965 wr32(hw, TXGBE_FCWTRLO(i), fcrtl);
966 wr32(hw, TXGBE_FCWTRHI(i), fcrth);
969 /* Configure pause time (2 TCs per register) */
970 pause_time = TXGBE_RXFCFSH_TIME(hw->fc.pause_time);
971 for (i = 0; i < (TXGBE_DCB_TC_MAX / 2); i++)
972 wr32(hw, TXGBE_FCXOFFTM(i), pause_time * 0x00010001);
974 /* Configure flow control refresh threshold value */
975 wr32(hw, TXGBE_RXFCRFSH, hw->fc.pause_time / 2);
982 * txgbe_negotiate_fc - Negotiate flow control
983 * @hw: pointer to hardware structure
984 * @adv_reg: flow control advertised settings
985 * @lp_reg: link partner's flow control settings
986 * @adv_sym: symmetric pause bit in advertisement
987 * @adv_asm: asymmetric pause bit in advertisement
988 * @lp_sym: symmetric pause bit in link partner advertisement
989 * @lp_asm: asymmetric pause bit in link partner advertisement
991 * Find the intersection between advertised settings and link partner's
992 * advertised settings
994 s32 txgbe_negotiate_fc(struct txgbe_hw *hw, u32 adv_reg, u32 lp_reg,
995 u32 adv_sym, u32 adv_asm, u32 lp_sym, u32 lp_asm)
997 if ((!(adv_reg)) || (!(lp_reg))) {
998 DEBUGOUT("Local or link partner's advertised flow control settings are NULL. Local: %x, link partner: %x",
1000 return TXGBE_ERR_FC_NOT_NEGOTIATED;
1003 if ((adv_reg & adv_sym) && (lp_reg & lp_sym)) {
1005 * Now we need to check if the user selected Rx ONLY
1006 * of pause frames. In this case, we had to advertise
1007 * FULL flow control because we could not advertise RX
1008 * ONLY. Hence, we must now check to see if we need to
1009 * turn OFF the TRANSMISSION of PAUSE frames.
1011 if (hw->fc.requested_mode == txgbe_fc_full) {
1012 hw->fc.current_mode = txgbe_fc_full;
1013 DEBUGOUT("Flow Control = FULL.");
1015 hw->fc.current_mode = txgbe_fc_rx_pause;
1016 DEBUGOUT("Flow Control=RX PAUSE frames only");
1018 } else if (!(adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1019 (lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1020 hw->fc.current_mode = txgbe_fc_tx_pause;
1021 DEBUGOUT("Flow Control = TX PAUSE frames only.");
1022 } else if ((adv_reg & adv_sym) && (adv_reg & adv_asm) &&
1023 !(lp_reg & lp_sym) && (lp_reg & lp_asm)) {
1024 hw->fc.current_mode = txgbe_fc_rx_pause;
1025 DEBUGOUT("Flow Control = RX PAUSE frames only.");
1027 hw->fc.current_mode = txgbe_fc_none;
1028 DEBUGOUT("Flow Control = NONE.");
1034 * txgbe_fc_autoneg_fiber - Enable flow control on 1 gig fiber
1035 * @hw: pointer to hardware structure
1037 * Enable flow control according on 1 gig fiber.
1039 STATIC s32 txgbe_fc_autoneg_fiber(struct txgbe_hw *hw)
1041 u32 pcs_anadv_reg, pcs_lpab_reg;
1042 s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
1045 * On multispeed fiber at 1g, bail out if
1046 * - link is up but AN did not complete, or if
1047 * - link is up and AN completed but timed out
1050 pcs_anadv_reg = rd32_epcs(hw, SR_MII_MMD_AN_ADV);
1051 pcs_lpab_reg = rd32_epcs(hw, SR_MII_MMD_LP_BABL);
1053 err = txgbe_negotiate_fc(hw, pcs_anadv_reg,
1055 SR_MII_MMD_AN_ADV_PAUSE_SYM,
1056 SR_MII_MMD_AN_ADV_PAUSE_ASM,
1057 SR_MII_MMD_AN_ADV_PAUSE_SYM,
1058 SR_MII_MMD_AN_ADV_PAUSE_ASM);
1064 * txgbe_fc_autoneg_backplane - Enable flow control IEEE clause 37
1065 * @hw: pointer to hardware structure
1067 * Enable flow control according to IEEE clause 37.
1069 STATIC s32 txgbe_fc_autoneg_backplane(struct txgbe_hw *hw)
1071 u32 anlp1_reg, autoc_reg;
1072 s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
1075 * Read the 10g AN autoc and LP ability registers and resolve
1076 * local flow control settings accordingly
1078 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
1079 anlp1_reg = rd32_epcs(hw, SR_AN_MMD_LP_ABL1);
1081 err = txgbe_negotiate_fc(hw, autoc_reg,
1083 SR_AN_MMD_ADV_REG1_PAUSE_SYM,
1084 SR_AN_MMD_ADV_REG1_PAUSE_ASM,
1085 SR_AN_MMD_ADV_REG1_PAUSE_SYM,
1086 SR_AN_MMD_ADV_REG1_PAUSE_ASM);
1092 * txgbe_fc_autoneg_copper - Enable flow control IEEE clause 37
1093 * @hw: pointer to hardware structure
1095 * Enable flow control according to IEEE clause 37.
1097 STATIC s32 txgbe_fc_autoneg_copper(struct txgbe_hw *hw)
1099 u16 technology_ability_reg = 0;
1100 u16 lp_technology_ability_reg = 0;
1102 hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
1103 TXGBE_MD_DEV_AUTO_NEG,
1104 &technology_ability_reg);
1105 hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_LP,
1106 TXGBE_MD_DEV_AUTO_NEG,
1107 &lp_technology_ability_reg);
1109 return txgbe_negotiate_fc(hw, (u32)technology_ability_reg,
1110 (u32)lp_technology_ability_reg,
1111 TXGBE_TAF_SYM_PAUSE, TXGBE_TAF_ASM_PAUSE,
1112 TXGBE_TAF_SYM_PAUSE, TXGBE_TAF_ASM_PAUSE);
1116 * txgbe_fc_autoneg - Configure flow control
1117 * @hw: pointer to hardware structure
1119 * Compares our advertised flow control capabilities to those advertised by
1120 * our link partner, and determines the proper flow control mode to use.
1122 void txgbe_fc_autoneg(struct txgbe_hw *hw)
1124 s32 err = TXGBE_ERR_FC_NOT_NEGOTIATED;
1129 * AN should have completed when the cable was plugged in.
1130 * Look for reasons to bail out. Bail out if:
1131 * - FC autoneg is disabled, or if
1134 if (hw->fc.disable_fc_autoneg) {
1135 DEBUGOUT("Flow control autoneg is disabled");
1139 hw->mac.check_link(hw, &speed, &link_up, false);
1141 DEBUGOUT("The link is down");
1145 switch (hw->phy.media_type) {
1146 /* Autoneg flow control on fiber adapters */
1147 case txgbe_media_type_fiber_qsfp:
1148 case txgbe_media_type_fiber:
1149 if (speed == TXGBE_LINK_SPEED_1GB_FULL)
1150 err = txgbe_fc_autoneg_fiber(hw);
1153 /* Autoneg flow control on backplane adapters */
1154 case txgbe_media_type_backplane:
1155 err = txgbe_fc_autoneg_backplane(hw);
1158 /* Autoneg flow control on copper adapters */
1159 case txgbe_media_type_copper:
1160 if (txgbe_device_supports_autoneg_fc(hw))
1161 err = txgbe_fc_autoneg_copper(hw);
1170 hw->fc.fc_was_autonegged = true;
1172 hw->fc.fc_was_autonegged = false;
1173 hw->fc.current_mode = hw->fc.requested_mode;
1178 * txgbe_acquire_swfw_sync - Acquire SWFW semaphore
1179 * @hw: pointer to hardware structure
1180 * @mask: Mask to specify which semaphore to acquire
1182 * Acquires the SWFW semaphore through the MNGSEM register for the specified
1183 * function (CSR, PHY0, PHY1, EEPROM, Flash)
1185 s32 txgbe_acquire_swfw_sync(struct txgbe_hw *hw, u32 mask)
1188 u32 swmask = TXGBE_MNGSEM_SW(mask);
1189 u32 fwmask = TXGBE_MNGSEM_FW(mask);
1193 for (i = 0; i < timeout; i++) {
1195 * SW NVM semaphore bit is used for access to all
1196 * SW_FW_SYNC bits (not just NVM)
1198 if (txgbe_get_eeprom_semaphore(hw))
1199 return TXGBE_ERR_SWFW_SYNC;
1201 mngsem = rd32(hw, TXGBE_MNGSEM);
1202 if (mngsem & (fwmask | swmask)) {
1203 /* Resource is currently in use by FW or SW */
1204 txgbe_release_eeprom_semaphore(hw);
1208 wr32(hw, TXGBE_MNGSEM, mngsem);
1209 txgbe_release_eeprom_semaphore(hw);
1214 /* If time expired clear the bits holding the lock and retry */
1215 if (mngsem & (fwmask | swmask))
1216 txgbe_release_swfw_sync(hw, mngsem & (fwmask | swmask));
1219 return TXGBE_ERR_SWFW_SYNC;
1223 * txgbe_release_swfw_sync - Release SWFW semaphore
1224 * @hw: pointer to hardware structure
1225 * @mask: Mask to specify which semaphore to release
1227 * Releases the SWFW semaphore through the MNGSEM register for the specified
1228 * function (CSR, PHY0, PHY1, EEPROM, Flash)
1230 void txgbe_release_swfw_sync(struct txgbe_hw *hw, u32 mask)
1235 txgbe_get_eeprom_semaphore(hw);
1237 mngsem = rd32(hw, TXGBE_MNGSEM);
1239 wr32(hw, TXGBE_MNGSEM, mngsem);
1241 txgbe_release_eeprom_semaphore(hw);
1245 * txgbe_disable_sec_rx_path - Stops the receive data path
1246 * @hw: pointer to hardware structure
1248 * Stops the receive data path and waits for the HW to internally empty
1249 * the Rx security block
1251 s32 txgbe_disable_sec_rx_path(struct txgbe_hw *hw)
1253 #define TXGBE_MAX_SECRX_POLL 4000
1258 secrxreg = rd32(hw, TXGBE_SECRXCTL);
1259 secrxreg |= TXGBE_SECRXCTL_XDSA;
1260 wr32(hw, TXGBE_SECRXCTL, secrxreg);
1261 for (i = 0; i < TXGBE_MAX_SECRX_POLL; i++) {
1262 secrxreg = rd32(hw, TXGBE_SECRXSTAT);
1263 if (!(secrxreg & TXGBE_SECRXSTAT_RDY))
1264 /* Use interrupt-safe sleep just in case */
1270 /* For informational purposes only */
1271 if (i >= TXGBE_MAX_SECRX_POLL)
1272 DEBUGOUT("Rx unit being enabled before security path fully disabled. Continuing with init.");
1278 * txgbe_enable_sec_rx_path - Enables the receive data path
1279 * @hw: pointer to hardware structure
1281 * Enables the receive data path.
1283 s32 txgbe_enable_sec_rx_path(struct txgbe_hw *hw)
1287 secrxreg = rd32(hw, TXGBE_SECRXCTL);
1288 secrxreg &= ~TXGBE_SECRXCTL_XDSA;
1289 wr32(hw, TXGBE_SECRXCTL, secrxreg);
1296 * txgbe_disable_sec_tx_path - Stops the transmit data path
1297 * @hw: pointer to hardware structure
1299 * Stops the transmit data path and waits for the HW to internally empty
1300 * the Tx security block
1302 int txgbe_disable_sec_tx_path(struct txgbe_hw *hw)
1304 #define TXGBE_MAX_SECTX_POLL 40
1309 sectxreg = rd32(hw, TXGBE_SECTXCTL);
1310 sectxreg |= TXGBE_SECTXCTL_XDSA;
1311 wr32(hw, TXGBE_SECTXCTL, sectxreg);
1312 for (i = 0; i < TXGBE_MAX_SECTX_POLL; i++) {
1313 sectxreg = rd32(hw, TXGBE_SECTXSTAT);
1314 if (sectxreg & TXGBE_SECTXSTAT_RDY)
1316 /* Use interrupt-safe sleep just in case */
1320 /* For informational purposes only */
1321 if (i >= TXGBE_MAX_SECTX_POLL)
1322 DEBUGOUT("Tx unit being enabled before security path fully disabled. Continuing with init.");
1328 * txgbe_enable_sec_tx_path - Enables the transmit data path
1329 * @hw: pointer to hardware structure
1331 * Enables the transmit data path.
1333 int txgbe_enable_sec_tx_path(struct txgbe_hw *hw)
1337 sectxreg = rd32(hw, TXGBE_SECTXCTL);
1338 sectxreg &= ~TXGBE_SECTXCTL_XDSA;
1339 wr32(hw, TXGBE_SECTXCTL, sectxreg);
1346 * txgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
1347 * @hw: pointer to hardware structure
1348 * @san_mac_offset: SAN MAC address offset
1350 * This function will read the EEPROM location for the SAN MAC address
1351 * pointer, and returns the value at that location. This is used in both
1352 * get and set mac_addr routines.
1354 static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
1355 u16 *san_mac_offset)
1360 * First read the EEPROM pointer to see if the MAC addresses are
1363 err = hw->rom.readw_sw(hw, TXGBE_SAN_MAC_ADDR_PTR,
1366 DEBUGOUT("eeprom at offset %d failed",
1367 TXGBE_SAN_MAC_ADDR_PTR);
1374 * txgbe_get_san_mac_addr - SAN MAC address retrieval from the EEPROM
1375 * @hw: pointer to hardware structure
1376 * @san_mac_addr: SAN MAC address
1378 * Reads the SAN MAC address from the EEPROM, if it's available. This is
1379 * per-port, so set_lan_id() must be called before reading the addresses.
1380 * set_lan_id() is called by identify_sfp(), but this cannot be relied
1381 * upon for non-SFP connections, so we must call it here.
1383 s32 txgbe_get_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
1385 u16 san_mac_data, san_mac_offset;
1390 * First read the EEPROM pointer to see if the MAC addresses are
1391 * available. If they're not, no point in calling set_lan_id() here.
1393 err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
1394 if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
1395 goto san_mac_addr_out;
1397 /* apply the port offset to the address offset */
1398 (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
1399 (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
1400 for (i = 0; i < 3; i++) {
1401 err = hw->rom.read16(hw, san_mac_offset,
1404 DEBUGOUT("eeprom read at offset %d failed",
1406 goto san_mac_addr_out;
1408 san_mac_addr[i * 2] = (u8)(san_mac_data);
1409 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
1416 * No addresses available in this EEPROM. It's not an
1417 * error though, so just wipe the local address and return.
1419 for (i = 0; i < 6; i++)
1420 san_mac_addr[i] = 0xFF;
1425 * txgbe_set_san_mac_addr - Write the SAN MAC address to the EEPROM
1426 * @hw: pointer to hardware structure
1427 * @san_mac_addr: SAN MAC address
1429 * Write a SAN MAC address to the EEPROM.
1431 s32 txgbe_set_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
1434 u16 san_mac_data, san_mac_offset;
1437 /* Look for SAN mac address pointer. If not defined, return */
1438 err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
1439 if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
1440 return TXGBE_ERR_NO_SAN_ADDR_PTR;
1442 /* Apply the port offset to the address offset */
1443 (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
1444 (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
1446 for (i = 0; i < 3; i++) {
1447 san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
1448 san_mac_data |= (u16)(san_mac_addr[i * 2]);
1449 hw->rom.write16(hw, san_mac_offset, san_mac_data);
1457 * txgbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
1458 * @hw: pointer to hardware struct
1459 * @rar: receive address register index to disassociate
1460 * @vmdq: VMDq pool index to remove from the rar
1462 s32 txgbe_clear_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
1464 u32 mpsar_lo, mpsar_hi;
1465 u32 rar_entries = hw->mac.num_rar_entries;
1467 /* Make sure we are using a valid rar index range */
1468 if (rar >= rar_entries) {
1469 DEBUGOUT("RAR index %d is out of range.", rar);
1470 return TXGBE_ERR_INVALID_ARGUMENT;
1473 wr32(hw, TXGBE_ETHADDRIDX, rar);
1474 mpsar_lo = rd32(hw, TXGBE_ETHADDRASSL);
1475 mpsar_hi = rd32(hw, TXGBE_ETHADDRASSH);
1477 if (TXGBE_REMOVED(hw->hw_addr))
1480 if (!mpsar_lo && !mpsar_hi)
1483 if (vmdq == BIT_MASK32) {
1485 wr32(hw, TXGBE_ETHADDRASSL, 0);
1489 wr32(hw, TXGBE_ETHADDRASSH, 0);
1492 } else if (vmdq < 32) {
1493 mpsar_lo &= ~(1 << vmdq);
1494 wr32(hw, TXGBE_ETHADDRASSL, mpsar_lo);
1496 mpsar_hi &= ~(1 << (vmdq - 32));
1497 wr32(hw, TXGBE_ETHADDRASSH, mpsar_hi);
1500 /* was that the last pool using this rar? */
1501 if (mpsar_lo == 0 && mpsar_hi == 0 &&
1502 rar != 0 && rar != hw->mac.san_mac_rar_index)
1503 hw->mac.clear_rar(hw, rar);
1509 * txgbe_set_vmdq - Associate a VMDq pool index with a rx address
1510 * @hw: pointer to hardware struct
1511 * @rar: receive address register index to associate with a VMDq index
1512 * @vmdq: VMDq pool index
1514 s32 txgbe_set_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
1517 u32 rar_entries = hw->mac.num_rar_entries;
1519 /* Make sure we are using a valid rar index range */
1520 if (rar >= rar_entries) {
1521 DEBUGOUT("RAR index %d is out of range.", rar);
1522 return TXGBE_ERR_INVALID_ARGUMENT;
1525 wr32(hw, TXGBE_ETHADDRIDX, rar);
1527 mpsar = rd32(hw, TXGBE_ETHADDRASSL);
1529 wr32(hw, TXGBE_ETHADDRASSL, mpsar);
1531 mpsar = rd32(hw, TXGBE_ETHADDRASSH);
1532 mpsar |= 1 << (vmdq - 32);
1533 wr32(hw, TXGBE_ETHADDRASSH, mpsar);
1539 * txgbe_init_uta_tables - Initialize the Unicast Table Array
1540 * @hw: pointer to hardware structure
1542 s32 txgbe_init_uta_tables(struct txgbe_hw *hw)
1546 DEBUGOUT(" Clearing UTA");
1548 for (i = 0; i < 128; i++)
1549 wr32(hw, TXGBE_UCADDRTBL(i), 0);
1555 * txgbe_find_vlvf_slot - find the vlanid or the first empty slot
1556 * @hw: pointer to hardware structure
1557 * @vlan: VLAN id to write to VLAN filter
1558 * @vlvf_bypass: true to find vlanid only, false returns first empty slot if
1562 * return the VLVF index where this VLAN id should be placed
1565 s32 txgbe_find_vlvf_slot(struct txgbe_hw *hw, u32 vlan, bool vlvf_bypass)
1567 s32 regindex, first_empty_slot;
1570 /* short cut the special case */
1574 /* if vlvf_bypass is set we don't want to use an empty slot, we
1575 * will simply bypass the VLVF if there are no entries present in the
1576 * VLVF that contain our VLAN
1578 first_empty_slot = vlvf_bypass ? TXGBE_ERR_NO_SPACE : 0;
1580 /* add VLAN enable bit for comparison */
1581 vlan |= TXGBE_PSRVLAN_EA;
1583 /* Search for the vlan id in the VLVF entries. Save off the first empty
1584 * slot found along the way.
1586 * pre-decrement loop covering (TXGBE_NUM_POOL - 1) .. 1
1588 for (regindex = TXGBE_NUM_POOL; --regindex;) {
1589 wr32(hw, TXGBE_PSRVLANIDX, regindex);
1590 bits = rd32(hw, TXGBE_PSRVLAN);
1593 if (!first_empty_slot && !bits)
1594 first_empty_slot = regindex;
1597 /* If we are here then we didn't find the VLAN. Return first empty
1598 * slot we found during our search, else error.
1600 if (!first_empty_slot)
1601 DEBUGOUT("No space in VLVF.");
1603 return first_empty_slot ? first_empty_slot : TXGBE_ERR_NO_SPACE;
1607 * txgbe_set_vfta - Set VLAN filter table
1608 * @hw: pointer to hardware structure
1609 * @vlan: VLAN id to write to VLAN filter
1610 * @vind: VMDq output index that maps queue to VLAN id in VLVFB
1611 * @vlan_on: boolean flag to turn on/off VLAN
1612 * @vlvf_bypass: boolean flag indicating updating default pool is okay
1614 * Turn on/off specified VLAN in the VLAN filter table.
1616 s32 txgbe_set_vfta(struct txgbe_hw *hw, u32 vlan, u32 vind,
1617 bool vlan_on, bool vlvf_bypass)
1619 u32 regidx, vfta_delta, vfta;
1622 if (vlan > 4095 || vind > 63)
1623 return TXGBE_ERR_PARAM;
1626 * this is a 2 part operation - first the VFTA, then the
1627 * VLVF and VLVFB if VT Mode is set
1628 * We don't write the VFTA until we know the VLVF part succeeded.
1632 * The VFTA is a bitstring made up of 128 32-bit registers
1633 * that enable the particular VLAN id, much like the MTA:
1634 * bits[11-5]: which register
1635 * bits[4-0]: which bit in the register
1638 vfta_delta = 1 << (vlan % 32);
1639 vfta = rd32(hw, TXGBE_VLANTBL(regidx));
1642 * vfta_delta represents the difference between the current value
1643 * of vfta and the value we want in the register. Since the diff
1644 * is an XOR mask we can just update the vfta using an XOR
1646 vfta_delta &= vlan_on ? ~vfta : vfta;
1650 * Call txgbe_set_vlvf to set VLVFB and VLVF
1652 err = txgbe_set_vlvf(hw, vlan, vind, vlan_on, &vfta_delta,
1661 /* Update VFTA now that we are ready for traffic */
1663 wr32(hw, TXGBE_VLANTBL(regidx), vfta);
1669 * txgbe_set_vlvf - Set VLAN Pool Filter
1670 * @hw: pointer to hardware structure
1671 * @vlan: VLAN id to write to VLAN filter
1672 * @vind: VMDq output index that maps queue to VLAN id in PSRVLANPLM
1673 * @vlan_on: boolean flag to turn on/off VLAN in PSRVLAN
1674 * @vfta_delta: pointer to the difference between the current value
1675 * of PSRVLANPLM and the desired value
1676 * @vfta: the desired value of the VFTA
1677 * @vlvf_bypass: boolean flag indicating updating default pool is okay
1679 * Turn on/off specified bit in VLVF table.
1681 s32 txgbe_set_vlvf(struct txgbe_hw *hw, u32 vlan, u32 vind,
1682 bool vlan_on, u32 *vfta_delta, u32 vfta,
1689 if (vlan > 4095 || vind > 63)
1690 return TXGBE_ERR_PARAM;
1692 /* If VT Mode is set
1694 * make sure the vlan is in PSRVLAN
1695 * set the vind bit in the matching PSRVLANPLM
1697 * clear the pool bit and possibly the vind
1699 portctl = rd32(hw, TXGBE_PORTCTL);
1700 if (!(portctl & TXGBE_PORTCTL_NUMVT_MASK))
1703 vlvf_index = txgbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
1707 wr32(hw, TXGBE_PSRVLANIDX, vlvf_index);
1708 bits = rd32(hw, TXGBE_PSRVLANPLM(vind / 32));
1710 /* set the pool bit */
1711 bits |= 1 << (vind % 32);
1715 /* clear the pool bit */
1716 bits ^= 1 << (vind % 32);
1719 !rd32(hw, TXGBE_PSRVLANPLM(vind / 32))) {
1720 /* Clear PSRVLANPLM first, then disable PSRVLAN. Otherwise
1721 * we run the risk of stray packets leaking into
1722 * the PF via the default pool
1725 wr32(hw, TXGBE_PSRVLANPLM(vlan / 32), vfta);
1727 /* disable VLVF and clear remaining bit from pool */
1728 wr32(hw, TXGBE_PSRVLAN, 0);
1729 wr32(hw, TXGBE_PSRVLANPLM(vind / 32), 0);
1734 /* If there are still bits set in the PSRVLANPLM registers
1735 * for the VLAN ID indicated we need to see if the
1736 * caller is requesting that we clear the PSRVLANPLM entry bit.
1737 * If the caller has requested that we clear the PSRVLANPLM
1738 * entry bit but there are still pools/VFs using this VLAN
1739 * ID entry then ignore the request. We're not worried
1740 * about the case where we're turning the PSRVLANPLM VLAN ID
1741 * entry bit on, only when requested to turn it off as
1742 * there may be multiple pools and/or VFs using the
1743 * VLAN ID entry. In that case we cannot clear the
1744 * PSRVLANPLM bit until all pools/VFs using that VLAN ID have also
1745 * been cleared. This will be indicated by "bits" being
1751 /* record pool change and enable VLAN ID if not already enabled */
1752 wr32(hw, TXGBE_PSRVLANPLM(vind / 32), bits);
1753 wr32(hw, TXGBE_PSRVLAN, TXGBE_PSRVLAN_EA | vlan);
1759 * txgbe_clear_vfta - Clear VLAN filter table
1760 * @hw: pointer to hardware structure
1762 * Clears the VLAN filer table, and the VMDq index associated with the filter
1764 s32 txgbe_clear_vfta(struct txgbe_hw *hw)
1768 for (offset = 0; offset < hw->mac.vft_size; offset++)
1769 wr32(hw, TXGBE_VLANTBL(offset), 0);
1771 for (offset = 0; offset < TXGBE_NUM_POOL; offset++) {
1772 wr32(hw, TXGBE_PSRVLANIDX, offset);
1773 wr32(hw, TXGBE_PSRVLAN, 0);
1774 wr32(hw, TXGBE_PSRVLANPLM(0), 0);
1775 wr32(hw, TXGBE_PSRVLANPLM(1), 0);
1782 * txgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
1783 * @hw: pointer to hardware structure
1785 * Contains the logic to identify if we need to verify link for the
1788 static bool txgbe_need_crosstalk_fix(struct txgbe_hw *hw)
1790 /* Does FW say we need the fix */
1791 if (!hw->need_crosstalk_fix)
1794 /* Only consider SFP+ PHYs i.e. media type fiber */
1795 switch (hw->phy.media_type) {
1796 case txgbe_media_type_fiber:
1797 case txgbe_media_type_fiber_qsfp:
1807 * txgbe_check_mac_link - Determine link and speed status
1808 * @hw: pointer to hardware structure
1809 * @speed: pointer to link speed
1810 * @link_up: true when link is up
1811 * @link_up_wait_to_complete: bool used to wait for link up or not
1813 * Reads the links register to determine if link is up and the current speed
1815 s32 txgbe_check_mac_link(struct txgbe_hw *hw, u32 *speed,
1816 bool *link_up, bool link_up_wait_to_complete)
1818 u32 links_reg, links_orig;
1821 /* If Crosstalk fix enabled do the sanity check of making sure
1822 * the SFP+ cage is full.
1824 if (txgbe_need_crosstalk_fix(hw)) {
1827 switch (hw->mac.type) {
1828 case txgbe_mac_raptor:
1829 sfp_cage_full = !rd32m(hw, TXGBE_GPIODATA,
1833 /* sanity check - No SFP+ devices here */
1834 sfp_cage_full = false;
1838 if (!sfp_cage_full) {
1840 *speed = TXGBE_LINK_SPEED_UNKNOWN;
1845 /* clear the old state */
1846 links_orig = rd32(hw, TXGBE_PORTSTAT);
1848 links_reg = rd32(hw, TXGBE_PORTSTAT);
1850 if (links_orig != links_reg) {
1851 DEBUGOUT("LINKS changed from %08X to %08X",
1852 links_orig, links_reg);
1855 if (link_up_wait_to_complete) {
1856 for (i = 0; i < hw->mac.max_link_up_time; i++) {
1857 if (!(links_reg & TXGBE_PORTSTAT_UP)) {
1864 links_reg = rd32(hw, TXGBE_PORTSTAT);
1867 if (links_reg & TXGBE_PORTSTAT_UP)
1873 switch (links_reg & TXGBE_PORTSTAT_BW_MASK) {
1874 case TXGBE_PORTSTAT_BW_10G:
1875 *speed = TXGBE_LINK_SPEED_10GB_FULL;
1877 case TXGBE_PORTSTAT_BW_1G:
1878 *speed = TXGBE_LINK_SPEED_1GB_FULL;
1880 case TXGBE_PORTSTAT_BW_100M:
1881 *speed = TXGBE_LINK_SPEED_100M_FULL;
1884 *speed = TXGBE_LINK_SPEED_UNKNOWN;
1891 * txgbe_get_wwn_prefix - Get alternative WWNN/WWPN prefix from
1893 * @hw: pointer to hardware structure
1894 * @wwnn_prefix: the alternative WWNN prefix
1895 * @wwpn_prefix: the alternative WWPN prefix
1897 * This function will read the EEPROM from the alternative SAN MAC address
1898 * block to check the support for the alternative WWNN/WWPN prefix support.
1900 s32 txgbe_get_wwn_prefix(struct txgbe_hw *hw, u16 *wwnn_prefix,
1904 u16 alt_san_mac_blk_offset;
1906 /* clear output first */
1907 *wwnn_prefix = 0xFFFF;
1908 *wwpn_prefix = 0xFFFF;
1910 /* check if alternative SAN MAC is supported */
1911 offset = TXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
1912 if (hw->rom.readw_sw(hw, offset, &alt_san_mac_blk_offset))
1913 goto wwn_prefix_err;
1915 if (alt_san_mac_blk_offset == 0 || alt_san_mac_blk_offset == 0xFFFF)
1916 goto wwn_prefix_out;
1918 /* check capability in alternative san mac address block */
1919 offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
1920 if (hw->rom.read16(hw, offset, &caps))
1921 goto wwn_prefix_err;
1922 if (!(caps & TXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
1923 goto wwn_prefix_out;
1925 /* get the corresponding prefix for WWNN/WWPN */
1926 offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
1927 if (hw->rom.read16(hw, offset, wwnn_prefix))
1928 DEBUGOUT("eeprom read at offset %d failed", offset);
1930 offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
1931 if (hw->rom.read16(hw, offset, wwpn_prefix))
1932 goto wwn_prefix_err;
1938 DEBUGOUT("eeprom read at offset %d failed", offset);
1943 * txgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
1944 * @hw: pointer to hardware structure
1945 * @enable: enable or disable switch for MAC anti-spoofing
1946 * @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
1949 void txgbe_set_mac_anti_spoofing(struct txgbe_hw *hw, bool enable, int vf)
1951 int vf_target_reg = vf >> 3;
1952 int vf_target_shift = vf % 8;
1955 pfvfspoof = rd32(hw, TXGBE_POOLTXASMAC(vf_target_reg));
1957 pfvfspoof |= (1 << vf_target_shift);
1959 pfvfspoof &= ~(1 << vf_target_shift);
1960 wr32(hw, TXGBE_POOLTXASMAC(vf_target_reg), pfvfspoof);
1964 * txgbe_set_ethertype_anti_spoofing - Configure Ethertype anti-spoofing
1965 * @hw: pointer to hardware structure
1966 * @enable: enable or disable switch for Ethertype anti-spoofing
1967 * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
1970 void txgbe_set_ethertype_anti_spoofing(struct txgbe_hw *hw,
1971 bool enable, int vf)
1973 int vf_target_reg = vf >> 3;
1974 int vf_target_shift = vf % 8;
1977 pfvfspoof = rd32(hw, TXGBE_POOLTXASET(vf_target_reg));
1979 pfvfspoof |= (1 << vf_target_shift);
1981 pfvfspoof &= ~(1 << vf_target_shift);
1982 wr32(hw, TXGBE_POOLTXASET(vf_target_reg), pfvfspoof);
1986 * txgbe_get_device_caps - Get additional device capabilities
1987 * @hw: pointer to hardware structure
1988 * @device_caps: the EEPROM word with the extra device capabilities
1990 * This function will read the EEPROM location for the device capabilities,
1991 * and return the word through device_caps.
1993 s32 txgbe_get_device_caps(struct txgbe_hw *hw, u16 *device_caps)
1995 hw->rom.readw_sw(hw, TXGBE_DEVICE_CAPS, device_caps);
2001 * txgbe_set_pba - Initialize Rx packet buffer
2002 * @hw: pointer to hardware structure
2003 * @num_pb: number of packet buffers to allocate
2004 * @headroom: reserve n KB of headroom
2005 * @strategy: packet buffer allocation strategy
2007 void txgbe_set_pba(struct txgbe_hw *hw, int num_pb, u32 headroom,
2010 u32 pbsize = hw->mac.rx_pb_size;
2012 u32 rxpktsize, txpktsize, txpbthresh;
2014 UNREFERENCED_PARAMETER(hw);
2016 /* Reserve headroom */
2022 /* Divide remaining packet buffer space amongst the number of packet
2023 * buffers requested using supplied strategy.
2026 case PBA_STRATEGY_WEIGHTED:
2027 /* txgbe_dcb_pba_80_48 strategy weight first half of packet
2028 * buffer with 5/8 of the packet buffer space.
2030 rxpktsize = (pbsize * 5) / (num_pb * 4);
2031 pbsize -= rxpktsize * (num_pb / 2);
2033 for (; i < (num_pb / 2); i++)
2034 wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
2035 /* fall through - configure remaining packet buffers */
2036 case PBA_STRATEGY_EQUAL:
2037 rxpktsize = (pbsize / (num_pb - i));
2039 for (; i < num_pb; i++)
2040 wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
2046 /* Only support an equally distributed Tx packet buffer strategy. */
2047 txpktsize = TXGBE_PBTXSIZE_MAX / num_pb;
2048 txpbthresh = (txpktsize / 1024) - TXGBE_TXPKT_SIZE_MAX;
2049 for (i = 0; i < num_pb; i++) {
2050 wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
2051 wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
2054 /* Clear unused TCs, if any, to zero buffer size*/
2055 for (; i < TXGBE_MAX_UP; i++) {
2056 wr32(hw, TXGBE_PBRXSIZE(i), 0);
2057 wr32(hw, TXGBE_PBTXSIZE(i), 0);
2058 wr32(hw, TXGBE_PBTXDMATH(i), 0);
2063 * txgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
2064 * @hw: pointer to the hardware structure
2066 * The MACs can experience issues if TX work is still pending
2067 * when a reset occurs. This function prevents this by flushing the PCIe
2068 * buffers on the system.
2070 void txgbe_clear_tx_pending(struct txgbe_hw *hw)
2072 u32 hlreg0, i, poll;
2075 * If double reset is not requested then all transactions should
2076 * already be clear and as such there is no work to do
2078 if (!(hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
2081 hlreg0 = rd32(hw, TXGBE_PSRCTL);
2082 wr32(hw, TXGBE_PSRCTL, hlreg0 | TXGBE_PSRCTL_LBENA);
2084 /* Wait for a last completion before clearing buffers */
2089 * Before proceeding, make sure that the PCIe block does not have
2090 * transactions pending.
2092 poll = (800 * 11) / 10;
2093 for (i = 0; i < poll; i++)
2096 /* Flush all writes and allow 20usec for all transactions to clear */
2100 /* restore previous register values */
2101 wr32(hw, TXGBE_PSRCTL, hlreg0);
2105 * txgbe_get_thermal_sensor_data - Gathers thermal sensor data
2106 * @hw: pointer to hardware structure
2108 * Returns the thermal sensor data structure
2110 s32 txgbe_get_thermal_sensor_data(struct txgbe_hw *hw)
2112 struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2116 /* Only support thermal sensors attached to physical port 0 */
2117 if (hw->bus.lan_id != 0)
2118 return TXGBE_NOT_IMPLEMENTED;
2120 ts_stat = rd32(hw, TXGBE_TSSTAT);
2121 tsv = (s64)TXGBE_TSSTAT_DATA(ts_stat);
2122 tsv = tsv > 1200 ? tsv : 1200;
2123 tsv = -(48380 << 8) / 1000
2124 + tsv * (31020 << 8) / 100000
2125 - tsv * tsv * (18201 << 8) / 100000000
2126 + tsv * tsv * tsv * (81542 << 8) / 1000000000000
2127 - tsv * tsv * tsv * tsv * (16743 << 8) / 1000000000000000;
2130 data->sensor[0].temp = (s16)tsv;
2136 * txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
2137 * @hw: pointer to hardware structure
2139 * Inits the thermal sensor thresholds according to the NVM map
2140 * and save off the threshold and location values into mac.thermal_sensor_data
2142 s32 txgbe_init_thermal_sensor_thresh(struct txgbe_hw *hw)
2144 struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2146 memset(data, 0, sizeof(struct txgbe_thermal_sensor_data));
2148 if (hw->bus.lan_id != 0)
2149 return TXGBE_NOT_IMPLEMENTED;
2151 wr32(hw, TXGBE_TSCTRL, TXGBE_TSCTRL_EVALMD);
2152 wr32(hw, TXGBE_TSINTR,
2153 TXGBE_TSINTR_AEN | TXGBE_TSINTR_DEN);
2154 wr32(hw, TXGBE_TSEN, TXGBE_TSEN_ENA);
2157 data->sensor[0].alarm_thresh = 100;
2158 wr32(hw, TXGBE_TSATHRE, 677);
2159 data->sensor[0].dalarm_thresh = 90;
2160 wr32(hw, TXGBE_TSDTHRE, 614);
2165 void txgbe_disable_rx(struct txgbe_hw *hw)
2169 pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
2170 if (pfdtxgswc & TXGBE_PSRCTL_LBENA) {
2171 pfdtxgswc &= ~TXGBE_PSRCTL_LBENA;
2172 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
2173 hw->mac.set_lben = true;
2175 hw->mac.set_lben = false;
2178 wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
2179 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
2182 void txgbe_enable_rx(struct txgbe_hw *hw)
2186 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, TXGBE_MACRXCFG_ENA);
2187 wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, TXGBE_PBRXCTL_ENA);
2189 if (hw->mac.set_lben) {
2190 pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
2191 pfdtxgswc |= TXGBE_PSRCTL_LBENA;
2192 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
2193 hw->mac.set_lben = false;
2198 * txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
2199 * @hw: pointer to hardware structure
2200 * @speed: new link speed
2201 * @autoneg_wait_to_complete: true when waiting for completion is needed
2203 * Set the link speed in the MAC and/or PHY register and restarts link.
2205 s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
2207 bool autoneg_wait_to_complete)
2209 u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2210 u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2214 bool autoneg, link_up = false;
2216 /* Mask off requested but non-supported speeds */
2217 status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
2221 speed &= link_speed;
2223 /* Try each speed one by one, highest priority first. We do this in
2224 * software because 10Gb fiber doesn't support speed autonegotiation.
2226 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
2228 highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
2230 /* Set the module link speed */
2231 switch (hw->phy.media_type) {
2232 case txgbe_media_type_fiber:
2233 hw->mac.set_rate_select_speed(hw,
2234 TXGBE_LINK_SPEED_10GB_FULL);
2236 case txgbe_media_type_fiber_qsfp:
2237 /* QSFP module automatically detects MAC link speed */
2240 DEBUGOUT("Unexpected media type.");
2244 /* Allow module to change analog characteristics (1G->10G) */
2247 status = hw->mac.setup_mac_link(hw,
2248 TXGBE_LINK_SPEED_10GB_FULL,
2249 autoneg_wait_to_complete);
2253 /* Flap the Tx laser if it has not already been done */
2254 hw->mac.flap_tx_laser(hw);
2256 /* Wait for the controller to acquire link. Per IEEE 802.3ap,
2257 * Section 73.10.2, we may have to wait up to 500ms if KR is
2258 * attempted. uses the same timing for 10g SFI.
2260 for (i = 0; i < 5; i++) {
2261 /* Wait for the link partner to also set speed */
2264 /* If we have link, just jump out */
2265 status = hw->mac.check_link(hw, &link_speed,
2275 if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
2277 if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
2278 highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;
2280 /* Set the module link speed */
2281 switch (hw->phy.media_type) {
2282 case txgbe_media_type_fiber:
2283 hw->mac.set_rate_select_speed(hw,
2284 TXGBE_LINK_SPEED_1GB_FULL);
2286 case txgbe_media_type_fiber_qsfp:
2287 /* QSFP module automatically detects link speed */
2290 DEBUGOUT("Unexpected media type.");
2294 /* Allow module to change analog characteristics (10G->1G) */
2297 status = hw->mac.setup_mac_link(hw,
2298 TXGBE_LINK_SPEED_1GB_FULL,
2299 autoneg_wait_to_complete);
2303 /* Flap the Tx laser if it has not already been done */
2304 hw->mac.flap_tx_laser(hw);
2306 /* Wait for the link partner to also set speed */
2309 /* If we have link, just jump out */
2310 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
2318 /* We didn't get link. Configure back to the highest speed we tried,
2319 * (if there was more than one). We call ourselves back with just the
2320 * single highest speed that the user requested.
2323 status = txgbe_setup_mac_link_multispeed_fiber(hw,
2325 autoneg_wait_to_complete);
2328 /* Set autoneg_advertised value based on input link speed */
2329 hw->phy.autoneg_advertised = 0;
2331 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
2332 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
2334 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
2335 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
2341 * txgbe_init_shared_code - Initialize the shared code
2342 * @hw: pointer to hardware structure
2344 * This will assign function pointers and assign the MAC type and PHY code.
2345 * Does not touch the hardware. This function must be called prior to any
2346 * other function in the shared code. The txgbe_hw structure should be
2347 * memset to 0 prior to calling this function. The following fields in
2348 * hw structure should be filled in prior to calling this function:
2349 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
2350 * subsystem_vendor_id, and revision_id
2352 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
2359 txgbe_set_mac_type(hw);
2361 txgbe_init_ops_dummy(hw);
2362 switch (hw->mac.type) {
2363 case txgbe_mac_raptor:
2364 status = txgbe_init_ops_pf(hw);
2366 case txgbe_mac_raptor_vf:
2367 status = txgbe_init_ops_vf(hw);
2370 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2373 hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
2375 hw->bus.set_lan_id(hw);
2381 * txgbe_set_mac_type - Sets MAC type
2382 * @hw: pointer to the HW structure
2384 * This function sets the mac type of the adapter based on the
2385 * vendor ID and device ID stored in the hw structure.
2387 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
2391 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
2392 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
2393 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2396 switch (hw->device_id) {
2397 case TXGBE_DEV_ID_SP1000:
2398 case TXGBE_DEV_ID_WX1820:
2399 hw->mac.type = txgbe_mac_raptor;
2401 case TXGBE_DEV_ID_SP1000_VF:
2402 case TXGBE_DEV_ID_WX1820_VF:
2403 hw->phy.media_type = txgbe_media_type_virtual;
2404 hw->mac.type = txgbe_mac_raptor_vf;
2407 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2408 DEBUGOUT("Unsupported device id: %x", hw->device_id);
2412 DEBUGOUT("found mac: %d, returns: %d",
2417 void txgbe_init_mac_link_ops(struct txgbe_hw *hw)
2419 struct txgbe_mac_info *mac = &hw->mac;
2422 * enable the laser control functions for SFP+ fiber
2423 * and MNG not enabled
2425 if (hw->phy.media_type == txgbe_media_type_fiber &&
2426 !txgbe_mng_enabled(hw)) {
2427 mac->disable_tx_laser =
2428 txgbe_disable_tx_laser_multispeed_fiber;
2429 mac->enable_tx_laser =
2430 txgbe_enable_tx_laser_multispeed_fiber;
2431 mac->flap_tx_laser =
2432 txgbe_flap_tx_laser_multispeed_fiber;
2435 if ((hw->phy.media_type == txgbe_media_type_fiber ||
2436 hw->phy.media_type == txgbe_media_type_fiber_qsfp) &&
2437 hw->phy.multispeed_fiber) {
2438 /* Set up dual speed SFP+ support */
2439 mac->setup_link = txgbe_setup_mac_link_multispeed_fiber;
2440 mac->setup_mac_link = txgbe_setup_mac_link;
2441 mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
2443 mac->setup_link = txgbe_setup_mac_link;
2444 mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
2449 * txgbe_init_phy_raptor - PHY/SFP specific init
2450 * @hw: pointer to hardware structure
2452 * Initialize any function pointers that were not able to be
2453 * set during init_shared_code because the PHY/SFP type was
2454 * not known. Perform the SFP init if necessary.
2457 s32 txgbe_init_phy_raptor(struct txgbe_hw *hw)
2459 struct txgbe_mac_info *mac = &hw->mac;
2460 struct txgbe_phy_info *phy = &hw->phy;
2463 if ((hw->device_id & 0xFF) == TXGBE_DEV_ID_QSFP) {
2464 /* Store flag indicating I2C bus access control unit. */
2465 hw->phy.qsfp_shared_i2c_bus = TRUE;
2467 /* Initialize access to QSFP+ I2C bus */
2471 /* Identify the PHY or SFP module */
2472 err = phy->identify(hw);
2473 if (err == TXGBE_ERR_SFP_NOT_SUPPORTED)
2474 goto init_phy_ops_out;
2476 /* Setup function pointers based on detected SFP module and speeds */
2477 txgbe_init_mac_link_ops(hw);
2479 /* If copper media, overwrite with copper function pointers */
2480 if (phy->media_type == txgbe_media_type_copper) {
2481 mac->setup_link = txgbe_setup_copper_link_raptor;
2482 mac->get_link_capabilities =
2483 txgbe_get_copper_link_capabilities;
2486 if (phy->media_type == txgbe_media_type_backplane) {
2487 mac->kr_handle = txgbe_kr_handle;
2488 mac->bp_down_event = txgbe_bp_down_event;
2491 /* Set necessary function pointers based on PHY type */
2492 switch (hw->phy.type) {
2494 phy->setup_link = txgbe_setup_phy_link_tnx;
2495 phy->check_link = txgbe_check_phy_link_tnx;
2505 s32 txgbe_setup_sfp_modules(struct txgbe_hw *hw)
2509 if (hw->phy.sfp_type == txgbe_sfp_type_unknown)
2512 txgbe_init_mac_link_ops(hw);
2514 /* PHY config will finish before releasing the semaphore */
2515 err = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2517 return TXGBE_ERR_SWFW_SYNC;
2519 /* Release the semaphore */
2520 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2522 /* Delay obtaining semaphore again to allow FW access
2523 * prot_autoc_write uses the semaphore too.
2525 msec_delay(hw->rom.semaphore_delay);
2528 DEBUGOUT("sfp module setup not complete");
2529 return TXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
2536 * txgbe_prot_autoc_read_raptor - Hides MAC differences needed for AUTOC read
2537 * @hw: pointer to hardware structure
2538 * @locked: Return the if we locked for this read.
2539 * @value: Value we read from AUTOC
2541 * For this part we need to wrap read-modify-writes with a possible
2542 * FW/SW lock. It is assumed this lock will be freed with the next
2543 * prot_autoc_write_raptor().
2545 s32 txgbe_prot_autoc_read_raptor(struct txgbe_hw *hw, bool *locked, u64 *value)
2548 bool lock_state = false;
2550 /* If LESM is on then we need to hold the SW/FW semaphore. */
2551 if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2552 err = hw->mac.acquire_swfw_sync(hw,
2553 TXGBE_MNGSEM_SWPHY);
2555 return TXGBE_ERR_SWFW_SYNC;
2561 *locked = lock_state;
2563 *value = txgbe_autoc_read(hw);
2568 * txgbe_prot_autoc_write_raptor - Hides MAC differences needed for AUTOC write
2569 * @hw: pointer to hardware structure
2570 * @autoc: value to write to AUTOC
2571 * @locked: bool to indicate whether the SW/FW lock was already taken by
2572 * previous prot_autoc_read_raptor.
2574 * This part may need to hold the SW/FW lock around all writes to
2575 * AUTOC. Likewise after a write we need to do a pipeline reset.
2577 s32 txgbe_prot_autoc_write_raptor(struct txgbe_hw *hw, bool locked, u64 autoc)
2581 /* Blocked by MNG FW so bail */
2582 if (txgbe_check_reset_blocked(hw))
2585 /* We only need to get the lock if:
2586 * - We didn't do it already (in the read part of a read-modify-write)
2587 * - LESM is enabled.
2589 if (!locked && txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2590 err = hw->mac.acquire_swfw_sync(hw,
2591 TXGBE_MNGSEM_SWPHY);
2593 return TXGBE_ERR_SWFW_SYNC;
2598 txgbe_autoc_write(hw, autoc);
2599 err = txgbe_reset_pipeline_raptor(hw);
2602 /* Free the SW/FW semaphore as we either grabbed it here or
2603 * already had it when this function was called.
2606 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2611 /* cmd_addr is used for some special command:
2612 * 1. to be sector address, when implemented erase sector command
2613 * 2. to be flash address when implemented read, write flash address
2615 * Return 0 on success, return 1 on failure.
2617 u32 txgbe_fmgr_cmd_op(struct txgbe_hw *hw, u32 cmd, u32 cmd_addr)
2621 cmd_val = TXGBE_SPICMD_CMD(cmd) | TXGBE_SPICMD_CLK(3) | cmd_addr;
2622 wr32(hw, TXGBE_SPICMD, cmd_val);
2624 for (i = 0; i < TXGBE_SPI_TIMEOUT; i++) {
2625 if (rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_OPDONE)
2631 if (i == TXGBE_SPI_TIMEOUT)
2637 u32 txgbe_flash_read_dword(struct txgbe_hw *hw, u32 addr)
2641 status = txgbe_fmgr_cmd_op(hw, 1, addr);
2642 if (status == 0x1) {
2643 DEBUGOUT("Read flash timeout.");
2647 return rd32(hw, TXGBE_SPIDAT);
2651 * txgbe_init_ops_pf - Inits func ptrs and MAC type
2652 * @hw: pointer to hardware structure
2654 * Initialize the function pointers and assign the MAC type.
2655 * Does not touch the hardware.
2657 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
2659 struct txgbe_bus_info *bus = &hw->bus;
2660 struct txgbe_mac_info *mac = &hw->mac;
2661 struct txgbe_phy_info *phy = &hw->phy;
2662 struct txgbe_rom_info *rom = &hw->rom;
2663 struct txgbe_mbx_info *mbx = &hw->mbx;
2666 bus->set_lan_id = txgbe_set_lan_id_multi_port;
2669 phy->get_media_type = txgbe_get_media_type_raptor;
2670 phy->identify = txgbe_identify_phy;
2671 phy->init = txgbe_init_phy_raptor;
2672 phy->read_reg = txgbe_read_phy_reg;
2673 phy->write_reg = txgbe_write_phy_reg;
2674 phy->read_reg_mdi = txgbe_read_phy_reg_mdi;
2675 phy->write_reg_mdi = txgbe_write_phy_reg_mdi;
2676 phy->setup_link = txgbe_setup_phy_link;
2677 phy->setup_link_speed = txgbe_setup_phy_link_speed;
2678 phy->get_fw_version = txgbe_get_phy_fw_version;
2679 phy->read_i2c_byte = txgbe_read_i2c_byte;
2680 phy->write_i2c_byte = txgbe_write_i2c_byte;
2681 phy->read_i2c_sff8472 = txgbe_read_i2c_sff8472;
2682 phy->read_i2c_eeprom = txgbe_read_i2c_eeprom;
2683 phy->write_i2c_eeprom = txgbe_write_i2c_eeprom;
2684 phy->identify_sfp = txgbe_identify_module;
2685 phy->read_i2c_byte_unlocked = txgbe_read_i2c_byte_unlocked;
2686 phy->write_i2c_byte_unlocked = txgbe_write_i2c_byte_unlocked;
2687 phy->reset = txgbe_reset_phy;
2690 mac->init_hw = txgbe_init_hw;
2691 mac->start_hw = txgbe_start_hw_raptor;
2692 mac->clear_hw_cntrs = txgbe_clear_hw_cntrs;
2693 mac->enable_rx_dma = txgbe_enable_rx_dma_raptor;
2694 mac->get_mac_addr = txgbe_get_mac_addr;
2695 mac->stop_hw = txgbe_stop_hw;
2696 mac->acquire_swfw_sync = txgbe_acquire_swfw_sync;
2697 mac->release_swfw_sync = txgbe_release_swfw_sync;
2698 mac->reset_hw = txgbe_reset_hw;
2699 mac->update_mc_addr_list = txgbe_update_mc_addr_list;
2701 mac->disable_sec_rx_path = txgbe_disable_sec_rx_path;
2702 mac->enable_sec_rx_path = txgbe_enable_sec_rx_path;
2703 mac->disable_sec_tx_path = txgbe_disable_sec_tx_path;
2704 mac->enable_sec_tx_path = txgbe_enable_sec_tx_path;
2705 mac->get_san_mac_addr = txgbe_get_san_mac_addr;
2706 mac->set_san_mac_addr = txgbe_set_san_mac_addr;
2707 mac->get_device_caps = txgbe_get_device_caps;
2708 mac->get_wwn_prefix = txgbe_get_wwn_prefix;
2709 mac->autoc_read = txgbe_autoc_read;
2710 mac->autoc_write = txgbe_autoc_write;
2711 mac->prot_autoc_read = txgbe_prot_autoc_read_raptor;
2712 mac->prot_autoc_write = txgbe_prot_autoc_write_raptor;
2714 /* RAR, Multicast, VLAN */
2715 mac->set_rar = txgbe_set_rar;
2716 mac->clear_rar = txgbe_clear_rar;
2717 mac->init_rx_addrs = txgbe_init_rx_addrs;
2718 mac->enable_rx = txgbe_enable_rx;
2719 mac->disable_rx = txgbe_disable_rx;
2720 mac->set_vmdq = txgbe_set_vmdq;
2721 mac->clear_vmdq = txgbe_clear_vmdq;
2722 mac->set_vfta = txgbe_set_vfta;
2723 mac->set_vlvf = txgbe_set_vlvf;
2724 mac->clear_vfta = txgbe_clear_vfta;
2725 mac->init_uta_tables = txgbe_init_uta_tables;
2726 mac->setup_sfp = txgbe_setup_sfp_modules;
2727 mac->set_mac_anti_spoofing = txgbe_set_mac_anti_spoofing;
2728 mac->set_ethertype_anti_spoofing = txgbe_set_ethertype_anti_spoofing;
2731 mac->fc_enable = txgbe_fc_enable;
2732 mac->setup_fc = txgbe_setup_fc;
2733 mac->fc_autoneg = txgbe_fc_autoneg;
2736 mac->get_link_capabilities = txgbe_get_link_capabilities_raptor;
2737 mac->check_link = txgbe_check_mac_link;
2738 mac->setup_pba = txgbe_set_pba;
2740 /* Manageability interface */
2741 mac->set_fw_drv_ver = txgbe_hic_set_drv_ver;
2742 mac->get_thermal_sensor_data = txgbe_get_thermal_sensor_data;
2743 mac->init_thermal_sensor_thresh = txgbe_init_thermal_sensor_thresh;
2745 mbx->init_params = txgbe_init_mbx_params_pf;
2746 mbx->read = txgbe_read_mbx_pf;
2747 mbx->write = txgbe_write_mbx_pf;
2748 mbx->check_for_msg = txgbe_check_for_msg_pf;
2749 mbx->check_for_ack = txgbe_check_for_ack_pf;
2750 mbx->check_for_rst = txgbe_check_for_rst_pf;
2753 rom->init_params = txgbe_init_eeprom_params;
2754 rom->read16 = txgbe_ee_read16;
2755 rom->readw_buffer = txgbe_ee_readw_buffer;
2756 rom->readw_sw = txgbe_ee_readw_sw;
2757 rom->read32 = txgbe_ee_read32;
2758 rom->write16 = txgbe_ee_write16;
2759 rom->writew_buffer = txgbe_ee_writew_buffer;
2760 rom->writew_sw = txgbe_ee_writew_sw;
2761 rom->write32 = txgbe_ee_write32;
2762 rom->validate_checksum = txgbe_validate_eeprom_checksum;
2763 rom->update_checksum = txgbe_update_eeprom_checksum;
2764 rom->calc_checksum = txgbe_calc_eeprom_checksum;
2766 mac->mcft_size = TXGBE_RAPTOR_MC_TBL_SIZE;
2767 mac->vft_size = TXGBE_RAPTOR_VFT_TBL_SIZE;
2768 mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;
2769 mac->rx_pb_size = TXGBE_RAPTOR_RX_PB_SIZE;
2770 mac->max_rx_queues = TXGBE_RAPTOR_MAX_RX_QUEUES;
2771 mac->max_tx_queues = TXGBE_RAPTOR_MAX_TX_QUEUES;
2777 * txgbe_get_link_capabilities_raptor - Determines link capabilities
2778 * @hw: pointer to hardware structure
2779 * @speed: pointer to link speed
2780 * @autoneg: true when autoneg or autotry is enabled
2782 * Determines the link capabilities by reading the AUTOC register.
2784 s32 txgbe_get_link_capabilities_raptor(struct txgbe_hw *hw,
2791 /* Check if 1G SFP module. */
2792 if (hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
2793 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
2794 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
2795 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
2796 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
2797 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1) {
2798 *speed = TXGBE_LINK_SPEED_1GB_FULL;
2804 * Determine link capabilities based on the stored value of AUTOC,
2805 * which represents EEPROM defaults. If AUTOC value has not
2806 * been stored, use the current register values.
2808 if (hw->mac.orig_link_settings_stored)
2809 autoc = hw->mac.orig_autoc;
2811 autoc = hw->mac.autoc_read(hw);
2813 switch (autoc & TXGBE_AUTOC_LMS_MASK) {
2814 case TXGBE_AUTOC_LMS_1G_LINK_NO_AN:
2815 *speed = TXGBE_LINK_SPEED_1GB_FULL;
2819 case TXGBE_AUTOC_LMS_10G_LINK_NO_AN:
2820 *speed = TXGBE_LINK_SPEED_10GB_FULL;
2824 case TXGBE_AUTOC_LMS_1G_AN:
2825 *speed = TXGBE_LINK_SPEED_1GB_FULL;
2829 case TXGBE_AUTOC_LMS_10G:
2830 *speed = TXGBE_LINK_SPEED_10GB_FULL;
2834 case TXGBE_AUTOC_LMS_KX4_KX_KR:
2835 case TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
2836 *speed = TXGBE_LINK_SPEED_UNKNOWN;
2837 if (autoc & TXGBE_AUTOC_KR_SUPP)
2838 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2839 if (autoc & TXGBE_AUTOC_KX4_SUPP)
2840 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2841 if (autoc & TXGBE_AUTOC_KX_SUPP)
2842 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
2846 case TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
2847 *speed = TXGBE_LINK_SPEED_100M_FULL;
2848 if (autoc & TXGBE_AUTOC_KR_SUPP)
2849 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2850 if (autoc & TXGBE_AUTOC_KX4_SUPP)
2851 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2852 if (autoc & TXGBE_AUTOC_KX_SUPP)
2853 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
2857 case TXGBE_AUTOC_LMS_SGMII_1G_100M:
2858 *speed = TXGBE_LINK_SPEED_1GB_FULL |
2859 TXGBE_LINK_SPEED_100M_FULL |
2860 TXGBE_LINK_SPEED_10M_FULL;
2865 return TXGBE_ERR_LINK_SETUP;
2868 if (hw->phy.multispeed_fiber) {
2869 *speed |= TXGBE_LINK_SPEED_10GB_FULL |
2870 TXGBE_LINK_SPEED_1GB_FULL;
2872 /* QSFP must not enable full auto-negotiation
2873 * Limited autoneg is enabled at 1G
2875 if (hw->phy.media_type == txgbe_media_type_fiber_qsfp)
2885 * txgbe_get_media_type_raptor - Get media type
2886 * @hw: pointer to hardware structure
2888 * Returns the media type (fiber, copper, backplane)
2890 u32 txgbe_get_media_type_raptor(struct txgbe_hw *hw)
2894 if (hw->phy.ffe_set)
2895 txgbe_bp_mode_set(hw);
2897 /* Detect if there is a copper PHY attached. */
2898 switch (hw->phy.type) {
2899 case txgbe_phy_cu_unknown:
2901 media_type = txgbe_media_type_copper;
2907 switch (hw->subsystem_device_id & 0xFF) {
2908 case TXGBE_DEV_ID_KR_KX_KX4:
2909 case TXGBE_DEV_ID_MAC_SGMII:
2910 case TXGBE_DEV_ID_MAC_XAUI:
2911 /* Default device ID is mezzanine card KX/KX4 */
2912 media_type = txgbe_media_type_backplane;
2914 case TXGBE_DEV_ID_SFP:
2915 media_type = txgbe_media_type_fiber;
2917 case TXGBE_DEV_ID_QSFP:
2918 media_type = txgbe_media_type_fiber_qsfp;
2920 case TXGBE_DEV_ID_XAUI:
2921 case TXGBE_DEV_ID_SGMII:
2922 media_type = txgbe_media_type_copper;
2924 case TXGBE_DEV_ID_SFI_XAUI:
2925 if (hw->bus.lan_id == 0)
2926 media_type = txgbe_media_type_fiber;
2928 media_type = txgbe_media_type_copper;
2931 media_type = txgbe_media_type_unknown;
2939 * txgbe_start_mac_link_raptor - Setup MAC link settings
2940 * @hw: pointer to hardware structure
2941 * @autoneg_wait_to_complete: true when waiting for completion is needed
2943 * Configures link settings based on values in the txgbe_hw struct.
2944 * Restarts the link. Performs autonegotiation if needed.
2946 s32 txgbe_start_mac_link_raptor(struct txgbe_hw *hw,
2947 bool autoneg_wait_to_complete)
2950 bool got_lock = false;
2952 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
2954 /* reset_pipeline requires us to hold this lock as it writes to
2957 if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2958 status = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2966 txgbe_reset_pipeline_raptor(hw);
2969 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2971 /* Add delay to filter out noises during initial link setup */
2979 * txgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
2980 * @hw: pointer to hardware structure
2982 * The base drivers may require better control over SFP+ module
2983 * PHY states. This includes selectively shutting down the Tx
2984 * laser on the PHY, effectively halting physical link.
2986 void txgbe_disable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
2988 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
2990 /* Blocked by MNG FW so bail */
2991 if (txgbe_check_reset_blocked(hw))
2994 if (txgbe_close_notify(hw))
2995 txgbe_led_off(hw, TXGBE_LEDCTL_UP | TXGBE_LEDCTL_10G |
2996 TXGBE_LEDCTL_1G | TXGBE_LEDCTL_ACTIVE);
2998 /* Disable Tx laser; allow 100us to go dark per spec */
2999 esdp_reg |= (TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
3000 wr32(hw, TXGBE_GPIODATA, esdp_reg);
3006 * txgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
3007 * @hw: pointer to hardware structure
3009 * The base drivers may require better control over SFP+ module
3010 * PHY states. This includes selectively turning on the Tx
3011 * laser on the PHY, effectively starting physical link.
3013 void txgbe_enable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
3015 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
3017 if (txgbe_open_notify(hw))
3018 wr32(hw, TXGBE_LEDCTL, 0);
3020 /* Enable Tx laser; allow 100ms to light up */
3021 esdp_reg &= ~(TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
3022 wr32(hw, TXGBE_GPIODATA, esdp_reg);
3028 * txgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
3029 * @hw: pointer to hardware structure
3031 * When the driver changes the link speeds that it can support,
3032 * it sets autotry_restart to true to indicate that we need to
3033 * initiate a new autotry session with the link partner. To do
3034 * so, we set the speed then disable and re-enable the Tx laser, to
3035 * alert the link partner that it also needs to restart autotry on its
3036 * end. This is consistent with true clause 37 autoneg, which also
3037 * involves a loss of signal.
3039 void txgbe_flap_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
3041 /* Blocked by MNG FW so bail */
3042 if (txgbe_check_reset_blocked(hw))
3045 if (hw->mac.autotry_restart) {
3046 txgbe_disable_tx_laser_multispeed_fiber(hw);
3047 txgbe_enable_tx_laser_multispeed_fiber(hw);
3048 hw->mac.autotry_restart = false;
3053 * txgbe_set_hard_rate_select_speed - Set module link speed
3054 * @hw: pointer to hardware structure
3055 * @speed: link speed to set
3057 * Set module link speed via RS0/RS1 rate select pins.
3059 void txgbe_set_hard_rate_select_speed(struct txgbe_hw *hw,
3062 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
3065 case TXGBE_LINK_SPEED_10GB_FULL:
3066 esdp_reg |= (TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
3068 case TXGBE_LINK_SPEED_1GB_FULL:
3069 esdp_reg &= ~(TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
3072 DEBUGOUT("Invalid fixed module speed");
3076 wr32(hw, TXGBE_GPIODATA, esdp_reg);
3081 * txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
3082 * @hw: pointer to hardware structure
3083 * @speed: new link speed
3084 * @autoneg_wait_to_complete: true when waiting for completion is needed
3086 * Implements the Intel SmartSpeed algorithm.
3088 s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
3090 bool autoneg_wait_to_complete)
3093 u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
3095 bool link_up = false;
3096 u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
3098 /* Set autoneg_advertised value based on input link speed */
3099 hw->phy.autoneg_advertised = 0;
3101 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
3102 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
3104 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
3105 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
3107 if (speed & TXGBE_LINK_SPEED_100M_FULL)
3108 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
3111 * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
3112 * autoneg advertisement if link is unable to be established at the
3113 * highest negotiated rate. This can sometimes happen due to integrity
3114 * issues with the physical media connection.
3117 /* First, try to get link with full advertisement */
3118 hw->phy.smart_speed_active = false;
3119 for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
3120 status = txgbe_setup_mac_link(hw, speed,
3121 autoneg_wait_to_complete);
3126 * Wait for the controller to acquire link. Per IEEE 802.3ap,
3127 * Section 73.10.2, we may have to wait up to 500ms if KR is
3128 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
3129 * Table 9 in the AN MAS.
3131 for (i = 0; i < 5; i++) {
3134 /* If we have link, just jump out */
3135 status = hw->mac.check_link(hw, &link_speed, &link_up,
3146 * We didn't get link. If we advertised KR plus one of KX4/KX
3147 * (or BX4/BX), then disable KR and try again.
3149 if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
3150 ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
3151 (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
3154 /* Turn SmartSpeed on to disable KR support */
3155 hw->phy.smart_speed_active = true;
3156 status = txgbe_setup_mac_link(hw, speed,
3157 autoneg_wait_to_complete);
3162 * Wait for the controller to acquire link. 600ms will allow for
3163 * the AN link_fail_inhibit_timer as well for multiple cycles of
3164 * parallel detect, both 10g and 1g. This allows for the maximum
3165 * connect attempts as defined in the AN MAS table 73-7.
3167 for (i = 0; i < 6; i++) {
3170 /* If we have link, just jump out */
3171 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
3179 /* We didn't get link. Turn SmartSpeed back off. */
3180 hw->phy.smart_speed_active = false;
3181 status = txgbe_setup_mac_link(hw, speed,
3182 autoneg_wait_to_complete);
3185 if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
3186 DEBUGOUT("Smartspeed has downgraded the link speed from the maximum advertised");
3191 * txgbe_setup_mac_link - Set MAC link speed
3192 * @hw: pointer to hardware structure
3193 * @speed: new link speed
3194 * @autoneg_wait_to_complete: true when waiting for completion is needed
3196 * Set the link speed in the AUTOC register and restarts link.
3198 s32 txgbe_setup_mac_link(struct txgbe_hw *hw,
3200 bool autoneg_wait_to_complete)
3202 bool autoneg = false;
3205 u64 autoc = hw->mac.autoc_read(hw);
3206 u64 pma_pmd_10gs = autoc & TXGBE_AUTOC_10GS_PMA_PMD_MASK;
3207 u64 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
3208 u64 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
3210 u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
3212 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
3214 /* Check to see if speed passed in is supported. */
3215 status = hw->mac.get_link_capabilities(hw,
3216 &link_capabilities, &autoneg);
3220 speed &= link_capabilities;
3221 if (speed == TXGBE_LINK_SPEED_UNKNOWN)
3222 return TXGBE_ERR_LINK_SETUP;
3224 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
3225 if (hw->mac.orig_link_settings_stored)
3226 orig_autoc = hw->mac.orig_autoc;
3230 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
3231 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
3233 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
3234 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
3235 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
3236 /* Set KX4/KX/KR support according to speed requested */
3237 autoc &= ~(TXGBE_AUTOC_KX_SUPP |
3238 TXGBE_AUTOC_KX4_SUPP |
3239 TXGBE_AUTOC_KR_SUPP);
3240 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
3241 if (orig_autoc & TXGBE_AUTOC_KX4_SUPP)
3242 autoc |= TXGBE_AUTOC_KX4_SUPP;
3243 if (orig_autoc & TXGBE_AUTOC_KR_SUPP)
3244 autoc |= TXGBE_AUTOC_KR_SUPP;
3246 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
3247 autoc |= TXGBE_AUTOC_KX_SUPP;
3248 } else if ((pma_pmd_1g == TXGBE_AUTOC_1G_SFI) &&
3249 (link_mode == TXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
3250 link_mode == TXGBE_AUTOC_LMS_1G_AN)) {
3251 /* Switch from 1G SFI to 10G SFI if requested */
3252 if (speed == TXGBE_LINK_SPEED_10GB_FULL &&
3253 pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) {
3254 autoc &= ~TXGBE_AUTOC_LMS_MASK;
3255 autoc |= TXGBE_AUTOC_LMS_10G;
3257 } else if ((pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) &&
3258 (link_mode == TXGBE_AUTOC_LMS_10G)) {
3259 /* Switch from 10G SFI to 1G SFI if requested */
3260 if (speed == TXGBE_LINK_SPEED_1GB_FULL &&
3261 pma_pmd_1g == TXGBE_AUTOC_1G_SFI) {
3262 autoc &= ~TXGBE_AUTOC_LMS_MASK;
3263 if (autoneg || hw->phy.type == txgbe_phy_qsfp_intel)
3264 autoc |= TXGBE_AUTOC_LMS_1G_AN;
3266 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
3270 autoc &= ~TXGBE_AUTOC_SPEED_MASK;
3271 autoc |= TXGBE_AUTOC_SPEED(speed);
3272 autoc &= ~TXGBE_AUTOC_AUTONEG;
3273 autoc |= (autoneg ? TXGBE_AUTOC_AUTONEG : 0);
3276 hw->mac.autoc_write(hw, autoc);
3278 /* Add delay to filter out noises during initial link setup */
3285 * txgbe_setup_copper_link_raptor - Set the PHY autoneg advertised field
3286 * @hw: pointer to hardware structure
3287 * @speed: new link speed
3288 * @autoneg_wait_to_complete: true if waiting is needed to complete
3290 * Restarts link on PHY and MAC based on settings passed in.
3292 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
3294 bool autoneg_wait_to_complete)
3298 /* Setup the PHY according to input speed */
3299 status = hw->phy.setup_link_speed(hw, speed,
3300 autoneg_wait_to_complete);
3302 txgbe_start_mac_link_raptor(hw, autoneg_wait_to_complete);
3308 txgbe_check_flash_load(struct txgbe_hw *hw, u32 check_bit)
3313 /* if there's flash existing */
3314 if (!(rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_BPFLASH)) {
3315 /* wait hw load flash done */
3316 for (i = 0; i < 10; i++) {
3317 reg = rd32(hw, TXGBE_ILDRSTAT);
3318 if (!(reg & check_bit)) {
3325 err = TXGBE_ERR_FLASH_LOADING_FAILED;
3331 txgbe_reset_misc(struct txgbe_hw *hw)
3336 wr32(hw, TXGBE_ISBADDRL, hw->isb_dma & 0x00000000FFFFFFFF);
3337 wr32(hw, TXGBE_ISBADDRH, hw->isb_dma >> 32);
3339 value = rd32_epcs(hw, SR_XS_PCS_CTRL2);
3340 if ((value & 0x3) != SR_PCS_CTRL2_TYPE_SEL_X)
3341 hw->link_status = TXGBE_LINK_STATUS_NONE;
3343 /* receive packets that size > 2048 */
3344 wr32m(hw, TXGBE_MACRXCFG,
3345 TXGBE_MACRXCFG_JUMBO, TXGBE_MACRXCFG_JUMBO);
3347 wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
3348 TXGBE_FRMSZ_MAX(TXGBE_FRAME_SIZE_DFT));
3350 /* clear counters on read */
3351 wr32m(hw, TXGBE_MACCNTCTL,
3352 TXGBE_MACCNTCTL_RC, TXGBE_MACCNTCTL_RC);
3354 wr32m(hw, TXGBE_RXFCCFG,
3355 TXGBE_RXFCCFG_FC, TXGBE_RXFCCFG_FC);
3356 wr32m(hw, TXGBE_TXFCCFG,
3357 TXGBE_TXFCCFG_FC, TXGBE_TXFCCFG_FC);
3359 wr32m(hw, TXGBE_MACRXFLT,
3360 TXGBE_MACRXFLT_PROMISC, TXGBE_MACRXFLT_PROMISC);
3362 wr32m(hw, TXGBE_RSTSTAT,
3363 TXGBE_RSTSTAT_TMRINIT_MASK, TXGBE_RSTSTAT_TMRINIT(30));
3365 /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
3366 wr32(hw, TXGBE_MNGFLEXSEL, 0);
3367 for (i = 0; i < 16; i++) {
3368 wr32(hw, TXGBE_MNGFLEXDWL(i), 0);
3369 wr32(hw, TXGBE_MNGFLEXDWH(i), 0);
3370 wr32(hw, TXGBE_MNGFLEXMSK(i), 0);
3372 wr32(hw, TXGBE_LANFLEXSEL, 0);
3373 for (i = 0; i < 16; i++) {
3374 wr32(hw, TXGBE_LANFLEXDWL(i), 0);
3375 wr32(hw, TXGBE_LANFLEXDWH(i), 0);
3376 wr32(hw, TXGBE_LANFLEXMSK(i), 0);
3379 /* set pause frame dst mac addr */
3380 wr32(hw, TXGBE_RXPBPFCDMACL, 0xC2000001);
3381 wr32(hw, TXGBE_RXPBPFCDMACH, 0x0180);
3383 hw->mac.init_thermal_sensor_thresh(hw);
3385 /* enable mac transmitter */
3386 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE, TXGBE_MACTXCFG_TXE);
3388 hw->mac.autoc = hw->mac.orig_autoc;
3389 for (i = 0; i < 4; i++)
3390 wr32m(hw, TXGBE_IVAR(i), 0x80808080, 0);
3394 * txgbe_reset_hw - Perform hardware reset
3395 * @hw: pointer to hardware structure
3397 * Resets the hardware by resetting the transmit and receive units, masks
3398 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
3401 s32 txgbe_reset_hw(struct txgbe_hw *hw)
3406 /* Call adapter stop to disable tx/rx and clear interrupts */
3407 status = hw->mac.stop_hw(hw);
3411 /* flush pending Tx transactions */
3412 txgbe_clear_tx_pending(hw);
3414 /* Identify PHY and related function pointers */
3415 status = hw->phy.init(hw);
3416 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
3419 /* Setup SFP module if there is one present. */
3420 if (hw->phy.sfp_setup_needed) {
3421 status = hw->mac.setup_sfp(hw);
3422 hw->phy.sfp_setup_needed = false;
3424 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
3428 if (!hw->phy.reset_disable)
3431 /* remember AUTOC from before we reset */
3432 autoc = hw->mac.autoc_read(hw);
3436 * Issue global reset to the MAC. Needs to be SW reset if link is up.
3437 * If link reset is used when link is up, it might reset the PHY when
3438 * mng is using it. If link is down or the flag to force full link
3439 * reset is set, then perform link reset.
3441 if (txgbe_mng_present(hw)) {
3442 txgbe_hic_reset(hw);
3444 wr32(hw, TXGBE_RST, TXGBE_RST_LAN(hw->bus.lan_id));
3449 txgbe_reset_misc(hw);
3451 if (hw->bus.lan_id == 0) {
3452 status = txgbe_check_flash_load(hw,
3453 TXGBE_ILDRSTAT_SWRST_LAN0);
3455 status = txgbe_check_flash_load(hw,
3456 TXGBE_ILDRSTAT_SWRST_LAN1);
3464 * Double resets are required for recovery from certain error
3465 * conditions. Between resets, it is necessary to stall to
3466 * allow time for any pending HW events to complete.
3468 if (hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
3469 hw->mac.flags &= ~TXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
3474 * Store the original AUTOC/AUTOC2 values if they have not been
3475 * stored off yet. Otherwise restore the stored original
3476 * values since the reset operation sets back to defaults.
3478 if (!hw->mac.orig_link_settings_stored) {
3479 hw->mac.orig_autoc = hw->mac.autoc_read(hw);
3480 hw->mac.orig_link_settings_stored = true;
3482 hw->mac.orig_autoc = autoc;
3485 if (hw->phy.ffe_set) {
3486 /* Make sure phy power is up */
3489 /* A temporary solution to set phy */
3490 txgbe_set_phy_temp(hw);
3493 /* Store the permanent mac address */
3494 hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
3497 * Store MAC address from RAR0, clear receive address registers, and
3498 * clear the multicast table. Also reset num_rar_entries to 128,
3499 * since we modify this value when programming the SAN MAC address.
3501 hw->mac.num_rar_entries = 128;
3502 hw->mac.init_rx_addrs(hw);
3504 /* Store the permanent SAN mac address */
3505 hw->mac.get_san_mac_addr(hw, hw->mac.san_addr);
3507 /* Add the SAN MAC address to the RAR only if it's a valid address */
3508 if (txgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
3509 /* Save the SAN MAC RAR index */
3510 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
3512 hw->mac.set_rar(hw, hw->mac.san_mac_rar_index,
3513 hw->mac.san_addr, 0, true);
3515 /* clear VMDq pool/queue selection for this RAR */
3516 hw->mac.clear_vmdq(hw, hw->mac.san_mac_rar_index,
3519 /* Reserve the last RAR for the SAN MAC address */
3520 hw->mac.num_rar_entries--;
3523 /* Store the alternative WWNN/WWPN prefix */
3524 hw->mac.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
3525 &hw->mac.wwpn_prefix);
3531 * txgbe_fdir_check_cmd_complete - poll to check whether FDIRPICMD is complete
3532 * @hw: pointer to hardware structure
3533 * @fdircmd: current value of FDIRCMD register
3535 static s32 txgbe_fdir_check_cmd_complete(struct txgbe_hw *hw, u32 *fdircmd)
3539 for (i = 0; i < TXGBE_FDIRCMD_CMD_POLL; i++) {
3540 *fdircmd = rd32(hw, TXGBE_FDIRPICMD);
3541 if (!(*fdircmd & TXGBE_FDIRPICMD_OP_MASK))
3546 return TXGBE_ERR_FDIR_CMD_INCOMPLETE;
3550 * txgbe_reinit_fdir_tables - Reinitialize Flow Director tables.
3551 * @hw: pointer to hardware structure
3553 s32 txgbe_reinit_fdir_tables(struct txgbe_hw *hw)
3557 u32 fdirctrl = rd32(hw, TXGBE_FDIRCTL);
3559 fdirctrl &= ~TXGBE_FDIRCTL_INITDONE;
3562 * Before starting reinitialization process,
3563 * FDIRPICMD.OP must be zero.
3565 err = txgbe_fdir_check_cmd_complete(hw, &fdircmd);
3567 DEBUGOUT("Flow Director previous command did not complete, aborting table re-initialization.");
3571 wr32(hw, TXGBE_FDIRFREE, 0);
3574 * adapters flow director init flow cannot be restarted,
3575 * Workaround silicon errata by performing the following steps
3576 * before re-writing the FDIRCTL control register with the same value.
3577 * - write 1 to bit 8 of FDIRPICMD register &
3578 * - write 0 to bit 8 of FDIRPICMD register
3580 wr32m(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_CLR, TXGBE_FDIRPICMD_CLR);
3582 wr32m(hw, TXGBE_FDIRPICMD, TXGBE_FDIRPICMD_CLR, 0);
3585 * Clear FDIR Hash register to clear any leftover hashes
3586 * waiting to be programmed.
3588 wr32(hw, TXGBE_FDIRPIHASH, 0x00);
3591 wr32(hw, TXGBE_FDIRCTL, fdirctrl);
3594 /* Poll init-done after we write FDIRCTL register */
3595 for (i = 0; i < TXGBE_FDIR_INIT_DONE_POLL; i++) {
3596 if (rd32m(hw, TXGBE_FDIRCTL, TXGBE_FDIRCTL_INITDONE))
3600 if (i >= TXGBE_FDIR_INIT_DONE_POLL) {
3601 DEBUGOUT("Flow Director Signature poll time exceeded!");
3602 return TXGBE_ERR_FDIR_REINIT_FAILED;
3605 /* Clear FDIR statistics registers (read to clear) */
3606 rd32(hw, TXGBE_FDIRUSED);
3607 rd32(hw, TXGBE_FDIRFAIL);
3608 rd32(hw, TXGBE_FDIRMATCH);
3609 rd32(hw, TXGBE_FDIRMISS);
3610 rd32(hw, TXGBE_FDIRLEN);
3616 * txgbe_start_hw_raptor - Prepare hardware for Tx/Rx
3617 * @hw: pointer to hardware structure
3619 * Starts the hardware using the generic start_hw function
3620 * and the generation start_hw function.
3621 * Then performs revision-specific operations, if any.
3623 s32 txgbe_start_hw_raptor(struct txgbe_hw *hw)
3627 err = txgbe_start_hw(hw);
3631 err = txgbe_start_hw_gen2(hw);
3635 /* We need to run link autotry after the driver loads */
3636 hw->mac.autotry_restart = true;
3643 * txgbe_enable_rx_dma_raptor - Enable the Rx DMA unit
3644 * @hw: pointer to hardware structure
3645 * @regval: register value to write to RXCTRL
3647 * Enables the Rx DMA unit
3649 s32 txgbe_enable_rx_dma_raptor(struct txgbe_hw *hw, u32 regval)
3652 * Workaround silicon errata when enabling the Rx datapath.
3653 * If traffic is incoming before we enable the Rx unit, it could hang
3654 * the Rx DMA unit. Therefore, make sure the security engine is
3655 * completely disabled prior to enabling the Rx unit.
3658 hw->mac.disable_sec_rx_path(hw);
3660 if (regval & TXGBE_PBRXCTL_ENA)
3661 txgbe_enable_rx(hw);
3663 txgbe_disable_rx(hw);
3665 hw->mac.enable_sec_rx_path(hw);
3671 * txgbe_verify_lesm_fw_enabled_raptor - Checks LESM FW module state.
3672 * @hw: pointer to hardware structure
3674 * Returns true if the LESM FW module is present and enabled. Otherwise
3675 * returns false. Smart Speed must be disabled if LESM FW module is enabled.
3677 bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw)
3679 bool lesm_enabled = false;
3680 u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
3683 /* get the offset to the Firmware Module block */
3684 status = hw->rom.read16(hw, TXGBE_FW_PTR, &fw_offset);
3686 if (status != 0 || fw_offset == 0 || fw_offset == 0xFFFF)
3689 /* get the offset to the LESM Parameters block */
3690 status = hw->rom.read16(hw, (fw_offset +
3691 TXGBE_FW_LESM_PARAMETERS_PTR),
3692 &fw_lesm_param_offset);
3695 fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
3698 /* get the LESM state word */
3699 status = hw->rom.read16(hw, (fw_lesm_param_offset +
3700 TXGBE_FW_LESM_STATE_1),
3703 if (status == 0 && (fw_lesm_state & TXGBE_FW_LESM_STATE_ENABLED))
3704 lesm_enabled = true;
3707 lesm_enabled = false;
3708 return lesm_enabled;
3712 * txgbe_reset_pipeline_raptor - perform pipeline reset
3714 * @hw: pointer to hardware structure
3716 * Reset pipeline by asserting Restart_AN together with LMS change to ensure
3717 * full pipeline reset. This function assumes the SW/FW lock is held.
3719 s32 txgbe_reset_pipeline_raptor(struct txgbe_hw *hw)
3724 autoc = hw->mac.autoc_read(hw);
3726 /* Enable link if disabled in NVM */
3727 if (autoc & TXGBE_AUTOC_LINK_DIA_MASK)
3728 autoc &= ~TXGBE_AUTOC_LINK_DIA_MASK;
3730 autoc |= TXGBE_AUTOC_AN_RESTART;
3731 /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
3732 hw->mac.autoc_write(hw, autoc ^ TXGBE_AUTOC_LMS_AN);
3734 /* Write AUTOC register with original LMS field and Restart_AN */
3735 hw->mac.autoc_write(hw, autoc);