aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/ether.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/ether.c')
-rw-r--r--drivers/usb/gadget/ether.c148
1 files changed, 108 insertions, 40 deletions
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index d15bf22b9a03..22e3c9443641 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -47,7 +47,7 @@
47#include <asm/uaccess.h> 47#include <asm/uaccess.h>
48#include <asm/unaligned.h> 48#include <asm/unaligned.h>
49 49
50#include <linux/usb_ch9.h> 50#include <linux/usb/ch9.h>
51#include <linux/usb/cdc.h> 51#include <linux/usb/cdc.h>
52#include <linux/usb_gadget.h> 52#include <linux/usb_gadget.h>
53 53
@@ -72,9 +72,18 @@
72 * 72 *
73 * There's some hardware that can't talk CDC. We make that hardware 73 * There's some hardware that can't talk CDC. We make that hardware
74 * implement a "minimalist" vendor-agnostic CDC core: same framing, but 74 * implement a "minimalist" vendor-agnostic CDC core: same framing, but
75 * link-level setup only requires activating the configuration. 75 * link-level setup only requires activating the configuration. Only the
76 * Linux supports it, but other host operating systems may not. 76 * endpoint descriptors, and product/vendor IDs, are relevant; no control
77 * (This is a subset of CDC Ethernet.) 77 * operations are available. Linux supports it, but other host operating
78 * systems may not. (This is a subset of CDC Ethernet.)
79 *
80 * It turns out that if you add a few descriptors to that "CDC Subset",
81 * (Windows) host side drivers from MCCI can treat it as one submode of
82 * a proprietary scheme called "SAFE" ... without needing to know about
83 * specific product/vendor IDs. So we do that, making it easier to use
84 * those MS-Windows drivers. Those added descriptors make it resemble a
85 * CDC MDLM device, but they don't change device behavior at all. (See
86 * MCCI Engineering report 950198 "SAFE Networking Functions".)
78 * 87 *
79 * A third option is also in use. Rather than CDC Ethernet, or something 88 * A third option is also in use. Rather than CDC Ethernet, or something
80 * simpler, Microsoft pushes their own approach: RNDIS. The published 89 * simpler, Microsoft pushes their own approach: RNDIS. The published
@@ -254,6 +263,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
254#define DEV_CONFIG_CDC 263#define DEV_CONFIG_CDC
255#endif 264#endif
256 265
266#ifdef CONFIG_USB_GADGET_S3C2410
267#define DEV_CONFIG_CDC
268#endif
269
257#ifdef CONFIG_USB_GADGET_AT91 270#ifdef CONFIG_USB_GADGET_AT91
258#define DEV_CONFIG_CDC 271#define DEV_CONFIG_CDC
259#endif 272#endif
@@ -266,6 +279,10 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
266#define DEV_CONFIG_CDC 279#define DEV_CONFIG_CDC
267#endif 280#endif
268 281
282#ifdef CONFIG_USB_GADGET_HUSB2DEV
283#define DEV_CONFIG_CDC
284#endif
285
269 286
270/* For CDC-incapable hardware, choose the simple cdc subset. 287/* For CDC-incapable hardware, choose the simple cdc subset.
271 * Anything that talks bulk (without notable bugs) can do this. 288 * Anything that talks bulk (without notable bugs) can do this.
@@ -283,9 +300,6 @@ MODULE_PARM_DESC(host_addr, "Host Ethernet Address");
283#define DEV_CONFIG_SUBSET 300#define DEV_CONFIG_SUBSET
284#endif 301#endif
285 302
286#ifdef CONFIG_USB_GADGET_S3C2410
287#define DEV_CONFIG_CDC
288#endif
289 303
290/*-------------------------------------------------------------------------*/ 304/*-------------------------------------------------------------------------*/
291 305
@@ -487,8 +501,17 @@ rndis_config = {
487 * endpoint. Both have a "data" interface and two bulk endpoints. 501 * endpoint. Both have a "data" interface and two bulk endpoints.
488 * There are also differences in how control requests are handled. 502 * There are also differences in how control requests are handled.
489 * 503 *
490 * RNDIS shares a lot with CDC-Ethernet, since it's a variant of 504 * RNDIS shares a lot with CDC-Ethernet, since it's a variant of the
491 * the CDC-ACM (modem) spec. 505 * CDC-ACM (modem) spec. Unfortunately MSFT's RNDIS driver is buggy; it
506 * may hang or oops. Since bugfixes (or accurate specs, letting Linux
507 * work around those bugs) are unlikely to ever come from MSFT, you may
508 * wish to avoid using RNDIS.
509 *
510 * MCCI offers an alternative to RNDIS if you need to connect to Windows
511 * but have hardware that can't support CDC Ethernet. We add descriptors
512 * to present the CDC Subset as a (nonconformant) CDC MDLM variant called
513 * "SAFE". That borrows from both CDC Ethernet and CDC MDLM. You can
514 * get those drivers from MCCI, or bundled with various products.
492 */ 515 */
493 516
494#ifdef DEV_CONFIG_CDC 517#ifdef DEV_CONFIG_CDC
@@ -522,8 +545,6 @@ rndis_control_intf = {
522}; 545};
523#endif 546#endif
524 547
525#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
526
527static const struct usb_cdc_header_desc header_desc = { 548static const struct usb_cdc_header_desc header_desc = {
528 .bLength = sizeof header_desc, 549 .bLength = sizeof header_desc,
529 .bDescriptorType = USB_DT_CS_INTERFACE, 550 .bDescriptorType = USB_DT_CS_INTERFACE,
@@ -532,6 +553,8 @@ static const struct usb_cdc_header_desc header_desc = {
532 .bcdCDC = __constant_cpu_to_le16 (0x0110), 553 .bcdCDC = __constant_cpu_to_le16 (0x0110),
533}; 554};
534 555
556#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
557
535static const struct usb_cdc_union_desc union_desc = { 558static const struct usb_cdc_union_desc union_desc = {
536 .bLength = sizeof union_desc, 559 .bLength = sizeof union_desc,
537 .bDescriptorType = USB_DT_CS_INTERFACE, 560 .bDescriptorType = USB_DT_CS_INTERFACE,
@@ -564,7 +587,40 @@ static const struct usb_cdc_acm_descriptor acm_descriptor = {
564 587
565#endif 588#endif
566 589
567#ifdef DEV_CONFIG_CDC 590#ifndef DEV_CONFIG_CDC
591
592/* "SAFE" loosely follows CDC WMC MDLM, violating the spec in various
593 * ways: data endpoints live in the control interface, there's no data
594 * interface, and it's not used to talk to a cell phone radio.
595 */
596
597static const struct usb_cdc_mdlm_desc mdlm_desc = {
598 .bLength = sizeof mdlm_desc,
599 .bDescriptorType = USB_DT_CS_INTERFACE,
600 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
601
602 .bcdVersion = __constant_cpu_to_le16(0x0100),
603 .bGUID = {
604 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
605 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
606 },
607};
608
609/* since "usb_cdc_mdlm_detail_desc" is a variable length structure, we
610 * can't really use its struct. All we do here is say that we're using
611 * the submode of "SAFE" which directly matches the CDC Subset.
612 */
613static const u8 mdlm_detail_desc[] = {
614 6,
615 USB_DT_CS_INTERFACE,
616 USB_CDC_MDLM_DETAIL_TYPE,
617
618 0, /* "SAFE" */
619 0, /* network control capabilities (none) */
620 0, /* network data capabilities ("raw" encapsulation) */
621};
622
623#endif
568 624
569static const struct usb_cdc_ether_desc ether_desc = { 625static const struct usb_cdc_ether_desc ether_desc = {
570 .bLength = sizeof ether_desc, 626 .bLength = sizeof ether_desc,
@@ -579,7 +635,6 @@ static const struct usb_cdc_ether_desc ether_desc = {
579 .bNumberPowerFilters = 0, 635 .bNumberPowerFilters = 0,
580}; 636};
581 637
582#endif
583 638
584#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS) 639#if defined(DEV_CONFIG_CDC) || defined(CONFIG_USB_ETH_RNDIS)
585 640
@@ -672,6 +727,9 @@ rndis_data_intf = {
672/* 727/*
673 * "Simple" CDC-subset option is a simple vendor-neutral model that most 728 * "Simple" CDC-subset option is a simple vendor-neutral model that most
674 * full speed controllers can handle: one interface, two bulk endpoints. 729 * full speed controllers can handle: one interface, two bulk endpoints.
730 *
731 * To assist host side drivers, we fancy it up a bit, and add descriptors
732 * so some host side drivers will understand it as a "SAFE" variant.
675 */ 733 */
676 734
677static const struct usb_interface_descriptor 735static const struct usb_interface_descriptor
@@ -682,8 +740,8 @@ subset_data_intf = {
682 .bInterfaceNumber = 0, 740 .bInterfaceNumber = 0,
683 .bAlternateSetting = 0, 741 .bAlternateSetting = 0,
684 .bNumEndpoints = 2, 742 .bNumEndpoints = 2,
685 .bInterfaceClass = USB_CLASS_VENDOR_SPEC, 743 .bInterfaceClass = USB_CLASS_COMM,
686 .bInterfaceSubClass = 0, 744 .bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM,
687 .bInterfaceProtocol = 0, 745 .bInterfaceProtocol = 0,
688 .iInterface = STRING_DATA, 746 .iInterface = STRING_DATA,
689}; 747};
@@ -731,10 +789,15 @@ static const struct usb_descriptor_header *fs_eth_function [11] = {
731static inline void __init fs_subset_descriptors(void) 789static inline void __init fs_subset_descriptors(void)
732{ 790{
733#ifdef DEV_CONFIG_SUBSET 791#ifdef DEV_CONFIG_SUBSET
792 /* behavior is "CDC Subset"; extra descriptors say "SAFE" */
734 fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf; 793 fs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
735 fs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc; 794 fs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
736 fs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc; 795 fs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
737 fs_eth_function[4] = NULL; 796 fs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
797 fs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc;
798 fs_eth_function[6] = (struct usb_descriptor_header *) &fs_source_desc;
799 fs_eth_function[7] = (struct usb_descriptor_header *) &fs_sink_desc;
800 fs_eth_function[8] = NULL;
738#else 801#else
739 fs_eth_function[1] = NULL; 802 fs_eth_function[1] = NULL;
740#endif 803#endif
@@ -828,10 +891,15 @@ static const struct usb_descriptor_header *hs_eth_function [11] = {
828static inline void __init hs_subset_descriptors(void) 891static inline void __init hs_subset_descriptors(void)
829{ 892{
830#ifdef DEV_CONFIG_SUBSET 893#ifdef DEV_CONFIG_SUBSET
894 /* behavior is "CDC Subset"; extra descriptors say "SAFE" */
831 hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf; 895 hs_eth_function[1] = (struct usb_descriptor_header *) &subset_data_intf;
832 hs_eth_function[2] = (struct usb_descriptor_header *) &fs_source_desc; 896 hs_eth_function[2] = (struct usb_descriptor_header *) &header_desc;
833 hs_eth_function[3] = (struct usb_descriptor_header *) &fs_sink_desc; 897 hs_eth_function[3] = (struct usb_descriptor_header *) &mdlm_desc;
834 hs_eth_function[4] = NULL; 898 hs_eth_function[4] = (struct usb_descriptor_header *) &mdlm_detail_desc;
899 hs_eth_function[5] = (struct usb_descriptor_header *) &ether_desc;
900 hs_eth_function[6] = (struct usb_descriptor_header *) &hs_source_desc;
901 hs_eth_function[7] = (struct usb_descriptor_header *) &hs_sink_desc;
902 hs_eth_function[8] = NULL;
835#else 903#else
836 hs_eth_function[1] = NULL; 904 hs_eth_function[1] = NULL;
837#endif 905#endif
@@ -878,10 +946,8 @@ static char manufacturer [50];
878static char product_desc [40] = DRIVER_DESC; 946static char product_desc [40] = DRIVER_DESC;
879static char serial_number [20]; 947static char serial_number [20];
880 948
881#ifdef DEV_CONFIG_CDC
882/* address that the host will use ... usually assigned at random */ 949/* address that the host will use ... usually assigned at random */
883static char ethaddr [2 * ETH_ALEN + 1]; 950static char ethaddr [2 * ETH_ALEN + 1];
884#endif
885 951
886/* static strings, in UTF-8 */ 952/* static strings, in UTF-8 */
887static struct usb_string strings [] = { 953static struct usb_string strings [] = {
@@ -889,9 +955,9 @@ static struct usb_string strings [] = {
889 { STRING_PRODUCT, product_desc, }, 955 { STRING_PRODUCT, product_desc, },
890 { STRING_SERIALNUMBER, serial_number, }, 956 { STRING_SERIALNUMBER, serial_number, },
891 { STRING_DATA, "Ethernet Data", }, 957 { STRING_DATA, "Ethernet Data", },
958 { STRING_ETHADDR, ethaddr, },
892#ifdef DEV_CONFIG_CDC 959#ifdef DEV_CONFIG_CDC
893 { STRING_CDC, "CDC Ethernet", }, 960 { STRING_CDC, "CDC Ethernet", },
894 { STRING_ETHADDR, ethaddr, },
895 { STRING_CONTROL, "CDC Communications Control", }, 961 { STRING_CONTROL, "CDC Communications Control", },
896#endif 962#endif
897#ifdef DEV_CONFIG_SUBSET 963#ifdef DEV_CONFIG_SUBSET
@@ -986,10 +1052,10 @@ set_ether_config (struct eth_dev *dev, gfp_t gfp_flags)
986 } 1052 }
987#endif 1053#endif
988 1054
989 dev->in = ep_desc (dev->gadget, &hs_source_desc, &fs_source_desc); 1055 dev->in = ep_desc(gadget, &hs_source_desc, &fs_source_desc);
990 dev->in_ep->driver_data = dev; 1056 dev->in_ep->driver_data = dev;
991 1057
992 dev->out = ep_desc (dev->gadget, &hs_sink_desc, &fs_sink_desc); 1058 dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc);
993 dev->out_ep->driver_data = dev; 1059 dev->out_ep->driver_data = dev;
994 1060
995 /* With CDC, the host isn't allowed to use these two data 1061 /* With CDC, the host isn't allowed to use these two data
@@ -2278,10 +2344,10 @@ eth_bind (struct usb_gadget *gadget)
2278 "RNDIS/%s", driver_desc); 2344 "RNDIS/%s", driver_desc);
2279 2345
2280 /* CDC subset ... recognized by Linux since 2.4.10, but Windows 2346 /* CDC subset ... recognized by Linux since 2.4.10, but Windows
2281 * drivers aren't widely available. 2347 * drivers aren't widely available. (That may be improved by
2348 * supporting one submode of the "SAFE" variant of MDLM.)
2282 */ 2349 */
2283 } else if (!cdc) { 2350 } else if (!cdc) {
2284 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
2285 device_desc.idVendor = 2351 device_desc.idVendor =
2286 __constant_cpu_to_le16(SIMPLE_VENDOR_NUM); 2352 __constant_cpu_to_le16(SIMPLE_VENDOR_NUM);
2287 device_desc.idProduct = 2353 device_desc.idProduct =
@@ -2352,6 +2418,10 @@ autoconf_fail:
2352 if (!cdc) { 2418 if (!cdc) {
2353 eth_config.bNumInterfaces = 1; 2419 eth_config.bNumInterfaces = 1;
2354 eth_config.iConfiguration = STRING_SUBSET; 2420 eth_config.iConfiguration = STRING_SUBSET;
2421
2422 /* use functions to set these up, in case we're built to work
2423 * with multiple controllers and must override CDC Ethernet.
2424 */
2355 fs_subset_descriptors(); 2425 fs_subset_descriptors();
2356 hs_subset_descriptors(); 2426 hs_subset_descriptors();
2357 } 2427 }
@@ -2415,22 +2485,20 @@ autoconf_fail:
2415 2485
2416 /* Module params for these addresses should come from ID proms. 2486 /* Module params for these addresses should come from ID proms.
2417 * The host side address is used with CDC and RNDIS, and commonly 2487 * The host side address is used with CDC and RNDIS, and commonly
2418 * ends up in a persistent config database. 2488 * ends up in a persistent config database. It's not clear if
2489 * host side code for the SAFE thing cares -- its original BLAN
2490 * thing didn't, Sharp never assigned those addresses on Zaurii.
2419 */ 2491 */
2420 if (get_ether_addr(dev_addr, net->dev_addr)) 2492 if (get_ether_addr(dev_addr, net->dev_addr))
2421 dev_warn(&gadget->dev, 2493 dev_warn(&gadget->dev,
2422 "using random %s ethernet address\n", "self"); 2494 "using random %s ethernet address\n", "self");
2423 if (cdc || rndis) { 2495 if (get_ether_addr(host_addr, dev->host_mac))
2424 if (get_ether_addr(host_addr, dev->host_mac)) 2496 dev_warn(&gadget->dev,
2425 dev_warn(&gadget->dev, 2497 "using random %s ethernet address\n", "host");
2426 "using random %s ethernet address\n", "host"); 2498 snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X",
2427#ifdef DEV_CONFIG_CDC 2499 dev->host_mac [0], dev->host_mac [1],
2428 snprintf (ethaddr, sizeof ethaddr, "%02X%02X%02X%02X%02X%02X", 2500 dev->host_mac [2], dev->host_mac [3],
2429 dev->host_mac [0], dev->host_mac [1], 2501 dev->host_mac [4], dev->host_mac [5]);
2430 dev->host_mac [2], dev->host_mac [3],
2431 dev->host_mac [4], dev->host_mac [5]);
2432#endif
2433 }
2434 2502
2435 if (rndis) { 2503 if (rndis) {
2436 status = rndis_init(); 2504 status = rndis_init();