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 setttings 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/init.h>
20 #include <linux/errno.h>
21 #include <linux/slab.h>
22 #include <linux/stddef.h>
23 #include <linux/interrupt.h>
24 #include <linux/netdevice.h>
25 #include <linux/etherdevice.h>
26 #include <linux/skbuff.h>
27 #include <linux/spinlock.h>
29 #include <linux/delay.h>
30 #include <linux/dma-mapping.h>
31 #include <linux/ethtool.h>
32 #include <linux/mii.h>
33 #include <linux/phy.h>
37 #include <asm/uaccess.h>
38 #include <asm/types.h>
42 static char hw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
51 "tx-multicast-frames",
52 "tx-broadcast-frames",
56 "rx-multicast-frames",
57 "rx-broadcast-frames",
58 "stats-counter-carry",
63 static char tx_fw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
64 "tx-single-collision",
65 "tx-multiple-collision",
69 "tx-carrier-sense-errors",
71 "tx-excessive-differ-frames",
74 "tx-1024-1518-frames",
78 static char rx_fw_stat_gstrings
[][ETH_GSTRING_LEN
] = {
80 "rx-alignment-errors",
81 "rx-in-range-length-errors",
82 "rx-out-of-range-length-errors",
87 "rx-busy-drop-frames",
90 "rx-mismatch-drop-frames",
94 "rx-1024-1518-frames",
102 "rx-ip-checksum-errors",
105 #define UEC_HW_STATS_LEN ARRAY_SIZE(hw_stat_gstrings)
106 #define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings)
107 #define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings)
110 uec_get_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
112 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
113 struct phy_device
*phydev
= ugeth
->phydev
;
114 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
120 ecmd
->maxrxpkt
= ug_info
->interruptcoalescingmaxvalue
[0];
122 return phy_ethtool_gset(phydev
, ecmd
);
126 uec_set_settings(struct net_device
*netdev
, struct ethtool_cmd
*ecmd
)
128 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
129 struct phy_device
*phydev
= ugeth
->phydev
;
134 return phy_ethtool_sset(phydev
, ecmd
);
138 uec_get_pauseparam(struct net_device
*netdev
,
139 struct ethtool_pauseparam
*pause
)
141 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
143 pause
->autoneg
= ugeth
->phydev
->autoneg
;
145 if (ugeth
->ug_info
->receiveFlowControl
)
147 if (ugeth
->ug_info
->transmitFlowControl
)
152 uec_set_pauseparam(struct net_device
*netdev
,
153 struct ethtool_pauseparam
*pause
)
155 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
158 ugeth
->ug_info
->receiveFlowControl
= pause
->rx_pause
;
159 ugeth
->ug_info
->transmitFlowControl
= pause
->tx_pause
;
161 if (ugeth
->phydev
->autoneg
) {
162 if (netif_running(netdev
)) {
163 /* FIXME: automatically restart */
165 "Please re-open the interface.\n");
168 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
170 ret
= init_flow_control_params(ug_info
->aufc
,
171 ug_info
->receiveFlowControl
,
172 ug_info
->transmitFlowControl
,
173 ug_info
->pausePeriod
,
174 ug_info
->extensionField
,
175 &ugeth
->uccf
->uf_regs
->upsmr
,
176 &ugeth
->ug_regs
->uempr
,
177 &ugeth
->ug_regs
->maccfg1
);
184 uec_get_msglevel(struct net_device
*netdev
)
186 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
187 return ugeth
->msg_enable
;
191 uec_set_msglevel(struct net_device
*netdev
, uint32_t data
)
193 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
194 ugeth
->msg_enable
= data
;
198 uec_get_regs_len(struct net_device
*netdev
)
200 return sizeof(struct ucc_geth
);
204 uec_get_regs(struct net_device
*netdev
,
205 struct ethtool_regs
*regs
, void *p
)
208 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
209 u32 __iomem
*ug_regs
= (u32 __iomem
*)ugeth
->ug_regs
;
212 for (i
= 0; i
< sizeof(struct ucc_geth
) / sizeof(u32
); i
++)
213 buff
[i
] = in_be32(&ug_regs
[i
]);
217 uec_get_ringparam(struct net_device
*netdev
,
218 struct ethtool_ringparam
*ring
)
220 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
221 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
224 ring
->rx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
225 ring
->rx_mini_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
226 ring
->rx_jumbo_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
227 ring
->tx_max_pending
= UCC_GETH_BD_RING_SIZE_MAX
;
229 ring
->rx_pending
= ug_info
->bdRingLenRx
[queue
];
230 ring
->rx_mini_pending
= ug_info
->bdRingLenRx
[queue
];
231 ring
->rx_jumbo_pending
= ug_info
->bdRingLenRx
[queue
];
232 ring
->tx_pending
= ug_info
->bdRingLenTx
[queue
];
236 uec_set_ringparam(struct net_device
*netdev
,
237 struct ethtool_ringparam
*ring
)
239 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
240 struct ucc_geth_info
*ug_info
= ugeth
->ug_info
;
241 int queue
= 0, ret
= 0;
243 if (ring
->rx_pending
< UCC_GETH_RX_BD_RING_SIZE_MIN
) {
244 printk("%s: RxBD ring size must be no smaller than %d.\n",
245 netdev
->name
, UCC_GETH_RX_BD_RING_SIZE_MIN
);
248 if (ring
->rx_pending
% UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
) {
249 printk("%s: RxBD ring size must be multiple of %d.\n",
250 netdev
->name
, UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT
);
253 if (ring
->tx_pending
< UCC_GETH_TX_BD_RING_SIZE_MIN
) {
254 printk("%s: TxBD ring size must be no smaller than %d.\n",
255 netdev
->name
, UCC_GETH_TX_BD_RING_SIZE_MIN
);
259 ug_info
->bdRingLenRx
[queue
] = ring
->rx_pending
;
260 ug_info
->bdRingLenTx
[queue
] = ring
->tx_pending
;
262 if (netif_running(netdev
)) {
263 /* FIXME: restart automatically */
265 "Please re-open the interface.\n");
271 static int uec_get_sset_count(struct net_device
*netdev
, int sset
)
273 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
274 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
279 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
)
280 len
+= UEC_HW_STATS_LEN
;
281 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
)
282 len
+= UEC_TX_FW_STATS_LEN
;
283 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
284 len
+= UEC_RX_FW_STATS_LEN
;
293 static void uec_get_strings(struct net_device
*netdev
, u32 stringset
, u8
*buf
)
295 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
296 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
298 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
299 memcpy(buf
, hw_stat_gstrings
, UEC_HW_STATS_LEN
*
301 buf
+= UEC_HW_STATS_LEN
* ETH_GSTRING_LEN
;
303 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
304 memcpy(buf
, tx_fw_stat_gstrings
, UEC_TX_FW_STATS_LEN
*
306 buf
+= UEC_TX_FW_STATS_LEN
* ETH_GSTRING_LEN
;
308 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
)
309 memcpy(buf
, rx_fw_stat_gstrings
, UEC_RX_FW_STATS_LEN
*
313 static void uec_get_ethtool_stats(struct net_device
*netdev
,
314 struct ethtool_stats
*stats
, uint64_t *data
)
316 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
317 u32 stats_mode
= ugeth
->ug_info
->statisticsMode
;
321 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE
) {
323 base
= (u32 __iomem
*)&ugeth
->ug_regs
->tx64
;
327 for (i
= 0; i
< UEC_HW_STATS_LEN
; i
++)
328 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
330 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX
) {
331 base
= (u32 __iomem
*)ugeth
->p_tx_fw_statistics_pram
;
332 for (i
= 0; i
< UEC_TX_FW_STATS_LEN
; i
++)
333 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
335 if (stats_mode
& UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX
) {
336 base
= (u32 __iomem
*)ugeth
->p_rx_fw_statistics_pram
;
337 for (i
= 0; i
< UEC_RX_FW_STATS_LEN
; i
++)
338 data
[j
++] = base
? in_be32(&base
[i
]) : 0;
342 static int uec_nway_reset(struct net_device
*netdev
)
344 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
346 return phy_start_aneg(ugeth
->phydev
);
349 /* Report driver information */
351 uec_get_drvinfo(struct net_device
*netdev
,
352 struct ethtool_drvinfo
*drvinfo
)
354 strncpy(drvinfo
->driver
, DRV_NAME
, 32);
355 strncpy(drvinfo
->version
, DRV_VERSION
, 32);
356 strncpy(drvinfo
->fw_version
, "N/A", 32);
357 strncpy(drvinfo
->bus_info
, "QUICC ENGINE", 32);
358 drvinfo
->eedump_len
= 0;
359 drvinfo
->regdump_len
= uec_get_regs_len(netdev
);
364 static void uec_get_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
366 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
367 struct phy_device
*phydev
= ugeth
->phydev
;
369 if (phydev
&& phydev
->irq
)
370 wol
->supported
|= WAKE_PHY
;
371 if (qe_alive_during_sleep())
372 wol
->supported
|= WAKE_MAGIC
;
374 wol
->wolopts
= ugeth
->wol_en
;
377 static int uec_set_wol(struct net_device
*netdev
, struct ethtool_wolinfo
*wol
)
379 struct ucc_geth_private
*ugeth
= netdev_priv(netdev
);
380 struct phy_device
*phydev
= ugeth
->phydev
;
382 if (wol
->wolopts
& ~(WAKE_PHY
| WAKE_MAGIC
))
384 else if (wol
->wolopts
& WAKE_PHY
&& (!phydev
|| !phydev
->irq
))
386 else if (wol
->wolopts
& WAKE_MAGIC
&& !qe_alive_during_sleep())
389 ugeth
->wol_en
= wol
->wolopts
;
390 device_set_wakeup_enable(&netdev
->dev
, ugeth
->wol_en
);
396 #define uec_get_wol NULL
397 #define uec_set_wol NULL
398 #endif /* CONFIG_PM */
400 static const struct ethtool_ops uec_ethtool_ops
= {
401 .get_settings
= uec_get_settings
,
402 .set_settings
= uec_set_settings
,
403 .get_drvinfo
= uec_get_drvinfo
,
404 .get_regs_len
= uec_get_regs_len
,
405 .get_regs
= uec_get_regs
,
406 .get_msglevel
= uec_get_msglevel
,
407 .set_msglevel
= uec_set_msglevel
,
408 .nway_reset
= uec_nway_reset
,
409 .get_link
= ethtool_op_get_link
,
410 .get_ringparam
= uec_get_ringparam
,
411 .set_ringparam
= uec_set_ringparam
,
412 .get_pauseparam
= uec_get_pauseparam
,
413 .set_pauseparam
= uec_set_pauseparam
,
414 .set_sg
= ethtool_op_set_sg
,
415 .get_sset_count
= uec_get_sset_count
,
416 .get_strings
= uec_get_strings
,
417 .get_ethtool_stats
= uec_get_ethtool_stats
,
418 .get_wol
= uec_get_wol
,
419 .set_wol
= uec_set_wol
,
422 void uec_set_ethtool_ops(struct net_device
*netdev
)
424 SET_ETHTOOL_OPS(netdev
, &uec_ethtool_ops
);