blob: 64f4094ac7f16f63ca2227d966e5d59b5d689325 [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)
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000011 * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
Andy Fleming7f7f5312005-11-11 12:38:59 -060012 *
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000013 * Copyright 2002-2009 Freescale Semiconductor, Inc.
Andy Fleming7f7f5312005-11-11 12:38:59 -060014 *
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
Andy Fleming7f7f5312005-11-11 12:38:59 -060023#include <linux/kernel.h>
Andy Fleming7f7f5312005-11-11 12:38:59 -060024#include <linux/string.h>
25#include <linux/errno.h>
26#include <linux/unistd.h>
Andy Fleming7f7f5312005-11-11 12:38:59 -060027#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));
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +000052 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -060053 int new_setting = 0;
54 u32 temp;
55 unsigned long flags;
56
Andy Fleming4d7902f2009-02-04 16:43:44 -080057 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING))
58 return count;
59
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000060
Andy Fleming7f7f5312005-11-11 12:38:59 -060061 /* Find out the new setting */
Kumar Gala4409d282007-02-12 23:40:06 -060062 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060063 new_setting = 1;
Joe Perches8e95a202009-12-03 07:58:21 +000064 else if (!strncmp("off", buf, count - 1) ||
65 !strncmp("0", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060066 new_setting = 0;
67 else
68 return count;
69
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +000070
71 local_irq_save(flags);
72 lock_rx_qs(priv);
Andy Fleming7f7f5312005-11-11 12:38:59 -060073
74 /* Set the new stashing value */
75 priv->bd_stash_en = new_setting;
76
Sandeep Gopalpetf4983702009-11-02 07:03:09 +000077 temp = gfar_read(&regs->attr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040078
Andy Fleming7f7f5312005-11-11 12:38:59 -060079 if (new_setting)
80 temp |= ATTR_BDSTASH;
81 else
82 temp &= ~(ATTR_BDSTASH);
83
Sandeep Gopalpetf4983702009-11-02 07:03:09 +000084 gfar_write(&regs->attr, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -060085
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +000086 unlock_rx_qs(priv);
87 local_irq_restore(flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060088
89 return count;
90}
91
Anton Vorontsovb2f66d12009-02-01 00:54:16 -080092static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
Grant Likely35a84fd2007-12-01 22:12:45 -070093
Kumar Gala4409d282007-02-12 23:40:06 -060094static ssize_t gfar_show_rx_stash_size(struct device *dev,
95 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -060096{
Kumar Gala4409d282007-02-12 23:40:06 -060097 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060098
99 return sprintf(buf, "%d\n", priv->rx_stash_size);
100}
101
Kumar Gala4409d282007-02-12 23:40:06 -0600102static ssize_t gfar_set_rx_stash_size(struct device *dev,
103 struct device_attribute *attr,
104 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600105{
Kumar Gala4409d282007-02-12 23:40:06 -0600106 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000107 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600108 unsigned int length = simple_strtoul(buf, NULL, 0);
109 u32 temp;
110 unsigned long flags;
111
Andy Fleming4d7902f2009-02-04 16:43:44 -0800112 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
113 return count;
114
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000115 local_irq_save(flags);
116 lock_rx_qs(priv);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000117
Andy Fleming7f7f5312005-11-11 12:38:59 -0600118 if (length > priv->rx_buffer_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500119 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600120
121 if (length == priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500122 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600123
124 priv->rx_stash_size = length;
125
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000126 temp = gfar_read(&regs->attreli);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600127 temp &= ~ATTRELI_EL_MASK;
128 temp |= ATTRELI_EL(length);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000129 gfar_write(&regs->attreli, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600130
131 /* Turn stashing on/off as appropriate */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000132 temp = gfar_read(&regs->attr);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600133
134 if (length)
135 temp |= ATTR_BUFSTASH;
136 else
137 temp &= ~(ATTR_BUFSTASH);
138
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000139 gfar_write(&regs->attr, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600140
Andy Flemingf162b9d2008-05-02 13:00:30 -0500141out:
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000142 unlock_rx_qs(priv);
143 local_irq_restore(flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600144
145 return count;
146}
147
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800148static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
149 gfar_set_rx_stash_size);
Grant Likely35a84fd2007-12-01 22:12:45 -0700150
Andy Fleming7f7f5312005-11-11 12:38:59 -0600151/* Stashing will only be enabled when rx_stash_size != 0 */
Kumar Gala4409d282007-02-12 23:40:06 -0600152static ssize_t gfar_show_rx_stash_index(struct device *dev,
153 struct device_attribute *attr,
154 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600155{
Kumar Gala4409d282007-02-12 23:40:06 -0600156 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600157
158 return sprintf(buf, "%d\n", priv->rx_stash_index);
159}
160
Kumar Gala4409d282007-02-12 23:40:06 -0600161static ssize_t gfar_set_rx_stash_index(struct device *dev,
162 struct device_attribute *attr,
163 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600164{
Kumar Gala4409d282007-02-12 23:40:06 -0600165 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000166 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600167 unsigned short index = simple_strtoul(buf, NULL, 0);
168 u32 temp;
169 unsigned long flags;
170
Andy Fleming4d7902f2009-02-04 16:43:44 -0800171 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
172 return count;
173
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000174 local_irq_save(flags);
175 lock_rx_qs(priv);
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000176
Andy Fleming7f7f5312005-11-11 12:38:59 -0600177 if (index > priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500178 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600179
180 if (index == priv->rx_stash_index)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500181 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600182
183 priv->rx_stash_index = index;
184
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000185 temp = gfar_read(&regs->attreli);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600186 temp &= ~ATTRELI_EI_MASK;
187 temp |= ATTRELI_EI(index);
Anton Vorontsov499428e2009-11-10 14:11:07 +0000188 gfar_write(&regs->attreli, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600189
Andy Flemingf162b9d2008-05-02 13:00:30 -0500190out:
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000191 unlock_rx_qs(priv);
192 local_irq_restore(flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600193
194 return count;
195}
196
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800197static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
198 gfar_set_rx_stash_index);
Grant Likely35a84fd2007-12-01 22:12:45 -0700199
Kumar Gala4409d282007-02-12 23:40:06 -0600200static ssize_t gfar_show_fifo_threshold(struct device *dev,
201 struct device_attribute *attr,
202 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600203{
Kumar Gala4409d282007-02-12 23:40:06 -0600204 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600205
206 return sprintf(buf, "%d\n", priv->fifo_threshold);
207}
208
Kumar Gala4409d282007-02-12 23:40:06 -0600209static ssize_t gfar_set_fifo_threshold(struct device *dev,
210 struct device_attribute *attr,
211 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600212{
Kumar Gala4409d282007-02-12 23:40:06 -0600213 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000214 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600215 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
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000222 local_irq_save(flags);
223 lock_tx_qs(priv);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600224
225 priv->fifo_threshold = length;
226
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000227 temp = gfar_read(&regs->fifo_tx_thr);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600228 temp &= ~FIFO_TX_THR_MASK;
229 temp |= length;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000230 gfar_write(&regs->fifo_tx_thr, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600231
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000232 unlock_tx_qs(priv);
233 local_irq_restore(flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600234
235 return count;
236}
237
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800238static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
239 gfar_set_fifo_threshold);
Grant Likely35a84fd2007-12-01 22:12:45 -0700240
Kumar Gala4409d282007-02-12 23:40:06 -0600241static ssize_t gfar_show_fifo_starve(struct device *dev,
242 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600243{
Kumar Gala4409d282007-02-12 23:40:06 -0600244 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600245
246 return sprintf(buf, "%d\n", priv->fifo_starve);
247}
248
Kumar Gala4409d282007-02-12 23:40:06 -0600249static ssize_t gfar_set_fifo_starve(struct device *dev,
250 struct device_attribute *attr,
251 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600252{
Kumar Gala4409d282007-02-12 23:40:06 -0600253 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000254 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600255 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
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000262 local_irq_save(flags);
263 lock_tx_qs(priv);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600264
265 priv->fifo_starve = num;
266
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000267 temp = gfar_read(&regs->fifo_tx_starve);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600268 temp &= ~FIFO_TX_STARVE_MASK;
269 temp |= num;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000270 gfar_write(&regs->fifo_tx_starve, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600271
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000272 unlock_tx_qs(priv);
273 local_irq_restore(flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600274
275 return count;
276}
277
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800278static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
279 gfar_set_fifo_starve);
Grant Likely35a84fd2007-12-01 22:12:45 -0700280
Kumar Gala4409d282007-02-12 23:40:06 -0600281static ssize_t gfar_show_fifo_starve_off(struct device *dev,
282 struct device_attribute *attr,
283 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600284{
Kumar Gala4409d282007-02-12 23:40:06 -0600285 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600286
287 return sprintf(buf, "%d\n", priv->fifo_starve_off);
288}
289
Kumar Gala4409d282007-02-12 23:40:06 -0600290static ssize_t gfar_set_fifo_starve_off(struct device *dev,
291 struct device_attribute *attr,
292 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600293{
Kumar Gala4409d282007-02-12 23:40:06 -0600294 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpet46ceb602009-11-02 07:03:34 +0000295 struct gfar __iomem *regs = priv->gfargrp[0].regs;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600296 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
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000303 local_irq_save(flags);
304 lock_tx_qs(priv);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600305
306 priv->fifo_starve_off = num;
307
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000308 temp = gfar_read(&regs->fifo_tx_starve_shutoff);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600309 temp &= ~FIFO_TX_STARVE_OFF_MASK;
310 temp |= num;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000311 gfar_write(&regs->fifo_tx_starve_shutoff, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600312
Sandeep Gopalpetfba4ed02009-11-02 07:03:15 +0000313 unlock_tx_qs(priv);
314 local_irq_restore(flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600315
316 return count;
317}
318
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800319static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
320 gfar_set_fifo_starve_off);
Grant Likely35a84fd2007-12-01 22:12:45 -0700321
Andy Fleming7f7f5312005-11-11 12:38:59 -0600322void gfar_init_sysfs(struct net_device *dev)
323{
324 struct gfar_private *priv = netdev_priv(dev);
Grant Likely35a84fd2007-12-01 22:12:45 -0700325 int rc;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600326
327 /* Initialize the default values */
Andy Fleming7f7f5312005-11-11 12:38:59 -0600328 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;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600331
332 /* Create our sysfs files */
Grant Likely35a84fd2007-12-01 22:12:45 -0700333 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");
Andy Fleming7f7f5312005-11-11 12:38:59 -0600341}