2 * Copyright (c) 2007 Freescale Semiconductor, Inc. All rights reserved.
4 * Description: QE UCC Gigabit Ethernet Ethtool API Set
6 * Author: Li Yang <leoli@freescale.com>
9 * Can only get/set settings of the first queue.
10 * Need to re-open the interface manually after changing some parameters.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/stddef.h>
21 #include <linux/interrupt.h>
22 #include <linux/netdevice.h>
23 #include <linux/etherdevice.h>
24 #include <linux/skbuff.h>
25 #include <linux/spinlock.h>
27 #include <linux/delay.h>
28 #include <linux/dma-mapping.h>
29 #include <linux/ethtool.h>
30 #include <linux/mii.h>
31 #include <linux/phy.h>
35 #include <linux/uaccess.h>
36 #include <asm/types.h>
40 static const char hw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
49 "tx-multicast-frames",
50 "tx-broadcast-frames",
54 "rx-multicast-frames",
55 "rx-broadcast-frames",
56 "stats-counter-carry",
61 static const char tx_fw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
62 "tx-single-collision",
63 "tx-multiple-collision",
67 "tx-carrier-sense-errors",
69 "tx-excessive-differ-frames",
72 "tx-1024-1518-frames",
76 static const char rx_fw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
78 "rx-alignment-errors",
79 "rx-in-range-length-errors",
80 "rx-out-of-range-length-errors",
85 "rx-busy-drop-frames",
88 "rx-mismatch-drop-frames",
92 "rx-1024-1518-frames",
100 "rx-ip-checksum-errors",
103 #define UEC_HW_STATS_LEN ARRAY_SIZE(hw_stat_gstrings)
104 #define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings)
105 #define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings)
108 uec_get_ksettings(struct net_device
*netdev
, struct ethtool_link_ksettings
*cmd
)
110 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
111 struct phy_device
*phydev
= ugeth
->phydev
;
116 phy_ethtool_ksettings_get(phydev
, cmd
);
122 uec_set_ksettings(struct net_device
*netdev
,
123 const struct ethtool_link_ksettings
*cmd
)
125 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
126 struct phy_device
*phydev
= ugeth
->phydev
;
131 return phy_ethtool_ksettings_set(phydev
, cmd
);
135 uec_get_pauseparam(struct net_device
*netdev
,
136 struct ethtool_pauseparam
*pause
)
138 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
140 pause
->autoneg
= ugeth
->phydev
->autoneg
;
142 if (ugeth
->ug_info
->receiveFlowControl
)
144 if (ugeth
->ug_info
->transmitFlowControl
)
149 uec_set_pauseparam(struct net_device
*netdev
,
150 struct ethtool_pauseparam
*pause
)
152 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
155 ugeth
->ug_info
->receiveFlowControl
= pause
->rx_pause
;
156 ugeth
->ug_info
->transmitFlowControl
= pause
->tx_pause
;
158 if (ugeth
->phydev
->autoneg
) {
159 if (netif_running(netdev
)) {
160 /* FIXME: automatically restart */
161 netdev_info(netdev
, "Please re-open the interface\n");
164 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
166 ret
= init_flow_control_params(ug_info
->aufc
,
167 ug_info
->receiveFlowControl
,
168 ug_info
->transmitFlowControl
,
169 ug_info
->pausePeriod
,
170 ug_info
->extensionField
,
171 &ugeth
->uccf
->uf_regs
->upsmr
,
172 &ugeth
->ug_regs
->uempr
,
173 &ugeth
->ug_regs
->maccfg1
);
180 uec_get_msglevel(struct net_device
*netdev
)
182 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
183 return ugeth
->msg_enable
;
187 uec_set_msglevel(struct net_device
*netdev
, uint32_t data
)
189 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
190 ugeth
->msg_enable
= data
;
194 uec_get_regs_len(struct net_device
*netdev
)
196 return sizeof(struct ucc_geth
);
200 uec_get_regs(struct net_device
*netdev
,
201 struct ethtool_regs
*regs
, void *p
)
204 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
205 u32 __iomem
*ug_regs
= (u32 __iomem
*)ugeth
->ug_regs
;
208 for (i
= 0; i
< sizeof(struct ucc_geth
) / sizeof(u32
); i
++)
209 buff
[i
] = in_be32(&ug_regs
[i
]);
213 uec_get_ringparam(struct net_device
*netdev
,
214 struct ethtool_ringparam
*ring
)
216 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
217 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
220 ring
->rx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
221 ring
->rx_mini_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
222 ring
->rx_jumbo_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
223 ring
->tx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
225 ring
->rx_pending
= ug_info
->bdRingLenRx
[queue
];
226 ring
->rx_mini_pending
= ug_info
->bdRingLenRx
[queue
];
227 ring
->rx_jumbo_pending
= ug_info
->bdRingLenRx
[queue
];
228 ring
->tx_pending
= ug_info
->bdRingLenTx
[queue
];
232 uec_set_ringparam(struct net_device
*netdev
,
233 struct ethtool_ringparam
*ring
)
235 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
236 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
237 int queue
= 0, ret
= 0;
239 if (ring
->rx_pending
< UCC_GETH_RX_BD_RING_SIZE_MIN
) {
240 netdev_info(netdev
, "RxBD ring size must be no smaller than %d\n",
241 UCC_GETH_RX_BD_RING_SIZE_MIN
);
244 if (ring
->rx_pending
% UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
) {
245 netdev_info(netdev
, "RxBD ring size must be multiple of %d\n",
246 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
);
249 if (ring
->tx_pending
< UCC_GETH_TX_BD_RING_SIZE_MIN
) {
250 netdev_info(netdev
, "TxBD ring size must be no smaller than %d\n",
251 UCC_GETH_TX_BD_RING_SIZE_MIN
);
255 ug_info
->bdRingLenRx
[queue
] = ring
->rx_pending
;
256 ug_info
->bdRingLenTx
[queue
] = ring
->tx_pending
;
258 if (netif_running(netdev
)) {
259 /* FIXME: restart automatically */
260 netdev_info(netdev
, "Please re-open the interface\n");
266 static int uec_get_sset_count(struct net_device
*netdev
, int sset
)
268 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
269 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
274 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
)
275 len
+= UEC_HW_STATS_LEN
;
276 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
)
277 len
+= UEC_TX_FW_STATS_LEN
;
278 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
279 len
+= UEC_RX_FW_STATS_LEN
;
288 static void uec_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*buf
)
290 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
291 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
293 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
294 memcpy(buf
, hw_stat_gstrings
, UEC_HW_STATS_LEN
*
296 buf
+= UEC_HW_STATS_LEN
* ETH_GSTRING_LEN
;
298 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
299 memcpy(buf
, tx_fw_stat_gstrings
, UEC_TX_FW_STATS_LEN
*
301 buf
+= UEC_TX_FW_STATS_LEN
* ETH_GSTRING_LEN
;
303 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
304 memcpy(buf
, rx_fw_stat_gstrings
, UEC_RX_FW_STATS_LEN
*
308 static void uec_get_ethtool_stats(struct net_device
*netdev
,
309 struct ethtool_stats
*stats
, uint64_t *data
)
311 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
312 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
316 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
318 base
= (u32 __iomem
*)&ugeth
->ug_regs
->tx64
;
322 for (i
= 0; i
< UEC_HW_STATS_LEN
; i
++)
323 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
325 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
326 base
= (u32 __iomem
*)ugeth
->p_tx_fw_statistics_pram
;
327 for (i
= 0; i
< UEC_TX_FW_STATS_LEN
; i
++)
328 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
330 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
) {
331 base
= (u32 __iomem
*)ugeth
->p_rx_fw_statistics_pram
;
332 for (i
= 0; i
< UEC_RX_FW_STATS_LEN
; i
++)
333 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
337 /* Report driver information */
339 uec_get_drvinfo(struct net_device
*netdev
,
340 struct ethtool_drvinfo
*drvinfo
)
342 strlcpy(drvinfo
->driver
, DRV_NAME
, sizeof(drvinfo
->driver
));
343 strlcpy(drvinfo
->version
, DRV_VERSION
, sizeof(drvinfo
->version
));
344 strlcpy(drvinfo
->fw_version
, "N/A", sizeof(drvinfo
->fw_version
));
345 strlcpy(drvinfo
->bus_info
, "QUICC ENGINE", sizeof(drvinfo
->bus_info
));
350 static void uec_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
352 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
353 struct phy_device
*phydev
= ugeth
->phydev
;
355 if (phydev
&& phydev
->irq
)
356 wol
->supported
|= WAKE_PHY
;
357 if (qe_alive_during_sleep())
358 wol
->supported
|= WAKE_MAGIC
;
360 wol
->wolopts
= ugeth
->wol_en
;
363 static int uec_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
365 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
366 struct phy_device
*phydev
= ugeth
->phydev
;
368 if (wol
->wolopts
& ~(WAKE_PHY
| WAKE_MAGIC
))
370 else if (wol
->wolopts
& WAKE_PHY
&& (!phydev
|| !phydev
->irq
))
372 else if (wol
->wolopts
& WAKE_MAGIC
&& !qe_alive_during_sleep())
375 ugeth
->wol_en
= wol
->wolopts
;
376 device_set_wakeup_enable(&netdev
->dev
, ugeth
->wol_en
);
382 #define uec_get_wol NULL
383 #define uec_set_wol NULL
384 #endif /* CONFIG_PM */
386 static const struct ethtool_ops uec_ethtool_ops
= {
387 .get_drvinfo
= uec_get_drvinfo
,
388 .get_regs_len
= uec_get_regs_len
,
389 .get_regs
= uec_get_regs
,
390 .get_msglevel
= uec_get_msglevel
,
391 .set_msglevel
= uec_set_msglevel
,
392 .nway_reset
= phy_ethtool_nway_reset
,
393 .get_link
= ethtool_op_get_link
,
394 .get_ringparam
= uec_get_ringparam
,
395 .set_ringparam
= uec_set_ringparam
,
396 .get_pauseparam
= uec_get_pauseparam
,
397 .set_pauseparam
= uec_set_pauseparam
,
398 .get_sset_count
= uec_get_sset_count
,
399 .get_strings
= uec_get_strings
,
400 .get_ethtool_stats
= uec_get_ethtool_stats
,
401 .get_wol
= uec_get_wol
,
402 .set_wol
= uec_set_wol
,
403 .get_ts_info
= ethtool_op_get_ts_info
,
404 .get_link_ksettings
= uec_get_ksettings
,
405 .set_link_ksettings
= uec_set_ksettings
,
408 void uec_set_ethtool_ops(struct net_device
*netdev
)
410 netdev
->ethtool_ops
= &uec_ethtool_ops
;