Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: ipa: add an endpoint device attribute group

Create a new attribute group meant to provide a single place that
defines endpoint IDs that might be needed by user space. Not all
defined endpoints are presented, and only those that are defined
will be made visible.

The new attributes use "extended" device attributes to hold endpoint
IDs, which is a little more compact and efficient. Reimplement the
existing modem endpoint ID attribute files using common code.

Signed-off-by: Alex Elder <elder@linaro.org>
Link: https://lore.kernel.org/r/20220719191639.373249-1-elder@linaro.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Alex Elder and committed by
Jakub Kicinski
d79e4164 f12b86c0

+102 -31
+49 -13
Documentation/ABI/testing/sysfs-devices-platform-soc-ipa
··· 46 46 that is supported by the hardware. The possible values 47 47 are "MAPv4" or "MAPv5". 48 48 49 + What: .../XXXXXXX.ipa/endpoint_id/ 50 + Date: July 2022 51 + KernelVersion: v5.19 52 + Contact: Alex Elder <elder@kernel.org> 53 + Description: 54 + The .../XXXXXXX.ipa/endpoint_id/ directory contains 55 + attributes that define IDs associated with IPA 56 + endpoints. The "rx" or "tx" in an endpoint name is 57 + from the perspective of the AP. An endpoint ID is a 58 + small unsigned integer. 59 + 60 + What: .../XXXXXXX.ipa/endpoint_id/modem_rx 61 + Date: July 2022 62 + KernelVersion: v5.19 63 + Contact: Alex Elder <elder@kernel.org> 64 + Description: 65 + The .../XXXXXXX.ipa/endpoint_id/modem_rx file contains 66 + the ID of the AP endpoint on which packets originating 67 + from the embedded modem are received. 68 + 69 + What: .../XXXXXXX.ipa/endpoint_id/modem_tx 70 + Date: July 2022 71 + KernelVersion: v5.19 72 + Contact: Alex Elder <elder@kernel.org> 73 + Description: 74 + The .../XXXXXXX.ipa/endpoint_id/modem_tx file contains 75 + the ID of the AP endpoint on which packets destined 76 + for the embedded modem are sent. 77 + 78 + What: .../XXXXXXX.ipa/endpoint_id/monitor_rx 79 + Date: July 2022 80 + KernelVersion: v5.19 81 + Contact: Alex Elder <elder@kernel.org> 82 + Description: 83 + The .../XXXXXXX.ipa/endpoint_id/monitor_rx file contains 84 + the ID of the AP endpoint on which IPA "monitor" data is 85 + received. The monitor endpoint supplies replicas of 86 + packets that enter the IPA hardware for processing. 87 + Each replicated packet is preceded by a fixed-size "ODL" 88 + header (see .../XXXXXXX.ipa/feature/monitor, above). 89 + Large packets are truncated, to reduce the bandwidth 90 + required to provide the monitor function. 91 + 49 92 What: .../XXXXXXX.ipa/modem/ 50 93 Date: June 2021 51 94 KernelVersion: v5.14 52 95 Contact: Alex Elder <elder@kernel.org> 53 96 Description: 54 - The .../XXXXXXX.ipa/modem/ directory contains a set of 55 - attributes describing properties of the modem execution 56 - environment reachable by the IPA hardware. 97 + The .../XXXXXXX.ipa/modem/ directory contains attributes 98 + describing properties of the modem embedded in the SoC. 57 99 58 100 What: .../XXXXXXX.ipa/modem/rx_endpoint_id 59 101 Date: June 2021 60 102 KernelVersion: v5.14 61 103 Contact: Alex Elder <elder@kernel.org> 62 104 Description: 63 - The .../XXXXXXX.ipa/feature/rx_endpoint_id file contains 64 - the AP endpoint ID that receives packets originating from 65 - the modem execution environment. The "rx" is from the 66 - perspective of the AP; this endpoint is considered an "IPA 67 - producer". An endpoint ID is a small unsigned integer. 105 + The .../XXXXXXX.ipa/modem/rx_endpoint_id file duplicates 106 + the value found in .../XXXXXXX.ipa/endpoint_id/modem_rx. 68 107 69 108 What: .../XXXXXXX.ipa/modem/tx_endpoint_id 70 109 Date: June 2021 71 110 KernelVersion: v5.14 72 111 Contact: Alex Elder <elder@kernel.org> 73 112 Description: 74 - The .../XXXXXXX.ipa/feature/tx_endpoint_id file contains 75 - the AP endpoint ID used to transmit packets destined for 76 - the modem execution environment. The "tx" is from the 77 - perspective of the AP; this endpoint is considered an "IPA 78 - consumer". An endpoint ID is a small unsigned integer. 113 + The .../XXXXXXX.ipa/modem/tx_endpoint_id file duplicates 114 + the value found in .../XXXXXXX.ipa/endpoint_id/modem_tx.
+1
drivers/net/ipa/ipa_main.c
··· 851 851 static const struct attribute_group *ipa_attribute_groups[] = { 852 852 &ipa_attribute_group, 853 853 &ipa_feature_attribute_group, 854 + &ipa_endpoint_id_attribute_group, 854 855 &ipa_modem_attribute_group, 855 856 NULL, 856 857 };
+51 -18
drivers/net/ipa/ipa_sysfs.c
··· 96 96 .attrs = ipa_feature_attrs, 97 97 }; 98 98 99 - static ssize_t 100 - ipa_endpoint_id_show(struct ipa *ipa, char *buf, enum ipa_endpoint_name name) 99 + static umode_t ipa_endpoint_id_is_visible(struct kobject *kobj, 100 + struct attribute *attr, int n) 101 101 { 102 - u32 endpoint_id = ipa->name_map[name]->endpoint_id; 102 + struct ipa *ipa = dev_get_drvdata(kobj_to_dev(kobj)); 103 + struct device_attribute *dev_attr; 104 + struct dev_ext_attribute *ea; 105 + bool visible; 103 106 104 - return scnprintf(buf, PAGE_SIZE, "%u\n", endpoint_id); 107 + /* An endpoint id attribute is only visible if it's defined */ 108 + dev_attr = container_of(attr, struct device_attribute, attr); 109 + ea = container_of(dev_attr, struct dev_ext_attribute, attr); 110 + 111 + visible = !!ipa->name_map[(enum ipa_endpoint_name)(uintptr_t)ea->var]; 112 + 113 + return visible ? attr->mode : 0; 105 114 } 106 115 107 - static ssize_t rx_endpoint_id_show(struct device *dev, 108 - struct device_attribute *attr, char *buf) 116 + static ssize_t endpoint_id_attr_show(struct device *dev, 117 + struct device_attribute *attr, char *buf) 109 118 { 110 119 struct ipa *ipa = dev_get_drvdata(dev); 120 + struct ipa_endpoint *endpoint; 121 + struct dev_ext_attribute *ea; 111 122 112 - return ipa_endpoint_id_show(ipa, buf, IPA_ENDPOINT_AP_MODEM_RX); 123 + ea = container_of(attr, struct dev_ext_attribute, attr); 124 + endpoint = ipa->name_map[(enum ipa_endpoint_name)(uintptr_t)ea->var]; 125 + 126 + return sysfs_emit(buf, "%u\n", endpoint->endpoint_id); 113 127 } 114 128 115 - static DEVICE_ATTR_RO(rx_endpoint_id); 129 + #define ENDPOINT_ID_ATTR(_n, _endpoint_name) \ 130 + static struct dev_ext_attribute dev_attr_endpoint_id_ ## _n = { \ 131 + .attr = __ATTR(_n, 0444, endpoint_id_attr_show, NULL), \ 132 + .var = (void *)(_endpoint_name), \ 133 + } 116 134 117 - static ssize_t tx_endpoint_id_show(struct device *dev, 118 - struct device_attribute *attr, char *buf) 119 - { 120 - struct ipa *ipa = dev_get_drvdata(dev); 135 + ENDPOINT_ID_ATTR(modem_rx, IPA_ENDPOINT_AP_MODEM_RX); 136 + ENDPOINT_ID_ATTR(modem_tx, IPA_ENDPOINT_AP_MODEM_TX); 121 137 122 - return ipa_endpoint_id_show(ipa, buf, IPA_ENDPOINT_AP_MODEM_TX); 123 - } 138 + static struct attribute *ipa_endpoint_id_attrs[] = { 139 + &dev_attr_endpoint_id_modem_rx.attr.attr, 140 + &dev_attr_endpoint_id_modem_tx.attr.attr, 141 + NULL 142 + }; 124 143 125 - static DEVICE_ATTR_RO(tx_endpoint_id); 144 + const struct attribute_group ipa_endpoint_id_attribute_group = { 145 + .name = "endpoint_id", 146 + .is_visible = ipa_endpoint_id_is_visible, 147 + .attrs = ipa_endpoint_id_attrs, 148 + }; 149 + 150 + /* Reuse endpoint ID attributes for the legacy modem endpoint IDs */ 151 + #define MODEM_ATTR(_n, _endpoint_name) \ 152 + static struct dev_ext_attribute dev_attr_modem_ ## _n = { \ 153 + .attr = __ATTR(_n, 0444, endpoint_id_attr_show, NULL), \ 154 + .var = (void *)(_endpoint_name), \ 155 + } 156 + 157 + MODEM_ATTR(rx_endpoint_id, IPA_ENDPOINT_AP_MODEM_RX); 158 + MODEM_ATTR(tx_endpoint_id, IPA_ENDPOINT_AP_MODEM_TX); 126 159 127 160 static struct attribute *ipa_modem_attrs[] = { 128 - &dev_attr_rx_endpoint_id.attr, 129 - &dev_attr_tx_endpoint_id.attr, 130 - NULL 161 + &dev_attr_modem_rx_endpoint_id.attr.attr, 162 + &dev_attr_modem_tx_endpoint_id.attr.attr, 163 + NULL, 131 164 }; 132 165 133 166 const struct attribute_group ipa_modem_attribute_group = {
+1
drivers/net/ipa/ipa_sysfs.h
··· 10 10 11 11 extern const struct attribute_group ipa_attribute_group; 12 12 extern const struct attribute_group ipa_feature_attribute_group; 13 + extern const struct attribute_group ipa_endpoint_id_attribute_group; 13 14 extern const struct attribute_group ipa_modem_attribute_group; 14 15 15 16 #endif /* _IPA_SYSFS_H_ */