Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Copyright (C) 2006-2008 PA Semi, Inc
  4 *
  5 * Ethtool hooks for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  8
  9#include <linux/netdevice.h>
 10#include <linux/ethtool.h>
 11#include <linux/pci.h>
 12
 13#include <asm/pasemi_dma.h>
 14#include "pasemi_mac.h"
 15
 16static struct {
 17	const char str[ETH_GSTRING_LEN];
 18} ethtool_stats_keys[] = {
 19	{ "rx-drops" },
 20	{ "rx-bytes" },
 21	{ "rx-packets" },
 22	{ "rx-broadcast-packets" },
 23	{ "rx-multicast-packets" },
 24	{ "rx-crc-errors" },
 25	{ "rx-undersize-errors" },
 26	{ "rx-oversize-errors" },
 27	{ "rx-short-fragment-errors" },
 28	{ "rx-jabber-errors" },
 29	{ "rx-64-byte-packets" },
 30	{ "rx-65-127-byte-packets" },
 31	{ "rx-128-255-byte-packets" },
 32	{ "rx-256-511-byte-packets" },
 33	{ "rx-512-1023-byte-packets" },
 34	{ "rx-1024-1518-byte-packets" },
 35	{ "rx-pause-frames" },
 36	{ "tx-bytes" },
 37	{ "tx-packets" },
 38	{ "tx-broadcast-packets" },
 39	{ "tx-multicast-packets" },
 40	{ "tx-collisions" },
 41	{ "tx-late-collisions" },
 42	{ "tx-excessive-collisions" },
 43	{ "tx-crc-errors" },
 44	{ "tx-undersize-errors" },
 45	{ "tx-oversize-errors" },
 46	{ "tx-64-byte-packets" },
 47	{ "tx-65-127-byte-packets" },
 48	{ "tx-128-255-byte-packets" },
 49	{ "tx-256-511-byte-packets" },
 50	{ "tx-512-1023-byte-packets" },
 51	{ "tx-1024-1518-byte-packets" },
 52};
 53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 54static u32
 55pasemi_mac_ethtool_get_msglevel(struct net_device *netdev)
 56{
 57	struct pasemi_mac *mac = netdev_priv(netdev);
 58	return mac->msg_enable;
 59}
 60
 61static void
 62pasemi_mac_ethtool_set_msglevel(struct net_device *netdev,
 63				u32 level)
 64{
 65	struct pasemi_mac *mac = netdev_priv(netdev);
 66	mac->msg_enable = level;
 67}
 68
 69
 70static void
 71pasemi_mac_ethtool_get_ringparam(struct net_device *netdev,
 72				 struct ethtool_ringparam *ering,
 73				 struct kernel_ethtool_ringparam *kernel_ering,
 74				 struct netlink_ext_ack *extack)
 75{
 76	struct pasemi_mac *mac = netdev_priv(netdev);
 77
 78	ering->tx_max_pending = TX_RING_SIZE/2;
 79	ering->tx_pending = RING_USED(mac->tx)/2;
 80	ering->rx_max_pending = RX_RING_SIZE/4;
 81	ering->rx_pending = RING_USED(mac->rx)/4;
 82}
 83
 84static int pasemi_mac_get_sset_count(struct net_device *netdev, int sset)
 85{
 86	switch (sset) {
 87	case ETH_SS_STATS:
 88		return ARRAY_SIZE(ethtool_stats_keys);
 89	default:
 90		return -EOPNOTSUPP;
 91	}
 92}
 93
 94static void pasemi_mac_get_ethtool_stats(struct net_device *netdev,
 95		struct ethtool_stats *stats, u64 *data)
 96{
 97	struct pasemi_mac *mac = netdev_priv(netdev);
 98	int i;
 99
100	data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if))
101			>> PAS_DMA_RXINT_RCMDSTA_DROPS_S;
102	for (i = 0; i < 32; i++)
103		data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i));
104}
105
106static void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset,
107				   u8 *data)
108{
109	memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
110}
111
112const struct ethtool_ops pasemi_mac_ethtool_ops = {
 
 
113	.get_msglevel		= pasemi_mac_ethtool_get_msglevel,
114	.set_msglevel		= pasemi_mac_ethtool_set_msglevel,
115	.get_link		= ethtool_op_get_link,
116	.get_ringparam          = pasemi_mac_ethtool_get_ringparam,
117	.get_strings		= pasemi_mac_get_strings,
118	.get_sset_count		= pasemi_mac_get_sset_count,
119	.get_ethtool_stats	= pasemi_mac_get_ethtool_stats,
120	.get_link_ksettings	= phy_ethtool_get_link_ksettings,
121	.set_link_ksettings	= phy_ethtool_set_link_ksettings,
122};
123
v4.6
 
  1/*
  2 * Copyright (C) 2006-2008 PA Semi, Inc
  3 *
  4 * Ethtool hooks for the PA Semi PWRficient onchip 1G/10G Ethernet MACs
  5 *
  6 * This program is free software; you can redistribute it and/or modify
  7 * it under the terms of the GNU General Public License version 2 as
  8 * published by the Free Software Foundation.
  9 *
 10 * This program is distributed in the hope that it will be useful,
 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 * GNU General Public License for more details.
 14 *
 15 * You should have received a copy of the GNU General Public License
 16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 17 */
 18
 19
 20#include <linux/netdevice.h>
 21#include <linux/ethtool.h>
 22#include <linux/pci.h>
 23
 24#include <asm/pasemi_dma.h>
 25#include "pasemi_mac.h"
 26
 27static struct {
 28	const char str[ETH_GSTRING_LEN];
 29} ethtool_stats_keys[] = {
 30	{ "rx-drops" },
 31	{ "rx-bytes" },
 32	{ "rx-packets" },
 33	{ "rx-broadcast-packets" },
 34	{ "rx-multicast-packets" },
 35	{ "rx-crc-errors" },
 36	{ "rx-undersize-errors" },
 37	{ "rx-oversize-errors" },
 38	{ "rx-short-fragment-errors" },
 39	{ "rx-jabber-errors" },
 40	{ "rx-64-byte-packets" },
 41	{ "rx-65-127-byte-packets" },
 42	{ "rx-128-255-byte-packets" },
 43	{ "rx-256-511-byte-packets" },
 44	{ "rx-512-1023-byte-packets" },
 45	{ "rx-1024-1518-byte-packets" },
 46	{ "rx-pause-frames" },
 47	{ "tx-bytes" },
 48	{ "tx-packets" },
 49	{ "tx-broadcast-packets" },
 50	{ "tx-multicast-packets" },
 51	{ "tx-collisions" },
 52	{ "tx-late-collisions" },
 53	{ "tx-excessive-collisions" },
 54	{ "tx-crc-errors" },
 55	{ "tx-undersize-errors" },
 56	{ "tx-oversize-errors" },
 57	{ "tx-64-byte-packets" },
 58	{ "tx-65-127-byte-packets" },
 59	{ "tx-128-255-byte-packets" },
 60	{ "tx-256-511-byte-packets" },
 61	{ "tx-512-1023-byte-packets" },
 62	{ "tx-1024-1518-byte-packets" },
 63};
 64
 65static int
 66pasemi_mac_ethtool_get_settings(struct net_device *netdev,
 67			       struct ethtool_cmd *cmd)
 68{
 69	struct pasemi_mac *mac = netdev_priv(netdev);
 70	struct phy_device *phydev = mac->phydev;
 71
 72	if (!phydev)
 73		return -EOPNOTSUPP;
 74
 75	return phy_ethtool_gset(phydev, cmd);
 76}
 77
 78static int
 79pasemi_mac_ethtool_set_settings(struct net_device *netdev,
 80			       struct ethtool_cmd *cmd)
 81{
 82	struct pasemi_mac *mac = netdev_priv(netdev);
 83	struct phy_device *phydev = mac->phydev;
 84
 85	if (!phydev)
 86		return -EOPNOTSUPP;
 87
 88	return phy_ethtool_sset(phydev, cmd);
 89}
 90
 91static u32
 92pasemi_mac_ethtool_get_msglevel(struct net_device *netdev)
 93{
 94	struct pasemi_mac *mac = netdev_priv(netdev);
 95	return mac->msg_enable;
 96}
 97
 98static void
 99pasemi_mac_ethtool_set_msglevel(struct net_device *netdev,
100				u32 level)
101{
102	struct pasemi_mac *mac = netdev_priv(netdev);
103	mac->msg_enable = level;
104}
105
106
107static void
108pasemi_mac_ethtool_get_ringparam(struct net_device *netdev,
109				 struct ethtool_ringparam *ering)
 
 
110{
111	struct pasemi_mac *mac = netdev_priv(netdev);
112
113	ering->tx_max_pending = TX_RING_SIZE/2;
114	ering->tx_pending = RING_USED(mac->tx)/2;
115	ering->rx_max_pending = RX_RING_SIZE/4;
116	ering->rx_pending = RING_USED(mac->rx)/4;
117}
118
119static int pasemi_mac_get_sset_count(struct net_device *netdev, int sset)
120{
121	switch (sset) {
122	case ETH_SS_STATS:
123		return ARRAY_SIZE(ethtool_stats_keys);
124	default:
125		return -EOPNOTSUPP;
126	}
127}
128
129static void pasemi_mac_get_ethtool_stats(struct net_device *netdev,
130		struct ethtool_stats *stats, u64 *data)
131{
132	struct pasemi_mac *mac = netdev_priv(netdev);
133	int i;
134
135	data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if))
136			>> PAS_DMA_RXINT_RCMDSTA_DROPS_S;
137	for (i = 0; i < 32; i++)
138		data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i));
139}
140
141static void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset,
142				   u8 *data)
143{
144	memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
145}
146
147const struct ethtool_ops pasemi_mac_ethtool_ops = {
148	.get_settings		= pasemi_mac_ethtool_get_settings,
149	.set_settings		= pasemi_mac_ethtool_set_settings,
150	.get_msglevel		= pasemi_mac_ethtool_get_msglevel,
151	.set_msglevel		= pasemi_mac_ethtool_set_msglevel,
152	.get_link		= ethtool_op_get_link,
153	.get_ringparam          = pasemi_mac_ethtool_get_ringparam,
154	.get_strings		= pasemi_mac_get_strings,
155	.get_sset_count		= pasemi_mac_get_sset_count,
156	.get_ethtool_stats	= pasemi_mac_get_ethtool_stats,
 
 
157};
158