1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020
5 #include "txgbe_type.h"
7 #include "txgbe_eeprom.h"
11 #define TXGBE_RAPTOR_MAX_TX_QUEUES 128
12 #define TXGBE_RAPTOR_MAX_RX_QUEUES 128
13 #define TXGBE_RAPTOR_RAR_ENTRIES 128
15 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
17 bool autoneg_wait_to_complete);
20 * txgbe_init_hw - Generic hardware initialization
21 * @hw: pointer to hardware structure
23 * Initialize the hardware by resetting the hardware, filling the bus info
24 * structure and media type, clears all on chip counters, initializes receive
25 * address registers, multicast table, VLAN filter table, calls routine to set
26 * up link and flow control settings, and leaves transmit and receive units
27 * disabled and uninitialized
29 s32 txgbe_init_hw(struct txgbe_hw *hw)
33 DEBUGFUNC("txgbe_init_hw");
35 /* Reset the hardware */
36 status = hw->mac.reset_hw(hw);
37 if (status == 0 || status == TXGBE_ERR_SFP_NOT_PRESENT) {
39 status = hw->mac.start_hw(hw);
43 DEBUGOUT("Failed to initialize HW, STATUS = %d\n", status);
50 * txgbe_set_lan_id_multi_port - Set LAN id for PCIe multiple port devices
51 * @hw: pointer to the HW structure
53 * Determines the LAN function id by reading memory-mapped registers and swaps
54 * the port value if requested, and set MAC instance for devices.
56 void txgbe_set_lan_id_multi_port(struct txgbe_hw *hw)
58 struct txgbe_bus_info *bus = &hw->bus;
61 DEBUGFUNC("txgbe_set_lan_id_multi_port_pcie");
63 reg = rd32(hw, TXGBE_PORTSTAT);
64 bus->lan_id = TXGBE_PORTSTAT_ID(reg);
66 /* check for single port */
67 reg = rd32(hw, TXGBE_PWR);
68 if (TXGBE_PWR_LANID(reg) == TXGBE_PWR_LANID_SWAP)
71 bus->func = bus->lan_id;
75 * txgbe_validate_mac_addr - Validate MAC address
76 * @mac_addr: pointer to MAC address.
78 * Tests a MAC address to ensure it is a valid Individual Address.
80 s32 txgbe_validate_mac_addr(u8 *mac_addr)
84 DEBUGFUNC("txgbe_validate_mac_addr");
86 /* Make sure it is not a multicast address */
87 if (TXGBE_IS_MULTICAST(mac_addr)) {
88 status = TXGBE_ERR_INVALID_MAC_ADDR;
89 /* Not a broadcast address */
90 } else if (TXGBE_IS_BROADCAST(mac_addr)) {
91 status = TXGBE_ERR_INVALID_MAC_ADDR;
92 /* Reject the zero address */
93 } else if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
94 mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) {
95 status = TXGBE_ERR_INVALID_MAC_ADDR;
101 * txgbe_need_crosstalk_fix - Determine if we need to do cross talk fix
102 * @hw: pointer to hardware structure
104 * Contains the logic to identify if we need to verify link for the
107 static bool txgbe_need_crosstalk_fix(struct txgbe_hw *hw)
109 /* Does FW say we need the fix */
110 if (!hw->need_crosstalk_fix)
113 /* Only consider SFP+ PHYs i.e. media type fiber */
114 switch (hw->phy.media_type) {
115 case txgbe_media_type_fiber:
116 case txgbe_media_type_fiber_qsfp:
126 * txgbe_check_mac_link - Determine link and speed status
127 * @hw: pointer to hardware structure
128 * @speed: pointer to link speed
129 * @link_up: true when link is up
130 * @link_up_wait_to_complete: bool used to wait for link up or not
132 * Reads the links register to determine if link is up and the current speed
134 s32 txgbe_check_mac_link(struct txgbe_hw *hw, u32 *speed,
135 bool *link_up, bool link_up_wait_to_complete)
137 u32 links_reg, links_orig;
140 DEBUGFUNC("txgbe_check_mac_link");
142 /* If Crosstalk fix enabled do the sanity check of making sure
143 * the SFP+ cage is full.
145 if (txgbe_need_crosstalk_fix(hw)) {
148 switch (hw->mac.type) {
149 case txgbe_mac_raptor:
150 sfp_cage_full = !rd32m(hw, TXGBE_GPIODATA,
154 /* sanity check - No SFP+ devices here */
155 sfp_cage_full = false;
159 if (!sfp_cage_full) {
161 *speed = TXGBE_LINK_SPEED_UNKNOWN;
166 /* clear the old state */
167 links_orig = rd32(hw, TXGBE_PORTSTAT);
169 links_reg = rd32(hw, TXGBE_PORTSTAT);
171 if (links_orig != links_reg) {
172 DEBUGOUT("LINKS changed from %08X to %08X\n",
173 links_orig, links_reg);
176 if (link_up_wait_to_complete) {
177 for (i = 0; i < hw->mac.max_link_up_time; i++) {
178 if (!(links_reg & TXGBE_PORTSTAT_UP)) {
185 links_reg = rd32(hw, TXGBE_PORTSTAT);
188 if (links_reg & TXGBE_PORTSTAT_UP)
194 switch (links_reg & TXGBE_PORTSTAT_BW_MASK) {
195 case TXGBE_PORTSTAT_BW_10G:
196 *speed = TXGBE_LINK_SPEED_10GB_FULL;
198 case TXGBE_PORTSTAT_BW_1G:
199 *speed = TXGBE_LINK_SPEED_1GB_FULL;
201 case TXGBE_PORTSTAT_BW_100M:
202 *speed = TXGBE_LINK_SPEED_100M_FULL;
205 *speed = TXGBE_LINK_SPEED_UNKNOWN;
212 * txgbe_clear_tx_pending - Clear pending TX work from the PCIe fifo
213 * @hw: pointer to the hardware structure
215 * The MACs can experience issues if TX work is still pending
216 * when a reset occurs. This function prevents this by flushing the PCIe
217 * buffers on the system.
219 void txgbe_clear_tx_pending(struct txgbe_hw *hw)
224 * If double reset is not requested then all transactions should
225 * already be clear and as such there is no work to do
227 if (!(hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED))
230 hlreg0 = rd32(hw, TXGBE_PSRCTL);
231 wr32(hw, TXGBE_PSRCTL, hlreg0 | TXGBE_PSRCTL_LBENA);
233 /* Wait for a last completion before clearing buffers */
238 * Before proceeding, make sure that the PCIe block does not have
239 * transactions pending.
241 poll = (800 * 11) / 10;
242 for (i = 0; i < poll; i++)
245 /* Flush all writes and allow 20usec for all transactions to clear */
249 /* restore previous register values */
250 wr32(hw, TXGBE_PSRCTL, hlreg0);
254 * txgbe_setup_mac_link_multispeed_fiber - Set MAC link speed
255 * @hw: pointer to hardware structure
256 * @speed: new link speed
257 * @autoneg_wait_to_complete: true when waiting for completion is needed
259 * Set the link speed in the MAC and/or PHY register and restarts link.
261 s32 txgbe_setup_mac_link_multispeed_fiber(struct txgbe_hw *hw,
263 bool autoneg_wait_to_complete)
265 u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
266 u32 highest_link_speed = TXGBE_LINK_SPEED_UNKNOWN;
270 bool autoneg, link_up = false;
272 DEBUGFUNC("txgbe_setup_mac_link_multispeed_fiber");
274 /* Mask off requested but non-supported speeds */
275 status = hw->mac.get_link_capabilities(hw, &link_speed, &autoneg);
281 /* Try each speed one by one, highest priority first. We do this in
282 * software because 10Gb fiber doesn't support speed autonegotiation.
284 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
286 highest_link_speed = TXGBE_LINK_SPEED_10GB_FULL;
288 /* Set the module link speed */
289 switch (hw->phy.media_type) {
290 case txgbe_media_type_fiber:
291 hw->mac.set_rate_select_speed(hw,
292 TXGBE_LINK_SPEED_10GB_FULL);
294 case txgbe_media_type_fiber_qsfp:
295 /* QSFP module automatically detects MAC link speed */
298 DEBUGOUT("Unexpected media type.\n");
302 /* Allow module to change analog characteristics (1G->10G) */
305 status = hw->mac.setup_mac_link(hw,
306 TXGBE_LINK_SPEED_10GB_FULL,
307 autoneg_wait_to_complete);
311 /* Flap the Tx laser if it has not already been done */
312 hw->mac.flap_tx_laser(hw);
314 /* Wait for the controller to acquire link. Per IEEE 802.3ap,
315 * Section 73.10.2, we may have to wait up to 500ms if KR is
316 * attempted. uses the same timing for 10g SFI.
318 for (i = 0; i < 5; i++) {
319 /* Wait for the link partner to also set speed */
322 /* If we have link, just jump out */
323 status = hw->mac.check_link(hw, &link_speed,
333 if (speed & TXGBE_LINK_SPEED_1GB_FULL) {
335 if (highest_link_speed == TXGBE_LINK_SPEED_UNKNOWN)
336 highest_link_speed = TXGBE_LINK_SPEED_1GB_FULL;
338 /* Set the module link speed */
339 switch (hw->phy.media_type) {
340 case txgbe_media_type_fiber:
341 hw->mac.set_rate_select_speed(hw,
342 TXGBE_LINK_SPEED_1GB_FULL);
344 case txgbe_media_type_fiber_qsfp:
345 /* QSFP module automatically detects link speed */
348 DEBUGOUT("Unexpected media type.\n");
352 /* Allow module to change analog characteristics (10G->1G) */
355 status = hw->mac.setup_mac_link(hw,
356 TXGBE_LINK_SPEED_1GB_FULL,
357 autoneg_wait_to_complete);
361 /* Flap the Tx laser if it has not already been done */
362 hw->mac.flap_tx_laser(hw);
364 /* Wait for the link partner to also set speed */
367 /* If we have link, just jump out */
368 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
376 /* We didn't get link. Configure back to the highest speed we tried,
377 * (if there was more than one). We call ourselves back with just the
378 * single highest speed that the user requested.
381 status = txgbe_setup_mac_link_multispeed_fiber(hw,
383 autoneg_wait_to_complete);
386 /* Set autoneg_advertised value based on input link speed */
387 hw->phy.autoneg_advertised = 0;
389 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
390 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
392 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
393 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
399 * txgbe_init_shared_code - Initialize the shared code
400 * @hw: pointer to hardware structure
402 * This will assign function pointers and assign the MAC type and PHY code.
403 * Does not touch the hardware. This function must be called prior to any
404 * other function in the shared code. The txgbe_hw structure should be
405 * memset to 0 prior to calling this function. The following fields in
406 * hw structure should be filled in prior to calling this function:
407 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
408 * subsystem_vendor_id, and revision_id
410 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
414 DEBUGFUNC("txgbe_init_shared_code");
419 txgbe_set_mac_type(hw);
421 txgbe_init_ops_dummy(hw);
422 switch (hw->mac.type) {
423 case txgbe_mac_raptor:
424 status = txgbe_init_ops_pf(hw);
427 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
430 hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
432 hw->bus.set_lan_id(hw);
438 * txgbe_set_mac_type - Sets MAC type
439 * @hw: pointer to the HW structure
441 * This function sets the mac type of the adapter based on the
442 * vendor ID and device ID stored in the hw structure.
444 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
448 DEBUGFUNC("txgbe_set_mac_type");
450 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
451 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
452 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
455 switch (hw->device_id) {
456 case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
457 hw->phy.media_type = txgbe_media_type_backplane;
458 hw->mac.type = txgbe_mac_raptor;
460 case TXGBE_DEV_ID_RAPTOR_XAUI:
461 case TXGBE_DEV_ID_RAPTOR_SGMII:
462 hw->phy.media_type = txgbe_media_type_copper;
463 hw->mac.type = txgbe_mac_raptor;
465 case TXGBE_DEV_ID_RAPTOR_SFP:
466 case TXGBE_DEV_ID_WX1820_SFP:
467 hw->phy.media_type = txgbe_media_type_fiber;
468 hw->mac.type = txgbe_mac_raptor;
470 case TXGBE_DEV_ID_RAPTOR_QSFP:
471 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
472 hw->mac.type = txgbe_mac_raptor;
474 case TXGBE_DEV_ID_RAPTOR_VF:
475 case TXGBE_DEV_ID_RAPTOR_VF_HV:
476 hw->phy.media_type = txgbe_media_type_virtual;
477 hw->mac.type = txgbe_mac_raptor_vf;
480 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
481 DEBUGOUT("Unsupported device id: %x", hw->device_id);
485 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
486 hw->mac.type, hw->phy.media_type, err);
490 void txgbe_init_mac_link_ops(struct txgbe_hw *hw)
492 struct txgbe_mac_info *mac = &hw->mac;
494 DEBUGFUNC("txgbe_init_mac_link_ops");
497 * enable the laser control functions for SFP+ fiber
498 * and MNG not enabled
500 if (hw->phy.media_type == txgbe_media_type_fiber &&
501 !txgbe_mng_enabled(hw)) {
502 mac->disable_tx_laser =
503 txgbe_disable_tx_laser_multispeed_fiber;
504 mac->enable_tx_laser =
505 txgbe_enable_tx_laser_multispeed_fiber;
507 txgbe_flap_tx_laser_multispeed_fiber;
510 if ((hw->phy.media_type == txgbe_media_type_fiber ||
511 hw->phy.media_type == txgbe_media_type_fiber_qsfp) &&
512 hw->phy.multispeed_fiber) {
513 /* Set up dual speed SFP+ support */
514 mac->setup_link = txgbe_setup_mac_link_multispeed_fiber;
515 mac->setup_mac_link = txgbe_setup_mac_link;
516 mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed;
517 } else if ((hw->phy.media_type == txgbe_media_type_backplane) &&
518 (hw->phy.smart_speed == txgbe_smart_speed_auto ||
519 hw->phy.smart_speed == txgbe_smart_speed_on) &&
520 !txgbe_verify_lesm_fw_enabled_raptor(hw)) {
521 mac->setup_link = txgbe_setup_mac_link_smartspeed;
523 mac->setup_link = txgbe_setup_mac_link;
528 * txgbe_init_phy_raptor - PHY/SFP specific init
529 * @hw: pointer to hardware structure
531 * Initialize any function pointers that were not able to be
532 * set during init_shared_code because the PHY/SFP type was
533 * not known. Perform the SFP init if necessary.
536 s32 txgbe_init_phy_raptor(struct txgbe_hw *hw)
538 struct txgbe_mac_info *mac = &hw->mac;
539 struct txgbe_phy_info *phy = &hw->phy;
542 DEBUGFUNC("txgbe_init_phy_raptor");
544 if (hw->device_id == TXGBE_DEV_ID_RAPTOR_QSFP) {
545 /* Store flag indicating I2C bus access control unit. */
546 hw->phy.qsfp_shared_i2c_bus = TRUE;
548 /* Initialize access to QSFP+ I2C bus */
552 /* Identify the PHY or SFP module */
553 err = phy->identify(hw);
554 if (err == TXGBE_ERR_SFP_NOT_SUPPORTED)
555 goto init_phy_ops_out;
557 /* Setup function pointers based on detected SFP module and speeds */
558 txgbe_init_mac_link_ops(hw);
560 /* If copper media, overwrite with copper function pointers */
561 if (phy->media_type == txgbe_media_type_copper) {
562 mac->setup_link = txgbe_setup_copper_link_raptor;
563 mac->get_link_capabilities =
564 txgbe_get_copper_link_capabilities;
567 /* Set necessary function pointers based on PHY type */
568 switch (hw->phy.type) {
570 phy->setup_link = txgbe_setup_phy_link_tnx;
571 phy->check_link = txgbe_check_phy_link_tnx;
582 * txgbe_init_ops_pf - Inits func ptrs and MAC type
583 * @hw: pointer to hardware structure
585 * Initialize the function pointers and assign the MAC type.
586 * Does not touch the hardware.
588 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
590 struct txgbe_bus_info *bus = &hw->bus;
591 struct txgbe_mac_info *mac = &hw->mac;
592 struct txgbe_phy_info *phy = &hw->phy;
593 struct txgbe_rom_info *rom = &hw->rom;
595 DEBUGFUNC("txgbe_init_ops_pf");
598 bus->set_lan_id = txgbe_set_lan_id_multi_port;
601 phy->identify = txgbe_identify_phy;
602 phy->init = txgbe_init_phy_raptor;
603 phy->read_reg = txgbe_read_phy_reg;
604 phy->write_reg = txgbe_write_phy_reg;
605 phy->read_reg_mdi = txgbe_read_phy_reg_mdi;
606 phy->write_reg_mdi = txgbe_write_phy_reg_mdi;
607 phy->setup_link = txgbe_setup_phy_link;
608 phy->setup_link_speed = txgbe_setup_phy_link_speed;
609 phy->read_i2c_byte = txgbe_read_i2c_byte;
610 phy->write_i2c_byte = txgbe_write_i2c_byte;
611 phy->read_i2c_eeprom = txgbe_read_i2c_eeprom;
612 phy->write_i2c_eeprom = txgbe_write_i2c_eeprom;
613 phy->reset = txgbe_reset_phy;
616 mac->init_hw = txgbe_init_hw;
617 mac->reset_hw = txgbe_reset_hw;
620 mac->get_link_capabilities = txgbe_get_link_capabilities_raptor;
621 mac->check_link = txgbe_check_mac_link;
624 rom->init_params = txgbe_init_eeprom_params;
625 rom->read16 = txgbe_ee_read16;
626 rom->readw_buffer = txgbe_ee_readw_buffer;
627 rom->readw_sw = txgbe_ee_readw_sw;
628 rom->read32 = txgbe_ee_read32;
629 rom->write16 = txgbe_ee_write16;
630 rom->writew_buffer = txgbe_ee_writew_buffer;
631 rom->writew_sw = txgbe_ee_writew_sw;
632 rom->write32 = txgbe_ee_write32;
633 rom->validate_checksum = txgbe_validate_eeprom_checksum;
634 rom->update_checksum = txgbe_update_eeprom_checksum;
635 rom->calc_checksum = txgbe_calc_eeprom_checksum;
637 mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;
638 mac->max_rx_queues = TXGBE_RAPTOR_MAX_RX_QUEUES;
639 mac->max_tx_queues = TXGBE_RAPTOR_MAX_TX_QUEUES;
645 * txgbe_get_link_capabilities_raptor - Determines link capabilities
646 * @hw: pointer to hardware structure
647 * @speed: pointer to link speed
648 * @autoneg: true when autoneg or autotry is enabled
650 * Determines the link capabilities by reading the AUTOC register.
652 s32 txgbe_get_link_capabilities_raptor(struct txgbe_hw *hw,
659 DEBUGFUNC("txgbe_get_link_capabilities_raptor");
661 /* Check if 1G SFP module. */
662 if (hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
663 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
664 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
665 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
666 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
667 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1) {
668 *speed = TXGBE_LINK_SPEED_1GB_FULL;
674 * Determine link capabilities based on the stored value of AUTOC,
675 * which represents EEPROM defaults. If AUTOC value has not
676 * been stored, use the current register values.
678 if (hw->mac.orig_link_settings_stored)
679 autoc = hw->mac.orig_autoc;
681 autoc = hw->mac.autoc_read(hw);
683 switch (autoc & TXGBE_AUTOC_LMS_MASK) {
684 case TXGBE_AUTOC_LMS_1G_LINK_NO_AN:
685 *speed = TXGBE_LINK_SPEED_1GB_FULL;
689 case TXGBE_AUTOC_LMS_10G_LINK_NO_AN:
690 *speed = TXGBE_LINK_SPEED_10GB_FULL;
694 case TXGBE_AUTOC_LMS_1G_AN:
695 *speed = TXGBE_LINK_SPEED_1GB_FULL;
699 case TXGBE_AUTOC_LMS_10G:
700 *speed = TXGBE_LINK_SPEED_10GB_FULL;
704 case TXGBE_AUTOC_LMS_KX4_KX_KR:
705 case TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
706 *speed = TXGBE_LINK_SPEED_UNKNOWN;
707 if (autoc & TXGBE_AUTOC_KR_SUPP)
708 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
709 if (autoc & TXGBE_AUTOC_KX4_SUPP)
710 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
711 if (autoc & TXGBE_AUTOC_KX_SUPP)
712 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
716 case TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
717 *speed = TXGBE_LINK_SPEED_100M_FULL;
718 if (autoc & TXGBE_AUTOC_KR_SUPP)
719 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
720 if (autoc & TXGBE_AUTOC_KX4_SUPP)
721 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
722 if (autoc & TXGBE_AUTOC_KX_SUPP)
723 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
727 case TXGBE_AUTOC_LMS_SGMII_1G_100M:
728 *speed = TXGBE_LINK_SPEED_1GB_FULL |
729 TXGBE_LINK_SPEED_100M_FULL |
730 TXGBE_LINK_SPEED_10M_FULL;
735 return TXGBE_ERR_LINK_SETUP;
738 if (hw->phy.multispeed_fiber) {
739 *speed |= TXGBE_LINK_SPEED_10GB_FULL |
740 TXGBE_LINK_SPEED_1GB_FULL;
742 /* QSFP must not enable full auto-negotiation
743 * Limited autoneg is enabled at 1G
745 if (hw->phy.media_type == txgbe_media_type_fiber_qsfp)
755 * txgbe_start_mac_link_raptor - Setup MAC link settings
756 * @hw: pointer to hardware structure
757 * @autoneg_wait_to_complete: true when waiting for completion is needed
759 * Configures link settings based on values in the txgbe_hw struct.
760 * Restarts the link. Performs autonegotiation if needed.
762 s32 txgbe_start_mac_link_raptor(struct txgbe_hw *hw,
763 bool autoneg_wait_to_complete)
766 bool got_lock = false;
768 DEBUGFUNC("txgbe_start_mac_link_raptor");
770 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
772 /* reset_pipeline requires us to hold this lock as it writes to
775 if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
776 status = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
784 txgbe_reset_pipeline_raptor(hw);
787 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
789 /* Add delay to filter out noises during initial link setup */
797 * txgbe_disable_tx_laser_multispeed_fiber - Disable Tx laser
798 * @hw: pointer to hardware structure
800 * The base drivers may require better control over SFP+ module
801 * PHY states. This includes selectively shutting down the Tx
802 * laser on the PHY, effectively halting physical link.
804 void txgbe_disable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
806 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
808 /* Blocked by MNG FW so bail */
809 if (txgbe_check_reset_blocked(hw))
812 /* Disable Tx laser; allow 100us to go dark per spec */
813 esdp_reg |= (TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
814 wr32(hw, TXGBE_GPIODATA, esdp_reg);
820 * txgbe_enable_tx_laser_multispeed_fiber - Enable Tx laser
821 * @hw: pointer to hardware structure
823 * The base drivers may require better control over SFP+ module
824 * PHY states. This includes selectively turning on the Tx
825 * laser on the PHY, effectively starting physical link.
827 void txgbe_enable_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
829 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
831 /* Enable Tx laser; allow 100ms to light up */
832 esdp_reg &= ~(TXGBE_GPIOBIT_0 | TXGBE_GPIOBIT_1);
833 wr32(hw, TXGBE_GPIODATA, esdp_reg);
839 * txgbe_flap_tx_laser_multispeed_fiber - Flap Tx laser
840 * @hw: pointer to hardware structure
842 * When the driver changes the link speeds that it can support,
843 * it sets autotry_restart to true to indicate that we need to
844 * initiate a new autotry session with the link partner. To do
845 * so, we set the speed then disable and re-enable the Tx laser, to
846 * alert the link partner that it also needs to restart autotry on its
847 * end. This is consistent with true clause 37 autoneg, which also
848 * involves a loss of signal.
850 void txgbe_flap_tx_laser_multispeed_fiber(struct txgbe_hw *hw)
852 DEBUGFUNC("txgbe_flap_tx_laser_multispeed_fiber");
854 /* Blocked by MNG FW so bail */
855 if (txgbe_check_reset_blocked(hw))
858 if (hw->mac.autotry_restart) {
859 txgbe_disable_tx_laser_multispeed_fiber(hw);
860 txgbe_enable_tx_laser_multispeed_fiber(hw);
861 hw->mac.autotry_restart = false;
866 * txgbe_set_hard_rate_select_speed - Set module link speed
867 * @hw: pointer to hardware structure
868 * @speed: link speed to set
870 * Set module link speed via RS0/RS1 rate select pins.
872 void txgbe_set_hard_rate_select_speed(struct txgbe_hw *hw,
875 u32 esdp_reg = rd32(hw, TXGBE_GPIODATA);
878 case TXGBE_LINK_SPEED_10GB_FULL:
879 esdp_reg |= (TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
881 case TXGBE_LINK_SPEED_1GB_FULL:
882 esdp_reg &= ~(TXGBE_GPIOBIT_4 | TXGBE_GPIOBIT_5);
885 DEBUGOUT("Invalid fixed module speed\n");
889 wr32(hw, TXGBE_GPIODATA, esdp_reg);
894 * txgbe_setup_mac_link_smartspeed - Set MAC link speed using SmartSpeed
895 * @hw: pointer to hardware structure
896 * @speed: new link speed
897 * @autoneg_wait_to_complete: true when waiting for completion is needed
899 * Implements the Intel SmartSpeed algorithm.
901 s32 txgbe_setup_mac_link_smartspeed(struct txgbe_hw *hw,
903 bool autoneg_wait_to_complete)
906 u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN;
908 bool link_up = false;
909 u32 autoc_reg = rd32_epcs(hw, SR_AN_MMD_ADV_REG1);
911 DEBUGFUNC("txgbe_setup_mac_link_smartspeed");
913 /* Set autoneg_advertised value based on input link speed */
914 hw->phy.autoneg_advertised = 0;
916 if (speed & TXGBE_LINK_SPEED_10GB_FULL)
917 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_10GB_FULL;
919 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
920 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_1GB_FULL;
922 if (speed & TXGBE_LINK_SPEED_100M_FULL)
923 hw->phy.autoneg_advertised |= TXGBE_LINK_SPEED_100M_FULL;
926 * Implement Intel SmartSpeed algorithm. SmartSpeed will reduce the
927 * autoneg advertisement if link is unable to be established at the
928 * highest negotiated rate. This can sometimes happen due to integrity
929 * issues with the physical media connection.
932 /* First, try to get link with full advertisement */
933 hw->phy.smart_speed_active = false;
934 for (j = 0; j < TXGBE_SMARTSPEED_MAX_RETRIES; j++) {
935 status = txgbe_setup_mac_link(hw, speed,
936 autoneg_wait_to_complete);
941 * Wait for the controller to acquire link. Per IEEE 802.3ap,
942 * Section 73.10.2, we may have to wait up to 500ms if KR is
943 * attempted, or 200ms if KX/KX4/BX/BX4 is attempted, per
944 * Table 9 in the AN MAS.
946 for (i = 0; i < 5; i++) {
949 /* If we have link, just jump out */
950 status = hw->mac.check_link(hw, &link_speed, &link_up,
961 * We didn't get link. If we advertised KR plus one of KX4/KX
962 * (or BX4/BX), then disable KR and try again.
964 if (((autoc_reg & TXGBE_AUTOC_KR_SUPP) == 0) ||
965 ((autoc_reg & TXGBE_AUTOC_KX_SUPP) == 0 &&
966 (autoc_reg & TXGBE_AUTOC_KX4_SUPP) == 0))
969 /* Turn SmartSpeed on to disable KR support */
970 hw->phy.smart_speed_active = true;
971 status = txgbe_setup_mac_link(hw, speed,
972 autoneg_wait_to_complete);
977 * Wait for the controller to acquire link. 600ms will allow for
978 * the AN link_fail_inhibit_timer as well for multiple cycles of
979 * parallel detect, both 10g and 1g. This allows for the maximum
980 * connect attempts as defined in the AN MAS table 73-7.
982 for (i = 0; i < 6; i++) {
985 /* If we have link, just jump out */
986 status = hw->mac.check_link(hw, &link_speed, &link_up, false);
994 /* We didn't get link. Turn SmartSpeed back off. */
995 hw->phy.smart_speed_active = false;
996 status = txgbe_setup_mac_link(hw, speed,
997 autoneg_wait_to_complete);
1000 if (link_up && link_speed == TXGBE_LINK_SPEED_1GB_FULL)
1001 DEBUGOUT("Smartspeed has downgraded the link speed "
1002 "from the maximum advertised\n");
1007 * txgbe_setup_mac_link - Set MAC link speed
1008 * @hw: pointer to hardware structure
1009 * @speed: new link speed
1010 * @autoneg_wait_to_complete: true when waiting for completion is needed
1012 * Set the link speed in the AUTOC register and restarts link.
1014 s32 txgbe_setup_mac_link(struct txgbe_hw *hw,
1016 bool autoneg_wait_to_complete)
1018 bool autoneg = false;
1021 u64 autoc = hw->mac.autoc_read(hw);
1022 u64 pma_pmd_10gs = autoc & TXGBE_AUTOC_10GS_PMA_PMD_MASK;
1023 u64 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
1024 u64 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
1025 u64 current_autoc = autoc;
1029 u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
1031 DEBUGFUNC("txgbe_setup_mac_link");
1033 /* Check to see if speed passed in is supported. */
1034 status = hw->mac.get_link_capabilities(hw,
1035 &link_capabilities, &autoneg);
1039 speed &= link_capabilities;
1040 if (speed == TXGBE_LINK_SPEED_UNKNOWN)
1041 return TXGBE_ERR_LINK_SETUP;
1043 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
1044 if (hw->mac.orig_link_settings_stored)
1045 orig_autoc = hw->mac.orig_autoc;
1049 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
1050 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
1052 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
1053 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
1054 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
1055 /* Set KX4/KX/KR support according to speed requested */
1056 autoc &= ~(TXGBE_AUTOC_KX_SUPP |
1057 TXGBE_AUTOC_KX4_SUPP |
1058 TXGBE_AUTOC_KR_SUPP);
1059 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
1060 if (orig_autoc & TXGBE_AUTOC_KX4_SUPP)
1061 autoc |= TXGBE_AUTOC_KX4_SUPP;
1062 if ((orig_autoc & TXGBE_AUTOC_KR_SUPP) &&
1063 !hw->phy.smart_speed_active)
1064 autoc |= TXGBE_AUTOC_KR_SUPP;
1066 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
1067 autoc |= TXGBE_AUTOC_KX_SUPP;
1068 } else if ((pma_pmd_1g == TXGBE_AUTOC_1G_SFI) &&
1069 (link_mode == TXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
1070 link_mode == TXGBE_AUTOC_LMS_1G_AN)) {
1071 /* Switch from 1G SFI to 10G SFI if requested */
1072 if (speed == TXGBE_LINK_SPEED_10GB_FULL &&
1073 pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) {
1074 autoc &= ~TXGBE_AUTOC_LMS_MASK;
1075 autoc |= TXGBE_AUTOC_LMS_10G;
1077 } else if ((pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) &&
1078 (link_mode == TXGBE_AUTOC_LMS_10G)) {
1079 /* Switch from 10G SFI to 1G SFI if requested */
1080 if (speed == TXGBE_LINK_SPEED_1GB_FULL &&
1081 pma_pmd_1g == TXGBE_AUTOC_1G_SFI) {
1082 autoc &= ~TXGBE_AUTOC_LMS_MASK;
1083 if (autoneg || hw->phy.type == txgbe_phy_qsfp_intel)
1084 autoc |= TXGBE_AUTOC_LMS_1G_AN;
1086 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
1090 if (autoc == current_autoc)
1093 autoc &= ~TXGBE_AUTOC_SPEED_MASK;
1094 autoc |= TXGBE_AUTOC_SPEED(speed);
1095 autoc |= (autoneg ? TXGBE_AUTOC_AUTONEG : 0);
1098 hw->mac.autoc_write(hw, autoc);
1100 /* Only poll for autoneg to complete if specified to do so */
1101 if (autoneg_wait_to_complete) {
1102 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
1103 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
1104 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
1105 links_reg = 0; /*Just in case Autoneg time=0*/
1106 for (i = 0; i < TXGBE_AUTO_NEG_TIME; i++) {
1107 links_reg = rd32(hw, TXGBE_PORTSTAT);
1108 if (links_reg & TXGBE_PORTSTAT_UP)
1112 if (!(links_reg & TXGBE_PORTSTAT_UP)) {
1113 status = TXGBE_ERR_AUTONEG_NOT_COMPLETE;
1114 DEBUGOUT("Autoneg did not complete.\n");
1119 /* Add delay to filter out noises during initial link setup */
1126 * txgbe_setup_copper_link_raptor - Set the PHY autoneg advertised field
1127 * @hw: pointer to hardware structure
1128 * @speed: new link speed
1129 * @autoneg_wait_to_complete: true if waiting is needed to complete
1131 * Restarts link on PHY and MAC based on settings passed in.
1133 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
1135 bool autoneg_wait_to_complete)
1139 DEBUGFUNC("txgbe_setup_copper_link_raptor");
1141 /* Setup the PHY according to input speed */
1142 status = hw->phy.setup_link_speed(hw, speed,
1143 autoneg_wait_to_complete);
1145 txgbe_start_mac_link_raptor(hw, autoneg_wait_to_complete);
1151 txgbe_check_flash_load(struct txgbe_hw *hw, u32 check_bit)
1156 /* if there's flash existing */
1157 if (!(rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_BPFLASH)) {
1158 /* wait hw load flash done */
1159 for (i = 0; i < 10; i++) {
1160 reg = rd32(hw, TXGBE_ILDRSTAT);
1161 if (!(reg & check_bit)) {
1168 err = TXGBE_ERR_FLASH_LOADING_FAILED;
1174 * txgbe_reset_hw - Perform hardware reset
1175 * @hw: pointer to hardware structure
1177 * Resets the hardware by resetting the transmit and receive units, masks
1178 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
1181 s32 txgbe_reset_hw(struct txgbe_hw *hw)
1186 DEBUGFUNC("txgbe_reset_hw");
1188 /* Call adapter stop to disable tx/rx and clear interrupts */
1189 status = hw->mac.stop_hw(hw);
1193 /* flush pending Tx transactions */
1194 txgbe_clear_tx_pending(hw);
1196 /* Identify PHY and related function pointers */
1197 status = hw->phy.init(hw);
1198 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
1201 /* Setup SFP module if there is one present. */
1202 if (hw->phy.sfp_setup_needed) {
1203 status = hw->mac.setup_sfp(hw);
1204 hw->phy.sfp_setup_needed = false;
1206 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
1210 if (!hw->phy.reset_disable)
1213 /* remember AUTOC from before we reset */
1214 autoc = hw->mac.autoc_read(hw);
1218 * Issue global reset to the MAC. Needs to be SW reset if link is up.
1219 * If link reset is used when link is up, it might reset the PHY when
1220 * mng is using it. If link is down or the flag to force full link
1221 * reset is set, then perform link reset.
1223 if (txgbe_mng_present(hw)) {
1224 txgbe_hic_reset(hw);
1226 wr32(hw, TXGBE_RST, TXGBE_RST_LAN(hw->bus.lan_id));
1231 if (hw->bus.lan_id == 0) {
1232 status = txgbe_check_flash_load(hw,
1233 TXGBE_ILDRSTAT_SWRST_LAN0);
1235 status = txgbe_check_flash_load(hw,
1236 TXGBE_ILDRSTAT_SWRST_LAN1);
1244 * Double resets are required for recovery from certain error
1245 * conditions. Between resets, it is necessary to stall to
1246 * allow time for any pending HW events to complete.
1248 if (hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
1249 hw->mac.flags &= ~TXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
1254 * Store the original AUTOC/AUTOC2 values if they have not been
1255 * stored off yet. Otherwise restore the stored original
1256 * values since the reset operation sets back to defaults.
1258 if (!hw->mac.orig_link_settings_stored) {
1259 hw->mac.orig_autoc = hw->mac.autoc_read(hw);
1260 hw->mac.autoc_write(hw, hw->mac.orig_autoc);
1261 hw->mac.orig_link_settings_stored = true;
1263 hw->mac.orig_autoc = autoc;
1266 /* Store the permanent mac address */
1267 hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
1270 * Store MAC address from RAR0, clear receive address registers, and
1271 * clear the multicast table. Also reset num_rar_entries to 128,
1272 * since we modify this value when programming the SAN MAC address.
1274 hw->mac.num_rar_entries = 128;
1275 hw->mac.init_rx_addrs(hw);
1277 /* Store the permanent SAN mac address */
1278 hw->mac.get_san_mac_addr(hw, hw->mac.san_addr);
1280 /* Add the SAN MAC address to the RAR only if it's a valid address */
1281 if (txgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
1282 /* Save the SAN MAC RAR index */
1283 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
1285 hw->mac.set_rar(hw, hw->mac.san_mac_rar_index,
1286 hw->mac.san_addr, 0, true);
1288 /* clear VMDq pool/queue selection for this RAR */
1289 hw->mac.clear_vmdq(hw, hw->mac.san_mac_rar_index,
1292 /* Reserve the last RAR for the SAN MAC address */
1293 hw->mac.num_rar_entries--;
1296 /* Store the alternative WWNN/WWPN prefix */
1297 hw->mac.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
1298 &hw->mac.wwpn_prefix);
1304 * txgbe_verify_lesm_fw_enabled_raptor - Checks LESM FW module state.
1305 * @hw: pointer to hardware structure
1307 * Returns true if the LESM FW module is present and enabled. Otherwise
1308 * returns false. Smart Speed must be disabled if LESM FW module is enabled.
1310 bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw)
1312 bool lesm_enabled = false;
1313 u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
1316 DEBUGFUNC("txgbe_verify_lesm_fw_enabled_raptor");
1318 /* get the offset to the Firmware Module block */
1319 status = hw->rom.read16(hw, TXGBE_FW_PTR, &fw_offset);
1321 if (status != 0 || fw_offset == 0 || fw_offset == 0xFFFF)
1324 /* get the offset to the LESM Parameters block */
1325 status = hw->rom.read16(hw, (fw_offset +
1326 TXGBE_FW_LESM_PARAMETERS_PTR),
1327 &fw_lesm_param_offset);
1330 fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
1333 /* get the LESM state word */
1334 status = hw->rom.read16(hw, (fw_lesm_param_offset +
1335 TXGBE_FW_LESM_STATE_1),
1338 if (status == 0 && (fw_lesm_state & TXGBE_FW_LESM_STATE_ENABLED))
1339 lesm_enabled = true;
1342 lesm_enabled = false;
1343 return lesm_enabled;
1347 * txgbe_reset_pipeline_raptor - perform pipeline reset
1349 * @hw: pointer to hardware structure
1351 * Reset pipeline by asserting Restart_AN together with LMS change to ensure
1352 * full pipeline reset. This function assumes the SW/FW lock is held.
1354 s32 txgbe_reset_pipeline_raptor(struct txgbe_hw *hw)
1359 autoc = hw->mac.autoc_read(hw);
1361 /* Enable link if disabled in NVM */
1362 if (autoc & TXGBE_AUTOC_LINK_DIA_MASK)
1363 autoc &= ~TXGBE_AUTOC_LINK_DIA_MASK;
1365 autoc |= TXGBE_AUTOC_AN_RESTART;
1366 /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
1367 hw->mac.autoc_write(hw, autoc ^ TXGBE_AUTOC_LMS_AN);
1369 /* Write AUTOC register with original LMS field and Restart_AN */
1370 hw->mac.autoc_write(hw, autoc);