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