gianfar_sysfs.c 8.3 KB

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