Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1 | /**************************************************************************** |
Ben Hutchings | f7a6d2c | 2013-08-29 23:32:48 +0100 | [diff] [blame] | 2 | * Driver for Solarflare network controllers and boards |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 3 | * Copyright 2005-2006 Fen Systems Ltd. |
Ben Hutchings | f7a6d2c | 2013-08-29 23:32:48 +0100 | [diff] [blame] | 4 | * Copyright 2006-2013 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> |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 14 | #include <linux/in.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 15 | #include "net_driver.h" |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 16 | #include "workarounds.h" |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 17 | #include "selftest.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 18 | #include "efx.h" |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 19 | #include "filter.h" |
Ben Hutchings | 744093c | 2009-11-29 15:12:08 +0000 | [diff] [blame] | 20 | #include "nic.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 21 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 22 | struct efx_sw_stat_desc { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 23 | const char *name; |
| 24 | enum { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 25 | EFX_ETHTOOL_STAT_SOURCE_nic, |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 26 | EFX_ETHTOOL_STAT_SOURCE_channel, |
| 27 | EFX_ETHTOOL_STAT_SOURCE_tx_queue |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 28 | } source; |
| 29 | unsigned offset; |
| 30 | u64(*get_stat) (void *field); /* Reader function */ |
| 31 | }; |
| 32 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 33 | /* Initialiser for a struct efx_sw_stat_desc with type-checking */ |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 50 | static u64 efx_get_atomic_stat(void *field) |
| 51 | { |
| 52 | return atomic_read((atomic_t *) field); |
| 53 | } |
| 54 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 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 | |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 63 | #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \ |
| 64 | EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \ |
| 65 | unsigned int, efx_get_uint_stat) |
| 66 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 67 | static const struct efx_sw_stat_desc efx_sw_stat_desc[] = { |
Ben Hutchings | 02e1216 | 2013-04-27 01:55:21 +0100 | [diff] [blame] | 68 | EFX_ETHTOOL_UINT_TXQ_STAT(merge_events), |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 69 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts), |
| 70 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers), |
| 71 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets), |
Edward Cree | 46d1efd | 2016-11-17 10:52:36 +0000 | [diff] [blame] | 72 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_fallbacks), |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 73 | EFX_ETHTOOL_UINT_TXQ_STAT(pushes), |
Jon Cooper | ee45fd92c | 2013-09-02 18:24:29 +0100 | [diff] [blame] | 74 | EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets), |
Bert Kenward | e9117e5 | 2016-11-17 10:51:54 +0000 | [diff] [blame] | 75 | EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 76 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
| 77 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), |
| 78 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), |
| 79 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), |
Ben Hutchings | c1ac403 | 2009-11-28 05:36:29 +0000 | [diff] [blame] | 80 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 81 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 82 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events), |
| 83 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 84 | }; |
| 85 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 86 | #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 87 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 88 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 89 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 90 | /************************************************************************** |
| 91 | * |
| 92 | * Ethtool operations |
| 93 | * |
| 94 | ************************************************************************** |
| 95 | */ |
| 96 | |
| 97 | /* Identify device by flashing LEDs */ |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 98 | static int efx_ethtool_phys_id(struct net_device *net_dev, |
| 99 | enum ethtool_phys_id_state state) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 100 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 101 | struct efx_nic *efx = netdev_priv(net_dev); |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 102 | enum efx_led_mode mode = EFX_LED_DEFAULT; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 103 | |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 104 | switch (state) { |
| 105 | case ETHTOOL_ID_ON: |
| 106 | mode = EFX_LED_ON; |
| 107 | break; |
| 108 | case ETHTOOL_ID_OFF: |
| 109 | mode = EFX_LED_OFF; |
| 110 | break; |
| 111 | case ETHTOOL_ID_INACTIVE: |
| 112 | mode = EFX_LED_DEFAULT; |
| 113 | break; |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 114 | case ETHTOOL_ID_ACTIVE: |
| 115 | return 1; /* cycle on/off once per second */ |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 116 | } |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 117 | |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 118 | efx->type->set_id_led(efx, mode); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | /* This must be called with rtnl_lock held. */ |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 123 | static int |
| 124 | efx_ethtool_get_link_ksettings(struct net_device *net_dev, |
| 125 | struct ethtool_link_ksettings *cmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 126 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 127 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 128 | struct efx_link_state *link_state = &efx->link_state; |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 129 | u32 supported; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 130 | |
| 131 | mutex_lock(&efx->mac_lock); |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 132 | efx->phy_op->get_link_ksettings(efx, cmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 133 | mutex_unlock(&efx->mac_lock); |
| 134 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 135 | /* Both MACs support pause frames (bidirectional and respond-only) */ |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 136 | ethtool_convert_link_mode_to_legacy_u32(&supported, |
| 137 | cmd->link_modes.supported); |
| 138 | |
| 139 | supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; |
| 140 | |
| 141 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 142 | supported); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 143 | |
| 144 | if (LOOPBACK_INTERNAL(efx)) { |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 145 | cmd->base.speed = link_state->speed; |
| 146 | cmd->base.duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 147 | } |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 148 | |
| 149 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* This must be called with rtnl_lock held. */ |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 153 | static int |
| 154 | efx_ethtool_set_link_ksettings(struct net_device *net_dev, |
| 155 | const struct ethtool_link_ksettings *cmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 156 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 157 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 158 | int rc; |
| 159 | |
Ben Hutchings | 754c653 | 2010-02-03 09:31:57 +0000 | [diff] [blame] | 160 | /* GMAC does not support 1000Mbps HD */ |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 161 | if ((cmd->base.speed == SPEED_1000) && |
| 162 | (cmd->base.duplex != DUPLEX_FULL)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 163 | netif_dbg(efx, drv, efx->net_dev, |
| 164 | "rejecting unsupported 1000Mbps HD setting\n"); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 165 | return -EINVAL; |
| 166 | } |
| 167 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 168 | mutex_lock(&efx->mac_lock); |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 169 | rc = efx->phy_op->set_link_ksettings(efx, cmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 170 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 171 | return rc; |
| 172 | } |
| 173 | |
| 174 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, |
| 175 | struct ethtool_drvinfo *info) |
| 176 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 177 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 178 | |
Ben Hutchings | c5d5f5f | 2010-06-23 11:30:26 +0000 | [diff] [blame] | 179 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 180 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); |
Edward Cree | 5a6681e | 2016-11-28 18:55:34 +0000 | [diff] [blame] | 181 | efx_mcdi_print_fwver(efx, info->fw_version, |
| 182 | sizeof(info->fw_version)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 183 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
| 184 | } |
| 185 | |
Ben Hutchings | 5b98c1b | 2010-06-21 03:06:53 +0000 | [diff] [blame] | 186 | static int efx_ethtool_get_regs_len(struct net_device *net_dev) |
| 187 | { |
| 188 | return efx_nic_get_regs_len(netdev_priv(net_dev)); |
| 189 | } |
| 190 | |
| 191 | static void efx_ethtool_get_regs(struct net_device *net_dev, |
| 192 | struct ethtool_regs *regs, void *buf) |
| 193 | { |
| 194 | struct efx_nic *efx = netdev_priv(net_dev); |
| 195 | |
| 196 | regs->version = efx->type->revision; |
| 197 | efx_nic_get_regs(efx, buf); |
| 198 | } |
| 199 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 200 | static u32 efx_ethtool_get_msglevel(struct net_device *net_dev) |
| 201 | { |
| 202 | struct efx_nic *efx = netdev_priv(net_dev); |
| 203 | return efx->msg_enable; |
| 204 | } |
| 205 | |
| 206 | static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) |
| 207 | { |
| 208 | struct efx_nic *efx = netdev_priv(net_dev); |
| 209 | efx->msg_enable = msg_enable; |
| 210 | } |
| 211 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 212 | /** |
| 213 | * efx_fill_test - fill in an individual self-test entry |
| 214 | * @test_index: Index of the test |
| 215 | * @strings: Ethtool strings, or %NULL |
| 216 | * @data: Ethtool test results, or %NULL |
| 217 | * @test: Pointer to test result (used only if data != %NULL) |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 218 | * @unit_format: Unit name format (e.g. "chan\%d") |
| 219 | * @unit_id: Unit id (e.g. 0 for "chan0") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 220 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 221 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 222 | * |
| 223 | * Fill in an individual self-test entry. |
| 224 | */ |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 225 | static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 226 | int *test, const char *unit_format, int unit_id, |
| 227 | const char *test_format, const char *test_id) |
| 228 | { |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 229 | char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN]; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 230 | |
| 231 | /* Fill data value, if applicable */ |
| 232 | if (data) |
| 233 | data[test_index] = *test; |
| 234 | |
| 235 | /* Fill string, if applicable */ |
| 236 | if (strings) { |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 237 | if (strchr(unit_format, '%')) |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 238 | snprintf(unit_str, sizeof(unit_str), |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 239 | unit_format, unit_id); |
| 240 | else |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 241 | strcpy(unit_str, unit_format); |
| 242 | snprintf(test_str, sizeof(test_str), test_format, test_id); |
| 243 | snprintf(strings + test_index * ETH_GSTRING_LEN, |
| 244 | ETH_GSTRING_LEN, |
| 245 | "%-6s %-24s", unit_str, test_str); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 249 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 250 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
| 251 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue |
| 252 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 253 | "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * efx_fill_loopback_test - fill in a block of loopback self-test entries |
| 257 | * @efx: Efx NIC |
| 258 | * @lb_tests: Efx loopback self-test results structure |
| 259 | * @mode: Loopback test mode |
| 260 | * @test_index: Starting index of the test |
| 261 | * @strings: Ethtool strings, or %NULL |
| 262 | * @data: Ethtool test results, or %NULL |
Ben Hutchings | 17e678d | 2014-02-12 19:00:16 +0000 | [diff] [blame] | 263 | * |
| 264 | * Fill in a block of loopback self-test entries. Return new test |
| 265 | * index. |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 266 | */ |
| 267 | static int efx_fill_loopback_test(struct efx_nic *efx, |
| 268 | struct efx_loopback_self_tests *lb_tests, |
| 269 | enum efx_loopback_mode mode, |
| 270 | unsigned int test_index, |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 271 | u8 *strings, u64 *data) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 272 | { |
Ben Hutchings | 1ac0226 | 2012-09-13 02:22:52 +0100 | [diff] [blame] | 273 | struct efx_channel *channel = |
| 274 | efx_get_channel(efx, efx->tx_channel_offset); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 275 | struct efx_tx_queue *tx_queue; |
| 276 | |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 277 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 278 | efx_fill_test(test_index++, strings, data, |
| 279 | &lb_tests->tx_sent[tx_queue->queue], |
| 280 | EFX_TX_QUEUE_NAME(tx_queue), |
| 281 | EFX_LOOPBACK_NAME(mode, "tx_sent")); |
| 282 | efx_fill_test(test_index++, strings, data, |
| 283 | &lb_tests->tx_done[tx_queue->queue], |
| 284 | EFX_TX_QUEUE_NAME(tx_queue), |
| 285 | EFX_LOOPBACK_NAME(mode, "tx_done")); |
| 286 | } |
| 287 | efx_fill_test(test_index++, strings, data, |
| 288 | &lb_tests->rx_good, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 289 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 290 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
| 291 | efx_fill_test(test_index++, strings, data, |
| 292 | &lb_tests->rx_bad, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 293 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 294 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
| 295 | |
| 296 | return test_index; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * efx_ethtool_fill_self_tests - get self-test details |
| 301 | * @efx: Efx NIC |
| 302 | * @tests: Efx self-test results structure, or %NULL |
| 303 | * @strings: Ethtool strings, or %NULL |
| 304 | * @data: Ethtool test results, or %NULL |
Ben Hutchings | 17e678d | 2014-02-12 19:00:16 +0000 | [diff] [blame] | 305 | * |
| 306 | * Get self-test number of strings, strings, and/or test results. |
| 307 | * Return number of strings (== number of test results). |
| 308 | * |
| 309 | * The reason for merging these three functions is to make sure that |
| 310 | * they can never be inconsistent. |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 311 | */ |
| 312 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, |
| 313 | struct efx_self_tests *tests, |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 314 | u8 *strings, u64 *data) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 315 | { |
| 316 | struct efx_channel *channel; |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 317 | unsigned int n = 0, i; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 318 | enum efx_loopback_mode mode; |
| 319 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 320 | efx_fill_test(n++, strings, data, &tests->phy_alive, |
| 321 | "phy", 0, "alive", NULL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 322 | efx_fill_test(n++, strings, data, &tests->nvram, |
| 323 | "core", 0, "nvram", NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 324 | efx_fill_test(n++, strings, data, &tests->interrupt, |
| 325 | "core", 0, "interrupt", NULL); |
| 326 | |
| 327 | /* Event queues */ |
| 328 | efx_for_each_channel(channel, efx) { |
| 329 | efx_fill_test(n++, strings, data, |
| 330 | &tests->eventq_dma[channel->channel], |
| 331 | EFX_CHANNEL_NAME(channel), |
| 332 | "eventq.dma", NULL); |
| 333 | efx_fill_test(n++, strings, data, |
| 334 | &tests->eventq_int[channel->channel], |
| 335 | EFX_CHANNEL_NAME(channel), |
| 336 | "eventq.int", NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 337 | } |
| 338 | |
Jon Cooper | 74cd60a | 2013-09-16 14:18:51 +0100 | [diff] [blame] | 339 | efx_fill_test(n++, strings, data, &tests->memory, |
| 340 | "core", 0, "memory", NULL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 341 | efx_fill_test(n++, strings, data, &tests->registers, |
| 342 | "core", 0, "registers", NULL); |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 343 | |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 344 | if (efx->phy_op->run_tests != NULL) { |
Edward Cree | e01b16a | 2016-12-02 15:51:33 +0000 | [diff] [blame] | 345 | EFX_WARN_ON_PARANOID(efx->phy_op->test_name == NULL); |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 346 | |
| 347 | for (i = 0; true; ++i) { |
| 348 | const char *name; |
| 349 | |
Edward Cree | e01b16a | 2016-12-02 15:51:33 +0000 | [diff] [blame] | 350 | EFX_WARN_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 351 | name = efx->phy_op->test_name(efx, i); |
| 352 | if (name == NULL) |
| 353 | break; |
| 354 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 355 | efx_fill_test(n++, strings, data, &tests->phy_ext[i], |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 356 | "phy", 0, name, NULL); |
| 357 | } |
| 358 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 359 | |
| 360 | /* Loopback tests */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 361 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 362 | if (!(efx->loopback_modes & (1 << mode))) |
| 363 | continue; |
| 364 | n = efx_fill_loopback_test(efx, |
| 365 | &tests->loopback[mode], mode, n, |
| 366 | strings, data); |
| 367 | } |
| 368 | |
| 369 | return n; |
| 370 | } |
| 371 | |
Andrew Rybchenko | 8ccf3800 | 2014-07-17 12:10:43 +0100 | [diff] [blame] | 372 | static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings) |
| 373 | { |
| 374 | size_t n_stats = 0; |
| 375 | struct efx_channel *channel; |
| 376 | |
| 377 | efx_for_each_channel(channel, efx) { |
| 378 | if (efx_channel_has_tx_queues(channel)) { |
| 379 | n_stats++; |
| 380 | if (strings != NULL) { |
| 381 | snprintf(strings, ETH_GSTRING_LEN, |
| 382 | "tx-%u.tx_packets", |
| 383 | channel->tx_queue[0].queue / |
| 384 | EFX_TXQ_TYPES); |
| 385 | |
| 386 | strings += ETH_GSTRING_LEN; |
| 387 | } |
| 388 | } |
| 389 | } |
| 390 | efx_for_each_channel(channel, efx) { |
| 391 | if (efx_channel_has_rx_queue(channel)) { |
| 392 | n_stats++; |
| 393 | if (strings != NULL) { |
| 394 | snprintf(strings, ETH_GSTRING_LEN, |
| 395 | "rx-%d.rx_packets", channel->channel); |
| 396 | strings += ETH_GSTRING_LEN; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | return n_stats; |
| 401 | } |
| 402 | |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 403 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
| 404 | int string_set) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 405 | { |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 406 | struct efx_nic *efx = netdev_priv(net_dev); |
| 407 | |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 408 | switch (string_set) { |
| 409 | case ETH_SS_STATS: |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 410 | return efx->type->describe_stats(efx, NULL) + |
Andrew Rybchenko | 8ccf3800 | 2014-07-17 12:10:43 +0100 | [diff] [blame] | 411 | EFX_ETHTOOL_SW_STAT_COUNT + |
| 412 | efx_describe_per_queue_stats(efx, NULL) + |
| 413 | efx_ptp_describe_stats(efx, NULL); |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 414 | case ETH_SS_TEST: |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 415 | return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 416 | default: |
| 417 | return -EINVAL; |
| 418 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 419 | } |
| 420 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 421 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
| 422 | u32 string_set, u8 *strings) |
| 423 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 424 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 425 | int i; |
| 426 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 427 | switch (string_set) { |
| 428 | case ETH_SS_STATS: |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 429 | strings += (efx->type->describe_stats(efx, strings) * |
| 430 | ETH_GSTRING_LEN); |
| 431 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 432 | strlcpy(strings + i * ETH_GSTRING_LEN, |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 433 | efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); |
Ben Hutchings | 99691c4 | 2013-12-11 02:36:08 +0000 | [diff] [blame] | 434 | strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; |
Andrew Rybchenko | 8ccf3800 | 2014-07-17 12:10:43 +0100 | [diff] [blame] | 435 | strings += (efx_describe_per_queue_stats(efx, strings) * |
| 436 | ETH_GSTRING_LEN); |
Ben Hutchings | 99691c4 | 2013-12-11 02:36:08 +0000 | [diff] [blame] | 437 | efx_ptp_describe_stats(efx, strings); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 438 | break; |
| 439 | case ETH_SS_TEST: |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 440 | efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 441 | break; |
| 442 | default: |
| 443 | /* No other string sets */ |
| 444 | break; |
| 445 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static void efx_ethtool_get_stats(struct net_device *net_dev, |
| 449 | struct ethtool_stats *stats, |
| 450 | u64 *data) |
| 451 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 452 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 453 | const struct efx_sw_stat_desc *stat; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 454 | struct efx_channel *channel; |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 455 | struct efx_tx_queue *tx_queue; |
Andrew Rybchenko | 8ccf3800 | 2014-07-17 12:10:43 +0100 | [diff] [blame] | 456 | struct efx_rx_queue *rx_queue; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 457 | int i; |
| 458 | |
Ben Hutchings | 1cb3452 | 2011-09-02 23:23:00 +0100 | [diff] [blame] | 459 | spin_lock_bh(&efx->stats_lock); |
| 460 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 461 | /* Get NIC statistics */ |
| 462 | data += efx->type->update_stats(efx, data, NULL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 463 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 464 | /* Get software statistics */ |
| 465 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { |
| 466 | stat = &efx_sw_stat_desc[i]; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 467 | switch (stat->source) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 468 | case EFX_ETHTOOL_STAT_SOURCE_nic: |
| 469 | data[i] = stat->get_stat((void *)efx + stat->offset); |
| 470 | break; |
| 471 | case EFX_ETHTOOL_STAT_SOURCE_channel: |
| 472 | data[i] = 0; |
| 473 | efx_for_each_channel(channel, efx) |
| 474 | data[i] += stat->get_stat((void *)channel + |
| 475 | stat->offset); |
| 476 | break; |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 477 | case EFX_ETHTOOL_STAT_SOURCE_tx_queue: |
| 478 | data[i] = 0; |
| 479 | efx_for_each_channel(channel, efx) { |
| 480 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 481 | data[i] += |
| 482 | stat->get_stat((void *)tx_queue |
| 483 | + stat->offset); |
| 484 | } |
| 485 | break; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 486 | } |
| 487 | } |
Ben Hutchings | 99691c4 | 2013-12-11 02:36:08 +0000 | [diff] [blame] | 488 | data += EFX_ETHTOOL_SW_STAT_COUNT; |
Ben Hutchings | 1cb3452 | 2011-09-02 23:23:00 +0100 | [diff] [blame] | 489 | |
| 490 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | 99691c4 | 2013-12-11 02:36:08 +0000 | [diff] [blame] | 491 | |
Andrew Rybchenko | 8ccf3800 | 2014-07-17 12:10:43 +0100 | [diff] [blame] | 492 | efx_for_each_channel(channel, efx) { |
| 493 | if (efx_channel_has_tx_queues(channel)) { |
| 494 | *data = 0; |
| 495 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
| 496 | *data += tx_queue->tx_packets; |
| 497 | } |
| 498 | data++; |
| 499 | } |
| 500 | } |
| 501 | efx_for_each_channel(channel, efx) { |
| 502 | if (efx_channel_has_rx_queue(channel)) { |
| 503 | *data = 0; |
| 504 | efx_for_each_channel_rx_queue(rx_queue, channel) { |
| 505 | *data += rx_queue->rx_packets; |
| 506 | } |
| 507 | data++; |
| 508 | } |
| 509 | } |
| 510 | |
Ben Hutchings | 99691c4 | 2013-12-11 02:36:08 +0000 | [diff] [blame] | 511 | efx_ptp_update_stats(efx, data); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 512 | } |
| 513 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 514 | static void efx_ethtool_self_test(struct net_device *net_dev, |
| 515 | struct ethtool_test *test, u64 *data) |
| 516 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 517 | struct efx_nic *efx = netdev_priv(net_dev); |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 518 | struct efx_self_tests *efx_tests; |
Ben Hutchings | 17e678d | 2014-02-12 19:00:16 +0000 | [diff] [blame] | 519 | bool already_up; |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 520 | int rc = -ENOMEM; |
| 521 | |
| 522 | efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL); |
| 523 | if (!efx_tests) |
| 524 | goto fail; |
| 525 | |
Ben Hutchings | f16aeea | 2012-07-27 19:31:16 +0100 | [diff] [blame] | 526 | if (efx->state != STATE_READY) { |
Ben Hutchings | 5eed1f6 | 2014-02-12 19:00:28 +0000 | [diff] [blame] | 527 | rc = -EBUSY; |
Ben Hutchings | 17e678d | 2014-02-12 19:00:16 +0000 | [diff] [blame] | 528 | goto out; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 529 | } |
| 530 | |
Ben Hutchings | ac33ac6 | 2010-12-07 18:29:52 +0000 | [diff] [blame] | 531 | netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
| 532 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
| 533 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 534 | /* We need rx buffers and interrupts. */ |
| 535 | already_up = (efx->net_dev->flags & IFF_UP); |
| 536 | if (!already_up) { |
| 537 | rc = dev_open(efx->net_dev); |
| 538 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 539 | netif_err(efx, drv, efx->net_dev, |
| 540 | "failed opening device.\n"); |
Ben Hutchings | 17e678d | 2014-02-12 19:00:16 +0000 | [diff] [blame] | 541 | goto out; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 545 | rc = efx_selftest(efx, efx_tests, test->flags); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 546 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 547 | if (!already_up) |
| 548 | dev_close(efx->net_dev); |
| 549 | |
Ben Hutchings | ac33ac6 | 2010-12-07 18:29:52 +0000 | [diff] [blame] | 550 | netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
| 551 | rc == 0 ? "passed" : "failed", |
| 552 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 553 | |
Ben Hutchings | 17e678d | 2014-02-12 19:00:16 +0000 | [diff] [blame] | 554 | out: |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 555 | efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data); |
| 556 | kfree(efx_tests); |
| 557 | fail: |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 558 | if (rc) |
| 559 | test->flags |= ETH_TEST_FL_FAILED; |
| 560 | } |
| 561 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 562 | /* Restart autonegotiation */ |
| 563 | static int efx_ethtool_nway_reset(struct net_device *net_dev) |
| 564 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 565 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 566 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 567 | return mdio45_nway_restart(&efx->mdio); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 568 | } |
| 569 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 570 | /* |
| 571 | * Each channel has a single IRQ and moderation timer, started by any |
| 572 | * completion (or other event). Unless the module parameter |
| 573 | * separate_tx_channels is set, IRQs and moderation are therefore |
| 574 | * shared between RX and TX completions. In this case, when RX IRQ |
| 575 | * moderation is explicitly changed then TX IRQ moderation is |
| 576 | * automatically changed too, but otherwise we fail if the two values |
| 577 | * are requested to be different. |
| 578 | * |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 579 | * The hardware does not support a limit on the number of completions |
| 580 | * before an IRQ, so we do not use the max_frames fields. We should |
| 581 | * report and require that max_frames == (usecs != 0), but this would |
| 582 | * invalidate existing user documentation. |
| 583 | * |
| 584 | * The hardware does not have distinct settings for interrupt |
| 585 | * moderation while the previous IRQ is being handled, so we should |
| 586 | * not use the 'irq' fields. However, an earlier developer |
| 587 | * misunderstood the meaning of the 'irq' fields and the driver did |
| 588 | * not support the standard fields. To avoid invalidating existing |
| 589 | * user documentation, we report and accept changes through either the |
| 590 | * standard or 'irq' fields. If both are changed at the same time, we |
| 591 | * prefer the standard field. |
| 592 | * |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 593 | * We implement adaptive IRQ moderation, but use a different algorithm |
| 594 | * from that assumed in the definition of struct ethtool_coalesce. |
| 595 | * Therefore we do not use any of the adaptive moderation parameters |
| 596 | * in it. |
| 597 | */ |
| 598 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 599 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
| 600 | struct ethtool_coalesce *coalesce) |
| 601 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 602 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 603 | unsigned int tx_usecs, rx_usecs; |
| 604 | bool rx_adaptive; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 605 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 606 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 607 | |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 608 | coalesce->tx_coalesce_usecs = tx_usecs; |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 609 | coalesce->tx_coalesce_usecs_irq = tx_usecs; |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 610 | coalesce->rx_coalesce_usecs = rx_usecs; |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 611 | coalesce->rx_coalesce_usecs_irq = rx_usecs; |
| 612 | coalesce->use_adaptive_rx_coalesce = rx_adaptive; |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 613 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 614 | return 0; |
| 615 | } |
| 616 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 617 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, |
| 618 | struct ethtool_coalesce *coalesce) |
| 619 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 620 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 621 | struct efx_channel *channel; |
Ben Hutchings | b548f97 | 2011-09-05 07:41:44 +0000 | [diff] [blame] | 622 | unsigned int tx_usecs, rx_usecs; |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 623 | bool adaptive, rx_may_override_tx; |
| 624 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 625 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 626 | if (coalesce->use_adaptive_tx_coalesce) |
Ben Hutchings | 9f85ee9 | 2011-09-05 07:41:27 +0000 | [diff] [blame] | 627 | return -EINVAL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 628 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 629 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive); |
| 630 | |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 631 | if (coalesce->rx_coalesce_usecs != rx_usecs) |
| 632 | rx_usecs = coalesce->rx_coalesce_usecs; |
| 633 | else |
| 634 | rx_usecs = coalesce->rx_coalesce_usecs_irq; |
| 635 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 636 | adaptive = coalesce->use_adaptive_rx_coalesce; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 637 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 638 | /* If channels are shared, TX IRQ moderation can be quietly |
| 639 | * overridden unless it is changed from its old value. |
| 640 | */ |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 641 | rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs && |
| 642 | coalesce->tx_coalesce_usecs_irq == tx_usecs); |
| 643 | if (coalesce->tx_coalesce_usecs != tx_usecs) |
| 644 | tx_usecs = coalesce->tx_coalesce_usecs; |
| 645 | else |
| 646 | tx_usecs = coalesce->tx_coalesce_usecs_irq; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 647 | |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 648 | rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive, |
| 649 | rx_may_override_tx); |
| 650 | if (rc != 0) |
| 651 | return rc; |
| 652 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 653 | efx_for_each_channel(channel, efx) |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 654 | efx->type->push_irq_moderation(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 655 | |
| 656 | return 0; |
| 657 | } |
| 658 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 659 | static void efx_ethtool_get_ringparam(struct net_device *net_dev, |
| 660 | struct ethtool_ringparam *ring) |
| 661 | { |
| 662 | struct efx_nic *efx = netdev_priv(net_dev); |
| 663 | |
| 664 | ring->rx_max_pending = EFX_MAX_DMAQ_SIZE; |
Ben Hutchings | d9317ae | 2014-01-23 14:35:48 +0000 | [diff] [blame] | 665 | ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 666 | ring->rx_pending = efx->rxq_entries; |
| 667 | ring->tx_pending = efx->txq_entries; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | static int efx_ethtool_set_ringparam(struct net_device *net_dev, |
| 671 | struct ethtool_ringparam *ring) |
| 672 | { |
| 673 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 674 | u32 txq_entries; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 675 | |
| 676 | if (ring->rx_mini_pending || ring->rx_jumbo_pending || |
| 677 | ring->rx_pending > EFX_MAX_DMAQ_SIZE || |
Ben Hutchings | d9317ae | 2014-01-23 14:35:48 +0000 | [diff] [blame] | 678 | ring->tx_pending > EFX_TXQ_MAX_ENT(efx)) |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 679 | return -EINVAL; |
| 680 | |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 681 | if (ring->rx_pending < EFX_RXQ_MIN_ENT) { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 682 | netif_err(efx, drv, efx->net_dev, |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 683 | "RX queues cannot be smaller than %u\n", |
| 684 | EFX_RXQ_MIN_ENT); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 685 | return -EINVAL; |
| 686 | } |
| 687 | |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 688 | txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx)); |
| 689 | if (txq_entries != ring->tx_pending) |
| 690 | netif_warn(efx, drv, efx->net_dev, |
| 691 | "increasing TX queue size to minimum of %u\n", |
| 692 | txq_entries); |
| 693 | |
| 694 | return efx_realloc_channels(efx, ring->rx_pending, txq_entries); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 695 | } |
| 696 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 697 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
| 698 | struct ethtool_pauseparam *pause) |
| 699 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 700 | struct efx_nic *efx = netdev_priv(net_dev); |
David S. Miller | b5626946 | 2011-05-17 17:53:22 -0400 | [diff] [blame] | 701 | u8 wanted_fc, old_fc; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 702 | u32 old_adv; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 703 | int rc = 0; |
| 704 | |
| 705 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 706 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 707 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
| 708 | (pause->tx_pause ? EFX_FC_TX : 0) | |
| 709 | (pause->autoneg ? EFX_FC_AUTO : 0)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 710 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 711 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 712 | netif_dbg(efx, drv, efx->net_dev, |
| 713 | "Flow control unsupported: tx ON rx OFF\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 714 | rc = -EINVAL; |
| 715 | goto out; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 716 | } |
| 717 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 718 | if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 719 | netif_dbg(efx, drv, efx->net_dev, |
| 720 | "Autonegotiation is disabled\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 721 | rc = -EINVAL; |
| 722 | goto out; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 723 | } |
| 724 | |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 725 | /* Hook for Falcon bug 11482 workaround */ |
| 726 | if (efx->type->prepare_enable_fc_tx && |
| 727 | (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX)) |
| 728 | efx->type->prepare_enable_fc_tx(efx); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 729 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 730 | old_adv = efx->link_advertising; |
| 731 | old_fc = efx->wanted_fc; |
| 732 | efx_link_set_wanted_fc(efx, wanted_fc); |
| 733 | if (efx->link_advertising != old_adv || |
| 734 | (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { |
| 735 | rc = efx->phy_op->reconfigure(efx); |
| 736 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 737 | netif_err(efx, drv, efx->net_dev, |
| 738 | "Unable to advertise requested flow " |
| 739 | "control setting\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 740 | goto out; |
| 741 | } |
| 742 | } |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 743 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 744 | /* Reconfigure the MAC. The PHY *may* generate a link state change event |
| 745 | * if the user just changed the advertised capabilities, but there's no |
| 746 | * harm doing this twice */ |
Edward Cree | 0d32241 | 2015-05-20 11:10:03 +0100 | [diff] [blame] | 747 | efx_mac_reconfigure(efx); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 748 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 749 | out: |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 750 | mutex_unlock(&efx->mac_lock); |
| 751 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 752 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, |
| 756 | struct ethtool_pauseparam *pause) |
| 757 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 758 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 759 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 760 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
| 761 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); |
| 762 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 765 | static void efx_ethtool_get_wol(struct net_device *net_dev, |
| 766 | struct ethtool_wolinfo *wol) |
| 767 | { |
| 768 | struct efx_nic *efx = netdev_priv(net_dev); |
| 769 | return efx->type->get_wol(efx, wol); |
| 770 | } |
| 771 | |
| 772 | |
| 773 | static int efx_ethtool_set_wol(struct net_device *net_dev, |
| 774 | struct ethtool_wolinfo *wol) |
| 775 | { |
| 776 | struct efx_nic *efx = netdev_priv(net_dev); |
| 777 | return efx->type->set_wol(efx, wol->wolopts); |
| 778 | } |
| 779 | |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 780 | static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 781 | { |
| 782 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 783 | int rc; |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 784 | |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 785 | rc = efx->type->map_reset_flags(flags); |
| 786 | if (rc < 0) |
| 787 | return rc; |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 788 | |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 789 | return efx_reset(efx, rc); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 792 | /* MAC address mask including only I/G bit */ |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 793 | static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0}; |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 794 | |
Ben Hutchings | 0e0c340 | 2012-09-06 02:11:04 +0100 | [diff] [blame] | 795 | #define IP4_ADDR_FULL_MASK ((__force __be32)~0) |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 796 | #define IP_PROTO_FULL_MASK 0xFF |
Ben Hutchings | 0e0c340 | 2012-09-06 02:11:04 +0100 | [diff] [blame] | 797 | #define PORT_FULL_MASK ((__force __be16)~0) |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 798 | #define ETHER_TYPE_FULL_MASK ((__force __be16)~0) |
Ben Hutchings | 0e0c340 | 2012-09-06 02:11:04 +0100 | [diff] [blame] | 799 | |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 800 | static inline void ip6_fill_mask(__be32 *mask) |
| 801 | { |
| 802 | mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0; |
| 803 | } |
| 804 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 805 | static int efx_ethtool_get_class_rule(struct efx_nic *efx, |
| 806 | struct ethtool_rx_flow_spec *rule) |
| 807 | { |
| 808 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
| 809 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 810 | struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
| 811 | struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; |
| 812 | struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; |
| 813 | struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; |
| 814 | struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; |
| 815 | struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 816 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
| 817 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 818 | struct efx_filter_spec spec; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 819 | int rc; |
| 820 | |
| 821 | rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL, |
| 822 | rule->location, &spec); |
| 823 | if (rc) |
| 824 | return rc; |
| 825 | |
Ben Hutchings | f26e958 | 2012-10-30 01:01:52 +0000 | [diff] [blame] | 826 | if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP) |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 827 | rule->ring_cookie = RX_CLS_FLOW_DISC; |
| 828 | else |
| 829 | rule->ring_cookie = spec.dmaq_id; |
| 830 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 831 | if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
| 832 | spec.ether_type == htons(ETH_P_IP) && |
| 833 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && |
| 834 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && |
| 835 | !(spec.match_flags & |
| 836 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 837 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 838 | EFX_FILTER_MATCH_IP_PROTO | |
| 839 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { |
| 840 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? |
| 841 | TCP_V4_FLOW : UDP_V4_FLOW); |
| 842 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 843 | ip_entry->ip4dst = spec.loc_host[0]; |
| 844 | ip_mask->ip4dst = IP4_ADDR_FULL_MASK; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 845 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 846 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 847 | ip_entry->ip4src = spec.rem_host[0]; |
| 848 | ip_mask->ip4src = IP4_ADDR_FULL_MASK; |
| 849 | } |
| 850 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { |
| 851 | ip_entry->pdst = spec.loc_port; |
| 852 | ip_mask->pdst = PORT_FULL_MASK; |
| 853 | } |
| 854 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { |
| 855 | ip_entry->psrc = spec.rem_port; |
| 856 | ip_mask->psrc = PORT_FULL_MASK; |
| 857 | } |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 858 | } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
| 859 | spec.ether_type == htons(ETH_P_IPV6) && |
| 860 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && |
| 861 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && |
| 862 | !(spec.match_flags & |
| 863 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 864 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 865 | EFX_FILTER_MATCH_IP_PROTO | |
| 866 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { |
| 867 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? |
| 868 | TCP_V6_FLOW : UDP_V6_FLOW); |
| 869 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 870 | memcpy(ip6_entry->ip6dst, spec.loc_host, |
| 871 | sizeof(ip6_entry->ip6dst)); |
| 872 | ip6_fill_mask(ip6_mask->ip6dst); |
| 873 | } |
| 874 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 875 | memcpy(ip6_entry->ip6src, spec.rem_host, |
| 876 | sizeof(ip6_entry->ip6src)); |
| 877 | ip6_fill_mask(ip6_mask->ip6src); |
| 878 | } |
| 879 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { |
| 880 | ip6_entry->pdst = spec.loc_port; |
| 881 | ip6_mask->pdst = PORT_FULL_MASK; |
| 882 | } |
| 883 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { |
| 884 | ip6_entry->psrc = spec.rem_port; |
| 885 | ip6_mask->psrc = PORT_FULL_MASK; |
| 886 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 887 | } else if (!(spec.match_flags & |
| 888 | ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG | |
| 889 | EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE | |
| 890 | EFX_FILTER_MATCH_OUTER_VID))) { |
| 891 | rule->flow_type = ETHER_FLOW; |
| 892 | if (spec.match_flags & |
| 893 | (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) { |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 894 | ether_addr_copy(mac_entry->h_dest, spec.loc_mac); |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 895 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC) |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 896 | eth_broadcast_addr(mac_mask->h_dest); |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 897 | else |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 898 | ether_addr_copy(mac_mask->h_dest, |
| 899 | mac_addr_ig_mask); |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 900 | } |
| 901 | if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) { |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 902 | ether_addr_copy(mac_entry->h_source, spec.rem_mac); |
| 903 | eth_broadcast_addr(mac_mask->h_source); |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 904 | } |
| 905 | if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) { |
| 906 | mac_entry->h_proto = spec.ether_type; |
| 907 | mac_mask->h_proto = ETHER_TYPE_FULL_MASK; |
| 908 | } |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 909 | } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && |
| 910 | spec.ether_type == htons(ETH_P_IP) && |
| 911 | !(spec.match_flags & |
| 912 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 913 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 914 | EFX_FILTER_MATCH_IP_PROTO))) { |
| 915 | rule->flow_type = IPV4_USER_FLOW; |
| 916 | uip_entry->ip_ver = ETH_RX_NFC_IP4; |
| 917 | if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { |
| 918 | uip_mask->proto = IP_PROTO_FULL_MASK; |
| 919 | uip_entry->proto = spec.ip_proto; |
| 920 | } |
| 921 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 922 | uip_entry->ip4dst = spec.loc_host[0]; |
| 923 | uip_mask->ip4dst = IP4_ADDR_FULL_MASK; |
| 924 | } |
| 925 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 926 | uip_entry->ip4src = spec.rem_host[0]; |
| 927 | uip_mask->ip4src = IP4_ADDR_FULL_MASK; |
| 928 | } |
| 929 | } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && |
| 930 | spec.ether_type == htons(ETH_P_IPV6) && |
| 931 | !(spec.match_flags & |
| 932 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 933 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 934 | EFX_FILTER_MATCH_IP_PROTO))) { |
| 935 | rule->flow_type = IPV6_USER_FLOW; |
| 936 | if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { |
| 937 | uip6_mask->l4_proto = IP_PROTO_FULL_MASK; |
| 938 | uip6_entry->l4_proto = spec.ip_proto; |
| 939 | } |
| 940 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 941 | memcpy(uip6_entry->ip6dst, spec.loc_host, |
| 942 | sizeof(uip6_entry->ip6dst)); |
| 943 | ip6_fill_mask(uip6_mask->ip6dst); |
| 944 | } |
| 945 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 946 | memcpy(uip6_entry->ip6src, spec.rem_host, |
| 947 | sizeof(uip6_entry->ip6src)); |
| 948 | ip6_fill_mask(uip6_mask->ip6src); |
| 949 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 950 | } else { |
| 951 | /* The above should handle all filters that we insert */ |
| 952 | WARN_ON(1); |
| 953 | return -EINVAL; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 954 | } |
| 955 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 956 | if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) { |
| 957 | rule->flow_type |= FLOW_EXT; |
| 958 | rule->h_ext.vlan_tci = spec.outer_vid; |
| 959 | rule->m_ext.vlan_tci = htons(0xfff); |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 960 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 961 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 962 | return rc; |
| 963 | } |
| 964 | |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 965 | static int |
| 966 | efx_ethtool_get_rxnfc(struct net_device *net_dev, |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 967 | struct ethtool_rxnfc *info, u32 *rule_locs) |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 968 | { |
| 969 | struct efx_nic *efx = netdev_priv(net_dev); |
| 970 | |
| 971 | switch (info->cmd) { |
| 972 | case ETHTOOL_GRXRINGS: |
| 973 | info->data = efx->n_rx_channels; |
| 974 | return 0; |
| 975 | |
| 976 | case ETHTOOL_GRXFH: { |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 977 | info->data = 0; |
Edward Cree | 4fdda95 | 2017-01-04 15:10:56 +0000 | [diff] [blame] | 978 | if (!efx->rss_active) /* No RSS */ |
| 979 | return 0; |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 980 | switch (info->flow_type) { |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 981 | case UDP_V4_FLOW: |
Edward Cree | b718c88 | 2016-11-03 22:12:58 +0000 | [diff] [blame] | 982 | if (efx->rx_hash_udp_4tuple) |
| 983 | /* fall through */ |
| 984 | case TCP_V4_FLOW: |
| 985 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 986 | /* fall through */ |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 987 | case SCTP_V4_FLOW: |
| 988 | case AH_ESP_V4_FLOW: |
| 989 | case IPV4_FLOW: |
| 990 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 991 | break; |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 992 | case UDP_V6_FLOW: |
Edward Cree | b718c88 | 2016-11-03 22:12:58 +0000 | [diff] [blame] | 993 | if (efx->rx_hash_udp_4tuple) |
| 994 | /* fall through */ |
| 995 | case TCP_V6_FLOW: |
| 996 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 997 | /* fall through */ |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 998 | case SCTP_V6_FLOW: |
| 999 | case AH_ESP_V6_FLOW: |
| 1000 | case IPV6_FLOW: |
| 1001 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1002 | break; |
| 1003 | default: |
| 1004 | break; |
| 1005 | } |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1006 | return 0; |
| 1007 | } |
| 1008 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1009 | case ETHTOOL_GRXCLSRLCNT: |
| 1010 | info->data = efx_filter_get_rx_id_limit(efx); |
| 1011 | if (info->data == 0) |
| 1012 | return -EOPNOTSUPP; |
| 1013 | info->data |= RX_CLS_LOC_SPECIAL; |
| 1014 | info->rule_cnt = |
| 1015 | efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL); |
| 1016 | return 0; |
| 1017 | |
| 1018 | case ETHTOOL_GRXCLSRULE: |
| 1019 | if (efx_filter_get_rx_id_limit(efx) == 0) |
| 1020 | return -EOPNOTSUPP; |
| 1021 | return efx_ethtool_get_class_rule(efx, &info->fs); |
| 1022 | |
| 1023 | case ETHTOOL_GRXCLSRLALL: { |
| 1024 | s32 rc; |
| 1025 | info->data = efx_filter_get_rx_id_limit(efx); |
| 1026 | if (info->data == 0) |
| 1027 | return -EOPNOTSUPP; |
| 1028 | rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL, |
| 1029 | rule_locs, info->rule_cnt); |
| 1030 | if (rc < 0) |
| 1031 | return rc; |
| 1032 | info->rule_cnt = rc; |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1036 | default: |
| 1037 | return -EOPNOTSUPP; |
| 1038 | } |
| 1039 | } |
| 1040 | |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 1041 | static inline bool ip6_mask_is_full(__be32 mask[4]) |
| 1042 | { |
| 1043 | return !~(mask[0] & mask[1] & mask[2] & mask[3]); |
| 1044 | } |
| 1045 | |
| 1046 | static inline bool ip6_mask_is_empty(__be32 mask[4]) |
| 1047 | { |
| 1048 | return !(mask[0] | mask[1] | mask[2] | mask[3]); |
| 1049 | } |
| 1050 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1051 | static int efx_ethtool_set_class_rule(struct efx_nic *efx, |
| 1052 | struct ethtool_rx_flow_spec *rule) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1053 | { |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1054 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
| 1055 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 1056 | struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
| 1057 | struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; |
| 1058 | struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; |
| 1059 | struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; |
| 1060 | struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; |
| 1061 | struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1062 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
| 1063 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; |
| 1064 | struct efx_filter_spec spec; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 1065 | int rc; |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1066 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1067 | /* Check that user wants us to choose the location */ |
Ben Hutchings | 9e0f9a1 | 2012-09-04 18:57:25 +0100 | [diff] [blame] | 1068 | if (rule->location != RX_CLS_LOC_ANY) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1069 | return -EINVAL; |
| 1070 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1071 | /* Range-check ring_cookie */ |
| 1072 | if (rule->ring_cookie >= efx->n_rx_channels && |
| 1073 | rule->ring_cookie != RX_CLS_FLOW_DISC) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1074 | return -EINVAL; |
| 1075 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1076 | /* Check for unsupported extensions */ |
| 1077 | if ((rule->flow_type & FLOW_EXT) && |
Ben Hutchings | 0e0c340 | 2012-09-06 02:11:04 +0100 | [diff] [blame] | 1078 | (rule->m_ext.vlan_etype || rule->m_ext.data[0] || |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1079 | rule->m_ext.data[1])) |
| 1080 | return -EINVAL; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 1081 | |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 1082 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, |
| 1083 | efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0, |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1084 | (rule->ring_cookie == RX_CLS_FLOW_DISC) ? |
Ben Hutchings | f26e958 | 2012-10-30 01:01:52 +0000 | [diff] [blame] | 1085 | EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie); |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1086 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 1087 | switch (rule->flow_type & ~FLOW_EXT) { |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1088 | case TCP_V4_FLOW: |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 1089 | case UDP_V4_FLOW: |
| 1090 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | |
| 1091 | EFX_FILTER_MATCH_IP_PROTO); |
| 1092 | spec.ether_type = htons(ETH_P_IP); |
| 1093 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ? |
| 1094 | IPPROTO_TCP : IPPROTO_UDP); |
| 1095 | if (ip_mask->ip4dst) { |
| 1096 | if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK) |
| 1097 | return -EINVAL; |
| 1098 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 1099 | spec.loc_host[0] = ip_entry->ip4dst; |
| 1100 | } |
| 1101 | if (ip_mask->ip4src) { |
| 1102 | if (ip_mask->ip4src != IP4_ADDR_FULL_MASK) |
| 1103 | return -EINVAL; |
| 1104 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 1105 | spec.rem_host[0] = ip_entry->ip4src; |
| 1106 | } |
| 1107 | if (ip_mask->pdst) { |
| 1108 | if (ip_mask->pdst != PORT_FULL_MASK) |
| 1109 | return -EINVAL; |
| 1110 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; |
| 1111 | spec.loc_port = ip_entry->pdst; |
| 1112 | } |
| 1113 | if (ip_mask->psrc) { |
| 1114 | if (ip_mask->psrc != PORT_FULL_MASK) |
| 1115 | return -EINVAL; |
| 1116 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; |
| 1117 | spec.rem_port = ip_entry->psrc; |
| 1118 | } |
| 1119 | if (ip_mask->tos) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1120 | return -EINVAL; |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1121 | break; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 1122 | |
Edward Cree | a7ad40d | 2016-02-05 11:16:50 +0000 | [diff] [blame] | 1123 | case TCP_V6_FLOW: |
| 1124 | case UDP_V6_FLOW: |
| 1125 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | |
| 1126 | EFX_FILTER_MATCH_IP_PROTO); |
| 1127 | spec.ether_type = htons(ETH_P_IPV6); |
| 1128 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ? |
| 1129 | IPPROTO_TCP : IPPROTO_UDP); |
| 1130 | if (!ip6_mask_is_empty(ip6_mask->ip6dst)) { |
| 1131 | if (!ip6_mask_is_full(ip6_mask->ip6dst)) |
| 1132 | return -EINVAL; |
| 1133 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 1134 | memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host)); |
| 1135 | } |
| 1136 | if (!ip6_mask_is_empty(ip6_mask->ip6src)) { |
| 1137 | if (!ip6_mask_is_full(ip6_mask->ip6src)) |
| 1138 | return -EINVAL; |
| 1139 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 1140 | memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host)); |
| 1141 | } |
| 1142 | if (ip6_mask->pdst) { |
| 1143 | if (ip6_mask->pdst != PORT_FULL_MASK) |
| 1144 | return -EINVAL; |
| 1145 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; |
| 1146 | spec.loc_port = ip6_entry->pdst; |
| 1147 | } |
| 1148 | if (ip6_mask->psrc) { |
| 1149 | if (ip6_mask->psrc != PORT_FULL_MASK) |
| 1150 | return -EINVAL; |
| 1151 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; |
| 1152 | spec.rem_port = ip6_entry->psrc; |
| 1153 | } |
| 1154 | if (ip6_mask->tclass) |
| 1155 | return -EINVAL; |
| 1156 | break; |
| 1157 | |
| 1158 | case IPV4_USER_FLOW: |
| 1159 | if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver || |
| 1160 | uip_entry->ip_ver != ETH_RX_NFC_IP4) |
| 1161 | return -EINVAL; |
| 1162 | spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; |
| 1163 | spec.ether_type = htons(ETH_P_IP); |
| 1164 | if (uip_mask->ip4dst) { |
| 1165 | if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK) |
| 1166 | return -EINVAL; |
| 1167 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 1168 | spec.loc_host[0] = uip_entry->ip4dst; |
| 1169 | } |
| 1170 | if (uip_mask->ip4src) { |
| 1171 | if (uip_mask->ip4src != IP4_ADDR_FULL_MASK) |
| 1172 | return -EINVAL; |
| 1173 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 1174 | spec.rem_host[0] = uip_entry->ip4src; |
| 1175 | } |
| 1176 | if (uip_mask->proto) { |
| 1177 | if (uip_mask->proto != IP_PROTO_FULL_MASK) |
| 1178 | return -EINVAL; |
| 1179 | spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; |
| 1180 | spec.ip_proto = uip_entry->proto; |
| 1181 | } |
| 1182 | break; |
| 1183 | |
| 1184 | case IPV6_USER_FLOW: |
| 1185 | if (uip6_mask->l4_4_bytes || uip6_mask->tclass) |
| 1186 | return -EINVAL; |
| 1187 | spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; |
| 1188 | spec.ether_type = htons(ETH_P_IPV6); |
| 1189 | if (!ip6_mask_is_empty(uip6_mask->ip6dst)) { |
| 1190 | if (!ip6_mask_is_full(uip6_mask->ip6dst)) |
| 1191 | return -EINVAL; |
| 1192 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 1193 | memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host)); |
| 1194 | } |
| 1195 | if (!ip6_mask_is_empty(uip6_mask->ip6src)) { |
| 1196 | if (!ip6_mask_is_full(uip6_mask->ip6src)) |
| 1197 | return -EINVAL; |
| 1198 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 1199 | memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host)); |
| 1200 | } |
| 1201 | if (uip6_mask->l4_proto) { |
| 1202 | if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK) |
| 1203 | return -EINVAL; |
| 1204 | spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; |
| 1205 | spec.ip_proto = uip6_entry->l4_proto; |
| 1206 | } |
| 1207 | break; |
| 1208 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 1209 | case ETHER_FLOW: |
| 1210 | if (!is_zero_ether_addr(mac_mask->h_dest)) { |
| 1211 | if (ether_addr_equal(mac_mask->h_dest, |
| 1212 | mac_addr_ig_mask)) |
| 1213 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG; |
| 1214 | else if (is_broadcast_ether_addr(mac_mask->h_dest)) |
| 1215 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC; |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 1216 | else |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 1217 | return -EINVAL; |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1218 | ether_addr_copy(spec.loc_mac, mac_entry->h_dest); |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 1219 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 1220 | if (!is_zero_ether_addr(mac_mask->h_source)) { |
| 1221 | if (!is_broadcast_ether_addr(mac_mask->h_source)) |
| 1222 | return -EINVAL; |
| 1223 | spec.match_flags |= EFX_FILTER_MATCH_REM_MAC; |
Edward Cree | cd84ff4 | 2014-03-07 18:27:41 +0000 | [diff] [blame] | 1224 | ether_addr_copy(spec.rem_mac, mac_entry->h_source); |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 1225 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 1226 | if (mac_mask->h_proto) { |
| 1227 | if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK) |
| 1228 | return -EINVAL; |
| 1229 | spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; |
| 1230 | spec.ether_type = mac_entry->h_proto; |
| 1231 | } |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1232 | break; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 1233 | |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1234 | default: |
| 1235 | return -EINVAL; |
| 1236 | } |
| 1237 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 1238 | if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) { |
| 1239 | if (rule->m_ext.vlan_tci != htons(0xfff)) |
| 1240 | return -EINVAL; |
| 1241 | spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID; |
| 1242 | spec.outer_vid = rule->h_ext.vlan_tci; |
| 1243 | } |
| 1244 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1245 | rc = efx_filter_insert_filter(efx, &spec, true); |
| 1246 | if (rc < 0) |
| 1247 | return rc; |
Ben Hutchings | 47a8467 | 2011-05-14 02:35:25 +0100 | [diff] [blame] | 1248 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1249 | rule->location = rc; |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | static int efx_ethtool_set_rxnfc(struct net_device *net_dev, |
| 1254 | struct ethtool_rxnfc *info) |
| 1255 | { |
| 1256 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1257 | |
| 1258 | if (efx_filter_get_rx_id_limit(efx) == 0) |
| 1259 | return -EOPNOTSUPP; |
| 1260 | |
| 1261 | switch (info->cmd) { |
| 1262 | case ETHTOOL_SRXCLSRLINS: |
| 1263 | return efx_ethtool_set_class_rule(efx, &info->fs); |
| 1264 | |
| 1265 | case ETHTOOL_SRXCLSRLDEL: |
| 1266 | return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL, |
| 1267 | info->fs.location); |
| 1268 | |
| 1269 | default: |
| 1270 | return -EOPNOTSUPP; |
| 1271 | } |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1274 | static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev) |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1275 | { |
| 1276 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1277 | |
Edward Cree | 5a6681e | 2016-11-28 18:55:34 +0000 | [diff] [blame] | 1278 | return (efx->n_rx_channels == 1) ? 0 : ARRAY_SIZE(efx->rx_indir_table); |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1279 | } |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1280 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1281 | static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key, |
| 1282 | u8 *hfunc) |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1283 | { |
| 1284 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1285 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1286 | if (hfunc) |
| 1287 | *hfunc = ETH_RSS_HASH_TOP; |
| 1288 | if (indir) |
| 1289 | memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table)); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1290 | return 0; |
| 1291 | } |
| 1292 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1293 | static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir, |
| 1294 | const u8 *key, const u8 hfunc) |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1295 | { |
| 1296 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1297 | |
Eyal Perry | 892311f | 2014-12-02 18:12:10 +0200 | [diff] [blame] | 1298 | /* We do not allow change in unsupported parameters */ |
| 1299 | if (key || |
| 1300 | (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)) |
| 1301 | return -EOPNOTSUPP; |
| 1302 | if (!indir) |
| 1303 | return 0; |
Jon Cooper | 267c015 | 2015-05-06 00:59:38 +0100 | [diff] [blame] | 1304 | |
| 1305 | return efx->type->rx_push_rss_config(efx, true, indir); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Fengguang Wu | b51ca34 | 2013-07-03 14:07:40 +0800 | [diff] [blame] | 1308 | static int efx_ethtool_get_ts_info(struct net_device *net_dev, |
| 1309 | struct ethtool_ts_info *ts_info) |
Ben Hutchings | 62ebac9 | 2013-04-08 17:34:58 +0100 | [diff] [blame] | 1310 | { |
| 1311 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1312 | |
| 1313 | /* Software capabilities */ |
| 1314 | ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1315 | SOF_TIMESTAMPING_SOFTWARE); |
| 1316 | ts_info->phc_index = -1; |
| 1317 | |
| 1318 | efx_ptp_get_ts_info(efx, ts_info); |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 1322 | static int efx_ethtool_get_module_eeprom(struct net_device *net_dev, |
| 1323 | struct ethtool_eeprom *ee, |
| 1324 | u8 *data) |
| 1325 | { |
| 1326 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1327 | int ret; |
| 1328 | |
| 1329 | if (!efx->phy_op || !efx->phy_op->get_module_eeprom) |
| 1330 | return -EOPNOTSUPP; |
| 1331 | |
| 1332 | mutex_lock(&efx->mac_lock); |
| 1333 | ret = efx->phy_op->get_module_eeprom(efx, ee, data); |
| 1334 | mutex_unlock(&efx->mac_lock); |
| 1335 | |
| 1336 | return ret; |
| 1337 | } |
| 1338 | |
| 1339 | static int efx_ethtool_get_module_info(struct net_device *net_dev, |
| 1340 | struct ethtool_modinfo *modinfo) |
| 1341 | { |
| 1342 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1343 | int ret; |
| 1344 | |
| 1345 | if (!efx->phy_op || !efx->phy_op->get_module_info) |
| 1346 | return -EOPNOTSUPP; |
| 1347 | |
| 1348 | mutex_lock(&efx->mac_lock); |
| 1349 | ret = efx->phy_op->get_module_info(efx, modinfo); |
| 1350 | mutex_unlock(&efx->mac_lock); |
| 1351 | |
| 1352 | return ret; |
| 1353 | } |
| 1354 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 1355 | const struct ethtool_ops efx_ethtool_ops = { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1356 | .get_drvinfo = efx_ethtool_get_drvinfo, |
Ben Hutchings | 5b98c1b | 2010-06-21 03:06:53 +0000 | [diff] [blame] | 1357 | .get_regs_len = efx_ethtool_get_regs_len, |
| 1358 | .get_regs = efx_ethtool_get_regs, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1359 | .get_msglevel = efx_ethtool_get_msglevel, |
| 1360 | .set_msglevel = efx_ethtool_set_msglevel, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1361 | .nway_reset = efx_ethtool_nway_reset, |
Ben Hutchings | ed4ba4b | 2010-12-09 12:10:25 +0000 | [diff] [blame] | 1362 | .get_link = ethtool_op_get_link, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1363 | .get_coalesce = efx_ethtool_get_coalesce, |
| 1364 | .set_coalesce = efx_ethtool_set_coalesce, |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 1365 | .get_ringparam = efx_ethtool_get_ringparam, |
| 1366 | .set_ringparam = efx_ethtool_set_ringparam, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1367 | .get_pauseparam = efx_ethtool_get_pauseparam, |
| 1368 | .set_pauseparam = efx_ethtool_set_pauseparam, |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 1369 | .get_sset_count = efx_ethtool_get_sset_count, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 1370 | .self_test = efx_ethtool_self_test, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1371 | .get_strings = efx_ethtool_get_strings, |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 1372 | .set_phys_id = efx_ethtool_phys_id, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1373 | .get_ethtool_stats = efx_ethtool_get_stats, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 1374 | .get_wol = efx_ethtool_get_wol, |
| 1375 | .set_wol = efx_ethtool_set_wol, |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 1376 | .reset = efx_ethtool_reset, |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1377 | .get_rxnfc = efx_ethtool_get_rxnfc, |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1378 | .set_rxnfc = efx_ethtool_set_rxnfc, |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1379 | .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size, |
Ben Hutchings | fe62d00 | 2014-05-15 01:25:27 +0100 | [diff] [blame] | 1380 | .get_rxfh = efx_ethtool_get_rxfh, |
| 1381 | .set_rxfh = efx_ethtool_set_rxfh, |
Ben Hutchings | 62ebac9 | 2013-04-08 17:34:58 +0100 | [diff] [blame] | 1382 | .get_ts_info = efx_ethtool_get_ts_info, |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 1383 | .get_module_info = efx_ethtool_get_module_info, |
| 1384 | .get_module_eeprom = efx_ethtool_get_module_eeprom, |
Philippe Reynes | 7cafe8f | 2016-12-15 00:12:53 +0100 | [diff] [blame] | 1385 | .get_link_ksettings = efx_ethtool_get_link_ksettings, |
| 1386 | .set_link_ksettings = efx_ethtool_set_link_ksettings, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1387 | }; |