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)
12 * Copyright (c) 2002-2005 Freescale Semiconductor, Inc.
14 * This program is free software; you can redistribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; either version 2 of the License, or (at your
17 * option) any later version.
19 * Sysfs file creation and management
22 #include <linux/kernel.h>
23 #include <linux/string.h>
24 #include <linux/errno.h>
25 #include <linux/unistd.h>
26 #include <linux/slab.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>
36 #include <linux/version.h>
40 static ssize_t gfar_show_bd_stash(struct device *dev,
41 struct device_attribute *attr, char *buf)
43 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
45 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
48 static ssize_t gfar_set_bd_stash(struct device *dev,
49 struct device_attribute *attr,
50 const char *buf, size_t count)
52 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
57 /* Find out the new setting */
58 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
60 else if (!strncmp("off", buf, count - 1)
61 || !strncmp("0", buf, count - 1))
66 spin_lock_irqsave(&priv->rxlock, flags);
68 /* Set the new stashing value */
69 priv->bd_stash_en = new_setting;
71 temp = gfar_read(&priv->regs->attr);
76 temp &= ~(ATTR_BDSTASH);
78 gfar_write(&priv->regs->attr, temp);
80 spin_unlock_irqrestore(&priv->rxlock, flags);
85 DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
87 static ssize_t gfar_show_rx_stash_size(struct device *dev,
88 struct device_attribute *attr, char *buf)
90 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
92 return sprintf(buf, "%d\n", priv->rx_stash_size);
95 static ssize_t gfar_set_rx_stash_size(struct device *dev,
96 struct device_attribute *attr,
97 const char *buf, size_t count)
99 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
100 unsigned int length = simple_strtoul(buf, NULL, 0);
104 spin_lock_irqsave(&priv->rxlock, flags);
105 if (length > priv->rx_buffer_size)
108 if (length == priv->rx_stash_size)
111 priv->rx_stash_size = length;
113 temp = gfar_read(&priv->regs->attreli);
114 temp &= ~ATTRELI_EL_MASK;
115 temp |= ATTRELI_EL(length);
116 gfar_write(&priv->regs->attreli, temp);
118 /* Turn stashing on/off as appropriate */
119 temp = gfar_read(&priv->regs->attr);
122 temp |= ATTR_BUFSTASH;
124 temp &= ~(ATTR_BUFSTASH);
126 gfar_write(&priv->regs->attr, temp);
128 spin_unlock_irqrestore(&priv->rxlock, flags);
133 DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
134 gfar_set_rx_stash_size);
136 /* Stashing will only be enabled when rx_stash_size != 0 */
137 static ssize_t gfar_show_rx_stash_index(struct device *dev,
138 struct device_attribute *attr,
141 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
143 return sprintf(buf, "%d\n", priv->rx_stash_index);
146 static ssize_t gfar_set_rx_stash_index(struct device *dev,
147 struct device_attribute *attr,
148 const char *buf, size_t count)
150 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
151 unsigned short index = simple_strtoul(buf, NULL, 0);
155 spin_lock_irqsave(&priv->rxlock, flags);
156 if (index > priv->rx_stash_size)
159 if (index == priv->rx_stash_index)
162 priv->rx_stash_index = index;
164 temp = gfar_read(&priv->regs->attreli);
165 temp &= ~ATTRELI_EI_MASK;
166 temp |= ATTRELI_EI(index);
167 gfar_write(&priv->regs->attreli, flags);
169 spin_unlock_irqrestore(&priv->rxlock, flags);
174 DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
175 gfar_set_rx_stash_index);
177 static ssize_t gfar_show_fifo_threshold(struct device *dev,
178 struct device_attribute *attr,
181 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
183 return sprintf(buf, "%d\n", priv->fifo_threshold);
186 static ssize_t gfar_set_fifo_threshold(struct device *dev,
187 struct device_attribute *attr,
188 const char *buf, size_t count)
190 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
191 unsigned int length = simple_strtoul(buf, NULL, 0);
195 if (length > GFAR_MAX_FIFO_THRESHOLD)
198 spin_lock_irqsave(&priv->txlock, flags);
200 priv->fifo_threshold = length;
202 temp = gfar_read(&priv->regs->fifo_tx_thr);
203 temp &= ~FIFO_TX_THR_MASK;
205 gfar_write(&priv->regs->fifo_tx_thr, temp);
207 spin_unlock_irqrestore(&priv->txlock, flags);
212 DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
213 gfar_set_fifo_threshold);
215 static ssize_t gfar_show_fifo_starve(struct device *dev,
216 struct device_attribute *attr, char *buf)
218 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
220 return sprintf(buf, "%d\n", priv->fifo_starve);
223 static ssize_t gfar_set_fifo_starve(struct device *dev,
224 struct device_attribute *attr,
225 const char *buf, size_t count)
227 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
228 unsigned int num = simple_strtoul(buf, NULL, 0);
232 if (num > GFAR_MAX_FIFO_STARVE)
235 spin_lock_irqsave(&priv->txlock, flags);
237 priv->fifo_starve = num;
239 temp = gfar_read(&priv->regs->fifo_tx_starve);
240 temp &= ~FIFO_TX_STARVE_MASK;
242 gfar_write(&priv->regs->fifo_tx_starve, temp);
244 spin_unlock_irqrestore(&priv->txlock, flags);
249 DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve, gfar_set_fifo_starve);
251 static ssize_t gfar_show_fifo_starve_off(struct device *dev,
252 struct device_attribute *attr,
255 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
257 return sprintf(buf, "%d\n", priv->fifo_starve_off);
260 static ssize_t gfar_set_fifo_starve_off(struct device *dev,
261 struct device_attribute *attr,
262 const char *buf, size_t count)
264 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
265 unsigned int num = simple_strtoul(buf, NULL, 0);
269 if (num > GFAR_MAX_FIFO_STARVE_OFF)
272 spin_lock_irqsave(&priv->txlock, flags);
274 priv->fifo_starve_off = num;
276 temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
277 temp &= ~FIFO_TX_STARVE_OFF_MASK;
279 gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
281 spin_unlock_irqrestore(&priv->txlock, flags);
286 DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
287 gfar_set_fifo_starve_off);
289 void gfar_init_sysfs(struct net_device *dev)
291 struct gfar_private *priv = netdev_priv(dev);
294 /* Initialize the default values */
295 priv->rx_stash_size = DEFAULT_STASH_LENGTH;
296 priv->rx_stash_index = DEFAULT_STASH_INDEX;
297 priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
298 priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
299 priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
300 priv->bd_stash_en = DEFAULT_BD_STASH;
302 /* Create our sysfs files */
303 rc = device_create_file(&dev->dev, &dev_attr_bd_stash);
304 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size);
305 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index);
306 rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold);
307 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve);
308 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off);
310 dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");