1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include <linux/ethtool.h>
19#include <linux/kernel.h>
20#include <linux/netdevice.h>
21
22#include "dwc-xlgmac.h"
23#include "dwc-xlgmac-reg.h"
24
25struct xlgmac_stats_desc {
26 char stat_string[ETH_GSTRING_LEN];
27 int stat_offset;
28};
29
30#define XLGMAC_STAT(str, var) \
31 { \
32 str, \
33 offsetof(struct xlgmac_pdata, stats.var), \
34 }
35
36static const struct xlgmac_stats_desc xlgmac_gstring_stats[] = {
37
38 XLGMAC_STAT("tx_bytes", txoctetcount_gb),
39 XLGMAC_STAT("tx_bytes_good", txoctetcount_g),
40 XLGMAC_STAT("tx_packets", txframecount_gb),
41 XLGMAC_STAT("tx_packets_good", txframecount_g),
42 XLGMAC_STAT("tx_unicast_packets", txunicastframes_gb),
43 XLGMAC_STAT("tx_broadcast_packets", txbroadcastframes_gb),
44 XLGMAC_STAT("tx_broadcast_packets_good", txbroadcastframes_g),
45 XLGMAC_STAT("tx_multicast_packets", txmulticastframes_gb),
46 XLGMAC_STAT("tx_multicast_packets_good", txmulticastframes_g),
47 XLGMAC_STAT("tx_vlan_packets_good", txvlanframes_g),
48 XLGMAC_STAT("tx_64_byte_packets", tx64octets_gb),
49 XLGMAC_STAT("tx_65_to_127_byte_packets", tx65to127octets_gb),
50 XLGMAC_STAT("tx_128_to_255_byte_packets", tx128to255octets_gb),
51 XLGMAC_STAT("tx_256_to_511_byte_packets", tx256to511octets_gb),
52 XLGMAC_STAT("tx_512_to_1023_byte_packets", tx512to1023octets_gb),
53 XLGMAC_STAT("tx_1024_to_max_byte_packets", tx1024tomaxoctets_gb),
54 XLGMAC_STAT("tx_underflow_errors", txunderflowerror),
55 XLGMAC_STAT("tx_pause_frames", txpauseframes),
56
57
58 XLGMAC_STAT("rx_bytes", rxoctetcount_gb),
59 XLGMAC_STAT("rx_bytes_good", rxoctetcount_g),
60 XLGMAC_STAT("rx_packets", rxframecount_gb),
61 XLGMAC_STAT("rx_unicast_packets_good", rxunicastframes_g),
62 XLGMAC_STAT("rx_broadcast_packets_good", rxbroadcastframes_g),
63 XLGMAC_STAT("rx_multicast_packets_good", rxmulticastframes_g),
64 XLGMAC_STAT("rx_vlan_packets", rxvlanframes_gb),
65 XLGMAC_STAT("rx_64_byte_packets", rx64octets_gb),
66 XLGMAC_STAT("rx_65_to_127_byte_packets", rx65to127octets_gb),
67 XLGMAC_STAT("rx_128_to_255_byte_packets", rx128to255octets_gb),
68 XLGMAC_STAT("rx_256_to_511_byte_packets", rx256to511octets_gb),
69 XLGMAC_STAT("rx_512_to_1023_byte_packets", rx512to1023octets_gb),
70 XLGMAC_STAT("rx_1024_to_max_byte_packets", rx1024tomaxoctets_gb),
71 XLGMAC_STAT("rx_undersize_packets_good", rxundersize_g),
72 XLGMAC_STAT("rx_oversize_packets_good", rxoversize_g),
73 XLGMAC_STAT("rx_crc_errors", rxcrcerror),
74 XLGMAC_STAT("rx_crc_errors_small_packets", rxrunterror),
75 XLGMAC_STAT("rx_crc_errors_giant_packets", rxjabbererror),
76 XLGMAC_STAT("rx_length_errors", rxlengtherror),
77 XLGMAC_STAT("rx_out_of_range_errors", rxoutofrangetype),
78 XLGMAC_STAT("rx_fifo_overflow_errors", rxfifooverflow),
79 XLGMAC_STAT("rx_watchdog_errors", rxwatchdogerror),
80 XLGMAC_STAT("rx_pause_frames", rxpauseframes),
81
82
83 XLGMAC_STAT("tx_tso_packets", tx_tso_packets),
84 XLGMAC_STAT("rx_split_header_packets", rx_split_header_packets),
85 XLGMAC_STAT("tx_process_stopped", tx_process_stopped),
86 XLGMAC_STAT("rx_process_stopped", rx_process_stopped),
87 XLGMAC_STAT("tx_buffer_unavailable", tx_buffer_unavailable),
88 XLGMAC_STAT("rx_buffer_unavailable", rx_buffer_unavailable),
89 XLGMAC_STAT("fatal_bus_error", fatal_bus_error),
90 XLGMAC_STAT("tx_vlan_packets", tx_vlan_packets),
91 XLGMAC_STAT("rx_vlan_packets", rx_vlan_packets),
92 XLGMAC_STAT("napi_poll_isr", napi_poll_isr),
93 XLGMAC_STAT("napi_poll_txtimer", napi_poll_txtimer),
94};
95
96#define XLGMAC_STATS_COUNT ARRAY_SIZE(xlgmac_gstring_stats)
97
98static void xlgmac_ethtool_get_drvinfo(struct net_device *netdev,
99 struct ethtool_drvinfo *drvinfo)
100{
101 struct xlgmac_pdata *pdata = netdev_priv(netdev);
102 u32 ver = pdata->hw_feat.version;
103 u32 snpsver, devid, userver;
104
105 strlcpy(drvinfo->driver, pdata->drv_name, sizeof(drvinfo->driver));
106 strlcpy(drvinfo->version, pdata->drv_ver, sizeof(drvinfo->version));
107 strlcpy(drvinfo->bus_info, dev_name(pdata->dev),
108 sizeof(drvinfo->bus_info));
109
110
111
112
113 snpsver = XLGMAC_GET_REG_BITS(ver, MAC_VR_SNPSVER_POS,
114 MAC_VR_SNPSVER_LEN);
115 devid = XLGMAC_GET_REG_BITS(ver, MAC_VR_DEVID_POS,
116 MAC_VR_DEVID_LEN);
117 userver = XLGMAC_GET_REG_BITS(ver, MAC_VR_USERVER_POS,
118 MAC_VR_USERVER_LEN);
119 snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version),
120 "S.D.U: %x.%x.%x", snpsver, devid, userver);
121}
122
123static u32 xlgmac_ethtool_get_msglevel(struct net_device *netdev)
124{
125 struct xlgmac_pdata *pdata = netdev_priv(netdev);
126
127 return pdata->msg_enable;
128}
129
130static void xlgmac_ethtool_set_msglevel(struct net_device *netdev,
131 u32 msglevel)
132{
133 struct xlgmac_pdata *pdata = netdev_priv(netdev);
134
135 pdata->msg_enable = msglevel;
136}
137
138static void xlgmac_ethtool_get_channels(struct net_device *netdev,
139 struct ethtool_channels *channel)
140{
141 struct xlgmac_pdata *pdata = netdev_priv(netdev);
142
143 channel->max_rx = XLGMAC_MAX_DMA_CHANNELS;
144 channel->max_tx = XLGMAC_MAX_DMA_CHANNELS;
145 channel->rx_count = pdata->rx_q_count;
146 channel->tx_count = pdata->tx_q_count;
147}
148
149static int
150xlgmac_ethtool_get_coalesce(struct net_device *netdev,
151 struct ethtool_coalesce *ec,
152 struct kernel_ethtool_coalesce *kernel_coal,
153 struct netlink_ext_ack *extack)
154{
155 struct xlgmac_pdata *pdata = netdev_priv(netdev);
156
157 memset(ec, 0, sizeof(struct ethtool_coalesce));
158 ec->rx_coalesce_usecs = pdata->rx_usecs;
159 ec->rx_max_coalesced_frames = pdata->rx_frames;
160 ec->tx_max_coalesced_frames = pdata->tx_frames;
161
162 return 0;
163}
164
165static int
166xlgmac_ethtool_set_coalesce(struct net_device *netdev,
167 struct ethtool_coalesce *ec,
168 struct kernel_ethtool_coalesce *kernel_coal,
169 struct netlink_ext_ack *extack)
170{
171 struct xlgmac_pdata *pdata = netdev_priv(netdev);
172 struct xlgmac_hw_ops *hw_ops = &pdata->hw_ops;
173 unsigned int rx_frames, rx_riwt, rx_usecs;
174 unsigned int tx_frames;
175
176
177 if ((ec->rx_coalesce_usecs_irq) || (ec->rx_max_coalesced_frames_irq) ||
178 (ec->tx_coalesce_usecs) || (ec->tx_coalesce_usecs_high) ||
179 (ec->tx_max_coalesced_frames_irq) || (ec->tx_coalesce_usecs_irq) ||
180 (ec->stats_block_coalesce_usecs) || (ec->pkt_rate_low) ||
181 (ec->use_adaptive_rx_coalesce) || (ec->use_adaptive_tx_coalesce) ||
182 (ec->rx_max_coalesced_frames_low) || (ec->rx_coalesce_usecs_low) ||
183 (ec->tx_coalesce_usecs_low) || (ec->tx_max_coalesced_frames_low) ||
184 (ec->pkt_rate_high) || (ec->rx_coalesce_usecs_high) ||
185 (ec->rx_max_coalesced_frames_high) ||
186 (ec->tx_max_coalesced_frames_high) ||
187 (ec->rate_sample_interval))
188 return -EOPNOTSUPP;
189
190 rx_usecs = ec->rx_coalesce_usecs;
191 rx_riwt = hw_ops->usec_to_riwt(pdata, rx_usecs);
192 rx_frames = ec->rx_max_coalesced_frames;
193 tx_frames = ec->tx_max_coalesced_frames;
194
195 if ((rx_riwt > XLGMAC_MAX_DMA_RIWT) ||
196 (rx_riwt < XLGMAC_MIN_DMA_RIWT) ||
197 (rx_frames > pdata->rx_desc_count))
198 return -EINVAL;
199
200 if (tx_frames > pdata->tx_desc_count)
201 return -EINVAL;
202
203 pdata->rx_riwt = rx_riwt;
204 pdata->rx_usecs = rx_usecs;
205 pdata->rx_frames = rx_frames;
206 hw_ops->config_rx_coalesce(pdata);
207
208 pdata->tx_frames = tx_frames;
209 hw_ops->config_tx_coalesce(pdata);
210
211 return 0;
212}
213
214static void xlgmac_ethtool_get_strings(struct net_device *netdev,
215 u32 stringset, u8 *data)
216{
217 int i;
218
219 switch (stringset) {
220 case ETH_SS_STATS:
221 for (i = 0; i < XLGMAC_STATS_COUNT; i++) {
222 memcpy(data, xlgmac_gstring_stats[i].stat_string,
223 ETH_GSTRING_LEN);
224 data += ETH_GSTRING_LEN;
225 }
226 break;
227 default:
228 WARN_ON(1);
229 break;
230 }
231}
232
233static int xlgmac_ethtool_get_sset_count(struct net_device *netdev,
234 int stringset)
235{
236 int ret;
237
238 switch (stringset) {
239 case ETH_SS_STATS:
240 ret = XLGMAC_STATS_COUNT;
241 break;
242
243 default:
244 ret = -EOPNOTSUPP;
245 }
246
247 return ret;
248}
249
250static void xlgmac_ethtool_get_ethtool_stats(struct net_device *netdev,
251 struct ethtool_stats *stats,
252 u64 *data)
253{
254 struct xlgmac_pdata *pdata = netdev_priv(netdev);
255 u8 *stat;
256 int i;
257
258 pdata->hw_ops.read_mmc_stats(pdata);
259 for (i = 0; i < XLGMAC_STATS_COUNT; i++) {
260 stat = (u8 *)pdata + xlgmac_gstring_stats[i].stat_offset;
261 *data++ = *(u64 *)stat;
262 }
263}
264
265static const struct ethtool_ops xlgmac_ethtool_ops = {
266 .get_drvinfo = xlgmac_ethtool_get_drvinfo,
267 .get_link = ethtool_op_get_link,
268 .get_msglevel = xlgmac_ethtool_get_msglevel,
269 .set_msglevel = xlgmac_ethtool_set_msglevel,
270 .get_channels = xlgmac_ethtool_get_channels,
271 .get_coalesce = xlgmac_ethtool_get_coalesce,
272 .set_coalesce = xlgmac_ethtool_set_coalesce,
273 .get_strings = xlgmac_ethtool_get_strings,
274 .get_sset_count = xlgmac_ethtool_get_sset_count,
275 .get_ethtool_stats = xlgmac_ethtool_get_ethtool_stats,
276};
277
278const struct ethtool_ops *xlgmac_get_ethtool_ops(void)
279{
280 return &xlgmac_ethtool_ops;
281}
282