dpaa_eth_sysfs.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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_RX_PCD:
  70. str = "Rx PCD";
  71. break;
  72. case FQ_TYPE_TX_CONFIRM:
  73. str = "Tx default confirmation";
  74. break;
  75. case FQ_TYPE_TX_CONF_MQ:
  76. str = "Tx confirmation (mq)";
  77. break;
  78. case FQ_TYPE_TX_ERROR:
  79. str = "Tx error";
  80. break;
  81. case FQ_TYPE_TX:
  82. str = "Tx";
  83. break;
  84. default:
  85. str = "Unknown";
  86. }
  87. if (prev && (abs(fq->fqid - prev->fqid) != 1 ||
  88. str != prevstr)) {
  89. if (last_fqid == first_fqid)
  90. bytes += sprintf(buf + bytes,
  91. "%s: %d\n", prevstr, prev->fqid);
  92. else
  93. bytes += sprintf(buf + bytes,
  94. "%s: %d - %d\n", prevstr,
  95. first_fqid, last_fqid);
  96. }
  97. if (prev && abs(fq->fqid - prev->fqid) == 1 &&
  98. str == prevstr) {
  99. last_fqid = fq->fqid;
  100. } else {
  101. first_fqid = fq->fqid;
  102. last_fqid = fq->fqid;
  103. }
  104. prev = fq;
  105. prevstr = str;
  106. i++;
  107. }
  108. if (prev) {
  109. if (last_fqid == first_fqid)
  110. bytes += sprintf(buf + bytes, "%s: %d\n", prevstr,
  111. prev->fqid);
  112. else
  113. bytes += sprintf(buf + bytes, "%s: %d - %d\n", prevstr,
  114. first_fqid, last_fqid);
  115. }
  116. return bytes;
  117. }
  118. static ssize_t dpaa_eth_show_bpids(struct device *dev,
  119. struct device_attribute *attr, char *buf)
  120. {
  121. struct dpaa_priv *priv = netdev_priv(to_net_dev(dev));
  122. ssize_t bytes = 0;
  123. int i = 0;
  124. for (i = 0; i < DPAA_BPS_NUM; i++)
  125. bytes += snprintf(buf + bytes, PAGE_SIZE - bytes, "%u\n",
  126. priv->dpaa_bps[i]->bpid);
  127. return bytes;
  128. }
  129. static struct device_attribute dpaa_eth_attrs[] = {
  130. __ATTR(device_addr, 0444, dpaa_eth_show_addr, NULL),
  131. __ATTR(fqids, 0444, dpaa_eth_show_fqids, NULL),
  132. __ATTR(bpids, 0444, dpaa_eth_show_bpids, NULL),
  133. };
  134. void dpaa_eth_sysfs_init(struct device *dev)
  135. {
  136. int i;
  137. for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
  138. if (device_create_file(dev, &dpaa_eth_attrs[i])) {
  139. dev_err(dev, "Error creating sysfs file\n");
  140. while (i > 0)
  141. device_remove_file(dev, &dpaa_eth_attrs[--i]);
  142. return;
  143. }
  144. }
  145. void dpaa_eth_sysfs_remove(struct device *dev)
  146. {
  147. int i;
  148. for (i = 0; i < ARRAY_SIZE(dpaa_eth_attrs); i++)
  149. device_remove_file(dev, &dpaa_eth_attrs[i]);
  150. }