^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2012 Smith Micro Software, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) 2012 Bjørn Mork <bjorn@mork.no>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This driver is based on and reuse most of cdc_ncm, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) ST-Ericsson 2010-2012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mii.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/usb/cdc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/usb/usbnet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/usb/cdc-wdm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/usb/cdc_ncm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <net/ipv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/ipv6_stubs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /* alternative VLAN for IP session 0 if not untagged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define MBIM_IPS0_VID 4094
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) /* driver specific data - must match cdc_ncm usage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct cdc_mbim_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) struct cdc_ncm_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) atomic_t pmcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct usb_driver *subdriver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned long _unused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /* flags for the cdc_mbim_state.flags field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) enum cdc_mbim_flags {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) FLAG_IPS0_VLAN = 1 << 0, /* IP session 0 is tagged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* using a counter to merge subdriver requests with our own into a combined state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static int cdc_mbim_manage_power(struct usbnet *dev, int on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int rv = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) dev_dbg(&dev->intf->dev, "%s() pmcount=%d, on=%d\n", __func__, atomic_read(&info->pmcount), on);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if ((on && atomic_add_return(1, &info->pmcount) == 1) || (!on && atomic_dec_and_test(&info->pmcount))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* need autopm_get/put here to ensure the usbcore sees the new value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) rv = usb_autopm_get_interface(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) dev->intf->needs_remote_wakeup = on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (!rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) usb_autopm_put_interface(dev->intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int cdc_mbim_wdm_manage_power(struct usb_interface *intf, int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct usbnet *dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* can be called while disconnecting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return cdc_mbim_manage_power(dev, status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static int cdc_mbim_rx_add_vid(struct net_device *netdev, __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct usbnet *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* creation of this VLAN is a request to tag IP session 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (vid == MBIM_IPS0_VID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) info->flags |= FLAG_IPS0_VLAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (vid >= 512) /* we don't map these to MBIM session */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static int cdc_mbim_rx_kill_vid(struct net_device *netdev, __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct usbnet *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* this is a request for an untagged IP session 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (vid == MBIM_IPS0_VID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) info->flags &= ~FLAG_IPS0_VLAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static const struct net_device_ops cdc_mbim_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .ndo_open = usbnet_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .ndo_stop = usbnet_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .ndo_start_xmit = usbnet_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .ndo_tx_timeout = usbnet_tx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .ndo_get_stats64 = usbnet_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .ndo_change_mtu = cdc_ncm_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .ndo_set_mac_address = eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .ndo_vlan_rx_add_vid = cdc_mbim_rx_add_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .ndo_vlan_rx_kill_vid = cdc_mbim_rx_kill_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* Change the control interface altsetting and update the .driver_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * pointer if the matching entry after changing class codes points to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * a different struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int cdc_mbim_set_ctrlalt(struct usbnet *dev, struct usb_interface *intf, u8 alt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct usb_driver *driver = to_usb_driver(intf->dev.driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) const struct usb_device_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct driver_info *info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ret = usb_set_interface(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) intf->cur_altsetting->desc.bInterfaceNumber,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) alt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) id = usb_match_id(intf, driver->id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) info = (struct driver_info *)id->driver_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (info != dev->driver_info) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) dev_dbg(&intf->dev, "driver_info updated to '%s'\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) info->description);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) dev->driver_info = info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int cdc_mbim_bind(struct usbnet *dev, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct cdc_ncm_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct usb_driver *subdriver = ERR_PTR(-ENODEV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u8 data_altsetting = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* should we change control altsetting on a NCM/MBIM function? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (cdc_ncm_select_altsetting(intf) == CDC_NCM_COMM_ALTSETTING_MBIM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) data_altsetting = CDC_NCM_DATA_ALTSETTING_MBIM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ret = cdc_mbim_set_ctrlalt(dev, intf, CDC_NCM_COMM_ALTSETTING_MBIM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* we will hit this for NCM/MBIM functions if prefer_mbim is false */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (!cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ret = cdc_ncm_bind_common(dev, intf, data_altsetting, dev->driver_info->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ctx = info->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* The MBIM descriptor and the status endpoint are required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (ctx->mbim_desc && dev->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) subdriver = usb_cdc_wdm_register(ctx->control,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) &dev->status->desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) le16_to_cpu(ctx->mbim_desc->wMaxControlMessage),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) cdc_mbim_wdm_manage_power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (IS_ERR(subdriver)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) ret = PTR_ERR(subdriver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) cdc_ncm_unbind(dev, intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /* can't let usbnet use the interrupt endpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) dev->status = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) info->subdriver = subdriver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* MBIM cannot do ARP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) dev->net->flags |= IFF_NOARP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) /* no need to put the VLAN tci in the packet headers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) dev->net->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_FILTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /* monitor VLAN additions and removals */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) dev->net->netdev_ops = &cdc_mbim_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) static void cdc_mbim_unbind(struct usbnet *dev, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct cdc_ncm_ctx *ctx = info->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* disconnect subdriver from control interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (info->subdriver && info->subdriver->disconnect)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) info->subdriver->disconnect(ctx->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) info->subdriver = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* let NCM unbind clean up both control and data interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) cdc_ncm_unbind(dev, intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* verify that the ethernet protocol is IPv4 or IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static bool is_ip_proto(__be16 proto)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) switch (proto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) case htons(ETH_P_IP):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) case htons(ETH_P_IPV6):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) static struct sk_buff *cdc_mbim_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct sk_buff *skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct cdc_ncm_ctx *ctx = info->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) __le32 sign = cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) u16 tci = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) bool is_ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) u8 *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) if (skb->len <= ETH_HLEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) /* Some applications using e.g. packet sockets will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * bypass the VLAN acceleration and create tagged
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * ethernet frames directly. We primarily look for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * the accelerated out-of-band tag, but fall back if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (vlan_get_tag(skb, &tci) < 0 && skb->len > VLAN_ETH_HLEN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) __vlan_get_tag(skb, &tci) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) is_ip = is_ip_proto(vlan_eth_hdr(skb)->h_vlan_encapsulated_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) skb_pull(skb, VLAN_ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) is_ip = is_ip_proto(eth_hdr(skb)->h_proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) skb_pull(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* Is IP session <0> tagged too? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (info->flags & FLAG_IPS0_VLAN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* drop all untagged packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (!tci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* map MBIM_IPS0_VID to IPS<0> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (tci == MBIM_IPS0_VID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) tci = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* mapping VLANs to MBIM sessions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * no tag => IPS session <0> if !FLAG_IPS0_VLAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * 1 - 255 => IPS session <vlanid>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * 256 - 511 => DSS session <vlanid - 256>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * 512 - 4093 => unsupported, drop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * 4094 => IPS session <0> if FLAG_IPS0_VLAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) switch (tci & 0x0f00) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) case 0x0000: /* VLAN ID 0 - 255 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (!is_ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) c = (u8 *)&sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) c[3] = tci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case 0x0100: /* VLAN ID 256 - 511 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (is_ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) sign = cpu_to_le32(USB_CDC_MBIM_NDP16_DSS_SIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) c = (u8 *)&sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) c[3] = tci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) netif_err(dev, tx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) "unsupported tci=0x%04x\n", tci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) spin_lock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) skb_out = cdc_ncm_fill_tx_frame(dev, skb, sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) spin_unlock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* Some devices are known to send Neigbor Solicitation messages and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * require Neigbor Advertisement replies. The IPv6 core will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * respond since IFF_NOARP is set, so we must handle them ourselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) static void do_neigh_solicit(struct usbnet *dev, u8 *buf, u16 tci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct ipv6hdr *iph = (void *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct nd_msg *msg = (void *)(iph + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct net_device *netdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct inet6_dev *in6_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) bool is_router;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) /* we'll only respond to requests from unicast addresses to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * our solicited node addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (!ipv6_addr_is_solict_mult(&iph->daddr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) !(ipv6_addr_type(&iph->saddr) & IPV6_ADDR_UNICAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /* need to send the NA on the VLAN dev, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (tci) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) netdev = __vlan_find_dev_deep_rcu(dev->net, htons(ETH_P_8021Q),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) tci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (!netdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) netdev = dev->net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) dev_hold(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) in6_dev = in6_dev_get(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (!in6_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) is_router = !!in6_dev->cnf.forwarding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) in6_dev_put(in6_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) /* ipv6_stub != NULL if in6_dev_get returned an inet6_dev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ipv6_stub->ndisc_send_na(netdev, &iph->saddr, &msg->target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) is_router /* router */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) true /* solicited */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) false /* override */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) true /* inc_opt */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) dev_put(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static bool is_neigh_solicit(u8 *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct ipv6hdr *iph = (void *)buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) struct nd_msg *msg = (void *)(iph + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return (len >= sizeof(struct ipv6hdr) + sizeof(struct nd_msg) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) iph->nexthdr == IPPROTO_ICMPV6 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) msg->icmph.icmp6_code == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) msg->icmph.icmp6_type == NDISC_NEIGHBOUR_SOLICITATION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static struct sk_buff *cdc_mbim_process_dgram(struct usbnet *dev, u8 *buf, size_t len, u16 tci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) __be16 proto = htons(ETH_P_802_3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (tci < 256 || tci == MBIM_IPS0_VID) { /* IPS session? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (len < sizeof(struct iphdr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) switch (*buf & 0xf0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) case 0x40:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) proto = htons(ETH_P_IP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) case 0x60:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (is_neigh_solicit(buf, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) do_neigh_solicit(dev, buf, tci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) proto = htons(ETH_P_IPV6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) skb = netdev_alloc_skb_ip_align(dev->net, len + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) /* add an ethernet header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) skb_put(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) eth_hdr(skb)->h_proto = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) eth_zero_addr(eth_hdr(skb)->h_source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) memcpy(eth_hdr(skb)->h_dest, dev->net->dev_addr, ETH_ALEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /* add datagram */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) skb_put_data(skb, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* map MBIM session to VLAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (tci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) static int cdc_mbim_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) struct cdc_ncm_ctx *ctx = info->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) int nframes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct usb_cdc_ncm_ndp16 *ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) struct usb_cdc_ncm_dpe16 *dpe16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) int ndpoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) int loopcount = 50; /* arbitrary max preventing infinite loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) u32 payload = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) u8 *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) u16 tci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) ndpoffset = cdc_ncm_rx_verify_nth16(ctx, skb_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (ndpoffset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) next_ndp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) nframes = cdc_ncm_rx_verify_ndp16(skb_in, ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (nframes < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) switch (ndp16->dwSignature & cpu_to_le32(0x00ffffff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) case cpu_to_le32(USB_CDC_MBIM_NDP16_IPS_SIGN):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) c = (u8 *)&ndp16->dwSignature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) tci = c[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) /* tag IPS<0> packets too if MBIM_IPS0_VID exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (!tci && info->flags & FLAG_IPS0_VLAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) tci = MBIM_IPS0_VID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) case cpu_to_le32(USB_CDC_MBIM_NDP16_DSS_SIGN):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) c = (u8 *)&ndp16->dwSignature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) tci = c[3] + 256;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) "unsupported NDP signature <0x%08x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) le32_to_cpu(ndp16->dwSignature));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) goto err_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) dpe16 = ndp16->dpe16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) for (x = 0; x < nframes; x++, dpe16++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) offset = le16_to_cpu(dpe16->wDatagramIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) len = le16_to_cpu(dpe16->wDatagramLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * CDC NCM ch. 3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * All entries after first NULL entry are to be ignored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if ((offset == 0) || (len == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) goto err_ndp; /* empty NTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /* sanity checking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (((offset + len) > skb_in->len) || (len > ctx->rx_max)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) "invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) x, offset, len, skb_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) goto err_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) skb = cdc_mbim_process_dgram(dev, skb_in->data + offset, len, tci);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) usbnet_skb_return(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) payload += len; /* count payload bytes in this NTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) err_ndp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /* are there more NDPs to process? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (ndpoffset && loopcount--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) goto next_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) /* update stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) ctx->rx_overhead += skb_in->len - payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ctx->rx_ntbs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) static int cdc_mbim_suspend(struct usb_interface *intf, pm_message_t message)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) int ret = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct usbnet *dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct cdc_ncm_ctx *ctx = info->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * Both usbnet_suspend() and subdriver->suspend() MUST return 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * in system sleep context, otherwise, the resume callback has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * to recover device from previous suspend failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) ret = usbnet_suspend(intf, message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (intf == ctx->control && info->subdriver && info->subdriver->suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) ret = info->subdriver->suspend(intf, message);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) usbnet_resume(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static int cdc_mbim_resume(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) struct usbnet *dev = usb_get_intfdata(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct cdc_mbim_state *info = (void *)&dev->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct cdc_ncm_ctx *ctx = info->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) bool callsub = (intf == ctx->control && info->subdriver && info->subdriver->resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) if (callsub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) ret = info->subdriver->resume(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) ret = usbnet_resume(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (ret < 0 && callsub)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) info->subdriver->suspend(intf, PMSG_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) static const struct driver_info cdc_mbim_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) .description = "CDC MBIM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) .bind = cdc_mbim_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) .unbind = cdc_mbim_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) .manage_power = cdc_mbim_manage_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) .rx_fixup = cdc_mbim_rx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) .tx_fixup = cdc_mbim_tx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /* MBIM and NCM devices should not need a ZLP after NTBs with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) * dwNtbOutMaxSize length. Nevertheless, a number of devices from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) * different vendor IDs will fail unless we send ZLPs, forcing us
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) * to make this the default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * This default may cause a performance penalty for spec conforming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * devices wanting to take advantage of optimizations possible without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * ZLPs. A whitelist is added in an attempt to avoid this for devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * known to conform to the MBIM specification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * All known devices supporting NCM compatibility mode are also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * conforming to the NCM and MBIM specifications. For this reason, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * NCM subclass entry is also in the ZLP whitelist.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static const struct driver_info cdc_mbim_info_zlp = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .description = "CDC MBIM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN | FLAG_SEND_ZLP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) .bind = cdc_mbim_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) .unbind = cdc_mbim_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) .manage_power = cdc_mbim_manage_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) .rx_fixup = cdc_mbim_rx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) .tx_fixup = cdc_mbim_tx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) /* The spefication explicitly allows NDPs to be placed anywhere in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) * frame, but some devices fail unless the NDP is placed after the IP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) * packets. Using the CDC_NCM_FLAG_NDP_TO_END flags to force this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) * behaviour.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * Note: The current implementation of this feature restricts each NTB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * to a single NDP, implying that multiplexed sessions cannot share an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) * NTB. This might affect performace for multiplexed sessions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static const struct driver_info cdc_mbim_info_ndp_to_end = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) .description = "CDC MBIM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) .bind = cdc_mbim_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) .unbind = cdc_mbim_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) .manage_power = cdc_mbim_manage_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) .rx_fixup = cdc_mbim_rx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) .tx_fixup = cdc_mbim_tx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) .data = CDC_NCM_FLAG_NDP_TO_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) /* Some modems (e.g. Telit LE922A6) do not work properly with altsetting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) * toggle done in cdc_ncm_bind_common. CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) * flag is used to avoid this procedure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) static const struct driver_info cdc_mbim_info_avoid_altsetting_toggle = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) .description = "CDC MBIM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) .flags = FLAG_NO_SETINT | FLAG_MULTI_PACKET | FLAG_WWAN | FLAG_SEND_ZLP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) .bind = cdc_mbim_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) .unbind = cdc_mbim_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) .manage_power = cdc_mbim_manage_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) .rx_fixup = cdc_mbim_rx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) .tx_fixup = cdc_mbim_tx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) .data = CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) static const struct usb_device_id mbim_devs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) /* This duplicate NCM entry is intentional. MBIM devices can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) * be disguised as NCM by default, and this is necessary to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) * allow us to bind the correct driver_info to such devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) * bind() will sort out this for us, selecting the correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) * entry and reject the other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) .driver_info = (unsigned long)&cdc_mbim_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /* ZLP conformance whitelist: All Ericsson MBIM devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) { USB_VENDOR_AND_INTERFACE_INFO(0x0bdb, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) .driver_info = (unsigned long)&cdc_mbim_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* Some Huawei devices, ME906s-158 (12d1:15c1) and E3372
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * (12d1:157d), are known to fail unless the NDP is placed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * after the IP packets. Applying the quirk to all Huawei
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * devices is broader than necessary, but harmless.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) { USB_VENDOR_AND_INTERFACE_INFO(0x12d1, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) .driver_info = (unsigned long)&cdc_mbim_info_ndp_to_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* The HP lt4132 (03f0:a31d) is a rebranded Huawei ME906s-158,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * therefore it too requires the above "NDP to end" quirk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) { USB_DEVICE_AND_INTERFACE_INFO(0x03f0, 0xa31d, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) .driver_info = (unsigned long)&cdc_mbim_info_ndp_to_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* Telit LE922A6 in MBIM composition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) { USB_DEVICE_AND_INTERFACE_INFO(0x1bc7, 0x1041, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) .driver_info = (unsigned long)&cdc_mbim_info_avoid_altsetting_toggle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) /* Telit LN920 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) { USB_DEVICE_AND_INTERFACE_INFO(0x1bc7, 0x1061, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) .driver_info = (unsigned long)&cdc_mbim_info_avoid_altsetting_toggle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /* Telit FN990 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) { USB_DEVICE_AND_INTERFACE_INFO(0x1bc7, 0x1071, USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) .driver_info = (unsigned long)&cdc_mbim_info_avoid_altsetting_toggle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) /* default entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) { USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MBIM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) .driver_info = (unsigned long)&cdc_mbim_info_zlp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) MODULE_DEVICE_TABLE(usb, mbim_devs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) static struct usb_driver cdc_mbim_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) .name = "cdc_mbim",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) .id_table = mbim_devs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) .probe = usbnet_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) .disconnect = usbnet_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) .suspend = cdc_mbim_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) .resume = cdc_mbim_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) .reset_resume = cdc_mbim_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) .supports_autosuspend = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) .disable_hub_initiated_lpm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) module_usb_driver(cdc_mbim_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) MODULE_AUTHOR("Greg Suarez <gsuarez@smithmicro.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) MODULE_AUTHOR("Bjørn Mork <bjorn@mork.no>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) MODULE_DESCRIPTION("USB CDC MBIM host driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) MODULE_LICENSE("GPL");