1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2 /* Copyright (C) 2015-2018 Netronome Systems, Inc. */
3
4 /*
5 * nfp_net_ethtool.c
6 * Netronome network device driver: ethtool support
7 * Authors: Jakub Kicinski <jakub.kicinski@netronome.com>
8 * Jason McMullan <jason.mcmullan@netronome.com>
9 * Rolf Neugebauer <rolf.neugebauer@netronome.com>
10 * Brad Petrus <brad.petrus@netronome.com>
11 */
12
13 #include <linux/bitfield.h>
14 #include <linux/kernel.h>
15 #include <linux/netdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/interrupt.h>
18 #include <linux/pci.h>
19 #include <linux/ethtool.h>
20 #include <linux/firmware.h>
21 #include <linux/sfp.h>
22
23 #include "nfpcore/nfp.h"
24 #include "nfpcore/nfp_dev.h"
25 #include "nfpcore/nfp_nsp.h"
26 #include "nfp_app.h"
27 #include "nfp_main.h"
28 #include "nfp_net_ctrl.h"
29 #include "nfp_net_dp.h"
30 #include "nfp_net.h"
31 #include "nfp_port.h"
32 #include "nfpcore/nfp_cpp.h"
33
34 struct nfp_et_stat {
35 char name[ETH_GSTRING_LEN];
36 int off;
37 };
38
39 static const struct nfp_et_stat nfp_net_et_stats[] = {
40 /* Stats from the device */
41 { "dev_rx_discards", NFP_NET_CFG_STATS_RX_DISCARDS },
42 { "dev_rx_errors", NFP_NET_CFG_STATS_RX_ERRORS },
43 { "dev_rx_bytes", NFP_NET_CFG_STATS_RX_OCTETS },
44 { "dev_rx_uc_bytes", NFP_NET_CFG_STATS_RX_UC_OCTETS },
45 { "dev_rx_mc_bytes", NFP_NET_CFG_STATS_RX_MC_OCTETS },
46 { "dev_rx_bc_bytes", NFP_NET_CFG_STATS_RX_BC_OCTETS },
47 { "dev_rx_pkts", NFP_NET_CFG_STATS_RX_FRAMES },
48 { "dev_rx_mc_pkts", NFP_NET_CFG_STATS_RX_MC_FRAMES },
49 { "dev_rx_bc_pkts", NFP_NET_CFG_STATS_RX_BC_FRAMES },
50
51 { "dev_tx_discards", NFP_NET_CFG_STATS_TX_DISCARDS },
52 { "dev_tx_errors", NFP_NET_CFG_STATS_TX_ERRORS },
53 { "dev_tx_bytes", NFP_NET_CFG_STATS_TX_OCTETS },
54 { "dev_tx_uc_bytes", NFP_NET_CFG_STATS_TX_UC_OCTETS },
55 { "dev_tx_mc_bytes", NFP_NET_CFG_STATS_TX_MC_OCTETS },
56 { "dev_tx_bc_bytes", NFP_NET_CFG_STATS_TX_BC_OCTETS },
57 { "dev_tx_pkts", NFP_NET_CFG_STATS_TX_FRAMES },
58 { "dev_tx_mc_pkts", NFP_NET_CFG_STATS_TX_MC_FRAMES },
59 { "dev_tx_bc_pkts", NFP_NET_CFG_STATS_TX_BC_FRAMES },
60
61 { "bpf_pass_pkts", NFP_NET_CFG_STATS_APP0_FRAMES },
62 { "bpf_pass_bytes", NFP_NET_CFG_STATS_APP0_BYTES },
63 /* see comments in outro functions in nfp_bpf_jit.c to find out
64 * how different BPF modes use app-specific counters
65 */
66 { "bpf_app1_pkts", NFP_NET_CFG_STATS_APP1_FRAMES },
67 { "bpf_app1_bytes", NFP_NET_CFG_STATS_APP1_BYTES },
68 { "bpf_app2_pkts", NFP_NET_CFG_STATS_APP2_FRAMES },
69 { "bpf_app2_bytes", NFP_NET_CFG_STATS_APP2_BYTES },
70 { "bpf_app3_pkts", NFP_NET_CFG_STATS_APP3_FRAMES },
71 { "bpf_app3_bytes", NFP_NET_CFG_STATS_APP3_BYTES },
72 };
73
74 static const struct nfp_et_stat nfp_mac_et_stats[] = {
75 { "rx_octets", NFP_MAC_STATS_RX_IN_OCTETS, },
76 { "rx_frame_too_long_errors",
77 NFP_MAC_STATS_RX_FRAME_TOO_LONG_ERRORS, },
78 { "rx_range_length_errors", NFP_MAC_STATS_RX_RANGE_LENGTH_ERRORS, },
79 { "rx_vlan_received_ok", NFP_MAC_STATS_RX_VLAN_RECEIVED_OK, },
80 { "rx_errors", NFP_MAC_STATS_RX_IN_ERRORS, },
81 { "rx_broadcast_pkts", NFP_MAC_STATS_RX_IN_BROADCAST_PKTS, },
82 { "rx_drop_events", NFP_MAC_STATS_RX_DROP_EVENTS, },
83 { "rx_alignment_errors", NFP_MAC_STATS_RX_ALIGNMENT_ERRORS, },
84 { "rx_pause_mac_ctrl_frames",
85 NFP_MAC_STATS_RX_PAUSE_MAC_CTRL_FRAMES, },
86 { "rx_frames_received_ok", NFP_MAC_STATS_RX_FRAMES_RECEIVED_OK, },
87 { "rx_frame_check_sequence_errors",
88 NFP_MAC_STATS_RX_FRAME_CHECK_SEQUENCE_ERRORS, },
89 { "rx_unicast_pkts", NFP_MAC_STATS_RX_UNICAST_PKTS, },
90 { "rx_multicast_pkts", NFP_MAC_STATS_RX_MULTICAST_PKTS, },
91 { "rx_pkts", NFP_MAC_STATS_RX_PKTS, },
92 { "rx_undersize_pkts", NFP_MAC_STATS_RX_UNDERSIZE_PKTS, },
93 { "rx_pkts_64_octets", NFP_MAC_STATS_RX_PKTS_64_OCTETS, },
94 { "rx_pkts_65_to_127_octets",
95 NFP_MAC_STATS_RX_PKTS_65_TO_127_OCTETS, },
96 { "rx_pkts_128_to_255_octets",
97 NFP_MAC_STATS_RX_PKTS_128_TO_255_OCTETS, },
98 { "rx_pkts_256_to_511_octets",
99 NFP_MAC_STATS_RX_PKTS_256_TO_511_OCTETS, },
100 { "rx_pkts_512_to_1023_octets",
101 NFP_MAC_STATS_RX_PKTS_512_TO_1023_OCTETS, },
102 { "rx_pkts_1024_to_1518_octets",
103 NFP_MAC_STATS_RX_PKTS_1024_TO_1518_OCTETS, },
104 { "rx_pkts_1519_to_max_octets",
105 NFP_MAC_STATS_RX_PKTS_1519_TO_MAX_OCTETS, },
106 { "rx_jabbers", NFP_MAC_STATS_RX_JABBERS, },
107 { "rx_fragments", NFP_MAC_STATS_RX_FRAGMENTS, },
108 { "rx_oversize_pkts", NFP_MAC_STATS_RX_OVERSIZE_PKTS, },
109 { "rx_pause_frames_class0", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS0, },
110 { "rx_pause_frames_class1", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS1, },
111 { "rx_pause_frames_class2", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS2, },
112 { "rx_pause_frames_class3", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS3, },
113 { "rx_pause_frames_class4", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS4, },
114 { "rx_pause_frames_class5", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS5, },
115 { "rx_pause_frames_class6", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS6, },
116 { "rx_pause_frames_class7", NFP_MAC_STATS_RX_PAUSE_FRAMES_CLASS7, },
117 { "rx_mac_ctrl_frames_received",
118 NFP_MAC_STATS_RX_MAC_CTRL_FRAMES_RECEIVED, },
119 { "rx_mac_head_drop", NFP_MAC_STATS_RX_MAC_HEAD_DROP, },
120 { "tx_queue_drop", NFP_MAC_STATS_TX_QUEUE_DROP, },
121 { "tx_octets", NFP_MAC_STATS_TX_OUT_OCTETS, },
122 { "tx_vlan_transmitted_ok", NFP_MAC_STATS_TX_VLAN_TRANSMITTED_OK, },
123 { "tx_errors", NFP_MAC_STATS_TX_OUT_ERRORS, },
124 { "tx_broadcast_pkts", NFP_MAC_STATS_TX_BROADCAST_PKTS, },
125 { "tx_pause_mac_ctrl_frames",
126 NFP_MAC_STATS_TX_PAUSE_MAC_CTRL_FRAMES, },
127 { "tx_frames_transmitted_ok",
128 NFP_MAC_STATS_TX_FRAMES_TRANSMITTED_OK, },
129 { "tx_unicast_pkts", NFP_MAC_STATS_TX_UNICAST_PKTS, },
130 { "tx_multicast_pkts", NFP_MAC_STATS_TX_MULTICAST_PKTS, },
131 { "tx_pkts_64_octets", NFP_MAC_STATS_TX_PKTS_64_OCTETS, },
132 { "tx_pkts_65_to_127_octets",
133 NFP_MAC_STATS_TX_PKTS_65_TO_127_OCTETS, },
134 { "tx_pkts_128_to_255_octets",
135 NFP_MAC_STATS_TX_PKTS_128_TO_255_OCTETS, },
136 { "tx_pkts_256_to_511_octets",
137 NFP_MAC_STATS_TX_PKTS_256_TO_511_OCTETS, },
138 { "tx_pkts_512_to_1023_octets",
139 NFP_MAC_STATS_TX_PKTS_512_TO_1023_OCTETS, },
140 { "tx_pkts_1024_to_1518_octets",
141 NFP_MAC_STATS_TX_PKTS_1024_TO_1518_OCTETS, },
142 { "tx_pkts_1519_to_max_octets",
143 NFP_MAC_STATS_TX_PKTS_1519_TO_MAX_OCTETS, },
144 { "tx_pause_frames_class0", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS0, },
145 { "tx_pause_frames_class1", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS1, },
146 { "tx_pause_frames_class2", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS2, },
147 { "tx_pause_frames_class3", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS3, },
148 { "tx_pause_frames_class4", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS4, },
149 { "tx_pause_frames_class5", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS5, },
150 { "tx_pause_frames_class6", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS6, },
151 { "tx_pause_frames_class7", NFP_MAC_STATS_TX_PAUSE_FRAMES_CLASS7, },
152 };
153
154 static const char nfp_tlv_stat_names[][ETH_GSTRING_LEN] = {
155 [1] = "dev_rx_discards",
156 [2] = "dev_rx_errors",
157 [3] = "dev_rx_bytes",
158 [4] = "dev_rx_uc_bytes",
159 [5] = "dev_rx_mc_bytes",
160 [6] = "dev_rx_bc_bytes",
161 [7] = "dev_rx_pkts",
162 [8] = "dev_rx_mc_pkts",
163 [9] = "dev_rx_bc_pkts",
164
165 [10] = "dev_tx_discards",
166 [11] = "dev_tx_errors",
167 [12] = "dev_tx_bytes",
168 [13] = "dev_tx_uc_bytes",
169 [14] = "dev_tx_mc_bytes",
170 [15] = "dev_tx_bc_bytes",
171 [16] = "dev_tx_pkts",
172 [17] = "dev_tx_mc_pkts",
173 [18] = "dev_tx_bc_pkts",
174 };
175
176 #define NN_ET_GLOBAL_STATS_LEN ARRAY_SIZE(nfp_net_et_stats)
177 #define NN_ET_SWITCH_STATS_LEN 9
178 #define NN_RVEC_GATHER_STATS 13
179 #define NN_RVEC_PER_Q_STATS 3
180 #define NN_CTRL_PATH_STATS 4
181
182 #define SFP_SFF_REV_COMPLIANCE 1
183
nfp_net_get_nspinfo(struct nfp_app * app,char * version)184 static void nfp_net_get_nspinfo(struct nfp_app *app, char *version)
185 {
186 struct nfp_nsp *nsp;
187
188 if (!app)
189 return;
190
191 nsp = nfp_nsp_open(app->cpp);
192 if (IS_ERR(nsp))
193 return;
194
195 snprintf(version, ETHTOOL_FWVERS_LEN, "%hu.%hu",
196 nfp_nsp_get_abi_ver_major(nsp),
197 nfp_nsp_get_abi_ver_minor(nsp));
198
199 nfp_nsp_close(nsp);
200 }
201
202 static void
nfp_get_drvinfo(struct nfp_app * app,struct pci_dev * pdev,const char * vnic_version,struct ethtool_drvinfo * drvinfo)203 nfp_get_drvinfo(struct nfp_app *app, struct pci_dev *pdev,
204 const char *vnic_version, struct ethtool_drvinfo *drvinfo)
205 {
206 char nsp_version[ETHTOOL_FWVERS_LEN] = {};
207
208 strscpy(drvinfo->driver, dev_driver_string(&pdev->dev),
209 sizeof(drvinfo->driver));
210 nfp_net_get_nspinfo(app, nsp_version);
211 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
212 "%s %s %s %s", vnic_version, nsp_version,
213 nfp_app_mip_name(app), nfp_app_name(app));
214 }
215
216 static void
nfp_net_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * drvinfo)217 nfp_net_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
218 {
219 char vnic_version[ETHTOOL_FWVERS_LEN] = {};
220 struct nfp_net *nn = netdev_priv(netdev);
221
222 snprintf(vnic_version, sizeof(vnic_version), "%d.%d.%d.%d",
223 nn->fw_ver.extend, nn->fw_ver.class,
224 nn->fw_ver.major, nn->fw_ver.minor);
225 strscpy(drvinfo->bus_info, pci_name(nn->pdev),
226 sizeof(drvinfo->bus_info));
227
228 nfp_get_drvinfo(nn->app, nn->pdev, vnic_version, drvinfo);
229 }
230
231 static int
nfp_net_nway_reset(struct net_device * netdev)232 nfp_net_nway_reset(struct net_device *netdev)
233 {
234 struct nfp_eth_table_port *eth_port;
235 struct nfp_port *port;
236 int err;
237
238 port = nfp_port_from_netdev(netdev);
239 eth_port = nfp_port_get_eth_port(port);
240 if (!eth_port)
241 return -EOPNOTSUPP;
242
243 if (!netif_running(netdev))
244 return 0;
245
246 err = nfp_eth_set_configured(port->app->cpp, eth_port->index, false);
247 if (err) {
248 netdev_info(netdev, "Link down failed: %d\n", err);
249 return err;
250 }
251
252 err = nfp_eth_set_configured(port->app->cpp, eth_port->index, true);
253 if (err) {
254 netdev_info(netdev, "Link up failed: %d\n", err);
255 return err;
256 }
257
258 netdev_info(netdev, "Link reset succeeded\n");
259 return 0;
260 }
261
262 static void
nfp_app_get_drvinfo(struct net_device * netdev,struct ethtool_drvinfo * drvinfo)263 nfp_app_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo)
264 {
265 struct nfp_app *app = nfp_app_from_netdev(netdev);
266
267 strscpy(drvinfo->bus_info, pci_name(app->pdev),
268 sizeof(drvinfo->bus_info));
269 nfp_get_drvinfo(app, app->pdev, "*", drvinfo);
270 }
271
272 static void
nfp_net_set_fec_link_mode(struct nfp_eth_table_port * eth_port,struct ethtool_link_ksettings * c)273 nfp_net_set_fec_link_mode(struct nfp_eth_table_port *eth_port,
274 struct ethtool_link_ksettings *c)
275 {
276 unsigned int modes;
277
278 ethtool_link_ksettings_add_link_mode(c, supported, FEC_NONE);
279 if (!nfp_eth_can_support_fec(eth_port)) {
280 ethtool_link_ksettings_add_link_mode(c, advertising, FEC_NONE);
281 return;
282 }
283
284 modes = nfp_eth_supported_fec_modes(eth_port);
285 if (modes & NFP_FEC_BASER) {
286 ethtool_link_ksettings_add_link_mode(c, supported, FEC_BASER);
287 ethtool_link_ksettings_add_link_mode(c, advertising, FEC_BASER);
288 }
289
290 if (modes & NFP_FEC_REED_SOLOMON) {
291 ethtool_link_ksettings_add_link_mode(c, supported, FEC_RS);
292 ethtool_link_ksettings_add_link_mode(c, advertising, FEC_RS);
293 }
294 }
295
296 static const struct nfp_eth_media_link_mode {
297 u16 ethtool_link_mode;
298 u16 speed;
299 } nfp_eth_media_table[NFP_MEDIA_LINK_MODES_NUMBER] = {
300 [NFP_MEDIA_1000BASE_CX] = {
301 .ethtool_link_mode = ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
302 .speed = NFP_SPEED_1G,
303 },
304 [NFP_MEDIA_1000BASE_KX] = {
305 .ethtool_link_mode = ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
306 .speed = NFP_SPEED_1G,
307 },
308 [NFP_MEDIA_10GBASE_KX4] = {
309 .ethtool_link_mode = ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
310 .speed = NFP_SPEED_10G,
311 },
312 [NFP_MEDIA_10GBASE_KR] = {
313 .ethtool_link_mode = ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
314 .speed = NFP_SPEED_10G,
315 },
316 [NFP_MEDIA_10GBASE_LR] = {
317 .ethtool_link_mode = ETHTOOL_LINK_MODE_10000baseLR_Full_BIT,
318 .speed = NFP_SPEED_10G,
319 },
320 [NFP_MEDIA_10GBASE_CX4] = {
321 .ethtool_link_mode = ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
322 .speed = NFP_SPEED_10G,
323 },
324 [NFP_MEDIA_10GBASE_CR] = {
325 .ethtool_link_mode = ETHTOOL_LINK_MODE_10000baseCR_Full_BIT,
326 .speed = NFP_SPEED_10G,
327 },
328 [NFP_MEDIA_10GBASE_SR] = {
329 .ethtool_link_mode = ETHTOOL_LINK_MODE_10000baseSR_Full_BIT,
330 .speed = NFP_SPEED_10G,
331 },
332 [NFP_MEDIA_10GBASE_ER] = {
333 .ethtool_link_mode = ETHTOOL_LINK_MODE_10000baseER_Full_BIT,
334 .speed = NFP_SPEED_10G,
335 },
336 [NFP_MEDIA_25GBASE_KR] = {
337 .ethtool_link_mode = ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
338 .speed = NFP_SPEED_25G,
339 },
340 [NFP_MEDIA_25GBASE_KR_S] = {
341 .ethtool_link_mode = ETHTOOL_LINK_MODE_25000baseKR_Full_BIT,
342 .speed = NFP_SPEED_25G,
343 },
344 [NFP_MEDIA_25GBASE_CR] = {
345 .ethtool_link_mode = ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
346 .speed = NFP_SPEED_25G,
347 },
348 [NFP_MEDIA_25GBASE_CR_S] = {
349 .ethtool_link_mode = ETHTOOL_LINK_MODE_25000baseCR_Full_BIT,
350 .speed = NFP_SPEED_25G,
351 },
352 [NFP_MEDIA_25GBASE_SR] = {
353 .ethtool_link_mode = ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
354 .speed = NFP_SPEED_25G,
355 },
356 [NFP_MEDIA_25GBASE_LR] = {
357 .ethtool_link_mode = ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
358 .speed = NFP_SPEED_25G,
359 },
360 [NFP_MEDIA_25GBASE_ER] = {
361 .ethtool_link_mode = ETHTOOL_LINK_MODE_25000baseSR_Full_BIT,
362 .speed = NFP_SPEED_25G,
363 },
364 [NFP_MEDIA_40GBASE_CR4] = {
365 .ethtool_link_mode = ETHTOOL_LINK_MODE_40000baseCR4_Full_BIT,
366 .speed = NFP_SPEED_40G,
367 },
368 [NFP_MEDIA_40GBASE_KR4] = {
369 .ethtool_link_mode = ETHTOOL_LINK_MODE_40000baseKR4_Full_BIT,
370 .speed = NFP_SPEED_40G,
371 },
372 [NFP_MEDIA_40GBASE_SR4] = {
373 .ethtool_link_mode = ETHTOOL_LINK_MODE_40000baseSR4_Full_BIT,
374 .speed = NFP_SPEED_40G,
375 },
376 [NFP_MEDIA_40GBASE_LR4] = {
377 .ethtool_link_mode = ETHTOOL_LINK_MODE_40000baseLR4_Full_BIT,
378 .speed = NFP_SPEED_40G,
379 },
380 [NFP_MEDIA_50GBASE_KR] = {
381 .ethtool_link_mode = ETHTOOL_LINK_MODE_50000baseKR_Full_BIT,
382 .speed = NFP_SPEED_50G,
383 },
384 [NFP_MEDIA_50GBASE_SR] = {
385 .ethtool_link_mode = ETHTOOL_LINK_MODE_50000baseSR_Full_BIT,
386 .speed = NFP_SPEED_50G,
387 },
388 [NFP_MEDIA_50GBASE_CR] = {
389 .ethtool_link_mode = ETHTOOL_LINK_MODE_50000baseCR_Full_BIT,
390 .speed = NFP_SPEED_50G,
391 },
392 [NFP_MEDIA_50GBASE_LR] = {
393 .ethtool_link_mode = ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
394 .speed = NFP_SPEED_50G,
395 },
396 [NFP_MEDIA_50GBASE_ER] = {
397 .ethtool_link_mode = ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
398 .speed = NFP_SPEED_50G,
399 },
400 [NFP_MEDIA_50GBASE_FR] = {
401 .ethtool_link_mode = ETHTOOL_LINK_MODE_50000baseLR_ER_FR_Full_BIT,
402 .speed = NFP_SPEED_50G,
403 },
404 [NFP_MEDIA_100GBASE_KR4] = {
405 .ethtool_link_mode = ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
406 .speed = NFP_SPEED_100G,
407 },
408 [NFP_MEDIA_100GBASE_SR4] = {
409 .ethtool_link_mode = ETHTOOL_LINK_MODE_100000baseSR4_Full_BIT,
410 .speed = NFP_SPEED_100G,
411 },
412 [NFP_MEDIA_100GBASE_CR4] = {
413 .ethtool_link_mode = ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
414 .speed = NFP_SPEED_100G,
415 },
416 [NFP_MEDIA_100GBASE_KP4] = {
417 .ethtool_link_mode = ETHTOOL_LINK_MODE_100000baseKR4_Full_BIT,
418 .speed = NFP_SPEED_100G,
419 },
420 [NFP_MEDIA_100GBASE_CR10] = {
421 .ethtool_link_mode = ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT,
422 .speed = NFP_SPEED_100G,
423 },
424 };
425
426 static const unsigned int nfp_eth_speed_map[NFP_SUP_SPEED_NUMBER] = {
427 [NFP_SPEED_1G] = SPEED_1000,
428 [NFP_SPEED_10G] = SPEED_10000,
429 [NFP_SPEED_25G] = SPEED_25000,
430 [NFP_SPEED_40G] = SPEED_40000,
431 [NFP_SPEED_50G] = SPEED_50000,
432 [NFP_SPEED_100G] = SPEED_100000,
433 };
434
nfp_add_media_link_mode(struct nfp_port * port,struct nfp_eth_table_port * eth_port,struct ethtool_link_ksettings * cmd)435 static void nfp_add_media_link_mode(struct nfp_port *port,
436 struct nfp_eth_table_port *eth_port,
437 struct ethtool_link_ksettings *cmd)
438 {
439 u64 supported_modes[2], advertised_modes[2];
440 struct nfp_eth_media_buf ethm = {
441 .eth_index = eth_port->eth_index,
442 };
443 struct nfp_cpp *cpp = port->app->cpp;
444
445 if (nfp_eth_read_media(cpp, ðm)) {
446 bitmap_fill(port->speed_bitmap, NFP_SUP_SPEED_NUMBER);
447 return;
448 }
449
450 bitmap_zero(port->speed_bitmap, NFP_SUP_SPEED_NUMBER);
451
452 for (u32 i = 0; i < 2; i++) {
453 supported_modes[i] = le64_to_cpu(ethm.supported_modes[i]);
454 advertised_modes[i] = le64_to_cpu(ethm.advertised_modes[i]);
455 }
456
457 for (u32 i = 0; i < NFP_MEDIA_LINK_MODES_NUMBER; i++) {
458 if (i < 64) {
459 if (supported_modes[0] & BIT_ULL(i)) {
460 __set_bit(nfp_eth_media_table[i].ethtool_link_mode,
461 cmd->link_modes.supported);
462 __set_bit(nfp_eth_media_table[i].speed,
463 port->speed_bitmap);
464 }
465
466 if (advertised_modes[0] & BIT_ULL(i))
467 __set_bit(nfp_eth_media_table[i].ethtool_link_mode,
468 cmd->link_modes.advertising);
469 } else {
470 if (supported_modes[1] & BIT_ULL(i - 64)) {
471 __set_bit(nfp_eth_media_table[i].ethtool_link_mode,
472 cmd->link_modes.supported);
473 __set_bit(nfp_eth_media_table[i].speed,
474 port->speed_bitmap);
475 }
476
477 if (advertised_modes[1] & BIT_ULL(i - 64))
478 __set_bit(nfp_eth_media_table[i].ethtool_link_mode,
479 cmd->link_modes.advertising);
480 }
481 }
482 }
483
484 /**
485 * nfp_net_get_link_ksettings - Get Link Speed settings
486 * @netdev: network interface device structure
487 * @cmd: ethtool command
488 *
489 * Reports speed settings based on info in the BAR provided by the fw.
490 */
491 static int
nfp_net_get_link_ksettings(struct net_device * netdev,struct ethtool_link_ksettings * cmd)492 nfp_net_get_link_ksettings(struct net_device *netdev,
493 struct ethtool_link_ksettings *cmd)
494 {
495 struct nfp_eth_table_port *eth_port;
496 struct nfp_port *port;
497 struct nfp_net *nn;
498 unsigned int speed;
499 u16 sts;
500
501 /* Init to unknowns */
502 ethtool_link_ksettings_zero_link_mode(cmd, supported);
503 ethtool_link_ksettings_zero_link_mode(cmd, advertising);
504 ethtool_link_ksettings_add_link_mode(cmd, supported, FIBRE);
505 cmd->base.port = PORT_OTHER;
506 cmd->base.speed = SPEED_UNKNOWN;
507 cmd->base.duplex = DUPLEX_UNKNOWN;
508
509 port = nfp_port_from_netdev(netdev);
510 eth_port = nfp_port_get_eth_port(port);
511 if (eth_port) {
512 ethtool_link_ksettings_add_link_mode(cmd, supported, Pause);
513 ethtool_link_ksettings_add_link_mode(cmd, advertising, Pause);
514 nfp_add_media_link_mode(port, eth_port, cmd);
515 if (eth_port->supp_aneg) {
516 ethtool_link_ksettings_add_link_mode(cmd, supported, Autoneg);
517 if (eth_port->aneg == NFP_ANEG_AUTO) {
518 ethtool_link_ksettings_add_link_mode(cmd, advertising, Autoneg);
519 cmd->base.autoneg = AUTONEG_ENABLE;
520 }
521 }
522 nfp_net_set_fec_link_mode(eth_port, cmd);
523 }
524
525 if (!netif_carrier_ok(netdev))
526 return 0;
527
528 /* Use link speed from ETH table if available, otherwise try the BAR */
529 if (eth_port) {
530 cmd->base.port = eth_port->port_type;
531 cmd->base.speed = eth_port->speed;
532 cmd->base.duplex = DUPLEX_FULL;
533 return 0;
534 }
535
536 if (!nfp_netdev_is_nfp_net(netdev))
537 return -EOPNOTSUPP;
538 nn = netdev_priv(netdev);
539
540 sts = nn_readw(nn, NFP_NET_CFG_STS);
541 speed = nfp_net_lr2speed(FIELD_GET(NFP_NET_CFG_STS_LINK_RATE, sts));
542 if (!speed)
543 return -EOPNOTSUPP;
544
545 if (speed != SPEED_UNKNOWN) {
546 cmd->base.speed = speed;
547 cmd->base.duplex = DUPLEX_FULL;
548 }
549
550 return 0;
551 }
552
553 static int
nfp_net_set_link_ksettings(struct net_device * netdev,const struct ethtool_link_ksettings * cmd)554 nfp_net_set_link_ksettings(struct net_device *netdev,
555 const struct ethtool_link_ksettings *cmd)
556 {
557 bool req_aneg = (cmd->base.autoneg == AUTONEG_ENABLE);
558 struct nfp_eth_table_port *eth_port;
559 struct nfp_port *port;
560 struct nfp_nsp *nsp;
561 int err;
562
563 port = nfp_port_from_netdev(netdev);
564 eth_port = __nfp_port_get_eth_port(port);
565 if (!eth_port)
566 return -EOPNOTSUPP;
567
568 if (netif_running(netdev)) {
569 netdev_warn(netdev, "Changing settings not allowed on an active interface. It may cause the port to be disabled until driver reload.\n");
570 return -EBUSY;
571 }
572
573 nsp = nfp_eth_config_start(port->app->cpp, eth_port->index);
574 if (IS_ERR(nsp))
575 return PTR_ERR(nsp);
576
577 if (req_aneg && !eth_port->supp_aneg) {
578 netdev_warn(netdev, "Autoneg is not supported.\n");
579 err = -EOPNOTSUPP;
580 goto err_bad_set;
581 }
582
583 err = __nfp_eth_set_aneg(nsp, req_aneg ? NFP_ANEG_AUTO : NFP_ANEG_DISABLED);
584 if (err)
585 goto err_bad_set;
586
587 if (cmd->base.speed != SPEED_UNKNOWN) {
588 u32 speed = cmd->base.speed / eth_port->lanes;
589 bool is_supported = false;
590
591 for (u32 i = 0; i < NFP_SUP_SPEED_NUMBER; i++) {
592 if (cmd->base.speed == nfp_eth_speed_map[i] &&
593 test_bit(i, port->speed_bitmap)) {
594 is_supported = true;
595 break;
596 }
597 }
598
599 if (!is_supported) {
600 netdev_err(netdev, "Speed %u is not supported.\n",
601 cmd->base.speed);
602 err = -EINVAL;
603 goto err_bad_set;
604 }
605
606 if (req_aneg) {
607 netdev_err(netdev, "Speed changing is not allowed when working on autoneg mode.\n");
608 err = -EINVAL;
609 goto err_bad_set;
610 }
611
612 err = __nfp_eth_set_speed(nsp, speed);
613 if (err)
614 goto err_bad_set;
615 }
616
617 err = nfp_eth_config_commit_end(nsp);
618 if (err > 0)
619 return 0; /* no change */
620
621 nfp_net_refresh_port_table(port);
622
623 return err;
624
625 err_bad_set:
626 nfp_eth_config_cleanup_end(nsp);
627 return err;
628 }
629
nfp_net_get_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)630 static void nfp_net_get_ringparam(struct net_device *netdev,
631 struct ethtool_ringparam *ring,
632 struct kernel_ethtool_ringparam *kernel_ring,
633 struct netlink_ext_ack *extack)
634 {
635 struct nfp_net *nn = netdev_priv(netdev);
636 u32 qc_max = nn->dev_info->max_qc_size;
637
638 ring->rx_max_pending = qc_max;
639 ring->tx_max_pending = qc_max / nn->dp.ops->tx_min_desc_per_pkt;
640 ring->rx_pending = nn->dp.rxd_cnt;
641 ring->tx_pending = nn->dp.txd_cnt;
642 }
643
nfp_net_set_ring_size(struct nfp_net * nn,u32 rxd_cnt,u32 txd_cnt)644 static int nfp_net_set_ring_size(struct nfp_net *nn, u32 rxd_cnt, u32 txd_cnt)
645 {
646 struct nfp_net_dp *dp;
647
648 dp = nfp_net_clone_dp(nn);
649 if (!dp)
650 return -ENOMEM;
651
652 dp->rxd_cnt = rxd_cnt;
653 dp->txd_cnt = txd_cnt;
654
655 return nfp_net_ring_reconfig(nn, dp, NULL);
656 }
657
nfp_net_set_ringparam(struct net_device * netdev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)658 static int nfp_net_set_ringparam(struct net_device *netdev,
659 struct ethtool_ringparam *ring,
660 struct kernel_ethtool_ringparam *kernel_ring,
661 struct netlink_ext_ack *extack)
662 {
663 u32 tx_dpp, qc_min, qc_max, rxd_cnt, txd_cnt;
664 struct nfp_net *nn = netdev_priv(netdev);
665
666 /* We don't have separate queues/rings for small/large frames. */
667 if (ring->rx_mini_pending || ring->rx_jumbo_pending)
668 return -EINVAL;
669
670 qc_min = nn->dev_info->min_qc_size;
671 qc_max = nn->dev_info->max_qc_size;
672 tx_dpp = nn->dp.ops->tx_min_desc_per_pkt;
673 /* Round up to supported values */
674 rxd_cnt = roundup_pow_of_two(ring->rx_pending);
675 txd_cnt = roundup_pow_of_two(ring->tx_pending);
676
677 if (rxd_cnt < qc_min || rxd_cnt > qc_max ||
678 txd_cnt < qc_min / tx_dpp || txd_cnt > qc_max / tx_dpp)
679 return -EINVAL;
680
681 if (nn->dp.rxd_cnt == rxd_cnt && nn->dp.txd_cnt == txd_cnt)
682 return 0;
683
684 nn_dbg(nn, "Change ring size: RxQ %u->%u, TxQ %u->%u\n",
685 nn->dp.rxd_cnt, rxd_cnt, nn->dp.txd_cnt, txd_cnt);
686
687 return nfp_net_set_ring_size(nn, rxd_cnt, txd_cnt);
688 }
689
nfp_test_link(struct net_device * netdev)690 static int nfp_test_link(struct net_device *netdev)
691 {
692 if (!netif_carrier_ok(netdev) || !(netdev->flags & IFF_UP))
693 return 1;
694
695 return 0;
696 }
697
nfp_test_nsp(struct net_device * netdev)698 static int nfp_test_nsp(struct net_device *netdev)
699 {
700 struct nfp_app *app = nfp_app_from_netdev(netdev);
701 struct nfp_nsp_identify *nspi;
702 struct nfp_nsp *nsp;
703 int err;
704
705 nsp = nfp_nsp_open(app->cpp);
706 if (IS_ERR(nsp)) {
707 err = PTR_ERR(nsp);
708 netdev_info(netdev, "NSP Test: failed to access the NSP: %d\n", err);
709 goto exit;
710 }
711
712 if (nfp_nsp_get_abi_ver_minor(nsp) < 15) {
713 err = -EOPNOTSUPP;
714 goto exit_close_nsp;
715 }
716
717 nspi = kzalloc(sizeof(*nspi), GFP_KERNEL);
718 if (!nspi) {
719 err = -ENOMEM;
720 goto exit_close_nsp;
721 }
722
723 err = nfp_nsp_read_identify(nsp, nspi, sizeof(*nspi));
724 if (err < 0)
725 netdev_info(netdev, "NSP Test: reading bsp version failed %d\n", err);
726
727 kfree(nspi);
728 exit_close_nsp:
729 nfp_nsp_close(nsp);
730 exit:
731 return err;
732 }
733
nfp_test_fw(struct net_device * netdev)734 static int nfp_test_fw(struct net_device *netdev)
735 {
736 struct nfp_net *nn = netdev_priv(netdev);
737 int err;
738
739 err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_GEN);
740 if (err)
741 netdev_info(netdev, "FW Test: update failed %d\n", err);
742
743 return err;
744 }
745
nfp_test_reg(struct net_device * netdev)746 static int nfp_test_reg(struct net_device *netdev)
747 {
748 struct nfp_app *app = nfp_app_from_netdev(netdev);
749 struct nfp_cpp *cpp = app->cpp;
750 u32 model = nfp_cpp_model(cpp);
751 u32 value;
752 int err;
753
754 err = nfp_cpp_model_autodetect(cpp, &value);
755 if (err < 0) {
756 netdev_info(netdev, "REG Test: NFP model detection failed %d\n", err);
757 return err;
758 }
759
760 return (value == model) ? 0 : 1;
761 }
762
link_test_supported(struct net_device * netdev)763 static bool link_test_supported(struct net_device *netdev)
764 {
765 return true;
766 }
767
nsp_test_supported(struct net_device * netdev)768 static bool nsp_test_supported(struct net_device *netdev)
769 {
770 if (nfp_app_from_netdev(netdev))
771 return true;
772
773 return false;
774 }
775
fw_test_supported(struct net_device * netdev)776 static bool fw_test_supported(struct net_device *netdev)
777 {
778 if (nfp_netdev_is_nfp_net(netdev))
779 return true;
780
781 return false;
782 }
783
reg_test_supported(struct net_device * netdev)784 static bool reg_test_supported(struct net_device *netdev)
785 {
786 if (nfp_app_from_netdev(netdev))
787 return true;
788
789 return false;
790 }
791
792 static struct nfp_self_test_item {
793 char name[ETH_GSTRING_LEN];
794 bool (*is_supported)(struct net_device *dev);
795 int (*func)(struct net_device *dev);
796 } nfp_self_test[] = {
797 {"Link Test", link_test_supported, nfp_test_link},
798 {"NSP Test", nsp_test_supported, nfp_test_nsp},
799 {"Firmware Test", fw_test_supported, nfp_test_fw},
800 {"Register Test", reg_test_supported, nfp_test_reg}
801 };
802
803 #define NFP_TEST_TOTAL_NUM ARRAY_SIZE(nfp_self_test)
804
nfp_get_self_test_strings(struct net_device * netdev,u8 * data)805 static void nfp_get_self_test_strings(struct net_device *netdev, u8 *data)
806 {
807 int i;
808
809 for (i = 0; i < NFP_TEST_TOTAL_NUM; i++)
810 if (nfp_self_test[i].is_supported(netdev))
811 ethtool_sprintf(&data, nfp_self_test[i].name);
812 }
813
nfp_get_self_test_count(struct net_device * netdev)814 static int nfp_get_self_test_count(struct net_device *netdev)
815 {
816 int i, count = 0;
817
818 for (i = 0; i < NFP_TEST_TOTAL_NUM; i++)
819 if (nfp_self_test[i].is_supported(netdev))
820 count++;
821
822 return count;
823 }
824
nfp_net_self_test(struct net_device * netdev,struct ethtool_test * eth_test,u64 * data)825 static void nfp_net_self_test(struct net_device *netdev, struct ethtool_test *eth_test,
826 u64 *data)
827 {
828 int i, ret, count = 0;
829
830 netdev_info(netdev, "Start self test\n");
831
832 for (i = 0; i < NFP_TEST_TOTAL_NUM; i++) {
833 if (nfp_self_test[i].is_supported(netdev)) {
834 ret = nfp_self_test[i].func(netdev);
835 if (ret)
836 eth_test->flags |= ETH_TEST_FL_FAILED;
837 data[count++] = ret;
838 }
839 }
840
841 netdev_info(netdev, "Test end\n");
842 }
843
nfp_vnic_get_sw_stats_count(struct net_device * netdev)844 static unsigned int nfp_vnic_get_sw_stats_count(struct net_device *netdev)
845 {
846 struct nfp_net *nn = netdev_priv(netdev);
847
848 return NN_RVEC_GATHER_STATS + nn->max_r_vecs * NN_RVEC_PER_Q_STATS +
849 NN_CTRL_PATH_STATS;
850 }
851
nfp_vnic_get_sw_stats_strings(struct net_device * netdev,u8 * data)852 static u8 *nfp_vnic_get_sw_stats_strings(struct net_device *netdev, u8 *data)
853 {
854 struct nfp_net *nn = netdev_priv(netdev);
855 int i;
856
857 for (i = 0; i < nn->max_r_vecs; i++) {
858 ethtool_sprintf(&data, "rvec_%u_rx_pkts", i);
859 ethtool_sprintf(&data, "rvec_%u_tx_pkts", i);
860 ethtool_sprintf(&data, "rvec_%u_tx_busy", i);
861 }
862
863 ethtool_sprintf(&data, "hw_rx_csum_ok");
864 ethtool_sprintf(&data, "hw_rx_csum_inner_ok");
865 ethtool_sprintf(&data, "hw_rx_csum_complete");
866 ethtool_sprintf(&data, "hw_rx_csum_err");
867 ethtool_sprintf(&data, "rx_replace_buf_alloc_fail");
868 ethtool_sprintf(&data, "rx_tls_decrypted_packets");
869 ethtool_sprintf(&data, "hw_tx_csum");
870 ethtool_sprintf(&data, "hw_tx_inner_csum");
871 ethtool_sprintf(&data, "tx_gather");
872 ethtool_sprintf(&data, "tx_lso");
873 ethtool_sprintf(&data, "tx_tls_encrypted_packets");
874 ethtool_sprintf(&data, "tx_tls_ooo");
875 ethtool_sprintf(&data, "tx_tls_drop_no_sync_data");
876
877 ethtool_sprintf(&data, "hw_tls_no_space");
878 ethtool_sprintf(&data, "rx_tls_resync_req_ok");
879 ethtool_sprintf(&data, "rx_tls_resync_req_ign");
880 ethtool_sprintf(&data, "rx_tls_resync_sent");
881
882 return data;
883 }
884
nfp_vnic_get_sw_stats(struct net_device * netdev,u64 * data)885 static u64 *nfp_vnic_get_sw_stats(struct net_device *netdev, u64 *data)
886 {
887 u64 gathered_stats[NN_RVEC_GATHER_STATS] = {};
888 struct nfp_net *nn = netdev_priv(netdev);
889 u64 tmp[NN_RVEC_GATHER_STATS];
890 unsigned int i, j;
891
892 for (i = 0; i < nn->max_r_vecs; i++) {
893 unsigned int start;
894
895 do {
896 start = u64_stats_fetch_begin(&nn->r_vecs[i].rx_sync);
897 data[0] = nn->r_vecs[i].rx_pkts;
898 tmp[0] = nn->r_vecs[i].hw_csum_rx_ok;
899 tmp[1] = nn->r_vecs[i].hw_csum_rx_inner_ok;
900 tmp[2] = nn->r_vecs[i].hw_csum_rx_complete;
901 tmp[3] = nn->r_vecs[i].hw_csum_rx_error;
902 tmp[4] = nn->r_vecs[i].rx_replace_buf_alloc_fail;
903 tmp[5] = nn->r_vecs[i].hw_tls_rx;
904 } while (u64_stats_fetch_retry(&nn->r_vecs[i].rx_sync, start));
905
906 do {
907 start = u64_stats_fetch_begin(&nn->r_vecs[i].tx_sync);
908 data[1] = nn->r_vecs[i].tx_pkts;
909 data[2] = nn->r_vecs[i].tx_busy;
910 tmp[6] = nn->r_vecs[i].hw_csum_tx;
911 tmp[7] = nn->r_vecs[i].hw_csum_tx_inner;
912 tmp[8] = nn->r_vecs[i].tx_gather;
913 tmp[9] = nn->r_vecs[i].tx_lso;
914 tmp[10] = nn->r_vecs[i].hw_tls_tx;
915 tmp[11] = nn->r_vecs[i].tls_tx_fallback;
916 tmp[12] = nn->r_vecs[i].tls_tx_no_fallback;
917 } while (u64_stats_fetch_retry(&nn->r_vecs[i].tx_sync, start));
918
919 data += NN_RVEC_PER_Q_STATS;
920
921 for (j = 0; j < NN_RVEC_GATHER_STATS; j++)
922 gathered_stats[j] += tmp[j];
923 }
924
925 for (j = 0; j < NN_RVEC_GATHER_STATS; j++)
926 *data++ = gathered_stats[j];
927
928 *data++ = atomic_read(&nn->ktls_no_space);
929 *data++ = atomic_read(&nn->ktls_rx_resync_req);
930 *data++ = atomic_read(&nn->ktls_rx_resync_ign);
931 *data++ = atomic_read(&nn->ktls_rx_resync_sent);
932
933 return data;
934 }
935
nfp_vnic_get_hw_stats_count(unsigned int num_vecs)936 static unsigned int nfp_vnic_get_hw_stats_count(unsigned int num_vecs)
937 {
938 return NN_ET_GLOBAL_STATS_LEN + num_vecs * 4;
939 }
940
941 static u8 *
nfp_vnic_get_hw_stats_strings(u8 * data,unsigned int num_vecs,bool repr)942 nfp_vnic_get_hw_stats_strings(u8 *data, unsigned int num_vecs, bool repr)
943 {
944 int swap_off, i;
945
946 BUILD_BUG_ON(NN_ET_GLOBAL_STATS_LEN < NN_ET_SWITCH_STATS_LEN * 2);
947 /* If repr is true first add SWITCH_STATS_LEN and then subtract it
948 * effectively swapping the RX and TX statistics (giving us the RX
949 * and TX from perspective of the switch).
950 */
951 swap_off = repr * NN_ET_SWITCH_STATS_LEN;
952
953 for (i = 0; i < NN_ET_SWITCH_STATS_LEN; i++)
954 ethtool_sprintf(&data, nfp_net_et_stats[i + swap_off].name);
955
956 for (i = NN_ET_SWITCH_STATS_LEN; i < NN_ET_SWITCH_STATS_LEN * 2; i++)
957 ethtool_sprintf(&data, nfp_net_et_stats[i - swap_off].name);
958
959 for (i = NN_ET_SWITCH_STATS_LEN * 2; i < NN_ET_GLOBAL_STATS_LEN; i++)
960 ethtool_sprintf(&data, nfp_net_et_stats[i].name);
961
962 for (i = 0; i < num_vecs; i++) {
963 ethtool_sprintf(&data, "rxq_%u_pkts", i);
964 ethtool_sprintf(&data, "rxq_%u_bytes", i);
965 ethtool_sprintf(&data, "txq_%u_pkts", i);
966 ethtool_sprintf(&data, "txq_%u_bytes", i);
967 }
968
969 return data;
970 }
971
972 static u64 *
nfp_vnic_get_hw_stats(u64 * data,u8 __iomem * mem,unsigned int num_vecs)973 nfp_vnic_get_hw_stats(u64 *data, u8 __iomem *mem, unsigned int num_vecs)
974 {
975 unsigned int i;
976
977 for (i = 0; i < NN_ET_GLOBAL_STATS_LEN; i++)
978 *data++ = readq(mem + nfp_net_et_stats[i].off);
979
980 for (i = 0; i < num_vecs; i++) {
981 *data++ = readq(mem + NFP_NET_CFG_RXR_STATS(i));
982 *data++ = readq(mem + NFP_NET_CFG_RXR_STATS(i) + 8);
983 *data++ = readq(mem + NFP_NET_CFG_TXR_STATS(i));
984 *data++ = readq(mem + NFP_NET_CFG_TXR_STATS(i) + 8);
985 }
986
987 return data;
988 }
989
nfp_vnic_get_tlv_stats_count(struct nfp_net * nn)990 static unsigned int nfp_vnic_get_tlv_stats_count(struct nfp_net *nn)
991 {
992 return nn->tlv_caps.vnic_stats_cnt + nn->max_r_vecs * 4;
993 }
994
nfp_vnic_get_tlv_stats_strings(struct nfp_net * nn,u8 * data)995 static u8 *nfp_vnic_get_tlv_stats_strings(struct nfp_net *nn, u8 *data)
996 {
997 unsigned int i, id;
998 u8 __iomem *mem;
999 u64 id_word = 0;
1000
1001 mem = nn->dp.ctrl_bar + nn->tlv_caps.vnic_stats_off;
1002 for (i = 0; i < nn->tlv_caps.vnic_stats_cnt; i++) {
1003 if (!(i % 4))
1004 id_word = readq(mem + i * 2);
1005
1006 id = (u16)id_word;
1007 id_word >>= 16;
1008
1009 if (id < ARRAY_SIZE(nfp_tlv_stat_names) &&
1010 nfp_tlv_stat_names[id][0]) {
1011 memcpy(data, nfp_tlv_stat_names[id], ETH_GSTRING_LEN);
1012 data += ETH_GSTRING_LEN;
1013 } else {
1014 ethtool_sprintf(&data, "dev_unknown_stat%u", id);
1015 }
1016 }
1017
1018 for (i = 0; i < nn->max_r_vecs; i++) {
1019 ethtool_sprintf(&data, "rxq_%u_pkts", i);
1020 ethtool_sprintf(&data, "rxq_%u_bytes", i);
1021 ethtool_sprintf(&data, "txq_%u_pkts", i);
1022 ethtool_sprintf(&data, "txq_%u_bytes", i);
1023 }
1024
1025 return data;
1026 }
1027
nfp_vnic_get_tlv_stats(struct nfp_net * nn,u64 * data)1028 static u64 *nfp_vnic_get_tlv_stats(struct nfp_net *nn, u64 *data)
1029 {
1030 u8 __iomem *mem;
1031 unsigned int i;
1032
1033 mem = nn->dp.ctrl_bar + nn->tlv_caps.vnic_stats_off;
1034 mem += roundup(2 * nn->tlv_caps.vnic_stats_cnt, 8);
1035 for (i = 0; i < nn->tlv_caps.vnic_stats_cnt; i++)
1036 *data++ = readq(mem + i * 8);
1037
1038 mem = nn->dp.ctrl_bar;
1039 for (i = 0; i < nn->max_r_vecs; i++) {
1040 *data++ = readq(mem + NFP_NET_CFG_RXR_STATS(i));
1041 *data++ = readq(mem + NFP_NET_CFG_RXR_STATS(i) + 8);
1042 *data++ = readq(mem + NFP_NET_CFG_TXR_STATS(i));
1043 *data++ = readq(mem + NFP_NET_CFG_TXR_STATS(i) + 8);
1044 }
1045
1046 return data;
1047 }
1048
nfp_mac_get_stats_count(struct net_device * netdev)1049 static unsigned int nfp_mac_get_stats_count(struct net_device *netdev)
1050 {
1051 struct nfp_port *port;
1052
1053 port = nfp_port_from_netdev(netdev);
1054 if (!__nfp_port_get_eth_port(port) || !port->eth_stats)
1055 return 0;
1056
1057 return ARRAY_SIZE(nfp_mac_et_stats);
1058 }
1059
nfp_mac_get_stats_strings(struct net_device * netdev,u8 * data)1060 static u8 *nfp_mac_get_stats_strings(struct net_device *netdev, u8 *data)
1061 {
1062 struct nfp_port *port;
1063 unsigned int i;
1064
1065 port = nfp_port_from_netdev(netdev);
1066 if (!__nfp_port_get_eth_port(port) || !port->eth_stats)
1067 return data;
1068
1069 for (i = 0; i < ARRAY_SIZE(nfp_mac_et_stats); i++)
1070 ethtool_sprintf(&data, "mac.%s", nfp_mac_et_stats[i].name);
1071
1072 return data;
1073 }
1074
nfp_mac_get_stats(struct net_device * netdev,u64 * data)1075 static u64 *nfp_mac_get_stats(struct net_device *netdev, u64 *data)
1076 {
1077 struct nfp_port *port;
1078 unsigned int i;
1079
1080 port = nfp_port_from_netdev(netdev);
1081 if (!__nfp_port_get_eth_port(port) || !port->eth_stats)
1082 return data;
1083
1084 for (i = 0; i < ARRAY_SIZE(nfp_mac_et_stats); i++)
1085 *data++ = readq(port->eth_stats + nfp_mac_et_stats[i].off);
1086
1087 return data;
1088 }
1089
nfp_net_get_strings(struct net_device * netdev,u32 stringset,u8 * data)1090 static void nfp_net_get_strings(struct net_device *netdev,
1091 u32 stringset, u8 *data)
1092 {
1093 struct nfp_net *nn = netdev_priv(netdev);
1094
1095 switch (stringset) {
1096 case ETH_SS_STATS:
1097 data = nfp_vnic_get_sw_stats_strings(netdev, data);
1098 if (!nn->tlv_caps.vnic_stats_off)
1099 data = nfp_vnic_get_hw_stats_strings(data,
1100 nn->max_r_vecs,
1101 false);
1102 else
1103 data = nfp_vnic_get_tlv_stats_strings(nn, data);
1104 data = nfp_mac_get_stats_strings(netdev, data);
1105 data = nfp_app_port_get_stats_strings(nn->port, data);
1106 break;
1107 case ETH_SS_TEST:
1108 nfp_get_self_test_strings(netdev, data);
1109 break;
1110 }
1111 }
1112
1113 static void
nfp_net_get_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * data)1114 nfp_net_get_stats(struct net_device *netdev, struct ethtool_stats *stats,
1115 u64 *data)
1116 {
1117 struct nfp_net *nn = netdev_priv(netdev);
1118
1119 data = nfp_vnic_get_sw_stats(netdev, data);
1120 if (!nn->tlv_caps.vnic_stats_off)
1121 data = nfp_vnic_get_hw_stats(data, nn->dp.ctrl_bar,
1122 nn->max_r_vecs);
1123 else
1124 data = nfp_vnic_get_tlv_stats(nn, data);
1125 data = nfp_mac_get_stats(netdev, data);
1126 data = nfp_app_port_get_stats(nn->port, data);
1127 }
1128
nfp_net_get_sset_count(struct net_device * netdev,int sset)1129 static int nfp_net_get_sset_count(struct net_device *netdev, int sset)
1130 {
1131 struct nfp_net *nn = netdev_priv(netdev);
1132 unsigned int cnt;
1133
1134 switch (sset) {
1135 case ETH_SS_STATS:
1136 cnt = nfp_vnic_get_sw_stats_count(netdev);
1137 if (!nn->tlv_caps.vnic_stats_off)
1138 cnt += nfp_vnic_get_hw_stats_count(nn->max_r_vecs);
1139 else
1140 cnt += nfp_vnic_get_tlv_stats_count(nn);
1141 cnt += nfp_mac_get_stats_count(netdev);
1142 cnt += nfp_app_port_get_stats_count(nn->port);
1143 return cnt;
1144 case ETH_SS_TEST:
1145 return nfp_get_self_test_count(netdev);
1146 default:
1147 return -EOPNOTSUPP;
1148 }
1149 }
1150
nfp_port_get_strings(struct net_device * netdev,u32 stringset,u8 * data)1151 static void nfp_port_get_strings(struct net_device *netdev,
1152 u32 stringset, u8 *data)
1153 {
1154 struct nfp_port *port = nfp_port_from_netdev(netdev);
1155
1156 switch (stringset) {
1157 case ETH_SS_STATS:
1158 if (nfp_port_is_vnic(port))
1159 data = nfp_vnic_get_hw_stats_strings(data, 0, true);
1160 else
1161 data = nfp_mac_get_stats_strings(netdev, data);
1162 data = nfp_app_port_get_stats_strings(port, data);
1163 break;
1164 case ETH_SS_TEST:
1165 nfp_get_self_test_strings(netdev, data);
1166 break;
1167 }
1168 }
1169
1170 static void
nfp_port_get_stats(struct net_device * netdev,struct ethtool_stats * stats,u64 * data)1171 nfp_port_get_stats(struct net_device *netdev, struct ethtool_stats *stats,
1172 u64 *data)
1173 {
1174 struct nfp_port *port = nfp_port_from_netdev(netdev);
1175
1176 if (nfp_port_is_vnic(port))
1177 data = nfp_vnic_get_hw_stats(data, port->vnic, 0);
1178 else
1179 data = nfp_mac_get_stats(netdev, data);
1180 data = nfp_app_port_get_stats(port, data);
1181 }
1182
nfp_port_get_sset_count(struct net_device * netdev,int sset)1183 static int nfp_port_get_sset_count(struct net_device *netdev, int sset)
1184 {
1185 struct nfp_port *port = nfp_port_from_netdev(netdev);
1186 unsigned int count;
1187
1188 switch (sset) {
1189 case ETH_SS_STATS:
1190 if (nfp_port_is_vnic(port))
1191 count = nfp_vnic_get_hw_stats_count(0);
1192 else
1193 count = nfp_mac_get_stats_count(netdev);
1194 count += nfp_app_port_get_stats_count(port);
1195 return count;
1196 case ETH_SS_TEST:
1197 return nfp_get_self_test_count(netdev);
1198 default:
1199 return -EOPNOTSUPP;
1200 }
1201 }
1202
nfp_port_fec_ethtool_to_nsp(u32 fec)1203 static int nfp_port_fec_ethtool_to_nsp(u32 fec)
1204 {
1205 switch (fec) {
1206 case ETHTOOL_FEC_AUTO:
1207 return NFP_FEC_AUTO_BIT;
1208 case ETHTOOL_FEC_OFF:
1209 return NFP_FEC_DISABLED_BIT;
1210 case ETHTOOL_FEC_RS:
1211 return NFP_FEC_REED_SOLOMON_BIT;
1212 case ETHTOOL_FEC_BASER:
1213 return NFP_FEC_BASER_BIT;
1214 default:
1215 /* NSP only supports a single mode at a time */
1216 return -EOPNOTSUPP;
1217 }
1218 }
1219
nfp_port_fec_nsp_to_ethtool(u32 fec)1220 static u32 nfp_port_fec_nsp_to_ethtool(u32 fec)
1221 {
1222 u32 result = 0;
1223
1224 if (fec & NFP_FEC_AUTO)
1225 result |= ETHTOOL_FEC_AUTO;
1226 if (fec & NFP_FEC_BASER)
1227 result |= ETHTOOL_FEC_BASER;
1228 if (fec & NFP_FEC_REED_SOLOMON)
1229 result |= ETHTOOL_FEC_RS;
1230 if (fec & NFP_FEC_DISABLED)
1231 result |= ETHTOOL_FEC_OFF;
1232
1233 return result ?: ETHTOOL_FEC_NONE;
1234 }
1235
1236 static int
nfp_port_get_fecparam(struct net_device * netdev,struct ethtool_fecparam * param)1237 nfp_port_get_fecparam(struct net_device *netdev,
1238 struct ethtool_fecparam *param)
1239 {
1240 struct nfp_eth_table_port *eth_port;
1241 struct nfp_port *port;
1242
1243 param->active_fec = ETHTOOL_FEC_NONE;
1244 param->fec = ETHTOOL_FEC_NONE;
1245
1246 port = nfp_port_from_netdev(netdev);
1247 eth_port = nfp_port_get_eth_port(port);
1248 if (!eth_port)
1249 return -EOPNOTSUPP;
1250
1251 if (!nfp_eth_can_support_fec(eth_port))
1252 return 0;
1253
1254 param->fec = nfp_port_fec_nsp_to_ethtool(eth_port->fec_modes_supported);
1255 param->active_fec = nfp_port_fec_nsp_to_ethtool(BIT(eth_port->act_fec));
1256
1257 return 0;
1258 }
1259
1260 static int
nfp_port_set_fecparam(struct net_device * netdev,struct ethtool_fecparam * param)1261 nfp_port_set_fecparam(struct net_device *netdev,
1262 struct ethtool_fecparam *param)
1263 {
1264 struct nfp_eth_table_port *eth_port;
1265 struct nfp_port *port;
1266 int err, fec;
1267
1268 port = nfp_port_from_netdev(netdev);
1269 eth_port = nfp_port_get_eth_port(port);
1270 if (!eth_port)
1271 return -EOPNOTSUPP;
1272
1273 if (!nfp_eth_can_support_fec(eth_port))
1274 return -EOPNOTSUPP;
1275
1276 fec = nfp_port_fec_ethtool_to_nsp(param->fec);
1277 if (fec < 0)
1278 return fec;
1279
1280 err = nfp_eth_set_fec(port->app->cpp, eth_port->index, fec);
1281 if (!err)
1282 /* Only refresh if we did something */
1283 nfp_net_refresh_port_table(port);
1284
1285 return err < 0 ? err : 0;
1286 }
1287
1288 /* RX network flow classification (RSS, filters, etc)
1289 */
ethtool_flow_to_nfp_flag(u32 flow_type)1290 static u32 ethtool_flow_to_nfp_flag(u32 flow_type)
1291 {
1292 static const u32 xlate_ethtool_to_nfp[IPV6_FLOW + 1] = {
1293 [TCP_V4_FLOW] = NFP_NET_CFG_RSS_IPV4_TCP,
1294 [TCP_V6_FLOW] = NFP_NET_CFG_RSS_IPV6_TCP,
1295 [UDP_V4_FLOW] = NFP_NET_CFG_RSS_IPV4_UDP,
1296 [UDP_V6_FLOW] = NFP_NET_CFG_RSS_IPV6_UDP,
1297 [IPV4_FLOW] = NFP_NET_CFG_RSS_IPV4,
1298 [IPV6_FLOW] = NFP_NET_CFG_RSS_IPV6,
1299 };
1300
1301 if (flow_type >= ARRAY_SIZE(xlate_ethtool_to_nfp))
1302 return 0;
1303
1304 return xlate_ethtool_to_nfp[flow_type];
1305 }
1306
nfp_net_get_rss_hash_opts(struct nfp_net * nn,struct ethtool_rxnfc * cmd)1307 static int nfp_net_get_rss_hash_opts(struct nfp_net *nn,
1308 struct ethtool_rxnfc *cmd)
1309 {
1310 u32 nfp_rss_flag;
1311
1312 cmd->data = 0;
1313
1314 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS_ANY))
1315 return -EOPNOTSUPP;
1316
1317 nfp_rss_flag = ethtool_flow_to_nfp_flag(cmd->flow_type);
1318 if (!nfp_rss_flag)
1319 return -EINVAL;
1320
1321 cmd->data |= RXH_IP_SRC | RXH_IP_DST;
1322 if (nn->rss_cfg & nfp_rss_flag)
1323 cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
1324
1325 return 0;
1326 }
1327
nfp_net_get_rxnfc(struct net_device * netdev,struct ethtool_rxnfc * cmd,u32 * rule_locs)1328 static int nfp_net_get_rxnfc(struct net_device *netdev,
1329 struct ethtool_rxnfc *cmd, u32 *rule_locs)
1330 {
1331 struct nfp_net *nn = netdev_priv(netdev);
1332
1333 switch (cmd->cmd) {
1334 case ETHTOOL_GRXRINGS:
1335 cmd->data = nn->dp.num_rx_rings;
1336 return 0;
1337 case ETHTOOL_GRXFH:
1338 return nfp_net_get_rss_hash_opts(nn, cmd);
1339 default:
1340 return -EOPNOTSUPP;
1341 }
1342 }
1343
nfp_net_set_rss_hash_opt(struct nfp_net * nn,struct ethtool_rxnfc * nfc)1344 static int nfp_net_set_rss_hash_opt(struct nfp_net *nn,
1345 struct ethtool_rxnfc *nfc)
1346 {
1347 u32 new_rss_cfg = nn->rss_cfg;
1348 u32 nfp_rss_flag;
1349 int err;
1350
1351 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS_ANY))
1352 return -EOPNOTSUPP;
1353
1354 /* RSS only supports IP SA/DA and L4 src/dst ports */
1355 if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
1356 RXH_L4_B_0_1 | RXH_L4_B_2_3))
1357 return -EINVAL;
1358
1359 /* We need at least the IP SA/DA fields for hashing */
1360 if (!(nfc->data & RXH_IP_SRC) ||
1361 !(nfc->data & RXH_IP_DST))
1362 return -EINVAL;
1363
1364 nfp_rss_flag = ethtool_flow_to_nfp_flag(nfc->flow_type);
1365 if (!nfp_rss_flag)
1366 return -EINVAL;
1367
1368 switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
1369 case 0:
1370 new_rss_cfg &= ~nfp_rss_flag;
1371 break;
1372 case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
1373 new_rss_cfg |= nfp_rss_flag;
1374 break;
1375 default:
1376 return -EINVAL;
1377 }
1378
1379 new_rss_cfg |= FIELD_PREP(NFP_NET_CFG_RSS_HFUNC, nn->rss_hfunc);
1380 new_rss_cfg |= NFP_NET_CFG_RSS_MASK;
1381
1382 if (new_rss_cfg == nn->rss_cfg)
1383 return 0;
1384
1385 writel(new_rss_cfg, nn->dp.ctrl_bar + NFP_NET_CFG_RSS_CTRL);
1386 err = nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_RSS);
1387 if (err)
1388 return err;
1389
1390 nn->rss_cfg = new_rss_cfg;
1391
1392 nn_dbg(nn, "Changed RSS config to 0x%x\n", nn->rss_cfg);
1393 return 0;
1394 }
1395
nfp_net_set_rxnfc(struct net_device * netdev,struct ethtool_rxnfc * cmd)1396 static int nfp_net_set_rxnfc(struct net_device *netdev,
1397 struct ethtool_rxnfc *cmd)
1398 {
1399 struct nfp_net *nn = netdev_priv(netdev);
1400
1401 switch (cmd->cmd) {
1402 case ETHTOOL_SRXFH:
1403 return nfp_net_set_rss_hash_opt(nn, cmd);
1404 default:
1405 return -EOPNOTSUPP;
1406 }
1407 }
1408
nfp_net_get_rxfh_indir_size(struct net_device * netdev)1409 static u32 nfp_net_get_rxfh_indir_size(struct net_device *netdev)
1410 {
1411 struct nfp_net *nn = netdev_priv(netdev);
1412
1413 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS_ANY))
1414 return 0;
1415
1416 return ARRAY_SIZE(nn->rss_itbl);
1417 }
1418
nfp_net_get_rxfh_key_size(struct net_device * netdev)1419 static u32 nfp_net_get_rxfh_key_size(struct net_device *netdev)
1420 {
1421 struct nfp_net *nn = netdev_priv(netdev);
1422
1423 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS_ANY))
1424 return -EOPNOTSUPP;
1425
1426 return nfp_net_rss_key_sz(nn);
1427 }
1428
nfp_net_get_rxfh(struct net_device * netdev,u32 * indir,u8 * key,u8 * hfunc)1429 static int nfp_net_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
1430 u8 *hfunc)
1431 {
1432 struct nfp_net *nn = netdev_priv(netdev);
1433 int i;
1434
1435 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS_ANY))
1436 return -EOPNOTSUPP;
1437
1438 if (indir)
1439 for (i = 0; i < ARRAY_SIZE(nn->rss_itbl); i++)
1440 indir[i] = nn->rss_itbl[i];
1441 if (key)
1442 memcpy(key, nn->rss_key, nfp_net_rss_key_sz(nn));
1443 if (hfunc) {
1444 *hfunc = nn->rss_hfunc;
1445 if (*hfunc >= 1 << ETH_RSS_HASH_FUNCS_COUNT)
1446 *hfunc = ETH_RSS_HASH_UNKNOWN;
1447 }
1448
1449 return 0;
1450 }
1451
nfp_net_set_rxfh(struct net_device * netdev,const u32 * indir,const u8 * key,const u8 hfunc)1452 static int nfp_net_set_rxfh(struct net_device *netdev,
1453 const u32 *indir, const u8 *key,
1454 const u8 hfunc)
1455 {
1456 struct nfp_net *nn = netdev_priv(netdev);
1457 int i;
1458
1459 if (!(nn->cap & NFP_NET_CFG_CTRL_RSS_ANY) ||
1460 !(hfunc == ETH_RSS_HASH_NO_CHANGE || hfunc == nn->rss_hfunc))
1461 return -EOPNOTSUPP;
1462
1463 if (!key && !indir)
1464 return 0;
1465
1466 if (key) {
1467 memcpy(nn->rss_key, key, nfp_net_rss_key_sz(nn));
1468 nfp_net_rss_write_key(nn);
1469 }
1470 if (indir) {
1471 for (i = 0; i < ARRAY_SIZE(nn->rss_itbl); i++)
1472 nn->rss_itbl[i] = indir[i];
1473
1474 nfp_net_rss_write_itbl(nn);
1475 }
1476
1477 return nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_RSS);
1478 }
1479
1480 /* Dump BAR registers
1481 */
nfp_net_get_regs_len(struct net_device * netdev)1482 static int nfp_net_get_regs_len(struct net_device *netdev)
1483 {
1484 return NFP_NET_CFG_BAR_SZ;
1485 }
1486
nfp_net_get_regs(struct net_device * netdev,struct ethtool_regs * regs,void * p)1487 static void nfp_net_get_regs(struct net_device *netdev,
1488 struct ethtool_regs *regs, void *p)
1489 {
1490 struct nfp_net *nn = netdev_priv(netdev);
1491 u32 *regs_buf = p;
1492 int i;
1493
1494 regs->version = nn_readl(nn, NFP_NET_CFG_VERSION);
1495
1496 for (i = 0; i < NFP_NET_CFG_BAR_SZ / sizeof(u32); i++)
1497 regs_buf[i] = readl(nn->dp.ctrl_bar + (i * sizeof(u32)));
1498 }
1499
nfp_net_get_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1500 static int nfp_net_get_coalesce(struct net_device *netdev,
1501 struct ethtool_coalesce *ec,
1502 struct kernel_ethtool_coalesce *kernel_coal,
1503 struct netlink_ext_ack *extack)
1504 {
1505 struct nfp_net *nn = netdev_priv(netdev);
1506
1507 if (!(nn->cap & NFP_NET_CFG_CTRL_IRQMOD))
1508 return -EINVAL;
1509
1510 ec->use_adaptive_rx_coalesce = nn->rx_coalesce_adapt_on;
1511 ec->use_adaptive_tx_coalesce = nn->tx_coalesce_adapt_on;
1512
1513 ec->rx_coalesce_usecs = nn->rx_coalesce_usecs;
1514 ec->rx_max_coalesced_frames = nn->rx_coalesce_max_frames;
1515 ec->tx_coalesce_usecs = nn->tx_coalesce_usecs;
1516 ec->tx_max_coalesced_frames = nn->tx_coalesce_max_frames;
1517
1518 return 0;
1519 }
1520
1521 /* Other debug dumps
1522 */
1523 static int
nfp_dump_nsp_diag(struct nfp_app * app,struct ethtool_dump * dump,void * buffer)1524 nfp_dump_nsp_diag(struct nfp_app *app, struct ethtool_dump *dump, void *buffer)
1525 {
1526 struct nfp_resource *res;
1527 int ret;
1528
1529 if (!app)
1530 return -EOPNOTSUPP;
1531
1532 dump->version = 1;
1533 dump->flag = NFP_DUMP_NSP_DIAG;
1534
1535 res = nfp_resource_acquire(app->cpp, NFP_RESOURCE_NSP_DIAG);
1536 if (IS_ERR(res))
1537 return PTR_ERR(res);
1538
1539 if (buffer) {
1540 if (dump->len != nfp_resource_size(res)) {
1541 ret = -EINVAL;
1542 goto exit_release;
1543 }
1544
1545 ret = nfp_cpp_read(app->cpp, nfp_resource_cpp_id(res),
1546 nfp_resource_address(res),
1547 buffer, dump->len);
1548 if (ret != dump->len)
1549 ret = ret < 0 ? ret : -EIO;
1550 else
1551 ret = 0;
1552 } else {
1553 dump->len = nfp_resource_size(res);
1554 ret = 0;
1555 }
1556 exit_release:
1557 nfp_resource_release(res);
1558
1559 return ret;
1560 }
1561
1562 /* Set the dump flag/level. Calculate the dump length for flag > 0 only (new TLV
1563 * based dumps), since flag 0 (default) calculates the length in
1564 * nfp_app_get_dump_flag(), and we need to support triggering a level 0 dump
1565 * without setting the flag first, for backward compatibility.
1566 */
nfp_app_set_dump(struct net_device * netdev,struct ethtool_dump * val)1567 static int nfp_app_set_dump(struct net_device *netdev, struct ethtool_dump *val)
1568 {
1569 struct nfp_app *app = nfp_app_from_netdev(netdev);
1570 s64 len;
1571
1572 if (!app)
1573 return -EOPNOTSUPP;
1574
1575 if (val->flag == NFP_DUMP_NSP_DIAG) {
1576 app->pf->dump_flag = val->flag;
1577 return 0;
1578 }
1579
1580 if (!app->pf->dumpspec)
1581 return -EOPNOTSUPP;
1582
1583 len = nfp_net_dump_calculate_size(app->pf, app->pf->dumpspec,
1584 val->flag);
1585 if (len < 0)
1586 return len;
1587
1588 app->pf->dump_flag = val->flag;
1589 app->pf->dump_len = len;
1590
1591 return 0;
1592 }
1593
1594 static int
nfp_app_get_dump_flag(struct net_device * netdev,struct ethtool_dump * dump)1595 nfp_app_get_dump_flag(struct net_device *netdev, struct ethtool_dump *dump)
1596 {
1597 struct nfp_app *app = nfp_app_from_netdev(netdev);
1598
1599 if (!app)
1600 return -EOPNOTSUPP;
1601
1602 if (app->pf->dump_flag == NFP_DUMP_NSP_DIAG)
1603 return nfp_dump_nsp_diag(app, dump, NULL);
1604
1605 dump->flag = app->pf->dump_flag;
1606 dump->len = app->pf->dump_len;
1607
1608 return 0;
1609 }
1610
1611 static int
nfp_app_get_dump_data(struct net_device * netdev,struct ethtool_dump * dump,void * buffer)1612 nfp_app_get_dump_data(struct net_device *netdev, struct ethtool_dump *dump,
1613 void *buffer)
1614 {
1615 struct nfp_app *app = nfp_app_from_netdev(netdev);
1616
1617 if (!app)
1618 return -EOPNOTSUPP;
1619
1620 if (app->pf->dump_flag == NFP_DUMP_NSP_DIAG)
1621 return nfp_dump_nsp_diag(app, dump, buffer);
1622
1623 dump->flag = app->pf->dump_flag;
1624 dump->len = app->pf->dump_len;
1625
1626 return nfp_net_dump_populate_buffer(app->pf, app->pf->dumpspec, dump,
1627 buffer);
1628 }
1629
1630 static int
nfp_port_get_module_info(struct net_device * netdev,struct ethtool_modinfo * modinfo)1631 nfp_port_get_module_info(struct net_device *netdev,
1632 struct ethtool_modinfo *modinfo)
1633 {
1634 struct nfp_eth_table_port *eth_port;
1635 struct nfp_port *port;
1636 unsigned int read_len;
1637 struct nfp_nsp *nsp;
1638 int err = 0;
1639 u8 data;
1640
1641 port = nfp_port_from_netdev(netdev);
1642 if (!port)
1643 return -EOPNOTSUPP;
1644
1645 /* update port state to get latest interface */
1646 set_bit(NFP_PORT_CHANGED, &port->flags);
1647 eth_port = nfp_port_get_eth_port(port);
1648 if (!eth_port)
1649 return -EOPNOTSUPP;
1650
1651 nsp = nfp_nsp_open(port->app->cpp);
1652 if (IS_ERR(nsp)) {
1653 err = PTR_ERR(nsp);
1654 netdev_err(netdev, "Failed to access the NSP: %d\n", err);
1655 return err;
1656 }
1657
1658 if (!nfp_nsp_has_read_module_eeprom(nsp)) {
1659 netdev_info(netdev, "reading module EEPROM not supported. Please update flash\n");
1660 err = -EOPNOTSUPP;
1661 goto exit_close_nsp;
1662 }
1663
1664 switch (eth_port->interface) {
1665 case NFP_INTERFACE_SFP:
1666 case NFP_INTERFACE_SFP28:
1667 err = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index,
1668 SFP_SFF8472_COMPLIANCE, &data,
1669 1, &read_len);
1670 if (err < 0)
1671 goto exit_close_nsp;
1672
1673 if (!data) {
1674 modinfo->type = ETH_MODULE_SFF_8079;
1675 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN;
1676 } else {
1677 modinfo->type = ETH_MODULE_SFF_8472;
1678 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN;
1679 }
1680 break;
1681 case NFP_INTERFACE_QSFP:
1682 err = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index,
1683 SFP_SFF_REV_COMPLIANCE, &data,
1684 1, &read_len);
1685 if (err < 0)
1686 goto exit_close_nsp;
1687
1688 if (data < 0x3) {
1689 modinfo->type = ETH_MODULE_SFF_8436;
1690 modinfo->eeprom_len = ETH_MODULE_SFF_8436_MAX_LEN;
1691 } else {
1692 modinfo->type = ETH_MODULE_SFF_8636;
1693 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1694 }
1695 break;
1696 case NFP_INTERFACE_QSFP28:
1697 modinfo->type = ETH_MODULE_SFF_8636;
1698 modinfo->eeprom_len = ETH_MODULE_SFF_8636_MAX_LEN;
1699 break;
1700 default:
1701 netdev_err(netdev, "Unsupported module 0x%x detected\n",
1702 eth_port->interface);
1703 err = -EINVAL;
1704 }
1705
1706 exit_close_nsp:
1707 nfp_nsp_close(nsp);
1708 return err;
1709 }
1710
1711 static int
nfp_port_get_module_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * data)1712 nfp_port_get_module_eeprom(struct net_device *netdev,
1713 struct ethtool_eeprom *eeprom, u8 *data)
1714 {
1715 struct nfp_eth_table_port *eth_port;
1716 struct nfp_port *port;
1717 struct nfp_nsp *nsp;
1718 int err;
1719
1720 port = nfp_port_from_netdev(netdev);
1721 eth_port = __nfp_port_get_eth_port(port);
1722 if (!eth_port)
1723 return -EOPNOTSUPP;
1724
1725 nsp = nfp_nsp_open(port->app->cpp);
1726 if (IS_ERR(nsp)) {
1727 err = PTR_ERR(nsp);
1728 netdev_err(netdev, "Failed to access the NSP: %d\n", err);
1729 return err;
1730 }
1731
1732 if (!nfp_nsp_has_read_module_eeprom(nsp)) {
1733 netdev_info(netdev, "reading module EEPROM not supported. Please update flash\n");
1734 err = -EOPNOTSUPP;
1735 goto exit_close_nsp;
1736 }
1737
1738 err = nfp_nsp_read_module_eeprom(nsp, eth_port->eth_index,
1739 eeprom->offset, data, eeprom->len,
1740 &eeprom->len);
1741 if (err < 0) {
1742 if (eeprom->len) {
1743 netdev_warn(netdev,
1744 "Incomplete read from module EEPROM: %d\n",
1745 err);
1746 err = 0;
1747 } else {
1748 netdev_err(netdev,
1749 "Reading from module EEPROM failed: %d\n",
1750 err);
1751 }
1752 }
1753
1754 exit_close_nsp:
1755 nfp_nsp_close(nsp);
1756 return err;
1757 }
1758
nfp_net_set_coalesce(struct net_device * netdev,struct ethtool_coalesce * ec,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1759 static int nfp_net_set_coalesce(struct net_device *netdev,
1760 struct ethtool_coalesce *ec,
1761 struct kernel_ethtool_coalesce *kernel_coal,
1762 struct netlink_ext_ack *extack)
1763 {
1764 struct nfp_net *nn = netdev_priv(netdev);
1765 unsigned int factor;
1766
1767 /* Compute factor used to convert coalesce '_usecs' parameters to
1768 * ME timestamp ticks. There are 16 ME clock cycles for each timestamp
1769 * count.
1770 */
1771 factor = nn->tlv_caps.me_freq_mhz / 16;
1772
1773 /* Each pair of (usecs, max_frames) fields specifies that interrupts
1774 * should be coalesced until
1775 * (usecs > 0 && time_since_first_completion >= usecs) ||
1776 * (max_frames > 0 && completed_frames >= max_frames)
1777 *
1778 * It is illegal to set both usecs and max_frames to zero as this would
1779 * cause interrupts to never be generated. To disable coalescing, set
1780 * usecs = 0 and max_frames = 1.
1781 *
1782 * Some implementations ignore the value of max_frames and use the
1783 * condition time_since_first_completion >= usecs
1784 */
1785
1786 if (!(nn->cap & NFP_NET_CFG_CTRL_IRQMOD))
1787 return -EINVAL;
1788
1789 /* ensure valid configuration */
1790 if (!ec->rx_coalesce_usecs && !ec->rx_max_coalesced_frames)
1791 return -EINVAL;
1792
1793 if (!ec->tx_coalesce_usecs && !ec->tx_max_coalesced_frames)
1794 return -EINVAL;
1795
1796 if (nfp_net_coalesce_para_check(ec->rx_coalesce_usecs * factor,
1797 ec->rx_max_coalesced_frames))
1798 return -EINVAL;
1799
1800 if (nfp_net_coalesce_para_check(ec->tx_coalesce_usecs * factor,
1801 ec->tx_max_coalesced_frames))
1802 return -EINVAL;
1803
1804 /* configuration is valid */
1805 nn->rx_coalesce_adapt_on = !!ec->use_adaptive_rx_coalesce;
1806 nn->tx_coalesce_adapt_on = !!ec->use_adaptive_tx_coalesce;
1807
1808 nn->rx_coalesce_usecs = ec->rx_coalesce_usecs;
1809 nn->rx_coalesce_max_frames = ec->rx_max_coalesced_frames;
1810 nn->tx_coalesce_usecs = ec->tx_coalesce_usecs;
1811 nn->tx_coalesce_max_frames = ec->tx_max_coalesced_frames;
1812
1813 /* write configuration to device */
1814 nfp_net_coalesce_write_cfg(nn);
1815 return nfp_net_reconfig(nn, NFP_NET_CFG_UPDATE_IRQMOD);
1816 }
1817
nfp_net_get_channels(struct net_device * netdev,struct ethtool_channels * channel)1818 static void nfp_net_get_channels(struct net_device *netdev,
1819 struct ethtool_channels *channel)
1820 {
1821 struct nfp_net *nn = netdev_priv(netdev);
1822 unsigned int num_tx_rings;
1823
1824 num_tx_rings = nn->dp.num_tx_rings;
1825 if (nn->dp.xdp_prog)
1826 num_tx_rings -= nn->dp.num_rx_rings;
1827
1828 channel->max_rx = min(nn->max_rx_rings, nn->max_r_vecs);
1829 channel->max_tx = min(nn->max_tx_rings, nn->max_r_vecs);
1830 channel->max_combined = min(channel->max_rx, channel->max_tx);
1831 channel->max_other = NFP_NET_NON_Q_VECTORS;
1832 channel->combined_count = min(nn->dp.num_rx_rings, num_tx_rings);
1833 channel->rx_count = nn->dp.num_rx_rings - channel->combined_count;
1834 channel->tx_count = num_tx_rings - channel->combined_count;
1835 channel->other_count = NFP_NET_NON_Q_VECTORS;
1836 }
1837
nfp_net_set_num_rings(struct nfp_net * nn,unsigned int total_rx,unsigned int total_tx)1838 static int nfp_net_set_num_rings(struct nfp_net *nn, unsigned int total_rx,
1839 unsigned int total_tx)
1840 {
1841 struct nfp_net_dp *dp;
1842
1843 dp = nfp_net_clone_dp(nn);
1844 if (!dp)
1845 return -ENOMEM;
1846
1847 dp->num_rx_rings = total_rx;
1848 dp->num_tx_rings = total_tx;
1849 /* nfp_net_check_config() will catch num_tx_rings > nn->max_tx_rings */
1850 if (dp->xdp_prog)
1851 dp->num_tx_rings += total_rx;
1852
1853 return nfp_net_ring_reconfig(nn, dp, NULL);
1854 }
1855
nfp_net_set_channels(struct net_device * netdev,struct ethtool_channels * channel)1856 static int nfp_net_set_channels(struct net_device *netdev,
1857 struct ethtool_channels *channel)
1858 {
1859 struct nfp_net *nn = netdev_priv(netdev);
1860 unsigned int total_rx, total_tx;
1861
1862 /* Reject unsupported */
1863 if (channel->other_count != NFP_NET_NON_Q_VECTORS ||
1864 (channel->rx_count && channel->tx_count))
1865 return -EINVAL;
1866
1867 total_rx = channel->combined_count + channel->rx_count;
1868 total_tx = channel->combined_count + channel->tx_count;
1869
1870 if (total_rx > min(nn->max_rx_rings, nn->max_r_vecs) ||
1871 total_tx > min(nn->max_tx_rings, nn->max_r_vecs))
1872 return -EINVAL;
1873
1874 return nfp_net_set_num_rings(nn, total_rx, total_tx);
1875 }
1876
nfp_port_get_pauseparam(struct net_device * netdev,struct ethtool_pauseparam * pause)1877 static void nfp_port_get_pauseparam(struct net_device *netdev,
1878 struct ethtool_pauseparam *pause)
1879 {
1880 struct nfp_eth_table_port *eth_port;
1881 struct nfp_port *port;
1882
1883 port = nfp_port_from_netdev(netdev);
1884 eth_port = nfp_port_get_eth_port(port);
1885 if (!eth_port)
1886 return;
1887
1888 /* Currently pause frame support is fixed */
1889 pause->autoneg = AUTONEG_DISABLE;
1890 pause->rx_pause = 1;
1891 pause->tx_pause = 1;
1892 }
1893
nfp_net_set_phys_id(struct net_device * netdev,enum ethtool_phys_id_state state)1894 static int nfp_net_set_phys_id(struct net_device *netdev,
1895 enum ethtool_phys_id_state state)
1896 {
1897 struct nfp_eth_table_port *eth_port;
1898 struct nfp_port *port;
1899 int err;
1900
1901 port = nfp_port_from_netdev(netdev);
1902 eth_port = __nfp_port_get_eth_port(port);
1903 if (!eth_port)
1904 return -EOPNOTSUPP;
1905
1906 switch (state) {
1907 case ETHTOOL_ID_ACTIVE:
1908 /* Control LED to blink */
1909 err = nfp_eth_set_idmode(port->app->cpp, eth_port->index, 1);
1910 break;
1911
1912 case ETHTOOL_ID_INACTIVE:
1913 /* Control LED to normal mode */
1914 err = nfp_eth_set_idmode(port->app->cpp, eth_port->index, 0);
1915 break;
1916
1917 case ETHTOOL_ID_ON:
1918 case ETHTOOL_ID_OFF:
1919 default:
1920 return -EOPNOTSUPP;
1921 }
1922
1923 return err;
1924 }
1925
1926 #define NFP_EEPROM_LEN ETH_ALEN
1927
1928 static int
nfp_net_get_eeprom_len(struct net_device * netdev)1929 nfp_net_get_eeprom_len(struct net_device *netdev)
1930 {
1931 struct nfp_eth_table_port *eth_port;
1932 struct nfp_port *port;
1933
1934 port = nfp_port_from_netdev(netdev);
1935 eth_port = __nfp_port_get_eth_port(port);
1936 if (!eth_port)
1937 return 0;
1938
1939 return NFP_EEPROM_LEN;
1940 }
1941
1942 static int
nfp_net_get_nsp_hwindex(struct net_device * netdev,struct nfp_nsp ** nspptr,u32 * index)1943 nfp_net_get_nsp_hwindex(struct net_device *netdev,
1944 struct nfp_nsp **nspptr,
1945 u32 *index)
1946 {
1947 struct nfp_eth_table_port *eth_port;
1948 struct nfp_port *port;
1949 struct nfp_nsp *nsp;
1950 int err;
1951
1952 port = nfp_port_from_netdev(netdev);
1953 eth_port = __nfp_port_get_eth_port(port);
1954 if (!eth_port)
1955 return -EOPNOTSUPP;
1956
1957 nsp = nfp_nsp_open(port->app->cpp);
1958 if (IS_ERR(nsp)) {
1959 err = PTR_ERR(nsp);
1960 netdev_err(netdev, "Failed to access the NSP: %d\n", err);
1961 return err;
1962 }
1963
1964 if (!nfp_nsp_has_hwinfo_lookup(nsp)) {
1965 netdev_err(netdev, "NSP doesn't support PF MAC generation\n");
1966 nfp_nsp_close(nsp);
1967 return -EOPNOTSUPP;
1968 }
1969
1970 *nspptr = nsp;
1971 *index = eth_port->eth_index;
1972
1973 return 0;
1974 }
1975
1976 static int
nfp_net_get_port_mac_by_hwinfo(struct net_device * netdev,u8 * mac_addr)1977 nfp_net_get_port_mac_by_hwinfo(struct net_device *netdev,
1978 u8 *mac_addr)
1979 {
1980 char hwinfo[32] = {};
1981 struct nfp_nsp *nsp;
1982 u32 index;
1983 int err;
1984
1985 err = nfp_net_get_nsp_hwindex(netdev, &nsp, &index);
1986 if (err)
1987 return err;
1988
1989 snprintf(hwinfo, sizeof(hwinfo), "eth%u.mac", index);
1990 err = nfp_nsp_hwinfo_lookup(nsp, hwinfo, sizeof(hwinfo));
1991 nfp_nsp_close(nsp);
1992 if (err) {
1993 netdev_err(netdev, "Reading persistent MAC address failed: %d\n",
1994 err);
1995 return -EOPNOTSUPP;
1996 }
1997
1998 if (sscanf(hwinfo, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
1999 &mac_addr[0], &mac_addr[1], &mac_addr[2],
2000 &mac_addr[3], &mac_addr[4], &mac_addr[5]) != 6) {
2001 netdev_err(netdev, "Can't parse persistent MAC address (%s)\n",
2002 hwinfo);
2003 return -EOPNOTSUPP;
2004 }
2005
2006 return 0;
2007 }
2008
2009 static int
nfp_net_set_port_mac_by_hwinfo(struct net_device * netdev,u8 * mac_addr)2010 nfp_net_set_port_mac_by_hwinfo(struct net_device *netdev,
2011 u8 *mac_addr)
2012 {
2013 char hwinfo[32] = {};
2014 struct nfp_nsp *nsp;
2015 u32 index;
2016 int err;
2017
2018 err = nfp_net_get_nsp_hwindex(netdev, &nsp, &index);
2019 if (err)
2020 return err;
2021
2022 snprintf(hwinfo, sizeof(hwinfo),
2023 "eth%u.mac=%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx",
2024 index, mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3],
2025 mac_addr[4], mac_addr[5]);
2026
2027 err = nfp_nsp_hwinfo_set(nsp, hwinfo, sizeof(hwinfo));
2028 nfp_nsp_close(nsp);
2029 if (err) {
2030 netdev_err(netdev, "HWinfo set failed: %d, hwinfo: %s\n",
2031 err, hwinfo);
2032 return -EOPNOTSUPP;
2033 }
2034
2035 return 0;
2036 }
2037
2038 static int
nfp_net_get_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * bytes)2039 nfp_net_get_eeprom(struct net_device *netdev,
2040 struct ethtool_eeprom *eeprom, u8 *bytes)
2041 {
2042 struct nfp_app *app = nfp_app_from_netdev(netdev);
2043 u8 buf[NFP_EEPROM_LEN] = {};
2044
2045 if (nfp_net_get_port_mac_by_hwinfo(netdev, buf))
2046 return -EOPNOTSUPP;
2047
2048 if (eeprom->len == 0)
2049 return -EINVAL;
2050
2051 eeprom->magic = app->pdev->vendor | (app->pdev->device << 16);
2052 memcpy(bytes, buf + eeprom->offset, eeprom->len);
2053
2054 return 0;
2055 }
2056
2057 static int
nfp_net_set_eeprom(struct net_device * netdev,struct ethtool_eeprom * eeprom,u8 * bytes)2058 nfp_net_set_eeprom(struct net_device *netdev,
2059 struct ethtool_eeprom *eeprom, u8 *bytes)
2060 {
2061 struct nfp_app *app = nfp_app_from_netdev(netdev);
2062 u8 buf[NFP_EEPROM_LEN] = {};
2063
2064 if (nfp_net_get_port_mac_by_hwinfo(netdev, buf))
2065 return -EOPNOTSUPP;
2066
2067 if (eeprom->len == 0)
2068 return -EINVAL;
2069
2070 if (eeprom->magic != (app->pdev->vendor | app->pdev->device << 16))
2071 return -EINVAL;
2072
2073 memcpy(buf + eeprom->offset, bytes, eeprom->len);
2074 if (nfp_net_set_port_mac_by_hwinfo(netdev, buf))
2075 return -EOPNOTSUPP;
2076
2077 return 0;
2078 }
2079
2080 static const struct ethtool_ops nfp_net_ethtool_ops = {
2081 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
2082 ETHTOOL_COALESCE_MAX_FRAMES |
2083 ETHTOOL_COALESCE_USE_ADAPTIVE,
2084 .get_drvinfo = nfp_net_get_drvinfo,
2085 .nway_reset = nfp_net_nway_reset,
2086 .get_link = ethtool_op_get_link,
2087 .get_ringparam = nfp_net_get_ringparam,
2088 .set_ringparam = nfp_net_set_ringparam,
2089 .self_test = nfp_net_self_test,
2090 .get_strings = nfp_net_get_strings,
2091 .get_ethtool_stats = nfp_net_get_stats,
2092 .get_sset_count = nfp_net_get_sset_count,
2093 .get_rxnfc = nfp_net_get_rxnfc,
2094 .set_rxnfc = nfp_net_set_rxnfc,
2095 .get_rxfh_indir_size = nfp_net_get_rxfh_indir_size,
2096 .get_rxfh_key_size = nfp_net_get_rxfh_key_size,
2097 .get_rxfh = nfp_net_get_rxfh,
2098 .set_rxfh = nfp_net_set_rxfh,
2099 .get_regs_len = nfp_net_get_regs_len,
2100 .get_regs = nfp_net_get_regs,
2101 .set_dump = nfp_app_set_dump,
2102 .get_dump_flag = nfp_app_get_dump_flag,
2103 .get_dump_data = nfp_app_get_dump_data,
2104 .get_eeprom_len = nfp_net_get_eeprom_len,
2105 .get_eeprom = nfp_net_get_eeprom,
2106 .set_eeprom = nfp_net_set_eeprom,
2107 .get_module_info = nfp_port_get_module_info,
2108 .get_module_eeprom = nfp_port_get_module_eeprom,
2109 .get_coalesce = nfp_net_get_coalesce,
2110 .set_coalesce = nfp_net_set_coalesce,
2111 .get_channels = nfp_net_get_channels,
2112 .set_channels = nfp_net_set_channels,
2113 .get_link_ksettings = nfp_net_get_link_ksettings,
2114 .set_link_ksettings = nfp_net_set_link_ksettings,
2115 .get_fecparam = nfp_port_get_fecparam,
2116 .set_fecparam = nfp_port_set_fecparam,
2117 .get_pauseparam = nfp_port_get_pauseparam,
2118 .set_phys_id = nfp_net_set_phys_id,
2119 };
2120
2121 const struct ethtool_ops nfp_port_ethtool_ops = {
2122 .get_drvinfo = nfp_app_get_drvinfo,
2123 .nway_reset = nfp_net_nway_reset,
2124 .get_link = ethtool_op_get_link,
2125 .get_strings = nfp_port_get_strings,
2126 .get_ethtool_stats = nfp_port_get_stats,
2127 .self_test = nfp_net_self_test,
2128 .get_sset_count = nfp_port_get_sset_count,
2129 .set_dump = nfp_app_set_dump,
2130 .get_dump_flag = nfp_app_get_dump_flag,
2131 .get_dump_data = nfp_app_get_dump_data,
2132 .get_eeprom_len = nfp_net_get_eeprom_len,
2133 .get_eeprom = nfp_net_get_eeprom,
2134 .set_eeprom = nfp_net_set_eeprom,
2135 .get_module_info = nfp_port_get_module_info,
2136 .get_module_eeprom = nfp_port_get_module_eeprom,
2137 .get_link_ksettings = nfp_net_get_link_ksettings,
2138 .set_link_ksettings = nfp_net_set_link_ksettings,
2139 .get_fecparam = nfp_port_get_fecparam,
2140 .set_fecparam = nfp_port_set_fecparam,
2141 .get_pauseparam = nfp_port_get_pauseparam,
2142 .set_phys_id = nfp_net_set_phys_id,
2143 };
2144
nfp_net_set_ethtool_ops(struct net_device * netdev)2145 void nfp_net_set_ethtool_ops(struct net_device *netdev)
2146 {
2147 netdev->ethtool_ops = &nfp_net_ethtool_ops;
2148 }
2149