ipa_sysfs.c 4.3 KB

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