gianfar_sysfs.c 7.8 KB

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