gianfar_sysfs.c 8.3 KB

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