public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: Ivan Hu <ivan.hu@canonical.com>
To: gregkh@linuxfoundation.org, krzysztof.kozlowski@linaro.org,
	limiao@kylinos.cn, wangyuli@uniontech.com,
	jinxiaobo@uniontech.com, huanglei@kylinos.cn,
	mathias.nyman@linux.intel.com
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: quirks: Add quirk to prefer vendor-specific configuration
Date: Thu, 10 Apr 2025 10:46:26 +0800	[thread overview]
Message-ID: <20250410024626.981215-1-ivan.hu@canonical.com> (raw)

Some USB devices with multiple configurations expose a vendor-specific
interface class that should be preferred by default. However, the generic
usb_choose_configuration() logic selects the first configuration whose
first interface uses a non-vendor-specific class, which can lead to
incomplete or limited functionality.

Introduce a new quirk, USB_QUIRK_CHOOSE_VENDOR_SPEC_CFG, which
instructs the USB core to prefer a configuration that contains a
vendor-specific interface class when multiple configurations are present.

Apply this quirk to the ASIX AX88179 USB Ethernet adapter
(0x0b95:0x1790), which requires selecting its vendor-specific
configuration for full functionality, instead of falling back to
cdc_ncm.

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 drivers/usb/core/generic.c | 15 +++++++++++++++
 drivers/usb/core/quirks.c  |  3 +++
 include/linux/usb/quirks.h |  3 +++
 3 files changed, 21 insertions(+)

diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
index 9c6ae5e1198b..19bf35ede5a0 100644
--- a/drivers/usb/core/generic.c
+++ b/drivers/usb/core/generic.c
@@ -23,6 +23,7 @@
 #include <linux/usb/hcd.h>
 #include <linux/string_choices.h>
 #include <uapi/linux/usb/audio.h>
+#include <linux/usb/quirks.h>
 #include "usb.h"
 
 static int is_rndis(struct usb_interface_descriptor *desc)
@@ -155,6 +156,20 @@ int usb_choose_configuration(struct usb_device *udev)
 			continue;
 		}
 
+		/* This quirk forces the selection of a vendor-specific
+		 * interface class configuration when multiple configurations
+		 * are present.
+		 */
+		if (num_configs > 1 &&
+			udev->descriptor.bDeviceClass ==
+						USB_CLASS_PER_INTERFACE &&
+				udev->quirks & USB_QUIRK_CHOOSE_VENDOR_SPEC_CFG
+				&& (desc && desc->bInterfaceClass ==
+						USB_CLASS_VENDOR_SPEC)) {
+			best = c;
+			break;
+		}
+
 		/* When the first config's first interface is one of Microsoft's
 		 * pet nonstandard Ethernet-over-USB protocols, ignore it unless
 		 * this kernel has enabled the necessary host side driver.
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index 8efbacc5bc34..1e0e05cb29df 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -565,6 +565,9 @@ static const struct usb_device_id usb_quirk_list[] = {
 	/* INTEL VALUE SSD */
 	{ USB_DEVICE(0x8086, 0xf1a5), .driver_info = USB_QUIRK_RESET_RESUME },
 
+	/* ASIX AS88179 */
+	{ USB_DEVICE(0x0b95, 0x1790), .driver_info = USB_QUIRK_CHOOSE_VENDOR_SPEC_CFG },
+
 	{ }  /* terminating entry must be last */
 };
 
diff --git a/include/linux/usb/quirks.h b/include/linux/usb/quirks.h
index 59409c1fc3de..1f73bfc191f0 100644
--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -75,4 +75,7 @@
 /* short SET_ADDRESS request timeout */
 #define USB_QUIRK_SHORT_SET_ADDRESS_REQ_TIMEOUT	BIT(16)
 
+/* force selection of vendor-specific configuration*/
+#define USB_QUIRK_CHOOSE_VENDOR_SPEC_CFG	BIT(17)
+
 #endif /* __LINUX_USB_QUIRKS_H */
-- 
2.34.1


             reply	other threads:[~2025-04-10  2:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-10  2:46 Ivan Hu [this message]
2025-04-10  6:58 ` [PATCH] usb: quirks: Add quirk to prefer vendor-specific configuration Greg KH
2025-04-11  5:25   ` ivanhu
2025-04-11  5:47     ` 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=20250410024626.981215-1-ivan.hu@canonical.com \
    --to=ivan.hu@canonical.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=huanglei@kylinos.cn \
    --cc=jinxiaobo@uniontech.com \
    --cc=krzysztof.kozlowski@linaro.org \
    --cc=limiao@kylinos.cn \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=wangyuli@uniontech.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