aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/net/usbnet.c
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2005-08-31 12:53:58 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-09-08 19:28:32 -0400
commit0aa599c5644fddd3052433c5335260108a8a39a2 (patch)
tree53ff1eadd9d5386e7b9912b1d2728d150ad8567f /drivers/usb/net/usbnet.c
parent47ee3051c856cc2aa95d35d577a8cb37279d540f (diff)
[PATCH] USB: usbnet (6/9) module for Zaurii and compatibles
This moves usbnet support for Zaurus and compatibles into its own module. Other than exporting a couple of helper functions, this just involved shuffling some code and updating the comments. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/net/usbnet.c')
-rw-r--r--drivers/usb/net/usbnet.c357
1 files changed, 7 insertions, 350 deletions
diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
index d52480aced80..75a05ab0a642 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/usb/net/usbnet.c
@@ -1,7 +1,6 @@
1/* 1/*
2 * USB Networking Links 2 * USB Networking Links
3 * Copyright (C) 2000-2005 by David Brownell 3 * Copyright (C) 2000-2005 by David Brownell
4 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
5 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com> 4 * Copyright (C) 2003-2005 David Hollis <dhollis@davehollis.com>
6 * 5 *
7 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
@@ -173,14 +172,6 @@ MODULE_PARM_DESC (msg_level, "Override default message level");
173 172
174/*-------------------------------------------------------------------------*/ 173/*-------------------------------------------------------------------------*/
175 174
176static u32 usbnet_get_link (struct net_device *);
177
178/* mostly for PDA style devices, which are always connected if present */
179static int always_connected (struct usbnet *dev)
180{
181 return 0;
182}
183
184/* handles CDC Ethernet and many other network "bulk data" interfaces */ 175/* handles CDC Ethernet and many other network "bulk data" interfaces */
185int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf) 176int usbnet_get_endpoints(struct usbnet *dev, struct usb_interface *intf)
186{ 177{
@@ -321,7 +312,7 @@ EXPORT_SYMBOL_GPL(usbnet_skb_return);
321#define NEED_GENERIC_CDC 312#define NEED_GENERIC_CDC
322#endif 313#endif
323 314
324#ifdef CONFIG_USB_ZAURUS 315#if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_ZAURUS_MODULE)
325/* Ethernet variant uses funky framing, broken ethernet addressing */ 316/* Ethernet variant uses funky framing, broken ethernet addressing */
326#define NEED_GENERIC_CDC 317#define NEED_GENERIC_CDC
327#endif 318#endif
@@ -336,14 +327,6 @@ EXPORT_SYMBOL_GPL(usbnet_skb_return);
336 327
337#include <linux/usb_cdc.h> 328#include <linux/usb_cdc.h>
338 329
339struct cdc_state {
340 struct usb_cdc_header_desc *header;
341 struct usb_cdc_union_desc *u;
342 struct usb_cdc_ether_desc *ether;
343 struct usb_interface *control;
344 struct usb_interface *data;
345};
346
347static struct usb_driver usbnet_driver; 330static struct usb_driver usbnet_driver;
348 331
349/* 332/*
@@ -351,7 +334,7 @@ static struct usb_driver usbnet_driver;
351 * endpoints, activates data interface (if needed), maybe sets MTU. 334 * endpoints, activates data interface (if needed), maybe sets MTU.
352 * all pure cdc, except for certain firmware workarounds. 335 * all pure cdc, except for certain firmware workarounds.
353 */ 336 */
354static int generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf) 337int usbnet_generic_cdc_bind (struct usbnet *dev, struct usb_interface *intf)
355{ 338{
356 u8 *buf = intf->cur_altsetting->extra; 339 u8 *buf = intf->cur_altsetting->extra;
357 int len = intf->cur_altsetting->extralen; 340 int len = intf->cur_altsetting->extralen;
@@ -530,8 +513,9 @@ bad_desc:
530 dev_info (&dev->udev->dev, "bad CDC descriptors\n"); 513 dev_info (&dev->udev->dev, "bad CDC descriptors\n");
531 return -ENODEV; 514 return -ENODEV;
532} 515}
516EXPORT_SYMBOL_GPL(usbnet_generic_cdc_bind);
533 517
534static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf) 518void usbnet_cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
535{ 519{
536 struct cdc_state *info = (void *) &dev->data; 520 struct cdc_state *info = (void *) &dev->data;
537 521
@@ -551,6 +535,7 @@ static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
551 info->control = NULL; 535 info->control = NULL;
552 } 536 }
553} 537}
538EXPORT_SYMBOL_GPL(usbnet_cdc_unbind);
554 539
555#endif /* NEED_GENERIC_CDC */ 540#endif /* NEED_GENERIC_CDC */
556 541
@@ -657,7 +642,7 @@ static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
657 int status; 642 int status;
658 struct cdc_state *info = (void *) &dev->data; 643 struct cdc_state *info = (void *) &dev->data;
659 644
660 status = generic_cdc_bind (dev, intf); 645 status = usbnet_generic_cdc_bind (dev, intf);
661 if (status < 0) 646 if (status < 0)
662 return status; 647 return status;
663 648
@@ -679,7 +664,7 @@ static const struct driver_info cdc_info = {
679 .flags = FLAG_ETHER, 664 .flags = FLAG_ETHER,
680 // .check_connect = cdc_check_connect, 665 // .check_connect = cdc_check_connect,
681 .bind = cdc_bind, 666 .bind = cdc_bind,
682 .unbind = cdc_unbind, 667 .unbind = usbnet_cdc_unbind,
683 .status = cdc_status, 668 .status = cdc_status,
684}; 669};
685 670
@@ -758,239 +743,6 @@ static const struct driver_info prolific_info = {
758#endif /* CONFIG_USB_PL2301 */ 743#endif /* CONFIG_USB_PL2301 */
759 744
760 745
761#ifdef CONFIG_USB_ZAURUS
762#define HAVE_HARDWARE
763
764#include <linux/crc32.h>
765
766/*-------------------------------------------------------------------------
767 *
768 * Zaurus is also a SA-1110 based PDA, but one using a different driver
769 * (and framing) for its USB slave/gadget controller than the case above.
770 *
771 * For the current version of that driver, the main way that framing is
772 * nonstandard (also from perspective of the CDC ethernet model!) is a
773 * crc32, added to help detect when some sa1100 usb-to-memory DMA errata
774 * haven't been fully worked around. Also, all Zaurii use the same
775 * default Ethernet address.
776 *
777 * PXA based models use the same framing, and also can't implement
778 * set_interface properly.
779 *
780 * All known Zaurii lie about their standards conformance. Most lie by
781 * saying they support CDC Ethernet. Some lie and say they support CDC
782 * MDLM (as if for access to cell phone modems). Someone, please beat
783 * on Sharp (and other such vendors) for a while with a cluestick.
784 *
785 *-------------------------------------------------------------------------*/
786
787static struct sk_buff *
788zaurus_tx_fixup (struct usbnet *dev, struct sk_buff *skb, unsigned flags)
789{
790 int padlen;
791 struct sk_buff *skb2;
792
793 padlen = 2;
794 if (!skb_cloned (skb)) {
795 int tailroom = skb_tailroom (skb);
796 if ((padlen + 4) <= tailroom)
797 goto done;
798 }
799 skb2 = skb_copy_expand (skb, 0, 4 + padlen, flags);
800 dev_kfree_skb_any (skb);
801 skb = skb2;
802 if (skb) {
803 u32 fcs;
804done:
805 fcs = crc32_le (~0, skb->data, skb->len);
806 fcs = ~fcs;
807
808 *skb_put (skb, 1) = fcs & 0xff;
809 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
810 *skb_put (skb, 1) = (fcs>>16) & 0xff;
811 *skb_put (skb, 1) = (fcs>>24) & 0xff;
812 }
813 return skb;
814}
815
816static int zaurus_bind (struct usbnet *dev, struct usb_interface *intf)
817{
818 /* Belcarra's funky framing has other options; mostly
819 * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
820 */
821 dev->net->hard_header_len += 6;
822 return generic_cdc_bind(dev, intf);
823}
824
825static const struct driver_info zaurus_sl5x00_info = {
826 .description = "Sharp Zaurus SL-5x00",
827 .flags = FLAG_FRAMING_Z,
828 .check_connect = always_connected,
829 .bind = zaurus_bind,
830 .unbind = cdc_unbind,
831 .tx_fixup = zaurus_tx_fixup,
832};
833#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
834
835static const struct driver_info zaurus_pxa_info = {
836 .description = "Sharp Zaurus, PXA-2xx based",
837 .flags = FLAG_FRAMING_Z,
838 .check_connect = always_connected,
839 .bind = zaurus_bind,
840 .unbind = cdc_unbind,
841 .tx_fixup = zaurus_tx_fixup,
842};
843#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
844
845static const struct driver_info olympus_mxl_info = {
846 .description = "Olympus R1000",
847 .flags = FLAG_FRAMING_Z,
848 .check_connect = always_connected,
849 .bind = zaurus_bind,
850 .unbind = cdc_unbind,
851 .tx_fixup = zaurus_tx_fixup,
852};
853#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
854
855
856/* Some more recent products using Lineo/Belcarra code will wrongly claim
857 * CDC MDLM conformance. They aren't conformant: data endpoints live
858 * in the control interface, there's no data interface, and it's not used
859 * to talk to a cell phone radio. But at least we can detect these two
860 * pseudo-classes, rather than growing this product list with entries for
861 * each new nonconformant product (sigh).
862 */
863static const u8 safe_guid[16] = {
864 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
865 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
866};
867static const u8 blan_guid[16] = {
868 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
869 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
870};
871
872static int blan_mdlm_bind (struct usbnet *dev, struct usb_interface *intf)
873{
874 u8 *buf = intf->cur_altsetting->extra;
875 int len = intf->cur_altsetting->extralen;
876 struct usb_cdc_mdlm_desc *desc = NULL;
877 struct usb_cdc_mdlm_detail_desc *detail = NULL;
878
879 while (len > 3) {
880 if (buf [1] != USB_DT_CS_INTERFACE)
881 goto next_desc;
882
883 /* use bDescriptorSubType, and just verify that we get a
884 * "BLAN" (or "SAFE") descriptor.
885 */
886 switch (buf [2]) {
887 case USB_CDC_MDLM_TYPE:
888 if (desc) {
889 dev_dbg (&intf->dev, "extra MDLM\n");
890 goto bad_desc;
891 }
892 desc = (void *) buf;
893 if (desc->bLength != sizeof *desc) {
894 dev_dbg (&intf->dev, "MDLM len %u\n",
895 desc->bLength);
896 goto bad_desc;
897 }
898 /* expect bcdVersion 1.0, ignore */
899 if (memcmp(&desc->bGUID, blan_guid, 16)
900 && memcmp(&desc->bGUID, safe_guid, 16) ) {
901 /* hey, this one might _really_ be MDLM! */
902 dev_dbg (&intf->dev, "MDLM guid\n");
903 goto bad_desc;
904 }
905 break;
906 case USB_CDC_MDLM_DETAIL_TYPE:
907 if (detail) {
908 dev_dbg (&intf->dev, "extra MDLM detail\n");
909 goto bad_desc;
910 }
911 detail = (void *) buf;
912 switch (detail->bGuidDescriptorType) {
913 case 0: /* "SAFE" */
914 if (detail->bLength != (sizeof *detail + 2))
915 goto bad_detail;
916 break;
917 case 1: /* "BLAN" */
918 if (detail->bLength != (sizeof *detail + 3))
919 goto bad_detail;
920 break;
921 default:
922 goto bad_detail;
923 }
924
925 /* assuming we either noticed BLAN already, or will
926 * find it soon, there are some data bytes here:
927 * - bmNetworkCapabilities (unused)
928 * - bmDataCapabilities (bits, see below)
929 * - bPad (ignored, for PADAFTER -- BLAN-only)
930 * bits are:
931 * - 0x01 -- Zaurus framing (add CRC)
932 * - 0x02 -- PADBEFORE (CRC includes some padding)
933 * - 0x04 -- PADAFTER (some padding after CRC)
934 * - 0x08 -- "fermat" packet mangling (for hw bugs)
935 * the PADBEFORE appears not to matter; we interop
936 * with devices that use it and those that don't.
937 */
938 if ((detail->bDetailData[1] & ~02) != 0x01) {
939 /* bmDataCapabilites == 0 would be fine too,
940 * but framing is minidriver-coupled for now.
941 */
942bad_detail:
943 dev_dbg (&intf->dev,
944 "bad MDLM detail, %d %d %d\n",
945 detail->bLength,
946 detail->bDetailData[0],
947 detail->bDetailData[2]);
948 goto bad_desc;
949 }
950 break;
951 }
952next_desc:
953 len -= buf [0]; /* bLength */
954 buf += buf [0];
955 }
956
957 if (!desc || !detail) {
958 dev_dbg (&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
959 desc ? "" : "func ",
960 detail ? "" : "detail ");
961 goto bad_desc;
962 }
963
964 /* There's probably a CDC Ethernet descriptor there, but we can't
965 * rely on the Ethernet address it provides since not all vendors
966 * bother to make it unique. Likewise there's no point in tracking
967 * of the CDC event notifications.
968 */
969 return usbnet_get_endpoints (dev, intf);
970
971bad_desc:
972 dev_info (&dev->udev->dev, "unsupported MDLM descriptors\n");
973 return -ENODEV;
974}
975
976static const struct driver_info bogus_mdlm_info = {
977 .description = "pseudo-MDLM (BLAN) device",
978 .flags = FLAG_FRAMING_Z,
979 .check_connect = always_connected,
980 .tx_fixup = zaurus_tx_fixup,
981 .bind = blan_mdlm_bind,
982};
983
984#else
985
986/* blacklist all those devices */
987#define ZAURUS_STRONGARM_INFO 0
988#define ZAURUS_PXA_INFO 0
989#define OLYMPUS_MXL_INFO 0
990
991#endif
992
993
994/*------------------------------------------------------------------------- 746/*-------------------------------------------------------------------------
995 * 747 *
996 * Network Device Driver (peer link to "Host Device", from USB host) 748 * Network Device Driver (peer link to "Host Device", from USB host)
@@ -2003,101 +1755,6 @@ static const struct usb_device_id products [] = {
2003}, 1755},
2004#endif 1756#endif
2005 1757
2006#if defined(CONFIG_USB_ZAURUS) || defined(CONFIG_USB_CDCETHER)
2007/*
2008 * SA-1100 based Sharp Zaurus ("collie"), or compatible.
2009 * Same idea as above, but different framing.
2010 *
2011 * PXA-2xx based models are also lying-about-cdc.
2012 * Some models don't even tell the same lies ...
2013 *
2014 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
2015 * unlike the older ones with 2.4 "embedix" kernels.
2016 *
2017 * NOTE: These entries do double-duty, serving as blacklist entries
2018 * whenever Zaurus support isn't enabled, but CDC Ethernet is.
2019 */
2020#define ZAURUS_MASTER_INTERFACE \
2021 .bInterfaceClass = USB_CLASS_COMM, \
2022 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
2023 .bInterfaceProtocol = USB_CDC_PROTO_NONE
2024{
2025 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2026 | USB_DEVICE_ID_MATCH_DEVICE,
2027 .idVendor = 0x04DD,
2028 .idProduct = 0x8004,
2029 ZAURUS_MASTER_INTERFACE,
2030 .driver_info = ZAURUS_STRONGARM_INFO,
2031}, {
2032 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2033 | USB_DEVICE_ID_MATCH_DEVICE,
2034 .idVendor = 0x04DD,
2035 .idProduct = 0x8005, /* A-300 */
2036 ZAURUS_MASTER_INTERFACE,
2037 .driver_info = ZAURUS_PXA_INFO,
2038}, {
2039 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2040 | USB_DEVICE_ID_MATCH_DEVICE,
2041 .idVendor = 0x04DD,
2042 .idProduct = 0x8006, /* B-500/SL-5600 */
2043 ZAURUS_MASTER_INTERFACE,
2044 .driver_info = ZAURUS_PXA_INFO,
2045}, {
2046 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2047 | USB_DEVICE_ID_MATCH_DEVICE,
2048 .idVendor = 0x04DD,
2049 .idProduct = 0x8007, /* C-700 */
2050 ZAURUS_MASTER_INTERFACE,
2051 .driver_info = ZAURUS_PXA_INFO,
2052}, {
2053 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2054 | USB_DEVICE_ID_MATCH_DEVICE,
2055 .idVendor = 0x04DD,
2056 .idProduct = 0x9031, /* C-750 C-760 */
2057 ZAURUS_MASTER_INTERFACE,
2058 .driver_info = ZAURUS_PXA_INFO,
2059}, {
2060 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2061 | USB_DEVICE_ID_MATCH_DEVICE,
2062 .idVendor = 0x04DD,
2063 .idProduct = 0x9032, /* SL-6000 */
2064 ZAURUS_MASTER_INTERFACE,
2065 .driver_info = ZAURUS_PXA_INFO,
2066}, {
2067 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2068 | USB_DEVICE_ID_MATCH_DEVICE,
2069 .idVendor = 0x04DD,
2070 /* reported with some C860 units */
2071 .idProduct = 0x9050, /* C-860 */
2072 ZAURUS_MASTER_INTERFACE,
2073 .driver_info = ZAURUS_PXA_INFO,
2074},
2075
2076#ifdef CONFIG_USB_ZAURUS
2077 /* At least some (reports vary) PXA units have very different lies
2078 * about their standards support: they claim to be cell phones with
2079 * direct access to their radios. (They don't conform to CDC MDLM.)
2080 */
2081{
2082 USB_INTERFACE_INFO (USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
2083 USB_CDC_PROTO_NONE),
2084 .driver_info = (unsigned long) &bogus_mdlm_info,
2085},
2086#endif
2087
2088/* Olympus has some models with a Zaurus-compatible option.
2089 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
2090 */
2091{
2092 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
2093 | USB_DEVICE_ID_MATCH_DEVICE,
2094 .idVendor = 0x07B4,
2095 .idProduct = 0x0F02, /* R-1000 */
2096 ZAURUS_MASTER_INTERFACE,
2097 .driver_info = OLYMPUS_MXL_INFO,
2098},
2099#endif
2100
2101#ifdef CONFIG_USB_CDCETHER 1758#ifdef CONFIG_USB_CDCETHER
2102{ 1759{
2103 /* CDC Ether uses two interfaces, not necessarily consecutive. 1760 /* CDC Ether uses two interfaces, not necessarily consecutive.