gianfar_sysfs.c 7.8 KB

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