ipa_sysfs.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (C) 2021-2022 Linaro Ltd. */
  3. #include <linux/kernel.h>
  4. #include <linux/types.h>
  5. #include <linux/device.h>
  6. #include <linux/sysfs.h>
  7. #include "ipa.h"
  8. #include "ipa_version.h"
  9. #include "ipa_sysfs.h"
  10. static const char *ipa_version_string(struct ipa *ipa)
  11. {
  12. switch (ipa->version) {
  13. case IPA_VERSION_3_0:
  14. return "3.0";
  15. case IPA_VERSION_3_1:
  16. return "3.1";
  17. case IPA_VERSION_3_5:
  18. return "3.5";
  19. case IPA_VERSION_3_5_1:
  20. return "3.5.1";
  21. case IPA_VERSION_4_0:
  22. return "4.0";
  23. case IPA_VERSION_4_1:
  24. return "4.1";
  25. case IPA_VERSION_4_2:
  26. return "4.2";
  27. case IPA_VERSION_4_5:
  28. return "4.5";
  29. case IPA_VERSION_4_7:
  30. return "4.7";
  31. case IPA_VERSION_4_9:
  32. return "4.9";
  33. case IPA_VERSION_4_11:
  34. return "4.11";
  35. default:
  36. return "0.0"; /* Won't happen (checked at probe time) */
  37. }
  38. }
  39. static ssize_t
  40. version_show(struct device *dev, struct device_attribute *attr, char *buf)
  41. {
  42. struct ipa *ipa = dev_get_drvdata(dev);
  43. return scnprintf(buf, PAGE_SIZE, "%s\n", ipa_version_string(ipa));
  44. }
  45. static DEVICE_ATTR_RO(version);
  46. static struct attribute *ipa_attrs[] = {
  47. &dev_attr_version.attr,
  48. NULL
  49. };
  50. const struct attribute_group ipa_attribute_group = {
  51. .attrs = ipa_attrs,
  52. };
  53. static const char *ipa_offload_string(struct ipa *ipa)
  54. {
  55. return ipa->version < IPA_VERSION_4_5 ? "MAPv4" : "MAPv5";
  56. }
  57. static ssize_t rx_offload_show(struct device *dev,
  58. struct device_attribute *attr, char *buf)
  59. {
  60. struct ipa *ipa = dev_get_drvdata(dev);
  61. return scnprintf(buf, PAGE_SIZE, "%s\n", ipa_offload_string(ipa));
  62. }
  63. static DEVICE_ATTR_RO(rx_offload);
  64. static ssize_t tx_offload_show(struct device *dev,
  65. struct device_attribute *attr, char *buf)
  66. {
  67. struct ipa *ipa = dev_get_drvdata(dev);
  68. return scnprintf(buf, PAGE_SIZE, "%s\n", ipa_offload_string(ipa));
  69. }
  70. static DEVICE_ATTR_RO(tx_offload);
  71. static struct attribute *ipa_feature_attrs[] = {
  72. &dev_attr_rx_offload.attr,
  73. &dev_attr_tx_offload.attr,
  74. NULL
  75. };
  76. const struct attribute_group ipa_feature_attribute_group = {
  77. .name = "feature",
  78. .attrs = ipa_feature_attrs,
  79. };
  80. static umode_t ipa_endpoint_id_is_visible(struct kobject *kobj,
  81. struct attribute *attr, int n)
  82. {
  83. struct ipa *ipa = dev_get_drvdata(kobj_to_dev(kobj));
  84. struct device_attribute *dev_attr;
  85. struct dev_ext_attribute *ea;
  86. bool visible;
  87. /* An endpoint id attribute is only visible if it's defined */
  88. dev_attr = container_of(attr, struct device_attribute, attr);
  89. ea = container_of(dev_attr, struct dev_ext_attribute, attr);
  90. visible = !!ipa->name_map[(enum ipa_endpoint_name)(uintptr_t)ea->var];
  91. return visible ? attr->mode : 0;
  92. }
  93. static ssize_t endpoint_id_attr_show(struct device *dev,
  94. struct device_attribute *attr, char *buf)
  95. {
  96. struct ipa *ipa = dev_get_drvdata(dev);
  97. struct ipa_endpoint *endpoint;
  98. struct dev_ext_attribute *ea;
  99. ea = container_of(attr, struct dev_ext_attribute, attr);
  100. endpoint = ipa->name_map[(enum ipa_endpoint_name)(uintptr_t)ea->var];
  101. return sysfs_emit(buf, "%u\n", endpoint->endpoint_id);
  102. }
  103. #define ENDPOINT_ID_ATTR(_n, _endpoint_name) \
  104. static struct dev_ext_attribute dev_attr_endpoint_id_ ## _n = { \
  105. .attr = __ATTR(_n, 0444, endpoint_id_attr_show, NULL), \
  106. .var = (void *)(_endpoint_name), \
  107. }
  108. ENDPOINT_ID_ATTR(modem_rx, IPA_ENDPOINT_AP_MODEM_RX);
  109. ENDPOINT_ID_ATTR(modem_tx, IPA_ENDPOINT_AP_MODEM_TX);
  110. static struct attribute *ipa_endpoint_id_attrs[] = {
  111. &dev_attr_endpoint_id_modem_rx.attr.attr,
  112. &dev_attr_endpoint_id_modem_tx.attr.attr,
  113. NULL
  114. };
  115. const struct attribute_group ipa_endpoint_id_attribute_group = {
  116. .name = "endpoint_id",
  117. .is_visible = ipa_endpoint_id_is_visible,
  118. .attrs = ipa_endpoint_id_attrs,
  119. };
  120. /* Reuse endpoint ID attributes for the legacy modem endpoint IDs */
  121. #define MODEM_ATTR(_n, _endpoint_name) \
  122. static struct dev_ext_attribute dev_attr_modem_ ## _n = { \
  123. .attr = __ATTR(_n, 0444, endpoint_id_attr_show, NULL), \
  124. .var = (void *)(_endpoint_name), \
  125. }
  126. MODEM_ATTR(rx_endpoint_id, IPA_ENDPOINT_AP_MODEM_RX);
  127. MODEM_ATTR(tx_endpoint_id, IPA_ENDPOINT_AP_MODEM_TX);
  128. static struct attribute *ipa_modem_attrs[] = {
  129. &dev_attr_modem_rx_endpoint_id.attr.attr,
  130. &dev_attr_modem_tx_endpoint_id.attr.attr,
  131. NULL,
  132. };
  133. const struct attribute_group ipa_modem_attribute_group = {
  134. .name = "modem",
  135. .attrs = ipa_modem_attrs,
  136. };