]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * drivers/net/gianfar_ethtool.c | |
3 | * | |
4 | * Gianfar Ethernet Driver | |
5 | * Ethtool support for Gianfar Enet | |
6 | * Based on e1000 ethtool support | |
7 | * | |
8 | * Author: Andy Fleming | |
4c8d3d99 | 9 | * Maintainer: Kumar Gala |
a12f801d | 10 | * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> |
1da177e4 | 11 | * |
a12f801d | 12 | * Copyright 2003-2006, 2008-2009 Freescale Semiconductor, Inc. |
1da177e4 | 13 | * |
6aa20a22 JG |
14 | * This software may be used and distributed according to |
15 | * the terms of the GNU Public License, Version 2, incorporated herein | |
1da177e4 LT |
16 | * by reference. |
17 | */ | |
18 | ||
1da177e4 | 19 | #include <linux/kernel.h> |
1da177e4 LT |
20 | #include <linux/string.h> |
21 | #include <linux/errno.h> | |
22 | #include <linux/slab.h> | |
23 | #include <linux/interrupt.h> | |
24 | #include <linux/init.h> | |
25 | #include <linux/delay.h> | |
26 | #include <linux/netdevice.h> | |
27 | #include <linux/etherdevice.h> | |
28 | #include <linux/skbuff.h> | |
29 | #include <linux/spinlock.h> | |
30 | #include <linux/mm.h> | |
31 | ||
32 | #include <asm/io.h> | |
33 | #include <asm/irq.h> | |
34 | #include <asm/uaccess.h> | |
35 | #include <linux/module.h> | |
1da177e4 LT |
36 | #include <linux/crc32.h> |
37 | #include <asm/types.h> | |
1da177e4 | 38 | #include <linux/ethtool.h> |
bb40dcbb AF |
39 | #include <linux/mii.h> |
40 | #include <linux/phy.h> | |
1da177e4 LT |
41 | |
42 | #include "gianfar.h" | |
43 | ||
0bbaf069 | 44 | extern void gfar_start(struct net_device *dev); |
a12f801d | 45 | extern int gfar_clean_rx_ring(struct gfar_priv_rx_q *rx_queue, int rx_work_limit); |
1da177e4 | 46 | |
bb40dcbb AF |
47 | #define GFAR_MAX_COAL_USECS 0xffff |
48 | #define GFAR_MAX_COAL_FRAMES 0xff | |
0bbaf069 | 49 | static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, |
1da177e4 | 50 | u64 * buf); |
0bbaf069 KG |
51 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf); |
52 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); | |
53 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals); | |
54 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals); | |
55 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals); | |
56 | static void gfar_gdrvinfo(struct net_device *dev, struct ethtool_drvinfo *drvinfo); | |
1da177e4 LT |
57 | |
58 | static char stat_gstrings[][ETH_GSTRING_LEN] = { | |
59 | "rx-dropped-by-kernel", | |
60 | "rx-large-frame-errors", | |
61 | "rx-short-frame-errors", | |
62 | "rx-non-octet-errors", | |
63 | "rx-crc-errors", | |
64 | "rx-overrun-errors", | |
65 | "rx-busy-errors", | |
66 | "rx-babbling-errors", | |
67 | "rx-truncated-frames", | |
68 | "ethernet-bus-error", | |
69 | "tx-babbling-errors", | |
70 | "tx-underrun-errors", | |
71 | "rx-skb-missing-errors", | |
72 | "tx-timeout-errors", | |
73 | "tx-rx-64-frames", | |
74 | "tx-rx-65-127-frames", | |
75 | "tx-rx-128-255-frames", | |
76 | "tx-rx-256-511-frames", | |
77 | "tx-rx-512-1023-frames", | |
78 | "tx-rx-1024-1518-frames", | |
79 | "tx-rx-1519-1522-good-vlan", | |
80 | "rx-bytes", | |
81 | "rx-packets", | |
82 | "rx-fcs-errors", | |
83 | "receive-multicast-packet", | |
84 | "receive-broadcast-packet", | |
85 | "rx-control-frame-packets", | |
86 | "rx-pause-frame-packets", | |
87 | "rx-unknown-op-code", | |
88 | "rx-alignment-error", | |
89 | "rx-frame-length-error", | |
90 | "rx-code-error", | |
91 | "rx-carrier-sense-error", | |
92 | "rx-undersize-packets", | |
93 | "rx-oversize-packets", | |
94 | "rx-fragmented-frames", | |
95 | "rx-jabber-frames", | |
96 | "rx-dropped-frames", | |
97 | "tx-byte-counter", | |
98 | "tx-packets", | |
99 | "tx-multicast-packets", | |
100 | "tx-broadcast-packets", | |
101 | "tx-pause-control-frames", | |
102 | "tx-deferral-packets", | |
103 | "tx-excessive-deferral-packets", | |
104 | "tx-single-collision-packets", | |
105 | "tx-multiple-collision-packets", | |
106 | "tx-late-collision-packets", | |
107 | "tx-excessive-collision-packets", | |
108 | "tx-total-collision", | |
109 | "reserved", | |
110 | "tx-dropped-frames", | |
111 | "tx-jabber-frames", | |
112 | "tx-fcs-errors", | |
113 | "tx-control-frames", | |
114 | "tx-oversize-frames", | |
115 | "tx-undersize-frames", | |
116 | "tx-fragmented-frames", | |
117 | }; | |
118 | ||
0bbaf069 KG |
119 | /* Fill in a buffer with the strings which correspond to the |
120 | * stats */ | |
121 | static void gfar_gstrings(struct net_device *dev, u32 stringset, u8 * buf) | |
122 | { | |
123 | struct gfar_private *priv = netdev_priv(dev); | |
7f7f5316 | 124 | |
b31a1d8b | 125 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
0bbaf069 KG |
126 | memcpy(buf, stat_gstrings, GFAR_STATS_LEN * ETH_GSTRING_LEN); |
127 | else | |
128 | memcpy(buf, stat_gstrings, | |
129 | GFAR_EXTRA_STATS_LEN * ETH_GSTRING_LEN); | |
130 | } | |
131 | ||
1da177e4 LT |
132 | /* Fill in an array of 64-bit statistics from various sources. |
133 | * This array will be appended to the end of the ethtool_stats | |
134 | * structure, and returned to user space | |
135 | */ | |
0bbaf069 | 136 | static void gfar_fill_stats(struct net_device *dev, struct ethtool_stats *dummy, u64 * buf) |
1da177e4 LT |
137 | { |
138 | int i; | |
139 | struct gfar_private *priv = netdev_priv(dev); | |
f4983704 | 140 | struct gfar __iomem *regs = priv->gfargrp.regs; |
1da177e4 | 141 | u64 *extra = (u64 *) & priv->extra_stats; |
1da177e4 | 142 | |
b31a1d8b | 143 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) { |
f4983704 | 144 | u32 __iomem *rmon = (u32 __iomem *) ®s->rmon; |
0bbaf069 | 145 | struct gfar_stats *stats = (struct gfar_stats *) buf; |
1da177e4 | 146 | |
0bbaf069 | 147 | for (i = 0; i < GFAR_RMON_LEN; i++) |
cc8c6e37 | 148 | stats->rmon[i] = (u64) gfar_read(&rmon[i]); |
1da177e4 | 149 | |
0bbaf069 KG |
150 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) |
151 | stats->extra[i] = extra[i]; | |
152 | } else | |
153 | for (i = 0; i < GFAR_EXTRA_STATS_LEN; i++) | |
154 | buf[i] = extra[i]; | |
1da177e4 LT |
155 | } |
156 | ||
b9f2c044 | 157 | static int gfar_sset_count(struct net_device *dev, int sset) |
1da177e4 | 158 | { |
1da177e4 | 159 | struct gfar_private *priv = netdev_priv(dev); |
1da177e4 | 160 | |
b9f2c044 JG |
161 | switch (sset) { |
162 | case ETH_SS_STATS: | |
b31a1d8b | 163 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_RMON) |
b9f2c044 JG |
164 | return GFAR_STATS_LEN; |
165 | else | |
166 | return GFAR_EXTRA_STATS_LEN; | |
167 | default: | |
168 | return -EOPNOTSUPP; | |
169 | } | |
1da177e4 LT |
170 | } |
171 | ||
1da177e4 | 172 | /* Fills in the drvinfo structure with some basic info */ |
0bbaf069 | 173 | static void gfar_gdrvinfo(struct net_device *dev, struct |
1da177e4 LT |
174 | ethtool_drvinfo *drvinfo) |
175 | { | |
176 | strncpy(drvinfo->driver, DRV_NAME, GFAR_INFOSTR_LEN); | |
177 | strncpy(drvinfo->version, gfar_driver_version, GFAR_INFOSTR_LEN); | |
178 | strncpy(drvinfo->fw_version, "N/A", GFAR_INFOSTR_LEN); | |
179 | strncpy(drvinfo->bus_info, "N/A", GFAR_INFOSTR_LEN); | |
1da177e4 LT |
180 | drvinfo->regdump_len = 0; |
181 | drvinfo->eedump_len = 0; | |
182 | } | |
183 | ||
bb40dcbb AF |
184 | |
185 | static int gfar_ssettings(struct net_device *dev, struct ethtool_cmd *cmd) | |
186 | { | |
187 | struct gfar_private *priv = netdev_priv(dev); | |
188 | struct phy_device *phydev = priv->phydev; | |
189 | ||
190 | if (NULL == phydev) | |
191 | return -ENODEV; | |
192 | ||
193 | return phy_ethtool_sset(phydev, cmd); | |
194 | } | |
195 | ||
196 | ||
1da177e4 | 197 | /* Return the current settings in the ethtool_cmd structure */ |
0bbaf069 | 198 | static int gfar_gsettings(struct net_device *dev, struct ethtool_cmd *cmd) |
1da177e4 LT |
199 | { |
200 | struct gfar_private *priv = netdev_priv(dev); | |
bb40dcbb | 201 | struct phy_device *phydev = priv->phydev; |
a12f801d SG |
202 | struct gfar_priv_rx_q *rx_queue = NULL; |
203 | struct gfar_priv_tx_q *tx_queue = NULL; | |
bb40dcbb AF |
204 | |
205 | if (NULL == phydev) | |
206 | return -ENODEV; | |
fba4ed03 SG |
207 | tx_queue = priv->tx_queue[0]; |
208 | rx_queue = priv->rx_queue[0]; | |
6aa20a22 | 209 | |
fba4ed03 SG |
210 | /* etsec-1.7 and older versions have only one txic |
211 | * and rxic regs although they support multiple queues */ | |
a12f801d SG |
212 | cmd->maxtxpkt = get_icft_value(tx_queue->txic); |
213 | cmd->maxrxpkt = get_icft_value(rx_queue->rxic); | |
1da177e4 | 214 | |
bb40dcbb | 215 | return phy_ethtool_gset(phydev, cmd); |
1da177e4 LT |
216 | } |
217 | ||
218 | /* Return the length of the register structure */ | |
0bbaf069 | 219 | static int gfar_reglen(struct net_device *dev) |
1da177e4 LT |
220 | { |
221 | return sizeof (struct gfar); | |
222 | } | |
223 | ||
224 | /* Return a dump of the GFAR register space */ | |
0bbaf069 | 225 | static void gfar_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf) |
1da177e4 LT |
226 | { |
227 | int i; | |
228 | struct gfar_private *priv = netdev_priv(dev); | |
f4983704 | 229 | u32 __iomem *theregs = (u32 __iomem *) priv->gfargrp.regs; |
1da177e4 LT |
230 | u32 *buf = (u32 *) regbuf; |
231 | ||
232 | for (i = 0; i < sizeof (struct gfar) / sizeof (u32); i++) | |
cc8c6e37 | 233 | buf[i] = gfar_read(&theregs[i]); |
1da177e4 LT |
234 | } |
235 | ||
1da177e4 LT |
236 | /* Convert microseconds to ethernet clock ticks, which changes |
237 | * depending on what speed the controller is running at */ | |
238 | static unsigned int gfar_usecs2ticks(struct gfar_private *priv, unsigned int usecs) | |
239 | { | |
240 | unsigned int count; | |
241 | ||
242 | /* The timer is different, depending on the interface speed */ | |
bb40dcbb AF |
243 | switch (priv->phydev->speed) { |
244 | case SPEED_1000: | |
1da177e4 LT |
245 | count = GFAR_GBIT_TIME; |
246 | break; | |
bb40dcbb | 247 | case SPEED_100: |
1da177e4 LT |
248 | count = GFAR_100_TIME; |
249 | break; | |
bb40dcbb | 250 | case SPEED_10: |
1da177e4 LT |
251 | default: |
252 | count = GFAR_10_TIME; | |
253 | break; | |
254 | } | |
255 | ||
256 | /* Make sure we return a number greater than 0 | |
257 | * if usecs > 0 */ | |
258 | return ((usecs * 1000 + count - 1) / count); | |
259 | } | |
260 | ||
261 | /* Convert ethernet clock ticks to microseconds */ | |
262 | static unsigned int gfar_ticks2usecs(struct gfar_private *priv, unsigned int ticks) | |
263 | { | |
264 | unsigned int count; | |
265 | ||
266 | /* The timer is different, depending on the interface speed */ | |
bb40dcbb AF |
267 | switch (priv->phydev->speed) { |
268 | case SPEED_1000: | |
1da177e4 LT |
269 | count = GFAR_GBIT_TIME; |
270 | break; | |
bb40dcbb | 271 | case SPEED_100: |
1da177e4 LT |
272 | count = GFAR_100_TIME; |
273 | break; | |
bb40dcbb | 274 | case SPEED_10: |
1da177e4 LT |
275 | default: |
276 | count = GFAR_10_TIME; | |
277 | break; | |
278 | } | |
279 | ||
280 | /* Make sure we return a number greater than 0 */ | |
281 | /* if ticks is > 0 */ | |
282 | return ((ticks * count) / 1000); | |
283 | } | |
284 | ||
285 | /* Get the coalescing parameters, and put them in the cvals | |
286 | * structure. */ | |
0bbaf069 | 287 | static int gfar_gcoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) |
1da177e4 LT |
288 | { |
289 | struct gfar_private *priv = netdev_priv(dev); | |
a12f801d SG |
290 | struct gfar_priv_rx_q *rx_queue = NULL; |
291 | struct gfar_priv_tx_q *tx_queue = NULL; | |
b46a8454 DH |
292 | unsigned long rxtime; |
293 | unsigned long rxcount; | |
294 | unsigned long txtime; | |
295 | unsigned long txcount; | |
6aa20a22 | 296 | |
b31a1d8b | 297 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
0bbaf069 | 298 | return -EOPNOTSUPP; |
1da177e4 | 299 | |
bb40dcbb AF |
300 | if (NULL == priv->phydev) |
301 | return -ENODEV; | |
302 | ||
fba4ed03 SG |
303 | rx_queue = priv->rx_queue[0]; |
304 | tx_queue = priv->tx_queue[0]; | |
a12f801d SG |
305 | |
306 | rxtime = get_ictt_value(rx_queue->rxic); | |
307 | rxcount = get_icft_value(rx_queue->rxic); | |
308 | txtime = get_ictt_value(tx_queue->txic); | |
309 | txcount = get_icft_value(tx_queue->txic); | |
b46a8454 DH |
310 | cvals->rx_coalesce_usecs = gfar_ticks2usecs(priv, rxtime); |
311 | cvals->rx_max_coalesced_frames = rxcount; | |
1da177e4 | 312 | |
b46a8454 DH |
313 | cvals->tx_coalesce_usecs = gfar_ticks2usecs(priv, txtime); |
314 | cvals->tx_max_coalesced_frames = txcount; | |
1da177e4 LT |
315 | |
316 | cvals->use_adaptive_rx_coalesce = 0; | |
317 | cvals->use_adaptive_tx_coalesce = 0; | |
318 | ||
319 | cvals->pkt_rate_low = 0; | |
320 | cvals->rx_coalesce_usecs_low = 0; | |
321 | cvals->rx_max_coalesced_frames_low = 0; | |
322 | cvals->tx_coalesce_usecs_low = 0; | |
323 | cvals->tx_max_coalesced_frames_low = 0; | |
324 | ||
325 | /* When the packet rate is below pkt_rate_high but above | |
326 | * pkt_rate_low (both measured in packets per second) the | |
327 | * normal {rx,tx}_* coalescing parameters are used. | |
328 | */ | |
329 | ||
330 | /* When the packet rate is (measured in packets per second) | |
331 | * is above pkt_rate_high, the {rx,tx}_*_high parameters are | |
332 | * used. | |
333 | */ | |
334 | cvals->pkt_rate_high = 0; | |
335 | cvals->rx_coalesce_usecs_high = 0; | |
336 | cvals->rx_max_coalesced_frames_high = 0; | |
337 | cvals->tx_coalesce_usecs_high = 0; | |
338 | cvals->tx_max_coalesced_frames_high = 0; | |
339 | ||
340 | /* How often to do adaptive coalescing packet rate sampling, | |
341 | * measured in seconds. Must not be zero. | |
342 | */ | |
343 | cvals->rate_sample_interval = 0; | |
344 | ||
345 | return 0; | |
346 | } | |
347 | ||
348 | /* Change the coalescing values. | |
349 | * Both cvals->*_usecs and cvals->*_frames have to be > 0 | |
350 | * in order for coalescing to be active | |
351 | */ | |
0bbaf069 | 352 | static int gfar_scoalesce(struct net_device *dev, struct ethtool_coalesce *cvals) |
1da177e4 LT |
353 | { |
354 | struct gfar_private *priv = netdev_priv(dev); | |
f4983704 | 355 | struct gfar __iomem *regs = priv->gfargrp.regs; |
a12f801d SG |
356 | struct gfar_priv_tx_q *tx_queue = NULL; |
357 | struct gfar_priv_rx_q *rx_queue = NULL; | |
1da177e4 | 358 | |
b31a1d8b | 359 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_COALESCE)) |
0bbaf069 KG |
360 | return -EOPNOTSUPP; |
361 | ||
fba4ed03 SG |
362 | tx_queue = priv->tx_queue[0]; |
363 | rx_queue = priv->rx_queue[0]; | |
a12f801d | 364 | |
1da177e4 LT |
365 | /* Set up rx coalescing */ |
366 | if ((cvals->rx_coalesce_usecs == 0) || | |
367 | (cvals->rx_max_coalesced_frames == 0)) | |
a12f801d | 368 | rx_queue->rxcoalescing = 0; |
1da177e4 | 369 | else |
a12f801d | 370 | rx_queue->rxcoalescing = 1; |
1da177e4 | 371 | |
bb40dcbb AF |
372 | if (NULL == priv->phydev) |
373 | return -ENODEV; | |
374 | ||
375 | /* Check the bounds of the values */ | |
376 | if (cvals->rx_coalesce_usecs > GFAR_MAX_COAL_USECS) { | |
377 | pr_info("Coalescing is limited to %d microseconds\n", | |
378 | GFAR_MAX_COAL_USECS); | |
379 | return -EINVAL; | |
380 | } | |
381 | ||
382 | if (cvals->rx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { | |
383 | pr_info("Coalescing is limited to %d frames\n", | |
384 | GFAR_MAX_COAL_FRAMES); | |
385 | return -EINVAL; | |
386 | } | |
387 | ||
a12f801d | 388 | rx_queue->rxic = mk_ic_value(cvals->rx_max_coalesced_frames, |
accff95c | 389 | gfar_usecs2ticks(priv, cvals->rx_coalesce_usecs)); |
1da177e4 LT |
390 | |
391 | /* Set up tx coalescing */ | |
392 | if ((cvals->tx_coalesce_usecs == 0) || | |
393 | (cvals->tx_max_coalesced_frames == 0)) | |
a12f801d | 394 | tx_queue->txcoalescing = 0; |
1da177e4 | 395 | else |
a12f801d | 396 | tx_queue->txcoalescing = 1; |
1da177e4 | 397 | |
bb40dcbb AF |
398 | /* Check the bounds of the values */ |
399 | if (cvals->tx_coalesce_usecs > GFAR_MAX_COAL_USECS) { | |
400 | pr_info("Coalescing is limited to %d microseconds\n", | |
401 | GFAR_MAX_COAL_USECS); | |
402 | return -EINVAL; | |
403 | } | |
404 | ||
405 | if (cvals->tx_max_coalesced_frames > GFAR_MAX_COAL_FRAMES) { | |
406 | pr_info("Coalescing is limited to %d frames\n", | |
407 | GFAR_MAX_COAL_FRAMES); | |
408 | return -EINVAL; | |
409 | } | |
410 | ||
a12f801d | 411 | tx_queue->txic = mk_ic_value(cvals->tx_max_coalesced_frames, |
accff95c | 412 | gfar_usecs2ticks(priv, cvals->tx_coalesce_usecs)); |
1da177e4 | 413 | |
f4983704 | 414 | gfar_write(®s->rxic, 0); |
a12f801d | 415 | if (rx_queue->rxcoalescing) |
f4983704 | 416 | gfar_write(®s->rxic, rx_queue->rxic); |
1da177e4 | 417 | |
f4983704 | 418 | gfar_write(®s->txic, 0); |
a12f801d | 419 | if (tx_queue->txcoalescing) |
f4983704 | 420 | gfar_write(®s->txic, tx_queue->txic); |
1da177e4 LT |
421 | |
422 | return 0; | |
423 | } | |
424 | ||
425 | /* Fills in rvals with the current ring parameters. Currently, | |
426 | * rx, rx_mini, and rx_jumbo rings are the same size, as mini and | |
427 | * jumbo are ignored by the driver */ | |
0bbaf069 | 428 | static void gfar_gringparam(struct net_device *dev, struct ethtool_ringparam *rvals) |
1da177e4 LT |
429 | { |
430 | struct gfar_private *priv = netdev_priv(dev); | |
a12f801d SG |
431 | struct gfar_priv_tx_q *tx_queue = NULL; |
432 | struct gfar_priv_rx_q *rx_queue = NULL; | |
433 | ||
fba4ed03 SG |
434 | tx_queue = priv->tx_queue[0]; |
435 | rx_queue = priv->rx_queue[0]; | |
1da177e4 LT |
436 | |
437 | rvals->rx_max_pending = GFAR_RX_MAX_RING_SIZE; | |
438 | rvals->rx_mini_max_pending = GFAR_RX_MAX_RING_SIZE; | |
439 | rvals->rx_jumbo_max_pending = GFAR_RX_MAX_RING_SIZE; | |
440 | rvals->tx_max_pending = GFAR_TX_MAX_RING_SIZE; | |
441 | ||
442 | /* Values changeable by the user. The valid values are | |
443 | * in the range 1 to the "*_max_pending" counterpart above. | |
444 | */ | |
a12f801d SG |
445 | rvals->rx_pending = rx_queue->rx_ring_size; |
446 | rvals->rx_mini_pending = rx_queue->rx_ring_size; | |
447 | rvals->rx_jumbo_pending = rx_queue->rx_ring_size; | |
448 | rvals->tx_pending = tx_queue->tx_ring_size; | |
1da177e4 LT |
449 | } |
450 | ||
451 | /* Change the current ring parameters, stopping the controller if | |
452 | * necessary so that we don't mess things up while we're in | |
453 | * motion. We wait for the ring to be clean before reallocating | |
454 | * the rings. */ | |
0bbaf069 | 455 | static int gfar_sringparam(struct net_device *dev, struct ethtool_ringparam *rvals) |
1da177e4 | 456 | { |
1da177e4 | 457 | struct gfar_private *priv = netdev_priv(dev); |
fba4ed03 | 458 | int err = 0, i = 0; |
1da177e4 LT |
459 | |
460 | if (rvals->rx_pending > GFAR_RX_MAX_RING_SIZE) | |
461 | return -EINVAL; | |
462 | ||
463 | if (!is_power_of_2(rvals->rx_pending)) { | |
464 | printk("%s: Ring sizes must be a power of 2\n", | |
465 | dev->name); | |
466 | return -EINVAL; | |
467 | } | |
468 | ||
469 | if (rvals->tx_pending > GFAR_TX_MAX_RING_SIZE) | |
470 | return -EINVAL; | |
471 | ||
472 | if (!is_power_of_2(rvals->tx_pending)) { | |
473 | printk("%s: Ring sizes must be a power of 2\n", | |
474 | dev->name); | |
475 | return -EINVAL; | |
476 | } | |
477 | ||
a12f801d | 478 | |
0bbaf069 KG |
479 | if (dev->flags & IFF_UP) { |
480 | unsigned long flags; | |
1da177e4 | 481 | |
0bbaf069 KG |
482 | /* Halt TX and RX, and process the frames which |
483 | * have already been received */ | |
fba4ed03 SG |
484 | local_irq_save(flags); |
485 | lock_tx_qs(priv); | |
486 | lock_rx_qs(priv); | |
fef6108d | 487 | |
0bbaf069 | 488 | gfar_halt(dev); |
fef6108d | 489 | |
fba4ed03 SG |
490 | unlock_rx_qs(priv); |
491 | unlock_tx_qs(priv); | |
492 | local_irq_restore(flags); | |
1da177e4 | 493 | |
fba4ed03 SG |
494 | for (i = 0; i < priv->num_rx_queues; i++) |
495 | gfar_clean_rx_ring(priv->rx_queue[i], | |
496 | priv->rx_queue[i]->rx_ring_size); | |
12dea57b | 497 | |
0bbaf069 KG |
498 | /* Now we take down the rings to rebuild them */ |
499 | stop_gfar(dev); | |
500 | } | |
1da177e4 | 501 | |
0bbaf069 | 502 | /* Change the size */ |
fba4ed03 SG |
503 | for (i = 0; i < priv->num_rx_queues; i++) { |
504 | priv->rx_queue[i]->rx_ring_size = rvals->rx_pending; | |
505 | priv->tx_queue[i]->tx_ring_size = rvals->tx_pending; | |
506 | priv->tx_queue[i]->num_txbdfree = priv->tx_queue[i]->tx_ring_size; | |
507 | } | |
1da177e4 | 508 | |
0bbaf069 | 509 | /* Rebuild the rings with the new size */ |
12dea57b | 510 | if (dev->flags & IFF_UP) { |
0bbaf069 | 511 | err = startup_gfar(dev); |
fba4ed03 | 512 | netif_tx_wake_all_queues(dev); |
12dea57b | 513 | } |
0bbaf069 KG |
514 | return err; |
515 | } | |
1da177e4 | 516 | |
0bbaf069 KG |
517 | static int gfar_set_rx_csum(struct net_device *dev, uint32_t data) |
518 | { | |
519 | struct gfar_private *priv = netdev_priv(dev); | |
d87eb127 | 520 | unsigned long flags; |
fba4ed03 | 521 | int err = 0, i = 0; |
1da177e4 | 522 | |
b31a1d8b | 523 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
0bbaf069 KG |
524 | return -EOPNOTSUPP; |
525 | ||
a12f801d | 526 | |
0bbaf069 | 527 | if (dev->flags & IFF_UP) { |
0bbaf069 KG |
528 | /* Halt TX and RX, and process the frames which |
529 | * have already been received */ | |
fba4ed03 SG |
530 | local_irq_save(flags); |
531 | lock_tx_qs(priv); | |
532 | lock_rx_qs(priv); | |
fef6108d | 533 | |
0bbaf069 | 534 | gfar_halt(dev); |
fef6108d | 535 | |
fba4ed03 SG |
536 | unlock_tx_qs(priv); |
537 | unlock_rx_qs(priv); | |
538 | local_irq_save(flags); | |
0bbaf069 | 539 | |
fba4ed03 SG |
540 | for (i = 0; i < priv->num_rx_queues; i++) |
541 | gfar_clean_rx_ring(priv->rx_queue[i], | |
542 | priv->rx_queue[i]->rx_ring_size); | |
12dea57b | 543 | |
0bbaf069 | 544 | /* Now we take down the rings to rebuild them */ |
1da177e4 LT |
545 | stop_gfar(dev); |
546 | } | |
547 | ||
d87eb127 | 548 | spin_lock_irqsave(&priv->bflock, flags); |
0bbaf069 | 549 | priv->rx_csum_enable = data; |
d87eb127 | 550 | spin_unlock_irqrestore(&priv->bflock, flags); |
1da177e4 | 551 | |
12dea57b | 552 | if (dev->flags & IFF_UP) { |
1da177e4 | 553 | err = startup_gfar(dev); |
fba4ed03 | 554 | netif_tx_wake_all_queues(dev); |
12dea57b | 555 | } |
1da177e4 LT |
556 | return err; |
557 | } | |
558 | ||
0bbaf069 KG |
559 | static uint32_t gfar_get_rx_csum(struct net_device *dev) |
560 | { | |
561 | struct gfar_private *priv = netdev_priv(dev); | |
562 | ||
b31a1d8b | 563 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
0bbaf069 KG |
564 | return 0; |
565 | ||
566 | return priv->rx_csum_enable; | |
567 | } | |
568 | ||
569 | static int gfar_set_tx_csum(struct net_device *dev, uint32_t data) | |
570 | { | |
0bbaf069 KG |
571 | struct gfar_private *priv = netdev_priv(dev); |
572 | ||
b31a1d8b | 573 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
0bbaf069 KG |
574 | return -EOPNOTSUPP; |
575 | ||
12dea57b | 576 | netif_tx_lock_bh(dev); |
0bbaf069 KG |
577 | |
578 | if (data) | |
579 | dev->features |= NETIF_F_IP_CSUM; | |
580 | else | |
581 | dev->features &= ~NETIF_F_IP_CSUM; | |
582 | ||
12dea57b | 583 | netif_tx_unlock_bh(dev); |
0bbaf069 KG |
584 | |
585 | return 0; | |
586 | } | |
587 | ||
588 | static uint32_t gfar_get_tx_csum(struct net_device *dev) | |
589 | { | |
590 | struct gfar_private *priv = netdev_priv(dev); | |
591 | ||
b31a1d8b | 592 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_CSUM)) |
0bbaf069 KG |
593 | return 0; |
594 | ||
595 | return (dev->features & NETIF_F_IP_CSUM) != 0; | |
596 | } | |
597 | ||
598 | static uint32_t gfar_get_msglevel(struct net_device *dev) | |
6aa20a22 | 599 | { |
0bbaf069 KG |
600 | struct gfar_private *priv = netdev_priv(dev); |
601 | return priv->msg_enable; | |
6aa20a22 JG |
602 | } |
603 | ||
0bbaf069 | 604 | static void gfar_set_msglevel(struct net_device *dev, uint32_t data) |
6aa20a22 | 605 | { |
0bbaf069 KG |
606 | struct gfar_private *priv = netdev_priv(dev); |
607 | priv->msg_enable = data; | |
608 | } | |
609 | ||
d87eb127 SW |
610 | #ifdef CONFIG_PM |
611 | static void gfar_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | |
612 | { | |
613 | struct gfar_private *priv = netdev_priv(dev); | |
614 | ||
b31a1d8b | 615 | if (priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) { |
d87eb127 SW |
616 | wol->supported = WAKE_MAGIC; |
617 | wol->wolopts = priv->wol_en ? WAKE_MAGIC : 0; | |
618 | } else { | |
619 | wol->supported = wol->wolopts = 0; | |
620 | } | |
621 | } | |
622 | ||
623 | static int gfar_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) | |
624 | { | |
625 | struct gfar_private *priv = netdev_priv(dev); | |
626 | unsigned long flags; | |
627 | ||
b31a1d8b | 628 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_MAGIC_PACKET) && |
d87eb127 SW |
629 | wol->wolopts != 0) |
630 | return -EINVAL; | |
631 | ||
632 | if (wol->wolopts & ~WAKE_MAGIC) | |
633 | return -EINVAL; | |
634 | ||
635 | spin_lock_irqsave(&priv->bflock, flags); | |
636 | priv->wol_en = wol->wolopts & WAKE_MAGIC ? 1 : 0; | |
2884e5cc | 637 | device_set_wakeup_enable(&dev->dev, priv->wol_en); |
d87eb127 SW |
638 | spin_unlock_irqrestore(&priv->bflock, flags); |
639 | ||
640 | return 0; | |
641 | } | |
642 | #endif | |
0bbaf069 | 643 | |
7282d491 | 644 | const struct ethtool_ops gfar_ethtool_ops = { |
1da177e4 | 645 | .get_settings = gfar_gsettings, |
bb40dcbb | 646 | .set_settings = gfar_ssettings, |
1da177e4 LT |
647 | .get_drvinfo = gfar_gdrvinfo, |
648 | .get_regs_len = gfar_reglen, | |
649 | .get_regs = gfar_get_regs, | |
650 | .get_link = ethtool_op_get_link, | |
651 | .get_coalesce = gfar_gcoalesce, | |
652 | .set_coalesce = gfar_scoalesce, | |
653 | .get_ringparam = gfar_gringparam, | |
654 | .set_ringparam = gfar_sringparam, | |
655 | .get_strings = gfar_gstrings, | |
b9f2c044 | 656 | .get_sset_count = gfar_sset_count, |
1da177e4 | 657 | .get_ethtool_stats = gfar_fill_stats, |
0bbaf069 KG |
658 | .get_rx_csum = gfar_get_rx_csum, |
659 | .get_tx_csum = gfar_get_tx_csum, | |
660 | .set_rx_csum = gfar_set_rx_csum, | |
661 | .set_tx_csum = gfar_set_tx_csum, | |
4669bc90 | 662 | .set_sg = ethtool_op_set_sg, |
0bbaf069 KG |
663 | .get_msglevel = gfar_get_msglevel, |
664 | .set_msglevel = gfar_set_msglevel, | |
d87eb127 SW |
665 | #ifdef CONFIG_PM |
666 | .get_wol = gfar_get_wol, | |
667 | .set_wol = gfar_set_wol, | |
668 | #endif | |
1da177e4 | 669 | }; |