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) {
322 base = (u32 __iomem *)&ugeth->ug_regs->tx64;
323 for (i = 0; i < UEC_HW_STATS_LEN; i++)
324 data[j++] = in_be32(&base[i]);
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 strncpy(drvinfo->driver, DRV_NAME, 32);
351 strncpy(drvinfo->version, DRV_VERSION, 32);
352 strncpy(drvinfo->fw_version, "N/A", 32);
353 strncpy(drvinfo->bus_info, "QUICC ENGINE", 32);
354 drvinfo->eedump_len = 0;
355 drvinfo->regdump_len = uec_get_regs_len(netdev);
358 static const struct ethtool_ops uec_ethtool_ops = {
359 .get_settings = uec_get_settings,
360 .set_settings = uec_set_settings,
361 .get_drvinfo = uec_get_drvinfo,
362 .get_regs_len = uec_get_regs_len,
363 .get_regs = uec_get_regs,
364 .get_msglevel = uec_get_msglevel,
365 .set_msglevel = uec_set_msglevel,
366 .nway_reset = uec_nway_reset,
367 .get_link = ethtool_op_get_link,
368 .get_ringparam = uec_get_ringparam,
369 .set_ringparam = uec_set_ringparam,
370 .get_pauseparam = uec_get_pauseparam,
371 .set_pauseparam = uec_set_pauseparam,
372 .set_sg = ethtool_op_set_sg,
373 .get_sset_count = uec_get_sset_count,
374 .get_strings = uec_get_strings,
375 .get_ethtool_stats = uec_get_ethtool_stats,
378 void uec_set_ethtool_ops(struct net_device *netdev)
380 SET_ETHTOOL_OPS(netdev, &uec_ethtool_ops);