gianfar_sysfs.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. goto out;
  88. if (length == priv->rx_stash_size)
  89. goto out;
  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. out:
  103. spin_unlock_irqrestore(&priv->rxlock, flags);
  104. return count;
  105. }
  106. DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
  107. gfar_set_rx_stash_size);
  108. /* Stashing will only be enabled when rx_stash_size != 0 */
  109. static ssize_t gfar_show_rx_stash_index(struct device *dev,
  110. struct device_attribute *attr,
  111. char *buf)
  112. {
  113. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  114. return sprintf(buf, "%d\n", priv->rx_stash_index);
  115. }
  116. static ssize_t gfar_set_rx_stash_index(struct device *dev,
  117. struct device_attribute *attr,
  118. const char *buf, size_t count)
  119. {
  120. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  121. unsigned short index = simple_strtoul(buf, NULL, 0);
  122. u32 temp;
  123. unsigned long flags;
  124. spin_lock_irqsave(&priv->rxlock, flags);
  125. if (index > priv->rx_stash_size)
  126. goto out;
  127. if (index == priv->rx_stash_index)
  128. goto out;
  129. priv->rx_stash_index = index;
  130. temp = gfar_read(&priv->regs->attreli);
  131. temp &= ~ATTRELI_EI_MASK;
  132. temp |= ATTRELI_EI(index);
  133. gfar_write(&priv->regs->attreli, flags);
  134. out:
  135. spin_unlock_irqrestore(&priv->rxlock, flags);
  136. return count;
  137. }
  138. DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
  139. gfar_set_rx_stash_index);
  140. static ssize_t gfar_show_fifo_threshold(struct device *dev,
  141. struct device_attribute *attr,
  142. char *buf)
  143. {
  144. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  145. return sprintf(buf, "%d\n", priv->fifo_threshold);
  146. }
  147. static ssize_t gfar_set_fifo_threshold(struct device *dev,
  148. struct device_attribute *attr,
  149. const char *buf, size_t count)
  150. {
  151. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  152. unsigned int length = simple_strtoul(buf, NULL, 0);
  153. u32 temp;
  154. unsigned long flags;
  155. if (length > GFAR_MAX_FIFO_THRESHOLD)
  156. return count;
  157. spin_lock_irqsave(&priv->txlock, flags);
  158. priv->fifo_threshold = length;
  159. temp = gfar_read(&priv->regs->fifo_tx_thr);
  160. temp &= ~FIFO_TX_THR_MASK;
  161. temp |= length;
  162. gfar_write(&priv->regs->fifo_tx_thr, temp);
  163. spin_unlock_irqrestore(&priv->txlock, flags);
  164. return count;
  165. }
  166. DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
  167. gfar_set_fifo_threshold);
  168. static ssize_t gfar_show_fifo_starve(struct device *dev,
  169. struct device_attribute *attr, char *buf)
  170. {
  171. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  172. return sprintf(buf, "%d\n", priv->fifo_starve);
  173. }
  174. static ssize_t gfar_set_fifo_starve(struct device *dev,
  175. struct device_attribute *attr,
  176. const char *buf, size_t count)
  177. {
  178. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  179. unsigned int num = simple_strtoul(buf, NULL, 0);
  180. u32 temp;
  181. unsigned long flags;
  182. if (num > GFAR_MAX_FIFO_STARVE)
  183. return count;
  184. spin_lock_irqsave(&priv->txlock, flags);
  185. priv->fifo_starve = num;
  186. temp = gfar_read(&priv->regs->fifo_tx_starve);
  187. temp &= ~FIFO_TX_STARVE_MASK;
  188. temp |= num;
  189. gfar_write(&priv->regs->fifo_tx_starve, temp);
  190. spin_unlock_irqrestore(&priv->txlock, flags);
  191. return count;
  192. }
  193. DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve, gfar_set_fifo_starve);
  194. static ssize_t gfar_show_fifo_starve_off(struct device *dev,
  195. struct device_attribute *attr,
  196. char *buf)
  197. {
  198. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  199. return sprintf(buf, "%d\n", priv->fifo_starve_off);
  200. }
  201. static ssize_t gfar_set_fifo_starve_off(struct device *dev,
  202. struct device_attribute *attr,
  203. const char *buf, size_t count)
  204. {
  205. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  206. unsigned int num = simple_strtoul(buf, NULL, 0);
  207. u32 temp;
  208. unsigned long flags;
  209. if (num > GFAR_MAX_FIFO_STARVE_OFF)
  210. return count;
  211. spin_lock_irqsave(&priv->txlock, flags);
  212. priv->fifo_starve_off = num;
  213. temp = gfar_read(&priv->regs->fifo_tx_starve_shutoff);
  214. temp &= ~FIFO_TX_STARVE_OFF_MASK;
  215. temp |= num;
  216. gfar_write(&priv->regs->fifo_tx_starve_shutoff, temp);
  217. spin_unlock_irqrestore(&priv->txlock, flags);
  218. return count;
  219. }
  220. DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
  221. gfar_set_fifo_starve_off);
  222. void gfar_init_sysfs(struct net_device *dev)
  223. {
  224. struct gfar_private *priv = netdev_priv(dev);
  225. int rc;
  226. /* Initialize the default values */
  227. priv->rx_stash_size = DEFAULT_STASH_LENGTH;
  228. priv->rx_stash_index = DEFAULT_STASH_INDEX;
  229. priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
  230. priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
  231. priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
  232. priv->bd_stash_en = DEFAULT_BD_STASH;
  233. /* Create our sysfs files */
  234. rc = device_create_file(&dev->dev, &dev_attr_bd_stash);
  235. rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size);
  236. rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index);
  237. rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold);
  238. rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve);
  239. rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off);
  240. if (rc)
  241. dev_err(&dev->dev, "Error creating gianfar sysfs files.\n");
  242. }