1 // SPDX-License-Identifier: GPL-2.0
3 /* Copyright (C) 2021-2024 Linaro Ltd. */
5 #include <linux/device.h>
6 #include <linux/sysfs.h>
7 #include <linux/types.h>
10 #include "ipa_sysfs.h"
11 #include "ipa_version.h"
13 static const char *ipa_version_string(struct ipa
*ipa
)
15 switch (ipa
->version
) {
22 case IPA_VERSION_3_5_1
:
36 case IPA_VERSION_4_11
:
41 return "0.0"; /* Won't happen (checked at probe time) */
46 version_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
48 struct ipa
*ipa
= dev_get_drvdata(dev
);
50 return sysfs_emit(buf
, "%s\n", ipa_version_string(ipa
));
53 static DEVICE_ATTR_RO(version
);
55 static struct attribute
*ipa_attrs
[] = {
56 &dev_attr_version
.attr
,
60 const struct attribute_group ipa_attribute_group
= {
64 static const char *ipa_offload_string(struct ipa
*ipa
)
66 return ipa
->version
< IPA_VERSION_4_5
? "MAPv4" : "MAPv5";
69 static ssize_t
rx_offload_show(struct device
*dev
,
70 struct device_attribute
*attr
, char *buf
)
72 struct ipa
*ipa
= dev_get_drvdata(dev
);
74 return sysfs_emit(buf
, "%s\n", ipa_offload_string(ipa
));
77 static DEVICE_ATTR_RO(rx_offload
);
79 static ssize_t
tx_offload_show(struct device
*dev
,
80 struct device_attribute
*attr
, char *buf
)
82 struct ipa
*ipa
= dev_get_drvdata(dev
);
84 return sysfs_emit(buf
, "%s\n", ipa_offload_string(ipa
));
87 static DEVICE_ATTR_RO(tx_offload
);
89 static struct attribute
*ipa_feature_attrs
[] = {
90 &dev_attr_rx_offload
.attr
,
91 &dev_attr_tx_offload
.attr
,
95 const struct attribute_group ipa_feature_attribute_group
= {
97 .attrs
= ipa_feature_attrs
,
100 static umode_t
ipa_endpoint_id_is_visible(struct kobject
*kobj
,
101 struct attribute
*attr
, int n
)
103 struct ipa
*ipa
= dev_get_drvdata(kobj_to_dev(kobj
));
104 struct device_attribute
*dev_attr
;
105 struct dev_ext_attribute
*ea
;
108 /* An endpoint id attribute is only visible if it's defined */
109 dev_attr
= container_of(attr
, struct device_attribute
, attr
);
110 ea
= container_of(dev_attr
, struct dev_ext_attribute
, attr
);
112 visible
= !!ipa
->name_map
[(enum ipa_endpoint_name
)(uintptr_t)ea
->var
];
114 return visible
? attr
->mode
: 0;
117 static ssize_t
endpoint_id_attr_show(struct device
*dev
,
118 struct device_attribute
*attr
, char *buf
)
120 struct ipa
*ipa
= dev_get_drvdata(dev
);
121 struct ipa_endpoint
*endpoint
;
122 struct dev_ext_attribute
*ea
;
124 ea
= container_of(attr
, struct dev_ext_attribute
, attr
);
125 endpoint
= ipa
->name_map
[(enum ipa_endpoint_name
)(uintptr_t)ea
->var
];
127 return sysfs_emit(buf
, "%u\n", endpoint
->endpoint_id
);
130 #define ENDPOINT_ID_ATTR(_n, _endpoint_name) \
131 static struct dev_ext_attribute dev_attr_endpoint_id_ ## _n = { \
132 .attr = __ATTR(_n, 0444, endpoint_id_attr_show, NULL), \
133 .var = (void *)(_endpoint_name), \
136 ENDPOINT_ID_ATTR(modem_rx
, IPA_ENDPOINT_AP_MODEM_RX
);
137 ENDPOINT_ID_ATTR(modem_tx
, IPA_ENDPOINT_AP_MODEM_TX
);
139 static struct attribute
*ipa_endpoint_id_attrs
[] = {
140 &dev_attr_endpoint_id_modem_rx
.attr
.attr
,
141 &dev_attr_endpoint_id_modem_tx
.attr
.attr
,
145 const struct attribute_group ipa_endpoint_id_attribute_group
= {
146 .name
= "endpoint_id",
147 .is_visible
= ipa_endpoint_id_is_visible
,
148 .attrs
= ipa_endpoint_id_attrs
,
151 /* Reuse endpoint ID attributes for the legacy modem endpoint IDs */
152 #define MODEM_ATTR(_n, _endpoint_name) \
153 static struct dev_ext_attribute dev_attr_modem_ ## _n = { \
154 .attr = __ATTR(_n, 0444, endpoint_id_attr_show, NULL), \
155 .var = (void *)(_endpoint_name), \
158 MODEM_ATTR(rx_endpoint_id
, IPA_ENDPOINT_AP_MODEM_RX
);
159 MODEM_ATTR(tx_endpoint_id
, IPA_ENDPOINT_AP_MODEM_TX
);
161 static struct attribute
*ipa_modem_attrs
[] = {
162 &dev_attr_modem_rx_endpoint_id
.attr
.attr
,
163 &dev_attr_modem_tx_endpoint_id
.attr
.attr
,
167 const struct attribute_group ipa_modem_attribute_group
= {
169 .attrs
= ipa_modem_attrs
,