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