diff mbox series

[RFC,v1,10/10] net: qrtr: mhi: Report endpoint id in sysfs

Message ID 20241018181842.1368394-11-denkenz@gmail.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series QRTR Multi-endpoint support | expand

Checks

Context Check Description
netdev/series_format warning Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Denis Kenzior Oct. 18, 2024, 6:18 p.m. UTC
Add a read-only 'endpoint' sysfs entry that contains the qrtr endpoint
identifier assigned to this mhi device.  Can be used to direct / receive
qrtr traffic only from a particular MHI device.

Signed-off-by: Denis Kenzior <denkenz@gmail.com>
Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
Reviewed-by: Andy Gross <agross@kernel.org>
---
 net/qrtr/mhi.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Chris Lew Oct. 23, 2024, 12:25 a.m. UTC | #1
On 10/18/2024 11:18 AM, Denis Kenzior wrote:
> Add a read-only 'endpoint' sysfs entry that contains the qrtr endpoint
> identifier assigned to this mhi device.  Can be used to direct / receive
> qrtr traffic only from a particular MHI device.
> 
> Signed-off-by: Denis Kenzior <denkenz@gmail.com>
> Reviewed-by: Marcel Holtmann <marcel@holtmann.org>
> Reviewed-by: Andy Gross <agross@kernel.org>
> ---
>   net/qrtr/mhi.c | 14 ++++++++++++++
>   1 file changed, 14 insertions(+)
> 
> diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
> index 69f53625a049..a4696ed31fb1 100644
> --- a/net/qrtr/mhi.c
> +++ b/net/qrtr/mhi.c
> @@ -72,6 +72,16 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
>   	return rc;
>   }
>   
> +static ssize_t endpoint_show(struct device *dev,
> +			     struct device_attribute *attr, char *buf)
> +{
> +	struct qrtr_mhi_dev *qdev = dev_get_drvdata(dev);
> +
> +	return sprintf(buf, "%d\n", qdev->ep.id);

%u might be more appropriate because the endpoint id is stored as a u32

> +}
> +
> +static DEVICE_ATTR_RO(endpoint);
> +
>   static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
>   			       const struct mhi_device_id *id)
>   {
> @@ -91,6 +101,9 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
>   	if (rc)
>   		return rc;
>   
> +	if (device_create_file(&mhi_dev->dev, &dev_attr_endpoint) < 0)
> +		dev_err(qdev->dev, "Failed to create endpoint attribute\n");
> +
>   	/* start channels */
>   	rc = mhi_prepare_for_transfer_autoqueue(mhi_dev);
>   	if (rc) {
> @@ -107,6 +120,7 @@ static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev)
>   {
>   	struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
>   
> +	device_remove_file(&mhi_dev->dev, &dev_attr_endpoint);
>   	qrtr_endpoint_unregister(&qdev->ep);
>   	mhi_unprepare_from_transfer(mhi_dev);
>   	dev_set_drvdata(&mhi_dev->dev, NULL);
Denis Kenzior Oct. 24, 2024, 6:06 p.m. UTC | #2
Hi Chris,

>> @@ -72,6 +72,16 @@ static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, 
>> struct sk_buff *skb)
>>       return rc;
>>   }
>> +static ssize_t endpoint_show(struct device *dev,
>> +                 struct device_attribute *attr, char *buf)
>> +{
>> +    struct qrtr_mhi_dev *qdev = dev_get_drvdata(dev);
>> +
>> +    return sprintf(buf, "%d\n", qdev->ep.id);
> 
> %u might be more appropriate because the endpoint id is stored as a u32

Nice catch.  I'll fix it for the next version.

Regards,
-Denis
diff mbox series

Patch

diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
index 69f53625a049..a4696ed31fb1 100644
--- a/net/qrtr/mhi.c
+++ b/net/qrtr/mhi.c
@@ -72,6 +72,16 @@  static int qcom_mhi_qrtr_send(struct qrtr_endpoint *ep, struct sk_buff *skb)
 	return rc;
 }
 
+static ssize_t endpoint_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	struct qrtr_mhi_dev *qdev = dev_get_drvdata(dev);
+
+	return sprintf(buf, "%d\n", qdev->ep.id);
+}
+
+static DEVICE_ATTR_RO(endpoint);
+
 static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
 			       const struct mhi_device_id *id)
 {
@@ -91,6 +101,9 @@  static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
 	if (rc)
 		return rc;
 
+	if (device_create_file(&mhi_dev->dev, &dev_attr_endpoint) < 0)
+		dev_err(qdev->dev, "Failed to create endpoint attribute\n");
+
 	/* start channels */
 	rc = mhi_prepare_for_transfer_autoqueue(mhi_dev);
 	if (rc) {
@@ -107,6 +120,7 @@  static void qcom_mhi_qrtr_remove(struct mhi_device *mhi_dev)
 {
 	struct qrtr_mhi_dev *qdev = dev_get_drvdata(&mhi_dev->dev);
 
+	device_remove_file(&mhi_dev->dev, &dev_attr_endpoint);
 	qrtr_endpoint_unregister(&qdev->ep);
 	mhi_unprepare_from_transfer(mhi_dev);
 	dev_set_drvdata(&mhi_dev->dev, NULL);