1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
2 /* Copyright 2017-2019 NXP */
3
4 #include <linux/ethtool_netlink.h>
5 #include <linux/net_tstamp.h>
6 #include <linux/module.h>
7 #include <linux/of.h>
8 #include <linux/ptp_clock_kernel.h>
9
10 #include "enetc.h"
11
12 static const u32 enetc_si_regs[] = {
13 ENETC_SIMR, ENETC_SIPMAR0, ENETC_SIPMAR1, ENETC_SICBDRMR,
14 ENETC_SICBDRSR, ENETC_SICBDRBAR0, ENETC_SICBDRBAR1, ENETC_SICBDRPIR,
15 ENETC_SICBDRCIR, ENETC_SICBDRLENR, ENETC_SICAPR0, ENETC_SICAPR1,
16 ENETC_SIUEFDCR
17 };
18
19 static const u32 enetc_txbdr_regs[] = {
20 ENETC_TBMR, ENETC_TBSR, ENETC_TBBAR0, ENETC_TBBAR1,
21 ENETC_TBPIR, ENETC_TBCIR, ENETC_TBLENR, ENETC_TBIER, ENETC_TBICR0,
22 ENETC_TBICR1
23 };
24
25 static const u32 enetc_rxbdr_regs[] = {
26 ENETC_RBMR, ENETC_RBSR, ENETC_RBBSR, ENETC_RBCIR, ENETC_RBBAR0,
27 ENETC_RBBAR1, ENETC_RBPIR, ENETC_RBLENR, ENETC_RBIER, ENETC_RBICR0,
28 ENETC_RBICR1
29 };
30
31 static const u32 enetc_port_regs[] = {
32 ENETC_PMR, ENETC_PSR, ENETC_PSIPMR, ENETC_PSIPMAR0(0),
33 ENETC_PSIPMAR1(0), ENETC_PTXMBAR, ENETC_PCAPR0, ENETC_PCAPR1,
34 ENETC_PSICFGR0(0), ENETC_PRFSCAPR, ENETC_PTCMSDUR(0),
35 ENETC_PM0_CMD_CFG, ENETC_PM0_MAXFRM, ENETC_PM0_IF_MODE
36 };
37
38 static const u32 enetc_port_mm_regs[] = {
39 ENETC_MMCSR, ENETC_PFPMR, ENETC_PTCFPR(0), ENETC_PTCFPR(1),
40 ENETC_PTCFPR(2), ENETC_PTCFPR(3), ENETC_PTCFPR(4), ENETC_PTCFPR(5),
41 ENETC_PTCFPR(6), ENETC_PTCFPR(7),
42 };
43
enetc_get_reglen(struct net_device * ndev)44 static int enetc_get_reglen(struct net_device *ndev)
45 {
46 struct enetc_ndev_priv *priv = netdev_priv(ndev);
47 struct enetc_hw *hw = &priv->si->hw;
48 int len;
49
50 len = ARRAY_SIZE(enetc_si_regs);
51 len += ARRAY_SIZE(enetc_txbdr_regs) * priv->num_tx_rings;
52 len += ARRAY_SIZE(enetc_rxbdr_regs) * priv->num_rx_rings;
53
54 if (hw->port)
55 len += ARRAY_SIZE(enetc_port_regs);
56
57 if (hw->port && !!(priv->si->hw_features & ENETC_SI_F_QBU))
58 len += ARRAY_SIZE(enetc_port_mm_regs);
59
60 len *= sizeof(u32) * 2; /* store 2 entries per reg: addr and value */
61
62 return len;
63 }
64
enetc_get_regs(struct net_device * ndev,struct ethtool_regs * regs,void * regbuf)65 static void enetc_get_regs(struct net_device *ndev, struct ethtool_regs *regs,
66 void *regbuf)
67 {
68 struct enetc_ndev_priv *priv = netdev_priv(ndev);
69 struct enetc_hw *hw = &priv->si->hw;
70 u32 *buf = (u32 *)regbuf;
71 int i, j;
72 u32 addr;
73
74 for (i = 0; i < ARRAY_SIZE(enetc_si_regs); i++) {
75 *buf++ = enetc_si_regs[i];
76 *buf++ = enetc_rd(hw, enetc_si_regs[i]);
77 }
78
79 for (i = 0; i < priv->num_tx_rings; i++) {
80 for (j = 0; j < ARRAY_SIZE(enetc_txbdr_regs); j++) {
81 addr = ENETC_BDR(TX, i, enetc_txbdr_regs[j]);
82
83 *buf++ = addr;
84 *buf++ = enetc_rd(hw, addr);
85 }
86 }
87
88 for (i = 0; i < priv->num_rx_rings; i++) {
89 for (j = 0; j < ARRAY_SIZE(enetc_rxbdr_regs); j++) {
90 addr = ENETC_BDR(RX, i, enetc_rxbdr_regs[j]);
91
92 *buf++ = addr;
93 *buf++ = enetc_rd(hw, addr);
94 }
95 }
96
97 if (!hw->port)
98 return;
99
100 for (i = 0; i < ARRAY_SIZE(enetc_port_regs); i++) {
101 addr = ENETC_PORT_BASE + enetc_port_regs[i];
102 *buf++ = addr;
103 *buf++ = enetc_rd(hw, addr);
104 }
105
106 if (priv->si->hw_features & ENETC_SI_F_QBU) {
107 for (i = 0; i < ARRAY_SIZE(enetc_port_mm_regs); i++) {
108 addr = ENETC_PORT_BASE + enetc_port_mm_regs[i];
109 *buf++ = addr;
110 *buf++ = enetc_rd(hw, addr);
111 }
112 }
113 }
114
115 static const struct {
116 int reg;
117 char name[ETH_GSTRING_LEN];
118 } enetc_si_counters[] = {
119 { ENETC_SIROCT, "SI rx octets" },
120 { ENETC_SIRFRM, "SI rx frames" },
121 { ENETC_SIRUCA, "SI rx u-cast frames" },
122 { ENETC_SIRMCA, "SI rx m-cast frames" },
123 { ENETC_SITOCT, "SI tx octets" },
124 { ENETC_SITFRM, "SI tx frames" },
125 { ENETC_SITUCA, "SI tx u-cast frames" },
126 { ENETC_SITMCA, "SI tx m-cast frames" },
127 };
128
129 static const struct {
130 int reg;
131 char name[ETH_GSTRING_LEN] __nonstring;
132 } enetc_emac_counters[] = {
133 { ENETC_PM_RVLAN(0), "eMAC rx VLAN frames" },
134 { ENETC_PM_RERR(0), "eMAC rx frame errors" },
135 { ENETC_PM_RUCA(0), "eMAC rx unicast frames" },
136 { ENETC_PM_RDRP(0), "eMAC rx dropped packets" },
137 { ENETC_PM_RPKT(0), "eMAC rx packets" },
138 { ENETC_PM_TOCT(0), "eMAC tx octets" },
139 { ENETC_PM_TFCS(0), "eMAC tx fcs errors" },
140 { ENETC_PM_TVLAN(0), "eMAC tx VLAN frames" },
141 { ENETC_PM_TUCA(0), "eMAC tx unicast frames" },
142 { ENETC_PM_TPKT(0), "eMAC tx packets" },
143 { ENETC_PM_TUND(0), "eMAC tx undersized packets" },
144 };
145
146 static const struct {
147 int reg;
148 char name[ETH_GSTRING_LEN] __nonstring;
149 } enetc_pmac_counters[] = {
150 { ENETC_PM_RVLAN(1), "pMAC rx VLAN frames" },
151 { ENETC_PM_RERR(1), "pMAC rx frame errors" },
152 { ENETC_PM_RUCA(1), "pMAC rx unicast frames" },
153 { ENETC_PM_RDRP(1), "pMAC rx dropped packets" },
154 { ENETC_PM_RPKT(1), "pMAC rx packets" },
155 { ENETC_PM_TOCT(1), "pMAC tx octets" },
156 { ENETC_PM_TFCS(1), "pMAC tx fcs errors" },
157 { ENETC_PM_TVLAN(1), "pMAC tx VLAN frames" },
158 { ENETC_PM_TUCA(1), "pMAC tx unicast frames" },
159 { ENETC_PM_TPKT(1), "pMAC tx packets" },
160 { ENETC_PM_TUND(1), "pMAC tx undersized packets" },
161 };
162
163 static const struct {
164 int reg;
165 char name[ETH_GSTRING_LEN] __nonstring;
166 } enetc_port_counters[] = {
167 { ENETC_UFDMF, "SI MAC nomatch u-cast discards" },
168 { ENETC_MFDMF, "SI MAC nomatch m-cast discards" },
169 { ENETC_PBFDSIR, "SI MAC nomatch b-cast discards" },
170 { ENETC_PUFDVFR, "SI VLAN nomatch u-cast discards" },
171 { ENETC_PMFDVFR, "SI VLAN nomatch m-cast discards" },
172 { ENETC_PBFDVFR, "SI VLAN nomatch b-cast discards" },
173 { ENETC_PFDMSAPR, "SI pruning discarded frames" },
174 { ENETC_PICDR(0), "ICM DR0 discarded frames" },
175 { ENETC_PICDR(1), "ICM DR1 discarded frames" },
176 { ENETC_PICDR(2), "ICM DR2 discarded frames" },
177 { ENETC_PICDR(3), "ICM DR3 discarded frames" },
178 };
179
180 static const struct {
181 int reg;
182 char name[ETH_GSTRING_LEN] __nonstring;
183 } enetc4_emac_counters[] = {
184 { ENETC4_PM_ROCT(0), "eMAC rx octets" },
185 { ENETC4_PM_RVLAN(0), "eMAC rx VLAN frames" },
186 { ENETC4_PM_RERR(0), "eMAC rx frame errors" },
187 { ENETC4_PM_RUCA(0), "eMAC rx unicast frames" },
188 { ENETC4_PM_RDRP(0), "eMAC rx dropped packets" },
189 { ENETC4_PM_RPKT(0), "eMAC rx packets" },
190 { ENETC4_PM_TOCT(0), "eMAC tx octets" },
191 { ENETC4_PM_TVLAN(0), "eMAC tx VLAN frames" },
192 { ENETC4_PM_TFCS(0), "eMAC tx fcs errors" },
193 { ENETC4_PM_TUCA(0), "eMAC tx unicast frames" },
194 { ENETC4_PM_TPKT(0), "eMAC tx packets" },
195 { ENETC4_PM_TUND(0), "eMAC tx undersized packets" },
196 { ENETC4_PM_TIOCT(0), "eMAC tx invalid octets" },
197 };
198
199 static const struct {
200 int reg;
201 char name[ETH_GSTRING_LEN] __nonstring;
202 } enetc4_pmac_counters[] = {
203 { ENETC4_PM_ROCT(1), "pMAC rx octets" },
204 { ENETC4_PM_RVLAN(1), "pMAC rx VLAN frames" },
205 { ENETC4_PM_RERR(1), "pMAC rx frame errors" },
206 { ENETC4_PM_RUCA(1), "pMAC rx unicast frames" },
207 { ENETC4_PM_RDRP(1), "pMAC rx dropped packets" },
208 { ENETC4_PM_RPKT(1), "pMAC rx packets" },
209 { ENETC4_PM_TOCT(1), "pMAC tx octets" },
210 { ENETC4_PM_TVLAN(1), "pMAC tx VLAN frames" },
211 { ENETC4_PM_TFCS(1), "pMAC tx fcs errors" },
212 { ENETC4_PM_TUCA(1), "pMAC tx unicast frames" },
213 { ENETC4_PM_TPKT(1), "pMAC tx packets" },
214 { ENETC4_PM_TUND(1), "pMAC tx undersized packets" },
215 { ENETC4_PM_TIOCT(1), "pMAC tx invalid octets" },
216 };
217
218 static const struct {
219 int reg;
220 char name[ETH_GSTRING_LEN] __nonstring;
221 } enetc4_port_counters[] = {
222 { ENETC4_PICDRDCR(0), "ICM DR0 discarded frames" },
223 { ENETC4_PICDRDCR(1), "ICM DR1 discarded frames" },
224 { ENETC4_PICDRDCR(2), "ICM DR2 discarded frames" },
225 { ENETC4_PICDRDCR(3), "ICM DR3 discarded frames" },
226 { ENETC4_PUFDMFR, "MAC filter discarded unicast" },
227 { ENETC4_PMFDMFR, "MAC filter discarded multicast" },
228 { ENETC4_PBFDSIR, "MAC filter discarded broadcast" },
229 { ENETC4_PFDMSAPR, "MAC SA pruning discarded frames" },
230 { ENETC4_PUFDVFR, "VLAN filter discarded unicast" },
231 { ENETC4_PMFDVFR, "VLAN filter discarded multicast" },
232 { ENETC4_PBFDVFR, "VLAN filter discarded broadcast" },
233 { ENETC4_PRXDCR, "MAC rx discarded frames" },
234 { ENETC4_PRXDCRRR, "MAC rx discard read-reset" },
235 { ENETC4_PRXDCRR0, "MAC rx discard reason 0" },
236 { ENETC4_PRXDCRR1, "MAC rx discard reason 1" },
237 };
238
239 static const char rx_ring_stats[][ETH_GSTRING_LEN] = {
240 "Rx ring %2d frames",
241 "Rx ring %2d alloc errors",
242 "Rx ring %2d XDP drops",
243 "Rx ring %2d recycles",
244 "Rx ring %2d recycle failures",
245 "Rx ring %2d redirects",
246 "Rx ring %2d redirect failures",
247 "Rx ring %2d discarded frames",
248 };
249
250 static const char tx_ring_stats[][ETH_GSTRING_LEN] = {
251 "Tx ring %2d frames",
252 "Tx ring %2d XDP frames",
253 "Tx ring %2d XDP drops",
254 "Tx window drop %2d frames",
255 };
256
enetc_get_sset_count(struct net_device * ndev,int sset)257 static int enetc_get_sset_count(struct net_device *ndev, int sset)
258 {
259 struct enetc_ndev_priv *priv = netdev_priv(ndev);
260 struct enetc_si *si = priv->si;
261 int len;
262
263 if (sset != ETH_SS_STATS)
264 return -EOPNOTSUPP;
265
266 len = ARRAY_SIZE(enetc_si_counters) +
267 ARRAY_SIZE(tx_ring_stats) * priv->num_tx_rings +
268 ARRAY_SIZE(rx_ring_stats) * priv->num_rx_rings;
269
270 if (!enetc_si_is_pf(si))
271 return len;
272
273 if (is_enetc_rev1(si)) {
274 len += ARRAY_SIZE(enetc_port_counters);
275 len += ARRAY_SIZE(enetc_emac_counters);
276 if (si->hw_features & ENETC_SI_F_QBU)
277 len += ARRAY_SIZE(enetc_pmac_counters);
278 } else {
279 len += ARRAY_SIZE(enetc4_port_counters);
280
281 if (enetc_is_pseudo_mac(si))
282 return len;
283
284 len += ARRAY_SIZE(enetc4_emac_counters);
285 if (si->hw_features & ENETC_SI_F_QBU)
286 len += ARRAY_SIZE(enetc4_pmac_counters);
287 }
288
289 return len;
290 }
291
enetc_get_pf_strings(struct enetc_si * si,u8 * data)292 static void enetc_get_pf_strings(struct enetc_si *si, u8 *data)
293 {
294 int i;
295
296 for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
297 ethtool_cpy(&data, enetc_port_counters[i].name);
298
299 for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
300 ethtool_cpy(&data, enetc_emac_counters[i].name);
301
302 if (!(si->hw_features & ENETC_SI_F_QBU))
303 return;
304
305 for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
306 ethtool_cpy(&data, enetc_pmac_counters[i].name);
307 }
308
enetc4_get_pf_strings(struct enetc_si * si,u8 * data)309 static void enetc4_get_pf_strings(struct enetc_si *si, u8 *data)
310 {
311 int i;
312
313 for (i = 0; i < ARRAY_SIZE(enetc4_port_counters); i++)
314 ethtool_cpy(&data, enetc4_port_counters[i].name);
315
316 if (enetc_is_pseudo_mac(si))
317 return;
318
319 for (i = 0; i < ARRAY_SIZE(enetc4_emac_counters); i++)
320 ethtool_cpy(&data, enetc4_emac_counters[i].name);
321
322 if (!(si->hw_features & ENETC_SI_F_QBU))
323 return;
324
325 for (i = 0; i < ARRAY_SIZE(enetc4_pmac_counters); i++)
326 ethtool_cpy(&data, enetc4_pmac_counters[i].name);
327 }
328
enetc_get_strings(struct net_device * ndev,u32 stringset,u8 * data)329 static void enetc_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
330 {
331 struct enetc_ndev_priv *priv = netdev_priv(ndev);
332 struct enetc_si *si = priv->si;
333 int i, j;
334
335 switch (stringset) {
336 case ETH_SS_STATS:
337 for (i = 0; i < ARRAY_SIZE(enetc_si_counters); i++)
338 ethtool_puts(&data, enetc_si_counters[i].name);
339 for (i = 0; i < priv->num_tx_rings; i++)
340 for (j = 0; j < ARRAY_SIZE(tx_ring_stats); j++)
341 ethtool_sprintf(&data, tx_ring_stats[j], i);
342 for (i = 0; i < priv->num_rx_rings; i++)
343 for (j = 0; j < ARRAY_SIZE(rx_ring_stats); j++)
344 ethtool_sprintf(&data, rx_ring_stats[j], i);
345
346 if (!enetc_si_is_pf(si))
347 break;
348
349 if (is_enetc_rev1(si))
350 enetc_get_pf_strings(si, data);
351 else
352 enetc4_get_pf_strings(si, data);
353
354 break;
355 }
356 }
357
enetc_pf_get_ethtool_stats(struct enetc_si * si,int * o,u64 * data)358 static void enetc_pf_get_ethtool_stats(struct enetc_si *si, int *o, u64 *data)
359 {
360 struct enetc_hw *hw = &si->hw;
361 int i;
362
363 for (i = 0; i < ARRAY_SIZE(enetc_port_counters); i++)
364 data[(*o)++] = enetc_port_rd(hw, enetc_port_counters[i].reg);
365
366 for (i = 0; i < ARRAY_SIZE(enetc_emac_counters); i++)
367 data[(*o)++] = enetc_port_rd64(hw, enetc_emac_counters[i].reg);
368
369 if (!(si->hw_features & ENETC_SI_F_QBU))
370 return;
371
372 for (i = 0; i < ARRAY_SIZE(enetc_pmac_counters); i++)
373 data[(*o)++] = enetc_port_rd64(hw, enetc_pmac_counters[i].reg);
374 }
375
enetc4_pf_get_ethtool_stats(struct enetc_si * si,int * o,u64 * data)376 static void enetc4_pf_get_ethtool_stats(struct enetc_si *si, int *o, u64 *data)
377 {
378 struct enetc_hw *hw = &si->hw;
379 int i;
380
381 for (i = 0; i < ARRAY_SIZE(enetc4_port_counters); i++)
382 data[(*o)++] = enetc_port_rd(hw, enetc4_port_counters[i].reg);
383
384 if (enetc_is_pseudo_mac(si))
385 return;
386
387 for (i = 0; i < ARRAY_SIZE(enetc4_emac_counters); i++)
388 data[(*o)++] = enetc_port_rd64(hw, enetc4_emac_counters[i].reg);
389
390 if (!(si->hw_features & ENETC_SI_F_QBU))
391 return;
392
393 for (i = 0; i < ARRAY_SIZE(enetc4_pmac_counters); i++)
394 data[(*o)++] = enetc_port_rd64(hw, enetc4_pmac_counters[i].reg);
395 }
396
enetc_get_ethtool_stats(struct net_device * ndev,struct ethtool_stats * stats,u64 * data)397 static void enetc_get_ethtool_stats(struct net_device *ndev,
398 struct ethtool_stats *stats, u64 *data)
399 {
400 struct enetc_ndev_priv *priv = netdev_priv(ndev);
401 struct enetc_si *si = priv->si;
402 struct enetc_hw *hw = &si->hw;
403 int i, o = 0;
404
405 for (i = 0; i < ARRAY_SIZE(enetc_si_counters); i++)
406 data[o++] = enetc_rd64(hw, enetc_si_counters[i].reg);
407
408 for (i = 0; i < priv->num_tx_rings; i++) {
409 data[o++] = priv->tx_ring[i]->stats.packets;
410 data[o++] = priv->tx_ring[i]->stats.xdp_tx;
411 data[o++] = priv->tx_ring[i]->stats.xdp_tx_drops;
412 data[o++] = priv->tx_ring[i]->stats.win_drop;
413 }
414
415 for (i = 0; i < priv->num_rx_rings; i++) {
416 data[o++] = priv->rx_ring[i]->stats.packets;
417 data[o++] = priv->rx_ring[i]->stats.rx_alloc_errs;
418 data[o++] = priv->rx_ring[i]->stats.xdp_drops;
419 data[o++] = priv->rx_ring[i]->stats.recycles;
420 data[o++] = priv->rx_ring[i]->stats.recycle_failures;
421 data[o++] = priv->rx_ring[i]->stats.xdp_redirect;
422 data[o++] = priv->rx_ring[i]->stats.xdp_redirect_failures;
423 data[o++] = enetc_rd(hw, ENETC_RBDCR(i));
424 }
425
426 if (!enetc_si_is_pf(si))
427 return;
428
429 if (is_enetc_rev1(si))
430 enetc_pf_get_ethtool_stats(si, &o, data);
431 else
432 enetc4_pf_get_ethtool_stats(si, &o, data);
433 }
434
enetc_pause_stats(struct enetc_si * si,int mac,struct ethtool_pause_stats * pause_stats)435 static void enetc_pause_stats(struct enetc_si *si, int mac,
436 struct ethtool_pause_stats *pause_stats)
437 {
438 struct enetc_hw *hw = &si->hw;
439
440 switch (si->pdev->revision) {
441 case ENETC_REV1:
442 pause_stats->tx_pause_frames = enetc_port_rd64(hw, ENETC_PM_TXPF(mac));
443 pause_stats->rx_pause_frames = enetc_port_rd64(hw, ENETC_PM_RXPF(mac));
444 break;
445 case ENETC_REV4:
446 pause_stats->tx_pause_frames = enetc_port_rd64(hw, ENETC4_PM_TXPF(mac));
447 pause_stats->rx_pause_frames = enetc_port_rd64(hw, ENETC4_PM_RXPF(mac));
448 break;
449 default:
450 break;
451 }
452 }
453
enetc_get_pause_stats(struct net_device * ndev,struct ethtool_pause_stats * pause_stats)454 static void enetc_get_pause_stats(struct net_device *ndev,
455 struct ethtool_pause_stats *pause_stats)
456 {
457 struct enetc_ndev_priv *priv = netdev_priv(ndev);
458 struct enetc_si *si = priv->si;
459
460 switch (pause_stats->src) {
461 case ETHTOOL_MAC_STATS_SRC_EMAC:
462 enetc_pause_stats(si, 0, pause_stats);
463 break;
464 case ETHTOOL_MAC_STATS_SRC_PMAC:
465 if (si->hw_features & ENETC_SI_F_QBU)
466 enetc_pause_stats(si, 1, pause_stats);
467 break;
468 case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
469 ethtool_aggregate_pause_stats(ndev, pause_stats);
470 break;
471 }
472 }
473
enetc_mac_stats(struct enetc_hw * hw,int mac,struct ethtool_eth_mac_stats * s)474 static void enetc_mac_stats(struct enetc_hw *hw, int mac,
475 struct ethtool_eth_mac_stats *s)
476 {
477 s->FramesTransmittedOK = enetc_port_rd64(hw, ENETC_PM_TFRM(mac));
478 s->SingleCollisionFrames = enetc_port_rd64(hw, ENETC_PM_TSCOL(mac));
479 s->MultipleCollisionFrames = enetc_port_rd64(hw, ENETC_PM_TMCOL(mac));
480 s->FramesReceivedOK = enetc_port_rd64(hw, ENETC_PM_RFRM(mac));
481 s->FrameCheckSequenceErrors = enetc_port_rd64(hw, ENETC_PM_RFCS(mac));
482 s->AlignmentErrors = enetc_port_rd64(hw, ENETC_PM_RALN(mac));
483 s->OctetsTransmittedOK = enetc_port_rd64(hw, ENETC_PM_TEOCT(mac));
484 s->FramesWithDeferredXmissions = enetc_port_rd64(hw, ENETC_PM_TDFR(mac));
485 s->LateCollisions = enetc_port_rd64(hw, ENETC_PM_TLCOL(mac));
486 s->FramesAbortedDueToXSColls = enetc_port_rd64(hw, ENETC_PM_TECOL(mac));
487 s->FramesLostDueToIntMACXmitError = enetc_port_rd64(hw, ENETC_PM_TERR(mac));
488 s->CarrierSenseErrors = enetc_port_rd64(hw, ENETC_PM_TCRSE(mac));
489 s->OctetsReceivedOK = enetc_port_rd64(hw, ENETC_PM_REOCT(mac));
490 s->FramesLostDueToIntMACRcvError = enetc_port_rd64(hw, ENETC_PM_RDRNTP(mac));
491 s->MulticastFramesXmittedOK = enetc_port_rd64(hw, ENETC_PM_TMCA(mac));
492 s->BroadcastFramesXmittedOK = enetc_port_rd64(hw, ENETC_PM_TBCA(mac));
493 s->MulticastFramesReceivedOK = enetc_port_rd64(hw, ENETC_PM_RMCA(mac));
494 s->BroadcastFramesReceivedOK = enetc_port_rd64(hw, ENETC_PM_RBCA(mac));
495 }
496
enetc4_mac_stats(struct enetc_hw * hw,int mac,struct ethtool_eth_mac_stats * s)497 static void enetc4_mac_stats(struct enetc_hw *hw, int mac,
498 struct ethtool_eth_mac_stats *s)
499 {
500 s->FramesTransmittedOK = enetc_port_rd64(hw, ENETC4_PM_TFRM(mac));
501 s->SingleCollisionFrames = enetc_port_rd64(hw, ENETC4_PM_TSCOL(mac));
502 s->MultipleCollisionFrames = enetc_port_rd64(hw, ENETC4_PM_TMCOL(mac));
503 s->FramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RFRM(mac));
504 s->FrameCheckSequenceErrors = enetc_port_rd64(hw, ENETC4_PM_RFCS(mac));
505 s->AlignmentErrors = enetc_port_rd64(hw, ENETC4_PM_RALN(mac));
506 s->OctetsTransmittedOK = enetc_port_rd64(hw, ENETC4_PM_TEOCT(mac));
507 s->FramesWithDeferredXmissions = enetc_port_rd64(hw, ENETC4_PM_TDFR(mac));
508 s->LateCollisions = enetc_port_rd64(hw, ENETC4_PM_TLCOL(mac));
509 s->FramesAbortedDueToXSColls = enetc_port_rd64(hw, ENETC4_PM_TECOL(mac));
510 s->FramesLostDueToIntMACXmitError = enetc_port_rd64(hw, ENETC4_PM_TERR(mac));
511 s->OctetsReceivedOK = enetc_port_rd64(hw, ENETC4_PM_REOCT(mac));
512 s->FramesLostDueToIntMACRcvError = enetc_port_rd64(hw, ENETC4_PM_RDRNTP(mac));
513 s->MulticastFramesXmittedOK = enetc_port_rd64(hw, ENETC4_PM_TMCA(mac));
514 s->BroadcastFramesXmittedOK = enetc_port_rd64(hw, ENETC4_PM_TBCA(mac));
515 s->MulticastFramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RMCA(mac));
516 s->BroadcastFramesReceivedOK = enetc_port_rd64(hw, ENETC4_PM_RBCA(mac));
517 }
518
enetc_ctrl_stats(struct enetc_si * si,int mac,struct ethtool_eth_ctrl_stats * s)519 static void enetc_ctrl_stats(struct enetc_si *si, int mac,
520 struct ethtool_eth_ctrl_stats *s)
521 {
522 struct enetc_hw *hw = &si->hw;
523
524 switch (si->pdev->revision) {
525 case ENETC_REV1:
526 s->MACControlFramesTransmitted = enetc_port_rd64(hw, ENETC_PM_TCNP(mac));
527 s->MACControlFramesReceived = enetc_port_rd64(hw, ENETC_PM_RCNP(mac));
528 break;
529 case ENETC_REV4:
530 s->MACControlFramesTransmitted = enetc_port_rd64(hw, ENETC4_PM_TCNP(mac));
531 s->MACControlFramesReceived = enetc_port_rd64(hw, ENETC4_PM_RCNP(mac));
532 break;
533 default:
534 break;
535 }
536 }
537
538 static const struct ethtool_rmon_hist_range enetc_rmon_ranges[] = {
539 { 64, 64 },
540 { 65, 127 },
541 { 128, 255 },
542 { 256, 511 },
543 { 512, 1023 },
544 { 1024, 1522 },
545 { 1523, ENETC_MAC_MAXFRM_SIZE },
546 {},
547 };
548
enetc_rmon_stats(struct enetc_hw * hw,int mac,struct ethtool_rmon_stats * s)549 static void enetc_rmon_stats(struct enetc_hw *hw, int mac,
550 struct ethtool_rmon_stats *s)
551 {
552 s->undersize_pkts = enetc_port_rd64(hw, ENETC_PM_RUND(mac));
553 s->oversize_pkts = enetc_port_rd64(hw, ENETC_PM_ROVR(mac));
554 s->fragments = enetc_port_rd64(hw, ENETC_PM_RFRG(mac));
555 s->jabbers = enetc_port_rd64(hw, ENETC_PM_RJBR(mac));
556
557 s->hist[0] = enetc_port_rd64(hw, ENETC_PM_R64(mac));
558 s->hist[1] = enetc_port_rd64(hw, ENETC_PM_R127(mac));
559 s->hist[2] = enetc_port_rd64(hw, ENETC_PM_R255(mac));
560 s->hist[3] = enetc_port_rd64(hw, ENETC_PM_R511(mac));
561 s->hist[4] = enetc_port_rd64(hw, ENETC_PM_R1023(mac));
562 s->hist[5] = enetc_port_rd64(hw, ENETC_PM_R1522(mac));
563 s->hist[6] = enetc_port_rd64(hw, ENETC_PM_R1523X(mac));
564
565 s->hist_tx[0] = enetc_port_rd64(hw, ENETC_PM_T64(mac));
566 s->hist_tx[1] = enetc_port_rd64(hw, ENETC_PM_T127(mac));
567 s->hist_tx[2] = enetc_port_rd64(hw, ENETC_PM_T255(mac));
568 s->hist_tx[3] = enetc_port_rd64(hw, ENETC_PM_T511(mac));
569 s->hist_tx[4] = enetc_port_rd64(hw, ENETC_PM_T1023(mac));
570 s->hist_tx[5] = enetc_port_rd64(hw, ENETC_PM_T1522(mac));
571 s->hist_tx[6] = enetc_port_rd64(hw, ENETC_PM_T1523X(mac));
572 }
573
enetc4_rmon_stats(struct enetc_hw * hw,int mac,struct ethtool_rmon_stats * s)574 static void enetc4_rmon_stats(struct enetc_hw *hw, int mac,
575 struct ethtool_rmon_stats *s)
576 {
577 s->undersize_pkts = enetc_port_rd64(hw, ENETC4_PM_RUND(mac));
578 s->oversize_pkts = enetc_port_rd64(hw, ENETC4_PM_ROVR(mac));
579 s->fragments = enetc_port_rd64(hw, ENETC4_PM_RFRG(mac));
580 s->jabbers = enetc_port_rd64(hw, ENETC4_PM_RJBR(mac));
581
582 s->hist[0] = enetc_port_rd64(hw, ENETC4_PM_R64(mac));
583 s->hist[1] = enetc_port_rd64(hw, ENETC4_PM_R127(mac));
584 s->hist[2] = enetc_port_rd64(hw, ENETC4_PM_R255(mac));
585 s->hist[3] = enetc_port_rd64(hw, ENETC4_PM_R511(mac));
586 s->hist[4] = enetc_port_rd64(hw, ENETC4_PM_R1023(mac));
587 s->hist[5] = enetc_port_rd64(hw, ENETC4_PM_R1522(mac));
588 s->hist[6] = enetc_port_rd64(hw, ENETC4_PM_R1523X(mac));
589
590 s->hist_tx[0] = enetc_port_rd64(hw, ENETC4_PM_T64(mac));
591 s->hist_tx[1] = enetc_port_rd64(hw, ENETC4_PM_T127(mac));
592 s->hist_tx[2] = enetc_port_rd64(hw, ENETC4_PM_T255(mac));
593 s->hist_tx[3] = enetc_port_rd64(hw, ENETC4_PM_T511(mac));
594 s->hist_tx[4] = enetc_port_rd64(hw, ENETC4_PM_T1023(mac));
595 s->hist_tx[5] = enetc_port_rd64(hw, ENETC4_PM_T1522(mac));
596 s->hist_tx[6] = enetc_port_rd64(hw, ENETC4_PM_T1523X(mac));
597 }
598
enetc_get_mac_stats(struct enetc_si * si,int mac,struct ethtool_eth_mac_stats * mac_stats)599 static void enetc_get_mac_stats(struct enetc_si *si, int mac,
600 struct ethtool_eth_mac_stats *mac_stats)
601 {
602 struct enetc_hw *hw = &si->hw;
603
604 switch (si->pdev->revision) {
605 case ENETC_REV1:
606 enetc_mac_stats(hw, mac, mac_stats);
607 break;
608 case ENETC_REV4:
609 enetc4_mac_stats(hw, mac, mac_stats);
610 break;
611 default:
612 break;
613 }
614 }
615
enetc_get_eth_mac_stats(struct net_device * ndev,struct ethtool_eth_mac_stats * mac_stats)616 static void enetc_get_eth_mac_stats(struct net_device *ndev,
617 struct ethtool_eth_mac_stats *mac_stats)
618 {
619 struct enetc_ndev_priv *priv = netdev_priv(ndev);
620 struct enetc_si *si = priv->si;
621
622 switch (mac_stats->src) {
623 case ETHTOOL_MAC_STATS_SRC_EMAC:
624 enetc_get_mac_stats(si, 0, mac_stats);
625 break;
626 case ETHTOOL_MAC_STATS_SRC_PMAC:
627 if (si->hw_features & ENETC_SI_F_QBU)
628 enetc_get_mac_stats(si, 1, mac_stats);
629 break;
630 case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
631 ethtool_aggregate_mac_stats(ndev, mac_stats);
632 break;
633 }
634 }
635
enetc_ppm_mac_stats(struct enetc_si * si,struct ethtool_eth_mac_stats * s)636 static void enetc_ppm_mac_stats(struct enetc_si *si,
637 struct ethtool_eth_mac_stats *s)
638 {
639 struct enetc_hw *hw = &si->hw;
640 u64 rufcr, rmfcr, rbfcr;
641 u64 tufcr, tmfcr, tbfcr;
642
643 rufcr = enetc_port_rd64(hw, ENETC4_PPMRUFCR);
644 rmfcr = enetc_port_rd64(hw, ENETC4_PPMRMFCR);
645 rbfcr = enetc_port_rd64(hw, ENETC4_PPMRBFCR);
646
647 tufcr = enetc_port_rd64(hw, ENETC4_PPMTUFCR);
648 tmfcr = enetc_port_rd64(hw, ENETC4_PPMTMFCR);
649 tbfcr = enetc_port_rd64(hw, ENETC4_PPMTBFCR);
650
651 s->FramesTransmittedOK = tufcr + tmfcr + tbfcr;
652 s->FramesReceivedOK = rufcr + rmfcr + rbfcr;
653 s->OctetsTransmittedOK = enetc_port_rd64(hw, ENETC4_PPMTOCR);
654 s->OctetsReceivedOK = enetc_port_rd64(hw, ENETC4_PPMROCR);
655 s->MulticastFramesXmittedOK = tmfcr;
656 s->BroadcastFramesXmittedOK = tbfcr;
657 s->MulticastFramesReceivedOK = rmfcr;
658 s->BroadcastFramesReceivedOK = rbfcr;
659 }
660
enetc_ppm_get_eth_mac_stats(struct net_device * ndev,struct ethtool_eth_mac_stats * mac_stats)661 static void enetc_ppm_get_eth_mac_stats(struct net_device *ndev,
662 struct ethtool_eth_mac_stats *mac_stats)
663 {
664 struct enetc_ndev_priv *priv = netdev_priv(ndev);
665
666 switch (mac_stats->src) {
667 case ETHTOOL_MAC_STATS_SRC_EMAC:
668 enetc_ppm_mac_stats(priv->si, mac_stats);
669 break;
670 case ETHTOOL_MAC_STATS_SRC_PMAC:
671 break;
672 case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
673 ethtool_aggregate_mac_stats(ndev, mac_stats);
674 break;
675 }
676 }
677
enetc_get_eth_ctrl_stats(struct net_device * ndev,struct ethtool_eth_ctrl_stats * ctrl_stats)678 static void enetc_get_eth_ctrl_stats(struct net_device *ndev,
679 struct ethtool_eth_ctrl_stats *ctrl_stats)
680 {
681 struct enetc_ndev_priv *priv = netdev_priv(ndev);
682 struct enetc_si *si = priv->si;
683
684 switch (ctrl_stats->src) {
685 case ETHTOOL_MAC_STATS_SRC_EMAC:
686 enetc_ctrl_stats(si, 0, ctrl_stats);
687 break;
688 case ETHTOOL_MAC_STATS_SRC_PMAC:
689 if (si->hw_features & ENETC_SI_F_QBU)
690 enetc_ctrl_stats(si, 1, ctrl_stats);
691 break;
692 case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
693 ethtool_aggregate_ctrl_stats(ndev, ctrl_stats);
694 break;
695 }
696 }
697
enetc_get_mac_rmon_stats(struct enetc_si * si,int mac,struct ethtool_rmon_stats * rmon_stats)698 static void enetc_get_mac_rmon_stats(struct enetc_si *si, int mac,
699 struct ethtool_rmon_stats *rmon_stats)
700 {
701 struct enetc_hw *hw = &si->hw;
702
703 switch (si->pdev->revision) {
704 case ENETC_REV1:
705 enetc_rmon_stats(hw, mac, rmon_stats);
706 break;
707 case ENETC_REV4:
708 enetc4_rmon_stats(hw, mac, rmon_stats);
709 break;
710 default:
711 break;
712 }
713 }
714
enetc_get_rmon_stats(struct net_device * ndev,struct ethtool_rmon_stats * rmon_stats,const struct ethtool_rmon_hist_range ** ranges)715 static void enetc_get_rmon_stats(struct net_device *ndev,
716 struct ethtool_rmon_stats *rmon_stats,
717 const struct ethtool_rmon_hist_range **ranges)
718 {
719 struct enetc_ndev_priv *priv = netdev_priv(ndev);
720 struct enetc_si *si = priv->si;
721
722 *ranges = enetc_rmon_ranges;
723
724 switch (rmon_stats->src) {
725 case ETHTOOL_MAC_STATS_SRC_EMAC:
726 enetc_get_mac_rmon_stats(si, 0, rmon_stats);
727 break;
728 case ETHTOOL_MAC_STATS_SRC_PMAC:
729 if (si->hw_features & ENETC_SI_F_QBU)
730 enetc_get_mac_rmon_stats(si, 1, rmon_stats);
731 break;
732 case ETHTOOL_MAC_STATS_SRC_AGGREGATE:
733 ethtool_aggregate_rmon_stats(ndev, rmon_stats);
734 break;
735 }
736 }
737
738 #define ENETC_RSSHASH_L3 (RXH_L2DA | RXH_VLAN | RXH_L3_PROTO | RXH_IP_SRC | \
739 RXH_IP_DST)
740 #define ENETC_RSSHASH_L4 (ENETC_RSSHASH_L3 | RXH_L4_B_0_1 | RXH_L4_B_2_3)
enetc_get_rxfh_fields(struct net_device * netdev,struct ethtool_rxfh_fields * rxnfc)741 static int enetc_get_rxfh_fields(struct net_device *netdev,
742 struct ethtool_rxfh_fields *rxnfc)
743 {
744 static const u32 rsshash[] = {
745 [TCP_V4_FLOW] = ENETC_RSSHASH_L4,
746 [UDP_V4_FLOW] = ENETC_RSSHASH_L4,
747 [SCTP_V4_FLOW] = ENETC_RSSHASH_L4,
748 [AH_ESP_V4_FLOW] = ENETC_RSSHASH_L3,
749 [IPV4_FLOW] = ENETC_RSSHASH_L3,
750 [TCP_V6_FLOW] = ENETC_RSSHASH_L4,
751 [UDP_V6_FLOW] = ENETC_RSSHASH_L4,
752 [SCTP_V6_FLOW] = ENETC_RSSHASH_L4,
753 [AH_ESP_V6_FLOW] = ENETC_RSSHASH_L3,
754 [IPV6_FLOW] = ENETC_RSSHASH_L3,
755 [ETHER_FLOW] = 0,
756 };
757
758 if (rxnfc->flow_type >= ARRAY_SIZE(rsshash))
759 return -EINVAL;
760
761 rxnfc->data = rsshash[rxnfc->flow_type];
762
763 return 0;
764 }
765
766 /* current HW spec does byte reversal on everything including MAC addresses */
ether_addr_copy_swap(u8 * dst,const u8 * src)767 static void ether_addr_copy_swap(u8 *dst, const u8 *src)
768 {
769 int i;
770
771 for (i = 0; i < ETH_ALEN; i++)
772 dst[i] = src[ETH_ALEN - i - 1];
773 }
774
enetc_set_cls_entry(struct enetc_si * si,struct ethtool_rx_flow_spec * fs,bool en)775 static int enetc_set_cls_entry(struct enetc_si *si,
776 struct ethtool_rx_flow_spec *fs, bool en)
777 {
778 struct ethtool_tcpip4_spec *l4ip4_h, *l4ip4_m;
779 struct ethtool_usrip4_spec *l3ip4_h, *l3ip4_m;
780 struct ethhdr *eth_h, *eth_m;
781 struct enetc_cmd_rfse rfse = { {0} };
782
783 if (!en)
784 goto done;
785
786 switch (fs->flow_type & 0xff) {
787 case TCP_V4_FLOW:
788 l4ip4_h = &fs->h_u.tcp_ip4_spec;
789 l4ip4_m = &fs->m_u.tcp_ip4_spec;
790 goto l4ip4;
791 case UDP_V4_FLOW:
792 l4ip4_h = &fs->h_u.udp_ip4_spec;
793 l4ip4_m = &fs->m_u.udp_ip4_spec;
794 goto l4ip4;
795 case SCTP_V4_FLOW:
796 l4ip4_h = &fs->h_u.sctp_ip4_spec;
797 l4ip4_m = &fs->m_u.sctp_ip4_spec;
798 l4ip4:
799 rfse.sip_h[0] = l4ip4_h->ip4src;
800 rfse.sip_m[0] = l4ip4_m->ip4src;
801 rfse.dip_h[0] = l4ip4_h->ip4dst;
802 rfse.dip_m[0] = l4ip4_m->ip4dst;
803 rfse.sport_h = ntohs(l4ip4_h->psrc);
804 rfse.sport_m = ntohs(l4ip4_m->psrc);
805 rfse.dport_h = ntohs(l4ip4_h->pdst);
806 rfse.dport_m = ntohs(l4ip4_m->pdst);
807 if (l4ip4_m->tos)
808 netdev_warn(si->ndev, "ToS field is not supported and was ignored\n");
809 rfse.ethtype_h = ETH_P_IP; /* IPv4 */
810 rfse.ethtype_m = 0xffff;
811 break;
812 case IP_USER_FLOW:
813 l3ip4_h = &fs->h_u.usr_ip4_spec;
814 l3ip4_m = &fs->m_u.usr_ip4_spec;
815
816 rfse.sip_h[0] = l3ip4_h->ip4src;
817 rfse.sip_m[0] = l3ip4_m->ip4src;
818 rfse.dip_h[0] = l3ip4_h->ip4dst;
819 rfse.dip_m[0] = l3ip4_m->ip4dst;
820 if (l3ip4_m->tos)
821 netdev_warn(si->ndev, "ToS field is not supported and was ignored\n");
822 rfse.ethtype_h = ETH_P_IP; /* IPv4 */
823 rfse.ethtype_m = 0xffff;
824 break;
825 case ETHER_FLOW:
826 eth_h = &fs->h_u.ether_spec;
827 eth_m = &fs->m_u.ether_spec;
828
829 ether_addr_copy_swap(rfse.smac_h, eth_h->h_source);
830 ether_addr_copy_swap(rfse.smac_m, eth_m->h_source);
831 ether_addr_copy_swap(rfse.dmac_h, eth_h->h_dest);
832 ether_addr_copy_swap(rfse.dmac_m, eth_m->h_dest);
833 rfse.ethtype_h = ntohs(eth_h->h_proto);
834 rfse.ethtype_m = ntohs(eth_m->h_proto);
835 break;
836 default:
837 return -EOPNOTSUPP;
838 }
839
840 rfse.mode |= ENETC_RFSE_EN;
841 if (fs->ring_cookie != RX_CLS_FLOW_DISC) {
842 rfse.mode |= ENETC_RFSE_MODE_BD;
843 rfse.result = fs->ring_cookie;
844 }
845 done:
846 return enetc_set_fs_entry(si, &rfse, fs->location);
847 }
848
enetc_get_rx_ring_count(struct net_device * ndev)849 static u32 enetc_get_rx_ring_count(struct net_device *ndev)
850 {
851 struct enetc_ndev_priv *priv = netdev_priv(ndev);
852
853 return priv->num_rx_rings;
854 }
855
enetc_get_rxnfc(struct net_device * ndev,struct ethtool_rxnfc * rxnfc,u32 * rule_locs)856 static int enetc_get_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *rxnfc,
857 u32 *rule_locs)
858 {
859 struct enetc_ndev_priv *priv = netdev_priv(ndev);
860 int i, j;
861
862 switch (rxnfc->cmd) {
863 case ETHTOOL_GRXCLSRLCNT:
864 /* total number of entries */
865 rxnfc->data = priv->si->num_fs_entries;
866 /* number of entries in use */
867 rxnfc->rule_cnt = 0;
868 for (i = 0; i < priv->si->num_fs_entries; i++)
869 if (priv->cls_rules[i].used)
870 rxnfc->rule_cnt++;
871 break;
872 case ETHTOOL_GRXCLSRULE:
873 if (rxnfc->fs.location >= priv->si->num_fs_entries)
874 return -EINVAL;
875
876 /* get entry x */
877 rxnfc->fs = priv->cls_rules[rxnfc->fs.location].fs;
878 break;
879 case ETHTOOL_GRXCLSRLALL:
880 /* total number of entries */
881 rxnfc->data = priv->si->num_fs_entries;
882 /* array of indexes of used entries */
883 j = 0;
884 for (i = 0; i < priv->si->num_fs_entries; i++) {
885 if (!priv->cls_rules[i].used)
886 continue;
887 if (j == rxnfc->rule_cnt)
888 return -EMSGSIZE;
889 rule_locs[j++] = i;
890 }
891 /* number of entries in use */
892 rxnfc->rule_cnt = j;
893 break;
894 default:
895 return -EOPNOTSUPP;
896 }
897
898 return 0;
899 }
900
enetc_set_rxnfc(struct net_device * ndev,struct ethtool_rxnfc * rxnfc)901 static int enetc_set_rxnfc(struct net_device *ndev, struct ethtool_rxnfc *rxnfc)
902 {
903 struct enetc_ndev_priv *priv = netdev_priv(ndev);
904 int err;
905
906 switch (rxnfc->cmd) {
907 case ETHTOOL_SRXCLSRLINS:
908 if (rxnfc->fs.location >= priv->si->num_fs_entries)
909 return -EINVAL;
910
911 if (rxnfc->fs.ring_cookie >= priv->num_rx_rings &&
912 rxnfc->fs.ring_cookie != RX_CLS_FLOW_DISC)
913 return -EINVAL;
914
915 err = enetc_set_cls_entry(priv->si, &rxnfc->fs, true);
916 if (err)
917 return err;
918 priv->cls_rules[rxnfc->fs.location].fs = rxnfc->fs;
919 priv->cls_rules[rxnfc->fs.location].used = 1;
920 break;
921 case ETHTOOL_SRXCLSRLDEL:
922 if (rxnfc->fs.location >= priv->si->num_fs_entries)
923 return -EINVAL;
924
925 err = enetc_set_cls_entry(priv->si, &rxnfc->fs, false);
926 if (err)
927 return err;
928 priv->cls_rules[rxnfc->fs.location].used = 0;
929 break;
930 default:
931 return -EOPNOTSUPP;
932 }
933
934 return 0;
935 }
936
enetc_get_rxfh_key_size(struct net_device * ndev)937 static u32 enetc_get_rxfh_key_size(struct net_device *ndev)
938 {
939 struct enetc_ndev_priv *priv = netdev_priv(ndev);
940
941 /* return the size of the RX flow hash key. PF only */
942 return (priv->si->hw.port) ? ENETC_RSSHASH_KEY_SIZE : 0;
943 }
944
enetc_get_rxfh_indir_size(struct net_device * ndev)945 static u32 enetc_get_rxfh_indir_size(struct net_device *ndev)
946 {
947 struct enetc_ndev_priv *priv = netdev_priv(ndev);
948
949 /* return the size of the RX flow hash indirection table */
950 return priv->si->num_rss;
951 }
952
enetc_get_rss_key_base(struct enetc_si * si)953 static int enetc_get_rss_key_base(struct enetc_si *si)
954 {
955 if (is_enetc_rev1(si))
956 return ENETC_PRSSK(0);
957
958 return ENETC4_PRSSKR(0);
959 }
960
enetc_get_rss_key(struct enetc_si * si,const u8 * key)961 static void enetc_get_rss_key(struct enetc_si *si, const u8 *key)
962 {
963 int base = enetc_get_rss_key_base(si);
964 struct enetc_hw *hw = &si->hw;
965 int i;
966
967 for (i = 0; i < ENETC_RSSHASH_KEY_SIZE / 4; i++)
968 ((u32 *)key)[i] = enetc_port_rd(hw, base + i * 4);
969 }
970
enetc_get_rxfh(struct net_device * ndev,struct ethtool_rxfh_param * rxfh)971 static int enetc_get_rxfh(struct net_device *ndev,
972 struct ethtool_rxfh_param *rxfh)
973 {
974 struct enetc_ndev_priv *priv = netdev_priv(ndev);
975 struct enetc_si *si = priv->si;
976 int err = 0;
977
978 /* return hash function */
979 rxfh->hfunc = ETH_RSS_HASH_TOP;
980
981 /* return hash key */
982 if (rxfh->key && enetc_si_is_pf(si))
983 enetc_get_rss_key(si, rxfh->key);
984
985 /* return RSS table */
986 if (rxfh->indir)
987 err = si->ops->get_rss_table(si, rxfh->indir, si->num_rss);
988
989 return err;
990 }
991
enetc_set_rss_key(struct enetc_si * si,const u8 * bytes)992 void enetc_set_rss_key(struct enetc_si *si, const u8 *bytes)
993 {
994 int base = enetc_get_rss_key_base(si);
995 struct enetc_hw *hw = &si->hw;
996 int i;
997
998 for (i = 0; i < ENETC_RSSHASH_KEY_SIZE / 4; i++)
999 enetc_port_wr(hw, base + i * 4, ((u32 *)bytes)[i]);
1000 }
1001 EXPORT_SYMBOL_GPL(enetc_set_rss_key);
1002
enetc_set_rxfh(struct net_device * ndev,struct ethtool_rxfh_param * rxfh,struct netlink_ext_ack * extack)1003 static int enetc_set_rxfh(struct net_device *ndev,
1004 struct ethtool_rxfh_param *rxfh,
1005 struct netlink_ext_ack *extack)
1006 {
1007 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1008 struct enetc_si *si = priv->si;
1009 int err = 0;
1010
1011 if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE &&
1012 rxfh->hfunc != ETH_RSS_HASH_TOP)
1013 return -EOPNOTSUPP;
1014
1015 /* set hash key, if PF */
1016 if (rxfh->key) {
1017 if (!enetc_si_is_pf(si))
1018 return -EOPNOTSUPP;
1019
1020 enetc_set_rss_key(si, rxfh->key);
1021 }
1022
1023 /* set RSS table */
1024 if (rxfh->indir)
1025 err = si->ops->set_rss_table(si, rxfh->indir, si->num_rss);
1026
1027 return err;
1028 }
1029
enetc_get_ringparam(struct net_device * ndev,struct ethtool_ringparam * ring,struct kernel_ethtool_ringparam * kernel_ring,struct netlink_ext_ack * extack)1030 static void enetc_get_ringparam(struct net_device *ndev,
1031 struct ethtool_ringparam *ring,
1032 struct kernel_ethtool_ringparam *kernel_ring,
1033 struct netlink_ext_ack *extack)
1034 {
1035 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1036
1037 ring->rx_max_pending = priv->rx_bd_count;
1038 ring->tx_max_pending = priv->tx_bd_count;
1039 ring->rx_pending = priv->rx_bd_count;
1040 ring->tx_pending = priv->tx_bd_count;
1041
1042 /* do some h/w sanity checks for BDR length */
1043 if (netif_running(ndev)) {
1044 struct enetc_hw *hw = &priv->si->hw;
1045 u32 val = enetc_rxbdr_rd(hw, 0, ENETC_RBLENR);
1046
1047 if (val != priv->rx_bd_count)
1048 netif_err(priv, hw, ndev, "RxBDR[RBLENR] = %d!\n", val);
1049
1050 val = enetc_txbdr_rd(hw, 0, ENETC_TBLENR);
1051
1052 if (val != priv->tx_bd_count)
1053 netif_err(priv, hw, ndev, "TxBDR[TBLENR] = %d!\n", val);
1054 }
1055 }
1056
enetc_get_coalesce(struct net_device * ndev,struct ethtool_coalesce * ic,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1057 static int enetc_get_coalesce(struct net_device *ndev,
1058 struct ethtool_coalesce *ic,
1059 struct kernel_ethtool_coalesce *kernel_coal,
1060 struct netlink_ext_ack *extack)
1061 {
1062 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1063 struct enetc_int_vector *v = priv->int_vector[0];
1064 u64 clk_freq = priv->sysclk_freq;
1065
1066 ic->tx_coalesce_usecs = enetc_cycles_to_usecs(priv->tx_ictt, clk_freq);
1067 ic->rx_coalesce_usecs = enetc_cycles_to_usecs(v->rx_ictt, clk_freq);
1068
1069 ic->tx_max_coalesced_frames = ENETC_TXIC_PKTTHR;
1070 ic->rx_max_coalesced_frames = ENETC_RXIC_PKTTHR;
1071
1072 ic->use_adaptive_rx_coalesce = priv->ic_mode & ENETC_IC_RX_ADAPTIVE;
1073
1074 return 0;
1075 }
1076
enetc_set_coalesce(struct net_device * ndev,struct ethtool_coalesce * ic,struct kernel_ethtool_coalesce * kernel_coal,struct netlink_ext_ack * extack)1077 static int enetc_set_coalesce(struct net_device *ndev,
1078 struct ethtool_coalesce *ic,
1079 struct kernel_ethtool_coalesce *kernel_coal,
1080 struct netlink_ext_ack *extack)
1081 {
1082 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1083 u64 clk_freq = priv->sysclk_freq;
1084 u32 rx_ictt, tx_ictt;
1085 int i, ic_mode;
1086 bool changed;
1087
1088 tx_ictt = enetc_usecs_to_cycles(ic->tx_coalesce_usecs, clk_freq);
1089 rx_ictt = enetc_usecs_to_cycles(ic->rx_coalesce_usecs, clk_freq);
1090
1091 if (ic->rx_max_coalesced_frames != ENETC_RXIC_PKTTHR)
1092 return -EOPNOTSUPP;
1093
1094 if (ic->tx_max_coalesced_frames != ENETC_TXIC_PKTTHR)
1095 return -EOPNOTSUPP;
1096
1097 ic_mode = ENETC_IC_NONE;
1098 if (ic->use_adaptive_rx_coalesce) {
1099 ic_mode |= ENETC_IC_RX_ADAPTIVE;
1100 rx_ictt = 0x1;
1101 } else {
1102 ic_mode |= rx_ictt ? ENETC_IC_RX_MANUAL : 0;
1103 }
1104
1105 ic_mode |= tx_ictt ? ENETC_IC_TX_MANUAL : 0;
1106
1107 /* commit the settings */
1108 changed = (ic_mode != priv->ic_mode) || (priv->tx_ictt != tx_ictt);
1109
1110 priv->ic_mode = ic_mode;
1111 priv->tx_ictt = tx_ictt;
1112
1113 for (i = 0; i < priv->bdr_int_num; i++) {
1114 struct enetc_int_vector *v = priv->int_vector[i];
1115
1116 v->rx_ictt = rx_ictt;
1117 v->rx_dim_en = !!(ic_mode & ENETC_IC_RX_ADAPTIVE);
1118 }
1119
1120 if (netif_running(ndev) && changed) {
1121 /* reconfigure the operation mode of h/w interrupts,
1122 * traffic needs to be paused in the process
1123 */
1124 enetc_stop(ndev);
1125 enetc_start(ndev);
1126 }
1127
1128 return 0;
1129 }
1130
enetc_get_phc_index_by_pdev(struct enetc_si * si)1131 static int enetc_get_phc_index_by_pdev(struct enetc_si *si)
1132 {
1133 struct pci_bus *bus = si->pdev->bus;
1134 struct pci_dev *timer_pdev;
1135 unsigned int devfn;
1136 int phc_index;
1137
1138 switch (si->revision) {
1139 case ENETC_REV_1_0:
1140 devfn = PCI_DEVFN(0, 4);
1141 break;
1142 case ENETC_REV_4_1:
1143 devfn = PCI_DEVFN(24, 0);
1144 break;
1145 case ENETC_REV_4_3:
1146 devfn = PCI_DEVFN(0, 1);
1147 break;
1148 default:
1149 return -1;
1150 }
1151
1152 timer_pdev = pci_get_domain_bus_and_slot(pci_domain_nr(bus),
1153 bus->number, devfn);
1154 if (!timer_pdev)
1155 return -1;
1156
1157 phc_index = ptp_clock_index_by_dev(&timer_pdev->dev);
1158 pci_dev_put(timer_pdev);
1159
1160 return phc_index;
1161 }
1162
enetc_get_phc_index(struct enetc_si * si)1163 static int enetc_get_phc_index(struct enetc_si *si)
1164 {
1165 struct device_node *np = si->pdev->dev.of_node;
1166 struct device_node *timer_np;
1167 int phc_index;
1168
1169 if (!np)
1170 return enetc_get_phc_index_by_pdev(si);
1171
1172 timer_np = of_parse_phandle(np, "ptp-timer", 0);
1173 if (!timer_np)
1174 return enetc_get_phc_index_by_pdev(si);
1175
1176 phc_index = ptp_clock_index_by_of_node(timer_np);
1177 of_node_put(timer_np);
1178
1179 return phc_index;
1180 }
1181
enetc_get_ts_generic_info(struct net_device * ndev,struct kernel_ethtool_ts_info * info)1182 static void enetc_get_ts_generic_info(struct net_device *ndev,
1183 struct kernel_ethtool_ts_info *info)
1184 {
1185 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1186
1187 info->so_timestamping = SOF_TIMESTAMPING_TX_HARDWARE |
1188 SOF_TIMESTAMPING_RX_HARDWARE |
1189 SOF_TIMESTAMPING_RAW_HARDWARE |
1190 SOF_TIMESTAMPING_TX_SOFTWARE;
1191
1192 info->tx_types = (1 << HWTSTAMP_TX_OFF) |
1193 (1 << HWTSTAMP_TX_ON);
1194
1195 if (enetc_si_is_pf(priv->si))
1196 info->tx_types |= (1 << HWTSTAMP_TX_ONESTEP_SYNC);
1197
1198 info->rx_filters = (1 << HWTSTAMP_FILTER_NONE) |
1199 (1 << HWTSTAMP_FILTER_ALL);
1200 }
1201
enetc_get_ts_info(struct net_device * ndev,struct kernel_ethtool_ts_info * info)1202 static int enetc_get_ts_info(struct net_device *ndev,
1203 struct kernel_ethtool_ts_info *info)
1204 {
1205 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1206 struct enetc_si *si = priv->si;
1207
1208 if (!enetc_ptp_clock_is_enabled(si))
1209 goto timestamp_tx_sw;
1210
1211 info->phc_index = enetc_get_phc_index(si);
1212 if (info->phc_index < 0)
1213 goto timestamp_tx_sw;
1214
1215 enetc_get_ts_generic_info(ndev, info);
1216
1217 return 0;
1218
1219 timestamp_tx_sw:
1220 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE;
1221
1222 return 0;
1223 }
1224
enetc_get_wol(struct net_device * dev,struct ethtool_wolinfo * wol)1225 static void enetc_get_wol(struct net_device *dev,
1226 struct ethtool_wolinfo *wol)
1227 {
1228 wol->supported = 0;
1229 wol->wolopts = 0;
1230
1231 if (dev->phydev)
1232 phy_ethtool_get_wol(dev->phydev, wol);
1233 }
1234
enetc_set_wol(struct net_device * dev,struct ethtool_wolinfo * wol)1235 static int enetc_set_wol(struct net_device *dev,
1236 struct ethtool_wolinfo *wol)
1237 {
1238 int ret;
1239
1240 if (!dev->phydev)
1241 return -EOPNOTSUPP;
1242
1243 ret = phy_ethtool_set_wol(dev->phydev, wol);
1244 if (!ret)
1245 device_set_wakeup_enable(&dev->dev, wol->wolopts);
1246
1247 return ret;
1248 }
1249
enetc_get_pauseparam(struct net_device * dev,struct ethtool_pauseparam * pause)1250 static void enetc_get_pauseparam(struct net_device *dev,
1251 struct ethtool_pauseparam *pause)
1252 {
1253 struct enetc_ndev_priv *priv = netdev_priv(dev);
1254
1255 phylink_ethtool_get_pauseparam(priv->phylink, pause);
1256 }
1257
enetc_set_pauseparam(struct net_device * dev,struct ethtool_pauseparam * pause)1258 static int enetc_set_pauseparam(struct net_device *dev,
1259 struct ethtool_pauseparam *pause)
1260 {
1261 struct enetc_ndev_priv *priv = netdev_priv(dev);
1262
1263 return phylink_ethtool_set_pauseparam(priv->phylink, pause);
1264 }
1265
enetc_get_link_ksettings(struct net_device * dev,struct ethtool_link_ksettings * cmd)1266 static int enetc_get_link_ksettings(struct net_device *dev,
1267 struct ethtool_link_ksettings *cmd)
1268 {
1269 struct enetc_ndev_priv *priv = netdev_priv(dev);
1270
1271 if (!priv->phylink)
1272 return -EOPNOTSUPP;
1273
1274 return phylink_ethtool_ksettings_get(priv->phylink, cmd);
1275 }
1276
enetc_set_link_ksettings(struct net_device * dev,const struct ethtool_link_ksettings * cmd)1277 static int enetc_set_link_ksettings(struct net_device *dev,
1278 const struct ethtool_link_ksettings *cmd)
1279 {
1280 struct enetc_ndev_priv *priv = netdev_priv(dev);
1281
1282 if (!priv->phylink)
1283 return -EOPNOTSUPP;
1284
1285 return phylink_ethtool_ksettings_set(priv->phylink, cmd);
1286 }
1287
enetc_get_mm_stats(struct net_device * ndev,struct ethtool_mm_stats * s)1288 static void enetc_get_mm_stats(struct net_device *ndev,
1289 struct ethtool_mm_stats *s)
1290 {
1291 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1292 struct enetc_hw *hw = &priv->si->hw;
1293 struct enetc_si *si = priv->si;
1294
1295 if (!(si->hw_features & ENETC_SI_F_QBU))
1296 return;
1297
1298 s->MACMergeFrameAssErrorCount = enetc_port_rd(hw, ENETC_MMFAECR);
1299 s->MACMergeFrameSmdErrorCount = enetc_port_rd(hw, ENETC_MMFSECR);
1300 s->MACMergeFrameAssOkCount = enetc_port_rd(hw, ENETC_MMFAOCR);
1301 s->MACMergeFragCountRx = enetc_port_rd(hw, ENETC_MMFCRXR);
1302 s->MACMergeFragCountTx = enetc_port_rd(hw, ENETC_MMFCTXR);
1303 s->MACMergeHoldCount = enetc_port_rd(hw, ENETC_MMHCR);
1304 }
1305
enetc_get_mm(struct net_device * ndev,struct ethtool_mm_state * state)1306 static int enetc_get_mm(struct net_device *ndev, struct ethtool_mm_state *state)
1307 {
1308 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1309 struct enetc_si *si = priv->si;
1310 struct enetc_hw *hw = &si->hw;
1311 u32 lafs, rafs, val;
1312
1313 if (!(si->hw_features & ENETC_SI_F_QBU))
1314 return -EOPNOTSUPP;
1315
1316 mutex_lock(&priv->mm_lock);
1317
1318 val = enetc_port_rd(hw, ENETC_PFPMR);
1319 state->pmac_enabled = !!(val & ENETC_PFPMR_PMACE);
1320
1321 val = enetc_port_rd(hw, ENETC_MMCSR);
1322
1323 switch (ENETC_MMCSR_GET_VSTS(val)) {
1324 case 0:
1325 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
1326 break;
1327 case 2:
1328 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING;
1329 break;
1330 case 3:
1331 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED;
1332 break;
1333 case 4:
1334 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
1335 break;
1336 case 5:
1337 default:
1338 state->verify_status = ETHTOOL_MM_VERIFY_STATUS_UNKNOWN;
1339 break;
1340 }
1341
1342 rafs = ENETC_MMCSR_GET_RAFS(val);
1343 state->tx_min_frag_size = ethtool_mm_frag_size_add_to_min(rafs);
1344 lafs = ENETC_MMCSR_GET_LAFS(val);
1345 state->rx_min_frag_size = ethtool_mm_frag_size_add_to_min(lafs);
1346 state->tx_enabled = !!(val & ENETC_MMCSR_LPE); /* mirror of MMCSR_ME */
1347 state->tx_active = state->tx_enabled &&
1348 (state->verify_status == ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED ||
1349 state->verify_status == ETHTOOL_MM_VERIFY_STATUS_DISABLED);
1350 state->verify_enabled = !(val & ENETC_MMCSR_VDIS);
1351 state->verify_time = ENETC_MMCSR_GET_VT(val);
1352 /* A verifyTime of 128 ms would exceed the 7 bit width
1353 * of the ENETC_MMCSR_VT field
1354 */
1355 state->max_verify_time = 127;
1356
1357 mutex_unlock(&priv->mm_lock);
1358
1359 return 0;
1360 }
1361
enetc_mm_wait_tx_active(struct enetc_hw * hw,int verify_time)1362 static int enetc_mm_wait_tx_active(struct enetc_hw *hw, int verify_time)
1363 {
1364 int timeout = verify_time * USEC_PER_MSEC * ENETC_MM_VERIFY_RETRIES;
1365 u32 val;
1366
1367 /* This will time out after the standard value of 3 verification
1368 * attempts. To not sleep forever, it relies on a non-zero verify_time,
1369 * guarantee which is provided by the ethtool nlattr policy.
1370 */
1371 return read_poll_timeout(enetc_port_rd, val,
1372 ENETC_MMCSR_GET_VSTS(val) == 3,
1373 ENETC_MM_VERIFY_SLEEP_US, timeout,
1374 true, hw, ENETC_MMCSR);
1375 }
1376
enetc_set_ptcfpr(struct enetc_hw * hw,u8 preemptible_tcs)1377 static void enetc_set_ptcfpr(struct enetc_hw *hw, u8 preemptible_tcs)
1378 {
1379 u32 val;
1380 int tc;
1381
1382 for (tc = 0; tc < 8; tc++) {
1383 val = enetc_port_rd(hw, ENETC_PTCFPR(tc));
1384
1385 if (preemptible_tcs & BIT(tc))
1386 val |= ENETC_PTCFPR_FPE;
1387 else
1388 val &= ~ENETC_PTCFPR_FPE;
1389
1390 enetc_port_wr(hw, ENETC_PTCFPR(tc), val);
1391 }
1392 }
1393
1394 /* ENETC does not have an IRQ to notify changes to the MAC Merge TX status
1395 * (active/inactive), but the preemptible traffic classes should only be
1396 * committed to hardware once TX is active. Resort to polling.
1397 */
enetc_mm_commit_preemptible_tcs(struct enetc_ndev_priv * priv)1398 void enetc_mm_commit_preemptible_tcs(struct enetc_ndev_priv *priv)
1399 {
1400 struct enetc_hw *hw = &priv->si->hw;
1401 u8 preemptible_tcs = 0;
1402 u32 val;
1403 int err;
1404
1405 val = enetc_port_rd(hw, ENETC_MMCSR);
1406 if (!(val & ENETC_MMCSR_ME))
1407 goto out;
1408
1409 if (!(val & ENETC_MMCSR_VDIS)) {
1410 err = enetc_mm_wait_tx_active(hw, ENETC_MMCSR_GET_VT(val));
1411 if (err)
1412 goto out;
1413 }
1414
1415 preemptible_tcs = priv->preemptible_tcs;
1416 out:
1417 enetc_set_ptcfpr(hw, preemptible_tcs);
1418 }
1419
1420 /* FIXME: Workaround for the link partner's verification failing if ENETC
1421 * priorly received too much express traffic. The documentation doesn't
1422 * suggest this is needed.
1423 */
enetc_restart_emac_rx(struct enetc_si * si)1424 static void enetc_restart_emac_rx(struct enetc_si *si)
1425 {
1426 u32 val = enetc_port_rd(&si->hw, ENETC_PM0_CMD_CFG);
1427
1428 enetc_port_wr(&si->hw, ENETC_PM0_CMD_CFG, val & ~ENETC_PM0_RX_EN);
1429
1430 if (val & ENETC_PM0_RX_EN)
1431 enetc_port_wr(&si->hw, ENETC_PM0_CMD_CFG, val);
1432 }
1433
enetc_set_mm(struct net_device * ndev,struct ethtool_mm_cfg * cfg,struct netlink_ext_ack * extack)1434 static int enetc_set_mm(struct net_device *ndev, struct ethtool_mm_cfg *cfg,
1435 struct netlink_ext_ack *extack)
1436 {
1437 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1438 struct enetc_hw *hw = &priv->si->hw;
1439 struct enetc_si *si = priv->si;
1440 u32 val, add_frag_size;
1441 int err;
1442
1443 if (!(si->hw_features & ENETC_SI_F_QBU))
1444 return -EOPNOTSUPP;
1445
1446 err = ethtool_mm_frag_size_min_to_add(cfg->tx_min_frag_size,
1447 &add_frag_size, extack);
1448 if (err)
1449 return err;
1450
1451 mutex_lock(&priv->mm_lock);
1452
1453 val = enetc_port_rd(hw, ENETC_PFPMR);
1454 if (cfg->pmac_enabled)
1455 val |= ENETC_PFPMR_PMACE;
1456 else
1457 val &= ~ENETC_PFPMR_PMACE;
1458 enetc_port_wr(hw, ENETC_PFPMR, val);
1459
1460 val = enetc_port_rd(hw, ENETC_MMCSR);
1461
1462 if (cfg->verify_enabled)
1463 val &= ~ENETC_MMCSR_VDIS;
1464 else
1465 val |= ENETC_MMCSR_VDIS;
1466
1467 if (cfg->tx_enabled)
1468 priv->active_offloads |= ENETC_F_QBU;
1469 else
1470 priv->active_offloads &= ~ENETC_F_QBU;
1471
1472 /* If link is up, enable/disable MAC Merge right away */
1473 if (!(val & ENETC_MMCSR_LINK_FAIL)) {
1474 if (!!(priv->active_offloads & ENETC_F_QBU))
1475 val |= ENETC_MMCSR_ME;
1476 else
1477 val &= ~ENETC_MMCSR_ME;
1478 }
1479
1480 val &= ~ENETC_MMCSR_VT_MASK;
1481 val |= ENETC_MMCSR_VT(cfg->verify_time);
1482
1483 val &= ~ENETC_MMCSR_RAFS_MASK;
1484 val |= ENETC_MMCSR_RAFS(add_frag_size);
1485
1486 enetc_port_wr(hw, ENETC_MMCSR, val);
1487
1488 enetc_restart_emac_rx(priv->si);
1489
1490 enetc_mm_commit_preemptible_tcs(priv);
1491
1492 mutex_unlock(&priv->mm_lock);
1493
1494 return 0;
1495 }
1496
1497 /* When the link is lost, the verification state machine goes to the FAILED
1498 * state and doesn't restart on its own after a new link up event.
1499 * According to 802.3 Figure 99-8 - Verify state diagram, the LINK_FAIL bit
1500 * should have been sufficient to re-trigger verification, but for ENETC it
1501 * doesn't. As a workaround, we need to toggle the Merge Enable bit to
1502 * re-trigger verification when link comes up.
1503 */
enetc_mm_link_state_update(struct enetc_ndev_priv * priv,bool link)1504 void enetc_mm_link_state_update(struct enetc_ndev_priv *priv, bool link)
1505 {
1506 struct enetc_hw *hw = &priv->si->hw;
1507 u32 val;
1508
1509 mutex_lock(&priv->mm_lock);
1510
1511 val = enetc_port_rd(hw, ENETC_MMCSR);
1512
1513 if (link) {
1514 val &= ~ENETC_MMCSR_LINK_FAIL;
1515 if (priv->active_offloads & ENETC_F_QBU)
1516 val |= ENETC_MMCSR_ME;
1517 } else {
1518 val |= ENETC_MMCSR_LINK_FAIL;
1519 if (priv->active_offloads & ENETC_F_QBU)
1520 val &= ~ENETC_MMCSR_ME;
1521 }
1522
1523 enetc_port_wr(hw, ENETC_MMCSR, val);
1524
1525 enetc_mm_commit_preemptible_tcs(priv);
1526
1527 mutex_unlock(&priv->mm_lock);
1528 }
1529 EXPORT_SYMBOL_GPL(enetc_mm_link_state_update);
1530
1531 const struct ethtool_ops enetc_pf_ethtool_ops = {
1532 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1533 ETHTOOL_COALESCE_MAX_FRAMES |
1534 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1535 .get_regs_len = enetc_get_reglen,
1536 .get_regs = enetc_get_regs,
1537 .get_sset_count = enetc_get_sset_count,
1538 .get_strings = enetc_get_strings,
1539 .get_ethtool_stats = enetc_get_ethtool_stats,
1540 .get_pause_stats = enetc_get_pause_stats,
1541 .get_rmon_stats = enetc_get_rmon_stats,
1542 .get_eth_ctrl_stats = enetc_get_eth_ctrl_stats,
1543 .get_eth_mac_stats = enetc_get_eth_mac_stats,
1544 .get_rx_ring_count = enetc_get_rx_ring_count,
1545 .get_rxnfc = enetc_get_rxnfc,
1546 .set_rxnfc = enetc_set_rxnfc,
1547 .get_rxfh_key_size = enetc_get_rxfh_key_size,
1548 .get_rxfh_indir_size = enetc_get_rxfh_indir_size,
1549 .get_rxfh = enetc_get_rxfh,
1550 .set_rxfh = enetc_set_rxfh,
1551 .get_rxfh_fields = enetc_get_rxfh_fields,
1552 .get_ringparam = enetc_get_ringparam,
1553 .get_coalesce = enetc_get_coalesce,
1554 .set_coalesce = enetc_set_coalesce,
1555 .get_link_ksettings = enetc_get_link_ksettings,
1556 .set_link_ksettings = enetc_set_link_ksettings,
1557 .get_link = ethtool_op_get_link,
1558 .get_ts_info = enetc_get_ts_info,
1559 .get_wol = enetc_get_wol,
1560 .set_wol = enetc_set_wol,
1561 .get_pauseparam = enetc_get_pauseparam,
1562 .set_pauseparam = enetc_set_pauseparam,
1563 .get_mm = enetc_get_mm,
1564 .set_mm = enetc_set_mm,
1565 .get_mm_stats = enetc_get_mm_stats,
1566 };
1567
1568 const struct ethtool_ops enetc4_ppm_ethtool_ops = {
1569 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1570 ETHTOOL_COALESCE_MAX_FRAMES |
1571 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1572 .get_sset_count = enetc_get_sset_count,
1573 .get_strings = enetc_get_strings,
1574 .get_ethtool_stats = enetc_get_ethtool_stats,
1575 .get_eth_mac_stats = enetc_ppm_get_eth_mac_stats,
1576 .get_rx_ring_count = enetc_get_rx_ring_count,
1577 .get_rxfh_key_size = enetc_get_rxfh_key_size,
1578 .get_rxfh_indir_size = enetc_get_rxfh_indir_size,
1579 .get_rxfh = enetc_get_rxfh,
1580 .set_rxfh = enetc_set_rxfh,
1581 .get_rxfh_fields = enetc_get_rxfh_fields,
1582 .get_ringparam = enetc_get_ringparam,
1583 .get_coalesce = enetc_get_coalesce,
1584 .set_coalesce = enetc_set_coalesce,
1585 .get_link_ksettings = enetc_get_link_ksettings,
1586 .set_link_ksettings = enetc_set_link_ksettings,
1587 .get_link = ethtool_op_get_link,
1588 };
1589
1590 const struct ethtool_ops enetc_vf_ethtool_ops = {
1591 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1592 ETHTOOL_COALESCE_MAX_FRAMES |
1593 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1594 .get_regs_len = enetc_get_reglen,
1595 .get_regs = enetc_get_regs,
1596 .get_sset_count = enetc_get_sset_count,
1597 .get_strings = enetc_get_strings,
1598 .get_ethtool_stats = enetc_get_ethtool_stats,
1599 .get_rx_ring_count = enetc_get_rx_ring_count,
1600 .get_rxnfc = enetc_get_rxnfc,
1601 .set_rxnfc = enetc_set_rxnfc,
1602 .get_rxfh_indir_size = enetc_get_rxfh_indir_size,
1603 .get_rxfh = enetc_get_rxfh,
1604 .set_rxfh = enetc_set_rxfh,
1605 .get_rxfh_fields = enetc_get_rxfh_fields,
1606 .get_ringparam = enetc_get_ringparam,
1607 .get_coalesce = enetc_get_coalesce,
1608 .set_coalesce = enetc_set_coalesce,
1609 .get_link = ethtool_op_get_link,
1610 .get_ts_info = enetc_get_ts_info,
1611 };
1612
1613 const struct ethtool_ops enetc4_pf_ethtool_ops = {
1614 .supported_coalesce_params = ETHTOOL_COALESCE_USECS |
1615 ETHTOOL_COALESCE_MAX_FRAMES |
1616 ETHTOOL_COALESCE_USE_ADAPTIVE_RX,
1617 .get_sset_count = enetc_get_sset_count,
1618 .get_strings = enetc_get_strings,
1619 .get_ethtool_stats = enetc_get_ethtool_stats,
1620 .get_pause_stats = enetc_get_pause_stats,
1621 .get_rmon_stats = enetc_get_rmon_stats,
1622 .get_eth_ctrl_stats = enetc_get_eth_ctrl_stats,
1623 .get_eth_mac_stats = enetc_get_eth_mac_stats,
1624 .get_ringparam = enetc_get_ringparam,
1625 .get_coalesce = enetc_get_coalesce,
1626 .set_coalesce = enetc_set_coalesce,
1627 .get_link_ksettings = enetc_get_link_ksettings,
1628 .set_link_ksettings = enetc_set_link_ksettings,
1629 .get_link = ethtool_op_get_link,
1630 .get_wol = enetc_get_wol,
1631 .set_wol = enetc_set_wol,
1632 .get_pauseparam = enetc_get_pauseparam,
1633 .set_pauseparam = enetc_set_pauseparam,
1634 .get_rx_ring_count = enetc_get_rx_ring_count,
1635 .get_rxfh_key_size = enetc_get_rxfh_key_size,
1636 .get_rxfh_indir_size = enetc_get_rxfh_indir_size,
1637 .get_rxfh = enetc_get_rxfh,
1638 .set_rxfh = enetc_set_rxfh,
1639 .get_rxfh_fields = enetc_get_rxfh_fields,
1640 .get_ts_info = enetc_get_ts_info,
1641 };
1642
enetc_set_ethtool_ops(struct net_device * ndev)1643 void enetc_set_ethtool_ops(struct net_device *ndev)
1644 {
1645 struct enetc_ndev_priv *priv = netdev_priv(ndev);
1646
1647 ndev->ethtool_ops = priv->si->drvdata->eth_ops;
1648 }
1649 EXPORT_SYMBOL_GPL(enetc_set_ethtool_ops);
1650