aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/usb')
-rw-r--r--drivers/net/usb/Kconfig21
-rw-r--r--drivers/net/usb/Makefile2
-rw-r--r--drivers/net/usb/asix.c53
-rw-r--r--drivers/net/usb/catc.c6
-rw-r--r--drivers/net/usb/cdc_ether.c114
-rw-r--r--drivers/net/usb/dm9601.c11
-rw-r--r--drivers/net/usb/hso.c4
-rw-r--r--drivers/net/usb/ipheth.c565
-rw-r--r--drivers/net/usb/kaweth.c14
-rw-r--r--drivers/net/usb/mcs7830.c10
-rw-r--r--drivers/net/usb/pegasus.c9
-rw-r--r--drivers/net/usb/pegasus.h2
-rw-r--r--drivers/net/usb/rndis_host.c18
-rw-r--r--drivers/net/usb/sierra_net.c1004
-rw-r--r--drivers/net/usb/smsc75xx.c6
-rw-r--r--drivers/net/usb/smsc95xx.c6
-rw-r--r--drivers/net/usb/usbnet.c15
17 files changed, 1722 insertions, 138 deletions
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index ba56ce4382d9..d7b7018a1de1 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -385,4 +385,25 @@ config USB_CDC_PHONET
385 cellular modem, as found on most Nokia handsets with the 385 cellular modem, as found on most Nokia handsets with the
386 "PC suite" USB profile. 386 "PC suite" USB profile.
387 387
388config USB_IPHETH
389 tristate "Apple iPhone USB Ethernet driver"
390 default n
391 ---help---
392 Module used to share Internet connection (tethering) from your
393 iPhone (Original, 3G and 3GS) to your system.
394 Note that you need userspace libraries and programs that are needed
395 to pair your device with your system and that understand the iPhone
396 protocol.
397
398 For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
399
400config USB_SIERRA_NET
401 tristate "USB-to-WWAN Driver for Sierra Wireless modems"
402 depends on USB_USBNET
403 help
404 Choose this option if you have a Sierra Wireless USB-to-WWAN device.
405
406 To compile this driver as a module, choose M here: the
407 module will be called sierra_net.
408
388endmenu 409endmenu
diff --git a/drivers/net/usb/Makefile b/drivers/net/usb/Makefile
index 82ea62955b56..b13a279663ba 100644
--- a/drivers/net/usb/Makefile
+++ b/drivers/net/usb/Makefile
@@ -23,4 +23,6 @@ obj-$(CONFIG_USB_NET_MCS7830) += mcs7830.o
23obj-$(CONFIG_USB_USBNET) += usbnet.o 23obj-$(CONFIG_USB_USBNET) += usbnet.o
24obj-$(CONFIG_USB_NET_INT51X1) += int51x1.o 24obj-$(CONFIG_USB_NET_INT51X1) += int51x1.o
25obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o 25obj-$(CONFIG_USB_CDC_PHONET) += cdc-phonet.o
26obj-$(CONFIG_USB_IPHETH) += ipheth.o
27obj-$(CONFIG_USB_SIERRA_NET) += sierra_net.o
26 28
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index 35f56fc82803..31b73310ec77 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -224,10 +224,9 @@ static int asix_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
224 cmd, value, index, size); 224 cmd, value, index, size);
225 225
226 if (data) { 226 if (data) {
227 buf = kmalloc(size, GFP_KERNEL); 227 buf = kmemdup(data, size, GFP_KERNEL);
228 if (!buf) 228 if (!buf)
229 goto out; 229 goto out;
230 memcpy(buf, data, size);
231 } 230 }
232 231
233 err = usb_control_msg( 232 err = usb_control_msg(
@@ -322,8 +321,29 @@ static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
322 /* get the packet length */ 321 /* get the packet length */
323 size = (u16) (header & 0x0000ffff); 322 size = (u16) (header & 0x0000ffff);
324 323
325 if ((skb->len) - ((size + 1) & 0xfffe) == 0) 324 if ((skb->len) - ((size + 1) & 0xfffe) == 0) {
325 u8 alignment = (u32)skb->data & 0x3;
326 if (alignment != 0x2) {
327 /*
328 * not 16bit aligned so use the room provided by
329 * the 32 bit header to align the data
330 *
331 * note we want 16bit alignment as MAC header is
332 * 14bytes thus ip header will be aligned on
333 * 32bit boundary so accessing ipheader elements
334 * using a cast to struct ip header wont cause
335 * an unaligned accesses.
336 */
337 u8 realignment = (alignment + 2) & 0x3;
338 memmove(skb->data - realignment,
339 skb->data,
340 size);
341 skb->data -= realignment;
342 skb_set_tail_pointer(skb, size);
343 }
326 return 2; 344 return 2;
345 }
346
327 if (size > ETH_FRAME_LEN) { 347 if (size > ETH_FRAME_LEN) {
328 netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n", 348 netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
329 size); 349 size);
@@ -331,7 +351,18 @@ static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
331 } 351 }
332 ax_skb = skb_clone(skb, GFP_ATOMIC); 352 ax_skb = skb_clone(skb, GFP_ATOMIC);
333 if (ax_skb) { 353 if (ax_skb) {
354 u8 alignment = (u32)packet & 0x3;
334 ax_skb->len = size; 355 ax_skb->len = size;
356
357 if (alignment != 0x2) {
358 /*
359 * not 16bit aligned use the room provided by
360 * the 32 bit header to align the data
361 */
362 u8 realignment = (alignment + 2) & 0x3;
363 memmove(packet - realignment, packet, size);
364 packet -= realignment;
365 }
335 ax_skb->data = packet; 366 ax_skb->data = packet;
336 skb_set_tail_pointer(ax_skb, size); 367 skb_set_tail_pointer(ax_skb, size);
337 usbnet_skb_return(dev, ax_skb); 368 usbnet_skb_return(dev, ax_skb);
@@ -558,16 +589,14 @@ static void asix_set_multicast(struct net_device *net)
558 * for our 8 byte filter buffer 589 * for our 8 byte filter buffer
559 * to avoid allocating memory that 590 * to avoid allocating memory that
560 * is tricky to free later */ 591 * is tricky to free later */
561 struct dev_mc_list *mc_list; 592 struct netdev_hw_addr *ha;
562 u32 crc_bits; 593 u32 crc_bits;
563 594
564 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); 595 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
565 596
566 /* Build the multicast hash filter. */ 597 /* Build the multicast hash filter. */
567 netdev_for_each_mc_addr(mc_list, net) { 598 netdev_for_each_mc_addr(ha, net) {
568 crc_bits = 599 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
569 ether_crc(ETH_ALEN,
570 mc_list->dmi_addr) >> 26;
571 data->multi_filter[crc_bits >> 3] |= 600 data->multi_filter[crc_bits >> 3] |=
572 1 << (crc_bits & 7); 601 1 << (crc_bits & 7);
573 } 602 }
@@ -794,16 +823,14 @@ static void ax88172_set_multicast(struct net_device *net)
794 * for our 8 byte filter buffer 823 * for our 8 byte filter buffer
795 * to avoid allocating memory that 824 * to avoid allocating memory that
796 * is tricky to free later */ 825 * is tricky to free later */
797 struct dev_mc_list *mc_list; 826 struct netdev_hw_addr *ha;
798 u32 crc_bits; 827 u32 crc_bits;
799 828
800 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE); 829 memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
801 830
802 /* Build the multicast hash filter. */ 831 /* Build the multicast hash filter. */
803 netdev_for_each_mc_addr(mc_list, net) { 832 netdev_for_each_mc_addr(ha, net) {
804 crc_bits = 833 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
805 ether_crc(ETH_ALEN,
806 mc_list->dmi_addr) >> 26;
807 data->multi_filter[crc_bits >> 3] |= 834 data->multi_filter[crc_bits >> 3] |=
808 1 << (crc_bits & 7); 835 1 << (crc_bits & 7);
809 } 836 }
diff --git a/drivers/net/usb/catc.c b/drivers/net/usb/catc.c
index 602e123b2741..97687d335903 100644
--- a/drivers/net/usb/catc.c
+++ b/drivers/net/usb/catc.c
@@ -629,7 +629,7 @@ static void catc_multicast(unsigned char *addr, u8 *multicast)
629static void catc_set_multicast_list(struct net_device *netdev) 629static void catc_set_multicast_list(struct net_device *netdev)
630{ 630{
631 struct catc *catc = netdev_priv(netdev); 631 struct catc *catc = netdev_priv(netdev);
632 struct dev_mc_list *mc; 632 struct netdev_hw_addr *ha;
633 u8 broadcast[6]; 633 u8 broadcast[6];
634 u8 rx = RxEnable | RxPolarity | RxMultiCast; 634 u8 rx = RxEnable | RxPolarity | RxMultiCast;
635 635
@@ -647,8 +647,8 @@ static void catc_set_multicast_list(struct net_device *netdev)
647 if (netdev->flags & IFF_ALLMULTI) { 647 if (netdev->flags & IFF_ALLMULTI) {
648 memset(catc->multicast, 0xff, 64); 648 memset(catc->multicast, 0xff, 64);
649 } else { 649 } else {
650 netdev_for_each_mc_addr(mc, netdev) { 650 netdev_for_each_mc_addr(ha, netdev) {
651 u32 crc = ether_crc_le(6, mc->dmi_addr); 651 u32 crc = ether_crc_le(6, ha->addr);
652 if (!catc->is_f5u011) { 652 if (!catc->is_f5u011) {
653 catc->multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7); 653 catc->multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
654 } else { 654 } else {
diff --git a/drivers/net/usb/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index c8cdb7f30adc..b3fe0de40469 100644
--- a/drivers/net/usb/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
@@ -64,6 +64,11 @@ static int is_wireless_rndis(struct usb_interface_descriptor *desc)
64 64
65#endif 65#endif
66 66
67static const u8 mbm_guid[16] = {
68 0xa3, 0x17, 0xa8, 0x8b, 0x04, 0x5e, 0x4f, 0x01,
69 0xa6, 0x07, 0xc0, 0xff, 0xcb, 0x7e, 0x39, 0x2a,
70};
71
67/* 72/*
68 * probes control interface, claims data interface, collects the bulk 73 * probes control interface, claims data interface, collects the bulk
69 * endpoints, activates data interface (if needed), maybe sets MTU. 74 * endpoints, activates data interface (if needed), maybe sets MTU.
@@ -79,6 +84,8 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
79 int status; 84 int status;
80 int rndis; 85 int rndis;
81 struct usb_driver *driver = driver_of(intf); 86 struct usb_driver *driver = driver_of(intf);
87 struct usb_cdc_mdlm_desc *desc = NULL;
88 struct usb_cdc_mdlm_detail_desc *detail = NULL;
82 89
83 if (sizeof dev->data < sizeof *info) 90 if (sizeof dev->data < sizeof *info)
84 return -EDOM; 91 return -EDOM;
@@ -229,6 +236,34 @@ int usbnet_generic_cdc_bind(struct usbnet *dev, struct usb_interface *intf)
229 * side link address we were given. 236 * side link address we were given.
230 */ 237 */
231 break; 238 break;
239 case USB_CDC_MDLM_TYPE:
240 if (desc) {
241 dev_dbg(&intf->dev, "extra MDLM descriptor\n");
242 goto bad_desc;
243 }
244
245 desc = (void *)buf;
246
247 if (desc->bLength != sizeof(*desc))
248 goto bad_desc;
249
250 if (memcmp(&desc->bGUID, mbm_guid, 16))
251 goto bad_desc;
252 break;
253 case USB_CDC_MDLM_DETAIL_TYPE:
254 if (detail) {
255 dev_dbg(&intf->dev, "extra MDLM detail descriptor\n");
256 goto bad_desc;
257 }
258
259 detail = (void *)buf;
260
261 if (detail->bGuidDescriptorType == 0) {
262 if (detail->bLength < (sizeof(*detail) + 1))
263 goto bad_desc;
264 } else
265 goto bad_desc;
266 break;
232 } 267 }
233next_desc: 268next_desc:
234 len -= buf [0]; /* bLength */ 269 len -= buf [0]; /* bLength */
@@ -431,6 +466,7 @@ static const struct driver_info mbm_info = {
431 .bind = cdc_bind, 466 .bind = cdc_bind,
432 .unbind = usbnet_cdc_unbind, 467 .unbind = usbnet_cdc_unbind,
433 .status = cdc_status, 468 .status = cdc_status,
469 .manage_power = cdc_manage_power,
434}; 470};
435 471
436/*-------------------------------------------------------------------------*/ 472/*-------------------------------------------------------------------------*/
@@ -542,80 +578,10 @@ static const struct usb_device_id products [] = {
542 USB_CDC_PROTO_NONE), 578 USB_CDC_PROTO_NONE),
543 .driver_info = (unsigned long) &cdc_info, 579 .driver_info = (unsigned long) &cdc_info,
544}, { 580}, {
545 /* Ericsson F3507g */ 581 USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
546 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1900, USB_CLASS_COMM, 582 USB_CDC_PROTO_NONE),
547 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE), 583 .driver_info = (unsigned long)&mbm_info,
548 .driver_info = (unsigned long) &mbm_info, 584
549}, {
550 /* Ericsson F3507g ver. 2 */
551 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1902, USB_CLASS_COMM,
552 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
553 .driver_info = (unsigned long) &mbm_info,
554}, {
555 /* Ericsson F3607gw */
556 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1904, USB_CLASS_COMM,
557 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
558 .driver_info = (unsigned long) &mbm_info,
559}, {
560 /* Ericsson F3607gw ver 2 */
561 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1905, USB_CLASS_COMM,
562 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
563 .driver_info = (unsigned long) &mbm_info,
564}, {
565 /* Ericsson F3607gw ver 3 */
566 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1906, USB_CLASS_COMM,
567 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
568 .driver_info = (unsigned long) &mbm_info,
569}, {
570 /* Ericsson F3307 */
571 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x190a, USB_CLASS_COMM,
572 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
573 .driver_info = (unsigned long) &mbm_info,
574}, {
575 /* Ericsson F3307 ver 2 */
576 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1909, USB_CLASS_COMM,
577 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
578 .driver_info = (unsigned long) &mbm_info,
579}, {
580 /* Ericsson C3607w */
581 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x1049, USB_CLASS_COMM,
582 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
583 .driver_info = (unsigned long) &mbm_info,
584}, {
585 /* Ericsson C3607w ver 2 */
586 USB_DEVICE_AND_INTERFACE_INFO(0x0bdb, 0x190b, USB_CLASS_COMM,
587 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
588 .driver_info = (unsigned long) &mbm_info,
589}, {
590 /* Toshiba F3507g */
591 USB_DEVICE_AND_INTERFACE_INFO(0x0930, 0x130b, USB_CLASS_COMM,
592 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
593 .driver_info = (unsigned long) &mbm_info,
594}, {
595 /* Toshiba F3607gw */
596 USB_DEVICE_AND_INTERFACE_INFO(0x0930, 0x130c, USB_CLASS_COMM,
597 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
598 .driver_info = (unsigned long) &mbm_info,
599}, {
600 /* Toshiba F3607gw ver 2 */
601 USB_DEVICE_AND_INTERFACE_INFO(0x0930, 0x1311, USB_CLASS_COMM,
602 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
603 .driver_info = (unsigned long) &mbm_info,
604}, {
605 /* Dell F3507g */
606 USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x8147, USB_CLASS_COMM,
607 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
608 .driver_info = (unsigned long) &mbm_info,
609}, {
610 /* Dell F3607gw */
611 USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x8183, USB_CLASS_COMM,
612 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
613 .driver_info = (unsigned long) &mbm_info,
614}, {
615 /* Dell F3607gw ver 2 */
616 USB_DEVICE_AND_INTERFACE_INFO(0x413c, 0x8184, USB_CLASS_COMM,
617 USB_CDC_SUBCLASS_MDLM, USB_CDC_PROTO_NONE),
618 .driver_info = (unsigned long) &mbm_info,
619}, 585},
620 { }, // END 586 { }, // END
621}; 587};
diff --git a/drivers/net/usb/dm9601.c b/drivers/net/usb/dm9601.c
index 04b281002a76..02b622e3b9fb 100644
--- a/drivers/net/usb/dm9601.c
+++ b/drivers/net/usb/dm9601.c
@@ -93,10 +93,9 @@ static int dm_write(struct usbnet *dev, u8 reg, u16 length, void *data)
93 netdev_dbg(dev->net, "dm_write() reg=0x%02x, length=%d\n", reg, length); 93 netdev_dbg(dev->net, "dm_write() reg=0x%02x, length=%d\n", reg, length);
94 94
95 if (data) { 95 if (data) {
96 buf = kmalloc(length, GFP_KERNEL); 96 buf = kmemdup(data, length, GFP_KERNEL);
97 if (!buf) 97 if (!buf)
98 goto out; 98 goto out;
99 memcpy(buf, data, length);
100 } 99 }
101 100
102 err = usb_control_msg(dev->udev, 101 err = usb_control_msg(dev->udev,
@@ -240,7 +239,7 @@ static int dm_write_shared_word(struct usbnet *dev, int phy, u8 reg, __le16 valu
240 goto out; 239 goto out;
241 240
242 dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg); 241 dm_write_reg(dev, DM_SHARED_ADDR, phy ? (reg | 0x40) : reg);
243 dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0x1c : 0x14); 242 dm_write_reg(dev, DM_SHARED_CTRL, phy ? 0x1a : 0x12);
244 243
245 for (i = 0; i < DM_TIMEOUT; i++) { 244 for (i = 0; i < DM_TIMEOUT; i++) {
246 u8 tmp; 245 u8 tmp;
@@ -387,10 +386,10 @@ static void dm9601_set_multicast(struct net_device *net)
387 netdev_mc_count(net) > DM_MAX_MCAST) { 386 netdev_mc_count(net) > DM_MAX_MCAST) {
388 rx_ctl |= 0x04; 387 rx_ctl |= 0x04;
389 } else if (!netdev_mc_empty(net)) { 388 } else if (!netdev_mc_empty(net)) {
390 struct dev_mc_list *mc_list; 389 struct netdev_hw_addr *ha;
391 390
392 netdev_for_each_mc_addr(mc_list, net) { 391 netdev_for_each_mc_addr(ha, net) {
393 u32 crc = ether_crc(ETH_ALEN, mc_list->dmi_addr) >> 26; 392 u32 crc = ether_crc(ETH_ALEN, ha->addr) >> 26;
394 hashes[crc >> 3] |= 1 << (crc & 0x7); 393 hashes[crc >> 3] |= 1 << (crc & 0x7);
395 } 394 }
396 } 395 }
diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
index be0cc99e881a..9964df199511 100644
--- a/drivers/net/usb/hso.c
+++ b/drivers/net/usb/hso.c
@@ -834,8 +834,6 @@ static netdev_tx_t hso_net_start_xmit(struct sk_buff *skb,
834 } else { 834 } else {
835 net->stats.tx_packets++; 835 net->stats.tx_packets++;
836 net->stats.tx_bytes += skb->len; 836 net->stats.tx_bytes += skb->len;
837 /* And tell the kernel when the last transmit started. */
838 net->trans_start = jiffies;
839 } 837 }
840 dev_kfree_skb(skb); 838 dev_kfree_skb(skb);
841 /* we're done */ 839 /* we're done */
@@ -1474,7 +1472,6 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
1474 spin_unlock_irqrestore(&serial->serial_lock, flags); 1472 spin_unlock_irqrestore(&serial->serial_lock, flags);
1475 1473
1476 /* done */ 1474 /* done */
1477 return;
1478} 1475}
1479 1476
1480/* how many characters in the buffer */ 1477/* how many characters in the buffer */
@@ -1994,7 +1991,6 @@ static void hso_std_serial_write_bulk_callback(struct urb *urb)
1994 hso_kick_transmit(serial); 1991 hso_kick_transmit(serial);
1995 1992
1996 D1(" "); 1993 D1(" ");
1997 return;
1998} 1994}
1999 1995
2000/* called for writing diag or CS serial port */ 1996/* called for writing diag or CS serial port */
diff --git a/drivers/net/usb/ipheth.c b/drivers/net/usb/ipheth.c
new file mode 100644
index 000000000000..197c352c47fb
--- /dev/null
+++ b/drivers/net/usb/ipheth.c
@@ -0,0 +1,565 @@
1/*
2 * ipheth.c - Apple iPhone USB Ethernet driver
3 *
4 * Copyright (c) 2009 Diego Giagio <diego@giagio.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of GIAGIO.COM nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * Alternatively, provided that this notice is retained in full, this
20 * software may be distributed under the terms of the GNU General
21 * Public License ("GPL") version 2, in which case the provisions of the
22 * GPL apply INSTEAD OF those given above.
23 *
24 * The provided data structures and external interfaces from this code
25 * are not restricted to be used by modules with a GPL compatible license.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38 * DAMAGE.
39 *
40 *
41 * Attention: iPhone device must be paired, otherwise it won't respond to our
42 * driver. For more info: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
43 *
44 */
45
46#include <linux/kernel.h>
47#include <linux/errno.h>
48#include <linux/init.h>
49#include <linux/slab.h>
50#include <linux/module.h>
51#include <linux/netdevice.h>
52#include <linux/etherdevice.h>
53#include <linux/ethtool.h>
54#include <linux/usb.h>
55#include <linux/workqueue.h>
56
57#define USB_VENDOR_APPLE 0x05ac
58#define USB_PRODUCT_IPHONE 0x1290
59#define USB_PRODUCT_IPHONE_3G 0x1292
60#define USB_PRODUCT_IPHONE_3GS 0x1294
61
62#define IPHETH_USBINTF_CLASS 255
63#define IPHETH_USBINTF_SUBCLASS 253
64#define IPHETH_USBINTF_PROTO 1
65
66#define IPHETH_BUF_SIZE 1516
67#define IPHETH_TX_TIMEOUT (5 * HZ)
68
69#define IPHETH_INTFNUM 2
70#define IPHETH_ALT_INTFNUM 1
71
72#define IPHETH_CTRL_ENDP 0x00
73#define IPHETH_CTRL_BUF_SIZE 0x40
74#define IPHETH_CTRL_TIMEOUT (5 * HZ)
75
76#define IPHETH_CMD_GET_MACADDR 0x00
77#define IPHETH_CMD_CARRIER_CHECK 0x45
78
79#define IPHETH_CARRIER_CHECK_TIMEOUT round_jiffies_relative(1 * HZ)
80#define IPHETH_CARRIER_ON 0x04
81
82static struct usb_device_id ipheth_table[] = {
83 { USB_DEVICE_AND_INTERFACE_INFO(
84 USB_VENDOR_APPLE, USB_PRODUCT_IPHONE,
85 IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
86 IPHETH_USBINTF_PROTO) },
87 { USB_DEVICE_AND_INTERFACE_INFO(
88 USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3G,
89 IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
90 IPHETH_USBINTF_PROTO) },
91 { USB_DEVICE_AND_INTERFACE_INFO(
92 USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3GS,
93 IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
94 IPHETH_USBINTF_PROTO) },
95 { }
96};
97MODULE_DEVICE_TABLE(usb, ipheth_table);
98
99struct ipheth_device {
100 struct usb_device *udev;
101 struct usb_interface *intf;
102 struct net_device *net;
103 struct sk_buff *tx_skb;
104 struct urb *tx_urb;
105 struct urb *rx_urb;
106 unsigned char *tx_buf;
107 unsigned char *rx_buf;
108 unsigned char *ctrl_buf;
109 u8 bulk_in;
110 u8 bulk_out;
111 struct delayed_work carrier_work;
112};
113
114static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags);
115
116static int ipheth_alloc_urbs(struct ipheth_device *iphone)
117{
118 struct urb *tx_urb = NULL;
119 struct urb *rx_urb = NULL;
120 u8 *tx_buf = NULL;
121 u8 *rx_buf = NULL;
122
123 tx_urb = usb_alloc_urb(0, GFP_KERNEL);
124 if (tx_urb == NULL)
125 goto error_nomem;
126
127 rx_urb = usb_alloc_urb(0, GFP_KERNEL);
128 if (rx_urb == NULL)
129 goto free_tx_urb;
130
131 tx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
132 GFP_KERNEL, &tx_urb->transfer_dma);
133 if (tx_buf == NULL)
134 goto free_rx_urb;
135
136 rx_buf = usb_alloc_coherent(iphone->udev, IPHETH_BUF_SIZE,
137 GFP_KERNEL, &rx_urb->transfer_dma);
138 if (rx_buf == NULL)
139 goto free_tx_buf;
140
141
142 iphone->tx_urb = tx_urb;
143 iphone->rx_urb = rx_urb;
144 iphone->tx_buf = tx_buf;
145 iphone->rx_buf = rx_buf;
146 return 0;
147
148free_tx_buf:
149 usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, tx_buf,
150 tx_urb->transfer_dma);
151free_rx_urb:
152 usb_free_urb(rx_urb);
153free_tx_urb:
154 usb_free_urb(tx_urb);
155error_nomem:
156 return -ENOMEM;
157}
158
159static void ipheth_free_urbs(struct ipheth_device *iphone)
160{
161 usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->rx_buf,
162 iphone->rx_urb->transfer_dma);
163 usb_free_coherent(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf,
164 iphone->tx_urb->transfer_dma);
165 usb_free_urb(iphone->rx_urb);
166 usb_free_urb(iphone->tx_urb);
167}
168
169static void ipheth_kill_urbs(struct ipheth_device *dev)
170{
171 usb_kill_urb(dev->tx_urb);
172 usb_kill_urb(dev->rx_urb);
173}
174
175static void ipheth_rcvbulk_callback(struct urb *urb)
176{
177 struct ipheth_device *dev;
178 struct sk_buff *skb;
179 int status;
180 char *buf;
181 int len;
182
183 dev = urb->context;
184 if (dev == NULL)
185 return;
186
187 status = urb->status;
188 switch (status) {
189 case -ENOENT:
190 case -ECONNRESET:
191 case -ESHUTDOWN:
192 return;
193 case 0:
194 break;
195 default:
196 err("%s: urb status: %d", __func__, urb->status);
197 return;
198 }
199
200 len = urb->actual_length;
201 buf = urb->transfer_buffer;
202
203 skb = dev_alloc_skb(NET_IP_ALIGN + len);
204 if (!skb) {
205 err("%s: dev_alloc_skb: -ENOMEM", __func__);
206 dev->net->stats.rx_dropped++;
207 return;
208 }
209
210 skb_reserve(skb, NET_IP_ALIGN);
211 memcpy(skb_put(skb, len), buf + NET_IP_ALIGN, len - NET_IP_ALIGN);
212 skb->dev = dev->net;
213 skb->protocol = eth_type_trans(skb, dev->net);
214
215 dev->net->stats.rx_packets++;
216 dev->net->stats.rx_bytes += len;
217
218 netif_rx(skb);
219 ipheth_rx_submit(dev, GFP_ATOMIC);
220}
221
222static void ipheth_sndbulk_callback(struct urb *urb)
223{
224 struct ipheth_device *dev;
225
226 dev = urb->context;
227 if (dev == NULL)
228 return;
229
230 if (urb->status != 0 &&
231 urb->status != -ENOENT &&
232 urb->status != -ECONNRESET &&
233 urb->status != -ESHUTDOWN)
234 err("%s: urb status: %d", __func__, urb->status);
235
236 dev_kfree_skb_irq(dev->tx_skb);
237 netif_wake_queue(dev->net);
238}
239
240static int ipheth_carrier_set(struct ipheth_device *dev)
241{
242 struct usb_device *udev = dev->udev;
243 int retval;
244
245 retval = usb_control_msg(udev,
246 usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
247 IPHETH_CMD_CARRIER_CHECK, /* request */
248 0xc0, /* request type */
249 0x00, /* value */
250 0x02, /* index */
251 dev->ctrl_buf, IPHETH_CTRL_BUF_SIZE,
252 IPHETH_CTRL_TIMEOUT);
253 if (retval < 0) {
254 err("%s: usb_control_msg: %d", __func__, retval);
255 return retval;
256 }
257
258 if (dev->ctrl_buf[0] == IPHETH_CARRIER_ON)
259 netif_carrier_on(dev->net);
260 else
261 netif_carrier_off(dev->net);
262
263 return 0;
264}
265
266static void ipheth_carrier_check_work(struct work_struct *work)
267{
268 struct ipheth_device *dev = container_of(work, struct ipheth_device,
269 carrier_work.work);
270
271 ipheth_carrier_set(dev);
272 schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
273}
274
275static int ipheth_get_macaddr(struct ipheth_device *dev)
276{
277 struct usb_device *udev = dev->udev;
278 struct net_device *net = dev->net;
279 int retval;
280
281 retval = usb_control_msg(udev,
282 usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
283 IPHETH_CMD_GET_MACADDR, /* request */
284 0xc0, /* request type */
285 0x00, /* value */
286 0x02, /* index */
287 dev->ctrl_buf,
288 IPHETH_CTRL_BUF_SIZE,
289 IPHETH_CTRL_TIMEOUT);
290 if (retval < 0) {
291 err("%s: usb_control_msg: %d", __func__, retval);
292 } else if (retval < ETH_ALEN) {
293 err("%s: usb_control_msg: short packet: %d bytes",
294 __func__, retval);
295 retval = -EINVAL;
296 } else {
297 memcpy(net->dev_addr, dev->ctrl_buf, ETH_ALEN);
298 retval = 0;
299 }
300
301 return retval;
302}
303
304static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags)
305{
306 struct usb_device *udev = dev->udev;
307 int retval;
308
309 usb_fill_bulk_urb(dev->rx_urb, udev,
310 usb_rcvbulkpipe(udev, dev->bulk_in),
311 dev->rx_buf, IPHETH_BUF_SIZE,
312 ipheth_rcvbulk_callback,
313 dev);
314 dev->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
315
316 retval = usb_submit_urb(dev->rx_urb, mem_flags);
317 if (retval)
318 err("%s: usb_submit_urb: %d", __func__, retval);
319 return retval;
320}
321
322static int ipheth_open(struct net_device *net)
323{
324 struct ipheth_device *dev = netdev_priv(net);
325 struct usb_device *udev = dev->udev;
326 int retval = 0;
327
328 usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
329
330 retval = ipheth_carrier_set(dev);
331 if (retval)
332 return retval;
333
334 retval = ipheth_rx_submit(dev, GFP_KERNEL);
335 if (retval)
336 return retval;
337
338 schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
339 netif_start_queue(net);
340 return retval;
341}
342
343static int ipheth_close(struct net_device *net)
344{
345 struct ipheth_device *dev = netdev_priv(net);
346
347 cancel_delayed_work_sync(&dev->carrier_work);
348 netif_stop_queue(net);
349 return 0;
350}
351
352static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
353{
354 struct ipheth_device *dev = netdev_priv(net);
355 struct usb_device *udev = dev->udev;
356 int retval;
357
358 /* Paranoid */
359 if (skb->len > IPHETH_BUF_SIZE) {
360 WARN(1, "%s: skb too large: %d bytes", __func__, skb->len);
361 dev->net->stats.tx_dropped++;
362 dev_kfree_skb_irq(skb);
363 return NETDEV_TX_OK;
364 }
365
366 memcpy(dev->tx_buf, skb->data, skb->len);
367 if (skb->len < IPHETH_BUF_SIZE)
368 memset(dev->tx_buf + skb->len, 0, IPHETH_BUF_SIZE - skb->len);
369
370 usb_fill_bulk_urb(dev->tx_urb, udev,
371 usb_sndbulkpipe(udev, dev->bulk_out),
372 dev->tx_buf, IPHETH_BUF_SIZE,
373 ipheth_sndbulk_callback,
374 dev);
375 dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
376
377 retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
378 if (retval) {
379 err("%s: usb_submit_urb: %d", __func__, retval);
380 dev->net->stats.tx_errors++;
381 dev_kfree_skb_irq(skb);
382 } else {
383 dev->tx_skb = skb;
384
385 dev->net->stats.tx_packets++;
386 dev->net->stats.tx_bytes += skb->len;
387 netif_stop_queue(net);
388 }
389
390 return NETDEV_TX_OK;
391}
392
393static void ipheth_tx_timeout(struct net_device *net)
394{
395 struct ipheth_device *dev = netdev_priv(net);
396
397 err("%s: TX timeout", __func__);
398 dev->net->stats.tx_errors++;
399 usb_unlink_urb(dev->tx_urb);
400}
401
402static struct net_device_stats *ipheth_stats(struct net_device *net)
403{
404 struct ipheth_device *dev = netdev_priv(net);
405 return &dev->net->stats;
406}
407
408static u32 ipheth_ethtool_op_get_link(struct net_device *net)
409{
410 struct ipheth_device *dev = netdev_priv(net);
411 return netif_carrier_ok(dev->net);
412}
413
414static struct ethtool_ops ops = {
415 .get_link = ipheth_ethtool_op_get_link
416};
417
418static const struct net_device_ops ipheth_netdev_ops = {
419 .ndo_open = &ipheth_open,
420 .ndo_stop = &ipheth_close,
421 .ndo_start_xmit = &ipheth_tx,
422 .ndo_tx_timeout = &ipheth_tx_timeout,
423 .ndo_get_stats = &ipheth_stats,
424};
425
426static struct device_type ipheth_type = {
427 .name = "wwan",
428};
429
430static int ipheth_probe(struct usb_interface *intf,
431 const struct usb_device_id *id)
432{
433 struct usb_device *udev = interface_to_usbdev(intf);
434 struct usb_host_interface *hintf;
435 struct usb_endpoint_descriptor *endp;
436 struct ipheth_device *dev;
437 struct net_device *netdev;
438 int i;
439 int retval;
440
441 netdev = alloc_etherdev(sizeof(struct ipheth_device));
442 if (!netdev)
443 return -ENOMEM;
444
445 netdev->netdev_ops = &ipheth_netdev_ops;
446 netdev->watchdog_timeo = IPHETH_TX_TIMEOUT;
447 strcpy(netdev->name, "wwan%d");
448
449 dev = netdev_priv(netdev);
450 dev->udev = udev;
451 dev->net = netdev;
452 dev->intf = intf;
453
454 /* Set up endpoints */
455 hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM);
456 if (hintf == NULL) {
457 retval = -ENODEV;
458 err("Unable to find alternate settings interface");
459 goto err_endpoints;
460 }
461
462 for (i = 0; i < hintf->desc.bNumEndpoints; i++) {
463 endp = &hintf->endpoint[i].desc;
464 if (usb_endpoint_is_bulk_in(endp))
465 dev->bulk_in = endp->bEndpointAddress;
466 else if (usb_endpoint_is_bulk_out(endp))
467 dev->bulk_out = endp->bEndpointAddress;
468 }
469 if (!(dev->bulk_in && dev->bulk_out)) {
470 retval = -ENODEV;
471 err("Unable to find endpoints");
472 goto err_endpoints;
473 }
474
475 dev->ctrl_buf = kmalloc(IPHETH_CTRL_BUF_SIZE, GFP_KERNEL);
476 if (dev->ctrl_buf == NULL) {
477 retval = -ENOMEM;
478 goto err_alloc_ctrl_buf;
479 }
480
481 retval = ipheth_get_macaddr(dev);
482 if (retval)
483 goto err_get_macaddr;
484
485 INIT_DELAYED_WORK(&dev->carrier_work, ipheth_carrier_check_work);
486
487 retval = ipheth_alloc_urbs(dev);
488 if (retval) {
489 err("error allocating urbs: %d", retval);
490 goto err_alloc_urbs;
491 }
492
493 usb_set_intfdata(intf, dev);
494
495 SET_NETDEV_DEV(netdev, &intf->dev);
496 SET_ETHTOOL_OPS(netdev, &ops);
497 SET_NETDEV_DEVTYPE(netdev, &ipheth_type);
498
499 retval = register_netdev(netdev);
500 if (retval) {
501 err("error registering netdev: %d", retval);
502 retval = -EIO;
503 goto err_register_netdev;
504 }
505
506 dev_info(&intf->dev, "Apple iPhone USB Ethernet device attached\n");
507 return 0;
508
509err_register_netdev:
510 ipheth_free_urbs(dev);
511err_alloc_urbs:
512err_get_macaddr:
513err_alloc_ctrl_buf:
514 kfree(dev->ctrl_buf);
515err_endpoints:
516 free_netdev(netdev);
517 return retval;
518}
519
520static void ipheth_disconnect(struct usb_interface *intf)
521{
522 struct ipheth_device *dev;
523
524 dev = usb_get_intfdata(intf);
525 if (dev != NULL) {
526 unregister_netdev(dev->net);
527 ipheth_kill_urbs(dev);
528 ipheth_free_urbs(dev);
529 kfree(dev->ctrl_buf);
530 free_netdev(dev->net);
531 }
532 usb_set_intfdata(intf, NULL);
533 dev_info(&intf->dev, "Apple iPhone USB Ethernet now disconnected\n");
534}
535
536static struct usb_driver ipheth_driver = {
537 .name = "ipheth",
538 .probe = ipheth_probe,
539 .disconnect = ipheth_disconnect,
540 .id_table = ipheth_table,
541};
542
543static int __init ipheth_init(void)
544{
545 int retval;
546
547 retval = usb_register(&ipheth_driver);
548 if (retval) {
549 err("usb_register failed: %d", retval);
550 return retval;
551 }
552 return 0;
553}
554
555static void __exit ipheth_exit(void)
556{
557 usb_deregister(&ipheth_driver);
558}
559
560module_init(ipheth_init);
561module_exit(ipheth_exit);
562
563MODULE_AUTHOR("Diego Giagio <diego@giagio.com>");
564MODULE_DESCRIPTION("Apple iPhone USB Ethernet driver");
565MODULE_LICENSE("Dual BSD/GPL");
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index 52671ea043a7..d6078b8c4273 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -145,6 +145,7 @@ static struct usb_device_id usb_klsi_table[] = {
145 { USB_DEVICE(0x0707, 0x0100) }, /* SMC 2202USB */ 145 { USB_DEVICE(0x0707, 0x0100) }, /* SMC 2202USB */
146 { USB_DEVICE(0x07aa, 0x0001) }, /* Correga K.K. */ 146 { USB_DEVICE(0x07aa, 0x0001) }, /* Correga K.K. */
147 { USB_DEVICE(0x07b8, 0x4000) }, /* D-Link DU-E10 */ 147 { USB_DEVICE(0x07b8, 0x4000) }, /* D-Link DU-E10 */
148 { USB_DEVICE(0x07c9, 0xb010) }, /* Allied Telesyn AT-USB10 USB Ethernet Adapter */
148 { USB_DEVICE(0x0846, 0x1001) }, /* NetGear EA-101 */ 149 { USB_DEVICE(0x0846, 0x1001) }, /* NetGear EA-101 */
149 { USB_DEVICE(0x0846, 0x1002) }, /* NetGear EA-101 */ 150 { USB_DEVICE(0x0846, 0x1002) }, /* NetGear EA-101 */
150 { USB_DEVICE(0x085a, 0x0008) }, /* PortGear Ethernet Adapter */ 151 { USB_DEVICE(0x085a, 0x0008) }, /* PortGear Ethernet Adapter */
@@ -855,7 +856,6 @@ skip:
855 { 856 {
856 kaweth->stats.tx_packets++; 857 kaweth->stats.tx_packets++;
857 kaweth->stats.tx_bytes += skb->len; 858 kaweth->stats.tx_bytes += skb->len;
858 net->trans_start = jiffies;
859 } 859 }
860 860
861 spin_unlock_irq(&kaweth->device_lock); 861 spin_unlock_irq(&kaweth->device_lock);
@@ -1155,13 +1155,13 @@ err_fw:
1155 if (!kaweth->irq_urb) 1155 if (!kaweth->irq_urb)
1156 goto err_tx_and_rx; 1156 goto err_tx_and_rx;
1157 1157
1158 kaweth->intbuffer = usb_buffer_alloc( kaweth->dev, 1158 kaweth->intbuffer = usb_alloc_coherent( kaweth->dev,
1159 INTBUFFERSIZE, 1159 INTBUFFERSIZE,
1160 GFP_KERNEL, 1160 GFP_KERNEL,
1161 &kaweth->intbufferhandle); 1161 &kaweth->intbufferhandle);
1162 if (!kaweth->intbuffer) 1162 if (!kaweth->intbuffer)
1163 goto err_tx_and_rx_and_irq; 1163 goto err_tx_and_rx_and_irq;
1164 kaweth->rx_buf = usb_buffer_alloc( kaweth->dev, 1164 kaweth->rx_buf = usb_alloc_coherent( kaweth->dev,
1165 KAWETH_BUF_SIZE, 1165 KAWETH_BUF_SIZE,
1166 GFP_KERNEL, 1166 GFP_KERNEL,
1167 &kaweth->rxbufferhandle); 1167 &kaweth->rxbufferhandle);
@@ -1202,9 +1202,9 @@ err_fw:
1202 1202
1203err_intfdata: 1203err_intfdata:
1204 usb_set_intfdata(intf, NULL); 1204 usb_set_intfdata(intf, NULL);
1205 usb_buffer_free(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle); 1205 usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1206err_all_but_rxbuf: 1206err_all_but_rxbuf:
1207 usb_buffer_free(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle); 1207 usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
1208err_tx_and_rx_and_irq: 1208err_tx_and_rx_and_irq:
1209 usb_free_urb(kaweth->irq_urb); 1209 usb_free_urb(kaweth->irq_urb);
1210err_tx_and_rx: 1210err_tx_and_rx:
@@ -1241,8 +1241,8 @@ static void kaweth_disconnect(struct usb_interface *intf)
1241 usb_free_urb(kaweth->tx_urb); 1241 usb_free_urb(kaweth->tx_urb);
1242 usb_free_urb(kaweth->irq_urb); 1242 usb_free_urb(kaweth->irq_urb);
1243 1243
1244 usb_buffer_free(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle); 1244 usb_free_coherent(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
1245 usb_buffer_free(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle); 1245 usb_free_coherent(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
1246 1246
1247 free_netdev(netdev); 1247 free_netdev(netdev);
1248} 1248}
diff --git a/drivers/net/usb/mcs7830.c b/drivers/net/usb/mcs7830.c
index 9f24e3f871e1..a6281e3987b5 100644
--- a/drivers/net/usb/mcs7830.c
+++ b/drivers/net/usb/mcs7830.c
@@ -142,12 +142,10 @@ static int mcs7830_set_reg(struct usbnet *dev, u16 index, u16 size, const void *
142 int ret; 142 int ret;
143 void *buffer; 143 void *buffer;
144 144
145 buffer = kmalloc(size, GFP_NOIO); 145 buffer = kmemdup(data, size, GFP_NOIO);
146 if (buffer == NULL) 146 if (buffer == NULL)
147 return -ENOMEM; 147 return -ENOMEM;
148 148
149 memcpy(buffer, data, size);
150
151 ret = usb_control_msg(xdev, usb_sndctrlpipe(xdev, 0), MCS7830_WR_BREQ, 149 ret = usb_control_msg(xdev, usb_sndctrlpipe(xdev, 0), MCS7830_WR_BREQ,
152 MCS7830_WR_BMREQ, 0x0000, index, buffer, 150 MCS7830_WR_BMREQ, 0x0000, index, buffer,
153 size, MCS7830_CTRL_TIMEOUT); 151 size, MCS7830_CTRL_TIMEOUT);
@@ -453,12 +451,12 @@ static void mcs7830_data_set_multicast(struct net_device *net)
453 * for our 8 byte filter buffer 451 * for our 8 byte filter buffer
454 * to avoid allocating memory that 452 * to avoid allocating memory that
455 * is tricky to free later */ 453 * is tricky to free later */
456 struct dev_mc_list *mc_list; 454 struct netdev_hw_addr *ha;
457 u32 crc_bits; 455 u32 crc_bits;
458 456
459 /* Build the multicast hash filter. */ 457 /* Build the multicast hash filter. */
460 netdev_for_each_mc_addr(mc_list, net) { 458 netdev_for_each_mc_addr(ha, net) {
461 crc_bits = ether_crc(ETH_ALEN, mc_list->dmi_addr) >> 26; 459 crc_bits = ether_crc(ETH_ALEN, ha->addr) >> 26;
462 data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7); 460 data->multi_filter[crc_bits >> 3] |= 1 << (crc_bits & 7);
463 } 461 }
464 } 462 }
diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index 41838773b568..974d17f0263e 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -203,13 +203,12 @@ static int set_registers(pegasus_t * pegasus, __u16 indx, __u16 size,
203 char *buffer; 203 char *buffer;
204 DECLARE_WAITQUEUE(wait, current); 204 DECLARE_WAITQUEUE(wait, current);
205 205
206 buffer = kmalloc(size, GFP_KERNEL); 206 buffer = kmemdup(data, size, GFP_KERNEL);
207 if (!buffer) { 207 if (!buffer) {
208 netif_warn(pegasus, drv, pegasus->net, 208 netif_warn(pegasus, drv, pegasus->net,
209 "out of memory in %s\n", __func__); 209 "out of memory in %s\n", __func__);
210 return -ENOMEM; 210 return -ENOMEM;
211 } 211 }
212 memcpy(buffer, data, size);
213 212
214 add_wait_queue(&pegasus->ctrl_wait, &wait); 213 add_wait_queue(&pegasus->ctrl_wait, &wait);
215 set_current_state(TASK_UNINTERRUPTIBLE); 214 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -255,13 +254,12 @@ static int set_register(pegasus_t * pegasus, __u16 indx, __u8 data)
255 char *tmp; 254 char *tmp;
256 DECLARE_WAITQUEUE(wait, current); 255 DECLARE_WAITQUEUE(wait, current);
257 256
258 tmp = kmalloc(1, GFP_KERNEL); 257 tmp = kmemdup(&data, 1, GFP_KERNEL);
259 if (!tmp) { 258 if (!tmp) {
260 netif_warn(pegasus, drv, pegasus->net, 259 netif_warn(pegasus, drv, pegasus->net,
261 "out of memory in %s\n", __func__); 260 "out of memory in %s\n", __func__);
262 return -ENOMEM; 261 return -ENOMEM;
263 } 262 }
264 memcpy(tmp, &data, 1);
265 add_wait_queue(&pegasus->ctrl_wait, &wait); 263 add_wait_queue(&pegasus->ctrl_wait, &wait);
266 set_current_state(TASK_UNINTERRUPTIBLE); 264 set_current_state(TASK_UNINTERRUPTIBLE);
267 while (pegasus->flags & ETH_REGS_CHANGED) 265 while (pegasus->flags & ETH_REGS_CHANGED)
@@ -808,7 +806,7 @@ static void write_bulk_callback(struct urb *urb)
808 break; 806 break;
809 } 807 }
810 808
811 net->trans_start = jiffies; 809 net->trans_start = jiffies; /* prevent tx timeout */
812 netif_wake_queue(net); 810 netif_wake_queue(net);
813} 811}
814 812
@@ -909,7 +907,6 @@ static netdev_tx_t pegasus_start_xmit(struct sk_buff *skb,
909 } else { 907 } else {
910 pegasus->stats.tx_packets++; 908 pegasus->stats.tx_packets++;
911 pegasus->stats.tx_bytes += skb->len; 909 pegasus->stats.tx_bytes += skb->len;
912 net->trans_start = jiffies;
913 } 910 }
914 dev_kfree_skb(skb); 911 dev_kfree_skb(skb);
915 912
diff --git a/drivers/net/usb/pegasus.h b/drivers/net/usb/pegasus.h
index b90d8766ab74..29f5211e645b 100644
--- a/drivers/net/usb/pegasus.h
+++ b/drivers/net/usb/pegasus.h
@@ -256,7 +256,7 @@ PEGASUS_DEV( "IO DATA USB ET/TX", VENDOR_IODATA, 0x0904,
256 DEFAULT_GPIO_RESET ) 256 DEFAULT_GPIO_RESET )
257PEGASUS_DEV( "IO DATA USB ET/TX-S", VENDOR_IODATA, 0x0913, 257PEGASUS_DEV( "IO DATA USB ET/TX-S", VENDOR_IODATA, 0x0913,
258 DEFAULT_GPIO_RESET | PEGASUS_II ) 258 DEFAULT_GPIO_RESET | PEGASUS_II )
259PEGASUS_DEV( "IO DATA USB ETX-US2", VENDOR_IODATA, 0x092a, 259PEGASUS_DEV( "IO DATA USB ETX-US2", VENDOR_IODATA, 0x093a,
260 DEFAULT_GPIO_RESET | PEGASUS_II ) 260 DEFAULT_GPIO_RESET | PEGASUS_II )
261PEGASUS_DEV( "Kingston KNU101TX Ethernet", VENDOR_KINGSTON, 0x000a, 261PEGASUS_DEV( "Kingston KNU101TX Ethernet", VENDOR_KINGSTON, 0x000a,
262 DEFAULT_GPIO_RESET) 262 DEFAULT_GPIO_RESET)
diff --git a/drivers/net/usb/rndis_host.c b/drivers/net/usb/rndis_host.c
index dd8a4adf48ca..28d3ee175e7b 100644
--- a/drivers/net/usb/rndis_host.c
+++ b/drivers/net/usb/rndis_host.c
@@ -104,8 +104,10 @@ static void rndis_msg_indicate(struct usbnet *dev, struct rndis_indicate *msg,
104int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen) 104int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
105{ 105{
106 struct cdc_state *info = (void *) &dev->data; 106 struct cdc_state *info = (void *) &dev->data;
107 struct usb_cdc_notification notification;
107 int master_ifnum; 108 int master_ifnum;
108 int retval; 109 int retval;
110 int partial;
109 unsigned count; 111 unsigned count;
110 __le32 rsp; 112 __le32 rsp;
111 u32 xid = 0, msg_len, request_id; 113 u32 xid = 0, msg_len, request_id;
@@ -133,13 +135,17 @@ int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen)
133 if (unlikely(retval < 0 || xid == 0)) 135 if (unlikely(retval < 0 || xid == 0))
134 return retval; 136 return retval;
135 137
136 // FIXME Seems like some devices discard responses when 138 /* Some devices don't respond on the control channel until
137 // we time out and cancel our "get response" requests... 139 * polled on the status channel, so do that first. */
138 // so, this is fragile. Probably need to poll for status. 140 retval = usb_interrupt_msg(
141 dev->udev,
142 usb_rcvintpipe(dev->udev, dev->status->desc.bEndpointAddress),
143 &notification, sizeof(notification), &partial,
144 RNDIS_CONTROL_TIMEOUT_MS);
145 if (unlikely(retval < 0))
146 return retval;
139 147
140 /* ignore status endpoint, just poll the control channel; 148 /* Poll the control channel; the request probably completed immediately */
141 * the request probably completed immediately
142 */
143 rsp = buf->msg_type | RNDIS_MSG_COMPLETION; 149 rsp = buf->msg_type | RNDIS_MSG_COMPLETION;
144 for (count = 0; count < 10; count++) { 150 for (count = 0; count < 10; count++) {
145 memset(buf, 0, CONTROL_BUFFER_SIZE); 151 memset(buf, 0, CONTROL_BUFFER_SIZE);
diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
new file mode 100644
index 000000000000..f1942d69a0d5
--- /dev/null
+++ b/drivers/net/usb/sierra_net.c
@@ -0,0 +1,1004 @@
1/*
2 * USB-to-WWAN Driver for Sierra Wireless modems
3 *
4 * Copyright (C) 2008, 2009, 2010 Paxton Smith, Matthew Safar, Rory Filer
5 * <linux@sierrawireless.com>
6 *
7 * Portions of this based on the cdc_ether driver by David Brownell (2003-2005)
8 * and Ole Andre Vadla Ravnas (ActiveSync) (2006).
9 *
10 * IMPORTANT DISCLAIMER: This driver is not commercially supported by
11 * Sierra Wireless. Use at your own risk.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 */
27
28#define DRIVER_VERSION "v.2.0"
29#define DRIVER_AUTHOR "Paxton Smith, Matthew Safar, Rory Filer"
30#define DRIVER_DESC "USB-to-WWAN Driver for Sierra Wireless modems"
31static const char driver_name[] = "sierra_net";
32
33/* if defined debug messages enabled */
34/*#define DEBUG*/
35
36#include <linux/module.h>
37#include <linux/etherdevice.h>
38#include <linux/ethtool.h>
39#include <linux/mii.h>
40#include <linux/sched.h>
41#include <linux/timer.h>
42#include <linux/usb.h>
43#include <linux/usb/cdc.h>
44#include <net/ip.h>
45#include <net/udp.h>
46#include <asm/unaligned.h>
47#include <linux/usb/usbnet.h>
48
49#define SWI_USB_REQUEST_GET_FW_ATTR 0x06
50#define SWI_GET_FW_ATTR_MASK 0x08
51
52/* atomic counter partially included in MAC address to make sure 2 devices
53 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
54 */
55static atomic_t iface_counter = ATOMIC_INIT(0);
56
57/*
58 * SYNC Timer Delay definition used to set the expiry time
59 */
60#define SIERRA_NET_SYNCDELAY (2*HZ)
61
62/* Max. MTU supported. The modem buffers are limited to 1500 */
63#define SIERRA_NET_MAX_SUPPORTED_MTU 1500
64
65/* The SIERRA_NET_USBCTL_BUF_LEN defines a buffer size allocated for control
66 * message reception ... and thus the max. received packet.
67 * (May be the cause for parse_hip returning -EINVAL)
68 */
69#define SIERRA_NET_USBCTL_BUF_LEN 1024
70
71/* list of interface numbers - used for constructing interface lists */
72struct sierra_net_iface_info {
73 const u32 infolen; /* number of interface numbers on list */
74 const u8 *ifaceinfo; /* pointer to the array holding the numbers */
75};
76
77struct sierra_net_info_data {
78 u16 rx_urb_size;
79 struct sierra_net_iface_info whitelist;
80};
81
82/* Private data structure */
83struct sierra_net_data {
84
85 u8 ethr_hdr_tmpl[ETH_HLEN]; /* ethernet header template for rx'd pkts */
86
87 u16 link_up; /* air link up or down */
88 u8 tx_hdr_template[4]; /* part of HIP hdr for tx'd packets */
89
90 u8 sync_msg[4]; /* SYNC message */
91 u8 shdwn_msg[4]; /* Shutdown message */
92
93 /* Backpointer to the container */
94 struct usbnet *usbnet;
95
96 u8 ifnum; /* interface number */
97
98/* Bit masks, must be a power of 2 */
99#define SIERRA_NET_EVENT_RESP_AVAIL 0x01
100#define SIERRA_NET_TIMER_EXPIRY 0x02
101 unsigned long kevent_flags;
102 struct work_struct sierra_net_kevent;
103 struct timer_list sync_timer; /* For retrying SYNC sequence */
104};
105
106struct param {
107 int is_present;
108 union {
109 void *ptr;
110 u32 dword;
111 u16 word;
112 u8 byte;
113 };
114};
115
116/* HIP message type */
117#define SIERRA_NET_HIP_EXTENDEDID 0x7F
118#define SIERRA_NET_HIP_HSYNC_ID 0x60 /* Modem -> host */
119#define SIERRA_NET_HIP_RESTART_ID 0x62 /* Modem -> host */
120#define SIERRA_NET_HIP_MSYNC_ID 0x20 /* Host -> modem */
121#define SIERRA_NET_HIP_SHUTD_ID 0x26 /* Host -> modem */
122
123#define SIERRA_NET_HIP_EXT_IP_IN_ID 0x0202
124#define SIERRA_NET_HIP_EXT_IP_OUT_ID 0x0002
125
126/* 3G UMTS Link Sense Indication definitions */
127#define SIERRA_NET_HIP_LSI_UMTSID 0x78
128
129/* Reverse Channel Grant Indication HIP message */
130#define SIERRA_NET_HIP_RCGI 0x64
131
132/* LSI Protocol types */
133#define SIERRA_NET_PROTOCOL_UMTS 0x01
134/* LSI Coverage */
135#define SIERRA_NET_COVERAGE_NONE 0x00
136#define SIERRA_NET_COVERAGE_NOPACKET 0x01
137
138/* LSI Session */
139#define SIERRA_NET_SESSION_IDLE 0x00
140/* LSI Link types */
141#define SIERRA_NET_AS_LINK_TYPE_IPv4 0x00
142
143struct lsi_umts {
144 u8 protocol;
145 u8 unused1;
146 __be16 length;
147 /* eventually use a union for the rest - assume umts for now */
148 u8 coverage;
149 u8 unused2[41];
150 u8 session_state;
151 u8 unused3[33];
152 u8 link_type;
153 u8 pdp_addr_len; /* NW-supplied PDP address len */
154 u8 pdp_addr[16]; /* NW-supplied PDP address (bigendian)) */
155 u8 unused4[23];
156 u8 dns1_addr_len; /* NW-supplied 1st DNS address len (bigendian) */
157 u8 dns1_addr[16]; /* NW-supplied 1st DNS address */
158 u8 dns2_addr_len; /* NW-supplied 2nd DNS address len */
159 u8 dns2_addr[16]; /* NW-supplied 2nd DNS address (bigendian)*/
160 u8 wins1_addr_len; /* NW-supplied 1st Wins address len */
161 u8 wins1_addr[16]; /* NW-supplied 1st Wins address (bigendian)*/
162 u8 wins2_addr_len; /* NW-supplied 2nd Wins address len */
163 u8 wins2_addr[16]; /* NW-supplied 2nd Wins address (bigendian) */
164 u8 unused5[4];
165 u8 gw_addr_len; /* NW-supplied GW address len */
166 u8 gw_addr[16]; /* NW-supplied GW address (bigendian) */
167 u8 reserved[8];
168} __attribute__ ((packed));
169
170#define SIERRA_NET_LSI_COMMON_LEN 4
171#define SIERRA_NET_LSI_UMTS_LEN (sizeof(struct lsi_umts))
172#define SIERRA_NET_LSI_UMTS_STATUS_LEN \
173 (SIERRA_NET_LSI_UMTS_LEN - SIERRA_NET_LSI_COMMON_LEN)
174
175/* Forward definitions */
176static void sierra_sync_timer(unsigned long syncdata);
177static int sierra_net_change_mtu(struct net_device *net, int new_mtu);
178
179/* Our own net device operations structure */
180static const struct net_device_ops sierra_net_device_ops = {
181 .ndo_open = usbnet_open,
182 .ndo_stop = usbnet_stop,
183 .ndo_start_xmit = usbnet_start_xmit,
184 .ndo_tx_timeout = usbnet_tx_timeout,
185 .ndo_change_mtu = sierra_net_change_mtu,
186 .ndo_set_mac_address = eth_mac_addr,
187 .ndo_validate_addr = eth_validate_addr,
188};
189
190/* get private data associated with passed in usbnet device */
191static inline struct sierra_net_data *sierra_net_get_private(struct usbnet *dev)
192{
193 return (struct sierra_net_data *)dev->data[0];
194}
195
196/* set private data associated with passed in usbnet device */
197static inline void sierra_net_set_private(struct usbnet *dev,
198 struct sierra_net_data *priv)
199{
200 dev->data[0] = (unsigned long)priv;
201}
202
203/* is packet IPv4 */
204static inline int is_ip(struct sk_buff *skb)
205{
206 return (skb->protocol == cpu_to_be16(ETH_P_IP));
207}
208
209/*
210 * check passed in packet and make sure that:
211 * - it is linear (no scatter/gather)
212 * - it is ethernet (mac_header properly set)
213 */
214static int check_ethip_packet(struct sk_buff *skb, struct usbnet *dev)
215{
216 skb_reset_mac_header(skb); /* ethernet header */
217
218 if (skb_is_nonlinear(skb)) {
219 netdev_err(dev->net, "Non linear buffer-dropping\n");
220 return 0;
221 }
222
223 if (!pskb_may_pull(skb, ETH_HLEN))
224 return 0;
225 skb->protocol = eth_hdr(skb)->h_proto;
226
227 return 1;
228}
229
230static const u8 *save16bit(struct param *p, const u8 *datap)
231{
232 p->is_present = 1;
233 p->word = get_unaligned_be16(datap);
234 return datap + sizeof(p->word);
235}
236
237static const u8 *save8bit(struct param *p, const u8 *datap)
238{
239 p->is_present = 1;
240 p->byte = *datap;
241 return datap + sizeof(p->byte);
242}
243
244/*----------------------------------------------------------------------------*
245 * BEGIN HIP *
246 *----------------------------------------------------------------------------*/
247/* HIP header */
248#define SIERRA_NET_HIP_HDR_LEN 4
249/* Extended HIP header */
250#define SIERRA_NET_HIP_EXT_HDR_LEN 6
251
252struct hip_hdr {
253 int hdrlen;
254 struct param payload_len;
255 struct param msgid;
256 struct param msgspecific;
257 struct param extmsgid;
258};
259
260static int parse_hip(const u8 *buf, const u32 buflen, struct hip_hdr *hh)
261{
262 const u8 *curp = buf;
263 int padded;
264
265 if (buflen < SIERRA_NET_HIP_HDR_LEN)
266 return -EPROTO;
267
268 curp = save16bit(&hh->payload_len, curp);
269 curp = save8bit(&hh->msgid, curp);
270 curp = save8bit(&hh->msgspecific, curp);
271
272 padded = hh->msgid.byte & 0x80;
273 hh->msgid.byte &= 0x7F; /* 7 bits */
274
275 hh->extmsgid.is_present = (hh->msgid.byte == SIERRA_NET_HIP_EXTENDEDID);
276 if (hh->extmsgid.is_present) {
277 if (buflen < SIERRA_NET_HIP_EXT_HDR_LEN)
278 return -EPROTO;
279
280 hh->payload_len.word &= 0x3FFF; /* 14 bits */
281
282 curp = save16bit(&hh->extmsgid, curp);
283 hh->extmsgid.word &= 0x03FF; /* 10 bits */
284
285 hh->hdrlen = SIERRA_NET_HIP_EXT_HDR_LEN;
286 } else {
287 hh->payload_len.word &= 0x07FF; /* 11 bits */
288 hh->hdrlen = SIERRA_NET_HIP_HDR_LEN;
289 }
290
291 if (padded) {
292 hh->hdrlen++;
293 hh->payload_len.word--;
294 }
295
296 /* if real packet shorter than the claimed length */
297 if (buflen < (hh->hdrlen + hh->payload_len.word))
298 return -EINVAL;
299
300 return 0;
301}
302
303static void build_hip(u8 *buf, const u16 payloadlen,
304 struct sierra_net_data *priv)
305{
306 /* the following doesn't have the full functionality. We
307 * currently build only one kind of header, so it is faster this way
308 */
309 put_unaligned_be16(payloadlen, buf);
310 memcpy(buf+2, priv->tx_hdr_template, sizeof(priv->tx_hdr_template));
311}
312/*----------------------------------------------------------------------------*
313 * END HIP *
314 *----------------------------------------------------------------------------*/
315
316static int sierra_net_send_cmd(struct usbnet *dev,
317 u8 *cmd, int cmdlen, const char * cmd_name)
318{
319 struct sierra_net_data *priv = sierra_net_get_private(dev);
320 int status;
321
322 status = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0),
323 USB_CDC_SEND_ENCAPSULATED_COMMAND,
324 USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE, 0,
325 priv->ifnum, cmd, cmdlen, USB_CTRL_SET_TIMEOUT);
326
327 if (status != cmdlen && status != -ENODEV)
328 netdev_err(dev->net, "Submit %s failed %d\n", cmd_name, status);
329
330 return status;
331}
332
333static int sierra_net_send_sync(struct usbnet *dev)
334{
335 int status;
336 struct sierra_net_data *priv = sierra_net_get_private(dev);
337
338 dev_dbg(&dev->udev->dev, "%s", __func__);
339
340 status = sierra_net_send_cmd(dev, priv->sync_msg,
341 sizeof(priv->sync_msg), "SYNC");
342
343 return status;
344}
345
346static void sierra_net_set_ctx_index(struct sierra_net_data *priv, u8 ctx_ix)
347{
348 dev_dbg(&(priv->usbnet->udev->dev), "%s %d", __func__, ctx_ix);
349 priv->tx_hdr_template[0] = 0x3F;
350 priv->tx_hdr_template[1] = ctx_ix;
351 *((u16 *)&priv->tx_hdr_template[2]) =
352 cpu_to_be16(SIERRA_NET_HIP_EXT_IP_OUT_ID);
353}
354
355static inline int sierra_net_is_valid_addrlen(u8 len)
356{
357 return (len == sizeof(struct in_addr));
358}
359
360static int sierra_net_parse_lsi(struct usbnet *dev, char *data, int datalen)
361{
362 struct lsi_umts *lsi = (struct lsi_umts *)data;
363
364 if (datalen < sizeof(struct lsi_umts)) {
365 netdev_err(dev->net, "%s: Data length %d, exp %Zu\n",
366 __func__, datalen,
367 sizeof(struct lsi_umts));
368 return -1;
369 }
370
371 if (lsi->length != cpu_to_be16(SIERRA_NET_LSI_UMTS_STATUS_LEN)) {
372 netdev_err(dev->net, "%s: LSI_UMTS_STATUS_LEN %d, exp %u\n",
373 __func__, be16_to_cpu(lsi->length),
374 (u32)SIERRA_NET_LSI_UMTS_STATUS_LEN);
375 return -1;
376 }
377
378 /* Validate the protocol - only support UMTS for now */
379 if (lsi->protocol != SIERRA_NET_PROTOCOL_UMTS) {
380 netdev_err(dev->net, "Protocol unsupported, 0x%02x\n",
381 lsi->protocol);
382 return -1;
383 }
384
385 /* Validate the link type */
386 if (lsi->link_type != SIERRA_NET_AS_LINK_TYPE_IPv4) {
387 netdev_err(dev->net, "Link type unsupported: 0x%02x\n",
388 lsi->link_type);
389 return -1;
390 }
391
392 /* Validate the coverage */
393 if (lsi->coverage == SIERRA_NET_COVERAGE_NONE
394 || lsi->coverage == SIERRA_NET_COVERAGE_NOPACKET) {
395 netdev_err(dev->net, "No coverage, 0x%02x\n", lsi->coverage);
396 return 0;
397 }
398
399 /* Validate the session state */
400 if (lsi->session_state == SIERRA_NET_SESSION_IDLE) {
401 netdev_err(dev->net, "Session idle, 0x%02x\n",
402 lsi->session_state);
403 return 0;
404 }
405
406 /* Set link_sense true */
407 return 1;
408}
409
410static void sierra_net_handle_lsi(struct usbnet *dev, char *data,
411 struct hip_hdr *hh)
412{
413 struct sierra_net_data *priv = sierra_net_get_private(dev);
414 int link_up;
415
416 link_up = sierra_net_parse_lsi(dev, data + hh->hdrlen,
417 hh->payload_len.word);
418 if (link_up < 0) {
419 netdev_err(dev->net, "Invalid LSI\n");
420 return;
421 }
422 if (link_up) {
423 sierra_net_set_ctx_index(priv, hh->msgspecific.byte);
424 priv->link_up = 1;
425 netif_carrier_on(dev->net);
426 } else {
427 priv->link_up = 0;
428 netif_carrier_off(dev->net);
429 }
430}
431
432static void sierra_net_dosync(struct usbnet *dev)
433{
434 int status;
435 struct sierra_net_data *priv = sierra_net_get_private(dev);
436
437 dev_dbg(&dev->udev->dev, "%s", __func__);
438
439 /* tell modem we are ready */
440 status = sierra_net_send_sync(dev);
441 if (status < 0)
442 netdev_err(dev->net,
443 "Send SYNC failed, status %d\n", status);
444 status = sierra_net_send_sync(dev);
445 if (status < 0)
446 netdev_err(dev->net,
447 "Send SYNC failed, status %d\n", status);
448
449 /* Now, start a timer and make sure we get the Restart Indication */
450 priv->sync_timer.function = sierra_sync_timer;
451 priv->sync_timer.data = (unsigned long) dev;
452 priv->sync_timer.expires = jiffies + SIERRA_NET_SYNCDELAY;
453 add_timer(&priv->sync_timer);
454}
455
456static void sierra_net_kevent(struct work_struct *work)
457{
458 struct sierra_net_data *priv =
459 container_of(work, struct sierra_net_data, sierra_net_kevent);
460 struct usbnet *dev = priv->usbnet;
461 int len;
462 int err;
463 u8 *buf;
464 u8 ifnum;
465
466 if (test_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags)) {
467 clear_bit(SIERRA_NET_EVENT_RESP_AVAIL, &priv->kevent_flags);
468
469 /* Query the modem for the LSI message */
470 buf = kzalloc(SIERRA_NET_USBCTL_BUF_LEN, GFP_KERNEL);
471 if (!buf) {
472 netdev_err(dev->net,
473 "failed to allocate buf for LS msg\n");
474 return;
475 }
476 ifnum = priv->ifnum;
477 len = usb_control_msg(dev->udev, usb_rcvctrlpipe(dev->udev, 0),
478 USB_CDC_GET_ENCAPSULATED_RESPONSE,
479 USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE,
480 0, ifnum, buf, SIERRA_NET_USBCTL_BUF_LEN,
481 USB_CTRL_SET_TIMEOUT);
482
483 if (len < 0) {
484 netdev_err(dev->net,
485 "usb_control_msg failed, status %d\n", len);
486 } else {
487 struct hip_hdr hh;
488
489 dev_dbg(&dev->udev->dev, "%s: Received status message,"
490 " %04x bytes", __func__, len);
491
492 err = parse_hip(buf, len, &hh);
493 if (err) {
494 netdev_err(dev->net, "%s: Bad packet,"
495 " parse result %d\n", __func__, err);
496 kfree(buf);
497 return;
498 }
499
500 /* Validate packet length */
501 if (len != hh.hdrlen + hh.payload_len.word) {
502 netdev_err(dev->net, "%s: Bad packet, received"
503 " %d, expected %d\n", __func__, len,
504 hh.hdrlen + hh.payload_len.word);
505 kfree(buf);
506 return;
507 }
508
509 /* Switch on received message types */
510 switch (hh.msgid.byte) {
511 case SIERRA_NET_HIP_LSI_UMTSID:
512 dev_dbg(&dev->udev->dev, "LSI for ctx:%d",
513 hh.msgspecific.byte);
514 sierra_net_handle_lsi(dev, buf, &hh);
515 break;
516 case SIERRA_NET_HIP_RESTART_ID:
517 dev_dbg(&dev->udev->dev, "Restart reported: %d,"
518 " stopping sync timer",
519 hh.msgspecific.byte);
520 /* Got sync resp - stop timer & clear mask */
521 del_timer_sync(&priv->sync_timer);
522 clear_bit(SIERRA_NET_TIMER_EXPIRY,
523 &priv->kevent_flags);
524 break;
525 case SIERRA_NET_HIP_HSYNC_ID:
526 dev_dbg(&dev->udev->dev, "SYNC received");
527 err = sierra_net_send_sync(dev);
528 if (err < 0)
529 netdev_err(dev->net,
530 "Send SYNC failed %d\n", err);
531 break;
532 case SIERRA_NET_HIP_EXTENDEDID:
533 netdev_err(dev->net, "Unrecognized HIP msg, "
534 "extmsgid 0x%04x\n", hh.extmsgid.word);
535 break;
536 case SIERRA_NET_HIP_RCGI:
537 /* Ignored */
538 break;
539 default:
540 netdev_err(dev->net, "Unrecognized HIP msg, "
541 "msgid 0x%02x\n", hh.msgid.byte);
542 break;
543 }
544 }
545 kfree(buf);
546 }
547 /* The sync timer bit might be set */
548 if (test_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags)) {
549 clear_bit(SIERRA_NET_TIMER_EXPIRY, &priv->kevent_flags);
550 dev_dbg(&dev->udev->dev, "Deferred sync timer expiry");
551 sierra_net_dosync(priv->usbnet);
552 }
553
554 if (priv->kevent_flags)
555 dev_dbg(&dev->udev->dev, "sierra_net_kevent done, "
556 "kevent_flags = 0x%lx", priv->kevent_flags);
557}
558
559static void sierra_net_defer_kevent(struct usbnet *dev, int work)
560{
561 struct sierra_net_data *priv = sierra_net_get_private(dev);
562
563 set_bit(work, &priv->kevent_flags);
564 schedule_work(&priv->sierra_net_kevent);
565}
566
567/*
568 * Sync Retransmit Timer Handler. On expiry, kick the work queue
569 */
570void sierra_sync_timer(unsigned long syncdata)
571{
572 struct usbnet *dev = (struct usbnet *)syncdata;
573
574 dev_dbg(&dev->udev->dev, "%s", __func__);
575 /* Kick the tasklet */
576 sierra_net_defer_kevent(dev, SIERRA_NET_TIMER_EXPIRY);
577}
578
579static void sierra_net_status(struct usbnet *dev, struct urb *urb)
580{
581 struct usb_cdc_notification *event;
582
583 dev_dbg(&dev->udev->dev, "%s", __func__);
584
585 if (urb->actual_length < sizeof *event)
586 return;
587
588 /* Add cases to handle other standard notifications. */
589 event = urb->transfer_buffer;
590 switch (event->bNotificationType) {
591 case USB_CDC_NOTIFY_NETWORK_CONNECTION:
592 case USB_CDC_NOTIFY_SPEED_CHANGE:
593 /* USB 305 sends those */
594 break;
595 case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
596 sierra_net_defer_kevent(dev, SIERRA_NET_EVENT_RESP_AVAIL);
597 break;
598 default:
599 netdev_err(dev->net, ": unexpected notification %02x!\n",
600 event->bNotificationType);
601 break;
602 }
603}
604
605static void sierra_net_get_drvinfo(struct net_device *net,
606 struct ethtool_drvinfo *info)
607{
608 /* Inherit standard device info */
609 usbnet_get_drvinfo(net, info);
610 strncpy(info->driver, driver_name, sizeof info->driver);
611 strncpy(info->version, DRIVER_VERSION, sizeof info->version);
612}
613
614static u32 sierra_net_get_link(struct net_device *net)
615{
616 struct usbnet *dev = netdev_priv(net);
617 /* Report link is down whenever the interface is down */
618 return sierra_net_get_private(dev)->link_up && netif_running(net);
619}
620
621static struct ethtool_ops sierra_net_ethtool_ops = {
622 .get_drvinfo = sierra_net_get_drvinfo,
623 .get_link = sierra_net_get_link,
624 .get_msglevel = usbnet_get_msglevel,
625 .set_msglevel = usbnet_set_msglevel,
626 .get_settings = usbnet_get_settings,
627 .set_settings = usbnet_set_settings,
628 .nway_reset = usbnet_nway_reset,
629};
630
631/* MTU can not be more than 1500 bytes, enforce it. */
632static int sierra_net_change_mtu(struct net_device *net, int new_mtu)
633{
634 if (new_mtu > SIERRA_NET_MAX_SUPPORTED_MTU)
635 return -EINVAL;
636
637 return usbnet_change_mtu(net, new_mtu);
638}
639
640static int is_whitelisted(const u8 ifnum,
641 const struct sierra_net_iface_info *whitelist)
642{
643 if (whitelist) {
644 const u8 *list = whitelist->ifaceinfo;
645 int i;
646
647 for (i = 0; i < whitelist->infolen; i++) {
648 if (list[i] == ifnum)
649 return 1;
650 }
651 }
652 return 0;
653}
654
655static int sierra_net_get_fw_attr(struct usbnet *dev, u16 *datap)
656{
657 int result = 0;
658 u16 *attrdata;
659
660 attrdata = kmalloc(sizeof(*attrdata), GFP_KERNEL);
661 if (!attrdata)
662 return -ENOMEM;
663
664 result = usb_control_msg(
665 dev->udev,
666 usb_rcvctrlpipe(dev->udev, 0),
667 /* _u8 vendor specific request */
668 SWI_USB_REQUEST_GET_FW_ATTR,
669 USB_DIR_IN | USB_TYPE_VENDOR, /* __u8 request type */
670 0x0000, /* __u16 value not used */
671 0x0000, /* __u16 index not used */
672 attrdata, /* char *data */
673 sizeof(*attrdata), /* __u16 size */
674 USB_CTRL_SET_TIMEOUT); /* int timeout */
675
676 if (result < 0) {
677 kfree(attrdata);
678 return -EIO;
679 }
680
681 *datap = *attrdata;
682
683 kfree(attrdata);
684 return result;
685}
686
687/*
688 * collects the bulk endpoints, the status endpoint.
689 */
690static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
691{
692 u8 ifacenum;
693 u8 numendpoints;
694 u16 fwattr = 0;
695 int status;
696 struct ethhdr *eth;
697 struct sierra_net_data *priv;
698 static const u8 sync_tmplate[sizeof(priv->sync_msg)] = {
699 0x00, 0x00, SIERRA_NET_HIP_MSYNC_ID, 0x00};
700 static const u8 shdwn_tmplate[sizeof(priv->shdwn_msg)] = {
701 0x00, 0x00, SIERRA_NET_HIP_SHUTD_ID, 0x00};
702
703 struct sierra_net_info_data *data =
704 (struct sierra_net_info_data *)dev->driver_info->data;
705
706 dev_dbg(&dev->udev->dev, "%s", __func__);
707
708 ifacenum = intf->cur_altsetting->desc.bInterfaceNumber;
709 /* We only accept certain interfaces */
710 if (!is_whitelisted(ifacenum, &data->whitelist)) {
711 dev_dbg(&dev->udev->dev, "Ignoring interface: %d", ifacenum);
712 return -ENODEV;
713 }
714 numendpoints = intf->cur_altsetting->desc.bNumEndpoints;
715 /* We have three endpoints, bulk in and out, and a status */
716 if (numendpoints != 3) {
717 dev_err(&dev->udev->dev, "Expected 3 endpoints, found: %d",
718 numendpoints);
719 return -ENODEV;
720 }
721 /* Status endpoint set in usbnet_get_endpoints() */
722 dev->status = NULL;
723 status = usbnet_get_endpoints(dev, intf);
724 if (status < 0) {
725 dev_err(&dev->udev->dev, "Error in usbnet_get_endpoints (%d)",
726 status);
727 return -ENODEV;
728 }
729 /* Initialize sierra private data */
730 priv = kzalloc(sizeof *priv, GFP_KERNEL);
731 if (!priv) {
732 dev_err(&dev->udev->dev, "No memory");
733 return -ENOMEM;
734 }
735
736 priv->usbnet = dev;
737 priv->ifnum = ifacenum;
738 dev->net->netdev_ops = &sierra_net_device_ops;
739
740 /* change MAC addr to include, ifacenum, and to be unique */
741 dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
742 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
743
744 /* we will have to manufacture ethernet headers, prepare template */
745 eth = (struct ethhdr *)priv->ethr_hdr_tmpl;
746 memcpy(&eth->h_dest, dev->net->dev_addr, ETH_ALEN);
747 eth->h_proto = cpu_to_be16(ETH_P_IP);
748
749 /* prepare shutdown message template */
750 memcpy(priv->shdwn_msg, shdwn_tmplate, sizeof(priv->shdwn_msg));
751 /* set context index initially to 0 - prepares tx hdr template */
752 sierra_net_set_ctx_index(priv, 0);
753
754 /* decrease the rx_urb_size and max_tx_size to 4k on USB 1.1 */
755 dev->rx_urb_size = data->rx_urb_size;
756 if (dev->udev->speed != USB_SPEED_HIGH)
757 dev->rx_urb_size = min_t(size_t, 4096, data->rx_urb_size);
758
759 dev->net->hard_header_len += SIERRA_NET_HIP_EXT_HDR_LEN;
760 dev->hard_mtu = dev->net->mtu + dev->net->hard_header_len;
761
762 /* Set up the netdev */
763 dev->net->flags |= IFF_NOARP;
764 dev->net->ethtool_ops = &sierra_net_ethtool_ops;
765 netif_carrier_off(dev->net);
766
767 sierra_net_set_private(dev, priv);
768
769 priv->kevent_flags = 0;
770
771 /* Use the shared workqueue */
772 INIT_WORK(&priv->sierra_net_kevent, sierra_net_kevent);
773
774 /* Only need to do this once */
775 init_timer(&priv->sync_timer);
776
777 /* verify fw attributes */
778 status = sierra_net_get_fw_attr(dev, &fwattr);
779 dev_dbg(&dev->udev->dev, "Fw attr: %x\n", fwattr);
780
781 /* test whether firmware supports DHCP */
782 if (!(status == sizeof(fwattr) && (fwattr & SWI_GET_FW_ATTR_MASK))) {
783 /* found incompatible firmware version */
784 dev_err(&dev->udev->dev, "Incompatible driver and firmware"
785 " versions\n");
786 kfree(priv);
787 return -ENODEV;
788 }
789 /* prepare sync message from template */
790 memcpy(priv->sync_msg, sync_tmplate, sizeof(priv->sync_msg));
791
792 /* initiate the sync sequence */
793 sierra_net_dosync(dev);
794
795 return 0;
796}
797
798static void sierra_net_unbind(struct usbnet *dev, struct usb_interface *intf)
799{
800 int status;
801 struct sierra_net_data *priv = sierra_net_get_private(dev);
802
803 dev_dbg(&dev->udev->dev, "%s", __func__);
804
805 /* Kill the timer then flush the work queue */
806 del_timer_sync(&priv->sync_timer);
807
808 flush_scheduled_work();
809
810 /* tell modem we are going away */
811 status = sierra_net_send_cmd(dev, priv->shdwn_msg,
812 sizeof(priv->shdwn_msg), "Shutdown");
813 if (status < 0)
814 netdev_err(dev->net,
815 "usb_control_msg failed, status %d\n", status);
816
817 sierra_net_set_private(dev, NULL);
818
819 kfree(priv);
820}
821
822static struct sk_buff *sierra_net_skb_clone(struct usbnet *dev,
823 struct sk_buff *skb, int len)
824{
825 struct sk_buff *new_skb;
826
827 /* clone skb */
828 new_skb = skb_clone(skb, GFP_ATOMIC);
829
830 /* remove len bytes from original */
831 skb_pull(skb, len);
832
833 /* trim next packet to it's length */
834 if (new_skb) {
835 skb_trim(new_skb, len);
836 } else {
837 if (netif_msg_rx_err(dev))
838 netdev_err(dev->net, "failed to get skb\n");
839 dev->net->stats.rx_dropped++;
840 }
841
842 return new_skb;
843}
844
845/* ---------------------------- Receive data path ----------------------*/
846static int sierra_net_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
847{
848 int err;
849 struct hip_hdr hh;
850 struct sk_buff *new_skb;
851
852 dev_dbg(&dev->udev->dev, "%s", __func__);
853
854 /* could contain multiple packets */
855 while (likely(skb->len)) {
856 err = parse_hip(skb->data, skb->len, &hh);
857 if (err) {
858 if (netif_msg_rx_err(dev))
859 netdev_err(dev->net, "Invalid HIP header %d\n",
860 err);
861 /* dev->net->stats.rx_errors incremented by caller */
862 dev->net->stats.rx_length_errors++;
863 return 0;
864 }
865
866 /* Validate Extended HIP header */
867 if (!hh.extmsgid.is_present
868 || hh.extmsgid.word != SIERRA_NET_HIP_EXT_IP_IN_ID) {
869 if (netif_msg_rx_err(dev))
870 netdev_err(dev->net, "HIP/ETH: Invalid pkt\n");
871
872 dev->net->stats.rx_frame_errors++;
873 /* dev->net->stats.rx_errors incremented by caller */;
874 return 0;
875 }
876
877 skb_pull(skb, hh.hdrlen);
878
879 /* We are going to accept this packet, prepare it */
880 memcpy(skb->data, sierra_net_get_private(dev)->ethr_hdr_tmpl,
881 ETH_HLEN);
882
883 /* Last packet in batch handled by usbnet */
884 if (hh.payload_len.word == skb->len)
885 return 1;
886
887 new_skb = sierra_net_skb_clone(dev, skb, hh.payload_len.word);
888 if (new_skb)
889 usbnet_skb_return(dev, new_skb);
890
891 } /* while */
892
893 return 0;
894}
895
896/* ---------------------------- Transmit data path ----------------------*/
897struct sk_buff *sierra_net_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
898 gfp_t flags)
899{
900 struct sierra_net_data *priv = sierra_net_get_private(dev);
901 u16 len;
902 bool need_tail;
903
904 dev_dbg(&dev->udev->dev, "%s", __func__);
905 if (priv->link_up && check_ethip_packet(skb, dev) && is_ip(skb)) {
906 /* enough head room as is? */
907 if (SIERRA_NET_HIP_EXT_HDR_LEN <= skb_headroom(skb)) {
908 /* Save the Eth/IP length and set up HIP hdr */
909 len = skb->len;
910 skb_push(skb, SIERRA_NET_HIP_EXT_HDR_LEN);
911 /* Handle ZLP issue */
912 need_tail = ((len + SIERRA_NET_HIP_EXT_HDR_LEN)
913 % dev->maxpacket == 0);
914 if (need_tail) {
915 if (unlikely(skb_tailroom(skb) == 0)) {
916 netdev_err(dev->net, "tx_fixup:"
917 "no room for packet\n");
918 dev_kfree_skb_any(skb);
919 return NULL;
920 } else {
921 skb->data[skb->len] = 0;
922 __skb_put(skb, 1);
923 len = len + 1;
924 }
925 }
926 build_hip(skb->data, len, priv);
927 return skb;
928 } else {
929 /*
930 * compensate in the future if necessary
931 */
932 netdev_err(dev->net, "tx_fixup: no room for HIP\n");
933 } /* headroom */
934 }
935
936 if (!priv->link_up)
937 dev->net->stats.tx_carrier_errors++;
938
939 /* tx_dropped incremented by usbnet */
940
941 /* filter the packet out, release it */
942 dev_kfree_skb_any(skb);
943 return NULL;
944}
945
946static const u8 sierra_net_ifnum_list[] = { 7, 10, 11 };
947static const struct sierra_net_info_data sierra_net_info_data_68A3 = {
948 .rx_urb_size = 8 * 1024,
949 .whitelist = {
950 .infolen = ARRAY_SIZE(sierra_net_ifnum_list),
951 .ifaceinfo = sierra_net_ifnum_list
952 }
953};
954
955static const struct driver_info sierra_net_info_68A3 = {
956 .description = "Sierra Wireless USB-to-WWAN Modem",
957 .flags = FLAG_WWAN | FLAG_SEND_ZLP,
958 .bind = sierra_net_bind,
959 .unbind = sierra_net_unbind,
960 .status = sierra_net_status,
961 .rx_fixup = sierra_net_rx_fixup,
962 .tx_fixup = sierra_net_tx_fixup,
963 .data = (unsigned long)&sierra_net_info_data_68A3,
964};
965
966static const struct usb_device_id products[] = {
967 {USB_DEVICE(0x1199, 0x68A3), /* Sierra Wireless USB-to-WWAN modem */
968 .driver_info = (unsigned long) &sierra_net_info_68A3},
969
970 {}, /* last item */
971};
972MODULE_DEVICE_TABLE(usb, products);
973
974/* We are based on usbnet, so let it handle the USB driver specifics */
975static struct usb_driver sierra_net_driver = {
976 .name = "sierra_net",
977 .id_table = products,
978 .probe = usbnet_probe,
979 .disconnect = usbnet_disconnect,
980 .suspend = usbnet_suspend,
981 .resume = usbnet_resume,
982 .no_dynamic_id = 1,
983};
984
985static int __init sierra_net_init(void)
986{
987 BUILD_BUG_ON(FIELD_SIZEOF(struct usbnet, data)
988 < sizeof(struct cdc_state));
989
990 return usb_register(&sierra_net_driver);
991}
992
993static void __exit sierra_net_exit(void)
994{
995 usb_deregister(&sierra_net_driver);
996}
997
998module_exit(sierra_net_exit);
999module_init(sierra_net_init);
1000
1001MODULE_AUTHOR(DRIVER_AUTHOR);
1002MODULE_DESCRIPTION(DRIVER_DESC);
1003MODULE_VERSION(DRIVER_VERSION);
1004MODULE_LICENSE("GPL");
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 35b98b1b79e4..753ee6eb7edd 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -445,14 +445,14 @@ static void smsc75xx_set_multicast(struct net_device *netdev)
445 netif_dbg(dev, drv, dev->net, "receive all multicast enabled"); 445 netif_dbg(dev, drv, dev->net, "receive all multicast enabled");
446 pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF; 446 pdata->rfe_ctl |= RFE_CTL_AM | RFE_CTL_DPF;
447 } else if (!netdev_mc_empty(dev->net)) { 447 } else if (!netdev_mc_empty(dev->net)) {
448 struct dev_mc_list *mc_list; 448 struct netdev_hw_addr *ha;
449 449
450 netif_dbg(dev, drv, dev->net, "receive multicast hash filter"); 450 netif_dbg(dev, drv, dev->net, "receive multicast hash filter");
451 451
452 pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF; 452 pdata->rfe_ctl |= RFE_CTL_MHF | RFE_CTL_DPF;
453 453
454 netdev_for_each_mc_addr(mc_list, netdev) { 454 netdev_for_each_mc_addr(ha, netdev) {
455 u32 bitnum = smsc75xx_hash(mc_list->dmi_addr); 455 u32 bitnum = smsc75xx_hash(ha->addr);
456 pdata->multicast_hash_table[bitnum / 32] |= 456 pdata->multicast_hash_table[bitnum / 32] |=
457 (1 << (bitnum % 32)); 457 (1 << (bitnum % 32));
458 } 458 }
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index 3135af63d378..12a3c88c5282 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -385,13 +385,13 @@ static void smsc95xx_set_multicast(struct net_device *netdev)
385 pdata->mac_cr |= MAC_CR_MCPAS_; 385 pdata->mac_cr |= MAC_CR_MCPAS_;
386 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_); 386 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_HPFILT_);
387 } else if (!netdev_mc_empty(dev->net)) { 387 } else if (!netdev_mc_empty(dev->net)) {
388 struct dev_mc_list *mc_list; 388 struct netdev_hw_addr *ha;
389 389
390 pdata->mac_cr |= MAC_CR_HPFILT_; 390 pdata->mac_cr |= MAC_CR_HPFILT_;
391 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_); 391 pdata->mac_cr &= ~(MAC_CR_PRMS_ | MAC_CR_MCPAS_);
392 392
393 netdev_for_each_mc_addr(mc_list, netdev) { 393 netdev_for_each_mc_addr(ha, netdev) {
394 u32 bitnum = smsc95xx_hash(mc_list->dmi_addr); 394 u32 bitnum = smsc95xx_hash(ha->addr);
395 u32 mask = 0x01 << (bitnum & 0x1F); 395 u32 mask = 0x01 << (bitnum & 0x1F);
396 if (bitnum & 0x20) 396 if (bitnum & 0x20)
397 hash_hi |= mask; 397 hash_hi |= mask;
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 7177abc78dc6..a95c73de5824 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1069,12 +1069,15 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
1069 * NOTE: strictly conforming cdc-ether devices should expect 1069 * NOTE: strictly conforming cdc-ether devices should expect
1070 * the ZLP here, but ignore the one-byte packet. 1070 * the ZLP here, but ignore the one-byte packet.
1071 */ 1071 */
1072 if (!(info->flags & FLAG_SEND_ZLP) && (length % dev->maxpacket) == 0) { 1072 if (length % dev->maxpacket == 0) {
1073 urb->transfer_buffer_length++; 1073 if (!(info->flags & FLAG_SEND_ZLP)) {
1074 if (skb_tailroom(skb)) { 1074 urb->transfer_buffer_length++;
1075 skb->data[skb->len] = 0; 1075 if (skb_tailroom(skb)) {
1076 __skb_put(skb, 1); 1076 skb->data[skb->len] = 0;
1077 } 1077 __skb_put(skb, 1);
1078 }
1079 } else
1080 urb->transfer_flags |= URB_ZERO_PACKET;
1078 } 1081 }
1079 1082
1080 spin_lock_irqsave(&dev->txq.lock, flags); 1083 spin_lock_irqsave(&dev->txq.lock, flags);