Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
| 3 | * Copyright 2005-2006 Fen Systems Ltd. |
Ben Hutchings | 906bb26 | 2009-11-29 15:16:19 +0000 | [diff] [blame] | 4 | * Copyright 2006-2009 Solarflare Communications Inc. |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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 | #include <linux/netdevice.h> |
| 12 | #include <linux/ethtool.h> |
| 13 | #include <linux/rtnetlink.h> |
| 14 | #include "net_driver.h" |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 15 | #include "workarounds.h" |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 16 | #include "selftest.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 17 | #include "efx.h" |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 18 | #include "filter.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 19 | #include "nic.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 20 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 21 | struct ethtool_string { |
| 22 | char name[ETH_GSTRING_LEN]; |
| 23 | }; |
| 24 | |
| 25 | struct efx_ethtool_stat { |
| 26 | const char *name; |
| 27 | enum { |
| 28 | EFX_ETHTOOL_STAT_SOURCE_mac_stats, |
| 29 | EFX_ETHTOOL_STAT_SOURCE_nic, |
| 30 | EFX_ETHTOOL_STAT_SOURCE_channel |
| 31 | } source; |
| 32 | unsigned offset; |
| 33 | u64(*get_stat) (void *field); /* Reader function */ |
| 34 | }; |
| 35 | |
| 36 | /* Initialiser for a struct #efx_ethtool_stat with type-checking */ |
| 37 | #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ |
| 38 | get_stat_function) { \ |
| 39 | .name = #stat_name, \ |
| 40 | .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ |
| 41 | .offset = ((((field_type *) 0) == \ |
| 42 | &((struct efx_##source_name *)0)->field) ? \ |
| 43 | offsetof(struct efx_##source_name, field) : \ |
| 44 | offsetof(struct efx_##source_name, field)), \ |
| 45 | .get_stat = get_stat_function, \ |
| 46 | } |
| 47 | |
| 48 | static u64 efx_get_uint_stat(void *field) |
| 49 | { |
| 50 | return *(unsigned int *)field; |
| 51 | } |
| 52 | |
| 53 | static u64 efx_get_ulong_stat(void *field) |
| 54 | { |
| 55 | return *(unsigned long *)field; |
| 56 | } |
| 57 | |
| 58 | static u64 efx_get_u64_stat(void *field) |
| 59 | { |
| 60 | return *(u64 *) field; |
| 61 | } |
| 62 | |
| 63 | static u64 efx_get_atomic_stat(void *field) |
| 64 | { |
| 65 | return atomic_read((atomic_t *) field); |
| 66 | } |
| 67 | |
| 68 | #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \ |
| 69 | EFX_ETHTOOL_STAT(field, mac_stats, field, \ |
| 70 | unsigned long, efx_get_ulong_stat) |
| 71 | |
| 72 | #define EFX_ETHTOOL_U64_MAC_STAT(field) \ |
| 73 | EFX_ETHTOOL_STAT(field, mac_stats, field, \ |
| 74 | u64, efx_get_u64_stat) |
| 75 | |
| 76 | #define EFX_ETHTOOL_UINT_NIC_STAT(name) \ |
| 77 | EFX_ETHTOOL_STAT(name, nic, n_##name, \ |
| 78 | unsigned int, efx_get_uint_stat) |
| 79 | |
| 80 | #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ |
| 81 | EFX_ETHTOOL_STAT(field, nic, field, \ |
| 82 | atomic_t, efx_get_atomic_stat) |
| 83 | |
| 84 | #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ |
| 85 | EFX_ETHTOOL_STAT(field, channel, n_##field, \ |
| 86 | unsigned int, efx_get_uint_stat) |
| 87 | |
| 88 | static struct efx_ethtool_stat efx_ethtool_stats[] = { |
| 89 | EFX_ETHTOOL_U64_MAC_STAT(tx_bytes), |
| 90 | EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes), |
| 91 | EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes), |
| 92 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets), |
| 93 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad), |
| 94 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause), |
| 95 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_control), |
| 96 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast), |
| 97 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast), |
| 98 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast), |
| 99 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64), |
| 100 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_64), |
| 101 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127), |
| 102 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255), |
| 103 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511), |
| 104 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023), |
| 105 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx), |
| 106 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo), |
| 107 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo), |
| 108 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision), |
| 109 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision), |
| 110 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision), |
| 111 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision), |
| 112 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred), |
| 113 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision), |
| 114 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred), |
| 115 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp), |
| 116 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error), |
| 117 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error), |
| 118 | EFX_ETHTOOL_U64_MAC_STAT(rx_bytes), |
| 119 | EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes), |
| 120 | EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes), |
| 121 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets), |
| 122 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_good), |
| 123 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad), |
| 124 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause), |
| 125 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_control), |
| 126 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast), |
| 127 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast), |
| 128 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast), |
| 129 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64), |
| 130 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_64), |
| 131 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127), |
| 132 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255), |
| 133 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511), |
| 134 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023), |
| 135 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx), |
| 136 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo), |
| 137 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo), |
| 138 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64), |
| 139 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx), |
| 140 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo), |
| 141 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo), |
| 142 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow), |
| 143 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed), |
| 144 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier), |
| 145 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error), |
| 146 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error), |
| 147 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error), |
| 148 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error), |
| 149 | EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt), |
| 150 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
| 151 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), |
| 152 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), |
| 153 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), |
Ben Hutchings | c1ac403 | 2009-11-28 05:36:29 +0000 | [diff] [blame] | 154 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 155 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
| 156 | }; |
| 157 | |
| 158 | /* Number of ethtool statistics */ |
| 159 | #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats) |
| 160 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 161 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 162 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 163 | /************************************************************************** |
| 164 | * |
| 165 | * Ethtool operations |
| 166 | * |
| 167 | ************************************************************************** |
| 168 | */ |
| 169 | |
| 170 | /* Identify device by flashing LEDs */ |
Ben Hutchings | 65f667f | 2008-12-12 21:32:10 -0800 | [diff] [blame] | 171 | static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 172 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 173 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 174 | |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 175 | do { |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 176 | efx->type->set_id_led(efx, EFX_LED_ON); |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 177 | schedule_timeout_interruptible(HZ / 2); |
| 178 | |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 179 | efx->type->set_id_led(efx, EFX_LED_OFF); |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 180 | schedule_timeout_interruptible(HZ / 2); |
| 181 | } while (!signal_pending(current) && --count != 0); |
| 182 | |
Ben Hutchings | 06629f0 | 2009-11-29 03:43:43 +0000 | [diff] [blame] | 183 | efx->type->set_id_led(efx, EFX_LED_DEFAULT); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | /* This must be called with rtnl_lock held. */ |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 188 | static int efx_ethtool_get_settings(struct net_device *net_dev, |
| 189 | struct ethtool_cmd *ecmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 190 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 191 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 192 | struct efx_link_state *link_state = &efx->link_state; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 193 | |
| 194 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 195 | efx->phy_op->get_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 196 | mutex_unlock(&efx->mac_lock); |
| 197 | |
Ben Hutchings | 754c653 | 2010-02-03 09:31:57 +0000 | [diff] [blame] | 198 | /* GMAC does not support 1000Mbps HD */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 199 | ecmd->supported &= ~SUPPORTED_1000baseT_Half; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 200 | /* Both MACs support pause frames (bidirectional and respond-only) */ |
| 201 | ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; |
| 202 | |
| 203 | if (LOOPBACK_INTERNAL(efx)) { |
| 204 | ecmd->speed = link_state->speed; |
| 205 | ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF; |
| 206 | } |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 207 | |
| 208 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* This must be called with rtnl_lock held. */ |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 212 | static int efx_ethtool_set_settings(struct net_device *net_dev, |
| 213 | struct ethtool_cmd *ecmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 214 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 215 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 216 | int rc; |
| 217 | |
Ben Hutchings | 754c653 | 2010-02-03 09:31:57 +0000 | [diff] [blame] | 218 | /* GMAC does not support 1000Mbps HD */ |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 219 | if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 220 | netif_dbg(efx, drv, efx->net_dev, |
| 221 | "rejecting unsupported 1000Mbps HD setting\n"); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 222 | return -EINVAL; |
| 223 | } |
| 224 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 225 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 226 | rc = efx->phy_op->set_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 227 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 228 | return rc; |
| 229 | } |
| 230 | |
| 231 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, |
| 232 | struct ethtool_drvinfo *info) |
| 233 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 234 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 235 | |
Ben Hutchings | c5d5f5f | 2010-06-23 11:30:26 +0000 | [diff] [blame] | 236 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 237 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 238 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) |
| 239 | siena_print_fwver(efx, info->fw_version, |
| 240 | sizeof(info->fw_version)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 241 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
| 242 | } |
| 243 | |
Ben Hutchings | 5b98c1b | 2010-06-21 03:06:53 +0000 | [diff] [blame] | 244 | static int efx_ethtool_get_regs_len(struct net_device *net_dev) |
| 245 | { |
| 246 | return efx_nic_get_regs_len(netdev_priv(net_dev)); |
| 247 | } |
| 248 | |
| 249 | static void efx_ethtool_get_regs(struct net_device *net_dev, |
| 250 | struct ethtool_regs *regs, void *buf) |
| 251 | { |
| 252 | struct efx_nic *efx = netdev_priv(net_dev); |
| 253 | |
| 254 | regs->version = efx->type->revision; |
| 255 | efx_nic_get_regs(efx, buf); |
| 256 | } |
| 257 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 258 | static u32 efx_ethtool_get_msglevel(struct net_device *net_dev) |
| 259 | { |
| 260 | struct efx_nic *efx = netdev_priv(net_dev); |
| 261 | return efx->msg_enable; |
| 262 | } |
| 263 | |
| 264 | static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) |
| 265 | { |
| 266 | struct efx_nic *efx = netdev_priv(net_dev); |
| 267 | efx->msg_enable = msg_enable; |
| 268 | } |
| 269 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 270 | /** |
| 271 | * efx_fill_test - fill in an individual self-test entry |
| 272 | * @test_index: Index of the test |
| 273 | * @strings: Ethtool strings, or %NULL |
| 274 | * @data: Ethtool test results, or %NULL |
| 275 | * @test: Pointer to test result (used only if data != %NULL) |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 276 | * @unit_format: Unit name format (e.g. "chan\%d") |
| 277 | * @unit_id: Unit id (e.g. 0 for "chan0") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 278 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 279 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 280 | * |
| 281 | * Fill in an individual self-test entry. |
| 282 | */ |
| 283 | static void efx_fill_test(unsigned int test_index, |
| 284 | struct ethtool_string *strings, u64 *data, |
| 285 | int *test, const char *unit_format, int unit_id, |
| 286 | const char *test_format, const char *test_id) |
| 287 | { |
| 288 | struct ethtool_string unit_str, test_str; |
| 289 | |
| 290 | /* Fill data value, if applicable */ |
| 291 | if (data) |
| 292 | data[test_index] = *test; |
| 293 | |
| 294 | /* Fill string, if applicable */ |
| 295 | if (strings) { |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 296 | if (strchr(unit_format, '%')) |
| 297 | snprintf(unit_str.name, sizeof(unit_str.name), |
| 298 | unit_format, unit_id); |
| 299 | else |
| 300 | strcpy(unit_str.name, unit_format); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 301 | snprintf(test_str.name, sizeof(test_str.name), |
| 302 | test_format, test_id); |
| 303 | snprintf(strings[test_index].name, |
| 304 | sizeof(strings[test_index].name), |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 305 | "%-6s %-24s", unit_str.name, test_str.name); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 309 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 310 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
| 311 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue |
| 312 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 313 | "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 314 | |
| 315 | /** |
| 316 | * efx_fill_loopback_test - fill in a block of loopback self-test entries |
| 317 | * @efx: Efx NIC |
| 318 | * @lb_tests: Efx loopback self-test results structure |
| 319 | * @mode: Loopback test mode |
| 320 | * @test_index: Starting index of the test |
| 321 | * @strings: Ethtool strings, or %NULL |
| 322 | * @data: Ethtool test results, or %NULL |
| 323 | */ |
| 324 | static int efx_fill_loopback_test(struct efx_nic *efx, |
| 325 | struct efx_loopback_self_tests *lb_tests, |
| 326 | enum efx_loopback_mode mode, |
| 327 | unsigned int test_index, |
| 328 | struct ethtool_string *strings, u64 *data) |
| 329 | { |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 330 | struct efx_channel *channel = efx_get_channel(efx, 0); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 331 | struct efx_tx_queue *tx_queue; |
| 332 | |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 333 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 334 | efx_fill_test(test_index++, strings, data, |
| 335 | &lb_tests->tx_sent[tx_queue->queue], |
| 336 | EFX_TX_QUEUE_NAME(tx_queue), |
| 337 | EFX_LOOPBACK_NAME(mode, "tx_sent")); |
| 338 | efx_fill_test(test_index++, strings, data, |
| 339 | &lb_tests->tx_done[tx_queue->queue], |
| 340 | EFX_TX_QUEUE_NAME(tx_queue), |
| 341 | EFX_LOOPBACK_NAME(mode, "tx_done")); |
| 342 | } |
| 343 | efx_fill_test(test_index++, strings, data, |
| 344 | &lb_tests->rx_good, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 345 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 346 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
| 347 | efx_fill_test(test_index++, strings, data, |
| 348 | &lb_tests->rx_bad, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 349 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 350 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
| 351 | |
| 352 | return test_index; |
| 353 | } |
| 354 | |
| 355 | /** |
| 356 | * efx_ethtool_fill_self_tests - get self-test details |
| 357 | * @efx: Efx NIC |
| 358 | * @tests: Efx self-test results structure, or %NULL |
| 359 | * @strings: Ethtool strings, or %NULL |
| 360 | * @data: Ethtool test results, or %NULL |
| 361 | */ |
| 362 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, |
| 363 | struct efx_self_tests *tests, |
| 364 | struct ethtool_string *strings, |
| 365 | u64 *data) |
| 366 | { |
| 367 | struct efx_channel *channel; |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 368 | unsigned int n = 0, i; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 369 | enum efx_loopback_mode mode; |
| 370 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 371 | efx_fill_test(n++, strings, data, &tests->phy_alive, |
| 372 | "phy", 0, "alive", NULL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 373 | efx_fill_test(n++, strings, data, &tests->nvram, |
| 374 | "core", 0, "nvram", NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 375 | efx_fill_test(n++, strings, data, &tests->interrupt, |
| 376 | "core", 0, "interrupt", NULL); |
| 377 | |
| 378 | /* Event queues */ |
| 379 | efx_for_each_channel(channel, efx) { |
| 380 | efx_fill_test(n++, strings, data, |
| 381 | &tests->eventq_dma[channel->channel], |
| 382 | EFX_CHANNEL_NAME(channel), |
| 383 | "eventq.dma", NULL); |
| 384 | efx_fill_test(n++, strings, data, |
| 385 | &tests->eventq_int[channel->channel], |
| 386 | EFX_CHANNEL_NAME(channel), |
| 387 | "eventq.int", NULL); |
| 388 | efx_fill_test(n++, strings, data, |
| 389 | &tests->eventq_poll[channel->channel], |
| 390 | EFX_CHANNEL_NAME(channel), |
| 391 | "eventq.poll", NULL); |
| 392 | } |
| 393 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 394 | efx_fill_test(n++, strings, data, &tests->registers, |
| 395 | "core", 0, "registers", NULL); |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 396 | |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 397 | if (efx->phy_op->run_tests != NULL) { |
| 398 | EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL); |
| 399 | |
| 400 | for (i = 0; true; ++i) { |
| 401 | const char *name; |
| 402 | |
| 403 | EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); |
| 404 | name = efx->phy_op->test_name(efx, i); |
| 405 | if (name == NULL) |
| 406 | break; |
| 407 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 408 | efx_fill_test(n++, strings, data, &tests->phy_ext[i], |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 409 | "phy", 0, name, NULL); |
| 410 | } |
| 411 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 412 | |
| 413 | /* Loopback tests */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 414 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 415 | if (!(efx->loopback_modes & (1 << mode))) |
| 416 | continue; |
| 417 | n = efx_fill_loopback_test(efx, |
| 418 | &tests->loopback[mode], mode, n, |
| 419 | strings, data); |
| 420 | } |
| 421 | |
| 422 | return n; |
| 423 | } |
| 424 | |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 425 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
| 426 | int string_set) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 427 | { |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 428 | switch (string_set) { |
| 429 | case ETH_SS_STATS: |
| 430 | return EFX_ETHTOOL_NUM_STATS; |
| 431 | case ETH_SS_TEST: |
| 432 | return efx_ethtool_fill_self_tests(netdev_priv(net_dev), |
| 433 | NULL, NULL, NULL); |
| 434 | default: |
| 435 | return -EINVAL; |
| 436 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 439 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
| 440 | u32 string_set, u8 *strings) |
| 441 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 442 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 443 | struct ethtool_string *ethtool_strings = |
| 444 | (struct ethtool_string *)strings; |
| 445 | int i; |
| 446 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 447 | switch (string_set) { |
| 448 | case ETH_SS_STATS: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 449 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) |
| 450 | strncpy(ethtool_strings[i].name, |
| 451 | efx_ethtool_stats[i].name, |
| 452 | sizeof(ethtool_strings[i].name)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 453 | break; |
| 454 | case ETH_SS_TEST: |
| 455 | efx_ethtool_fill_self_tests(efx, NULL, |
| 456 | ethtool_strings, NULL); |
| 457 | break; |
| 458 | default: |
| 459 | /* No other string sets */ |
| 460 | break; |
| 461 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | static void efx_ethtool_get_stats(struct net_device *net_dev, |
| 465 | struct ethtool_stats *stats, |
| 466 | u64 *data) |
| 467 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 468 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 469 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
| 470 | struct efx_ethtool_stat *stat; |
| 471 | struct efx_channel *channel; |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 472 | struct rtnl_link_stats64 temp; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 473 | int i; |
| 474 | |
| 475 | EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS); |
| 476 | |
| 477 | /* Update MAC and NIC statistics */ |
Eric Dumazet | 2817273 | 2010-07-07 14:58:56 -0700 | [diff] [blame] | 478 | dev_get_stats(net_dev, &temp); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 479 | |
| 480 | /* Fill detailed statistics buffer */ |
| 481 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) { |
| 482 | stat = &efx_ethtool_stats[i]; |
| 483 | switch (stat->source) { |
| 484 | case EFX_ETHTOOL_STAT_SOURCE_mac_stats: |
| 485 | data[i] = stat->get_stat((void *)mac_stats + |
| 486 | stat->offset); |
| 487 | break; |
| 488 | case EFX_ETHTOOL_STAT_SOURCE_nic: |
| 489 | data[i] = stat->get_stat((void *)efx + stat->offset); |
| 490 | break; |
| 491 | case EFX_ETHTOOL_STAT_SOURCE_channel: |
| 492 | data[i] = 0; |
| 493 | efx_for_each_channel(channel, efx) |
| 494 | data[i] += stat->get_stat((void *)channel + |
| 495 | stat->offset); |
| 496 | break; |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | |
Ben Hutchings | 738a8f4 | 2009-11-29 15:16:05 +0000 | [diff] [blame] | 501 | static int efx_ethtool_set_tso(struct net_device *net_dev, u32 enable) |
| 502 | { |
| 503 | struct efx_nic *efx __attribute__ ((unused)) = netdev_priv(net_dev); |
| 504 | unsigned long features; |
| 505 | |
| 506 | features = NETIF_F_TSO; |
| 507 | if (efx->type->offload_features & NETIF_F_V6_CSUM) |
| 508 | features |= NETIF_F_TSO6; |
| 509 | |
| 510 | if (enable) |
| 511 | net_dev->features |= features; |
| 512 | else |
| 513 | net_dev->features &= ~features; |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
Ben Hutchings | c383b53 | 2009-11-29 15:11:02 +0000 | [diff] [blame] | 518 | static int efx_ethtool_set_tx_csum(struct net_device *net_dev, u32 enable) |
| 519 | { |
| 520 | struct efx_nic *efx = netdev_priv(net_dev); |
| 521 | unsigned long features = efx->type->offload_features & NETIF_F_ALL_CSUM; |
| 522 | |
| 523 | if (enable) |
| 524 | net_dev->features |= features; |
| 525 | else |
| 526 | net_dev->features &= ~features; |
| 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 531 | static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable) |
| 532 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 533 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 534 | |
| 535 | /* No way to stop the hardware doing the checks; we just |
| 536 | * ignore the result. |
| 537 | */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 538 | efx->rx_checksum_enabled = !!enable; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 539 | |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev) |
| 544 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 545 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 546 | |
| 547 | return efx->rx_checksum_enabled; |
| 548 | } |
| 549 | |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 550 | static int efx_ethtool_set_flags(struct net_device *net_dev, u32 data) |
| 551 | { |
| 552 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 553 | u32 supported = (efx->type->offload_features & |
| 554 | (ETH_FLAG_RXHASH | ETH_FLAG_NTUPLE)); |
| 555 | int rc; |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 556 | |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 557 | rc = ethtool_op_set_flags(net_dev, data, supported); |
| 558 | if (rc) |
| 559 | return rc; |
| 560 | |
| 561 | if (!(data & ETH_FLAG_NTUPLE)) { |
| 562 | efx_filter_table_clear(efx, EFX_FILTER_TABLE_RX_IP, |
| 563 | EFX_FILTER_PRI_MANUAL); |
| 564 | efx_filter_table_clear(efx, EFX_FILTER_TABLE_RX_MAC, |
| 565 | EFX_FILTER_PRI_MANUAL); |
| 566 | } |
| 567 | |
| 568 | return 0; |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 569 | } |
| 570 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 571 | static void efx_ethtool_self_test(struct net_device *net_dev, |
| 572 | struct ethtool_test *test, u64 *data) |
| 573 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 574 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 575 | struct efx_self_tests efx_tests; |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 576 | int already_up; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 577 | int rc; |
| 578 | |
| 579 | ASSERT_RTNL(); |
| 580 | if (efx->state != STATE_RUNNING) { |
| 581 | rc = -EIO; |
| 582 | goto fail1; |
| 583 | } |
| 584 | |
Ben Hutchings | ac33ac6 | 2010-12-07 18:29:52 +0000 | [diff] [blame^] | 585 | netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
| 586 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
| 587 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 588 | /* We need rx buffers and interrupts. */ |
| 589 | already_up = (efx->net_dev->flags & IFF_UP); |
| 590 | if (!already_up) { |
| 591 | rc = dev_open(efx->net_dev); |
| 592 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 593 | netif_err(efx, drv, efx->net_dev, |
| 594 | "failed opening device.\n"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 595 | goto fail2; |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | memset(&efx_tests, 0, sizeof(efx_tests)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 600 | |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 601 | rc = efx_selftest(efx, &efx_tests, test->flags); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 602 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 603 | if (!already_up) |
| 604 | dev_close(efx->net_dev); |
| 605 | |
Ben Hutchings | ac33ac6 | 2010-12-07 18:29:52 +0000 | [diff] [blame^] | 606 | netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
| 607 | rc == 0 ? "passed" : "failed", |
| 608 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 609 | |
| 610 | fail2: |
| 611 | fail1: |
| 612 | /* Fill ethtool results structures */ |
| 613 | efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data); |
| 614 | if (rc) |
| 615 | test->flags |= ETH_TEST_FL_FAILED; |
| 616 | } |
| 617 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 618 | /* Restart autonegotiation */ |
| 619 | static int efx_ethtool_nway_reset(struct net_device *net_dev) |
| 620 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 621 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 622 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 623 | return mdio45_nway_restart(&efx->mdio); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | static u32 efx_ethtool_get_link(struct net_device *net_dev) |
| 627 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 628 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 629 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 630 | return efx->link_state.up; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
| 634 | struct ethtool_coalesce *coalesce) |
| 635 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 636 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 637 | struct efx_channel *channel; |
| 638 | |
| 639 | memset(coalesce, 0, sizeof(*coalesce)); |
| 640 | |
| 641 | /* Find lowest IRQ moderation across all used TX queues */ |
| 642 | coalesce->tx_coalesce_usecs_irq = ~((u32) 0); |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 643 | efx_for_each_channel(channel, efx) { |
| 644 | if (!efx_channel_get_tx_queue(channel, 0)) |
| 645 | continue; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 646 | if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) { |
Ben Hutchings | a4900ac | 2010-04-28 09:30:43 +0000 | [diff] [blame] | 647 | if (channel->channel < efx->n_rx_channels) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 648 | coalesce->tx_coalesce_usecs_irq = |
| 649 | channel->irq_moderation; |
| 650 | else |
| 651 | coalesce->tx_coalesce_usecs_irq = 0; |
| 652 | } |
| 653 | } |
| 654 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 655 | coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive; |
| 656 | coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 657 | |
Ben Hutchings | 152b6a6 | 2009-11-29 03:43:56 +0000 | [diff] [blame] | 658 | coalesce->tx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION; |
| 659 | coalesce->rx_coalesce_usecs_irq *= EFX_IRQ_MOD_RESOLUTION; |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 660 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | /* Set coalescing parameters |
| 665 | * The difficulties occur for shared channels |
| 666 | */ |
| 667 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, |
| 668 | struct ethtool_coalesce *coalesce) |
| 669 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 670 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 671 | struct efx_channel *channel; |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 672 | unsigned tx_usecs, rx_usecs, adaptive; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 673 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 674 | if (coalesce->use_adaptive_tx_coalesce) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 675 | return -EOPNOTSUPP; |
| 676 | |
| 677 | if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 678 | netif_err(efx, drv, efx->net_dev, "invalid coalescing setting. " |
| 679 | "Only rx/tx_coalesce_usecs_irq are supported\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 680 | return -EOPNOTSUPP; |
| 681 | } |
| 682 | |
| 683 | rx_usecs = coalesce->rx_coalesce_usecs_irq; |
| 684 | tx_usecs = coalesce->tx_coalesce_usecs_irq; |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 685 | adaptive = coalesce->use_adaptive_rx_coalesce; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 686 | |
| 687 | /* If the channel is shared only allow RX parameters to be set */ |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 688 | efx_for_each_channel(channel, efx) { |
| 689 | if (efx_channel_get_rx_queue(channel) && |
| 690 | efx_channel_get_tx_queue(channel, 0) && |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 691 | tx_usecs) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 692 | netif_err(efx, drv, efx->net_dev, "Channel is shared. " |
| 693 | "Only RX coalescing may be set\n"); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 694 | return -EOPNOTSUPP; |
| 695 | } |
| 696 | } |
| 697 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 698 | efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 699 | efx_for_each_channel(channel, efx) |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 700 | efx->type->push_irq_moderation(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 701 | |
| 702 | return 0; |
| 703 | } |
| 704 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 705 | static void efx_ethtool_get_ringparam(struct net_device *net_dev, |
| 706 | struct ethtool_ringparam *ring) |
| 707 | { |
| 708 | struct efx_nic *efx = netdev_priv(net_dev); |
| 709 | |
| 710 | ring->rx_max_pending = EFX_MAX_DMAQ_SIZE; |
| 711 | ring->tx_max_pending = EFX_MAX_DMAQ_SIZE; |
| 712 | ring->rx_mini_max_pending = 0; |
| 713 | ring->rx_jumbo_max_pending = 0; |
| 714 | ring->rx_pending = efx->rxq_entries; |
| 715 | ring->tx_pending = efx->txq_entries; |
| 716 | ring->rx_mini_pending = 0; |
| 717 | ring->rx_jumbo_pending = 0; |
| 718 | } |
| 719 | |
| 720 | static int efx_ethtool_set_ringparam(struct net_device *net_dev, |
| 721 | struct ethtool_ringparam *ring) |
| 722 | { |
| 723 | struct efx_nic *efx = netdev_priv(net_dev); |
| 724 | |
| 725 | if (ring->rx_mini_pending || ring->rx_jumbo_pending || |
| 726 | ring->rx_pending > EFX_MAX_DMAQ_SIZE || |
| 727 | ring->tx_pending > EFX_MAX_DMAQ_SIZE) |
| 728 | return -EINVAL; |
| 729 | |
| 730 | if (ring->rx_pending < EFX_MIN_RING_SIZE || |
| 731 | ring->tx_pending < EFX_MIN_RING_SIZE) { |
| 732 | netif_err(efx, drv, efx->net_dev, |
| 733 | "TX and RX queues cannot be smaller than %ld\n", |
| 734 | EFX_MIN_RING_SIZE); |
| 735 | return -EINVAL; |
| 736 | } |
| 737 | |
| 738 | return efx_realloc_channels(efx, ring->rx_pending, ring->tx_pending); |
| 739 | } |
| 740 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 741 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
| 742 | struct ethtool_pauseparam *pause) |
| 743 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 744 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 745 | enum efx_fc_type wanted_fc, old_fc; |
| 746 | u32 old_adv; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 747 | bool reset; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 748 | int rc = 0; |
| 749 | |
| 750 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 751 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 752 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
| 753 | (pause->tx_pause ? EFX_FC_TX : 0) | |
| 754 | (pause->autoneg ? EFX_FC_AUTO : 0)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 755 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 756 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 757 | netif_dbg(efx, drv, efx->net_dev, |
| 758 | "Flow control unsupported: tx ON rx OFF\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 759 | rc = -EINVAL; |
| 760 | goto out; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 761 | } |
| 762 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 763 | if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 764 | netif_dbg(efx, drv, efx->net_dev, |
| 765 | "Autonegotiation is disabled\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 766 | rc = -EINVAL; |
| 767 | goto out; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /* TX flow control may automatically turn itself off if the |
| 771 | * link partner (intermittently) stops responding to pause |
| 772 | * frames. There isn't any indication that this has happened, |
| 773 | * so the best we do is leave it up to the user to spot this |
| 774 | * and fix it be cycling transmit flow control on this end. */ |
| 775 | reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX); |
| 776 | if (EFX_WORKAROUND_11482(efx) && reset) { |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 777 | if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) { |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 778 | /* Recover by resetting the EM block */ |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 779 | falcon_stop_nic_stats(efx); |
| 780 | falcon_drain_tx_fifo(efx); |
| 781 | efx->mac_op->reconfigure(efx); |
| 782 | falcon_start_nic_stats(efx); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 783 | } else { |
| 784 | /* Schedule a reset to recover */ |
| 785 | efx_schedule_reset(efx, RESET_TYPE_INVISIBLE); |
| 786 | } |
| 787 | } |
| 788 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 789 | old_adv = efx->link_advertising; |
| 790 | old_fc = efx->wanted_fc; |
| 791 | efx_link_set_wanted_fc(efx, wanted_fc); |
| 792 | if (efx->link_advertising != old_adv || |
| 793 | (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { |
| 794 | rc = efx->phy_op->reconfigure(efx); |
| 795 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 796 | netif_err(efx, drv, efx->net_dev, |
| 797 | "Unable to advertise requested flow " |
| 798 | "control setting\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 799 | goto out; |
| 800 | } |
| 801 | } |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 802 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 803 | /* Reconfigure the MAC. The PHY *may* generate a link state change event |
| 804 | * if the user just changed the advertised capabilities, but there's no |
| 805 | * harm doing this twice */ |
| 806 | efx->mac_op->reconfigure(efx); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 807 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 808 | out: |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 809 | mutex_unlock(&efx->mac_lock); |
| 810 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 811 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, |
| 815 | struct ethtool_pauseparam *pause) |
| 816 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 817 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 818 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 819 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
| 820 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); |
| 821 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 825 | static void efx_ethtool_get_wol(struct net_device *net_dev, |
| 826 | struct ethtool_wolinfo *wol) |
| 827 | { |
| 828 | struct efx_nic *efx = netdev_priv(net_dev); |
| 829 | return efx->type->get_wol(efx, wol); |
| 830 | } |
| 831 | |
| 832 | |
| 833 | static int efx_ethtool_set_wol(struct net_device *net_dev, |
| 834 | struct ethtool_wolinfo *wol) |
| 835 | { |
| 836 | struct efx_nic *efx = netdev_priv(net_dev); |
| 837 | return efx->type->set_wol(efx, wol->wolopts); |
| 838 | } |
| 839 | |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 840 | static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 841 | { |
| 842 | struct efx_nic *efx = netdev_priv(net_dev); |
| 843 | enum reset_type method; |
| 844 | enum { |
| 845 | ETH_RESET_EFX_INVISIBLE = (ETH_RESET_DMA | ETH_RESET_FILTER | |
| 846 | ETH_RESET_OFFLOAD | ETH_RESET_MAC) |
| 847 | }; |
| 848 | |
| 849 | /* Check for minimal reset flags */ |
| 850 | if ((*flags & ETH_RESET_EFX_INVISIBLE) != ETH_RESET_EFX_INVISIBLE) |
| 851 | return -EINVAL; |
| 852 | *flags ^= ETH_RESET_EFX_INVISIBLE; |
| 853 | method = RESET_TYPE_INVISIBLE; |
| 854 | |
| 855 | if (*flags & ETH_RESET_PHY) { |
| 856 | *flags ^= ETH_RESET_PHY; |
| 857 | method = RESET_TYPE_ALL; |
| 858 | } |
| 859 | |
| 860 | if ((*flags & efx->type->reset_world_flags) == |
| 861 | efx->type->reset_world_flags) { |
| 862 | *flags ^= efx->type->reset_world_flags; |
| 863 | method = RESET_TYPE_WORLD; |
| 864 | } |
| 865 | |
| 866 | return efx_reset(efx, method); |
| 867 | } |
| 868 | |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 869 | static int |
| 870 | efx_ethtool_get_rxnfc(struct net_device *net_dev, |
| 871 | struct ethtool_rxnfc *info, void *rules __always_unused) |
| 872 | { |
| 873 | struct efx_nic *efx = netdev_priv(net_dev); |
| 874 | |
| 875 | switch (info->cmd) { |
| 876 | case ETHTOOL_GRXRINGS: |
| 877 | info->data = efx->n_rx_channels; |
| 878 | return 0; |
| 879 | |
| 880 | case ETHTOOL_GRXFH: { |
| 881 | unsigned min_revision = 0; |
| 882 | |
| 883 | info->data = 0; |
| 884 | switch (info->flow_type) { |
| 885 | case TCP_V4_FLOW: |
| 886 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 887 | /* fall through */ |
| 888 | case UDP_V4_FLOW: |
| 889 | case SCTP_V4_FLOW: |
| 890 | case AH_ESP_V4_FLOW: |
| 891 | case IPV4_FLOW: |
| 892 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
| 893 | min_revision = EFX_REV_FALCON_B0; |
| 894 | break; |
| 895 | case TCP_V6_FLOW: |
| 896 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 897 | /* fall through */ |
| 898 | case UDP_V6_FLOW: |
| 899 | case SCTP_V6_FLOW: |
| 900 | case AH_ESP_V6_FLOW: |
| 901 | case IPV6_FLOW: |
| 902 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
| 903 | min_revision = EFX_REV_SIENA_A0; |
| 904 | break; |
| 905 | default: |
| 906 | break; |
| 907 | } |
| 908 | if (efx_nic_rev(efx) < min_revision) |
| 909 | info->data = 0; |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | default: |
| 914 | return -EOPNOTSUPP; |
| 915 | } |
| 916 | } |
| 917 | |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 918 | static int efx_ethtool_set_rx_ntuple(struct net_device *net_dev, |
| 919 | struct ethtool_rx_ntuple *ntuple) |
| 920 | { |
| 921 | struct efx_nic *efx = netdev_priv(net_dev); |
| 922 | struct ethtool_tcpip4_spec *ip_entry = &ntuple->fs.h_u.tcp_ip4_spec; |
| 923 | struct ethtool_tcpip4_spec *ip_mask = &ntuple->fs.m_u.tcp_ip4_spec; |
| 924 | struct ethhdr *mac_entry = &ntuple->fs.h_u.ether_spec; |
| 925 | struct ethhdr *mac_mask = &ntuple->fs.m_u.ether_spec; |
| 926 | struct efx_filter_spec filter; |
| 927 | |
| 928 | /* Range-check action */ |
| 929 | if (ntuple->fs.action < ETHTOOL_RXNTUPLE_ACTION_CLEAR || |
| 930 | ntuple->fs.action >= (s32)efx->n_rx_channels) |
| 931 | return -EINVAL; |
| 932 | |
| 933 | if (~ntuple->fs.data_mask) |
| 934 | return -EINVAL; |
| 935 | |
| 936 | switch (ntuple->fs.flow_type) { |
| 937 | case TCP_V4_FLOW: |
| 938 | case UDP_V4_FLOW: |
| 939 | /* Must match all of destination, */ |
| 940 | if (ip_mask->ip4dst | ip_mask->pdst) |
| 941 | return -EINVAL; |
| 942 | /* all or none of source, */ |
| 943 | if ((ip_mask->ip4src | ip_mask->psrc) && |
| 944 | ((__force u32)~ip_mask->ip4src | |
| 945 | (__force u16)~ip_mask->psrc)) |
| 946 | return -EINVAL; |
| 947 | /* and nothing else */ |
| 948 | if ((u8)~ip_mask->tos | (u16)~ntuple->fs.vlan_tag_mask) |
| 949 | return -EINVAL; |
| 950 | break; |
| 951 | case ETHER_FLOW: |
| 952 | /* Must match all of destination, */ |
| 953 | if (!is_zero_ether_addr(mac_mask->h_dest)) |
| 954 | return -EINVAL; |
| 955 | /* all or none of VID, */ |
| 956 | if (ntuple->fs.vlan_tag_mask != 0xf000 && |
| 957 | ntuple->fs.vlan_tag_mask != 0xffff) |
| 958 | return -EINVAL; |
| 959 | /* and nothing else */ |
| 960 | if (!is_broadcast_ether_addr(mac_mask->h_source) || |
| 961 | mac_mask->h_proto != htons(0xffff)) |
| 962 | return -EINVAL; |
| 963 | break; |
| 964 | default: |
| 965 | return -EINVAL; |
| 966 | } |
| 967 | |
| 968 | filter.priority = EFX_FILTER_PRI_MANUAL; |
| 969 | filter.flags = 0; |
| 970 | |
| 971 | switch (ntuple->fs.flow_type) { |
| 972 | case TCP_V4_FLOW: |
| 973 | if (!ip_mask->ip4src) |
| 974 | efx_filter_set_rx_tcp_full(&filter, |
| 975 | htonl(ip_entry->ip4src), |
| 976 | htons(ip_entry->psrc), |
| 977 | htonl(ip_entry->ip4dst), |
| 978 | htons(ip_entry->pdst)); |
| 979 | else |
| 980 | efx_filter_set_rx_tcp_wild(&filter, |
| 981 | htonl(ip_entry->ip4dst), |
| 982 | htons(ip_entry->pdst)); |
| 983 | break; |
| 984 | case UDP_V4_FLOW: |
| 985 | if (!ip_mask->ip4src) |
| 986 | efx_filter_set_rx_udp_full(&filter, |
| 987 | htonl(ip_entry->ip4src), |
| 988 | htons(ip_entry->psrc), |
| 989 | htonl(ip_entry->ip4dst), |
| 990 | htons(ip_entry->pdst)); |
| 991 | else |
| 992 | efx_filter_set_rx_udp_wild(&filter, |
| 993 | htonl(ip_entry->ip4dst), |
| 994 | htons(ip_entry->pdst)); |
| 995 | break; |
| 996 | case ETHER_FLOW: |
| 997 | if (ntuple->fs.vlan_tag_mask == 0xf000) |
| 998 | efx_filter_set_rx_mac_full(&filter, |
| 999 | ntuple->fs.vlan_tag & 0xfff, |
| 1000 | mac_entry->h_dest); |
| 1001 | else |
| 1002 | efx_filter_set_rx_mac_wild(&filter, mac_entry->h_dest); |
| 1003 | break; |
| 1004 | } |
| 1005 | |
| 1006 | if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_CLEAR) { |
| 1007 | return efx_filter_remove_filter(efx, &filter); |
| 1008 | } else { |
| 1009 | if (ntuple->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP) |
| 1010 | filter.dmaq_id = 0xfff; |
| 1011 | else |
| 1012 | filter.dmaq_id = ntuple->fs.action; |
| 1013 | return efx_filter_insert_filter(efx, &filter, true); |
| 1014 | } |
| 1015 | } |
| 1016 | |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1017 | static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, |
| 1018 | struct ethtool_rxfh_indir *indir) |
| 1019 | { |
| 1020 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1021 | size_t copy_size = |
| 1022 | min_t(size_t, indir->size, ARRAY_SIZE(efx->rx_indir_table)); |
| 1023 | |
| 1024 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) |
| 1025 | return -EOPNOTSUPP; |
| 1026 | |
| 1027 | indir->size = ARRAY_SIZE(efx->rx_indir_table); |
| 1028 | memcpy(indir->ring_index, efx->rx_indir_table, |
| 1029 | copy_size * sizeof(indir->ring_index[0])); |
| 1030 | return 0; |
| 1031 | } |
| 1032 | |
| 1033 | static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev, |
| 1034 | const struct ethtool_rxfh_indir *indir) |
| 1035 | { |
| 1036 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1037 | size_t i; |
| 1038 | |
| 1039 | if (efx_nic_rev(efx) < EFX_REV_FALCON_B0) |
| 1040 | return -EOPNOTSUPP; |
| 1041 | |
| 1042 | /* Validate size and indices */ |
| 1043 | if (indir->size != ARRAY_SIZE(efx->rx_indir_table)) |
| 1044 | return -EINVAL; |
| 1045 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); i++) |
| 1046 | if (indir->ring_index[i] >= efx->n_rx_channels) |
| 1047 | return -EINVAL; |
| 1048 | |
| 1049 | memcpy(efx->rx_indir_table, indir->ring_index, |
| 1050 | sizeof(efx->rx_indir_table)); |
| 1051 | efx_nic_push_rx_indir_table(efx); |
| 1052 | return 0; |
| 1053 | } |
| 1054 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 1055 | const struct ethtool_ops efx_ethtool_ops = { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1056 | .get_settings = efx_ethtool_get_settings, |
| 1057 | .set_settings = efx_ethtool_set_settings, |
| 1058 | .get_drvinfo = efx_ethtool_get_drvinfo, |
Ben Hutchings | 5b98c1b | 2010-06-21 03:06:53 +0000 | [diff] [blame] | 1059 | .get_regs_len = efx_ethtool_get_regs_len, |
| 1060 | .get_regs = efx_ethtool_get_regs, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1061 | .get_msglevel = efx_ethtool_get_msglevel, |
| 1062 | .set_msglevel = efx_ethtool_set_msglevel, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1063 | .nway_reset = efx_ethtool_nway_reset, |
| 1064 | .get_link = efx_ethtool_get_link, |
| 1065 | .get_coalesce = efx_ethtool_get_coalesce, |
| 1066 | .set_coalesce = efx_ethtool_set_coalesce, |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 1067 | .get_ringparam = efx_ethtool_get_ringparam, |
| 1068 | .set_ringparam = efx_ethtool_set_ringparam, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1069 | .get_pauseparam = efx_ethtool_get_pauseparam, |
| 1070 | .set_pauseparam = efx_ethtool_set_pauseparam, |
| 1071 | .get_rx_csum = efx_ethtool_get_rx_csum, |
| 1072 | .set_rx_csum = efx_ethtool_set_rx_csum, |
| 1073 | .get_tx_csum = ethtool_op_get_tx_csum, |
Ben Hutchings | c383b53 | 2009-11-29 15:11:02 +0000 | [diff] [blame] | 1074 | /* Need to enable/disable IPv6 too */ |
| 1075 | .set_tx_csum = efx_ethtool_set_tx_csum, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1076 | .get_sg = ethtool_op_get_sg, |
| 1077 | .set_sg = ethtool_op_set_sg, |
Ben Hutchings | b9b39b6 | 2008-05-07 12:51:12 +0100 | [diff] [blame] | 1078 | .get_tso = ethtool_op_get_tso, |
Ben Hutchings | 738a8f4 | 2009-11-29 15:16:05 +0000 | [diff] [blame] | 1079 | /* Need to enable/disable TSO-IPv6 too */ |
| 1080 | .set_tso = efx_ethtool_set_tso, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1081 | .get_flags = ethtool_op_get_flags, |
Ben Hutchings | 39c9cf0 | 2010-06-23 11:31:28 +0000 | [diff] [blame] | 1082 | .set_flags = efx_ethtool_set_flags, |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 1083 | .get_sset_count = efx_ethtool_get_sset_count, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 1084 | .self_test = efx_ethtool_self_test, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1085 | .get_strings = efx_ethtool_get_strings, |
| 1086 | .phys_id = efx_ethtool_phys_id, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1087 | .get_ethtool_stats = efx_ethtool_get_stats, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 1088 | .get_wol = efx_ethtool_get_wol, |
| 1089 | .set_wol = efx_ethtool_set_wol, |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 1090 | .reset = efx_ethtool_reset, |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1091 | .get_rxnfc = efx_ethtool_get_rxnfc, |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1092 | .set_rx_ntuple = efx_ethtool_set_rx_ntuple, |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1093 | .get_rxfh_indir = efx_ethtool_get_rxfh_indir, |
| 1094 | .set_rxfh_indir = efx_ethtool_set_rxfh_indir, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1095 | }; |