Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * ether.c -- Ethernet gadget driver, with CDC and non-CDC options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2003-2005,2008 David Brownell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (C) 2008 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) /* #define VERBOSE_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #if defined USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #  undef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #ifdef CONFIG_USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #  define USB_ETH_RNDIS y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "u_ether.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * Ethernet gadget driver -- with CDC and non-CDC options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * Builds on hardware support for a full duplex link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * CDC Ethernet is the standard USB solution for sending Ethernet frames
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * using USB.  Real hardware tends to use the same framing protocol but look
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * different for control features.  This driver strongly prefers to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  * this USB-IF standard as its open-systems interoperability solution;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * most host side USB stacks (except from Microsoft) support it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * This is sometimes called "CDC ECM" (Ethernet Control Model) to support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * TLA-soup.  "CDC ACM" (Abstract Control Model) is for modems, and a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * "CDC EEM" (Ethernet Emulation Model) is starting to spread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)  * There's some hardware that can't talk CDC ECM.  We make that hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * implement a "minimalist" vendor-agnostic CDC core:  same framing, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  * link-level setup only requires activating the configuration.  Only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  * endpoint descriptors, and product/vendor IDs, are relevant; no control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)  * operations are available.  Linux supports it, but other host operating
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)  * systems may not.  (This is a subset of CDC Ethernet.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * It turns out that if you add a few descriptors to that "CDC Subset",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * (Windows) host side drivers from MCCI can treat it as one submode of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * a proprietary scheme called "SAFE" ... without needing to know about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * specific product/vendor IDs.  So we do that, making it easier to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * those MS-Windows drivers.  Those added descriptors make it resemble a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * CDC MDLM device, but they don't change device behavior at all.  (See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * MCCI Engineering report 950198 "SAFE Networking Functions".)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * A third option is also in use.  Rather than CDC Ethernet, or something
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * simpler, Microsoft pushes their own approach: RNDIS.  The published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * RNDIS specs are ambiguous and appear to be incomplete, and are also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * needlessly complex.  They borrow more from CDC ACM than CDC ECM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #define DRIVER_DESC		"Ethernet Gadget"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) #define DRIVER_VERSION		"Memorial Day 2008"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #ifdef USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define PREFIX			"RNDIS/"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #define PREFIX			""
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70)  * This driver aims for interoperability by using CDC ECM unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  *		can_support_ecm()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  * returns false, in which case it supports the CDC Subset.  By default,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * that returns true; most hardware has no problems with CDC ECM, that's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)  * a good default.  Previous versions of this driver had no default; this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77)  * version changes that, removing overhead for new controller support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79)  *	IF YOUR HARDWARE CAN'T SUPPORT CDC ECM, UPDATE THAT ROUTINE!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) static inline bool has_rndis(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) #ifdef	USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) #include "u_ecm.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) #include "u_gether.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) #ifdef	USB_ETH_RNDIS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) #include "u_rndis.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) #include "rndis.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) #define rndis_borrow_net(...) do {} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #include "u_eem.h"
^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) USB_GADGET_COMPOSITE_OPTIONS();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) USB_ETHERNET_MODULE_PARAMETERS();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!!  Ever!!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * Instead:  allocate your own, using normal USB-IF procedures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* Thanks to NetChip Technologies for donating this product ID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  * It's for devices with only CDC Ethernet configurations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #define CDC_VENDOR_NUM		0x0525	/* NetChip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) #define CDC_PRODUCT_NUM		0xa4a1	/* Linux-USB Ethernet Gadget */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) /* For hardware that can't talk CDC, we use the same vendor ID that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)  * ARM Linux has used for ethernet-over-usb, both with sa1100 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * with pxa250.  We're protocol-compatible, if the host-side drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  * use the endpoint descriptors.  bcdDevice (version) is nonzero, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * drivers that need to hard-wire endpoint numbers have a hook.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)  * The protocol is a minimal subset of CDC Ether, which works on any bulk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)  * hardware that's not deeply broken ... even on hardware that can't talk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)  * RNDIS (like SA-1100, with no interrupt endpoint, or anything that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)  * doesn't handle control-OUT).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define	SIMPLE_VENDOR_NUM	0x049f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) #define	SIMPLE_PRODUCT_NUM	0x505a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /* For hardware that can talk RNDIS and either of the above protocols,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)  * use this ID ... the windows INF files will know it.  Unless it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)  * used with CDC Ethernet, Linux 2.4 hosts will need updates to choose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)  * the non-RNDIS configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define RNDIS_VENDOR_NUM	0x0525	/* NetChip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define RNDIS_PRODUCT_NUM	0xa4a2	/* Ethernet/RNDIS Gadget */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* For EEM gadgets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define EEM_VENDOR_NUM		0x1d6b	/* Linux Foundation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define EEM_PRODUCT_NUM		0x0102	/* EEM Gadget */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static struct usb_device_descriptor device_desc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	.bLength =		sizeof device_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	.bDescriptorType =	USB_DT_DEVICE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	/* .bcdUSB = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	.bDeviceClass =		USB_CLASS_COMM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	.bDeviceSubClass =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	.bDeviceProtocol =	0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	/* .bMaxPacketSize0 = f(hardware) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	/* Vendor and product id defaults change according to what configs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	 * we support.  (As does bNumConfigurations.)  These values can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	 * also be overridden by module parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.idVendor =		cpu_to_le16 (CDC_VENDOR_NUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.idProduct =		cpu_to_le16 (CDC_PRODUCT_NUM),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	/* .bcdDevice = f(hardware) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	/* .iManufacturer = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	/* .iProduct = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	/* NO SERIAL NUMBER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	.bNumConfigurations =	1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static const struct usb_descriptor_header *otg_desc[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static struct usb_string strings_dev[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	[USB_GADGET_MANUFACTURER_IDX].s = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	[USB_GADGET_PRODUCT_IDX].s = PREFIX DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	[USB_GADGET_SERIAL_IDX].s = "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	{  } /* end of list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static struct usb_gadget_strings stringtab_dev = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	.language	= 0x0409,	/* en-us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	.strings	= strings_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static struct usb_gadget_strings *dev_strings[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	&stringtab_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static struct usb_function_instance *fi_ecm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static struct usb_function *f_ecm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static struct usb_function_instance *fi_eem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static struct usb_function *f_eem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static struct usb_function_instance *fi_geth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static struct usb_function *f_geth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static struct usb_function_instance *fi_rndis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) static struct usb_function *f_rndis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * We may not have an RNDIS configuration, but if we do it needs to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * the first one present.  That's to make Microsoft's drivers happy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  * and to follow DOCSIS 1.0 (cable modem standard).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static int rndis_do_config(struct usb_configuration *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	int status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	/* FIXME alloc iConfiguration string, set it in c->strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	if (gadget_is_otg(c->cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		c->descriptors = otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	f_rndis = usb_get_function(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (IS_ERR(f_rndis))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		return PTR_ERR(f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	status = usb_add_function(c, f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		usb_put_function(f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) static struct usb_configuration rndis_config_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	.label			= "RNDIS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	.bConfigurationValue	= 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	/* .iConfiguration = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*-------------------------------------------------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #ifdef CONFIG_USB_ETH_EEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static bool use_eem = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static bool use_eem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) module_param(use_eem, bool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * We _always_ have an ECM, CDC Subset, or EEM configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int eth_do_config(struct usb_configuration *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	int status = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	/* FIXME alloc iConfiguration string, set it in c->strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (gadget_is_otg(c->cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		c->descriptors = otg_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	if (use_eem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		f_eem = usb_get_function(fi_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		if (IS_ERR(f_eem))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			return PTR_ERR(f_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		status = usb_add_function(c, f_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			usb_put_function(f_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	} else if (can_support_ecm(c->cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		f_ecm = usb_get_function(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		if (IS_ERR(f_ecm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			return PTR_ERR(f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		status = usb_add_function(c, f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			usb_put_function(f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		f_geth = usb_get_function(fi_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		if (IS_ERR(f_geth))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 			return PTR_ERR(f_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		status = usb_add_function(c, f_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 			usb_put_function(f_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static struct usb_configuration eth_config_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	/* .label = f(hardware) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	.bConfigurationValue	= 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	/* .iConfiguration = DYNAMIC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) };
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) static int eth_bind(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	struct usb_gadget	*gadget = cdev->gadget;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	struct f_eem_opts	*eem_opts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	struct f_ecm_opts	*ecm_opts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	struct f_gether_opts	*geth_opts = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	struct net_device	*net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	int			status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	/* set up main config label and device descriptor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	if (use_eem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		/* EEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		fi_eem = usb_get_function_instance("eem");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		if (IS_ERR(fi_eem))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			return PTR_ERR(fi_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		net = eem_opts->net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		eth_config_driver.label = "CDC Ethernet (EEM)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	} else if (can_support_ecm(gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		/* ECM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		fi_ecm = usb_get_function_instance("ecm");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		if (IS_ERR(fi_ecm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 			return PTR_ERR(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		net = ecm_opts->net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		eth_config_driver.label = "CDC Ethernet (ECM)";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		/* CDC Subset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		fi_geth = usb_get_function_instance("geth");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		if (IS_ERR(fi_geth))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			return PTR_ERR(fi_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		geth_opts = container_of(fi_geth, struct f_gether_opts,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 					 func_inst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		net = geth_opts->net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		eth_config_driver.label = "CDC Subset/SAFE";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		device_desc.idProduct = cpu_to_le16(SIMPLE_PRODUCT_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		if (!has_rndis())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 			device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	gether_set_qmult(net, qmult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (!gether_set_host_addr(net, host_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		pr_info("using host ethernet address: %s", host_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	if (!gether_set_dev_addr(net, dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		pr_info("using self ethernet address: %s", dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	if (has_rndis()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 		/* RNDIS plus ECM-or-Subset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		gether_set_gadget(net, cdev->gadget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		status = gether_register_netdev(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		if (status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 		if (use_eem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 			eem_opts->bound = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 		else if (can_support_ecm(gadget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 			ecm_opts->bound = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 			geth_opts->bound = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		fi_rndis = usb_get_function_instance("rndis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 		if (IS_ERR(fi_rndis)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 			status = PTR_ERR(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 			goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 		rndis_borrow_net(fi_rndis, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 		device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 		device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		device_desc.bNumConfigurations = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	/* Allocate string descriptor numbers ... note that string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	 * contents can be overridden by the composite_dev glue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	status = usb_string_ids_tab(cdev, strings_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (gadget_is_otg(gadget) && !otg_desc[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		struct usb_descriptor_header *usb_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		usb_desc = usb_otg_descriptor_alloc(gadget);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		if (!usb_desc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		usb_otg_descriptor_init(gadget, usb_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		otg_desc[0] = usb_desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 		otg_desc[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	/* register our configuration(s); RNDIS first, if it's used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	if (has_rndis()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 		status = usb_add_config(cdev, &rndis_config_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 				rndis_do_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	status = usb_add_config(cdev, &eth_config_driver, eth_do_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	if (status < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	usb_composite_overwrite_options(cdev, &coverwrite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 			DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) fail2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	kfree(otg_desc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	otg_desc[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) fail1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	if (has_rndis())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		usb_put_function_instance(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	if (use_eem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		usb_put_function_instance(fi_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	else if (can_support_ecm(gadget))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		usb_put_function_instance(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 		usb_put_function_instance(fi_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static int eth_unbind(struct usb_composite_dev *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	if (has_rndis()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		usb_put_function(f_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		usb_put_function_instance(fi_rndis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (use_eem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		usb_put_function(f_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		usb_put_function_instance(fi_eem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	} else if (can_support_ecm(cdev->gadget)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		usb_put_function(f_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		usb_put_function_instance(fi_ecm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 		usb_put_function(f_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		usb_put_function_instance(fi_geth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 	kfree(otg_desc[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 	otg_desc[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static struct usb_composite_driver eth_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	.name		= "g_ether",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	.dev		= &device_desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	.strings	= dev_strings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	.max_speed	= USB_SPEED_SUPER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	.bind		= eth_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	.unbind		= eth_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) module_usb_composite_driver(eth_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) MODULE_DESCRIPTION(PREFIX DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) MODULE_AUTHOR("David Brownell, Benedikt Spanger");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) MODULE_LICENSE("GPL");