gianfar_sysfs.c 8.0 KB

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