]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/gianfar_sysfs.c
gianfar: Add support for skb recycling
[net-next-2.6.git] / drivers / net / gianfar_sysfs.c
CommitLineData
7f7f5316
AF
1/*
2 * drivers/net/gianfar_sysfs.c
3 *
4 * Gianfar Ethernet Driver
5 * This driver is designed for the non-CPM ethernet controllers
6 * on the 85xx and 83xx family of integrated processors
7 * Based on 8260_io/fcc_enet.c
8 *
9 * Author: Andy Fleming
b56d55b6 10 * Maintainer: Kumar Gala (galak@kernel.crashing.org)
7f7f5316
AF
11 *
12 * Copyright (c) 2002-2005 Freescale Semiconductor, Inc.
13 *
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
18 *
19 * Sysfs file creation and management
20 */
21
7f7f5316 22#include <linux/kernel.h>
7f7f5316
AF
23#include <linux/string.h>
24#include <linux/errno.h>
25#include <linux/unistd.h>
26#include <linux/slab.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/etherdevice.h>
30#include <linux/spinlock.h>
31#include <linux/mm.h>
32#include <linux/device.h>
33
34#include <asm/uaccess.h>
35#include <linux/module.h>
7f7f5316
AF
36
37#include "gianfar.h"
38
4409d281
KG
39static ssize_t gfar_show_bd_stash(struct device *dev,
40 struct device_attribute *attr, char *buf)
7f7f5316 41{
4409d281 42 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316 43
4409d281 44 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
7f7f5316
AF
45}
46
4409d281
KG
47static ssize_t gfar_set_bd_stash(struct device *dev,
48 struct device_attribute *attr,
49 const char *buf, size_t count)
7f7f5316 50{
4409d281 51 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
52 int new_setting = 0;
53 u32 temp;
54 unsigned long flags;
55
56 /* Find out the new setting */
4409d281 57 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
7f7f5316 58 new_setting = 1;
4409d281
KG
59 else if (!strncmp("off", buf, count - 1)
60 || !strncmp("0", buf, count - 1))
7f7f5316
AF
61 new_setting = 0;
62 else
63 return count;
64
fef6108d 65 spin_lock_irqsave(&priv->rxlock, flags);
7f7f5316
AF
66
67 /* Set the new stashing value */
68 priv->bd_stash_en = new_setting;
69
70 temp = gfar_read(&priv->regs->attr);
6aa20a22 71
7f7f5316
AF
72 if (new_setting)
73 temp |= ATTR_BDSTASH;
74 else
75 temp &= ~(ATTR_BDSTASH);
76
77 gfar_write(&priv->regs->attr, temp);
78
fef6108d 79 spin_unlock_irqrestore(&priv->rxlock, flags);
7f7f5316
AF
80
81 return count;
82}
83
b2f66d18 84static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
35a84fdc 85
4409d281
KG
86static ssize_t gfar_show_rx_stash_size(struct device *dev,
87 struct device_attribute *attr, char *buf)
7f7f5316 88{
4409d281 89 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
90
91 return sprintf(buf, "%d\n", priv->rx_stash_size);
92}
93
4409d281
KG
94static ssize_t gfar_set_rx_stash_size(struct device *dev,
95 struct device_attribute *attr,
96 const char *buf, size_t count)
7f7f5316 97{
4409d281 98 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
99 unsigned int length = simple_strtoul(buf, NULL, 0);
100 u32 temp;
101 unsigned long flags;
102
fef6108d 103 spin_lock_irqsave(&priv->rxlock, flags);
7f7f5316 104 if (length > priv->rx_buffer_size)
f162b9d5 105 goto out;
7f7f5316
AF
106
107 if (length == priv->rx_stash_size)
f162b9d5 108 goto out;
7f7f5316
AF
109
110 priv->rx_stash_size = length;
111
112 temp = gfar_read(&priv->regs->attreli);
113 temp &= ~ATTRELI_EL_MASK;
114 temp |= ATTRELI_EL(length);
115 gfar_write(&priv->regs->attreli, temp);
116
117 /* Turn stashing on/off as appropriate */
118 temp = gfar_read(&priv->regs->attr);
119
120 if (length)
121 temp |= ATTR_BUFSTASH;
122 else
123 temp &= ~(ATTR_BUFSTASH);
124
125 gfar_write(&priv->regs->attr, temp);
126
f162b9d5 127out:
fef6108d 128 spin_unlock_irqrestore(&priv->rxlock, flags);
7f7f5316
AF
129
130 return count;
131}
132
b2f66d18
AV
133static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
134 gfar_set_rx_stash_size);
35a84fdc 135
7f7f5316 136/* Stashing will only be enabled when rx_stash_size != 0 */
4409d281
KG
137static ssize_t gfar_show_rx_stash_index(struct device *dev,
138 struct device_attribute *attr,
139 char *buf)
7f7f5316 140{
4409d281 141 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
142
143 return sprintf(buf, "%d\n", priv->rx_stash_index);
144}
145
4409d281
KG
146static ssize_t gfar_set_rx_stash_index(struct device *dev,
147 struct device_attribute *attr,
148 const char *buf, size_t count)
7f7f5316 149{
4409d281 150 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
151 unsigned short index = simple_strtoul(buf, NULL, 0);
152 u32 temp;
153 unsigned long flags;
154
fef6108d 155 spin_lock_irqsave(&priv->rxlock, flags);
7f7f5316 156 if (index > priv->rx_stash_size)
f162b9d5 157 goto out;
7f7f5316
AF
158
159 if (index == priv->rx_stash_index)
f162b9d5 160 goto out;
7f7f5316
AF
161
162 priv->rx_stash_index = index;
163
164 temp = gfar_read(&priv->regs->attreli);
165 temp &= ~ATTRELI_EI_MASK;
166 temp |= ATTRELI_EI(index);
167 gfar_write(&priv->regs->attreli, flags);
168
f162b9d5 169out:
fef6108d 170 spin_unlock_irqrestore(&priv->rxlock, flags);
7f7f5316
AF
171
172 return count;
173}
174
b2f66d18
AV
175static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
176 gfar_set_rx_stash_index);
35a84fdc 177
4409d281
KG
178static ssize_t gfar_show_fifo_threshold(struct device *dev,
179 struct device_attribute *attr,
180 char *buf)
7f7f5316 181{
4409d281 182 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
183
184 return sprintf(buf, "%d\n", priv->fifo_threshold);
185}
186
4409d281
KG
187static ssize_t gfar_set_fifo_threshold(struct device *dev,
188 struct device_attribute *attr,
189 const char *buf, size_t count)
7f7f5316 190{
4409d281 191 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
192 unsigned int length = simple_strtoul(buf, NULL, 0);
193 u32 temp;
194 unsigned long flags;
195
196 if (length > GFAR_MAX_FIFO_THRESHOLD)
197 return count;
198
fef6108d 199 spin_lock_irqsave(&priv->txlock, flags);
7f7f5316
AF
200
201 priv->fifo_threshold = length;
202
203 temp = gfar_read(&priv->regs->fifo_tx_thr);
204 temp &= ~FIFO_TX_THR_MASK;
205 temp |= length;
206 gfar_write(&priv->regs->fifo_tx_thr, temp);
207
fef6108d 208 spin_unlock_irqrestore(&priv->txlock, flags);
7f7f5316
AF
209
210 return count;
211}
212
b2f66d18
AV
213static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
214 gfar_set_fifo_threshold);
35a84fdc 215
4409d281
KG
216static ssize_t gfar_show_fifo_starve(struct device *dev,
217 struct device_attribute *attr, char *buf)
7f7f5316 218{
4409d281 219 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
220
221 return sprintf(buf, "%d\n", priv->fifo_starve);
222}
223
4409d281
KG
224static ssize_t gfar_set_fifo_starve(struct device *dev,
225 struct device_attribute *attr,
226 const char *buf, size_t count)
7f7f5316 227{
4409d281 228 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
229 unsigned int num = simple_strtoul(buf, NULL, 0);
230 u32 temp;
231 unsigned long flags;
232
233 if (num > GFAR_MAX_FIFO_STARVE)
234 return count;
235
fef6108d 236 spin_lock_irqsave(&priv->txlock, flags);
7f7f5316
AF
237
238 priv->fifo_starve = num;
239
240 temp = gfar_read(&priv->regs->fifo_tx_starve);
241 temp &= ~FIFO_TX_STARVE_MASK;
242 temp |= num;
243 gfar_write(&priv->regs->fifo_tx_starve, temp);
244
fef6108d 245 spin_unlock_irqrestore(&priv->txlock, flags);
7f7f5316
AF
246
247 return count;
248}
249
b2f66d18
AV
250static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
251 gfar_set_fifo_starve);
35a84fdc 252
4409d281
KG
253static ssize_t gfar_show_fifo_starve_off(struct device *dev,
254 struct device_attribute *attr,
255 char *buf)
7f7f5316 256{
4409d281 257 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
258
259 return sprintf(buf, "%d\n", priv->fifo_starve_off);
260}
261
4409d281
KG
262static ssize_t gfar_set_fifo_starve_off(struct device *dev,
263 struct device_attribute *attr,
264 const char *buf, size_t count)
7f7f5316 265{
4409d281 266 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
267 unsigned int num = simple_strtoul(buf, NULL, 0);
268 u32 temp;
269 unsigned long flags;
270
271 if (num > GFAR_MAX_FIFO_STARVE_OFF)
272 return count;
273
fef6108d 274 spin_lock_irqsave(&priv->txlock, flags);
7f7f5316
AF
275
276 priv->fifo_starve_off = num;
277
278 temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
279 temp &= ~FIFO_TX_STARVE_OFF_MASK;
280 temp |= num;
281 gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
282
fef6108d 283 spin_unlock_irqrestore(&priv->txlock, flags);
7f7f5316
AF
284
285 return count;
286}
287
b2f66d18
AV
288static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
289 gfar_set_fifo_starve_off);
35a84fdc 290
7f7f5316
AF
291void gfar_init_sysfs(struct net_device *dev)
292{
293 struct gfar_private *priv = netdev_priv(dev);
35a84fdc 294 int rc;
7f7f5316
AF
295
296 /* Initialize the default values */
297 priv->rx_stash_size = DEFAULT_STASH_LENGTH;
298 priv->rx_stash_index = DEFAULT_STASH_INDEX;
299 priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
300 priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
301 priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
302 priv->bd_stash_en = DEFAULT_BD_STASH;
303
304 /* Create our sysfs files */
35a84fdc
GL
305 rc = device_create_file(&dev->dev, &dev_attr_bd_stash);
306 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size);
307 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index);
308 rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold);
309 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve);
310 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off);
311 if (rc)
312 dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");
7f7f5316 313}