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/slab.h>
28 #include <linux/init.h>
29 #include <linux/delay.h>
30 #include <linux/etherdevice.h>
31 #include <linux/spinlock.h>
33 #include <linux/device.h>
35 #include <asm/uaccess.h>
36 #include <linux/module.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));
53 struct gfar __iomem *regs = priv->gfargrp.regs;
54 struct gfar_priv_rx_q *rx_queue = NULL;
59 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING))
62 rx_queue = priv->rx_queue;
64 /* Find out the new setting */
65 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
67 else if (!strncmp("off", buf, count - 1)
68 || !strncmp("0", buf, count - 1))
73 spin_lock_irqsave(&rx_queue->rxlock, flags);
75 /* Set the new stashing value */
76 priv->bd_stash_en = new_setting;
78 temp = gfar_read(®s->attr);
83 temp &= ~(ATTR_BDSTASH);
85 gfar_write(®s->attr, temp);
87 spin_unlock_irqrestore(&rx_queue->rxlock, 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.regs;
108 struct gfar_priv_rx_q *rx_queue = NULL;
109 unsigned int length = simple_strtoul(buf, NULL, 0);
113 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
116 rx_queue = priv->rx_queue;
118 spin_lock_irqsave(&rx_queue->rxlock, flags);
119 if (length > priv->rx_buffer_size)
122 if (length == priv->rx_stash_size)
125 priv->rx_stash_size = length;
127 temp = gfar_read(®s->attreli);
128 temp &= ~ATTRELI_EL_MASK;
129 temp |= ATTRELI_EL(length);
130 gfar_write(®s->attreli, temp);
132 /* Turn stashing on/off as appropriate */
133 temp = gfar_read(®s->attr);
136 temp |= ATTR_BUFSTASH;
138 temp &= ~(ATTR_BUFSTASH);
140 gfar_write(®s->attr, temp);
143 spin_unlock_irqrestore(&rx_queue->rxlock, 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.regs;
167 struct gfar_priv_rx_q *rx_queue = NULL;
168 unsigned short index = simple_strtoul(buf, NULL, 0);
172 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
175 rx_queue = priv->rx_queue;
177 spin_lock_irqsave(&rx_queue->rxlock, flags);
178 if (index > priv->rx_stash_size)
181 if (index == priv->rx_stash_index)
184 priv->rx_stash_index = index;
186 temp = gfar_read(®s->attreli);
187 temp &= ~ATTRELI_EI_MASK;
188 temp |= ATTRELI_EI(index);
189 gfar_write(®s->attreli, flags);
192 spin_unlock_irqrestore(&rx_queue->rxlock, 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.regs;
215 struct gfar_priv_tx_q *tx_queue = NULL;
216 unsigned int length = simple_strtoul(buf, NULL, 0);
220 if (length > GFAR_MAX_FIFO_THRESHOLD)
223 tx_queue = priv->tx_queue;
225 spin_lock_irqsave(&tx_queue->txlock, flags);
227 priv->fifo_threshold = length;
229 temp = gfar_read(®s->fifo_tx_thr);
230 temp &= ~FIFO_TX_THR_MASK;
232 gfar_write(®s->fifo_tx_thr, temp);
234 spin_unlock_irqrestore(&tx_queue->txlock, flags);
239 static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
240 gfar_set_fifo_threshold);
242 static ssize_t gfar_show_fifo_starve(struct device *dev,
243 struct device_attribute *attr, char *buf)
245 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
247 return sprintf(buf, "%d\n", priv->fifo_starve);
250 static ssize_t gfar_set_fifo_starve(struct device *dev,
251 struct device_attribute *attr,
252 const char *buf, size_t count)
254 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
255 struct gfar __iomem *regs = priv->gfargrp.regs;
256 struct gfar_priv_tx_q *tx_queue = NULL;
257 unsigned int num = simple_strtoul(buf, NULL, 0);
261 if (num > GFAR_MAX_FIFO_STARVE)
264 tx_queue = priv->tx_queue;
265 spin_lock_irqsave(&tx_queue->txlock, flags);
267 priv->fifo_starve = num;
269 temp = gfar_read(®s->fifo_tx_starve);
270 temp &= ~FIFO_TX_STARVE_MASK;
272 gfar_write(®s->fifo_tx_starve, temp);
274 spin_unlock_irqrestore(&tx_queue->txlock, flags);
279 static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
280 gfar_set_fifo_starve);
282 static ssize_t gfar_show_fifo_starve_off(struct device *dev,
283 struct device_attribute *attr,
286 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
288 return sprintf(buf, "%d\n", priv->fifo_starve_off);
291 static ssize_t gfar_set_fifo_starve_off(struct device *dev,
292 struct device_attribute *attr,
293 const char *buf, size_t count)
295 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
296 struct gfar __iomem *regs = priv->gfargrp.regs;
297 struct gfar_priv_tx_q *tx_queue = NULL;
298 unsigned int num = simple_strtoul(buf, NULL, 0);
302 if (num > GFAR_MAX_FIFO_STARVE_OFF)
305 tx_queue = priv->tx_queue;
306 spin_lock_irqsave(&tx_queue->txlock, flags);
308 priv->fifo_starve_off = num;
310 temp = gfar_read(®s->fifo_tx_starve_shutoff);
311 temp &= ~FIFO_TX_STARVE_OFF_MASK;
313 gfar_write(®s->fifo_tx_starve_shutoff, temp);
315 spin_unlock_irqrestore(&tx_queue->txlock, flags);
320 static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
321 gfar_set_fifo_starve_off);
323 void gfar_init_sysfs(struct net_device *dev)
325 struct gfar_private *priv = netdev_priv(dev);
328 /* Initialize the default values */
329 priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
330 priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
331 priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
333 /* Create our sysfs files */
334 rc = device_create_file(&dev->dev, &dev_attr_bd_stash);
335 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size);
336 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index);
337 rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold);
338 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve);
339 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off);
341 dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");