1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
5 #include "txgbe_type.h"
9 #include "txgbe_eeprom.h"
10 #include "txgbe_mng.h"
13 #define TXGBE_RAPTOR_MAX_TX_QUEUES 128
14 #define TXGBE_RAPTOR_MAX_RX_QUEUES 128
15 #define TXGBE_RAPTOR_RAR_ENTRIES 128
16 #define TXGBE_RAPTOR_MC_TBL_SIZE 128
17 #define TXGBE_RAPTOR_VFT_TBL_SIZE 128
18 #define TXGBE_RAPTOR_RX_PB_SIZE 512 /*KB*/
20 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
22 bool autoneg_wait_to_complete);
24 static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr);
25 static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
29 * txgbe_device_supports_autoneg_fc - Check if device supports autonegotiation
31 * @hw: pointer to hardware structure
33 * This function returns true if the device supports flow control
34 * autonegotiation, and false if it does not.
37 bool txgbe_device_supports_autoneg_fc(struct txgbe_hw *hw)
39 bool supported = false;
43 DEBUGFUNC("txgbe_device_supports_autoneg_fc");
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->device_id) {
63 case TXGBE_DEV_ID_RAPTOR_XAUI:
64 case TXGBE_DEV_ID_RAPTOR_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)
95 DEBUGFUNC("txgbe_setup_fc");
97 /* Validate the requested mode */
98 if (hw->fc.strict_ieee && hw->fc.requested_mode == txgbe_fc_rx_pause) {
99 DEBUGOUT("txgbe_fc_rx_pause not valid in strict IEEE mode\n");
100 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
105 * 10gig parts do not have a word in the EEPROM to determine the
106 * default flow control setting, so we explicitly set it to full.
108 if (hw->fc.requested_mode == txgbe_fc_default)
109 hw->fc.requested_mode = txgbe_fc_full;
112 * Set up the 1G and 10G flow control advertisement registers so the
113 * HW will be able to do fc autoneg once the cable is plugged in. If
114 * we link at 10G, the 1G advertisement is harmless and vice versa.
116 switch (hw->phy.media_type) {
117 case txgbe_media_type_backplane:
118 /* some MAC's need RMW protection on AUTOC */
119 err = hw->mac.prot_autoc_read(hw, &locked, ®_bp);
123 /* fall through - only backplane uses autoc */
124 case txgbe_media_type_fiber_qsfp:
125 case txgbe_media_type_fiber:
126 case txgbe_media_type_copper:
127 hw->phy.read_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
128 TXGBE_MD_DEV_AUTO_NEG, ®_cu);
135 * The possible values of fc.requested_mode are:
136 * 0: Flow control is completely disabled
137 * 1: Rx flow control is enabled (we can receive pause frames,
138 * but not send pause frames).
139 * 2: Tx flow control is enabled (we can send pause frames but
140 * we do not support receiving pause frames).
141 * 3: Both Rx and Tx flow control (symmetric) are enabled.
144 switch (hw->fc.requested_mode) {
146 /* Flow control completely disabled by software override. */
147 reg &= ~(SR_MII_MMD_AN_ADV_PAUSE_SYM |
148 SR_MII_MMD_AN_ADV_PAUSE_ASM);
149 if (hw->phy.media_type == txgbe_media_type_backplane)
150 reg_bp &= ~(TXGBE_AUTOC_SYM_PAUSE |
151 TXGBE_AUTOC_ASM_PAUSE);
152 else if (hw->phy.media_type == txgbe_media_type_copper)
153 reg_cu &= ~(TXGBE_TAF_SYM_PAUSE | TXGBE_TAF_ASM_PAUSE);
155 case txgbe_fc_tx_pause:
157 * Tx Flow control is enabled, and Rx Flow control is
158 * disabled by software override.
160 reg |= SR_MII_MMD_AN_ADV_PAUSE_ASM;
161 reg &= ~SR_MII_MMD_AN_ADV_PAUSE_SYM;
162 if (hw->phy.media_type == txgbe_media_type_backplane) {
163 reg_bp |= TXGBE_AUTOC_ASM_PAUSE;
164 reg_bp &= ~TXGBE_AUTOC_SYM_PAUSE;
165 } else if (hw->phy.media_type == txgbe_media_type_copper) {
166 reg_cu |= TXGBE_TAF_ASM_PAUSE;
167 reg_cu &= ~TXGBE_TAF_SYM_PAUSE;
169 reg |= SR_MII_MMD_AN_ADV_PAUSE_ASM;
170 reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_ASM;
172 case txgbe_fc_rx_pause:
174 * Rx Flow control is enabled and Tx Flow control is
175 * disabled by software override. Since there really
176 * isn't a way to advertise that we are capable of RX
177 * Pause ONLY, we will advertise that we support both
178 * symmetric and asymmetric Rx PAUSE, as such we fall
179 * through to the fc_full statement. Later, we will
180 * disable the adapter's ability to send PAUSE frames.
183 /* Flow control (both Rx and Tx) is enabled by SW override. */
184 reg |= SR_MII_MMD_AN_ADV_PAUSE_SYM |
185 SR_MII_MMD_AN_ADV_PAUSE_ASM;
186 if (hw->phy.media_type == txgbe_media_type_backplane)
187 reg_bp |= TXGBE_AUTOC_SYM_PAUSE |
188 TXGBE_AUTOC_ASM_PAUSE;
189 else if (hw->phy.media_type == txgbe_media_type_copper)
190 reg_cu |= TXGBE_TAF_SYM_PAUSE | TXGBE_TAF_ASM_PAUSE;
191 reg |= SR_MII_MMD_AN_ADV_PAUSE_SYM |
192 SR_MII_MMD_AN_ADV_PAUSE_ASM;
193 reg_bp |= SR_AN_MMD_ADV_REG1_PAUSE_SYM |
194 SR_AN_MMD_ADV_REG1_PAUSE_ASM;
197 DEBUGOUT("Flow control param set incorrectly\n");
198 err = TXGBE_ERR_CONFIG;
203 * Enable auto-negotiation between the MAC & PHY;
204 * the MAC will advertise clause 37 flow control.
206 value = rd32_epcs(hw, SR_MII_MMD_AN_ADV);
207 value = (value & ~(SR_MII_MMD_AN_ADV_PAUSE_ASM |
208 SR_MII_MMD_AN_ADV_PAUSE_SYM)) | reg;
209 wr32_epcs(hw, SR_MII_MMD_AN_ADV, value);
212 * AUTOC restart handles negotiation of 1G and 10G on backplane
213 * and copper. There is no need to set the PCS1GCTL register.
216 if (hw->phy.media_type == txgbe_media_type_backplane) {
217 value = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
218 value = (value & ~(SR_AN_MMD_ADV_REG1_PAUSE_ASM |
219 SR_AN_MMD_ADV_REG1_PAUSE_SYM)) |
221 wr32_epcs(hw, SR_AN_MMD_ADV_REG1, value);
222 } else if ((hw->phy.media_type == txgbe_media_type_copper) &&
223 (txgbe_device_supports_autoneg_fc(hw))) {
224 hw->phy.write_reg(hw, TXGBE_MD_AUTO_NEG_ADVT,
225 TXGBE_MD_DEV_AUTO_NEG, reg_cu);
228 DEBUGOUT("Set up FC; reg = 0x%08X\n", reg);
234 * txgbe_start_hw - Prepare hardware for Tx/Rx
235 * @hw: pointer to hardware structure
237 * Starts the hardware by filling the bus info structure and media type, clears
238 * all on chip counters, initializes receive address registers, multicast
239 * table, VLAN filter table, calls routine to set up link and flow control
240 * settings, and leaves transmit and receive units disabled and uninitialized
242 s32 txgbe_start_hw(struct txgbe_hw *hw)
247 DEBUGFUNC("txgbe_start_hw");
249 /* Set the media type */
250 hw->phy.media_type = hw->phy.get_media_type(hw);
252 /* Clear the VLAN filter table */
253 hw->mac.clear_vfta(hw);
255 /* Clear statistics registers */
256 hw->mac.clear_hw_cntrs(hw);
258 /* Setup flow control */
259 err = txgbe_setup_fc(hw);
260 if (err != 0 && err != TXGBE_NOT_IMPLEMENTED) {
261 DEBUGOUT("Flow control setup failed, returning %d\n", err);
265 /* Cache bit indicating need for crosstalk fix */
266 switch (hw->mac.type) {
267 case txgbe_mac_raptor:
268 hw->mac.get_device_caps(hw, &device_caps);
269 if (device_caps & TXGBE_DEVICE_CAPS_NO_CROSSTALK_WR)
270 hw->need_crosstalk_fix = false;
272 hw->need_crosstalk_fix = true;
275 hw->need_crosstalk_fix = false;
279 /* Clear adapter stopped flag */
280 hw->adapter_stopped = false;
286 * txgbe_start_hw_gen2 - Init sequence for common device family
287 * @hw: pointer to hw structure
289 * Performs the init sequence common to the second generation
292 s32 txgbe_start_hw_gen2(struct txgbe_hw *hw)
296 /* Clear the rate limiters */
297 for (i = 0; i < hw->mac.max_tx_queues; i++) {
298 wr32(hw, TXGBE_ARBPOOLIDX, i);
299 wr32(hw, TXGBE_ARBTXRATE, 0);
303 /* We need to run link autotry after the driver loads */
304 hw->mac.autotry_restart = true;
310 * txgbe_init_hw - Generic hardware initialization
311 * @hw: pointer to hardware structure
313 * Initialize the hardware by resetting the hardware, filling the bus info
314 * structure and media type, clears all on chip counters, initializes receive
315 * address registers, multicast table, VLAN filter table, calls routine to set
316 * up link and flow control settings, and leaves transmit and receive units
317 * disabled and uninitialized
319 s32 txgbe_init_hw(struct txgbe_hw *hw)
323 DEBUGFUNC("txgbe_init_hw");
325 /* Reset the hardware */
326 status = hw->mac.reset_hw(hw);
327 if (status == 0 || status == TXGBE_ERR_SFP_NOT_PRESENT) {
329 status = hw->mac.start_hw(hw);
333 DEBUGOUT("Failed to initialize HW, STATUS = %d\n", status);
339 * txgbe_clear_hw_cntrs - Generic clear hardware counters
340 * @hw: pointer to hardware structure
342 * Clears all hardware statistics counters by reading them from the hardware
343 * Statistics counters are clear on read.
345 s32 txgbe_clear_hw_cntrs(struct txgbe_hw *hw)
349 DEBUGFUNC("txgbe_clear_hw_cntrs");
352 /* don't write clear queue stats */
353 for (i = 0; i < TXGBE_MAX_QP; i++) {
354 hw->qp_last[i].rx_qp_packets = 0;
355 hw->qp_last[i].tx_qp_packets = 0;
356 hw->qp_last[i].rx_qp_bytes = 0;
357 hw->qp_last[i].tx_qp_bytes = 0;
358 hw->qp_last[i].rx_qp_mc_packets = 0;
362 for (i = 0; i < TXGBE_MAX_UP; i++) {
363 rd32(hw, TXGBE_PBRXUPXON(i));
364 rd32(hw, TXGBE_PBRXUPXOFF(i));
365 rd32(hw, TXGBE_PBTXUPXON(i));
366 rd32(hw, TXGBE_PBTXUPXOFF(i));
367 rd32(hw, TXGBE_PBTXUPOFF(i));
369 rd32(hw, TXGBE_PBRXMISS(i));
371 rd32(hw, TXGBE_PBRXLNKXON);
372 rd32(hw, TXGBE_PBRXLNKXOFF);
373 rd32(hw, TXGBE_PBTXLNKXON);
374 rd32(hw, TXGBE_PBTXLNKXOFF);
377 rd32(hw, TXGBE_DMARXPKT);
378 rd32(hw, TXGBE_DMATXPKT);
380 rd64(hw, TXGBE_DMARXOCTL);
381 rd64(hw, TXGBE_DMATXOCTL);
384 rd64(hw, TXGBE_MACRXERRCRCL);
385 rd64(hw, TXGBE_MACRXMPKTL);
386 rd64(hw, TXGBE_MACTXMPKTL);
388 rd64(hw, TXGBE_MACRXPKTL);
389 rd64(hw, TXGBE_MACTXPKTL);
390 rd64(hw, TXGBE_MACRXGBOCTL);
392 rd64(hw, TXGBE_MACRXOCTL);
393 rd32(hw, TXGBE_MACTXOCTL);
395 rd64(hw, TXGBE_MACRX1TO64L);
396 rd64(hw, TXGBE_MACRX65TO127L);
397 rd64(hw, TXGBE_MACRX128TO255L);
398 rd64(hw, TXGBE_MACRX256TO511L);
399 rd64(hw, TXGBE_MACRX512TO1023L);
400 rd64(hw, TXGBE_MACRX1024TOMAXL);
401 rd64(hw, TXGBE_MACTX1TO64L);
402 rd64(hw, TXGBE_MACTX65TO127L);
403 rd64(hw, TXGBE_MACTX128TO255L);
404 rd64(hw, TXGBE_MACTX256TO511L);
405 rd64(hw, TXGBE_MACTX512TO1023L);
406 rd64(hw, TXGBE_MACTX1024TOMAXL);
408 rd64(hw, TXGBE_MACRXERRLENL);
409 rd32(hw, TXGBE_MACRXOVERSIZE);
410 rd32(hw, TXGBE_MACRXJABBER);
413 rd32(hw, TXGBE_FCOECRC);
414 rd32(hw, TXGBE_FCOELAST);
415 rd32(hw, TXGBE_FCOERPDC);
416 rd32(hw, TXGBE_FCOEPRC);
417 rd32(hw, TXGBE_FCOEPTC);
418 rd32(hw, TXGBE_FCOEDWRC);
419 rd32(hw, TXGBE_FCOEDWTC);
421 /* Flow Director Stats */
422 rd32(hw, TXGBE_FDIRMATCH);
423 rd32(hw, TXGBE_FDIRMISS);
424 rd32(hw, TXGBE_FDIRUSED);
425 rd32(hw, TXGBE_FDIRUSED);
426 rd32(hw, TXGBE_FDIRFAIL);
427 rd32(hw, TXGBE_FDIRFAIL);
430 rd32(hw, TXGBE_LSECTX_UTPKT);
431 rd32(hw, TXGBE_LSECTX_ENCPKT);
432 rd32(hw, TXGBE_LSECTX_PROTPKT);
433 rd32(hw, TXGBE_LSECTX_ENCOCT);
434 rd32(hw, TXGBE_LSECTX_PROTOCT);
435 rd32(hw, TXGBE_LSECRX_UTPKT);
436 rd32(hw, TXGBE_LSECRX_BTPKT);
437 rd32(hw, TXGBE_LSECRX_NOSCIPKT);
438 rd32(hw, TXGBE_LSECRX_UNSCIPKT);
439 rd32(hw, TXGBE_LSECRX_DECOCT);
440 rd32(hw, TXGBE_LSECRX_VLDOCT);
441 rd32(hw, TXGBE_LSECRX_UNCHKPKT);
442 rd32(hw, TXGBE_LSECRX_DLYPKT);
443 rd32(hw, TXGBE_LSECRX_LATEPKT);
444 for (i = 0; i < 2; i++) {
445 rd32(hw, TXGBE_LSECRX_OKPKT(i));
446 rd32(hw, TXGBE_LSECRX_INVPKT(i));
447 rd32(hw, TXGBE_LSECRX_BADPKT(i));
449 rd32(hw, TXGBE_LSECRX_INVSAPKT);
450 rd32(hw, TXGBE_LSECRX_BADSAPKT);
456 * txgbe_get_mac_addr - Generic get MAC address
457 * @hw: pointer to hardware structure
458 * @mac_addr: Adapter MAC address
460 * Reads the adapter's MAC address from first Receive Address Register (RAR0)
461 * A reset of the adapter must be performed prior to calling this function
462 * in order for the MAC address to have been loaded from the EEPROM into RAR0
464 s32 txgbe_get_mac_addr(struct txgbe_hw *hw, u8 *mac_addr)
470 DEBUGFUNC("txgbe_get_mac_addr");
472 wr32(hw, TXGBE_ETHADDRIDX, 0);
473 rar_high = rd32(hw, TXGBE_ETHADDRH);
474 rar_low = rd32(hw, TXGBE_ETHADDRL);
476 for (i = 0; i < 2; i++)
477 mac_addr[i] = (u8)(rar_high >> (1 - i) * 8);
479 for (i = 0; i < 4; i++)
480 mac_addr[i + 2] = (u8)(rar_low >> (3 - i) * 8);
486 * txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
487 * @hw: pointer to the HW structure
489 * Determines the LAN function id by reading memory-mapped registers and swaps
490 * the port value if requested, and set MAC instance for devices.
492 void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
494 struct txgbe_bus_info *bus = &hw->bus;
497 DEBUGFUNC("txgbe_set_lan_id_multi_port_pcie");
499 reg = rd32(hw, TXGBE_PORTSTAT);
500 bus->lan_id = TXGBE_PORTSTAT_ID(reg);
502 /* check for single port */
503 reg = rd32(hw, TXGBE_PWR);
504 if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
507 bus->func = bus->lan_id;
511 * txgbe_stop_hw - Generic stop Tx/Rx units
512 * @hw: pointer to hardware structure
514 * Sets the adapter_stopped flag within txgbe_hw struct. Clears interrupts,
515 * disables transmit and receive units. The adapter_stopped flag is used by
516 * the shared code and drivers to determine if the adapter is in a stopped
517 * state and should not touch the hardware.
519 s32 txgbe_stop_hw(struct txgbe_hw *hw)
524 DEBUGFUNC("txgbe_stop_hw");
527 * Set the adapter_stopped flag so other driver functions stop touching
530 hw->adapter_stopped = true;
532 /* Disable the receive unit */
533 txgbe_disable_rx(hw);
535 /* Clear interrupt mask to stop interrupts from being generated */
536 wr32(hw, TXGBE_IENMISC, 0);
537 wr32(hw, TXGBE_IMS(0), TXGBE_IMS_MASK);
538 wr32(hw, TXGBE_IMS(1), TXGBE_IMS_MASK);
540 /* Clear any pending interrupts, flush previous writes */
541 wr32(hw, TXGBE_ICRMISC, TXGBE_ICRMISC_MASK);
542 wr32(hw, TXGBE_ICR(0), TXGBE_ICR_MASK);
543 wr32(hw, TXGBE_ICR(1), TXGBE_ICR_MASK);
545 /* Disable the transmit unit. Each queue must be disabled. */
546 for (i = 0; i < hw->mac.max_tx_queues; i++)
547 wr32(hw, TXGBE_TXCFG(i), TXGBE_TXCFG_FLUSH);
549 /* Disable the receive unit by stopping each queue */
550 for (i = 0; i < hw->mac.max_rx_queues; i++) {
551 reg_val = rd32(hw, TXGBE_RXCFG(i));
552 reg_val &= ~TXGBE_RXCFG_ENA;
553 wr32(hw, TXGBE_RXCFG(i), reg_val);
556 /* flush all queues disables */
564 * txgbe_validate_mac_addr - Validate MAC address
565 * @mac_addr: pointer to MAC address.
567 * Tests a MAC address to ensure it is a valid Individual Address.
569 s32 txgbe_validate_mac_addr(u8 *mac_addr)
573 DEBUGFUNC("txgbe_validate_mac_addr");
575 /* Make sure it is not a multicast address */
576 if (TXGBE_IS_MULTICAST(mac_addr)) {
577 status = TXGBE_ERR_INVALID_MAC_ADDR;
578 /* Not a broadcast address */
579 } else if (TXGBE_IS_BROADCAST(mac_addr)) {
580 status = TXGBE_ERR_INVALID_MAC_ADDR;
581 /* Reject the zero address */
582 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
583 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
584 status = TXGBE_ERR_INVALID_MAC_ADDR;
590 * txgbe_set_rar - Set Rx address register
591 * @hw: pointer to hardware structure
592 * @index: Receive address register to write
593 * @addr: Address to put into receive address register
594 * @vmdq: VMDq "set" or "pool" index
595 * @enable_addr: set flag that address is active
597 * Puts an ethernet address into a receive address register.
599 s32 txgbe_set_rar(struct txgbe_hw *hw, u32 index, u8 *addr, u32 vmdq,
602 u32 rar_low, rar_high;
603 u32 rar_entries = hw->mac.num_rar_entries;
605 DEBUGFUNC("txgbe_set_rar");
607 /* Make sure we are using a valid rar index range */
608 if (index >= rar_entries) {
609 DEBUGOUT("RAR index %d is out of range.\n", index);
610 return TXGBE_ERR_INVALID_ARGUMENT;
613 /* setup VMDq pool selection before this RAR gets enabled */
614 hw->mac.set_vmdq(hw, index, vmdq);
617 * HW expects these in little endian so we reverse the byte
618 * order from network order (big endian) to little endian
620 rar_low = TXGBE_ETHADDRL_AD0(addr[5]) |
621 TXGBE_ETHADDRL_AD1(addr[4]) |
622 TXGBE_ETHADDRL_AD2(addr[3]) |
623 TXGBE_ETHADDRL_AD3(addr[2]);
625 * Some parts put the VMDq setting in the extra RAH bits,
626 * so save everything except the lower 16 bits that hold part
627 * of the address and the address valid bit.
629 rar_high = rd32(hw, TXGBE_ETHADDRH);
630 rar_high &= ~TXGBE_ETHADDRH_AD_MASK;
631 rar_high |= (TXGBE_ETHADDRH_AD4(addr[1]) |
632 TXGBE_ETHADDRH_AD5(addr[0]));
634 rar_high &= ~TXGBE_ETHADDRH_VLD;
635 if (enable_addr != 0)
636 rar_high |= TXGBE_ETHADDRH_VLD;
638 wr32(hw, TXGBE_ETHADDRIDX, index);
639 wr32(hw, TXGBE_ETHADDRL, rar_low);
640 wr32(hw, TXGBE_ETHADDRH, rar_high);
646 * txgbe_clear_rar - Remove Rx address register
647 * @hw: pointer to hardware structure
648 * @index: Receive address register to write
650 * Clears an ethernet address from a receive address register.
652 s32 txgbe_clear_rar(struct txgbe_hw *hw, u32 index)
655 u32 rar_entries = hw->mac.num_rar_entries;
657 DEBUGFUNC("txgbe_clear_rar");
659 /* Make sure we are using a valid rar index range */
660 if (index >= rar_entries) {
661 DEBUGOUT("RAR index %d is out of range.\n", index);
662 return TXGBE_ERR_INVALID_ARGUMENT;
666 * Some parts put the VMDq setting in the extra RAH bits,
667 * so save everything except the lower 16 bits that hold part
668 * of the address and the address valid bit.
670 wr32(hw, TXGBE_ETHADDRIDX, index);
671 rar_high = rd32(hw, TXGBE_ETHADDRH);
672 rar_high &= ~(TXGBE_ETHADDRH_AD_MASK | TXGBE_ETHADDRH_VLD);
674 wr32(hw, TXGBE_ETHADDRL, 0);
675 wr32(hw, TXGBE_ETHADDRH, rar_high);
677 /* clear VMDq pool/queue selection for this RAR */
678 hw->mac.clear_vmdq(hw, index, BIT_MASK32);
684 * txgbe_init_rx_addrs - Initializes receive address filters.
685 * @hw: pointer to hardware structure
687 * Places the MAC address in receive address register 0 and clears the rest
688 * of the receive address registers. Clears the multicast table. Assumes
689 * the receiver is in reset when the routine is called.
691 s32 txgbe_init_rx_addrs(struct txgbe_hw *hw)
695 u32 rar_entries = hw->mac.num_rar_entries;
697 DEBUGFUNC("txgbe_init_rx_addrs");
700 * If the current mac address is valid, assume it is a software override
701 * to the permanent address.
702 * Otherwise, use the permanent address from the eeprom.
704 if (txgbe_validate_mac_addr(hw->mac.addr) ==
705 TXGBE_ERR_INVALID_MAC_ADDR) {
706 /* Get the MAC address from the RAR0 for later reference */
707 hw->mac.get_mac_addr(hw, hw->mac.addr);
709 DEBUGOUT(" Keeping Current RAR0 Addr =%.2X %.2X %.2X ",
710 hw->mac.addr[0], hw->mac.addr[1],
712 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
713 hw->mac.addr[4], hw->mac.addr[5]);
715 /* Setup the receive address. */
716 DEBUGOUT("Overriding MAC Address in RAR[0]\n");
717 DEBUGOUT(" New MAC Addr =%.2X %.2X %.2X ",
718 hw->mac.addr[0], hw->mac.addr[1],
720 DEBUGOUT("%.2X %.2X %.2X\n", hw->mac.addr[3],
721 hw->mac.addr[4], hw->mac.addr[5]);
723 hw->mac.set_rar(hw, 0, hw->mac.addr, 0, true);
726 /* clear VMDq pool/queue selection for RAR 0 */
727 hw->mac.clear_vmdq(hw, 0, BIT_MASK32);
729 hw->addr_ctrl.overflow_promisc = 0;
731 hw->addr_ctrl.rar_used_count = 1;
733 /* Zero out the other receive addresses. */
734 DEBUGOUT("Clearing RAR[1-%d]\n", rar_entries - 1);
735 for (i = 1; i < rar_entries; i++) {
736 wr32(hw, TXGBE_ETHADDRIDX, i);
737 wr32(hw, TXGBE_ETHADDRL, 0);
738 wr32(hw, TXGBE_ETHADDRH, 0);
742 hw->addr_ctrl.mta_in_use = 0;
743 psrctl = rd32(hw, TXGBE_PSRCTL);
744 psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
745 psrctl |= TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
746 wr32(hw, TXGBE_PSRCTL, psrctl);
748 DEBUGOUT(" Clearing MTA\n");
749 for (i = 0; i < hw->mac.mcft_size; i++)
750 wr32(hw, TXGBE_MCADDRTBL(i), 0);
752 txgbe_init_uta_tables(hw);
758 * txgbe_mta_vector - Determines bit-vector in multicast table to set
759 * @hw: pointer to hardware structure
760 * @mc_addr: the multicast address
762 * Extracts the 12 bits, from a multicast address, to determine which
763 * bit-vector to set in the multicast table. The hardware uses 12 bits, from
764 * incoming rx multicast addresses, to determine the bit-vector to check in
765 * the MTA. Which of the 4 combination, of 12-bits, the hardware uses is set
766 * by the MO field of the PSRCTRL. The MO field is set during initialization
769 static s32 txgbe_mta_vector(struct txgbe_hw *hw, u8 *mc_addr)
773 DEBUGFUNC("txgbe_mta_vector");
775 switch (hw->mac.mc_filter_type) {
776 case 0: /* use bits [47:36] of the address */
777 vector = ((mc_addr[4] >> 4) | (((u16)mc_addr[5]) << 4));
779 case 1: /* use bits [46:35] of the address */
780 vector = ((mc_addr[4] >> 3) | (((u16)mc_addr[5]) << 5));
782 case 2: /* use bits [45:34] of the address */
783 vector = ((mc_addr[4] >> 2) | (((u16)mc_addr[5]) << 6));
785 case 3: /* use bits [43:32] of the address */
786 vector = ((mc_addr[4]) | (((u16)mc_addr[5]) << 8));
788 default: /* Invalid mc_filter_type */
789 DEBUGOUT("MC filter type param set incorrectly\n");
794 /* vector can only be 12-bits or boundary will be exceeded */
800 * txgbe_set_mta - Set bit-vector in multicast table
801 * @hw: pointer to hardware structure
802 * @mc_addr: Multicast address
804 * Sets the bit-vector in the multicast table.
806 void txgbe_set_mta(struct txgbe_hw *hw, u8 *mc_addr)
812 DEBUGFUNC("txgbe_set_mta");
814 hw->addr_ctrl.mta_in_use++;
816 vector = txgbe_mta_vector(hw, mc_addr);
817 DEBUGOUT(" bit-vector = 0x%03X\n", vector);
820 * The MTA is a register array of 128 32-bit registers. It is treated
821 * like an array of 4096 bits. We want to set bit
822 * BitArray[vector_value]. So we figure out what register the bit is
823 * in, read it, OR in the new bit, then write back the new value. The
824 * register is determined by the upper 7 bits of the vector value and
825 * the bit within that register are determined by the lower 5 bits of
828 vector_reg = (vector >> 5) & 0x7F;
829 vector_bit = vector & 0x1F;
830 hw->mac.mta_shadow[vector_reg] |= (1 << vector_bit);
834 * txgbe_update_mc_addr_list - Updates MAC list of multicast addresses
835 * @hw: pointer to hardware structure
836 * @mc_addr_list: the list of new multicast addresses
837 * @mc_addr_count: number of addresses
838 * @next: iterator function to walk the multicast address list
839 * @clear: flag, when set clears the table beforehand
841 * When the clear flag is set, the given list replaces any existing list.
842 * Hashes the given addresses into the multicast table.
844 s32 txgbe_update_mc_addr_list(struct txgbe_hw *hw, u8 *mc_addr_list,
845 u32 mc_addr_count, txgbe_mc_addr_itr next,
851 DEBUGFUNC("txgbe_update_mc_addr_list");
854 * Set the new number of MC addresses that we are being requested to
857 hw->addr_ctrl.num_mc_addrs = mc_addr_count;
858 hw->addr_ctrl.mta_in_use = 0;
860 /* Clear mta_shadow */
862 DEBUGOUT(" Clearing MTA\n");
863 memset(&hw->mac.mta_shadow, 0, sizeof(hw->mac.mta_shadow));
866 /* Update mta_shadow */
867 for (i = 0; i < mc_addr_count; i++) {
868 DEBUGOUT(" Adding the multicast addresses:\n");
869 txgbe_set_mta(hw, next(hw, &mc_addr_list, &vmdq));
873 for (i = 0; i < hw->mac.mcft_size; i++)
874 wr32a(hw, TXGBE_MCADDRTBL(0), i,
875 hw->mac.mta_shadow[i]);
877 if (hw->addr_ctrl.mta_in_use > 0) {
878 u32 psrctl = rd32(hw, TXGBE_PSRCTL);
879 psrctl &= ~(TXGBE_PSRCTL_ADHF12_MASK | TXGBE_PSRCTL_MCHFENA);
880 psrctl |= TXGBE_PSRCTL_MCHFENA |
881 TXGBE_PSRCTL_ADHF12(hw->mac.mc_filter_type);
882 wr32(hw, TXGBE_PSRCTL, psrctl);
885 DEBUGOUT("txgbe update mc addr list complete\n");
890 * txgbe_fc_enable - Enable flow control
891 * @hw: pointer to hardware structure
893 * Enable flow control according to the current settings.
895 s32 txgbe_fc_enable(struct txgbe_hw *hw)
898 u32 mflcn_reg, fccfg_reg;
903 DEBUGFUNC("txgbe_fc_enable");
905 /* Validate the water mark configuration */
906 if (!hw->fc.pause_time) {
907 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
911 /* Low water mark of zero causes XOFF floods */
912 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
913 if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
914 hw->fc.high_water[i]) {
915 if (!hw->fc.low_water[i] ||
916 hw->fc.low_water[i] >= hw->fc.high_water[i]) {
917 DEBUGOUT("Invalid water mark configuration\n");
918 err = TXGBE_ERR_INVALID_LINK_SETTINGS;
924 /* Negotiate the fc mode to use */
925 hw->mac.fc_autoneg(hw);
927 /* Disable any previous flow control settings */
928 mflcn_reg = rd32(hw, TXGBE_RXFCCFG);
929 mflcn_reg &= ~(TXGBE_RXFCCFG_FC | TXGBE_RXFCCFG_PFC);
931 fccfg_reg = rd32(hw, TXGBE_TXFCCFG);
932 fccfg_reg &= ~(TXGBE_TXFCCFG_FC | TXGBE_TXFCCFG_PFC);
935 * The possible values of fc.current_mode are:
936 * 0: Flow control is completely disabled
937 * 1: Rx flow control is enabled (we can receive pause frames,
938 * but not send pause frames).
939 * 2: Tx flow control is enabled (we can send pause frames but
940 * we do not support receiving pause frames).
941 * 3: Both Rx and Tx flow control (symmetric) are enabled.
944 switch (hw->fc.current_mode) {
947 * Flow control is disabled by software override or autoneg.
948 * The code below will actually disable it in the HW.
951 case txgbe_fc_rx_pause:
953 * Rx Flow control is enabled and Tx Flow control is
954 * disabled by software override. Since there really
955 * isn't a way to advertise that we are capable of RX
956 * Pause ONLY, we will advertise that we support both
957 * symmetric and asymmetric Rx PAUSE. Later, we will
958 * disable the adapter's ability to send PAUSE frames.
960 mflcn_reg |= TXGBE_RXFCCFG_FC;
962 case txgbe_fc_tx_pause:
964 * Tx Flow control is enabled, and Rx Flow control is
965 * disabled by software override.
967 fccfg_reg |= TXGBE_TXFCCFG_FC;
970 /* Flow control (both Rx and Tx) is enabled by SW override. */
971 mflcn_reg |= TXGBE_RXFCCFG_FC;
972 fccfg_reg |= TXGBE_TXFCCFG_FC;
975 DEBUGOUT("Flow control param set incorrectly\n");
976 err = TXGBE_ERR_CONFIG;
980 /* Set 802.3x based flow control settings. */
981 wr32(hw, TXGBE_RXFCCFG, mflcn_reg);
982 wr32(hw, TXGBE_TXFCCFG, fccfg_reg);
984 /* Set up and enable Rx high/low water mark thresholds, enable XON. */
985 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
986 if ((hw->fc.current_mode & txgbe_fc_tx_pause) &&
987 hw->fc.high_water[i]) {
988 fcrtl = TXGBE_FCWTRLO_TH(hw->fc.low_water[i]) |
990 fcrth = TXGBE_FCWTRHI_TH(hw->fc.high_water[i]) |
994 * In order to prevent Tx hangs when the internal Tx
995 * switch is enabled we must set the high water mark
996 * to the Rx packet buffer size - 24KB. This allows
997 * the Tx switch to function even under heavy Rx
1001 fcrth = rd32(hw, TXGBE_PBRXSIZE(i)) - 24576;
1003 wr32(hw, TXGBE_FCWTRLO(i), fcrtl);
1004 wr32(hw, TXGBE_FCWTRHI(i), fcrth);
1007 /* Configure pause time (2 TCs per register) */
1008 pause_time = TXGBE_RXFCFSH_TIME(hw->fc.pause_time);
1009 for (i = 0; i < (TXGBE_DCB_TC_MAX / 2); i++)
1010 wr32(hw, TXGBE_FCXOFFTM(i), pause_time * 0x00010001);
1012 /* Configure flow control refresh threshold value */
1013 wr32(hw, TXGBE_RXFCRFSH, hw->fc.pause_time / 2);
1020 * txgbe_acquire_swfw_sync - Acquire SWFW semaphore
1021 * @hw: pointer to hardware structure
1022 * @mask: Mask to specify which semaphore to acquire
1024 * Acquires the SWFW semaphore through the MNGSEM register for the specified
1025 * function (CSR, PHY0, PHY1, EEPROM, Flash)
1027 s32 txgbe_acquire_swfw_sync(struct txgbe_hw *hw, u32 mask)
1030 u32 swmask = TXGBE_MNGSEM_SW(mask);
1031 u32 fwmask = TXGBE_MNGSEM_FW(mask);
1035 DEBUGFUNC("txgbe_acquire_swfw_sync");
1037 for (i = 0; i < timeout; i++) {
1039 * SW NVM semaphore bit is used for access to all
1040 * SW_FW_SYNC bits (not just NVM)
1042 if (txgbe_get_eeprom_semaphore(hw))
1043 return TXGBE_ERR_SWFW_SYNC;
1045 mngsem = rd32(hw, TXGBE_MNGSEM);
1046 if (mngsem & (fwmask | swmask)) {
1047 /* Resource is currently in use by FW or SW */
1048 txgbe_release_eeprom_semaphore(hw);
1052 wr32(hw, TXGBE_MNGSEM, mngsem);
1053 txgbe_release_eeprom_semaphore(hw);
1058 /* If time expired clear the bits holding the lock and retry */
1059 if (mngsem & (fwmask | swmask))
1060 txgbe_release_swfw_sync(hw, mngsem & (fwmask | swmask));
1063 return TXGBE_ERR_SWFW_SYNC;
1067 * txgbe_release_swfw_sync - Release SWFW semaphore
1068 * @hw: pointer to hardware structure
1069 * @mask: Mask to specify which semaphore to release
1071 * Releases the SWFW semaphore through the MNGSEM register for the specified
1072 * function (CSR, PHY0, PHY1, EEPROM, Flash)
1074 void txgbe_release_swfw_sync(struct txgbe_hw *hw, u32 mask)
1079 DEBUGFUNC("txgbe_release_swfw_sync");
1081 txgbe_get_eeprom_semaphore(hw);
1083 mngsem = rd32(hw, TXGBE_MNGSEM);
1085 wr32(hw, TXGBE_MNGSEM, mngsem);
1087 txgbe_release_eeprom_semaphore(hw);
1091 * txgbe_disable_sec_rx_path - Stops the receive data path
1092 * @hw: pointer to hardware structure
1094 * Stops the receive data path and waits for the HW to internally empty
1095 * the Rx security block
1097 s32 txgbe_disable_sec_rx_path(struct txgbe_hw *hw)
1099 #define TXGBE_MAX_SECRX_POLL 4000
1104 DEBUGFUNC("txgbe_disable_sec_rx_path");
1106 secrxreg = rd32(hw, TXGBE_SECRXCTL);
1107 secrxreg |= TXGBE_SECRXCTL_XDSA;
1108 wr32(hw, TXGBE_SECRXCTL, secrxreg);
1109 for (i = 0; i < TXGBE_MAX_SECRX_POLL; i++) {
1110 secrxreg = rd32(hw, TXGBE_SECRXSTAT);
1111 if (!(secrxreg & TXGBE_SECRXSTAT_RDY))
1112 /* Use interrupt-safe sleep just in case */
1118 /* For informational purposes only */
1119 if (i >= TXGBE_MAX_SECRX_POLL)
1120 DEBUGOUT("Rx unit being enabled before security "
1121 "path fully disabled. Continuing with init.\n");
1127 * txgbe_enable_sec_rx_path - Enables the receive data path
1128 * @hw: pointer to hardware structure
1130 * Enables the receive data path.
1132 s32 txgbe_enable_sec_rx_path(struct txgbe_hw *hw)
1136 DEBUGFUNC("txgbe_enable_sec_rx_path");
1138 secrxreg = rd32(hw, TXGBE_SECRXCTL);
1139 secrxreg &= ~TXGBE_SECRXCTL_XDSA;
1140 wr32(hw, TXGBE_SECRXCTL, secrxreg);
1147 * txgbe_disable_sec_tx_path - Stops the transmit data path
1148 * @hw: pointer to hardware structure
1150 * Stops the transmit data path and waits for the HW to internally empty
1151 * the Tx security block
1153 int txgbe_disable_sec_tx_path(struct txgbe_hw *hw)
1155 #define TXGBE_MAX_SECTX_POLL 40
1160 sectxreg = rd32(hw, TXGBE_SECTXCTL);
1161 sectxreg |= TXGBE_SECTXCTL_XDSA;
1162 wr32(hw, TXGBE_SECTXCTL, sectxreg);
1163 for (i = 0; i < TXGBE_MAX_SECTX_POLL; i++) {
1164 sectxreg = rd32(hw, TXGBE_SECTXSTAT);
1165 if (sectxreg & TXGBE_SECTXSTAT_RDY)
1167 /* Use interrupt-safe sleep just in case */
1171 /* For informational purposes only */
1172 if (i >= TXGBE_MAX_SECTX_POLL)
1173 PMD_DRV_LOG(DEBUG, "Tx unit being enabled before security "
1174 "path fully disabled. Continuing with init.");
1180 * txgbe_enable_sec_tx_path - Enables the transmit data path
1181 * @hw: pointer to hardware structure
1183 * Enables the transmit data path.
1185 int txgbe_enable_sec_tx_path(struct txgbe_hw *hw)
1189 sectxreg = rd32(hw, TXGBE_SECTXCTL);
1190 sectxreg &= ~TXGBE_SECTXCTL_XDSA;
1191 wr32(hw, TXGBE_SECTXCTL, sectxreg);
1198 * txgbe_get_san_mac_addr_offset - Get SAN MAC address offset from the EEPROM
1199 * @hw: pointer to hardware structure
1200 * @san_mac_offset: SAN MAC address offset
1202 * This function will read the EEPROM location for the SAN MAC address
1203 * pointer, and returns the value at that location. This is used in both
1204 * get and set mac_addr routines.
1206 static s32 txgbe_get_san_mac_addr_offset(struct txgbe_hw *hw,
1207 u16 *san_mac_offset)
1211 DEBUGFUNC("txgbe_get_san_mac_addr_offset");
1214 * First read the EEPROM pointer to see if the MAC addresses are
1217 err = hw->rom.readw_sw(hw, TXGBE_SAN_MAC_ADDR_PTR,
1220 DEBUGOUT("eeprom at offset %d failed",
1221 TXGBE_SAN_MAC_ADDR_PTR);
1228 * txgbe_get_san_mac_addr - SAN MAC address retrieval from the EEPROM
1229 * @hw: pointer to hardware structure
1230 * @san_mac_addr: SAN MAC address
1232 * Reads the SAN MAC address from the EEPROM, if it's available. This is
1233 * per-port, so set_lan_id() must be called before reading the addresses.
1234 * set_lan_id() is called by identify_sfp(), but this cannot be relied
1235 * upon for non-SFP connections, so we must call it here.
1237 s32 txgbe_get_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
1239 u16 san_mac_data, san_mac_offset;
1243 DEBUGFUNC("txgbe_get_san_mac_addr");
1246 * First read the EEPROM pointer to see if the MAC addresses are
1247 * available. If they're not, no point in calling set_lan_id() here.
1249 err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
1250 if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
1251 goto san_mac_addr_out;
1253 /* apply the port offset to the address offset */
1254 (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
1255 (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
1256 for (i = 0; i < 3; i++) {
1257 err = hw->rom.read16(hw, san_mac_offset,
1260 DEBUGOUT("eeprom read at offset %d failed",
1262 goto san_mac_addr_out;
1264 san_mac_addr[i * 2] = (u8)(san_mac_data);
1265 san_mac_addr[i * 2 + 1] = (u8)(san_mac_data >> 8);
1272 * No addresses available in this EEPROM. It's not an
1273 * error though, so just wipe the local address and return.
1275 for (i = 0; i < 6; i++)
1276 san_mac_addr[i] = 0xFF;
1281 * txgbe_set_san_mac_addr - Write the SAN MAC address to the EEPROM
1282 * @hw: pointer to hardware structure
1283 * @san_mac_addr: SAN MAC address
1285 * Write a SAN MAC address to the EEPROM.
1287 s32 txgbe_set_san_mac_addr(struct txgbe_hw *hw, u8 *san_mac_addr)
1290 u16 san_mac_data, san_mac_offset;
1293 DEBUGFUNC("txgbe_set_san_mac_addr");
1295 /* Look for SAN mac address pointer. If not defined, return */
1296 err = txgbe_get_san_mac_addr_offset(hw, &san_mac_offset);
1297 if (err || san_mac_offset == 0 || san_mac_offset == 0xFFFF)
1298 return TXGBE_ERR_NO_SAN_ADDR_PTR;
1300 /* Apply the port offset to the address offset */
1301 (hw->bus.func) ? (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT1_OFFSET) :
1302 (san_mac_offset += TXGBE_SAN_MAC_ADDR_PORT0_OFFSET);
1304 for (i = 0; i < 3; i++) {
1305 san_mac_data = (u16)((u16)(san_mac_addr[i * 2 + 1]) << 8);
1306 san_mac_data |= (u16)(san_mac_addr[i * 2]);
1307 hw->rom.write16(hw, san_mac_offset, san_mac_data);
1315 * txgbe_clear_vmdq - Disassociate a VMDq pool index from a rx address
1316 * @hw: pointer to hardware struct
1317 * @rar: receive address register index to disassociate
1318 * @vmdq: VMDq pool index to remove from the rar
1320 s32 txgbe_clear_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
1322 u32 mpsar_lo, mpsar_hi;
1323 u32 rar_entries = hw->mac.num_rar_entries;
1325 DEBUGFUNC("txgbe_clear_vmdq");
1327 /* Make sure we are using a valid rar index range */
1328 if (rar >= rar_entries) {
1329 DEBUGOUT("RAR index %d is out of range.\n", rar);
1330 return TXGBE_ERR_INVALID_ARGUMENT;
1333 wr32(hw, TXGBE_ETHADDRIDX, rar);
1334 mpsar_lo = rd32(hw, TXGBE_ETHADDRASSL);
1335 mpsar_hi = rd32(hw, TXGBE_ETHADDRASSH);
1337 if (TXGBE_REMOVED(hw->hw_addr))
1340 if (!mpsar_lo && !mpsar_hi)
1343 if (vmdq == BIT_MASK32) {
1345 wr32(hw, TXGBE_ETHADDRASSL, 0);
1349 wr32(hw, TXGBE_ETHADDRASSH, 0);
1352 } else if (vmdq < 32) {
1353 mpsar_lo &= ~(1 << vmdq);
1354 wr32(hw, TXGBE_ETHADDRASSL, mpsar_lo);
1356 mpsar_hi &= ~(1 << (vmdq - 32));
1357 wr32(hw, TXGBE_ETHADDRASSH, mpsar_hi);
1360 /* was that the last pool using this rar? */
1361 if (mpsar_lo == 0 && mpsar_hi == 0 &&
1362 rar != 0 && rar != hw->mac.san_mac_rar_index)
1363 hw->mac.clear_rar(hw, rar);
1369 * txgbe_set_vmdq - Associate a VMDq pool index with a rx address
1370 * @hw: pointer to hardware struct
1371 * @rar: receive address register index to associate with a VMDq index
1372 * @vmdq: VMDq pool index
1374 s32 txgbe_set_vmdq(struct txgbe_hw *hw, u32 rar, u32 vmdq)
1377 u32 rar_entries = hw->mac.num_rar_entries;
1379 DEBUGFUNC("txgbe_set_vmdq");
1381 /* Make sure we are using a valid rar index range */
1382 if (rar >= rar_entries) {
1383 DEBUGOUT("RAR index %d is out of range.\n", rar);
1384 return TXGBE_ERR_INVALID_ARGUMENT;
1387 wr32(hw, TXGBE_ETHADDRIDX, rar);
1389 mpsar = rd32(hw, TXGBE_ETHADDRASSL);
1391 wr32(hw, TXGBE_ETHADDRASSL, mpsar);
1393 mpsar = rd32(hw, TXGBE_ETHADDRASSH);
1394 mpsar |= 1 << (vmdq - 32);
1395 wr32(hw, TXGBE_ETHADDRASSH, mpsar);
1401 * txgbe_init_uta_tables - Initialize the Unicast Table Array
1402 * @hw: pointer to hardware structure
1404 s32 txgbe_init_uta_tables(struct txgbe_hw *hw)
1408 DEBUGFUNC("txgbe_init_uta_tables");
1409 DEBUGOUT(" Clearing UTA\n");
1411 for (i = 0; i < 128; i++)
1412 wr32(hw, TXGBE_UCADDRTBL(i), 0);
1418 * txgbe_find_vlvf_slot - find the vlanid or the first empty slot
1419 * @hw: pointer to hardware structure
1420 * @vlan: VLAN id to write to VLAN filter
1421 * @vlvf_bypass: true to find vlanid only, false returns first empty slot if
1425 * return the VLVF index where this VLAN id should be placed
1428 s32 txgbe_find_vlvf_slot(struct txgbe_hw *hw, u32 vlan, bool vlvf_bypass)
1430 s32 regindex, first_empty_slot;
1433 /* short cut the special case */
1437 /* if vlvf_bypass is set we don't want to use an empty slot, we
1438 * will simply bypass the VLVF if there are no entries present in the
1439 * VLVF that contain our VLAN
1441 first_empty_slot = vlvf_bypass ? TXGBE_ERR_NO_SPACE : 0;
1443 /* add VLAN enable bit for comparison */
1444 vlan |= TXGBE_PSRVLAN_EA;
1446 /* Search for the vlan id in the VLVF entries. Save off the first empty
1447 * slot found along the way.
1449 * pre-decrement loop covering (TXGBE_NUM_POOL - 1) .. 1
1451 for (regindex = TXGBE_NUM_POOL; --regindex;) {
1452 wr32(hw, TXGBE_PSRVLANIDX, regindex);
1453 bits = rd32(hw, TXGBE_PSRVLAN);
1456 if (!first_empty_slot && !bits)
1457 first_empty_slot = regindex;
1460 /* If we are here then we didn't find the VLAN. Return first empty
1461 * slot we found during our search, else error.
1463 if (!first_empty_slot)
1464 DEBUGOUT("No space in VLVF.\n");
1466 return first_empty_slot ? first_empty_slot : TXGBE_ERR_NO_SPACE;
1470 * txgbe_set_vfta - Set VLAN filter table
1471 * @hw: pointer to hardware structure
1472 * @vlan: VLAN id to write to VLAN filter
1473 * @vind: VMDq output index that maps queue to VLAN id in VLVFB
1474 * @vlan_on: boolean flag to turn on/off VLAN
1475 * @vlvf_bypass: boolean flag indicating updating default pool is okay
1477 * Turn on/off specified VLAN in the VLAN filter table.
1479 s32 txgbe_set_vfta(struct txgbe_hw *hw, u32 vlan, u32 vind,
1480 bool vlan_on, bool vlvf_bypass)
1482 u32 regidx, vfta_delta, vfta;
1485 DEBUGFUNC("txgbe_set_vfta");
1487 if (vlan > 4095 || vind > 63)
1488 return TXGBE_ERR_PARAM;
1491 * this is a 2 part operation - first the VFTA, then the
1492 * VLVF and VLVFB if VT Mode is set
1493 * We don't write the VFTA until we know the VLVF part succeeded.
1497 * The VFTA is a bitstring made up of 128 32-bit registers
1498 * that enable the particular VLAN id, much like the MTA:
1499 * bits[11-5]: which register
1500 * bits[4-0]: which bit in the register
1503 vfta_delta = 1 << (vlan % 32);
1504 vfta = rd32(hw, TXGBE_VLANTBL(regidx));
1507 * vfta_delta represents the difference between the current value
1508 * of vfta and the value we want in the register. Since the diff
1509 * is an XOR mask we can just update the vfta using an XOR
1511 vfta_delta &= vlan_on ? ~vfta : vfta;
1515 * Call txgbe_set_vlvf to set VLVFB and VLVF
1517 err = txgbe_set_vlvf(hw, vlan, vind, vlan_on, &vfta_delta,
1526 /* Update VFTA now that we are ready for traffic */
1528 wr32(hw, TXGBE_VLANTBL(regidx), vfta);
1534 * txgbe_set_vlvf - Set VLAN Pool Filter
1535 * @hw: pointer to hardware structure
1536 * @vlan: VLAN id to write to VLAN filter
1537 * @vind: VMDq output index that maps queue to VLAN id in PSRVLANPLM
1538 * @vlan_on: boolean flag to turn on/off VLAN in PSRVLAN
1539 * @vfta_delta: pointer to the difference between the current value
1540 * of PSRVLANPLM and the desired value
1541 * @vfta: the desired value of the VFTA
1542 * @vlvf_bypass: boolean flag indicating updating default pool is okay
1544 * Turn on/off specified bit in VLVF table.
1546 s32 txgbe_set_vlvf(struct txgbe_hw *hw, u32 vlan, u32 vind,
1547 bool vlan_on, u32 *vfta_delta, u32 vfta,
1554 DEBUGFUNC("txgbe_set_vlvf");
1556 if (vlan > 4095 || vind > 63)
1557 return TXGBE_ERR_PARAM;
1559 /* If VT Mode is set
1561 * make sure the vlan is in PSRVLAN
1562 * set the vind bit in the matching PSRVLANPLM
1564 * clear the pool bit and possibly the vind
1566 portctl = rd32(hw, TXGBE_PORTCTL);
1567 if (!(portctl & TXGBE_PORTCTL_NUMVT_MASK))
1570 vlvf_index = txgbe_find_vlvf_slot(hw, vlan, vlvf_bypass);
1574 wr32(hw, TXGBE_PSRVLANIDX, vlvf_index);
1575 bits = rd32(hw, TXGBE_PSRVLANPLM(vind / 32));
1577 /* set the pool bit */
1578 bits |= 1 << (vind % 32);
1582 /* clear the pool bit */
1583 bits ^= 1 << (vind % 32);
1586 !rd32(hw, TXGBE_PSRVLANPLM(vind / 32))) {
1587 /* Clear PSRVLANPLM first, then disable PSRVLAN. Otherwise
1588 * we run the risk of stray packets leaking into
1589 * the PF via the default pool
1592 wr32(hw, TXGBE_PSRVLANPLM(vlan / 32), vfta);
1594 /* disable VLVF and clear remaining bit from pool */
1595 wr32(hw, TXGBE_PSRVLAN, 0);
1596 wr32(hw, TXGBE_PSRVLANPLM(vind / 32), 0);
1601 /* If there are still bits set in the PSRVLANPLM registers
1602 * for the VLAN ID indicated we need to see if the
1603 * caller is requesting that we clear the PSRVLANPLM entry bit.
1604 * If the caller has requested that we clear the PSRVLANPLM
1605 * entry bit but there are still pools/VFs using this VLAN
1606 * ID entry then ignore the request. We're not worried
1607 * about the case where we're turning the PSRVLANPLM VLAN ID
1608 * entry bit on, only when requested to turn it off as
1609 * there may be multiple pools and/or VFs using the
1610 * VLAN ID entry. In that case we cannot clear the
1611 * PSRVLANPLM bit until all pools/VFs using that VLAN ID have also
1612 * been cleared. This will be indicated by "bits" being
1618 /* record pool change and enable VLAN ID if not already enabled */
1619 wr32(hw, TXGBE_PSRVLANPLM(vind / 32), bits);
1620 wr32(hw, TXGBE_PSRVLAN, TXGBE_PSRVLAN_EA | vlan);
1626 * txgbe_clear_vfta - Clear VLAN filter table
1627 * @hw: pointer to hardware structure
1629 * Clears the VLAN filer table, and the VMDq index associated with the filter
1631 s32 txgbe_clear_vfta(struct txgbe_hw *hw)
1635 DEBUGFUNC("txgbe_clear_vfta");
1637 for (offset = 0; offset < hw->mac.vft_size; offset++)
1638 wr32(hw, TXGBE_VLANTBL(offset), 0);
1640 for (offset = 0; offset < TXGBE_NUM_POOL; offset++) {
1641 wr32(hw, TXGBE_PSRVLANIDX, offset);
1642 wr32(hw, TXGBE_PSRVLAN, 0);
1643 wr32(hw, TXGBE_PSRVLANPLM(0), 0);
1644 wr32(hw, TXGBE_PSRVLANPLM(1), 0);
1651 * txgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
1652 * @hw: pointer to hardware structure
1654 * Contains the logic to identify if we need to verify link for the
1657 static bool txgbe_need_crosstalk_fix(struct txgbe_hw *hw)
1659 /* Does FW say we need the fix */
1660 if (!hw->need_crosstalk_fix)
1663 /* Only consider SFP+ PHYs i.e. media type fiber */
1664 switch (hw->phy.media_type) {
1665 case txgbe_media_type_fiber:
1666 case txgbe_media_type_fiber_qsfp:
1676 * txgbe_check_mac_link - Determine link and speed status
1677 * @hw: pointer to hardware structure
1678 * @speed: pointer to link speed
1679 * @link_up: true when link is up
1680 * @link_up_wait_to_complete: bool used to wait for link up or not
1682 * Reads the links register to determine if link is up and the current speed
1684 s32 txgbe_check_mac_link(struct txgbe_hw *hw, u32 *speed,
1685 bool *link_up, bool link_up_wait_to_complete)
1687 u32 links_reg, links_orig;
1690 DEBUGFUNC("txgbe_check_mac_link");
1692 /* If Crosstalk fix enabled do the sanity check of making sure
1693 * the SFP+ cage is full.
1695 if (txgbe_need_crosstalk_fix(hw)) {
1698 switch (hw->mac.type) {
1699 case txgbe_mac_raptor:
1700 sfp_cage_full = !rd32m(hw, TXGBE_GPIODATA,
1704 /* sanity check - No SFP+ devices here */
1705 sfp_cage_full = false;
1709 if (!sfp_cage_full) {
1711 *speed = TXGBE_LINK_SPEED_UNKNOWN;
1716 /* clear the old state */
1717 links_orig = rd32(hw, TXGBE_PORTSTAT);
1719 links_reg = rd32(hw, TXGBE_PORTSTAT);
1721 if (links_orig != links_reg) {
1722 DEBUGOUT("LINKS changed from %08X to %08X\n",
1723 links_orig, links_reg);
1726 if (link_up_wait_to_complete) {
1727 for (i = 0; i < hw->mac.max_link_up_time; i++) {
1728 if (!(links_reg & TXGBE_PORTSTAT_UP)) {
1735 links_reg = rd32(hw, TXGBE_PORTSTAT);
1738 if (links_reg & TXGBE_PORTSTAT_UP)
1744 switch (links_reg & TXGBE_PORTSTAT_BW_MASK) {
1745 case TXGBE_PORTSTAT_BW_10G:
1746 *speed = TXGBE_LINK_SPEED_10GB_FULL;
1748 case TXGBE_PORTSTAT_BW_1G:
1749 *speed = TXGBE_LINK_SPEED_1GB_FULL;
1751 case TXGBE_PORTSTAT_BW_100M:
1752 *speed = TXGBE_LINK_SPEED_100M_FULL;
1755 *speed = TXGBE_LINK_SPEED_UNKNOWN;
1762 * txgbe_get_wwn_prefix - Get alternative WWNN/WWPN prefix from
1764 * @hw: pointer to hardware structure
1765 * @wwnn_prefix: the alternative WWNN prefix
1766 * @wwpn_prefix: the alternative WWPN prefix
1768 * This function will read the EEPROM from the alternative SAN MAC address
1769 * block to check the support for the alternative WWNN/WWPN prefix support.
1771 s32 txgbe_get_wwn_prefix(struct txgbe_hw *hw, u16 *wwnn_prefix,
1775 u16 alt_san_mac_blk_offset;
1777 DEBUGFUNC("txgbe_get_wwn_prefix");
1779 /* clear output first */
1780 *wwnn_prefix = 0xFFFF;
1781 *wwpn_prefix = 0xFFFF;
1783 /* check if alternative SAN MAC is supported */
1784 offset = TXGBE_ALT_SAN_MAC_ADDR_BLK_PTR;
1785 if (hw->rom.readw_sw(hw, offset, &alt_san_mac_blk_offset))
1786 goto wwn_prefix_err;
1788 if (alt_san_mac_blk_offset == 0 || alt_san_mac_blk_offset == 0xFFFF)
1789 goto wwn_prefix_out;
1791 /* check capability in alternative san mac address block */
1792 offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_CAPS_OFFSET;
1793 if (hw->rom.read16(hw, offset, &caps))
1794 goto wwn_prefix_err;
1795 if (!(caps & TXGBE_ALT_SAN_MAC_ADDR_CAPS_ALTWWN))
1796 goto wwn_prefix_out;
1798 /* get the corresponding prefix for WWNN/WWPN */
1799 offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWNN_OFFSET;
1800 if (hw->rom.read16(hw, offset, wwnn_prefix))
1801 DEBUGOUT("eeprom read at offset %d failed", offset);
1803 offset = alt_san_mac_blk_offset + TXGBE_ALT_SAN_MAC_ADDR_WWPN_OFFSET;
1804 if (hw->rom.read16(hw, offset, wwpn_prefix))
1805 goto wwn_prefix_err;
1811 DEBUGOUT("eeprom read at offset %d failed", offset);
1816 * txgbe_set_mac_anti_spoofing - Enable/Disable MAC anti-spoofing
1817 * @hw: pointer to hardware structure
1818 * @enable: enable or disable switch for MAC anti-spoofing
1819 * @vf: Virtual Function pool - VF Pool to set for MAC anti-spoofing
1822 void txgbe_set_mac_anti_spoofing(struct txgbe_hw *hw, bool enable, int vf)
1824 int vf_target_reg = vf >> 3;
1825 int vf_target_shift = vf % 8;
1828 pfvfspoof = rd32(hw, TXGBE_POOLTXASMAC(vf_target_reg));
1830 pfvfspoof |= (1 << vf_target_shift);
1832 pfvfspoof &= ~(1 << vf_target_shift);
1833 wr32(hw, TXGBE_POOLTXASMAC(vf_target_reg), pfvfspoof);
1837 * txgbe_set_ethertype_anti_spoofing - Configure Ethertype anti-spoofing
1838 * @hw: pointer to hardware structure
1839 * @enable: enable or disable switch for Ethertype anti-spoofing
1840 * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
1843 void txgbe_set_ethertype_anti_spoofing(struct txgbe_hw *hw,
1844 bool enable, int vf)
1846 int vf_target_reg = vf >> 3;
1847 int vf_target_shift = vf % 8;
1850 pfvfspoof = rd32(hw, TXGBE_POOLTXASET(vf_target_reg));
1852 pfvfspoof |= (1 << vf_target_shift);
1854 pfvfspoof &= ~(1 << vf_target_shift);
1855 wr32(hw, TXGBE_POOLTXASET(vf_target_reg), pfvfspoof);
1859 * txgbe_get_device_caps - Get additional device capabilities
1860 * @hw: pointer to hardware structure
1861 * @device_caps: the EEPROM word with the extra device capabilities
1863 * This function will read the EEPROM location for the device capabilities,
1864 * and return the word through device_caps.
1866 s32 txgbe_get_device_caps(struct txgbe_hw *hw, u16 *device_caps)
1868 DEBUGFUNC("txgbe_get_device_caps");
1870 hw->rom.readw_sw(hw, TXGBE_DEVICE_CAPS, device_caps);
1876 * txgbe_set_pba - Initialize Rx packet buffer
1877 * @hw: pointer to hardware structure
1878 * @num_pb: number of packet buffers to allocate
1879 * @headroom: reserve n KB of headroom
1880 * @strategy: packet buffer allocation strategy
1882 void txgbe_set_pba(struct txgbe_hw *hw, int num_pb, u32 headroom,
1885 u32 pbsize = hw->mac.rx_pb_size;
1887 u32 rxpktsize, txpktsize, txpbthresh;
1889 UNREFERENCED_PARAMETER(hw);
1891 /* Reserve headroom */
1897 /* Divide remaining packet buffer space amongst the number of packet
1898 * buffers requested using supplied strategy.
1901 case PBA_STRATEGY_WEIGHTED:
1902 /* txgbe_dcb_pba_80_48 strategy weight first half of packet
1903 * buffer with 5/8 of the packet buffer space.
1905 rxpktsize = (pbsize * 5) / (num_pb * 4);
1906 pbsize -= rxpktsize * (num_pb / 2);
1908 for (; i < (num_pb / 2); i++)
1909 wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
1910 /* fall through - configure remaining packet buffers */
1911 case PBA_STRATEGY_EQUAL:
1912 rxpktsize = (pbsize / (num_pb - i));
1914 for (; i < num_pb; i++)
1915 wr32(hw, TXGBE_PBRXSIZE(i), rxpktsize);
1921 /* Only support an equally distributed Tx packet buffer strategy. */
1922 txpktsize = TXGBE_PBTXSIZE_MAX / num_pb;
1923 txpbthresh = (txpktsize / 1024) - TXGBE_TXPKT_SIZE_MAX;
1924 for (i = 0; i < num_pb; i++) {
1925 wr32(hw, TXGBE_PBTXSIZE(i), txpktsize);
1926 wr32(hw, TXGBE_PBTXDMATH(i), txpbthresh);
1929 /* Clear unused TCs, if any, to zero buffer size*/
1930 for (; i < TXGBE_MAX_UP; i++) {
1931 wr32(hw, TXGBE_PBRXSIZE(i), 0);
1932 wr32(hw, TXGBE_PBTXSIZE(i), 0);
1933 wr32(hw, TXGBE_PBTXDMATH(i), 0);
1938 * txgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
1939 * @hw: pointer to the hardware structure
1941 * The MACs can experience issues if TX work is still pending
1942 * when a reset occurs. This function prevents this by flushing the PCIe
1943 * buffers on the system.
1945 void txgbe_clear_tx_pending(struct txgbe_hw *hw)
1947 u32 hlreg0, i, poll;
1950 * If double reset is not requested then all transactions should
1951 * already be clear and as such there is no work to do
1953 if (!(hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
1956 hlreg0 = rd32(hw, TXGBE_PSRCTL);
1957 wr32(hw, TXGBE_PSRCTL, hlreg0 | TXGBE_PSRCTL_LBENA);
1959 /* Wait for a last completion before clearing buffers */
1964 * Before proceeding, make sure that the PCIe block does not have
1965 * transactions pending.
1967 poll = (800 * 11) / 10;
1968 for (i = 0; i < poll; i++)
1971 /* Flush all writes and allow 20usec for all transactions to clear */
1975 /* restore previous register values */
1976 wr32(hw, TXGBE_PSRCTL, hlreg0);
1980 * txgbe_get_thermal_sensor_data - Gathers thermal sensor data
1981 * @hw: pointer to hardware structure
1983 * Returns the thermal sensor data structure
1985 s32 txgbe_get_thermal_sensor_data(struct txgbe_hw *hw)
1987 struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
1991 DEBUGFUNC("txgbe_get_thermal_sensor_data");
1993 /* Only support thermal sensors attached to physical port 0 */
1994 if (hw->bus.lan_id != 0)
1995 return TXGBE_NOT_IMPLEMENTED;
1997 ts_stat = rd32(hw, TXGBE_TSSTAT);
1998 tsv = (s64)TXGBE_TSSTAT_DATA(ts_stat);
1999 tsv = tsv > 1200 ? tsv : 1200;
2000 tsv = -(48380 << 8) / 1000
2001 + tsv * (31020 << 8) / 100000
2002 - tsv * tsv * (18201 << 8) / 100000000
2003 + tsv * tsv * tsv * (81542 << 8) / 1000000000000
2004 - tsv * tsv * tsv * tsv * (16743 << 8) / 1000000000000000;
2007 data->sensor[0].temp = (s16)tsv;
2013 * txgbe_init_thermal_sensor_thresh - Inits thermal sensor thresholds
2014 * @hw: pointer to hardware structure
2016 * Inits the thermal sensor thresholds according to the NVM map
2017 * and save off the threshold and location values into mac.thermal_sensor_data
2019 s32 txgbe_init_thermal_sensor_thresh(struct txgbe_hw *hw)
2021 struct txgbe_thermal_sensor_data *data = &hw->mac.thermal_sensor_data;
2023 DEBUGFUNC("txgbe_init_thermal_sensor_thresh");
2025 memset(data, 0, sizeof(struct txgbe_thermal_sensor_data));
2027 if (hw->bus.lan_id != 0)
2028 return TXGBE_NOT_IMPLEMENTED;
2030 wr32(hw, TXGBE_TSCTRL, TXGBE_TSCTRL_EVALMD);
2031 wr32(hw, TXGBE_TSINTR,
2032 TXGBE_TSINTR_AEN | TXGBE_TSINTR_DEN);
2033 wr32(hw, TXGBE_TSEN, TXGBE_TSEN_ENA);
2036 data->sensor[0].alarm_thresh = 100;
2037 wr32(hw, TXGBE_TSATHRE, 677);
2038 data->sensor[0].dalarm_thresh = 90;
2039 wr32(hw, TXGBE_TSDTHRE, 614);
2044 void txgbe_disable_rx(struct txgbe_hw *hw)
2048 pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
2049 if (pfdtxgswc & TXGBE_PSRCTL_LBENA) {
2050 pfdtxgswc &= ~TXGBE_PSRCTL_LBENA;
2051 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
2052 hw->mac.set_lben = true;
2054 hw->mac.set_lben = false;
2057 wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, 0);
2058 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, 0);
2061 void txgbe_enable_rx(struct txgbe_hw *hw)
2065 wr32m(hw, TXGBE_MACRXCFG, TXGBE_MACRXCFG_ENA, TXGBE_MACRXCFG_ENA);
2066 wr32m(hw, TXGBE_PBRXCTL, TXGBE_PBRXCTL_ENA, TXGBE_PBRXCTL_ENA);
2068 if (hw->mac.set_lben) {
2069 pfdtxgswc = rd32(hw, TXGBE_PSRCTL);
2070 pfdtxgswc |= TXGBE_PSRCTL_LBENA;
2071 wr32(hw, TXGBE_PSRCTL, pfdtxgswc);
2072 hw->mac.set_lben = false;
2077 * txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
2078 * @hw: pointer to hardware structure
2079 * @speed: new link speed
2080 * @autoneg_wait_to_complete: true when waiting for completion is needed
2082 * Set the link speed in the MAC and/or PHY register and restarts link.
2084 s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
2086 bool autoneg_wait_to_complete)
2088 u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2089 u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2093 bool autoneg, link_up = false;
2095 DEBUGFUNC("txgbe_setup_mac_link_multispeed_fiber");
2097 /* Mask off requested but non-supported speeds */
2098 status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
2102 speed &= link_speed;
2104 /* Try each speed one by one, highest priority first. We do this in
2105 * software because 10Gb fiber doesn't support speed autonegotiation.
2107 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
2109 highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
2111 /* Set the module link speed */
2112 switch (hw->phy.media_type) {
2113 case txgbe_media_type_fiber:
2114 hw->mac.set_rate_select_speed(hw,
2115 TXGBE_LINK_SPEED_10GB_FULL);
2117 case txgbe_media_type_fiber_qsfp:
2118 /* QSFP module automatically detects MAC link speed */
2121 DEBUGOUT("Unexpected media type.\n");
2125 /* Allow module to change analog characteristics (1G->10G) */
2128 status = hw->mac.setup_mac_link(hw,
2129 TXGBE_LINK_SPEED_10GB_FULL,
2130 autoneg_wait_to_complete);
2134 /* Flap the Tx laser if it has not already been done */
2135 hw->mac.flap_tx_laser(hw);
2137 /* Wait for the controller to acquire link. Per IEEE 802.3ap,
2138 * Section 73.10.2, we may have to wait up to 500ms if KR is
2139 * attempted. uses the same timing for 10g SFI.
2141 for (i = 0; i < 5; i++) {
2142 /* Wait for the link partner to also set speed */
2145 /* If we have link, just jump out */
2146 status = hw->mac.check_link(hw, &link_speed,
2156 if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
2158 if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
2159 highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;
2161 /* Set the module link speed */
2162 switch (hw->phy.media_type) {
2163 case txgbe_media_type_fiber:
2164 hw->mac.set_rate_select_speed(hw,
2165 TXGBE_LINK_SPEED_1GB_FULL);
2167 case txgbe_media_type_fiber_qsfp:
2168 /* QSFP module automatically detects link speed */
2171 DEBUGOUT("Unexpected media type.\n");
2175 /* Allow module to change analog characteristics (10G->1G) */
2178 status = hw->mac.setup_mac_link(hw,
2179 TXGBE_LINK_SPEED_1GB_FULL,
2180 autoneg_wait_to_complete);
2184 /* Flap the Tx laser if it has not already been done */
2185 hw->mac.flap_tx_laser(hw);
2187 /* Wait for the link partner to also set speed */
2190 /* If we have link, just jump out */
2191 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
2199 /* We didn't get link. Configure back to the highest speed we tried,
2200 * (if there was more than one). We call ourselves back with just the
2201 * single highest speed that the user requested.
2204 status = txgbe_setup_mac_link_multispeed_fiber(hw,
2206 autoneg_wait_to_complete);
2209 /* Set autoneg_advertised value based on input link speed */
2210 hw->phy.autoneg_advertised = 0;
2212 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
2213 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
2215 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
2216 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
2222 * txgbe_init_shared_code - Initialize the shared code
2223 * @hw: pointer to hardware structure
2225 * This will assign function pointers and assign the MAC type and PHY code.
2226 * Does not touch the hardware. This function must be called prior to any
2227 * other function in the shared code. The txgbe_hw structure should be
2228 * memset to 0 prior to calling this function. The following fields in
2229 * hw structure should be filled in prior to calling this function:
2230 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
2231 * subsystem_vendor_id, and revision_id
2233 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
2237 DEBUGFUNC("txgbe_init_shared_code");
2242 txgbe_set_mac_type(hw);
2244 txgbe_init_ops_dummy(hw);
2245 switch (hw->mac.type) {
2246 case txgbe_mac_raptor:
2247 status = txgbe_init_ops_pf(hw);
2250 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2253 hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
2255 hw->bus.set_lan_id(hw);
2261 * txgbe_set_mac_type - Sets MAC type
2262 * @hw: pointer to the HW structure
2264 * This function sets the mac type of the adapter based on the
2265 * vendor ID and device ID stored in the hw structure.
2267 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
2271 DEBUGFUNC("txgbe_set_mac_type");
2273 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
2274 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
2275 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2278 switch (hw->device_id) {
2279 case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
2280 hw->phy.media_type = txgbe_media_type_backplane;
2281 hw->mac.type = txgbe_mac_raptor;
2283 case TXGBE_DEV_ID_RAPTOR_XAUI:
2284 case TXGBE_DEV_ID_RAPTOR_SGMII:
2285 hw->phy.media_type = txgbe_media_type_copper;
2286 hw->mac.type = txgbe_mac_raptor;
2288 case TXGBE_DEV_ID_RAPTOR_SFP:
2289 case TXGBE_DEV_ID_WX1820_SFP:
2290 hw->phy.media_type = txgbe_media_type_fiber;
2291 hw->mac.type = txgbe_mac_raptor;
2293 case TXGBE_DEV_ID_RAPTOR_QSFP:
2294 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
2295 hw->mac.type = txgbe_mac_raptor;
2297 case TXGBE_DEV_ID_RAPTOR_VF:
2298 case TXGBE_DEV_ID_RAPTOR_VF_HV:
2299 hw->phy.media_type = txgbe_media_type_virtual;
2300 hw->mac.type = txgbe_mac_raptor_vf;
2303 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
2304 DEBUGOUT("Unsupported device id: %x", hw->device_id);
2308 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
2309 hw->mac.type, hw->phy.media_type, err);
2313 void txgbe_init_mac_link_ops(struct txgbe_hw *hw)
2315 struct txgbe_mac_info *mac = &hw->mac;
2317 DEBUGFUNC("txgbe_init_mac_link_ops");
2320 * enable the laser control functions for SFP+ fiber
2321 * and MNG not enabled
2323 if (hw->phy.media_type == txgbe_media_type_fiber &&
2324 !txgbe_mng_enabled(hw)) {
2325 mac->disable_tx_laser =
2326 txgbe_disable_tx_laser_multispeed_fiber;
2327 mac->enable_tx_laser =
2328 txgbe_enable_tx_laser_multispeed_fiber;
2329 mac->flap_tx_laser =
2330 txgbe_flap_tx_laser_multispeed_fiber;
2333 if ((hw->phy.media_type == txgbe_media_type_fiber ||
2334 hw->phy.media_type == txgbe_media_type_fiber_qsfp) &&
2335 hw->phy.multispeed_fiber) {
2336 /* Set up dual speed SFP+ support */
2337 mac->setup_link = txgbe_setup_mac_link_multispeed_fiber;
2338 mac->setup_mac_link = txgbe_setup_mac_link;
2339 mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
2340 } else if ((hw->phy.media_type == txgbe_media_type_backplane) &&
2341 (hw->phy.smart_speed == txgbe_smart_speed_auto ||
2342 hw->phy.smart_speed == txgbe_smart_speed_on) &&
2343 !txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2344 mac->setup_link = txgbe_setup_mac_link_smartspeed;
2346 mac->setup_link = txgbe_setup_mac_link;
2351 * txgbe_init_phy_raptor - PHY/SFP specific init
2352 * @hw: pointer to hardware structure
2354 * Initialize any function pointers that were not able to be
2355 * set during init_shared_code because the PHY/SFP type was
2356 * not known. Perform the SFP init if necessary.
2359 s32 txgbe_init_phy_raptor(struct txgbe_hw *hw)
2361 struct txgbe_mac_info *mac = &hw->mac;
2362 struct txgbe_phy_info *phy = &hw->phy;
2365 DEBUGFUNC("txgbe_init_phy_raptor");
2367 if (hw->device_id == TXGBE_DEV_ID_RAPTOR_QSFP) {
2368 /* Store flag indicating I2C bus access control unit. */
2369 hw->phy.qsfp_shared_i2c_bus = TRUE;
2371 /* Initialize access to QSFP+ I2C bus */
2375 /* Identify the PHY or SFP module */
2376 err = phy->identify(hw);
2377 if (err == TXGBE_ERR_SFP_NOT_SUPPORTED)
2378 goto init_phy_ops_out;
2380 /* Setup function pointers based on detected SFP module and speeds */
2381 txgbe_init_mac_link_ops(hw);
2383 /* If copper media, overwrite with copper function pointers */
2384 if (phy->media_type == txgbe_media_type_copper) {
2385 mac->setup_link = txgbe_setup_copper_link_raptor;
2386 mac->get_link_capabilities =
2387 txgbe_get_copper_link_capabilities;
2390 /* Set necessary function pointers based on PHY type */
2391 switch (hw->phy.type) {
2393 phy->setup_link = txgbe_setup_phy_link_tnx;
2394 phy->check_link = txgbe_check_phy_link_tnx;
2404 s32 txgbe_setup_sfp_modules(struct txgbe_hw *hw)
2408 DEBUGFUNC("txgbe_setup_sfp_modules");
2410 if (hw->phy.sfp_type == txgbe_sfp_type_unknown)
2413 txgbe_init_mac_link_ops(hw);
2415 /* PHY config will finish before releasing the semaphore */
2416 err = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2418 return TXGBE_ERR_SWFW_SYNC;
2420 /* Release the semaphore */
2421 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2423 /* Delay obtaining semaphore again to allow FW access
2424 * prot_autoc_write uses the semaphore too.
2426 msec_delay(hw->rom.semaphore_delay);
2429 DEBUGOUT("sfp module setup not complete\n");
2430 return TXGBE_ERR_SFP_SETUP_NOT_COMPLETE;
2437 * txgbe_prot_autoc_read_raptor - Hides MAC differences needed for AUTOC read
2438 * @hw: pointer to hardware structure
2439 * @locked: Return the if we locked for this read.
2440 * @value: Value we read from AUTOC
2442 * For this part we need to wrap read-modify-writes with a possible
2443 * FW/SW lock. It is assumed this lock will be freed with the next
2444 * prot_autoc_write_raptor().
2446 s32 txgbe_prot_autoc_read_raptor(struct txgbe_hw *hw, bool *locked, u64 *value)
2449 bool lock_state = false;
2451 /* If LESM is on then we need to hold the SW/FW semaphore. */
2452 if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2453 err = hw->mac.acquire_swfw_sync(hw,
2454 TXGBE_MNGSEM_SWPHY);
2456 return TXGBE_ERR_SWFW_SYNC;
2462 *locked = lock_state;
2464 *value = txgbe_autoc_read(hw);
2469 * txgbe_prot_autoc_write_raptor - Hides MAC differences needed for AUTOC write
2470 * @hw: pointer to hardware structure
2471 * @autoc: value to write to AUTOC
2472 * @locked: bool to indicate whether the SW/FW lock was already taken by
2473 * previous prot_autoc_read_raptor.
2475 * This part may need to hold the SW/FW lock around all writes to
2476 * AUTOC. Likewise after a write we need to do a pipeline reset.
2478 s32 txgbe_prot_autoc_write_raptor(struct txgbe_hw *hw, bool locked, u64 autoc)
2482 /* Blocked by MNG FW so bail */
2483 if (txgbe_check_reset_blocked(hw))
2486 /* We only need to get the lock if:
2487 * - We didn't do it already (in the read part of a read-modify-write)
2488 * - LESM is enabled.
2490 if (!locked && txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2491 err = hw->mac.acquire_swfw_sync(hw,
2492 TXGBE_MNGSEM_SWPHY);
2494 return TXGBE_ERR_SWFW_SYNC;
2499 txgbe_autoc_write(hw, autoc);
2500 err = txgbe_reset_pipeline_raptor(hw);
2503 /* Free the SW/FW semaphore as we either grabbed it here or
2504 * already had it when this function was called.
2507 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2513 * txgbe_init_ops_pf - Inits func ptrs and MAC type
2514 * @hw: pointer to hardware structure
2516 * Initialize the function pointers and assign the MAC type.
2517 * Does not touch the hardware.
2519 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
2521 struct txgbe_bus_info *bus = &hw->bus;
2522 struct txgbe_mac_info *mac = &hw->mac;
2523 struct txgbe_phy_info *phy = &hw->phy;
2524 struct txgbe_rom_info *rom = &hw->rom;
2525 struct txgbe_mbx_info *mbx = &hw->mbx;
2527 DEBUGFUNC("txgbe_init_ops_pf");
2530 bus->set_lan_id = txgbe_set_lan_id_multi_port;
2533 phy->get_media_type = txgbe_get_media_type_raptor;
2534 phy->identify = txgbe_identify_phy;
2535 phy->init = txgbe_init_phy_raptor;
2536 phy->read_reg = txgbe_read_phy_reg;
2537 phy->write_reg = txgbe_write_phy_reg;
2538 phy->read_reg_mdi = txgbe_read_phy_reg_mdi;
2539 phy->write_reg_mdi = txgbe_write_phy_reg_mdi;
2540 phy->setup_link = txgbe_setup_phy_link;
2541 phy->setup_link_speed = txgbe_setup_phy_link_speed;
2542 phy->read_i2c_byte = txgbe_read_i2c_byte;
2543 phy->write_i2c_byte = txgbe_write_i2c_byte;
2544 phy->read_i2c_eeprom = txgbe_read_i2c_eeprom;
2545 phy->write_i2c_eeprom = txgbe_write_i2c_eeprom;
2546 phy->reset = txgbe_reset_phy;
2549 mac->init_hw = txgbe_init_hw;
2550 mac->start_hw = txgbe_start_hw_raptor;
2551 mac->clear_hw_cntrs = txgbe_clear_hw_cntrs;
2552 mac->enable_rx_dma = txgbe_enable_rx_dma_raptor;
2553 mac->get_mac_addr = txgbe_get_mac_addr;
2554 mac->stop_hw = txgbe_stop_hw;
2555 mac->acquire_swfw_sync = txgbe_acquire_swfw_sync;
2556 mac->release_swfw_sync = txgbe_release_swfw_sync;
2557 mac->reset_hw = txgbe_reset_hw;
2559 mac->disable_sec_rx_path = txgbe_disable_sec_rx_path;
2560 mac->enable_sec_rx_path = txgbe_enable_sec_rx_path;
2561 mac->disable_sec_tx_path = txgbe_disable_sec_tx_path;
2562 mac->enable_sec_tx_path = txgbe_enable_sec_tx_path;
2563 mac->get_san_mac_addr = txgbe_get_san_mac_addr;
2564 mac->set_san_mac_addr = txgbe_set_san_mac_addr;
2565 mac->get_device_caps = txgbe_get_device_caps;
2566 mac->get_wwn_prefix = txgbe_get_wwn_prefix;
2567 mac->autoc_read = txgbe_autoc_read;
2568 mac->autoc_write = txgbe_autoc_write;
2569 mac->prot_autoc_read = txgbe_prot_autoc_read_raptor;
2570 mac->prot_autoc_write = txgbe_prot_autoc_write_raptor;
2572 /* RAR, Multicast, VLAN */
2573 mac->set_rar = txgbe_set_rar;
2574 mac->clear_rar = txgbe_clear_rar;
2575 mac->init_rx_addrs = txgbe_init_rx_addrs;
2576 mac->enable_rx = txgbe_enable_rx;
2577 mac->disable_rx = txgbe_disable_rx;
2578 mac->set_vmdq = txgbe_set_vmdq;
2579 mac->clear_vmdq = txgbe_clear_vmdq;
2580 mac->set_vfta = txgbe_set_vfta;
2581 mac->set_vlvf = txgbe_set_vlvf;
2582 mac->clear_vfta = txgbe_clear_vfta;
2583 mac->init_uta_tables = txgbe_init_uta_tables;
2584 mac->setup_sfp = txgbe_setup_sfp_modules;
2585 mac->set_mac_anti_spoofing = txgbe_set_mac_anti_spoofing;
2586 mac->set_ethertype_anti_spoofing = txgbe_set_ethertype_anti_spoofing;
2589 mac->fc_enable = txgbe_fc_enable;
2590 mac->setup_fc = txgbe_setup_fc;
2593 mac->get_link_capabilities = txgbe_get_link_capabilities_raptor;
2594 mac->check_link = txgbe_check_mac_link;
2595 mac->setup_pba = txgbe_set_pba;
2597 /* Manageability interface */
2598 mac->set_fw_drv_ver = txgbe_hic_set_drv_ver;
2599 mac->get_thermal_sensor_data = txgbe_get_thermal_sensor_data;
2600 mac->init_thermal_sensor_thresh = txgbe_init_thermal_sensor_thresh;
2602 mbx->init_params = txgbe_init_mbx_params_pf;
2603 mbx->read = txgbe_read_mbx_pf;
2604 mbx->write = txgbe_write_mbx_pf;
2605 mbx->check_for_msg = txgbe_check_for_msg_pf;
2606 mbx->check_for_ack = txgbe_check_for_ack_pf;
2607 mbx->check_for_rst = txgbe_check_for_rst_pf;
2610 rom->init_params = txgbe_init_eeprom_params;
2611 rom->read16 = txgbe_ee_read16;
2612 rom->readw_buffer = txgbe_ee_readw_buffer;
2613 rom->readw_sw = txgbe_ee_readw_sw;
2614 rom->read32 = txgbe_ee_read32;
2615 rom->write16 = txgbe_ee_write16;
2616 rom->writew_buffer = txgbe_ee_writew_buffer;
2617 rom->writew_sw = txgbe_ee_writew_sw;
2618 rom->write32 = txgbe_ee_write32;
2619 rom->validate_checksum = txgbe_validate_eeprom_checksum;
2620 rom->update_checksum = txgbe_update_eeprom_checksum;
2621 rom->calc_checksum = txgbe_calc_eeprom_checksum;
2623 mac->mcft_size = TXGBE_RAPTOR_MC_TBL_SIZE;
2624 mac->vft_size = TXGBE_RAPTOR_VFT_TBL_SIZE;
2625 mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;
2626 mac->rx_pb_size = TXGBE_RAPTOR_RX_PB_SIZE;
2627 mac->max_rx_queues = TXGBE_RAPTOR_MAX_RX_QUEUES;
2628 mac->max_tx_queues = TXGBE_RAPTOR_MAX_TX_QUEUES;
2634 * txgbe_get_link_capabilities_raptor - Determines link capabilities
2635 * @hw: pointer to hardware structure
2636 * @speed: pointer to link speed
2637 * @autoneg: true when autoneg or autotry is enabled
2639 * Determines the link capabilities by reading the AUTOC register.
2641 s32 txgbe_get_link_capabilities_raptor(struct txgbe_hw *hw,
2648 DEBUGFUNC("txgbe_get_link_capabilities_raptor");
2650 /* Check if 1G SFP module. */
2651 if (hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
2652 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
2653 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
2654 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
2655 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
2656 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1) {
2657 *speed = TXGBE_LINK_SPEED_1GB_FULL;
2663 * Determine link capabilities based on the stored value of AUTOC,
2664 * which represents EEPROM defaults. If AUTOC value has not
2665 * been stored, use the current register values.
2667 if (hw->mac.orig_link_settings_stored)
2668 autoc = hw->mac.orig_autoc;
2670 autoc = hw->mac.autoc_read(hw);
2672 switch (autoc & TXGBE_AUTOC_LMS_MASK) {
2673 case TXGBE_AUTOC_LMS_1G_LINK_NO_AN:
2674 *speed = TXGBE_LINK_SPEED_1GB_FULL;
2678 case TXGBE_AUTOC_LMS_10G_LINK_NO_AN:
2679 *speed = TXGBE_LINK_SPEED_10GB_FULL;
2683 case TXGBE_AUTOC_LMS_1G_AN:
2684 *speed = TXGBE_LINK_SPEED_1GB_FULL;
2688 case TXGBE_AUTOC_LMS_10G:
2689 *speed = TXGBE_LINK_SPEED_10GB_FULL;
2693 case TXGBE_AUTOC_LMS_KX4_KX_KR:
2694 case TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
2695 *speed = TXGBE_LINK_SPEED_UNKNOWN;
2696 if (autoc & TXGBE_AUTOC_KR_SUPP)
2697 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2698 if (autoc & TXGBE_AUTOC_KX4_SUPP)
2699 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2700 if (autoc & TXGBE_AUTOC_KX_SUPP)
2701 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
2705 case TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
2706 *speed = TXGBE_LINK_SPEED_100M_FULL;
2707 if (autoc & TXGBE_AUTOC_KR_SUPP)
2708 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2709 if (autoc & TXGBE_AUTOC_KX4_SUPP)
2710 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
2711 if (autoc & TXGBE_AUTOC_KX_SUPP)
2712 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
2716 case TXGBE_AUTOC_LMS_SGMII_1G_100M:
2717 *speed = TXGBE_LINK_SPEED_1GB_FULL |
2718 TXGBE_LINK_SPEED_100M_FULL |
2719 TXGBE_LINK_SPEED_10M_FULL;
2724 return TXGBE_ERR_LINK_SETUP;
2727 if (hw->phy.multispeed_fiber) {
2728 *speed |= TXGBE_LINK_SPEED_10GB_FULL |
2729 TXGBE_LINK_SPEED_1GB_FULL;
2731 /* QSFP must not enable full auto-negotiation
2732 * Limited autoneg is enabled at 1G
2734 if (hw->phy.media_type == txgbe_media_type_fiber_qsfp)
2744 * txgbe_get_media_type_raptor - Get media type
2745 * @hw: pointer to hardware structure
2747 * Returns the media type (fiber, copper, backplane)
2749 u32 txgbe_get_media_type_raptor(struct txgbe_hw *hw)
2753 DEBUGFUNC("txgbe_get_media_type_raptor");
2755 /* Detect if there is a copper PHY attached. */
2756 switch (hw->phy.type) {
2757 case txgbe_phy_cu_unknown:
2759 media_type = txgbe_media_type_copper;
2765 switch (hw->device_id) {
2766 case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
2767 /* Default device ID is mezzanine card KX/KX4 */
2768 media_type = txgbe_media_type_backplane;
2770 case TXGBE_DEV_ID_RAPTOR_SFP:
2771 case TXGBE_DEV_ID_WX1820_SFP:
2772 media_type = txgbe_media_type_fiber;
2774 case TXGBE_DEV_ID_RAPTOR_QSFP:
2775 media_type = txgbe_media_type_fiber_qsfp;
2777 case TXGBE_DEV_ID_RAPTOR_XAUI:
2778 case TXGBE_DEV_ID_RAPTOR_SGMII:
2779 media_type = txgbe_media_type_copper;
2782 media_type = txgbe_media_type_unknown;
2790 * txgbe_start_mac_link_raptor - Setup MAC link settings
2791 * @hw: pointer to hardware structure
2792 * @autoneg_wait_to_complete: true when waiting for completion is needed
2794 * Configures link settings based on values in the txgbe_hw struct.
2795 * Restarts the link. Performs autonegotiation if needed.
2797 s32 txgbe_start_mac_link_raptor(struct txgbe_hw *hw,
2798 bool autoneg_wait_to_complete)
2801 bool got_lock = false;
2803 DEBUGFUNC("txgbe_start_mac_link_raptor");
2805 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
2807 /* reset_pipeline requires us to hold this lock as it writes to
2810 if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
2811 status = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2819 txgbe_reset_pipeline_raptor(hw);
2822 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
2824 /* Add delay to filter out noises during initial link setup */
2832 * txgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
2833 * @hw: pointer to hardware structure
2835 * The base drivers may require better control over SFP+ module
2836 * PHY states. This includes selectively shutting down the Tx
2837 * laser on the PHY, effectively halting physical link.
2839 void txgbe_disable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
2841 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
2843 /* Blocked by MNG FW so bail */
2844 if (txgbe_check_reset_blocked(hw))
2847 /* Disable Tx laser; allow 100us to go dark per spec */
2848 esdp_reg |= (TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
2849 wr32(hw, TXGBE_GPIODATA, esdp_reg);
2855 * txgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
2856 * @hw: pointer to hardware structure
2858 * The base drivers may require better control over SFP+ module
2859 * PHY states. This includes selectively turning on the Tx
2860 * laser on the PHY, effectively starting physical link.
2862 void txgbe_enable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
2864 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
2866 /* Enable Tx laser; allow 100ms to light up */
2867 esdp_reg &= ~(TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
2868 wr32(hw, TXGBE_GPIODATA, esdp_reg);
2874 * txgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
2875 * @hw: pointer to hardware structure
2877 * When the driver changes the link speeds that it can support,
2878 * it sets autotry_restart to true to indicate that we need to
2879 * initiate a new autotry session with the link partner. To do
2880 * so, we set the speed then disable and re-enable the Tx laser, to
2881 * alert the link partner that it also needs to restart autotry on its
2882 * end. This is consistent with true clause 37 autoneg, which also
2883 * involves a loss of signal.
2885 void txgbe_flap_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
2887 DEBUGFUNC("txgbe_flap_tx_laser_multispeed_fiber");
2889 /* Blocked by MNG FW so bail */
2890 if (txgbe_check_reset_blocked(hw))
2893 if (hw->mac.autotry_restart) {
2894 txgbe_disable_tx_laser_multispeed_fiber(hw);
2895 txgbe_enable_tx_laser_multispeed_fiber(hw);
2896 hw->mac.autotry_restart = false;
2901 * txgbe_set_hard_rate_select_speed - Set module link speed
2902 * @hw: pointer to hardware structure
2903 * @speed: link speed to set
2905 * Set module link speed via RS0/RS1 rate select pins.
2907 void txgbe_set_hard_rate_select_speed(struct txgbe_hw *hw,
2910 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
2913 case TXGBE_LINK_SPEED_10GB_FULL:
2914 esdp_reg |= (TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
2916 case TXGBE_LINK_SPEED_1GB_FULL:
2917 esdp_reg &= ~(TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
2920 DEBUGOUT("Invalid fixed module speed\n");
2924 wr32(hw, TXGBE_GPIODATA, esdp_reg);
2929 * txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
2930 * @hw: pointer to hardware structure
2931 * @speed: new link speed
2932 * @autoneg_wait_to_complete: true when waiting for completion is needed
2934 * Implements the Intel SmartSpeed algorithm.
2936 s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
2938 bool autoneg_wait_to_complete)
2941 u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
2943 bool link_up = false;
2944 u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
2946 DEBUGFUNC("txgbe_setup_mac_link_smartspeed");
2948 /* Set autoneg_advertised value based on input link speed */
2949 hw->phy.autoneg_advertised = 0;
2951 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
2952 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
2954 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
2955 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
2957 if (speed & TXGBE_LINK_SPEED_100M_FULL)
2958 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
2961 * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
2962 * autoneg advertisement if link is unable to be established at the
2963 * highest negotiated rate. This can sometimes happen due to integrity
2964 * issues with the physical media connection.
2967 /* First, try to get link with full advertisement */
2968 hw->phy.smart_speed_active = false;
2969 for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
2970 status = txgbe_setup_mac_link(hw, speed,
2971 autoneg_wait_to_complete);
2976 * Wait for the controller to acquire link. Per IEEE 802.3ap,
2977 * Section 73.10.2, we may have to wait up to 500ms if KR is
2978 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
2979 * Table 9 in the AN MAS.
2981 for (i = 0; i < 5; i++) {
2984 /* If we have link, just jump out */
2985 status = hw->mac.check_link(hw, &link_speed, &link_up,
2996 * We didn't get link. If we advertised KR plus one of KX4/KX
2997 * (or BX4/BX), then disable KR and try again.
2999 if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
3000 ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
3001 (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
3004 /* Turn SmartSpeed on to disable KR support */
3005 hw->phy.smart_speed_active = true;
3006 status = txgbe_setup_mac_link(hw, speed,
3007 autoneg_wait_to_complete);
3012 * Wait for the controller to acquire link. 600ms will allow for
3013 * the AN link_fail_inhibit_timer as well for multiple cycles of
3014 * parallel detect, both 10g and 1g. This allows for the maximum
3015 * connect attempts as defined in the AN MAS table 73-7.
3017 for (i = 0; i < 6; i++) {
3020 /* If we have link, just jump out */
3021 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
3029 /* We didn't get link. Turn SmartSpeed back off. */
3030 hw->phy.smart_speed_active = false;
3031 status = txgbe_setup_mac_link(hw, speed,
3032 autoneg_wait_to_complete);
3035 if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
3036 DEBUGOUT("Smartspeed has downgraded the link speed "
3037 "from the maximum advertised\n");
3042 * txgbe_setup_mac_link - Set MAC link speed
3043 * @hw: pointer to hardware structure
3044 * @speed: new link speed
3045 * @autoneg_wait_to_complete: true when waiting for completion is needed
3047 * Set the link speed in the AUTOC register and restarts link.
3049 s32 txgbe_setup_mac_link(struct txgbe_hw *hw,
3051 bool autoneg_wait_to_complete)
3053 bool autoneg = false;
3056 u64 autoc = hw->mac.autoc_read(hw);
3057 u64 pma_pmd_10gs = autoc & TXGBE_AUTOC_10GS_PMA_PMD_MASK;
3058 u64 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
3059 u64 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
3060 u64 current_autoc = autoc;
3064 u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
3066 DEBUGFUNC("txgbe_setup_mac_link");
3068 /* Check to see if speed passed in is supported. */
3069 status = hw->mac.get_link_capabilities(hw,
3070 &link_capabilities, &autoneg);
3074 speed &= link_capabilities;
3075 if (speed == TXGBE_LINK_SPEED_UNKNOWN)
3076 return TXGBE_ERR_LINK_SETUP;
3078 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
3079 if (hw->mac.orig_link_settings_stored)
3080 orig_autoc = hw->mac.orig_autoc;
3084 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
3085 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
3087 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
3088 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
3089 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
3090 /* Set KX4/KX/KR support according to speed requested */
3091 autoc &= ~(TXGBE_AUTOC_KX_SUPP |
3092 TXGBE_AUTOC_KX4_SUPP |
3093 TXGBE_AUTOC_KR_SUPP);
3094 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
3095 if (orig_autoc & TXGBE_AUTOC_KX4_SUPP)
3096 autoc |= TXGBE_AUTOC_KX4_SUPP;
3097 if ((orig_autoc & TXGBE_AUTOC_KR_SUPP) &&
3098 !hw->phy.smart_speed_active)
3099 autoc |= TXGBE_AUTOC_KR_SUPP;
3101 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
3102 autoc |= TXGBE_AUTOC_KX_SUPP;
3103 } else if ((pma_pmd_1g == TXGBE_AUTOC_1G_SFI) &&
3104 (link_mode == TXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
3105 link_mode == TXGBE_AUTOC_LMS_1G_AN)) {
3106 /* Switch from 1G SFI to 10G SFI if requested */
3107 if (speed == TXGBE_LINK_SPEED_10GB_FULL &&
3108 pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) {
3109 autoc &= ~TXGBE_AUTOC_LMS_MASK;
3110 autoc |= TXGBE_AUTOC_LMS_10G;
3112 } else if ((pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) &&
3113 (link_mode == TXGBE_AUTOC_LMS_10G)) {
3114 /* Switch from 10G SFI to 1G SFI if requested */
3115 if (speed == TXGBE_LINK_SPEED_1GB_FULL &&
3116 pma_pmd_1g == TXGBE_AUTOC_1G_SFI) {
3117 autoc &= ~TXGBE_AUTOC_LMS_MASK;
3118 if (autoneg || hw->phy.type == txgbe_phy_qsfp_intel)
3119 autoc |= TXGBE_AUTOC_LMS_1G_AN;
3121 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
3125 if (autoc == current_autoc)
3128 autoc &= ~TXGBE_AUTOC_SPEED_MASK;
3129 autoc |= TXGBE_AUTOC_SPEED(speed);
3130 autoc |= (autoneg ? TXGBE_AUTOC_AUTONEG : 0);
3133 hw->mac.autoc_write(hw, autoc);
3135 /* Only poll for autoneg to complete if specified to do so */
3136 if (autoneg_wait_to_complete) {
3137 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
3138 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
3139 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
3140 links_reg = 0; /*Just in case Autoneg time=0*/
3141 for (i = 0; i < TXGBE_AUTO_NEG_TIME; i++) {
3142 links_reg = rd32(hw, TXGBE_PORTSTAT);
3143 if (links_reg & TXGBE_PORTSTAT_UP)
3147 if (!(links_reg & TXGBE_PORTSTAT_UP)) {
3148 status = TXGBE_ERR_AUTONEG_NOT_COMPLETE;
3149 DEBUGOUT("Autoneg did not complete.\n");
3154 /* Add delay to filter out noises during initial link setup */
3161 * txgbe_setup_copper_link_raptor - Set the PHY autoneg advertised field
3162 * @hw: pointer to hardware structure
3163 * @speed: new link speed
3164 * @autoneg_wait_to_complete: true if waiting is needed to complete
3166 * Restarts link on PHY and MAC based on settings passed in.
3168 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
3170 bool autoneg_wait_to_complete)
3174 DEBUGFUNC("txgbe_setup_copper_link_raptor");
3176 /* Setup the PHY according to input speed */
3177 status = hw->phy.setup_link_speed(hw, speed,
3178 autoneg_wait_to_complete);
3180 txgbe_start_mac_link_raptor(hw, autoneg_wait_to_complete);
3186 txgbe_check_flash_load(struct txgbe_hw *hw, u32 check_bit)
3191 /* if there's flash existing */
3192 if (!(rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_BPFLASH)) {
3193 /* wait hw load flash done */
3194 for (i = 0; i < 10; i++) {
3195 reg = rd32(hw, TXGBE_ILDRSTAT);
3196 if (!(reg & check_bit)) {
3203 err = TXGBE_ERR_FLASH_LOADING_FAILED;
3209 txgbe_reset_misc(struct txgbe_hw *hw)
3214 wr32(hw, TXGBE_ISBADDRL, hw->isb_dma & 0x00000000FFFFFFFF);
3215 wr32(hw, TXGBE_ISBADDRH, hw->isb_dma >> 32);
3217 value = rd32_epcs(hw, SR_XS_PCS_CTRL2);
3218 if ((value & 0x3) != SR_PCS_CTRL2_TYPE_SEL_X)
3219 hw->link_status = TXGBE_LINK_STATUS_NONE;
3221 /* receive packets that size > 2048 */
3222 wr32m(hw, TXGBE_MACRXCFG,
3223 TXGBE_MACRXCFG_JUMBO, TXGBE_MACRXCFG_JUMBO);
3225 wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
3226 TXGBE_FRMSZ_MAX(TXGBE_FRAME_SIZE_DFT));
3228 /* clear counters on read */
3229 wr32m(hw, TXGBE_MACCNTCTL,
3230 TXGBE_MACCNTCTL_RC, TXGBE_MACCNTCTL_RC);
3232 wr32m(hw, TXGBE_RXFCCFG,
3233 TXGBE_RXFCCFG_FC, TXGBE_RXFCCFG_FC);
3234 wr32m(hw, TXGBE_TXFCCFG,
3235 TXGBE_TXFCCFG_FC, TXGBE_TXFCCFG_FC);
3237 wr32m(hw, TXGBE_MACRXFLT,
3238 TXGBE_MACRXFLT_PROMISC, TXGBE_MACRXFLT_PROMISC);
3240 wr32m(hw, TXGBE_RSTSTAT,
3241 TXGBE_RSTSTAT_TMRINIT_MASK, TXGBE_RSTSTAT_TMRINIT(30));
3243 /* errata 4: initialize mng flex tbl and wakeup flex tbl*/
3244 wr32(hw, TXGBE_MNGFLEXSEL, 0);
3245 for (i = 0; i < 16; i++) {
3246 wr32(hw, TXGBE_MNGFLEXDWL(i), 0);
3247 wr32(hw, TXGBE_MNGFLEXDWH(i), 0);
3248 wr32(hw, TXGBE_MNGFLEXMSK(i), 0);
3250 wr32(hw, TXGBE_LANFLEXSEL, 0);
3251 for (i = 0; i < 16; i++) {
3252 wr32(hw, TXGBE_LANFLEXDWL(i), 0);
3253 wr32(hw, TXGBE_LANFLEXDWH(i), 0);
3254 wr32(hw, TXGBE_LANFLEXMSK(i), 0);
3257 /* set pause frame dst mac addr */
3258 wr32(hw, TXGBE_RXPBPFCDMACL, 0xC2000001);
3259 wr32(hw, TXGBE_RXPBPFCDMACH, 0x0180);
3261 hw->mac.init_thermal_sensor_thresh(hw);
3263 /* enable mac transmitter */
3264 wr32m(hw, TXGBE_MACTXCFG, TXGBE_MACTXCFG_TXE, TXGBE_MACTXCFG_TXE);
3266 for (i = 0; i < 4; i++)
3267 wr32m(hw, TXGBE_IVAR(i), 0x80808080, 0);
3271 * txgbe_reset_hw - Perform hardware reset
3272 * @hw: pointer to hardware structure
3274 * Resets the hardware by resetting the transmit and receive units, masks
3275 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
3278 s32 txgbe_reset_hw(struct txgbe_hw *hw)
3283 DEBUGFUNC("txgbe_reset_hw");
3285 /* Call adapter stop to disable tx/rx and clear interrupts */
3286 status = hw->mac.stop_hw(hw);
3290 /* flush pending Tx transactions */
3291 txgbe_clear_tx_pending(hw);
3293 /* Identify PHY and related function pointers */
3294 status = hw->phy.init(hw);
3295 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
3298 /* Setup SFP module if there is one present. */
3299 if (hw->phy.sfp_setup_needed) {
3300 status = hw->mac.setup_sfp(hw);
3301 hw->phy.sfp_setup_needed = false;
3303 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
3307 if (!hw->phy.reset_disable)
3310 /* remember AUTOC from before we reset */
3311 autoc = hw->mac.autoc_read(hw);
3315 * Issue global reset to the MAC. Needs to be SW reset if link is up.
3316 * If link reset is used when link is up, it might reset the PHY when
3317 * mng is using it. If link is down or the flag to force full link
3318 * reset is set, then perform link reset.
3320 if (txgbe_mng_present(hw)) {
3321 txgbe_hic_reset(hw);
3323 wr32(hw, TXGBE_RST, TXGBE_RST_LAN(hw->bus.lan_id));
3328 txgbe_reset_misc(hw);
3330 if (hw->bus.lan_id == 0) {
3331 status = txgbe_check_flash_load(hw,
3332 TXGBE_ILDRSTAT_SWRST_LAN0);
3334 status = txgbe_check_flash_load(hw,
3335 TXGBE_ILDRSTAT_SWRST_LAN1);
3343 * Double resets are required for recovery from certain error
3344 * conditions. Between resets, it is necessary to stall to
3345 * allow time for any pending HW events to complete.
3347 if (hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
3348 hw->mac.flags &= ~TXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
3353 * Store the original AUTOC/AUTOC2 values if they have not been
3354 * stored off yet. Otherwise restore the stored original
3355 * values since the reset operation sets back to defaults.
3357 if (!hw->mac.orig_link_settings_stored) {
3358 hw->mac.orig_autoc = hw->mac.autoc_read(hw);
3359 hw->mac.autoc_write(hw, hw->mac.orig_autoc);
3360 hw->mac.orig_link_settings_stored = true;
3362 hw->mac.orig_autoc = autoc;
3365 /* Store the permanent mac address */
3366 hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
3369 * Store MAC address from RAR0, clear receive address registers, and
3370 * clear the multicast table. Also reset num_rar_entries to 128,
3371 * since we modify this value when programming the SAN MAC address.
3373 hw->mac.num_rar_entries = 128;
3374 hw->mac.init_rx_addrs(hw);
3376 /* Store the permanent SAN mac address */
3377 hw->mac.get_san_mac_addr(hw, hw->mac.san_addr);
3379 /* Add the SAN MAC address to the RAR only if it's a valid address */
3380 if (txgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
3381 /* Save the SAN MAC RAR index */
3382 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
3384 hw->mac.set_rar(hw, hw->mac.san_mac_rar_index,
3385 hw->mac.san_addr, 0, true);
3387 /* clear VMDq pool/queue selection for this RAR */
3388 hw->mac.clear_vmdq(hw, hw->mac.san_mac_rar_index,
3391 /* Reserve the last RAR for the SAN MAC address */
3392 hw->mac.num_rar_entries--;
3395 /* Store the alternative WWNN/WWPN prefix */
3396 hw->mac.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
3397 &hw->mac.wwpn_prefix);
3403 * txgbe_start_hw_raptor - Prepare hardware for Tx/Rx
3404 * @hw: pointer to hardware structure
3406 * Starts the hardware using the generic start_hw function
3407 * and the generation start_hw function.
3408 * Then performs revision-specific operations, if any.
3410 s32 txgbe_start_hw_raptor(struct txgbe_hw *hw)
3414 DEBUGFUNC("txgbe_start_hw_raptor");
3416 err = txgbe_start_hw(hw);
3420 err = txgbe_start_hw_gen2(hw);
3424 /* We need to run link autotry after the driver loads */
3425 hw->mac.autotry_restart = true;
3432 * txgbe_enable_rx_dma_raptor - Enable the Rx DMA unit
3433 * @hw: pointer to hardware structure
3434 * @regval: register value to write to RXCTRL
3436 * Enables the Rx DMA unit
3438 s32 txgbe_enable_rx_dma_raptor(struct txgbe_hw *hw, u32 regval)
3440 DEBUGFUNC("txgbe_enable_rx_dma_raptor");
3443 * Workaround silicon errata when enabling the Rx datapath.
3444 * If traffic is incoming before we enable the Rx unit, it could hang
3445 * the Rx DMA unit. Therefore, make sure the security engine is
3446 * completely disabled prior to enabling the Rx unit.
3449 hw->mac.disable_sec_rx_path(hw);
3451 if (regval & TXGBE_PBRXCTL_ENA)
3452 txgbe_enable_rx(hw);
3454 txgbe_disable_rx(hw);
3456 hw->mac.enable_sec_rx_path(hw);
3462 * txgbe_verify_lesm_fw_enabled_raptor - Checks LESM FW module state.
3463 * @hw: pointer to hardware structure
3465 * Returns true if the LESM FW module is present and enabled. Otherwise
3466 * returns false. Smart Speed must be disabled if LESM FW module is enabled.
3468 bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw)
3470 bool lesm_enabled = false;
3471 u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
3474 DEBUGFUNC("txgbe_verify_lesm_fw_enabled_raptor");
3476 /* get the offset to the Firmware Module block */
3477 status = hw->rom.read16(hw, TXGBE_FW_PTR, &fw_offset);
3479 if (status != 0 || fw_offset == 0 || fw_offset == 0xFFFF)
3482 /* get the offset to the LESM Parameters block */
3483 status = hw->rom.read16(hw, (fw_offset +
3484 TXGBE_FW_LESM_PARAMETERS_PTR),
3485 &fw_lesm_param_offset);
3488 fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
3491 /* get the LESM state word */
3492 status = hw->rom.read16(hw, (fw_lesm_param_offset +
3493 TXGBE_FW_LESM_STATE_1),
3496 if (status == 0 && (fw_lesm_state & TXGBE_FW_LESM_STATE_ENABLED))
3497 lesm_enabled = true;
3500 lesm_enabled = false;
3501 return lesm_enabled;
3505 * txgbe_reset_pipeline_raptor - perform pipeline reset
3507 * @hw: pointer to hardware structure
3509 * Reset pipeline by asserting Restart_AN together with LMS change to ensure
3510 * full pipeline reset. This function assumes the SW/FW lock is held.
3512 s32 txgbe_reset_pipeline_raptor(struct txgbe_hw *hw)
3517 autoc = hw->mac.autoc_read(hw);
3519 /* Enable link if disabled in NVM */
3520 if (autoc & TXGBE_AUTOC_LINK_DIA_MASK)
3521 autoc &= ~TXGBE_AUTOC_LINK_DIA_MASK;
3523 autoc |= TXGBE_AUTOC_AN_RESTART;
3524 /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
3525 hw->mac.autoc_write(hw, autoc ^ TXGBE_AUTOC_LMS_AN);
3527 /* Write AUTOC register with original LMS field and Restart_AN */
3528 hw->mac.autoc_write(hw, autoc);