fm10k: Remove redundant rx_errors in ethtool
[deliverable/linux.git] / drivers / net / ethernet / intel / fm10k / fm10k_ethtool.c
1 /* Intel Ethernet Switch Host Interface Driver
2 * Copyright(c) 2013 - 2015 Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * The full GNU General Public License is included in this distribution in
14 * the file called "COPYING".
15 *
16 * Contact Information:
17 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
18 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
19 */
20
21 #include <linux/vmalloc.h>
22
23 #include "fm10k.h"
24
25 struct fm10k_stats {
26 char stat_string[ETH_GSTRING_LEN];
27 int sizeof_stat;
28 int stat_offset;
29 };
30
31 #define FM10K_NETDEV_STAT(_net_stat) { \
32 .stat_string = #_net_stat, \
33 .sizeof_stat = FIELD_SIZEOF(struct net_device_stats, _net_stat), \
34 .stat_offset = offsetof(struct net_device_stats, _net_stat) \
35 }
36
37 static const struct fm10k_stats fm10k_gstrings_net_stats[] = {
38 FM10K_NETDEV_STAT(tx_packets),
39 FM10K_NETDEV_STAT(tx_bytes),
40 FM10K_NETDEV_STAT(tx_errors),
41 FM10K_NETDEV_STAT(rx_packets),
42 FM10K_NETDEV_STAT(rx_bytes),
43 FM10K_NETDEV_STAT(rx_errors),
44 FM10K_NETDEV_STAT(rx_dropped),
45
46 /* detailed Rx errors */
47 FM10K_NETDEV_STAT(rx_length_errors),
48 FM10K_NETDEV_STAT(rx_crc_errors),
49 FM10K_NETDEV_STAT(rx_fifo_errors),
50 };
51
52 #define FM10K_NETDEV_STATS_LEN ARRAY_SIZE(fm10k_gstrings_net_stats)
53
54 #define FM10K_STAT(_name, _stat) { \
55 .stat_string = _name, \
56 .sizeof_stat = FIELD_SIZEOF(struct fm10k_intfc, _stat), \
57 .stat_offset = offsetof(struct fm10k_intfc, _stat) \
58 }
59
60 static const struct fm10k_stats fm10k_gstrings_stats[] = {
61 FM10K_STAT("tx_restart_queue", restart_queue),
62 FM10K_STAT("tx_busy", tx_busy),
63 FM10K_STAT("tx_csum_errors", tx_csum_errors),
64 FM10K_STAT("rx_alloc_failed", alloc_failed),
65 FM10K_STAT("rx_csum_errors", rx_csum_errors),
66
67 FM10K_STAT("tx_packets_nic", tx_packets_nic),
68 FM10K_STAT("tx_bytes_nic", tx_bytes_nic),
69 FM10K_STAT("rx_packets_nic", rx_packets_nic),
70 FM10K_STAT("rx_bytes_nic", rx_bytes_nic),
71 FM10K_STAT("rx_drops_nic", rx_drops_nic),
72 FM10K_STAT("rx_overrun_pf", rx_overrun_pf),
73 FM10K_STAT("rx_overrun_vf", rx_overrun_vf),
74
75 FM10K_STAT("timeout", stats.timeout.count),
76 FM10K_STAT("ur", stats.ur.count),
77 FM10K_STAT("ca", stats.ca.count),
78 FM10K_STAT("um", stats.um.count),
79 FM10K_STAT("xec", stats.xec.count),
80 FM10K_STAT("vlan_drop", stats.vlan_drop.count),
81 FM10K_STAT("loopback_drop", stats.loopback_drop.count),
82 FM10K_STAT("nodesc_drop", stats.nodesc_drop.count),
83
84 FM10K_STAT("swapi_status", hw.swapi.status),
85 FM10K_STAT("mac_rules_used", hw.swapi.mac.used),
86 FM10K_STAT("mac_rules_avail", hw.swapi.mac.avail),
87
88 FM10K_STAT("mbx_tx_busy", hw.mbx.tx_busy),
89 FM10K_STAT("mbx_tx_dropped", hw.mbx.tx_dropped),
90 FM10K_STAT("mbx_tx_messages", hw.mbx.tx_messages),
91 FM10K_STAT("mbx_tx_dwords", hw.mbx.tx_dwords),
92 FM10K_STAT("mbx_rx_messages", hw.mbx.rx_messages),
93 FM10K_STAT("mbx_rx_dwords", hw.mbx.rx_dwords),
94 FM10K_STAT("mbx_rx_parse_err", hw.mbx.rx_parse_err),
95
96 FM10K_STAT("tx_hwtstamp_timeouts", tx_hwtstamp_timeouts),
97 };
98
99 #define FM10K_GLOBAL_STATS_LEN ARRAY_SIZE(fm10k_gstrings_stats)
100
101 #define FM10K_QUEUE_STATS_LEN \
102 (MAX_QUEUES * 2 * (sizeof(struct fm10k_queue_stats) / sizeof(u64)))
103
104 #define FM10K_STATS_LEN (FM10K_GLOBAL_STATS_LEN + \
105 FM10K_NETDEV_STATS_LEN + \
106 FM10K_QUEUE_STATS_LEN)
107
108 static const char fm10k_gstrings_test[][ETH_GSTRING_LEN] = {
109 "Mailbox test (on/offline)"
110 };
111
112 #define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
113
114 enum fm10k_self_test_types {
115 FM10K_TEST_MBX,
116 FM10K_TEST_MAX = FM10K_TEST_LEN
117 };
118
119 static void fm10k_get_strings(struct net_device *dev, u32 stringset,
120 u8 *data)
121 {
122 char *p = (char *)data;
123 int i;
124
125 switch (stringset) {
126 case ETH_SS_TEST:
127 memcpy(data, *fm10k_gstrings_test,
128 FM10K_TEST_LEN * ETH_GSTRING_LEN);
129 break;
130 case ETH_SS_STATS:
131 for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
132 memcpy(p, fm10k_gstrings_net_stats[i].stat_string,
133 ETH_GSTRING_LEN);
134 p += ETH_GSTRING_LEN;
135 }
136 for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
137 memcpy(p, fm10k_gstrings_stats[i].stat_string,
138 ETH_GSTRING_LEN);
139 p += ETH_GSTRING_LEN;
140 }
141
142 for (i = 0; i < MAX_QUEUES; i++) {
143 sprintf(p, "tx_queue_%u_packets", i);
144 p += ETH_GSTRING_LEN;
145 sprintf(p, "tx_queue_%u_bytes", i);
146 p += ETH_GSTRING_LEN;
147 sprintf(p, "rx_queue_%u_packets", i);
148 p += ETH_GSTRING_LEN;
149 sprintf(p, "rx_queue_%u_bytes", i);
150 p += ETH_GSTRING_LEN;
151 }
152 break;
153 }
154 }
155
156 static int fm10k_get_sset_count(struct net_device *dev, int sset)
157 {
158 switch (sset) {
159 case ETH_SS_TEST:
160 return FM10K_TEST_LEN;
161 case ETH_SS_STATS:
162 return FM10K_STATS_LEN;
163 default:
164 return -EOPNOTSUPP;
165 }
166 }
167
168 static void fm10k_get_ethtool_stats(struct net_device *netdev,
169 struct ethtool_stats *stats, u64 *data)
170 {
171 const int stat_count = sizeof(struct fm10k_queue_stats) / sizeof(u64);
172 struct fm10k_intfc *interface = netdev_priv(netdev);
173 struct net_device_stats *net_stats = &netdev->stats;
174 char *p;
175 int i, j;
176
177 fm10k_update_stats(interface);
178
179 for (i = 0; i < FM10K_NETDEV_STATS_LEN; i++) {
180 p = (char *)net_stats + fm10k_gstrings_net_stats[i].stat_offset;
181 *(data++) = (fm10k_gstrings_net_stats[i].sizeof_stat ==
182 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
183 }
184
185 for (i = 0; i < FM10K_GLOBAL_STATS_LEN; i++) {
186 p = (char *)interface + fm10k_gstrings_stats[i].stat_offset;
187 *(data++) = (fm10k_gstrings_stats[i].sizeof_stat ==
188 sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
189 }
190
191 for (i = 0; i < MAX_QUEUES; i++) {
192 struct fm10k_ring *ring;
193 u64 *queue_stat;
194
195 ring = interface->tx_ring[i];
196 if (ring)
197 queue_stat = (u64 *)&ring->stats;
198 for (j = 0; j < stat_count; j++)
199 *(data++) = ring ? queue_stat[j] : 0;
200
201 ring = interface->rx_ring[i];
202 if (ring)
203 queue_stat = (u64 *)&ring->stats;
204 for (j = 0; j < stat_count; j++)
205 *(data++) = ring ? queue_stat[j] : 0;
206 }
207 }
208
209 /* If function below adds more registers this define needs to be updated */
210 #define FM10K_REGS_LEN_Q 29
211
212 static void fm10k_get_reg_q(struct fm10k_hw *hw, u32 *buff, int i)
213 {
214 int idx = 0;
215
216 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAL(i));
217 buff[idx++] = fm10k_read_reg(hw, FM10K_RDBAH(i));
218 buff[idx++] = fm10k_read_reg(hw, FM10K_RDLEN(i));
219 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_RXCTRL(i));
220 buff[idx++] = fm10k_read_reg(hw, FM10K_RDH(i));
221 buff[idx++] = fm10k_read_reg(hw, FM10K_RDT(i));
222 buff[idx++] = fm10k_read_reg(hw, FM10K_RXQCTL(i));
223 buff[idx++] = fm10k_read_reg(hw, FM10K_RXDCTL(i));
224 buff[idx++] = fm10k_read_reg(hw, FM10K_RXINT(i));
225 buff[idx++] = fm10k_read_reg(hw, FM10K_SRRCTL(i));
226 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRC(i));
227 buff[idx++] = fm10k_read_reg(hw, FM10K_QPRDC(i));
228 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_L(i));
229 buff[idx++] = fm10k_read_reg(hw, FM10K_QBRC_H(i));
230 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAL(i));
231 buff[idx++] = fm10k_read_reg(hw, FM10K_TDBAH(i));
232 buff[idx++] = fm10k_read_reg(hw, FM10K_TDLEN(i));
233 buff[idx++] = fm10k_read_reg(hw, FM10K_TPH_TXCTRL(i));
234 buff[idx++] = fm10k_read_reg(hw, FM10K_TDH(i));
235 buff[idx++] = fm10k_read_reg(hw, FM10K_TDT(i));
236 buff[idx++] = fm10k_read_reg(hw, FM10K_TXDCTL(i));
237 buff[idx++] = fm10k_read_reg(hw, FM10K_TXQCTL(i));
238 buff[idx++] = fm10k_read_reg(hw, FM10K_TXINT(i));
239 buff[idx++] = fm10k_read_reg(hw, FM10K_QPTC(i));
240 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_L(i));
241 buff[idx++] = fm10k_read_reg(hw, FM10K_QBTC_H(i));
242 buff[idx++] = fm10k_read_reg(hw, FM10K_TQDLOC(i));
243 buff[idx++] = fm10k_read_reg(hw, FM10K_TX_SGLORT(i));
244 buff[idx++] = fm10k_read_reg(hw, FM10K_PFVTCTL(i));
245
246 BUG_ON(idx != FM10K_REGS_LEN_Q);
247 }
248
249 /* If function above adds more registers this define needs to be updated */
250 #define FM10K_REGS_LEN_VSI 43
251
252 static void fm10k_get_reg_vsi(struct fm10k_hw *hw, u32 *buff, int i)
253 {
254 int idx = 0, j;
255
256 buff[idx++] = fm10k_read_reg(hw, FM10K_MRQC(i));
257 for (j = 0; j < 10; j++)
258 buff[idx++] = fm10k_read_reg(hw, FM10K_RSSRK(i, j));
259 for (j = 0; j < 32; j++)
260 buff[idx++] = fm10k_read_reg(hw, FM10K_RETA(i, j));
261
262 BUG_ON(idx != FM10K_REGS_LEN_VSI);
263 }
264
265 static void fm10k_get_regs(struct net_device *netdev,
266 struct ethtool_regs *regs, void *p)
267 {
268 struct fm10k_intfc *interface = netdev_priv(netdev);
269 struct fm10k_hw *hw = &interface->hw;
270 u32 *buff = p;
271 u16 i;
272
273 regs->version = (1 << 24) | (hw->revision_id << 16) | hw->device_id;
274
275 switch (hw->mac.type) {
276 case fm10k_mac_pf:
277 /* General PF Registers */
278 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL);
279 *(buff++) = fm10k_read_reg(hw, FM10K_CTRL_EXT);
280 *(buff++) = fm10k_read_reg(hw, FM10K_GCR);
281 *(buff++) = fm10k_read_reg(hw, FM10K_GCR_EXT);
282
283 for (i = 0; i < 8; i++) {
284 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTMAP(i));
285 *(buff++) = fm10k_read_reg(hw, FM10K_DGLORTDEC(i));
286 }
287
288 for (i = 0; i < 65; i++) {
289 fm10k_get_reg_vsi(hw, buff, i);
290 buff += FM10K_REGS_LEN_VSI;
291 }
292
293 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL);
294 *(buff++) = fm10k_read_reg(hw, FM10K_DMA_CTRL2);
295
296 for (i = 0; i < FM10K_MAX_QUEUES_PF; i++) {
297 fm10k_get_reg_q(hw, buff, i);
298 buff += FM10K_REGS_LEN_Q;
299 }
300
301 *(buff++) = fm10k_read_reg(hw, FM10K_TPH_CTRL);
302
303 for (i = 0; i < 8; i++)
304 *(buff++) = fm10k_read_reg(hw, FM10K_INT_MAP(i));
305
306 /* Interrupt Throttling Registers */
307 for (i = 0; i < 130; i++)
308 *(buff++) = fm10k_read_reg(hw, FM10K_ITR(i));
309
310 break;
311 case fm10k_mac_vf:
312 /* General VF registers */
313 *(buff++) = fm10k_read_reg(hw, FM10K_VFCTRL);
314 *(buff++) = fm10k_read_reg(hw, FM10K_VFINT_MAP);
315 *(buff++) = fm10k_read_reg(hw, FM10K_VFSYSTIME);
316
317 /* Interrupt Throttling Registers */
318 for (i = 0; i < 8; i++)
319 *(buff++) = fm10k_read_reg(hw, FM10K_VFITR(i));
320
321 fm10k_get_reg_vsi(hw, buff, 0);
322 buff += FM10K_REGS_LEN_VSI;
323
324 for (i = 0; i < FM10K_MAX_QUEUES_POOL; i++) {
325 if (i < hw->mac.max_queues)
326 fm10k_get_reg_q(hw, buff, i);
327 else
328 memset(buff, 0, sizeof(u32) * FM10K_REGS_LEN_Q);
329 buff += FM10K_REGS_LEN_Q;
330 }
331
332 break;
333 default:
334 return;
335 }
336 }
337
338 /* If function above adds more registers these define need to be updated */
339 #define FM10K_REGS_LEN_PF \
340 (162 + (65 * FM10K_REGS_LEN_VSI) + (FM10K_MAX_QUEUES_PF * FM10K_REGS_LEN_Q))
341 #define FM10K_REGS_LEN_VF \
342 (11 + FM10K_REGS_LEN_VSI + (FM10K_MAX_QUEUES_POOL * FM10K_REGS_LEN_Q))
343
344 static int fm10k_get_regs_len(struct net_device *netdev)
345 {
346 struct fm10k_intfc *interface = netdev_priv(netdev);
347 struct fm10k_hw *hw = &interface->hw;
348
349 switch (hw->mac.type) {
350 case fm10k_mac_pf:
351 return FM10K_REGS_LEN_PF * sizeof(u32);
352 case fm10k_mac_vf:
353 return FM10K_REGS_LEN_VF * sizeof(u32);
354 default:
355 return 0;
356 }
357 }
358
359 static void fm10k_get_drvinfo(struct net_device *dev,
360 struct ethtool_drvinfo *info)
361 {
362 struct fm10k_intfc *interface = netdev_priv(dev);
363
364 strncpy(info->driver, fm10k_driver_name,
365 sizeof(info->driver) - 1);
366 strncpy(info->version, fm10k_driver_version,
367 sizeof(info->version) - 1);
368 strncpy(info->bus_info, pci_name(interface->pdev),
369 sizeof(info->bus_info) - 1);
370
371 info->n_stats = FM10K_STATS_LEN;
372
373 info->regdump_len = fm10k_get_regs_len(dev);
374 }
375
376 static void fm10k_get_pauseparam(struct net_device *dev,
377 struct ethtool_pauseparam *pause)
378 {
379 struct fm10k_intfc *interface = netdev_priv(dev);
380
381 /* record fixed values for autoneg and tx pause */
382 pause->autoneg = 0;
383 pause->tx_pause = 1;
384
385 pause->rx_pause = interface->rx_pause ? 1 : 0;
386 }
387
388 static int fm10k_set_pauseparam(struct net_device *dev,
389 struct ethtool_pauseparam *pause)
390 {
391 struct fm10k_intfc *interface = netdev_priv(dev);
392 struct fm10k_hw *hw = &interface->hw;
393
394 if (pause->autoneg || !pause->tx_pause)
395 return -EINVAL;
396
397 /* we can only support pause on the PF to avoid head-of-line blocking */
398 if (hw->mac.type == fm10k_mac_pf)
399 interface->rx_pause = pause->rx_pause ? ~0 : 0;
400 else if (pause->rx_pause)
401 return -EINVAL;
402
403 if (netif_running(dev))
404 fm10k_update_rx_drop_en(interface);
405
406 return 0;
407 }
408
409 static u32 fm10k_get_msglevel(struct net_device *netdev)
410 {
411 struct fm10k_intfc *interface = netdev_priv(netdev);
412
413 return interface->msg_enable;
414 }
415
416 static void fm10k_set_msglevel(struct net_device *netdev, u32 data)
417 {
418 struct fm10k_intfc *interface = netdev_priv(netdev);
419
420 interface->msg_enable = data;
421 }
422
423 static void fm10k_get_ringparam(struct net_device *netdev,
424 struct ethtool_ringparam *ring)
425 {
426 struct fm10k_intfc *interface = netdev_priv(netdev);
427
428 ring->rx_max_pending = FM10K_MAX_RXD;
429 ring->tx_max_pending = FM10K_MAX_TXD;
430 ring->rx_mini_max_pending = 0;
431 ring->rx_jumbo_max_pending = 0;
432 ring->rx_pending = interface->rx_ring_count;
433 ring->tx_pending = interface->tx_ring_count;
434 ring->rx_mini_pending = 0;
435 ring->rx_jumbo_pending = 0;
436 }
437
438 static int fm10k_set_ringparam(struct net_device *netdev,
439 struct ethtool_ringparam *ring)
440 {
441 struct fm10k_intfc *interface = netdev_priv(netdev);
442 struct fm10k_ring *temp_ring;
443 int i, err = 0;
444 u32 new_rx_count, new_tx_count;
445
446 if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending))
447 return -EINVAL;
448
449 new_tx_count = clamp_t(u32, ring->tx_pending,
450 FM10K_MIN_TXD, FM10K_MAX_TXD);
451 new_tx_count = ALIGN(new_tx_count, FM10K_REQ_TX_DESCRIPTOR_MULTIPLE);
452
453 new_rx_count = clamp_t(u32, ring->rx_pending,
454 FM10K_MIN_RXD, FM10K_MAX_RXD);
455 new_rx_count = ALIGN(new_rx_count, FM10K_REQ_RX_DESCRIPTOR_MULTIPLE);
456
457 if ((new_tx_count == interface->tx_ring_count) &&
458 (new_rx_count == interface->rx_ring_count)) {
459 /* nothing to do */
460 return 0;
461 }
462
463 while (test_and_set_bit(__FM10K_RESETTING, &interface->state))
464 usleep_range(1000, 2000);
465
466 if (!netif_running(interface->netdev)) {
467 for (i = 0; i < interface->num_tx_queues; i++)
468 interface->tx_ring[i]->count = new_tx_count;
469 for (i = 0; i < interface->num_rx_queues; i++)
470 interface->rx_ring[i]->count = new_rx_count;
471 interface->tx_ring_count = new_tx_count;
472 interface->rx_ring_count = new_rx_count;
473 goto clear_reset;
474 }
475
476 /* allocate temporary buffer to store rings in */
477 i = max_t(int, interface->num_tx_queues, interface->num_rx_queues);
478 temp_ring = vmalloc(i * sizeof(struct fm10k_ring));
479
480 if (!temp_ring) {
481 err = -ENOMEM;
482 goto clear_reset;
483 }
484
485 fm10k_down(interface);
486
487 /* Setup new Tx resources and free the old Tx resources in that order.
488 * We can then assign the new resources to the rings via a memcpy.
489 * The advantage to this approach is that we are guaranteed to still
490 * have resources even in the case of an allocation failure.
491 */
492 if (new_tx_count != interface->tx_ring_count) {
493 for (i = 0; i < interface->num_tx_queues; i++) {
494 memcpy(&temp_ring[i], interface->tx_ring[i],
495 sizeof(struct fm10k_ring));
496
497 temp_ring[i].count = new_tx_count;
498 err = fm10k_setup_tx_resources(&temp_ring[i]);
499 if (err) {
500 while (i) {
501 i--;
502 fm10k_free_tx_resources(&temp_ring[i]);
503 }
504 goto err_setup;
505 }
506 }
507
508 for (i = 0; i < interface->num_tx_queues; i++) {
509 fm10k_free_tx_resources(interface->tx_ring[i]);
510
511 memcpy(interface->tx_ring[i], &temp_ring[i],
512 sizeof(struct fm10k_ring));
513 }
514
515 interface->tx_ring_count = new_tx_count;
516 }
517
518 /* Repeat the process for the Rx rings if needed */
519 if (new_rx_count != interface->rx_ring_count) {
520 for (i = 0; i < interface->num_rx_queues; i++) {
521 memcpy(&temp_ring[i], interface->rx_ring[i],
522 sizeof(struct fm10k_ring));
523
524 temp_ring[i].count = new_rx_count;
525 err = fm10k_setup_rx_resources(&temp_ring[i]);
526 if (err) {
527 while (i) {
528 i--;
529 fm10k_free_rx_resources(&temp_ring[i]);
530 }
531 goto err_setup;
532 }
533 }
534
535 for (i = 0; i < interface->num_rx_queues; i++) {
536 fm10k_free_rx_resources(interface->rx_ring[i]);
537
538 memcpy(interface->rx_ring[i], &temp_ring[i],
539 sizeof(struct fm10k_ring));
540 }
541
542 interface->rx_ring_count = new_rx_count;
543 }
544
545 err_setup:
546 fm10k_up(interface);
547 vfree(temp_ring);
548 clear_reset:
549 clear_bit(__FM10K_RESETTING, &interface->state);
550 return err;
551 }
552
553 static int fm10k_get_coalesce(struct net_device *dev,
554 struct ethtool_coalesce *ec)
555 {
556 struct fm10k_intfc *interface = netdev_priv(dev);
557
558 ec->use_adaptive_tx_coalesce =
559 !!(interface->tx_itr & FM10K_ITR_ADAPTIVE);
560 ec->tx_coalesce_usecs = interface->tx_itr & ~FM10K_ITR_ADAPTIVE;
561
562 ec->use_adaptive_rx_coalesce =
563 !!(interface->rx_itr & FM10K_ITR_ADAPTIVE);
564 ec->rx_coalesce_usecs = interface->rx_itr & ~FM10K_ITR_ADAPTIVE;
565
566 return 0;
567 }
568
569 static int fm10k_set_coalesce(struct net_device *dev,
570 struct ethtool_coalesce *ec)
571 {
572 struct fm10k_intfc *interface = netdev_priv(dev);
573 struct fm10k_q_vector *qv;
574 u16 tx_itr, rx_itr;
575 int i;
576
577 /* verify limits */
578 if ((ec->rx_coalesce_usecs > FM10K_ITR_MAX) ||
579 (ec->tx_coalesce_usecs > FM10K_ITR_MAX))
580 return -EINVAL;
581
582 /* record settings */
583 tx_itr = ec->tx_coalesce_usecs;
584 rx_itr = ec->rx_coalesce_usecs;
585
586 /* set initial values for adaptive ITR */
587 if (ec->use_adaptive_tx_coalesce)
588 tx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_10K;
589
590 if (ec->use_adaptive_rx_coalesce)
591 rx_itr = FM10K_ITR_ADAPTIVE | FM10K_ITR_20K;
592
593 /* update interface */
594 interface->tx_itr = tx_itr;
595 interface->rx_itr = rx_itr;
596
597 /* update q_vectors */
598 for (i = 0; i < interface->num_q_vectors; i++) {
599 qv = interface->q_vector[i];
600 qv->tx.itr = tx_itr;
601 qv->rx.itr = rx_itr;
602 }
603
604 return 0;
605 }
606
607 static int fm10k_get_rss_hash_opts(struct fm10k_intfc *interface,
608 struct ethtool_rxnfc *cmd)
609 {
610 cmd->data = 0;
611
612 /* Report default options for RSS on fm10k */
613 switch (cmd->flow_type) {
614 case TCP_V4_FLOW:
615 case TCP_V6_FLOW:
616 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
617 /* fall through */
618 case UDP_V4_FLOW:
619 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
620 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
621 /* fall through */
622 case SCTP_V4_FLOW:
623 case SCTP_V6_FLOW:
624 case AH_ESP_V4_FLOW:
625 case AH_ESP_V6_FLOW:
626 case AH_V4_FLOW:
627 case AH_V6_FLOW:
628 case ESP_V4_FLOW:
629 case ESP_V6_FLOW:
630 case IPV4_FLOW:
631 case IPV6_FLOW:
632 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
633 break;
634 case UDP_V6_FLOW:
635 if (interface->flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
636 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
637 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
638 break;
639 default:
640 return -EINVAL;
641 }
642
643 return 0;
644 }
645
646 static int fm10k_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
647 u32 *rule_locs)
648 {
649 struct fm10k_intfc *interface = netdev_priv(dev);
650 int ret = -EOPNOTSUPP;
651
652 switch (cmd->cmd) {
653 case ETHTOOL_GRXRINGS:
654 cmd->data = interface->num_rx_queues;
655 ret = 0;
656 break;
657 case ETHTOOL_GRXFH:
658 ret = fm10k_get_rss_hash_opts(interface, cmd);
659 break;
660 default:
661 break;
662 }
663
664 return ret;
665 }
666
667 #define UDP_RSS_FLAGS (FM10K_FLAG_RSS_FIELD_IPV4_UDP | \
668 FM10K_FLAG_RSS_FIELD_IPV6_UDP)
669 static int fm10k_set_rss_hash_opt(struct fm10k_intfc *interface,
670 struct ethtool_rxnfc *nfc)
671 {
672 u32 flags = interface->flags;
673
674 /* RSS does not support anything other than hashing
675 * to queues on src and dst IPs and ports
676 */
677 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
678 RXH_L4_B_0_1 | RXH_L4_B_2_3))
679 return -EINVAL;
680
681 switch (nfc->flow_type) {
682 case TCP_V4_FLOW:
683 case TCP_V6_FLOW:
684 if (!(nfc->data & RXH_IP_SRC) ||
685 !(nfc->data & RXH_IP_DST) ||
686 !(nfc->data & RXH_L4_B_0_1) ||
687 !(nfc->data & RXH_L4_B_2_3))
688 return -EINVAL;
689 break;
690 case UDP_V4_FLOW:
691 if (!(nfc->data & RXH_IP_SRC) ||
692 !(nfc->data & RXH_IP_DST))
693 return -EINVAL;
694 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
695 case 0:
696 flags &= ~FM10K_FLAG_RSS_FIELD_IPV4_UDP;
697 break;
698 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
699 flags |= FM10K_FLAG_RSS_FIELD_IPV4_UDP;
700 break;
701 default:
702 return -EINVAL;
703 }
704 break;
705 case UDP_V6_FLOW:
706 if (!(nfc->data & RXH_IP_SRC) ||
707 !(nfc->data & RXH_IP_DST))
708 return -EINVAL;
709 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
710 case 0:
711 flags &= ~FM10K_FLAG_RSS_FIELD_IPV6_UDP;
712 break;
713 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
714 flags |= FM10K_FLAG_RSS_FIELD_IPV6_UDP;
715 break;
716 default:
717 return -EINVAL;
718 }
719 break;
720 case AH_ESP_V4_FLOW:
721 case AH_V4_FLOW:
722 case ESP_V4_FLOW:
723 case SCTP_V4_FLOW:
724 case AH_ESP_V6_FLOW:
725 case AH_V6_FLOW:
726 case ESP_V6_FLOW:
727 case SCTP_V6_FLOW:
728 if (!(nfc->data & RXH_IP_SRC) ||
729 !(nfc->data & RXH_IP_DST) ||
730 (nfc->data & RXH_L4_B_0_1) ||
731 (nfc->data & RXH_L4_B_2_3))
732 return -EINVAL;
733 break;
734 default:
735 return -EINVAL;
736 }
737
738 /* if we changed something we need to update flags */
739 if (flags != interface->flags) {
740 struct fm10k_hw *hw = &interface->hw;
741 u32 mrqc;
742
743 if ((flags & UDP_RSS_FLAGS) &&
744 !(interface->flags & UDP_RSS_FLAGS))
745 netif_warn(interface, drv, interface->netdev,
746 "enabling UDP RSS: fragmented packets may arrive out of order to the stack above\n");
747
748 interface->flags = flags;
749
750 /* Perform hash on these packet types */
751 mrqc = FM10K_MRQC_IPV4 |
752 FM10K_MRQC_TCP_IPV4 |
753 FM10K_MRQC_IPV6 |
754 FM10K_MRQC_TCP_IPV6;
755
756 if (flags & FM10K_FLAG_RSS_FIELD_IPV4_UDP)
757 mrqc |= FM10K_MRQC_UDP_IPV4;
758 if (flags & FM10K_FLAG_RSS_FIELD_IPV6_UDP)
759 mrqc |= FM10K_MRQC_UDP_IPV6;
760
761 fm10k_write_reg(hw, FM10K_MRQC(0), mrqc);
762 }
763
764 return 0;
765 }
766
767 static int fm10k_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
768 {
769 struct fm10k_intfc *interface = netdev_priv(dev);
770 int ret = -EOPNOTSUPP;
771
772 switch (cmd->cmd) {
773 case ETHTOOL_SRXFH:
774 ret = fm10k_set_rss_hash_opt(interface, cmd);
775 break;
776 default:
777 break;
778 }
779
780 return ret;
781 }
782
783 static int fm10k_mbx_test(struct fm10k_intfc *interface, u64 *data)
784 {
785 struct fm10k_hw *hw = &interface->hw;
786 struct fm10k_mbx_info *mbx = &hw->mbx;
787 u32 attr_flag, test_msg[6];
788 unsigned long timeout;
789 int err;
790
791 /* For now this is a VF only feature */
792 if (hw->mac.type != fm10k_mac_vf)
793 return 0;
794
795 /* loop through both nested and unnested attribute types */
796 for (attr_flag = (1 << FM10K_TEST_MSG_UNSET);
797 attr_flag < (1 << (2 * FM10K_TEST_MSG_NESTED));
798 attr_flag += attr_flag) {
799 /* generate message to be tested */
800 fm10k_tlv_msg_test_create(test_msg, attr_flag);
801
802 fm10k_mbx_lock(interface);
803 mbx->test_result = FM10K_NOT_IMPLEMENTED;
804 err = mbx->ops.enqueue_tx(hw, mbx, test_msg);
805 fm10k_mbx_unlock(interface);
806
807 /* wait up to 1 second for response */
808 timeout = jiffies + HZ;
809 do {
810 if (err < 0)
811 goto err_out;
812
813 usleep_range(500, 1000);
814
815 fm10k_mbx_lock(interface);
816 mbx->ops.process(hw, mbx);
817 fm10k_mbx_unlock(interface);
818
819 err = mbx->test_result;
820 if (!err)
821 break;
822 } while (time_is_after_jiffies(timeout));
823
824 /* reporting errors */
825 if (err)
826 goto err_out;
827 }
828
829 err_out:
830 *data = err < 0 ? (attr_flag) : (err > 0);
831 return err;
832 }
833
834 static void fm10k_self_test(struct net_device *dev,
835 struct ethtool_test *eth_test, u64 *data)
836 {
837 struct fm10k_intfc *interface = netdev_priv(dev);
838 struct fm10k_hw *hw = &interface->hw;
839
840 memset(data, 0, sizeof(*data) * FM10K_TEST_LEN);
841
842 if (FM10K_REMOVED(hw)) {
843 netif_err(interface, drv, dev,
844 "Interface removed - test blocked\n");
845 eth_test->flags |= ETH_TEST_FL_FAILED;
846 return;
847 }
848
849 if (fm10k_mbx_test(interface, &data[FM10K_TEST_MBX]))
850 eth_test->flags |= ETH_TEST_FL_FAILED;
851 }
852
853 static u32 fm10k_get_reta_size(struct net_device *netdev)
854 {
855 return FM10K_RETA_SIZE * FM10K_RETA_ENTRIES_PER_REG;
856 }
857
858 static int fm10k_get_reta(struct net_device *netdev, u32 *indir)
859 {
860 struct fm10k_intfc *interface = netdev_priv(netdev);
861 int i;
862
863 if (!indir)
864 return 0;
865
866 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
867 u32 reta = interface->reta[i];
868
869 indir[0] = (reta << 24) >> 24;
870 indir[1] = (reta << 16) >> 24;
871 indir[2] = (reta << 8) >> 24;
872 indir[3] = (reta) >> 24;
873 }
874
875 return 0;
876 }
877
878 static int fm10k_set_reta(struct net_device *netdev, const u32 *indir)
879 {
880 struct fm10k_intfc *interface = netdev_priv(netdev);
881 struct fm10k_hw *hw = &interface->hw;
882 int i;
883 u16 rss_i;
884
885 if (!indir)
886 return 0;
887
888 /* Verify user input. */
889 rss_i = interface->ring_feature[RING_F_RSS].indices;
890 for (i = fm10k_get_reta_size(netdev); i--;) {
891 if (indir[i] < rss_i)
892 continue;
893 return -EINVAL;
894 }
895
896 /* record entries to reta table */
897 for (i = 0; i < FM10K_RETA_SIZE; i++, indir += 4) {
898 u32 reta = indir[0] |
899 (indir[1] << 8) |
900 (indir[2] << 16) |
901 (indir[3] << 24);
902
903 if (interface->reta[i] == reta)
904 continue;
905
906 interface->reta[i] = reta;
907 fm10k_write_reg(hw, FM10K_RETA(0, i), reta);
908 }
909
910 return 0;
911 }
912
913 static u32 fm10k_get_rssrk_size(struct net_device *netdev)
914 {
915 return FM10K_RSSRK_SIZE * FM10K_RSSRK_ENTRIES_PER_REG;
916 }
917
918 static int fm10k_get_rssh(struct net_device *netdev, u32 *indir, u8 *key,
919 u8 *hfunc)
920 {
921 struct fm10k_intfc *interface = netdev_priv(netdev);
922 int i, err;
923
924 if (hfunc)
925 *hfunc = ETH_RSS_HASH_TOP;
926
927 err = fm10k_get_reta(netdev, indir);
928 if (err || !key)
929 return err;
930
931 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4)
932 *(__le32 *)key = cpu_to_le32(interface->rssrk[i]);
933
934 return 0;
935 }
936
937 static int fm10k_set_rssh(struct net_device *netdev, const u32 *indir,
938 const u8 *key, const u8 hfunc)
939 {
940 struct fm10k_intfc *interface = netdev_priv(netdev);
941 struct fm10k_hw *hw = &interface->hw;
942 int i, err;
943
944 /* We do not allow change in unsupported parameters */
945 if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
946 return -EOPNOTSUPP;
947
948 err = fm10k_set_reta(netdev, indir);
949 if (err || !key)
950 return err;
951
952 for (i = 0; i < FM10K_RSSRK_SIZE; i++, key += 4) {
953 u32 rssrk = le32_to_cpu(*(__le32 *)key);
954
955 if (interface->rssrk[i] == rssrk)
956 continue;
957
958 interface->rssrk[i] = rssrk;
959 fm10k_write_reg(hw, FM10K_RSSRK(0, i), rssrk);
960 }
961
962 return 0;
963 }
964
965 static unsigned int fm10k_max_channels(struct net_device *dev)
966 {
967 struct fm10k_intfc *interface = netdev_priv(dev);
968 unsigned int max_combined = interface->hw.mac.max_queues;
969 u8 tcs = netdev_get_num_tc(dev);
970
971 /* For QoS report channels per traffic class */
972 if (tcs > 1)
973 max_combined = 1 << (fls(max_combined / tcs) - 1);
974
975 return max_combined;
976 }
977
978 static void fm10k_get_channels(struct net_device *dev,
979 struct ethtool_channels *ch)
980 {
981 struct fm10k_intfc *interface = netdev_priv(dev);
982 struct fm10k_hw *hw = &interface->hw;
983
984 /* report maximum channels */
985 ch->max_combined = fm10k_max_channels(dev);
986
987 /* report info for other vector */
988 ch->max_other = NON_Q_VECTORS(hw);
989 ch->other_count = ch->max_other;
990
991 /* record RSS queues */
992 ch->combined_count = interface->ring_feature[RING_F_RSS].indices;
993 }
994
995 static int fm10k_set_channels(struct net_device *dev,
996 struct ethtool_channels *ch)
997 {
998 struct fm10k_intfc *interface = netdev_priv(dev);
999 unsigned int count = ch->combined_count;
1000 struct fm10k_hw *hw = &interface->hw;
1001
1002 /* verify they are not requesting separate vectors */
1003 if (!count || ch->rx_count || ch->tx_count)
1004 return -EINVAL;
1005
1006 /* verify other_count has not changed */
1007 if (ch->other_count != NON_Q_VECTORS(hw))
1008 return -EINVAL;
1009
1010 /* verify the number of channels does not exceed hardware limits */
1011 if (count > fm10k_max_channels(dev))
1012 return -EINVAL;
1013
1014 interface->ring_feature[RING_F_RSS].limit = count;
1015
1016 /* use setup TC to update any traffic class queue mapping */
1017 return fm10k_setup_tc(dev, netdev_get_num_tc(dev));
1018 }
1019
1020 static int fm10k_get_ts_info(struct net_device *dev,
1021 struct ethtool_ts_info *info)
1022 {
1023 struct fm10k_intfc *interface = netdev_priv(dev);
1024
1025 info->so_timestamping =
1026 SOF_TIMESTAMPING_TX_SOFTWARE |
1027 SOF_TIMESTAMPING_RX_SOFTWARE |
1028 SOF_TIMESTAMPING_SOFTWARE |
1029 SOF_TIMESTAMPING_TX_HARDWARE |
1030 SOF_TIMESTAMPING_RX_HARDWARE |
1031 SOF_TIMESTAMPING_RAW_HARDWARE;
1032
1033 if (interface->ptp_clock)
1034 info->phc_index = ptp_clock_index(interface->ptp_clock);
1035 else
1036 info->phc_index = -1;
1037
1038 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1039 (1 << HWTSTAMP_TX_ON);
1040
1041 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1042 (1 << HWTSTAMP_FILTER_ALL);
1043
1044 return 0;
1045 }
1046
1047 static const struct ethtool_ops fm10k_ethtool_ops = {
1048 .get_strings = fm10k_get_strings,
1049 .get_sset_count = fm10k_get_sset_count,
1050 .get_ethtool_stats = fm10k_get_ethtool_stats,
1051 .get_drvinfo = fm10k_get_drvinfo,
1052 .get_link = ethtool_op_get_link,
1053 .get_pauseparam = fm10k_get_pauseparam,
1054 .set_pauseparam = fm10k_set_pauseparam,
1055 .get_msglevel = fm10k_get_msglevel,
1056 .set_msglevel = fm10k_set_msglevel,
1057 .get_ringparam = fm10k_get_ringparam,
1058 .set_ringparam = fm10k_set_ringparam,
1059 .get_coalesce = fm10k_get_coalesce,
1060 .set_coalesce = fm10k_set_coalesce,
1061 .get_rxnfc = fm10k_get_rxnfc,
1062 .set_rxnfc = fm10k_set_rxnfc,
1063 .get_regs = fm10k_get_regs,
1064 .get_regs_len = fm10k_get_regs_len,
1065 .self_test = fm10k_self_test,
1066 .get_rxfh_indir_size = fm10k_get_reta_size,
1067 .get_rxfh_key_size = fm10k_get_rssrk_size,
1068 .get_rxfh = fm10k_get_rssh,
1069 .set_rxfh = fm10k_set_rssh,
1070 .get_channels = fm10k_get_channels,
1071 .set_channels = fm10k_set_channels,
1072 .get_ts_info = fm10k_get_ts_info,
1073 };
1074
1075 void fm10k_set_ethtool_ops(struct net_device *dev)
1076 {
1077 dev->ethtool_ops = &fm10k_ethtool_ops;
1078 }
This page took 0.054527 seconds and 5 git commands to generate.