Merge branch 'for-linus' of git://one.firstfloor.org/home/andi/git/linux-2.6
[deliverable/linux.git] / drivers / net / gianfar_sysfs.c
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
10 * Maintainer: Kumar Gala (galak@kernel.crashing.org)
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
22 #include <linux/kernel.h>
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>
36 #include <linux/version.h>
37
38 #include "gianfar.h"
39
40 #define GFAR_ATTR(_name) \
41 static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \
42 static ssize_t gfar_set_##_name(struct class_device *cdev, \
43 const char *buf, size_t count); \
44 static CLASS_DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name)
45
46 #define GFAR_CREATE_FILE(_dev, _name) \
47 class_device_create_file(&_dev->class_dev, &class_device_attr_##_name)
48
49 GFAR_ATTR(bd_stash);
50 GFAR_ATTR(rx_stash_size);
51 GFAR_ATTR(rx_stash_index);
52 GFAR_ATTR(fifo_threshold);
53 GFAR_ATTR(fifo_starve);
54 GFAR_ATTR(fifo_starve_off);
55
56 #define to_net_dev(cd) container_of(cd, struct net_device, class_dev)
57
58 static ssize_t gfar_show_bd_stash(struct class_device *cdev, char *buf)
59 {
60 struct net_device *dev = to_net_dev(cdev);
61 struct gfar_private *priv = netdev_priv(dev);
62
63 return sprintf(buf, "%s\n", priv->bd_stash_en? "on" : "off");
64 }
65
66 static ssize_t gfar_set_bd_stash(struct class_device *cdev,
67 const char *buf, size_t count)
68 {
69 struct net_device *dev = to_net_dev(cdev);
70 struct gfar_private *priv = netdev_priv(dev);
71 int new_setting = 0;
72 u32 temp;
73 unsigned long flags;
74
75 /* Find out the new setting */
76 if (!strncmp("on", buf, count-1) || !strncmp("1", buf, count-1))
77 new_setting = 1;
78 else if (!strncmp("off", buf, count-1) || !strncmp("0", buf, count-1))
79 new_setting = 0;
80 else
81 return count;
82
83 spin_lock_irqsave(&priv->rxlock, flags);
84
85 /* Set the new stashing value */
86 priv->bd_stash_en = new_setting;
87
88 temp = gfar_read(&priv->regs->attr);
89
90 if (new_setting)
91 temp |= ATTR_BDSTASH;
92 else
93 temp &= ~(ATTR_BDSTASH);
94
95 gfar_write(&priv->regs->attr, temp);
96
97 spin_unlock_irqrestore(&priv->rxlock, flags);
98
99 return count;
100 }
101
102 static ssize_t gfar_show_rx_stash_size(struct class_device *cdev, char *buf)
103 {
104 struct net_device *dev = to_net_dev(cdev);
105 struct gfar_private *priv = netdev_priv(dev);
106
107 return sprintf(buf, "%d\n", priv->rx_stash_size);
108 }
109
110 static ssize_t gfar_set_rx_stash_size(struct class_device *cdev,
111 const char *buf, size_t count)
112 {
113 struct net_device *dev = to_net_dev(cdev);
114 struct gfar_private *priv = netdev_priv(dev);
115 unsigned int length = simple_strtoul(buf, NULL, 0);
116 u32 temp;
117 unsigned long flags;
118
119 spin_lock_irqsave(&priv->rxlock, flags);
120 if (length > priv->rx_buffer_size)
121 return count;
122
123 if (length == priv->rx_stash_size)
124 return count;
125
126 priv->rx_stash_size = length;
127
128 temp = gfar_read(&priv->regs->attreli);
129 temp &= ~ATTRELI_EL_MASK;
130 temp |= ATTRELI_EL(length);
131 gfar_write(&priv->regs->attreli, temp);
132
133 /* Turn stashing on/off as appropriate */
134 temp = gfar_read(&priv->regs->attr);
135
136 if (length)
137 temp |= ATTR_BUFSTASH;
138 else
139 temp &= ~(ATTR_BUFSTASH);
140
141 gfar_write(&priv->regs->attr, temp);
142
143 spin_unlock_irqrestore(&priv->rxlock, flags);
144
145 return count;
146 }
147
148
149 /* Stashing will only be enabled when rx_stash_size != 0 */
150 static ssize_t gfar_show_rx_stash_index(struct class_device *cdev, char *buf)
151 {
152 struct net_device *dev = to_net_dev(cdev);
153 struct gfar_private *priv = netdev_priv(dev);
154
155 return sprintf(buf, "%d\n", priv->rx_stash_index);
156 }
157
158 static ssize_t gfar_set_rx_stash_index(struct class_device *cdev,
159 const char *buf, size_t count)
160 {
161 struct net_device *dev = to_net_dev(cdev);
162 struct gfar_private *priv = netdev_priv(dev);
163 unsigned short index = simple_strtoul(buf, NULL, 0);
164 u32 temp;
165 unsigned long flags;
166
167 spin_lock_irqsave(&priv->rxlock, flags);
168 if (index > priv->rx_stash_size)
169 return count;
170
171 if (index == priv->rx_stash_index)
172 return count;
173
174 priv->rx_stash_index = index;
175
176 temp = gfar_read(&priv->regs->attreli);
177 temp &= ~ATTRELI_EI_MASK;
178 temp |= ATTRELI_EI(index);
179 gfar_write(&priv->regs->attreli, flags);
180
181 spin_unlock_irqrestore(&priv->rxlock, flags);
182
183 return count;
184 }
185
186 static ssize_t gfar_show_fifo_threshold(struct class_device *cdev, char *buf)
187 {
188 struct net_device *dev = to_net_dev(cdev);
189 struct gfar_private *priv = netdev_priv(dev);
190
191 return sprintf(buf, "%d\n", priv->fifo_threshold);
192 }
193
194 static ssize_t gfar_set_fifo_threshold(struct class_device *cdev,
195 const char *buf, size_t count)
196 {
197 struct net_device *dev = to_net_dev(cdev);
198 struct gfar_private *priv = netdev_priv(dev);
199 unsigned int length = simple_strtoul(buf, NULL, 0);
200 u32 temp;
201 unsigned long flags;
202
203 if (length > GFAR_MAX_FIFO_THRESHOLD)
204 return count;
205
206 spin_lock_irqsave(&priv->txlock, flags);
207
208 priv->fifo_threshold = length;
209
210 temp = gfar_read(&priv->regs->fifo_tx_thr);
211 temp &= ~FIFO_TX_THR_MASK;
212 temp |= length;
213 gfar_write(&priv->regs->fifo_tx_thr, temp);
214
215 spin_unlock_irqrestore(&priv->txlock, flags);
216
217 return count;
218 }
219
220 static ssize_t gfar_show_fifo_starve(struct class_device *cdev, char *buf)
221 {
222 struct net_device *dev = to_net_dev(cdev);
223 struct gfar_private *priv = netdev_priv(dev);
224
225 return sprintf(buf, "%d\n", priv->fifo_starve);
226 }
227
228
229 static ssize_t gfar_set_fifo_starve(struct class_device *cdev,
230 const char *buf, size_t count)
231 {
232 struct net_device *dev = to_net_dev(cdev);
233 struct gfar_private *priv = netdev_priv(dev);
234 unsigned int num = simple_strtoul(buf, NULL, 0);
235 u32 temp;
236 unsigned long flags;
237
238 if (num > GFAR_MAX_FIFO_STARVE)
239 return count;
240
241 spin_lock_irqsave(&priv->txlock, flags);
242
243 priv->fifo_starve = num;
244
245 temp = gfar_read(&priv->regs->fifo_tx_starve);
246 temp &= ~FIFO_TX_STARVE_MASK;
247 temp |= num;
248 gfar_write(&priv->regs->fifo_tx_starve, temp);
249
250 spin_unlock_irqrestore(&priv->txlock, flags);
251
252 return count;
253 }
254
255 static ssize_t gfar_show_fifo_starve_off(struct class_device *cdev, char *buf)
256 {
257 struct net_device *dev = to_net_dev(cdev);
258 struct gfar_private *priv = netdev_priv(dev);
259
260 return sprintf(buf, "%d\n", priv->fifo_starve_off);
261 }
262
263 static ssize_t gfar_set_fifo_starve_off(struct class_device *cdev,
264 const char *buf, size_t count)
265 {
266 struct net_device *dev = to_net_dev(cdev);
267 struct gfar_private *priv = netdev_priv(dev);
268 unsigned int num = simple_strtoul(buf, NULL, 0);
269 u32 temp;
270 unsigned long flags;
271
272 if (num > GFAR_MAX_FIFO_STARVE_OFF)
273 return count;
274
275 spin_lock_irqsave(&priv->txlock, flags);
276
277 priv->fifo_starve_off = num;
278
279 temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
280 temp &= ~FIFO_TX_STARVE_OFF_MASK;
281 temp |= num;
282 gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
283
284 spin_unlock_irqrestore(&priv->txlock, flags);
285
286 return count;
287 }
288
289 void gfar_init_sysfs(struct net_device *dev)
290 {
291 struct gfar_private *priv = netdev_priv(dev);
292
293 /* Initialize the default values */
294 priv->rx_stash_size = DEFAULT_STASH_LENGTH;
295 priv->rx_stash_index = DEFAULT_STASH_INDEX;
296 priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
297 priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
298 priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
299 priv->bd_stash_en = DEFAULT_BD_STASH;
300
301 /* Create our sysfs files */
302 GFAR_CREATE_FILE(dev, bd_stash);
303 GFAR_CREATE_FILE(dev, rx_stash_size);
304 GFAR_CREATE_FILE(dev, rx_stash_index);
305 GFAR_CREATE_FILE(dev, fifo_threshold);
306 GFAR_CREATE_FILE(dev, fifo_starve);
307 GFAR_CREATE_FILE(dev, fifo_starve_off);
308
309 }
This page took 0.080441 seconds and 6 git commands to generate.