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 BH |
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", | |
740ced99 BH |
29 | [LOOPBACK_PHYXS] = "PHYXS", |
30 | [LOOPBACK_PCS] = "PCS", | |
31 | [LOOPBACK_PMAPMD] = "PMA/PMD", | |
3273c2e8 BH |
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 | ||
4a5b504d | 174 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
4a5b504d | 175 | |
8ceee660 BH |
176 | /************************************************************************** |
177 | * | |
178 | * Ethtool operations | |
179 | * | |
180 | ************************************************************************** | |
181 | */ | |
182 | ||
183 | /* Identify device by flashing LEDs */ | |
65f667fb | 184 | static int efx_ethtool_phys_id(struct net_device *net_dev, u32 count) |
8ceee660 | 185 | { |
767e468c | 186 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
187 | |
188 | efx->board_info.blink(efx, 1); | |
65f667fb BH |
189 | set_current_state(TASK_INTERRUPTIBLE); |
190 | if (count) | |
191 | schedule_timeout(count * HZ); | |
192 | else | |
193 | schedule(); | |
8ceee660 BH |
194 | efx->board_info.blink(efx, 0); |
195 | return 0; | |
196 | } | |
197 | ||
198 | /* This must be called with rtnl_lock held. */ | |
199 | int efx_ethtool_get_settings(struct net_device *net_dev, | |
200 | struct ethtool_cmd *ecmd) | |
201 | { | |
767e468c | 202 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
203 | int rc; |
204 | ||
205 | mutex_lock(&efx->mac_lock); | |
206 | rc = falcon_xmac_get_settings(efx, ecmd); | |
207 | mutex_unlock(&efx->mac_lock); | |
208 | ||
209 | return rc; | |
210 | } | |
211 | ||
212 | /* This must be called with rtnl_lock held. */ | |
213 | int efx_ethtool_set_settings(struct net_device *net_dev, | |
214 | struct ethtool_cmd *ecmd) | |
215 | { | |
767e468c | 216 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
217 | int rc; |
218 | ||
219 | mutex_lock(&efx->mac_lock); | |
220 | rc = falcon_xmac_set_settings(efx, ecmd); | |
221 | mutex_unlock(&efx->mac_lock); | |
222 | if (!rc) | |
223 | efx_reconfigure_port(efx); | |
224 | ||
225 | return rc; | |
226 | } | |
227 | ||
228 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, | |
229 | struct ethtool_drvinfo *info) | |
230 | { | |
767e468c | 231 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
232 | |
233 | strlcpy(info->driver, EFX_DRIVER_NAME, sizeof(info->driver)); | |
234 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); | |
235 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); | |
236 | } | |
237 | ||
3273c2e8 BH |
238 | /** |
239 | * efx_fill_test - fill in an individual self-test entry | |
240 | * @test_index: Index of the test | |
241 | * @strings: Ethtool strings, or %NULL | |
242 | * @data: Ethtool test results, or %NULL | |
243 | * @test: Pointer to test result (used only if data != %NULL) | |
740ced99 BH |
244 | * @unit_format: Unit name format (e.g. "chan\%d") |
245 | * @unit_id: Unit id (e.g. 0 for "chan0") | |
3273c2e8 | 246 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
740ced99 | 247 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
3273c2e8 BH |
248 | * |
249 | * Fill in an individual self-test entry. | |
250 | */ | |
251 | static void efx_fill_test(unsigned int test_index, | |
252 | struct ethtool_string *strings, u64 *data, | |
253 | int *test, const char *unit_format, int unit_id, | |
254 | const char *test_format, const char *test_id) | |
255 | { | |
256 | struct ethtool_string unit_str, test_str; | |
257 | ||
258 | /* Fill data value, if applicable */ | |
259 | if (data) | |
260 | data[test_index] = *test; | |
261 | ||
262 | /* Fill string, if applicable */ | |
263 | if (strings) { | |
264 | snprintf(unit_str.name, sizeof(unit_str.name), | |
265 | unit_format, unit_id); | |
266 | snprintf(test_str.name, sizeof(test_str.name), | |
267 | test_format, test_id); | |
268 | snprintf(strings[test_index].name, | |
269 | sizeof(strings[test_index].name), | |
740ced99 | 270 | "%-6s %-24s", unit_str.name, test_str.name); |
3273c2e8 BH |
271 | } |
272 | } | |
273 | ||
274 | #define EFX_PORT_NAME "port%d", 0 | |
740ced99 | 275 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
3273c2e8 BH |
276 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
277 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue | |
278 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ | |
279 | "loopback.%s." _counter, LOOPBACK_MODE_NAME(mode) | |
280 | ||
281 | /** | |
282 | * efx_fill_loopback_test - fill in a block of loopback self-test entries | |
283 | * @efx: Efx NIC | |
284 | * @lb_tests: Efx loopback self-test results structure | |
285 | * @mode: Loopback test mode | |
286 | * @test_index: Starting index of the test | |
287 | * @strings: Ethtool strings, or %NULL | |
288 | * @data: Ethtool test results, or %NULL | |
289 | */ | |
290 | static int efx_fill_loopback_test(struct efx_nic *efx, | |
291 | struct efx_loopback_self_tests *lb_tests, | |
292 | enum efx_loopback_mode mode, | |
293 | unsigned int test_index, | |
294 | struct ethtool_string *strings, u64 *data) | |
295 | { | |
296 | struct efx_tx_queue *tx_queue; | |
297 | ||
298 | efx_for_each_tx_queue(tx_queue, efx) { | |
299 | efx_fill_test(test_index++, strings, data, | |
300 | &lb_tests->tx_sent[tx_queue->queue], | |
301 | EFX_TX_QUEUE_NAME(tx_queue), | |
302 | EFX_LOOPBACK_NAME(mode, "tx_sent")); | |
303 | efx_fill_test(test_index++, strings, data, | |
304 | &lb_tests->tx_done[tx_queue->queue], | |
305 | EFX_TX_QUEUE_NAME(tx_queue), | |
306 | EFX_LOOPBACK_NAME(mode, "tx_done")); | |
307 | } | |
308 | efx_fill_test(test_index++, strings, data, | |
309 | &lb_tests->rx_good, | |
310 | EFX_PORT_NAME, | |
311 | EFX_LOOPBACK_NAME(mode, "rx_good")); | |
312 | efx_fill_test(test_index++, strings, data, | |
313 | &lb_tests->rx_bad, | |
314 | EFX_PORT_NAME, | |
315 | EFX_LOOPBACK_NAME(mode, "rx_bad")); | |
316 | ||
317 | return test_index; | |
318 | } | |
319 | ||
320 | /** | |
321 | * efx_ethtool_fill_self_tests - get self-test details | |
322 | * @efx: Efx NIC | |
323 | * @tests: Efx self-test results structure, or %NULL | |
324 | * @strings: Ethtool strings, or %NULL | |
325 | * @data: Ethtool test results, or %NULL | |
326 | */ | |
327 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, | |
328 | struct efx_self_tests *tests, | |
329 | struct ethtool_string *strings, | |
330 | u64 *data) | |
331 | { | |
332 | struct efx_channel *channel; | |
333 | unsigned int n = 0; | |
334 | enum efx_loopback_mode mode; | |
335 | ||
8c8661e4 BH |
336 | efx_fill_test(n++, strings, data, &tests->mii, |
337 | "core", 0, "mii", NULL); | |
338 | efx_fill_test(n++, strings, data, &tests->nvram, | |
339 | "core", 0, "nvram", NULL); | |
3273c2e8 BH |
340 | efx_fill_test(n++, strings, data, &tests->interrupt, |
341 | "core", 0, "interrupt", NULL); | |
342 | ||
343 | /* Event queues */ | |
344 | efx_for_each_channel(channel, efx) { | |
345 | efx_fill_test(n++, strings, data, | |
346 | &tests->eventq_dma[channel->channel], | |
347 | EFX_CHANNEL_NAME(channel), | |
348 | "eventq.dma", NULL); | |
349 | efx_fill_test(n++, strings, data, | |
350 | &tests->eventq_int[channel->channel], | |
351 | EFX_CHANNEL_NAME(channel), | |
352 | "eventq.int", NULL); | |
353 | efx_fill_test(n++, strings, data, | |
354 | &tests->eventq_poll[channel->channel], | |
355 | EFX_CHANNEL_NAME(channel), | |
356 | "eventq.poll", NULL); | |
357 | } | |
358 | ||
8c8661e4 BH |
359 | efx_fill_test(n++, strings, data, &tests->registers, |
360 | "core", 0, "registers", NULL); | |
361 | efx_fill_test(n++, strings, data, &tests->phy, | |
362 | EFX_PORT_NAME, "phy", NULL); | |
3273c2e8 BH |
363 | |
364 | /* Loopback tests */ | |
365 | efx_fill_test(n++, strings, data, &tests->loopback_speed, | |
366 | EFX_PORT_NAME, "loopback.speed", NULL); | |
367 | efx_fill_test(n++, strings, data, &tests->loopback_full_duplex, | |
368 | EFX_PORT_NAME, "loopback.full_duplex", NULL); | |
8c8661e4 | 369 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
3273c2e8 BH |
370 | if (!(efx->loopback_modes & (1 << mode))) |
371 | continue; | |
372 | n = efx_fill_loopback_test(efx, | |
373 | &tests->loopback[mode], mode, n, | |
374 | strings, data); | |
375 | } | |
376 | ||
377 | return n; | |
378 | } | |
379 | ||
3594e131 BH |
380 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
381 | int string_set) | |
8ceee660 | 382 | { |
3594e131 BH |
383 | switch (string_set) { |
384 | case ETH_SS_STATS: | |
385 | return EFX_ETHTOOL_NUM_STATS; | |
386 | case ETH_SS_TEST: | |
387 | return efx_ethtool_fill_self_tests(netdev_priv(net_dev), | |
388 | NULL, NULL, NULL); | |
389 | default: | |
390 | return -EINVAL; | |
391 | } | |
3273c2e8 BH |
392 | } |
393 | ||
8ceee660 BH |
394 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
395 | u32 string_set, u8 *strings) | |
396 | { | |
767e468c | 397 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
398 | struct ethtool_string *ethtool_strings = |
399 | (struct ethtool_string *)strings; | |
400 | int i; | |
401 | ||
3273c2e8 BH |
402 | switch (string_set) { |
403 | case ETH_SS_STATS: | |
8ceee660 BH |
404 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) |
405 | strncpy(ethtool_strings[i].name, | |
406 | efx_ethtool_stats[i].name, | |
407 | sizeof(ethtool_strings[i].name)); | |
3273c2e8 BH |
408 | break; |
409 | case ETH_SS_TEST: | |
410 | efx_ethtool_fill_self_tests(efx, NULL, | |
411 | ethtool_strings, NULL); | |
412 | break; | |
413 | default: | |
414 | /* No other string sets */ | |
415 | break; | |
416 | } | |
8ceee660 BH |
417 | } |
418 | ||
419 | static void efx_ethtool_get_stats(struct net_device *net_dev, | |
420 | struct ethtool_stats *stats, | |
421 | u64 *data) | |
422 | { | |
767e468c | 423 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
424 | struct efx_mac_stats *mac_stats = &efx->mac_stats; |
425 | struct efx_ethtool_stat *stat; | |
426 | struct efx_channel *channel; | |
427 | int i; | |
428 | ||
429 | EFX_BUG_ON_PARANOID(stats->n_stats != EFX_ETHTOOL_NUM_STATS); | |
430 | ||
431 | /* Update MAC and NIC statistics */ | |
eeda3fd6 | 432 | dev_get_stats(net_dev); |
8ceee660 BH |
433 | |
434 | /* Fill detailed statistics buffer */ | |
435 | for (i = 0; i < EFX_ETHTOOL_NUM_STATS; i++) { | |
436 | stat = &efx_ethtool_stats[i]; | |
437 | switch (stat->source) { | |
438 | case EFX_ETHTOOL_STAT_SOURCE_mac_stats: | |
439 | data[i] = stat->get_stat((void *)mac_stats + | |
440 | stat->offset); | |
441 | break; | |
442 | case EFX_ETHTOOL_STAT_SOURCE_nic: | |
443 | data[i] = stat->get_stat((void *)efx + stat->offset); | |
444 | break; | |
445 | case EFX_ETHTOOL_STAT_SOURCE_channel: | |
446 | data[i] = 0; | |
447 | efx_for_each_channel(channel, efx) | |
448 | data[i] += stat->get_stat((void *)channel + | |
449 | stat->offset); | |
450 | break; | |
451 | } | |
452 | } | |
453 | } | |
454 | ||
8ceee660 BH |
455 | static int efx_ethtool_set_rx_csum(struct net_device *net_dev, u32 enable) |
456 | { | |
767e468c | 457 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
458 | |
459 | /* No way to stop the hardware doing the checks; we just | |
460 | * ignore the result. | |
461 | */ | |
dc8cfa55 | 462 | efx->rx_checksum_enabled = !!enable; |
8ceee660 BH |
463 | |
464 | return 0; | |
465 | } | |
466 | ||
467 | static u32 efx_ethtool_get_rx_csum(struct net_device *net_dev) | |
468 | { | |
767e468c | 469 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
470 | |
471 | return efx->rx_checksum_enabled; | |
472 | } | |
473 | ||
3273c2e8 BH |
474 | static void efx_ethtool_self_test(struct net_device *net_dev, |
475 | struct ethtool_test *test, u64 *data) | |
476 | { | |
767e468c | 477 | struct efx_nic *efx = netdev_priv(net_dev); |
3273c2e8 BH |
478 | struct efx_self_tests efx_tests; |
479 | int offline, already_up; | |
480 | int rc; | |
481 | ||
482 | ASSERT_RTNL(); | |
483 | if (efx->state != STATE_RUNNING) { | |
484 | rc = -EIO; | |
485 | goto fail1; | |
486 | } | |
487 | ||
488 | /* We need rx buffers and interrupts. */ | |
489 | already_up = (efx->net_dev->flags & IFF_UP); | |
490 | if (!already_up) { | |
491 | rc = dev_open(efx->net_dev); | |
492 | if (rc) { | |
493 | EFX_ERR(efx, "failed opening device.\n"); | |
494 | goto fail2; | |
495 | } | |
496 | } | |
497 | ||
498 | memset(&efx_tests, 0, sizeof(efx_tests)); | |
499 | offline = (test->flags & ETH_TEST_FL_OFFLINE); | |
500 | ||
501 | /* Perform online self tests first */ | |
502 | rc = efx_online_test(efx, &efx_tests); | |
503 | if (rc) | |
504 | goto out; | |
505 | ||
506 | /* Perform offline tests only if online tests passed */ | |
8c8661e4 | 507 | if (offline) |
bc3c90a2 BH |
508 | rc = efx_offline_test(efx, &efx_tests, |
509 | efx->loopback_modes); | |
3273c2e8 BH |
510 | |
511 | out: | |
512 | if (!already_up) | |
513 | dev_close(efx->net_dev); | |
514 | ||
515 | EFX_LOG(efx, "%s all %sline self-tests\n", | |
516 | rc == 0 ? "passed" : "failed", offline ? "off" : "on"); | |
517 | ||
518 | fail2: | |
519 | fail1: | |
520 | /* Fill ethtool results structures */ | |
521 | efx_ethtool_fill_self_tests(efx, &efx_tests, NULL, data); | |
522 | if (rc) | |
523 | test->flags |= ETH_TEST_FL_FAILED; | |
524 | } | |
525 | ||
8ceee660 BH |
526 | /* Restart autonegotiation */ |
527 | static int efx_ethtool_nway_reset(struct net_device *net_dev) | |
528 | { | |
767e468c | 529 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
530 | |
531 | return mii_nway_restart(&efx->mii); | |
532 | } | |
533 | ||
534 | static u32 efx_ethtool_get_link(struct net_device *net_dev) | |
535 | { | |
767e468c | 536 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
537 | |
538 | return efx->link_up; | |
539 | } | |
540 | ||
4a5b504d BH |
541 | static int efx_ethtool_get_eeprom_len(struct net_device *net_dev) |
542 | { | |
543 | struct efx_nic *efx = netdev_priv(net_dev); | |
544 | struct efx_spi_device *spi = efx->spi_eeprom; | |
545 | ||
546 | if (!spi) | |
547 | return 0; | |
0a95f563 BH |
548 | return min(spi->size, EFX_EEPROM_BOOTCONFIG_END) - |
549 | min(spi->size, EFX_EEPROM_BOOTCONFIG_START); | |
4a5b504d BH |
550 | } |
551 | ||
552 | static int efx_ethtool_get_eeprom(struct net_device *net_dev, | |
553 | struct ethtool_eeprom *eeprom, u8 *buf) | |
554 | { | |
555 | struct efx_nic *efx = netdev_priv(net_dev); | |
556 | struct efx_spi_device *spi = efx->spi_eeprom; | |
557 | size_t len; | |
558 | int rc; | |
559 | ||
f4150724 | 560 | mutex_lock(&efx->spi_lock); |
0a95f563 | 561 | rc = falcon_spi_read(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START, |
4a5b504d | 562 | eeprom->len, &len, buf); |
f4150724 | 563 | mutex_unlock(&efx->spi_lock); |
4a5b504d BH |
564 | eeprom->magic = EFX_ETHTOOL_EEPROM_MAGIC; |
565 | eeprom->len = len; | |
566 | return rc; | |
567 | } | |
568 | ||
569 | static int efx_ethtool_set_eeprom(struct net_device *net_dev, | |
570 | struct ethtool_eeprom *eeprom, u8 *buf) | |
571 | { | |
572 | struct efx_nic *efx = netdev_priv(net_dev); | |
573 | struct efx_spi_device *spi = efx->spi_eeprom; | |
574 | size_t len; | |
575 | int rc; | |
576 | ||
577 | if (eeprom->magic != EFX_ETHTOOL_EEPROM_MAGIC) | |
578 | return -EINVAL; | |
579 | ||
f4150724 | 580 | mutex_lock(&efx->spi_lock); |
0a95f563 | 581 | rc = falcon_spi_write(spi, eeprom->offset + EFX_EEPROM_BOOTCONFIG_START, |
4a5b504d | 582 | eeprom->len, &len, buf); |
f4150724 | 583 | mutex_unlock(&efx->spi_lock); |
4a5b504d BH |
584 | eeprom->len = len; |
585 | return rc; | |
586 | } | |
587 | ||
8ceee660 BH |
588 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
589 | struct ethtool_coalesce *coalesce) | |
590 | { | |
767e468c | 591 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
592 | struct efx_tx_queue *tx_queue; |
593 | struct efx_rx_queue *rx_queue; | |
594 | struct efx_channel *channel; | |
595 | ||
596 | memset(coalesce, 0, sizeof(*coalesce)); | |
597 | ||
598 | /* Find lowest IRQ moderation across all used TX queues */ | |
599 | coalesce->tx_coalesce_usecs_irq = ~((u32) 0); | |
600 | efx_for_each_tx_queue(tx_queue, efx) { | |
601 | channel = tx_queue->channel; | |
602 | if (channel->irq_moderation < coalesce->tx_coalesce_usecs_irq) { | |
603 | if (channel->used_flags != EFX_USED_BY_RX_TX) | |
604 | coalesce->tx_coalesce_usecs_irq = | |
605 | channel->irq_moderation; | |
606 | else | |
607 | coalesce->tx_coalesce_usecs_irq = 0; | |
608 | } | |
609 | } | |
610 | ||
611 | /* Find lowest IRQ moderation across all used RX queues */ | |
612 | coalesce->rx_coalesce_usecs_irq = ~((u32) 0); | |
613 | efx_for_each_rx_queue(rx_queue, efx) { | |
614 | channel = rx_queue->channel; | |
615 | if (channel->irq_moderation < coalesce->rx_coalesce_usecs_irq) | |
616 | coalesce->rx_coalesce_usecs_irq = | |
617 | channel->irq_moderation; | |
618 | } | |
619 | ||
620 | return 0; | |
621 | } | |
622 | ||
623 | /* Set coalescing parameters | |
624 | * The difficulties occur for shared channels | |
625 | */ | |
626 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, | |
627 | struct ethtool_coalesce *coalesce) | |
628 | { | |
767e468c | 629 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
630 | struct efx_channel *channel; |
631 | struct efx_tx_queue *tx_queue; | |
632 | unsigned tx_usecs, rx_usecs; | |
633 | ||
634 | if (coalesce->use_adaptive_rx_coalesce || | |
635 | coalesce->use_adaptive_tx_coalesce) | |
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; | |
646 | ||
647 | /* If the channel is shared only allow RX parameters to be set */ | |
648 | efx_for_each_tx_queue(tx_queue, efx) { | |
649 | if ((tx_queue->channel->used_flags == EFX_USED_BY_RX_TX) && | |
650 | tx_usecs) { | |
651 | EFX_ERR(efx, "Channel is shared. " | |
652 | "Only RX coalescing may be set\n"); | |
653 | return -EOPNOTSUPP; | |
654 | } | |
655 | } | |
656 | ||
657 | efx_init_irq_moderation(efx, tx_usecs, rx_usecs); | |
658 | ||
659 | /* Reset channel to pick up new moderation value. Note that | |
660 | * this may change the value of the irq_moderation field | |
661 | * (e.g. to allow for hardware timer granularity). | |
662 | */ | |
663 | efx_for_each_channel(channel, efx) | |
664 | falcon_set_int_moderation(channel); | |
665 | ||
666 | return 0; | |
667 | } | |
668 | ||
669 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, | |
670 | struct ethtool_pauseparam *pause) | |
671 | { | |
767e468c | 672 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
673 | enum efx_fc_type flow_control = efx->flow_control; |
674 | int rc; | |
675 | ||
676 | flow_control &= ~(EFX_FC_RX | EFX_FC_TX | EFX_FC_AUTO); | |
677 | flow_control |= pause->rx_pause ? EFX_FC_RX : 0; | |
678 | flow_control |= pause->tx_pause ? EFX_FC_TX : 0; | |
679 | flow_control |= pause->autoneg ? EFX_FC_AUTO : 0; | |
680 | ||
681 | /* Try to push the pause parameters */ | |
682 | mutex_lock(&efx->mac_lock); | |
683 | rc = falcon_xmac_set_pause(efx, flow_control); | |
684 | mutex_unlock(&efx->mac_lock); | |
685 | ||
686 | if (!rc) | |
687 | efx_reconfigure_port(efx); | |
688 | ||
689 | return rc; | |
690 | } | |
691 | ||
692 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, | |
693 | struct ethtool_pauseparam *pause) | |
694 | { | |
767e468c | 695 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 696 | |
dc8cfa55 BH |
697 | pause->rx_pause = !!(efx->flow_control & EFX_FC_RX); |
698 | pause->tx_pause = !!(efx->flow_control & EFX_FC_TX); | |
699 | pause->autoneg = !!(efx->flow_control & EFX_FC_AUTO); | |
8ceee660 BH |
700 | } |
701 | ||
702 | ||
703 | struct ethtool_ops efx_ethtool_ops = { | |
704 | .get_settings = efx_ethtool_get_settings, | |
705 | .set_settings = efx_ethtool_set_settings, | |
706 | .get_drvinfo = efx_ethtool_get_drvinfo, | |
707 | .nway_reset = efx_ethtool_nway_reset, | |
708 | .get_link = efx_ethtool_get_link, | |
4a5b504d BH |
709 | .get_eeprom_len = efx_ethtool_get_eeprom_len, |
710 | .get_eeprom = efx_ethtool_get_eeprom, | |
711 | .set_eeprom = efx_ethtool_set_eeprom, | |
8ceee660 BH |
712 | .get_coalesce = efx_ethtool_get_coalesce, |
713 | .set_coalesce = efx_ethtool_set_coalesce, | |
714 | .get_pauseparam = efx_ethtool_get_pauseparam, | |
715 | .set_pauseparam = efx_ethtool_set_pauseparam, | |
716 | .get_rx_csum = efx_ethtool_get_rx_csum, | |
717 | .set_rx_csum = efx_ethtool_set_rx_csum, | |
718 | .get_tx_csum = ethtool_op_get_tx_csum, | |
60ac1065 | 719 | .set_tx_csum = ethtool_op_set_tx_csum, |
8ceee660 BH |
720 | .get_sg = ethtool_op_get_sg, |
721 | .set_sg = ethtool_op_set_sg, | |
b9b39b62 | 722 | .get_tso = ethtool_op_get_tso, |
60ac1065 | 723 | .set_tso = ethtool_op_set_tso, |
8ceee660 BH |
724 | .get_flags = ethtool_op_get_flags, |
725 | .set_flags = ethtool_op_set_flags, | |
3594e131 | 726 | .get_sset_count = efx_ethtool_get_sset_count, |
3273c2e8 | 727 | .self_test = efx_ethtool_self_test, |
8ceee660 BH |
728 | .get_strings = efx_ethtool_get_strings, |
729 | .phys_id = efx_ethtool_phys_id, | |
8ceee660 BH |
730 | .get_ethtool_stats = efx_ethtool_get_stats, |
731 | }; |