aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
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
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')
-rw-r--r--drivers/usb/net/Kconfig34
-rw-r--r--drivers/usb/net/Makefile1
-rw-r--r--drivers/usb/net/usbnet.c357
-rw-r--r--drivers/usb/net/usbnet.h22
-rw-r--r--drivers/usb/net/zaurus.c386
5 files changed, 433 insertions, 367 deletions
diff --git a/drivers/usb/net/Kconfig b/drivers/usb/net/Kconfig
index 0aafd599d7d4..20de10916a4e 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/usb/net/Kconfig
@@ -140,23 +140,6 @@ config USB_PL2301
140comment "Intelligent USB Devices/Gadgets" 140comment "Intelligent USB Devices/Gadgets"
141 depends on USB_USBNET 141 depends on USB_USBNET
142 142
143config USB_ZAURUS
144 boolean "Sharp Zaurus (stock ROMs) and compatible"
145 depends on USB_USBNET
146 select CRC32
147 default y
148 help
149 Choose this option to support the usb networking links used by
150 Zaurus models like the SL-5000D, SL-5500, SL-5600, A-300, B-500.
151 This also supports some related device firmware, as used in some
152 PDAs from Olympus and some cell phones from Motorola.
153
154 If you install an alternate ROM image, such as the Linux 2.6 based
155 versions of OpenZaurus, you should no longer need to support this
156 protocol. Only the "eth-fd" or "net_fd" drivers in these devices
157 really need this non-conformant variant of CDC Ethernet (or in
158 some cases CDC MDLM) protocol, not "g_ether".
159
160config USB_CDCETHER 143config USB_CDCETHER
161 boolean "CDC Ethernet support (smart devices such as cable modems)" 144 boolean "CDC Ethernet support (smart devices such as cable modems)"
162 depends on USB_USBNET 145 depends on USB_USBNET
@@ -294,6 +277,23 @@ config USB_EPSON2888
294 Choose this option to support the usb networking links used 277 Choose this option to support the usb networking links used
295 by some sample firmware from Epson. 278 by some sample firmware from Epson.
296 279
280config USB_NET_ZAURUS
281 tristate "Sharp Zaurus (stock ROMs) and compatible"
282 depends on USB_USBNET
283 select CRC32
284 default y
285 help
286 Choose this option to support the usb networking links used by
287 Zaurus models like the SL-5000D, SL-5500, SL-5600, A-300, B-500.
288 This also supports some related device firmware, as used in some
289 PDAs from Olympus and some cell phones from Motorola.
290
291 If you install an alternate ROM image, such as the Linux 2.6 based
292 versions of OpenZaurus, you should no longer need to support this
293 protocol. Only the "eth-fd" or "net_fd" drivers in these devices
294 really need this non-conformant variant of CDC Ethernet (or in
295 some cases CDC MDLM) protocol, not "g_ether".
296
297 297
298config USB_ZD1201 298config USB_ZD1201
299 tristate "USB ZD1201 based Wireless device support" 299 tristate "USB ZD1201 based Wireless device support"
diff --git a/drivers/usb/net/Makefile b/drivers/usb/net/Makefile
index f9b181e91c1f..e13d7af3114b 100644
--- a/drivers/usb/net/Makefile
+++ b/drivers/usb/net/Makefile
@@ -10,5 +10,6 @@ obj-$(CONFIG_USB_NET_AX8817X) += asix.o
10obj-$(CONFIG_USB_NET_GL620A) += gl620a.o 10obj-$(CONFIG_USB_NET_GL620A) += gl620a.o
11obj-$(CONFIG_USB_NET_NET1080) += net1080.o 11obj-$(CONFIG_USB_NET_NET1080) += net1080.o
12obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o 12obj-$(CONFIG_USB_NET_CDC_SUBSET) += cdc_subset.o
13obj-$(CONFIG_USB_NET_ZAURUS) += zaurus.o
13obj-$(CONFIG_USB_USBNET) += usbnet.o 14obj-$(CONFIG_USB_USBNET) += usbnet.o
14obj-$(CONFIG_USB_ZD1201) += zd1201.o 15obj-$(CONFIG_USB_ZD1201) += zd1201.o
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.
diff --git a/drivers/usb/net/usbnet.h b/drivers/usb/net/usbnet.h
index 21b5feb54fc0..7aa0abd1a9bd 100644
--- a/drivers/usb/net/usbnet.h
+++ b/drivers/usb/net/usbnet.h
@@ -126,6 +126,28 @@ extern int usbnet_resume (struct usb_interface *);
126extern void usbnet_disconnect(struct usb_interface *); 126extern void usbnet_disconnect(struct usb_interface *);
127 127
128 128
129/* Drivers that reuse some of the standard USB CDC infrastructure
130 * (notably, using multiple interfaces according to the the CDC
131 * union descriptor) get some helper code.
132 */
133struct cdc_state {
134 struct usb_cdc_header_desc *header;
135 struct usb_cdc_union_desc *u;
136 struct usb_cdc_ether_desc *ether;
137 struct usb_interface *control;
138 struct usb_interface *data;
139};
140
141extern int usbnet_generic_cdc_bind (struct usbnet *, struct usb_interface *);
142extern void usbnet_cdc_unbind (struct usbnet *, struct usb_interface *);
143
144/* CDC and RNDIS support the same host-chosen packet filters for IN transfers */
145#define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \
146 |USB_CDC_PACKET_TYPE_ALL_MULTICAST \
147 |USB_CDC_PACKET_TYPE_PROMISCUOUS \
148 |USB_CDC_PACKET_TYPE_DIRECTED)
149
150
129/* we record the state for each of our queued skbs */ 151/* we record the state for each of our queued skbs */
130enum skb_state { 152enum skb_state {
131 illegal = 0, 153 illegal = 0,
diff --git a/drivers/usb/net/zaurus.c b/drivers/usb/net/zaurus.c
new file mode 100644
index 000000000000..ee3b892aeabc
--- /dev/null
+++ b/drivers/usb/net/zaurus.c
@@ -0,0 +1,386 @@
1/*
2 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
3 * Copyright (C) 2002-2005 by David Brownell
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20// #define DEBUG // error path messages, extra info
21// #define VERBOSE // more; success messages
22
23#include <linux/config.h>
24#ifdef CONFIG_USB_DEBUG
25# define DEBUG
26#endif
27#include <linux/module.h>
28#include <linux/sched.h>
29#include <linux/init.h>
30#include <linux/netdevice.h>
31#include <linux/ethtool.h>
32#include <linux/workqueue.h>
33#include <linux/mii.h>
34#include <linux/crc32.h>
35#include <linux/usb.h>
36#include <linux/usb_cdc.h>
37
38#include "usbnet.h"
39
40
41/*
42 * All known Zaurii lie about their standards conformance. At least
43 * the earliest SA-1100 models lie by saying they support CDC Ethernet.
44 * Some later models (especially PXA-25x and PXA-27x based ones) lie
45 * and say they support CDC MDLM (for access to cell phone modems).
46 *
47 * There are non-Zaurus products that use these same protocols too.
48 *
49 * The annoying thing is that at the same time Sharp was developing
50 * that annoying standards-breaking software, the Linux community had
51 * a simple "CDC Subset" working reliably on the same SA-1100 hardware.
52 * That is, the same functionality but not violating standards.
53 *
54 * The CDC Ethernet nonconformance points are troublesome to hosts
55 * with a true CDC Ethernet implementation:
56 * - Framing appends a CRC, which the spec says drivers "must not" do;
57 * - Transfers data in altsetting zero, instead of altsetting 1;
58 * - All these peripherals use the same ethernet address.
59 *
60 * The CDC MDLM nonconformance is less immediately troublesome, since all
61 * MDLM implementations are quasi-proprietary anyway.
62 */
63
64static struct sk_buff *
65zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags)
66{
67 int padlen;
68 struct sk_buff *skb2;
69
70 padlen = 2;
71 if (!skb_cloned(skb)) {
72 int tailroom = skb_tailroom(skb);
73 if ((padlen + 4) <= tailroom)
74 goto done;
75 }
76 skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags);
77 dev_kfree_skb_any(skb);
78 skb = skb2;
79 if (skb) {
80 u32 fcs;
81done:
82 fcs = crc32_le(~0, skb->data, skb->len);
83 fcs = ~fcs;
84
85 *skb_put (skb, 1) = fcs & 0xff;
86 *skb_put (skb, 1) = (fcs>> 8) & 0xff;
87 *skb_put (skb, 1) = (fcs>>16) & 0xff;
88 *skb_put (skb, 1) = (fcs>>24) & 0xff;
89 }
90 return skb;
91}
92
93static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf)
94{
95 /* Belcarra's funky framing has other options; mostly
96 * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
97 */
98 dev->net->hard_header_len += 6;
99 dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
100 return usbnet_generic_cdc_bind(dev, intf);
101}
102
103/* PDA style devices are always connected if present */
104static int always_connected (struct usbnet *dev)
105{
106 return 0;
107}
108
109static const struct driver_info zaurus_sl5x00_info = {
110 .description = "Sharp Zaurus SL-5x00",
111 .flags = FLAG_FRAMING_Z,
112 .check_connect = always_connected,
113 .bind = zaurus_bind,
114 .unbind = usbnet_cdc_unbind,
115 .tx_fixup = zaurus_tx_fixup,
116};
117#define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
118
119static const struct driver_info zaurus_pxa_info = {
120 .description = "Sharp Zaurus, PXA-2xx based",
121 .flags = FLAG_FRAMING_Z,
122 .check_connect = always_connected,
123 .bind = zaurus_bind,
124 .unbind = usbnet_cdc_unbind,
125 .tx_fixup = zaurus_tx_fixup,
126};
127#define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
128
129static const struct driver_info olympus_mxl_info = {
130 .description = "Olympus R1000",
131 .flags = FLAG_FRAMING_Z,
132 .check_connect = always_connected,
133 .bind = zaurus_bind,
134 .unbind = usbnet_cdc_unbind,
135 .tx_fixup = zaurus_tx_fixup,
136};
137#define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
138
139
140/* Some more recent products using Lineo/Belcarra code will wrongly claim
141 * CDC MDLM conformance. They aren't conformant: data endpoints live
142 * in the control interface, there's no data interface, and it's not used
143 * to talk to a cell phone radio. But at least we can detect these two
144 * pseudo-classes, rather than growing this product list with entries for
145 * each new nonconformant product (sigh).
146 */
147static const u8 safe_guid[16] = {
148 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
149 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
150};
151static const u8 blan_guid[16] = {
152 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
153 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
154};
155
156static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf)
157{
158 u8 *buf = intf->cur_altsetting->extra;
159 int len = intf->cur_altsetting->extralen;
160 struct usb_cdc_mdlm_desc *desc = NULL;
161 struct usb_cdc_mdlm_detail_desc *detail = NULL;
162
163 while (len > 3) {
164 if (buf [1] != USB_DT_CS_INTERFACE)
165 goto next_desc;
166
167 /* use bDescriptorSubType, and just verify that we get a
168 * "BLAN" (or "SAFE") descriptor.
169 */
170 switch (buf [2]) {
171 case USB_CDC_MDLM_TYPE:
172 if (desc) {
173 dev_dbg(&intf->dev, "extra MDLM\n");
174 goto bad_desc;
175 }
176 desc = (void *) buf;
177 if (desc->bLength != sizeof *desc) {
178 dev_dbg(&intf->dev, "MDLM len %u\n",
179 desc->bLength);
180 goto bad_desc;
181 }
182 /* expect bcdVersion 1.0, ignore */
183 if (memcmp(&desc->bGUID, blan_guid, 16)
184 && memcmp(&desc->bGUID, safe_guid, 16) ) {
185 /* hey, this one might _really_ be MDLM! */
186 dev_dbg(&intf->dev, "MDLM guid\n");
187 goto bad_desc;
188 }
189 break;
190 case USB_CDC_MDLM_DETAIL_TYPE:
191 if (detail) {
192 dev_dbg(&intf->dev, "extra MDLM detail\n");
193 goto bad_desc;
194 }
195 detail = (void *) buf;
196 switch (detail->bGuidDescriptorType) {
197 case 0: /* "SAFE" */
198 if (detail->bLength != (sizeof *detail + 2))
199 goto bad_detail;
200 break;
201 case 1: /* "BLAN" */
202 if (detail->bLength != (sizeof *detail + 3))
203 goto bad_detail;
204 break;
205 default:
206 goto bad_detail;
207 }
208
209 /* assuming we either noticed BLAN already, or will
210 * find it soon, there are some data bytes here:
211 * - bmNetworkCapabilities (unused)
212 * - bmDataCapabilities (bits, see below)
213 * - bPad (ignored, for PADAFTER -- BLAN-only)
214 * bits are:
215 * - 0x01 -- Zaurus framing (add CRC)
216 * - 0x02 -- PADBEFORE (CRC includes some padding)
217 * - 0x04 -- PADAFTER (some padding after CRC)
218 * - 0x08 -- "fermat" packet mangling (for hw bugs)
219 * the PADBEFORE appears not to matter; we interop
220 * with devices that use it and those that don't.
221 */
222 if ((detail->bDetailData[1] & ~0x02) != 0x01) {
223 /* bmDataCapabilites == 0 would be fine too,
224 * but framing is minidriver-coupled for now.
225 */
226bad_detail:
227 dev_dbg(&intf->dev,
228 "bad MDLM detail, %d %d %d\n",
229 detail->bLength,
230 detail->bDetailData[0],
231 detail->bDetailData[2]);
232 goto bad_desc;
233 }
234 break;
235 }
236next_desc:
237 len -= buf [0]; /* bLength */
238 buf += buf [0];
239 }
240
241 if (!desc || !detail) {
242 dev_dbg(&intf->dev, "missing cdc mdlm %s%sdescriptor\n",
243 desc ? "" : "func ",
244 detail ? "" : "detail ");
245 goto bad_desc;
246 }
247
248 /* There's probably a CDC Ethernet descriptor there, but we can't
249 * rely on the Ethernet address it provides since not all vendors
250 * bother to make it unique. Likewise there's no point in tracking
251 * of the CDC event notifications.
252 */
253 return usbnet_get_endpoints(dev, intf);
254
255bad_desc:
256 dev_info(&dev->udev->dev, "unsupported MDLM descriptors\n");
257 return -ENODEV;
258}
259
260static const struct driver_info bogus_mdlm_info = {
261 .description = "pseudo-MDLM (BLAN) device",
262 .flags = FLAG_FRAMING_Z,
263 .check_connect = always_connected,
264 .tx_fixup = zaurus_tx_fixup,
265 .bind = blan_mdlm_bind,
266};
267
268static const struct usb_device_id products [] = {
269#define ZAURUS_MASTER_INTERFACE \
270 .bInterfaceClass = USB_CLASS_COMM, \
271 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
272 .bInterfaceProtocol = USB_CDC_PROTO_NONE
273
274/* SA-1100 based Sharp Zaurus ("collie"), or compatible. */
275{
276 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
277 | USB_DEVICE_ID_MATCH_DEVICE,
278 .idVendor = 0x04DD,
279 .idProduct = 0x8004,
280 ZAURUS_MASTER_INTERFACE,
281 .driver_info = ZAURUS_STRONGARM_INFO,
282},
283
284/* PXA-2xx based models are also lying-about-cdc. If you add any
285 * more devices that claim to be CDC Ethernet, make sure they get
286 * added to the blacklist in cdc_ether too.
287 *
288 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
289 * unlike the older ones with 2.4 "embedix" kernels.
290 */
291{
292 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
293 | USB_DEVICE_ID_MATCH_DEVICE,
294 .idVendor = 0x04DD,
295 .idProduct = 0x8005, /* A-300 */
296 ZAURUS_MASTER_INTERFACE,
297 .driver_info = ZAURUS_PXA_INFO,
298}, {
299 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
300 | USB_DEVICE_ID_MATCH_DEVICE,
301 .idVendor = 0x04DD,
302 .idProduct = 0x8006, /* B-500/SL-5600 */
303 ZAURUS_MASTER_INTERFACE,
304 .driver_info = ZAURUS_PXA_INFO,
305}, {
306 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
307 | USB_DEVICE_ID_MATCH_DEVICE,
308 .idVendor = 0x04DD,
309 .idProduct = 0x8007, /* C-700 */
310 ZAURUS_MASTER_INTERFACE,
311 .driver_info = ZAURUS_PXA_INFO,
312}, {
313 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
314 | USB_DEVICE_ID_MATCH_DEVICE,
315 .idVendor = 0x04DD,
316 .idProduct = 0x9031, /* C-750 C-760 */
317 ZAURUS_MASTER_INTERFACE,
318 .driver_info = ZAURUS_PXA_INFO,
319}, {
320 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
321 | USB_DEVICE_ID_MATCH_DEVICE,
322 .idVendor = 0x04DD,
323 .idProduct = 0x9032, /* SL-6000 */
324 ZAURUS_MASTER_INTERFACE,
325 .driver_info = ZAURUS_PXA_INFO,
326}, {
327 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
328 | USB_DEVICE_ID_MATCH_DEVICE,
329 .idVendor = 0x04DD,
330 /* reported with some C860 units */
331 .idProduct = 0x9050, /* C-860 */
332 ZAURUS_MASTER_INTERFACE,
333 .driver_info = ZAURUS_PXA_INFO,
334},
335
336
337/* At least some of the newest PXA units have very different lies about
338 * their standards support: they claim to be cell phones offering
339 * direct access to their radios! (No, they don't conform to CDC MDLM.)
340 */
341{
342 USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
343 USB_CDC_PROTO_NONE),
344 .driver_info = (unsigned long) &bogus_mdlm_info,
345},
346
347/* Olympus has some models with a Zaurus-compatible option.
348 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
349 */
350{
351 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
352 | USB_DEVICE_ID_MATCH_DEVICE,
353 .idVendor = 0x07B4,
354 .idProduct = 0x0F02, /* R-1000 */
355 ZAURUS_MASTER_INTERFACE,
356 .driver_info = OLYMPUS_MXL_INFO,
357},
358 { }, // END
359};
360MODULE_DEVICE_TABLE(usb, products);
361
362static struct usb_driver zaurus_driver = {
363 .owner = THIS_MODULE,
364 .name = "zaurus",
365 .id_table = products,
366 .probe = usbnet_probe,
367 .disconnect = usbnet_disconnect,
368 .suspend = usbnet_suspend,
369 .resume = usbnet_resume,
370};
371
372static int __init zaurus_init(void)
373{
374 return usb_register(&zaurus_driver);
375}
376module_init(zaurus_init);
377
378static void __exit zaurus_exit(void)
379{
380 usb_deregister(&zaurus_driver);
381}
382module_exit(zaurus_exit);
383
384MODULE_AUTHOR("Pavel Machek, David Brownell");
385MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products");
386MODULE_LICENSE("GPL");