2 * drivers/net/gianfar_sysfs.c
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
10 * Maintainer: Kumar Gala (galak@kernel.crashing.org)
12 * Copyright (c) 2002-2005 Freescale Semiconductor, Inc.
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.
19 * Sysfs file creation and management
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>
32 #include <linux/device.h>
34 #include <asm/uaccess.h>
35 #include <linux/module.h>
36 #include <linux/version.h>
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)
46 #define GFAR_CREATE_FILE(_dev, _name) \
47 class_device_create_file(&_dev->class_dev, &class_device_attr_##_name)
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
);
56 #define to_net_dev(cd) container_of(cd, struct net_device, class_dev)
58 static ssize_t
gfar_show_bd_stash(struct class_device
*cdev
, char *buf
)
60 struct net_device
*dev
= to_net_dev(cdev
);
61 struct gfar_private
*priv
= netdev_priv(dev
);
63 return sprintf(buf
, "%s\n", priv
->bd_stash_en
? "on" : "off");
66 static ssize_t
gfar_set_bd_stash(struct class_device
*cdev
,
67 const char *buf
, size_t count
)
69 struct net_device
*dev
= to_net_dev(cdev
);
70 struct gfar_private
*priv
= netdev_priv(dev
);
75 /* Find out the new setting */
76 if (!strncmp("on", buf
, count
-1) || !strncmp("1", buf
, count
-1))
78 else if (!strncmp("off", buf
, count
-1) || !strncmp("0", buf
, count
-1))
83 spin_lock_irqsave(&priv
->rxlock
, flags
);
85 /* Set the new stashing value */
86 priv
->bd_stash_en
= new_setting
;
88 temp
= gfar_read(&priv
->regs
->attr
);
93 temp
&= ~(ATTR_BDSTASH
);
95 gfar_write(&priv
->regs
->attr
, temp
);
97 spin_unlock_irqrestore(&priv
->rxlock
, flags
);
102 static ssize_t
gfar_show_rx_stash_size(struct class_device
*cdev
, char *buf
)
104 struct net_device
*dev
= to_net_dev(cdev
);
105 struct gfar_private
*priv
= netdev_priv(dev
);
107 return sprintf(buf
, "%d\n", priv
->rx_stash_size
);
110 static ssize_t
gfar_set_rx_stash_size(struct class_device
*cdev
,
111 const char *buf
, size_t count
)
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);
119 spin_lock_irqsave(&priv
->rxlock
, flags
);
120 if (length
> priv
->rx_buffer_size
)
123 if (length
== priv
->rx_stash_size
)
126 priv
->rx_stash_size
= length
;
128 temp
= gfar_read(&priv
->regs
->attreli
);
129 temp
&= ~ATTRELI_EL_MASK
;
130 temp
|= ATTRELI_EL(length
);
131 gfar_write(&priv
->regs
->attreli
, temp
);
133 /* Turn stashing on/off as appropriate */
134 temp
= gfar_read(&priv
->regs
->attr
);
137 temp
|= ATTR_BUFSTASH
;
139 temp
&= ~(ATTR_BUFSTASH
);
141 gfar_write(&priv
->regs
->attr
, temp
);
143 spin_unlock_irqrestore(&priv
->rxlock
, flags
);
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
)
152 struct net_device
*dev
= to_net_dev(cdev
);
153 struct gfar_private
*priv
= netdev_priv(dev
);
155 return sprintf(buf
, "%d\n", priv
->rx_stash_index
);
158 static ssize_t
gfar_set_rx_stash_index(struct class_device
*cdev
,
159 const char *buf
, size_t count
)
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);
167 spin_lock_irqsave(&priv
->rxlock
, flags
);
168 if (index
> priv
->rx_stash_size
)
171 if (index
== priv
->rx_stash_index
)
174 priv
->rx_stash_index
= index
;
176 temp
= gfar_read(&priv
->regs
->attreli
);
177 temp
&= ~ATTRELI_EI_MASK
;
178 temp
|= ATTRELI_EI(index
);
179 gfar_write(&priv
->regs
->attreli
, flags
);
181 spin_unlock_irqrestore(&priv
->rxlock
, flags
);
186 static ssize_t
gfar_show_fifo_threshold(struct class_device
*cdev
, char *buf
)
188 struct net_device
*dev
= to_net_dev(cdev
);
189 struct gfar_private
*priv
= netdev_priv(dev
);
191 return sprintf(buf
, "%d\n", priv
->fifo_threshold
);
194 static ssize_t
gfar_set_fifo_threshold(struct class_device
*cdev
,
195 const char *buf
, size_t count
)
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);
203 if (length
> GFAR_MAX_FIFO_THRESHOLD
)
206 spin_lock_irqsave(&priv
->txlock
, flags
);
208 priv
->fifo_threshold
= length
;
210 temp
= gfar_read(&priv
->regs
->fifo_tx_thr
);
211 temp
&= ~FIFO_TX_THR_MASK
;
213 gfar_write(&priv
->regs
->fifo_tx_thr
, temp
);
215 spin_unlock_irqrestore(&priv
->txlock
, flags
);
220 static ssize_t
gfar_show_fifo_starve(struct class_device
*cdev
, char *buf
)
222 struct net_device
*dev
= to_net_dev(cdev
);
223 struct gfar_private
*priv
= netdev_priv(dev
);
225 return sprintf(buf
, "%d\n", priv
->fifo_starve
);
229 static ssize_t
gfar_set_fifo_starve(struct class_device
*cdev
,
230 const char *buf
, size_t count
)
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);
238 if (num
> GFAR_MAX_FIFO_STARVE
)
241 spin_lock_irqsave(&priv
->txlock
, flags
);
243 priv
->fifo_starve
= num
;
245 temp
= gfar_read(&priv
->regs
->fifo_tx_starve
);
246 temp
&= ~FIFO_TX_STARVE_MASK
;
248 gfar_write(&priv
->regs
->fifo_tx_starve
, temp
);
250 spin_unlock_irqrestore(&priv
->txlock
, flags
);
255 static ssize_t
gfar_show_fifo_starve_off(struct class_device
*cdev
, char *buf
)
257 struct net_device
*dev
= to_net_dev(cdev
);
258 struct gfar_private
*priv
= netdev_priv(dev
);
260 return sprintf(buf
, "%d\n", priv
->fifo_starve_off
);
263 static ssize_t
gfar_set_fifo_starve_off(struct class_device
*cdev
,
264 const char *buf
, size_t count
)
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);
272 if (num
> GFAR_MAX_FIFO_STARVE_OFF
)
275 spin_lock_irqsave(&priv
->txlock
, flags
);
277 priv
->fifo_starve_off
= num
;
279 temp
= gfar_read(&priv
->regs
->fifo_tx_starve_shutoff
);
280 temp
&= ~FIFO_TX_STARVE_OFF_MASK
;
282 gfar_write(&priv
->regs
->fifo_tx_starve_shutoff
, temp
);
284 spin_unlock_irqrestore(&priv
->txlock
, flags
);
289 void gfar_init_sysfs(struct net_device
*dev
)
291 struct gfar_private
*priv
= netdev_priv(dev
);
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
;
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
);