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