^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * cdc_ncm.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) ST-Ericsson 2010-2012
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Contact: Alexey Orishko <alexey.orishko@stericsson.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Original author: Hans Petter Selasky <hans.petter.selasky@stericsson.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * USB Host Driver for Network Control Model (NCM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * http://www.usb.org/developers/docs/devclass_docs/NCM10_012011.zip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * The NCM encoding, decoding and initialization logic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * derives from FreeBSD 8.x. if_cdce.c and if_cdcereg.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * licenses. You may choose this file to be licensed under the terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * of the GNU General Public License (GPL) Version 2 or the 2-clause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * BSD license listed below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Redistribution and use in source and binary forms, with or without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * modification, are permitted provided that the following conditions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * 1. Redistributions of source code must retain the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * notice, this list of conditions and the following disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * 2. Redistributions in binary form must reproduce the above copyright
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * notice, this list of conditions and the following disclaimer in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * documentation and/or other materials provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * SUCH DAMAGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/mii.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/usb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/hrtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/usb/usbnet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/usb/cdc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/usb/cdc_ncm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #if IS_ENABLED(CONFIG_USB_NET_CDC_MBIM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static bool prefer_mbim = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static bool prefer_mbim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) module_param(prefer_mbim, bool, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) MODULE_PARM_DESC(prefer_mbim, "Prefer MBIM setting on dual NCM/MBIM functions");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static void cdc_ncm_txpath_bh(unsigned long param);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static struct usb_driver cdc_ncm_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct cdc_ncm_stats {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) char stat_string[ETH_GSTRING_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int sizeof_stat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int stat_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define CDC_NCM_STAT(str, m) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .stat_string = str, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .sizeof_stat = sizeof(((struct cdc_ncm_ctx *)0)->m), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .stat_offset = offsetof(struct cdc_ncm_ctx, m) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define CDC_NCM_SIMPLE_STAT(m) CDC_NCM_STAT(__stringify(m), m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static const struct cdc_ncm_stats cdc_ncm_gstrings_stats[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) CDC_NCM_SIMPLE_STAT(tx_reason_ntb_full),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) CDC_NCM_SIMPLE_STAT(tx_reason_ndp_full),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) CDC_NCM_SIMPLE_STAT(tx_reason_timeout),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) CDC_NCM_SIMPLE_STAT(tx_reason_max_datagram),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) CDC_NCM_SIMPLE_STAT(tx_overhead),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) CDC_NCM_SIMPLE_STAT(tx_ntbs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) CDC_NCM_SIMPLE_STAT(rx_overhead),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) CDC_NCM_SIMPLE_STAT(rx_ntbs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #define CDC_NCM_LOW_MEM_MAX_CNT 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static int cdc_ncm_get_sset_count(struct net_device __always_unused *netdev, int sset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) switch (sset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case ETH_SS_STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return ARRAY_SIZE(cdc_ncm_gstrings_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static void cdc_ncm_get_ethtool_stats(struct net_device *netdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct ethtool_stats __always_unused *stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) u64 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct usbnet *dev = netdev_priv(netdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) char *p = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) for (i = 0; i < ARRAY_SIZE(cdc_ncm_gstrings_stats); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) p = (char *)ctx + cdc_ncm_gstrings_stats[i].stat_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) data[i] = (cdc_ncm_gstrings_stats[i].sizeof_stat == sizeof(u64)) ? *(u64 *)p : *(u32 *)p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static void cdc_ncm_get_strings(struct net_device __always_unused *netdev, u32 stringset, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u8 *p = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) switch (stringset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) case ETH_SS_STATS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) for (i = 0; i < ARRAY_SIZE(cdc_ncm_gstrings_stats); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) memcpy(p, cdc_ncm_gstrings_stats[i].stat_string, ETH_GSTRING_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) p += ETH_GSTRING_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) static void cdc_ncm_update_rxtx_max(struct usbnet *dev, u32 new_rx, u32 new_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static const struct ethtool_ops cdc_ncm_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) .get_link = usbnet_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .nway_reset = usbnet_nway_reset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .get_drvinfo = usbnet_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .get_msglevel = usbnet_get_msglevel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .set_msglevel = usbnet_set_msglevel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .get_ts_info = ethtool_op_get_ts_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .get_sset_count = cdc_ncm_get_sset_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .get_strings = cdc_ncm_get_strings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) .get_ethtool_stats = cdc_ncm_get_ethtool_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .get_link_ksettings = usbnet_get_link_ksettings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) .set_link_ksettings = usbnet_set_link_ksettings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static u32 cdc_ncm_check_rx_max(struct usbnet *dev, u32 new_rx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) u32 val, max, min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* clamp new_rx to sane values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) min = USB_CDC_NCM_NTB_MIN_IN_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) max = min_t(u32, CDC_NCM_NTB_MAX_SIZE_RX, le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* dwNtbInMaxSize spec violation? Use MIN size for both limits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (max < min) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) dev_warn(&dev->intf->dev, "dwNtbInMaxSize=%u is too small. Using %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize), min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) max = min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) val = clamp_t(u32, new_rx, min, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (val != new_rx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) dev_dbg(&dev->intf->dev, "rx_max must be in the [%u, %u] range\n", min, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static u32 cdc_ncm_check_tx_max(struct usbnet *dev, u32 new_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) u32 val, max, min;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* clamp new_tx to sane values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) min = ctx->max_datagram_size + ctx->max_ndp_size + sizeof(struct usb_cdc_ncm_nth16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) min = ctx->max_datagram_size + ctx->max_ndp_size + sizeof(struct usb_cdc_ncm_nth32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) max = min_t(u32, CDC_NCM_NTB_MAX_SIZE_TX, le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (max == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) max = CDC_NCM_NTB_MAX_SIZE_TX; /* dwNtbOutMaxSize not set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* some devices set dwNtbOutMaxSize too low for the above default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) min = min(min, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) val = clamp_t(u32, new_tx, min, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (val != new_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) dev_dbg(&dev->intf->dev, "tx_max must be in the [%u, %u] range\n", min, max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static ssize_t cdc_ncm_show_min_tx_pkt(struct device *d, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return sprintf(buf, "%u\n", ctx->min_tx_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) static ssize_t cdc_ncm_show_rx_max(struct device *d, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) return sprintf(buf, "%u\n", ctx->rx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static ssize_t cdc_ncm_show_tx_max(struct device *d, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return sprintf(buf, "%u\n", ctx->tx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static ssize_t cdc_ncm_show_tx_timer_usecs(struct device *d, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return sprintf(buf, "%u\n", ctx->timer_interval / (u32)NSEC_PER_USEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static ssize_t cdc_ncm_store_min_tx_pkt(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* no need to restrict values - anything from 0 to infinity is OK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (kstrtoul(buf, 0, &val))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ctx->min_tx_pkt = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static ssize_t cdc_ncm_store_rx_max(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (kstrtoul(buf, 0, &val) || cdc_ncm_check_rx_max(dev, val) != val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) cdc_ncm_update_rxtx_max(dev, val, ctx->tx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static ssize_t cdc_ncm_store_tx_max(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (kstrtoul(buf, 0, &val) || cdc_ncm_check_tx_max(dev, val) != val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) cdc_ncm_update_rxtx_max(dev, ctx->rx_max, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static ssize_t cdc_ncm_store_tx_timer_usecs(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) unsigned long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) ret = kstrtoul(buf, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (val && (val < CDC_NCM_TIMER_INTERVAL_MIN || val > CDC_NCM_TIMER_INTERVAL_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) spin_lock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) ctx->timer_interval = val * NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (!ctx->timer_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) ctx->tx_timer_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) spin_unlock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return len;
^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) static DEVICE_ATTR(min_tx_pkt, 0644, cdc_ncm_show_min_tx_pkt, cdc_ncm_store_min_tx_pkt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static DEVICE_ATTR(rx_max, 0644, cdc_ncm_show_rx_max, cdc_ncm_store_rx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static DEVICE_ATTR(tx_max, 0644, cdc_ncm_show_tx_max, cdc_ncm_store_tx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static DEVICE_ATTR(tx_timer_usecs, 0644, cdc_ncm_show_tx_timer_usecs, cdc_ncm_store_tx_timer_usecs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static ssize_t ndp_to_end_show(struct device *d, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) return sprintf(buf, "%c\n", ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END ? 'Y' : 'N');
^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) static ssize_t ndp_to_end_store(struct device *d, struct device_attribute *attr, const char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct usbnet *dev = netdev_priv(to_net_dev(d));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) bool enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if (strtobool(buf, &enable))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* no change? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (enable == (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (ctx->is_ndp16 && !ctx->delayed_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (!ctx->delayed_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (!ctx->is_ndp16 && !ctx->delayed_ndp32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ctx->delayed_ndp32 = kzalloc(ctx->max_ndp_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (!ctx->delayed_ndp32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* flush pending data before changing flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) netif_tx_lock_bh(dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) usbnet_start_xmit(NULL, dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) spin_lock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ctx->drvflags |= CDC_NCM_FLAG_NDP_TO_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ctx->drvflags &= ~CDC_NCM_FLAG_NDP_TO_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) spin_unlock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) netif_tx_unlock_bh(dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static DEVICE_ATTR_RW(ndp_to_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #define NCM_PARM_ATTR(name, format, tocpu) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static ssize_t cdc_ncm_show_##name(struct device *d, struct device_attribute *attr, char *buf) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct usbnet *dev = netdev_priv(to_net_dev(d)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return sprintf(buf, format "\n", tocpu(ctx->ncm_parm.name)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static DEVICE_ATTR(name, 0444, cdc_ncm_show_##name, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) NCM_PARM_ATTR(bmNtbFormatsSupported, "0x%04x", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) NCM_PARM_ATTR(dwNtbInMaxSize, "%u", le32_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) NCM_PARM_ATTR(wNdpInDivisor, "%u", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) NCM_PARM_ATTR(wNdpInPayloadRemainder, "%u", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) NCM_PARM_ATTR(wNdpInAlignment, "%u", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) NCM_PARM_ATTR(dwNtbOutMaxSize, "%u", le32_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) NCM_PARM_ATTR(wNdpOutDivisor, "%u", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) NCM_PARM_ATTR(wNdpOutPayloadRemainder, "%u", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) NCM_PARM_ATTR(wNdpOutAlignment, "%u", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) NCM_PARM_ATTR(wNtbOutMaxDatagrams, "%u", le16_to_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) static struct attribute *cdc_ncm_sysfs_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) &dev_attr_min_tx_pkt.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) &dev_attr_ndp_to_end.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) &dev_attr_rx_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) &dev_attr_tx_max.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) &dev_attr_tx_timer_usecs.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) &dev_attr_bmNtbFormatsSupported.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) &dev_attr_dwNtbInMaxSize.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) &dev_attr_wNdpInDivisor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) &dev_attr_wNdpInPayloadRemainder.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) &dev_attr_wNdpInAlignment.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) &dev_attr_dwNtbOutMaxSize.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) &dev_attr_wNdpOutDivisor.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) &dev_attr_wNdpOutPayloadRemainder.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) &dev_attr_wNdpOutAlignment.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) &dev_attr_wNtbOutMaxDatagrams.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static const struct attribute_group cdc_ncm_sysfs_attr_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) .name = "cdc_ncm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) .attrs = cdc_ncm_sysfs_attrs,
^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) /* handle rx_max and tx_max changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static void cdc_ncm_update_rxtx_max(struct usbnet *dev, u32 new_rx, u32 new_tx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) val = cdc_ncm_check_rx_max(dev, new_rx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /* inform device about NTB input size changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) if (val != ctx->rx_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) __le32 dwNtbInMaxSize = cpu_to_le32(val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) dev_info(&dev->intf->dev, "setting rx_max = %u\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /* tell device to use new size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (usbnet_write_cmd(dev, USB_CDC_SET_NTB_INPUT_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) USB_TYPE_CLASS | USB_DIR_OUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 0, iface_no, &dwNtbInMaxSize, 4) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) dev_dbg(&dev->intf->dev, "Setting NTB Input Size failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ctx->rx_max = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /* usbnet use these values for sizing rx queues */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (dev->rx_urb_size != ctx->rx_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) dev->rx_urb_size = ctx->rx_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) if (netif_running(dev->net))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) usbnet_unlink_rx_urbs(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) val = cdc_ncm_check_tx_max(dev, new_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (val != ctx->tx_max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) dev_info(&dev->intf->dev, "setting tx_max = %u\n", val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) /* Adding a pad byte here if necessary simplifies the handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * in cdc_ncm_fill_tx_frame, making tx_max always represent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) * the real skb max size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * We cannot use dev->maxpacket here because this is called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * .bind which is called before usbnet sets up dev->maxpacket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (val != le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) val % usb_maxpacket(dev->udev, dev->out, 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) val++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* we might need to flush any pending tx buffers if running */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (netif_running(dev->net) && val > ctx->tx_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) netif_tx_lock_bh(dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) usbnet_start_xmit(NULL, dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /* make sure tx_curr_skb is reallocated if it was empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (ctx->tx_curr_skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) dev_kfree_skb_any(ctx->tx_curr_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) ctx->tx_curr_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ctx->tx_max = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) netif_tx_unlock_bh(dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) ctx->tx_max = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) dev->hard_mtu = ctx->tx_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /* max qlen depend on hard_mtu and rx_urb_size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) usbnet_update_max_qlen(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* never pad more than 3 full USB packets per transfer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) ctx->min_tx_pkt = clamp_t(u16, ctx->tx_max - 3 * usb_maxpacket(dev->udev, dev->out, 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) CDC_NCM_MIN_TX_PKT, ctx->tx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* helpers for NCM and MBIM differences */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static u8 cdc_ncm_flags(struct usbnet *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting) && ctx->mbim_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return ctx->mbim_desc->bmNetworkCapabilities;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) if (ctx->func_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return ctx->func_desc->bmNetworkCapabilities;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) return 0;
^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) static int cdc_ncm_eth_hlen(struct usbnet *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) return ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) static u32 cdc_ncm_min_dgram_size(struct usbnet *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return CDC_MBIM_MIN_DATAGRAM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) return CDC_NCM_MIN_DATAGRAM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) static u32 cdc_ncm_max_dgram_size(struct usbnet *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (cdc_ncm_comm_intf_is_mbim(dev->intf->cur_altsetting) && ctx->mbim_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return le16_to_cpu(ctx->mbim_desc->wMaxSegmentSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (ctx->ether_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return le16_to_cpu(ctx->ether_desc->wMaxSegmentSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) return CDC_NCM_MAX_DATAGRAM_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* initial one-time device setup. MUST be called with the data interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * in altsetting 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static int cdc_ncm_init(struct usbnet *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) err = usbnet_read_cmd(dev, USB_CDC_GET_NTB_PARAMETERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) USB_TYPE_CLASS | USB_DIR_IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) |USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 0, iface_no, &ctx->ncm_parm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) sizeof(ctx->ncm_parm));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) dev_err(&dev->intf->dev, "failed GET_NTB_PARAMETERS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return err; /* GET_NTB_PARAMETERS is required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) /* set CRC Mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (cdc_ncm_flags(dev) & USB_CDC_NCM_NCAP_CRC_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) dev_dbg(&dev->intf->dev, "Setting CRC mode off\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) err = usbnet_write_cmd(dev, USB_CDC_SET_CRC_MODE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) USB_TYPE_CLASS | USB_DIR_OUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) USB_CDC_NCM_CRC_NOT_APPENDED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) iface_no, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) dev_err(&dev->intf->dev, "SET_CRC_MODE failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* use ndp16 by default */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) ctx->is_ndp16 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) /* set NTB format, if both formats are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * "The host shall only send this command while the NCM Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * Interface is in alternate setting 0."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (le16_to_cpu(ctx->ncm_parm.bmNtbFormatsSupported) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) USB_CDC_NCM_NTB32_SUPPORTED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (ctx->drvflags & CDC_NCM_FLAG_PREFER_NTB32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) ctx->is_ndp16 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) dev_dbg(&dev->intf->dev, "Setting NTB format to 32-bit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) USB_TYPE_CLASS | USB_DIR_OUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) USB_CDC_NCM_NTB32_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) iface_no, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) ctx->is_ndp16 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) dev_dbg(&dev->intf->dev, "Setting NTB format to 16-bit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) err = usbnet_write_cmd(dev, USB_CDC_SET_NTB_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) USB_TYPE_CLASS | USB_DIR_OUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) USB_CDC_NCM_NTB16_FORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) iface_no, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) ctx->is_ndp16 = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) dev_err(&dev->intf->dev, "SET_NTB_FORMAT failed\n");
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) /* set initial device values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) ctx->rx_max = le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) ctx->tx_max = le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) ctx->tx_remainder = le16_to_cpu(ctx->ncm_parm.wNdpOutPayloadRemainder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) ctx->tx_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutDivisor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) ctx->tx_ndp_modulus = le16_to_cpu(ctx->ncm_parm.wNdpOutAlignment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* devices prior to NCM Errata shall set this field to zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ctx->tx_max_datagrams = le16_to_cpu(ctx->ncm_parm.wNtbOutMaxDatagrams);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) dev_dbg(&dev->intf->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) "dwNtbInMaxSize=%u dwNtbOutMaxSize=%u wNdpOutPayloadRemainder=%u wNdpOutDivisor=%u wNdpOutAlignment=%u wNtbOutMaxDatagrams=%u flags=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) ctx->rx_max, ctx->tx_max, ctx->tx_remainder, ctx->tx_modulus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) ctx->tx_ndp_modulus, ctx->tx_max_datagrams, cdc_ncm_flags(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) /* max count of tx datagrams */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) if ((ctx->tx_max_datagrams == 0) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) (ctx->tx_max_datagrams > CDC_NCM_DPT_DATAGRAMS_MAX))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) ctx->tx_max_datagrams = CDC_NCM_DPT_DATAGRAMS_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) /* set up maximum NDP size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) ctx->max_ndp_size = sizeof(struct usb_cdc_ncm_ndp16) + (ctx->tx_max_datagrams + 1) * sizeof(struct usb_cdc_ncm_dpe16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) ctx->max_ndp_size = sizeof(struct usb_cdc_ncm_ndp32) + (ctx->tx_max_datagrams + 1) * sizeof(struct usb_cdc_ncm_dpe32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* initial coalescing timer interval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) ctx->timer_interval = CDC_NCM_TIMER_INTERVAL_USEC * NSEC_PER_USEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) /* set a new max datagram size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static void cdc_ncm_set_dgram_size(struct usbnet *dev, int new_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) u8 iface_no = ctx->control->cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) __le16 max_datagram_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) u16 mbim_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) /* set default based on descriptors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) ctx->max_datagram_size = clamp_t(u32, new_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) cdc_ncm_min_dgram_size(dev),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) CDC_NCM_MAX_DATAGRAM_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) /* inform the device about the selected Max Datagram Size? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (!(cdc_ncm_flags(dev) & USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* read current mtu value from device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) err = usbnet_read_cmd(dev, USB_CDC_GET_MAX_DATAGRAM_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 0, iface_no, &max_datagram_size, sizeof(max_datagram_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (err != sizeof(max_datagram_size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) dev_dbg(&dev->intf->dev, "GET_MAX_DATAGRAM_SIZE failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) goto out;
^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) if (le16_to_cpu(max_datagram_size) == ctx->max_datagram_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) max_datagram_size = cpu_to_le16(ctx->max_datagram_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) err = usbnet_write_cmd(dev, USB_CDC_SET_MAX_DATAGRAM_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) USB_TYPE_CLASS | USB_DIR_OUT | USB_RECIP_INTERFACE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 0, iface_no, &max_datagram_size, sizeof(max_datagram_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) dev_dbg(&dev->intf->dev, "SET_MAX_DATAGRAM_SIZE failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /* set MTU to max supported by the device if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) dev->net->mtu = min_t(int, dev->net->mtu, ctx->max_datagram_size - cdc_ncm_eth_hlen(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) /* do not exceed operater preferred MTU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (ctx->mbim_extended_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) mbim_mtu = le16_to_cpu(ctx->mbim_extended_desc->wMTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (mbim_mtu != 0 && mbim_mtu < dev->net->mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) dev->net->mtu = mbim_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) static void cdc_ncm_fix_modulus(struct usbnet *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * verify that the structure alignment is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * - power of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * - not greater than the maximum transmit length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * - not less than four bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) val = ctx->tx_ndp_modulus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) (val != ((-val) & val)) || (val >= ctx->tx_max)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) dev_dbg(&dev->intf->dev, "Using default alignment: 4 bytes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) ctx->tx_ndp_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^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) * verify that the payload alignment is:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * - power of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * - not greater than the maximum transmit length
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * - not less than four bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) val = ctx->tx_modulus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if ((val < USB_CDC_NCM_NDP_ALIGN_MIN_SIZE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) (val != ((-val) & val)) || (val >= ctx->tx_max)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) dev_dbg(&dev->intf->dev, "Using default transmit modulus: 4 bytes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) ctx->tx_modulus = USB_CDC_NCM_NDP_ALIGN_MIN_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /* verify the payload remainder */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (ctx->tx_remainder >= ctx->tx_modulus) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) dev_dbg(&dev->intf->dev, "Using default transmit remainder: 0 bytes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) ctx->tx_remainder = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) /* adjust TX-remainder according to NCM specification. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) ctx->tx_remainder = ((ctx->tx_remainder - cdc_ncm_eth_hlen(dev)) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) (ctx->tx_modulus - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static int cdc_ncm_setup(struct usbnet *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) u32 def_rx, def_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /* be conservative when selecting intial buffer size to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * increase the number of hosts this will work for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) def_rx = min_t(u32, CDC_NCM_NTB_DEF_SIZE_RX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) le32_to_cpu(ctx->ncm_parm.dwNtbInMaxSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) def_tx = min_t(u32, CDC_NCM_NTB_DEF_SIZE_TX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) le32_to_cpu(ctx->ncm_parm.dwNtbOutMaxSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) /* clamp rx_max and tx_max and inform device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) cdc_ncm_update_rxtx_max(dev, def_rx, def_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /* sanitize the modulus and remainder values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) cdc_ncm_fix_modulus(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) /* set max datagram size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) cdc_ncm_set_dgram_size(dev, cdc_ncm_max_dgram_size(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) cdc_ncm_find_endpoints(struct usbnet *dev, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct usb_host_endpoint *e, *in = NULL, *out = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) u8 ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) for (ep = 0; ep < intf->cur_altsetting->desc.bNumEndpoints; ep++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) e = intf->cur_altsetting->endpoint + ep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) /* ignore endpoints which cannot transfer data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (!usb_endpoint_maxp(&e->desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) switch (e->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) case USB_ENDPOINT_XFER_INT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (usb_endpoint_dir_in(&e->desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (!dev->status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) dev->status = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) case USB_ENDPOINT_XFER_BULK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) if (usb_endpoint_dir_in(&e->desc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (!in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) in = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (!out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) out = e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) if (in && !dev->in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) dev->in = usb_rcvbulkpipe(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) in->desc.bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) USB_ENDPOINT_NUMBER_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) if (out && !dev->out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) dev->out = usb_sndbulkpipe(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) out->desc.bEndpointAddress &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) USB_ENDPOINT_NUMBER_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static void cdc_ncm_free(struct cdc_ncm_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (ctx == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (ctx->tx_rem_skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) dev_kfree_skb_any(ctx->tx_rem_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) ctx->tx_rem_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) if (ctx->tx_curr_skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) dev_kfree_skb_any(ctx->tx_curr_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) ctx->tx_curr_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) kfree(ctx->delayed_ndp16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) kfree(ctx->delayed_ndp32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) kfree(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /* we need to override the usbnet change_mtu ndo for two reasons:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * - respect the negotiated maximum datagram size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * - avoid unwanted changes to rx and tx buffers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) int cdc_ncm_change_mtu(struct net_device *net, int new_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) struct usbnet *dev = netdev_priv(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) net->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) cdc_ncm_set_dgram_size(dev, new_mtu + cdc_ncm_eth_hlen(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) EXPORT_SYMBOL_GPL(cdc_ncm_change_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) static const struct net_device_ops cdc_ncm_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) .ndo_open = usbnet_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) .ndo_stop = usbnet_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) .ndo_start_xmit = usbnet_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) .ndo_tx_timeout = usbnet_tx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) .ndo_set_rx_mode = usbnet_set_rx_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) .ndo_get_stats64 = usbnet_get_stats64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) .ndo_change_mtu = cdc_ncm_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) .ndo_set_mac_address = eth_mac_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) .ndo_validate_addr = eth_validate_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_altsetting, int drvflags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) struct cdc_ncm_ctx *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) struct usb_driver *driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) int temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) u8 iface_no;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) struct usb_cdc_parsed_header hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) if (!ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) ctx->tx_timer.function = &cdc_ncm_tx_timer_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) tasklet_init(&ctx->bh, cdc_ncm_txpath_bh, (unsigned long)dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) atomic_set(&ctx->stop, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) spin_lock_init(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) /* store ctx pointer in device data field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) dev->data[0] = (unsigned long)ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) /* only the control interface can be successfully probed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) ctx->control = intf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /* get some pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) driver = driver_of(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) buf = intf->cur_altsetting->extra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) len = intf->cur_altsetting->extralen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) /* parse through descriptors associated with control interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) cdc_parse_cdc_header(&hdr, intf, buf, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (hdr.usb_cdc_union_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) ctx->data = usb_ifnum_to_if(dev->udev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) hdr.usb_cdc_union_desc->bSlaveInterface0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) ctx->ether_desc = hdr.usb_cdc_ether_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) ctx->func_desc = hdr.usb_cdc_ncm_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) ctx->mbim_desc = hdr.usb_cdc_mbim_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) ctx->mbim_extended_desc = hdr.usb_cdc_mbim_extended_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /* some buggy devices have an IAD but no CDC Union */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (!hdr.usb_cdc_union_desc && intf->intf_assoc && intf->intf_assoc->bInterfaceCount == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) dev_dbg(&intf->dev, "CDC Union missing - got slave from IAD\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) /* check if we got everything */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) if (!ctx->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) dev_dbg(&intf->dev, "CDC Union missing and no IAD found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) if (cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (!ctx->mbim_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) dev_dbg(&intf->dev, "MBIM functional descriptor missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (!ctx->ether_desc || !ctx->func_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) dev_dbg(&intf->dev, "NCM or ECM functional descriptors missing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) /* claim data interface, if different from control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (ctx->data != ctx->control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) temp = usb_driver_claim_interface(driver, ctx->data, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) if (temp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) dev_dbg(&intf->dev, "failed to claim data intf\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) iface_no = ctx->data->cur_altsetting->desc.bInterfaceNumber;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) /* Device-specific flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) ctx->drvflags = drvflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /* Reset data interface. Some devices will not reset properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) * unless they are configured first. Toggle the altsetting to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) * force a reset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) * Some other devices do not work properly with this procedure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) * that can be avoided using quirk CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) if (!(ctx->drvflags & CDC_MBIM_FLAG_AVOID_ALTSETTING_TOGGLE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) usb_set_interface(dev->udev, iface_no, data_altsetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) temp = usb_set_interface(dev->udev, iface_no, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) if (temp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) dev_dbg(&intf->dev, "set interface failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) /* initialize basic device settings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) if (cdc_ncm_init(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) /* Some firmwares need a pause here or they will silently fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) * to set up the interface properly. This value was decided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * empirically on a Sierra Wireless MC7455 running 02.08.02.00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) * firmware.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) usleep_range(10000, 20000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) /* configure data interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) temp = usb_set_interface(dev->udev, iface_no, data_altsetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) if (temp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) dev_dbg(&intf->dev, "set interface failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) cdc_ncm_find_endpoints(dev, ctx->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) cdc_ncm_find_endpoints(dev, ctx->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (!dev->in || !dev->out || !dev->status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) dev_dbg(&intf->dev, "failed to collect endpoints\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) usb_set_intfdata(ctx->data, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) usb_set_intfdata(ctx->control, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) if (ctx->ether_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) temp = usbnet_get_ethernet_addr(dev, ctx->ether_desc->iMACAddress);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) if (temp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) dev_dbg(&intf->dev, "failed to get mac address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) dev_info(&intf->dev, "MAC-Address: %pM\n", dev->net->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) /* finish setting up the device specific data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) cdc_ncm_setup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) /* Allocate the delayed NDP if needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) if (ctx->is_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) ctx->delayed_ndp16 = kzalloc(ctx->max_ndp_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (!ctx->delayed_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) ctx->delayed_ndp32 = kzalloc(ctx->max_ndp_size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (!ctx->delayed_ndp32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) goto error2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) dev_info(&intf->dev, "NDP will be placed at end of frame for this device.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) /* override ethtool_ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) dev->net->ethtool_ops = &cdc_ncm_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) /* add our sysfs attrs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) dev->net->sysfs_groups[0] = &cdc_ncm_sysfs_attr_group;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) /* must handle MTU changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) dev->net->netdev_ops = &cdc_ncm_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) dev->net->max_mtu = cdc_ncm_max_dgram_size(dev) - cdc_ncm_eth_hlen(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) error2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) usb_set_intfdata(ctx->control, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) usb_set_intfdata(ctx->data, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (ctx->data != ctx->control)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) usb_driver_release_interface(driver, ctx->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) cdc_ncm_free((struct cdc_ncm_ctx *)dev->data[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) dev->data[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) dev_info(&intf->dev, "bind() failure\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) EXPORT_SYMBOL_GPL(cdc_ncm_bind_common);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) struct usb_driver *driver = driver_of(intf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (ctx == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) return; /* no setup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) atomic_set(&ctx->stop, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) hrtimer_cancel(&ctx->tx_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) tasklet_kill(&ctx->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) /* handle devices with combined control and data interface */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) if (ctx->control == ctx->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) ctx->data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) /* disconnect master --> disconnect slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) if (intf == ctx->control && ctx->data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) usb_set_intfdata(ctx->data, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) usb_driver_release_interface(driver, ctx->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) ctx->data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) } else if (intf == ctx->data && ctx->control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) usb_set_intfdata(ctx->control, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) usb_driver_release_interface(driver, ctx->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) ctx->control = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) usb_set_intfdata(intf, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) cdc_ncm_free(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) EXPORT_SYMBOL_GPL(cdc_ncm_unbind);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /* Return the number of the MBIM control interface altsetting iff it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) * is preferred and available,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) u8 cdc_ncm_select_altsetting(struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) struct usb_host_interface *alt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) /* The MBIM spec defines a NCM compatible default altsetting,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) * which we may have matched:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * "Functions that implement both NCM 1.0 and MBIM (an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * “NCM/MBIM function”) according to this recommendation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * shall provide two alternate settings for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * Communication Interface. Alternate setting 0, and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * associated class and endpoint descriptors, shall be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) * constructed according to the rules given for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) * Communication Interface in section 5 of [USBNCM10].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) * Alternate setting 1, and the associated class and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * endpoint descriptors, shall be constructed according to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * the rules given in section 6 (USB Device Model) of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) * specification."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) if (intf->num_altsetting < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) return intf->cur_altsetting->desc.bAlternateSetting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (prefer_mbim) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) alt = usb_altnum_to_altsetting(intf, CDC_NCM_COMM_ALTSETTING_MBIM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (alt && cdc_ncm_comm_intf_is_mbim(alt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) return CDC_NCM_COMM_ALTSETTING_MBIM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) return CDC_NCM_COMM_ALTSETTING_NCM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) EXPORT_SYMBOL_GPL(cdc_ncm_select_altsetting);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) /* MBIM backwards compatible function? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (cdc_ncm_select_altsetting(intf) != CDC_NCM_COMM_ALTSETTING_NCM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) /* The NCM data altsetting is fixed, so we hard-coded it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) * Additionally, generic NCM devices are assumed to accept arbitrarily
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) * placed NDP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) return cdc_ncm_bind_common(dev, intf, CDC_NCM_DATA_ALTSETTING_NCM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) static void cdc_ncm_align_tail(struct sk_buff *skb, size_t modulus, size_t remainder, size_t max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) size_t align = ALIGN(skb->len, modulus) - skb->len + remainder;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) if (skb->len + align > max)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) align = max - skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (align && skb_tailroom(skb) >= align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) skb_put_zero(skb, align);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) /* return a pointer to a valid struct usb_cdc_ncm_ndp16 of type sign, possibly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) * allocating a new one within skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) static struct usb_cdc_ncm_ndp16 *cdc_ncm_ndp16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign, size_t reserve)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) struct usb_cdc_ncm_ndp16 *ndp16 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) struct usb_cdc_ncm_nth16 *nth16 = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) size_t ndpoffset = le16_to_cpu(nth16->wNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) /* If NDP should be moved to the end of the NCM package, we can't follow the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) * NTH16 header as we would normally do. NDP isn't written to the SKB yet, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) * the wNdpIndex field in the header is actually not consistent with reality. It will be later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) if (ctx->delayed_ndp16->dwSignature == sign)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) return ctx->delayed_ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) /* We can only push a single NDP to the end. Return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) * NULL to send what we've already got and queue this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) * skb for later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) else if (ctx->delayed_ndp16->dwSignature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) /* follow the chain of NDPs, looking for a match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) while (ndpoffset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb->data + ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) if (ndp16->dwSignature == sign)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) return ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) ndpoffset = le16_to_cpu(ndp16->wNextNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) /* align new NDP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) /* verify that there is room for the NDP and the datagram (reserve) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) /* link to it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) if (ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) ndp16->wNextNdpIndex = cpu_to_le16(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) nth16->wNdpIndex = cpu_to_le16(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) /* push a new empty NDP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) ndp16 = skb_put_zero(skb, ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) ndp16 = ctx->delayed_ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) ndp16->dwSignature = sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) ndp16->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp16) + sizeof(struct usb_cdc_ncm_dpe16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) return ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) static struct usb_cdc_ncm_ndp32 *cdc_ncm_ndp32(struct cdc_ncm_ctx *ctx, struct sk_buff *skb, __le32 sign, size_t reserve)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) struct usb_cdc_ncm_ndp32 *ndp32 = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) struct usb_cdc_ncm_nth32 *nth32 = (void *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) size_t ndpoffset = le32_to_cpu(nth32->dwNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) /* If NDP should be moved to the end of the NCM package, we can't follow the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) * NTH32 header as we would normally do. NDP isn't written to the SKB yet, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) * the wNdpIndex field in the header is actually not consistent with reality. It will be later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) if (ctx->delayed_ndp32->dwSignature == sign)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) return ctx->delayed_ndp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) /* We can only push a single NDP to the end. Return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) * NULL to send what we've already got and queue this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) * skb for later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) else if (ctx->delayed_ndp32->dwSignature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) /* follow the chain of NDPs, looking for a match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) while (ndpoffset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb->data + ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (ndp32->dwSignature == sign)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) return ndp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) ndpoffset = le32_to_cpu(ndp32->dwNextNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) /* align new NDP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) cdc_ncm_align_tail(skb, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /* verify that there is room for the NDP and the datagram (reserve) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) if ((ctx->tx_curr_size - skb->len - reserve) < ctx->max_ndp_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /* link to it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) if (ndp32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) ndp32->dwNextNdpIndex = cpu_to_le32(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) nth32->dwNdpIndex = cpu_to_le32(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) /* push a new empty NDP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) if (!(ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) ndp32 = skb_put_zero(skb, ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) ndp32 = ctx->delayed_ndp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) ndp32->dwSignature = sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) ndp32->wLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_ndp32) + sizeof(struct usb_cdc_ncm_dpe32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) return ndp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) struct sk_buff *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) struct usb_cdc_ncm_nth16 *nth16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) struct usb_cdc_ncm_nth32 *nth32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) } nth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) struct usb_cdc_ncm_ndp16 *ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) struct usb_cdc_ncm_ndp32 *ndp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) } ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) struct sk_buff *skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) u16 n = 0, index, ndplen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) u8 ready2send = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) u32 delayed_ndp_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) size_t padding_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) /* When our NDP gets written in cdc_ncm_ndp(), then skb_out->len gets updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) * accordingly. Otherwise, we should check here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) delayed_ndp_size = ctx->max_ndp_size +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) max_t(u32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) ctx->tx_ndp_modulus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) ctx->tx_modulus + ctx->tx_remainder) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) delayed_ndp_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) /* if there is a remaining skb, it gets priority */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) if (skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) swap(skb, ctx->tx_rem_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) swap(sign, ctx->tx_rem_sign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) ready2send = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) /* check if we are resuming an OUT skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) skb_out = ctx->tx_curr_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) /* allocate a new OUT skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) if (!skb_out) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) if (ctx->tx_low_mem_val == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) ctx->tx_curr_size = ctx->tx_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) /* If the memory allocation fails we will wait longer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * each time before attempting another full size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) * allocation again to not overload the system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) * further.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) if (skb_out == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) ctx->tx_low_mem_max_cnt = min(ctx->tx_low_mem_max_cnt + 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) (unsigned)CDC_NCM_LOW_MEM_MAX_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) ctx->tx_low_mem_val = ctx->tx_low_mem_max_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) if (skb_out == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) /* See if a very small allocation is possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) * We will send this packet immediately and hope
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) * that there is more memory available later.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) if (skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) ctx->tx_curr_size = max(skb->len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) (u32)USB_CDC_NCM_NTB_MIN_OUT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) ctx->tx_curr_size = USB_CDC_NCM_NTB_MIN_OUT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) skb_out = alloc_skb(ctx->tx_curr_size, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) /* No allocation possible so we will abort */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (skb_out == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) if (skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) dev->net->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) goto exit_no_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) ctx->tx_low_mem_val--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) if (ctx->is_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) /* fill out the initial 16-bit NTB header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) nth.nth16 = skb_put_zero(skb_out, sizeof(struct usb_cdc_ncm_nth16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) nth.nth16->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH16_SIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) nth.nth16->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) nth.nth16->wSequence = cpu_to_le16(ctx->tx_seq++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) /* fill out the initial 32-bit NTB header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) nth.nth32 = skb_put_zero(skb_out, sizeof(struct usb_cdc_ncm_nth32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) nth.nth32->dwSignature = cpu_to_le32(USB_CDC_NCM_NTH32_SIGN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) nth.nth32->wHeaderLength = cpu_to_le16(sizeof(struct usb_cdc_ncm_nth32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) nth.nth32->wSequence = cpu_to_le16(ctx->tx_seq++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) /* count total number of frames in this NTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) ctx->tx_curr_frame_num = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) /* recent payload counter for this skb_out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) ctx->tx_curr_frame_payload = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) for (n = ctx->tx_curr_frame_num; n < ctx->tx_max_datagrams; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) /* send any remaining skb first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) if (skb == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) skb = ctx->tx_rem_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) sign = ctx->tx_rem_sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) ctx->tx_rem_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) /* check for end of skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) if (skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) /* get the appropriate NDP for this skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) ndp.ndp16 = cdc_ncm_ndp16(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) ndp.ndp32 = cdc_ncm_ndp32(ctx, skb_out, sign, skb->len + ctx->tx_modulus + ctx->tx_remainder);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) /* align beginning of next frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) cdc_ncm_align_tail(skb_out, ctx->tx_modulus, ctx->tx_remainder, ctx->tx_curr_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) /* check if we had enough room left for both NDP and frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) if ((ctx->is_ndp16 && !ndp.ndp16) || (!ctx->is_ndp16 && !ndp.ndp32) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) skb_out->len + skb->len + delayed_ndp_size > ctx->tx_curr_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) if (n == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) /* won't fit, MTU problem? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) dev->net->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) /* no room for skb - store for later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) if (ctx->tx_rem_skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) dev_kfree_skb_any(ctx->tx_rem_skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) dev->net->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) ctx->tx_rem_skb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) ctx->tx_rem_sign = sign;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) ready2send = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) ctx->tx_reason_ntb_full++; /* count reason for transmitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) /* calculate frame number withing this NDP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) if (ctx->is_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) ndplen = le16_to_cpu(ndp.ndp16->wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) index = (ndplen - sizeof(struct usb_cdc_ncm_ndp16)) / sizeof(struct usb_cdc_ncm_dpe16) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) /* OK, add this skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) ndp.ndp16->dpe16[index].wDatagramLength = cpu_to_le16(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) ndp.ndp16->dpe16[index].wDatagramIndex = cpu_to_le16(skb_out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) ndp.ndp16->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) ndplen = le16_to_cpu(ndp.ndp32->wLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) index = (ndplen - sizeof(struct usb_cdc_ncm_ndp32)) / sizeof(struct usb_cdc_ncm_dpe32) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) ndp.ndp32->dpe32[index].dwDatagramLength = cpu_to_le32(skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) ndp.ndp32->dpe32[index].dwDatagramIndex = cpu_to_le32(skb_out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) ndp.ndp32->wLength = cpu_to_le16(ndplen + sizeof(struct usb_cdc_ncm_dpe32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) skb_put_data(skb_out, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) ctx->tx_curr_frame_payload += skb->len; /* count real tx payload data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) /* send now if this NDP is full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) if (index >= CDC_NCM_DPT_DATAGRAMS_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) ready2send = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) ctx->tx_reason_ndp_full++; /* count reason for transmitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) /* free up any dangling skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) if (skb != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) dev->net->stats.tx_dropped++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) ctx->tx_curr_frame_num = n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) if (n == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) /* wait for more frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) /* push variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) ctx->tx_curr_skb = skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) goto exit_no_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) } else if ((n < ctx->tx_max_datagrams) && (ready2send == 0) && (ctx->timer_interval > 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) /* wait for more frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) /* push variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) ctx->tx_curr_skb = skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) /* set the pending count */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) if (n < CDC_NCM_RESTART_TIMER_DATAGRAM_CNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) goto exit_no_skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) if (n == ctx->tx_max_datagrams)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) ctx->tx_reason_max_datagram++; /* count reason for transmitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) /* frame goes out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) /* variables will be reset at next call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) /* If requested, put NDP at end of frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) if (ctx->is_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) nth.nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) cdc_ncm_align_tail(skb_out, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size - ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) nth.nth16->wNdpIndex = cpu_to_le16(skb_out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) skb_put_data(skb_out, ctx->delayed_ndp16, ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) /* Zero out delayed NDP - signature checking will naturally fail. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) ndp.ndp16 = memset(ctx->delayed_ndp16, 0, ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) nth.nth32 = (struct usb_cdc_ncm_nth32 *)skb_out->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) cdc_ncm_align_tail(skb_out, ctx->tx_ndp_modulus, 0, ctx->tx_curr_size - ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) nth.nth32->dwNdpIndex = cpu_to_le32(skb_out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) skb_put_data(skb_out, ctx->delayed_ndp32, ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) ndp.ndp32 = memset(ctx->delayed_ndp32, 0, ctx->max_ndp_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) /* If collected data size is less or equal ctx->min_tx_pkt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) * bytes, we send buffers as it is. If we get more data, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) * would be more efficient for USB HS mobile device with DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) * engine to receive a full size NTB, than canceling DMA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) * transfer and receiving a short packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) * This optimization support is pointless if we end up sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) * a ZLP after full sized NTBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (!(dev->driver_info->flags & FLAG_SEND_ZLP) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) skb_out->len > ctx->min_tx_pkt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) padding_count = ctx->tx_curr_size - skb_out->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) if (!WARN_ON(padding_count > ctx->tx_curr_size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) skb_put_zero(skb_out, padding_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) } else if (skb_out->len < ctx->tx_curr_size &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) (skb_out->len % dev->maxpacket) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) skb_put_u8(skb_out, 0); /* force short packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) /* set final frame length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) if (ctx->is_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) nth.nth16 = (struct usb_cdc_ncm_nth16 *)skb_out->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) nth.nth16->wBlockLength = cpu_to_le16(skb_out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) nth.nth32 = (struct usb_cdc_ncm_nth32 *)skb_out->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) nth.nth32->dwBlockLength = cpu_to_le32(skb_out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) /* return skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) ctx->tx_curr_skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) /* keep private stats: framing overhead and number of NTBs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) ctx->tx_ntbs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) /* usbnet will count all the framing overhead by default.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) * Adjust the stats so that the tx_bytes counter show real
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) * payload data instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) usbnet_set_skb_tx_stats(skb_out, n,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) (long)ctx->tx_curr_frame_payload - skb_out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) return skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) exit_no_skb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) /* Start timer, if there is a remaining non-empty skb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (ctx->tx_curr_skb != NULL && n > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) cdc_ncm_tx_timeout_start(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) EXPORT_SYMBOL_GPL(cdc_ncm_fill_tx_frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) /* start timer, if not already started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) hrtimer_start(&ctx->tx_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) ctx->timer_interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) HRTIMER_MODE_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) struct cdc_ncm_ctx *ctx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) container_of(timer, struct cdc_ncm_ctx, tx_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) if (!atomic_read(&ctx->stop))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) tasklet_schedule(&ctx->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) return HRTIMER_NORESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) static void cdc_ncm_txpath_bh(unsigned long param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) struct usbnet *dev = (struct usbnet *)param;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) spin_lock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) if (ctx->tx_timer_pending != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) ctx->tx_timer_pending--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) cdc_ncm_tx_timeout_start(ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) spin_unlock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) } else if (dev->net != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) ctx->tx_reason_timeout++; /* count reason for transmitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) spin_unlock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) netif_tx_lock_bh(dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) usbnet_start_xmit(NULL, dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) netif_tx_unlock_bh(dev->net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) spin_unlock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) struct sk_buff *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) struct sk_buff *skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) * The Ethernet API we are using does not support transmitting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) * multiple Ethernet frames in a single call. This driver will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) * accumulate multiple Ethernet frames and send out a larger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) * USB frame when the USB buffer is full or when a single jiffies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) * timeout happens.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if (ctx == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) spin_lock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) skb_out = cdc_ncm_fill_tx_frame(dev, skb, cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) skb_out = cdc_ncm_fill_tx_frame(dev, skb, cpu_to_le32(USB_CDC_NCM_NDP32_NOCRC_SIGN));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) spin_unlock_bh(&ctx->mtx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) return skb_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) if (skb != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) EXPORT_SYMBOL_GPL(cdc_ncm_tx_fixup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) /* verify NTB header and return offset of first NDP, or negative error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) int cdc_ncm_rx_verify_nth16(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) struct usbnet *dev = netdev_priv(skb_in->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) struct usb_cdc_ncm_nth16 *nth16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) if (ctx == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth16) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) sizeof(struct usb_cdc_ncm_ndp16))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) netif_dbg(dev, rx_err, dev->net, "frame too short\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) nth16 = (struct usb_cdc_ncm_nth16 *)skb_in->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) if (nth16->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH16_SIGN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) "invalid NTH16 signature <%#010x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) le32_to_cpu(nth16->dwSignature));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) len = le16_to_cpu(nth16->wBlockLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) if (len > ctx->rx_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) "unsupported NTB block length %u/%u\n", len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) ctx->rx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) "sequence number glitch prev=%d curr=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) ctx->rx_seq, le16_to_cpu(nth16->wSequence));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) ctx->rx_seq = le16_to_cpu(nth16->wSequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) ret = le16_to_cpu(nth16->wNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_nth16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) int cdc_ncm_rx_verify_nth32(struct cdc_ncm_ctx *ctx, struct sk_buff *skb_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) struct usbnet *dev = netdev_priv(skb_in->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) struct usb_cdc_ncm_nth32 *nth32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) if (ctx == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth32) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) sizeof(struct usb_cdc_ncm_ndp32))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) netif_dbg(dev, rx_err, dev->net, "frame too short\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) nth32 = (struct usb_cdc_ncm_nth32 *)skb_in->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) if (nth32->dwSignature != cpu_to_le32(USB_CDC_NCM_NTH32_SIGN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) "invalid NTH32 signature <%#010x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) le32_to_cpu(nth32->dwSignature));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) len = le32_to_cpu(nth32->dwBlockLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) if (len > ctx->rx_max) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) "unsupported NTB block length %u/%u\n", len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) ctx->rx_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) if ((ctx->rx_seq + 1) != le16_to_cpu(nth32->wSequence) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) (ctx->rx_seq || le16_to_cpu(nth32->wSequence)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth32->wSequence))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) "sequence number glitch prev=%d curr=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) ctx->rx_seq, le16_to_cpu(nth32->wSequence));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) ctx->rx_seq = le16_to_cpu(nth32->wSequence);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) ret = le32_to_cpu(nth32->dwNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_nth32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) /* verify NDP header and return number of datagrams, or negative error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) int cdc_ncm_rx_verify_ndp16(struct sk_buff *skb_in, int ndpoffset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) struct usbnet *dev = netdev_priv(skb_in->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) struct usb_cdc_ncm_ndp16 *ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp16)) > skb_in->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) netif_dbg(dev, rx_err, dev->net, "invalid NDP offset <%u>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) netif_dbg(dev, rx_err, dev->net, "invalid DPT16 length <%u>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) le16_to_cpu(ndp16->wLength));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) ret = ((le16_to_cpu(ndp16->wLength) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) sizeof(struct usb_cdc_ncm_ndp16)) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) sizeof(struct usb_cdc_ncm_dpe16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) ret--; /* we process NDP entries except for the last one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) if ((sizeof(struct usb_cdc_ncm_ndp16) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) ret * (sizeof(struct usb_cdc_ncm_dpe16))) > skb_in->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) netif_dbg(dev, rx_err, dev->net, "Invalid nframes = %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) /* verify NDP header and return number of datagrams, or negative error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) int cdc_ncm_rx_verify_ndp32(struct sk_buff *skb_in, int ndpoffset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) struct usbnet *dev = netdev_priv(skb_in->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) struct usb_cdc_ncm_ndp32 *ndp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) if ((ndpoffset + sizeof(struct usb_cdc_ncm_ndp32)) > skb_in->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) netif_dbg(dev, rx_err, dev->net, "invalid NDP offset <%u>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb_in->data + ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) if (le16_to_cpu(ndp32->wLength) < USB_CDC_NCM_NDP32_LENGTH_MIN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) netif_dbg(dev, rx_err, dev->net, "invalid DPT32 length <%u>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) le16_to_cpu(ndp32->wLength));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) ret = ((le16_to_cpu(ndp32->wLength) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) sizeof(struct usb_cdc_ncm_ndp32)) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) sizeof(struct usb_cdc_ncm_dpe32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) ret--; /* we process NDP entries except for the last one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) if ((sizeof(struct usb_cdc_ncm_ndp32) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) ret * (sizeof(struct usb_cdc_ncm_dpe32))) > skb_in->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) netif_dbg(dev, rx_err, dev->net, "Invalid nframes = %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) EXPORT_SYMBOL_GPL(cdc_ncm_rx_verify_ndp32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) unsigned int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) int nframes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) struct usb_cdc_ncm_ndp16 *ndp16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) struct usb_cdc_ncm_ndp32 *ndp32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) } ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) struct usb_cdc_ncm_dpe16 *dpe16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) struct usb_cdc_ncm_dpe32 *dpe32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) } dpe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) int ndpoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) int loopcount = 50; /* arbitrary max preventing infinite loop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) u32 payload = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) ndpoffset = cdc_ncm_rx_verify_nth16(ctx, skb_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) ndpoffset = cdc_ncm_rx_verify_nth32(ctx, skb_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) if (ndpoffset < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) next_ndp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) if (ctx->is_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) nframes = cdc_ncm_rx_verify_ndp16(skb_in, ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) if (nframes < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) ndp.ndp16 = (struct usb_cdc_ncm_ndp16 *)(skb_in->data + ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) if (ndp.ndp16->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP16_NOCRC_SIGN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) "invalid DPT16 signature <%#010x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) le32_to_cpu(ndp.ndp16->dwSignature));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) goto err_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) dpe.dpe16 = ndp.ndp16->dpe16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) nframes = cdc_ncm_rx_verify_ndp32(skb_in, ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) if (nframes < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) ndp.ndp32 = (struct usb_cdc_ncm_ndp32 *)(skb_in->data + ndpoffset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) if (ndp.ndp32->dwSignature != cpu_to_le32(USB_CDC_NCM_NDP32_NOCRC_SIGN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) "invalid DPT32 signature <%#010x>\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) le32_to_cpu(ndp.ndp32->dwSignature));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) goto err_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) dpe.dpe32 = ndp.ndp32->dpe32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) for (x = 0; x < nframes; x++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) if (ctx->is_ndp16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) offset = le16_to_cpu(dpe.dpe16->wDatagramIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) len = le16_to_cpu(dpe.dpe16->wDatagramLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) offset = le32_to_cpu(dpe.dpe32->dwDatagramIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) len = le32_to_cpu(dpe.dpe32->dwDatagramLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) * CDC NCM ch. 3.7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) * All entries after first NULL entry are to be ignored
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) if ((offset == 0) || (len == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) goto err_ndp; /* empty NTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) /* sanity checking - watch out for integer wrap*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) if ((offset > skb_in->len) || (len > skb_in->len - offset) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) (len > ctx->rx_max) || (len < ETH_HLEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) netif_dbg(dev, rx_err, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) "invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) x, offset, len, skb_in);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) if (!x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) goto err_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) /* create a fresh copy to reduce truesize */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) skb = netdev_alloc_skb_ip_align(dev->net, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) skb_put_data(skb, skb_in->data + offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) usbnet_skb_return(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) payload += len; /* count payload bytes in this NTB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) dpe.dpe16++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) dpe.dpe32++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) err_ndp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) /* are there more NDPs to process? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) if (ctx->is_ndp16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) ndpoffset = le16_to_cpu(ndp.ndp16->wNextNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) ndpoffset = le32_to_cpu(ndp.ndp32->dwNextNdpIndex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) if (ndpoffset && loopcount--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) goto next_ndp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) /* update stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) ctx->rx_overhead += skb_in->len - payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) ctx->rx_ntbs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) EXPORT_SYMBOL_GPL(cdc_ncm_rx_fixup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) cdc_ncm_speed_change(struct usbnet *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) struct usb_cdc_speed_change *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) uint32_t rx_speed = le32_to_cpu(data->DLBitRRate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) uint32_t tx_speed = le32_to_cpu(data->ULBitRate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) * Currently the USB-NET API does not support reporting the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) * device speed. Do print it instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) if ((tx_speed > 1000000) && (rx_speed > 1000000)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) netif_info(dev, link, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) "%u mbit/s downlink %u mbit/s uplink\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) (unsigned int)(rx_speed / 1000000U),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) (unsigned int)(tx_speed / 1000000U));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) netif_info(dev, link, dev->net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) "%u kbit/s downlink %u kbit/s uplink\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) (unsigned int)(rx_speed / 1000U),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) (unsigned int)(tx_speed / 1000U));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) static void cdc_ncm_status(struct usbnet *dev, struct urb *urb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) struct usb_cdc_notification *event;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) if (urb->actual_length < sizeof(*event))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) /* test for split data in 8-byte chunks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) if (test_and_clear_bit(EVENT_STS_SPLIT, &dev->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) cdc_ncm_speed_change(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) (struct usb_cdc_speed_change *)urb->transfer_buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) event = urb->transfer_buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) switch (event->bNotificationType) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) case USB_CDC_NOTIFY_NETWORK_CONNECTION:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) * According to the CDC NCM specification ch.7.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) * USB_CDC_NOTIFY_NETWORK_CONNECTION notification shall be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) * sent by device after USB_CDC_NOTIFY_SPEED_CHANGE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) usbnet_link_change(dev, !!event->wValue, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) case USB_CDC_NOTIFY_SPEED_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) if (urb->actual_length < (sizeof(*event) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) sizeof(struct usb_cdc_speed_change)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) set_bit(EVENT_STS_SPLIT, &dev->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) cdc_ncm_speed_change(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) (struct usb_cdc_speed_change *)&event[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) dev_dbg(&dev->udev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) "NCM: unexpected notification 0x%02x!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) event->bNotificationType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) static const struct driver_info cdc_ncm_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) .description = "CDC NCM",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) | FLAG_LINK_INTR | FLAG_ETHER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) .bind = cdc_ncm_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) .unbind = cdc_ncm_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) .manage_power = usbnet_manage_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) .status = cdc_ncm_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) .rx_fixup = cdc_ncm_rx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) .tx_fixup = cdc_ncm_tx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) .set_rx_mode = usbnet_cdc_update_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) /* Same as cdc_ncm_info, but with FLAG_WWAN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) static const struct driver_info wwan_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) .description = "Mobile Broadband Network Device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) | FLAG_LINK_INTR | FLAG_WWAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) .bind = cdc_ncm_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) .unbind = cdc_ncm_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) .manage_power = usbnet_manage_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) .status = cdc_ncm_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) .rx_fixup = cdc_ncm_rx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) .tx_fixup = cdc_ncm_tx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) .set_rx_mode = usbnet_cdc_update_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) /* Same as wwan_info, but with FLAG_NOARP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) static const struct driver_info wwan_noarp_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) .description = "Mobile Broadband Network Device (NO ARP)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) .flags = FLAG_POINTTOPOINT | FLAG_NO_SETINT | FLAG_MULTI_PACKET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) | FLAG_LINK_INTR | FLAG_WWAN | FLAG_NOARP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) .bind = cdc_ncm_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) .unbind = cdc_ncm_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) .manage_power = usbnet_manage_power,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) .status = cdc_ncm_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) .rx_fixup = cdc_ncm_rx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) .tx_fixup = cdc_ncm_tx_fixup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) .set_rx_mode = usbnet_cdc_update_filter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) static const struct usb_device_id cdc_devs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) /* Ericsson MBM devices like F5521gw */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) | USB_DEVICE_ID_MATCH_VENDOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) .idVendor = 0x0bdb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) .bInterfaceClass = USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) .bInterfaceProtocol = USB_CDC_PROTO_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) .driver_info = (unsigned long) &wwan_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) /* Telit LE910 V2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) { USB_DEVICE_AND_INTERFACE_INFO(0x1bc7, 0x0036,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) .driver_info = (unsigned long)&wwan_noarp_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) /* DW5812 LTE Verizon Mobile Broadband Card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) * Unlike DW5550 this device requires FLAG_NOARP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) { USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x81bb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) .driver_info = (unsigned long)&wwan_noarp_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) /* DW5813 LTE AT&T Mobile Broadband Card
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) * Unlike DW5550 this device requires FLAG_NOARP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) { USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x81bc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) .driver_info = (unsigned long)&wwan_noarp_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) /* Dell branded MBM devices like DW5550 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) | USB_DEVICE_ID_MATCH_VENDOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) .idVendor = 0x413c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) .bInterfaceClass = USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) .bInterfaceProtocol = USB_CDC_PROTO_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) .driver_info = (unsigned long) &wwan_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) /* Toshiba branded MBM devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) { .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) | USB_DEVICE_ID_MATCH_VENDOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) .idVendor = 0x0930,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) .bInterfaceClass = USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) .bInterfaceSubClass = USB_CDC_SUBCLASS_NCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) .bInterfaceProtocol = USB_CDC_PROTO_NONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) .driver_info = (unsigned long) &wwan_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) /* tag Huawei devices as wwan */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) { USB_VENDOR_AND_INTERFACE_INFO(0x12d1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) USB_CDC_SUBCLASS_NCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) .driver_info = (unsigned long)&wwan_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) /* Infineon(now Intel) HSPA Modem platform */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) { USB_DEVICE_AND_INTERFACE_INFO(0x1519, 0x0443,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) .driver_info = (unsigned long)&wwan_noarp_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) /* u-blox TOBY-L4 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) { USB_DEVICE_AND_INTERFACE_INFO(0x1546, 0x1010,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) .driver_info = (unsigned long)&wwan_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) /* Generic CDC-NCM devices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) { USB_INTERFACE_INFO(USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) USB_CDC_SUBCLASS_NCM, USB_CDC_PROTO_NONE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) .driver_info = (unsigned long)&cdc_ncm_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) MODULE_DEVICE_TABLE(usb, cdc_devs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) static struct usb_driver cdc_ncm_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) .name = "cdc_ncm",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) .id_table = cdc_devs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) .probe = usbnet_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) .disconnect = usbnet_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) .suspend = usbnet_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) .resume = usbnet_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) .reset_resume = usbnet_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) .supports_autosuspend = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) .disable_hub_initiated_lpm = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) module_usb_driver(cdc_ncm_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) MODULE_AUTHOR("Hans Petter Selasky");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) MODULE_DESCRIPTION("USB CDC NCM host driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) MODULE_LICENSE("Dual BSD/GPL");