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