gianfar_sysfs.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /*
  2. * drivers/net/ethernet/freescale/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. * Modifier: Sandeep Gopalpet <sandeep.kumar@freescale.com>
  12. *
  13. * Copyright 2002-2009 Freescale Semiconductor, Inc.
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2 of the License, or (at your
  18. * option) any later version.
  19. *
  20. * Sysfs file creation and management
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/string.h>
  24. #include <linux/errno.h>
  25. #include <linux/unistd.h>
  26. #include <linux/delay.h>
  27. #include <linux/etherdevice.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/mm.h>
  30. #include <linux/device.h>
  31. #include <asm/uaccess.h>
  32. #include <linux/module.h>
  33. #include "gianfar.h"
  34. static ssize_t gfar_show_bd_stash(struct device *dev,
  35. struct device_attribute *attr, char *buf)
  36. {
  37. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  38. return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
  39. }
  40. static ssize_t gfar_set_bd_stash(struct device *dev,
  41. struct device_attribute *attr,
  42. const char *buf, size_t count)
  43. {
  44. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  45. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  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. local_irq_save(flags);
  60. lock_rx_qs(priv);
  61. /* Set the new stashing value */
  62. priv->bd_stash_en = new_setting;
  63. temp = gfar_read(&regs->attr);
  64. if (new_setting)
  65. temp |= ATTR_BDSTASH;
  66. else
  67. temp &= ~(ATTR_BDSTASH);
  68. gfar_write(&regs->attr, temp);
  69. unlock_rx_qs(priv);
  70. local_irq_restore(flags);
  71. return count;
  72. }
  73. static DEVICE_ATTR(bd_stash, 0644, gfar_show_bd_stash, gfar_set_bd_stash);
  74. static ssize_t gfar_show_rx_stash_size(struct device *dev,
  75. struct device_attribute *attr, char *buf)
  76. {
  77. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  78. return sprintf(buf, "%d\n", priv->rx_stash_size);
  79. }
  80. static ssize_t gfar_set_rx_stash_size(struct device *dev,
  81. struct device_attribute *attr,
  82. const char *buf, size_t count)
  83. {
  84. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  85. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  86. unsigned int length = simple_strtoul(buf, NULL, 0);
  87. u32 temp;
  88. unsigned long flags;
  89. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
  90. return count;
  91. local_irq_save(flags);
  92. lock_rx_qs(priv);
  93. if (length > priv->rx_buffer_size)
  94. goto out;
  95. if (length == priv->rx_stash_size)
  96. goto out;
  97. priv->rx_stash_size = length;
  98. temp = gfar_read(&regs->attreli);
  99. temp &= ~ATTRELI_EL_MASK;
  100. temp |= ATTRELI_EL(length);
  101. gfar_write(&regs->attreli, temp);
  102. /* Turn stashing on/off as appropriate */
  103. temp = gfar_read(&regs->attr);
  104. if (length)
  105. temp |= ATTR_BUFSTASH;
  106. else
  107. temp &= ~(ATTR_BUFSTASH);
  108. gfar_write(&regs->attr, temp);
  109. out:
  110. unlock_rx_qs(priv);
  111. local_irq_restore(flags);
  112. return count;
  113. }
  114. static DEVICE_ATTR(rx_stash_size, 0644, gfar_show_rx_stash_size,
  115. gfar_set_rx_stash_size);
  116. /* Stashing will only be enabled when rx_stash_size != 0 */
  117. static ssize_t gfar_show_rx_stash_index(struct device *dev,
  118. struct device_attribute *attr,
  119. char *buf)
  120. {
  121. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  122. return sprintf(buf, "%d\n", priv->rx_stash_index);
  123. }
  124. static ssize_t gfar_set_rx_stash_index(struct device *dev,
  125. struct device_attribute *attr,
  126. const char *buf, size_t count)
  127. {
  128. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  129. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  130. unsigned short index = simple_strtoul(buf, NULL, 0);
  131. u32 temp;
  132. unsigned long flags;
  133. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
  134. return count;
  135. local_irq_save(flags);
  136. lock_rx_qs(priv);
  137. if (index > priv->rx_stash_size)
  138. goto out;
  139. if (index == priv->rx_stash_index)
  140. goto out;
  141. priv->rx_stash_index = index;
  142. temp = gfar_read(&regs->attreli);
  143. temp &= ~ATTRELI_EI_MASK;
  144. temp |= ATTRELI_EI(index);
  145. gfar_write(&regs->attreli, temp);
  146. out:
  147. unlock_rx_qs(priv);
  148. local_irq_restore(flags);
  149. return count;
  150. }
  151. static DEVICE_ATTR(rx_stash_index, 0644, gfar_show_rx_stash_index,
  152. gfar_set_rx_stash_index);
  153. static ssize_t gfar_show_fifo_threshold(struct device *dev,
  154. struct device_attribute *attr,
  155. char *buf)
  156. {
  157. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  158. return sprintf(buf, "%d\n", priv->fifo_threshold);
  159. }
  160. static ssize_t gfar_set_fifo_threshold(struct device *dev,
  161. struct device_attribute *attr,
  162. const char *buf, size_t count)
  163. {
  164. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  165. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  166. unsigned int length = simple_strtoul(buf, NULL, 0);
  167. u32 temp;
  168. unsigned long flags;
  169. if (length > GFAR_MAX_FIFO_THRESHOLD)
  170. return count;
  171. local_irq_save(flags);
  172. lock_tx_qs(priv);
  173. priv->fifo_threshold = length;
  174. temp = gfar_read(&regs->fifo_tx_thr);
  175. temp &= ~FIFO_TX_THR_MASK;
  176. temp |= length;
  177. gfar_write(&regs->fifo_tx_thr, temp);
  178. unlock_tx_qs(priv);
  179. local_irq_restore(flags);
  180. return count;
  181. }
  182. static DEVICE_ATTR(fifo_threshold, 0644, gfar_show_fifo_threshold,
  183. gfar_set_fifo_threshold);
  184. static ssize_t gfar_show_fifo_starve(struct device *dev,
  185. struct device_attribute *attr, char *buf)
  186. {
  187. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  188. return sprintf(buf, "%d\n", priv->fifo_starve);
  189. }
  190. static ssize_t gfar_set_fifo_starve(struct device *dev,
  191. struct device_attribute *attr,
  192. const char *buf, size_t count)
  193. {
  194. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  195. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  196. unsigned int num = simple_strtoul(buf, NULL, 0);
  197. u32 temp;
  198. unsigned long flags;
  199. if (num > GFAR_MAX_FIFO_STARVE)
  200. return count;
  201. local_irq_save(flags);
  202. lock_tx_qs(priv);
  203. priv->fifo_starve = num;
  204. temp = gfar_read(&regs->fifo_tx_starve);
  205. temp &= ~FIFO_TX_STARVE_MASK;
  206. temp |= num;
  207. gfar_write(&regs->fifo_tx_starve, temp);
  208. unlock_tx_qs(priv);
  209. local_irq_restore(flags);
  210. return count;
  211. }
  212. static DEVICE_ATTR(fifo_starve, 0644, gfar_show_fifo_starve,
  213. gfar_set_fifo_starve);
  214. static ssize_t gfar_show_fifo_starve_off(struct device *dev,
  215. struct device_attribute *attr,
  216. char *buf)
  217. {
  218. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  219. return sprintf(buf, "%d\n", priv->fifo_starve_off);
  220. }
  221. static ssize_t gfar_set_fifo_starve_off(struct device *dev,
  222. struct device_attribute *attr,
  223. const char *buf, size_t count)
  224. {
  225. struct gfar_private *priv = netdev_priv(to_net_dev(dev));
  226. struct gfar __iomem *regs = priv->gfargrp[0].regs;
  227. unsigned int num = simple_strtoul(buf, NULL, 0);
  228. u32 temp;
  229. unsigned long flags;
  230. if (num > GFAR_MAX_FIFO_STARVE_OFF)
  231. return count;
  232. local_irq_save(flags);
  233. lock_tx_qs(priv);
  234. priv->fifo_starve_off = num;
  235. temp = gfar_read(&regs->fifo_tx_starve_shutoff);
  236. temp &= ~FIFO_TX_STARVE_OFF_MASK;
  237. temp |= num;
  238. gfar_write(&regs->fifo_tx_starve_shutoff, temp);
  239. unlock_tx_qs(priv);
  240. local_irq_restore(flags);
  241. return count;
  242. }
  243. static DEVICE_ATTR(fifo_starve_off, 0644, gfar_show_fifo_starve_off,
  244. gfar_set_fifo_starve_off);
  245. void gfar_init_sysfs(struct net_device *dev)
  246. {
  247. struct gfar_private *priv = netdev_priv(dev);
  248. int rc;
  249. /* Initialize the default values */
  250. priv->fifo_threshold = DEFAULT_FIFO_TX_THR;
  251. priv->fifo_starve = DEFAULT_FIFO_TX_STARVE;
  252. priv->fifo_starve_off = DEFAULT_FIFO_TX_STARVE_OFF;
  253. /* Create our sysfs files */
  254. rc = device_create_file(&dev->dev, &dev_attr_bd_stash);
  255. rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_size);
  256. rc |= device_create_file(&dev->dev, &dev_attr_rx_stash_index);
  257. rc |= device_create_file(&dev->dev, &dev_attr_fifo_threshold);
  258. rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve);
  259. rc |= device_create_file(&dev->dev, &dev_attr_fifo_starve_off);
  260. if (rc)
  261. dev_err(&dev->dev, "Error creating gianfar sysfs files\n");
  262. }