dpaa_eth_sysfs.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* Copyright 2008-2016 Freescale Semiconductor Inc.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions are met:
  5. * * Redistributions of source code must retain the above copyright
  6. * notice, this list of conditions and the following disclaimer.
  7. * * Redistributions in binary form must reproduce the above copyright
  8. * notice, this list of conditions and the following disclaimer in the
  9. * documentation and/or other materials provided with the distribution.
  10. * * Neither the name of Freescale Semiconductor nor the
  11. * names of its contributors may be used to endorse or promote products
  12. * derived from this software without specific prior written permission.
  13. *
  14. *
  15. * ALTERNATIVELY, this software may be distributed under the terms of the
  16. * GNU General Public License ("GPL") as published by the Free Software
  17. * Foundation, either version 2 of that License or (at your option) any
  18. * later version.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
  21. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #include <linux/init.h>
  32. #include <linux/module.h>
  33. #include <linux/io.h>
  34. #include <linux/of_net.h>
  35. #include "dpaa_eth.h"
  36. #include "mac.h"
  37. static ssize_t dpaa_eth_show_addr(struct device *dev,
  38. struct device_attribute *attr, char *buf)
  39. {
  40. struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
  41. struct mac_device *mac_dev = priv->mac_dev;
  42. if (mac_dev)
  43. return sprintf(buf, "%llx",
  44. (unsigned long long)mac_dev->res->start);
  45. else
  46. return sprintf(buf, "none");
  47. }
  48. static ssize_t dpaa_eth_show_fqids(struct device *dev,
  49. struct device_attribute *attr, char *buf)
  50. {
  51. struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
  52. struct dpaa_fq *prev = NULL;
  53. char *prevstr = NULL;
  54. struct dpaa_fq *tmp;
  55. struct dpaa_fq *fq;
  56. u32 first_fqid = 0;
  57. u32 last_fqid = 0;
  58. ssize_t bytes = 0;
  59. char *str;
  60. int i = 0;
  61. list_for_each_entry_safe(fq, tmp, &priv->dpaa_fq_list, list) {
  62. switch (fq->fq_type) {
  63. case FQ_TYPE_RX_DEFAULT:
  64. str = "Rx default";
  65. break;
  66. case FQ_TYPE_RX_ERROR:
  67. str = "Rx error";
  68. break;
  69. case FQ_TYPE_TX_CONFIRM:
  70. str = "Tx default confirmation";
  71. break;
  72. case FQ_TYPE_TX_CONF_MQ:
  73. str = "Tx confirmation (mq)";
  74. break;
  75. case FQ_TYPE_TX_ERROR:
  76. str = "Tx error";
  77. break;
  78. case FQ_TYPE_TX:
  79. str = "Tx";
  80. break;
  81. default:
  82. str = "Unknown";
  83. }
  84. if (prev && (abs(fq->fqid - prev->fqid) != 1 ||
  85. str != prevstr)) {
  86. if (last_fqid == first_fqid)
  87. bytes += sprintf(buf + bytes,
  88. "%s: %d\n", prevstr, prev->fqid);
  89. else
  90. bytes += sprintf(buf + bytes,
  91. "%s: %d - %d\n", prevstr,
  92. first_fqid, last_fqid);
  93. }
  94. if (prev && abs(fq->fqid - prev->fqid) == 1 &&
  95. str == prevstr) {
  96. last_fqid = fq->fqid;
  97. } else {
  98. first_fqid = fq->fqid;
  99. last_fqid = fq->fqid;
  100. }
  101. prev = fq;
  102. prevstr = str;
  103. i++;
  104. }
  105. if (prev) {
  106. if (last_fqid == first_fqid)
  107. bytes += sprintf(buf + bytes, "%s: %d\n", prevstr,
  108. prev->fqid);
  109. else
  110. bytes += sprintf(buf + bytes, "%s: %d - %d\n", prevstr,
  111. first_fqid, last_fqid);
  112. }
  113. return bytes;
  114. }
  115. static ssize_t dpaa_eth_show_bpids(struct device *dev,
  116. struct device_attribute *attr, char *buf)
  117. {
  118. struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
  119. ssize_t bytes = 0;
  120. int i = 0;
  121. for (i = 0; i < DPAA_BPS_NUM; i++)
  122. bytes += snprintf(buf + bytes, PAGE_SIZE - bytes, "%u\n",
  123. priv->dpaa_bps[i]->bpid);
  124. return bytes;
  125. }
  126. static struct device_attribute dpaa_eth_attrs[] = {
  127. __ATTR(device_addr, 0444, dpaa_eth_show_addr, NULL),
  128. __ATTR(fqids, 0444, dpaa_eth_show_fqids, NULL),
  129. __ATTR(bpids, 0444, dpaa_eth_show_bpids, NULL),
  130. };
  131. void dpaa_eth_sysfs_init(struct device *dev)
  132. {
  133. int i;
  134. for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
  135. if (device_create_file(dev, &dpaa_eth_attrs[i])) {
  136. dev_err(dev, "Error creating sysfs file\n");
  137. while (i > 0)
  138. device_remove_file(dev, &dpaa_eth_attrs[--i]);
  139. return;
  140. }
  141. }
  142. void dpaa_eth_sysfs_remove(struct device *dev)
  143. {
  144. int i;
  145. for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
  146. device_remove_file(dev, &dpaa_eth_attrs[i]);
  147. }