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 <asm/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_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
110 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
111 struct phy_device
*phydev
= ugeth
->phydev
;
112 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
118 ecmd
->maxrxpkt
= ug_info
->interruptcoalescingmaxvalue
[0];
120 return phy_ethtool_gset(phydev
, ecmd
);
124 uec_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
126 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
127 struct phy_device
*phydev
= ugeth
->phydev
;
132 return phy_ethtool_sset(phydev
, ecmd
);
136 uec_get_pauseparam(struct net_device
*netdev
,
137 struct ethtool_pauseparam
*pause
)
139 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
141 pause
->autoneg
= ugeth
->phydev
->autoneg
;
143 if (ugeth
->ug_info
->receiveFlowControl
)
145 if (ugeth
->ug_info
->transmitFlowControl
)
150 uec_set_pauseparam(struct net_device
*netdev
,
151 struct ethtool_pauseparam
*pause
)
153 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
156 ugeth
->ug_info
->receiveFlowControl
= pause
->rx_pause
;
157 ugeth
->ug_info
->transmitFlowControl
= pause
->tx_pause
;
159 if (ugeth
->phydev
->autoneg
) {
160 if (netif_running(netdev
)) {
161 /* FIXME: automatically restart */
162 netdev_info(netdev
, "Please re-open the interface\n");
165 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
167 ret
= init_flow_control_params(ug_info
->aufc
,
168 ug_info
->receiveFlowControl
,
169 ug_info
->transmitFlowControl
,
170 ug_info
->pausePeriod
,
171 ug_info
->extensionField
,
172 &ugeth
->uccf
->uf_regs
->upsmr
,
173 &ugeth
->ug_regs
->uempr
,
174 &ugeth
->ug_regs
->maccfg1
);
181 uec_get_msglevel(struct net_device
*netdev
)
183 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
184 return ugeth
->msg_enable
;
188 uec_set_msglevel(struct net_device
*netdev
, uint32_t data
)
190 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
191 ugeth
->msg_enable
= data
;
195 uec_get_regs_len(struct net_device
*netdev
)
197 return sizeof(struct ucc_geth
);
201 uec_get_regs(struct net_device
*netdev
,
202 struct ethtool_regs
*regs
, void *p
)
205 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
206 u32 __iomem
*ug_regs
= (u32 __iomem
*)ugeth
->ug_regs
;
209 for (i
= 0; i
< sizeof(struct ucc_geth
) / sizeof(u32
); i
++)
210 buff
[i
] = in_be32(&ug_regs
[i
]);
214 uec_get_ringparam(struct net_device
*netdev
,
215 struct ethtool_ringparam
*ring
)
217 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
218 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
221 ring
->rx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
222 ring
->rx_mini_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
223 ring
->rx_jumbo_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
224 ring
->tx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
226 ring
->rx_pending
= ug_info
->bdRingLenRx
[queue
];
227 ring
->rx_mini_pending
= ug_info
->bdRingLenRx
[queue
];
228 ring
->rx_jumbo_pending
= ug_info
->bdRingLenRx
[queue
];
229 ring
->tx_pending
= ug_info
->bdRingLenTx
[queue
];
233 uec_set_ringparam(struct net_device
*netdev
,
234 struct ethtool_ringparam
*ring
)
236 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
237 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
238 int queue
= 0, ret
= 0;
240 if (ring
->rx_pending
< UCC_GETH_RX_BD_RING_SIZE_MIN
) {
241 netdev_info(netdev
, "RxBD ring size must be no smaller than %d\n",
242 UCC_GETH_RX_BD_RING_SIZE_MIN
);
245 if (ring
->rx_pending
% UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
) {
246 netdev_info(netdev
, "RxBD ring size must be multiple of %d\n",
247 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
);
250 if (ring
->tx_pending
< UCC_GETH_TX_BD_RING_SIZE_MIN
) {
251 netdev_info(netdev
, "TxBD ring size must be no smaller than %d\n",
252 UCC_GETH_TX_BD_RING_SIZE_MIN
);
256 ug_info
->bdRingLenRx
[queue
] = ring
->rx_pending
;
257 ug_info
->bdRingLenTx
[queue
] = ring
->tx_pending
;
259 if (netif_running(netdev
)) {
260 /* FIXME: restart automatically */
261 netdev_info(netdev
, "Please re-open the interface\n");
267 static int uec_get_sset_count(struct net_device
*netdev
, int sset
)
269 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
270 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
275 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
)
276 len
+= UEC_HW_STATS_LEN
;
277 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
)
278 len
+= UEC_TX_FW_STATS_LEN
;
279 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
280 len
+= UEC_RX_FW_STATS_LEN
;
289 static void uec_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*buf
)
291 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
292 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
294 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
295 memcpy(buf
, hw_stat_gstrings
, UEC_HW_STATS_LEN
*
297 buf
+= UEC_HW_STATS_LEN
* ETH_GSTRING_LEN
;
299 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
300 memcpy(buf
, tx_fw_stat_gstrings
, UEC_TX_FW_STATS_LEN
*
302 buf
+= UEC_TX_FW_STATS_LEN
* ETH_GSTRING_LEN
;
304 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
305 memcpy(buf
, rx_fw_stat_gstrings
, UEC_RX_FW_STATS_LEN
*
309 static void uec_get_ethtool_stats(struct net_device
*netdev
,
310 struct ethtool_stats
*stats
, uint64_t *data
)
312 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
313 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
317 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
319 base
= (u32 __iomem
*)&ugeth
->ug_regs
->tx64
;
323 for (i
= 0; i
< UEC_HW_STATS_LEN
; i
++)
324 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
326 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
327 base
= (u32 __iomem
*)ugeth
->p_tx_fw_statistics_pram
;
328 for (i
= 0; i
< UEC_TX_FW_STATS_LEN
; i
++)
329 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
331 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
) {
332 base
= (u32 __iomem
*)ugeth
->p_rx_fw_statistics_pram
;
333 for (i
= 0; i
< UEC_RX_FW_STATS_LEN
; i
++)
334 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
338 static int uec_nway_reset(struct net_device
*netdev
)
340 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
342 return phy_start_aneg(ugeth
->phydev
);
345 /* Report driver information */
347 uec_get_drvinfo(struct net_device
*netdev
,
348 struct ethtool_drvinfo
*drvinfo
)
350 strlcpy(drvinfo
->driver
, DRV_NAME
, sizeof(drvinfo
->driver
));
351 strlcpy(drvinfo
->version
, DRV_VERSION
, sizeof(drvinfo
->version
));
352 strlcpy(drvinfo
->fw_version
, "N/A", sizeof(drvinfo
->fw_version
));
353 strlcpy(drvinfo
->bus_info
, "QUICC ENGINE", sizeof(drvinfo
->bus_info
));
358 static void uec_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
360 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
361 struct phy_device
*phydev
= ugeth
->phydev
;
363 if (phydev
&& phydev
->irq
)
364 wol
->supported
|= WAKE_PHY
;
365 if (qe_alive_during_sleep())
366 wol
->supported
|= WAKE_MAGIC
;
368 wol
->wolopts
= ugeth
->wol_en
;
371 static int uec_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
373 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
374 struct phy_device
*phydev
= ugeth
->phydev
;
376 if (wol
->wolopts
& ~(WAKE_PHY
| WAKE_MAGIC
))
378 else if (wol
->wolopts
& WAKE_PHY
&& (!phydev
|| !phydev
->irq
))
380 else if (wol
->wolopts
& WAKE_MAGIC
&& !qe_alive_during_sleep())
383 ugeth
->wol_en
= wol
->wolopts
;
384 device_set_wakeup_enable(&netdev
->dev
, ugeth
->wol_en
);
390 #define uec_get_wol NULL
391 #define uec_set_wol NULL
392 #endif /* CONFIG_PM */
394 static const struct ethtool_ops uec_ethtool_ops
= {
395 .get_settings
= uec_get_settings
,
396 .set_settings
= uec_set_settings
,
397 .get_drvinfo
= uec_get_drvinfo
,
398 .get_regs_len
= uec_get_regs_len
,
399 .get_regs
= uec_get_regs
,
400 .get_msglevel
= uec_get_msglevel
,
401 .set_msglevel
= uec_set_msglevel
,
402 .nway_reset
= uec_nway_reset
,
403 .get_link
= ethtool_op_get_link
,
404 .get_ringparam
= uec_get_ringparam
,
405 .set_ringparam
= uec_set_ringparam
,
406 .get_pauseparam
= uec_get_pauseparam
,
407 .set_pauseparam
= uec_set_pauseparam
,
408 .get_sset_count
= uec_get_sset_count
,
409 .get_strings
= uec_get_strings
,
410 .get_ethtool_stats
= uec_get_ethtool_stats
,
411 .get_wol
= uec_get_wol
,
412 .set_wol
= uec_set_wol
,
413 .get_ts_info
= ethtool_op_get_ts_info
,
416 void uec_set_ethtool_ops(struct net_device
*netdev
)
418 netdev
->ethtool_ops
= &uec_ethtool_ops
;