Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2015-2025 Beijing WangXun Technology Co., Ltd. 3 : : * Copyright(c) 2010-2017 Intel Corporation 4 : : */ 5 : : 6 : : #include "txgbe_type.h" 7 : : #include "txgbe_mbx.h" 8 : : #include "txgbe_phy.h" 9 : : #include "txgbe_dcb.h" 10 : : #include "txgbe_vf.h" 11 : : #include "txgbe_eeprom.h" 12 : : #include "txgbe_mng.h" 13 : : #include "txgbe_hw.h" 14 : : #include "txgbe_aml.h" 15 : : #include "txgbe_aml40.h" 16 : : 17 : 0 : void txgbe_init_ops_aml40(struct txgbe_hw *hw) 18 : : { 19 : : struct txgbe_mac_info *mac = &hw->mac; 20 : : struct txgbe_phy_info *phy = &hw->phy; 21 : : 22 : 0 : txgbe_init_ops_generic(hw); 23 : : 24 : : /* PHY */ 25 : 0 : phy->get_media_type = txgbe_get_media_type_aml40; 26 : : 27 : : /* LINK */ 28 : 0 : mac->init_mac_link_ops = txgbe_init_mac_link_ops_aml40; 29 : 0 : mac->get_link_capabilities = txgbe_get_link_capabilities_aml40; 30 : 0 : mac->check_link = txgbe_check_mac_link_aml40; 31 : 0 : } 32 : : 33 : 0 : s32 txgbe_check_mac_link_aml40(struct txgbe_hw *hw, u32 *speed, 34 : : bool *link_up, bool link_up_wait_to_complete) 35 : : { 36 : : u32 links_reg, links_orig; 37 : : u32 i; 38 : : 39 : : /* clear the old state */ 40 : : links_orig = rd32(hw, TXGBE_PORTSTAT); 41 : : 42 : : links_reg = rd32(hw, TXGBE_PORTSTAT); 43 : : 44 [ # # ]: 0 : if (links_orig != links_reg) { 45 : 0 : DEBUGOUT("LINKS changed from %08X to %08X", 46 : : links_orig, links_reg); 47 : : } 48 : : 49 [ # # ]: 0 : if (link_up_wait_to_complete) { 50 [ # # ]: 0 : for (i = 0; i < hw->mac.max_link_up_time; i++) { 51 [ # # ]: 0 : if (!(links_reg & TXGBE_PORTSTAT_UP)) { 52 : 0 : *link_up = false; 53 : : } else { 54 : 0 : *link_up = true; 55 : 0 : break; 56 : : } 57 : : msec_delay(100); 58 : : links_reg = rd32(hw, TXGBE_PORTSTAT); 59 : : } 60 : : } else { 61 [ # # ]: 0 : if (links_reg & TXGBE_PORTSTAT_UP) 62 : 0 : *link_up = true; 63 : : else 64 : 0 : *link_up = false; 65 : : } 66 : : 67 [ # # ]: 0 : if (link_up) { 68 [ # # ]: 0 : if ((links_reg & TXGBE_CFG_PORT_ST_AML_LINK_40G) == 69 : : TXGBE_CFG_PORT_ST_AML_LINK_40G) 70 : 0 : *speed = TXGBE_LINK_SPEED_40GB_FULL; 71 : : } else { 72 : 0 : *speed = TXGBE_LINK_SPEED_UNKNOWN; 73 : : } 74 : : 75 : 0 : return 0; 76 : : } 77 : : 78 : 0 : s32 txgbe_get_link_capabilities_aml40(struct txgbe_hw *hw, 79 : : u32 *speed, 80 : : bool *autoneg) 81 : : { 82 [ # # ]: 0 : if (hw->phy.sfp_type == txgbe_qsfp_type_40g_cu_core0 || 83 : : hw->phy.sfp_type == txgbe_qsfp_type_40g_cu_core1) { 84 : 0 : *speed = TXGBE_LINK_SPEED_40GB_FULL; 85 : 0 : *autoneg = false; 86 : : } else { 87 : : /* 88 : : * Temporary workaround: set speed to 40G even if sfp not present 89 : : * to avoid TXGBE_ERR_LINK_SETUP returned by setup_mac_link, but 90 : : * a more reasonable solution is don't execute setup_mac_link when 91 : : * sfp module not present. 92 : : */ 93 : 0 : *speed = TXGBE_LINK_SPEED_40GB_FULL; 94 : 0 : *autoneg = true; 95 : : } 96 : : 97 : 0 : return 0; 98 : : } 99 : : 100 : 0 : u32 txgbe_get_media_type_aml40(struct txgbe_hw *hw) 101 : : { 102 : : UNREFERENCED_PARAMETER(hw); 103 : 0 : return txgbe_media_type_fiber_qsfp; 104 : : } 105 : : 106 : 0 : s32 txgbe_setup_mac_link_aml40(struct txgbe_hw *hw, 107 : : u32 speed, 108 : : bool autoneg_wait_to_complete) 109 : : { 110 : 0 : bool autoneg = false; 111 : : s32 status = 0; 112 : 0 : u32 link_speed = TXGBE_LINK_SPEED_UNKNOWN; 113 : 0 : bool link_up = false; 114 : 0 : u32 link_capabilities = TXGBE_LINK_SPEED_UNKNOWN; 115 : : 116 [ # # ]: 0 : if (hw->phy.sfp_type == txgbe_sfp_type_not_present) { 117 : 0 : DEBUGOUT("SFP not detected, skip setup mac link"); 118 : 0 : return 0; 119 : : } 120 : : 121 : : /* Check to see if speed passed in is supported. */ 122 : 0 : status = hw->mac.get_link_capabilities(hw, 123 : : &link_capabilities, &autoneg); 124 [ # # ]: 0 : if (status) 125 : : return status; 126 : : 127 : 0 : speed &= link_capabilities; 128 [ # # ]: 0 : if (speed == TXGBE_LINK_SPEED_UNKNOWN) 129 : : return TXGBE_ERR_LINK_SETUP; 130 : : 131 : 0 : status = hw->mac.check_link(hw, &link_speed, &link_up, 132 : : autoneg_wait_to_complete); 133 : : 134 [ # # # # ]: 0 : if (link_speed == speed && link_up) 135 : : return status; 136 : : 137 [ # # ]: 0 : if (speed & TXGBE_LINK_SPEED_40GB_FULL) 138 : : speed = 0x20; 139 : : 140 : 0 : status = hw->phy.set_link_hostif(hw, (u8)speed, autoneg, true); 141 : : 142 : 0 : txgbe_wait_for_link_up_aml(hw, speed); 143 : : 144 : 0 : return status; 145 : : } 146 : : 147 : 0 : void txgbe_init_mac_link_ops_aml40(struct txgbe_hw *hw) 148 : : { 149 : : struct txgbe_mac_info *mac = &hw->mac; 150 : : 151 : 0 : mac->disable_tx_laser = 152 : : txgbe_disable_tx_laser_multispeed_fiber; 153 : 0 : mac->enable_tx_laser = 154 : : txgbe_enable_tx_laser_multispeed_fiber; 155 : 0 : mac->flap_tx_laser = 156 : : txgbe_flap_tx_laser_multispeed_fiber; 157 : : 158 : 0 : mac->setup_link = txgbe_setup_mac_link_aml40; 159 : 0 : mac->set_rate_select_speed = txgbe_set_hard_rate_select_speed; 160 : 0 : }