gianfar_sysfs.c 8.8 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.regs;
  48. struct gfar_priv_rx_q *rx_queue = NULL;
  49. int new_setting = 0;
  50. u32 temp;
  51. unsigned long flags;
  52. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BD_STASHING))
  53. return count;
  54. rx_queue = priv->rx_queue;
  55. /* Find out the new setting */
  56. if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
  57. new_setting = 1;
  58. else if (!strncmp("off", buf, count - 1)
  59. || !strncmp("0", buf, count - 1))
  60. new_setting = 0;
  61. else
  62. return count;
  63. spin_lock_irqsave(&rx_queue->rxlock, flags);
  64. /* Set the new stashing value */
  65. priv->bd_stash_en = new_setting;
  66. temp = gfar_read(&regs->attr);
  67. if (new_setting)
  68. temp |= ATTR_BDSTASH;
  69. else
  70. temp &= ~(ATTR_BDSTASH);
  71. gfar_write(&regs->attr, temp);
  72. spin_unlock_irqrestore(&rx_queue->rxlock, 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.regs;
  88. struct gfar_priv_rx_q *rx_queue = NULL;
  89. unsigned int length = simple_strtoul(buf, NULL, 0);
  90. u32 temp;
  91. unsigned long flags;
  92. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
  93. return count;
  94. rx_queue = priv->rx_queue;
  95. spin_lock_irqsave(&rx_queue->rxlock, flags);
  96. if (length > priv->rx_buffer_size)
  97. goto out;
  98. if (length == priv->rx_stash_size)
  99. goto out;
  100. priv->rx_stash_size = length;
  101. temp = gfar_read(&regs->attreli);
  102. temp &= ~ATTRELI_EL_MASK;
  103. temp |= ATTRELI_EL(length);
  104. gfar_write(&regs->attreli, temp);
  105. /* Turn stashing on/off as appropriate */
  106. temp = gfar_read(&regs->attr);
  107. if (length)
  108. temp |= ATTR_BUFSTASH;
  109. else
  110. temp &= ~(ATTR_BUFSTASH);
  111. gfar_write(&regs->attr, temp);
  112. out:
  113. spin_unlock_irqrestore(&rx_queue->rxlock, 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.regs;
  132. struct gfar_priv_rx_q *rx_queue = NULL;
  133. unsigned short index = simple_strtoul(buf, NULL, 0);
  134. u32 temp;
  135. unsigned long flags;
  136. if (!(priv->device_flags & FSL_GIANFAR_DEV_HAS_BUF_STASHING))
  137. return count;
  138. rx_queue = priv->rx_queue;
  139. spin_lock_irqsave(&rx_queue->rxlock, flags);
  140. if (index > priv->rx_stash_size)
  141. goto out;
  142. if (index == priv->rx_stash_index)
  143. goto out;
  144. priv->rx_stash_index = index;
  145. temp = gfar_read(&regs->attreli);
  146. temp &= ~ATTRELI_EI_MASK;
  147. temp |= ATTRELI_EI(index);
  148. gfar_write(&regs->attreli, flags);
  149. out:
  150. spin_unlock_irqrestore(&rx_queue->rxlock, 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.regs;
  168. struct gfar_priv_tx_q *tx_queue = NULL;
  169. unsigned int length = simple_strtoul(buf, NULL, 0);
  170. u32 temp;
  171. unsigned long flags;
  172. if (length > GFAR_MAX_FIFO_THRESHOLD)
  173. return count;
  174. tx_queue = priv->tx_queue;
  175. spin_lock_irqsave(&tx_queue->txlock, flags);
  176. priv->fifo_threshold = length;
  177. temp = gfar_read(&regs->fifo_tx_thr);
  178. temp &= ~FIFO_TX_THR_MASK;
  179. temp |= length;
  180. gfar_write(&regs->fifo_tx_thr, temp);
  181. spin_unlock_irqrestore(&tx_queue->txlock, 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.regs;
  198. struct gfar_priv_tx_q *tx_queue = NULL;
  199. unsigned int num = simple_strtoul(buf, NULL, 0);
  200. u32 temp;
  201. unsigned long flags;
  202. if (num > GFAR_MAX_FIFO_STARVE)
  203. return count;
  204. tx_queue = priv->tx_queue;
  205. spin_lock_irqsave(&tx_queue->txlock, flags);
  206. priv->fifo_starve = num;
  207. temp = gfar_read(&regs->fifo_tx_starve);
  208. temp &= ~FIFO_TX_STARVE_MASK;
  209. temp |= num;
  210. gfar_write(&regs->fifo_tx_starve, temp);
  211. spin_unlock_irqrestore(&tx_queue->txlock, 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.regs;
  229. struct gfar_priv_tx_q *tx_queue = NULL;
  230. unsigned int num = simple_strtoul(buf, NULL, 0);
  231. u32 temp;
  232. unsigned long flags;
  233. if (num > GFAR_MAX_FIFO_STARVE_OFF)
  234. return count;
  235. tx_queue = priv->tx_queue;
  236. spin_lock_irqsave(&tx_queue->txlock, flags);
  237. priv->fifo_starve_off = num;
  238. temp = gfar_read(&regs->fifo_tx_starve_shutoff);
  239. temp &= ~FIFO_TX_STARVE_OFF_MASK;
  240. temp |= num;
  241. gfar_write(&regs->fifo_tx_starve_shutoff, temp);
  242. spin_unlock_irqrestore(&tx_queue->txlock, 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. }