2 * drivers/net/ethernet/freescale/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)
11 * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
13 * Copyright 2002-2009 Freescale Semiconductor, Inc.
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License as published by the
17 * Free Software Foundation; either version 2 of the License, or (at your
18 * option) any later version.
20 * Sysfs file creation and management
23 #include <linux/kernel.h>
24 #include <linux/string.h>
25 #include <linux/errno.h>
26 #include <linux/unistd.h>
27 #include <linux/delay.h>
28 #include <linux/etherdevice.h>
29 #include <linux/spinlock.h>
31 #include <linux/device.h>
33 #include <asm/uaccess.h>
34 #include <linux/module.h>
38 static ssize_t
gfar_show_bd_stash(struct device
*dev
,
39 struct device_attribute
*attr
, char *buf
)
41 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
43 return sprintf(buf
, "%s\n", priv
->bd_stash_en
? "on" : "off");
46 static ssize_t
gfar_set_bd_stash(struct device
*dev
,
47 struct device_attribute
*attr
,
48 const char *buf
, size_t count
)
50 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
51 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
56 if (!(priv
->device_flags
& FSL_GIANFAR_DEV_HAS_BD_STASHING
))
60 /* Find out the new setting */
61 if (!strncmp("on", buf
, count
- 1) || !strncmp("1", buf
, count
- 1))
63 else if (!strncmp("off", buf
, count
- 1) ||
64 !strncmp("0", buf
, count
- 1))
70 local_irq_save(flags
);
73 /* Set the new stashing value */
74 priv
->bd_stash_en
= new_setting
;
76 temp
= gfar_read(®s
->attr
);
81 temp
&= ~(ATTR_BDSTASH
);
83 gfar_write(®s
->attr
, temp
);
86 local_irq_restore(flags
);
91 static DEVICE_ATTR(bd_stash
, 0644, gfar_show_bd_stash
, gfar_set_bd_stash
);
93 static ssize_t
gfar_show_rx_stash_size(struct device
*dev
,
94 struct device_attribute
*attr
, char *buf
)
96 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
98 return sprintf(buf
, "%d\n", priv
->rx_stash_size
);
101 static ssize_t
gfar_set_rx_stash_size(struct device
*dev
,
102 struct device_attribute
*attr
,
103 const char *buf
, size_t count
)
105 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
106 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
107 unsigned int length
= simple_strtoul(buf
, NULL
, 0);
111 if (!(priv
->device_flags
& FSL_GIANFAR_DEV_HAS_BUF_STASHING
))
114 local_irq_save(flags
);
117 if (length
> priv
->rx_buffer_size
)
120 if (length
== priv
->rx_stash_size
)
123 priv
->rx_stash_size
= length
;
125 temp
= gfar_read(®s
->attreli
);
126 temp
&= ~ATTRELI_EL_MASK
;
127 temp
|= ATTRELI_EL(length
);
128 gfar_write(®s
->attreli
, temp
);
130 /* Turn stashing on/off as appropriate */
131 temp
= gfar_read(®s
->attr
);
134 temp
|= ATTR_BUFSTASH
;
136 temp
&= ~(ATTR_BUFSTASH
);
138 gfar_write(®s
->attr
, temp
);
142 local_irq_restore(flags
);
147 static DEVICE_ATTR(rx_stash_size
, 0644, gfar_show_rx_stash_size
,
148 gfar_set_rx_stash_size
);
150 /* Stashing will only be enabled when rx_stash_size != 0 */
151 static ssize_t
gfar_show_rx_stash_index(struct device
*dev
,
152 struct device_attribute
*attr
,
155 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
157 return sprintf(buf
, "%d\n", priv
->rx_stash_index
);
160 static ssize_t
gfar_set_rx_stash_index(struct device
*dev
,
161 struct device_attribute
*attr
,
162 const char *buf
, size_t count
)
164 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
165 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
166 unsigned short index
= simple_strtoul(buf
, NULL
, 0);
170 if (!(priv
->device_flags
& FSL_GIANFAR_DEV_HAS_BUF_STASHING
))
173 local_irq_save(flags
);
176 if (index
> priv
->rx_stash_size
)
179 if (index
== priv
->rx_stash_index
)
182 priv
->rx_stash_index
= index
;
184 temp
= gfar_read(®s
->attreli
);
185 temp
&= ~ATTRELI_EI_MASK
;
186 temp
|= ATTRELI_EI(index
);
187 gfar_write(®s
->attreli
, temp
);
191 local_irq_restore(flags
);
196 static DEVICE_ATTR(rx_stash_index
, 0644, gfar_show_rx_stash_index
,
197 gfar_set_rx_stash_index
);
199 static ssize_t
gfar_show_fifo_threshold(struct device
*dev
,
200 struct device_attribute
*attr
,
203 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
205 return sprintf(buf
, "%d\n", priv
->fifo_threshold
);
208 static ssize_t
gfar_set_fifo_threshold(struct device
*dev
,
209 struct device_attribute
*attr
,
210 const char *buf
, size_t count
)
212 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
213 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
214 unsigned int length
= simple_strtoul(buf
, NULL
, 0);
218 if (length
> GFAR_MAX_FIFO_THRESHOLD
)
221 local_irq_save(flags
);
224 priv
->fifo_threshold
= length
;
226 temp
= gfar_read(®s
->fifo_tx_thr
);
227 temp
&= ~FIFO_TX_THR_MASK
;
229 gfar_write(®s
->fifo_tx_thr
, temp
);
232 local_irq_restore(flags
);
237 static DEVICE_ATTR(fifo_threshold
, 0644, gfar_show_fifo_threshold
,
238 gfar_set_fifo_threshold
);
240 static ssize_t
gfar_show_fifo_starve(struct device
*dev
,
241 struct device_attribute
*attr
, char *buf
)
243 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
245 return sprintf(buf
, "%d\n", priv
->fifo_starve
);
248 static ssize_t
gfar_set_fifo_starve(struct device
*dev
,
249 struct device_attribute
*attr
,
250 const char *buf
, size_t count
)
252 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
253 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
254 unsigned int num
= simple_strtoul(buf
, NULL
, 0);
258 if (num
> GFAR_MAX_FIFO_STARVE
)
261 local_irq_save(flags
);
264 priv
->fifo_starve
= num
;
266 temp
= gfar_read(®s
->fifo_tx_starve
);
267 temp
&= ~FIFO_TX_STARVE_MASK
;
269 gfar_write(®s
->fifo_tx_starve
, temp
);
272 local_irq_restore(flags
);
277 static DEVICE_ATTR(fifo_starve
, 0644, gfar_show_fifo_starve
,
278 gfar_set_fifo_starve
);
280 static ssize_t
gfar_show_fifo_starve_off(struct device
*dev
,
281 struct device_attribute
*attr
,
284 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
286 return sprintf(buf
, "%d\n", priv
->fifo_starve_off
);
289 static ssize_t
gfar_set_fifo_starve_off(struct device
*dev
,
290 struct device_attribute
*attr
,
291 const char *buf
, size_t count
)
293 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
294 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
295 unsigned int num
= simple_strtoul(buf
, NULL
, 0);
299 if (num
> GFAR_MAX_FIFO_STARVE_OFF
)
302 local_irq_save(flags
);
305 priv
->fifo_starve_off
= num
;
307 temp
= gfar_read(®s
->fifo_tx_starve_shutoff
);
308 temp
&= ~FIFO_TX_STARVE_OFF_MASK
;
310 gfar_write(®s
->fifo_tx_starve_shutoff
, temp
);
313 local_irq_restore(flags
);
318 static DEVICE_ATTR(fifo_starve_off
, 0644, gfar_show_fifo_starve_off
,
319 gfar_set_fifo_starve_off
);
321 void gfar_init_sysfs(struct net_device
*dev
)
323 struct gfar_private
*priv
= netdev_priv(dev
);
326 /* Initialize the default values */
327 priv
->fifo_threshold
= DEFAULT_FIFO_TX_THR
;
328 priv
->fifo_starve
= DEFAULT_FIFO_TX_STARVE
;
329 priv
->fifo_starve_off
= DEFAULT_FIFO_TX_STARVE_OFF
;
331 /* Create our sysfs files */
332 rc
= device_create_file(&dev
->dev
, &dev_attr_bd_stash
);
333 rc
|= device_create_file(&dev
->dev
, &dev_attr_rx_stash_size
);
334 rc
|= device_create_file(&dev
->dev
, &dev_attr_rx_stash_index
);
335 rc
|= device_create_file(&dev
->dev
, &dev_attr_fifo_threshold
);
336 rc
|= device_create_file(&dev
->dev
, &dev_attr_fifo_starve
);
337 rc
|= device_create_file(&dev
->dev
, &dev_attr_fifo_starve_off
);
339 dev_err(&dev
->dev
, "Error creating gianfar sysfs files\n");