Blame view
drivers/net/gianfar_sysfs.c
8.04 KB
7f7f53168 [PATCH] Gianfar u... |
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 drivers/net/gianf... |
10 |
* Maintainer: Kumar Gala (galak@kernel.crashing.org) |
7f7f53168 [PATCH] Gianfar u... |
11 12 13 14 15 16 17 18 19 20 |
* * Copyright (c) 2002-2005 Freescale Semiconductor, Inc. * * 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 [PATCH] Gianfar u... |
21 |
#include <linux/kernel.h> |
7f7f53168 [PATCH] Gianfar u... |
22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <linux/string.h> #include <linux/errno.h> #include <linux/unistd.h> #include <linux/slab.h> #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 [PATCH] Gianfar u... |
35 36 |
#include "gianfar.h" |
4409d2814 Convert network d... |
37 38 |
static ssize_t gfar_show_bd_stash(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168 [PATCH] Gianfar u... |
39 |
{ |
4409d2814 Convert network d... |
40 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
41 |
|
4409d2814 Convert network d... |
42 43 |
return sprintf(buf, "%s ", priv->bd_stash_en ? "on" : "off"); |
7f7f53168 [PATCH] Gianfar u... |
44 |
} |
4409d2814 Convert network d... |
45 46 47 |
static ssize_t gfar_set_bd_stash(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168 [PATCH] Gianfar u... |
48 |
{ |
4409d2814 Convert network d... |
49 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
50 51 52 |
int new_setting = 0; u32 temp; unsigned long flags; |
4d7902f22 gianfar: Fix stas... |
53 54 |
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING)) return count; |
7f7f53168 [PATCH] Gianfar u... |
55 |
/* Find out the new setting */ |
4409d2814 Convert network d... |
56 |
if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1)) |
7f7f53168 [PATCH] Gianfar u... |
57 |
new_setting = 1; |
4409d2814 Convert network d... |
58 59 |
else if (!strncmp("off", buf, count - 1) || !strncmp("0", buf, count - 1)) |
7f7f53168 [PATCH] Gianfar u... |
60 61 62 |
new_setting = 0; else return count; |
fef6108d4 [PATCH] Fix locki... |
63 |
spin_lock_irqsave(&priv->rxlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
64 65 66 67 68 |
/* Set the new stashing value */ priv->bd_stash_en = new_setting; temp = gfar_read(&priv->regs->attr); |
6aa20a223 drivers/net: Trim... |
69 |
|
7f7f53168 [PATCH] Gianfar u... |
70 71 72 73 74 75 |
if (new_setting) temp |= ATTR_BDSTASH; else temp &= ~(ATTR_BDSTASH); gfar_write(&priv->regs->attr, temp); |
fef6108d4 [PATCH] Fix locki... |
76 |
spin_unlock_irqrestore(&priv->rxlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
77 78 79 |
return count; } |
b2f66d183 gianfar: Fix spar... |
80 |
static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash); |
35a84fdc8 gianfar driver: e... |
81 |
|
4409d2814 Convert network d... |
82 83 |
static ssize_t gfar_show_rx_stash_size(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168 [PATCH] Gianfar u... |
84 |
{ |
4409d2814 Convert network d... |
85 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
86 87 88 89 |
return sprintf(buf, "%d ", priv->rx_stash_size); } |
4409d2814 Convert network d... |
90 91 92 |
static ssize_t gfar_set_rx_stash_size(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168 [PATCH] Gianfar u... |
93 |
{ |
4409d2814 Convert network d... |
94 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
95 96 97 |
unsigned int length = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; |
4d7902f22 gianfar: Fix stas... |
98 99 |
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) return count; |
fef6108d4 [PATCH] Fix locki... |
100 |
spin_lock_irqsave(&priv->rxlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
101 |
if (length > priv->rx_buffer_size) |
f162b9d58 gianfar: Fix a lo... |
102 |
goto out; |
7f7f53168 [PATCH] Gianfar u... |
103 104 |
if (length == priv->rx_stash_size) |
f162b9d58 gianfar: Fix a lo... |
105 |
goto out; |
7f7f53168 [PATCH] Gianfar u... |
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
priv->rx_stash_size = length; temp = gfar_read(&priv->regs->attreli); temp &= ~ATTRELI_EL_MASK; temp |= ATTRELI_EL(length); gfar_write(&priv->regs->attreli, temp); /* Turn stashing on/off as appropriate */ temp = gfar_read(&priv->regs->attr); if (length) temp |= ATTR_BUFSTASH; else temp &= ~(ATTR_BUFSTASH); gfar_write(&priv->regs->attr, temp); |
f162b9d58 gianfar: Fix a lo... |
123 |
out: |
fef6108d4 [PATCH] Fix locki... |
124 |
spin_unlock_irqrestore(&priv->rxlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
125 126 127 |
return count; } |
b2f66d183 gianfar: Fix spar... |
128 129 |
static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size, gfar_set_rx_stash_size); |
35a84fdc8 gianfar driver: e... |
130 |
|
7f7f53168 [PATCH] Gianfar u... |
131 |
/* Stashing will only be enabled when rx_stash_size != 0 */ |
4409d2814 Convert network d... |
132 133 134 |
static ssize_t gfar_show_rx_stash_index(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168 [PATCH] Gianfar u... |
135 |
{ |
4409d2814 Convert network d... |
136 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
137 138 139 140 |
return sprintf(buf, "%d ", priv->rx_stash_index); } |
4409d2814 Convert network d... |
141 142 143 |
static ssize_t gfar_set_rx_stash_index(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168 [PATCH] Gianfar u... |
144 |
{ |
4409d2814 Convert network d... |
145 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
146 147 148 |
unsigned short index = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; |
4d7902f22 gianfar: Fix stas... |
149 150 |
if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) return count; |
fef6108d4 [PATCH] Fix locki... |
151 |
spin_lock_irqsave(&priv->rxlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
152 |
if (index > priv->rx_stash_size) |
f162b9d58 gianfar: Fix a lo... |
153 |
goto out; |
7f7f53168 [PATCH] Gianfar u... |
154 155 |
if (index == priv->rx_stash_index) |
f162b9d58 gianfar: Fix a lo... |
156 |
goto out; |
7f7f53168 [PATCH] Gianfar u... |
157 158 159 160 161 162 163 |
priv->rx_stash_index = index; temp = gfar_read(&priv->regs->attreli); temp &= ~ATTRELI_EI_MASK; temp |= ATTRELI_EI(index); gfar_write(&priv->regs->attreli, flags); |
f162b9d58 gianfar: Fix a lo... |
164 |
out: |
fef6108d4 [PATCH] Fix locki... |
165 |
spin_unlock_irqrestore(&priv->rxlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
166 167 168 |
return count; } |
b2f66d183 gianfar: Fix spar... |
169 170 |
static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index, gfar_set_rx_stash_index); |
35a84fdc8 gianfar driver: e... |
171 |
|
4409d2814 Convert network d... |
172 173 174 |
static ssize_t gfar_show_fifo_threshold(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168 [PATCH] Gianfar u... |
175 |
{ |
4409d2814 Convert network d... |
176 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
177 178 179 180 |
return sprintf(buf, "%d ", priv->fifo_threshold); } |
4409d2814 Convert network d... |
181 182 183 |
static ssize_t gfar_set_fifo_threshold(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168 [PATCH] Gianfar u... |
184 |
{ |
4409d2814 Convert network d... |
185 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
186 187 188 189 190 191 |
unsigned int length = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; if (length > GFAR_MAX_FIFO_THRESHOLD) return count; |
fef6108d4 [PATCH] Fix locki... |
192 |
spin_lock_irqsave(&priv->txlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
193 194 195 196 197 198 199 |
priv->fifo_threshold = length; temp = gfar_read(&priv->regs->fifo_tx_thr); temp &= ~FIFO_TX_THR_MASK; temp |= length; gfar_write(&priv->regs->fifo_tx_thr, temp); |
fef6108d4 [PATCH] Fix locki... |
200 |
spin_unlock_irqrestore(&priv->txlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
201 202 203 |
return count; } |
b2f66d183 gianfar: Fix spar... |
204 205 |
static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold, gfar_set_fifo_threshold); |
35a84fdc8 gianfar driver: e... |
206 |
|
4409d2814 Convert network d... |
207 208 |
static ssize_t gfar_show_fifo_starve(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168 [PATCH] Gianfar u... |
209 |
{ |
4409d2814 Convert network d... |
210 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
211 212 213 214 |
return sprintf(buf, "%d ", priv->fifo_starve); } |
4409d2814 Convert network d... |
215 216 217 |
static ssize_t gfar_set_fifo_starve(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168 [PATCH] Gianfar u... |
218 |
{ |
4409d2814 Convert network d... |
219 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
220 221 222 223 224 225 |
unsigned int num = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; if (num > GFAR_MAX_FIFO_STARVE) return count; |
fef6108d4 [PATCH] Fix locki... |
226 |
spin_lock_irqsave(&priv->txlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
227 228 229 230 231 232 233 |
priv->fifo_starve = num; temp = gfar_read(&priv->regs->fifo_tx_starve); temp &= ~FIFO_TX_STARVE_MASK; temp |= num; gfar_write(&priv->regs->fifo_tx_starve, temp); |
fef6108d4 [PATCH] Fix locki... |
234 |
spin_unlock_irqrestore(&priv->txlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
235 236 237 |
return count; } |
b2f66d183 gianfar: Fix spar... |
238 239 |
static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve, gfar_set_fifo_starve); |
35a84fdc8 gianfar driver: e... |
240 |
|
4409d2814 Convert network d... |
241 242 243 |
static ssize_t gfar_show_fifo_starve_off(struct device *dev, struct device_attribute *attr, char *buf) |
7f7f53168 [PATCH] Gianfar u... |
244 |
{ |
4409d2814 Convert network d... |
245 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
246 247 248 249 |
return sprintf(buf, "%d ", priv->fifo_starve_off); } |
4409d2814 Convert network d... |
250 251 252 |
static ssize_t gfar_set_fifo_starve_off(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
7f7f53168 [PATCH] Gianfar u... |
253 |
{ |
4409d2814 Convert network d... |
254 |
struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
7f7f53168 [PATCH] Gianfar u... |
255 256 257 258 259 260 |
unsigned int num = simple_strtoul(buf, NULL, 0); u32 temp; unsigned long flags; if (num > GFAR_MAX_FIFO_STARVE_OFF) return count; |
fef6108d4 [PATCH] Fix locki... |
261 |
spin_lock_irqsave(&priv->txlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
262 263 264 265 266 267 268 |
priv->fifo_starve_off = num; temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff); temp &= ~FIFO_TX_STARVE_OFF_MASK; temp |= num; gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp); |
fef6108d4 [PATCH] Fix locki... |
269 |
spin_unlock_irqrestore(&priv->txlock, flags); |
7f7f53168 [PATCH] Gianfar u... |
270 271 272 |
return count; } |
b2f66d183 gianfar: Fix spar... |
273 274 |
static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off, gfar_set_fifo_starve_off); |
35a84fdc8 gianfar driver: e... |
275 |
|
7f7f53168 [PATCH] Gianfar u... |
276 277 278 |
void gfar_init_sysfs(struct net_device *dev) { struct gfar_private *priv = netdev_priv(dev); |
35a84fdc8 gianfar driver: e... |
279 |
int rc; |
7f7f53168 [PATCH] Gianfar u... |
280 281 |
/* Initialize the default values */ |
7f7f53168 [PATCH] Gianfar u... |
282 283 284 |
priv->fifo_threshold = DEFAULT_FIFO_TX_THR; priv->fifo_starve = DEFAULT_FIFO_TX_STARVE; priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF; |
7f7f53168 [PATCH] Gianfar u... |
285 286 |
/* Create our sysfs files */ |
35a84fdc8 gianfar driver: e... |
287 288 289 290 291 292 293 294 295 |
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 [PATCH] Gianfar u... |
296 |
} |