blob: 230878b9419053ee65621528d7710e3f74677f94 [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>
36#include <linux/version.h>
37
38#include "gianfar.h"
39
Kumar Gala4409d282007-02-12 23:40:06 -060040static ssize_t gfar_show_bd_stash(struct device *dev,
41 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -060042{
Kumar Gala4409d282007-02-12 23:40:06 -060043 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060044
Kumar Gala4409d282007-02-12 23:40:06 -060045 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
Andy Fleming7f7f5312005-11-11 12:38:59 -060046}
47
Kumar Gala4409d282007-02-12 23:40:06 -060048static ssize_t gfar_set_bd_stash(struct device *dev,
49 struct device_attribute *attr,
50 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -060051{
Kumar Gala4409d282007-02-12 23:40:06 -060052 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060053 int new_setting = 0;
54 u32 temp;
55 unsigned long flags;
56
57 /* Find out the new setting */
Kumar Gala4409d282007-02-12 23:40:06 -060058 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060059 new_setting = 1;
Kumar Gala4409d282007-02-12 23:40:06 -060060 else if (!strncmp("off", buf, count - 1)
61 || !strncmp("0", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060062 new_setting = 0;
63 else
64 return count;
65
Andy Flemingfef61082006-04-20 16:44:29 -050066 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060067
68 /* Set the new stashing value */
69 priv->bd_stash_en = new_setting;
70
71 temp = gfar_read(&priv->regs->attr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040072
Andy Fleming7f7f5312005-11-11 12:38:59 -060073 if (new_setting)
74 temp |= ATTR_BDSTASH;
75 else
76 temp &= ~(ATTR_BDSTASH);
77
78 gfar_write(&priv->regs->attr, temp);
79
Andy Flemingfef61082006-04-20 16:44:29 -050080 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060081
82 return count;
83}
84
Grant Likely35a84fd2007-12-01 22:12:45 -070085DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
86
Kumar Gala4409d282007-02-12 23:40:06 -060087static ssize_t gfar_show_rx_stash_size(struct device *dev,
88 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -060089{
Kumar Gala4409d282007-02-12 23:40:06 -060090 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060091
92 return sprintf(buf, "%d\n", priv->rx_stash_size);
93}
94
Kumar Gala4409d282007-02-12 23:40:06 -060095static ssize_t gfar_set_rx_stash_size(struct device *dev,
96 struct device_attribute *attr,
97 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -060098{
Kumar Gala4409d282007-02-12 23:40:06 -060099 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600100 unsigned int length = simple_strtoul(buf, NULL, 0);
101 u32 temp;
102 unsigned long flags;
103
Andy Flemingfef61082006-04-20 16:44:29 -0500104 spin_lock_irqsave(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600105 if (length > priv->rx_buffer_size)
106 return count;
107
108 if (length == priv->rx_stash_size)
109 return count;
110
111 priv->rx_stash_size = length;
112
113 temp = gfar_read(&priv->regs->attreli);
114 temp &= ~ATTRELI_EL_MASK;
115 temp |= ATTRELI_EL(length);
116 gfar_write(&priv->regs->attreli, temp);
117
118 /* Turn stashing on/off as appropriate */
119 temp = gfar_read(&priv->regs->attr);
120
121 if (length)
122 temp |= ATTR_BUFSTASH;
123 else
124 temp &= ~(ATTR_BUFSTASH);
125
126 gfar_write(&priv->regs->attr, temp);
127
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
Grant Likely35a84fd2007-12-01 22:12:45 -0700133DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
134 gfar_set_rx_stash_size);
135
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)
157 return count;
158
159 if (index == priv->rx_stash_index)
160 return count;
161
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 Flemingfef61082006-04-20 16:44:29 -0500169 spin_unlock_irqrestore(&priv->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600170
171 return count;
172}
173
Grant Likely35a84fd2007-12-01 22:12:45 -0700174DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
175 gfar_set_rx_stash_index);
176
Kumar Gala4409d282007-02-12 23:40:06 -0600177static ssize_t gfar_show_fifo_threshold(struct device *dev,
178 struct device_attribute *attr,
179 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600180{
Kumar Gala4409d282007-02-12 23:40:06 -0600181 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600182
183 return sprintf(buf, "%d\n", priv->fifo_threshold);
184}
185
Kumar Gala4409d282007-02-12 23:40:06 -0600186static ssize_t gfar_set_fifo_threshold(struct device *dev,
187 struct device_attribute *attr,
188 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600189{
Kumar Gala4409d282007-02-12 23:40:06 -0600190 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600191 unsigned int length = simple_strtoul(buf, NULL, 0);
192 u32 temp;
193 unsigned long flags;
194
195 if (length > GFAR_MAX_FIFO_THRESHOLD)
196 return count;
197
Andy Flemingfef61082006-04-20 16:44:29 -0500198 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600199
200 priv->fifo_threshold = length;
201
202 temp = gfar_read(&priv->regs->fifo_tx_thr);
203 temp &= ~FIFO_TX_THR_MASK;
204 temp |= length;
205 gfar_write(&priv->regs->fifo_tx_thr, temp);
206
Andy Flemingfef61082006-04-20 16:44:29 -0500207 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600208
209 return count;
210}
211
Grant Likely35a84fd2007-12-01 22:12:45 -0700212DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
213 gfar_set_fifo_threshold);
214
Kumar Gala4409d282007-02-12 23:40:06 -0600215static ssize_t gfar_show_fifo_starve(struct device *dev,
216 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600217{
Kumar Gala4409d282007-02-12 23:40:06 -0600218 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600219
220 return sprintf(buf, "%d\n", priv->fifo_starve);
221}
222
Kumar Gala4409d282007-02-12 23:40:06 -0600223static ssize_t gfar_set_fifo_starve(struct device *dev,
224 struct device_attribute *attr,
225 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600226{
Kumar Gala4409d282007-02-12 23:40:06 -0600227 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600228 unsigned int num = simple_strtoul(buf, NULL, 0);
229 u32 temp;
230 unsigned long flags;
231
232 if (num > GFAR_MAX_FIFO_STARVE)
233 return count;
234
Andy Flemingfef61082006-04-20 16:44:29 -0500235 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600236
237 priv->fifo_starve = num;
238
239 temp = gfar_read(&priv->regs->fifo_tx_starve);
240 temp &= ~FIFO_TX_STARVE_MASK;
241 temp |= num;
242 gfar_write(&priv->regs->fifo_tx_starve, temp);
243
Andy Flemingfef61082006-04-20 16:44:29 -0500244 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600245
246 return count;
247}
248
Grant Likely35a84fd2007-12-01 22:12:45 -0700249DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve, gfar_set_fifo_starve);
250
Kumar Gala4409d282007-02-12 23:40:06 -0600251static ssize_t gfar_show_fifo_starve_off(struct device *dev,
252 struct device_attribute *attr,
253 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600254{
Kumar Gala4409d282007-02-12 23:40:06 -0600255 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600256
257 return sprintf(buf, "%d\n", priv->fifo_starve_off);
258}
259
Kumar Gala4409d282007-02-12 23:40:06 -0600260static ssize_t gfar_set_fifo_starve_off(struct device *dev,
261 struct device_attribute *attr,
262 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600263{
Kumar Gala4409d282007-02-12 23:40:06 -0600264 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600265 unsigned int num = simple_strtoul(buf, NULL, 0);
266 u32 temp;
267 unsigned long flags;
268
269 if (num > GFAR_MAX_FIFO_STARVE_OFF)
270 return count;
271
Andy Flemingfef61082006-04-20 16:44:29 -0500272 spin_lock_irqsave(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600273
274 priv->fifo_starve_off = num;
275
276 temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
277 temp &= ~FIFO_TX_STARVE_OFF_MASK;
278 temp |= num;
279 gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
280
Andy Flemingfef61082006-04-20 16:44:29 -0500281 spin_unlock_irqrestore(&priv->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600282
283 return count;
284}
285
Grant Likely35a84fd2007-12-01 22:12:45 -0700286DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
287 gfar_set_fifo_starve_off);
288
Andy Fleming7f7f5312005-11-11 12:38:59 -0600289void gfar_init_sysfs(struct net_device *dev)
290{
291 struct gfar_private *priv = netdev_priv(dev);
Grant Likely35a84fd2007-12-01 22:12:45 -0700292 int rc;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600293
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;
301
302 /* Create our sysfs files */
Grant Likely35a84fd2007-12-01 22:12:45 -0700303 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);
309 if (rc)
310 dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");
Andy Fleming7f7f5312005-11-11 12:38:59 -0600311}