1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2007 Freescale Semiconductor, Inc. All rights reserved.
5 * Description: QE UCC Gigabit Ethernet Ethtool API Set
7 * Author: Li Yang <leoli@freescale.com>
10 * Can only get/set settings of the first queue.
11 * Need to re-open the interface manually after changing some parameters.
14 #include <linux/kernel.h>
15 #include <linux/errno.h>
16 #include <linux/stddef.h>
17 #include <linux/interrupt.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
20 #include <linux/skbuff.h>
21 #include <linux/spinlock.h>
23 #include <linux/delay.h>
24 #include <linux/dma-mapping.h>
25 #include <linux/ethtool.h>
26 #include <linux/mii.h>
27 #include <linux/phy.h>
31 #include <linux/uaccess.h>
32 #include <asm/types.h>
36 static const char hw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
45 "tx-multicast-frames",
46 "tx-broadcast-frames",
50 "rx-multicast-frames",
51 "rx-broadcast-frames",
52 "stats-counter-carry",
57 static const char tx_fw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
58 "tx-single-collision",
59 "tx-multiple-collision",
63 "tx-carrier-sense-errors",
65 "tx-excessive-differ-frames",
68 "tx-1024-1518-frames",
72 static const char rx_fw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
74 "rx-alignment-errors",
75 "rx-in-range-length-errors",
76 "rx-out-of-range-length-errors",
81 "rx-busy-drop-frames",
84 "rx-mismatch-drop-frames",
88 "rx-1024-1518-frames",
96 "rx-ip-checksum-errors",
99 #define UEC_HW_STATS_LEN ARRAY_SIZE(hw_stat_gstrings)
100 #define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings)
101 #define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings)
104 uec_get_ksettings(struct net_device
*netdev
, struct ethtool_link_ksettings
*cmd
)
106 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
107 struct phy_device
*phydev
= ugeth
->phydev
;
112 phy_ethtool_ksettings_get(phydev
, cmd
);
118 uec_set_ksettings(struct net_device
*netdev
,
119 const struct ethtool_link_ksettings
*cmd
)
121 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
122 struct phy_device
*phydev
= ugeth
->phydev
;
127 return phy_ethtool_ksettings_set(phydev
, cmd
);
131 uec_get_pauseparam(struct net_device
*netdev
,
132 struct ethtool_pauseparam
*pause
)
134 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
136 pause
->autoneg
= ugeth
->phydev
->autoneg
;
138 if (ugeth
->ug_info
->receiveFlowControl
)
140 if (ugeth
->ug_info
->transmitFlowControl
)
145 uec_set_pauseparam(struct net_device
*netdev
,
146 struct ethtool_pauseparam
*pause
)
148 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
151 ugeth
->ug_info
->receiveFlowControl
= pause
->rx_pause
;
152 ugeth
->ug_info
->transmitFlowControl
= pause
->tx_pause
;
154 if (ugeth
->phydev
->autoneg
) {
155 if (netif_running(netdev
)) {
156 /* FIXME: automatically restart */
157 netdev_info(netdev
, "Please re-open the interface\n");
160 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
162 ret
= init_flow_control_params(ug_info
->aufc
,
163 ug_info
->receiveFlowControl
,
164 ug_info
->transmitFlowControl
,
165 ug_info
->pausePeriod
,
166 ug_info
->extensionField
,
167 &ugeth
->uccf
->uf_regs
->upsmr
,
168 &ugeth
->ug_regs
->uempr
,
169 &ugeth
->ug_regs
->maccfg1
);
176 uec_get_msglevel(struct net_device
*netdev
)
178 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
179 return ugeth
->msg_enable
;
183 uec_set_msglevel(struct net_device
*netdev
, uint32_t data
)
185 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
186 ugeth
->msg_enable
= data
;
190 uec_get_regs_len(struct net_device
*netdev
)
192 return sizeof(struct ucc_geth
);
196 uec_get_regs(struct net_device
*netdev
,
197 struct ethtool_regs
*regs
, void *p
)
200 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
201 u32 __iomem
*ug_regs
= (u32 __iomem
*)ugeth
->ug_regs
;
204 for (i
= 0; i
< sizeof(struct ucc_geth
) / sizeof(u32
); i
++)
205 buff
[i
] = in_be32(&ug_regs
[i
]);
209 uec_get_ringparam(struct net_device
*netdev
,
210 struct ethtool_ringparam
*ring
)
212 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
213 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
216 ring
->rx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
217 ring
->rx_mini_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
218 ring
->rx_jumbo_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
219 ring
->tx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
221 ring
->rx_pending
= ug_info
->bdRingLenRx
[queue
];
222 ring
->rx_mini_pending
= ug_info
->bdRingLenRx
[queue
];
223 ring
->rx_jumbo_pending
= ug_info
->bdRingLenRx
[queue
];
224 ring
->tx_pending
= ug_info
->bdRingLenTx
[queue
];
228 uec_set_ringparam(struct net_device
*netdev
,
229 struct ethtool_ringparam
*ring
)
231 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
232 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
233 int queue
= 0, ret
= 0;
235 if (ring
->rx_pending
< UCC_GETH_RX_BD_RING_SIZE_MIN
) {
236 netdev_info(netdev
, "RxBD ring size must be no smaller than %d\n",
237 UCC_GETH_RX_BD_RING_SIZE_MIN
);
240 if (ring
->rx_pending
% UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
) {
241 netdev_info(netdev
, "RxBD ring size must be multiple of %d\n",
242 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
);
245 if (ring
->tx_pending
< UCC_GETH_TX_BD_RING_SIZE_MIN
) {
246 netdev_info(netdev
, "TxBD ring size must be no smaller than %d\n",
247 UCC_GETH_TX_BD_RING_SIZE_MIN
);
251 if (netif_running(netdev
))
254 ug_info
->bdRingLenRx
[queue
] = ring
->rx_pending
;
255 ug_info
->bdRingLenTx
[queue
] = ring
->tx_pending
;
260 static int uec_get_sset_count(struct net_device
*netdev
, int sset
)
262 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
263 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
268 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
)
269 len
+= UEC_HW_STATS_LEN
;
270 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
)
271 len
+= UEC_TX_FW_STATS_LEN
;
272 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
273 len
+= UEC_RX_FW_STATS_LEN
;
282 static void uec_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*buf
)
284 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
285 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
287 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
288 memcpy(buf
, hw_stat_gstrings
, UEC_HW_STATS_LEN
*
290 buf
+= UEC_HW_STATS_LEN
* ETH_GSTRING_LEN
;
292 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
293 memcpy(buf
, tx_fw_stat_gstrings
, UEC_TX_FW_STATS_LEN
*
295 buf
+= UEC_TX_FW_STATS_LEN
* ETH_GSTRING_LEN
;
297 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
298 memcpy(buf
, rx_fw_stat_gstrings
, UEC_RX_FW_STATS_LEN
*
302 static void uec_get_ethtool_stats(struct net_device
*netdev
,
303 struct ethtool_stats
*stats
, uint64_t *data
)
305 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
306 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
310 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
312 base
= (u32 __iomem
*)&ugeth
->ug_regs
->tx64
;
316 for (i
= 0; i
< UEC_HW_STATS_LEN
; i
++)
317 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
319 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
320 base
= (u32 __iomem
*)ugeth
->p_tx_fw_statistics_pram
;
321 for (i
= 0; i
< UEC_TX_FW_STATS_LEN
; i
++)
322 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
324 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
) {
325 base
= (u32 __iomem
*)ugeth
->p_rx_fw_statistics_pram
;
326 for (i
= 0; i
< UEC_RX_FW_STATS_LEN
; i
++)
327 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
331 /* Report driver information */
333 uec_get_drvinfo(struct net_device
*netdev
,
334 struct ethtool_drvinfo
*drvinfo
)
336 strlcpy(drvinfo
->driver
, DRV_NAME
, sizeof(drvinfo
->driver
));
337 strlcpy(drvinfo
->version
, DRV_VERSION
, sizeof(drvinfo
->version
));
338 strlcpy(drvinfo
->fw_version
, "N/A", sizeof(drvinfo
->fw_version
));
339 strlcpy(drvinfo
->bus_info
, "QUICC ENGINE", sizeof(drvinfo
->bus_info
));
344 static void uec_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
346 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
347 struct phy_device
*phydev
= ugeth
->phydev
;
349 if (phydev
&& phydev
->irq
)
350 wol
->supported
|= WAKE_PHY
;
351 if (qe_alive_during_sleep())
352 wol
->supported
|= WAKE_MAGIC
;
354 wol
->wolopts
= ugeth
->wol_en
;
357 static int uec_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
359 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
360 struct phy_device
*phydev
= ugeth
->phydev
;
362 if (wol
->wolopts
& ~(WAKE_PHY
| WAKE_MAGIC
))
364 else if (wol
->wolopts
& WAKE_PHY
&& (!phydev
|| !phydev
->irq
))
366 else if (wol
->wolopts
& WAKE_MAGIC
&& !qe_alive_during_sleep())
369 ugeth
->wol_en
= wol
->wolopts
;
370 device_set_wakeup_enable(&netdev
->dev
, ugeth
->wol_en
);
376 #define uec_get_wol NULL
377 #define uec_set_wol NULL
378 #endif /* CONFIG_PM */
380 static const struct ethtool_ops uec_ethtool_ops
= {
381 .get_drvinfo
= uec_get_drvinfo
,
382 .get_regs_len
= uec_get_regs_len
,
383 .get_regs
= uec_get_regs
,
384 .get_msglevel
= uec_get_msglevel
,
385 .set_msglevel
= uec_set_msglevel
,
386 .nway_reset
= phy_ethtool_nway_reset
,
387 .get_link
= ethtool_op_get_link
,
388 .get_ringparam
= uec_get_ringparam
,
389 .set_ringparam
= uec_set_ringparam
,
390 .get_pauseparam
= uec_get_pauseparam
,
391 .set_pauseparam
= uec_set_pauseparam
,
392 .get_sset_count
= uec_get_sset_count
,
393 .get_strings
= uec_get_strings
,
394 .get_ethtool_stats
= uec_get_ethtool_stats
,
395 .get_wol
= uec_get_wol
,
396 .set_wol
= uec_set_wol
,
397 .get_ts_info
= ethtool_op_get_ts_info
,
398 .get_link_ksettings
= uec_get_ksettings
,
399 .set_link_ksettings
= uec_set_ksettings
,
402 void uec_set_ethtool_ops(struct net_device
*netdev
)
404 netdev
->ethtool_ops
= &uec_ethtool_ops
;