kernel: bump 5.10 to 5.10.109
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 795-v5.13-r8152-search-the-configuration-of-vendor-mode.patch
1 From 579f58dd2819910354753bc5489fc1588fe9cfe2 Mon Sep 17 00:00:00 2001
2 From: Hayes Wang <hayeswang@realtek.com>
3 Date: Fri, 16 Apr 2021 16:04:37 +0800
4 Subject: [PATCH] r8152: search the configuration of vendor mode
5
6 commit c2198943e33b100ed21dfb636c8fa6baef841e9d upstream.
7
8 The vendor mode is not always at config #1, so it is necessary to
9 set the correct configuration number.
10
11 Signed-off-by: Hayes Wang <hayeswang@realtek.com>
12 Signed-off-by: David S. Miller <davem@davemloft.net>
13 ---
14 drivers/net/usb/r8152.c | 39 +++++++++++++++++++++++++++++++++++----
15 1 file changed, 35 insertions(+), 4 deletions(-)
16
17 --- a/drivers/net/usb/r8152.c
18 +++ b/drivers/net/usb/r8152.c
19 @@ -29,7 +29,7 @@
20 #include <linux/usb/r8152.h>
21
22 /* Information for net-next */
23 -#define NETNEXT_VERSION "11"
24 +#define NETNEXT_VERSION "12"
25
26 /* Information for net */
27 #define NET_VERSION "11"
28 @@ -8108,6 +8108,39 @@ static void r8156b_init(struct r8152 *tp
29 tp->coalesce = 15000; /* 15 us */
30 }
31
32 +static bool rtl_vendor_mode(struct usb_interface *intf)
33 +{
34 + struct usb_host_interface *alt = intf->cur_altsetting;
35 + struct usb_device *udev;
36 + struct usb_host_config *c;
37 + int i, num_configs;
38 +
39 + if (alt->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC)
40 + return true;
41 +
42 + /* The vendor mode is not always config #1, so to find it out. */
43 + udev = interface_to_usbdev(intf);
44 + c = udev->config;
45 + num_configs = udev->descriptor.bNumConfigurations;
46 + for (i = 0; i < num_configs; (i++, c++)) {
47 + struct usb_interface_descriptor *desc = NULL;
48 +
49 + if (c->desc.bNumInterfaces > 0)
50 + desc = &c->intf_cache[0]->altsetting->desc;
51 + else
52 + continue;
53 +
54 + if (desc->bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
55 + usb_driver_set_configuration(udev, c->desc.bConfigurationValue);
56 + break;
57 + }
58 + }
59 +
60 + WARN_ON_ONCE(i == num_configs);
61 +
62 + return false;
63 +}
64 +
65 static int rtl8152_pre_reset(struct usb_interface *intf)
66 {
67 struct r8152 *tp = usb_get_intfdata(intf);
68 @@ -9346,10 +9379,8 @@ static int rtl8152_probe(struct usb_inte
69 if (version == RTL_VER_UNKNOWN)
70 return -ENODEV;
71
72 - if (udev->actconfig->desc.bConfigurationValue != 1) {
73 - usb_driver_set_configuration(udev, 1);
74 + if (!rtl_vendor_mode(intf))
75 return -ENODEV;
76 - }
77
78 if (intf->cur_altsetting->desc.bNumEndpoints < 3)
79 return -ENODEV;