blob: 25fae568261f6d2b51ea1011c4610b2019b88de7 [file] [log] [blame]
Olof Johanssone37c7722008-02-20 20:57:59 -06001/*
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
Jeff Kirsher0ab75ae2013-12-06 06:28:43 -080016 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Olof Johanssone37c7722008-02-20 20:57:59 -060017 */
18
19
20#include <linux/netdevice.h>
21#include <linux/ethtool.h>
22#include <linux/pci.h>
23#include <linux/inet_lro.h>
24
25#include <asm/pasemi_dma.h>
26#include "pasemi_mac.h"
27
28static struct {
29 const char str[ETH_GSTRING_LEN];
30} ethtool_stats_keys[] = {
31 { "rx-drops" },
32 { "rx-bytes" },
33 { "rx-packets" },
34 { "rx-broadcast-packets" },
35 { "rx-multicast-packets" },
36 { "rx-crc-errors" },
37 { "rx-undersize-errors" },
38 { "rx-oversize-errors" },
39 { "rx-short-fragment-errors" },
40 { "rx-jabber-errors" },
41 { "rx-64-byte-packets" },
42 { "rx-65-127-byte-packets" },
43 { "rx-128-255-byte-packets" },
44 { "rx-256-511-byte-packets" },
45 { "rx-512-1023-byte-packets" },
46 { "rx-1024-1518-byte-packets" },
47 { "rx-pause-frames" },
48 { "tx-bytes" },
49 { "tx-packets" },
50 { "tx-broadcast-packets" },
51 { "tx-multicast-packets" },
52 { "tx-collisions" },
53 { "tx-late-collisions" },
54 { "tx-excessive-collisions" },
55 { "tx-crc-errors" },
56 { "tx-undersize-errors" },
57 { "tx-oversize-errors" },
58 { "tx-64-byte-packets" },
59 { "tx-65-127-byte-packets" },
60 { "tx-128-255-byte-packets" },
61 { "tx-256-511-byte-packets" },
62 { "tx-512-1023-byte-packets" },
63 { "tx-1024-1518-byte-packets" },
64};
65
66static int
67pasemi_mac_ethtool_get_settings(struct net_device *netdev,
68 struct ethtool_cmd *cmd)
69{
70 struct pasemi_mac *mac = netdev_priv(netdev);
71 struct phy_device *phydev = mac->phydev;
72
Valentine Barshak49682862009-10-05 03:27:56 +000073 if (!phydev)
74 return -EOPNOTSUPP;
75
Olof Johanssone37c7722008-02-20 20:57:59 -060076 return phy_ethtool_gset(phydev, cmd);
77}
78
Valentine Barshak54022402009-10-12 04:25:05 -070079static int
80pasemi_mac_ethtool_set_settings(struct net_device *netdev,
81 struct ethtool_cmd *cmd)
82{
83 struct pasemi_mac *mac = netdev_priv(netdev);
84 struct phy_device *phydev = mac->phydev;
85
86 if (!phydev)
87 return -EOPNOTSUPP;
88
89 return phy_ethtool_sset(phydev, cmd);
90}
91
Olof Johanssone37c7722008-02-20 20:57:59 -060092static u32
93pasemi_mac_ethtool_get_msglevel(struct net_device *netdev)
94{
95 struct pasemi_mac *mac = netdev_priv(netdev);
96 return mac->msg_enable;
97}
98
99static void
100pasemi_mac_ethtool_set_msglevel(struct net_device *netdev,
101 u32 level)
102{
103 struct pasemi_mac *mac = netdev_priv(netdev);
104 mac->msg_enable = level;
105}
106
107
108static void
109pasemi_mac_ethtool_get_ringparam(struct net_device *netdev,
110 struct ethtool_ringparam *ering)
111{
Wang Chen4cf16532008-11-12 23:38:14 -0800112 struct pasemi_mac *mac = netdev_priv(netdev);
Olof Johanssone37c7722008-02-20 20:57:59 -0600113
114 ering->tx_max_pending = TX_RING_SIZE/2;
115 ering->tx_pending = RING_USED(mac->tx)/2;
116 ering->rx_max_pending = RX_RING_SIZE/4;
117 ering->rx_pending = RING_USED(mac->rx)/4;
118}
119
120static int pasemi_mac_get_sset_count(struct net_device *netdev, int sset)
121{
122 switch (sset) {
123 case ETH_SS_STATS:
124 return ARRAY_SIZE(ethtool_stats_keys);
125 default:
126 return -EOPNOTSUPP;
127 }
128}
129
130static void pasemi_mac_get_ethtool_stats(struct net_device *netdev,
131 struct ethtool_stats *stats, u64 *data)
132{
Wang Chen4cf16532008-11-12 23:38:14 -0800133 struct pasemi_mac *mac = netdev_priv(netdev);
Olof Johanssone37c7722008-02-20 20:57:59 -0600134 int i;
135
136 data[0] = pasemi_read_dma_reg(PAS_DMA_RXINT_RCMDSTA(mac->dma_if))
137 >> PAS_DMA_RXINT_RCMDSTA_DROPS_S;
138 for (i = 0; i < 32; i++)
139 data[1+i] = pasemi_read_mac_reg(mac->dma_if, PAS_MAC_RMON(i));
140}
141
142static void pasemi_mac_get_strings(struct net_device *netdev, u32 stringset,
143 u8 *data)
144{
145 memcpy(data, ethtool_stats_keys, sizeof(ethtool_stats_keys));
146}
147
148const struct ethtool_ops pasemi_mac_ethtool_ops = {
149 .get_settings = pasemi_mac_ethtool_get_settings,
Valentine Barshak54022402009-10-12 04:25:05 -0700150 .set_settings = pasemi_mac_ethtool_set_settings,
Olof Johanssone37c7722008-02-20 20:57:59 -0600151 .get_msglevel = pasemi_mac_ethtool_get_msglevel,
152 .set_msglevel = pasemi_mac_ethtool_set_msglevel,
153 .get_link = ethtool_op_get_link,
154 .get_ringparam = pasemi_mac_ethtool_get_ringparam,
155 .get_strings = pasemi_mac_get_strings,
156 .get_sset_count = pasemi_mac_get_sset_count,
157 .get_ethtool_stats = pasemi_mac_get_ethtool_stats,
158};
159