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/config.h>
  22. #include <linux/kernel.h>
  23. #include <linux/sched.h>
  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. #include <asm/uaccess.h>
  35. #include <linux/module.h>
  36. #include <linux/version.h>
  37. #include "gianfar.h"
  38. #define GFAR_ATTR(_name) \
  39. static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \
  40. static ssize_t gfar_set_##_name(struct class_device *cdev, \
  41. const char *buf, size_t count); \
  42. static CLASS_DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name)
  43. #define GFAR_CREATE_FILE(_dev, _name) \
  44. class_device_create_file(&_dev->class_dev, &class_device_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. #define to_net_dev(cd) container_of(cd, struct net_device, class_dev)
  52. static ssize_t gfar_show_bd_stash(struct class_device *cdev, char *buf)
  53. {
  54. struct net_device *dev = to_net_dev(cdev);
  55. struct gfar_private *priv = netdev_priv(dev);
  56. return sprintf(buf, "%s\n", priv->bd_stash_en? "on" : "off");
  57. }
  58. static ssize_t gfar_set_bd_stash(struct class_device *cdev,
  59. const char *buf, size_t count)
  60. {
  61. struct net_device *dev = to_net_dev(cdev);
  62. struct gfar_private *priv = netdev_priv(dev);
  63. int new_setting = 0;
  64. u32 temp;
  65. unsigned long flags;
  66. /* Find out the new setting */
  67. if (!strncmp("on", buf, count-1) || !strncmp("1", buf, count-1))
  68. new_setting = 1;
  69. else if (!strncmp("off", buf, count-1) || !strncmp("0", buf, count-1))
  70. new_setting = 0;
  71. else
  72. return count;
  73. spin_lock_irqsave(&priv->lock, 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->lock, flags);
  83. return count;
  84. }
  85. static ssize_t gfar_show_rx_stash_size(struct class_device *cdev, char *buf)
  86. {
  87. struct net_device *dev = to_net_dev(cdev);
  88. struct gfar_private *priv = netdev_priv(dev);
  89. return sprintf(buf, "%d\n", priv->rx_stash_size);
  90. }
  91. static ssize_t gfar_set_rx_stash_size(struct class_device *cdev,
  92. const char *buf, size_t count)
  93. {
  94. struct net_device *dev = to_net_dev(cdev);
  95. struct gfar_private *priv = netdev_priv(dev);
  96. unsigned int length = simple_strtoul(buf, NULL, 0);
  97. u32 temp;
  98. unsigned long flags;
  99. spin_lock_irqsave(&priv->lock, 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->lock, 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 class_device *cdev, char *buf)
  121. {
  122. struct net_device *dev = to_net_dev(cdev);
  123. struct gfar_private *priv = netdev_priv(dev);
  124. return sprintf(buf, "%d\n", priv->rx_stash_index);
  125. }
  126. static ssize_t gfar_set_rx_stash_index(struct class_device *cdev,
  127. const char *buf, size_t count)
  128. {
  129. struct net_device *dev = to_net_dev(cdev);
  130. struct gfar_private *priv = netdev_priv(dev);
  131. unsigned short index = simple_strtoul(buf, NULL, 0);
  132. u32 temp;
  133. unsigned long flags;
  134. spin_lock_irqsave(&priv->lock, flags);
  135. if (index > priv->rx_stash_size)
  136. return count;
  137. if (index == priv->rx_stash_index)
  138. return count;
  139. priv->rx_stash_index = index;
  140. temp = gfar_read(&priv->regs->attreli);
  141. temp &= ~ATTRELI_EI_MASK;
  142. temp |= ATTRELI_EI(index);
  143. gfar_write(&priv->regs->attreli, flags);
  144. spin_unlock_irqrestore(&priv->lock, flags);
  145. return count;
  146. }
  147. static ssize_t gfar_show_fifo_threshold(struct class_device *cdev, char *buf)
  148. {
  149. struct net_device *dev = to_net_dev(cdev);
  150. struct gfar_private *priv = netdev_priv(dev);
  151. return sprintf(buf, "%d\n", priv->fifo_threshold);
  152. }
  153. static ssize_t gfar_set_fifo_threshold(struct class_device *cdev,
  154. const char *buf, size_t count)
  155. {
  156. struct net_device *dev = to_net_dev(cdev);
  157. struct gfar_private *priv = netdev_priv(dev);
  158. unsigned int length = simple_strtoul(buf, NULL, 0);
  159. u32 temp;
  160. unsigned long flags;
  161. if (length > GFAR_MAX_FIFO_THRESHOLD)
  162. return count;
  163. spin_lock_irqsave(&priv->lock, flags);
  164. priv->fifo_threshold = length;
  165. temp = gfar_read(&priv->regs->fifo_tx_thr);
  166. temp &= ~FIFO_TX_THR_MASK;
  167. temp |= length;
  168. gfar_write(&priv->regs->fifo_tx_thr, temp);
  169. spin_unlock_irqrestore(&priv->lock, flags);
  170. return count;
  171. }
  172. static ssize_t gfar_show_fifo_starve(struct class_device *cdev, char *buf)
  173. {
  174. struct net_device *dev = to_net_dev(cdev);
  175. struct gfar_private *priv = netdev_priv(dev);
  176. return sprintf(buf, "%d\n", priv->fifo_starve);
  177. }
  178. static ssize_t gfar_set_fifo_starve(struct class_device *cdev,
  179. const char *buf, size_t count)
  180. {
  181. struct net_device *dev = to_net_dev(cdev);
  182. struct gfar_private *priv = netdev_priv(dev);
  183. unsigned int num = simple_strtoul(buf, NULL, 0);
  184. u32 temp;
  185. unsigned long flags;
  186. if (num > GFAR_MAX_FIFO_STARVE)
  187. return count;
  188. spin_lock_irqsave(&priv->lock, flags);
  189. priv->fifo_starve = num;
  190. temp = gfar_read(&priv->regs->fifo_tx_starve);
  191. temp &= ~FIFO_TX_STARVE_MASK;
  192. temp |= num;
  193. gfar_write(&priv->regs->fifo_tx_starve, temp);
  194. spin_unlock_irqrestore(&priv->lock, flags);
  195. return count;
  196. }
  197. static ssize_t gfar_show_fifo_starve_off(struct class_device *cdev, char *buf)
  198. {
  199. struct net_device *dev = to_net_dev(cdev);
  200. struct gfar_private *priv = netdev_priv(dev);
  201. return sprintf(buf, "%d\n", priv->fifo_starve_off);
  202. }
  203. static ssize_t gfar_set_fifo_starve_off(struct class_device *cdev,
  204. const char *buf, size_t count)
  205. {
  206. struct net_device *dev = to_net_dev(cdev);
  207. struct gfar_private *priv = netdev_priv(dev);
  208. unsigned int num = simple_strtoul(buf, NULL, 0);
  209. u32 temp;
  210. unsigned long flags;
  211. if (num > GFAR_MAX_FIFO_STARVE_OFF)
  212. return count;
  213. spin_lock_irqsave(&priv->lock, flags);
  214. priv->fifo_starve_off = num;
  215. temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
  216. temp &= ~FIFO_TX_STARVE_OFF_MASK;
  217. temp |= num;
  218. gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
  219. spin_unlock_irqrestore(&priv->lock, flags);
  220. return count;
  221. }
  222. void gfar_init_sysfs(struct net_device *dev)
  223. {
  224. struct gfar_private *priv = netdev_priv(dev);
  225. /* Initialize the default values */
  226. priv->rx_stash_size = DEFAULT_STASH_LENGTH;
  227. priv->rx_stash_index = DEFAULT_STASH_INDEX;
  228. priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
  229. priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
  230. priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
  231. priv->bd_stash_en = DEFAULT_BD_STASH;
  232. /* Create our sysfs files */
  233. GFAR_CREATE_FILE(dev, bd_stash);
  234. GFAR_CREATE_FILE(dev, rx_stash_size);
  235. GFAR_CREATE_FILE(dev, rx_stash_index);
  236. GFAR_CREATE_FILE(dev, fifo_threshold);
  237. GFAR_CREATE_FILE(dev, fifo_starve);
  238. GFAR_CREATE_FILE(dev, fifo_starve_off);
  239. }