blob: adea11ea4038e65d98949ca3740f9663e307c867 [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>
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>
32#include <linux/mm.h>
33#include <linux/device.h>
34
35#include <asm/uaccess.h>
36#include <linux/module.h>
Andy Fleming7f7f5312005-11-11 12:38:59 -060037
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));
Sandeep Gopalpetf4983702009-11-02 07:03:09 +000053 struct gfar __iomem *regs = priv->gfargrp.regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000054 struct gfar_priv_rx_q *rx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -060055 int new_setting = 0;
56 u32 temp;
57 unsigned long flags;
58
Andy Fleming4d7902f2009-02-04 16:43:44 -080059 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING))
60 return count;
61
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000062 rx_queue = priv->rx_queue;
63
Andy Fleming7f7f5312005-11-11 12:38:59 -060064 /* Find out the new setting */
Kumar Gala4409d282007-02-12 23:40:06 -060065 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060066 new_setting = 1;
Kumar Gala4409d282007-02-12 23:40:06 -060067 else if (!strncmp("off", buf, count - 1)
68 || !strncmp("0", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060069 new_setting = 0;
70 else
71 return count;
72
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000073 spin_lock_irqsave(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060074
75 /* Set the new stashing value */
76 priv->bd_stash_en = new_setting;
77
Sandeep Gopalpetf4983702009-11-02 07:03:09 +000078 temp = gfar_read(&regs->attr);
Jeff Garzik6aa20a22006-09-13 13:24:59 -040079
Andy Fleming7f7f5312005-11-11 12:38:59 -060080 if (new_setting)
81 temp |= ATTR_BDSTASH;
82 else
83 temp &= ~(ATTR_BDSTASH);
84
Sandeep Gopalpetf4983702009-11-02 07:03:09 +000085 gfar_write(&regs->attr, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -060086
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000087 spin_unlock_irqrestore(&rx_queue->rxlock, 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 Gopalpetf4983702009-11-02 07:03:09 +0000107 struct gfar __iomem *regs = priv->gfargrp.regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000108 struct gfar_priv_rx_q *rx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600109 unsigned int length = simple_strtoul(buf, NULL, 0);
110 u32 temp;
111 unsigned long flags;
112
Andy Fleming4d7902f2009-02-04 16:43:44 -0800113 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
114 return count;
115
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000116 rx_queue = priv->rx_queue;
117
118 spin_lock_irqsave(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600119 if (length > priv->rx_buffer_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500120 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600121
122 if (length == priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500123 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600124
125 priv->rx_stash_size = length;
126
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000127 temp = gfar_read(&regs->attreli);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600128 temp &= ~ATTRELI_EL_MASK;
129 temp |= ATTRELI_EL(length);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000130 gfar_write(&regs->attreli, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600131
132 /* Turn stashing on/off as appropriate */
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000133 temp = gfar_read(&regs->attr);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600134
135 if (length)
136 temp |= ATTR_BUFSTASH;
137 else
138 temp &= ~(ATTR_BUFSTASH);
139
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000140 gfar_write(&regs->attr, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600141
Andy Flemingf162b9d2008-05-02 13:00:30 -0500142out:
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000143 spin_unlock_irqrestore(&rx_queue->rxlock, 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 Gopalpetf4983702009-11-02 07:03:09 +0000166 struct gfar __iomem *regs = priv->gfargrp.regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000167 struct gfar_priv_rx_q *rx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600168 unsigned short index = simple_strtoul(buf, NULL, 0);
169 u32 temp;
170 unsigned long flags;
171
Andy Fleming4d7902f2009-02-04 16:43:44 -0800172 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
173 return count;
174
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000175 rx_queue = priv->rx_queue;
176
177 spin_lock_irqsave(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600178 if (index > priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500179 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600180
181 if (index == priv->rx_stash_index)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500182 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600183
184 priv->rx_stash_index = index;
185
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000186 temp = gfar_read(&regs->attreli);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600187 temp &= ~ATTRELI_EI_MASK;
188 temp |= ATTRELI_EI(index);
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000189 gfar_write(&regs->attreli, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600190
Andy Flemingf162b9d2008-05-02 13:00:30 -0500191out:
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000192 spin_unlock_irqrestore(&rx_queue->rxlock, 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 Gopalpetf4983702009-11-02 07:03:09 +0000214 struct gfar __iomem *regs = priv->gfargrp.regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000215 struct gfar_priv_tx_q *tx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600216 unsigned int length = simple_strtoul(buf, NULL, 0);
217 u32 temp;
218 unsigned long flags;
219
220 if (length > GFAR_MAX_FIFO_THRESHOLD)
221 return count;
222
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000223 tx_queue = priv->tx_queue;
224
225 spin_lock_irqsave(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600226
227 priv->fifo_threshold = length;
228
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000229 temp = gfar_read(&regs->fifo_tx_thr);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600230 temp &= ~FIFO_TX_THR_MASK;
231 temp |= length;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000232 gfar_write(&regs->fifo_tx_thr, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600233
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000234 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600235
236 return count;
237}
238
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800239static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
240 gfar_set_fifo_threshold);
Grant Likely35a84fd2007-12-01 22:12:45 -0700241
Kumar Gala4409d282007-02-12 23:40:06 -0600242static ssize_t gfar_show_fifo_starve(struct device *dev,
243 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600244{
Kumar Gala4409d282007-02-12 23:40:06 -0600245 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600246
247 return sprintf(buf, "%d\n", priv->fifo_starve);
248}
249
Kumar Gala4409d282007-02-12 23:40:06 -0600250static ssize_t gfar_set_fifo_starve(struct device *dev,
251 struct device_attribute *attr,
252 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600253{
Kumar Gala4409d282007-02-12 23:40:06 -0600254 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000255 struct gfar __iomem *regs = priv->gfargrp.regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000256 struct gfar_priv_tx_q *tx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600257 unsigned int num = simple_strtoul(buf, NULL, 0);
258 u32 temp;
259 unsigned long flags;
260
261 if (num > GFAR_MAX_FIFO_STARVE)
262 return count;
263
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000264 tx_queue = priv->tx_queue;
265 spin_lock_irqsave(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600266
267 priv->fifo_starve = num;
268
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000269 temp = gfar_read(&regs->fifo_tx_starve);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600270 temp &= ~FIFO_TX_STARVE_MASK;
271 temp |= num;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000272 gfar_write(&regs->fifo_tx_starve, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600273
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000274 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600275
276 return count;
277}
278
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800279static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
280 gfar_set_fifo_starve);
Grant Likely35a84fd2007-12-01 22:12:45 -0700281
Kumar Gala4409d282007-02-12 23:40:06 -0600282static ssize_t gfar_show_fifo_starve_off(struct device *dev,
283 struct device_attribute *attr,
284 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600285{
Kumar Gala4409d282007-02-12 23:40:06 -0600286 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600287
288 return sprintf(buf, "%d\n", priv->fifo_starve_off);
289}
290
Kumar Gala4409d282007-02-12 23:40:06 -0600291static ssize_t gfar_set_fifo_starve_off(struct device *dev,
292 struct device_attribute *attr,
293 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600294{
Kumar Gala4409d282007-02-12 23:40:06 -0600295 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000296 struct gfar __iomem *regs = priv->gfargrp.regs;
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000297 struct gfar_priv_tx_q *tx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600298 unsigned int num = simple_strtoul(buf, NULL, 0);
299 u32 temp;
300 unsigned long flags;
301
302 if (num > GFAR_MAX_FIFO_STARVE_OFF)
303 return count;
304
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000305 tx_queue = priv->tx_queue;
306 spin_lock_irqsave(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600307
308 priv->fifo_starve_off = num;
309
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000310 temp = gfar_read(&regs->fifo_tx_starve_shutoff);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600311 temp &= ~FIFO_TX_STARVE_OFF_MASK;
312 temp |= num;
Sandeep Gopalpetf4983702009-11-02 07:03:09 +0000313 gfar_write(&regs->fifo_tx_starve_shutoff, temp);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600314
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000315 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600316
317 return count;
318}
319
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800320static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
321 gfar_set_fifo_starve_off);
Grant Likely35a84fd2007-12-01 22:12:45 -0700322
Andy Fleming7f7f5312005-11-11 12:38:59 -0600323void gfar_init_sysfs(struct net_device *dev)
324{
325 struct gfar_private *priv = netdev_priv(dev);
Grant Likely35a84fd2007-12-01 22:12:45 -0700326 int rc;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600327
328 /* Initialize the default values */
Andy Fleming7f7f5312005-11-11 12:38:59 -0600329 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;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600332
333 /* Create our sysfs files */
Grant Likely35a84fd2007-12-01 22:12:45 -0700334 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);
340 if (rc)
341 dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");
Andy Fleming7f7f5312005-11-11 12:38:59 -0600342}