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