blob: 812a968a78e9808c37fa9bef1d308b42fead4d95 [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
Philippe Reynes5e74bf22016-05-01 17:08:09 +0200108uec_get_ksettings(struct net_device *netdev, struct ethtool_link_ksettings *cmd)
Li Yangac421852007-07-19 11:47:47 +0800109{
110 struct ucc_geth_private *ugeth = netdev_priv(netdev);
111 struct phy_device *phydev = ugeth->phydev;
Li Yangac421852007-07-19 11:47:47 +0800112
113 if (!phydev)
114 return -ENODEV;
115
Philippe Reynes5e74bf22016-05-01 17:08:09 +0200116 return phy_ethtool_ksettings_get(phydev, cmd);
Li Yangac421852007-07-19 11:47:47 +0800117}
118
119static int
Philippe Reynes5e74bf22016-05-01 17:08:09 +0200120uec_set_ksettings(struct net_device *netdev,
121 const struct ethtool_link_ksettings *cmd)
Li Yangac421852007-07-19 11:47:47 +0800122{
123 struct ucc_geth_private *ugeth = netdev_priv(netdev);
124 struct phy_device *phydev = ugeth->phydev;
125
126 if (!phydev)
127 return -ENODEV;
128
Philippe Reynes5e74bf22016-05-01 17:08:09 +0200129 return phy_ethtool_ksettings_set(phydev, cmd);
Li Yangac421852007-07-19 11:47:47 +0800130}
131
132static void
133uec_get_pauseparam(struct net_device *netdev,
134 struct ethtool_pauseparam *pause)
135{
136 struct ucc_geth_private *ugeth = netdev_priv(netdev);
137
138 pause->autoneg = ugeth->phydev->autoneg;
139
140 if (ugeth->ug_info->receiveFlowControl)
141 pause->rx_pause = 1;
142 if (ugeth->ug_info->transmitFlowControl)
143 pause->tx_pause = 1;
144}
145
146static int
147uec_set_pauseparam(struct net_device *netdev,
148 struct ethtool_pauseparam *pause)
149{
150 struct ucc_geth_private *ugeth = netdev_priv(netdev);
151 int ret = 0;
152
153 ugeth->ug_info->receiveFlowControl = pause->rx_pause;
154 ugeth->ug_info->transmitFlowControl = pause->tx_pause;
Jeff Garzik7d2e3cb2008-05-13 01:41:58 -0400155
Li Yangac421852007-07-19 11:47:47 +0800156 if (ugeth->phydev->autoneg) {
157 if (netif_running(netdev)) {
158 /* FIXME: automatically restart */
Joe Perchesc84d8052013-04-13 19:03:19 +0000159 netdev_info(netdev, "Please re-open the interface\n");
Li Yangac421852007-07-19 11:47:47 +0800160 }
161 } else {
162 struct ucc_geth_info *ug_info = ugeth->ug_info;
163
164 ret = init_flow_control_params(ug_info->aufc,
165 ug_info->receiveFlowControl,
166 ug_info->transmitFlowControl,
167 ug_info->pausePeriod,
168 ug_info->extensionField,
169 &ugeth->uccf->uf_regs->upsmr,
170 &ugeth->ug_regs->uempr,
171 &ugeth->ug_regs->maccfg1);
172 }
173
174 return ret;
175}
176
177static uint32_t
178uec_get_msglevel(struct net_device *netdev)
179{
180 struct ucc_geth_private *ugeth = netdev_priv(netdev);
181 return ugeth->msg_enable;
182}
183
184static void
185uec_set_msglevel(struct net_device *netdev, uint32_t data)
186{
187 struct ucc_geth_private *ugeth = netdev_priv(netdev);
188 ugeth->msg_enable = data;
189}
190
191static int
192uec_get_regs_len(struct net_device *netdev)
193{
194 return sizeof(struct ucc_geth);
195}
196
197static void
198uec_get_regs(struct net_device *netdev,
199 struct ethtool_regs *regs, void *p)
200{
201 int i;
202 struct ucc_geth_private *ugeth = netdev_priv(netdev);
203 u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs;
204 u32 *buff = p;
205
206 for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++)
207 buff[i] = in_be32(&ug_regs[i]);
208}
209
210static void
211uec_get_ringparam(struct net_device *netdev,
212 struct ethtool_ringparam *ring)
213{
214 struct ucc_geth_private *ugeth = netdev_priv(netdev);
215 struct ucc_geth_info *ug_info = ugeth->ug_info;
216 int queue = 0;
217
218 ring->rx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
219 ring->rx_mini_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
220 ring->rx_jumbo_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
221 ring->tx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
222
223 ring->rx_pending = ug_info->bdRingLenRx[queue];
224 ring->rx_mini_pending = ug_info->bdRingLenRx[queue];
225 ring->rx_jumbo_pending = ug_info->bdRingLenRx[queue];
226 ring->tx_pending = ug_info->bdRingLenTx[queue];
227}
228
229static int
230uec_set_ringparam(struct net_device *netdev,
231 struct ethtool_ringparam *ring)
232{
233 struct ucc_geth_private *ugeth = netdev_priv(netdev);
234 struct ucc_geth_info *ug_info = ugeth->ug_info;
235 int queue = 0, ret = 0;
236
237 if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) {
Joe Perchesc84d8052013-04-13 19:03:19 +0000238 netdev_info(netdev, "RxBD ring size must be no smaller than %d\n",
239 UCC_GETH_RX_BD_RING_SIZE_MIN);
Li Yangac421852007-07-19 11:47:47 +0800240 return -EINVAL;
241 }
242 if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) {
Joe Perchesc84d8052013-04-13 19:03:19 +0000243 netdev_info(netdev, "RxBD ring size must be multiple of %d\n",
244 UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT);
Li Yangac421852007-07-19 11:47:47 +0800245 return -EINVAL;
246 }
247 if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) {
Joe Perchesc84d8052013-04-13 19:03:19 +0000248 netdev_info(netdev, "TxBD ring size must be no smaller than %d\n",
249 UCC_GETH_TX_BD_RING_SIZE_MIN);
Li Yangac421852007-07-19 11:47:47 +0800250 return -EINVAL;
251 }
252
253 ug_info->bdRingLenRx[queue] = ring->rx_pending;
254 ug_info->bdRingLenTx[queue] = ring->tx_pending;
255
256 if (netif_running(netdev)) {
257 /* FIXME: restart automatically */
Joe Perchesc84d8052013-04-13 19:03:19 +0000258 netdev_info(netdev, "Please re-open the interface\n");
Li Yangac421852007-07-19 11:47:47 +0800259 }
260
261 return ret;
262}
263
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700264static int uec_get_sset_count(struct net_device *netdev, int sset)
Li Yangac421852007-07-19 11:47:47 +0800265{
266 struct ucc_geth_private *ugeth = netdev_priv(netdev);
267 u32 stats_mode = ugeth->ug_info->statisticsMode;
268 int len = 0;
269
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700270 switch (sset) {
271 case ETH_SS_STATS:
272 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
273 len += UEC_HW_STATS_LEN;
274 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
275 len += UEC_TX_FW_STATS_LEN;
276 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
277 len += UEC_RX_FW_STATS_LEN;
Li Yangac421852007-07-19 11:47:47 +0800278
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700279 return len;
280
281 default:
282 return -EOPNOTSUPP;
283 }
Li Yangac421852007-07-19 11:47:47 +0800284}
285
286static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
287{
288 struct ucc_geth_private *ugeth = netdev_priv(netdev);
289 u32 stats_mode = ugeth->ug_info->statisticsMode;
290
291 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
292 memcpy(buf, hw_stat_gstrings, UEC_HW_STATS_LEN *
293 ETH_GSTRING_LEN);
294 buf += UEC_HW_STATS_LEN * ETH_GSTRING_LEN;
295 }
296 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
297 memcpy(buf, tx_fw_stat_gstrings, UEC_TX_FW_STATS_LEN *
298 ETH_GSTRING_LEN);
299 buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN;
300 }
301 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
Joakim Tjernlund25f03dc2008-05-23 18:11:26 +0800302 memcpy(buf, rx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
Li Yangac421852007-07-19 11:47:47 +0800303 ETH_GSTRING_LEN);
304}
305
306static void uec_get_ethtool_stats(struct net_device *netdev,
307 struct ethtool_stats *stats, uint64_t *data)
308{
309 struct ucc_geth_private *ugeth = netdev_priv(netdev);
310 u32 stats_mode = ugeth->ug_info->statisticsMode;
311 u32 __iomem *base;
312 int i, j = 0;
313
314 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
Anton Vorontsove0ad2cd2009-08-27 07:35:47 +0000315 if (ugeth->ug_regs)
316 base = (u32 __iomem *)&ugeth->ug_regs->tx64;
317 else
318 base = NULL;
319
Li Yangac421852007-07-19 11:47:47 +0800320 for (i = 0; i < UEC_HW_STATS_LEN; i++)
Anton Vorontsove0ad2cd2009-08-27 07:35:47 +0000321 data[j++] = base ? in_be32(&base[i]) : 0;
Li Yangac421852007-07-19 11:47:47 +0800322 }
323 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
324 base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram;
325 for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
Anton Vorontsov18acfa22008-11-13 21:26:27 +0300326 data[j++] = base ? in_be32(&base[i]) : 0;
Li Yangac421852007-07-19 11:47:47 +0800327 }
328 if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
329 base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram;
330 for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
Anton Vorontsov18acfa22008-11-13 21:26:27 +0300331 data[j++] = base ? in_be32(&base[i]) : 0;
Li Yangac421852007-07-19 11:47:47 +0800332 }
333}
334
335static int uec_nway_reset(struct net_device *netdev)
336{
337 struct ucc_geth_private *ugeth = netdev_priv(netdev);
338
339 return phy_start_aneg(ugeth->phydev);
340}
341
342/* Report driver information */
343static void
344uec_get_drvinfo(struct net_device *netdev,
345 struct ethtool_drvinfo *drvinfo)
346{
Jiri Pirko7826d432013-01-06 00:44:26 +0000347 strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
348 strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
349 strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
350 strlcpy(drvinfo->bus_info, "QUICC ENGINE", sizeof(drvinfo->bus_info));
Li Yangac421852007-07-19 11:47:47 +0800351}
352
Anton Vorontsov23949052009-08-27 07:35:57 +0000353#ifdef CONFIG_PM
354
355static void uec_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
356{
357 struct ucc_geth_private *ugeth = netdev_priv(netdev);
358 struct phy_device *phydev = ugeth->phydev;
359
360 if (phydev && phydev->irq)
361 wol->supported |= WAKE_PHY;
362 if (qe_alive_during_sleep())
363 wol->supported |= WAKE_MAGIC;
364
365 wol->wolopts = ugeth->wol_en;
366}
367
368static int uec_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
369{
370 struct ucc_geth_private *ugeth = netdev_priv(netdev);
371 struct phy_device *phydev = ugeth->phydev;
372
373 if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
374 return -EINVAL;
375 else if (wol->wolopts & WAKE_PHY && (!phydev || !phydev->irq))
376 return -EINVAL;
377 else if (wol->wolopts & WAKE_MAGIC && !qe_alive_during_sleep())
378 return -EINVAL;
379
380 ugeth->wol_en = wol->wolopts;
381 device_set_wakeup_enable(&netdev->dev, ugeth->wol_en);
382
383 return 0;
384}
385
386#else
387#define uec_get_wol NULL
388#define uec_set_wol NULL
389#endif /* CONFIG_PM */
390
Li Yangac421852007-07-19 11:47:47 +0800391static const struct ethtool_ops uec_ethtool_ops = {
Li Yangac421852007-07-19 11:47:47 +0800392 .get_drvinfo = uec_get_drvinfo,
393 .get_regs_len = uec_get_regs_len,
394 .get_regs = uec_get_regs,
395 .get_msglevel = uec_get_msglevel,
396 .set_msglevel = uec_set_msglevel,
397 .nway_reset = uec_nway_reset,
398 .get_link = ethtool_op_get_link,
399 .get_ringparam = uec_get_ringparam,
400 .set_ringparam = uec_set_ringparam,
401 .get_pauseparam = uec_get_pauseparam,
402 .set_pauseparam = uec_set_pauseparam,
Jeff Garzikb9f2c042007-10-03 18:07:32 -0700403 .get_sset_count = uec_get_sset_count,
Li Yangac421852007-07-19 11:47:47 +0800404 .get_strings = uec_get_strings,
405 .get_ethtool_stats = uec_get_ethtool_stats,
Anton Vorontsov23949052009-08-27 07:35:57 +0000406 .get_wol = uec_get_wol,
407 .set_wol = uec_set_wol,
Richard Cochrane117d6d2012-04-03 22:59:40 +0000408 .get_ts_info = ethtool_op_get_ts_info,
Philippe Reynes5e74bf22016-05-01 17:08:09 +0200409 .get_link_ksettings = uec_get_ksettings,
410 .set_link_ksettings = uec_set_ksettings,
Li Yangac421852007-07-19 11:47:47 +0800411};
412
413void uec_set_ethtool_ops(struct net_device *netdev)
414{
Wilfried Klaebe7ad24ea2014-05-11 00:12:32 +0000415 netdev->ethtool_ops = &uec_ethtool_ops;
Li Yangac421852007-07-19 11:47:47 +0800416}