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