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)
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/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>
39 static ssize_t
gfar_show_bd_stash(struct device
*dev
,
40 struct device_attribute
*attr
, char *buf
)
42 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
44 return sprintf(buf
, "%s\n", priv
->bd_stash_en
? "on" : "off");
47 static ssize_t
gfar_set_bd_stash(struct device
*dev
,
48 struct device_attribute
*attr
,
49 const char *buf
, size_t count
)
51 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
52 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
57 if (!(priv
->device_flags
& FSL_GIANFAR_DEV_HAS_BD_STASHING
))
61 /* Find out the new setting */
62 if (!strncmp("on", buf
, count
- 1) || !strncmp("1", buf
, count
- 1))
64 else if (!strncmp("off", buf
, count
- 1) ||
65 !strncmp("0", buf
, count
- 1))
71 local_irq_save(flags
);
74 /* Set the new stashing value */
75 priv
->bd_stash_en
= new_setting
;
77 temp
= gfar_read(®s
->attr
);
82 temp
&= ~(ATTR_BDSTASH
);
84 gfar_write(®s
->attr
, temp
);
87 local_irq_restore(flags
);
92 static DEVICE_ATTR(bd_stash
, 0644, gfar_show_bd_stash
, gfar_set_bd_stash
);
94 static ssize_t
gfar_show_rx_stash_size(struct device
*dev
,
95 struct device_attribute
*attr
, char *buf
)
97 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
99 return sprintf(buf
, "%d\n", priv
->rx_stash_size
);
102 static ssize_t
gfar_set_rx_stash_size(struct device
*dev
,
103 struct device_attribute
*attr
,
104 const char *buf
, size_t count
)
106 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
107 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
108 unsigned int length
= simple_strtoul(buf
, NULL
, 0);
112 if (!(priv
->device_flags
& FSL_GIANFAR_DEV_HAS_BUF_STASHING
))
115 local_irq_save(flags
);
118 if (length
> priv
->rx_buffer_size
)
121 if (length
== priv
->rx_stash_size
)
124 priv
->rx_stash_size
= length
;
126 temp
= gfar_read(®s
->attreli
);
127 temp
&= ~ATTRELI_EL_MASK
;
128 temp
|= ATTRELI_EL(length
);
129 gfar_write(®s
->attreli
, temp
);
131 /* Turn stashing on/off as appropriate */
132 temp
= gfar_read(®s
->attr
);
135 temp
|= ATTR_BUFSTASH
;
137 temp
&= ~(ATTR_BUFSTASH
);
139 gfar_write(®s
->attr
, temp
);
143 local_irq_restore(flags
);
148 static DEVICE_ATTR(rx_stash_size
, 0644, gfar_show_rx_stash_size
,
149 gfar_set_rx_stash_size
);
151 /* Stashing will only be enabled when rx_stash_size != 0 */
152 static ssize_t
gfar_show_rx_stash_index(struct device
*dev
,
153 struct device_attribute
*attr
,
156 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
158 return sprintf(buf
, "%d\n", priv
->rx_stash_index
);
161 static ssize_t
gfar_set_rx_stash_index(struct device
*dev
,
162 struct device_attribute
*attr
,
163 const char *buf
, size_t count
)
165 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
166 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
167 unsigned short index
= simple_strtoul(buf
, NULL
, 0);
171 if (!(priv
->device_flags
& FSL_GIANFAR_DEV_HAS_BUF_STASHING
))
174 local_irq_save(flags
);
177 if (index
> priv
->rx_stash_size
)
180 if (index
== priv
->rx_stash_index
)
183 priv
->rx_stash_index
= index
;
185 temp
= gfar_read(®s
->attreli
);
186 temp
&= ~ATTRELI_EI_MASK
;
187 temp
|= ATTRELI_EI(index
);
188 gfar_write(®s
->attreli
, temp
);
192 local_irq_restore(flags
);
197 static DEVICE_ATTR(rx_stash_index
, 0644, gfar_show_rx_stash_index
,
198 gfar_set_rx_stash_index
);
200 static ssize_t
gfar_show_fifo_threshold(struct device
*dev
,
201 struct device_attribute
*attr
,
204 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
206 return sprintf(buf
, "%d\n", priv
->fifo_threshold
);
209 static ssize_t
gfar_set_fifo_threshold(struct device
*dev
,
210 struct device_attribute
*attr
,
211 const char *buf
, size_t count
)
213 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
214 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
215 unsigned int length
= simple_strtoul(buf
, NULL
, 0);
219 if (length
> GFAR_MAX_FIFO_THRESHOLD
)
222 local_irq_save(flags
);
225 priv
->fifo_threshold
= length
;
227 temp
= gfar_read(®s
->fifo_tx_thr
);
228 temp
&= ~FIFO_TX_THR_MASK
;
230 gfar_write(®s
->fifo_tx_thr
, temp
);
233 local_irq_restore(flags
);
238 static DEVICE_ATTR(fifo_threshold
, 0644, gfar_show_fifo_threshold
,
239 gfar_set_fifo_threshold
);
241 static ssize_t
gfar_show_fifo_starve(struct device
*dev
,
242 struct device_attribute
*attr
, char *buf
)
244 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
246 return sprintf(buf
, "%d\n", priv
->fifo_starve
);
249 static ssize_t
gfar_set_fifo_starve(struct device
*dev
,
250 struct device_attribute
*attr
,
251 const char *buf
, size_t count
)
253 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
254 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
255 unsigned int num
= simple_strtoul(buf
, NULL
, 0);
259 if (num
> GFAR_MAX_FIFO_STARVE
)
262 local_irq_save(flags
);
265 priv
->fifo_starve
= num
;
267 temp
= gfar_read(®s
->fifo_tx_starve
);
268 temp
&= ~FIFO_TX_STARVE_MASK
;
270 gfar_write(®s
->fifo_tx_starve
, temp
);
273 local_irq_restore(flags
);
278 static DEVICE_ATTR(fifo_starve
, 0644, gfar_show_fifo_starve
,
279 gfar_set_fifo_starve
);
281 static ssize_t
gfar_show_fifo_starve_off(struct device
*dev
,
282 struct device_attribute
*attr
,
285 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
287 return sprintf(buf
, "%d\n", priv
->fifo_starve_off
);
290 static ssize_t
gfar_set_fifo_starve_off(struct device
*dev
,
291 struct device_attribute
*attr
,
292 const char *buf
, size_t count
)
294 struct gfar_private
*priv
= netdev_priv(to_net_dev(dev
));
295 struct gfar __iomem
*regs
= priv
->gfargrp
[0].regs
;
296 unsigned int num
= simple_strtoul(buf
, NULL
, 0);
300 if (num
> GFAR_MAX_FIFO_STARVE_OFF
)
303 local_irq_save(flags
);
306 priv
->fifo_starve_off
= num
;
308 temp
= gfar_read(®s
->fifo_tx_starve_shutoff
);
309 temp
&= ~FIFO_TX_STARVE_OFF_MASK
;
311 gfar_write(®s
->fifo_tx_starve_shutoff
, temp
);
314 local_irq_restore(flags
);
319 static DEVICE_ATTR(fifo_starve_off
, 0644, gfar_show_fifo_starve_off
,
320 gfar_set_fifo_starve_off
);
322 void gfar_init_sysfs(struct net_device
*dev
)
324 struct gfar_private
*priv
= netdev_priv(dev
);
327 /* Initialize the default values */
328 priv
->fifo_threshold
= DEFAULT_FIFO_TX_THR
;
329 priv
->fifo_starve
= DEFAULT_FIFO_TX_STARVE
;
330 priv
->fifo_starve_off
= DEFAULT_FIFO_TX_STARVE_OFF
;
332 /* Create our sysfs files */
333 rc
= device_create_file(&dev
->dev
, &dev_attr_bd_stash
);
334 rc
|= device_create_file(&dev
->dev
, &dev_attr_rx_stash_size
);
335 rc
|= device_create_file(&dev
->dev
, &dev_attr_rx_stash_index
);
336 rc
|= device_create_file(&dev
->dev
, &dev_attr_fifo_threshold
);
337 rc
|= device_create_file(&dev
->dev
, &dev_attr_fifo_starve
);
338 rc
|= device_create_file(&dev
->dev
, &dev_attr_fifo_starve_off
);
340 dev_err(&dev
->dev
, "Error creating gianfar sysfs files.\n");