Blame view

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