2 * Copyright (C) 2015-2017 Netronome Systems, Inc.
4 * This software is dual licensed under the GNU General License Version 2,
5 * June 1991 as shown in the file COPYING in the top-level directory of this
6 * source tree or the BSD 2-Clause License provided below. You have the
7 * option to license this software under the complete terms of either license.
9 * The BSD 2-Clause License:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * 1. Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * 2. Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 * Netronome network device driver: ethtool support
37 * Authors: Jakub Kicinski <jakub.kicinski@netronome.com>
38 * Jason McMullan <jason.mcmullan@netronome.com>
39 * Rolf Neugebauer <rolf.neugebauer@netronome.com>
40 * Brad Petrus <brad.petrus@netronome.com>
43 #include <linux/kernel.h>
44 #include <linux/netdevice.h>
45 #include <linux/etherdevice.h>
46 #include <linux/interrupt.h>
47 #include <linux/pci.h>
48 #include <linux/ethtool.h>
50 #include "nfpcore/nfp.h"
51 #include "nfp_net_ctrl.h"
55 NFP_DUMP_NSP_DIAG = 0,
58 /* Support for stats. Returns netdev, driver, and device stats */
59 enum { NETDEV_ET_STATS, NFP_NET_DRV_ET_STATS, NFP_NET_DEV_ET_STATS };
60 struct _nfp_net_et_stats {
61 char name[ETH_GSTRING_LEN];
67 #define NN_ET_NETDEV_STAT(m) NETDEV_ET_STATS, \
68 FIELD_SIZEOF(struct net_device_stats, m), \
69 offsetof(struct net_device_stats, m)
70 /* For stats in the control BAR (other than Q stats) */
71 #define NN_ET_DEV_STAT(m) NFP_NET_DEV_ET_STATS, \
74 static const struct _nfp_net_et_stats nfp_net_et_stats[] = {
76 {"rx_packets", NN_ET_NETDEV_STAT(rx_packets)},
77 {"tx_packets", NN_ET_NETDEV_STAT(tx_packets)},
78 {"rx_bytes", NN_ET_NETDEV_STAT(rx_bytes)},
79 {"tx_bytes", NN_ET_NETDEV_STAT(tx_bytes)},
80 {"rx_errors", NN_ET_NETDEV_STAT(rx_errors)},
81 {"tx_errors", NN_ET_NETDEV_STAT(tx_errors)},
82 {"rx_dropped", NN_ET_NETDEV_STAT(rx_dropped)},
83 {"tx_dropped", NN_ET_NETDEV_STAT(tx_dropped)},
84 {"multicast", NN_ET_NETDEV_STAT(multicast)},
85 {"collisions", NN_ET_NETDEV_STAT(collisions)},
86 {"rx_over_errors", NN_ET_NETDEV_STAT(rx_over_errors)},
87 {"rx_crc_errors", NN_ET_NETDEV_STAT(rx_crc_errors)},
88 {"rx_frame_errors", NN_ET_NETDEV_STAT(rx_frame_errors)},
89 {"rx_fifo_errors", NN_ET_NETDEV_STAT(rx_fifo_errors)},
90 {"rx_missed_errors", NN_ET_NETDEV_STAT(rx_missed_errors)},
91 {"tx_aborted_errors", NN_ET_NETDEV_STAT(tx_aborted_errors)},
92 {"tx_carrier_errors", NN_ET_NETDEV_STAT(tx_carrier_errors)},
93 {"tx_fifo_errors", NN_ET_NETDEV_STAT(tx_fifo_errors)},
94 /* Stats from the device */
95 {"dev_rx_discards", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_DISCARDS)},
96 {"dev_rx_errors", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_ERRORS)},
97 {"dev_rx_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_OCTETS)},
98 {"dev_rx_uc_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_UC_OCTETS)},
99 {"dev_rx_mc_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_MC_OCTETS)},
100 {"dev_rx_bc_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_BC_OCTETS)},
101 {"dev_rx_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_FRAMES)},
102 {"dev_rx_mc_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_MC_FRAMES)},
103 {"dev_rx_bc_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_RX_BC_FRAMES)},
105 {"dev_tx_discards", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_DISCARDS)},
106 {"dev_tx_errors", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_ERRORS)},
107 {"dev_tx_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_OCTETS)},
108 {"dev_tx_uc_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_UC_OCTETS)},
109 {"dev_tx_mc_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_MC_OCTETS)},
110 {"dev_tx_bc_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_BC_OCTETS)},
111 {"dev_tx_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_FRAMES)},
112 {"dev_tx_mc_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_MC_FRAMES)},
113 {"dev_tx_bc_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_TX_BC_FRAMES)},
115 {"bpf_pass_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP0_FRAMES)},
116 {"bpf_pass_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP0_BYTES)},
117 /* see comments in outro functions in nfp_bpf_jit.c to find out
118 * how different BPF modes use app-specific counters
120 {"bpf_app1_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP1_FRAMES)},
121 {"bpf_app1_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP1_BYTES)},
122 {"bpf_app2_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP2_FRAMES)},
123 {"bpf_app2_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP2_BYTES)},
124 {"bpf_app3_pkts", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP3_FRAMES)},
125 {"bpf_app3_bytes", NN_ET_DEV_STAT(NFP_NET_CFG_STATS_APP3_BYTES)},
128 #define NN_ET_GLOBAL_STATS_LEN ARRAY_SIZE(nfp_net_et_stats)
129 #define NN_ET_RVEC_STATS_LEN (nn->num_r_vecs * 3)
130 #define NN_ET_RVEC_GATHER_STATS 7
131 #define NN_ET_QUEUE_STATS_LEN ((nn->num_tx_rings + nn->num_rx_rings) * 2)
132 #define NN_ET_STATS_LEN (NN_ET_GLOBAL_STATS_LEN + NN_ET_RVEC_GATHER_STATS + \
133 NN_ET_RVEC_STATS_LEN + NN_ET_QUEUE_STATS_LEN)
135 static void nfp_net_get_nspinfo(struct nfp_net *nn, char *version)
142 nsp = nfp_nsp_open(nn->cpp);
146 snprintf(version, ETHTOOL_FWVERS_LEN, "sp:%hu.%hu",
147 nfp_nsp_get_abi_ver_major(nsp),
148 nfp_nsp_get_abi_ver_minor(nsp));
153 static void nfp_net_get_drvinfo(struct net_device *netdev,
154 struct ethtool_drvinfo *drvinfo)
156 char nsp_version[ETHTOOL_FWVERS_LEN] = {};
157 struct nfp_net *nn = netdev_priv(netdev);
159 strlcpy(drvinfo->driver, nn->pdev->driver->name,
160 sizeof(drvinfo->driver));
161 strlcpy(drvinfo->version, nfp_driver_version, sizeof(drvinfo->version));
163 nfp_net_get_nspinfo(nn, nsp_version);
164 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
166 nn->fw_ver.resv, nn->fw_ver.class,
167 nn->fw_ver.major, nn->fw_ver.minor, nsp_version);
168 strlcpy(drvinfo->bus_info, pci_name(nn->pdev),
169 sizeof(drvinfo->bus_info));
171 drvinfo->n_stats = NN_ET_STATS_LEN;
172 drvinfo->regdump_len = NFP_NET_CFG_BAR_SZ;
175 static void nfp_net_get_ringparam(struct net_device *netdev,
176 struct ethtool_ringparam *ring)
178 struct nfp_net *nn = netdev_priv(netdev);
180 ring->rx_max_pending = NFP_NET_MAX_RX_DESCS;
181 ring->tx_max_pending = NFP_NET_MAX_TX_DESCS;
182 ring->rx_pending = nn->rxd_cnt;
183 ring->tx_pending = nn->txd_cnt;
186 static int nfp_net_set_ring_size(struct nfp_net *nn, u32 rxd_cnt, u32 txd_cnt)
188 struct nfp_net_ring_set *reconfig_rx = NULL, *reconfig_tx = NULL;
189 struct nfp_net_ring_set rx = {
190 .n_rings = nn->num_rx_rings,
191 .mtu = nn->netdev->mtu,
194 struct nfp_net_ring_set tx = {
195 .n_rings = nn->num_tx_rings,
199 if (nn->rxd_cnt != rxd_cnt)
201 if (nn->txd_cnt != txd_cnt)
204 return nfp_net_ring_reconfig(nn, &nn->xdp_prog,
205 reconfig_rx, reconfig_tx);
208 static int nfp_net_set_ringparam(struct net_device *netdev,
209 struct ethtool_ringparam *ring)
211 struct nfp_net *nn = netdev_priv(netdev);
212 u32 rxd_cnt, txd_cnt;
214 /* We don't have separate queues/rings for small/large frames. */
215 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
218 /* Round up to supported values */
219 rxd_cnt = roundup_pow_of_two(ring->rx_pending);
220 txd_cnt = roundup_pow_of_two(ring->tx_pending);
222 if (rxd_cnt < NFP_NET_MIN_RX_DESCS || rxd_cnt > NFP_NET_MAX_RX_DESCS ||
223 txd_cnt < NFP_NET_MIN_TX_DESCS || txd_cnt > NFP_NET_MAX_TX_DESCS)
226 if (nn->rxd_cnt == rxd_cnt && nn->txd_cnt == txd_cnt)
229 nn_dbg(nn, "Change ring size: RxQ %u->%u, TxQ %u->%u\n",
230 nn->rxd_cnt, rxd_cnt, nn->txd_cnt, txd_cnt);
232 return nfp_net_set_ring_size(nn, rxd_cnt, txd_cnt);
235 static void nfp_net_get_strings(struct net_device *netdev,
236 u32 stringset, u8 *data)
238 struct nfp_net *nn = netdev_priv(netdev);
244 for (i = 0; i < NN_ET_GLOBAL_STATS_LEN; i++) {
245 memcpy(p, nfp_net_et_stats[i].name, ETH_GSTRING_LEN);
246 p += ETH_GSTRING_LEN;
248 for (i = 0; i < nn->num_r_vecs; i++) {
249 sprintf(p, "rvec_%u_rx_pkts", i);
250 p += ETH_GSTRING_LEN;
251 sprintf(p, "rvec_%u_tx_pkts", i);
252 p += ETH_GSTRING_LEN;
253 sprintf(p, "rvec_%u_tx_busy", i);
254 p += ETH_GSTRING_LEN;
256 strncpy(p, "hw_rx_csum_ok", ETH_GSTRING_LEN);
257 p += ETH_GSTRING_LEN;
258 strncpy(p, "hw_rx_csum_inner_ok", ETH_GSTRING_LEN);
259 p += ETH_GSTRING_LEN;
260 strncpy(p, "hw_rx_csum_err", ETH_GSTRING_LEN);
261 p += ETH_GSTRING_LEN;
262 strncpy(p, "hw_tx_csum", ETH_GSTRING_LEN);
263 p += ETH_GSTRING_LEN;
264 strncpy(p, "hw_tx_inner_csum", ETH_GSTRING_LEN);
265 p += ETH_GSTRING_LEN;
266 strncpy(p, "tx_gather", ETH_GSTRING_LEN);
267 p += ETH_GSTRING_LEN;
268 strncpy(p, "tx_lso", ETH_GSTRING_LEN);
269 p += ETH_GSTRING_LEN;
270 for (i = 0; i < nn->num_tx_rings; i++) {
271 sprintf(p, "txq_%u_pkts", i);
272 p += ETH_GSTRING_LEN;
273 sprintf(p, "txq_%u_bytes", i);
274 p += ETH_GSTRING_LEN;
276 for (i = 0; i < nn->num_rx_rings; i++) {
277 sprintf(p, "rxq_%u_pkts", i);
278 p += ETH_GSTRING_LEN;
279 sprintf(p, "rxq_%u_bytes", i);
280 p += ETH_GSTRING_LEN;
286 static void nfp_net_get_stats(struct net_device *netdev,
287 struct ethtool_stats *stats, u64 *data)
289 u64 gathered_stats[NN_ET_RVEC_GATHER_STATS] = {};
290 struct nfp_net *nn = netdev_priv(netdev);
291 struct rtnl_link_stats64 *netdev_stats;
292 struct rtnl_link_stats64 temp = {};
293 u64 tmp[NN_ET_RVEC_GATHER_STATS];
298 netdev_stats = dev_get_stats(netdev, &temp);
300 for (i = 0; i < NN_ET_GLOBAL_STATS_LEN; i++) {
301 switch (nfp_net_et_stats[i].type) {
302 case NETDEV_ET_STATS:
303 p = (char *)netdev_stats + nfp_net_et_stats[i].off;
304 data[i] = nfp_net_et_stats[i].sz == sizeof(u64) ?
305 *(u64 *)p : *(u32 *)p;
308 case NFP_NET_DEV_ET_STATS:
309 io_p = nn->ctrl_bar + nfp_net_et_stats[i].off;
310 data[i] = readq(io_p);
314 for (j = 0; j < nn->num_r_vecs; j++) {
318 start = u64_stats_fetch_begin(&nn->r_vecs[j].rx_sync);
319 data[i++] = nn->r_vecs[j].rx_pkts;
320 tmp[0] = nn->r_vecs[j].hw_csum_rx_ok;
321 tmp[1] = nn->r_vecs[j].hw_csum_rx_inner_ok;
322 tmp[2] = nn->r_vecs[j].hw_csum_rx_error;
323 } while (u64_stats_fetch_retry(&nn->r_vecs[j].rx_sync, start));
326 start = u64_stats_fetch_begin(&nn->r_vecs[j].tx_sync);
327 data[i++] = nn->r_vecs[j].tx_pkts;
328 data[i++] = nn->r_vecs[j].tx_busy;
329 tmp[3] = nn->r_vecs[j].hw_csum_tx;
330 tmp[4] = nn->r_vecs[j].hw_csum_tx_inner;
331 tmp[5] = nn->r_vecs[j].tx_gather;
332 tmp[6] = nn->r_vecs[j].tx_lso;
333 } while (u64_stats_fetch_retry(&nn->r_vecs[j].tx_sync, start));
335 for (k = 0; k < NN_ET_RVEC_GATHER_STATS; k++)
336 gathered_stats[k] += tmp[k];
338 for (j = 0; j < NN_ET_RVEC_GATHER_STATS; j++)
339 data[i++] = gathered_stats[j];
340 for (j = 0; j < nn->num_tx_rings; j++) {
341 io_p = nn->ctrl_bar + NFP_NET_CFG_TXR_STATS(j);
342 data[i++] = readq(io_p);
343 io_p = nn->ctrl_bar + NFP_NET_CFG_TXR_STATS(j) + 8;
344 data[i++] = readq(io_p);
346 for (j = 0; j < nn->num_rx_rings; j++) {
347 io_p = nn->ctrl_bar + NFP_NET_CFG_RXR_STATS(j);
348 data[i++] = readq(io_p);
349 io_p = nn->ctrl_bar + NFP_NET_CFG_RXR_STATS(j) + 8;
350 data[i++] = readq(io_p);
354 static int nfp_net_get_sset_count(struct net_device *netdev, int sset)
356 struct nfp_net *nn = netdev_priv(netdev);
360 return NN_ET_STATS_LEN;
366 /* RX network flow classification (RSS, filters, etc)
368 static u32 ethtool_flow_to_nfp_flag(u32 flow_type)
370 static const u32 xlate_ethtool_to_nfp[IPV6_FLOW + 1] = {
371 [TCP_V4_FLOW] = NFP_NET_CFG_RSS_IPV4_TCP,
372 [TCP_V6_FLOW] = NFP_NET_CFG_RSS_IPV6_TCP,
373 [UDP_V4_FLOW] = NFP_NET_CFG_RSS_IPV4_UDP,
374 [UDP_V6_FLOW] = NFP_NET_CFG_RSS_IPV6_UDP,
375 [IPV4_FLOW] = NFP_NET_CFG_RSS_IPV4,
376 [IPV6_FLOW] = NFP_NET_CFG_RSS_IPV6,
379 if (flow_type >= ARRAY_SIZE(xlate_ethtool_to_nfp))
382 return xlate_ethtool_to_nfp[flow_type];
385 static int nfp_net_get_rss_hash_opts(struct nfp_net *nn,
386 struct ethtool_rxnfc *cmd)
392 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS))
395 nfp_rss_flag = ethtool_flow_to_nfp_flag(cmd->flow_type);
399 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
400 if (nn->rss_cfg & nfp_rss_flag)
401 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
406 static int nfp_net_get_rxnfc(struct net_device *netdev,
407 struct ethtool_rxnfc *cmd, u32 *rule_locs)
409 struct nfp_net *nn = netdev_priv(netdev);
412 case ETHTOOL_GRXRINGS:
413 cmd->data = nn->num_rx_rings;
416 return nfp_net_get_rss_hash_opts(nn, cmd);
422 static int nfp_net_set_rss_hash_opt(struct nfp_net *nn,
423 struct ethtool_rxnfc *nfc)
425 u32 new_rss_cfg = nn->rss_cfg;
429 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS))
432 /* RSS only supports IP SA/DA and L4 src/dst ports */
433 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
434 RXH_L4_B_0_1 | RXH_L4_B_2_3))
437 /* We need at least the IP SA/DA fields for hashing */
438 if (!(nfc->data & RXH_IP_SRC) ||
439 !(nfc->data & RXH_IP_DST))
442 nfp_rss_flag = ethtool_flow_to_nfp_flag(nfc->flow_type);
446 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
448 new_rss_cfg &= ~nfp_rss_flag;
450 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
451 new_rss_cfg |= nfp_rss_flag;
457 new_rss_cfg |= NFP_NET_CFG_RSS_TOEPLITZ;
458 new_rss_cfg |= NFP_NET_CFG_RSS_MASK;
460 if (new_rss_cfg == nn->rss_cfg)
463 writel(new_rss_cfg, nn->ctrl_bar + NFP_NET_CFG_RSS_CTRL);
464 err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_RSS);
468 nn->rss_cfg = new_rss_cfg;
470 nn_dbg(nn, "Changed RSS config to 0x%x\n", nn->rss_cfg);
474 static int nfp_net_set_rxnfc(struct net_device *netdev,
475 struct ethtool_rxnfc *cmd)
477 struct nfp_net *nn = netdev_priv(netdev);
481 return nfp_net_set_rss_hash_opt(nn, cmd);
487 static u32 nfp_net_get_rxfh_indir_size(struct net_device *netdev)
489 struct nfp_net *nn = netdev_priv(netdev);
491 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS))
494 return ARRAY_SIZE(nn->rss_itbl);
497 static u32 nfp_net_get_rxfh_key_size(struct net_device *netdev)
499 return NFP_NET_CFG_RSS_KEY_SZ;
502 static int nfp_net_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
505 struct nfp_net *nn = netdev_priv(netdev);
508 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS))
512 for (i = 0; i < ARRAY_SIZE(nn->rss_itbl); i++)
513 indir[i] = nn->rss_itbl[i];
515 memcpy(key, nn->rss_key, NFP_NET_CFG_RSS_KEY_SZ);
517 *hfunc = ETH_RSS_HASH_TOP;
522 static int nfp_net_set_rxfh(struct net_device *netdev,
523 const u32 *indir, const u8 *key,
526 struct nfp_net *nn = netdev_priv(netdev);
529 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS) ||
530 !(hfunc == ETH_RSS_HASH_NO_CHANGE || hfunc == ETH_RSS_HASH_TOP))
537 memcpy(nn->rss_key, key, NFP_NET_CFG_RSS_KEY_SZ);
538 nfp_net_rss_write_key(nn);
541 for (i = 0; i < ARRAY_SIZE(nn->rss_itbl); i++)
542 nn->rss_itbl[i] = indir[i];
544 nfp_net_rss_write_itbl(nn);
547 return nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_RSS);
550 /* Dump BAR registers
552 static int nfp_net_get_regs_len(struct net_device *netdev)
554 return NFP_NET_CFG_BAR_SZ;
557 static void nfp_net_get_regs(struct net_device *netdev,
558 struct ethtool_regs *regs, void *p)
560 struct nfp_net *nn = netdev_priv(netdev);
564 regs->version = nn_readl(nn, NFP_NET_CFG_VERSION);
566 for (i = 0; i < NFP_NET_CFG_BAR_SZ / sizeof(u32); i++)
567 regs_buf[i] = readl(nn->ctrl_bar + (i * sizeof(u32)));
570 static int nfp_net_get_coalesce(struct net_device *netdev,
571 struct ethtool_coalesce *ec)
573 struct nfp_net *nn = netdev_priv(netdev);
575 if (!(nn->cap & NFP_NET_CFG_CTRL_IRQMOD))
578 ec->rx_coalesce_usecs = nn->rx_coalesce_usecs;
579 ec->rx_max_coalesced_frames = nn->rx_coalesce_max_frames;
580 ec->tx_coalesce_usecs = nn->tx_coalesce_usecs;
581 ec->tx_max_coalesced_frames = nn->tx_coalesce_max_frames;
589 nfp_dump_nsp_diag(struct nfp_net *nn, struct ethtool_dump *dump, void *buffer)
591 struct nfp_resource *res;
598 dump->flag = NFP_DUMP_NSP_DIAG;
600 res = nfp_resource_acquire(nn->cpp, NFP_RESOURCE_NSP_DIAG);
605 if (dump->len != nfp_resource_size(res)) {
610 ret = nfp_cpp_read(nn->cpp, nfp_resource_cpp_id(res),
611 nfp_resource_address(res),
613 if (ret != dump->len)
614 ret = ret < 0 ? ret : -EIO;
618 dump->len = nfp_resource_size(res);
622 nfp_resource_release(res);
627 static int nfp_net_set_dump(struct net_device *netdev, struct ethtool_dump *val)
629 struct nfp_net *nn = netdev_priv(netdev);
634 if (val->flag != NFP_DUMP_NSP_DIAG)
637 nn->ethtool_dump_flag = val->flag;
643 nfp_net_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
645 return nfp_dump_nsp_diag(netdev_priv(netdev), dump, NULL);
649 nfp_net_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
652 return nfp_dump_nsp_diag(netdev_priv(netdev), dump, buffer);
655 static int nfp_net_set_coalesce(struct net_device *netdev,
656 struct ethtool_coalesce *ec)
658 struct nfp_net *nn = netdev_priv(netdev);
661 if (ec->rx_coalesce_usecs_irq ||
662 ec->rx_max_coalesced_frames_irq ||
663 ec->tx_coalesce_usecs_irq ||
664 ec->tx_max_coalesced_frames_irq ||
665 ec->stats_block_coalesce_usecs ||
666 ec->use_adaptive_rx_coalesce ||
667 ec->use_adaptive_tx_coalesce ||
669 ec->rx_coalesce_usecs_low ||
670 ec->rx_max_coalesced_frames_low ||
671 ec->tx_coalesce_usecs_low ||
672 ec->tx_max_coalesced_frames_low ||
674 ec->rx_coalesce_usecs_high ||
675 ec->rx_max_coalesced_frames_high ||
676 ec->tx_coalesce_usecs_high ||
677 ec->tx_max_coalesced_frames_high ||
678 ec->rate_sample_interval)
681 /* Compute factor used to convert coalesce '_usecs' parameters to
682 * ME timestamp ticks. There are 16 ME clock cycles for each timestamp
685 factor = nn->me_freq_mhz / 16;
687 /* Each pair of (usecs, max_frames) fields specifies that interrupts
688 * should be coalesced until
689 * (usecs > 0 && time_since_first_completion >= usecs) ||
690 * (max_frames > 0 && completed_frames >= max_frames)
692 * It is illegal to set both usecs and max_frames to zero as this would
693 * cause interrupts to never be generated. To disable coalescing, set
694 * usecs = 0 and max_frames = 1.
696 * Some implementations ignore the value of max_frames and use the
697 * condition time_since_first_completion >= usecs
700 if (!(nn->cap & NFP_NET_CFG_CTRL_IRQMOD))
703 /* ensure valid configuration */
704 if (!ec->rx_coalesce_usecs && !ec->rx_max_coalesced_frames)
707 if (!ec->tx_coalesce_usecs && !ec->tx_max_coalesced_frames)
710 if (ec->rx_coalesce_usecs * factor >= ((1 << 16) - 1))
713 if (ec->tx_coalesce_usecs * factor >= ((1 << 16) - 1))
716 if (ec->rx_max_coalesced_frames >= ((1 << 16) - 1))
719 if (ec->tx_max_coalesced_frames >= ((1 << 16) - 1))
722 /* configuration is valid */
723 nn->rx_coalesce_usecs = ec->rx_coalesce_usecs;
724 nn->rx_coalesce_max_frames = ec->rx_max_coalesced_frames;
725 nn->tx_coalesce_usecs = ec->tx_coalesce_usecs;
726 nn->tx_coalesce_max_frames = ec->tx_max_coalesced_frames;
728 /* write configuration to device */
729 nfp_net_coalesce_write_cfg(nn);
730 return nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_IRQMOD);
733 static void nfp_net_get_channels(struct net_device *netdev,
734 struct ethtool_channels *channel)
736 struct nfp_net *nn = netdev_priv(netdev);
737 unsigned int num_tx_rings;
739 num_tx_rings = nn->num_tx_rings;
741 num_tx_rings -= nn->num_rx_rings;
743 channel->max_rx = min(nn->max_rx_rings, nn->max_r_vecs);
744 channel->max_tx = min(nn->max_tx_rings, nn->max_r_vecs);
745 channel->max_combined = min(channel->max_rx, channel->max_tx);
746 channel->max_other = NFP_NET_NON_Q_VECTORS;
747 channel->combined_count = min(nn->num_rx_rings, num_tx_rings);
748 channel->rx_count = nn->num_rx_rings - channel->combined_count;
749 channel->tx_count = num_tx_rings - channel->combined_count;
750 channel->other_count = NFP_NET_NON_Q_VECTORS;
753 static int nfp_net_set_num_rings(struct nfp_net *nn, unsigned int total_rx,
754 unsigned int total_tx)
756 struct nfp_net_ring_set *reconfig_rx = NULL, *reconfig_tx = NULL;
757 struct nfp_net_ring_set rx = {
759 .mtu = nn->netdev->mtu,
762 struct nfp_net_ring_set tx = {
767 if (nn->num_rx_rings != total_rx)
769 if (nn->num_stack_tx_rings != total_tx ||
770 (nn->xdp_prog && reconfig_rx))
773 /* nfp_net_check_config() will catch tx.n_rings > nn->max_tx_rings */
775 tx.n_rings += total_rx;
777 return nfp_net_ring_reconfig(nn, &nn->xdp_prog,
778 reconfig_rx, reconfig_tx);
781 static int nfp_net_set_channels(struct net_device *netdev,
782 struct ethtool_channels *channel)
784 struct nfp_net *nn = netdev_priv(netdev);
785 unsigned int total_rx, total_tx;
787 /* Reject unsupported */
788 if (!channel->combined_count ||
789 channel->other_count != NFP_NET_NON_Q_VECTORS ||
790 (channel->rx_count && channel->tx_count))
793 total_rx = channel->combined_count + channel->rx_count;
794 total_tx = channel->combined_count + channel->tx_count;
796 if (total_rx > min(nn->max_rx_rings, nn->max_r_vecs) ||
797 total_tx > min(nn->max_tx_rings, nn->max_r_vecs))
800 return nfp_net_set_num_rings(nn, total_rx, total_tx);
803 static const struct ethtool_ops nfp_net_ethtool_ops = {
804 .get_drvinfo = nfp_net_get_drvinfo,
805 .get_link = ethtool_op_get_link,
806 .get_ringparam = nfp_net_get_ringparam,
807 .set_ringparam = nfp_net_set_ringparam,
808 .get_strings = nfp_net_get_strings,
809 .get_ethtool_stats = nfp_net_get_stats,
810 .get_sset_count = nfp_net_get_sset_count,
811 .get_rxnfc = nfp_net_get_rxnfc,
812 .set_rxnfc = nfp_net_set_rxnfc,
813 .get_rxfh_indir_size = nfp_net_get_rxfh_indir_size,
814 .get_rxfh_key_size = nfp_net_get_rxfh_key_size,
815 .get_rxfh = nfp_net_get_rxfh,
816 .set_rxfh = nfp_net_set_rxfh,
817 .get_regs_len = nfp_net_get_regs_len,
818 .get_regs = nfp_net_get_regs,
819 .set_dump = nfp_net_set_dump,
820 .get_dump_flag = nfp_net_get_dump_flag,
821 .get_dump_data = nfp_net_get_dump_data,
822 .get_coalesce = nfp_net_get_coalesce,
823 .set_coalesce = nfp_net_set_coalesce,
824 .get_channels = nfp_net_get_channels,
825 .set_channels = nfp_net_set_channels,
828 void nfp_net_set_ethtool_ops(struct net_device *netdev)
830 netdev->ethtool_ops = &nfp_net_ethtool_ops;