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