public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Bastien Nocera <hadess@hadess.net>
Cc: linux-usb@vger.kernel.org, linux-input@vger.kernel.org,
	"Alan Stern" <stern@rowland.harvard.edu>,
	"Benjamin Tissoires" <benjamin.tissoires@redhat.com>,
	"Filipe Laíns" <lains@riseup.net>,
	"Nestor Lopez Casado" <nlopezcasad@logitech.com>
Subject: Re: [PATCH 3/5] USB: core: Add wireless_status sysfs attribute
Date: Thu, 23 Feb 2023 14:51:54 +0100	[thread overview]
Message-ID: <Y/dvesNrHivGV6JK@kroah.com> (raw)
In-Reply-To: <20230223132452.37958-3-hadess@hadess.net>

On Thu, Feb 23, 2023 at 02:24:50PM +0100, Bastien Nocera wrote:
> Add a wireless_status sysfs attribute to USB devices to keep track of
> whether a USB device that uses a receiver/emitter combo has its
> emitter connected or disconnected.

That's going to be very vague, and is starting to get very
interface-specific as an attibute here.

Why can't it just be an input device attribute?  Why is "wireless"
suddenly a special case for USB devices (we thought we got rid of the
old wireless usb code...)

> By default, the USB device will declare not to use a receiver/emitter.

I do not understand this statement, what do you mean by this?

> Signed-off-by: Bastien Nocera <hadess@hadess.net>
> ---
>  Documentation/ABI/testing/sysfs-bus-usb | 12 ++++++
>  drivers/usb/core/sysfs.c                | 50 +++++++++++++++++++++++++
>  drivers/usb/core/usb.h                  |  1 +
>  include/linux/usb.h                     | 10 +++++
>  4 files changed, 73 insertions(+)
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb
> index 545c2dd97ed0..0bd22ece05cd 100644
> --- a/Documentation/ABI/testing/sysfs-bus-usb
> +++ b/Documentation/ABI/testing/sysfs-bus-usb
> @@ -166,6 +166,18 @@ Description:
>  		The file will be present for all speeds of USB devices, and will
>  		always read "no" for USB 1.1 and USB 2.0 devices.
>  
> +What:		/sys/bus/usb/devices/<INTERFACE>/wireless_status
> +Date:		January 2023

January was last month :(

> +Contact:	Bastien Nocera <hadess@hadess.net>
> +Description:
> +		Some USB devices use a small USB receiver coupled with a larger
> +		wireless device, usually communicating using proprietary
> +		wireless protocols. This attribute will read either "connected"
> +		or "disconnected" depending on whether the emitter is turned on,
> +		in range and connected, on the interface which is used to detect
> +		this state. If the device does not use a receiver/emitter combo,
> +		then this attribute will not exist.

So would you declare a wireless network device such a thing?

See, it gets tricky, I do not think this should be a generic USB
attribute at all.


> +
>  What:		/sys/bus/usb/devices/.../<hub_interface>/port<X>
>  Date:		August 2012
>  Contact:	Lan Tianyu <tianyu.lan@intel.com>
> diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
> index 8217032dfb85..da3c0f0dd633 100644
> --- a/drivers/usb/core/sysfs.c
> +++ b/drivers/usb/core/sysfs.c
> @@ -1232,9 +1232,59 @@ static const struct attribute_group intf_assoc_attr_grp = {
>  	.is_visible =	intf_assoc_attrs_are_visible,
>  };
>  
> +static ssize_t wireless_status_show(struct device *dev,
> +				    struct device_attribute *attr, char *buf)
> +{
> +	struct usb_interface *intf;
> +
> +	intf = to_usb_interface(dev);
> +	if (intf->wireless_status == USB_WIRELESS_STATUS_DISCONNECTED)
> +		return sysfs_emit(buf, "%s\n", "disconnected");
> +	return sysfs_emit(buf, "%s\n", "connected");
> +}
> +static DEVICE_ATTR_RO(wireless_status);
> +
> +static struct attribute *intf_wireless_status_attrs[] = {
> +	&dev_attr_wireless_status.attr,
> +	NULL
> +};
> +
> +static umode_t intf_wireless_status_attr_is_visible(struct kobject *kobj,
> +		struct attribute *a, int n)
> +{
> +	struct device *dev = kobj_to_dev(kobj);
> +	struct usb_interface *intf = to_usb_interface(dev);
> +
> +	if (a != &dev_attr_wireless_status.attr ||
> +	    intf->wireless_status != USB_WIRELESS_STATUS_NA)
> +		return a->mode;
> +	return 0;
> +}
> +
> +static const struct attribute_group intf_wireless_status_attr_grp = {
> +	.attrs =	intf_wireless_status_attrs,
> +	.is_visible =	intf_wireless_status_attr_is_visible,
> +};
> +
> +int usb_update_wireless_status_attr(struct usb_interface *intf)
> +{
> +	struct device *dev = &intf->dev;
> +	int ret;
> +
> +	ret = sysfs_update_group(&dev->kobj, &intf_wireless_status_attr_grp);
> +	if (ret < 0)
> +		return ret;
> +
> +	sysfs_notify(&dev->kobj, NULL, "wireless_status");
> +	kobject_uevent(&dev->kobj, KOBJ_CHANGE);

That could be very noisy, why does that deserve a KOBJ_CHANGE event?

thanks,

greg k-h

  reply	other threads:[~2023-02-23 13:52 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 13:24 [PATCH 1/5] HID: logitech-hidpp: Add support for ADC measurement feature Bastien Nocera
2023-02-23 13:24 ` [PATCH 2/5] HID: logitech-hidpp: Add Logitech G935 headset Bastien Nocera
2023-02-23 13:24 ` [PATCH 3/5] USB: core: Add wireless_status sysfs attribute Bastien Nocera
2023-02-23 13:51   ` Greg Kroah-Hartman [this message]
2023-02-23 14:58     ` Bastien Nocera
2023-02-23 13:24 ` [PATCH 4/5] USB: core: Add API to change the wireless_status Bastien Nocera
2023-02-23 13:52   ` Greg Kroah-Hartman
2023-02-23 14:59     ` Bastien Nocera
2023-02-23 15:41   ` Alan Stern
2023-02-23 16:17     ` Bastien Nocera
2023-02-23 16:25       ` Alan Stern
2023-02-23 16:51         ` Bastien Nocera
2023-02-23 17:07           ` Alan Stern
2023-02-23 23:04             ` Bastien Nocera
2023-02-24  2:34               ` Alan Stern
2023-02-28 16:23                 ` Bastien Nocera
2023-02-23 13:24 ` [PATCH 5/5] HID: logitech-hidpp: Set wireless_status for G935 receiver Bastien Nocera
2023-02-23 13:56 ` [PATCH 1/5] HID: logitech-hidpp: Add support for ADC measurement feature Greg Kroah-Hartman
2023-02-23 14:57   ` Bastien Nocera

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=Y/dvesNrHivGV6JK@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=benjamin.tissoires@redhat.com \
    --cc=hadess@hadess.net \
    --cc=lains@riseup.net \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nlopezcasad@logitech.com \
    --cc=stern@rowland.harvard.edu \
    /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