gianfar_sysfs.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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
  10. * Maintainer: Kumar Gala (galak@kernel.crashing.org)
  11. *
  12. * Copyright (c) 2002-2005 Freescale Semiconductor, Inc.
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the
  16. * Free Software Foundation; either version 2 of the License, or (at your
  17. * option) any later version.
  18. *
  19. * Sysfs file creation and management
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/string.h>
  23. #include <linux/errno.h>
  24. #include <linux/unistd.h>
  25. #include <linux/slab.h>
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/etherdevice.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/mm.h>
  31. #include <linux/device.h>
  32. #include <asm/uaccess.h>
  33. #include <linux/module.h>
  34. #include <linux/version.h>
  35. #include "gianfar.h"
  36. #define GFAR_ATTR(_name) \
  37. static ssize_t gfar_show_##_name(struct device *dev, \
  38. struct device_attribute *attr, char *buf); \
  39. static ssize_t gfar_set_##_name(struct device *dev, \
  40. struct device_attribute *attr, \
  41. const char *buf, size_t count); \
  42. static DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name)
  43. #define GFAR_CREATE_FILE(_dev, _name) \
  44. device_create_file(&_dev->dev, &dev_attr_##_name)
  45. GFAR_ATTR(bd_stash);
  46. GFAR_ATTR(rx_stash_size);
  47. GFAR_ATTR(rx_stash_index);
  48. GFAR_ATTR(fifo_threshold);
  49. GFAR_ATTR(fifo_starve);
  50. GFAR_ATTR(fifo_starve_off);
  51. static ssize_t gfar_show_bd_stash(struct device *dev,
  52. struct device_attribute *attr, char *buf)
  53. {
  54. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  55. return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
  56. }
  57. static ssize_t gfar_set_bd_stash(struct device *dev,
  58. struct device_attribute *attr,
  59. const char *buf, size_t count)
  60. {
  61. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  62. int new_setting = 0;
  63. u32 temp;
  64. unsigned long flags;
  65. /* Find out the new setting */
  66. if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
  67. new_setting = 1;
  68. else if (!strncmp("off", buf, count - 1)
  69. || !strncmp("0", buf, count - 1))
  70. new_setting = 0;
  71. else
  72. return count;
  73. spin_lock_irqsave(&priv->rxlock, flags);
  74. /* Set the new stashing value */
  75. priv->bd_stash_en = new_setting;
  76. temp = gfar_read(&priv->regs->attr);
  77. if (new_setting)
  78. temp |= ATTR_BDSTASH;
  79. else
  80. temp &= ~(ATTR_BDSTASH);
  81. gfar_write(&priv->regs->attr, temp);
  82. spin_unlock_irqrestore(&priv->rxlock, flags);
  83. return count;
  84. }
  85. static ssize_t gfar_show_rx_stash_size(struct device *dev,
  86. struct device_attribute *attr, char *buf)
  87. {
  88. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  89. return sprintf(buf, "%d\n", priv->rx_stash_size);
  90. }
  91. static ssize_t gfar_set_rx_stash_size(struct device *dev,
  92. struct device_attribute *attr,
  93. const char *buf, size_t count)
  94. {
  95. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  96. unsigned int length = simple_strtoul(buf, NULL, 0);
  97. u32 temp;
  98. unsigned long flags;
  99. spin_lock_irqsave(&priv->rxlock, flags);
  100. if (length > priv->rx_buffer_size)
  101. return count;
  102. if (length == priv->rx_stash_size)
  103. return count;
  104. priv->rx_stash_size = length;
  105. temp = gfar_read(&priv->regs->attreli);
  106. temp &= ~ATTRELI_EL_MASK;
  107. temp |= ATTRELI_EL(length);
  108. gfar_write(&priv->regs->attreli, temp);
  109. /* Turn stashing on/off as appropriate */
  110. temp = gfar_read(&priv->regs->attr);
  111. if (length)
  112. temp |= ATTR_BUFSTASH;
  113. else
  114. temp &= ~(ATTR_BUFSTASH);
  115. gfar_write(&priv->regs->attr, temp);
  116. spin_unlock_irqrestore(&priv->rxlock, flags);
  117. return count;
  118. }
  119. /* Stashing will only be enabled when rx_stash_size != 0 */
  120. static ssize_t gfar_show_rx_stash_index(struct device *dev,
  121. struct device_attribute *attr,
  122. char *buf)
  123. {
  124. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  125. return sprintf(buf, "%d\n", priv->rx_stash_index);
  126. }
  127. static ssize_t gfar_set_rx_stash_index(struct device *dev,
  128. struct device_attribute *attr,
  129. const char *buf, size_t count)
  130. {
  131. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  132. unsigned short index = simple_strtoul(buf, NULL, 0);
  133. u32 temp;
  134. unsigned long flags;
  135. spin_lock_irqsave(&priv->rxlock, flags);
  136. if (index > priv->rx_stash_size)
  137. return count;
  138. if (index == priv->rx_stash_index)
  139. return count;
  140. priv->rx_stash_index = index;
  141. temp = gfar_read(&priv->regs->attreli);
  142. temp &= ~ATTRELI_EI_MASK;
  143. temp |= ATTRELI_EI(index);
  144. gfar_write(&priv->regs->attreli, flags);
  145. spin_unlock_irqrestore(&priv->rxlock, flags);
  146. return count;
  147. }
  148. static ssize_t gfar_show_fifo_threshold(struct device *dev,
  149. struct device_attribute *attr,
  150. char *buf)
  151. {
  152. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  153. return sprintf(buf, "%d\n", priv->fifo_threshold);
  154. }
  155. static ssize_t gfar_set_fifo_threshold(struct device *dev,
  156. struct device_attribute *attr,
  157. const char *buf, size_t count)
  158. {
  159. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  160. unsigned int length = simple_strtoul(buf, NULL, 0);
  161. u32 temp;
  162. unsigned long flags;
  163. if (length > GFAR_MAX_FIFO_THRESHOLD)
  164. return count;
  165. spin_lock_irqsave(&priv->txlock, flags);
  166. priv->fifo_threshold = length;
  167. temp = gfar_read(&priv->regs->fifo_tx_thr);
  168. temp &= ~FIFO_TX_THR_MASK;
  169. temp |= length;
  170. gfar_write(&priv->regs->fifo_tx_thr, temp);
  171. spin_unlock_irqrestore(&priv->txlock, flags);
  172. return count;
  173. }
  174. static ssize_t gfar_show_fifo_starve(struct device *dev,
  175. struct device_attribute *attr, char *buf)
  176. {
  177. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  178. return sprintf(buf, "%d\n", priv->fifo_starve);
  179. }
  180. static ssize_t gfar_set_fifo_starve(struct device *dev,
  181. struct device_attribute *attr,
  182. const char *buf, size_t count)
  183. {
  184. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  185. unsigned int num = simple_strtoul(buf, NULL, 0);
  186. u32 temp;
  187. unsigned long flags;
  188. if (num > GFAR_MAX_FIFO_STARVE)
  189. return count;
  190. spin_lock_irqsave(&priv->txlock, flags);
  191. priv->fifo_starve = num;
  192. temp = gfar_read(&priv->regs->fifo_tx_starve);
  193. temp &= ~FIFO_TX_STARVE_MASK;
  194. temp |= num;
  195. gfar_write(&priv->regs->fifo_tx_starve, temp);
  196. spin_unlock_irqrestore(&priv->txlock, flags);
  197. return count;
  198. }
  199. static ssize_t gfar_show_fifo_starve_off(struct device *dev,
  200. struct device_attribute *attr,
  201. char *buf)
  202. {
  203. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  204. return sprintf(buf, "%d\n", priv->fifo_starve_off);
  205. }
  206. static ssize_t gfar_set_fifo_starve_off(struct device *dev,
  207. struct device_attribute *attr,
  208. const char *buf, size_t count)
  209. {
  210. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  211. unsigned int num = simple_strtoul(buf, NULL, 0);
  212. u32 temp;
  213. unsigned long flags;
  214. if (num > GFAR_MAX_FIFO_STARVE_OFF)
  215. return count;
  216. spin_lock_irqsave(&priv->txlock, flags);
  217. priv->fifo_starve_off = num;
  218. temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
  219. temp &= ~FIFO_TX_STARVE_OFF_MASK;
  220. temp |= num;
  221. gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
  222. spin_unlock_irqrestore(&priv->txlock, flags);
  223. return count;
  224. }
  225. void gfar_init_sysfs(struct net_device *dev)
  226. {
  227. struct gfar_private *priv = netdev_priv(dev);
  228. /* Initialize the default values */
  229. priv->rx_stash_size = DEFAULT_STASH_LENGTH;
  230. priv->rx_stash_index = DEFAULT_STASH_INDEX;
  231. priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
  232. priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
  233. priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
  234. priv->bd_stash_en = DEFAULT_BD_STASH;
  235. /* Create our sysfs files */
  236. GFAR_CREATE_FILE(dev, bd_stash);
  237. GFAR_CREATE_FILE(dev, rx_stash_size);
  238. GFAR_CREATE_FILE(dev, rx_stash_index);
  239. GFAR_CREATE_FILE(dev, fifo_threshold);
  240. GFAR_CREATE_FILE(dev, fifo_starve);
  241. GFAR_CREATE_FILE(dev, fifo_starve_off);
  242. }