Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sfc: move some ethtool code

Various ethtool entry points are moved.

Signed-off-by: Alexandru-Mihai Maftei <amaftei@solarflare.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alex Maftei (amaftei) and committed by
David S. Miller
3653954d 190c736a

+489 -442
+2 -2
drivers/net/ethernet/sfc/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 sfc-y += efx.o efx_common.o efx_channels.o nic.o \ 3 3 farch.o siena.o ef10.o \ 4 - tx.o tx_common.o rx.o rx_common.o \ 5 - selftest.o ethtool.o ptp.o tx_tso.o \ 4 + tx.o tx_common.o tx_tso.o rx.o rx_common.o \ 5 + selftest.o ethtool.o ethtool_common.o ptp.o \ 6 6 mcdi.o mcdi_port.o mcdi_port_common.o \ 7 7 mcdi_functions.o mcdi_mon.o 8 8 sfc-$(CONFIG_SFC_MTD) += mtd.o
+1 -440
drivers/net/ethernet/sfc/ethtool.c
··· 16 16 #include "efx_channels.h" 17 17 #include "rx_common.h" 18 18 #include "tx_common.h" 19 + #include "ethtool_common.h" 19 20 #include "filter.h" 20 21 #include "nic.h" 21 - 22 - struct efx_sw_stat_desc { 23 - const char *name; 24 - enum { 25 - EFX_ETHTOOL_STAT_SOURCE_nic, 26 - EFX_ETHTOOL_STAT_SOURCE_channel, 27 - EFX_ETHTOOL_STAT_SOURCE_tx_queue 28 - } source; 29 - unsigned offset; 30 - u64(*get_stat) (void *field); /* Reader function */ 31 - }; 32 - 33 - /* Initialiser for a struct efx_sw_stat_desc with type-checking */ 34 - #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ 35 - get_stat_function) { \ 36 - .name = #stat_name, \ 37 - .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ 38 - .offset = ((((field_type *) 0) == \ 39 - &((struct efx_##source_name *)0)->field) ? \ 40 - offsetof(struct efx_##source_name, field) : \ 41 - offsetof(struct efx_##source_name, field)), \ 42 - .get_stat = get_stat_function, \ 43 - } 44 - 45 - static u64 efx_get_uint_stat(void *field) 46 - { 47 - return *(unsigned int *)field; 48 - } 49 - 50 - static u64 efx_get_atomic_stat(void *field) 51 - { 52 - return atomic_read((atomic_t *) field); 53 - } 54 - 55 - #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ 56 - EFX_ETHTOOL_STAT(field, nic, field, \ 57 - atomic_t, efx_get_atomic_stat) 58 - 59 - #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ 60 - EFX_ETHTOOL_STAT(field, channel, n_##field, \ 61 - unsigned int, efx_get_uint_stat) 62 - #define EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(field) \ 63 - EFX_ETHTOOL_STAT(field, channel, field, \ 64 - unsigned int, efx_get_uint_stat) 65 - 66 - #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \ 67 - EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \ 68 - unsigned int, efx_get_uint_stat) 69 - 70 - static const struct efx_sw_stat_desc efx_sw_stat_desc[] = { 71 - EFX_ETHTOOL_UINT_TXQ_STAT(merge_events), 72 - EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts), 73 - EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers), 74 - EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets), 75 - EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks), 76 - EFX_ETHTOOL_UINT_TXQ_STAT(pushes), 77 - EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets), 78 - EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets), 79 - EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), 80 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), 81 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), 82 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), 83 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err), 84 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err), 85 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err), 86 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err), 87 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err), 88 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), 89 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), 90 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events), 91 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets), 92 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_drops), 93 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_bad_drops), 94 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_tx), 95 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_redirect), 96 - #ifdef CONFIG_RFS_ACCEL 97 - EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(rfs_filter_count), 98 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_succeeded), 99 - EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_failed), 100 - #endif 101 - }; 102 - 103 - #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc) 104 22 105 23 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB 106 24 ··· 106 188 return rc; 107 189 } 108 190 109 - static void efx_ethtool_get_drvinfo(struct net_device *net_dev, 110 - struct ethtool_drvinfo *info) 111 - { 112 - struct efx_nic *efx = netdev_priv(net_dev); 113 - 114 - strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); 115 - strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); 116 - efx_mcdi_print_fwver(efx, info->fw_version, 117 - sizeof(info->fw_version)); 118 - strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); 119 - } 120 - 121 191 static int efx_ethtool_get_regs_len(struct net_device *net_dev) 122 192 { 123 193 return efx_nic_get_regs_len(netdev_priv(net_dev)); ··· 118 212 119 213 regs->version = efx->type->revision; 120 214 efx_nic_get_regs(efx, buf); 121 - } 122 - 123 - static u32 efx_ethtool_get_msglevel(struct net_device *net_dev) 124 - { 125 - struct efx_nic *efx = netdev_priv(net_dev); 126 - return efx->msg_enable; 127 - } 128 - 129 - static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) 130 - { 131 - struct efx_nic *efx = netdev_priv(net_dev); 132 - efx->msg_enable = msg_enable; 133 - } 134 - 135 - /** 136 - * efx_fill_test - fill in an individual self-test entry 137 - * @test_index: Index of the test 138 - * @strings: Ethtool strings, or %NULL 139 - * @data: Ethtool test results, or %NULL 140 - * @test: Pointer to test result (used only if data != %NULL) 141 - * @unit_format: Unit name format (e.g. "chan\%d") 142 - * @unit_id: Unit id (e.g. 0 for "chan0") 143 - * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") 144 - * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") 145 - * 146 - * Fill in an individual self-test entry. 147 - */ 148 - static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data, 149 - int *test, const char *unit_format, int unit_id, 150 - const char *test_format, const char *test_id) 151 - { 152 - char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN]; 153 - 154 - /* Fill data value, if applicable */ 155 - if (data) 156 - data[test_index] = *test; 157 - 158 - /* Fill string, if applicable */ 159 - if (strings) { 160 - if (strchr(unit_format, '%')) 161 - snprintf(unit_str, sizeof(unit_str), 162 - unit_format, unit_id); 163 - else 164 - strcpy(unit_str, unit_format); 165 - snprintf(test_str, sizeof(test_str), test_format, test_id); 166 - snprintf(strings + test_index * ETH_GSTRING_LEN, 167 - ETH_GSTRING_LEN, 168 - "%-6s %-24s", unit_str, test_str); 169 - } 170 - } 171 - 172 - #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel 173 - #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue 174 - #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue 175 - #define EFX_LOOPBACK_NAME(_mode, _counter) \ 176 - "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) 177 - 178 - /** 179 - * efx_fill_loopback_test - fill in a block of loopback self-test entries 180 - * @efx: Efx NIC 181 - * @lb_tests: Efx loopback self-test results structure 182 - * @mode: Loopback test mode 183 - * @test_index: Starting index of the test 184 - * @strings: Ethtool strings, or %NULL 185 - * @data: Ethtool test results, or %NULL 186 - * 187 - * Fill in a block of loopback self-test entries. Return new test 188 - * index. 189 - */ 190 - static int efx_fill_loopback_test(struct efx_nic *efx, 191 - struct efx_loopback_self_tests *lb_tests, 192 - enum efx_loopback_mode mode, 193 - unsigned int test_index, 194 - u8 *strings, u64 *data) 195 - { 196 - struct efx_channel *channel = 197 - efx_get_channel(efx, efx->tx_channel_offset); 198 - struct efx_tx_queue *tx_queue; 199 - 200 - efx_for_each_channel_tx_queue(tx_queue, channel) { 201 - efx_fill_test(test_index++, strings, data, 202 - &lb_tests->tx_sent[tx_queue->queue], 203 - EFX_TX_QUEUE_NAME(tx_queue), 204 - EFX_LOOPBACK_NAME(mode, "tx_sent")); 205 - efx_fill_test(test_index++, strings, data, 206 - &lb_tests->tx_done[tx_queue->queue], 207 - EFX_TX_QUEUE_NAME(tx_queue), 208 - EFX_LOOPBACK_NAME(mode, "tx_done")); 209 - } 210 - efx_fill_test(test_index++, strings, data, 211 - &lb_tests->rx_good, 212 - "rx", 0, 213 - EFX_LOOPBACK_NAME(mode, "rx_good")); 214 - efx_fill_test(test_index++, strings, data, 215 - &lb_tests->rx_bad, 216 - "rx", 0, 217 - EFX_LOOPBACK_NAME(mode, "rx_bad")); 218 - 219 - return test_index; 220 - } 221 - 222 - /** 223 - * efx_ethtool_fill_self_tests - get self-test details 224 - * @efx: Efx NIC 225 - * @tests: Efx self-test results structure, or %NULL 226 - * @strings: Ethtool strings, or %NULL 227 - * @data: Ethtool test results, or %NULL 228 - * 229 - * Get self-test number of strings, strings, and/or test results. 230 - * Return number of strings (== number of test results). 231 - * 232 - * The reason for merging these three functions is to make sure that 233 - * they can never be inconsistent. 234 - */ 235 - static int efx_ethtool_fill_self_tests(struct efx_nic *efx, 236 - struct efx_self_tests *tests, 237 - u8 *strings, u64 *data) 238 - { 239 - struct efx_channel *channel; 240 - unsigned int n = 0, i; 241 - enum efx_loopback_mode mode; 242 - 243 - efx_fill_test(n++, strings, data, &tests->phy_alive, 244 - "phy", 0, "alive", NULL); 245 - efx_fill_test(n++, strings, data, &tests->nvram, 246 - "core", 0, "nvram", NULL); 247 - efx_fill_test(n++, strings, data, &tests->interrupt, 248 - "core", 0, "interrupt", NULL); 249 - 250 - /* Event queues */ 251 - efx_for_each_channel(channel, efx) { 252 - efx_fill_test(n++, strings, data, 253 - &tests->eventq_dma[channel->channel], 254 - EFX_CHANNEL_NAME(channel), 255 - "eventq.dma", NULL); 256 - efx_fill_test(n++, strings, data, 257 - &tests->eventq_int[channel->channel], 258 - EFX_CHANNEL_NAME(channel), 259 - "eventq.int", NULL); 260 - } 261 - 262 - efx_fill_test(n++, strings, data, &tests->memory, 263 - "core", 0, "memory", NULL); 264 - efx_fill_test(n++, strings, data, &tests->registers, 265 - "core", 0, "registers", NULL); 266 - 267 - if (efx->phy_op->run_tests != NULL) { 268 - EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL); 269 - 270 - for (i = 0; true; ++i) { 271 - const char *name; 272 - 273 - EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); 274 - name = efx->phy_op->test_name(efx, i); 275 - if (name == NULL) 276 - break; 277 - 278 - efx_fill_test(n++, strings, data, &tests->phy_ext[i], 279 - "phy", 0, name, NULL); 280 - } 281 - } 282 - 283 - /* Loopback tests */ 284 - for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { 285 - if (!(efx->loopback_modes & (1 << mode))) 286 - continue; 287 - n = efx_fill_loopback_test(efx, 288 - &tests->loopback[mode], mode, n, 289 - strings, data); 290 - } 291 - 292 - return n; 293 - } 294 - 295 - static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings) 296 - { 297 - size_t n_stats = 0; 298 - struct efx_channel *channel; 299 - 300 - efx_for_each_channel(channel, efx) { 301 - if (efx_channel_has_tx_queues(channel)) { 302 - n_stats++; 303 - if (strings != NULL) { 304 - snprintf(strings, ETH_GSTRING_LEN, 305 - "tx-%u.tx_packets", 306 - channel->tx_queue[0].queue / 307 - EFX_TXQ_TYPES); 308 - 309 - strings += ETH_GSTRING_LEN; 310 - } 311 - } 312 - } 313 - efx_for_each_channel(channel, efx) { 314 - if (efx_channel_has_rx_queue(channel)) { 315 - n_stats++; 316 - if (strings != NULL) { 317 - snprintf(strings, ETH_GSTRING_LEN, 318 - "rx-%d.rx_packets", channel->channel); 319 - strings += ETH_GSTRING_LEN; 320 - } 321 - } 322 - } 323 - if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { 324 - unsigned short xdp; 325 - 326 - for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { 327 - n_stats++; 328 - if (strings) { 329 - snprintf(strings, ETH_GSTRING_LEN, 330 - "tx-xdp-cpu-%hu.tx_packets", xdp); 331 - strings += ETH_GSTRING_LEN; 332 - } 333 - } 334 - } 335 - 336 - return n_stats; 337 - } 338 - 339 - static int efx_ethtool_get_sset_count(struct net_device *net_dev, 340 - int string_set) 341 - { 342 - struct efx_nic *efx = netdev_priv(net_dev); 343 - 344 - switch (string_set) { 345 - case ETH_SS_STATS: 346 - return efx->type->describe_stats(efx, NULL) + 347 - EFX_ETHTOOL_SW_STAT_COUNT + 348 - efx_describe_per_queue_stats(efx, NULL) + 349 - efx_ptp_describe_stats(efx, NULL); 350 - case ETH_SS_TEST: 351 - return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); 352 - default: 353 - return -EINVAL; 354 - } 355 - } 356 - 357 - static void efx_ethtool_get_strings(struct net_device *net_dev, 358 - u32 string_set, u8 *strings) 359 - { 360 - struct efx_nic *efx = netdev_priv(net_dev); 361 - int i; 362 - 363 - switch (string_set) { 364 - case ETH_SS_STATS: 365 - strings += (efx->type->describe_stats(efx, strings) * 366 - ETH_GSTRING_LEN); 367 - for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) 368 - strlcpy(strings + i * ETH_GSTRING_LEN, 369 - efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); 370 - strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; 371 - strings += (efx_describe_per_queue_stats(efx, strings) * 372 - ETH_GSTRING_LEN); 373 - efx_ptp_describe_stats(efx, strings); 374 - break; 375 - case ETH_SS_TEST: 376 - efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); 377 - break; 378 - default: 379 - /* No other string sets */ 380 - break; 381 - } 382 - } 383 - 384 - static void efx_ethtool_get_stats(struct net_device *net_dev, 385 - struct ethtool_stats *stats, 386 - u64 *data) 387 - { 388 - struct efx_nic *efx = netdev_priv(net_dev); 389 - const struct efx_sw_stat_desc *stat; 390 - struct efx_channel *channel; 391 - struct efx_tx_queue *tx_queue; 392 - struct efx_rx_queue *rx_queue; 393 - int i; 394 - 395 - spin_lock_bh(&efx->stats_lock); 396 - 397 - /* Get NIC statistics */ 398 - data += efx->type->update_stats(efx, data, NULL); 399 - 400 - /* Get software statistics */ 401 - for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { 402 - stat = &efx_sw_stat_desc[i]; 403 - switch (stat->source) { 404 - case EFX_ETHTOOL_STAT_SOURCE_nic: 405 - data[i] = stat->get_stat((void *)efx + stat->offset); 406 - break; 407 - case EFX_ETHTOOL_STAT_SOURCE_channel: 408 - data[i] = 0; 409 - efx_for_each_channel(channel, efx) 410 - data[i] += stat->get_stat((void *)channel + 411 - stat->offset); 412 - break; 413 - case EFX_ETHTOOL_STAT_SOURCE_tx_queue: 414 - data[i] = 0; 415 - efx_for_each_channel(channel, efx) { 416 - efx_for_each_channel_tx_queue(tx_queue, channel) 417 - data[i] += 418 - stat->get_stat((void *)tx_queue 419 - + stat->offset); 420 - } 421 - break; 422 - } 423 - } 424 - data += EFX_ETHTOOL_SW_STAT_COUNT; 425 - 426 - spin_unlock_bh(&efx->stats_lock); 427 - 428 - efx_for_each_channel(channel, efx) { 429 - if (efx_channel_has_tx_queues(channel)) { 430 - *data = 0; 431 - efx_for_each_channel_tx_queue(tx_queue, channel) { 432 - *data += tx_queue->tx_packets; 433 - } 434 - data++; 435 - } 436 - } 437 - efx_for_each_channel(channel, efx) { 438 - if (efx_channel_has_rx_queue(channel)) { 439 - *data = 0; 440 - efx_for_each_channel_rx_queue(rx_queue, channel) { 441 - *data += rx_queue->rx_packets; 442 - } 443 - data++; 444 - } 445 - } 446 - if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { 447 - int xdp; 448 - 449 - for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { 450 - data[0] = efx->xdp_tx_queues[xdp]->tx_packets; 451 - data++; 452 - } 453 - } 454 - 455 - efx_ptp_update_stats(efx, data); 456 215 } 457 216 458 217 static void efx_ethtool_self_test(struct net_device *net_dev, ··· 359 788 mutex_unlock(&efx->mac_lock); 360 789 361 790 return rc; 362 - } 363 - 364 - static void efx_ethtool_get_pauseparam(struct net_device *net_dev, 365 - struct ethtool_pauseparam *pause) 366 - { 367 - struct efx_nic *efx = netdev_priv(net_dev); 368 - 369 - pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); 370 - pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); 371 - pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); 372 791 } 373 792 374 793 static void efx_ethtool_get_wol(struct net_device *net_dev,
+456
drivers/net/ethernet/sfc/ethtool_common.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /**************************************************************************** 3 + * Driver for Solarflare network controllers and boards 4 + * Copyright 2019 Solarflare Communications Inc. 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License version 2 as published 8 + * by the Free Software Foundation, incorporated herein by reference. 9 + */ 10 + #include <linux/module.h> 11 + #include <linux/netdevice.h> 12 + #include "net_driver.h" 13 + #include "mcdi.h" 14 + #include "nic.h" 15 + #include "selftest.h" 16 + #include "ethtool_common.h" 17 + 18 + struct efx_sw_stat_desc { 19 + const char *name; 20 + enum { 21 + EFX_ETHTOOL_STAT_SOURCE_nic, 22 + EFX_ETHTOOL_STAT_SOURCE_channel, 23 + EFX_ETHTOOL_STAT_SOURCE_tx_queue 24 + } source; 25 + unsigned int offset; 26 + u64 (*get_stat)(void *field); /* Reader function */ 27 + }; 28 + 29 + /* Initialiser for a struct efx_sw_stat_desc with type-checking */ 30 + #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ 31 + get_stat_function) { \ 32 + .name = #stat_name, \ 33 + .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ 34 + .offset = ((((field_type *) 0) == \ 35 + &((struct efx_##source_name *)0)->field) ? \ 36 + offsetof(struct efx_##source_name, field) : \ 37 + offsetof(struct efx_##source_name, field)), \ 38 + .get_stat = get_stat_function, \ 39 + } 40 + 41 + static u64 efx_get_uint_stat(void *field) 42 + { 43 + return *(unsigned int *)field; 44 + } 45 + 46 + static u64 efx_get_atomic_stat(void *field) 47 + { 48 + return atomic_read((atomic_t *) field); 49 + } 50 + 51 + #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ 52 + EFX_ETHTOOL_STAT(field, nic, field, \ 53 + atomic_t, efx_get_atomic_stat) 54 + 55 + #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ 56 + EFX_ETHTOOL_STAT(field, channel, n_##field, \ 57 + unsigned int, efx_get_uint_stat) 58 + #define EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(field) \ 59 + EFX_ETHTOOL_STAT(field, channel, field, \ 60 + unsigned int, efx_get_uint_stat) 61 + 62 + #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \ 63 + EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \ 64 + unsigned int, efx_get_uint_stat) 65 + 66 + static const struct efx_sw_stat_desc efx_sw_stat_desc[] = { 67 + EFX_ETHTOOL_UINT_TXQ_STAT(merge_events), 68 + EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts), 69 + EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers), 70 + EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets), 71 + EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks), 72 + EFX_ETHTOOL_UINT_TXQ_STAT(pushes), 73 + EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets), 74 + EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets), 75 + EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), 76 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), 77 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), 78 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), 79 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_ip_hdr_chksum_err), 80 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_inner_tcp_udp_chksum_err), 81 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_ip_hdr_chksum_err), 82 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_outer_tcp_udp_chksum_err), 83 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_eth_crc_err), 84 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), 85 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), 86 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events), 87 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets), 88 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_drops), 89 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_bad_drops), 90 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_tx), 91 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_xdp_redirect), 92 + #ifdef CONFIG_RFS_ACCEL 93 + EFX_ETHTOOL_UINT_CHANNEL_STAT_NO_N(rfs_filter_count), 94 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_succeeded), 95 + EFX_ETHTOOL_UINT_CHANNEL_STAT(rfs_failed), 96 + #endif 97 + }; 98 + 99 + #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc) 100 + 101 + void efx_ethtool_get_drvinfo(struct net_device *net_dev, 102 + struct ethtool_drvinfo *info) 103 + { 104 + struct efx_nic *efx = netdev_priv(net_dev); 105 + 106 + strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); 107 + strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); 108 + efx_mcdi_print_fwver(efx, info->fw_version, 109 + sizeof(info->fw_version)); 110 + strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); 111 + } 112 + 113 + u32 efx_ethtool_get_msglevel(struct net_device *net_dev) 114 + { 115 + struct efx_nic *efx = netdev_priv(net_dev); 116 + 117 + return efx->msg_enable; 118 + } 119 + 120 + void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) 121 + { 122 + struct efx_nic *efx = netdev_priv(net_dev); 123 + 124 + efx->msg_enable = msg_enable; 125 + } 126 + 127 + void efx_ethtool_get_pauseparam(struct net_device *net_dev, 128 + struct ethtool_pauseparam *pause) 129 + { 130 + struct efx_nic *efx = netdev_priv(net_dev); 131 + 132 + pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); 133 + pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); 134 + pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); 135 + } 136 + 137 + /** 138 + * efx_fill_test - fill in an individual self-test entry 139 + * @test_index: Index of the test 140 + * @strings: Ethtool strings, or %NULL 141 + * @data: Ethtool test results, or %NULL 142 + * @test: Pointer to test result (used only if data != %NULL) 143 + * @unit_format: Unit name format (e.g. "chan\%d") 144 + * @unit_id: Unit id (e.g. 0 for "chan0") 145 + * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") 146 + * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") 147 + * 148 + * Fill in an individual self-test entry. 149 + */ 150 + void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data, 151 + int *test, const char *unit_format, int unit_id, 152 + const char *test_format, const char *test_id) 153 + { 154 + char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN]; 155 + 156 + /* Fill data value, if applicable */ 157 + if (data) 158 + data[test_index] = *test; 159 + 160 + /* Fill string, if applicable */ 161 + if (strings) { 162 + if (strchr(unit_format, '%')) 163 + snprintf(unit_str, sizeof(unit_str), 164 + unit_format, unit_id); 165 + else 166 + strcpy(unit_str, unit_format); 167 + snprintf(test_str, sizeof(test_str), test_format, test_id); 168 + snprintf(strings + test_index * ETH_GSTRING_LEN, 169 + ETH_GSTRING_LEN, 170 + "%-6s %-24s", unit_str, test_str); 171 + } 172 + } 173 + 174 + #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel 175 + #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue 176 + #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue 177 + #define EFX_LOOPBACK_NAME(_mode, _counter) \ 178 + "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) 179 + 180 + /** 181 + * efx_fill_loopback_test - fill in a block of loopback self-test entries 182 + * @efx: Efx NIC 183 + * @lb_tests: Efx loopback self-test results structure 184 + * @mode: Loopback test mode 185 + * @test_index: Starting index of the test 186 + * @strings: Ethtool strings, or %NULL 187 + * @data: Ethtool test results, or %NULL 188 + * 189 + * Fill in a block of loopback self-test entries. Return new test 190 + * index. 191 + */ 192 + int efx_fill_loopback_test(struct efx_nic *efx, 193 + struct efx_loopback_self_tests *lb_tests, 194 + enum efx_loopback_mode mode, 195 + unsigned int test_index, u8 *strings, u64 *data) 196 + { 197 + struct efx_channel *channel = 198 + efx_get_channel(efx, efx->tx_channel_offset); 199 + struct efx_tx_queue *tx_queue; 200 + 201 + efx_for_each_channel_tx_queue(tx_queue, channel) { 202 + efx_fill_test(test_index++, strings, data, 203 + &lb_tests->tx_sent[tx_queue->queue], 204 + EFX_TX_QUEUE_NAME(tx_queue), 205 + EFX_LOOPBACK_NAME(mode, "tx_sent")); 206 + efx_fill_test(test_index++, strings, data, 207 + &lb_tests->tx_done[tx_queue->queue], 208 + EFX_TX_QUEUE_NAME(tx_queue), 209 + EFX_LOOPBACK_NAME(mode, "tx_done")); 210 + } 211 + efx_fill_test(test_index++, strings, data, 212 + &lb_tests->rx_good, 213 + "rx", 0, 214 + EFX_LOOPBACK_NAME(mode, "rx_good")); 215 + efx_fill_test(test_index++, strings, data, 216 + &lb_tests->rx_bad, 217 + "rx", 0, 218 + EFX_LOOPBACK_NAME(mode, "rx_bad")); 219 + 220 + return test_index; 221 + } 222 + 223 + /** 224 + * efx_ethtool_fill_self_tests - get self-test details 225 + * @efx: Efx NIC 226 + * @tests: Efx self-test results structure, or %NULL 227 + * @strings: Ethtool strings, or %NULL 228 + * @data: Ethtool test results, or %NULL 229 + * 230 + * Get self-test number of strings, strings, and/or test results. 231 + * Return number of strings (== number of test results). 232 + * 233 + * The reason for merging these three functions is to make sure that 234 + * they can never be inconsistent. 235 + */ 236 + int efx_ethtool_fill_self_tests(struct efx_nic *efx, 237 + struct efx_self_tests *tests, 238 + u8 *strings, u64 *data) 239 + { 240 + struct efx_channel *channel; 241 + unsigned int n = 0, i; 242 + enum efx_loopback_mode mode; 243 + 244 + efx_fill_test(n++, strings, data, &tests->phy_alive, 245 + "phy", 0, "alive", NULL); 246 + efx_fill_test(n++, strings, data, &tests->nvram, 247 + "core", 0, "nvram", NULL); 248 + efx_fill_test(n++, strings, data, &tests->interrupt, 249 + "core", 0, "interrupt", NULL); 250 + 251 + /* Event queues */ 252 + efx_for_each_channel(channel, efx) { 253 + efx_fill_test(n++, strings, data, 254 + &tests->eventq_dma[channel->channel], 255 + EFX_CHANNEL_NAME(channel), 256 + "eventq.dma", NULL); 257 + efx_fill_test(n++, strings, data, 258 + &tests->eventq_int[channel->channel], 259 + EFX_CHANNEL_NAME(channel), 260 + "eventq.int", NULL); 261 + } 262 + 263 + efx_fill_test(n++, strings, data, &tests->memory, 264 + "core", 0, "memory", NULL); 265 + efx_fill_test(n++, strings, data, &tests->registers, 266 + "core", 0, "registers", NULL); 267 + 268 + if (efx->phy_op->run_tests != NULL) { 269 + EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL); 270 + 271 + for (i = 0; true; ++i) { 272 + const char *name; 273 + 274 + EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); 275 + name = efx->phy_op->test_name(efx, i); 276 + if (name == NULL) 277 + break; 278 + 279 + efx_fill_test(n++, strings, data, &tests->phy_ext[i], 280 + "phy", 0, name, NULL); 281 + } 282 + } 283 + 284 + /* Loopback tests */ 285 + for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { 286 + if (!(efx->loopback_modes & (1 << mode))) 287 + continue; 288 + n = efx_fill_loopback_test(efx, 289 + &tests->loopback[mode], mode, n, 290 + strings, data); 291 + } 292 + 293 + return n; 294 + } 295 + 296 + size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings) 297 + { 298 + size_t n_stats = 0; 299 + struct efx_channel *channel; 300 + 301 + efx_for_each_channel(channel, efx) { 302 + if (efx_channel_has_tx_queues(channel)) { 303 + n_stats++; 304 + if (strings != NULL) { 305 + snprintf(strings, ETH_GSTRING_LEN, 306 + "tx-%u.tx_packets", 307 + channel->tx_queue[0].queue / 308 + EFX_TXQ_TYPES); 309 + 310 + strings += ETH_GSTRING_LEN; 311 + } 312 + } 313 + } 314 + efx_for_each_channel(channel, efx) { 315 + if (efx_channel_has_rx_queue(channel)) { 316 + n_stats++; 317 + if (strings != NULL) { 318 + snprintf(strings, ETH_GSTRING_LEN, 319 + "rx-%d.rx_packets", channel->channel); 320 + strings += ETH_GSTRING_LEN; 321 + } 322 + } 323 + } 324 + if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { 325 + unsigned short xdp; 326 + 327 + for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { 328 + n_stats++; 329 + if (strings) { 330 + snprintf(strings, ETH_GSTRING_LEN, 331 + "tx-xdp-cpu-%hu.tx_packets", xdp); 332 + strings += ETH_GSTRING_LEN; 333 + } 334 + } 335 + } 336 + 337 + return n_stats; 338 + } 339 + 340 + int efx_ethtool_get_sset_count(struct net_device *net_dev, int string_set) 341 + { 342 + struct efx_nic *efx = netdev_priv(net_dev); 343 + 344 + switch (string_set) { 345 + case ETH_SS_STATS: 346 + return efx->type->describe_stats(efx, NULL) + 347 + EFX_ETHTOOL_SW_STAT_COUNT + 348 + efx_describe_per_queue_stats(efx, NULL) + 349 + efx_ptp_describe_stats(efx, NULL); 350 + case ETH_SS_TEST: 351 + return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); 352 + default: 353 + return -EINVAL; 354 + } 355 + } 356 + 357 + void efx_ethtool_get_strings(struct net_device *net_dev, 358 + u32 string_set, u8 *strings) 359 + { 360 + struct efx_nic *efx = netdev_priv(net_dev); 361 + int i; 362 + 363 + switch (string_set) { 364 + case ETH_SS_STATS: 365 + strings += (efx->type->describe_stats(efx, strings) * 366 + ETH_GSTRING_LEN); 367 + for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) 368 + strlcpy(strings + i * ETH_GSTRING_LEN, 369 + efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); 370 + strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; 371 + strings += (efx_describe_per_queue_stats(efx, strings) * 372 + ETH_GSTRING_LEN); 373 + efx_ptp_describe_stats(efx, strings); 374 + break; 375 + case ETH_SS_TEST: 376 + efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); 377 + break; 378 + default: 379 + /* No other string sets */ 380 + break; 381 + } 382 + } 383 + 384 + void efx_ethtool_get_stats(struct net_device *net_dev, 385 + struct ethtool_stats *stats, 386 + u64 *data) 387 + { 388 + struct efx_nic *efx = netdev_priv(net_dev); 389 + const struct efx_sw_stat_desc *stat; 390 + struct efx_channel *channel; 391 + struct efx_tx_queue *tx_queue; 392 + struct efx_rx_queue *rx_queue; 393 + int i; 394 + 395 + spin_lock_bh(&efx->stats_lock); 396 + 397 + /* Get NIC statistics */ 398 + data += efx->type->update_stats(efx, data, NULL); 399 + 400 + /* Get software statistics */ 401 + for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { 402 + stat = &efx_sw_stat_desc[i]; 403 + switch (stat->source) { 404 + case EFX_ETHTOOL_STAT_SOURCE_nic: 405 + data[i] = stat->get_stat((void *)efx + stat->offset); 406 + break; 407 + case EFX_ETHTOOL_STAT_SOURCE_channel: 408 + data[i] = 0; 409 + efx_for_each_channel(channel, efx) 410 + data[i] += stat->get_stat((void *)channel + 411 + stat->offset); 412 + break; 413 + case EFX_ETHTOOL_STAT_SOURCE_tx_queue: 414 + data[i] = 0; 415 + efx_for_each_channel(channel, efx) { 416 + efx_for_each_channel_tx_queue(tx_queue, channel) 417 + data[i] += 418 + stat->get_stat((void *)tx_queue 419 + + stat->offset); 420 + } 421 + break; 422 + } 423 + } 424 + data += EFX_ETHTOOL_SW_STAT_COUNT; 425 + 426 + spin_unlock_bh(&efx->stats_lock); 427 + 428 + efx_for_each_channel(channel, efx) { 429 + if (efx_channel_has_tx_queues(channel)) { 430 + *data = 0; 431 + efx_for_each_channel_tx_queue(tx_queue, channel) { 432 + *data += tx_queue->tx_packets; 433 + } 434 + data++; 435 + } 436 + } 437 + efx_for_each_channel(channel, efx) { 438 + if (efx_channel_has_rx_queue(channel)) { 439 + *data = 0; 440 + efx_for_each_channel_rx_queue(rx_queue, channel) { 441 + *data += rx_queue->rx_packets; 442 + } 443 + data++; 444 + } 445 + } 446 + if (efx->xdp_tx_queue_count && efx->xdp_tx_queues) { 447 + int xdp; 448 + 449 + for (xdp = 0; xdp < efx->xdp_tx_queue_count; xdp++) { 450 + data[0] = efx->xdp_tx_queues[xdp]->tx_packets; 451 + data++; 452 + } 453 + } 454 + 455 + efx_ptp_update_stats(efx, data); 456 + }
+30
drivers/net/ethernet/sfc/ethtool_common.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /**************************************************************************** 3 + * Driver for Solarflare network controllers and boards 4 + * Copyright 2019 Solarflare Communications Inc. 5 + * 6 + * This program is free software; you can redistribute it and/or modify it 7 + * under the terms of the GNU General Public License version 2 as published 8 + * by the Free Software Foundation, incorporated herein by reference. 9 + */ 10 + 11 + #ifndef EFX_ETHTOOL_COMMON_H 12 + #define EFX_ETHTOOL_COMMON_H 13 + 14 + void efx_ethtool_get_drvinfo(struct net_device *net_dev, 15 + struct ethtool_drvinfo *info); 16 + u32 efx_ethtool_get_msglevel(struct net_device *net_dev); 17 + void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable); 18 + void efx_ethtool_get_pauseparam(struct net_device *net_dev, 19 + struct ethtool_pauseparam *pause); 20 + int efx_ethtool_fill_self_tests(struct efx_nic *efx, 21 + struct efx_self_tests *tests, 22 + u8 *strings, u64 *data); 23 + int efx_ethtool_get_sset_count(struct net_device *net_dev, int string_set); 24 + void efx_ethtool_get_strings(struct net_device *net_dev, u32 string_set, 25 + u8 *strings); 26 + void efx_ethtool_get_stats(struct net_device *net_dev, 27 + struct ethtool_stats *stats __attribute__ ((unused)), 28 + u64 *data); 29 + 30 + #endif