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_init_shared_code - Initialize the shared code
255 * @hw: pointer to hardware structure
257 * This will assign function pointers and assign the MAC type and PHY code.
258 * Does not touch the hardware. This function must be called prior to any
259 * other function in the shared code. The txgbe_hw structure should be
260 * memset to 0 prior to calling this function. The following fields in
261 * hw structure should be filled in prior to calling this function:
262 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
263 * subsystem_vendor_id, and revision_id
265 s32 txgbe_init_shared_code(struct txgbe_hw *hw)
269 DEBUGFUNC("txgbe_init_shared_code");
274 txgbe_set_mac_type(hw);
276 txgbe_init_ops_dummy(hw);
277 switch (hw->mac.type) {
278 case txgbe_mac_raptor:
279 status = txgbe_init_ops_pf(hw);
282 status = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
285 hw->mac.max_link_up_time = TXGBE_LINK_UP_TIME;
287 hw->bus.set_lan_id(hw);
293 * txgbe_set_mac_type - Sets MAC type
294 * @hw: pointer to the HW structure
296 * This function sets the mac type of the adapter based on the
297 * vendor ID and device ID stored in the hw structure.
299 s32 txgbe_set_mac_type(struct txgbe_hw *hw)
303 DEBUGFUNC("txgbe_set_mac_type");
305 if (hw->vendor_id != PCI_VENDOR_ID_WANGXUN) {
306 DEBUGOUT("Unsupported vendor id: %x", hw->vendor_id);
307 return TXGBE_ERR_DEVICE_NOT_SUPPORTED;
310 switch (hw->device_id) {
311 case TXGBE_DEV_ID_RAPTOR_KR_KX_KX4:
312 hw->phy.media_type = txgbe_media_type_backplane;
313 hw->mac.type = txgbe_mac_raptor;
315 case TXGBE_DEV_ID_RAPTOR_XAUI:
316 case TXGBE_DEV_ID_RAPTOR_SGMII:
317 hw->phy.media_type = txgbe_media_type_copper;
318 hw->mac.type = txgbe_mac_raptor;
320 case TXGBE_DEV_ID_RAPTOR_SFP:
321 case TXGBE_DEV_ID_WX1820_SFP:
322 hw->phy.media_type = txgbe_media_type_fiber;
323 hw->mac.type = txgbe_mac_raptor;
325 case TXGBE_DEV_ID_RAPTOR_QSFP:
326 hw->phy.media_type = txgbe_media_type_fiber_qsfp;
327 hw->mac.type = txgbe_mac_raptor;
329 case TXGBE_DEV_ID_RAPTOR_VF:
330 case TXGBE_DEV_ID_RAPTOR_VF_HV:
331 hw->phy.media_type = txgbe_media_type_virtual;
332 hw->mac.type = txgbe_mac_raptor_vf;
335 err = TXGBE_ERR_DEVICE_NOT_SUPPORTED;
336 DEBUGOUT("Unsupported device id: %x", hw->device_id);
340 DEBUGOUT("found mac: %d media: %d, returns: %d\n",
341 hw->mac.type, hw->phy.media_type, err);
345 void txgbe_init_mac_link_ops(struct txgbe_hw *hw)
347 struct txgbe_mac_info *mac = &hw->mac;
349 DEBUGFUNC("txgbe_init_mac_link_ops");
351 mac->setup_link = txgbe_setup_mac_link;
355 * txgbe_init_phy_raptor - PHY/SFP specific init
356 * @hw: pointer to hardware structure
358 * Initialize any function pointers that were not able to be
359 * set during init_shared_code because the PHY/SFP type was
360 * not known. Perform the SFP init if necessary.
363 s32 txgbe_init_phy_raptor(struct txgbe_hw *hw)
365 struct txgbe_mac_info *mac = &hw->mac;
366 struct txgbe_phy_info *phy = &hw->phy;
369 DEBUGFUNC("txgbe_init_phy_raptor");
371 if (hw->device_id == TXGBE_DEV_ID_RAPTOR_QSFP) {
372 /* Store flag indicating I2C bus access control unit. */
373 hw->phy.qsfp_shared_i2c_bus = TRUE;
375 /* Initialize access to QSFP+ I2C bus */
379 /* Identify the PHY or SFP module */
380 err = phy->identify(hw);
381 if (err == TXGBE_ERR_SFP_NOT_SUPPORTED)
382 goto init_phy_ops_out;
384 /* Setup function pointers based on detected SFP module and speeds */
385 txgbe_init_mac_link_ops(hw);
387 /* If copper media, overwrite with copper function pointers */
388 if (phy->media_type == txgbe_media_type_copper) {
389 mac->setup_link = txgbe_setup_copper_link_raptor;
390 mac->get_link_capabilities =
391 txgbe_get_copper_link_capabilities;
394 /* Set necessary function pointers based on PHY type */
395 switch (hw->phy.type) {
397 phy->setup_link = txgbe_setup_phy_link_tnx;
398 phy->check_link = txgbe_check_phy_link_tnx;
409 * txgbe_init_ops_pf - Inits func ptrs and MAC type
410 * @hw: pointer to hardware structure
412 * Initialize the function pointers and assign the MAC type.
413 * Does not touch the hardware.
415 s32 txgbe_init_ops_pf(struct txgbe_hw *hw)
417 struct txgbe_bus_info *bus = &hw->bus;
418 struct txgbe_mac_info *mac = &hw->mac;
419 struct txgbe_phy_info *phy = &hw->phy;
420 struct txgbe_rom_info *rom = &hw->rom;
422 DEBUGFUNC("txgbe_init_ops_pf");
425 bus->set_lan_id = txgbe_set_lan_id_multi_port;
428 phy->identify = txgbe_identify_phy;
429 phy->init = txgbe_init_phy_raptor;
430 phy->read_reg = txgbe_read_phy_reg;
431 phy->write_reg = txgbe_write_phy_reg;
432 phy->read_reg_mdi = txgbe_read_phy_reg_mdi;
433 phy->write_reg_mdi = txgbe_write_phy_reg_mdi;
434 phy->setup_link = txgbe_setup_phy_link;
435 phy->setup_link_speed = txgbe_setup_phy_link_speed;
436 phy->read_i2c_byte = txgbe_read_i2c_byte;
437 phy->write_i2c_byte = txgbe_write_i2c_byte;
438 phy->read_i2c_eeprom = txgbe_read_i2c_eeprom;
439 phy->write_i2c_eeprom = txgbe_write_i2c_eeprom;
440 phy->reset = txgbe_reset_phy;
443 mac->init_hw = txgbe_init_hw;
444 mac->reset_hw = txgbe_reset_hw;
447 mac->get_link_capabilities = txgbe_get_link_capabilities_raptor;
448 mac->check_link = txgbe_check_mac_link;
451 rom->init_params = txgbe_init_eeprom_params;
452 rom->read16 = txgbe_ee_read16;
453 rom->readw_buffer = txgbe_ee_readw_buffer;
454 rom->readw_sw = txgbe_ee_readw_sw;
455 rom->read32 = txgbe_ee_read32;
456 rom->write16 = txgbe_ee_write16;
457 rom->writew_buffer = txgbe_ee_writew_buffer;
458 rom->writew_sw = txgbe_ee_writew_sw;
459 rom->write32 = txgbe_ee_write32;
460 rom->validate_checksum = txgbe_validate_eeprom_checksum;
461 rom->update_checksum = txgbe_update_eeprom_checksum;
462 rom->calc_checksum = txgbe_calc_eeprom_checksum;
464 mac->num_rar_entries = TXGBE_RAPTOR_RAR_ENTRIES;
465 mac->max_rx_queues = TXGBE_RAPTOR_MAX_RX_QUEUES;
466 mac->max_tx_queues = TXGBE_RAPTOR_MAX_TX_QUEUES;
472 * txgbe_get_link_capabilities_raptor - Determines link capabilities
473 * @hw: pointer to hardware structure
474 * @speed: pointer to link speed
475 * @autoneg: true when autoneg or autotry is enabled
477 * Determines the link capabilities by reading the AUTOC register.
479 s32 txgbe_get_link_capabilities_raptor(struct txgbe_hw *hw,
486 DEBUGFUNC("txgbe_get_link_capabilities_raptor");
488 /* Check if 1G SFP module. */
489 if (hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core0 ||
490 hw->phy.sfp_type == txgbe_sfp_type_1g_cu_core1 ||
491 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core0 ||
492 hw->phy.sfp_type == txgbe_sfp_type_1g_lx_core1 ||
493 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core0 ||
494 hw->phy.sfp_type == txgbe_sfp_type_1g_sx_core1) {
495 *speed = TXGBE_LINK_SPEED_1GB_FULL;
501 * Determine link capabilities based on the stored value of AUTOC,
502 * which represents EEPROM defaults. If AUTOC value has not
503 * been stored, use the current register values.
505 if (hw->mac.orig_link_settings_stored)
506 autoc = hw->mac.orig_autoc;
508 autoc = hw->mac.autoc_read(hw);
510 switch (autoc & TXGBE_AUTOC_LMS_MASK) {
511 case TXGBE_AUTOC_LMS_1G_LINK_NO_AN:
512 *speed = TXGBE_LINK_SPEED_1GB_FULL;
516 case TXGBE_AUTOC_LMS_10G_LINK_NO_AN:
517 *speed = TXGBE_LINK_SPEED_10GB_FULL;
521 case TXGBE_AUTOC_LMS_1G_AN:
522 *speed = TXGBE_LINK_SPEED_1GB_FULL;
526 case TXGBE_AUTOC_LMS_10G:
527 *speed = TXGBE_LINK_SPEED_10GB_FULL;
531 case TXGBE_AUTOC_LMS_KX4_KX_KR:
532 case TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN:
533 *speed = TXGBE_LINK_SPEED_UNKNOWN;
534 if (autoc & TXGBE_AUTOC_KR_SUPP)
535 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
536 if (autoc & TXGBE_AUTOC_KX4_SUPP)
537 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
538 if (autoc & TXGBE_AUTOC_KX_SUPP)
539 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
543 case TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII:
544 *speed = TXGBE_LINK_SPEED_100M_FULL;
545 if (autoc & TXGBE_AUTOC_KR_SUPP)
546 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
547 if (autoc & TXGBE_AUTOC_KX4_SUPP)
548 *speed |= TXGBE_LINK_SPEED_10GB_FULL;
549 if (autoc & TXGBE_AUTOC_KX_SUPP)
550 *speed |= TXGBE_LINK_SPEED_1GB_FULL;
554 case TXGBE_AUTOC_LMS_SGMII_1G_100M:
555 *speed = TXGBE_LINK_SPEED_1GB_FULL |
556 TXGBE_LINK_SPEED_100M_FULL |
557 TXGBE_LINK_SPEED_10M_FULL;
562 return TXGBE_ERR_LINK_SETUP;
569 * txgbe_start_mac_link_raptor - Setup MAC link settings
570 * @hw: pointer to hardware structure
571 * @autoneg_wait_to_complete: true when waiting for completion is needed
573 * Configures link settings based on values in the txgbe_hw struct.
574 * Restarts the link. Performs autonegotiation if needed.
576 s32 txgbe_start_mac_link_raptor(struct txgbe_hw *hw,
577 bool autoneg_wait_to_complete)
580 bool got_lock = false;
582 DEBUGFUNC("txgbe_start_mac_link_raptor");
584 UNREFERENCED_PARAMETER(autoneg_wait_to_complete);
586 /* reset_pipeline requires us to hold this lock as it writes to
589 if (txgbe_verify_lesm_fw_enabled_raptor(hw)) {
590 status = hw->mac.acquire_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
598 txgbe_reset_pipeline_raptor(hw);
601 hw->mac.release_swfw_sync(hw, TXGBE_MNGSEM_SWPHY);
603 /* Add delay to filter out noises during initial link setup */
611 * txgbe_setup_mac_link - Set MAC link speed
612 * @hw: pointer to hardware structure
613 * @speed: new link speed
614 * @autoneg_wait_to_complete: true when waiting for completion is needed
616 * Set the link speed in the AUTOC register and restarts link.
618 s32 txgbe_setup_mac_link(struct txgbe_hw *hw,
620 bool autoneg_wait_to_complete)
622 bool autoneg = false;
625 u64 autoc = hw->mac.autoc_read(hw);
626 u64 pma_pmd_10gs = autoc & TXGBE_AUTOC_10GS_PMA_PMD_MASK;
627 u64 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
628 u64 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
629 u64 current_autoc = autoc;
633 u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN;
635 DEBUGFUNC("txgbe_setup_mac_link");
637 /* Check to see if speed passed in is supported. */
638 status = hw->mac.get_link_capabilities(hw,
639 &link_capabilities, &autoneg);
643 speed &= link_capabilities;
644 if (speed == TXGBE_LINK_SPEED_UNKNOWN)
645 return TXGBE_ERR_LINK_SETUP;
647 /* Use stored value (EEPROM defaults) of AUTOC to find KR/KX4 support*/
648 if (hw->mac.orig_link_settings_stored)
649 orig_autoc = hw->mac.orig_autoc;
653 link_mode = autoc & TXGBE_AUTOC_LMS_MASK;
654 pma_pmd_1g = autoc & TXGBE_AUTOC_1G_PMA_PMD_MASK;
656 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
657 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
658 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
659 /* Set KX4/KX/KR support according to speed requested */
660 autoc &= ~(TXGBE_AUTOC_KX_SUPP |
661 TXGBE_AUTOC_KX4_SUPP |
662 TXGBE_AUTOC_KR_SUPP);
663 if (speed & TXGBE_LINK_SPEED_10GB_FULL) {
664 if (orig_autoc & TXGBE_AUTOC_KX4_SUPP)
665 autoc |= TXGBE_AUTOC_KX4_SUPP;
666 if ((orig_autoc & TXGBE_AUTOC_KR_SUPP) &&
667 !hw->phy.smart_speed_active)
668 autoc |= TXGBE_AUTOC_KR_SUPP;
670 if (speed & TXGBE_LINK_SPEED_1GB_FULL)
671 autoc |= TXGBE_AUTOC_KX_SUPP;
672 } else if ((pma_pmd_1g == TXGBE_AUTOC_1G_SFI) &&
673 (link_mode == TXGBE_AUTOC_LMS_1G_LINK_NO_AN ||
674 link_mode == TXGBE_AUTOC_LMS_1G_AN)) {
675 /* Switch from 1G SFI to 10G SFI if requested */
676 if (speed == TXGBE_LINK_SPEED_10GB_FULL &&
677 pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) {
678 autoc &= ~TXGBE_AUTOC_LMS_MASK;
679 autoc |= TXGBE_AUTOC_LMS_10G;
681 } else if ((pma_pmd_10gs == TXGBE_AUTOC_10GS_SFI) &&
682 (link_mode == TXGBE_AUTOC_LMS_10G)) {
683 /* Switch from 10G SFI to 1G SFI if requested */
684 if (speed == TXGBE_LINK_SPEED_1GB_FULL &&
685 pma_pmd_1g == TXGBE_AUTOC_1G_SFI) {
686 autoc &= ~TXGBE_AUTOC_LMS_MASK;
687 if (autoneg || hw->phy.type == txgbe_phy_qsfp_intel)
688 autoc |= TXGBE_AUTOC_LMS_1G_AN;
690 autoc |= TXGBE_AUTOC_LMS_1G_LINK_NO_AN;
694 if (autoc == current_autoc)
697 autoc &= ~TXGBE_AUTOC_SPEED_MASK;
698 autoc |= TXGBE_AUTOC_SPEED(speed);
699 autoc |= (autoneg ? TXGBE_AUTOC_AUTONEG : 0);
702 hw->mac.autoc_write(hw, autoc);
704 /* Only poll for autoneg to complete if specified to do so */
705 if (autoneg_wait_to_complete) {
706 if (link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR ||
707 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_1G_AN ||
708 link_mode == TXGBE_AUTOC_LMS_KX4_KX_KR_SGMII) {
709 links_reg = 0; /*Just in case Autoneg time=0*/
710 for (i = 0; i < TXGBE_AUTO_NEG_TIME; i++) {
711 links_reg = rd32(hw, TXGBE_PORTSTAT);
712 if (links_reg & TXGBE_PORTSTAT_UP)
716 if (!(links_reg & TXGBE_PORTSTAT_UP)) {
717 status = TXGBE_ERR_AUTONEG_NOT_COMPLETE;
718 DEBUGOUT("Autoneg did not complete.\n");
723 /* Add delay to filter out noises during initial link setup */
730 * txgbe_setup_copper_link_raptor - Set the PHY autoneg advertised field
731 * @hw: pointer to hardware structure
732 * @speed: new link speed
733 * @autoneg_wait_to_complete: true if waiting is needed to complete
735 * Restarts link on PHY and MAC based on settings passed in.
737 static s32 txgbe_setup_copper_link_raptor(struct txgbe_hw *hw,
739 bool autoneg_wait_to_complete)
743 DEBUGFUNC("txgbe_setup_copper_link_raptor");
745 /* Setup the PHY according to input speed */
746 status = hw->phy.setup_link_speed(hw, speed,
747 autoneg_wait_to_complete);
749 txgbe_start_mac_link_raptor(hw, autoneg_wait_to_complete);
755 txgbe_check_flash_load(struct txgbe_hw *hw, u32 check_bit)
760 /* if there's flash existing */
761 if (!(rd32(hw, TXGBE_SPISTAT) & TXGBE_SPISTAT_BPFLASH)) {
762 /* wait hw load flash done */
763 for (i = 0; i < 10; i++) {
764 reg = rd32(hw, TXGBE_ILDRSTAT);
765 if (!(reg & check_bit)) {
772 err = TXGBE_ERR_FLASH_LOADING_FAILED;
778 * txgbe_reset_hw - Perform hardware reset
779 * @hw: pointer to hardware structure
781 * Resets the hardware by resetting the transmit and receive units, masks
782 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
785 s32 txgbe_reset_hw(struct txgbe_hw *hw)
790 DEBUGFUNC("txgbe_reset_hw");
792 /* Call adapter stop to disable tx/rx and clear interrupts */
793 status = hw->mac.stop_hw(hw);
797 /* flush pending Tx transactions */
798 txgbe_clear_tx_pending(hw);
800 /* Identify PHY and related function pointers */
801 status = hw->phy.init(hw);
802 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
805 /* Setup SFP module if there is one present. */
806 if (hw->phy.sfp_setup_needed) {
807 status = hw->mac.setup_sfp(hw);
808 hw->phy.sfp_setup_needed = false;
810 if (status == TXGBE_ERR_SFP_NOT_SUPPORTED)
814 if (!hw->phy.reset_disable)
817 /* remember AUTOC from before we reset */
818 autoc = hw->mac.autoc_read(hw);
822 * Issue global reset to the MAC. Needs to be SW reset if link is up.
823 * If link reset is used when link is up, it might reset the PHY when
824 * mng is using it. If link is down or the flag to force full link
825 * reset is set, then perform link reset.
827 if (txgbe_mng_present(hw)) {
830 wr32(hw, TXGBE_RST, TXGBE_RST_LAN(hw->bus.lan_id));
835 if (hw->bus.lan_id == 0) {
836 status = txgbe_check_flash_load(hw,
837 TXGBE_ILDRSTAT_SWRST_LAN0);
839 status = txgbe_check_flash_load(hw,
840 TXGBE_ILDRSTAT_SWRST_LAN1);
848 * Double resets are required for recovery from certain error
849 * conditions. Between resets, it is necessary to stall to
850 * allow time for any pending HW events to complete.
852 if (hw->mac.flags & TXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
853 hw->mac.flags &= ~TXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
858 * Store the original AUTOC/AUTOC2 values if they have not been
859 * stored off yet. Otherwise restore the stored original
860 * values since the reset operation sets back to defaults.
862 if (!hw->mac.orig_link_settings_stored) {
863 hw->mac.orig_autoc = hw->mac.autoc_read(hw);
864 hw->mac.autoc_write(hw, hw->mac.orig_autoc);
865 hw->mac.orig_link_settings_stored = true;
867 hw->mac.orig_autoc = autoc;
870 /* Store the permanent mac address */
871 hw->mac.get_mac_addr(hw, hw->mac.perm_addr);
874 * Store MAC address from RAR0, clear receive address registers, and
875 * clear the multicast table. Also reset num_rar_entries to 128,
876 * since we modify this value when programming the SAN MAC address.
878 hw->mac.num_rar_entries = 128;
879 hw->mac.init_rx_addrs(hw);
881 /* Store the permanent SAN mac address */
882 hw->mac.get_san_mac_addr(hw, hw->mac.san_addr);
884 /* Add the SAN MAC address to the RAR only if it's a valid address */
885 if (txgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
886 /* Save the SAN MAC RAR index */
887 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
889 hw->mac.set_rar(hw, hw->mac.san_mac_rar_index,
890 hw->mac.san_addr, 0, true);
892 /* clear VMDq pool/queue selection for this RAR */
893 hw->mac.clear_vmdq(hw, hw->mac.san_mac_rar_index,
896 /* Reserve the last RAR for the SAN MAC address */
897 hw->mac.num_rar_entries--;
900 /* Store the alternative WWNN/WWPN prefix */
901 hw->mac.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
902 &hw->mac.wwpn_prefix);
908 * txgbe_verify_lesm_fw_enabled_raptor - Checks LESM FW module state.
909 * @hw: pointer to hardware structure
911 * Returns true if the LESM FW module is present and enabled. Otherwise
912 * returns false. Smart Speed must be disabled if LESM FW module is enabled.
914 bool txgbe_verify_lesm_fw_enabled_raptor(struct txgbe_hw *hw)
916 bool lesm_enabled = false;
917 u16 fw_offset, fw_lesm_param_offset, fw_lesm_state;
920 DEBUGFUNC("txgbe_verify_lesm_fw_enabled_raptor");
922 /* get the offset to the Firmware Module block */
923 status = hw->rom.read16(hw, TXGBE_FW_PTR, &fw_offset);
925 if (status != 0 || fw_offset == 0 || fw_offset == 0xFFFF)
928 /* get the offset to the LESM Parameters block */
929 status = hw->rom.read16(hw, (fw_offset +
930 TXGBE_FW_LESM_PARAMETERS_PTR),
931 &fw_lesm_param_offset);
934 fw_lesm_param_offset == 0 || fw_lesm_param_offset == 0xFFFF)
937 /* get the LESM state word */
938 status = hw->rom.read16(hw, (fw_lesm_param_offset +
939 TXGBE_FW_LESM_STATE_1),
942 if (status == 0 && (fw_lesm_state & TXGBE_FW_LESM_STATE_ENABLED))
946 lesm_enabled = false;
951 * txgbe_reset_pipeline_raptor - perform pipeline reset
953 * @hw: pointer to hardware structure
955 * Reset pipeline by asserting Restart_AN together with LMS change to ensure
956 * full pipeline reset. This function assumes the SW/FW lock is held.
958 s32 txgbe_reset_pipeline_raptor(struct txgbe_hw *hw)
963 autoc = hw->mac.autoc_read(hw);
965 /* Enable link if disabled in NVM */
966 if (autoc & TXGBE_AUTOC_LINK_DIA_MASK)
967 autoc &= ~TXGBE_AUTOC_LINK_DIA_MASK;
969 autoc |= TXGBE_AUTOC_AN_RESTART;
970 /* Write AUTOC register with toggled LMS[2] bit and Restart_AN */
971 hw->mac.autoc_write(hw, autoc ^ TXGBE_AUTOC_LMS_AN);
973 /* Write AUTOC register with original LMS field and Restart_AN */
974 hw->mac.autoc_write(hw, autoc);