blob: 45ffb5d0ca33d54ec64c020dd2bf01ab44df0d15 [file] [log] [blame]
Andy Fleming7f7f5312005-11-11 12:38:59 -06001/*
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
Adrian Bunkb56d55b2006-01-11 02:00:10 +010010 * Maintainer: Kumar Gala (galak@kernel.crashing.org)
Andy Fleming7f7f5312005-11-11 12:38:59 -060011 *
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
Andy Fleming7f7f5312005-11-11 12:38:59 -060022#include <linux/kernel.h>
Andy Fleming7f7f5312005-11-11 12:38:59 -060023#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) \
41static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \
42static ssize_t gfar_set_##_name(struct class_device *cdev, \
43 const char *buf, size_t count); \
44static 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
49GFAR_ATTR(bd_stash);
50GFAR_ATTR(rx_stash_size);
51GFAR_ATTR(rx_stash_index);
52GFAR_ATTR(fifo_threshold);
53GFAR_ATTR(fifo_starve);
54GFAR_ATTR(fifo_starve_off);
55
56#define to_net_dev(cd) container_of(cd, struct net_device, class_dev)
57
58static 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
66static 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
Andy Flemingfef61082006-04-20 16:44:29 -050083 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060084
85 /* Set the new stashing value */
86 priv->bd_stash_en = new_setting;
87
88 temp = gfar_read(&priv->regs->attr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040089
Andy Fleming7f7f5312005-11-11 12:38:59 -060090 if (new_setting)
91 temp |= ATTR_BDSTASH;
92 else
93 temp &= ~(ATTR_BDSTASH);
94
95 gfar_write(&priv->regs->attr, temp);
96
Andy Flemingfef61082006-04-20 16:44:29 -050097 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060098
99 return count;
100}
101
102static 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
110static 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
Andy Flemingfef61082006-04-20 16:44:29 -0500119 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600120 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
Andy Flemingfef61082006-04-20 16:44:29 -0500143 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600144
145 return count;
146}
147
148
149/* Stashing will only be enabled when rx_stash_size != 0 */
150static 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
158static 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
Andy Flemingfef61082006-04-20 16:44:29 -0500167 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600168 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
Andy Flemingfef61082006-04-20 16:44:29 -0500181 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600182
183 return count;
184}
185
186static 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
194static 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
Andy Flemingfef61082006-04-20 16:44:29 -0500206 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600207
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
Andy Flemingfef61082006-04-20 16:44:29 -0500215 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600216
217 return count;
218}
219
220static 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
229static 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
Andy Flemingfef61082006-04-20 16:44:29 -0500241 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600242
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
Andy Flemingfef61082006-04-20 16:44:29 -0500250 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600251
252 return count;
253}
254
255static 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
263static 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
Andy Flemingfef61082006-04-20 16:44:29 -0500275 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600276
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
Andy Flemingfef61082006-04-20 16:44:29 -0500284 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600285
286 return count;
287}
288
289void 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}