blob: 74e0b4d42587ae5dd112cb47124d0789e45c63ae [file] [log] [blame]
Andy Fleming7f7f5312005-11-11 12:38:59 -06001/*
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
Adrian Bunkb56d55b2006-01-11 02:00:10 +010010 * Maintainer: Kumar Gala (galak@kernel.crashing.org)
Andy Fleming7f7f5312005-11-11 12:38:59 -060011 *
12 * Copyright (c) 2002-2005 Freescale Semiconductor, Inc.
13 *
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.
18 *
19 * Sysfs file creation and management
20 */
21
Andy Fleming7f7f5312005-11-11 12:38:59 -060022#include <linux/kernel.h>
Andy Fleming7f7f5312005-11-11 12:38:59 -060023#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>
31#include <linux/mm.h>
32#include <linux/device.h>
33
34#include <asm/uaccess.h>
35#include <linux/module.h>
Andy Fleming7f7f5312005-11-11 12:38:59 -060036
37#include "gianfar.h"
38
Kumar Gala4409d282007-02-12 23:40:06 -060039static ssize_t gfar_show_bd_stash(struct device *dev,
40 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -060041{
Kumar Gala4409d282007-02-12 23:40:06 -060042 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060043
Kumar Gala4409d282007-02-12 23:40:06 -060044 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
Andy Fleming7f7f5312005-11-11 12:38:59 -060045}
46
Kumar Gala4409d282007-02-12 23:40:06 -060047static ssize_t gfar_set_bd_stash(struct device *dev,
48 struct device_attribute *attr,
49 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -060050{
Kumar Gala4409d282007-02-12 23:40:06 -060051 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060052 int new_setting = 0;
53 u32 temp;
54 unsigned long flags;
55
56 /* Find out the new setting */
Kumar Gala4409d282007-02-12 23:40:06 -060057 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060058 new_setting = 1;
Kumar Gala4409d282007-02-12 23:40:06 -060059 else if (!strncmp("off", buf, count - 1)
60 || !strncmp("0", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060061 new_setting = 0;
62 else
63 return count;
64
Andy Flemingfef61082006-04-20 16:44:29 -050065 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060066
67 /* Set the new stashing value */
68 priv->bd_stash_en = new_setting;
69
70 temp = gfar_read(&priv->regs->attr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040071
Andy Fleming7f7f5312005-11-11 12:38:59 -060072 if (new_setting)
73 temp |= ATTR_BDSTASH;
74 else
75 temp &= ~(ATTR_BDSTASH);
76
77 gfar_write(&priv->regs->attr, temp);
78
Andy Flemingfef61082006-04-20 16:44:29 -050079 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060080
81 return count;
82}
83
Anton Vorontsovb2f66d12009-02-01 00:54:16 -080084static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
Grant Likely35a84fd2007-12-01 22:12:45 -070085
Kumar Gala4409d282007-02-12 23:40:06 -060086static ssize_t gfar_show_rx_stash_size(struct device *dev,
87 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -060088{
Kumar Gala4409d282007-02-12 23:40:06 -060089 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060090
91 return sprintf(buf, "%d\n", priv->rx_stash_size);
92}
93
Kumar Gala4409d282007-02-12 23:40:06 -060094static ssize_t gfar_set_rx_stash_size(struct device *dev,
95 struct device_attribute *attr,
96 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -060097{
Kumar Gala4409d282007-02-12 23:40:06 -060098 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060099 unsigned int length = simple_strtoul(buf, NULL, 0);
100 u32 temp;
101 unsigned long flags;
102
Andy Flemingfef61082006-04-20 16:44:29 -0500103 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600104 if (length > priv->rx_buffer_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500105 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600106
107 if (length == priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500108 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600109
110 priv->rx_stash_size = length;
111
112 temp = gfar_read(&priv->regs->attreli);
113 temp &= ~ATTRELI_EL_MASK;
114 temp |= ATTRELI_EL(length);
115 gfar_write(&priv->regs->attreli, temp);
116
117 /* Turn stashing on/off as appropriate */
118 temp = gfar_read(&priv->regs->attr);
119
120 if (length)
121 temp |= ATTR_BUFSTASH;
122 else
123 temp &= ~(ATTR_BUFSTASH);
124
125 gfar_write(&priv->regs->attr, temp);
126
Andy Flemingf162b9d2008-05-02 13:00:30 -0500127out:
Andy Flemingfef61082006-04-20 16:44:29 -0500128 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600129
130 return count;
131}
132
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800133static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
134 gfar_set_rx_stash_size);
Grant Likely35a84fd2007-12-01 22:12:45 -0700135
Andy Fleming7f7f5312005-11-11 12:38:59 -0600136/* Stashing will only be enabled when rx_stash_size != 0 */
Kumar Gala4409d282007-02-12 23:40:06 -0600137static ssize_t gfar_show_rx_stash_index(struct device *dev,
138 struct device_attribute *attr,
139 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600140{
Kumar Gala4409d282007-02-12 23:40:06 -0600141 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600142
143 return sprintf(buf, "%d\n", priv->rx_stash_index);
144}
145
Kumar Gala4409d282007-02-12 23:40:06 -0600146static ssize_t gfar_set_rx_stash_index(struct device *dev,
147 struct device_attribute *attr,
148 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600149{
Kumar Gala4409d282007-02-12 23:40:06 -0600150 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600151 unsigned short index = simple_strtoul(buf, NULL, 0);
152 u32 temp;
153 unsigned long flags;
154
Andy Flemingfef61082006-04-20 16:44:29 -0500155 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600156 if (index > priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500157 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600158
159 if (index == priv->rx_stash_index)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500160 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600161
162 priv->rx_stash_index = index;
163
164 temp = gfar_read(&priv->regs->attreli);
165 temp &= ~ATTRELI_EI_MASK;
166 temp |= ATTRELI_EI(index);
167 gfar_write(&priv->regs->attreli, flags);
168
Andy Flemingf162b9d2008-05-02 13:00:30 -0500169out:
Andy Flemingfef61082006-04-20 16:44:29 -0500170 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600171
172 return count;
173}
174
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800175static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
176 gfar_set_rx_stash_index);
Grant Likely35a84fd2007-12-01 22:12:45 -0700177
Kumar Gala4409d282007-02-12 23:40:06 -0600178static ssize_t gfar_show_fifo_threshold(struct device *dev,
179 struct device_attribute *attr,
180 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600181{
Kumar Gala4409d282007-02-12 23:40:06 -0600182 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600183
184 return sprintf(buf, "%d\n", priv->fifo_threshold);
185}
186
Kumar Gala4409d282007-02-12 23:40:06 -0600187static ssize_t gfar_set_fifo_threshold(struct device *dev,
188 struct device_attribute *attr,
189 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600190{
Kumar Gala4409d282007-02-12 23:40:06 -0600191 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600192 unsigned int length = simple_strtoul(buf, NULL, 0);
193 u32 temp;
194 unsigned long flags;
195
196 if (length > GFAR_MAX_FIFO_THRESHOLD)
197 return count;
198
Andy Flemingfef61082006-04-20 16:44:29 -0500199 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600200
201 priv->fifo_threshold = length;
202
203 temp = gfar_read(&priv->regs->fifo_tx_thr);
204 temp &= ~FIFO_TX_THR_MASK;
205 temp |= length;
206 gfar_write(&priv->regs->fifo_tx_thr, temp);
207
Andy Flemingfef61082006-04-20 16:44:29 -0500208 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600209
210 return count;
211}
212
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800213static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
214 gfar_set_fifo_threshold);
Grant Likely35a84fd2007-12-01 22:12:45 -0700215
Kumar Gala4409d282007-02-12 23:40:06 -0600216static ssize_t gfar_show_fifo_starve(struct device *dev,
217 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600218{
Kumar Gala4409d282007-02-12 23:40:06 -0600219 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600220
221 return sprintf(buf, "%d\n", priv->fifo_starve);
222}
223
Kumar Gala4409d282007-02-12 23:40:06 -0600224static ssize_t gfar_set_fifo_starve(struct device *dev,
225 struct device_attribute *attr,
226 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600227{
Kumar Gala4409d282007-02-12 23:40:06 -0600228 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600229 unsigned int num = simple_strtoul(buf, NULL, 0);
230 u32 temp;
231 unsigned long flags;
232
233 if (num > GFAR_MAX_FIFO_STARVE)
234 return count;
235
Andy Flemingfef61082006-04-20 16:44:29 -0500236 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600237
238 priv->fifo_starve = num;
239
240 temp = gfar_read(&priv->regs->fifo_tx_starve);
241 temp &= ~FIFO_TX_STARVE_MASK;
242 temp |= num;
243 gfar_write(&priv->regs->fifo_tx_starve, temp);
244
Andy Flemingfef61082006-04-20 16:44:29 -0500245 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600246
247 return count;
248}
249
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800250static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
251 gfar_set_fifo_starve);
Grant Likely35a84fd2007-12-01 22:12:45 -0700252
Kumar Gala4409d282007-02-12 23:40:06 -0600253static ssize_t gfar_show_fifo_starve_off(struct device *dev,
254 struct device_attribute *attr,
255 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600256{
Kumar Gala4409d282007-02-12 23:40:06 -0600257 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600258
259 return sprintf(buf, "%d\n", priv->fifo_starve_off);
260}
261
Kumar Gala4409d282007-02-12 23:40:06 -0600262static ssize_t gfar_set_fifo_starve_off(struct device *dev,
263 struct device_attribute *attr,
264 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600265{
Kumar Gala4409d282007-02-12 23:40:06 -0600266 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600267 unsigned int num = simple_strtoul(buf, NULL, 0);
268 u32 temp;
269 unsigned long flags;
270
271 if (num > GFAR_MAX_FIFO_STARVE_OFF)
272 return count;
273
Andy Flemingfef61082006-04-20 16:44:29 -0500274 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600275
276 priv->fifo_starve_off = num;
277
278 temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
279 temp &= ~FIFO_TX_STARVE_OFF_MASK;
280 temp |= num;
281 gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
282
Andy Flemingfef61082006-04-20 16:44:29 -0500283 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600284
285 return count;
286}
287
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800288static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
289 gfar_set_fifo_starve_off);
Grant Likely35a84fd2007-12-01 22:12:45 -0700290
Andy Fleming7f7f5312005-11-11 12:38:59 -0600291void gfar_init_sysfs(struct net_device *dev)
292{
293 struct gfar_private *priv = netdev_priv(dev);
Grant Likely35a84fd2007-12-01 22:12:45 -0700294 int rc;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600295
296 /* Initialize the default values */
297 priv->rx_stash_size = DEFAULT_STASH_LENGTH;
298 priv->rx_stash_index = DEFAULT_STASH_INDEX;
299 priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
300 priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
301 priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
302 priv->bd_stash_en = DEFAULT_BD_STASH;
303
304 /* Create our sysfs files */
Grant Likely35a84fd2007-12-01 22:12:45 -0700305 rc = device_create_file(&dev->dev, &dev_attr_bd_stash);
306 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size);
307 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index);
308 rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold);
309 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve);
310 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off);
311 if (rc)
312 dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");
Andy Fleming7f7f5312005-11-11 12:38:59 -0600313}