]>
Commit | Line | Data |
---|---|---|
8ceee660 | 1 | /**************************************************************************** |
f7a6d2c4 | 2 | * Driver for Solarflare network controllers and boards |
8ceee660 | 3 | * Copyright 2005-2006 Fen Systems Ltd. |
f7a6d2c4 | 4 | * Copyright 2006-2013 Solarflare Communications Inc. |
8ceee660 BH |
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> | |
c39d35eb | 14 | #include <linux/in.h> |
8ceee660 | 15 | #include "net_driver.h" |
04cc8cac | 16 | #include "workarounds.h" |
3273c2e8 | 17 | #include "selftest.h" |
8ceee660 | 18 | #include "efx.h" |
b4187e42 | 19 | #include "filter.h" |
744093c9 | 20 | #include "nic.h" |
8ceee660 | 21 | |
cd0ecc9a | 22 | struct efx_sw_stat_desc { |
8ceee660 BH |
23 | const char *name; |
24 | enum { | |
8ceee660 | 25 | EFX_ETHTOOL_STAT_SOURCE_nic, |
119226c5 BH |
26 | EFX_ETHTOOL_STAT_SOURCE_channel, |
27 | EFX_ETHTOOL_STAT_SOURCE_tx_queue | |
8ceee660 BH |
28 | } source; |
29 | unsigned offset; | |
30 | u64(*get_stat) (void *field); /* Reader function */ | |
31 | }; | |
32 | ||
cd0ecc9a | 33 | /* Initialiser for a struct efx_sw_stat_desc with type-checking */ |
8ceee660 BH |
34 | #define EFX_ETHTOOL_STAT(stat_name, source_name, field, field_type, \ |
35 | get_stat_function) { \ | |
36 | .name = #stat_name, \ | |
37 | .source = EFX_ETHTOOL_STAT_SOURCE_##source_name, \ | |
38 | .offset = ((((field_type *) 0) == \ | |
39 | &((struct efx_##source_name *)0)->field) ? \ | |
40 | offsetof(struct efx_##source_name, field) : \ | |
41 | offsetof(struct efx_##source_name, field)), \ | |
42 | .get_stat = get_stat_function, \ | |
43 | } | |
44 | ||
45 | static u64 efx_get_uint_stat(void *field) | |
46 | { | |
47 | return *(unsigned int *)field; | |
48 | } | |
49 | ||
8ceee660 BH |
50 | static u64 efx_get_atomic_stat(void *field) |
51 | { | |
52 | return atomic_read((atomic_t *) field); | |
53 | } | |
54 | ||
8ceee660 BH |
55 | #define EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(field) \ |
56 | EFX_ETHTOOL_STAT(field, nic, field, \ | |
57 | atomic_t, efx_get_atomic_stat) | |
58 | ||
59 | #define EFX_ETHTOOL_UINT_CHANNEL_STAT(field) \ | |
60 | EFX_ETHTOOL_STAT(field, channel, n_##field, \ | |
61 | unsigned int, efx_get_uint_stat) | |
62 | ||
119226c5 BH |
63 | #define EFX_ETHTOOL_UINT_TXQ_STAT(field) \ |
64 | EFX_ETHTOOL_STAT(tx_##field, tx_queue, field, \ | |
65 | unsigned int, efx_get_uint_stat) | |
66 | ||
cd0ecc9a | 67 | static const struct efx_sw_stat_desc efx_sw_stat_desc[] = { |
02e12165 | 68 | EFX_ETHTOOL_UINT_TXQ_STAT(merge_events), |
119226c5 BH |
69 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_bursts), |
70 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_long_headers), | |
71 | EFX_ETHTOOL_UINT_TXQ_STAT(tso_packets), | |
72 | EFX_ETHTOOL_UINT_TXQ_STAT(pushes), | |
ee45fd92 | 73 | EFX_ETHTOOL_UINT_TXQ_STAT(pio_packets), |
e9117e50 | 74 | EFX_ETHTOOL_UINT_TXQ_STAT(cb_packets), |
8ceee660 BH |
75 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
76 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), | |
77 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), | |
78 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), | |
c1ac403b | 79 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
8ceee660 | 80 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
8127d661 BH |
81 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_events), |
82 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_merge_packets), | |
8ceee660 BH |
83 | }; |
84 | ||
cd0ecc9a | 85 | #define EFX_ETHTOOL_SW_STAT_COUNT ARRAY_SIZE(efx_sw_stat_desc) |
8ceee660 | 86 | |
4a5b504d | 87 | #define EFX_ETHTOOL_EEPROM_MAGIC 0xEFAB |
4a5b504d | 88 | |
8ceee660 BH |
89 | /************************************************************************** |
90 | * | |
91 | * Ethtool operations | |
92 | * | |
93 | ************************************************************************** | |
94 | */ | |
95 | ||
96 | /* Identify device by flashing LEDs */ | |
c5e129ac BH |
97 | static int efx_ethtool_phys_id(struct net_device *net_dev, |
98 | enum ethtool_phys_id_state state) | |
8ceee660 | 99 | { |
767e468c | 100 | struct efx_nic *efx = netdev_priv(net_dev); |
fce55922 | 101 | enum efx_led_mode mode = EFX_LED_DEFAULT; |
8ceee660 | 102 | |
c5e129ac BH |
103 | switch (state) { |
104 | case ETHTOOL_ID_ON: | |
105 | mode = EFX_LED_ON; | |
106 | break; | |
107 | case ETHTOOL_ID_OFF: | |
108 | mode = EFX_LED_OFF; | |
109 | break; | |
110 | case ETHTOOL_ID_INACTIVE: | |
111 | mode = EFX_LED_DEFAULT; | |
112 | break; | |
fce55922 AB |
113 | case ETHTOOL_ID_ACTIVE: |
114 | return 1; /* cycle on/off once per second */ | |
c5e129ac | 115 | } |
398468ed | 116 | |
c5e129ac | 117 | efx->type->set_id_led(efx, mode); |
8ceee660 BH |
118 | return 0; |
119 | } | |
120 | ||
121 | /* This must be called with rtnl_lock held. */ | |
d215697f | 122 | static int efx_ethtool_get_settings(struct net_device *net_dev, |
123 | struct ethtool_cmd *ecmd) | |
8ceee660 | 124 | { |
767e468c | 125 | struct efx_nic *efx = netdev_priv(net_dev); |
d3245b28 | 126 | struct efx_link_state *link_state = &efx->link_state; |
8ceee660 BH |
127 | |
128 | mutex_lock(&efx->mac_lock); | |
177dfcd8 | 129 | efx->phy_op->get_settings(efx, ecmd); |
8ceee660 BH |
130 | mutex_unlock(&efx->mac_lock); |
131 | ||
d3245b28 BH |
132 | /* Both MACs support pause frames (bidirectional and respond-only) */ |
133 | ecmd->supported |= SUPPORTED_Pause | SUPPORTED_Asym_Pause; | |
134 | ||
135 | if (LOOPBACK_INTERNAL(efx)) { | |
70739497 | 136 | ethtool_cmd_speed_set(ecmd, link_state->speed); |
d3245b28 BH |
137 | ecmd->duplex = link_state->fd ? DUPLEX_FULL : DUPLEX_HALF; |
138 | } | |
177dfcd8 BH |
139 | |
140 | return 0; | |
8ceee660 BH |
141 | } |
142 | ||
143 | /* This must be called with rtnl_lock held. */ | |
d215697f | 144 | static int efx_ethtool_set_settings(struct net_device *net_dev, |
145 | struct ethtool_cmd *ecmd) | |
8ceee660 | 146 | { |
767e468c | 147 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
148 | int rc; |
149 | ||
754c653a | 150 | /* GMAC does not support 1000Mbps HD */ |
25db0338 DD |
151 | if ((ethtool_cmd_speed(ecmd) == SPEED_1000) && |
152 | (ecmd->duplex != DUPLEX_FULL)) { | |
62776d03 BH |
153 | netif_dbg(efx, drv, efx->net_dev, |
154 | "rejecting unsupported 1000Mbps HD setting\n"); | |
177dfcd8 BH |
155 | return -EINVAL; |
156 | } | |
157 | ||
8ceee660 | 158 | mutex_lock(&efx->mac_lock); |
177dfcd8 | 159 | rc = efx->phy_op->set_settings(efx, ecmd); |
8ceee660 | 160 | mutex_unlock(&efx->mac_lock); |
8ceee660 BH |
161 | return rc; |
162 | } | |
163 | ||
164 | static void efx_ethtool_get_drvinfo(struct net_device *net_dev, | |
165 | struct ethtool_drvinfo *info) | |
166 | { | |
767e468c | 167 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 168 | |
c5d5f5fd | 169 | strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); |
8ceee660 | 170 | strlcpy(info->version, EFX_DRIVER_VERSION, sizeof(info->version)); |
8880f4ec | 171 | if (efx_nic_rev(efx) >= EFX_REV_SIENA_A0) |
e5f0fd27 BH |
172 | efx_mcdi_print_fwver(efx, info->fw_version, |
173 | sizeof(info->fw_version)); | |
8ceee660 BH |
174 | strlcpy(info->bus_info, pci_name(efx->pci_dev), sizeof(info->bus_info)); |
175 | } | |
176 | ||
5b98c1bf BH |
177 | static int efx_ethtool_get_regs_len(struct net_device *net_dev) |
178 | { | |
179 | return efx_nic_get_regs_len(netdev_priv(net_dev)); | |
180 | } | |
181 | ||
182 | static void efx_ethtool_get_regs(struct net_device *net_dev, | |
183 | struct ethtool_regs *regs, void *buf) | |
184 | { | |
185 | struct efx_nic *efx = netdev_priv(net_dev); | |
186 | ||
187 | regs->version = efx->type->revision; | |
188 | efx_nic_get_regs(efx, buf); | |
189 | } | |
190 | ||
62776d03 BH |
191 | static u32 efx_ethtool_get_msglevel(struct net_device *net_dev) |
192 | { | |
193 | struct efx_nic *efx = netdev_priv(net_dev); | |
194 | return efx->msg_enable; | |
195 | } | |
196 | ||
197 | static void efx_ethtool_set_msglevel(struct net_device *net_dev, u32 msg_enable) | |
198 | { | |
199 | struct efx_nic *efx = netdev_priv(net_dev); | |
200 | efx->msg_enable = msg_enable; | |
201 | } | |
202 | ||
3273c2e8 BH |
203 | /** |
204 | * efx_fill_test - fill in an individual self-test entry | |
205 | * @test_index: Index of the test | |
206 | * @strings: Ethtool strings, or %NULL | |
207 | * @data: Ethtool test results, or %NULL | |
208 | * @test: Pointer to test result (used only if data != %NULL) | |
740ced99 BH |
209 | * @unit_format: Unit name format (e.g. "chan\%d") |
210 | * @unit_id: Unit id (e.g. 0 for "chan0") | |
3273c2e8 | 211 | * @test_format: Test name format (e.g. "loopback.\%s.tx.sent") |
740ced99 | 212 | * @test_id: Test id (e.g. "PHYXS" for "loopback.PHYXS.tx_sent") |
3273c2e8 BH |
213 | * |
214 | * Fill in an individual self-test entry. | |
215 | */ | |
b681e57c | 216 | static void efx_fill_test(unsigned int test_index, u8 *strings, u64 *data, |
3273c2e8 BH |
217 | int *test, const char *unit_format, int unit_id, |
218 | const char *test_format, const char *test_id) | |
219 | { | |
b681e57c | 220 | char unit_str[ETH_GSTRING_LEN], test_str[ETH_GSTRING_LEN]; |
3273c2e8 BH |
221 | |
222 | /* Fill data value, if applicable */ | |
223 | if (data) | |
224 | data[test_index] = *test; | |
225 | ||
226 | /* Fill string, if applicable */ | |
227 | if (strings) { | |
11e66966 | 228 | if (strchr(unit_format, '%')) |
b681e57c | 229 | snprintf(unit_str, sizeof(unit_str), |
11e66966 BH |
230 | unit_format, unit_id); |
231 | else | |
b681e57c BH |
232 | strcpy(unit_str, unit_format); |
233 | snprintf(test_str, sizeof(test_str), test_format, test_id); | |
234 | snprintf(strings + test_index * ETH_GSTRING_LEN, | |
235 | ETH_GSTRING_LEN, | |
236 | "%-6s %-24s", unit_str, test_str); | |
3273c2e8 BH |
237 | } |
238 | } | |
239 | ||
740ced99 | 240 | #define EFX_CHANNEL_NAME(_channel) "chan%d", _channel->channel |
3273c2e8 BH |
241 | #define EFX_TX_QUEUE_NAME(_tx_queue) "txq%d", _tx_queue->queue |
242 | #define EFX_RX_QUEUE_NAME(_rx_queue) "rxq%d", _rx_queue->queue | |
243 | #define EFX_LOOPBACK_NAME(_mode, _counter) \ | |
c459302d | 244 | "loopback.%s." _counter, STRING_TABLE_LOOKUP(_mode, efx_loopback_mode) |
3273c2e8 BH |
245 | |
246 | /** | |
247 | * efx_fill_loopback_test - fill in a block of loopback self-test entries | |
248 | * @efx: Efx NIC | |
249 | * @lb_tests: Efx loopback self-test results structure | |
250 | * @mode: Loopback test mode | |
251 | * @test_index: Starting index of the test | |
252 | * @strings: Ethtool strings, or %NULL | |
253 | * @data: Ethtool test results, or %NULL | |
17e678d1 BH |
254 | * |
255 | * Fill in a block of loopback self-test entries. Return new test | |
256 | * index. | |
3273c2e8 BH |
257 | */ |
258 | static int efx_fill_loopback_test(struct efx_nic *efx, | |
259 | struct efx_loopback_self_tests *lb_tests, | |
260 | enum efx_loopback_mode mode, | |
261 | unsigned int test_index, | |
b681e57c | 262 | u8 *strings, u64 *data) |
3273c2e8 | 263 | { |
1ac0226e BH |
264 | struct efx_channel *channel = |
265 | efx_get_channel(efx, efx->tx_channel_offset); | |
3273c2e8 BH |
266 | struct efx_tx_queue *tx_queue; |
267 | ||
f7d12cdc | 268 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
3273c2e8 BH |
269 | efx_fill_test(test_index++, strings, data, |
270 | &lb_tests->tx_sent[tx_queue->queue], | |
271 | EFX_TX_QUEUE_NAME(tx_queue), | |
272 | EFX_LOOPBACK_NAME(mode, "tx_sent")); | |
273 | efx_fill_test(test_index++, strings, data, | |
274 | &lb_tests->tx_done[tx_queue->queue], | |
275 | EFX_TX_QUEUE_NAME(tx_queue), | |
276 | EFX_LOOPBACK_NAME(mode, "tx_done")); | |
277 | } | |
278 | efx_fill_test(test_index++, strings, data, | |
279 | &lb_tests->rx_good, | |
11e66966 | 280 | "rx", 0, |
3273c2e8 BH |
281 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
282 | efx_fill_test(test_index++, strings, data, | |
283 | &lb_tests->rx_bad, | |
11e66966 | 284 | "rx", 0, |
3273c2e8 BH |
285 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
286 | ||
287 | return test_index; | |
288 | } | |
289 | ||
290 | /** | |
291 | * efx_ethtool_fill_self_tests - get self-test details | |
292 | * @efx: Efx NIC | |
293 | * @tests: Efx self-test results structure, or %NULL | |
294 | * @strings: Ethtool strings, or %NULL | |
295 | * @data: Ethtool test results, or %NULL | |
17e678d1 BH |
296 | * |
297 | * Get self-test number of strings, strings, and/or test results. | |
298 | * Return number of strings (== number of test results). | |
299 | * | |
300 | * The reason for merging these three functions is to make sure that | |
301 | * they can never be inconsistent. | |
3273c2e8 BH |
302 | */ |
303 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, | |
304 | struct efx_self_tests *tests, | |
b681e57c | 305 | u8 *strings, u64 *data) |
3273c2e8 BH |
306 | { |
307 | struct efx_channel *channel; | |
1796721a | 308 | unsigned int n = 0, i; |
3273c2e8 BH |
309 | enum efx_loopback_mode mode; |
310 | ||
4f16c073 BH |
311 | efx_fill_test(n++, strings, data, &tests->phy_alive, |
312 | "phy", 0, "alive", NULL); | |
8c8661e4 BH |
313 | efx_fill_test(n++, strings, data, &tests->nvram, |
314 | "core", 0, "nvram", NULL); | |
3273c2e8 BH |
315 | efx_fill_test(n++, strings, data, &tests->interrupt, |
316 | "core", 0, "interrupt", NULL); | |
317 | ||
318 | /* Event queues */ | |
319 | efx_for_each_channel(channel, efx) { | |
320 | efx_fill_test(n++, strings, data, | |
321 | &tests->eventq_dma[channel->channel], | |
322 | EFX_CHANNEL_NAME(channel), | |
323 | "eventq.dma", NULL); | |
324 | efx_fill_test(n++, strings, data, | |
325 | &tests->eventq_int[channel->channel], | |
326 | EFX_CHANNEL_NAME(channel), | |
327 | "eventq.int", NULL); | |
3273c2e8 BH |
328 | } |
329 | ||
74cd60a4 JC |
330 | efx_fill_test(n++, strings, data, &tests->memory, |
331 | "core", 0, "memory", NULL); | |
8c8661e4 BH |
332 | efx_fill_test(n++, strings, data, &tests->registers, |
333 | "core", 0, "registers", NULL); | |
1796721a | 334 | |
c1c4f453 BH |
335 | if (efx->phy_op->run_tests != NULL) { |
336 | EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL); | |
337 | ||
338 | for (i = 0; true; ++i) { | |
339 | const char *name; | |
340 | ||
341 | EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); | |
342 | name = efx->phy_op->test_name(efx, i); | |
343 | if (name == NULL) | |
344 | break; | |
345 | ||
4f16c073 | 346 | efx_fill_test(n++, strings, data, &tests->phy_ext[i], |
c1c4f453 BH |
347 | "phy", 0, name, NULL); |
348 | } | |
349 | } | |
3273c2e8 BH |
350 | |
351 | /* Loopback tests */ | |
8c8661e4 | 352 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
3273c2e8 BH |
353 | if (!(efx->loopback_modes & (1 << mode))) |
354 | continue; | |
355 | n = efx_fill_loopback_test(efx, | |
356 | &tests->loopback[mode], mode, n, | |
357 | strings, data); | |
358 | } | |
359 | ||
360 | return n; | |
361 | } | |
362 | ||
8ccf3800 AR |
363 | static size_t efx_describe_per_queue_stats(struct efx_nic *efx, u8 *strings) |
364 | { | |
365 | size_t n_stats = 0; | |
366 | struct efx_channel *channel; | |
367 | ||
368 | efx_for_each_channel(channel, efx) { | |
369 | if (efx_channel_has_tx_queues(channel)) { | |
370 | n_stats++; | |
371 | if (strings != NULL) { | |
372 | snprintf(strings, ETH_GSTRING_LEN, | |
373 | "tx-%u.tx_packets", | |
374 | channel->tx_queue[0].queue / | |
375 | EFX_TXQ_TYPES); | |
376 | ||
377 | strings += ETH_GSTRING_LEN; | |
378 | } | |
379 | } | |
380 | } | |
381 | efx_for_each_channel(channel, efx) { | |
382 | if (efx_channel_has_rx_queue(channel)) { | |
383 | n_stats++; | |
384 | if (strings != NULL) { | |
385 | snprintf(strings, ETH_GSTRING_LEN, | |
386 | "rx-%d.rx_packets", channel->channel); | |
387 | strings += ETH_GSTRING_LEN; | |
388 | } | |
389 | } | |
390 | } | |
391 | return n_stats; | |
392 | } | |
393 | ||
3594e131 BH |
394 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
395 | int string_set) | |
8ceee660 | 396 | { |
cd0ecc9a BH |
397 | struct efx_nic *efx = netdev_priv(net_dev); |
398 | ||
3594e131 BH |
399 | switch (string_set) { |
400 | case ETH_SS_STATS: | |
cd0ecc9a | 401 | return efx->type->describe_stats(efx, NULL) + |
8ccf3800 AR |
402 | EFX_ETHTOOL_SW_STAT_COUNT + |
403 | efx_describe_per_queue_stats(efx, NULL) + | |
404 | efx_ptp_describe_stats(efx, NULL); | |
3594e131 | 405 | case ETH_SS_TEST: |
cd0ecc9a | 406 | return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); |
3594e131 BH |
407 | default: |
408 | return -EINVAL; | |
409 | } | |
3273c2e8 BH |
410 | } |
411 | ||
8ceee660 BH |
412 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
413 | u32 string_set, u8 *strings) | |
414 | { | |
767e468c | 415 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
416 | int i; |
417 | ||
3273c2e8 BH |
418 | switch (string_set) { |
419 | case ETH_SS_STATS: | |
cd0ecc9a BH |
420 | strings += (efx->type->describe_stats(efx, strings) * |
421 | ETH_GSTRING_LEN); | |
422 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) | |
b681e57c | 423 | strlcpy(strings + i * ETH_GSTRING_LEN, |
cd0ecc9a | 424 | efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); |
99691c4a | 425 | strings += EFX_ETHTOOL_SW_STAT_COUNT * ETH_GSTRING_LEN; |
8ccf3800 AR |
426 | strings += (efx_describe_per_queue_stats(efx, strings) * |
427 | ETH_GSTRING_LEN); | |
99691c4a | 428 | efx_ptp_describe_stats(efx, strings); |
3273c2e8 BH |
429 | break; |
430 | case ETH_SS_TEST: | |
b681e57c | 431 | efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); |
3273c2e8 BH |
432 | break; |
433 | default: | |
434 | /* No other string sets */ | |
435 | break; | |
436 | } | |
8ceee660 BH |
437 | } |
438 | ||
439 | static void efx_ethtool_get_stats(struct net_device *net_dev, | |
440 | struct ethtool_stats *stats, | |
441 | u64 *data) | |
442 | { | |
767e468c | 443 | struct efx_nic *efx = netdev_priv(net_dev); |
cd0ecc9a | 444 | const struct efx_sw_stat_desc *stat; |
8ceee660 | 445 | struct efx_channel *channel; |
119226c5 | 446 | struct efx_tx_queue *tx_queue; |
8ccf3800 | 447 | struct efx_rx_queue *rx_queue; |
8ceee660 BH |
448 | int i; |
449 | ||
1cb34522 BH |
450 | spin_lock_bh(&efx->stats_lock); |
451 | ||
cd0ecc9a BH |
452 | /* Get NIC statistics */ |
453 | data += efx->type->update_stats(efx, data, NULL); | |
8ceee660 | 454 | |
cd0ecc9a BH |
455 | /* Get software statistics */ |
456 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { | |
457 | stat = &efx_sw_stat_desc[i]; | |
8ceee660 | 458 | switch (stat->source) { |
8ceee660 BH |
459 | case EFX_ETHTOOL_STAT_SOURCE_nic: |
460 | data[i] = stat->get_stat((void *)efx + stat->offset); | |
461 | break; | |
462 | case EFX_ETHTOOL_STAT_SOURCE_channel: | |
463 | data[i] = 0; | |
464 | efx_for_each_channel(channel, efx) | |
465 | data[i] += stat->get_stat((void *)channel + | |
466 | stat->offset); | |
467 | break; | |
119226c5 BH |
468 | case EFX_ETHTOOL_STAT_SOURCE_tx_queue: |
469 | data[i] = 0; | |
470 | efx_for_each_channel(channel, efx) { | |
471 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
472 | data[i] += | |
473 | stat->get_stat((void *)tx_queue | |
474 | + stat->offset); | |
475 | } | |
476 | break; | |
8ceee660 BH |
477 | } |
478 | } | |
99691c4a | 479 | data += EFX_ETHTOOL_SW_STAT_COUNT; |
1cb34522 BH |
480 | |
481 | spin_unlock_bh(&efx->stats_lock); | |
99691c4a | 482 | |
8ccf3800 AR |
483 | efx_for_each_channel(channel, efx) { |
484 | if (efx_channel_has_tx_queues(channel)) { | |
485 | *data = 0; | |
486 | efx_for_each_channel_tx_queue(tx_queue, channel) { | |
487 | *data += tx_queue->tx_packets; | |
488 | } | |
489 | data++; | |
490 | } | |
491 | } | |
492 | efx_for_each_channel(channel, efx) { | |
493 | if (efx_channel_has_rx_queue(channel)) { | |
494 | *data = 0; | |
495 | efx_for_each_channel_rx_queue(rx_queue, channel) { | |
496 | *data += rx_queue->rx_packets; | |
497 | } | |
498 | data++; | |
499 | } | |
500 | } | |
501 | ||
99691c4a | 502 | efx_ptp_update_stats(efx, data); |
8ceee660 BH |
503 | } |
504 | ||
3273c2e8 BH |
505 | static void efx_ethtool_self_test(struct net_device *net_dev, |
506 | struct ethtool_test *test, u64 *data) | |
507 | { | |
767e468c | 508 | struct efx_nic *efx = netdev_priv(net_dev); |
28801f35 | 509 | struct efx_self_tests *efx_tests; |
17e678d1 | 510 | bool already_up; |
28801f35 ED |
511 | int rc = -ENOMEM; |
512 | ||
513 | efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL); | |
514 | if (!efx_tests) | |
515 | goto fail; | |
516 | ||
f16aeea0 | 517 | if (efx->state != STATE_READY) { |
5eed1f68 | 518 | rc = -EBUSY; |
17e678d1 | 519 | goto out; |
3273c2e8 BH |
520 | } |
521 | ||
ac33ac61 BH |
522 | netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
523 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
524 | ||
3273c2e8 BH |
525 | /* We need rx buffers and interrupts. */ |
526 | already_up = (efx->net_dev->flags & IFF_UP); | |
527 | if (!already_up) { | |
528 | rc = dev_open(efx->net_dev); | |
529 | if (rc) { | |
62776d03 BH |
530 | netif_err(efx, drv, efx->net_dev, |
531 | "failed opening device.\n"); | |
17e678d1 | 532 | goto out; |
3273c2e8 BH |
533 | } |
534 | } | |
535 | ||
28801f35 | 536 | rc = efx_selftest(efx, efx_tests, test->flags); |
3273c2e8 | 537 | |
3273c2e8 BH |
538 | if (!already_up) |
539 | dev_close(efx->net_dev); | |
540 | ||
ac33ac61 BH |
541 | netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
542 | rc == 0 ? "passed" : "failed", | |
543 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
3273c2e8 | 544 | |
17e678d1 | 545 | out: |
28801f35 ED |
546 | efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data); |
547 | kfree(efx_tests); | |
548 | fail: | |
3273c2e8 BH |
549 | if (rc) |
550 | test->flags |= ETH_TEST_FL_FAILED; | |
551 | } | |
552 | ||
8ceee660 BH |
553 | /* Restart autonegotiation */ |
554 | static int efx_ethtool_nway_reset(struct net_device *net_dev) | |
555 | { | |
767e468c | 556 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 557 | |
68e7f45e | 558 | return mdio45_nway_restart(&efx->mdio); |
8ceee660 BH |
559 | } |
560 | ||
a0c4faf5 BH |
561 | /* |
562 | * Each channel has a single IRQ and moderation timer, started by any | |
563 | * completion (or other event). Unless the module parameter | |
564 | * separate_tx_channels is set, IRQs and moderation are therefore | |
565 | * shared between RX and TX completions. In this case, when RX IRQ | |
566 | * moderation is explicitly changed then TX IRQ moderation is | |
567 | * automatically changed too, but otherwise we fail if the two values | |
568 | * are requested to be different. | |
569 | * | |
13225977 BH |
570 | * The hardware does not support a limit on the number of completions |
571 | * before an IRQ, so we do not use the max_frames fields. We should | |
572 | * report and require that max_frames == (usecs != 0), but this would | |
573 | * invalidate existing user documentation. | |
574 | * | |
575 | * The hardware does not have distinct settings for interrupt | |
576 | * moderation while the previous IRQ is being handled, so we should | |
577 | * not use the 'irq' fields. However, an earlier developer | |
578 | * misunderstood the meaning of the 'irq' fields and the driver did | |
579 | * not support the standard fields. To avoid invalidating existing | |
580 | * user documentation, we report and accept changes through either the | |
581 | * standard or 'irq' fields. If both are changed at the same time, we | |
582 | * prefer the standard field. | |
583 | * | |
a0c4faf5 BH |
584 | * We implement adaptive IRQ moderation, but use a different algorithm |
585 | * from that assumed in the definition of struct ethtool_coalesce. | |
586 | * Therefore we do not use any of the adaptive moderation parameters | |
587 | * in it. | |
588 | */ | |
589 | ||
8ceee660 BH |
590 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
591 | struct ethtool_coalesce *coalesce) | |
592 | { | |
767e468c | 593 | struct efx_nic *efx = netdev_priv(net_dev); |
a0c4faf5 BH |
594 | unsigned int tx_usecs, rx_usecs; |
595 | bool rx_adaptive; | |
8ceee660 | 596 | |
a0c4faf5 | 597 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive); |
8ceee660 | 598 | |
13225977 | 599 | coalesce->tx_coalesce_usecs = tx_usecs; |
a0c4faf5 | 600 | coalesce->tx_coalesce_usecs_irq = tx_usecs; |
13225977 | 601 | coalesce->rx_coalesce_usecs = rx_usecs; |
a0c4faf5 BH |
602 | coalesce->rx_coalesce_usecs_irq = rx_usecs; |
603 | coalesce->use_adaptive_rx_coalesce = rx_adaptive; | |
0d86ebd8 | 604 | |
8ceee660 BH |
605 | return 0; |
606 | } | |
607 | ||
8ceee660 BH |
608 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, |
609 | struct ethtool_coalesce *coalesce) | |
610 | { | |
767e468c | 611 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 612 | struct efx_channel *channel; |
b548f976 | 613 | unsigned int tx_usecs, rx_usecs; |
9e393b30 BH |
614 | bool adaptive, rx_may_override_tx; |
615 | int rc; | |
8ceee660 | 616 | |
6fb70fd1 | 617 | if (coalesce->use_adaptive_tx_coalesce) |
9f85ee9c | 618 | return -EINVAL; |
8ceee660 | 619 | |
a0c4faf5 BH |
620 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive); |
621 | ||
13225977 BH |
622 | if (coalesce->rx_coalesce_usecs != rx_usecs) |
623 | rx_usecs = coalesce->rx_coalesce_usecs; | |
624 | else | |
625 | rx_usecs = coalesce->rx_coalesce_usecs_irq; | |
626 | ||
6fb70fd1 | 627 | adaptive = coalesce->use_adaptive_rx_coalesce; |
8ceee660 | 628 | |
a0c4faf5 BH |
629 | /* If channels are shared, TX IRQ moderation can be quietly |
630 | * overridden unless it is changed from its old value. | |
631 | */ | |
13225977 BH |
632 | rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs && |
633 | coalesce->tx_coalesce_usecs_irq == tx_usecs); | |
634 | if (coalesce->tx_coalesce_usecs != tx_usecs) | |
635 | tx_usecs = coalesce->tx_coalesce_usecs; | |
636 | else | |
637 | tx_usecs = coalesce->tx_coalesce_usecs_irq; | |
8ceee660 | 638 | |
9e393b30 BH |
639 | rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive, |
640 | rx_may_override_tx); | |
641 | if (rc != 0) | |
642 | return rc; | |
643 | ||
8ceee660 | 644 | efx_for_each_channel(channel, efx) |
ef2b90ee | 645 | efx->type->push_irq_moderation(channel); |
8ceee660 BH |
646 | |
647 | return 0; | |
648 | } | |
649 | ||
4642610c BH |
650 | static void efx_ethtool_get_ringparam(struct net_device *net_dev, |
651 | struct ethtool_ringparam *ring) | |
652 | { | |
653 | struct efx_nic *efx = netdev_priv(net_dev); | |
654 | ||
655 | ring->rx_max_pending = EFX_MAX_DMAQ_SIZE; | |
d9317aea | 656 | ring->tx_max_pending = EFX_TXQ_MAX_ENT(efx); |
4642610c BH |
657 | ring->rx_pending = efx->rxq_entries; |
658 | ring->tx_pending = efx->txq_entries; | |
4642610c BH |
659 | } |
660 | ||
661 | static int efx_ethtool_set_ringparam(struct net_device *net_dev, | |
662 | struct ethtool_ringparam *ring) | |
663 | { | |
664 | struct efx_nic *efx = netdev_priv(net_dev); | |
7e6d06f0 | 665 | u32 txq_entries; |
4642610c BH |
666 | |
667 | if (ring->rx_mini_pending || ring->rx_jumbo_pending || | |
668 | ring->rx_pending > EFX_MAX_DMAQ_SIZE || | |
d9317aea | 669 | ring->tx_pending > EFX_TXQ_MAX_ENT(efx)) |
4642610c BH |
670 | return -EINVAL; |
671 | ||
7e6d06f0 | 672 | if (ring->rx_pending < EFX_RXQ_MIN_ENT) { |
4642610c | 673 | netif_err(efx, drv, efx->net_dev, |
7e6d06f0 BH |
674 | "RX queues cannot be smaller than %u\n", |
675 | EFX_RXQ_MIN_ENT); | |
4642610c BH |
676 | return -EINVAL; |
677 | } | |
678 | ||
7e6d06f0 BH |
679 | txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx)); |
680 | if (txq_entries != ring->tx_pending) | |
681 | netif_warn(efx, drv, efx->net_dev, | |
682 | "increasing TX queue size to minimum of %u\n", | |
683 | txq_entries); | |
684 | ||
685 | return efx_realloc_channels(efx, ring->rx_pending, txq_entries); | |
4642610c BH |
686 | } |
687 | ||
8ceee660 BH |
688 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
689 | struct ethtool_pauseparam *pause) | |
690 | { | |
767e468c | 691 | struct efx_nic *efx = netdev_priv(net_dev); |
b5626946 | 692 | u8 wanted_fc, old_fc; |
d3245b28 | 693 | u32 old_adv; |
d3245b28 BH |
694 | int rc = 0; |
695 | ||
696 | mutex_lock(&efx->mac_lock); | |
8ceee660 | 697 | |
04cc8cac BH |
698 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
699 | (pause->tx_pause ? EFX_FC_TX : 0) | | |
700 | (pause->autoneg ? EFX_FC_AUTO : 0)); | |
701 | ||
702 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { | |
62776d03 BH |
703 | netif_dbg(efx, drv, efx->net_dev, |
704 | "Flow control unsupported: tx ON rx OFF\n"); | |
d3245b28 BH |
705 | rc = -EINVAL; |
706 | goto out; | |
04cc8cac BH |
707 | } |
708 | ||
d3245b28 | 709 | if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) { |
62776d03 BH |
710 | netif_dbg(efx, drv, efx->net_dev, |
711 | "Autonegotiation is disabled\n"); | |
d3245b28 BH |
712 | rc = -EINVAL; |
713 | goto out; | |
04cc8cac BH |
714 | } |
715 | ||
9dd3a13b BH |
716 | /* Hook for Falcon bug 11482 workaround */ |
717 | if (efx->type->prepare_enable_fc_tx && | |
718 | (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX)) | |
719 | efx->type->prepare_enable_fc_tx(efx); | |
04cc8cac | 720 | |
d3245b28 BH |
721 | old_adv = efx->link_advertising; |
722 | old_fc = efx->wanted_fc; | |
723 | efx_link_set_wanted_fc(efx, wanted_fc); | |
724 | if (efx->link_advertising != old_adv || | |
725 | (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { | |
726 | rc = efx->phy_op->reconfigure(efx); | |
727 | if (rc) { | |
62776d03 BH |
728 | netif_err(efx, drv, efx->net_dev, |
729 | "Unable to advertise requested flow " | |
730 | "control setting\n"); | |
d3245b28 BH |
731 | goto out; |
732 | } | |
733 | } | |
04cc8cac | 734 | |
d3245b28 BH |
735 | /* Reconfigure the MAC. The PHY *may* generate a link state change event |
736 | * if the user just changed the advertised capabilities, but there's no | |
737 | * harm doing this twice */ | |
0d322413 | 738 | efx_mac_reconfigure(efx); |
04cc8cac | 739 | |
d3245b28 | 740 | out: |
04cc8cac | 741 | mutex_unlock(&efx->mac_lock); |
8ceee660 | 742 | |
d3245b28 | 743 | return rc; |
8ceee660 BH |
744 | } |
745 | ||
746 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, | |
747 | struct ethtool_pauseparam *pause) | |
748 | { | |
767e468c | 749 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 750 | |
04cc8cac BH |
751 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
752 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); | |
753 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); | |
8ceee660 BH |
754 | } |
755 | ||
89c758fa BH |
756 | static void efx_ethtool_get_wol(struct net_device *net_dev, |
757 | struct ethtool_wolinfo *wol) | |
758 | { | |
759 | struct efx_nic *efx = netdev_priv(net_dev); | |
760 | return efx->type->get_wol(efx, wol); | |
761 | } | |
762 | ||
763 | ||
764 | static int efx_ethtool_set_wol(struct net_device *net_dev, | |
765 | struct ethtool_wolinfo *wol) | |
766 | { | |
767 | struct efx_nic *efx = netdev_priv(net_dev); | |
768 | return efx->type->set_wol(efx, wol->wolopts); | |
769 | } | |
770 | ||
d215697f | 771 | static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) |
eb9f6744 BH |
772 | { |
773 | struct efx_nic *efx = netdev_priv(net_dev); | |
0e2a9c7c | 774 | int rc; |
eb9f6744 | 775 | |
0e2a9c7c BH |
776 | rc = efx->type->map_reset_flags(flags); |
777 | if (rc < 0) | |
778 | return rc; | |
eb9f6744 | 779 | |
0e2a9c7c | 780 | return efx_reset(efx, rc); |
eb9f6744 BH |
781 | } |
782 | ||
7c460d9b | 783 | /* MAC address mask including only I/G bit */ |
cd84ff4d | 784 | static const u8 mac_addr_ig_mask[ETH_ALEN] __aligned(2) = {0x01, 0, 0, 0, 0, 0}; |
c274d65c | 785 | |
0e0c3408 | 786 | #define IP4_ADDR_FULL_MASK ((__force __be32)~0) |
a7ad40d0 | 787 | #define IP_PROTO_FULL_MASK 0xFF |
0e0c3408 | 788 | #define PORT_FULL_MASK ((__force __be16)~0) |
7c460d9b | 789 | #define ETHER_TYPE_FULL_MASK ((__force __be16)~0) |
0e0c3408 | 790 | |
a7ad40d0 EC |
791 | static inline void ip6_fill_mask(__be32 *mask) |
792 | { | |
793 | mask[0] = mask[1] = mask[2] = mask[3] = ~(__be32)0; | |
794 | } | |
795 | ||
b2bb7b77 BH |
796 | static int efx_ethtool_get_class_rule(struct efx_nic *efx, |
797 | struct ethtool_rx_flow_spec *rule) | |
798 | { | |
799 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; | |
800 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; | |
a7ad40d0 EC |
801 | struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
802 | struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; | |
803 | struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; | |
804 | struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; | |
805 | struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; | |
806 | struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; | |
c274d65c BH |
807 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
808 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; | |
b2bb7b77 | 809 | struct efx_filter_spec spec; |
b2bb7b77 BH |
810 | int rc; |
811 | ||
812 | rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL, | |
813 | rule->location, &spec); | |
814 | if (rc) | |
815 | return rc; | |
816 | ||
f26e958c | 817 | if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP) |
b2bb7b77 BH |
818 | rule->ring_cookie = RX_CLS_FLOW_DISC; |
819 | else | |
820 | rule->ring_cookie = spec.dmaq_id; | |
821 | ||
7c460d9b BH |
822 | if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
823 | spec.ether_type == htons(ETH_P_IP) && | |
824 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && | |
825 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && | |
826 | !(spec.match_flags & | |
827 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
828 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
829 | EFX_FILTER_MATCH_IP_PROTO | | |
830 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { | |
831 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? | |
832 | TCP_V4_FLOW : UDP_V4_FLOW); | |
833 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
834 | ip_entry->ip4dst = spec.loc_host[0]; | |
835 | ip_mask->ip4dst = IP4_ADDR_FULL_MASK; | |
836 | } | |
837 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
838 | ip_entry->ip4src = spec.rem_host[0]; | |
839 | ip_mask->ip4src = IP4_ADDR_FULL_MASK; | |
840 | } | |
841 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { | |
842 | ip_entry->pdst = spec.loc_port; | |
843 | ip_mask->pdst = PORT_FULL_MASK; | |
844 | } | |
845 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { | |
846 | ip_entry->psrc = spec.rem_port; | |
847 | ip_mask->psrc = PORT_FULL_MASK; | |
848 | } | |
a7ad40d0 EC |
849 | } else if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
850 | spec.ether_type == htons(ETH_P_IPV6) && | |
851 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && | |
852 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && | |
853 | !(spec.match_flags & | |
854 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
855 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
856 | EFX_FILTER_MATCH_IP_PROTO | | |
857 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { | |
858 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? | |
859 | TCP_V6_FLOW : UDP_V6_FLOW); | |
860 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
861 | memcpy(ip6_entry->ip6dst, spec.loc_host, | |
862 | sizeof(ip6_entry->ip6dst)); | |
863 | ip6_fill_mask(ip6_mask->ip6dst); | |
864 | } | |
865 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
866 | memcpy(ip6_entry->ip6src, spec.rem_host, | |
867 | sizeof(ip6_entry->ip6src)); | |
868 | ip6_fill_mask(ip6_mask->ip6src); | |
869 | } | |
870 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { | |
871 | ip6_entry->pdst = spec.loc_port; | |
872 | ip6_mask->pdst = PORT_FULL_MASK; | |
873 | } | |
874 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { | |
875 | ip6_entry->psrc = spec.rem_port; | |
876 | ip6_mask->psrc = PORT_FULL_MASK; | |
877 | } | |
7c460d9b BH |
878 | } else if (!(spec.match_flags & |
879 | ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG | | |
880 | EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE | | |
881 | EFX_FILTER_MATCH_OUTER_VID))) { | |
b2bb7b77 | 882 | rule->flow_type = ETHER_FLOW; |
7c460d9b BH |
883 | if (spec.match_flags & |
884 | (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) { | |
cd84ff4d | 885 | ether_addr_copy(mac_entry->h_dest, spec.loc_mac); |
7c460d9b | 886 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC) |
cd84ff4d | 887 | eth_broadcast_addr(mac_mask->h_dest); |
7c460d9b | 888 | else |
cd84ff4d EC |
889 | ether_addr_copy(mac_mask->h_dest, |
890 | mac_addr_ig_mask); | |
b2bb7b77 | 891 | } |
7c460d9b | 892 | if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) { |
cd84ff4d EC |
893 | ether_addr_copy(mac_entry->h_source, spec.rem_mac); |
894 | eth_broadcast_addr(mac_mask->h_source); | |
7c460d9b BH |
895 | } |
896 | if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) { | |
897 | mac_entry->h_proto = spec.ether_type; | |
898 | mac_mask->h_proto = ETHER_TYPE_FULL_MASK; | |
899 | } | |
a7ad40d0 EC |
900 | } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && |
901 | spec.ether_type == htons(ETH_P_IP) && | |
902 | !(spec.match_flags & | |
903 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
904 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
905 | EFX_FILTER_MATCH_IP_PROTO))) { | |
906 | rule->flow_type = IPV4_USER_FLOW; | |
907 | uip_entry->ip_ver = ETH_RX_NFC_IP4; | |
908 | if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { | |
909 | uip_mask->proto = IP_PROTO_FULL_MASK; | |
910 | uip_entry->proto = spec.ip_proto; | |
911 | } | |
912 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
913 | uip_entry->ip4dst = spec.loc_host[0]; | |
914 | uip_mask->ip4dst = IP4_ADDR_FULL_MASK; | |
915 | } | |
916 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
917 | uip_entry->ip4src = spec.rem_host[0]; | |
918 | uip_mask->ip4src = IP4_ADDR_FULL_MASK; | |
919 | } | |
920 | } else if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE && | |
921 | spec.ether_type == htons(ETH_P_IPV6) && | |
922 | !(spec.match_flags & | |
923 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
924 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
925 | EFX_FILTER_MATCH_IP_PROTO))) { | |
926 | rule->flow_type = IPV6_USER_FLOW; | |
927 | if (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) { | |
928 | uip6_mask->l4_proto = IP_PROTO_FULL_MASK; | |
929 | uip6_entry->l4_proto = spec.ip_proto; | |
930 | } | |
931 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
932 | memcpy(uip6_entry->ip6dst, spec.loc_host, | |
933 | sizeof(uip6_entry->ip6dst)); | |
934 | ip6_fill_mask(uip6_mask->ip6dst); | |
935 | } | |
936 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
937 | memcpy(uip6_entry->ip6src, spec.rem_host, | |
938 | sizeof(uip6_entry->ip6src)); | |
939 | ip6_fill_mask(uip6_mask->ip6src); | |
940 | } | |
7c460d9b BH |
941 | } else { |
942 | /* The above should handle all filters that we insert */ | |
943 | WARN_ON(1); | |
944 | return -EINVAL; | |
b2bb7b77 BH |
945 | } |
946 | ||
7c460d9b BH |
947 | if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) { |
948 | rule->flow_type |= FLOW_EXT; | |
949 | rule->h_ext.vlan_tci = spec.outer_vid; | |
950 | rule->m_ext.vlan_tci = htons(0xfff); | |
b2bb7b77 | 951 | } |
7c460d9b | 952 | |
b2bb7b77 BH |
953 | return rc; |
954 | } | |
955 | ||
765c9f46 BH |
956 | static int |
957 | efx_ethtool_get_rxnfc(struct net_device *net_dev, | |
b2bb7b77 | 958 | struct ethtool_rxnfc *info, u32 *rule_locs) |
765c9f46 BH |
959 | { |
960 | struct efx_nic *efx = netdev_priv(net_dev); | |
961 | ||
962 | switch (info->cmd) { | |
963 | case ETHTOOL_GRXRINGS: | |
964 | info->data = efx->n_rx_channels; | |
965 | return 0; | |
966 | ||
967 | case ETHTOOL_GRXFH: { | |
968 | unsigned min_revision = 0; | |
969 | ||
970 | info->data = 0; | |
971 | switch (info->flow_type) { | |
b718c88a EC |
972 | case UDP_V4_FLOW: |
973 | if (efx->rx_hash_udp_4tuple) | |
974 | /* fall through */ | |
765c9f46 | 975 | case TCP_V4_FLOW: |
b718c88a | 976 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
765c9f46 | 977 | /* fall through */ |
765c9f46 BH |
978 | case SCTP_V4_FLOW: |
979 | case AH_ESP_V4_FLOW: | |
980 | case IPV4_FLOW: | |
981 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
982 | min_revision = EFX_REV_FALCON_B0; | |
983 | break; | |
b718c88a EC |
984 | case UDP_V6_FLOW: |
985 | if (efx->rx_hash_udp_4tuple) | |
986 | /* fall through */ | |
765c9f46 | 987 | case TCP_V6_FLOW: |
b718c88a | 988 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; |
765c9f46 | 989 | /* fall through */ |
765c9f46 BH |
990 | case SCTP_V6_FLOW: |
991 | case AH_ESP_V6_FLOW: | |
992 | case IPV6_FLOW: | |
993 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
994 | min_revision = EFX_REV_SIENA_A0; | |
995 | break; | |
996 | default: | |
997 | break; | |
998 | } | |
999 | if (efx_nic_rev(efx) < min_revision) | |
1000 | info->data = 0; | |
1001 | return 0; | |
1002 | } | |
1003 | ||
b2bb7b77 BH |
1004 | case ETHTOOL_GRXCLSRLCNT: |
1005 | info->data = efx_filter_get_rx_id_limit(efx); | |
1006 | if (info->data == 0) | |
1007 | return -EOPNOTSUPP; | |
1008 | info->data |= RX_CLS_LOC_SPECIAL; | |
1009 | info->rule_cnt = | |
1010 | efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL); | |
1011 | return 0; | |
1012 | ||
1013 | case ETHTOOL_GRXCLSRULE: | |
1014 | if (efx_filter_get_rx_id_limit(efx) == 0) | |
1015 | return -EOPNOTSUPP; | |
1016 | return efx_ethtool_get_class_rule(efx, &info->fs); | |
1017 | ||
1018 | case ETHTOOL_GRXCLSRLALL: { | |
1019 | s32 rc; | |
1020 | info->data = efx_filter_get_rx_id_limit(efx); | |
1021 | if (info->data == 0) | |
1022 | return -EOPNOTSUPP; | |
1023 | rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL, | |
1024 | rule_locs, info->rule_cnt); | |
1025 | if (rc < 0) | |
1026 | return rc; | |
1027 | info->rule_cnt = rc; | |
1028 | return 0; | |
1029 | } | |
1030 | ||
765c9f46 BH |
1031 | default: |
1032 | return -EOPNOTSUPP; | |
1033 | } | |
1034 | } | |
1035 | ||
a7ad40d0 EC |
1036 | static inline bool ip6_mask_is_full(__be32 mask[4]) |
1037 | { | |
1038 | return !~(mask[0] & mask[1] & mask[2] & mask[3]); | |
1039 | } | |
1040 | ||
1041 | static inline bool ip6_mask_is_empty(__be32 mask[4]) | |
1042 | { | |
1043 | return !(mask[0] | mask[1] | mask[2] | mask[3]); | |
1044 | } | |
1045 | ||
b2bb7b77 BH |
1046 | static int efx_ethtool_set_class_rule(struct efx_nic *efx, |
1047 | struct ethtool_rx_flow_spec *rule) | |
b4187e42 | 1048 | { |
b2bb7b77 BH |
1049 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
1050 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; | |
a7ad40d0 EC |
1051 | struct ethtool_usrip4_spec *uip_entry = &rule->h_u.usr_ip4_spec; |
1052 | struct ethtool_usrip4_spec *uip_mask = &rule->m_u.usr_ip4_spec; | |
1053 | struct ethtool_tcpip6_spec *ip6_entry = &rule->h_u.tcp_ip6_spec; | |
1054 | struct ethtool_tcpip6_spec *ip6_mask = &rule->m_u.tcp_ip6_spec; | |
1055 | struct ethtool_usrip6_spec *uip6_entry = &rule->h_u.usr_ip6_spec; | |
1056 | struct ethtool_usrip6_spec *uip6_mask = &rule->m_u.usr_ip6_spec; | |
b2bb7b77 BH |
1057 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
1058 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; | |
1059 | struct efx_filter_spec spec; | |
c39d35eb | 1060 | int rc; |
b4187e42 | 1061 | |
b2bb7b77 | 1062 | /* Check that user wants us to choose the location */ |
9e0f9a10 | 1063 | if (rule->location != RX_CLS_LOC_ANY) |
b4187e42 BH |
1064 | return -EINVAL; |
1065 | ||
b2bb7b77 BH |
1066 | /* Range-check ring_cookie */ |
1067 | if (rule->ring_cookie >= efx->n_rx_channels && | |
1068 | rule->ring_cookie != RX_CLS_FLOW_DISC) | |
b4187e42 BH |
1069 | return -EINVAL; |
1070 | ||
b2bb7b77 BH |
1071 | /* Check for unsupported extensions */ |
1072 | if ((rule->flow_type & FLOW_EXT) && | |
0e0c3408 | 1073 | (rule->m_ext.vlan_etype || rule->m_ext.data[0] || |
b2bb7b77 BH |
1074 | rule->m_ext.data[1])) |
1075 | return -EINVAL; | |
1076 | ||
85740cdf BH |
1077 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, |
1078 | efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0, | |
b2bb7b77 | 1079 | (rule->ring_cookie == RX_CLS_FLOW_DISC) ? |
f26e958c | 1080 | EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie); |
c39d35eb | 1081 | |
7c460d9b | 1082 | switch (rule->flow_type & ~FLOW_EXT) { |
b4187e42 | 1083 | case TCP_V4_FLOW: |
7c460d9b BH |
1084 | case UDP_V4_FLOW: |
1085 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | | |
1086 | EFX_FILTER_MATCH_IP_PROTO); | |
1087 | spec.ether_type = htons(ETH_P_IP); | |
1088 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ? | |
1089 | IPPROTO_TCP : IPPROTO_UDP); | |
1090 | if (ip_mask->ip4dst) { | |
1091 | if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK) | |
1092 | return -EINVAL; | |
1093 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1094 | spec.loc_host[0] = ip_entry->ip4dst; | |
1095 | } | |
1096 | if (ip_mask->ip4src) { | |
1097 | if (ip_mask->ip4src != IP4_ADDR_FULL_MASK) | |
1098 | return -EINVAL; | |
1099 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1100 | spec.rem_host[0] = ip_entry->ip4src; | |
1101 | } | |
1102 | if (ip_mask->pdst) { | |
1103 | if (ip_mask->pdst != PORT_FULL_MASK) | |
1104 | return -EINVAL; | |
1105 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; | |
1106 | spec.loc_port = ip_entry->pdst; | |
1107 | } | |
1108 | if (ip_mask->psrc) { | |
1109 | if (ip_mask->psrc != PORT_FULL_MASK) | |
1110 | return -EINVAL; | |
1111 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; | |
1112 | spec.rem_port = ip_entry->psrc; | |
1113 | } | |
1114 | if (ip_mask->tos) | |
b4187e42 BH |
1115 | return -EINVAL; |
1116 | break; | |
c274d65c | 1117 | |
a7ad40d0 EC |
1118 | case TCP_V6_FLOW: |
1119 | case UDP_V6_FLOW: | |
1120 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | | |
1121 | EFX_FILTER_MATCH_IP_PROTO); | |
1122 | spec.ether_type = htons(ETH_P_IPV6); | |
1123 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V6_FLOW ? | |
1124 | IPPROTO_TCP : IPPROTO_UDP); | |
1125 | if (!ip6_mask_is_empty(ip6_mask->ip6dst)) { | |
1126 | if (!ip6_mask_is_full(ip6_mask->ip6dst)) | |
1127 | return -EINVAL; | |
1128 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1129 | memcpy(spec.loc_host, ip6_entry->ip6dst, sizeof(spec.loc_host)); | |
1130 | } | |
1131 | if (!ip6_mask_is_empty(ip6_mask->ip6src)) { | |
1132 | if (!ip6_mask_is_full(ip6_mask->ip6src)) | |
1133 | return -EINVAL; | |
1134 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1135 | memcpy(spec.rem_host, ip6_entry->ip6src, sizeof(spec.rem_host)); | |
1136 | } | |
1137 | if (ip6_mask->pdst) { | |
1138 | if (ip6_mask->pdst != PORT_FULL_MASK) | |
1139 | return -EINVAL; | |
1140 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; | |
1141 | spec.loc_port = ip6_entry->pdst; | |
1142 | } | |
1143 | if (ip6_mask->psrc) { | |
1144 | if (ip6_mask->psrc != PORT_FULL_MASK) | |
1145 | return -EINVAL; | |
1146 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; | |
1147 | spec.rem_port = ip6_entry->psrc; | |
1148 | } | |
1149 | if (ip6_mask->tclass) | |
1150 | return -EINVAL; | |
1151 | break; | |
1152 | ||
1153 | case IPV4_USER_FLOW: | |
1154 | if (uip_mask->l4_4_bytes || uip_mask->tos || uip_mask->ip_ver || | |
1155 | uip_entry->ip_ver != ETH_RX_NFC_IP4) | |
1156 | return -EINVAL; | |
1157 | spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; | |
1158 | spec.ether_type = htons(ETH_P_IP); | |
1159 | if (uip_mask->ip4dst) { | |
1160 | if (uip_mask->ip4dst != IP4_ADDR_FULL_MASK) | |
1161 | return -EINVAL; | |
1162 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1163 | spec.loc_host[0] = uip_entry->ip4dst; | |
1164 | } | |
1165 | if (uip_mask->ip4src) { | |
1166 | if (uip_mask->ip4src != IP4_ADDR_FULL_MASK) | |
1167 | return -EINVAL; | |
1168 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1169 | spec.rem_host[0] = uip_entry->ip4src; | |
1170 | } | |
1171 | if (uip_mask->proto) { | |
1172 | if (uip_mask->proto != IP_PROTO_FULL_MASK) | |
1173 | return -EINVAL; | |
1174 | spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; | |
1175 | spec.ip_proto = uip_entry->proto; | |
1176 | } | |
1177 | break; | |
1178 | ||
1179 | case IPV6_USER_FLOW: | |
1180 | if (uip6_mask->l4_4_bytes || uip6_mask->tclass) | |
1181 | return -EINVAL; | |
1182 | spec.match_flags = EFX_FILTER_MATCH_ETHER_TYPE; | |
1183 | spec.ether_type = htons(ETH_P_IPV6); | |
1184 | if (!ip6_mask_is_empty(uip6_mask->ip6dst)) { | |
1185 | if (!ip6_mask_is_full(uip6_mask->ip6dst)) | |
1186 | return -EINVAL; | |
1187 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
1188 | memcpy(spec.loc_host, uip6_entry->ip6dst, sizeof(spec.loc_host)); | |
1189 | } | |
1190 | if (!ip6_mask_is_empty(uip6_mask->ip6src)) { | |
1191 | if (!ip6_mask_is_full(uip6_mask->ip6src)) | |
1192 | return -EINVAL; | |
1193 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
1194 | memcpy(spec.rem_host, uip6_entry->ip6src, sizeof(spec.rem_host)); | |
1195 | } | |
1196 | if (uip6_mask->l4_proto) { | |
1197 | if (uip6_mask->l4_proto != IP_PROTO_FULL_MASK) | |
1198 | return -EINVAL; | |
1199 | spec.match_flags |= EFX_FILTER_MATCH_IP_PROTO; | |
1200 | spec.ip_proto = uip6_entry->l4_proto; | |
1201 | } | |
1202 | break; | |
1203 | ||
7c460d9b BH |
1204 | case ETHER_FLOW: |
1205 | if (!is_zero_ether_addr(mac_mask->h_dest)) { | |
1206 | if (ether_addr_equal(mac_mask->h_dest, | |
1207 | mac_addr_ig_mask)) | |
1208 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG; | |
1209 | else if (is_broadcast_ether_addr(mac_mask->h_dest)) | |
1210 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC; | |
c274d65c | 1211 | else |
7c460d9b | 1212 | return -EINVAL; |
cd84ff4d | 1213 | ether_addr_copy(spec.loc_mac, mac_entry->h_dest); |
c274d65c | 1214 | } |
7c460d9b BH |
1215 | if (!is_zero_ether_addr(mac_mask->h_source)) { |
1216 | if (!is_broadcast_ether_addr(mac_mask->h_source)) | |
1217 | return -EINVAL; | |
1218 | spec.match_flags |= EFX_FILTER_MATCH_REM_MAC; | |
cd84ff4d | 1219 | ether_addr_copy(spec.rem_mac, mac_entry->h_source); |
7c460d9b BH |
1220 | } |
1221 | if (mac_mask->h_proto) { | |
1222 | if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK) | |
1223 | return -EINVAL; | |
1224 | spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; | |
1225 | spec.ether_type = mac_entry->h_proto; | |
c274d65c | 1226 | } |
b4187e42 | 1227 | break; |
c39d35eb | 1228 | |
b4187e42 BH |
1229 | default: |
1230 | return -EINVAL; | |
1231 | } | |
1232 | ||
7c460d9b BH |
1233 | if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) { |
1234 | if (rule->m_ext.vlan_tci != htons(0xfff)) | |
1235 | return -EINVAL; | |
1236 | spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID; | |
1237 | spec.outer_vid = rule->h_ext.vlan_tci; | |
1238 | } | |
1239 | ||
b2bb7b77 BH |
1240 | rc = efx_filter_insert_filter(efx, &spec, true); |
1241 | if (rc < 0) | |
1242 | return rc; | |
47a8467c | 1243 | |
b2bb7b77 BH |
1244 | rule->location = rc; |
1245 | return 0; | |
1246 | } | |
1247 | ||
1248 | static int efx_ethtool_set_rxnfc(struct net_device *net_dev, | |
1249 | struct ethtool_rxnfc *info) | |
1250 | { | |
1251 | struct efx_nic *efx = netdev_priv(net_dev); | |
1252 | ||
1253 | if (efx_filter_get_rx_id_limit(efx) == 0) | |
1254 | return -EOPNOTSUPP; | |
1255 | ||
1256 | switch (info->cmd) { | |
1257 | case ETHTOOL_SRXCLSRLINS: | |
1258 | return efx_ethtool_set_class_rule(efx, &info->fs); | |
1259 | ||
1260 | case ETHTOOL_SRXCLSRLDEL: | |
1261 | return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL, | |
1262 | info->fs.location); | |
1263 | ||
1264 | default: | |
1265 | return -EOPNOTSUPP; | |
1266 | } | |
b4187e42 BH |
1267 | } |
1268 | ||
7850f63f | 1269 | static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev) |
765c9f46 BH |
1270 | { |
1271 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1272 | |
cd2d5b52 BH |
1273 | return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 || |
1274 | efx->n_rx_channels == 1) ? | |
7850f63f BH |
1275 | 0 : ARRAY_SIZE(efx->rx_indir_table)); |
1276 | } | |
1277 | ||
892311f6 EP |
1278 | static int efx_ethtool_get_rxfh(struct net_device *net_dev, u32 *indir, u8 *key, |
1279 | u8 *hfunc) | |
7850f63f BH |
1280 | { |
1281 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1282 | |
892311f6 EP |
1283 | if (hfunc) |
1284 | *hfunc = ETH_RSS_HASH_TOP; | |
1285 | if (indir) | |
1286 | memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table)); | |
765c9f46 BH |
1287 | return 0; |
1288 | } | |
1289 | ||
892311f6 EP |
1290 | static int efx_ethtool_set_rxfh(struct net_device *net_dev, const u32 *indir, |
1291 | const u8 *key, const u8 hfunc) | |
765c9f46 BH |
1292 | { |
1293 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1294 | |
892311f6 EP |
1295 | /* We do not allow change in unsupported parameters */ |
1296 | if (key || | |
1297 | (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)) | |
1298 | return -EOPNOTSUPP; | |
1299 | if (!indir) | |
1300 | return 0; | |
267c0157 JC |
1301 | |
1302 | return efx->type->rx_push_rss_config(efx, true, indir); | |
765c9f46 BH |
1303 | } |
1304 | ||
b51ca34a FW |
1305 | static int efx_ethtool_get_ts_info(struct net_device *net_dev, |
1306 | struct ethtool_ts_info *ts_info) | |
62ebac92 BH |
1307 | { |
1308 | struct efx_nic *efx = netdev_priv(net_dev); | |
1309 | ||
1310 | /* Software capabilities */ | |
1311 | ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE | | |
1312 | SOF_TIMESTAMPING_SOFTWARE); | |
1313 | ts_info->phc_index = -1; | |
1314 | ||
1315 | efx_ptp_get_ts_info(efx, ts_info); | |
1316 | return 0; | |
1317 | } | |
1318 | ||
c087bd2c SH |
1319 | static int efx_ethtool_get_module_eeprom(struct net_device *net_dev, |
1320 | struct ethtool_eeprom *ee, | |
1321 | u8 *data) | |
1322 | { | |
1323 | struct efx_nic *efx = netdev_priv(net_dev); | |
1324 | int ret; | |
1325 | ||
1326 | if (!efx->phy_op || !efx->phy_op->get_module_eeprom) | |
1327 | return -EOPNOTSUPP; | |
1328 | ||
1329 | mutex_lock(&efx->mac_lock); | |
1330 | ret = efx->phy_op->get_module_eeprom(efx, ee, data); | |
1331 | mutex_unlock(&efx->mac_lock); | |
1332 | ||
1333 | return ret; | |
1334 | } | |
1335 | ||
1336 | static int efx_ethtool_get_module_info(struct net_device *net_dev, | |
1337 | struct ethtool_modinfo *modinfo) | |
1338 | { | |
1339 | struct efx_nic *efx = netdev_priv(net_dev); | |
1340 | int ret; | |
1341 | ||
1342 | if (!efx->phy_op || !efx->phy_op->get_module_info) | |
1343 | return -EOPNOTSUPP; | |
1344 | ||
1345 | mutex_lock(&efx->mac_lock); | |
1346 | ret = efx->phy_op->get_module_info(efx, modinfo); | |
1347 | mutex_unlock(&efx->mac_lock); | |
1348 | ||
1349 | return ret; | |
1350 | } | |
1351 | ||
0fc0b732 | 1352 | const struct ethtool_ops efx_ethtool_ops = { |
8ceee660 BH |
1353 | .get_settings = efx_ethtool_get_settings, |
1354 | .set_settings = efx_ethtool_set_settings, | |
1355 | .get_drvinfo = efx_ethtool_get_drvinfo, | |
5b98c1bf BH |
1356 | .get_regs_len = efx_ethtool_get_regs_len, |
1357 | .get_regs = efx_ethtool_get_regs, | |
62776d03 BH |
1358 | .get_msglevel = efx_ethtool_get_msglevel, |
1359 | .set_msglevel = efx_ethtool_set_msglevel, | |
8ceee660 | 1360 | .nway_reset = efx_ethtool_nway_reset, |
ed4ba4b5 | 1361 | .get_link = ethtool_op_get_link, |
8ceee660 BH |
1362 | .get_coalesce = efx_ethtool_get_coalesce, |
1363 | .set_coalesce = efx_ethtool_set_coalesce, | |
4642610c BH |
1364 | .get_ringparam = efx_ethtool_get_ringparam, |
1365 | .set_ringparam = efx_ethtool_set_ringparam, | |
8ceee660 BH |
1366 | .get_pauseparam = efx_ethtool_get_pauseparam, |
1367 | .set_pauseparam = efx_ethtool_set_pauseparam, | |
3594e131 | 1368 | .get_sset_count = efx_ethtool_get_sset_count, |
3273c2e8 | 1369 | .self_test = efx_ethtool_self_test, |
8ceee660 | 1370 | .get_strings = efx_ethtool_get_strings, |
c5e129ac | 1371 | .set_phys_id = efx_ethtool_phys_id, |
8ceee660 | 1372 | .get_ethtool_stats = efx_ethtool_get_stats, |
89c758fa BH |
1373 | .get_wol = efx_ethtool_get_wol, |
1374 | .set_wol = efx_ethtool_set_wol, | |
eb9f6744 | 1375 | .reset = efx_ethtool_reset, |
765c9f46 | 1376 | .get_rxnfc = efx_ethtool_get_rxnfc, |
b2bb7b77 | 1377 | .set_rxnfc = efx_ethtool_set_rxnfc, |
7850f63f | 1378 | .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size, |
fe62d001 BH |
1379 | .get_rxfh = efx_ethtool_get_rxfh, |
1380 | .set_rxfh = efx_ethtool_set_rxfh, | |
62ebac92 | 1381 | .get_ts_info = efx_ethtool_get_ts_info, |
c087bd2c SH |
1382 | .get_module_info = efx_ethtool_get_module_info, |
1383 | .get_module_eeprom = efx_ethtool_get_module_eeprom, | |
8ceee660 | 1384 | }; |