blob: cc83350d56ba1c05aa7eb619b607635f76de6400 [file] [log] [blame]
Li Yangac421852007-07-19 11:47:47 +08001/*
2 * Copyright (c) 2007 Freescale Semiconductor, Inc. All rights reserved.
3 *
4 * Description: QE UCC Gigabit Ethernet Ethtool API Set
5 *
6 * Author: Li Yang <leoli@freescale.com>
7 *
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -04008 * Limitation:
Justin P. Mattock70f23fd2011-05-10 10:16:21 +02009 * Can only get/set settings of the first queue.
Martin Olsson98a17082009-04-22 18:21:29 +020010 * Need to re-open the interface manually after changing some parameters.
Li Yangac421852007-07-19 11:47:47 +080011 *
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.
16 */
17
18#include <linux/kernel.h>
Li Yangac421852007-07-19 11:47:47 +080019#include <linux/errno.h>
Li Yangac421852007-07-19 11:47:47 +080020#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>
26#include <linux/mm.h>
27#include <linux/delay.h>
28#include <linux/dma-mapping.h>
Li Yangac421852007-07-19 11:47:47 +080029#include <linux/ethtool.h>
30#include <linux/mii.h>
31#include <linux/phy.h>
32
33#include <asm/io.h>
34#include <asm/irq.h>
35#include <asm/uaccess.h>
36#include <asm/types.h>
Li Yangac421852007-07-19 11:47:47 +080037
38#include "ucc_geth.h"
Li Yangac421852007-07-19 11:47:47 +080039
Joe Perchesc84d8052013-04-13 19:03:19 +000040static const char hw_stat_gstrings[][ETH_GSTRING_LEN] = {
Li Yangac421852007-07-19 11:47:47 +080041 "tx-64-frames",
42 "tx-65-127-frames",
43 "tx-128-255-frames",
44 "rx-64-frames",
45 "rx-65-127-frames",
46 "rx-128-255-frames",
47 "tx-bytes-ok",
48 "tx-pause-frames",
49 "tx-multicast-frames",
50 "tx-broadcast-frames",
51 "rx-frames",
52 "rx-bytes-ok",
53 "rx-bytes-all",
54 "rx-multicast-frames",
55 "rx-broadcast-frames",
56 "stats-counter-carry",
57 "stats-counter-mask",
58 "rx-dropped-frames",
59};
60
Joe Perchesc84d8052013-04-13 19:03:19 +000061static const char tx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
Li Yangac421852007-07-19 11:47:47 +080062 "tx-single-collision",
63 "tx-multiple-collision",
64 "tx-late-collsion",
65 "tx-aborted-frames",
66 "tx-lost-frames",
67 "tx-carrier-sense-errors",
68 "tx-frames-ok",
69 "tx-excessive-differ-frames",
70 "tx-256-511-frames",
Li Yang08722bc2008-05-23 18:11:27 +080071 "tx-512-1023-frames",
Li Yangac421852007-07-19 11:47:47 +080072 "tx-1024-1518-frames",
73 "tx-jumbo-frames",
74};
75
Joe Perchesc84d8052013-04-13 19:03:19 +000076static const char rx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
Li Yangac421852007-07-19 11:47:47 +080077 "rx-crc-errors",
78 "rx-alignment-errors",
79 "rx-in-range-length-errors",
80 "rx-out-of-range-length-errors",
81 "rx-too-long-frames",
82 "rx-runt",
83 "rx-very-long-event",
84 "rx-symbol-errors",
85 "rx-busy-drop-frames",
86 "reserved",
87 "reserved",
88 "rx-mismatch-drop-frames",
89 "rx-small-than-64",
90 "rx-256-511-frames",
91 "rx-512-1023-frames",
92 "rx-1024-1518-frames",
93 "rx-jumbo-frames",
94 "rx-mac-error-loss",
95 "rx-pause-frames",
96 "reserved",
97 "rx-vlan-removed",
98 "rx-vlan-replaced",
99 "rx-vlan-inserted",
100 "rx-ip-checksum-errors",
101};
102
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)
106
Li Yangac421852007-07-19 11:47:47 +0800107static int
108uec_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
109{
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;
113
114 if (!phydev)
115 return -ENODEV;
116
117 ecmd->maxtxpkt = 1;
118 ecmd->maxrxpkt = ug_info->interruptcoalescingmaxvalue[0];
119
120 return phy_ethtool_gset(phydev, ecmd);
121}
122
123static int
124uec_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
125{
126 struct ucc_geth_private *ugeth = netdev_priv(netdev);
127 struct phy_device *phydev = ugeth->phydev;
128
129 if (!phydev)
130 return -ENODEV;
131
132 return phy_ethtool_sset(phydev, ecmd);
133}
134
135static void
136uec_get_pauseparam(struct net_device *netdev,
137 struct ethtool_pauseparam *pause)
138{
139 struct ucc_geth_private *ugeth = netdev_priv(netdev);
140
141 pause->autoneg = ugeth->phydev->autoneg;
142
143 if (ugeth->ug_info->receiveFlowControl)
144 pause->rx_pause = 1;
145 if (ugeth->ug_info->transmitFlowControl)
146 pause->tx_pause = 1;
147}
148
149static int
150uec_set_pauseparam(struct net_device *netdev,
151 struct ethtool_pauseparam *pause)
152{
153 struct ucc_geth_private *ugeth = netdev_priv(netdev);
154 int ret = 0;
155
156 ugeth->ug_info->receiveFlowControl = pause->rx_pause;
157 ugeth->ug_info->transmitFlowControl = pause->tx_pause;
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -0400158
Li Yangac421852007-07-19 11:47:47 +0800159 if (ugeth->phydev->autoneg) {
160 if (netif_running(netdev)) {
161 /* FIXME: automatically restart */
Joe Perchesc84d8052013-04-13 19:03:19 +0000162 netdev_info(netdev, "Please re-open the interface\n");
Li Yangac421852007-07-19 11:47:47 +0800163 }
164 } else {
165 struct ucc_geth_info *ug_info = ugeth->ug_info;
166
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);
175 }
176
177 return ret;
178}
179
180static uint32_t
181uec_get_msglevel(struct net_device *netdev)
182{
183 struct ucc_geth_private *ugeth = netdev_priv(netdev);
184 return ugeth->msg_enable;
185}
186
187static void
188uec_set_msglevel(struct net_device *netdev, uint32_t data)
189{
190 struct ucc_geth_private *ugeth = netdev_priv(netdev);
191 ugeth->msg_enable = data;
192}
193
194static int
195uec_get_regs_len(struct net_device *netdev)
196{
197 return sizeof(struct ucc_geth);
198}
199
200static void
201uec_get_regs(struct net_device *netdev,
202 struct ethtool_regs *regs, void *p)
203{
204 int i;
205 struct ucc_geth_private *ugeth = netdev_priv(netdev);
206 u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs;
207 u32 *buff = p;
208
209 for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++)
210 buff[i] = in_be32(&ug_regs[i]);
211}
212
213static void
214uec_get_ringparam(struct net_device *netdev,
215 struct ethtool_ringparam *ring)
216{
217 struct ucc_geth_private *ugeth = netdev_priv(netdev);
218 struct ucc_geth_info *ug_info = ugeth->ug_info;
219 int queue = 0;
220
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;
225
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];
230}
231
232static int
233uec_set_ringparam(struct net_device *netdev,
234 struct ethtool_ringparam *ring)
235{
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;
239
240 if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) {
Joe Perchesc84d8052013-04-13 19:03:19 +0000241 netdev_info(netdev, "RxBD ring size must be no smaller than %d\n",
242 UCC_GETH_RX_BD_RING_SIZE_MIN);
Li Yangac421852007-07-19 11:47:47 +0800243 return -EINVAL;
244 }
245 if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) {
Joe Perchesc84d8052013-04-13 19:03:19 +0000246 netdev_info(netdev, "RxBD ring size must be multiple of %d\n",
247 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT);
Li Yangac421852007-07-19 11:47:47 +0800248 return -EINVAL;
249 }
250 if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) {
Joe Perchesc84d8052013-04-13 19:03:19 +0000251 netdev_info(netdev, "TxBD ring size must be no smaller than %d\n",
252 UCC_GETH_TX_BD_RING_SIZE_MIN);
Li Yangac421852007-07-19 11:47:47 +0800253 return -EINVAL;
254 }
255
256 ug_info->bdRingLenRx[queue] = ring->rx_pending;
257 ug_info->bdRingLenTx[queue] = ring->tx_pending;
258
259 if (netif_running(netdev)) {
260 /* FIXME: restart automatically */
Joe Perchesc84d8052013-04-13 19:03:19 +0000261 netdev_info(netdev, "Please re-open the interface\n");
Li Yangac421852007-07-19 11:47:47 +0800262 }
263
264 return ret;
265}
266
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700267static int uec_get_sset_count(struct net_device *netdev, int sset)
Li Yangac421852007-07-19 11:47:47 +0800268{
269 struct ucc_geth_private *ugeth = netdev_priv(netdev);
270 u32 stats_mode = ugeth->ug_info->statisticsMode;
271 int len = 0;
272
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700273 switch (sset) {
274 case ETH_SS_STATS:
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;
Li Yangac421852007-07-19 11:47:47 +0800281
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700282 return len;
283
284 default:
285 return -EOPNOTSUPP;
286 }
Li Yangac421852007-07-19 11:47:47 +0800287}
288
289static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
290{
291 struct ucc_geth_private *ugeth = netdev_priv(netdev);
292 u32 stats_mode = ugeth->ug_info->statisticsMode;
293
294 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
295 memcpy(buf, hw_stat_gstrings, UEC_HW_STATS_LEN *
296 ETH_GSTRING_LEN);
297 buf += UEC_HW_STATS_LEN * ETH_GSTRING_LEN;
298 }
299 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
300 memcpy(buf, tx_fw_stat_gstrings, UEC_TX_FW_STATS_LEN *
301 ETH_GSTRING_LEN);
302 buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN;
303 }
304 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
Joakim Tjernlund25f03dc2008-05-23 18:11:26 +0800305 memcpy(buf, rx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
Li Yangac421852007-07-19 11:47:47 +0800306 ETH_GSTRING_LEN);
307}
308
309static void uec_get_ethtool_stats(struct net_device *netdev,
310 struct ethtool_stats *stats, uint64_t *data)
311{
312 struct ucc_geth_private *ugeth = netdev_priv(netdev);
313 u32 stats_mode = ugeth->ug_info->statisticsMode;
314 u32 __iomem *base;
315 int i, j = 0;
316
317 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
Anton Vorontsove0ad2cd2009-08-27 07:35:47 +0000318 if (ugeth->ug_regs)
319 base = (u32 __iomem *)&ugeth->ug_regs->tx64;
320 else
321 base = NULL;
322
Li Yangac421852007-07-19 11:47:47 +0800323 for (i = 0; i < UEC_HW_STATS_LEN; i++)
Anton Vorontsove0ad2cd2009-08-27 07:35:47 +0000324 data[j++] = base ? in_be32(&base[i]) : 0;
Li Yangac421852007-07-19 11:47:47 +0800325 }
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++)
Anton Vorontsov18acfa22008-11-13 21:26:27 +0300329 data[j++] = base ? in_be32(&base[i]) : 0;
Li Yangac421852007-07-19 11:47:47 +0800330 }
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++)
Anton Vorontsov18acfa22008-11-13 21:26:27 +0300334 data[j++] = base ? in_be32(&base[i]) : 0;
Li Yangac421852007-07-19 11:47:47 +0800335 }
336}
337
338static int uec_nway_reset(struct net_device *netdev)
339{
340 struct ucc_geth_private *ugeth = netdev_priv(netdev);
341
342 return phy_start_aneg(ugeth->phydev);
343}
344
345/* Report driver information */
346static void
347uec_get_drvinfo(struct net_device *netdev,
348 struct ethtool_drvinfo *drvinfo)
349{
Jiri Pirko7826d432013-01-06 00:44:26 +0000350 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));
Li Yangac421852007-07-19 11:47:47 +0800354 drvinfo->eedump_len = 0;
355 drvinfo->regdump_len = uec_get_regs_len(netdev);
356}
357
Anton Vorontsov23949052009-08-27 07:35:57 +0000358#ifdef CONFIG_PM
359
360static void uec_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
361{
362 struct ucc_geth_private *ugeth = netdev_priv(netdev);
363 struct phy_device *phydev = ugeth->phydev;
364
365 if (phydev && phydev->irq)
366 wol->supported |= WAKE_PHY;
367 if (qe_alive_during_sleep())
368 wol->supported |= WAKE_MAGIC;
369
370 wol->wolopts = ugeth->wol_en;
371}
372
373static int uec_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
374{
375 struct ucc_geth_private *ugeth = netdev_priv(netdev);
376 struct phy_device *phydev = ugeth->phydev;
377
378 if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
379 return -EINVAL;
380 else if (wol->wolopts & WAKE_PHY && (!phydev || !phydev->irq))
381 return -EINVAL;
382 else if (wol->wolopts & WAKE_MAGIC && !qe_alive_during_sleep())
383 return -EINVAL;
384
385 ugeth->wol_en = wol->wolopts;
386 device_set_wakeup_enable(&netdev->dev, ugeth->wol_en);
387
388 return 0;
389}
390
391#else
392#define uec_get_wol NULL
393#define uec_set_wol NULL
394#endif /* CONFIG_PM */
395
Li Yangac421852007-07-19 11:47:47 +0800396static const struct ethtool_ops uec_ethtool_ops = {
397 .get_settings = uec_get_settings,
398 .set_settings = uec_set_settings,
399 .get_drvinfo = uec_get_drvinfo,
400 .get_regs_len = uec_get_regs_len,
401 .get_regs = uec_get_regs,
402 .get_msglevel = uec_get_msglevel,
403 .set_msglevel = uec_set_msglevel,
404 .nway_reset = uec_nway_reset,
405 .get_link = ethtool_op_get_link,
406 .get_ringparam = uec_get_ringparam,
407 .set_ringparam = uec_set_ringparam,
408 .get_pauseparam = uec_get_pauseparam,
409 .set_pauseparam = uec_set_pauseparam,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700410 .get_sset_count = uec_get_sset_count,
Li Yangac421852007-07-19 11:47:47 +0800411 .get_strings = uec_get_strings,
412 .get_ethtool_stats = uec_get_ethtool_stats,
Anton Vorontsov23949052009-08-27 07:35:57 +0000413 .get_wol = uec_get_wol,
414 .set_wol = uec_set_wol,
Richard Cochrane117d6d2012-04-03 22:59:40 +0000415 .get_ts_info = ethtool_op_get_ts_info,
Li Yangac421852007-07-19 11:47:47 +0800416};
417
418void uec_set_ethtool_ops(struct net_device *netdev)
419{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000420 netdev->ethtool_ops = &uec_ethtool_ops;
Li Yangac421852007-07-19 11:47:47 +0800421}