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. |
| 4 | * Copyright 2006-2008 Solarflare Communications Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published |
| 8 | * by the Free Software Foundation, incorporated herein by reference. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/netdevice.h> |
| 12 | #include <linux/ethtool.h> |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 13 | #include <linux/mdio.h> |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 14 | #include <linux/rtnetlink.h> |
| 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 | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 19 | #include "falcon.h" |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 20 | #include "spi.h" |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 21 | #include "mdio_10g.h" |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 22 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 23 | struct ethtool_string { |
| 24 | char name[ETH_GSTRING_LEN]; |
| 25 | }; |
| 26 | |
| 27 | struct efx_ethtool_stat { |
| 28 | const char *name; |
| 29 | enum { |
| 30 | EFX_ETHTOOL_STAT_SOURCE_mac_stats, |
| 31 | EFX_ETHTOOL_STAT_SOURCE_nic, |
| 32 | EFX_ETHTOOL_STAT_SOURCE_channel |
| 33 | } source; |
| 34 | unsigned offset; |
| 35 | u64(*get_stat) (void *field); /* Reader function */ |
| 36 | }; |
| 37 | |
| 38 | /* Initialiser for a struct #efx_ethtool_stat with type-checking */ |
| 39 | #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ |
| 40 | get_stat_function) { \ |
| 41 | .name = #stat_name, \ |
| 42 | .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ |
| 43 | .offset = ((((field_type *) 0) == \ |
| 44 | &((struct efx_##source_name *)0)->field) ? \ |
| 45 | offsetof(struct efx_##source_name, field) : \ |
| 46 | offsetof(struct efx_##source_name, field)), \ |
| 47 | .get_stat = get_stat_function, \ |
| 48 | } |
| 49 | |
| 50 | static u64 efx_get_uint_stat(void *field) |
| 51 | { |
| 52 | return *(unsigned int *)field; |
| 53 | } |
| 54 | |
| 55 | static u64 efx_get_ulong_stat(void *field) |
| 56 | { |
| 57 | return *(unsigned long *)field; |
| 58 | } |
| 59 | |
| 60 | static u64 efx_get_u64_stat(void *field) |
| 61 | { |
| 62 | return *(u64 *) field; |
| 63 | } |
| 64 | |
| 65 | static u64 efx_get_atomic_stat(void *field) |
| 66 | { |
| 67 | return atomic_read((atomic_t *) field); |
| 68 | } |
| 69 | |
| 70 | #define EFX_ETHTOOL_ULONG_MAC_STAT(field) \ |
| 71 | EFX_ETHTOOL_STAT(field, mac_stats, field, \ |
| 72 | unsigned long, efx_get_ulong_stat) |
| 73 | |
| 74 | #define EFX_ETHTOOL_U64_MAC_STAT(field) \ |
| 75 | EFX_ETHTOOL_STAT(field, mac_stats, field, \ |
| 76 | u64, efx_get_u64_stat) |
| 77 | |
| 78 | #define EFX_ETHTOOL_UINT_NIC_STAT(name) \ |
| 79 | EFX_ETHTOOL_STAT(name, nic, n_##name, \ |
| 80 | unsigned int, efx_get_uint_stat) |
| 81 | |
| 82 | #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ |
| 83 | EFX_ETHTOOL_STAT(field, nic, field, \ |
| 84 | atomic_t, efx_get_atomic_stat) |
| 85 | |
| 86 | #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ |
| 87 | EFX_ETHTOOL_STAT(field, channel, n_##field, \ |
| 88 | unsigned int, efx_get_uint_stat) |
| 89 | |
| 90 | static struct efx_ethtool_stat efx_ethtool_stats[] = { |
| 91 | EFX_ETHTOOL_U64_MAC_STAT(tx_bytes), |
| 92 | EFX_ETHTOOL_U64_MAC_STAT(tx_good_bytes), |
| 93 | EFX_ETHTOOL_U64_MAC_STAT(tx_bad_bytes), |
| 94 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_packets), |
| 95 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_bad), |
| 96 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_pause), |
| 97 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_control), |
| 98 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_unicast), |
| 99 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_multicast), |
| 100 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_broadcast), |
| 101 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_lt64), |
| 102 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_64), |
| 103 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_65_to_127), |
| 104 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_128_to_255), |
| 105 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_256_to_511), |
| 106 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_512_to_1023), |
| 107 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_1024_to_15xx), |
| 108 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_15xx_to_jumbo), |
| 109 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_gtjumbo), |
| 110 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_collision), |
| 111 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_single_collision), |
| 112 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_multiple_collision), |
| 113 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_collision), |
| 114 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_deferred), |
| 115 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_late_collision), |
| 116 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_excessive_deferred), |
| 117 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_non_tcpudp), |
| 118 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_mac_src_error), |
| 119 | EFX_ETHTOOL_ULONG_MAC_STAT(tx_ip_src_error), |
| 120 | EFX_ETHTOOL_U64_MAC_STAT(rx_bytes), |
| 121 | EFX_ETHTOOL_U64_MAC_STAT(rx_good_bytes), |
| 122 | EFX_ETHTOOL_U64_MAC_STAT(rx_bad_bytes), |
| 123 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_packets), |
| 124 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_good), |
| 125 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad), |
| 126 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_pause), |
| 127 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_control), |
| 128 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_unicast), |
| 129 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_multicast), |
| 130 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_broadcast), |
| 131 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_lt64), |
| 132 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_64), |
| 133 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_65_to_127), |
| 134 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_128_to_255), |
| 135 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_256_to_511), |
| 136 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_512_to_1023), |
| 137 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_1024_to_15xx), |
| 138 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_15xx_to_jumbo), |
| 139 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_gtjumbo), |
| 140 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_lt64), |
| 141 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_64_to_15xx), |
| 142 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_15xx_to_jumbo), |
| 143 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_bad_gtjumbo), |
| 144 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_overflow), |
| 145 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_missed), |
| 146 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_false_carrier), |
| 147 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_symbol_error), |
| 148 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_align_error), |
| 149 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_length_error), |
| 150 | EFX_ETHTOOL_ULONG_MAC_STAT(rx_internal_error), |
| 151 | EFX_ETHTOOL_UINT_NIC_STAT(rx_nodesc_drop_cnt), |
| 152 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
| 153 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), |
| 154 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), |
| 155 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), |
Ben Hutchings | c1ac403 | 2009-11-28 05:36:29 +0000 | [diff] [blame] | 156 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 157 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
| 158 | }; |
| 159 | |
| 160 | /* Number of ethtool statistics */ |
| 161 | #define EFX_ETHTOOL_NUM_STATS ARRAY_SIZE(efx_ethtool_stats) |
| 162 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 163 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 164 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 165 | /************************************************************************** |
| 166 | * |
| 167 | * Ethtool operations |
| 168 | * |
| 169 | ************************************************************************** |
| 170 | */ |
| 171 | |
| 172 | /* Identify device by flashing LEDs */ |
Ben Hutchings | 65f667f | 2008-12-12 21:32:10 -0800 | [diff] [blame] | 173 | static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 174 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 175 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 176 | |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 177 | do { |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 178 | falcon_board(efx)->type->set_id_led(efx, EFX_LED_ON); |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 179 | schedule_timeout_interruptible(HZ / 2); |
| 180 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 181 | falcon_board(efx)->type->set_id_led(efx, EFX_LED_OFF); |
Ben Hutchings | 398468e | 2009-11-23 16:03:45 +0000 | [diff] [blame] | 182 | schedule_timeout_interruptible(HZ / 2); |
| 183 | } while (!signal_pending(current) && --count != 0); |
| 184 | |
Ben Hutchings | 44838a4 | 2009-11-25 16:09:41 +0000 | [diff] [blame] | 185 | falcon_board(efx)->type->set_id_led(efx, EFX_LED_DEFAULT); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | /* This must be called with rtnl_lock held. */ |
| 190 | int efx_ethtool_get_settings(struct net_device *net_dev, |
| 191 | struct ethtool_cmd *ecmd) |
| 192 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 193 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 194 | |
| 195 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 196 | efx->phy_op->get_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 197 | mutex_unlock(&efx->mac_lock); |
| 198 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 199 | /* Falcon GMAC does not support 1000Mbps HD */ |
| 200 | ecmd->supported &= ~SUPPORTED_1000baseT_Half; |
| 201 | |
| 202 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* This must be called with rtnl_lock held. */ |
| 206 | int efx_ethtool_set_settings(struct net_device *net_dev, |
| 207 | struct ethtool_cmd *ecmd) |
| 208 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 209 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 210 | int rc; |
| 211 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 212 | /* Falcon GMAC does not support 1000Mbps HD */ |
| 213 | if (ecmd->speed == SPEED_1000 && ecmd->duplex != DUPLEX_FULL) { |
| 214 | EFX_LOG(efx, "rejecting unsupported 1000Mbps HD" |
| 215 | " setting\n"); |
| 216 | return -EINVAL; |
| 217 | } |
| 218 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 219 | mutex_lock(&efx->mac_lock); |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 220 | rc = efx->phy_op->set_settings(efx, ecmd); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 221 | mutex_unlock(&efx->mac_lock); |
| 222 | if (!rc) |
| 223 | efx_reconfigure_port(efx); |
| 224 | |
| 225 | return rc; |
| 226 | } |
| 227 | |
| 228 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, |
| 229 | struct ethtool_drvinfo *info) |
| 230 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 231 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 232 | |
| 233 | strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver)); |
| 234 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); |
| 235 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
| 236 | } |
| 237 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 238 | /** |
| 239 | * efx_fill_test - fill in an individual self-test entry |
| 240 | * @test_index: Index of the test |
| 241 | * @strings: Ethtool strings, or %NULL |
| 242 | * @data: Ethtool test results, or %NULL |
| 243 | * @test: Pointer to test result (used only if data != %NULL) |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 244 | * @unit_format: Unit name format (e.g. "chan\%d") |
| 245 | * @unit_id: Unit id (e.g. 0 for "chan0") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 246 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 247 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 248 | * |
| 249 | * Fill in an individual self-test entry. |
| 250 | */ |
| 251 | static void efx_fill_test(unsigned int test_index, |
| 252 | struct ethtool_string *strings, u64 *data, |
| 253 | int *test, const char *unit_format, int unit_id, |
| 254 | const char *test_format, const char *test_id) |
| 255 | { |
| 256 | struct ethtool_string unit_str, test_str; |
| 257 | |
| 258 | /* Fill data value, if applicable */ |
| 259 | if (data) |
| 260 | data[test_index] = *test; |
| 261 | |
| 262 | /* Fill string, if applicable */ |
| 263 | if (strings) { |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 264 | if (strchr(unit_format, '%')) |
| 265 | snprintf(unit_str.name, sizeof(unit_str.name), |
| 266 | unit_format, unit_id); |
| 267 | else |
| 268 | strcpy(unit_str.name, unit_format); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 269 | snprintf(test_str.name, sizeof(test_str.name), |
| 270 | test_format, test_id); |
| 271 | snprintf(strings[test_index].name, |
| 272 | sizeof(strings[test_index].name), |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 273 | "%-6s %-24s", unit_str.name, test_str.name); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
Ben Hutchings | 740ced9 | 2008-12-12 21:41:55 -0800 | [diff] [blame] | 277 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 278 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
| 279 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue |
| 280 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ |
Ben Hutchings | c459302 | 2009-11-23 16:08:17 +0000 | [diff] [blame] | 281 | "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * efx_fill_loopback_test - fill in a block of loopback self-test entries |
| 285 | * @efx: Efx NIC |
| 286 | * @lb_tests: Efx loopback self-test results structure |
| 287 | * @mode: Loopback test mode |
| 288 | * @test_index: Starting index of the test |
| 289 | * @strings: Ethtool strings, or %NULL |
| 290 | * @data: Ethtool test results, or %NULL |
| 291 | */ |
| 292 | static int efx_fill_loopback_test(struct efx_nic *efx, |
| 293 | struct efx_loopback_self_tests *lb_tests, |
| 294 | enum efx_loopback_mode mode, |
| 295 | unsigned int test_index, |
| 296 | struct ethtool_string *strings, u64 *data) |
| 297 | { |
| 298 | struct efx_tx_queue *tx_queue; |
| 299 | |
| 300 | efx_for_each_tx_queue(tx_queue, efx) { |
| 301 | efx_fill_test(test_index++, strings, data, |
| 302 | &lb_tests->tx_sent[tx_queue->queue], |
| 303 | EFX_TX_QUEUE_NAME(tx_queue), |
| 304 | EFX_LOOPBACK_NAME(mode, "tx_sent")); |
| 305 | efx_fill_test(test_index++, strings, data, |
| 306 | &lb_tests->tx_done[tx_queue->queue], |
| 307 | EFX_TX_QUEUE_NAME(tx_queue), |
| 308 | EFX_LOOPBACK_NAME(mode, "tx_done")); |
| 309 | } |
| 310 | efx_fill_test(test_index++, strings, data, |
| 311 | &lb_tests->rx_good, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 312 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 313 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
| 314 | efx_fill_test(test_index++, strings, data, |
| 315 | &lb_tests->rx_bad, |
Ben Hutchings | 11e6696 | 2008-12-12 22:05:48 -0800 | [diff] [blame] | 316 | "rx", 0, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 317 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
| 318 | |
| 319 | return test_index; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * efx_ethtool_fill_self_tests - get self-test details |
| 324 | * @efx: Efx NIC |
| 325 | * @tests: Efx self-test results structure, or %NULL |
| 326 | * @strings: Ethtool strings, or %NULL |
| 327 | * @data: Ethtool test results, or %NULL |
| 328 | */ |
| 329 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, |
| 330 | struct efx_self_tests *tests, |
| 331 | struct ethtool_string *strings, |
| 332 | u64 *data) |
| 333 | { |
| 334 | struct efx_channel *channel; |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 335 | unsigned int n = 0, i; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 336 | enum efx_loopback_mode mode; |
| 337 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 338 | efx_fill_test(n++, strings, data, &tests->mdio, |
| 339 | "core", 0, "mdio", NULL); |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 340 | efx_fill_test(n++, strings, data, &tests->nvram, |
| 341 | "core", 0, "nvram", NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 342 | efx_fill_test(n++, strings, data, &tests->interrupt, |
| 343 | "core", 0, "interrupt", NULL); |
| 344 | |
| 345 | /* Event queues */ |
| 346 | efx_for_each_channel(channel, efx) { |
| 347 | efx_fill_test(n++, strings, data, |
| 348 | &tests->eventq_dma[channel->channel], |
| 349 | EFX_CHANNEL_NAME(channel), |
| 350 | "eventq.dma", NULL); |
| 351 | efx_fill_test(n++, strings, data, |
| 352 | &tests->eventq_int[channel->channel], |
| 353 | EFX_CHANNEL_NAME(channel), |
| 354 | "eventq.int", NULL); |
| 355 | efx_fill_test(n++, strings, data, |
| 356 | &tests->eventq_poll[channel->channel], |
| 357 | EFX_CHANNEL_NAME(channel), |
| 358 | "eventq.poll", NULL); |
| 359 | } |
| 360 | |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 361 | efx_fill_test(n++, strings, data, &tests->registers, |
| 362 | "core", 0, "registers", NULL); |
Ben Hutchings | 1796721 | 2008-12-26 13:47:25 -0800 | [diff] [blame] | 363 | |
| 364 | for (i = 0; i < efx->phy_op->num_tests; i++) |
| 365 | efx_fill_test(n++, strings, data, &tests->phy[i], |
| 366 | "phy", 0, efx->phy_op->test_names[i], NULL); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 367 | |
| 368 | /* Loopback tests */ |
Ben Hutchings | 8c8661e | 2008-09-01 12:49:02 +0100 | [diff] [blame] | 369 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 370 | if (!(efx->loopback_modes & (1 << mode))) |
| 371 | continue; |
| 372 | n = efx_fill_loopback_test(efx, |
| 373 | &tests->loopback[mode], mode, n, |
| 374 | strings, data); |
| 375 | } |
| 376 | |
| 377 | return n; |
| 378 | } |
| 379 | |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 380 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
| 381 | int string_set) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 382 | { |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 383 | switch (string_set) { |
| 384 | case ETH_SS_STATS: |
| 385 | return EFX_ETHTOOL_NUM_STATS; |
| 386 | case ETH_SS_TEST: |
| 387 | return efx_ethtool_fill_self_tests(netdev_priv(net_dev), |
| 388 | NULL, NULL, NULL); |
| 389 | default: |
| 390 | return -EINVAL; |
| 391 | } |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 394 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
| 395 | u32 string_set, u8 *strings) |
| 396 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 397 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 398 | struct ethtool_string *ethtool_strings = |
| 399 | (struct ethtool_string *)strings; |
| 400 | int i; |
| 401 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 402 | switch (string_set) { |
| 403 | case ETH_SS_STATS: |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 404 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) |
| 405 | strncpy(ethtool_strings[i].name, |
| 406 | efx_ethtool_stats[i].name, |
| 407 | sizeof(ethtool_strings[i].name)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 408 | break; |
| 409 | case ETH_SS_TEST: |
| 410 | efx_ethtool_fill_self_tests(efx, NULL, |
| 411 | ethtool_strings, NULL); |
| 412 | break; |
| 413 | default: |
| 414 | /* No other string sets */ |
| 415 | break; |
| 416 | } |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | static void efx_ethtool_get_stats(struct net_device *net_dev, |
| 420 | struct ethtool_stats *stats, |
| 421 | u64 *data) |
| 422 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 423 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 424 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
| 425 | struct efx_ethtool_stat *stat; |
| 426 | struct efx_channel *channel; |
| 427 | int i; |
| 428 | |
| 429 | EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS); |
| 430 | |
| 431 | /* Update MAC and NIC statistics */ |
Stephen Hemminger | eeda3fd | 2008-11-19 21:40:23 -0800 | [diff] [blame] | 432 | dev_get_stats(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 433 | |
| 434 | /* Fill detailed statistics buffer */ |
| 435 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) { |
| 436 | stat = &efx_ethtool_stats[i]; |
| 437 | switch (stat->source) { |
| 438 | case EFX_ETHTOOL_STAT_SOURCE_mac_stats: |
| 439 | data[i] = stat->get_stat((void *)mac_stats + |
| 440 | stat->offset); |
| 441 | break; |
| 442 | case EFX_ETHTOOL_STAT_SOURCE_nic: |
| 443 | data[i] = stat->get_stat((void *)efx + stat->offset); |
| 444 | break; |
| 445 | case EFX_ETHTOOL_STAT_SOURCE_channel: |
| 446 | data[i] = 0; |
| 447 | efx_for_each_channel(channel, efx) |
| 448 | data[i] += stat->get_stat((void *)channel + |
| 449 | stat->offset); |
| 450 | break; |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 455 | static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable) |
| 456 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 457 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 458 | |
| 459 | /* No way to stop the hardware doing the checks; we just |
| 460 | * ignore the result. |
| 461 | */ |
Ben Hutchings | dc8cfa5 | 2008-09-01 12:46:50 +0100 | [diff] [blame] | 462 | efx->rx_checksum_enabled = !!enable; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev) |
| 468 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 469 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 470 | |
| 471 | return efx->rx_checksum_enabled; |
| 472 | } |
| 473 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 474 | static void efx_ethtool_self_test(struct net_device *net_dev, |
| 475 | struct ethtool_test *test, u64 *data) |
| 476 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 477 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 478 | struct efx_self_tests efx_tests; |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 479 | int already_up; |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 480 | int rc; |
| 481 | |
| 482 | ASSERT_RTNL(); |
| 483 | if (efx->state != STATE_RUNNING) { |
| 484 | rc = -EIO; |
| 485 | goto fail1; |
| 486 | } |
| 487 | |
| 488 | /* We need rx buffers and interrupts. */ |
| 489 | already_up = (efx->net_dev->flags & IFF_UP); |
| 490 | if (!already_up) { |
| 491 | rc = dev_open(efx->net_dev); |
| 492 | if (rc) { |
| 493 | EFX_ERR(efx, "failed opening device.\n"); |
| 494 | goto fail2; |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | memset(&efx_tests, 0, sizeof(efx_tests)); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 499 | |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 500 | rc = efx_selftest(efx, &efx_tests, test->flags); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 501 | |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 502 | if (!already_up) |
| 503 | dev_close(efx->net_dev); |
| 504 | |
Ben Hutchings | 2ef3068 | 2008-12-26 13:47:04 -0800 | [diff] [blame] | 505 | EFX_LOG(efx, "%s %sline self-tests\n", |
| 506 | rc == 0 ? "passed" : "failed", |
| 507 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 508 | |
| 509 | fail2: |
| 510 | fail1: |
| 511 | /* Fill ethtool results structures */ |
| 512 | efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data); |
| 513 | if (rc) |
| 514 | test->flags |= ETH_TEST_FL_FAILED; |
| 515 | } |
| 516 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 517 | /* Restart autonegotiation */ |
| 518 | static int efx_ethtool_nway_reset(struct net_device *net_dev) |
| 519 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 520 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 521 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 522 | return mdio45_nway_restart(&efx->mdio); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static u32 efx_ethtool_get_link(struct net_device *net_dev) |
| 526 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 527 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 528 | |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 529 | return efx->link_state.up; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 532 | static int efx_ethtool_get_eeprom_len(struct net_device *net_dev) |
| 533 | { |
| 534 | struct efx_nic *efx = netdev_priv(net_dev); |
| 535 | struct efx_spi_device *spi = efx->spi_eeprom; |
| 536 | |
| 537 | if (!spi) |
| 538 | return 0; |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 539 | return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) - |
| 540 | min(spi->size, EFX_EEPROM_BOOTCONFIG_START); |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static int efx_ethtool_get_eeprom(struct net_device *net_dev, |
| 544 | struct ethtool_eeprom *eeprom, u8 *buf) |
| 545 | { |
| 546 | struct efx_nic *efx = netdev_priv(net_dev); |
| 547 | struct efx_spi_device *spi = efx->spi_eeprom; |
| 548 | size_t len; |
| 549 | int rc; |
| 550 | |
Ben Hutchings | ca54a9f | 2008-12-12 22:06:24 -0800 | [diff] [blame] | 551 | rc = mutex_lock_interruptible(&efx->spi_lock); |
| 552 | if (rc) |
| 553 | return rc; |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 554 | rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 555 | eeprom->len, &len, buf); |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 556 | mutex_unlock(&efx->spi_lock); |
Ben Hutchings | ca54a9f | 2008-12-12 22:06:24 -0800 | [diff] [blame] | 557 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 558 | eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC; |
| 559 | eeprom->len = len; |
| 560 | return rc; |
| 561 | } |
| 562 | |
| 563 | static int efx_ethtool_set_eeprom(struct net_device *net_dev, |
| 564 | struct ethtool_eeprom *eeprom, u8 *buf) |
| 565 | { |
| 566 | struct efx_nic *efx = netdev_priv(net_dev); |
| 567 | struct efx_spi_device *spi = efx->spi_eeprom; |
| 568 | size_t len; |
| 569 | int rc; |
| 570 | |
| 571 | if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC) |
| 572 | return -EINVAL; |
| 573 | |
Ben Hutchings | ca54a9f | 2008-12-12 22:06:24 -0800 | [diff] [blame] | 574 | rc = mutex_lock_interruptible(&efx->spi_lock); |
| 575 | if (rc) |
| 576 | return rc; |
Ben Hutchings | 0a95f56 | 2008-11-04 20:33:11 +0000 | [diff] [blame] | 577 | rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 578 | eeprom->len, &len, buf); |
Ben Hutchings | f415072 | 2008-11-04 20:34:28 +0000 | [diff] [blame] | 579 | mutex_unlock(&efx->spi_lock); |
Ben Hutchings | ca54a9f | 2008-12-12 22:06:24 -0800 | [diff] [blame] | 580 | |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 581 | eeprom->len = len; |
| 582 | return rc; |
| 583 | } |
| 584 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 585 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
| 586 | struct ethtool_coalesce *coalesce) |
| 587 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 588 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 589 | struct efx_tx_queue *tx_queue; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 590 | struct efx_channel *channel; |
| 591 | |
| 592 | memset(coalesce, 0, sizeof(*coalesce)); |
| 593 | |
| 594 | /* Find lowest IRQ moderation across all used TX queues */ |
| 595 | coalesce->tx_coalesce_usecs_irq = ~((u32) 0); |
| 596 | efx_for_each_tx_queue(tx_queue, efx) { |
| 597 | channel = tx_queue->channel; |
| 598 | if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) { |
| 599 | if (channel->used_flags != EFX_USED_BY_RX_TX) |
| 600 | coalesce->tx_coalesce_usecs_irq = |
| 601 | channel->irq_moderation; |
| 602 | else |
| 603 | coalesce->tx_coalesce_usecs_irq = 0; |
| 604 | } |
| 605 | } |
| 606 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 607 | coalesce->use_adaptive_rx_coalesce = efx->irq_rx_adaptive; |
| 608 | coalesce->rx_coalesce_usecs_irq = efx->irq_rx_moderation; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 609 | |
Ben Hutchings | 0d86ebd | 2009-10-23 08:32:13 +0000 | [diff] [blame] | 610 | coalesce->tx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION; |
| 611 | coalesce->rx_coalesce_usecs_irq *= FALCON_IRQ_MOD_RESOLUTION; |
| 612 | |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | /* Set coalescing parameters |
| 617 | * The difficulties occur for shared channels |
| 618 | */ |
| 619 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, |
| 620 | struct ethtool_coalesce *coalesce) |
| 621 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 622 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 623 | struct efx_channel *channel; |
| 624 | struct efx_tx_queue *tx_queue; |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 625 | unsigned tx_usecs, rx_usecs, adaptive; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 626 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 627 | if (coalesce->use_adaptive_tx_coalesce) |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 628 | return -EOPNOTSUPP; |
| 629 | |
| 630 | if (coalesce->rx_coalesce_usecs || coalesce->tx_coalesce_usecs) { |
| 631 | EFX_ERR(efx, "invalid coalescing setting. " |
| 632 | "Only rx/tx_coalesce_usecs_irq are supported\n"); |
| 633 | return -EOPNOTSUPP; |
| 634 | } |
| 635 | |
| 636 | rx_usecs = coalesce->rx_coalesce_usecs_irq; |
| 637 | tx_usecs = coalesce->tx_coalesce_usecs_irq; |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 638 | adaptive = coalesce->use_adaptive_rx_coalesce; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 639 | |
| 640 | /* If the channel is shared only allow RX parameters to be set */ |
| 641 | efx_for_each_tx_queue(tx_queue, efx) { |
| 642 | if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) && |
| 643 | tx_usecs) { |
| 644 | EFX_ERR(efx, "Channel is shared. " |
| 645 | "Only RX coalescing may be set\n"); |
| 646 | return -EOPNOTSUPP; |
| 647 | } |
| 648 | } |
| 649 | |
Ben Hutchings | 6fb70fd | 2009-03-20 13:30:37 +0000 | [diff] [blame] | 650 | efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 651 | efx_for_each_channel(channel, efx) |
Ben Hutchings | ef2b90e | 2009-11-29 03:42:31 +0000 | [diff] [blame^] | 652 | efx->type->push_irq_moderation(channel); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
| 658 | struct ethtool_pauseparam *pause) |
| 659 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 660 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 661 | enum efx_fc_type wanted_fc; |
| 662 | bool reset; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 663 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 664 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
| 665 | (pause->tx_pause ? EFX_FC_TX : 0) | |
| 666 | (pause->autoneg ? EFX_FC_AUTO : 0)); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 667 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 668 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { |
| 669 | EFX_LOG(efx, "Flow control unsupported: tx ON rx OFF\n"); |
| 670 | return -EINVAL; |
| 671 | } |
| 672 | |
Ben Hutchings | 68e7f45 | 2009-04-29 08:05:08 +0000 | [diff] [blame] | 673 | if (!(efx->phy_op->mmds & MDIO_DEVS_AN) && |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 674 | (wanted_fc & EFX_FC_AUTO)) { |
| 675 | EFX_LOG(efx, "PHY does not support flow control " |
| 676 | "autonegotiation\n"); |
| 677 | return -EINVAL; |
| 678 | } |
| 679 | |
| 680 | /* TX flow control may automatically turn itself off if the |
| 681 | * link partner (intermittently) stops responding to pause |
| 682 | * frames. There isn't any indication that this has happened, |
| 683 | * so the best we do is leave it up to the user to spot this |
| 684 | * and fix it be cycling transmit flow control on this end. */ |
| 685 | reset = (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX); |
| 686 | if (EFX_WORKAROUND_11482(efx) && reset) { |
Ben Hutchings | daeda63 | 2009-11-28 05:36:04 +0000 | [diff] [blame] | 687 | if (efx_nic_rev(efx) == EFX_REV_FALCON_B0) { |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 688 | /* Recover by resetting the EM block */ |
Ben Hutchings | eb50c0d | 2009-11-23 16:06:30 +0000 | [diff] [blame] | 689 | if (efx->link_state.up) |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 690 | falcon_drain_tx_fifo(efx); |
| 691 | } else { |
| 692 | /* Schedule a reset to recover */ |
| 693 | efx_schedule_reset(efx, RESET_TYPE_INVISIBLE); |
| 694 | } |
| 695 | } |
| 696 | |
| 697 | /* Try to push the pause parameters */ |
| 698 | mutex_lock(&efx->mac_lock); |
| 699 | |
| 700 | efx->wanted_fc = wanted_fc; |
Ben Hutchings | 3f926da | 2009-04-29 08:20:37 +0000 | [diff] [blame] | 701 | if (efx->phy_op->mmds & MDIO_DEVS_AN) |
| 702 | mdio45_ethtool_spauseparam_an(&efx->mdio, pause); |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 703 | __efx_reconfigure_port(efx); |
| 704 | |
| 705 | mutex_unlock(&efx->mac_lock); |
| 706 | |
Ben Hutchings | 177dfcd | 2008-12-12 21:50:08 -0800 | [diff] [blame] | 707 | return 0; |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, |
| 711 | struct ethtool_pauseparam *pause) |
| 712 | { |
Ben Hutchings | 767e468 | 2008-09-01 12:43:14 +0100 | [diff] [blame] | 713 | struct efx_nic *efx = netdev_priv(net_dev); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 714 | |
Ben Hutchings | 04cc8ca | 2008-12-12 21:50:46 -0800 | [diff] [blame] | 715 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
| 716 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); |
| 717 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | |
Stephen Hemminger | 0fc0b73 | 2009-09-02 01:03:33 -0700 | [diff] [blame] | 721 | const struct ethtool_ops efx_ethtool_ops = { |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 722 | .get_settings = efx_ethtool_get_settings, |
| 723 | .set_settings = efx_ethtool_set_settings, |
| 724 | .get_drvinfo = efx_ethtool_get_drvinfo, |
| 725 | .nway_reset = efx_ethtool_nway_reset, |
| 726 | .get_link = efx_ethtool_get_link, |
Ben Hutchings | 4a5b504 | 2008-09-01 12:47:16 +0100 | [diff] [blame] | 727 | .get_eeprom_len = efx_ethtool_get_eeprom_len, |
| 728 | .get_eeprom = efx_ethtool_get_eeprom, |
| 729 | .set_eeprom = efx_ethtool_set_eeprom, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 730 | .get_coalesce = efx_ethtool_get_coalesce, |
| 731 | .set_coalesce = efx_ethtool_set_coalesce, |
| 732 | .get_pauseparam = efx_ethtool_get_pauseparam, |
| 733 | .set_pauseparam = efx_ethtool_set_pauseparam, |
| 734 | .get_rx_csum = efx_ethtool_get_rx_csum, |
| 735 | .set_rx_csum = efx_ethtool_set_rx_csum, |
| 736 | .get_tx_csum = ethtool_op_get_tx_csum, |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 737 | .set_tx_csum = ethtool_op_set_tx_csum, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 738 | .get_sg = ethtool_op_get_sg, |
| 739 | .set_sg = ethtool_op_set_sg, |
Ben Hutchings | b9b39b6 | 2008-05-07 12:51:12 +0100 | [diff] [blame] | 740 | .get_tso = ethtool_op_get_tso, |
Ben Hutchings | 60ac106 | 2008-09-01 12:44:59 +0100 | [diff] [blame] | 741 | .set_tso = ethtool_op_set_tso, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 742 | .get_flags = ethtool_op_get_flags, |
| 743 | .set_flags = ethtool_op_set_flags, |
Ben Hutchings | 3594e13 | 2008-09-01 12:48:12 +0100 | [diff] [blame] | 744 | .get_sset_count = efx_ethtool_get_sset_count, |
Ben Hutchings | 3273c2e | 2008-05-07 13:36:19 +0100 | [diff] [blame] | 745 | .self_test = efx_ethtool_self_test, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 746 | .get_strings = efx_ethtool_get_strings, |
| 747 | .phys_id = efx_ethtool_phys_id, |
Ben Hutchings | 8ceee66 | 2008-04-27 12:55:59 +0100 | [diff] [blame] | 748 | .get_ethtool_stats = efx_ethtool_get_stats, |
| 749 | }; |