Michal Kubecek | d44e131 | 2019-12-11 10:58:29 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
| 2 | |
| 3 | #include "common.h" |
| 4 | |
| 5 | const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = { |
| 6 | [NETIF_F_SG_BIT] = "tx-scatter-gather", |
| 7 | [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4", |
| 8 | [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic", |
| 9 | [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6", |
| 10 | [NETIF_F_HIGHDMA_BIT] = "highdma", |
| 11 | [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist", |
| 12 | [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert", |
| 13 | |
| 14 | [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse", |
| 15 | [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter", |
| 16 | [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert", |
| 17 | [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse", |
| 18 | [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter", |
| 19 | [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged", |
| 20 | [NETIF_F_GSO_BIT] = "tx-generic-segmentation", |
| 21 | [NETIF_F_LLTX_BIT] = "tx-lockless", |
| 22 | [NETIF_F_NETNS_LOCAL_BIT] = "netns-local", |
| 23 | [NETIF_F_GRO_BIT] = "rx-gro", |
| 24 | [NETIF_F_GRO_HW_BIT] = "rx-gro-hw", |
| 25 | [NETIF_F_LRO_BIT] = "rx-lro", |
| 26 | |
| 27 | [NETIF_F_TSO_BIT] = "tx-tcp-segmentation", |
| 28 | [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust", |
| 29 | [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation", |
| 30 | [NETIF_F_TSO_MANGLEID_BIT] = "tx-tcp-mangleid-segmentation", |
| 31 | [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation", |
| 32 | [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation", |
| 33 | [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation", |
| 34 | [NETIF_F_GSO_GRE_CSUM_BIT] = "tx-gre-csum-segmentation", |
| 35 | [NETIF_F_GSO_IPXIP4_BIT] = "tx-ipxip4-segmentation", |
| 36 | [NETIF_F_GSO_IPXIP6_BIT] = "tx-ipxip6-segmentation", |
| 37 | [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation", |
| 38 | [NETIF_F_GSO_UDP_TUNNEL_CSUM_BIT] = "tx-udp_tnl-csum-segmentation", |
| 39 | [NETIF_F_GSO_PARTIAL_BIT] = "tx-gso-partial", |
| 40 | [NETIF_F_GSO_SCTP_BIT] = "tx-sctp-segmentation", |
| 41 | [NETIF_F_GSO_ESP_BIT] = "tx-esp-segmentation", |
| 42 | [NETIF_F_GSO_UDP_L4_BIT] = "tx-udp-segmentation", |
| 43 | |
| 44 | [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc", |
| 45 | [NETIF_F_SCTP_CRC_BIT] = "tx-checksum-sctp", |
| 46 | [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu", |
| 47 | [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter", |
| 48 | [NETIF_F_RXHASH_BIT] = "rx-hashing", |
| 49 | [NETIF_F_RXCSUM_BIT] = "rx-checksum", |
| 50 | [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy", |
| 51 | [NETIF_F_LOOPBACK_BIT] = "loopback", |
| 52 | [NETIF_F_RXFCS_BIT] = "rx-fcs", |
| 53 | [NETIF_F_RXALL_BIT] = "rx-all", |
| 54 | [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload", |
| 55 | [NETIF_F_HW_TC_BIT] = "hw-tc-offload", |
| 56 | [NETIF_F_HW_ESP_BIT] = "esp-hw-offload", |
| 57 | [NETIF_F_HW_ESP_TX_CSUM_BIT] = "esp-tx-csum-hw-offload", |
| 58 | [NETIF_F_RX_UDP_TUNNEL_PORT_BIT] = "rx-udp_tunnel-port-offload", |
| 59 | [NETIF_F_HW_TLS_RECORD_BIT] = "tls-hw-record", |
| 60 | [NETIF_F_HW_TLS_TX_BIT] = "tls-hw-tx-offload", |
| 61 | [NETIF_F_HW_TLS_RX_BIT] = "tls-hw-rx-offload", |
Steffen Klassert | 3b33583 | 2020-01-25 11:26:42 +0100 | [diff] [blame] | 62 | [NETIF_F_GRO_FRAGLIST_BIT] = "rx-gro-list", |
Michal Kubecek | d44e131 | 2019-12-11 10:58:29 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | const char |
| 66 | rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = { |
| 67 | [ETH_RSS_HASH_TOP_BIT] = "toeplitz", |
| 68 | [ETH_RSS_HASH_XOR_BIT] = "xor", |
| 69 | [ETH_RSS_HASH_CRC32_BIT] = "crc32", |
| 70 | }; |
| 71 | |
| 72 | const char |
| 73 | tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN] = { |
| 74 | [ETHTOOL_ID_UNSPEC] = "Unspec", |
| 75 | [ETHTOOL_RX_COPYBREAK] = "rx-copybreak", |
| 76 | [ETHTOOL_TX_COPYBREAK] = "tx-copybreak", |
| 77 | [ETHTOOL_PFC_PREVENTION_TOUT] = "pfc-prevention-tout", |
| 78 | }; |
| 79 | |
| 80 | const char |
| 81 | phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN] = { |
| 82 | [ETHTOOL_ID_UNSPEC] = "Unspec", |
| 83 | [ETHTOOL_PHY_DOWNSHIFT] = "phy-downshift", |
| 84 | [ETHTOOL_PHY_FAST_LINK_DOWN] = "phy-fast-link-down", |
| 85 | [ETHTOOL_PHY_EDPD] = "phy-energy-detect-power-down", |
| 86 | }; |
Michal Kubecek | 428c122 | 2019-12-11 10:58:34 +0100 | [diff] [blame] | 87 | |
| 88 | #define __LINK_MODE_NAME(speed, type, duplex) \ |
| 89 | #speed "base" #type "/" #duplex |
| 90 | #define __DEFINE_LINK_MODE_NAME(speed, type, duplex) \ |
| 91 | [ETHTOOL_LINK_MODE(speed, type, duplex)] = \ |
| 92 | __LINK_MODE_NAME(speed, type, duplex) |
| 93 | #define __DEFINE_SPECIAL_MODE_NAME(_mode, _name) \ |
| 94 | [ETHTOOL_LINK_MODE_ ## _mode ## _BIT] = _name |
| 95 | |
| 96 | const char link_mode_names[][ETH_GSTRING_LEN] = { |
| 97 | __DEFINE_LINK_MODE_NAME(10, T, Half), |
| 98 | __DEFINE_LINK_MODE_NAME(10, T, Full), |
| 99 | __DEFINE_LINK_MODE_NAME(100, T, Half), |
| 100 | __DEFINE_LINK_MODE_NAME(100, T, Full), |
| 101 | __DEFINE_LINK_MODE_NAME(1000, T, Half), |
| 102 | __DEFINE_LINK_MODE_NAME(1000, T, Full), |
| 103 | __DEFINE_SPECIAL_MODE_NAME(Autoneg, "Autoneg"), |
| 104 | __DEFINE_SPECIAL_MODE_NAME(TP, "TP"), |
| 105 | __DEFINE_SPECIAL_MODE_NAME(AUI, "AUI"), |
| 106 | __DEFINE_SPECIAL_MODE_NAME(MII, "MII"), |
| 107 | __DEFINE_SPECIAL_MODE_NAME(FIBRE, "FIBRE"), |
| 108 | __DEFINE_SPECIAL_MODE_NAME(BNC, "BNC"), |
| 109 | __DEFINE_LINK_MODE_NAME(10000, T, Full), |
| 110 | __DEFINE_SPECIAL_MODE_NAME(Pause, "Pause"), |
| 111 | __DEFINE_SPECIAL_MODE_NAME(Asym_Pause, "Asym_Pause"), |
| 112 | __DEFINE_LINK_MODE_NAME(2500, X, Full), |
| 113 | __DEFINE_SPECIAL_MODE_NAME(Backplane, "Backplane"), |
| 114 | __DEFINE_LINK_MODE_NAME(1000, KX, Full), |
| 115 | __DEFINE_LINK_MODE_NAME(10000, KX4, Full), |
| 116 | __DEFINE_LINK_MODE_NAME(10000, KR, Full), |
| 117 | __DEFINE_SPECIAL_MODE_NAME(10000baseR_FEC, "10000baseR_FEC"), |
| 118 | __DEFINE_LINK_MODE_NAME(20000, MLD2, Full), |
| 119 | __DEFINE_LINK_MODE_NAME(20000, KR2, Full), |
| 120 | __DEFINE_LINK_MODE_NAME(40000, KR4, Full), |
| 121 | __DEFINE_LINK_MODE_NAME(40000, CR4, Full), |
| 122 | __DEFINE_LINK_MODE_NAME(40000, SR4, Full), |
| 123 | __DEFINE_LINK_MODE_NAME(40000, LR4, Full), |
| 124 | __DEFINE_LINK_MODE_NAME(56000, KR4, Full), |
| 125 | __DEFINE_LINK_MODE_NAME(56000, CR4, Full), |
| 126 | __DEFINE_LINK_MODE_NAME(56000, SR4, Full), |
| 127 | __DEFINE_LINK_MODE_NAME(56000, LR4, Full), |
| 128 | __DEFINE_LINK_MODE_NAME(25000, CR, Full), |
| 129 | __DEFINE_LINK_MODE_NAME(25000, KR, Full), |
| 130 | __DEFINE_LINK_MODE_NAME(25000, SR, Full), |
| 131 | __DEFINE_LINK_MODE_NAME(50000, CR2, Full), |
| 132 | __DEFINE_LINK_MODE_NAME(50000, KR2, Full), |
| 133 | __DEFINE_LINK_MODE_NAME(100000, KR4, Full), |
| 134 | __DEFINE_LINK_MODE_NAME(100000, SR4, Full), |
| 135 | __DEFINE_LINK_MODE_NAME(100000, CR4, Full), |
| 136 | __DEFINE_LINK_MODE_NAME(100000, LR4_ER4, Full), |
| 137 | __DEFINE_LINK_MODE_NAME(50000, SR2, Full), |
| 138 | __DEFINE_LINK_MODE_NAME(1000, X, Full), |
| 139 | __DEFINE_LINK_MODE_NAME(10000, CR, Full), |
| 140 | __DEFINE_LINK_MODE_NAME(10000, SR, Full), |
| 141 | __DEFINE_LINK_MODE_NAME(10000, LR, Full), |
| 142 | __DEFINE_LINK_MODE_NAME(10000, LRM, Full), |
| 143 | __DEFINE_LINK_MODE_NAME(10000, ER, Full), |
| 144 | __DEFINE_LINK_MODE_NAME(2500, T, Full), |
| 145 | __DEFINE_LINK_MODE_NAME(5000, T, Full), |
| 146 | __DEFINE_SPECIAL_MODE_NAME(FEC_NONE, "None"), |
| 147 | __DEFINE_SPECIAL_MODE_NAME(FEC_RS, "RS"), |
| 148 | __DEFINE_SPECIAL_MODE_NAME(FEC_BASER, "BASER"), |
| 149 | __DEFINE_LINK_MODE_NAME(50000, KR, Full), |
| 150 | __DEFINE_LINK_MODE_NAME(50000, SR, Full), |
| 151 | __DEFINE_LINK_MODE_NAME(50000, CR, Full), |
| 152 | __DEFINE_LINK_MODE_NAME(50000, LR_ER_FR, Full), |
| 153 | __DEFINE_LINK_MODE_NAME(50000, DR, Full), |
| 154 | __DEFINE_LINK_MODE_NAME(100000, KR2, Full), |
| 155 | __DEFINE_LINK_MODE_NAME(100000, SR2, Full), |
| 156 | __DEFINE_LINK_MODE_NAME(100000, CR2, Full), |
| 157 | __DEFINE_LINK_MODE_NAME(100000, LR2_ER2_FR2, Full), |
| 158 | __DEFINE_LINK_MODE_NAME(100000, DR2, Full), |
| 159 | __DEFINE_LINK_MODE_NAME(200000, KR4, Full), |
| 160 | __DEFINE_LINK_MODE_NAME(200000, SR4, Full), |
| 161 | __DEFINE_LINK_MODE_NAME(200000, LR4_ER4_FR4, Full), |
| 162 | __DEFINE_LINK_MODE_NAME(200000, DR4, Full), |
| 163 | __DEFINE_LINK_MODE_NAME(200000, CR4, Full), |
| 164 | __DEFINE_LINK_MODE_NAME(100, T1, Full), |
| 165 | __DEFINE_LINK_MODE_NAME(1000, T1, Full), |
| 166 | __DEFINE_LINK_MODE_NAME(400000, KR8, Full), |
| 167 | __DEFINE_LINK_MODE_NAME(400000, SR8, Full), |
| 168 | __DEFINE_LINK_MODE_NAME(400000, LR8_ER8_FR8, Full), |
| 169 | __DEFINE_LINK_MODE_NAME(400000, DR8, Full), |
| 170 | __DEFINE_LINK_MODE_NAME(400000, CR8, Full), |
Aya Levin | f623e59 | 2020-02-11 14:32:52 -0800 | [diff] [blame] | 171 | __DEFINE_SPECIAL_MODE_NAME(FEC_LLRS, "LLRS"), |
Michal Kubecek | 428c122 | 2019-12-11 10:58:34 +0100 | [diff] [blame] | 172 | }; |
| 173 | static_assert(ARRAY_SIZE(link_mode_names) == __ETHTOOL_LINK_MODE_MASK_NBITS); |
Michal Kubecek | 459e0b8 | 2019-12-27 15:55:48 +0100 | [diff] [blame] | 174 | |
Michal Kubecek | 6a94b8c | 2020-01-26 23:11:04 +0100 | [diff] [blame] | 175 | const char netif_msg_class_names[][ETH_GSTRING_LEN] = { |
| 176 | [NETIF_MSG_DRV_BIT] = "drv", |
| 177 | [NETIF_MSG_PROBE_BIT] = "probe", |
| 178 | [NETIF_MSG_LINK_BIT] = "link", |
| 179 | [NETIF_MSG_TIMER_BIT] = "timer", |
| 180 | [NETIF_MSG_IFDOWN_BIT] = "ifdown", |
| 181 | [NETIF_MSG_IFUP_BIT] = "ifup", |
| 182 | [NETIF_MSG_RX_ERR_BIT] = "rx_err", |
| 183 | [NETIF_MSG_TX_ERR_BIT] = "tx_err", |
| 184 | [NETIF_MSG_TX_QUEUED_BIT] = "tx_queued", |
| 185 | [NETIF_MSG_INTR_BIT] = "intr", |
| 186 | [NETIF_MSG_TX_DONE_BIT] = "tx_done", |
| 187 | [NETIF_MSG_RX_STATUS_BIT] = "rx_status", |
| 188 | [NETIF_MSG_PKTDATA_BIT] = "pktdata", |
| 189 | [NETIF_MSG_HW_BIT] = "hw", |
| 190 | [NETIF_MSG_WOL_BIT] = "wol", |
| 191 | }; |
| 192 | static_assert(ARRAY_SIZE(netif_msg_class_names) == NETIF_MSG_CLASS_COUNT); |
| 193 | |
Michal Kubecek | 51ea22b | 2020-01-26 23:11:13 +0100 | [diff] [blame] | 194 | const char wol_mode_names[][ETH_GSTRING_LEN] = { |
| 195 | [const_ilog2(WAKE_PHY)] = "phy", |
| 196 | [const_ilog2(WAKE_UCAST)] = "ucast", |
| 197 | [const_ilog2(WAKE_MCAST)] = "mcast", |
| 198 | [const_ilog2(WAKE_BCAST)] = "bcast", |
| 199 | [const_ilog2(WAKE_ARP)] = "arp", |
| 200 | [const_ilog2(WAKE_MAGIC)] = "magic", |
| 201 | [const_ilog2(WAKE_MAGICSECURE)] = "magicsecure", |
| 202 | [const_ilog2(WAKE_FILTER)] = "filter", |
| 203 | }; |
| 204 | static_assert(ARRAY_SIZE(wol_mode_names) == WOL_MODE_COUNT); |
| 205 | |
Michal Kubecek | 459e0b8 | 2019-12-27 15:55:48 +0100 | [diff] [blame] | 206 | /* return false if legacy contained non-0 deprecated fields |
| 207 | * maxtxpkt/maxrxpkt. rest of ksettings always updated |
| 208 | */ |
| 209 | bool |
| 210 | convert_legacy_settings_to_link_ksettings( |
| 211 | struct ethtool_link_ksettings *link_ksettings, |
| 212 | const struct ethtool_cmd *legacy_settings) |
| 213 | { |
| 214 | bool retval = true; |
| 215 | |
| 216 | memset(link_ksettings, 0, sizeof(*link_ksettings)); |
| 217 | |
| 218 | /* This is used to tell users that driver is still using these |
| 219 | * deprecated legacy fields, and they should not use |
| 220 | * %ETHTOOL_GLINKSETTINGS/%ETHTOOL_SLINKSETTINGS |
| 221 | */ |
| 222 | if (legacy_settings->maxtxpkt || |
| 223 | legacy_settings->maxrxpkt) |
| 224 | retval = false; |
| 225 | |
| 226 | ethtool_convert_legacy_u32_to_link_mode( |
| 227 | link_ksettings->link_modes.supported, |
| 228 | legacy_settings->supported); |
| 229 | ethtool_convert_legacy_u32_to_link_mode( |
| 230 | link_ksettings->link_modes.advertising, |
| 231 | legacy_settings->advertising); |
| 232 | ethtool_convert_legacy_u32_to_link_mode( |
| 233 | link_ksettings->link_modes.lp_advertising, |
| 234 | legacy_settings->lp_advertising); |
| 235 | link_ksettings->base.speed |
| 236 | = ethtool_cmd_speed(legacy_settings); |
| 237 | link_ksettings->base.duplex |
| 238 | = legacy_settings->duplex; |
| 239 | link_ksettings->base.port |
| 240 | = legacy_settings->port; |
| 241 | link_ksettings->base.phy_address |
| 242 | = legacy_settings->phy_address; |
| 243 | link_ksettings->base.autoneg |
| 244 | = legacy_settings->autoneg; |
| 245 | link_ksettings->base.mdio_support |
| 246 | = legacy_settings->mdio_support; |
| 247 | link_ksettings->base.eth_tp_mdix |
| 248 | = legacy_settings->eth_tp_mdix; |
| 249 | link_ksettings->base.eth_tp_mdix_ctrl |
| 250 | = legacy_settings->eth_tp_mdix_ctrl; |
| 251 | return retval; |
| 252 | } |
Michal Kubecek | 3d2b847 | 2019-12-27 15:56:23 +0100 | [diff] [blame] | 253 | |
| 254 | int __ethtool_get_link(struct net_device *dev) |
| 255 | { |
| 256 | if (!dev->ethtool_ops->get_link) |
| 257 | return -EOPNOTSUPP; |
| 258 | |
| 259 | return netif_running(dev) && dev->ethtool_ops->get_link(dev); |
| 260 | } |
Michal Kubecek | e19c591 | 2020-03-12 21:08:43 +0100 | [diff] [blame] | 261 | |
| 262 | int ethtool_get_max_rxfh_channel(struct net_device *dev, u32 *max) |
| 263 | { |
| 264 | u32 dev_size, current_max = 0; |
| 265 | u32 *indir; |
| 266 | int ret; |
| 267 | |
| 268 | if (!dev->ethtool_ops->get_rxfh_indir_size || |
| 269 | !dev->ethtool_ops->get_rxfh) |
| 270 | return -EOPNOTSUPP; |
| 271 | dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev); |
| 272 | if (dev_size == 0) |
| 273 | return -EOPNOTSUPP; |
| 274 | |
| 275 | indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER); |
| 276 | if (!indir) |
| 277 | return -ENOMEM; |
| 278 | |
| 279 | ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL); |
| 280 | if (ret) |
| 281 | goto out; |
| 282 | |
| 283 | while (dev_size--) |
| 284 | current_max = max(current_max, indir[dev_size]); |
| 285 | |
| 286 | *max = current_max; |
| 287 | |
| 288 | out: |
| 289 | kfree(indir); |
| 290 | return ret; |
| 291 | } |