11 #include <linux/netdevice.h>
12 #include <linux/ethtool.h>
13 #include <linux/rtnetlink.h>
39 #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \
40 get_stat_function) { \
42 .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \
43 .offset = ((((field_type *) 0) == \
44 &((struct efx_##source_name *)0)->field) ? \
45 offsetof(struct efx_##source_name, field) : \
46 offsetof(struct efx_##source_name, field)), \
47 .get_stat = get_stat_function, \
50 static u64 efx_get_uint_stat(
void *
field)
52 return *(
unsigned int *)field;
55 static u64 efx_get_u64_stat(
void *
field)
57 return *(
u64 *) field;
60 static u64 efx_get_atomic_stat(
void *
field)
65 #define EFX_ETHTOOL_U64_MAC_STAT(field) \
66 EFX_ETHTOOL_STAT(field, mac_stats, field, \
67 u64, efx_get_u64_stat)
69 #define EFX_ETHTOOL_UINT_NIC_STAT(name) \
70 EFX_ETHTOOL_STAT(name, nic, n_##name, \
71 unsigned int, efx_get_uint_stat)
73 #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \
74 EFX_ETHTOOL_STAT(field, nic, field, \
75 atomic_t, efx_get_atomic_stat)
77 #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \
78 EFX_ETHTOOL_STAT(field, channel, n_##field, \
79 unsigned int, efx_get_uint_stat)
81 #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \
82 EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \
83 unsigned int, efx_get_uint_stat)
160 #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats)
162 #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB
172 static int efx_ethtool_phys_id(
struct net_device *net_dev,
175 struct efx_nic *efx = netdev_priv(net_dev);
192 efx->
type->set_id_led(efx, mode);
200 struct efx_nic *efx = netdev_priv(net_dev);
204 efx->
phy_op->get_settings(efx, ecmd);
213 ethtool_cmd_speed_set(ecmd, link_state->
speed);
221 static int efx_ethtool_set_settings(
struct net_device *net_dev,
224 struct efx_nic *efx = netdev_priv(net_dev);
228 if ((ethtool_cmd_speed(ecmd) ==
SPEED_1000) &&
231 "rejecting unsupported 1000Mbps HD setting\n");
236 rc = efx->
phy_op->set_settings(efx, ecmd);
241 static void efx_ethtool_get_drvinfo(
struct net_device *net_dev,
244 struct efx_nic *efx = netdev_priv(net_dev);
254 static int efx_ethtool_get_regs_len(
struct net_device *net_dev)
259 static void efx_ethtool_get_regs(
struct net_device *net_dev,
262 struct efx_nic *efx = netdev_priv(net_dev);
268 static u32 efx_ethtool_get_msglevel(
struct net_device *net_dev)
270 struct efx_nic *efx = netdev_priv(net_dev);
276 struct efx_nic *efx = netdev_priv(net_dev);
293 static void efx_fill_test(
unsigned int test_index,
295 int *
test,
const char *unit_format,
int unit_id,
296 const char *test_format,
const char *test_id)
302 data[test_index] = *
test;
306 if (
strchr(unit_format,
'%'))
307 snprintf(unit_str.name,
sizeof(unit_str.name),
308 unit_format, unit_id);
310 strcpy(unit_str.name, unit_format);
311 snprintf(test_str.name,
sizeof(test_str.name),
312 test_format, test_id);
314 sizeof(strings[test_index].name),
315 "%-6s %-24s", unit_str.name, test_str.name);
319 #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel
320 #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue
321 #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue
322 #define EFX_LOOPBACK_NAME(_mode, _counter) \
323 "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode)
334 static int efx_fill_loopback_test(
struct efx_nic *efx,
337 unsigned int test_index,
345 efx_fill_test(test_index++, strings, data,
349 efx_fill_test(test_index++, strings, data,
354 efx_fill_test(test_index++, strings, data,
358 efx_fill_test(test_index++, strings, data,
373 static int efx_ethtool_fill_self_tests(
struct efx_nic *efx,
379 unsigned int n = 0,
i;
382 efx_fill_test(n++, strings, data, &tests->
phy_alive,
383 "phy", 0,
"alive",
NULL);
384 efx_fill_test(n++, strings, data, &tests->
nvram,
385 "core", 0,
"nvram",
NULL);
386 efx_fill_test(n++, strings, data, &tests->
interrupt,
387 "core", 0,
"interrupt",
NULL);
391 efx_fill_test(n++, strings, data,
395 efx_fill_test(n++, strings, data,
401 efx_fill_test(n++, strings, data, &tests->
registers,
402 "core", 0,
"registers",
NULL);
407 for (
i = 0;
true; ++
i) {
411 name = efx->
phy_op->test_name(efx,
i);
415 efx_fill_test(n++, strings, data, &tests->
phy_ext[
i],
416 "phy", 0, name,
NULL);
424 n = efx_fill_loopback_test(efx,
432 static int efx_ethtool_get_sset_count(
struct net_device *net_dev,
435 switch (string_set) {
439 return efx_ethtool_fill_self_tests(netdev_priv(net_dev),
446 static void efx_ethtool_get_strings(
struct net_device *net_dev,
447 u32 string_set,
u8 *strings)
449 struct efx_nic *efx = netdev_priv(net_dev);
454 switch (string_set) {
457 strlcpy(ethtool_strings[i].name,
458 efx_ethtool_stats[i].name,
459 sizeof(ethtool_strings[i].name));
462 efx_ethtool_fill_self_tests(efx,
NULL,
463 ethtool_strings,
NULL);
471 static void efx_ethtool_get_stats(
struct net_device *net_dev,
475 struct efx_nic *efx = netdev_priv(net_dev);
487 efx->
type->update_stats(efx);
491 stat = &efx_ethtool_stats[
i];
493 case EFX_ETHTOOL_STAT_SOURCE_mac_stats:
494 data[
i] = stat->
get_stat((
void *)mac_stats +
497 case EFX_ETHTOOL_STAT_SOURCE_nic:
500 case EFX_ETHTOOL_STAT_SOURCE_channel:
503 data[i] += stat->get_stat((
void *)channel +
506 case EFX_ETHTOOL_STAT_SOURCE_tx_queue:
511 stat->get_stat((
void *)tx_queue
518 spin_unlock_bh(&efx->stats_lock);
524 struct efx_nic *efx = netdev_priv(net_dev);
529 efx_tests = kzalloc(
sizeof(*efx_tests),
GFP_KERNEL);
547 "failed opening device.\n");
558 rc == 0 ?
"passed" :
"failed",
563 efx_ethtool_fill_self_tests(efx, efx_tests,
NULL, data);
571 static int efx_ethtool_nway_reset(
struct net_device *net_dev)
573 struct efx_nic *efx = netdev_priv(net_dev);
607 static int efx_ethtool_get_coalesce(
struct net_device *net_dev,
610 struct efx_nic *efx = netdev_priv(net_dev);
611 unsigned int tx_usecs, rx_usecs;
625 static int efx_ethtool_set_coalesce(
struct net_device *net_dev,
628 struct efx_nic *efx = netdev_priv(net_dev);
630 unsigned int tx_usecs, rx_usecs;
631 bool adaptive, rx_may_override_tx;
662 efx->
type->push_irq_moderation(channel);
670 struct efx_nic *efx = netdev_priv(net_dev);
678 static int efx_ethtool_set_ringparam(
struct net_device *net_dev,
681 struct efx_nic *efx = netdev_priv(net_dev);
691 "RX queues cannot be smaller than %u\n",
699 "increasing TX queue size to minimum of %u\n",
705 static int efx_ethtool_set_pauseparam(
struct net_device *net_dev,
708 struct efx_nic *efx = netdev_priv(net_dev);
722 "Flow control unsupported: tx ON rx OFF\n");
729 "Autonegotiation is disabled\n");
757 (efx->
wanted_fc ^ old_fc) & EFX_FC_AUTO) {
758 rc = efx->
phy_op->reconfigure(efx);
761 "Unable to advertise requested flow "
762 "control setting\n");
770 efx->
type->reconfigure_mac(efx);
778 static void efx_ethtool_get_pauseparam(
struct net_device *net_dev,
781 struct efx_nic *efx = netdev_priv(net_dev);
789 static void efx_ethtool_get_wol(
struct net_device *net_dev,
792 struct efx_nic *efx = netdev_priv(net_dev);
793 return efx->
type->get_wol(efx, wol);
797 static int efx_ethtool_set_wol(
struct net_device *net_dev,
800 struct efx_nic *efx = netdev_priv(net_dev);
806 struct efx_nic *efx = netdev_priv(net_dev);
809 rc = efx->
type->map_reset_flags(flags);
817 static const u8 mac_addr_mc_mask[
ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
819 static int efx_ethtool_get_class_rule(
struct efx_nic *efx,
836 if (spec.dmaq_id == 0xfff)
865 &spec, &proto, &ip_entry->
ip4dst, &ip_entry->
pdst,
878 efx_ethtool_get_rxnfc(
struct net_device *net_dev,
881 struct efx_nic *efx = netdev_priv(net_dev);
889 unsigned min_revision = 0;
916 if (efx_nic_rev(efx) < min_revision)
933 return efx_ethtool_get_class_rule(efx, &info->
fs);
953 static int efx_ethtool_set_class_rule(
struct efx_nic *efx,
974 (rule->
m_ext.vlan_etype | rule->
m_ext.data[0] |
975 rule->
m_ext.data[1]))
998 if (ip_mask->
tos | rule->
m_ext.vlan_tci)
1022 if (!is_zero_ether_addr(mac_mask->
h_source) ||
1027 if (ether_addr_equal(mac_mask->
h_dest, mac_addr_mc_mask) &&
1028 vlan_tag_mask == 0) {
1029 if (is_multicast_ether_addr(mac_entry->
h_dest))
1037 else if (is_broadcast_ether_addr(mac_mask->
h_dest) &&
1038 (vlan_tag_mask == 0xfff || vlan_tag_mask == 0)) {
1064 static int efx_ethtool_set_rxnfc(
struct net_device *net_dev,
1067 struct efx_nic *efx = netdev_priv(net_dev);
1072 switch (info->
cmd) {
1074 return efx_ethtool_set_class_rule(efx, &info->
fs);
1085 static u32 efx_ethtool_get_rxfh_indir_size(
struct net_device *net_dev)
1087 struct efx_nic *efx = netdev_priv(net_dev);
1094 static int efx_ethtool_get_rxfh_indir(
struct net_device *net_dev, u32 *indir)
1096 struct efx_nic *efx = netdev_priv(net_dev);
1102 static int efx_ethtool_set_rxfh_indir(
struct net_device *net_dev,
1105 struct efx_nic *efx = netdev_priv(net_dev);
1112 static int efx_ethtool_get_module_eeprom(
struct net_device *net_dev,
1116 struct efx_nic *efx = netdev_priv(net_dev);
1123 ret = efx->
phy_op->get_module_eeprom(efx, ee, data);
1129 static int efx_ethtool_get_module_info(
struct net_device *net_dev,
1132 struct efx_nic *efx = netdev_priv(net_dev);
1139 ret = efx->
phy_op->get_module_info(efx, modinfo);
1146 .get_settings = efx_ethtool_get_settings,
1147 .set_settings = efx_ethtool_set_settings,
1148 .get_drvinfo = efx_ethtool_get_drvinfo,
1149 .get_regs_len = efx_ethtool_get_regs_len,
1150 .get_regs = efx_ethtool_get_regs,
1151 .get_msglevel = efx_ethtool_get_msglevel,
1152 .set_msglevel = efx_ethtool_set_msglevel,
1153 .nway_reset = efx_ethtool_nway_reset,
1155 .get_coalesce = efx_ethtool_get_coalesce,
1156 .set_coalesce = efx_ethtool_set_coalesce,
1157 .get_ringparam = efx_ethtool_get_ringparam,
1158 .set_ringparam = efx_ethtool_set_ringparam,
1159 .get_pauseparam = efx_ethtool_get_pauseparam,
1160 .set_pauseparam = efx_ethtool_set_pauseparam,
1161 .get_sset_count = efx_ethtool_get_sset_count,
1162 .self_test = efx_ethtool_self_test,
1163 .get_strings = efx_ethtool_get_strings,
1164 .set_phys_id = efx_ethtool_phys_id,
1165 .get_ethtool_stats = efx_ethtool_get_stats,
1166 .get_wol = efx_ethtool_get_wol,
1167 .set_wol = efx_ethtool_set_wol,
1168 .reset = efx_ethtool_reset,
1169 .get_rxnfc = efx_ethtool_get_rxnfc,
1170 .set_rxnfc = efx_ethtool_set_rxnfc,
1171 .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size,
1172 .get_rxfh_indir = efx_ethtool_get_rxfh_indir,
1173 .set_rxfh_indir = efx_ethtool_set_rxfh_indir,
1175 .get_module_info = efx_ethtool_get_module_info,
1176 .get_module_eeprom = efx_ethtool_get_module_eeprom,