ath25: switch default kernel to 5.15
[openwrt/openwrt.git] / target / linux / generic / backport-5.10 / 881-v5.19-rndis_host-enable-the-bogus-MAC-fixup-for-ZTE-device.patch
1 From 69a9efb689b43fedf5f19431f1889aa6b8d35d55 Mon Sep 17 00:00:00 2001
2 From: Lech Perczak <lech.perczak@gmail.com>
3 Date: Fri, 1 Apr 2022 22:04:01 +0200
4 Subject: [PATCH 2/3] rndis_host: enable the bogus MAC fixup for ZTE devices
5 from cdc_ether
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 Certain ZTE modems, namely: MF823. MF831, MF910, built-in modem from
11 MF286R, expose both CDC-ECM and RNDIS network interfaces.
12 They have a trait of ignoring the locally-administered MAC address
13 configured on the interface both in CDC-ECM and RNDIS part,
14 and this leads to dropping of incoming traffic by the host.
15 However, the workaround was only present in CDC-ECM, and MF286R
16 explicitly requires it in RNDIS mode.
17
18 Re-use the workaround in rndis_host as well, to fix operation of MF286R
19 module, some versions of which expose only the RNDIS interface. Do so by
20 introducing new flag, RNDIS_DRIVER_DATA_DST_MAC_FIXUP, and testing for it
21 in rndis_rx_fixup. This is required, as RNDIS uses frame batching, and all
22 of the packets inside the batch need the fixup. This might introduce a
23 performance penalty, because test is done for every returned Ethernet
24 frame.
25
26 Apply the workaround to both "flavors" of RNDIS interfaces, as older ZTE
27 modems, like MF823 found in the wild, report the USB_CLASS_COMM class
28 interfaces, while MF286R reports USB_CLASS_WIRELESS_CONTROLLER.
29
30 Suggested-by: Bjørn Mork <bjorn@mork.no>
31 Cc: Kristian Evensen <kristian.evensen@gmail.com>
32 Cc: Oliver Neukum <oliver@neukum.org>
33 Signed-off-by: Lech Perczak <lech.perczak@gmail.com>
34 ---
35 drivers/net/usb/rndis_host.c | 32 ++++++++++++++++++++++++++++++++
36 include/linux/usb/rndis_host.h | 1 +
37 2 files changed, 33 insertions(+)
38
39 --- a/drivers/net/usb/rndis_host.c
40 +++ b/drivers/net/usb/rndis_host.c
41 @@ -486,10 +486,14 @@ EXPORT_SYMBOL_GPL(rndis_unbind);
42 */
43 int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
44 {
45 + bool dst_mac_fixup;
46 +
47 /* This check is no longer done by usbnet */
48 if (skb->len < dev->net->hard_header_len)
49 return 0;
50
51 + dst_mac_fixup = !!(dev->driver_info->data & RNDIS_DRIVER_DATA_DST_MAC_FIXUP);
52 +
53 /* peripheral may have batched packets to us... */
54 while (likely(skb->len)) {
55 struct rndis_data_hdr *hdr = (void *)skb->data;
56 @@ -524,10 +528,17 @@ int rndis_rx_fixup(struct usbnet *dev, s
57 break;
58 skb_pull(skb, msg_len - sizeof *hdr);
59 skb_trim(skb2, data_len);
60 +
61 + if (unlikely(dst_mac_fixup))
62 + usbnet_cdc_zte_rx_fixup(dev, skb2);
63 +
64 usbnet_skb_return(dev, skb2);
65 }
66
67 /* caller will usbnet_skb_return the remaining packet */
68 + if (unlikely(dst_mac_fixup))
69 + usbnet_cdc_zte_rx_fixup(dev, skb);
70 +
71 return 1;
72 }
73 EXPORT_SYMBOL_GPL(rndis_rx_fixup);
74 @@ -601,6 +612,17 @@ static const struct driver_info rndis_po
75 .tx_fixup = rndis_tx_fixup,
76 };
77
78 +static const struct driver_info zte_rndis_info = {
79 + .description = "ZTE RNDIS device",
80 + .flags = FLAG_ETHER | FLAG_POINTTOPOINT | FLAG_FRAMING_RN | FLAG_NO_SETINT,
81 + .data = RNDIS_DRIVER_DATA_DST_MAC_FIXUP,
82 + .bind = rndis_bind,
83 + .unbind = rndis_unbind,
84 + .status = rndis_status,
85 + .rx_fixup = rndis_rx_fixup,
86 + .tx_fixup = rndis_tx_fixup,
87 +};
88 +
89 /*-------------------------------------------------------------------------*/
90
91 static const struct usb_device_id products [] = {
92 @@ -610,6 +632,16 @@ static const struct usb_device_id produc
93 USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
94 .driver_info = (unsigned long) &rndis_poll_status_info,
95 }, {
96 + /* ZTE WWAN modules */
97 + USB_VENDOR_AND_INTERFACE_INFO(0x19d2,
98 + USB_CLASS_WIRELESS_CONTROLLER, 1, 3),
99 + .driver_info = (unsigned long)&zte_rndis_info,
100 +}, {
101 + /* ZTE WWAN modules, ACM flavour */
102 + USB_VENDOR_AND_INTERFACE_INFO(0x19d2,
103 + USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
104 + .driver_info = (unsigned long)&zte_rndis_info,
105 +}, {
106 /* Hytera Communications DMR radios' "Radio to PC Network" */
107 USB_VENDOR_AND_INTERFACE_INFO(0x238b,
108 USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
109 --- a/include/linux/usb/rndis_host.h
110 +++ b/include/linux/usb/rndis_host.h
111 @@ -197,6 +197,7 @@ struct rndis_keepalive_c { /* IN (option
112
113 /* Flags for driver_info::data */
114 #define RNDIS_DRIVER_DATA_POLL_STATUS 1 /* poll status before control */
115 +#define RNDIS_DRIVER_DATA_DST_MAC_FIXUP 2 /* device ignores configured MAC address */
116
117 extern void rndis_status(struct usbnet *dev, struct urb *urb);
118 extern int