Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 1 | /* |
| 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 Bunk | b56d55b | 2006-01-11 02:00:10 +0100 | [diff] [blame] | 10 | * Maintainer: Kumar Gala (galak@kernel.crashing.org) |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 11 | * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com> |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 12 | * |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 13 | * Copyright 2002-2009 Freescale Semiconductor, Inc. |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 14 | * |
| 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 Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 23 | #include <linux/kernel.h> |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 24 | #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 Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 37 | |
| 38 | #include "gianfar.h" |
| 39 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 40 | static ssize_t gfar_show_bd_stash(struct device *dev, |
| 41 | struct device_attribute *attr, char *buf) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 42 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 43 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 44 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 45 | return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off"); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 46 | } |
| 47 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 48 | static ssize_t gfar_set_bd_stash(struct device *dev, |
| 49 | struct device_attribute *attr, |
| 50 | const char *buf, size_t count) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 51 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 52 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 53 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 54 | int new_setting = 0; |
| 55 | u32 temp; |
| 56 | unsigned long flags; |
| 57 | |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 58 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING)) |
| 59 | return count; |
| 60 | |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 61 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 62 | /* Find out the new setting */ |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 63 | if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1)) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 64 | new_setting = 1; |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 65 | else if (!strncmp("off", buf, count - 1) || |
| 66 | !strncmp("0", buf, count - 1)) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 67 | new_setting = 0; |
| 68 | else |
| 69 | return count; |
| 70 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 71 | |
| 72 | local_irq_save(flags); |
| 73 | lock_rx_qs(priv); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 74 | |
| 75 | /* Set the new stashing value */ |
| 76 | priv->bd_stash_en = new_setting; |
| 77 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 78 | temp = gfar_read(®s->attr); |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 79 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 80 | if (new_setting) |
| 81 | temp |= ATTR_BDSTASH; |
| 82 | else |
| 83 | temp &= ~(ATTR_BDSTASH); |
| 84 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 85 | gfar_write(®s->attr, temp); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 86 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 87 | unlock_rx_qs(priv); |
| 88 | local_irq_restore(flags); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 89 | |
| 90 | return count; |
| 91 | } |
| 92 | |
Anton Vorontsov | b2f66d1 | 2009-02-01 00:54:16 -0800 | [diff] [blame] | 93 | static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash); |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 94 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 95 | static ssize_t gfar_show_rx_stash_size(struct device *dev, |
| 96 | struct device_attribute *attr, char *buf) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 97 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 98 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 99 | |
| 100 | return sprintf(buf, "%d\n", priv->rx_stash_size); |
| 101 | } |
| 102 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 103 | static ssize_t gfar_set_rx_stash_size(struct device *dev, |
| 104 | struct device_attribute *attr, |
| 105 | const char *buf, size_t count) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 106 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 107 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 108 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 109 | unsigned int length = simple_strtoul(buf, NULL, 0); |
| 110 | u32 temp; |
| 111 | unsigned long flags; |
| 112 | |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 113 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) |
| 114 | return count; |
| 115 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 116 | local_irq_save(flags); |
| 117 | lock_rx_qs(priv); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 118 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 119 | if (length > priv->rx_buffer_size) |
Andy Fleming | f162b9d | 2008-05-02 13:00:30 -0500 | [diff] [blame] | 120 | goto out; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 121 | |
| 122 | if (length == priv->rx_stash_size) |
Andy Fleming | f162b9d | 2008-05-02 13:00:30 -0500 | [diff] [blame] | 123 | goto out; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 124 | |
| 125 | priv->rx_stash_size = length; |
| 126 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 127 | temp = gfar_read(®s->attreli); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 128 | temp &= ~ATTRELI_EL_MASK; |
| 129 | temp |= ATTRELI_EL(length); |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 130 | gfar_write(®s->attreli, temp); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 131 | |
| 132 | /* Turn stashing on/off as appropriate */ |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 133 | temp = gfar_read(®s->attr); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 134 | |
| 135 | if (length) |
| 136 | temp |= ATTR_BUFSTASH; |
| 137 | else |
| 138 | temp &= ~(ATTR_BUFSTASH); |
| 139 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 140 | gfar_write(®s->attr, temp); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 141 | |
Andy Fleming | f162b9d | 2008-05-02 13:00:30 -0500 | [diff] [blame] | 142 | out: |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 143 | unlock_rx_qs(priv); |
| 144 | local_irq_restore(flags); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 145 | |
| 146 | return count; |
| 147 | } |
| 148 | |
Anton Vorontsov | b2f66d1 | 2009-02-01 00:54:16 -0800 | [diff] [blame] | 149 | static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size, |
| 150 | gfar_set_rx_stash_size); |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 151 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 152 | /* Stashing will only be enabled when rx_stash_size != 0 */ |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 153 | static ssize_t gfar_show_rx_stash_index(struct device *dev, |
| 154 | struct device_attribute *attr, |
| 155 | char *buf) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 156 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 157 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 158 | |
| 159 | return sprintf(buf, "%d\n", priv->rx_stash_index); |
| 160 | } |
| 161 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 162 | static ssize_t gfar_set_rx_stash_index(struct device *dev, |
| 163 | struct device_attribute *attr, |
| 164 | const char *buf, size_t count) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 165 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 166 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 167 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 168 | unsigned short index = simple_strtoul(buf, NULL, 0); |
| 169 | u32 temp; |
| 170 | unsigned long flags; |
| 171 | |
Andy Fleming | 4d7902f | 2009-02-04 16:43:44 -0800 | [diff] [blame] | 172 | if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING)) |
| 173 | return count; |
| 174 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 175 | local_irq_save(flags); |
| 176 | lock_rx_qs(priv); |
Sandeep Gopalpet | a12f801 | 2009-11-02 07:03:00 +0000 | [diff] [blame] | 177 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 178 | if (index > priv->rx_stash_size) |
Andy Fleming | f162b9d | 2008-05-02 13:00:30 -0500 | [diff] [blame] | 179 | goto out; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 180 | |
| 181 | if (index == priv->rx_stash_index) |
Andy Fleming | f162b9d | 2008-05-02 13:00:30 -0500 | [diff] [blame] | 182 | goto out; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 183 | |
| 184 | priv->rx_stash_index = index; |
| 185 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 186 | temp = gfar_read(®s->attreli); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 187 | temp &= ~ATTRELI_EI_MASK; |
| 188 | temp |= ATTRELI_EI(index); |
Anton Vorontsov | 499428e | 2009-11-10 14:11:07 +0000 | [diff] [blame] | 189 | gfar_write(®s->attreli, temp); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 190 | |
Andy Fleming | f162b9d | 2008-05-02 13:00:30 -0500 | [diff] [blame] | 191 | out: |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 192 | unlock_rx_qs(priv); |
| 193 | local_irq_restore(flags); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 194 | |
| 195 | return count; |
| 196 | } |
| 197 | |
Anton Vorontsov | b2f66d1 | 2009-02-01 00:54:16 -0800 | [diff] [blame] | 198 | static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index, |
| 199 | gfar_set_rx_stash_index); |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 200 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 201 | static ssize_t gfar_show_fifo_threshold(struct device *dev, |
| 202 | struct device_attribute *attr, |
| 203 | char *buf) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 204 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 205 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 206 | |
| 207 | return sprintf(buf, "%d\n", priv->fifo_threshold); |
| 208 | } |
| 209 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 210 | static ssize_t gfar_set_fifo_threshold(struct device *dev, |
| 211 | struct device_attribute *attr, |
| 212 | const char *buf, size_t count) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 213 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 214 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 215 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 216 | 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 Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 223 | local_irq_save(flags); |
| 224 | lock_tx_qs(priv); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 225 | |
| 226 | priv->fifo_threshold = length; |
| 227 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 228 | temp = gfar_read(®s->fifo_tx_thr); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 229 | temp &= ~FIFO_TX_THR_MASK; |
| 230 | temp |= length; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 231 | gfar_write(®s->fifo_tx_thr, temp); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 232 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 233 | unlock_tx_qs(priv); |
| 234 | local_irq_restore(flags); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 235 | |
| 236 | return count; |
| 237 | } |
| 238 | |
Anton Vorontsov | b2f66d1 | 2009-02-01 00:54:16 -0800 | [diff] [blame] | 239 | static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold, |
| 240 | gfar_set_fifo_threshold); |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 241 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 242 | static ssize_t gfar_show_fifo_starve(struct device *dev, |
| 243 | struct device_attribute *attr, char *buf) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 244 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 245 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 246 | |
| 247 | return sprintf(buf, "%d\n", priv->fifo_starve); |
| 248 | } |
| 249 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 250 | static ssize_t gfar_set_fifo_starve(struct device *dev, |
| 251 | struct device_attribute *attr, |
| 252 | const char *buf, size_t count) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 253 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 254 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 255 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 256 | unsigned int num = simple_strtoul(buf, NULL, 0); |
| 257 | u32 temp; |
| 258 | unsigned long flags; |
| 259 | |
| 260 | if (num > GFAR_MAX_FIFO_STARVE) |
| 261 | return count; |
| 262 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 263 | local_irq_save(flags); |
| 264 | lock_tx_qs(priv); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 265 | |
| 266 | priv->fifo_starve = num; |
| 267 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 268 | temp = gfar_read(®s->fifo_tx_starve); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 269 | temp &= ~FIFO_TX_STARVE_MASK; |
| 270 | temp |= num; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 271 | gfar_write(®s->fifo_tx_starve, temp); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 272 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 273 | unlock_tx_qs(priv); |
| 274 | local_irq_restore(flags); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 275 | |
| 276 | return count; |
| 277 | } |
| 278 | |
Anton Vorontsov | b2f66d1 | 2009-02-01 00:54:16 -0800 | [diff] [blame] | 279 | static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve, |
| 280 | gfar_set_fifo_starve); |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 281 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 282 | static ssize_t gfar_show_fifo_starve_off(struct device *dev, |
| 283 | struct device_attribute *attr, |
| 284 | char *buf) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 285 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 286 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 287 | |
| 288 | return sprintf(buf, "%d\n", priv->fifo_starve_off); |
| 289 | } |
| 290 | |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 291 | static ssize_t gfar_set_fifo_starve_off(struct device *dev, |
| 292 | struct device_attribute *attr, |
| 293 | const char *buf, size_t count) |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 294 | { |
Kumar Gala | 4409d28 | 2007-02-12 23:40:06 -0600 | [diff] [blame] | 295 | struct gfar_private *priv = netdev_priv(to_net_dev(dev)); |
Sandeep Gopalpet | 46ceb60 | 2009-11-02 07:03:34 +0000 | [diff] [blame] | 296 | struct gfar __iomem *regs = priv->gfargrp[0].regs; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 297 | unsigned int num = simple_strtoul(buf, NULL, 0); |
| 298 | u32 temp; |
| 299 | unsigned long flags; |
| 300 | |
| 301 | if (num > GFAR_MAX_FIFO_STARVE_OFF) |
| 302 | return count; |
| 303 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 304 | local_irq_save(flags); |
| 305 | lock_tx_qs(priv); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 306 | |
| 307 | priv->fifo_starve_off = num; |
| 308 | |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 309 | temp = gfar_read(®s->fifo_tx_starve_shutoff); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 310 | temp &= ~FIFO_TX_STARVE_OFF_MASK; |
| 311 | temp |= num; |
Sandeep Gopalpet | f498370 | 2009-11-02 07:03:09 +0000 | [diff] [blame] | 312 | gfar_write(®s->fifo_tx_starve_shutoff, temp); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 313 | |
Sandeep Gopalpet | fba4ed0 | 2009-11-02 07:03:15 +0000 | [diff] [blame] | 314 | unlock_tx_qs(priv); |
| 315 | local_irq_restore(flags); |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 316 | |
| 317 | return count; |
| 318 | } |
| 319 | |
Anton Vorontsov | b2f66d1 | 2009-02-01 00:54:16 -0800 | [diff] [blame] | 320 | static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off, |
| 321 | gfar_set_fifo_starve_off); |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 322 | |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 323 | void gfar_init_sysfs(struct net_device *dev) |
| 324 | { |
| 325 | struct gfar_private *priv = netdev_priv(dev); |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 326 | int rc; |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 327 | |
| 328 | /* Initialize the default values */ |
Andy Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 329 | 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 Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 332 | |
| 333 | /* Create our sysfs files */ |
Grant Likely | 35a84fd | 2007-12-01 22:12:45 -0700 | [diff] [blame] | 334 | 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 Fleming | 7f7f531 | 2005-11-11 12:38:59 -0600 | [diff] [blame] | 342 | } |