From: Ping-Ke Shih <pkshih@realtek.com>
To: <linux-wireless@vger.kernel.org>
Cc: <wenjie.tsai@realtek.com>
Subject: [RFC rtw-next 2/2] wifi: rtw89: usb: add sysfs write example
Date: Tue, 19 May 2026 15:24:15 +0800 [thread overview]
Message-ID: <20260519072415.25746-2-pkshih@realtek.com> (raw)
In-Reply-To: <20260519072415.25746-1-pkshih@realtek.com>
From: Johnson Tsai <wenjie.tsai@realtek.com>
Add a simple echo_sum sysfs attribute on the USB interface device as
an RFC example for discussing whether a writable sysfs interface is
acceptable for this driver.
The attribute accepts two integers from userspace, stores their sum in
driver private data, and exposes the result.
Signed-off-by: Johnson Tsai <wenjie.tsai@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
---
drivers/net/wireless/realtek/rtw89/usb.c | 38 ++++++++++++++++++++++++
drivers/net/wireless/realtek/rtw89/usb.h | 2 ++
2 files changed, 40 insertions(+)
diff --git a/drivers/net/wireless/realtek/rtw89/usb.c b/drivers/net/wireless/realtek/rtw89/usb.c
index 53dcb84af5c0..566618e9f3b8 100644
--- a/drivers/net/wireless/realtek/rtw89/usb.c
+++ b/drivers/net/wireless/realtek/rtw89/usb.c
@@ -1059,6 +1059,43 @@ static void rtw89_usb_intf_deinit(struct rtw89_dev *rtwdev,
usb_set_intfdata(intf, NULL);
}
+static ssize_t echo_sum_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct usb_interface *intf = to_usb_interface(dev);
+ struct ieee80211_hw *hw = usb_get_intfdata(intf);
+ struct rtw89_usb *rtwusb;
+
+ if (!hw)
+ return -ENODEV;
+
+ rtwusb = rtw89_usb_priv(hw->priv);
+
+ return sysfs_emit(buf, "%u\n", rtwusb->echo_sum);
+}
+
+static ssize_t echo_sum_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct usb_interface *intf = to_usb_interface(dev);
+ struct ieee80211_hw *hw = usb_get_intfdata(intf);
+ struct rtw89_usb *rtwusb;
+ int a, b;
+
+ if (!hw)
+ return -ENODEV;
+
+ if (sscanf(buf, "%d %d", &a, &b) != 2)
+ return -EINVAL;
+
+ rtwusb = rtw89_usb_priv(hw->priv);
+ rtwusb->echo_sum = a + b;
+
+ return count;
+}
+static DEVICE_ATTR_ADMIN_RW(echo_sum);
+
static ssize_t hw_info_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1089,6 +1126,7 @@ static ssize_t hw_info_show(struct device *dev,
static DEVICE_ATTR_RO(hw_info);
static struct attribute *rtw89_usb_attrs[] = {
+ &dev_attr_echo_sum.attr,
&dev_attr_hw_info.attr,
NULL,
};
diff --git a/drivers/net/wireless/realtek/rtw89/usb.h b/drivers/net/wireless/realtek/rtw89/usb.h
index bdf312559743..9eba6264a9a2 100644
--- a/drivers/net/wireless/realtek/rtw89/usb.h
+++ b/drivers/net/wireless/realtek/rtw89/usb.h
@@ -87,6 +87,8 @@ struct rtw89_usb {
struct sk_buff_head tx_queue[RTW89_TXCH_NUM];
atomic_t tx_inflight[RTW89_TXCH_NUM];
+
+ u32 echo_sum;
};
static inline struct rtw89_usb *rtw89_usb_priv(struct rtw89_dev *rtwdev)
--
2.25.1
next prev parent reply other threads:[~2026-05-19 7:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-19 7:24 [RFC rtw-next 1/2] wifi: rtw89: usb: add hw_info sysfs attribute Ping-Ke Shih
2026-05-19 7:24 ` Ping-Ke Shih [this message]
2026-05-19 7:37 ` Ping-Ke Shih
2026-05-19 12:11 ` Johannes Berg
2026-05-19 12:22 ` Greg KH
2026-05-20 9:41 ` Johnson Tsai
2026-05-20 11:36 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260519072415.25746-2-pkshih@realtek.com \
--to=pkshih@realtek.com \
--cc=linux-wireless@vger.kernel.org \
--cc=wenjie.tsai@realtek.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox