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 | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 4 | * Copyright 2006-2010 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), |
| 72 | EFX_ETHTOOL_UINT_TXQ_STAT(pushes), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 73 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
| 74 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), |
| 75 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), |
| 76 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), |
Ben Hutchings | c1ac403 | 2009-11-28 05:36:29 +0000 | [diff] [blame] | 77 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 78 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 79 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_nodesc_trunc), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 80 | }; |
| 81 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 82 | #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 83 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 84 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 85 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 86 | /************************************************************************** |
| 87 | * |
| 88 | * Ethtool operations |
| 89 | * |
| 90 | ************************************************************************** |
| 91 | */ |
| 92 | |
| 93 | /* Identify device by flashing LEDs */ |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 94 | static int efx_ethtool_phys_id(struct net_device *net_dev, |
| 95 | enum ethtool_phys_id_state state) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 96 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 97 | struct efx_nic *efx = netdev_priv(net_dev); |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 98 | enum efx_led_mode mode = EFX_LED_DEFAULT; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 99 | |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 100 | switch (state) { |
| 101 | case ETHTOOL_ID_ON: |
| 102 | mode = EFX_LED_ON; |
| 103 | break; |
| 104 | case ETHTOOL_ID_OFF: |
| 105 | mode = EFX_LED_OFF; |
| 106 | break; |
| 107 | case ETHTOOL_ID_INACTIVE: |
| 108 | mode = EFX_LED_DEFAULT; |
| 109 | break; |
Allan, Bruce W | fce5592 | 2011-04-13 13:09:10 +0000 | [diff] [blame] | 110 | case ETHTOOL_ID_ACTIVE: |
| 111 | return 1; /* cycle on/off once per second */ |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 112 | } |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 113 | |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 114 | efx->type->set_id_led(efx, mode); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
| 118 | /* This must be called with rtnl_lock held. */ |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 119 | static int efx_ethtool_get_settings(struct net_device *net_dev, |
| 120 | struct ethtool_cmd *ecmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 121 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 122 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 123 | struct efx_link_state *link_state = &efx->link_state; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 124 | |
| 125 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 126 | efx->phy_op->get_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 127 | mutex_unlock(&efx->mac_lock); |
| 128 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 129 | /* Both MACs support pause frames (bidirectional and respond-only) */ |
| 130 | ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; |
| 131 | |
| 132 | if (LOOPBACK_INTERNAL(efx)) { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 133 | ethtool_cmd_speed_set(ecmd, link_state->speed); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 134 | ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF; |
| 135 | } |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 136 | |
| 137 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* This must be called with rtnl_lock held. */ |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 141 | static int efx_ethtool_set_settings(struct net_device *net_dev, |
| 142 | struct ethtool_cmd *ecmd) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 143 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 144 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 145 | int rc; |
| 146 | |
Ben Hutchings | 754c653 | 2010-02-03 09:31:57 +0000 | [diff] [blame] | 147 | /* GMAC does not support 1000Mbps HD */ |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 148 | if ((ethtool_cmd_speed(ecmd) == SPEED_1000) && |
| 149 | (ecmd->duplex != DUPLEX_FULL)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 150 | netif_dbg(efx, drv, efx->net_dev, |
| 151 | "rejecting unsupported 1000Mbps HD setting\n"); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 152 | return -EINVAL; |
| 153 | } |
| 154 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 155 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 156 | rc = efx->phy_op->set_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 157 | mutex_unlock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 158 | return rc; |
| 159 | } |
| 160 | |
| 161 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, |
| 162 | struct ethtool_drvinfo *info) |
| 163 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 164 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 165 | |
Ben Hutchings | c5d5f5f | 2010-06-23 11:30:26 +0000 | [diff] [blame] | 166 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 167 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); |
Ben Hutchings | 8880f4e | 2009-11-29 15:15:41 +0000 | [diff] [blame] | 168 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) |
Ben Hutchings | e5f0fd2 | 2011-02-24 23:57:47 +0000 | [diff] [blame] | 169 | efx_mcdi_print_fwver(efx, info->fw_version, |
| 170 | sizeof(info->fw_version)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 171 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
| 172 | } |
| 173 | |
Ben Hutchings | 5b98c1b | 2010-06-21 03:06:53 +0000 | [diff] [blame] | 174 | static int efx_ethtool_get_regs_len(struct net_device *net_dev) |
| 175 | { |
| 176 | return efx_nic_get_regs_len(netdev_priv(net_dev)); |
| 177 | } |
| 178 | |
| 179 | static void efx_ethtool_get_regs(struct net_device *net_dev, |
| 180 | struct ethtool_regs *regs, void *buf) |
| 181 | { |
| 182 | struct efx_nic *efx = netdev_priv(net_dev); |
| 183 | |
| 184 | regs->version = efx->type->revision; |
| 185 | efx_nic_get_regs(efx, buf); |
| 186 | } |
| 187 | |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 188 | static u32 efx_ethtool_get_msglevel(struct net_device *net_dev) |
| 189 | { |
| 190 | struct efx_nic *efx = netdev_priv(net_dev); |
| 191 | return efx->msg_enable; |
| 192 | } |
| 193 | |
| 194 | static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) |
| 195 | { |
| 196 | struct efx_nic *efx = netdev_priv(net_dev); |
| 197 | efx->msg_enable = msg_enable; |
| 198 | } |
| 199 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 200 | /** |
| 201 | * efx_fill_test - fill in an individual self-test entry |
| 202 | * @test_index: Index of the test |
| 203 | * @strings: Ethtool strings, or %NULL |
| 204 | * @data: Ethtool test results, or %NULL |
| 205 | * @test: Pointer to test result (used only if data != %NULL) |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 206 | * @unit_format: Unit name format (e.g. "chan\%d") |
| 207 | * @unit_id: Unit id (e.g. 0 for "chan0") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 208 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 209 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 210 | * |
| 211 | * Fill in an individual self-test entry. |
| 212 | */ |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 213 | 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] | 214 | int *test, const char *unit_format, int unit_id, |
| 215 | const char *test_format, const char *test_id) |
| 216 | { |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 217 | char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN]; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 218 | |
| 219 | /* Fill data value, if applicable */ |
| 220 | if (data) |
| 221 | data[test_index] = *test; |
| 222 | |
| 223 | /* Fill string, if applicable */ |
| 224 | if (strings) { |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 225 | if (strchr(unit_format, '%')) |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 226 | snprintf(unit_str, sizeof(unit_str), |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 227 | unit_format, unit_id); |
| 228 | else |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 229 | strcpy(unit_str, unit_format); |
| 230 | snprintf(test_str, sizeof(test_str), test_format, test_id); |
| 231 | snprintf(strings + test_index * ETH_GSTRING_LEN, |
| 232 | ETH_GSTRING_LEN, |
| 233 | "%-6s %-24s", unit_str, test_str); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 237 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 238 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
| 239 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue |
| 240 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 241 | "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * efx_fill_loopback_test - fill in a block of loopback self-test entries |
| 245 | * @efx: Efx NIC |
| 246 | * @lb_tests: Efx loopback self-test results structure |
| 247 | * @mode: Loopback test mode |
| 248 | * @test_index: Starting index of the test |
| 249 | * @strings: Ethtool strings, or %NULL |
| 250 | * @data: Ethtool test results, or %NULL |
| 251 | */ |
| 252 | static int efx_fill_loopback_test(struct efx_nic *efx, |
| 253 | struct efx_loopback_self_tests *lb_tests, |
| 254 | enum efx_loopback_mode mode, |
| 255 | unsigned int test_index, |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 256 | u8 *strings, u64 *data) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 257 | { |
Ben Hutchings | 1ac0226 | 2012-09-13 02:22:52 +0100 | [diff] [blame] | 258 | struct efx_channel *channel = |
| 259 | efx_get_channel(efx, efx->tx_channel_offset); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 260 | struct efx_tx_queue *tx_queue; |
| 261 | |
Ben Hutchings | f7d12cd | 2010-09-10 06:41:47 +0000 | [diff] [blame] | 262 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 263 | efx_fill_test(test_index++, strings, data, |
| 264 | &lb_tests->tx_sent[tx_queue->queue], |
| 265 | EFX_TX_QUEUE_NAME(tx_queue), |
| 266 | EFX_LOOPBACK_NAME(mode, "tx_sent")); |
| 267 | efx_fill_test(test_index++, strings, data, |
| 268 | &lb_tests->tx_done[tx_queue->queue], |
| 269 | EFX_TX_QUEUE_NAME(tx_queue), |
| 270 | EFX_LOOPBACK_NAME(mode, "tx_done")); |
| 271 | } |
| 272 | efx_fill_test(test_index++, strings, data, |
| 273 | &lb_tests->rx_good, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 274 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 275 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
| 276 | efx_fill_test(test_index++, strings, data, |
| 277 | &lb_tests->rx_bad, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 278 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 279 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
| 280 | |
| 281 | return test_index; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * efx_ethtool_fill_self_tests - get self-test details |
| 286 | * @efx: Efx NIC |
| 287 | * @tests: Efx self-test results structure, or %NULL |
| 288 | * @strings: Ethtool strings, or %NULL |
| 289 | * @data: Ethtool test results, or %NULL |
| 290 | */ |
| 291 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, |
| 292 | struct efx_self_tests *tests, |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 293 | u8 *strings, u64 *data) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 294 | { |
| 295 | struct efx_channel *channel; |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 296 | unsigned int n = 0, i; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 297 | enum efx_loopback_mode mode; |
| 298 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 299 | efx_fill_test(n++, strings, data, &tests->phy_alive, |
| 300 | "phy", 0, "alive", NULL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 301 | efx_fill_test(n++, strings, data, &tests->nvram, |
| 302 | "core", 0, "nvram", NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 303 | efx_fill_test(n++, strings, data, &tests->interrupt, |
| 304 | "core", 0, "interrupt", NULL); |
| 305 | |
| 306 | /* Event queues */ |
| 307 | efx_for_each_channel(channel, efx) { |
| 308 | efx_fill_test(n++, strings, data, |
| 309 | &tests->eventq_dma[channel->channel], |
| 310 | EFX_CHANNEL_NAME(channel), |
| 311 | "eventq.dma", NULL); |
| 312 | efx_fill_test(n++, strings, data, |
| 313 | &tests->eventq_int[channel->channel], |
| 314 | EFX_CHANNEL_NAME(channel), |
| 315 | "eventq.int", NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 316 | } |
| 317 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 318 | efx_fill_test(n++, strings, data, &tests->registers, |
| 319 | "core", 0, "registers", NULL); |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 320 | |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 321 | if (efx->phy_op->run_tests != NULL) { |
| 322 | EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL); |
| 323 | |
| 324 | for (i = 0; true; ++i) { |
| 325 | const char *name; |
| 326 | |
| 327 | EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); |
| 328 | name = efx->phy_op->test_name(efx, i); |
| 329 | if (name == NULL) |
| 330 | break; |
| 331 | |
Ben Hutchings | 4f16c07 | 2010-02-03 09:30:50 +0000 | [diff] [blame] | 332 | efx_fill_test(n++, strings, data, &tests->phy_ext[i], |
Ben Hutchings | c1c4f45 | 2009-11-29 15:08:55 +0000 | [diff] [blame] | 333 | "phy", 0, name, NULL); |
| 334 | } |
| 335 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 336 | |
| 337 | /* Loopback tests */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 338 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 339 | if (!(efx->loopback_modes & (1 << mode))) |
| 340 | continue; |
| 341 | n = efx_fill_loopback_test(efx, |
| 342 | &tests->loopback[mode], mode, n, |
| 343 | strings, data); |
| 344 | } |
| 345 | |
| 346 | return n; |
| 347 | } |
| 348 | |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 349 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
| 350 | int string_set) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 351 | { |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 352 | struct efx_nic *efx = netdev_priv(net_dev); |
| 353 | |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 354 | switch (string_set) { |
| 355 | case ETH_SS_STATS: |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 356 | return efx->type->describe_stats(efx, NULL) + |
| 357 | EFX_ETHTOOL_SW_STAT_COUNT; |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 358 | case ETH_SS_TEST: |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 359 | return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 360 | default: |
| 361 | return -EINVAL; |
| 362 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 363 | } |
| 364 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 365 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
| 366 | u32 string_set, u8 *strings) |
| 367 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 368 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 369 | int i; |
| 370 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 371 | switch (string_set) { |
| 372 | case ETH_SS_STATS: |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 373 | strings += (efx->type->describe_stats(efx, strings) * |
| 374 | ETH_GSTRING_LEN); |
| 375 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 376 | strlcpy(strings + i * ETH_GSTRING_LEN, |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 377 | efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 378 | break; |
| 379 | case ETH_SS_TEST: |
Ben Hutchings | b681e57 | 2012-12-14 22:18:55 +0000 | [diff] [blame] | 380 | efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 381 | break; |
| 382 | default: |
| 383 | /* No other string sets */ |
| 384 | break; |
| 385 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | static void efx_ethtool_get_stats(struct net_device *net_dev, |
| 389 | struct ethtool_stats *stats, |
| 390 | u64 *data) |
| 391 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 392 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 393 | const struct efx_sw_stat_desc *stat; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 394 | struct efx_channel *channel; |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 395 | struct efx_tx_queue *tx_queue; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 396 | int i; |
| 397 | |
Ben Hutchings | 1cb3452 | 2011-09-02 23:23:00 +0100 | [diff] [blame] | 398 | spin_lock_bh(&efx->stats_lock); |
| 399 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 400 | /* Get NIC statistics */ |
| 401 | data += efx->type->update_stats(efx, data, NULL); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 402 | |
Ben Hutchings | cd0ecc9 | 2012-12-14 21:52:56 +0000 | [diff] [blame] | 403 | /* Get software statistics */ |
| 404 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { |
| 405 | stat = &efx_sw_stat_desc[i]; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 406 | switch (stat->source) { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 407 | case EFX_ETHTOOL_STAT_SOURCE_nic: |
| 408 | data[i] = stat->get_stat((void *)efx + stat->offset); |
| 409 | break; |
| 410 | case EFX_ETHTOOL_STAT_SOURCE_channel: |
| 411 | data[i] = 0; |
| 412 | efx_for_each_channel(channel, efx) |
| 413 | data[i] += stat->get_stat((void *)channel + |
| 414 | stat->offset); |
| 415 | break; |
Ben Hutchings | 119226c | 2011-02-18 19:14:13 +0000 | [diff] [blame] | 416 | case EFX_ETHTOOL_STAT_SOURCE_tx_queue: |
| 417 | data[i] = 0; |
| 418 | efx_for_each_channel(channel, efx) { |
| 419 | efx_for_each_channel_tx_queue(tx_queue, channel) |
| 420 | data[i] += |
| 421 | stat->get_stat((void *)tx_queue |
| 422 | + stat->offset); |
| 423 | } |
| 424 | break; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 425 | } |
| 426 | } |
Ben Hutchings | 1cb3452 | 2011-09-02 23:23:00 +0100 | [diff] [blame] | 427 | |
| 428 | spin_unlock_bh(&efx->stats_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 429 | } |
| 430 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 431 | static void efx_ethtool_self_test(struct net_device *net_dev, |
| 432 | struct ethtool_test *test, u64 *data) |
| 433 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 434 | struct efx_nic *efx = netdev_priv(net_dev); |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 435 | struct efx_self_tests *efx_tests; |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 436 | int already_up; |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 437 | int rc = -ENOMEM; |
| 438 | |
| 439 | efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL); |
| 440 | if (!efx_tests) |
| 441 | goto fail; |
| 442 | |
Ben Hutchings | f16aeea | 2012-07-27 19:31:16 +0100 | [diff] [blame] | 443 | if (efx->state != STATE_READY) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 444 | rc = -EIO; |
| 445 | goto fail1; |
| 446 | } |
| 447 | |
Ben Hutchings | ac33ac6 | 2010-12-07 18:29:52 +0000 | [diff] [blame] | 448 | netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
| 449 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
| 450 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 451 | /* We need rx buffers and interrupts. */ |
| 452 | already_up = (efx->net_dev->flags & IFF_UP); |
| 453 | if (!already_up) { |
| 454 | rc = dev_open(efx->net_dev); |
| 455 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 456 | netif_err(efx, drv, efx->net_dev, |
| 457 | "failed opening device.\n"); |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 458 | goto fail1; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 462 | rc = efx_selftest(efx, efx_tests, test->flags); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 463 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 464 | if (!already_up) |
| 465 | dev_close(efx->net_dev); |
| 466 | |
Ben Hutchings | ac33ac6 | 2010-12-07 18:29:52 +0000 | [diff] [blame] | 467 | netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
| 468 | rc == 0 ? "passed" : "failed", |
| 469 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 470 | |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 471 | fail1: |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 472 | /* Fill ethtool results structures */ |
Eric Dumazet | 28801f3 | 2011-02-16 03:48:38 +0000 | [diff] [blame] | 473 | efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data); |
| 474 | kfree(efx_tests); |
| 475 | fail: |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 476 | if (rc) |
| 477 | test->flags |= ETH_TEST_FL_FAILED; |
| 478 | } |
| 479 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 480 | /* Restart autonegotiation */ |
| 481 | static int efx_ethtool_nway_reset(struct net_device *net_dev) |
| 482 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 483 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 484 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 485 | return mdio45_nway_restart(&efx->mdio); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 488 | /* |
| 489 | * Each channel has a single IRQ and moderation timer, started by any |
| 490 | * completion (or other event). Unless the module parameter |
| 491 | * separate_tx_channels is set, IRQs and moderation are therefore |
| 492 | * shared between RX and TX completions. In this case, when RX IRQ |
| 493 | * moderation is explicitly changed then TX IRQ moderation is |
| 494 | * automatically changed too, but otherwise we fail if the two values |
| 495 | * are requested to be different. |
| 496 | * |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 497 | * The hardware does not support a limit on the number of completions |
| 498 | * before an IRQ, so we do not use the max_frames fields. We should |
| 499 | * report and require that max_frames == (usecs != 0), but this would |
| 500 | * invalidate existing user documentation. |
| 501 | * |
| 502 | * The hardware does not have distinct settings for interrupt |
| 503 | * moderation while the previous IRQ is being handled, so we should |
| 504 | * not use the 'irq' fields. However, an earlier developer |
| 505 | * misunderstood the meaning of the 'irq' fields and the driver did |
| 506 | * not support the standard fields. To avoid invalidating existing |
| 507 | * user documentation, we report and accept changes through either the |
| 508 | * standard or 'irq' fields. If both are changed at the same time, we |
| 509 | * prefer the standard field. |
| 510 | * |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 511 | * We implement adaptive IRQ moderation, but use a different algorithm |
| 512 | * from that assumed in the definition of struct ethtool_coalesce. |
| 513 | * Therefore we do not use any of the adaptive moderation parameters |
| 514 | * in it. |
| 515 | */ |
| 516 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 517 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
| 518 | struct ethtool_coalesce *coalesce) |
| 519 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 520 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 521 | unsigned int tx_usecs, rx_usecs; |
| 522 | bool rx_adaptive; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 523 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 524 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 525 | |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 526 | coalesce->tx_coalesce_usecs = tx_usecs; |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 527 | coalesce->tx_coalesce_usecs_irq = tx_usecs; |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 528 | coalesce->rx_coalesce_usecs = rx_usecs; |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 529 | coalesce->rx_coalesce_usecs_irq = rx_usecs; |
| 530 | coalesce->use_adaptive_rx_coalesce = rx_adaptive; |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 531 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 532 | return 0; |
| 533 | } |
| 534 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 535 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, |
| 536 | struct ethtool_coalesce *coalesce) |
| 537 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 538 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 539 | struct efx_channel *channel; |
Ben Hutchings | b548f97 | 2011-09-05 07:41:44 +0000 | [diff] [blame] | 540 | unsigned int tx_usecs, rx_usecs; |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 541 | bool adaptive, rx_may_override_tx; |
| 542 | int rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 543 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 544 | if (coalesce->use_adaptive_tx_coalesce) |
Ben Hutchings | 9f85ee9 | 2011-09-05 07:41:27 +0000 | [diff] [blame] | 545 | return -EINVAL; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 546 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 547 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive); |
| 548 | |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 549 | if (coalesce->rx_coalesce_usecs != rx_usecs) |
| 550 | rx_usecs = coalesce->rx_coalesce_usecs; |
| 551 | else |
| 552 | rx_usecs = coalesce->rx_coalesce_usecs_irq; |
| 553 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 554 | adaptive = coalesce->use_adaptive_rx_coalesce; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 555 | |
Ben Hutchings | a0c4faf | 2011-09-05 07:42:25 +0000 | [diff] [blame] | 556 | /* If channels are shared, TX IRQ moderation can be quietly |
| 557 | * overridden unless it is changed from its old value. |
| 558 | */ |
Ben Hutchings | 1322597 | 2011-09-05 07:43:49 +0000 | [diff] [blame] | 559 | rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs && |
| 560 | coalesce->tx_coalesce_usecs_irq == tx_usecs); |
| 561 | if (coalesce->tx_coalesce_usecs != tx_usecs) |
| 562 | tx_usecs = coalesce->tx_coalesce_usecs; |
| 563 | else |
| 564 | tx_usecs = coalesce->tx_coalesce_usecs_irq; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 565 | |
Ben Hutchings | 9e393b3 | 2011-09-05 07:43:04 +0000 | [diff] [blame] | 566 | rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive, |
| 567 | rx_may_override_tx); |
| 568 | if (rc != 0) |
| 569 | return rc; |
| 570 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 571 | efx_for_each_channel(channel, efx) |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame] | 572 | efx->type->push_irq_moderation(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 577 | static void efx_ethtool_get_ringparam(struct net_device *net_dev, |
| 578 | struct ethtool_ringparam *ring) |
| 579 | { |
| 580 | struct efx_nic *efx = netdev_priv(net_dev); |
| 581 | |
| 582 | ring->rx_max_pending = EFX_MAX_DMAQ_SIZE; |
| 583 | ring->tx_max_pending = EFX_MAX_DMAQ_SIZE; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 584 | ring->rx_pending = efx->rxq_entries; |
| 585 | ring->tx_pending = efx->txq_entries; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | static int efx_ethtool_set_ringparam(struct net_device *net_dev, |
| 589 | struct ethtool_ringparam *ring) |
| 590 | { |
| 591 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 592 | u32 txq_entries; |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 593 | |
| 594 | if (ring->rx_mini_pending || ring->rx_jumbo_pending || |
| 595 | ring->rx_pending > EFX_MAX_DMAQ_SIZE || |
| 596 | ring->tx_pending > EFX_MAX_DMAQ_SIZE) |
| 597 | return -EINVAL; |
| 598 | |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 599 | if (ring->rx_pending < EFX_RXQ_MIN_ENT) { |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 600 | netif_err(efx, drv, efx->net_dev, |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 601 | "RX queues cannot be smaller than %u\n", |
| 602 | EFX_RXQ_MIN_ENT); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 603 | return -EINVAL; |
| 604 | } |
| 605 | |
Ben Hutchings | 7e6d06f | 2012-07-30 15:57:44 +0000 | [diff] [blame] | 606 | txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx)); |
| 607 | if (txq_entries != ring->tx_pending) |
| 608 | netif_warn(efx, drv, efx->net_dev, |
| 609 | "increasing TX queue size to minimum of %u\n", |
| 610 | txq_entries); |
| 611 | |
| 612 | return efx_realloc_channels(efx, ring->rx_pending, txq_entries); |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 615 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
| 616 | struct ethtool_pauseparam *pause) |
| 617 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 618 | struct efx_nic *efx = netdev_priv(net_dev); |
David S. Miller | b562694 | 2011-05-17 17:53:22 -0400 | [diff] [blame] | 619 | u8 wanted_fc, old_fc; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 620 | u32 old_adv; |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 621 | int rc = 0; |
| 622 | |
| 623 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 624 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 625 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
| 626 | (pause->tx_pause ? EFX_FC_TX : 0) | |
| 627 | (pause->autoneg ? EFX_FC_AUTO : 0)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 628 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 629 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 630 | netif_dbg(efx, drv, efx->net_dev, |
| 631 | "Flow control unsupported: tx ON rx OFF\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 632 | rc = -EINVAL; |
| 633 | goto out; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 634 | } |
| 635 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 636 | if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 637 | netif_dbg(efx, drv, efx->net_dev, |
| 638 | "Autonegotiation is disabled\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 639 | rc = -EINVAL; |
| 640 | goto out; |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 641 | } |
| 642 | |
Ben Hutchings | 9dd3a13 | 2012-09-13 01:11:25 +0100 | [diff] [blame] | 643 | /* Hook for Falcon bug 11482 workaround */ |
| 644 | if (efx->type->prepare_enable_fc_tx && |
| 645 | (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX)) |
| 646 | efx->type->prepare_enable_fc_tx(efx); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 647 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 648 | old_adv = efx->link_advertising; |
| 649 | old_fc = efx->wanted_fc; |
| 650 | efx_link_set_wanted_fc(efx, wanted_fc); |
| 651 | if (efx->link_advertising != old_adv || |
| 652 | (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { |
| 653 | rc = efx->phy_op->reconfigure(efx); |
| 654 | if (rc) { |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 655 | netif_err(efx, drv, efx->net_dev, |
| 656 | "Unable to advertise requested flow " |
| 657 | "control setting\n"); |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 658 | goto out; |
| 659 | } |
| 660 | } |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 661 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 662 | /* Reconfigure the MAC. The PHY *may* generate a link state change event |
| 663 | * if the user just changed the advertised capabilities, but there's no |
| 664 | * harm doing this twice */ |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 665 | efx->type->reconfigure_mac(efx); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 666 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 667 | out: |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 668 | mutex_unlock(&efx->mac_lock); |
| 669 | |
Ben Hutchings | d3245b2 | 2009-11-29 03:42:41 +0000 | [diff] [blame] | 670 | return rc; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, |
| 674 | struct ethtool_pauseparam *pause) |
| 675 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 676 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 677 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 678 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
| 679 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); |
| 680 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 684 | static void efx_ethtool_get_wol(struct net_device *net_dev, |
| 685 | struct ethtool_wolinfo *wol) |
| 686 | { |
| 687 | struct efx_nic *efx = netdev_priv(net_dev); |
| 688 | return efx->type->get_wol(efx, wol); |
| 689 | } |
| 690 | |
| 691 | |
| 692 | static int efx_ethtool_set_wol(struct net_device *net_dev, |
| 693 | struct ethtool_wolinfo *wol) |
| 694 | { |
| 695 | struct efx_nic *efx = netdev_priv(net_dev); |
| 696 | return efx->type->set_wol(efx, wol->wolopts); |
| 697 | } |
| 698 | |
stephen hemminger | d215697 | 2010-10-18 05:27:31 +0000 | [diff] [blame] | 699 | static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 700 | { |
| 701 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 702 | int rc; |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 703 | |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 704 | rc = efx->type->map_reset_flags(flags); |
| 705 | if (rc < 0) |
| 706 | return rc; |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 707 | |
Ben Hutchings | 0e2a9c7 | 2011-06-24 20:50:07 +0100 | [diff] [blame] | 708 | return efx_reset(efx, rc); |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 709 | } |
| 710 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 711 | /* MAC address mask including only I/G bit */ |
| 712 | static const u8 mac_addr_ig_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 }; |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 713 | |
Ben Hutchings | 0e0c340 | 2012-09-06 02:11:04 +0100 | [diff] [blame] | 714 | #define IP4_ADDR_FULL_MASK ((__force __be32)~0) |
| 715 | #define PORT_FULL_MASK ((__force __be16)~0) |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 716 | #define ETHER_TYPE_FULL_MASK ((__force __be16)~0) |
Ben Hutchings | 0e0c340 | 2012-09-06 02:11:04 +0100 | [diff] [blame] | 717 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 718 | static int efx_ethtool_get_class_rule(struct efx_nic *efx, |
| 719 | struct ethtool_rx_flow_spec *rule) |
| 720 | { |
| 721 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
| 722 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 723 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
| 724 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 725 | struct efx_filter_spec spec; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 726 | int rc; |
| 727 | |
| 728 | rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL, |
| 729 | rule->location, &spec); |
| 730 | if (rc) |
| 731 | return rc; |
| 732 | |
Ben Hutchings | f26e958 | 2012-10-30 01:01:52 +0000 | [diff] [blame] | 733 | if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP) |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 734 | rule->ring_cookie = RX_CLS_FLOW_DISC; |
| 735 | else |
| 736 | rule->ring_cookie = spec.dmaq_id; |
| 737 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 738 | if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
| 739 | spec.ether_type == htons(ETH_P_IP) && |
| 740 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && |
| 741 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && |
| 742 | !(spec.match_flags & |
| 743 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | |
| 744 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | |
| 745 | EFX_FILTER_MATCH_IP_PROTO | |
| 746 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { |
| 747 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? |
| 748 | TCP_V4_FLOW : UDP_V4_FLOW); |
| 749 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { |
| 750 | ip_entry->ip4dst = spec.loc_host[0]; |
| 751 | ip_mask->ip4dst = IP4_ADDR_FULL_MASK; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 752 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 753 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { |
| 754 | ip_entry->ip4src = spec.rem_host[0]; |
| 755 | ip_mask->ip4src = IP4_ADDR_FULL_MASK; |
| 756 | } |
| 757 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { |
| 758 | ip_entry->pdst = spec.loc_port; |
| 759 | ip_mask->pdst = PORT_FULL_MASK; |
| 760 | } |
| 761 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { |
| 762 | ip_entry->psrc = spec.rem_port; |
| 763 | ip_mask->psrc = PORT_FULL_MASK; |
| 764 | } |
| 765 | } else if (!(spec.match_flags & |
| 766 | ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG | |
| 767 | EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE | |
| 768 | EFX_FILTER_MATCH_OUTER_VID))) { |
| 769 | rule->flow_type = ETHER_FLOW; |
| 770 | if (spec.match_flags & |
| 771 | (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) { |
| 772 | memcpy(mac_entry->h_dest, spec.loc_mac, ETH_ALEN); |
| 773 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC) |
| 774 | memset(mac_mask->h_dest, ~0, ETH_ALEN); |
| 775 | else |
| 776 | memcpy(mac_mask->h_dest, mac_addr_ig_mask, |
| 777 | ETH_ALEN); |
| 778 | } |
| 779 | if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) { |
| 780 | memcpy(mac_entry->h_source, spec.rem_mac, ETH_ALEN); |
| 781 | memset(mac_mask->h_source, ~0, ETH_ALEN); |
| 782 | } |
| 783 | if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) { |
| 784 | mac_entry->h_proto = spec.ether_type; |
| 785 | mac_mask->h_proto = ETHER_TYPE_FULL_MASK; |
| 786 | } |
| 787 | } else { |
| 788 | /* The above should handle all filters that we insert */ |
| 789 | WARN_ON(1); |
| 790 | return -EINVAL; |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 791 | } |
| 792 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 793 | if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) { |
| 794 | rule->flow_type |= FLOW_EXT; |
| 795 | rule->h_ext.vlan_tci = spec.outer_vid; |
| 796 | rule->m_ext.vlan_tci = htons(0xfff); |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 797 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 798 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 799 | return rc; |
| 800 | } |
| 801 | |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 802 | static int |
| 803 | efx_ethtool_get_rxnfc(struct net_device *net_dev, |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 804 | struct ethtool_rxnfc *info, u32 *rule_locs) |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 805 | { |
| 806 | struct efx_nic *efx = netdev_priv(net_dev); |
| 807 | |
| 808 | switch (info->cmd) { |
| 809 | case ETHTOOL_GRXRINGS: |
| 810 | info->data = efx->n_rx_channels; |
| 811 | return 0; |
| 812 | |
| 813 | case ETHTOOL_GRXFH: { |
| 814 | unsigned min_revision = 0; |
| 815 | |
| 816 | info->data = 0; |
| 817 | switch (info->flow_type) { |
| 818 | case TCP_V4_FLOW: |
| 819 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 820 | /* fall through */ |
| 821 | case UDP_V4_FLOW: |
| 822 | case SCTP_V4_FLOW: |
| 823 | case AH_ESP_V4_FLOW: |
| 824 | case IPV4_FLOW: |
| 825 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
| 826 | min_revision = EFX_REV_FALCON_B0; |
| 827 | break; |
| 828 | case TCP_V6_FLOW: |
| 829 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
| 830 | /* fall through */ |
| 831 | case UDP_V6_FLOW: |
| 832 | case SCTP_V6_FLOW: |
| 833 | case AH_ESP_V6_FLOW: |
| 834 | case IPV6_FLOW: |
| 835 | info->data |= RXH_IP_SRC | RXH_IP_DST; |
| 836 | min_revision = EFX_REV_SIENA_A0; |
| 837 | break; |
| 838 | default: |
| 839 | break; |
| 840 | } |
| 841 | if (efx_nic_rev(efx) < min_revision) |
| 842 | info->data = 0; |
| 843 | return 0; |
| 844 | } |
| 845 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 846 | case ETHTOOL_GRXCLSRLCNT: |
| 847 | info->data = efx_filter_get_rx_id_limit(efx); |
| 848 | if (info->data == 0) |
| 849 | return -EOPNOTSUPP; |
| 850 | info->data |= RX_CLS_LOC_SPECIAL; |
| 851 | info->rule_cnt = |
| 852 | efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL); |
| 853 | return 0; |
| 854 | |
| 855 | case ETHTOOL_GRXCLSRULE: |
| 856 | if (efx_filter_get_rx_id_limit(efx) == 0) |
| 857 | return -EOPNOTSUPP; |
| 858 | return efx_ethtool_get_class_rule(efx, &info->fs); |
| 859 | |
| 860 | case ETHTOOL_GRXCLSRLALL: { |
| 861 | s32 rc; |
| 862 | info->data = efx_filter_get_rx_id_limit(efx); |
| 863 | if (info->data == 0) |
| 864 | return -EOPNOTSUPP; |
| 865 | rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL, |
| 866 | rule_locs, info->rule_cnt); |
| 867 | if (rc < 0) |
| 868 | return rc; |
| 869 | info->rule_cnt = rc; |
| 870 | return 0; |
| 871 | } |
| 872 | |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 873 | default: |
| 874 | return -EOPNOTSUPP; |
| 875 | } |
| 876 | } |
| 877 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 878 | static int efx_ethtool_set_class_rule(struct efx_nic *efx, |
| 879 | struct ethtool_rx_flow_spec *rule) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 880 | { |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 881 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
| 882 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; |
| 883 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
| 884 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; |
| 885 | struct efx_filter_spec spec; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 886 | int rc; |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 887 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 888 | /* Check that user wants us to choose the location */ |
Ben Hutchings | 9e0f9a1 | 2012-09-04 18:57:25 +0100 | [diff] [blame] | 889 | if (rule->location != RX_CLS_LOC_ANY) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 890 | return -EINVAL; |
| 891 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 892 | /* Range-check ring_cookie */ |
| 893 | if (rule->ring_cookie >= efx->n_rx_channels && |
| 894 | rule->ring_cookie != RX_CLS_FLOW_DISC) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 895 | return -EINVAL; |
| 896 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 897 | /* Check for unsupported extensions */ |
| 898 | if ((rule->flow_type & FLOW_EXT) && |
Ben Hutchings | 0e0c340 | 2012-09-06 02:11:04 +0100 | [diff] [blame] | 899 | (rule->m_ext.vlan_etype || rule->m_ext.data[0] || |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 900 | rule->m_ext.data[1])) |
| 901 | return -EINVAL; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 902 | |
Ben Hutchings | 85740cdf | 2013-01-29 23:33:15 +0000 | [diff] [blame] | 903 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, |
| 904 | efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0, |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 905 | (rule->ring_cookie == RX_CLS_FLOW_DISC) ? |
Ben Hutchings | f26e958 | 2012-10-30 01:01:52 +0000 | [diff] [blame] | 906 | EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie); |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 907 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 908 | switch (rule->flow_type & ~FLOW_EXT) { |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 909 | case TCP_V4_FLOW: |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 910 | case UDP_V4_FLOW: |
| 911 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | |
| 912 | EFX_FILTER_MATCH_IP_PROTO); |
| 913 | spec.ether_type = htons(ETH_P_IP); |
| 914 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ? |
| 915 | IPPROTO_TCP : IPPROTO_UDP); |
| 916 | if (ip_mask->ip4dst) { |
| 917 | if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK) |
| 918 | return -EINVAL; |
| 919 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; |
| 920 | spec.loc_host[0] = ip_entry->ip4dst; |
| 921 | } |
| 922 | if (ip_mask->ip4src) { |
| 923 | if (ip_mask->ip4src != IP4_ADDR_FULL_MASK) |
| 924 | return -EINVAL; |
| 925 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; |
| 926 | spec.rem_host[0] = ip_entry->ip4src; |
| 927 | } |
| 928 | if (ip_mask->pdst) { |
| 929 | if (ip_mask->pdst != PORT_FULL_MASK) |
| 930 | return -EINVAL; |
| 931 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; |
| 932 | spec.loc_port = ip_entry->pdst; |
| 933 | } |
| 934 | if (ip_mask->psrc) { |
| 935 | if (ip_mask->psrc != PORT_FULL_MASK) |
| 936 | return -EINVAL; |
| 937 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; |
| 938 | spec.rem_port = ip_entry->psrc; |
| 939 | } |
| 940 | if (ip_mask->tos) |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 941 | return -EINVAL; |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 942 | break; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 943 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 944 | case ETHER_FLOW: |
| 945 | if (!is_zero_ether_addr(mac_mask->h_dest)) { |
| 946 | if (ether_addr_equal(mac_mask->h_dest, |
| 947 | mac_addr_ig_mask)) |
| 948 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG; |
| 949 | else if (is_broadcast_ether_addr(mac_mask->h_dest)) |
| 950 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC; |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 951 | else |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 952 | return -EINVAL; |
| 953 | memcpy(spec.loc_mac, mac_entry->h_dest, ETH_ALEN); |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 954 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 955 | if (!is_zero_ether_addr(mac_mask->h_source)) { |
| 956 | if (!is_broadcast_ether_addr(mac_mask->h_source)) |
| 957 | return -EINVAL; |
| 958 | spec.match_flags |= EFX_FILTER_MATCH_REM_MAC; |
| 959 | memcpy(spec.rem_mac, mac_entry->h_source, ETH_ALEN); |
Ben Hutchings | c274d65 | 2012-02-02 22:41:49 +0000 | [diff] [blame] | 960 | } |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 961 | if (mac_mask->h_proto) { |
| 962 | if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK) |
| 963 | return -EINVAL; |
| 964 | spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; |
| 965 | spec.ether_type = mac_entry->h_proto; |
| 966 | } |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 967 | break; |
Ben Hutchings | c39d35e | 2010-12-07 19:11:26 +0000 | [diff] [blame] | 968 | |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 969 | default: |
| 970 | return -EINVAL; |
| 971 | } |
| 972 | |
Ben Hutchings | 7c460d9 | 2012-10-27 00:33:28 +0100 | [diff] [blame] | 973 | if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) { |
| 974 | if (rule->m_ext.vlan_tci != htons(0xfff)) |
| 975 | return -EINVAL; |
| 976 | spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID; |
| 977 | spec.outer_vid = rule->h_ext.vlan_tci; |
| 978 | } |
| 979 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 980 | rc = efx_filter_insert_filter(efx, &spec, true); |
| 981 | if (rc < 0) |
| 982 | return rc; |
Ben Hutchings | 47a8467 | 2011-05-14 02:35:25 +0100 | [diff] [blame] | 983 | |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 984 | rule->location = rc; |
| 985 | return 0; |
| 986 | } |
| 987 | |
| 988 | static int efx_ethtool_set_rxnfc(struct net_device *net_dev, |
| 989 | struct ethtool_rxnfc *info) |
| 990 | { |
| 991 | struct efx_nic *efx = netdev_priv(net_dev); |
| 992 | |
| 993 | if (efx_filter_get_rx_id_limit(efx) == 0) |
| 994 | return -EOPNOTSUPP; |
| 995 | |
| 996 | switch (info->cmd) { |
| 997 | case ETHTOOL_SRXCLSRLINS: |
| 998 | return efx_ethtool_set_class_rule(efx, &info->fs); |
| 999 | |
| 1000 | case ETHTOOL_SRXCLSRLDEL: |
| 1001 | return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL, |
| 1002 | info->fs.location); |
| 1003 | |
| 1004 | default: |
| 1005 | return -EOPNOTSUPP; |
| 1006 | } |
Ben Hutchings | b4187e4 | 2010-09-20 08:43:42 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1009 | 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] | 1010 | { |
| 1011 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1012 | |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 1013 | return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 || |
| 1014 | efx->n_rx_channels == 1) ? |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1015 | 0 : ARRAY_SIZE(efx->rx_indir_table)); |
| 1016 | } |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1017 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1018 | static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir) |
| 1019 | { |
| 1020 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1021 | |
| 1022 | memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table)); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1023 | return 0; |
| 1024 | } |
| 1025 | |
| 1026 | static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev, |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1027 | const u32 *indir) |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1028 | { |
| 1029 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1030 | |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1031 | memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table)); |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1032 | efx_nic_push_rx_indir_table(efx); |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Ben Hutchings | 62ebac9 | 2013-04-08 17:34:58 +0100 | [diff] [blame] | 1036 | int efx_ethtool_get_ts_info(struct net_device *net_dev, |
| 1037 | struct ethtool_ts_info *ts_info) |
| 1038 | { |
| 1039 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1040 | |
| 1041 | /* Software capabilities */ |
| 1042 | ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE | |
| 1043 | SOF_TIMESTAMPING_SOFTWARE); |
| 1044 | ts_info->phc_index = -1; |
| 1045 | |
| 1046 | efx_ptp_get_ts_info(efx, ts_info); |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 1050 | static int efx_ethtool_get_module_eeprom(struct net_device *net_dev, |
| 1051 | struct ethtool_eeprom *ee, |
| 1052 | u8 *data) |
| 1053 | { |
| 1054 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1055 | int ret; |
| 1056 | |
| 1057 | if (!efx->phy_op || !efx->phy_op->get_module_eeprom) |
| 1058 | return -EOPNOTSUPP; |
| 1059 | |
| 1060 | mutex_lock(&efx->mac_lock); |
| 1061 | ret = efx->phy_op->get_module_eeprom(efx, ee, data); |
| 1062 | mutex_unlock(&efx->mac_lock); |
| 1063 | |
| 1064 | return ret; |
| 1065 | } |
| 1066 | |
| 1067 | static int efx_ethtool_get_module_info(struct net_device *net_dev, |
| 1068 | struct ethtool_modinfo *modinfo) |
| 1069 | { |
| 1070 | struct efx_nic *efx = netdev_priv(net_dev); |
| 1071 | int ret; |
| 1072 | |
| 1073 | if (!efx->phy_op || !efx->phy_op->get_module_info) |
| 1074 | return -EOPNOTSUPP; |
| 1075 | |
| 1076 | mutex_lock(&efx->mac_lock); |
| 1077 | ret = efx->phy_op->get_module_info(efx, modinfo); |
| 1078 | mutex_unlock(&efx->mac_lock); |
| 1079 | |
| 1080 | return ret; |
| 1081 | } |
| 1082 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 1083 | const struct ethtool_ops efx_ethtool_ops = { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1084 | .get_settings = efx_ethtool_get_settings, |
| 1085 | .set_settings = efx_ethtool_set_settings, |
| 1086 | .get_drvinfo = efx_ethtool_get_drvinfo, |
Ben Hutchings | 5b98c1b | 2010-06-21 03:06:53 +0000 | [diff] [blame] | 1087 | .get_regs_len = efx_ethtool_get_regs_len, |
| 1088 | .get_regs = efx_ethtool_get_regs, |
Ben Hutchings | 62776d0 | 2010-06-23 11:30:07 +0000 | [diff] [blame] | 1089 | .get_msglevel = efx_ethtool_get_msglevel, |
| 1090 | .set_msglevel = efx_ethtool_set_msglevel, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1091 | .nway_reset = efx_ethtool_nway_reset, |
Ben Hutchings | ed4ba4b | 2010-12-09 12:10:25 +0000 | [diff] [blame] | 1092 | .get_link = ethtool_op_get_link, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1093 | .get_coalesce = efx_ethtool_get_coalesce, |
| 1094 | .set_coalesce = efx_ethtool_set_coalesce, |
Ben Hutchings | 4642610 | 2010-09-10 06:42:33 +0000 | [diff] [blame] | 1095 | .get_ringparam = efx_ethtool_get_ringparam, |
| 1096 | .set_ringparam = efx_ethtool_set_ringparam, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1097 | .get_pauseparam = efx_ethtool_get_pauseparam, |
| 1098 | .set_pauseparam = efx_ethtool_set_pauseparam, |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 1099 | .get_sset_count = efx_ethtool_get_sset_count, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 1100 | .self_test = efx_ethtool_self_test, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1101 | .get_strings = efx_ethtool_get_strings, |
Ben Hutchings | c5e129a | 2011-04-02 00:43:46 +0100 | [diff] [blame] | 1102 | .set_phys_id = efx_ethtool_phys_id, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1103 | .get_ethtool_stats = efx_ethtool_get_stats, |
Ben Hutchings | 89c758f | 2009-11-29 03:43:07 +0000 | [diff] [blame] | 1104 | .get_wol = efx_ethtool_get_wol, |
| 1105 | .set_wol = efx_ethtool_set_wol, |
Ben Hutchings | eb9f674 | 2009-11-29 03:43:15 +0000 | [diff] [blame] | 1106 | .reset = efx_ethtool_reset, |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1107 | .get_rxnfc = efx_ethtool_get_rxnfc, |
Ben Hutchings | b2bb7b7 | 2012-01-03 12:05:47 +0000 | [diff] [blame] | 1108 | .set_rxnfc = efx_ethtool_set_rxnfc, |
Ben Hutchings | 7850f63 | 2011-12-15 13:55:01 +0000 | [diff] [blame] | 1109 | .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size, |
Ben Hutchings | 765c9f4 | 2010-06-30 05:06:28 +0000 | [diff] [blame] | 1110 | .get_rxfh_indir = efx_ethtool_get_rxfh_indir, |
| 1111 | .set_rxfh_indir = efx_ethtool_set_rxfh_indir, |
Ben Hutchings | 62ebac9 | 2013-04-08 17:34:58 +0100 | [diff] [blame] | 1112 | .get_ts_info = efx_ethtool_get_ts_info, |
Stuart Hodgson | c087bd2 | 2012-05-01 18:50:43 +0100 | [diff] [blame] | 1113 | .get_module_info = efx_ethtool_get_module_info, |
| 1114 | .get_module_eeprom = efx_ethtool_get_module_eeprom, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 1115 | }; |