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