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), |
8ceee660 BH |
74 | EFX_ETHTOOL_ATOMIC_NIC_ERROR_STAT(rx_reset), |
75 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tobe_disc), | |
76 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_ip_hdr_chksum_err), | |
77 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_tcp_udp_chksum_err), | |
c1ac403b | 78 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_mcast_mismatch), |
8ceee660 | 79 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_frm_trunc), |
85740cdf | 80 | EFX_ETHTOOL_UINT_CHANNEL_STAT(rx_nodesc_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 | |
254 | */ | |
255 | static int efx_fill_loopback_test(struct efx_nic *efx, | |
256 | struct efx_loopback_self_tests *lb_tests, | |
257 | enum efx_loopback_mode mode, | |
258 | unsigned int test_index, | |
b681e57c | 259 | u8 *strings, u64 *data) |
3273c2e8 | 260 | { |
1ac0226e BH |
261 | struct efx_channel *channel = |
262 | efx_get_channel(efx, efx->tx_channel_offset); | |
3273c2e8 BH |
263 | struct efx_tx_queue *tx_queue; |
264 | ||
f7d12cdc | 265 | efx_for_each_channel_tx_queue(tx_queue, channel) { |
3273c2e8 BH |
266 | efx_fill_test(test_index++, strings, data, |
267 | &lb_tests->tx_sent[tx_queue->queue], | |
268 | EFX_TX_QUEUE_NAME(tx_queue), | |
269 | EFX_LOOPBACK_NAME(mode, "tx_sent")); | |
270 | efx_fill_test(test_index++, strings, data, | |
271 | &lb_tests->tx_done[tx_queue->queue], | |
272 | EFX_TX_QUEUE_NAME(tx_queue), | |
273 | EFX_LOOPBACK_NAME(mode, "tx_done")); | |
274 | } | |
275 | efx_fill_test(test_index++, strings, data, | |
276 | &lb_tests->rx_good, | |
11e66966 | 277 | "rx", 0, |
3273c2e8 BH |
278 | EFX_LOOPBACK_NAME(mode, "rx_good")); |
279 | efx_fill_test(test_index++, strings, data, | |
280 | &lb_tests->rx_bad, | |
11e66966 | 281 | "rx", 0, |
3273c2e8 BH |
282 | EFX_LOOPBACK_NAME(mode, "rx_bad")); |
283 | ||
284 | return test_index; | |
285 | } | |
286 | ||
287 | /** | |
288 | * efx_ethtool_fill_self_tests - get self-test details | |
289 | * @efx: Efx NIC | |
290 | * @tests: Efx self-test results structure, or %NULL | |
291 | * @strings: Ethtool strings, or %NULL | |
292 | * @data: Ethtool test results, or %NULL | |
293 | */ | |
294 | static int efx_ethtool_fill_self_tests(struct efx_nic *efx, | |
295 | struct efx_self_tests *tests, | |
b681e57c | 296 | u8 *strings, u64 *data) |
3273c2e8 BH |
297 | { |
298 | struct efx_channel *channel; | |
1796721a | 299 | unsigned int n = 0, i; |
3273c2e8 BH |
300 | enum efx_loopback_mode mode; |
301 | ||
4f16c073 BH |
302 | efx_fill_test(n++, strings, data, &tests->phy_alive, |
303 | "phy", 0, "alive", NULL); | |
8c8661e4 BH |
304 | efx_fill_test(n++, strings, data, &tests->nvram, |
305 | "core", 0, "nvram", NULL); | |
3273c2e8 BH |
306 | efx_fill_test(n++, strings, data, &tests->interrupt, |
307 | "core", 0, "interrupt", NULL); | |
308 | ||
309 | /* Event queues */ | |
310 | efx_for_each_channel(channel, efx) { | |
311 | efx_fill_test(n++, strings, data, | |
312 | &tests->eventq_dma[channel->channel], | |
313 | EFX_CHANNEL_NAME(channel), | |
314 | "eventq.dma", NULL); | |
315 | efx_fill_test(n++, strings, data, | |
316 | &tests->eventq_int[channel->channel], | |
317 | EFX_CHANNEL_NAME(channel), | |
318 | "eventq.int", NULL); | |
3273c2e8 BH |
319 | } |
320 | ||
74cd60a4 JC |
321 | efx_fill_test(n++, strings, data, &tests->memory, |
322 | "core", 0, "memory", NULL); | |
8c8661e4 BH |
323 | efx_fill_test(n++, strings, data, &tests->registers, |
324 | "core", 0, "registers", NULL); | |
1796721a | 325 | |
c1c4f453 BH |
326 | if (efx->phy_op->run_tests != NULL) { |
327 | EFX_BUG_ON_PARANOID(efx->phy_op->test_name == NULL); | |
328 | ||
329 | for (i = 0; true; ++i) { | |
330 | const char *name; | |
331 | ||
332 | EFX_BUG_ON_PARANOID(i >= EFX_MAX_PHY_TESTS); | |
333 | name = efx->phy_op->test_name(efx, i); | |
334 | if (name == NULL) | |
335 | break; | |
336 | ||
4f16c073 | 337 | efx_fill_test(n++, strings, data, &tests->phy_ext[i], |
c1c4f453 BH |
338 | "phy", 0, name, NULL); |
339 | } | |
340 | } | |
3273c2e8 BH |
341 | |
342 | /* Loopback tests */ | |
8c8661e4 | 343 | for (mode = LOOPBACK_NONE; mode <= LOOPBACK_TEST_MAX; mode++) { |
3273c2e8 BH |
344 | if (!(efx->loopback_modes & (1 << mode))) |
345 | continue; | |
346 | n = efx_fill_loopback_test(efx, | |
347 | &tests->loopback[mode], mode, n, | |
348 | strings, data); | |
349 | } | |
350 | ||
351 | return n; | |
352 | } | |
353 | ||
3594e131 BH |
354 | static int efx_ethtool_get_sset_count(struct net_device *net_dev, |
355 | int string_set) | |
8ceee660 | 356 | { |
cd0ecc9a BH |
357 | struct efx_nic *efx = netdev_priv(net_dev); |
358 | ||
3594e131 BH |
359 | switch (string_set) { |
360 | case ETH_SS_STATS: | |
cd0ecc9a BH |
361 | return efx->type->describe_stats(efx, NULL) + |
362 | EFX_ETHTOOL_SW_STAT_COUNT; | |
3594e131 | 363 | case ETH_SS_TEST: |
cd0ecc9a | 364 | return efx_ethtool_fill_self_tests(efx, NULL, NULL, NULL); |
3594e131 BH |
365 | default: |
366 | return -EINVAL; | |
367 | } | |
3273c2e8 BH |
368 | } |
369 | ||
8ceee660 BH |
370 | static void efx_ethtool_get_strings(struct net_device *net_dev, |
371 | u32 string_set, u8 *strings) | |
372 | { | |
767e468c | 373 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 BH |
374 | int i; |
375 | ||
3273c2e8 BH |
376 | switch (string_set) { |
377 | case ETH_SS_STATS: | |
cd0ecc9a BH |
378 | strings += (efx->type->describe_stats(efx, strings) * |
379 | ETH_GSTRING_LEN); | |
380 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) | |
b681e57c | 381 | strlcpy(strings + i * ETH_GSTRING_LEN, |
cd0ecc9a | 382 | efx_sw_stat_desc[i].name, ETH_GSTRING_LEN); |
3273c2e8 BH |
383 | break; |
384 | case ETH_SS_TEST: | |
b681e57c | 385 | efx_ethtool_fill_self_tests(efx, NULL, strings, NULL); |
3273c2e8 BH |
386 | break; |
387 | default: | |
388 | /* No other string sets */ | |
389 | break; | |
390 | } | |
8ceee660 BH |
391 | } |
392 | ||
393 | static void efx_ethtool_get_stats(struct net_device *net_dev, | |
394 | struct ethtool_stats *stats, | |
395 | u64 *data) | |
396 | { | |
767e468c | 397 | struct efx_nic *efx = netdev_priv(net_dev); |
cd0ecc9a | 398 | const struct efx_sw_stat_desc *stat; |
8ceee660 | 399 | struct efx_channel *channel; |
119226c5 | 400 | struct efx_tx_queue *tx_queue; |
8ceee660 BH |
401 | int i; |
402 | ||
1cb34522 BH |
403 | spin_lock_bh(&efx->stats_lock); |
404 | ||
cd0ecc9a BH |
405 | /* Get NIC statistics */ |
406 | data += efx->type->update_stats(efx, data, NULL); | |
8ceee660 | 407 | |
cd0ecc9a BH |
408 | /* Get software statistics */ |
409 | for (i = 0; i < EFX_ETHTOOL_SW_STAT_COUNT; i++) { | |
410 | stat = &efx_sw_stat_desc[i]; | |
8ceee660 | 411 | switch (stat->source) { |
8ceee660 BH |
412 | case EFX_ETHTOOL_STAT_SOURCE_nic: |
413 | data[i] = stat->get_stat((void *)efx + stat->offset); | |
414 | break; | |
415 | case EFX_ETHTOOL_STAT_SOURCE_channel: | |
416 | data[i] = 0; | |
417 | efx_for_each_channel(channel, efx) | |
418 | data[i] += stat->get_stat((void *)channel + | |
419 | stat->offset); | |
420 | break; | |
119226c5 BH |
421 | case EFX_ETHTOOL_STAT_SOURCE_tx_queue: |
422 | data[i] = 0; | |
423 | efx_for_each_channel(channel, efx) { | |
424 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
425 | data[i] += | |
426 | stat->get_stat((void *)tx_queue | |
427 | + stat->offset); | |
428 | } | |
429 | break; | |
8ceee660 BH |
430 | } |
431 | } | |
1cb34522 BH |
432 | |
433 | spin_unlock_bh(&efx->stats_lock); | |
8ceee660 BH |
434 | } |
435 | ||
3273c2e8 BH |
436 | static void efx_ethtool_self_test(struct net_device *net_dev, |
437 | struct ethtool_test *test, u64 *data) | |
438 | { | |
767e468c | 439 | struct efx_nic *efx = netdev_priv(net_dev); |
28801f35 | 440 | struct efx_self_tests *efx_tests; |
2ef3068e | 441 | int already_up; |
28801f35 ED |
442 | int rc = -ENOMEM; |
443 | ||
444 | efx_tests = kzalloc(sizeof(*efx_tests), GFP_KERNEL); | |
445 | if (!efx_tests) | |
446 | goto fail; | |
447 | ||
f16aeea0 | 448 | if (efx->state != STATE_READY) { |
3273c2e8 BH |
449 | rc = -EIO; |
450 | goto fail1; | |
451 | } | |
452 | ||
ac33ac61 BH |
453 | netif_info(efx, drv, efx->net_dev, "starting %sline testing\n", |
454 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
455 | ||
3273c2e8 BH |
456 | /* We need rx buffers and interrupts. */ |
457 | already_up = (efx->net_dev->flags & IFF_UP); | |
458 | if (!already_up) { | |
459 | rc = dev_open(efx->net_dev); | |
460 | if (rc) { | |
62776d03 BH |
461 | netif_err(efx, drv, efx->net_dev, |
462 | "failed opening device.\n"); | |
28801f35 | 463 | goto fail1; |
3273c2e8 BH |
464 | } |
465 | } | |
466 | ||
28801f35 | 467 | rc = efx_selftest(efx, efx_tests, test->flags); |
3273c2e8 | 468 | |
3273c2e8 BH |
469 | if (!already_up) |
470 | dev_close(efx->net_dev); | |
471 | ||
ac33ac61 BH |
472 | netif_info(efx, drv, efx->net_dev, "%s %sline self-tests\n", |
473 | rc == 0 ? "passed" : "failed", | |
474 | (test->flags & ETH_TEST_FL_OFFLINE) ? "off" : "on"); | |
3273c2e8 | 475 | |
28801f35 | 476 | fail1: |
3273c2e8 | 477 | /* Fill ethtool results structures */ |
28801f35 ED |
478 | efx_ethtool_fill_self_tests(efx, efx_tests, NULL, data); |
479 | kfree(efx_tests); | |
480 | fail: | |
3273c2e8 BH |
481 | if (rc) |
482 | test->flags |= ETH_TEST_FL_FAILED; | |
483 | } | |
484 | ||
8ceee660 BH |
485 | /* Restart autonegotiation */ |
486 | static int efx_ethtool_nway_reset(struct net_device *net_dev) | |
487 | { | |
767e468c | 488 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 489 | |
68e7f45e | 490 | return mdio45_nway_restart(&efx->mdio); |
8ceee660 BH |
491 | } |
492 | ||
a0c4faf5 BH |
493 | /* |
494 | * Each channel has a single IRQ and moderation timer, started by any | |
495 | * completion (or other event). Unless the module parameter | |
496 | * separate_tx_channels is set, IRQs and moderation are therefore | |
497 | * shared between RX and TX completions. In this case, when RX IRQ | |
498 | * moderation is explicitly changed then TX IRQ moderation is | |
499 | * automatically changed too, but otherwise we fail if the two values | |
500 | * are requested to be different. | |
501 | * | |
13225977 BH |
502 | * The hardware does not support a limit on the number of completions |
503 | * before an IRQ, so we do not use the max_frames fields. We should | |
504 | * report and require that max_frames == (usecs != 0), but this would | |
505 | * invalidate existing user documentation. | |
506 | * | |
507 | * The hardware does not have distinct settings for interrupt | |
508 | * moderation while the previous IRQ is being handled, so we should | |
509 | * not use the 'irq' fields. However, an earlier developer | |
510 | * misunderstood the meaning of the 'irq' fields and the driver did | |
511 | * not support the standard fields. To avoid invalidating existing | |
512 | * user documentation, we report and accept changes through either the | |
513 | * standard or 'irq' fields. If both are changed at the same time, we | |
514 | * prefer the standard field. | |
515 | * | |
a0c4faf5 BH |
516 | * We implement adaptive IRQ moderation, but use a different algorithm |
517 | * from that assumed in the definition of struct ethtool_coalesce. | |
518 | * Therefore we do not use any of the adaptive moderation parameters | |
519 | * in it. | |
520 | */ | |
521 | ||
8ceee660 BH |
522 | static int efx_ethtool_get_coalesce(struct net_device *net_dev, |
523 | struct ethtool_coalesce *coalesce) | |
524 | { | |
767e468c | 525 | struct efx_nic *efx = netdev_priv(net_dev); |
a0c4faf5 BH |
526 | unsigned int tx_usecs, rx_usecs; |
527 | bool rx_adaptive; | |
8ceee660 | 528 | |
a0c4faf5 | 529 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &rx_adaptive); |
8ceee660 | 530 | |
13225977 | 531 | coalesce->tx_coalesce_usecs = tx_usecs; |
a0c4faf5 | 532 | coalesce->tx_coalesce_usecs_irq = tx_usecs; |
13225977 | 533 | coalesce->rx_coalesce_usecs = rx_usecs; |
a0c4faf5 BH |
534 | coalesce->rx_coalesce_usecs_irq = rx_usecs; |
535 | coalesce->use_adaptive_rx_coalesce = rx_adaptive; | |
0d86ebd8 | 536 | |
8ceee660 BH |
537 | return 0; |
538 | } | |
539 | ||
8ceee660 BH |
540 | static int efx_ethtool_set_coalesce(struct net_device *net_dev, |
541 | struct ethtool_coalesce *coalesce) | |
542 | { | |
767e468c | 543 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 544 | struct efx_channel *channel; |
b548f976 | 545 | unsigned int tx_usecs, rx_usecs; |
9e393b30 BH |
546 | bool adaptive, rx_may_override_tx; |
547 | int rc; | |
8ceee660 | 548 | |
6fb70fd1 | 549 | if (coalesce->use_adaptive_tx_coalesce) |
9f85ee9c | 550 | return -EINVAL; |
8ceee660 | 551 | |
a0c4faf5 BH |
552 | efx_get_irq_moderation(efx, &tx_usecs, &rx_usecs, &adaptive); |
553 | ||
13225977 BH |
554 | if (coalesce->rx_coalesce_usecs != rx_usecs) |
555 | rx_usecs = coalesce->rx_coalesce_usecs; | |
556 | else | |
557 | rx_usecs = coalesce->rx_coalesce_usecs_irq; | |
558 | ||
6fb70fd1 | 559 | adaptive = coalesce->use_adaptive_rx_coalesce; |
8ceee660 | 560 | |
a0c4faf5 BH |
561 | /* If channels are shared, TX IRQ moderation can be quietly |
562 | * overridden unless it is changed from its old value. | |
563 | */ | |
13225977 BH |
564 | rx_may_override_tx = (coalesce->tx_coalesce_usecs == tx_usecs && |
565 | coalesce->tx_coalesce_usecs_irq == tx_usecs); | |
566 | if (coalesce->tx_coalesce_usecs != tx_usecs) | |
567 | tx_usecs = coalesce->tx_coalesce_usecs; | |
568 | else | |
569 | tx_usecs = coalesce->tx_coalesce_usecs_irq; | |
8ceee660 | 570 | |
9e393b30 BH |
571 | rc = efx_init_irq_moderation(efx, tx_usecs, rx_usecs, adaptive, |
572 | rx_may_override_tx); | |
573 | if (rc != 0) | |
574 | return rc; | |
575 | ||
8ceee660 | 576 | efx_for_each_channel(channel, efx) |
ef2b90ee | 577 | efx->type->push_irq_moderation(channel); |
8ceee660 BH |
578 | |
579 | return 0; | |
580 | } | |
581 | ||
4642610c BH |
582 | static void efx_ethtool_get_ringparam(struct net_device *net_dev, |
583 | struct ethtool_ringparam *ring) | |
584 | { | |
585 | struct efx_nic *efx = netdev_priv(net_dev); | |
586 | ||
587 | ring->rx_max_pending = EFX_MAX_DMAQ_SIZE; | |
588 | ring->tx_max_pending = EFX_MAX_DMAQ_SIZE; | |
4642610c BH |
589 | ring->rx_pending = efx->rxq_entries; |
590 | ring->tx_pending = efx->txq_entries; | |
4642610c BH |
591 | } |
592 | ||
593 | static int efx_ethtool_set_ringparam(struct net_device *net_dev, | |
594 | struct ethtool_ringparam *ring) | |
595 | { | |
596 | struct efx_nic *efx = netdev_priv(net_dev); | |
7e6d06f0 | 597 | u32 txq_entries; |
4642610c BH |
598 | |
599 | if (ring->rx_mini_pending || ring->rx_jumbo_pending || | |
600 | ring->rx_pending > EFX_MAX_DMAQ_SIZE || | |
601 | ring->tx_pending > EFX_MAX_DMAQ_SIZE) | |
602 | return -EINVAL; | |
603 | ||
7e6d06f0 | 604 | if (ring->rx_pending < EFX_RXQ_MIN_ENT) { |
4642610c | 605 | netif_err(efx, drv, efx->net_dev, |
7e6d06f0 BH |
606 | "RX queues cannot be smaller than %u\n", |
607 | EFX_RXQ_MIN_ENT); | |
4642610c BH |
608 | return -EINVAL; |
609 | } | |
610 | ||
7e6d06f0 BH |
611 | txq_entries = max(ring->tx_pending, EFX_TXQ_MIN_ENT(efx)); |
612 | if (txq_entries != ring->tx_pending) | |
613 | netif_warn(efx, drv, efx->net_dev, | |
614 | "increasing TX queue size to minimum of %u\n", | |
615 | txq_entries); | |
616 | ||
617 | return efx_realloc_channels(efx, ring->rx_pending, txq_entries); | |
4642610c BH |
618 | } |
619 | ||
8ceee660 BH |
620 | static int efx_ethtool_set_pauseparam(struct net_device *net_dev, |
621 | struct ethtool_pauseparam *pause) | |
622 | { | |
767e468c | 623 | struct efx_nic *efx = netdev_priv(net_dev); |
b5626946 | 624 | u8 wanted_fc, old_fc; |
d3245b28 | 625 | u32 old_adv; |
d3245b28 BH |
626 | int rc = 0; |
627 | ||
628 | mutex_lock(&efx->mac_lock); | |
8ceee660 | 629 | |
04cc8cac BH |
630 | wanted_fc = ((pause->rx_pause ? EFX_FC_RX : 0) | |
631 | (pause->tx_pause ? EFX_FC_TX : 0) | | |
632 | (pause->autoneg ? EFX_FC_AUTO : 0)); | |
633 | ||
634 | if ((wanted_fc & EFX_FC_TX) && !(wanted_fc & EFX_FC_RX)) { | |
62776d03 BH |
635 | netif_dbg(efx, drv, efx->net_dev, |
636 | "Flow control unsupported: tx ON rx OFF\n"); | |
d3245b28 BH |
637 | rc = -EINVAL; |
638 | goto out; | |
04cc8cac BH |
639 | } |
640 | ||
d3245b28 | 641 | if ((wanted_fc & EFX_FC_AUTO) && !efx->link_advertising) { |
62776d03 BH |
642 | netif_dbg(efx, drv, efx->net_dev, |
643 | "Autonegotiation is disabled\n"); | |
d3245b28 BH |
644 | rc = -EINVAL; |
645 | goto out; | |
04cc8cac BH |
646 | } |
647 | ||
9dd3a13b BH |
648 | /* Hook for Falcon bug 11482 workaround */ |
649 | if (efx->type->prepare_enable_fc_tx && | |
650 | (wanted_fc & EFX_FC_TX) && !(efx->wanted_fc & EFX_FC_TX)) | |
651 | efx->type->prepare_enable_fc_tx(efx); | |
04cc8cac | 652 | |
d3245b28 BH |
653 | old_adv = efx->link_advertising; |
654 | old_fc = efx->wanted_fc; | |
655 | efx_link_set_wanted_fc(efx, wanted_fc); | |
656 | if (efx->link_advertising != old_adv || | |
657 | (efx->wanted_fc ^ old_fc) & EFX_FC_AUTO) { | |
658 | rc = efx->phy_op->reconfigure(efx); | |
659 | if (rc) { | |
62776d03 BH |
660 | netif_err(efx, drv, efx->net_dev, |
661 | "Unable to advertise requested flow " | |
662 | "control setting\n"); | |
d3245b28 BH |
663 | goto out; |
664 | } | |
665 | } | |
04cc8cac | 666 | |
d3245b28 BH |
667 | /* Reconfigure the MAC. The PHY *may* generate a link state change event |
668 | * if the user just changed the advertised capabilities, but there's no | |
669 | * harm doing this twice */ | |
710b208d | 670 | efx->type->reconfigure_mac(efx); |
04cc8cac | 671 | |
d3245b28 | 672 | out: |
04cc8cac | 673 | mutex_unlock(&efx->mac_lock); |
8ceee660 | 674 | |
d3245b28 | 675 | return rc; |
8ceee660 BH |
676 | } |
677 | ||
678 | static void efx_ethtool_get_pauseparam(struct net_device *net_dev, | |
679 | struct ethtool_pauseparam *pause) | |
680 | { | |
767e468c | 681 | struct efx_nic *efx = netdev_priv(net_dev); |
8ceee660 | 682 | |
04cc8cac BH |
683 | pause->rx_pause = !!(efx->wanted_fc & EFX_FC_RX); |
684 | pause->tx_pause = !!(efx->wanted_fc & EFX_FC_TX); | |
685 | pause->autoneg = !!(efx->wanted_fc & EFX_FC_AUTO); | |
8ceee660 BH |
686 | } |
687 | ||
688 | ||
89c758fa BH |
689 | static void efx_ethtool_get_wol(struct net_device *net_dev, |
690 | struct ethtool_wolinfo *wol) | |
691 | { | |
692 | struct efx_nic *efx = netdev_priv(net_dev); | |
693 | return efx->type->get_wol(efx, wol); | |
694 | } | |
695 | ||
696 | ||
697 | static int efx_ethtool_set_wol(struct net_device *net_dev, | |
698 | struct ethtool_wolinfo *wol) | |
699 | { | |
700 | struct efx_nic *efx = netdev_priv(net_dev); | |
701 | return efx->type->set_wol(efx, wol->wolopts); | |
702 | } | |
703 | ||
d215697f | 704 | static int efx_ethtool_reset(struct net_device *net_dev, u32 *flags) |
eb9f6744 BH |
705 | { |
706 | struct efx_nic *efx = netdev_priv(net_dev); | |
0e2a9c7c | 707 | int rc; |
eb9f6744 | 708 | |
0e2a9c7c BH |
709 | rc = efx->type->map_reset_flags(flags); |
710 | if (rc < 0) | |
711 | return rc; | |
eb9f6744 | 712 | |
0e2a9c7c | 713 | return efx_reset(efx, rc); |
eb9f6744 BH |
714 | } |
715 | ||
7c460d9b BH |
716 | /* MAC address mask including only I/G bit */ |
717 | static const u8 mac_addr_ig_mask[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 }; | |
c274d65c | 718 | |
0e0c3408 BH |
719 | #define IP4_ADDR_FULL_MASK ((__force __be32)~0) |
720 | #define PORT_FULL_MASK ((__force __be16)~0) | |
7c460d9b | 721 | #define ETHER_TYPE_FULL_MASK ((__force __be16)~0) |
0e0c3408 | 722 | |
b2bb7b77 BH |
723 | static int efx_ethtool_get_class_rule(struct efx_nic *efx, |
724 | struct ethtool_rx_flow_spec *rule) | |
725 | { | |
726 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; | |
727 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; | |
c274d65c BH |
728 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; |
729 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; | |
b2bb7b77 | 730 | struct efx_filter_spec spec; |
b2bb7b77 BH |
731 | int rc; |
732 | ||
733 | rc = efx_filter_get_filter_safe(efx, EFX_FILTER_PRI_MANUAL, | |
734 | rule->location, &spec); | |
735 | if (rc) | |
736 | return rc; | |
737 | ||
f26e958c | 738 | if (spec.dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP) |
b2bb7b77 BH |
739 | rule->ring_cookie = RX_CLS_FLOW_DISC; |
740 | else | |
741 | rule->ring_cookie = spec.dmaq_id; | |
742 | ||
7c460d9b BH |
743 | if ((spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) && |
744 | spec.ether_type == htons(ETH_P_IP) && | |
745 | (spec.match_flags & EFX_FILTER_MATCH_IP_PROTO) && | |
746 | (spec.ip_proto == IPPROTO_TCP || spec.ip_proto == IPPROTO_UDP) && | |
747 | !(spec.match_flags & | |
748 | ~(EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_OUTER_VID | | |
749 | EFX_FILTER_MATCH_LOC_HOST | EFX_FILTER_MATCH_REM_HOST | | |
750 | EFX_FILTER_MATCH_IP_PROTO | | |
751 | EFX_FILTER_MATCH_LOC_PORT | EFX_FILTER_MATCH_REM_PORT))) { | |
752 | rule->flow_type = ((spec.ip_proto == IPPROTO_TCP) ? | |
753 | TCP_V4_FLOW : UDP_V4_FLOW); | |
754 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_HOST) { | |
755 | ip_entry->ip4dst = spec.loc_host[0]; | |
756 | ip_mask->ip4dst = IP4_ADDR_FULL_MASK; | |
757 | } | |
758 | if (spec.match_flags & EFX_FILTER_MATCH_REM_HOST) { | |
759 | ip_entry->ip4src = spec.rem_host[0]; | |
760 | ip_mask->ip4src = IP4_ADDR_FULL_MASK; | |
761 | } | |
762 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_PORT) { | |
763 | ip_entry->pdst = spec.loc_port; | |
764 | ip_mask->pdst = PORT_FULL_MASK; | |
765 | } | |
766 | if (spec.match_flags & EFX_FILTER_MATCH_REM_PORT) { | |
767 | ip_entry->psrc = spec.rem_port; | |
768 | ip_mask->psrc = PORT_FULL_MASK; | |
769 | } | |
770 | } else if (!(spec.match_flags & | |
771 | ~(EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG | | |
772 | EFX_FILTER_MATCH_REM_MAC | EFX_FILTER_MATCH_ETHER_TYPE | | |
773 | EFX_FILTER_MATCH_OUTER_VID))) { | |
b2bb7b77 | 774 | rule->flow_type = ETHER_FLOW; |
7c460d9b BH |
775 | if (spec.match_flags & |
776 | (EFX_FILTER_MATCH_LOC_MAC | EFX_FILTER_MATCH_LOC_MAC_IG)) { | |
777 | memcpy(mac_entry->h_dest, spec.loc_mac, ETH_ALEN); | |
778 | if (spec.match_flags & EFX_FILTER_MATCH_LOC_MAC) | |
779 | memset(mac_mask->h_dest, ~0, ETH_ALEN); | |
780 | else | |
781 | memcpy(mac_mask->h_dest, mac_addr_ig_mask, | |
782 | ETH_ALEN); | |
b2bb7b77 | 783 | } |
7c460d9b BH |
784 | if (spec.match_flags & EFX_FILTER_MATCH_REM_MAC) { |
785 | memcpy(mac_entry->h_source, spec.rem_mac, ETH_ALEN); | |
786 | memset(mac_mask->h_source, ~0, ETH_ALEN); | |
787 | } | |
788 | if (spec.match_flags & EFX_FILTER_MATCH_ETHER_TYPE) { | |
789 | mac_entry->h_proto = spec.ether_type; | |
790 | mac_mask->h_proto = ETHER_TYPE_FULL_MASK; | |
791 | } | |
792 | } else { | |
793 | /* The above should handle all filters that we insert */ | |
794 | WARN_ON(1); | |
795 | return -EINVAL; | |
b2bb7b77 BH |
796 | } |
797 | ||
7c460d9b BH |
798 | if (spec.match_flags & EFX_FILTER_MATCH_OUTER_VID) { |
799 | rule->flow_type |= FLOW_EXT; | |
800 | rule->h_ext.vlan_tci = spec.outer_vid; | |
801 | rule->m_ext.vlan_tci = htons(0xfff); | |
b2bb7b77 | 802 | } |
7c460d9b | 803 | |
b2bb7b77 BH |
804 | return rc; |
805 | } | |
806 | ||
765c9f46 BH |
807 | static int |
808 | efx_ethtool_get_rxnfc(struct net_device *net_dev, | |
b2bb7b77 | 809 | struct ethtool_rxnfc *info, u32 *rule_locs) |
765c9f46 BH |
810 | { |
811 | struct efx_nic *efx = netdev_priv(net_dev); | |
812 | ||
813 | switch (info->cmd) { | |
814 | case ETHTOOL_GRXRINGS: | |
815 | info->data = efx->n_rx_channels; | |
816 | return 0; | |
817 | ||
818 | case ETHTOOL_GRXFH: { | |
819 | unsigned min_revision = 0; | |
820 | ||
821 | info->data = 0; | |
822 | switch (info->flow_type) { | |
823 | case TCP_V4_FLOW: | |
824 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
825 | /* fall through */ | |
826 | case UDP_V4_FLOW: | |
827 | case SCTP_V4_FLOW: | |
828 | case AH_ESP_V4_FLOW: | |
829 | case IPV4_FLOW: | |
830 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
831 | min_revision = EFX_REV_FALCON_B0; | |
832 | break; | |
833 | case TCP_V6_FLOW: | |
834 | info->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3; | |
835 | /* fall through */ | |
836 | case UDP_V6_FLOW: | |
837 | case SCTP_V6_FLOW: | |
838 | case AH_ESP_V6_FLOW: | |
839 | case IPV6_FLOW: | |
840 | info->data |= RXH_IP_SRC | RXH_IP_DST; | |
841 | min_revision = EFX_REV_SIENA_A0; | |
842 | break; | |
843 | default: | |
844 | break; | |
845 | } | |
846 | if (efx_nic_rev(efx) < min_revision) | |
847 | info->data = 0; | |
848 | return 0; | |
849 | } | |
850 | ||
b2bb7b77 BH |
851 | case ETHTOOL_GRXCLSRLCNT: |
852 | info->data = efx_filter_get_rx_id_limit(efx); | |
853 | if (info->data == 0) | |
854 | return -EOPNOTSUPP; | |
855 | info->data |= RX_CLS_LOC_SPECIAL; | |
856 | info->rule_cnt = | |
857 | efx_filter_count_rx_used(efx, EFX_FILTER_PRI_MANUAL); | |
858 | return 0; | |
859 | ||
860 | case ETHTOOL_GRXCLSRULE: | |
861 | if (efx_filter_get_rx_id_limit(efx) == 0) | |
862 | return -EOPNOTSUPP; | |
863 | return efx_ethtool_get_class_rule(efx, &info->fs); | |
864 | ||
865 | case ETHTOOL_GRXCLSRLALL: { | |
866 | s32 rc; | |
867 | info->data = efx_filter_get_rx_id_limit(efx); | |
868 | if (info->data == 0) | |
869 | return -EOPNOTSUPP; | |
870 | rc = efx_filter_get_rx_ids(efx, EFX_FILTER_PRI_MANUAL, | |
871 | rule_locs, info->rule_cnt); | |
872 | if (rc < 0) | |
873 | return rc; | |
874 | info->rule_cnt = rc; | |
875 | return 0; | |
876 | } | |
877 | ||
765c9f46 BH |
878 | default: |
879 | return -EOPNOTSUPP; | |
880 | } | |
881 | } | |
882 | ||
b2bb7b77 BH |
883 | static int efx_ethtool_set_class_rule(struct efx_nic *efx, |
884 | struct ethtool_rx_flow_spec *rule) | |
b4187e42 | 885 | { |
b2bb7b77 BH |
886 | struct ethtool_tcpip4_spec *ip_entry = &rule->h_u.tcp_ip4_spec; |
887 | struct ethtool_tcpip4_spec *ip_mask = &rule->m_u.tcp_ip4_spec; | |
888 | struct ethhdr *mac_entry = &rule->h_u.ether_spec; | |
889 | struct ethhdr *mac_mask = &rule->m_u.ether_spec; | |
890 | struct efx_filter_spec spec; | |
c39d35eb | 891 | int rc; |
b4187e42 | 892 | |
b2bb7b77 | 893 | /* Check that user wants us to choose the location */ |
9e0f9a10 | 894 | if (rule->location != RX_CLS_LOC_ANY) |
b4187e42 BH |
895 | return -EINVAL; |
896 | ||
b2bb7b77 BH |
897 | /* Range-check ring_cookie */ |
898 | if (rule->ring_cookie >= efx->n_rx_channels && | |
899 | rule->ring_cookie != RX_CLS_FLOW_DISC) | |
b4187e42 BH |
900 | return -EINVAL; |
901 | ||
b2bb7b77 BH |
902 | /* Check for unsupported extensions */ |
903 | if ((rule->flow_type & FLOW_EXT) && | |
0e0c3408 | 904 | (rule->m_ext.vlan_etype || rule->m_ext.data[0] || |
b2bb7b77 BH |
905 | rule->m_ext.data[1])) |
906 | return -EINVAL; | |
907 | ||
85740cdf BH |
908 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_MANUAL, |
909 | efx->rx_scatter ? EFX_FILTER_FLAG_RX_SCATTER : 0, | |
b2bb7b77 | 910 | (rule->ring_cookie == RX_CLS_FLOW_DISC) ? |
f26e958c | 911 | EFX_FILTER_RX_DMAQ_ID_DROP : rule->ring_cookie); |
c39d35eb | 912 | |
7c460d9b | 913 | switch (rule->flow_type & ~FLOW_EXT) { |
b4187e42 | 914 | case TCP_V4_FLOW: |
7c460d9b BH |
915 | case UDP_V4_FLOW: |
916 | spec.match_flags = (EFX_FILTER_MATCH_ETHER_TYPE | | |
917 | EFX_FILTER_MATCH_IP_PROTO); | |
918 | spec.ether_type = htons(ETH_P_IP); | |
919 | spec.ip_proto = ((rule->flow_type & ~FLOW_EXT) == TCP_V4_FLOW ? | |
920 | IPPROTO_TCP : IPPROTO_UDP); | |
921 | if (ip_mask->ip4dst) { | |
922 | if (ip_mask->ip4dst != IP4_ADDR_FULL_MASK) | |
923 | return -EINVAL; | |
924 | spec.match_flags |= EFX_FILTER_MATCH_LOC_HOST; | |
925 | spec.loc_host[0] = ip_entry->ip4dst; | |
926 | } | |
927 | if (ip_mask->ip4src) { | |
928 | if (ip_mask->ip4src != IP4_ADDR_FULL_MASK) | |
929 | return -EINVAL; | |
930 | spec.match_flags |= EFX_FILTER_MATCH_REM_HOST; | |
931 | spec.rem_host[0] = ip_entry->ip4src; | |
932 | } | |
933 | if (ip_mask->pdst) { | |
934 | if (ip_mask->pdst != PORT_FULL_MASK) | |
935 | return -EINVAL; | |
936 | spec.match_flags |= EFX_FILTER_MATCH_LOC_PORT; | |
937 | spec.loc_port = ip_entry->pdst; | |
938 | } | |
939 | if (ip_mask->psrc) { | |
940 | if (ip_mask->psrc != PORT_FULL_MASK) | |
941 | return -EINVAL; | |
942 | spec.match_flags |= EFX_FILTER_MATCH_REM_PORT; | |
943 | spec.rem_port = ip_entry->psrc; | |
944 | } | |
945 | if (ip_mask->tos) | |
b4187e42 BH |
946 | return -EINVAL; |
947 | break; | |
c274d65c | 948 | |
7c460d9b BH |
949 | case ETHER_FLOW: |
950 | if (!is_zero_ether_addr(mac_mask->h_dest)) { | |
951 | if (ether_addr_equal(mac_mask->h_dest, | |
952 | mac_addr_ig_mask)) | |
953 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC_IG; | |
954 | else if (is_broadcast_ether_addr(mac_mask->h_dest)) | |
955 | spec.match_flags |= EFX_FILTER_MATCH_LOC_MAC; | |
c274d65c | 956 | else |
7c460d9b BH |
957 | return -EINVAL; |
958 | memcpy(spec.loc_mac, mac_entry->h_dest, ETH_ALEN); | |
c274d65c | 959 | } |
7c460d9b BH |
960 | if (!is_zero_ether_addr(mac_mask->h_source)) { |
961 | if (!is_broadcast_ether_addr(mac_mask->h_source)) | |
962 | return -EINVAL; | |
963 | spec.match_flags |= EFX_FILTER_MATCH_REM_MAC; | |
964 | memcpy(spec.rem_mac, mac_entry->h_source, ETH_ALEN); | |
965 | } | |
966 | if (mac_mask->h_proto) { | |
967 | if (mac_mask->h_proto != ETHER_TYPE_FULL_MASK) | |
968 | return -EINVAL; | |
969 | spec.match_flags |= EFX_FILTER_MATCH_ETHER_TYPE; | |
970 | spec.ether_type = mac_entry->h_proto; | |
c274d65c | 971 | } |
b4187e42 | 972 | break; |
c39d35eb | 973 | |
b4187e42 BH |
974 | default: |
975 | return -EINVAL; | |
976 | } | |
977 | ||
7c460d9b BH |
978 | if ((rule->flow_type & FLOW_EXT) && rule->m_ext.vlan_tci) { |
979 | if (rule->m_ext.vlan_tci != htons(0xfff)) | |
980 | return -EINVAL; | |
981 | spec.match_flags |= EFX_FILTER_MATCH_OUTER_VID; | |
982 | spec.outer_vid = rule->h_ext.vlan_tci; | |
983 | } | |
984 | ||
b2bb7b77 BH |
985 | rc = efx_filter_insert_filter(efx, &spec, true); |
986 | if (rc < 0) | |
987 | return rc; | |
47a8467c | 988 | |
b2bb7b77 BH |
989 | rule->location = rc; |
990 | return 0; | |
991 | } | |
992 | ||
993 | static int efx_ethtool_set_rxnfc(struct net_device *net_dev, | |
994 | struct ethtool_rxnfc *info) | |
995 | { | |
996 | struct efx_nic *efx = netdev_priv(net_dev); | |
997 | ||
998 | if (efx_filter_get_rx_id_limit(efx) == 0) | |
999 | return -EOPNOTSUPP; | |
1000 | ||
1001 | switch (info->cmd) { | |
1002 | case ETHTOOL_SRXCLSRLINS: | |
1003 | return efx_ethtool_set_class_rule(efx, &info->fs); | |
1004 | ||
1005 | case ETHTOOL_SRXCLSRLDEL: | |
1006 | return efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_MANUAL, | |
1007 | info->fs.location); | |
1008 | ||
1009 | default: | |
1010 | return -EOPNOTSUPP; | |
1011 | } | |
b4187e42 BH |
1012 | } |
1013 | ||
7850f63f | 1014 | static u32 efx_ethtool_get_rxfh_indir_size(struct net_device *net_dev) |
765c9f46 BH |
1015 | { |
1016 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1017 | |
cd2d5b52 BH |
1018 | return ((efx_nic_rev(efx) < EFX_REV_FALCON_B0 || |
1019 | efx->n_rx_channels == 1) ? | |
7850f63f BH |
1020 | 0 : ARRAY_SIZE(efx->rx_indir_table)); |
1021 | } | |
1022 | ||
1023 | static int efx_ethtool_get_rxfh_indir(struct net_device *net_dev, u32 *indir) | |
1024 | { | |
1025 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1026 | |
7850f63f | 1027 | memcpy(indir, efx->rx_indir_table, sizeof(efx->rx_indir_table)); |
765c9f46 BH |
1028 | return 0; |
1029 | } | |
1030 | ||
1031 | static int efx_ethtool_set_rxfh_indir(struct net_device *net_dev, | |
7850f63f | 1032 | const u32 *indir) |
765c9f46 BH |
1033 | { |
1034 | struct efx_nic *efx = netdev_priv(net_dev); | |
765c9f46 | 1035 | |
7850f63f | 1036 | memcpy(efx->rx_indir_table, indir, sizeof(efx->rx_indir_table)); |
d43050c0 | 1037 | efx->type->rx_push_rss_config(efx); |
765c9f46 BH |
1038 | return 0; |
1039 | } | |
1040 | ||
b51ca34a FW |
1041 | static int efx_ethtool_get_ts_info(struct net_device *net_dev, |
1042 | struct ethtool_ts_info *ts_info) | |
62ebac92 BH |
1043 | { |
1044 | struct efx_nic *efx = netdev_priv(net_dev); | |
1045 | ||
1046 | /* Software capabilities */ | |
1047 | ts_info->so_timestamping = (SOF_TIMESTAMPING_RX_SOFTWARE | | |
1048 | SOF_TIMESTAMPING_SOFTWARE); | |
1049 | ts_info->phc_index = -1; | |
1050 | ||
1051 | efx_ptp_get_ts_info(efx, ts_info); | |
1052 | return 0; | |
1053 | } | |
1054 | ||
c087bd2c SH |
1055 | static int efx_ethtool_get_module_eeprom(struct net_device *net_dev, |
1056 | struct ethtool_eeprom *ee, | |
1057 | u8 *data) | |
1058 | { | |
1059 | struct efx_nic *efx = netdev_priv(net_dev); | |
1060 | int ret; | |
1061 | ||
1062 | if (!efx->phy_op || !efx->phy_op->get_module_eeprom) | |
1063 | return -EOPNOTSUPP; | |
1064 | ||
1065 | mutex_lock(&efx->mac_lock); | |
1066 | ret = efx->phy_op->get_module_eeprom(efx, ee, data); | |
1067 | mutex_unlock(&efx->mac_lock); | |
1068 | ||
1069 | return ret; | |
1070 | } | |
1071 | ||
1072 | static int efx_ethtool_get_module_info(struct net_device *net_dev, | |
1073 | struct ethtool_modinfo *modinfo) | |
1074 | { | |
1075 | struct efx_nic *efx = netdev_priv(net_dev); | |
1076 | int ret; | |
1077 | ||
1078 | if (!efx->phy_op || !efx->phy_op->get_module_info) | |
1079 | return -EOPNOTSUPP; | |
1080 | ||
1081 | mutex_lock(&efx->mac_lock); | |
1082 | ret = efx->phy_op->get_module_info(efx, modinfo); | |
1083 | mutex_unlock(&efx->mac_lock); | |
1084 | ||
1085 | return ret; | |
1086 | } | |
1087 | ||
0fc0b732 | 1088 | const struct ethtool_ops efx_ethtool_ops = { |
8ceee660 BH |
1089 | .get_settings = efx_ethtool_get_settings, |
1090 | .set_settings = efx_ethtool_set_settings, | |
1091 | .get_drvinfo = efx_ethtool_get_drvinfo, | |
5b98c1bf BH |
1092 | .get_regs_len = efx_ethtool_get_regs_len, |
1093 | .get_regs = efx_ethtool_get_regs, | |
62776d03 BH |
1094 | .get_msglevel = efx_ethtool_get_msglevel, |
1095 | .set_msglevel = efx_ethtool_set_msglevel, | |
8ceee660 | 1096 | .nway_reset = efx_ethtool_nway_reset, |
ed4ba4b5 | 1097 | .get_link = ethtool_op_get_link, |
8ceee660 BH |
1098 | .get_coalesce = efx_ethtool_get_coalesce, |
1099 | .set_coalesce = efx_ethtool_set_coalesce, | |
4642610c BH |
1100 | .get_ringparam = efx_ethtool_get_ringparam, |
1101 | .set_ringparam = efx_ethtool_set_ringparam, | |
8ceee660 BH |
1102 | .get_pauseparam = efx_ethtool_get_pauseparam, |
1103 | .set_pauseparam = efx_ethtool_set_pauseparam, | |
3594e131 | 1104 | .get_sset_count = efx_ethtool_get_sset_count, |
3273c2e8 | 1105 | .self_test = efx_ethtool_self_test, |
8ceee660 | 1106 | .get_strings = efx_ethtool_get_strings, |
c5e129ac | 1107 | .set_phys_id = efx_ethtool_phys_id, |
8ceee660 | 1108 | .get_ethtool_stats = efx_ethtool_get_stats, |
89c758fa BH |
1109 | .get_wol = efx_ethtool_get_wol, |
1110 | .set_wol = efx_ethtool_set_wol, | |
eb9f6744 | 1111 | .reset = efx_ethtool_reset, |
765c9f46 | 1112 | .get_rxnfc = efx_ethtool_get_rxnfc, |
b2bb7b77 | 1113 | .set_rxnfc = efx_ethtool_set_rxnfc, |
7850f63f | 1114 | .get_rxfh_indir_size = efx_ethtool_get_rxfh_indir_size, |
765c9f46 BH |
1115 | .get_rxfh_indir = efx_ethtool_get_rxfh_indir, |
1116 | .set_rxfh_indir = efx_ethtool_set_rxfh_indir, | |
62ebac92 | 1117 | .get_ts_info = efx_ethtool_get_ts_info, |
c087bd2c SH |
1118 | .get_module_info = efx_ethtool_get_module_info, |
1119 | .get_module_eeprom = efx_ethtool_get_module_eeprom, | |
8ceee660 | 1120 | }; |