blob: 9c664f85705cb169e6f77f38bff14541cb7e1f31 [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 Gopalpeta12f8012009-11-02 07:03:00 +000053 struct gfar_priv_rx_q *rx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -060054 int new_setting = 0;
55 u32 temp;
56 unsigned long flags;
57
Andy Fleming4d7902f2009-02-04 16:43:44 -080058 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING))
59 return count;
60
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000061 rx_queue = priv->rx_queue;
62
Andy Fleming7f7f5312005-11-11 12:38:59 -060063 /* Find out the new setting */
Kumar Gala4409d282007-02-12 23:40:06 -060064 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060065 new_setting = 1;
Kumar Gala4409d282007-02-12 23:40:06 -060066 else if (!strncmp("off", buf, count - 1)
67 || !strncmp("0", buf, count - 1))
Andy Fleming7f7f5312005-11-11 12:38:59 -060068 new_setting = 0;
69 else
70 return count;
71
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000072 spin_lock_irqsave(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060073
74 /* Set the new stashing value */
75 priv->bd_stash_en = new_setting;
76
77 temp = gfar_read(&priv->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
84 gfar_write(&priv->regs->attr, temp);
85
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +000086 spin_unlock_irqrestore(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -060087
88 return count;
89}
90
Anton Vorontsovb2f66d12009-02-01 00:54:16 -080091static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
Grant Likely35a84fd2007-12-01 22:12:45 -070092
Kumar Gala4409d282007-02-12 23:40:06 -060093static ssize_t gfar_show_rx_stash_size(struct device *dev,
94 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -060095{
Kumar Gala4409d282007-02-12 23:40:06 -060096 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -060097
98 return sprintf(buf, "%d\n", priv->rx_stash_size);
99}
100
Kumar Gala4409d282007-02-12 23:40:06 -0600101static ssize_t gfar_set_rx_stash_size(struct device *dev,
102 struct device_attribute *attr,
103 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600104{
Kumar Gala4409d282007-02-12 23:40:06 -0600105 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000106 struct gfar_priv_rx_q *rx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600107 unsigned int length = simple_strtoul(buf, NULL, 0);
108 u32 temp;
109 unsigned long flags;
110
Andy Fleming4d7902f2009-02-04 16:43:44 -0800111 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
112 return count;
113
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000114 rx_queue = priv->rx_queue;
115
116 spin_lock_irqsave(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600117 if (length > priv->rx_buffer_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500118 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600119
120 if (length == priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500121 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600122
123 priv->rx_stash_size = length;
124
125 temp = gfar_read(&priv->regs->attreli);
126 temp &= ~ATTRELI_EL_MASK;
127 temp |= ATTRELI_EL(length);
128 gfar_write(&priv->regs->attreli, temp);
129
130 /* Turn stashing on/off as appropriate */
131 temp = gfar_read(&priv->regs->attr);
132
133 if (length)
134 temp |= ATTR_BUFSTASH;
135 else
136 temp &= ~(ATTR_BUFSTASH);
137
138 gfar_write(&priv->regs->attr, temp);
139
Andy Flemingf162b9d2008-05-02 13:00:30 -0500140out:
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000141 spin_unlock_irqrestore(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600142
143 return count;
144}
145
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800146static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
147 gfar_set_rx_stash_size);
Grant Likely35a84fd2007-12-01 22:12:45 -0700148
Andy Fleming7f7f5312005-11-11 12:38:59 -0600149/* Stashing will only be enabled when rx_stash_size != 0 */
Kumar Gala4409d282007-02-12 23:40:06 -0600150static ssize_t gfar_show_rx_stash_index(struct device *dev,
151 struct device_attribute *attr,
152 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600153{
Kumar Gala4409d282007-02-12 23:40:06 -0600154 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600155
156 return sprintf(buf, "%d\n", priv->rx_stash_index);
157}
158
Kumar Gala4409d282007-02-12 23:40:06 -0600159static ssize_t gfar_set_rx_stash_index(struct device *dev,
160 struct device_attribute *attr,
161 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600162{
Kumar Gala4409d282007-02-12 23:40:06 -0600163 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000164 struct gfar_priv_rx_q *rx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600165 unsigned short index = simple_strtoul(buf, NULL, 0);
166 u32 temp;
167 unsigned long flags;
168
Andy Fleming4d7902f2009-02-04 16:43:44 -0800169 if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
170 return count;
171
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000172 rx_queue = priv->rx_queue;
173
174 spin_lock_irqsave(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600175 if (index > priv->rx_stash_size)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500176 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600177
178 if (index == priv->rx_stash_index)
Andy Flemingf162b9d2008-05-02 13:00:30 -0500179 goto out;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600180
181 priv->rx_stash_index = index;
182
183 temp = gfar_read(&priv->regs->attreli);
184 temp &= ~ATTRELI_EI_MASK;
185 temp |= ATTRELI_EI(index);
186 gfar_write(&priv->regs->attreli, flags);
187
Andy Flemingf162b9d2008-05-02 13:00:30 -0500188out:
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000189 spin_unlock_irqrestore(&rx_queue->rxlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600190
191 return count;
192}
193
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800194static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
195 gfar_set_rx_stash_index);
Grant Likely35a84fd2007-12-01 22:12:45 -0700196
Kumar Gala4409d282007-02-12 23:40:06 -0600197static ssize_t gfar_show_fifo_threshold(struct device *dev,
198 struct device_attribute *attr,
199 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600200{
Kumar Gala4409d282007-02-12 23:40:06 -0600201 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600202
203 return sprintf(buf, "%d\n", priv->fifo_threshold);
204}
205
Kumar Gala4409d282007-02-12 23:40:06 -0600206static ssize_t gfar_set_fifo_threshold(struct device *dev,
207 struct device_attribute *attr,
208 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600209{
Kumar Gala4409d282007-02-12 23:40:06 -0600210 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000211 struct gfar_priv_tx_q *tx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600212 unsigned int length = simple_strtoul(buf, NULL, 0);
213 u32 temp;
214 unsigned long flags;
215
216 if (length > GFAR_MAX_FIFO_THRESHOLD)
217 return count;
218
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000219 tx_queue = priv->tx_queue;
220
221 spin_lock_irqsave(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600222
223 priv->fifo_threshold = length;
224
225 temp = gfar_read(&priv->regs->fifo_tx_thr);
226 temp &= ~FIFO_TX_THR_MASK;
227 temp |= length;
228 gfar_write(&priv->regs->fifo_tx_thr, temp);
229
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000230 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600231
232 return count;
233}
234
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800235static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
236 gfar_set_fifo_threshold);
Grant Likely35a84fd2007-12-01 22:12:45 -0700237
Kumar Gala4409d282007-02-12 23:40:06 -0600238static ssize_t gfar_show_fifo_starve(struct device *dev,
239 struct device_attribute *attr, char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600240{
Kumar Gala4409d282007-02-12 23:40:06 -0600241 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600242
243 return sprintf(buf, "%d\n", priv->fifo_starve);
244}
245
Kumar Gala4409d282007-02-12 23:40:06 -0600246static ssize_t gfar_set_fifo_starve(struct device *dev,
247 struct device_attribute *attr,
248 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600249{
Kumar Gala4409d282007-02-12 23:40:06 -0600250 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000251 struct gfar_priv_tx_q *tx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600252 unsigned int num = simple_strtoul(buf, NULL, 0);
253 u32 temp;
254 unsigned long flags;
255
256 if (num > GFAR_MAX_FIFO_STARVE)
257 return count;
258
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000259 tx_queue = priv->tx_queue;
260 spin_lock_irqsave(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600261
262 priv->fifo_starve = num;
263
264 temp = gfar_read(&priv->regs->fifo_tx_starve);
265 temp &= ~FIFO_TX_STARVE_MASK;
266 temp |= num;
267 gfar_write(&priv->regs->fifo_tx_starve, temp);
268
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000269 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600270
271 return count;
272}
273
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800274static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
275 gfar_set_fifo_starve);
Grant Likely35a84fd2007-12-01 22:12:45 -0700276
Kumar Gala4409d282007-02-12 23:40:06 -0600277static ssize_t gfar_show_fifo_starve_off(struct device *dev,
278 struct device_attribute *attr,
279 char *buf)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600280{
Kumar Gala4409d282007-02-12 23:40:06 -0600281 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Andy Fleming7f7f5312005-11-11 12:38:59 -0600282
283 return sprintf(buf, "%d\n", priv->fifo_starve_off);
284}
285
Kumar Gala4409d282007-02-12 23:40:06 -0600286static ssize_t gfar_set_fifo_starve_off(struct device *dev,
287 struct device_attribute *attr,
288 const char *buf, size_t count)
Andy Fleming7f7f5312005-11-11 12:38:59 -0600289{
Kumar Gala4409d282007-02-12 23:40:06 -0600290 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000291 struct gfar_priv_tx_q *tx_queue = NULL;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600292 unsigned int num = simple_strtoul(buf, NULL, 0);
293 u32 temp;
294 unsigned long flags;
295
296 if (num > GFAR_MAX_FIFO_STARVE_OFF)
297 return count;
298
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000299 tx_queue = priv->tx_queue;
300 spin_lock_irqsave(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600301
302 priv->fifo_starve_off = num;
303
304 temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
305 temp &= ~FIFO_TX_STARVE_OFF_MASK;
306 temp |= num;
307 gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
308
Sandeep Gopalpeta12f8012009-11-02 07:03:00 +0000309 spin_unlock_irqrestore(&tx_queue->txlock, flags);
Andy Fleming7f7f5312005-11-11 12:38:59 -0600310
311 return count;
312}
313
Anton Vorontsovb2f66d12009-02-01 00:54:16 -0800314static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
315 gfar_set_fifo_starve_off);
Grant Likely35a84fd2007-12-01 22:12:45 -0700316
Andy Fleming7f7f5312005-11-11 12:38:59 -0600317void gfar_init_sysfs(struct net_device *dev)
318{
319 struct gfar_private *priv = netdev_priv(dev);
Grant Likely35a84fd2007-12-01 22:12:45 -0700320 int rc;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600321
322 /* Initialize the default values */
Andy Fleming7f7f5312005-11-11 12:38:59 -0600323 priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
324 priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
325 priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
Andy Fleming7f7f5312005-11-11 12:38:59 -0600326
327 /* Create our sysfs files */
Grant Likely35a84fd2007-12-01 22:12:45 -0700328 rc = device_create_file(&dev->dev, &dev_attr_bd_stash);
329 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size);
330 rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index);
331 rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold);
332 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve);
333 rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off);
334 if (rc)
335 dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");
Andy Fleming7f7f5312005-11-11 12:38:59 -0600336}