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