PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / net / ethernet / freescale / gianfar_sysfs.c
blobe02dd1378751ea2a97eeaf9c2d5abcc1938c072a
1 /*
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
9 * Author: Andy Fleming
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>
30 #include <linux/mm.h>
31 #include <linux/device.h>
33 #include <asm/uaccess.h>
34 #include <linux/module.h>
36 #include "gianfar.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;
52 int new_setting = 0;
53 u32 temp;
54 unsigned long flags;
56 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING))
57 return count;
60 /* Find out the new setting */
61 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
62 new_setting = 1;
63 else if (!strncmp("off", buf, count - 1) ||
64 !strncmp("0", buf, count - 1))
65 new_setting = 0;
66 else
67 return count;
70 local_irq_save(flags);
71 lock_rx_qs(priv);
73 /* Set the new stashing value */
74 priv->bd_stash_en = new_setting;
76 temp = gfar_read(&regs->attr);
78 if (new_setting)
79 temp |= ATTR_BDSTASH;
80 else
81 temp &= ~(ATTR_BDSTASH);
83 gfar_write(&regs->attr, temp);
85 unlock_rx_qs(priv);
86 local_irq_restore(flags);
88 return count;
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);
108 u32 temp;
109 unsigned long flags;
111 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
112 return count;
114 local_irq_save(flags);
115 lock_rx_qs(priv);
117 if (length > priv->rx_buffer_size)
118 goto out;
120 if (length == priv->rx_stash_size)
121 goto out;
123 priv->rx_stash_size = length;
125 temp = gfar_read(&regs->attreli);
126 temp &= ~ATTRELI_EL_MASK;
127 temp |= ATTRELI_EL(length);
128 gfar_write(&regs->attreli, temp);
130 /* Turn stashing on/off as appropriate */
131 temp = gfar_read(&regs->attr);
133 if (length)
134 temp |= ATTR_BUFSTASH;
135 else
136 temp &= ~(ATTR_BUFSTASH);
138 gfar_write(&regs->attr, temp);
140 out:
141 unlock_rx_qs(priv);
142 local_irq_restore(flags);
144 return count;
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,
153 char *buf)
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);
167 u32 temp;
168 unsigned long flags;
170 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
171 return count;
173 local_irq_save(flags);
174 lock_rx_qs(priv);
176 if (index > priv->rx_stash_size)
177 goto out;
179 if (index == priv->rx_stash_index)
180 goto out;
182 priv->rx_stash_index = index;
184 temp = gfar_read(&regs->attreli);
185 temp &= ~ATTRELI_EI_MASK;
186 temp |= ATTRELI_EI(index);
187 gfar_write(&regs->attreli, temp);
189 out:
190 unlock_rx_qs(priv);
191 local_irq_restore(flags);
193 return count;
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,
201 char *buf)
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);
215 u32 temp;
216 unsigned long flags;
218 if (length > GFAR_MAX_FIFO_THRESHOLD)
219 return count;
221 local_irq_save(flags);
222 lock_tx_qs(priv);
224 priv->fifo_threshold = length;
226 temp = gfar_read(&regs->fifo_tx_thr);
227 temp &= ~FIFO_TX_THR_MASK;
228 temp |= length;
229 gfar_write(&regs->fifo_tx_thr, temp);
231 unlock_tx_qs(priv);
232 local_irq_restore(flags);
234 return count;
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);
255 u32 temp;
256 unsigned long flags;
258 if (num > GFAR_MAX_FIFO_STARVE)
259 return count;
261 local_irq_save(flags);
262 lock_tx_qs(priv);
264 priv->fifo_starve = num;
266 temp = gfar_read(&regs->fifo_tx_starve);
267 temp &= ~FIFO_TX_STARVE_MASK;
268 temp |= num;
269 gfar_write(&regs->fifo_tx_starve, temp);
271 unlock_tx_qs(priv);
272 local_irq_restore(flags);
274 return count;
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,
282 char *buf)
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);
296 u32 temp;
297 unsigned long flags;
299 if (num > GFAR_MAX_FIFO_STARVE_OFF)
300 return count;
302 local_irq_save(flags);
303 lock_tx_qs(priv);
305 priv->fifo_starve_off = num;
307 temp = gfar_read(&regs->fifo_tx_starve_shutoff);
308 temp &= ~FIFO_TX_STARVE_OFF_MASK;
309 temp |= num;
310 gfar_write(&regs->fifo_tx_starve_shutoff, temp);
312 unlock_tx_qs(priv);
313 local_irq_restore(flags);
315 return count;
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);
324 int rc;
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);
338 if (rc)
339 dev_err(&dev->dev, "Error creating gianfar sysfs files\n");