Blame view
drivers/net/gianfar_sysfs.c
8.31 KB
7f7f53168
|
1 2 3 4 5 6 7 8 9 |
/* * drivers/net/gianfar_sysfs.c * * Gianfar Ethernet Driver * This driver is designed for the non-CPM ethernet controllers * on the 85xx and 83xx family of integrated processors * Based on 8260_io/fcc_enet.c * * Author: Andy Fleming |
b56d55b69
|
10 |
* Maintainer: Kumar Gala (galak@kernel.crashing.org) |
a12f801d4
|
11 |
* Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> |
7f7f53168
|
12 |
* |
a12f801d4
|
13 |
* Copyright 2002-2009 Freescale Semiconductor, Inc. |
7f7f53168
|
14 15 16 17 18 19 20 21 |
* * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. * * Sysfs file creation and management */ |
7f7f53168
|
22 |
#include <linux/kernel.h> |
7f7f53168
|
23 24 25 |
#include <linux/string.h> #include <linux/errno.h> #include <linux/unistd.h> |
7f7f53168
|
26 27 28 29 30 31 32 33 34 |
#include <linux/init.h> #include <linux/delay.h> #include <linux/etherdevice.h> #include <linux/spinlock.h> #include <linux/mm.h> #include <linux/device.h> #include <asm/uaccess.h> #include <linux/module.h> |
7f7f53168
|
35 36 |
#include "gianfar.h" |
4409d2814
|
37 38 |
static ssize_t gfar_show_bd_stash(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168
|
39 |
{ |
4409d2814
|
40 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168
|
41 |
|
4409d2814
|
42 43 |
return sprintf(buf, "%s ", priv->bd_stash_en ? "on" : "off"); |
7f7f53168
|
44 |
} |
4409d2814
|
45 46 47 |
static ssize_t gfar_set_bd_stash(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168
|
48 |
{ |
4409d2814
|
49 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
46ceb60ca
|
50 |
struct gfar __iomem *regs = priv->gfargrp[0].regs; |
7f7f53168
|
51 52 53 |
int new_setting = 0; u32 temp; unsigned long flags; |
4d7902f22
|
54 55 |
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING)) return count; |
a12f801d4
|
56 |
|
7f7f53168
|
57 |
/* Find out the new setting */ |
4409d2814
|
58 |
if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1)) |
7f7f53168
|
59 |
new_setting = 1; |
8e95a2026
|
60 61 |
else if (!strncmp("off", buf, count - 1) || !strncmp("0", buf, count - 1)) |
7f7f53168
|
62 63 64 |
new_setting = 0; else return count; |
fba4ed030
|
65 66 67 |
local_irq_save(flags); lock_rx_qs(priv); |
7f7f53168
|
68 69 70 |
/* Set the new stashing value */ priv->bd_stash_en = new_setting; |
f4983704a
|
71 |
temp = gfar_read(®s->attr); |
6aa20a223
|
72 |
|
7f7f53168
|
73 74 75 76 |
if (new_setting) temp |= ATTR_BDSTASH; else temp &= ~(ATTR_BDSTASH); |
f4983704a
|
77 |
gfar_write(®s->attr, temp); |
7f7f53168
|
78 |
|
fba4ed030
|
79 80 |
unlock_rx_qs(priv); local_irq_restore(flags); |
7f7f53168
|
81 82 83 |
return count; } |
b2f66d183
|
84 |
static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash); |
35a84fdc8
|
85 |
|
4409d2814
|
86 87 |
static ssize_t gfar_show_rx_stash_size(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168
|
88 |
{ |
4409d2814
|
89 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168
|
90 91 92 93 |
return sprintf(buf, "%d ", priv->rx_stash_size); } |
4409d2814
|
94 95 96 |
static ssize_t gfar_set_rx_stash_size(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168
|
97 |
{ |
4409d2814
|
98 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
46ceb60ca
|
99 |
struct gfar __iomem *regs = priv->gfargrp[0].regs; |
7f7f53168
|
100 101 102 |
unsigned int length = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; |
4d7902f22
|
103 104 |
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) return count; |
fba4ed030
|
105 106 |
local_irq_save(flags); lock_rx_qs(priv); |
a12f801d4
|
107 |
|
7f7f53168
|
108 |
if (length > priv->rx_buffer_size) |
f162b9d58
|
109 |
goto out; |
7f7f53168
|
110 111 |
if (length == priv->rx_stash_size) |
f162b9d58
|
112 |
goto out; |
7f7f53168
|
113 114 |
priv->rx_stash_size = length; |
f4983704a
|
115 |
temp = gfar_read(®s->attreli); |
7f7f53168
|
116 117 |
temp &= ~ATTRELI_EL_MASK; temp |= ATTRELI_EL(length); |
f4983704a
|
118 |
gfar_write(®s->attreli, temp); |
7f7f53168
|
119 120 |
/* Turn stashing on/off as appropriate */ |
f4983704a
|
121 |
temp = gfar_read(®s->attr); |
7f7f53168
|
122 123 124 125 126 |
if (length) temp |= ATTR_BUFSTASH; else temp &= ~(ATTR_BUFSTASH); |
f4983704a
|
127 |
gfar_write(®s->attr, temp); |
7f7f53168
|
128 |
|
f162b9d58
|
129 |
out: |
fba4ed030
|
130 131 |
unlock_rx_qs(priv); local_irq_restore(flags); |
7f7f53168
|
132 133 134 |
return count; } |
b2f66d183
|
135 136 |
static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size, gfar_set_rx_stash_size); |
35a84fdc8
|
137 |
|
7f7f53168
|
138 |
/* Stashing will only be enabled when rx_stash_size != 0 */ |
4409d2814
|
139 140 141 |
static ssize_t gfar_show_rx_stash_index(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168
|
142 |
{ |
4409d2814
|
143 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168
|
144 145 146 147 |
return sprintf(buf, "%d ", priv->rx_stash_index); } |
4409d2814
|
148 149 150 |
static ssize_t gfar_set_rx_stash_index(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168
|
151 |
{ |
4409d2814
|
152 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
46ceb60ca
|
153 |
struct gfar __iomem *regs = priv->gfargrp[0].regs; |
7f7f53168
|
154 155 156 |
unsigned short index = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; |
4d7902f22
|
157 158 |
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) return count; |
fba4ed030
|
159 160 |
local_irq_save(flags); lock_rx_qs(priv); |
a12f801d4
|
161 |
|
7f7f53168
|
162 |
if (index > priv->rx_stash_size) |
f162b9d58
|
163 |
goto out; |
7f7f53168
|
164 165 |
if (index == priv->rx_stash_index) |
f162b9d58
|
166 |
goto out; |
7f7f53168
|
167 168 |
priv->rx_stash_index = index; |
f4983704a
|
169 |
temp = gfar_read(®s->attreli); |
7f7f53168
|
170 171 |
temp &= ~ATTRELI_EI_MASK; temp |= ATTRELI_EI(index); |
499428ed2
|
172 |
gfar_write(®s->attreli, temp); |
7f7f53168
|
173 |
|
f162b9d58
|
174 |
out: |
fba4ed030
|
175 176 |
unlock_rx_qs(priv); local_irq_restore(flags); |
7f7f53168
|
177 178 179 |
return count; } |
b2f66d183
|
180 181 |
static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index, gfar_set_rx_stash_index); |
35a84fdc8
|
182 |
|
4409d2814
|
183 184 185 |
static ssize_t gfar_show_fifo_threshold(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168
|
186 |
{ |
4409d2814
|
187 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168
|
188 189 190 191 |
return sprintf(buf, "%d ", priv->fifo_threshold); } |
4409d2814
|
192 193 194 |
static ssize_t gfar_set_fifo_threshold(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168
|
195 |
{ |
4409d2814
|
196 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
46ceb60ca
|
197 |
struct gfar __iomem *regs = priv->gfargrp[0].regs; |
7f7f53168
|
198 199 200 201 202 203 |
unsigned int length = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; if (length > GFAR_MAX_FIFO_THRESHOLD) return count; |
fba4ed030
|
204 205 |
local_irq_save(flags); lock_tx_qs(priv); |
7f7f53168
|
206 207 |
priv->fifo_threshold = length; |
f4983704a
|
208 |
temp = gfar_read(®s->fifo_tx_thr); |
7f7f53168
|
209 210 |
temp &= ~FIFO_TX_THR_MASK; temp |= length; |
f4983704a
|
211 |
gfar_write(®s->fifo_tx_thr, temp); |
7f7f53168
|
212 |
|
fba4ed030
|
213 214 |
unlock_tx_qs(priv); local_irq_restore(flags); |
7f7f53168
|
215 216 217 |
return count; } |
b2f66d183
|
218 219 |
static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold, gfar_set_fifo_threshold); |
35a84fdc8
|
220 |
|
4409d2814
|
221 222 |
static ssize_t gfar_show_fifo_starve(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168
|
223 |
{ |
4409d2814
|
224 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168
|
225 226 227 228 |
return sprintf(buf, "%d ", priv->fifo_starve); } |
4409d2814
|
229 230 231 |
static ssize_t gfar_set_fifo_starve(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168
|
232 |
{ |
4409d2814
|
233 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
46ceb60ca
|
234 |
struct gfar __iomem *regs = priv->gfargrp[0].regs; |
7f7f53168
|
235 236 237 238 239 240 |
unsigned int num = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; if (num > GFAR_MAX_FIFO_STARVE) return count; |
fba4ed030
|
241 242 |
local_irq_save(flags); lock_tx_qs(priv); |
7f7f53168
|
243 244 |
priv->fifo_starve = num; |
f4983704a
|
245 |
temp = gfar_read(®s->fifo_tx_starve); |
7f7f53168
|
246 247 |
temp &= ~FIFO_TX_STARVE_MASK; temp |= num; |
f4983704a
|
248 |
gfar_write(®s->fifo_tx_starve, temp); |
7f7f53168
|
249 |
|
fba4ed030
|
250 251 |
unlock_tx_qs(priv); local_irq_restore(flags); |
7f7f53168
|
252 253 254 |
return count; } |
b2f66d183
|
255 256 |
static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve, gfar_set_fifo_starve); |
35a84fdc8
|
257 |
|
4409d2814
|
258 259 260 |
static ssize_t gfar_show_fifo_starve_off(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168
|
261 |
{ |
4409d2814
|
262 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168
|
263 264 265 266 |
return sprintf(buf, "%d ", priv->fifo_starve_off); } |
4409d2814
|
267 268 269 |
static ssize_t gfar_set_fifo_starve_off(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168
|
270 |
{ |
4409d2814
|
271 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
46ceb60ca
|
272 |
struct gfar __iomem *regs = priv->gfargrp[0].regs; |
7f7f53168
|
273 274 275 276 277 278 |
unsigned int num = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; if (num > GFAR_MAX_FIFO_STARVE_OFF) return count; |
fba4ed030
|
279 280 |
local_irq_save(flags); lock_tx_qs(priv); |
7f7f53168
|
281 282 |
priv->fifo_starve_off = num; |
f4983704a
|
283 |
temp = gfar_read(®s->fifo_tx_starve_shutoff); |
7f7f53168
|
284 285 |
temp &= ~FIFO_TX_STARVE_OFF_MASK; temp |= num; |
f4983704a
|
286 |
gfar_write(®s->fifo_tx_starve_shutoff, temp); |
7f7f53168
|
287 |
|
fba4ed030
|
288 289 |
unlock_tx_qs(priv); local_irq_restore(flags); |
7f7f53168
|
290 291 292 |
return count; } |
b2f66d183
|
293 294 |
static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off, gfar_set_fifo_starve_off); |
35a84fdc8
|
295 |
|
7f7f53168
|
296 297 298 |
void gfar_init_sysfs(struct net_device *dev) { struct gfar_private *priv = netdev_priv(dev); |
35a84fdc8
|
299 |
int rc; |
7f7f53168
|
300 301 |
/* Initialize the default values */ |
7f7f53168
|
302 303 304 |
priv->fifo_threshold = DEFAULT_FIFO_TX_THR; priv->fifo_starve = DEFAULT_FIFO_TX_STARVE; priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF; |
7f7f53168
|
305 306 |
/* Create our sysfs files */ |
35a84fdc8
|
307 308 309 310 311 312 313 314 315 |
rc = device_create_file(&dev->dev, &dev_attr_bd_stash); rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size); rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index); rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold); rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve); rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off); if (rc) dev_err(&dev->dev, "Error creating gianfar sysfs files. "); |
7f7f53168
|
316 |
} |