Linux Audio

Check our new training course

Loading...
v4.17
 
  1/*
  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 *
  8 * Limitation:
  9 * Can only get/set settings of the first queue.
 10 * Need to re-open the interface manually after changing some parameters.
 11 *
 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>
 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>
 26#include <linux/mm.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>
 32
 33#include <asm/io.h>
 34#include <asm/irq.h>
 35#include <linux/uaccess.h>
 36#include <asm/types.h>
 37
 38#include "ucc_geth.h"
 39
 40static const char hw_stat_gstrings[][ETH_GSTRING_LEN] = {
 41	"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
 61static const char tx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
 62	"tx-single-collision",
 63	"tx-multiple-collision",
 64	"tx-late-collision",
 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",
 71	"tx-512-1023-frames",
 72	"tx-1024-1518-frames",
 73	"tx-jumbo-frames",
 74};
 75
 76static const char rx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
 77	"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
107static int
108uec_get_ksettings(struct net_device *netdev, struct ethtool_link_ksettings *cmd)
109{
110	struct ucc_geth_private *ugeth = netdev_priv(netdev);
111	struct phy_device *phydev = ugeth->phydev;
112
113	if (!phydev)
114		return -ENODEV;
115
116	phy_ethtool_ksettings_get(phydev, cmd);
117
118	return 0;
119}
120
121static int
122uec_set_ksettings(struct net_device *netdev,
123		  const struct ethtool_link_ksettings *cmd)
124{
125	struct ucc_geth_private *ugeth = netdev_priv(netdev);
126	struct phy_device *phydev = ugeth->phydev;
127
128	if (!phydev)
129		return -ENODEV;
130
131	return phy_ethtool_ksettings_set(phydev, cmd);
132}
133
134static void
135uec_get_pauseparam(struct net_device *netdev,
136                     struct ethtool_pauseparam *pause)
137{
138	struct ucc_geth_private *ugeth = netdev_priv(netdev);
139
140	pause->autoneg = ugeth->phydev->autoneg;
141
142	if (ugeth->ug_info->receiveFlowControl)
143		pause->rx_pause = 1;
144	if (ugeth->ug_info->transmitFlowControl)
145		pause->tx_pause = 1;
146}
147
148static int
149uec_set_pauseparam(struct net_device *netdev,
150                     struct ethtool_pauseparam *pause)
151{
152	struct ucc_geth_private *ugeth = netdev_priv(netdev);
153	int ret = 0;
154
155	ugeth->ug_info->receiveFlowControl = pause->rx_pause;
156	ugeth->ug_info->transmitFlowControl = pause->tx_pause;
157
158	if (ugeth->phydev->autoneg) {
159		if (netif_running(netdev)) {
160			/* FIXME: automatically restart */
161			netdev_info(netdev, "Please re-open the interface\n");
162		}
163	} else {
164		struct ucc_geth_info *ug_info = ugeth->ug_info;
165
166		ret = init_flow_control_params(ug_info->aufc,
167					ug_info->receiveFlowControl,
168					ug_info->transmitFlowControl,
169					ug_info->pausePeriod,
170					ug_info->extensionField,
171					&ugeth->uccf->uf_regs->upsmr,
172					&ugeth->ug_regs->uempr,
173					&ugeth->ug_regs->maccfg1);
174	}
175
176	return ret;
177}
178
179static uint32_t
180uec_get_msglevel(struct net_device *netdev)
181{
182	struct ucc_geth_private *ugeth = netdev_priv(netdev);
183	return ugeth->msg_enable;
184}
185
186static void
187uec_set_msglevel(struct net_device *netdev, uint32_t data)
188{
189	struct ucc_geth_private *ugeth = netdev_priv(netdev);
190	ugeth->msg_enable = data;
191}
192
193static int
194uec_get_regs_len(struct net_device *netdev)
195{
196	return sizeof(struct ucc_geth);
197}
198
199static void
200uec_get_regs(struct net_device *netdev,
201               struct ethtool_regs *regs, void *p)
202{
203	int i;
204	struct ucc_geth_private *ugeth = netdev_priv(netdev);
205	u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs;
206	u32 *buff = p;
207
208	for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++)
209		buff[i] = in_be32(&ug_regs[i]);
210}
211
212static void
213uec_get_ringparam(struct net_device *netdev,
214                    struct ethtool_ringparam *ring)
 
 
215{
216	struct ucc_geth_private *ugeth = netdev_priv(netdev);
217	struct ucc_geth_info *ug_info = ugeth->ug_info;
218	int queue = 0;
219
220	ring->rx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
221	ring->rx_mini_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
222	ring->rx_jumbo_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
223	ring->tx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
224
225	ring->rx_pending = ug_info->bdRingLenRx[queue];
226	ring->rx_mini_pending = ug_info->bdRingLenRx[queue];
227	ring->rx_jumbo_pending = ug_info->bdRingLenRx[queue];
228	ring->tx_pending = ug_info->bdRingLenTx[queue];
229}
230
231static int
232uec_set_ringparam(struct net_device *netdev,
233                    struct ethtool_ringparam *ring)
 
 
234{
235	struct ucc_geth_private *ugeth = netdev_priv(netdev);
236	struct ucc_geth_info *ug_info = ugeth->ug_info;
237	int queue = 0, ret = 0;
238
239	if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) {
240		netdev_info(netdev, "RxBD ring size must be no smaller than %d\n",
241			    UCC_GETH_RX_BD_RING_SIZE_MIN);
242		return -EINVAL;
243	}
244	if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) {
245		netdev_info(netdev, "RxBD ring size must be multiple of %d\n",
246			    UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT);
247		return -EINVAL;
248	}
249	if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) {
250		netdev_info(netdev, "TxBD ring size must be no smaller than %d\n",
251			    UCC_GETH_TX_BD_RING_SIZE_MIN);
252		return -EINVAL;
253	}
254
 
 
 
255	ug_info->bdRingLenRx[queue] = ring->rx_pending;
256	ug_info->bdRingLenTx[queue] = ring->tx_pending;
257
258	if (netif_running(netdev)) {
259		/* FIXME: restart automatically */
260		netdev_info(netdev, "Please re-open the interface\n");
261	}
262
263	return ret;
264}
265
266static int uec_get_sset_count(struct net_device *netdev, int sset)
267{
268	struct ucc_geth_private *ugeth = netdev_priv(netdev);
269	u32 stats_mode = ugeth->ug_info->statisticsMode;
270	int len = 0;
271
272	switch (sset) {
273	case ETH_SS_STATS:
274		if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
275			len += UEC_HW_STATS_LEN;
276		if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
277			len += UEC_TX_FW_STATS_LEN;
278		if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
279			len += UEC_RX_FW_STATS_LEN;
280
281		return len;
282
283	default:
284		return -EOPNOTSUPP;
285	}
286}
287
288static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
289{
290	struct ucc_geth_private *ugeth = netdev_priv(netdev);
291	u32 stats_mode = ugeth->ug_info->statisticsMode;
 
292
293	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
294		memcpy(buf, hw_stat_gstrings, UEC_HW_STATS_LEN *
295			       	ETH_GSTRING_LEN);
296		buf += UEC_HW_STATS_LEN * ETH_GSTRING_LEN;
297	}
298	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
299		memcpy(buf, tx_fw_stat_gstrings, UEC_TX_FW_STATS_LEN *
300			       	ETH_GSTRING_LEN);
301		buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN;
302	}
303	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
304		memcpy(buf, rx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
305			       	ETH_GSTRING_LEN);
306}
307
308static void uec_get_ethtool_stats(struct net_device *netdev,
309		struct ethtool_stats *stats, uint64_t *data)
310{
311	struct ucc_geth_private *ugeth = netdev_priv(netdev);
312	u32 stats_mode = ugeth->ug_info->statisticsMode;
313	u32 __iomem *base;
314	int i, j = 0;
315
316	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
317		if (ugeth->ug_regs)
318			base = (u32 __iomem *)&ugeth->ug_regs->tx64;
319		else
320			base = NULL;
321
322		for (i = 0; i < UEC_HW_STATS_LEN; i++)
323			data[j++] = base ? in_be32(&base[i]) : 0;
324	}
325	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
326		base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram;
327		for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
328			data[j++] = base ? in_be32(&base[i]) : 0;
329	}
330	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
331		base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram;
332		for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
333			data[j++] = base ? in_be32(&base[i]) : 0;
334	}
335}
336
337/* Report driver information */
338static void
339uec_get_drvinfo(struct net_device *netdev,
340                       struct ethtool_drvinfo *drvinfo)
341{
342	strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
343	strlcpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
344	strlcpy(drvinfo->fw_version, "N/A", sizeof(drvinfo->fw_version));
345	strlcpy(drvinfo->bus_info, "QUICC ENGINE", sizeof(drvinfo->bus_info));
346}
347
348#ifdef CONFIG_PM
349
350static void uec_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
351{
352	struct ucc_geth_private *ugeth = netdev_priv(netdev);
353	struct phy_device *phydev = ugeth->phydev;
354
355	if (phydev && phydev->irq)
356		wol->supported |= WAKE_PHY;
357	if (qe_alive_during_sleep())
358		wol->supported |= WAKE_MAGIC;
359
360	wol->wolopts = ugeth->wol_en;
361}
362
363static int uec_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
364{
365	struct ucc_geth_private *ugeth = netdev_priv(netdev);
366	struct phy_device *phydev = ugeth->phydev;
367
368	if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
369		return -EINVAL;
370	else if (wol->wolopts & WAKE_PHY && (!phydev || !phydev->irq))
371		return -EINVAL;
372	else if (wol->wolopts & WAKE_MAGIC && !qe_alive_during_sleep())
373		return -EINVAL;
374
375	ugeth->wol_en = wol->wolopts;
376	device_set_wakeup_enable(&netdev->dev, ugeth->wol_en);
377
378	return 0;
379}
380
381#else
382#define uec_get_wol NULL
383#define uec_set_wol NULL
384#endif /* CONFIG_PM */
385
386static const struct ethtool_ops uec_ethtool_ops = {
387	.get_drvinfo            = uec_get_drvinfo,
388	.get_regs_len           = uec_get_regs_len,
389	.get_regs               = uec_get_regs,
390	.get_msglevel           = uec_get_msglevel,
391	.set_msglevel           = uec_set_msglevel,
392	.nway_reset             = phy_ethtool_nway_reset,
393	.get_link               = ethtool_op_get_link,
394	.get_ringparam          = uec_get_ringparam,
395	.set_ringparam          = uec_set_ringparam,
396	.get_pauseparam         = uec_get_pauseparam,
397	.set_pauseparam         = uec_set_pauseparam,
398	.get_sset_count		= uec_get_sset_count,
399	.get_strings            = uec_get_strings,
400	.get_ethtool_stats      = uec_get_ethtool_stats,
401	.get_wol		= uec_get_wol,
402	.set_wol		= uec_set_wol,
403	.get_ts_info		= ethtool_op_get_ts_info,
404	.get_link_ksettings	= uec_get_ksettings,
405	.set_link_ksettings	= uec_set_ksettings,
406};
407
408void uec_set_ethtool_ops(struct net_device *netdev)
409{
410	netdev->ethtool_ops = &uec_ethtool_ops;
411}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * Copyright (c) 2007 Freescale Semiconductor, Inc. All rights reserved.
  4 *
  5 * Description: QE UCC Gigabit Ethernet Ethtool API Set
  6 *
  7 * Author: Li Yang <leoli@freescale.com>
  8 *
  9 * Limitation:
 10 * Can only get/set settings of the first queue.
 11 * Need to re-open the interface manually after changing some parameters.
 
 
 
 
 
 12 */
 13
 14#include <linux/kernel.h>
 15#include <linux/errno.h>
 16#include <linux/stddef.h>
 17#include <linux/interrupt.h>
 18#include <linux/netdevice.h>
 19#include <linux/etherdevice.h>
 20#include <linux/skbuff.h>
 21#include <linux/spinlock.h>
 22#include <linux/mm.h>
 23#include <linux/delay.h>
 24#include <linux/dma-mapping.h>
 25#include <linux/ethtool.h>
 26#include <linux/mii.h>
 27#include <linux/phy.h>
 28
 29#include <asm/io.h>
 30#include <asm/irq.h>
 31#include <linux/uaccess.h>
 32#include <asm/types.h>
 33
 34#include "ucc_geth.h"
 35
 36static const char hw_stat_gstrings[][ETH_GSTRING_LEN] = {
 37	"tx-64-frames",
 38	"tx-65-127-frames",
 39	"tx-128-255-frames",
 40	"rx-64-frames",
 41	"rx-65-127-frames",
 42	"rx-128-255-frames",
 43	"tx-bytes-ok",
 44	"tx-pause-frames",
 45	"tx-multicast-frames",
 46	"tx-broadcast-frames",
 47	"rx-frames",
 48	"rx-bytes-ok",
 49	"rx-bytes-all",
 50	"rx-multicast-frames",
 51	"rx-broadcast-frames",
 52	"stats-counter-carry",
 53	"stats-counter-mask",
 54	"rx-dropped-frames",
 55};
 56
 57static const char tx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
 58	"tx-single-collision",
 59	"tx-multiple-collision",
 60	"tx-late-collision",
 61	"tx-aborted-frames",
 62	"tx-lost-frames",
 63	"tx-carrier-sense-errors",
 64	"tx-frames-ok",
 65	"tx-excessive-differ-frames",
 66	"tx-256-511-frames",
 67	"tx-512-1023-frames",
 68	"tx-1024-1518-frames",
 69	"tx-jumbo-frames",
 70};
 71
 72static const char rx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
 73	"rx-crc-errors",
 74	"rx-alignment-errors",
 75	"rx-in-range-length-errors",
 76	"rx-out-of-range-length-errors",
 77	"rx-too-long-frames",
 78	"rx-runt",
 79	"rx-very-long-event",
 80	"rx-symbol-errors",
 81	"rx-busy-drop-frames",
 82	"reserved",
 83	"reserved",
 84	"rx-mismatch-drop-frames",
 85	"rx-small-than-64",
 86	"rx-256-511-frames",
 87	"rx-512-1023-frames",
 88	"rx-1024-1518-frames",
 89	"rx-jumbo-frames",
 90	"rx-mac-error-loss",
 91	"rx-pause-frames",
 92	"reserved",
 93	"rx-vlan-removed",
 94	"rx-vlan-replaced",
 95	"rx-vlan-inserted",
 96	"rx-ip-checksum-errors",
 97};
 98
 99#define UEC_HW_STATS_LEN ARRAY_SIZE(hw_stat_gstrings)
100#define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings)
101#define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings)
102
103static int
104uec_get_ksettings(struct net_device *netdev, struct ethtool_link_ksettings *cmd)
105{
106	struct ucc_geth_private *ugeth = netdev_priv(netdev);
107	struct phy_device *phydev = ugeth->phydev;
108
109	if (!phydev)
110		return -ENODEV;
111
112	phy_ethtool_ksettings_get(phydev, cmd);
113
114	return 0;
115}
116
117static int
118uec_set_ksettings(struct net_device *netdev,
119		  const struct ethtool_link_ksettings *cmd)
120{
121	struct ucc_geth_private *ugeth = netdev_priv(netdev);
122	struct phy_device *phydev = ugeth->phydev;
123
124	if (!phydev)
125		return -ENODEV;
126
127	return phy_ethtool_ksettings_set(phydev, cmd);
128}
129
130static void
131uec_get_pauseparam(struct net_device *netdev,
132                     struct ethtool_pauseparam *pause)
133{
134	struct ucc_geth_private *ugeth = netdev_priv(netdev);
135
136	pause->autoneg = ugeth->phydev->autoneg;
137
138	if (ugeth->ug_info->receiveFlowControl)
139		pause->rx_pause = 1;
140	if (ugeth->ug_info->transmitFlowControl)
141		pause->tx_pause = 1;
142}
143
144static int
145uec_set_pauseparam(struct net_device *netdev,
146                     struct ethtool_pauseparam *pause)
147{
148	struct ucc_geth_private *ugeth = netdev_priv(netdev);
149	int ret = 0;
150
151	ugeth->ug_info->receiveFlowControl = pause->rx_pause;
152	ugeth->ug_info->transmitFlowControl = pause->tx_pause;
153
154	if (ugeth->phydev->autoneg) {
155		if (netif_running(netdev)) {
156			/* FIXME: automatically restart */
157			netdev_info(netdev, "Please re-open the interface\n");
158		}
159	} else {
160		struct ucc_geth_info *ug_info = ugeth->ug_info;
161
162		ret = init_flow_control_params(ug_info->aufc,
163					ug_info->receiveFlowControl,
164					ug_info->transmitFlowControl,
165					ug_info->pausePeriod,
166					ug_info->extensionField,
167					&ugeth->uccf->uf_regs->upsmr,
168					&ugeth->ug_regs->uempr,
169					&ugeth->ug_regs->maccfg1);
170	}
171
172	return ret;
173}
174
175static uint32_t
176uec_get_msglevel(struct net_device *netdev)
177{
178	struct ucc_geth_private *ugeth = netdev_priv(netdev);
179	return ugeth->msg_enable;
180}
181
182static void
183uec_set_msglevel(struct net_device *netdev, uint32_t data)
184{
185	struct ucc_geth_private *ugeth = netdev_priv(netdev);
186	ugeth->msg_enable = data;
187}
188
189static int
190uec_get_regs_len(struct net_device *netdev)
191{
192	return sizeof(struct ucc_geth);
193}
194
195static void
196uec_get_regs(struct net_device *netdev,
197               struct ethtool_regs *regs, void *p)
198{
199	int i;
200	struct ucc_geth_private *ugeth = netdev_priv(netdev);
201	u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs;
202	u32 *buff = p;
203
204	for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++)
205		buff[i] = in_be32(&ug_regs[i]);
206}
207
208static void
209uec_get_ringparam(struct net_device *netdev,
210		  struct ethtool_ringparam *ring,
211		  struct kernel_ethtool_ringparam *kernel_ring,
212		  struct netlink_ext_ack *extack)
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		  struct kernel_ethtool_ringparam *kernel_ring,
233		  struct netlink_ext_ack *extack)
234{
235	struct ucc_geth_private *ugeth = netdev_priv(netdev);
236	struct ucc_geth_info *ug_info = ugeth->ug_info;
237	int queue = 0, ret = 0;
238
239	if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) {
240		netdev_info(netdev, "RxBD ring size must be no smaller than %d\n",
241			    UCC_GETH_RX_BD_RING_SIZE_MIN);
242		return -EINVAL;
243	}
244	if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) {
245		netdev_info(netdev, "RxBD ring size must be multiple of %d\n",
246			    UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT);
247		return -EINVAL;
248	}
249	if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) {
250		netdev_info(netdev, "TxBD ring size must be no smaller than %d\n",
251			    UCC_GETH_TX_BD_RING_SIZE_MIN);
252		return -EINVAL;
253	}
254
255	if (netif_running(netdev))
256		return -EBUSY;
257
258	ug_info->bdRingLenRx[queue] = ring->rx_pending;
259	ug_info->bdRingLenTx[queue] = ring->tx_pending;
260
 
 
 
 
 
261	return ret;
262}
263
264static int uec_get_sset_count(struct net_device *netdev, int sset)
265{
266	struct ucc_geth_private *ugeth = netdev_priv(netdev);
267	u32 stats_mode = ugeth->ug_info->statisticsMode;
268	int len = 0;
269
270	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;
278
279		return len;
280
281	default:
282		return -EOPNOTSUPP;
283	}
284}
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	int i;
291
292	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
293		for (i = 0; i < UEC_HW_STATS_LEN; i++)
294			ethtool_puts(&buf, hw_stat_gstrings[i]);
295	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
296		for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
297			ethtool_puts(&buf, tx_fw_stat_gstrings[i]);
 
 
 
 
298	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
299		for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
300			ethtool_puts(&buf, rx_fw_stat_gstrings[i]);
301}
302
303static void uec_get_ethtool_stats(struct net_device *netdev,
304		struct ethtool_stats *stats, uint64_t *data)
305{
306	struct ucc_geth_private *ugeth = netdev_priv(netdev);
307	u32 stats_mode = ugeth->ug_info->statisticsMode;
308	u32 __iomem *base;
309	int i, j = 0;
310
311	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
312		if (ugeth->ug_regs)
313			base = (u32 __iomem *)&ugeth->ug_regs->tx64;
314		else
315			base = NULL;
316
317		for (i = 0; i < UEC_HW_STATS_LEN; i++)
318			data[j++] = base ? in_be32(&base[i]) : 0;
319	}
320	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
321		base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram;
322		for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
323			data[j++] = base ? in_be32(&base[i]) : 0;
324	}
325	if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
326		base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram;
327		for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
328			data[j++] = base ? in_be32(&base[i]) : 0;
329	}
330}
331
332/* Report driver information */
333static void
334uec_get_drvinfo(struct net_device *netdev,
335                       struct ethtool_drvinfo *drvinfo)
336{
337	strscpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
338	strscpy(drvinfo->bus_info, "QUICC ENGINE", sizeof(drvinfo->bus_info));
 
 
339}
340
341#ifdef CONFIG_PM
342
343static void uec_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
344{
345	struct ucc_geth_private *ugeth = netdev_priv(netdev);
346	struct phy_device *phydev = ugeth->phydev;
347
348	if (phydev && phydev->irq)
349		wol->supported |= WAKE_PHY;
350	if (qe_alive_during_sleep())
351		wol->supported |= WAKE_MAGIC;
352
353	wol->wolopts = ugeth->wol_en;
354}
355
356static int uec_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
357{
358	struct ucc_geth_private *ugeth = netdev_priv(netdev);
359	struct phy_device *phydev = ugeth->phydev;
360
361	if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
362		return -EINVAL;
363	else if (wol->wolopts & WAKE_PHY && (!phydev || !phydev->irq))
364		return -EINVAL;
365	else if (wol->wolopts & WAKE_MAGIC && !qe_alive_during_sleep())
366		return -EINVAL;
367
368	ugeth->wol_en = wol->wolopts;
369	device_set_wakeup_enable(&netdev->dev, ugeth->wol_en);
370
371	return 0;
372}
373
374#else
375#define uec_get_wol NULL
376#define uec_set_wol NULL
377#endif /* CONFIG_PM */
378
379static const struct ethtool_ops uec_ethtool_ops = {
380	.get_drvinfo            = uec_get_drvinfo,
381	.get_regs_len           = uec_get_regs_len,
382	.get_regs               = uec_get_regs,
383	.get_msglevel           = uec_get_msglevel,
384	.set_msglevel           = uec_set_msglevel,
385	.nway_reset             = phy_ethtool_nway_reset,
386	.get_link               = ethtool_op_get_link,
387	.get_ringparam          = uec_get_ringparam,
388	.set_ringparam          = uec_set_ringparam,
389	.get_pauseparam         = uec_get_pauseparam,
390	.set_pauseparam         = uec_set_pauseparam,
391	.get_sset_count		= uec_get_sset_count,
392	.get_strings            = uec_get_strings,
393	.get_ethtool_stats      = uec_get_ethtool_stats,
394	.get_wol		= uec_get_wol,
395	.set_wol		= uec_set_wol,
396	.get_ts_info		= ethtool_op_get_ts_info,
397	.get_link_ksettings	= uec_get_ksettings,
398	.set_link_ksettings	= uec_set_ksettings,
399};
400
401void uec_set_ethtool_ops(struct net_device *netdev)
402{
403	netdev->ethtool_ops = &uec_ethtool_ops;
404}