1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/etherdevice.h>
26#include <linux/ethtool.h>
27#include <linux/interrupt.h>
28#include <linux/mii.h>
29#include <linux/phy.h>
30#include <linux/net_tstamp.h>
31#include <asm/io.h>
32
33#include "stmmac.h"
34#include "dwmac_dma.h"
35
36#define REG_SPACE_SIZE 0x1054
37#define MAC100_ETHTOOL_NAME "st_mac100"
38#define GMAC_ETHTOOL_NAME "st_gmac"
39
40struct stmmac_stats {
41 char stat_string[ETH_GSTRING_LEN];
42 int sizeof_stat;
43 int stat_offset;
44};
45
46#define STMMAC_STAT(m) \
47 { #m, FIELD_SIZEOF(struct stmmac_extra_stats, m), \
48 offsetof(struct stmmac_priv, xstats.m)}
49
50static const struct stmmac_stats stmmac_gstrings_stats[] = {
51
52 STMMAC_STAT(tx_underflow),
53 STMMAC_STAT(tx_carrier),
54 STMMAC_STAT(tx_losscarrier),
55 STMMAC_STAT(vlan_tag),
56 STMMAC_STAT(tx_deferred),
57 STMMAC_STAT(tx_vlan),
58 STMMAC_STAT(tx_jabber),
59 STMMAC_STAT(tx_frame_flushed),
60 STMMAC_STAT(tx_payload_error),
61 STMMAC_STAT(tx_ip_header_error),
62
63 STMMAC_STAT(rx_desc),
64 STMMAC_STAT(sa_filter_fail),
65 STMMAC_STAT(overflow_error),
66 STMMAC_STAT(ipc_csum_error),
67 STMMAC_STAT(rx_collision),
68 STMMAC_STAT(rx_crc),
69 STMMAC_STAT(dribbling_bit),
70 STMMAC_STAT(rx_length),
71 STMMAC_STAT(rx_mii),
72 STMMAC_STAT(rx_multicast),
73 STMMAC_STAT(rx_gmac_overflow),
74 STMMAC_STAT(rx_watchdog),
75 STMMAC_STAT(da_rx_filter_fail),
76 STMMAC_STAT(sa_rx_filter_fail),
77 STMMAC_STAT(rx_missed_cntr),
78 STMMAC_STAT(rx_overflow_cntr),
79 STMMAC_STAT(rx_vlan),
80
81 STMMAC_STAT(tx_undeflow_irq),
82 STMMAC_STAT(tx_process_stopped_irq),
83 STMMAC_STAT(tx_jabber_irq),
84 STMMAC_STAT(rx_overflow_irq),
85 STMMAC_STAT(rx_buf_unav_irq),
86 STMMAC_STAT(rx_process_stopped_irq),
87 STMMAC_STAT(rx_watchdog_irq),
88 STMMAC_STAT(tx_early_irq),
89 STMMAC_STAT(fatal_bus_error_irq),
90
91 STMMAC_STAT(rx_early_irq),
92 STMMAC_STAT(threshold),
93 STMMAC_STAT(tx_pkt_n),
94 STMMAC_STAT(rx_pkt_n),
95 STMMAC_STAT(normal_irq_n),
96 STMMAC_STAT(rx_normal_irq_n),
97 STMMAC_STAT(napi_poll),
98 STMMAC_STAT(tx_normal_irq_n),
99 STMMAC_STAT(tx_clean),
100 STMMAC_STAT(tx_set_ic_bit),
101 STMMAC_STAT(irq_receive_pmt_irq_n),
102
103 STMMAC_STAT(mmc_tx_irq_n),
104 STMMAC_STAT(mmc_rx_irq_n),
105 STMMAC_STAT(mmc_rx_csum_offload_irq_n),
106
107 STMMAC_STAT(irq_tx_path_in_lpi_mode_n),
108 STMMAC_STAT(irq_tx_path_exit_lpi_mode_n),
109 STMMAC_STAT(irq_rx_path_in_lpi_mode_n),
110 STMMAC_STAT(irq_rx_path_exit_lpi_mode_n),
111 STMMAC_STAT(phy_eee_wakeup_error_n),
112
113 STMMAC_STAT(ip_hdr_err),
114 STMMAC_STAT(ip_payload_err),
115 STMMAC_STAT(ip_csum_bypassed),
116 STMMAC_STAT(ipv4_pkt_rcvd),
117 STMMAC_STAT(ipv6_pkt_rcvd),
118 STMMAC_STAT(no_ptp_rx_msg_type_ext),
119 STMMAC_STAT(ptp_rx_msg_type_sync),
120 STMMAC_STAT(ptp_rx_msg_type_follow_up),
121 STMMAC_STAT(ptp_rx_msg_type_delay_req),
122 STMMAC_STAT(ptp_rx_msg_type_delay_resp),
123 STMMAC_STAT(ptp_rx_msg_type_pdelay_req),
124 STMMAC_STAT(ptp_rx_msg_type_pdelay_resp),
125 STMMAC_STAT(ptp_rx_msg_type_pdelay_follow_up),
126 STMMAC_STAT(ptp_rx_msg_type_announce),
127 STMMAC_STAT(ptp_rx_msg_type_management),
128 STMMAC_STAT(ptp_rx_msg_pkt_reserved_type),
129 STMMAC_STAT(ptp_frame_type),
130 STMMAC_STAT(ptp_ver),
131 STMMAC_STAT(timestamp_dropped),
132 STMMAC_STAT(av_pkt_rcvd),
133 STMMAC_STAT(av_tagged_pkt_rcvd),
134 STMMAC_STAT(vlan_tag_priority_val),
135 STMMAC_STAT(l3_filter_match),
136 STMMAC_STAT(l4_filter_match),
137 STMMAC_STAT(l3_l4_filter_no_match),
138
139 STMMAC_STAT(irq_pcs_ane_n),
140 STMMAC_STAT(irq_pcs_link_n),
141 STMMAC_STAT(irq_rgmii_n),
142
143 STMMAC_STAT(mtl_tx_status_fifo_full),
144 STMMAC_STAT(mtl_tx_fifo_not_empty),
145 STMMAC_STAT(mmtl_fifo_ctrl),
146 STMMAC_STAT(mtl_tx_fifo_read_ctrl_write),
147 STMMAC_STAT(mtl_tx_fifo_read_ctrl_wait),
148 STMMAC_STAT(mtl_tx_fifo_read_ctrl_read),
149 STMMAC_STAT(mtl_tx_fifo_read_ctrl_idle),
150 STMMAC_STAT(mac_tx_in_pause),
151 STMMAC_STAT(mac_tx_frame_ctrl_xfer),
152 STMMAC_STAT(mac_tx_frame_ctrl_idle),
153 STMMAC_STAT(mac_tx_frame_ctrl_wait),
154 STMMAC_STAT(mac_tx_frame_ctrl_pause),
155 STMMAC_STAT(mac_gmii_tx_proto_engine),
156 STMMAC_STAT(mtl_rx_fifo_fill_level_full),
157 STMMAC_STAT(mtl_rx_fifo_fill_above_thresh),
158 STMMAC_STAT(mtl_rx_fifo_fill_below_thresh),
159 STMMAC_STAT(mtl_rx_fifo_fill_level_empty),
160 STMMAC_STAT(mtl_rx_fifo_read_ctrl_flush),
161 STMMAC_STAT(mtl_rx_fifo_read_ctrl_read_data),
162 STMMAC_STAT(mtl_rx_fifo_read_ctrl_status),
163 STMMAC_STAT(mtl_rx_fifo_read_ctrl_idle),
164 STMMAC_STAT(mtl_rx_fifo_ctrl_active),
165 STMMAC_STAT(mac_rx_frame_ctrl_fifo),
166 STMMAC_STAT(mac_gmii_rx_proto_engine),
167
168 STMMAC_STAT(tx_tso_frames),
169 STMMAC_STAT(tx_tso_nfrags),
170};
171#define STMMAC_STATS_LEN ARRAY_SIZE(stmmac_gstrings_stats)
172
173
174#define STMMAC_MMC_STAT(m) \
175 { #m, FIELD_SIZEOF(struct stmmac_counters, m), \
176 offsetof(struct stmmac_priv, mmc.m)}
177
178static const struct stmmac_stats stmmac_mmc[] = {
179 STMMAC_MMC_STAT(mmc_tx_octetcount_gb),
180 STMMAC_MMC_STAT(mmc_tx_framecount_gb),
181 STMMAC_MMC_STAT(mmc_tx_broadcastframe_g),
182 STMMAC_MMC_STAT(mmc_tx_multicastframe_g),
183 STMMAC_MMC_STAT(mmc_tx_64_octets_gb),
184 STMMAC_MMC_STAT(mmc_tx_65_to_127_octets_gb),
185 STMMAC_MMC_STAT(mmc_tx_128_to_255_octets_gb),
186 STMMAC_MMC_STAT(mmc_tx_256_to_511_octets_gb),
187 STMMAC_MMC_STAT(mmc_tx_512_to_1023_octets_gb),
188 STMMAC_MMC_STAT(mmc_tx_1024_to_max_octets_gb),
189 STMMAC_MMC_STAT(mmc_tx_unicast_gb),
190 STMMAC_MMC_STAT(mmc_tx_multicast_gb),
191 STMMAC_MMC_STAT(mmc_tx_broadcast_gb),
192 STMMAC_MMC_STAT(mmc_tx_underflow_error),
193 STMMAC_MMC_STAT(mmc_tx_singlecol_g),
194 STMMAC_MMC_STAT(mmc_tx_multicol_g),
195 STMMAC_MMC_STAT(mmc_tx_deferred),
196 STMMAC_MMC_STAT(mmc_tx_latecol),
197 STMMAC_MMC_STAT(mmc_tx_exesscol),
198 STMMAC_MMC_STAT(mmc_tx_carrier_error),
199 STMMAC_MMC_STAT(mmc_tx_octetcount_g),
200 STMMAC_MMC_STAT(mmc_tx_framecount_g),
201 STMMAC_MMC_STAT(mmc_tx_excessdef),
202 STMMAC_MMC_STAT(mmc_tx_pause_frame),
203 STMMAC_MMC_STAT(mmc_tx_vlan_frame_g),
204 STMMAC_MMC_STAT(mmc_rx_framecount_gb),
205 STMMAC_MMC_STAT(mmc_rx_octetcount_gb),
206 STMMAC_MMC_STAT(mmc_rx_octetcount_g),
207 STMMAC_MMC_STAT(mmc_rx_broadcastframe_g),
208 STMMAC_MMC_STAT(mmc_rx_multicastframe_g),
209 STMMAC_MMC_STAT(mmc_rx_crc_error),
210 STMMAC_MMC_STAT(mmc_rx_align_error),
211 STMMAC_MMC_STAT(mmc_rx_run_error),
212 STMMAC_MMC_STAT(mmc_rx_jabber_error),
213 STMMAC_MMC_STAT(mmc_rx_undersize_g),
214 STMMAC_MMC_STAT(mmc_rx_oversize_g),
215 STMMAC_MMC_STAT(mmc_rx_64_octets_gb),
216 STMMAC_MMC_STAT(mmc_rx_65_to_127_octets_gb),
217 STMMAC_MMC_STAT(mmc_rx_128_to_255_octets_gb),
218 STMMAC_MMC_STAT(mmc_rx_256_to_511_octets_gb),
219 STMMAC_MMC_STAT(mmc_rx_512_to_1023_octets_gb),
220 STMMAC_MMC_STAT(mmc_rx_1024_to_max_octets_gb),
221 STMMAC_MMC_STAT(mmc_rx_unicast_g),
222 STMMAC_MMC_STAT(mmc_rx_length_error),
223 STMMAC_MMC_STAT(mmc_rx_autofrangetype),
224 STMMAC_MMC_STAT(mmc_rx_pause_frames),
225 STMMAC_MMC_STAT(mmc_rx_fifo_overflow),
226 STMMAC_MMC_STAT(mmc_rx_vlan_frames_gb),
227 STMMAC_MMC_STAT(mmc_rx_watchdog_error),
228 STMMAC_MMC_STAT(mmc_rx_ipc_intr_mask),
229 STMMAC_MMC_STAT(mmc_rx_ipc_intr),
230 STMMAC_MMC_STAT(mmc_rx_ipv4_gd),
231 STMMAC_MMC_STAT(mmc_rx_ipv4_hderr),
232 STMMAC_MMC_STAT(mmc_rx_ipv4_nopay),
233 STMMAC_MMC_STAT(mmc_rx_ipv4_frag),
234 STMMAC_MMC_STAT(mmc_rx_ipv4_udsbl),
235 STMMAC_MMC_STAT(mmc_rx_ipv4_gd_octets),
236 STMMAC_MMC_STAT(mmc_rx_ipv4_hderr_octets),
237 STMMAC_MMC_STAT(mmc_rx_ipv4_nopay_octets),
238 STMMAC_MMC_STAT(mmc_rx_ipv4_frag_octets),
239 STMMAC_MMC_STAT(mmc_rx_ipv4_udsbl_octets),
240 STMMAC_MMC_STAT(mmc_rx_ipv6_gd_octets),
241 STMMAC_MMC_STAT(mmc_rx_ipv6_hderr_octets),
242 STMMAC_MMC_STAT(mmc_rx_ipv6_nopay_octets),
243 STMMAC_MMC_STAT(mmc_rx_ipv6_gd),
244 STMMAC_MMC_STAT(mmc_rx_ipv6_hderr),
245 STMMAC_MMC_STAT(mmc_rx_ipv6_nopay),
246 STMMAC_MMC_STAT(mmc_rx_udp_gd),
247 STMMAC_MMC_STAT(mmc_rx_udp_err),
248 STMMAC_MMC_STAT(mmc_rx_tcp_gd),
249 STMMAC_MMC_STAT(mmc_rx_tcp_err),
250 STMMAC_MMC_STAT(mmc_rx_icmp_gd),
251 STMMAC_MMC_STAT(mmc_rx_icmp_err),
252 STMMAC_MMC_STAT(mmc_rx_udp_gd_octets),
253 STMMAC_MMC_STAT(mmc_rx_udp_err_octets),
254 STMMAC_MMC_STAT(mmc_rx_tcp_gd_octets),
255 STMMAC_MMC_STAT(mmc_rx_tcp_err_octets),
256 STMMAC_MMC_STAT(mmc_rx_icmp_gd_octets),
257 STMMAC_MMC_STAT(mmc_rx_icmp_err_octets),
258};
259#define STMMAC_MMC_STATS_LEN ARRAY_SIZE(stmmac_mmc)
260
261static void stmmac_ethtool_getdrvinfo(struct net_device *dev,
262 struct ethtool_drvinfo *info)
263{
264 struct stmmac_priv *priv = netdev_priv(dev);
265
266 if (priv->plat->has_gmac || priv->plat->has_gmac4)
267 strlcpy(info->driver, GMAC_ETHTOOL_NAME, sizeof(info->driver));
268 else
269 strlcpy(info->driver, MAC100_ETHTOOL_NAME,
270 sizeof(info->driver));
271
272 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version));
273}
274
275static int stmmac_ethtool_get_link_ksettings(struct net_device *dev,
276 struct ethtool_link_ksettings *cmd)
277{
278 struct stmmac_priv *priv = netdev_priv(dev);
279 struct phy_device *phy = dev->phydev;
280 int rc;
281
282 if (priv->hw->pcs & STMMAC_PCS_RGMII ||
283 priv->hw->pcs & STMMAC_PCS_SGMII) {
284 struct rgmii_adv adv;
285 u32 supported, advertising, lp_advertising;
286
287 if (!priv->xstats.pcs_link) {
288 cmd->base.speed = SPEED_UNKNOWN;
289 cmd->base.duplex = DUPLEX_UNKNOWN;
290 return 0;
291 }
292 cmd->base.duplex = priv->xstats.pcs_duplex;
293
294 cmd->base.speed = priv->xstats.pcs_speed;
295
296
297 if (!priv->hw->mac->pcs_get_adv_lp)
298 return -EOPNOTSUPP;
299
300 priv->hw->mac->pcs_get_adv_lp(priv->ioaddr, &adv);
301
302
303
304 ethtool_convert_link_mode_to_legacy_u32(
305 &supported, cmd->link_modes.supported);
306 ethtool_convert_link_mode_to_legacy_u32(
307 &advertising, cmd->link_modes.advertising);
308 ethtool_convert_link_mode_to_legacy_u32(
309 &lp_advertising, cmd->link_modes.lp_advertising);
310
311 if (adv.pause & STMMAC_PCS_PAUSE)
312 advertising |= ADVERTISED_Pause;
313 if (adv.pause & STMMAC_PCS_ASYM_PAUSE)
314 advertising |= ADVERTISED_Asym_Pause;
315 if (adv.lp_pause & STMMAC_PCS_PAUSE)
316 lp_advertising |= ADVERTISED_Pause;
317 if (adv.lp_pause & STMMAC_PCS_ASYM_PAUSE)
318 lp_advertising |= ADVERTISED_Asym_Pause;
319
320
321 cmd->base.autoneg = ADVERTISED_Autoneg;
322 supported |= SUPPORTED_Autoneg;
323 advertising |= ADVERTISED_Autoneg;
324 lp_advertising |= ADVERTISED_Autoneg;
325
326 if (adv.duplex) {
327 supported |= (SUPPORTED_1000baseT_Full |
328 SUPPORTED_100baseT_Full |
329 SUPPORTED_10baseT_Full);
330 advertising |= (ADVERTISED_1000baseT_Full |
331 ADVERTISED_100baseT_Full |
332 ADVERTISED_10baseT_Full);
333 } else {
334 supported |= (SUPPORTED_1000baseT_Half |
335 SUPPORTED_100baseT_Half |
336 SUPPORTED_10baseT_Half);
337 advertising |= (ADVERTISED_1000baseT_Half |
338 ADVERTISED_100baseT_Half |
339 ADVERTISED_10baseT_Half);
340 }
341 if (adv.lp_duplex)
342 lp_advertising |= (ADVERTISED_1000baseT_Full |
343 ADVERTISED_100baseT_Full |
344 ADVERTISED_10baseT_Full);
345 else
346 lp_advertising |= (ADVERTISED_1000baseT_Half |
347 ADVERTISED_100baseT_Half |
348 ADVERTISED_10baseT_Half);
349 cmd->base.port = PORT_OTHER;
350
351 ethtool_convert_legacy_u32_to_link_mode(
352 cmd->link_modes.supported, supported);
353 ethtool_convert_legacy_u32_to_link_mode(
354 cmd->link_modes.advertising, advertising);
355 ethtool_convert_legacy_u32_to_link_mode(
356 cmd->link_modes.lp_advertising, lp_advertising);
357
358 return 0;
359 }
360
361 if (phy == NULL) {
362 pr_err("%s: %s: PHY is not registered\n",
363 __func__, dev->name);
364 return -ENODEV;
365 }
366 if (!netif_running(dev)) {
367 pr_err("%s: interface is disabled: we cannot track "
368 "link speed / duplex setting\n", dev->name);
369 return -EBUSY;
370 }
371 rc = phy_ethtool_ksettings_get(phy, cmd);
372 return rc;
373}
374
375static int
376stmmac_ethtool_set_link_ksettings(struct net_device *dev,
377 const struct ethtool_link_ksettings *cmd)
378{
379 struct stmmac_priv *priv = netdev_priv(dev);
380 struct phy_device *phy = dev->phydev;
381 int rc;
382
383 if (priv->hw->pcs & STMMAC_PCS_RGMII ||
384 priv->hw->pcs & STMMAC_PCS_SGMII) {
385 u32 mask = ADVERTISED_Autoneg | ADVERTISED_Pause;
386
387
388 if (cmd->base.autoneg != AUTONEG_ENABLE)
389 return -EINVAL;
390
391 mask &= (ADVERTISED_1000baseT_Half |
392 ADVERTISED_1000baseT_Full |
393 ADVERTISED_100baseT_Half |
394 ADVERTISED_100baseT_Full |
395 ADVERTISED_10baseT_Half |
396 ADVERTISED_10baseT_Full);
397
398 spin_lock(&priv->lock);
399
400 if (priv->hw->mac->pcs_ctrl_ane)
401 priv->hw->mac->pcs_ctrl_ane(priv->ioaddr, 1,
402 priv->hw->ps, 0);
403
404 spin_unlock(&priv->lock);
405
406 return 0;
407 }
408
409 rc = phy_ethtool_ksettings_set(phy, cmd);
410
411 return rc;
412}
413
414static u32 stmmac_ethtool_getmsglevel(struct net_device *dev)
415{
416 struct stmmac_priv *priv = netdev_priv(dev);
417 return priv->msg_enable;
418}
419
420static void stmmac_ethtool_setmsglevel(struct net_device *dev, u32 level)
421{
422 struct stmmac_priv *priv = netdev_priv(dev);
423 priv->msg_enable = level;
424
425}
426
427static int stmmac_check_if_running(struct net_device *dev)
428{
429 if (!netif_running(dev))
430 return -EBUSY;
431 return 0;
432}
433
434static int stmmac_ethtool_get_regs_len(struct net_device *dev)
435{
436 return REG_SPACE_SIZE;
437}
438
439static void stmmac_ethtool_gregs(struct net_device *dev,
440 struct ethtool_regs *regs, void *space)
441{
442 int i;
443 u32 *reg_space = (u32 *) space;
444
445 struct stmmac_priv *priv = netdev_priv(dev);
446
447 memset(reg_space, 0x0, REG_SPACE_SIZE);
448
449 if (!(priv->plat->has_gmac || priv->plat->has_gmac4)) {
450
451 for (i = 0; i < 12; i++)
452 reg_space[i] = readl(priv->ioaddr + (i * 4));
453
454 for (i = 0; i < 9; i++)
455 reg_space[i + 12] =
456 readl(priv->ioaddr + (DMA_BUS_MODE + (i * 4)));
457 reg_space[22] = readl(priv->ioaddr + DMA_CUR_TX_BUF_ADDR);
458 reg_space[23] = readl(priv->ioaddr + DMA_CUR_RX_BUF_ADDR);
459 } else {
460
461 for (i = 0; i < 55; i++)
462 reg_space[i] = readl(priv->ioaddr + (i * 4));
463
464 for (i = 0; i < 22; i++)
465 reg_space[i + 55] =
466 readl(priv->ioaddr + (DMA_BUS_MODE + (i * 4)));
467 }
468}
469
470static void
471stmmac_get_pauseparam(struct net_device *netdev,
472 struct ethtool_pauseparam *pause)
473{
474 struct stmmac_priv *priv = netdev_priv(netdev);
475
476 pause->rx_pause = 0;
477 pause->tx_pause = 0;
478
479 if (priv->hw->pcs && priv->hw->mac->pcs_get_adv_lp) {
480 struct rgmii_adv adv_lp;
481
482 pause->autoneg = 1;
483 priv->hw->mac->pcs_get_adv_lp(priv->ioaddr, &adv_lp);
484 if (!adv_lp.pause)
485 return;
486 } else {
487 if (!(netdev->phydev->supported & SUPPORTED_Pause) ||
488 !(netdev->phydev->supported & SUPPORTED_Asym_Pause))
489 return;
490 }
491
492 pause->autoneg = netdev->phydev->autoneg;
493
494 if (priv->flow_ctrl & FLOW_RX)
495 pause->rx_pause = 1;
496 if (priv->flow_ctrl & FLOW_TX)
497 pause->tx_pause = 1;
498
499}
500
501static int
502stmmac_set_pauseparam(struct net_device *netdev,
503 struct ethtool_pauseparam *pause)
504{
505 struct stmmac_priv *priv = netdev_priv(netdev);
506 struct phy_device *phy = netdev->phydev;
507 int new_pause = FLOW_OFF;
508
509 if (priv->hw->pcs && priv->hw->mac->pcs_get_adv_lp) {
510 struct rgmii_adv adv_lp;
511
512 pause->autoneg = 1;
513 priv->hw->mac->pcs_get_adv_lp(priv->ioaddr, &adv_lp);
514 if (!adv_lp.pause)
515 return -EOPNOTSUPP;
516 } else {
517 if (!(phy->supported & SUPPORTED_Pause) ||
518 !(phy->supported & SUPPORTED_Asym_Pause))
519 return -EOPNOTSUPP;
520 }
521
522 if (pause->rx_pause)
523 new_pause |= FLOW_RX;
524 if (pause->tx_pause)
525 new_pause |= FLOW_TX;
526
527 priv->flow_ctrl = new_pause;
528 phy->autoneg = pause->autoneg;
529
530 if (phy->autoneg) {
531 if (netif_running(netdev))
532 return phy_start_aneg(phy);
533 }
534
535 priv->hw->mac->flow_ctrl(priv->hw, phy->duplex, priv->flow_ctrl,
536 priv->pause);
537 return 0;
538}
539
540static void stmmac_get_ethtool_stats(struct net_device *dev,
541 struct ethtool_stats *dummy, u64 *data)
542{
543 struct stmmac_priv *priv = netdev_priv(dev);
544 int i, j = 0;
545
546
547 if (priv->hw->dma->dma_diagnostic_fr)
548 priv->hw->dma->dma_diagnostic_fr(&dev->stats,
549 (void *) &priv->xstats,
550 priv->ioaddr);
551 else {
552
553 if (priv->dma_cap.rmon) {
554 dwmac_mmc_read(priv->mmcaddr, &priv->mmc);
555
556 for (i = 0; i < STMMAC_MMC_STATS_LEN; i++) {
557 char *p;
558 p = (char *)priv + stmmac_mmc[i].stat_offset;
559
560 data[j++] = (stmmac_mmc[i].sizeof_stat ==
561 sizeof(u64)) ? (*(u64 *)p) :
562 (*(u32 *)p);
563 }
564 }
565 if (priv->eee_enabled) {
566 int val = phy_get_eee_err(dev->phydev);
567 if (val)
568 priv->xstats.phy_eee_wakeup_error_n = val;
569 }
570
571 if ((priv->hw->mac->debug) &&
572 (priv->synopsys_id >= DWMAC_CORE_3_50))
573 priv->hw->mac->debug(priv->ioaddr,
574 (void *)&priv->xstats);
575 }
576 for (i = 0; i < STMMAC_STATS_LEN; i++) {
577 char *p = (char *)priv + stmmac_gstrings_stats[i].stat_offset;
578 data[j++] = (stmmac_gstrings_stats[i].sizeof_stat ==
579 sizeof(u64)) ? (*(u64 *)p) : (*(u32 *)p);
580 }
581}
582
583static int stmmac_get_sset_count(struct net_device *netdev, int sset)
584{
585 struct stmmac_priv *priv = netdev_priv(netdev);
586 int len;
587
588 switch (sset) {
589 case ETH_SS_STATS:
590 len = STMMAC_STATS_LEN;
591
592 if (priv->dma_cap.rmon)
593 len += STMMAC_MMC_STATS_LEN;
594
595 return len;
596 default:
597 return -EOPNOTSUPP;
598 }
599}
600
601static void stmmac_get_strings(struct net_device *dev, u32 stringset, u8 *data)
602{
603 int i;
604 u8 *p = data;
605 struct stmmac_priv *priv = netdev_priv(dev);
606
607 switch (stringset) {
608 case ETH_SS_STATS:
609 if (priv->dma_cap.rmon)
610 for (i = 0; i < STMMAC_MMC_STATS_LEN; i++) {
611 memcpy(p, stmmac_mmc[i].stat_string,
612 ETH_GSTRING_LEN);
613 p += ETH_GSTRING_LEN;
614 }
615 for (i = 0; i < STMMAC_STATS_LEN; i++) {
616 memcpy(p, stmmac_gstrings_stats[i].stat_string,
617 ETH_GSTRING_LEN);
618 p += ETH_GSTRING_LEN;
619 }
620 break;
621 default:
622 WARN_ON(1);
623 break;
624 }
625}
626
627
628static void stmmac_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
629{
630 struct stmmac_priv *priv = netdev_priv(dev);
631
632 spin_lock_irq(&priv->lock);
633 if (device_can_wakeup(priv->device)) {
634 wol->supported = WAKE_MAGIC | WAKE_UCAST;
635 wol->wolopts = priv->wolopts;
636 }
637 spin_unlock_irq(&priv->lock);
638}
639
640static int stmmac_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
641{
642 struct stmmac_priv *priv = netdev_priv(dev);
643 u32 support = WAKE_MAGIC | WAKE_UCAST;
644
645
646
647
648 if ((priv->hw_cap_support) && (!priv->dma_cap.pmt_magic_frame))
649 wol->wolopts &= ~WAKE_MAGIC;
650
651 if (!device_can_wakeup(priv->device))
652 return -EINVAL;
653
654 if (wol->wolopts & ~support)
655 return -EINVAL;
656
657 if (wol->wolopts) {
658 pr_info("stmmac: wakeup enable\n");
659 device_set_wakeup_enable(priv->device, 1);
660 enable_irq_wake(priv->wol_irq);
661 } else {
662 device_set_wakeup_enable(priv->device, 0);
663 disable_irq_wake(priv->wol_irq);
664 }
665
666 spin_lock_irq(&priv->lock);
667 priv->wolopts = wol->wolopts;
668 spin_unlock_irq(&priv->lock);
669
670 return 0;
671}
672
673static int stmmac_ethtool_op_get_eee(struct net_device *dev,
674 struct ethtool_eee *edata)
675{
676 struct stmmac_priv *priv = netdev_priv(dev);
677
678 if (!priv->dma_cap.eee)
679 return -EOPNOTSUPP;
680
681 edata->eee_enabled = priv->eee_enabled;
682 edata->eee_active = priv->eee_active;
683 edata->tx_lpi_timer = priv->tx_lpi_timer;
684
685 return phy_ethtool_get_eee(dev->phydev, edata);
686}
687
688static int stmmac_ethtool_op_set_eee(struct net_device *dev,
689 struct ethtool_eee *edata)
690{
691 struct stmmac_priv *priv = netdev_priv(dev);
692
693 priv->eee_enabled = edata->eee_enabled;
694
695 if (!priv->eee_enabled)
696 stmmac_disable_eee_mode(priv);
697 else {
698
699
700
701
702 priv->eee_enabled = stmmac_eee_init(priv);
703 if (!priv->eee_enabled)
704 return -EOPNOTSUPP;
705
706
707 priv->tx_lpi_timer = edata->tx_lpi_timer;
708 }
709
710 return phy_ethtool_set_eee(dev->phydev, edata);
711}
712
713static u32 stmmac_usec2riwt(u32 usec, struct stmmac_priv *priv)
714{
715 unsigned long clk = clk_get_rate(priv->stmmac_clk);
716
717 if (!clk)
718 return 0;
719
720 return (usec * (clk / 1000000)) / 256;
721}
722
723static u32 stmmac_riwt2usec(u32 riwt, struct stmmac_priv *priv)
724{
725 unsigned long clk = clk_get_rate(priv->stmmac_clk);
726
727 if (!clk)
728 return 0;
729
730 return (riwt * 256) / (clk / 1000000);
731}
732
733static int stmmac_get_coalesce(struct net_device *dev,
734 struct ethtool_coalesce *ec)
735{
736 struct stmmac_priv *priv = netdev_priv(dev);
737
738 ec->tx_coalesce_usecs = priv->tx_coal_timer;
739 ec->tx_max_coalesced_frames = priv->tx_coal_frames;
740
741 if (priv->use_riwt)
742 ec->rx_coalesce_usecs = stmmac_riwt2usec(priv->rx_riwt, priv);
743
744 return 0;
745}
746
747static int stmmac_set_coalesce(struct net_device *dev,
748 struct ethtool_coalesce *ec)
749{
750 struct stmmac_priv *priv = netdev_priv(dev);
751 unsigned int rx_riwt;
752
753
754 if ((ec->rx_max_coalesced_frames) || (ec->rx_coalesce_usecs_irq) ||
755 (ec->rx_max_coalesced_frames_irq) || (ec->tx_coalesce_usecs_irq) ||
756 (ec->use_adaptive_rx_coalesce) || (ec->use_adaptive_tx_coalesce) ||
757 (ec->pkt_rate_low) || (ec->rx_coalesce_usecs_low) ||
758 (ec->rx_max_coalesced_frames_low) || (ec->tx_coalesce_usecs_high) ||
759 (ec->tx_max_coalesced_frames_low) || (ec->pkt_rate_high) ||
760 (ec->tx_coalesce_usecs_low) || (ec->rx_coalesce_usecs_high) ||
761 (ec->rx_max_coalesced_frames_high) ||
762 (ec->tx_max_coalesced_frames_irq) ||
763 (ec->stats_block_coalesce_usecs) ||
764 (ec->tx_max_coalesced_frames_high) || (ec->rate_sample_interval))
765 return -EOPNOTSUPP;
766
767 if (ec->rx_coalesce_usecs == 0)
768 return -EINVAL;
769
770 if ((ec->tx_coalesce_usecs == 0) &&
771 (ec->tx_max_coalesced_frames == 0))
772 return -EINVAL;
773
774 if ((ec->tx_coalesce_usecs > STMMAC_MAX_COAL_TX_TICK) ||
775 (ec->tx_max_coalesced_frames > STMMAC_TX_MAX_FRAMES))
776 return -EINVAL;
777
778 rx_riwt = stmmac_usec2riwt(ec->rx_coalesce_usecs, priv);
779
780 if ((rx_riwt > MAX_DMA_RIWT) || (rx_riwt < MIN_DMA_RIWT))
781 return -EINVAL;
782 else if (!priv->use_riwt)
783 return -EOPNOTSUPP;
784
785
786 priv->tx_coal_frames = ec->tx_max_coalesced_frames;
787 priv->tx_coal_timer = ec->tx_coalesce_usecs;
788 priv->rx_riwt = rx_riwt;
789 priv->hw->dma->rx_watchdog(priv->ioaddr, priv->rx_riwt);
790
791 return 0;
792}
793
794static int stmmac_get_ts_info(struct net_device *dev,
795 struct ethtool_ts_info *info)
796{
797 struct stmmac_priv *priv = netdev_priv(dev);
798
799 if ((priv->dma_cap.time_stamp || priv->dma_cap.atime_stamp)) {
800
801 info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
802 SOF_TIMESTAMPING_TX_HARDWARE |
803 SOF_TIMESTAMPING_RX_SOFTWARE |
804 SOF_TIMESTAMPING_RX_HARDWARE |
805 SOF_TIMESTAMPING_SOFTWARE |
806 SOF_TIMESTAMPING_RAW_HARDWARE;
807
808 if (priv->ptp_clock)
809 info->phc_index = ptp_clock_index(priv->ptp_clock);
810
811 info->tx_types = (1 << HWTSTAMP_TX_OFF) | (1 << HWTSTAMP_TX_ON);
812
813 info->rx_filters = ((1 << HWTSTAMP_FILTER_NONE) |
814 (1 << HWTSTAMP_FILTER_PTP_V1_L4_EVENT) |
815 (1 << HWTSTAMP_FILTER_PTP_V1_L4_SYNC) |
816 (1 << HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ) |
817 (1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
818 (1 << HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
819 (1 << HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ) |
820 (1 << HWTSTAMP_FILTER_PTP_V2_EVENT) |
821 (1 << HWTSTAMP_FILTER_PTP_V2_SYNC) |
822 (1 << HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
823 (1 << HWTSTAMP_FILTER_ALL));
824 return 0;
825 } else
826 return ethtool_op_get_ts_info(dev, info);
827}
828
829static int stmmac_get_tunable(struct net_device *dev,
830 const struct ethtool_tunable *tuna, void *data)
831{
832 struct stmmac_priv *priv = netdev_priv(dev);
833 int ret = 0;
834
835 switch (tuna->id) {
836 case ETHTOOL_RX_COPYBREAK:
837 *(u32 *)data = priv->rx_copybreak;
838 break;
839 default:
840 ret = -EINVAL;
841 break;
842 }
843
844 return ret;
845}
846
847static int stmmac_set_tunable(struct net_device *dev,
848 const struct ethtool_tunable *tuna,
849 const void *data)
850{
851 struct stmmac_priv *priv = netdev_priv(dev);
852 int ret = 0;
853
854 switch (tuna->id) {
855 case ETHTOOL_RX_COPYBREAK:
856 priv->rx_copybreak = *(u32 *)data;
857 break;
858 default:
859 ret = -EINVAL;
860 break;
861 }
862
863 return ret;
864}
865
866static const struct ethtool_ops stmmac_ethtool_ops = {
867 .begin = stmmac_check_if_running,
868 .get_drvinfo = stmmac_ethtool_getdrvinfo,
869 .get_msglevel = stmmac_ethtool_getmsglevel,
870 .set_msglevel = stmmac_ethtool_setmsglevel,
871 .get_regs = stmmac_ethtool_gregs,
872 .get_regs_len = stmmac_ethtool_get_regs_len,
873 .get_link = ethtool_op_get_link,
874 .nway_reset = phy_ethtool_nway_reset,
875 .get_pauseparam = stmmac_get_pauseparam,
876 .set_pauseparam = stmmac_set_pauseparam,
877 .get_ethtool_stats = stmmac_get_ethtool_stats,
878 .get_strings = stmmac_get_strings,
879 .get_wol = stmmac_get_wol,
880 .set_wol = stmmac_set_wol,
881 .get_eee = stmmac_ethtool_op_get_eee,
882 .set_eee = stmmac_ethtool_op_set_eee,
883 .get_sset_count = stmmac_get_sset_count,
884 .get_ts_info = stmmac_get_ts_info,
885 .get_coalesce = stmmac_get_coalesce,
886 .set_coalesce = stmmac_set_coalesce,
887 .get_tunable = stmmac_get_tunable,
888 .set_tunable = stmmac_set_tunable,
889 .get_link_ksettings = stmmac_ethtool_get_link_ksettings,
890 .set_link_ksettings = stmmac_ethtool_set_link_ksettings,
891};
892
893void stmmac_set_ethtool_ops(struct net_device *netdev)
894{
895 netdev->ethtool_ops = &stmmac_ethtool_ops;
896}
897