at86rf230: mask irq's before deregister device
[deliverable/linux.git] / drivers / net / ethernet / freescale / gianfar_sysfs.c
CommitLineData
7f7f5316 1/*
3396c782 2 * drivers/net/ethernet/freescale/gianfar_sysfs.c
7f7f5316
AF
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
b56d55b6 10 * Maintainer: Kumar Gala (galak@kernel.crashing.org)
a12f801d 11 * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
7f7f5316 12 *
a12f801d 13 * Copyright 2002-2009 Freescale Semiconductor, Inc.
7f7f5316
AF
14 *
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.
19 *
20 * Sysfs file creation and management
21 */
22
7f7f5316 23#include <linux/kernel.h>
7f7f5316
AF
24#include <linux/string.h>
25#include <linux/errno.h>
26#include <linux/unistd.h>
7f7f5316
AF
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>
32
33#include <asm/uaccess.h>
34#include <linux/module.h>
7f7f5316
AF
35
36#include "gianfar.h"
37
4409d281
KG
38static ssize_t gfar_show_bd_stash(struct device *dev,
39 struct device_attribute *attr, char *buf)
7f7f5316 40{
4409d281 41 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316 42
4409d281 43 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
7f7f5316
AF
44}
45
4409d281
KG
46static ssize_t gfar_set_bd_stash(struct device *dev,
47 struct device_attribute *attr,
48 const char *buf, size_t count)
7f7f5316 49{
4409d281 50 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
46ceb60c 51 struct gfar __iomem *regs = priv->gfargrp[0].regs;
7f7f5316
AF
52 int new_setting = 0;
53 u32 temp;
54 unsigned long flags;
55
4d7902f2
AF
56 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING))
57 return count;
58
a12f801d 59
7f7f5316 60 /* Find out the new setting */
4409d281 61 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
7f7f5316 62 new_setting = 1;
8e95a202
JP
63 else if (!strncmp("off", buf, count - 1) ||
64 !strncmp("0", buf, count - 1))
7f7f5316
AF
65 new_setting = 0;
66 else
67 return count;
68
fba4ed03
SG
69
70 local_irq_save(flags);
71 lock_rx_qs(priv);
7f7f5316
AF
72
73 /* Set the new stashing value */
74 priv->bd_stash_en = new_setting;
75
f4983704 76 temp = gfar_read(&regs->attr);
6aa20a22 77
7f7f5316
AF
78 if (new_setting)
79 temp |= ATTR_BDSTASH;
80 else
81 temp &= ~(ATTR_BDSTASH);
82
f4983704 83 gfar_write(&regs->attr, temp);
7f7f5316 84
fba4ed03
SG
85 unlock_rx_qs(priv);
86 local_irq_restore(flags);
7f7f5316
AF
87
88 return count;
89}
90
b2f66d18 91static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
35a84fdc 92
4409d281
KG
93static ssize_t gfar_show_rx_stash_size(struct device *dev,
94 struct device_attribute *attr, char *buf)
7f7f5316 95{
4409d281 96 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
97
98 return sprintf(buf, "%d\n", priv->rx_stash_size);
99}
100
4409d281
KG
101static ssize_t gfar_set_rx_stash_size(struct device *dev,
102 struct device_attribute *attr,
103 const char *buf, size_t count)
7f7f5316 104{
4409d281 105 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
46ceb60c 106 struct gfar __iomem *regs = priv->gfargrp[0].regs;
7f7f5316
AF
107 unsigned int length = simple_strtoul(buf, NULL, 0);
108 u32 temp;
109 unsigned long flags;
110
4d7902f2
AF
111 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
112 return count;
113
fba4ed03
SG
114 local_irq_save(flags);
115 lock_rx_qs(priv);
a12f801d 116
7f7f5316 117 if (length > priv->rx_buffer_size)
f162b9d5 118 goto out;
7f7f5316
AF
119
120 if (length == priv->rx_stash_size)
f162b9d5 121 goto out;
7f7f5316
AF
122
123 priv->rx_stash_size = length;
124
f4983704 125 temp = gfar_read(&regs->attreli);
7f7f5316
AF
126 temp &= ~ATTRELI_EL_MASK;
127 temp |= ATTRELI_EL(length);
f4983704 128 gfar_write(&regs->attreli, temp);
7f7f5316
AF
129
130 /* Turn stashing on/off as appropriate */
f4983704 131 temp = gfar_read(&regs->attr);
7f7f5316
AF
132
133 if (length)
134 temp |= ATTR_BUFSTASH;
135 else
136 temp &= ~(ATTR_BUFSTASH);
137
f4983704 138 gfar_write(&regs->attr, temp);
7f7f5316 139
f162b9d5 140out:
fba4ed03
SG
141 unlock_rx_qs(priv);
142 local_irq_restore(flags);
7f7f5316
AF
143
144 return count;
145}
146
b2f66d18
AV
147static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
148 gfar_set_rx_stash_size);
35a84fdc 149
7f7f5316 150/* Stashing will only be enabled when rx_stash_size != 0 */
4409d281
KG
151static ssize_t gfar_show_rx_stash_index(struct device *dev,
152 struct device_attribute *attr,
153 char *buf)
7f7f5316 154{
4409d281 155 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
156
157 return sprintf(buf, "%d\n", priv->rx_stash_index);
158}
159
4409d281
KG
160static ssize_t gfar_set_rx_stash_index(struct device *dev,
161 struct device_attribute *attr,
162 const char *buf, size_t count)
7f7f5316 163{
4409d281 164 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
46ceb60c 165 struct gfar __iomem *regs = priv->gfargrp[0].regs;
7f7f5316
AF
166 unsigned short index = simple_strtoul(buf, NULL, 0);
167 u32 temp;
168 unsigned long flags;
169
4d7902f2
AF
170 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
171 return count;
172
fba4ed03
SG
173 local_irq_save(flags);
174 lock_rx_qs(priv);
a12f801d 175
7f7f5316 176 if (index > priv->rx_stash_size)
f162b9d5 177 goto out;
7f7f5316
AF
178
179 if (index == priv->rx_stash_index)
f162b9d5 180 goto out;
7f7f5316
AF
181
182 priv->rx_stash_index = index;
183
f4983704 184 temp = gfar_read(&regs->attreli);
7f7f5316
AF
185 temp &= ~ATTRELI_EI_MASK;
186 temp |= ATTRELI_EI(index);
499428ed 187 gfar_write(&regs->attreli, temp);
7f7f5316 188
f162b9d5 189out:
fba4ed03
SG
190 unlock_rx_qs(priv);
191 local_irq_restore(flags);
7f7f5316
AF
192
193 return count;
194}
195
b2f66d18
AV
196static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
197 gfar_set_rx_stash_index);
35a84fdc 198
4409d281
KG
199static ssize_t gfar_show_fifo_threshold(struct device *dev,
200 struct device_attribute *attr,
201 char *buf)
7f7f5316 202{
4409d281 203 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
204
205 return sprintf(buf, "%d\n", priv->fifo_threshold);
206}
207
4409d281
KG
208static ssize_t gfar_set_fifo_threshold(struct device *dev,
209 struct device_attribute *attr,
210 const char *buf, size_t count)
7f7f5316 211{
4409d281 212 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
46ceb60c 213 struct gfar __iomem *regs = priv->gfargrp[0].regs;
7f7f5316
AF
214 unsigned int length = simple_strtoul(buf, NULL, 0);
215 u32 temp;
216 unsigned long flags;
217
218 if (length > GFAR_MAX_FIFO_THRESHOLD)
219 return count;
220
fba4ed03
SG
221 local_irq_save(flags);
222 lock_tx_qs(priv);
7f7f5316
AF
223
224 priv->fifo_threshold = length;
225
f4983704 226 temp = gfar_read(&regs->fifo_tx_thr);
7f7f5316
AF
227 temp &= ~FIFO_TX_THR_MASK;
228 temp |= length;
f4983704 229 gfar_write(&regs->fifo_tx_thr, temp);
7f7f5316 230
fba4ed03
SG
231 unlock_tx_qs(priv);
232 local_irq_restore(flags);
7f7f5316
AF
233
234 return count;
235}
236
b2f66d18
AV
237static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
238 gfar_set_fifo_threshold);
35a84fdc 239
4409d281
KG
240static ssize_t gfar_show_fifo_starve(struct device *dev,
241 struct device_attribute *attr, char *buf)
7f7f5316 242{
4409d281 243 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
244
245 return sprintf(buf, "%d\n", priv->fifo_starve);
246}
247
4409d281
KG
248static ssize_t gfar_set_fifo_starve(struct device *dev,
249 struct device_attribute *attr,
250 const char *buf, size_t count)
7f7f5316 251{
4409d281 252 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
46ceb60c 253 struct gfar __iomem *regs = priv->gfargrp[0].regs;
7f7f5316
AF
254 unsigned int num = simple_strtoul(buf, NULL, 0);
255 u32 temp;
256 unsigned long flags;
257
258 if (num > GFAR_MAX_FIFO_STARVE)
259 return count;
260
fba4ed03
SG
261 local_irq_save(flags);
262 lock_tx_qs(priv);
7f7f5316
AF
263
264 priv->fifo_starve = num;
265
f4983704 266 temp = gfar_read(&regs->fifo_tx_starve);
7f7f5316
AF
267 temp &= ~FIFO_TX_STARVE_MASK;
268 temp |= num;
f4983704 269 gfar_write(&regs->fifo_tx_starve, temp);
7f7f5316 270
fba4ed03
SG
271 unlock_tx_qs(priv);
272 local_irq_restore(flags);
7f7f5316
AF
273
274 return count;
275}
276
b2f66d18
AV
277static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
278 gfar_set_fifo_starve);
35a84fdc 279
4409d281
KG
280static ssize_t gfar_show_fifo_starve_off(struct device *dev,
281 struct device_attribute *attr,
282 char *buf)
7f7f5316 283{
4409d281 284 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
7f7f5316
AF
285
286 return sprintf(buf, "%d\n", priv->fifo_starve_off);
287}
288
4409d281
KG
289static ssize_t gfar_set_fifo_starve_off(struct device *dev,
290 struct device_attribute *attr,
291 const char *buf, size_t count)
7f7f5316 292{
4409d281 293 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
46ceb60c 294 struct gfar __iomem *regs = priv->gfargrp[0].regs;
7f7f5316
AF
295 unsigned int num = simple_strtoul(buf, NULL, 0);
296 u32 temp;
297 unsigned long flags;
298
299 if (num > GFAR_MAX_FIFO_STARVE_OFF)
300 return count;
301
fba4ed03
SG
302 local_irq_save(flags);
303 lock_tx_qs(priv);
7f7f5316
AF
304
305 priv->fifo_starve_off = num;
306
f4983704 307 temp = gfar_read(&regs->fifo_tx_starve_shutoff);
7f7f5316
AF
308 temp &= ~FIFO_TX_STARVE_OFF_MASK;
309 temp |= num;
f4983704 310 gfar_write(&regs->fifo_tx_starve_shutoff, temp);
7f7f5316 311
fba4ed03
SG
312 unlock_tx_qs(priv);
313 local_irq_restore(flags);
7f7f5316
AF
314
315 return count;
316}
317
b2f66d18
AV
318static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
319 gfar_set_fifo_starve_off);
35a84fdc 320
7f7f5316
AF
321void gfar_init_sysfs(struct net_device *dev)
322{
323 struct gfar_private *priv = netdev_priv(dev);
35a84fdc 324 int rc;
7f7f5316
AF
325
326 /* Initialize the default values */
7f7f5316
AF
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;
7f7f5316
AF
330
331 /* Create our sysfs files */
35a84fdc
GL
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)
375d6a1b 339 dev_err(&dev->dev, "Error creating gianfar sysfs files\n");
7f7f5316 340}
This page took 0.88604 seconds and 5 git commands to generate.