aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/usb
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 00:04:47 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-03-21 00:04:47 -0400
commit3b59bf081622b6446db77ad06c93fe23677bc533 (patch)
tree3f4bb5a27c90cc86994a1f6d3c53fbf9208003cb /drivers/net/usb
parente45836fafe157df137a837093037f741ad8f4c90 (diff)
parentbbdb32cb5b73597386913d052165423b9d736145 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next
Pull networking merge from David Miller: "1) Move ixgbe driver over to purely page based buffering on receive. From Alexander Duyck. 2) Add receive packet steering support to e1000e, from Bruce Allan. 3) Convert TCP MD5 support over to RCU, from Eric Dumazet. 4) Reduce cpu usage in handling out-of-order TCP packets on modern systems, also from Eric Dumazet. 5) Support the IP{,V6}_UNICAST_IF socket options, making the wine folks happy, from Erich Hoover. 6) Support VLAN trunking from guests in hyperv driver, from Haiyang Zhang. 7) Support byte-queue-limtis in r8169, from Igor Maravic. 8) Outline code intended for IP_RECVTOS in IP_PKTOPTIONS existed but was never properly implemented, Jiri Benc fixed that. 9) 64-bit statistics support in r8169 and 8139too, from Junchang Wang. 10) Support kernel side dump filtering by ctmark in netfilter ctnetlink, from Pablo Neira Ayuso. 11) Support byte-queue-limits in gianfar driver, from Paul Gortmaker. 12) Add new peek socket options to assist with socket migration, from Pavel Emelyanov. 13) Add sch_plug packet scheduler whose queue is controlled by userland daemons using explicit freeze and release commands. From Shriram Rajagopalan. 14) Fix FCOE checksum offload handling on transmit, from Yi Zou." * git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next: (1846 commits) Fix pppol2tp getsockname() Remove printk from rds_sendmsg ipv6: fix incorrent ipv6 ipsec packet fragment cpsw: Hook up default ndo_change_mtu. net: qmi_wwan: fix build error due to cdc-wdm dependecy netdev: driver: ethernet: Add TI CPSW driver netdev: driver: ethernet: add cpsw address lookup engine support phy: add am79c874 PHY support mlx4_core: fix race on comm channel bonding: send igmp report for its master fs_enet: Add MPC5125 FEC support and PHY interface selection net: bpf_jit: fix BPF_S_LDX_B_MSH compilation net: update the usage of CHECKSUM_UNNECESSARY fcoe: use CHECKSUM_UNNECESSARY instead of CHECKSUM_PARTIAL on tx net: do not do gso for CHECKSUM_UNNECESSARY in netif_needs_gso ixgbe: Fix issues with SR-IOV loopback when flow control is disabled net/hyperv: Fix the code handling tx busy ixgbe: fix namespace issues when FCoE/DCB is not enabled rtlwifi: Remove unused ETH_ADDR_LEN defines igbvf: Use ETH_ALEN ... Fix up fairly trivial conflicts in drivers/isdn/gigaset/interface.c and drivers/net/usb/{Kconfig,qmi_wwan.c} as per David.
Diffstat (limited to 'drivers/net/usb')
-rw-r--r--drivers/net/usb/Kconfig1
-rw-r--r--drivers/net/usb/asix.c88
-rw-r--r--drivers/net/usb/cdc_ncm.c236
-rw-r--r--drivers/net/usb/kaweth.c8
-rw-r--r--drivers/net/usb/mcs7830.c2
-rw-r--r--drivers/net/usb/pegasus.c4
-rw-r--r--drivers/net/usb/rtl8150.c4
-rw-r--r--drivers/net/usb/smsc75xx.c2
-rw-r--r--drivers/net/usb/smsc95xx.c2
-rw-r--r--drivers/net/usb/usbnet.c6
10 files changed, 144 insertions, 209 deletions
diff --git a/drivers/net/usb/Kconfig b/drivers/net/usb/Kconfig
index 4bad899fb38f..833e32f8d63b 100644
--- a/drivers/net/usb/Kconfig
+++ b/drivers/net/usb/Kconfig
@@ -401,6 +401,7 @@ config USB_NET_KALMIA
401config USB_NET_QMI_WWAN 401config USB_NET_QMI_WWAN
402 tristate "QMI WWAN driver for Qualcomm MSM based 3G and LTE modems" 402 tristate "QMI WWAN driver for Qualcomm MSM based 3G and LTE modems"
403 depends on USB_USBNET 403 depends on USB_USBNET
404 select USB_WDM
404 help 405 help
405 Support WWAN LTE/3G devices based on Qualcomm Mobile Data Modem 406 Support WWAN LTE/3G devices based on Qualcomm Mobile Data Modem
406 (MDM) chipsets. Examples of such devices are 407 (MDM) chipsets. Examples of such devices are
diff --git a/drivers/net/usb/asix.c b/drivers/net/usb/asix.c
index d6da5eed5453..5ee032cafade 100644
--- a/drivers/net/usb/asix.c
+++ b/drivers/net/usb/asix.c
@@ -305,88 +305,40 @@ asix_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
305 305
306static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb) 306static int asix_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
307{ 307{
308 u8 *head; 308 int offset = 0;
309 u32 header;
310 char *packet;
311 struct sk_buff *ax_skb;
312 u16 size;
313 309
314 head = (u8 *) skb->data; 310 while (offset + sizeof(u32) < skb->len) {
315 memcpy(&header, head, sizeof(header)); 311 struct sk_buff *ax_skb;
316 le32_to_cpus(&header); 312 u16 size;
317 packet = head + sizeof(header); 313 u32 header = get_unaligned_le32(skb->data + offset);
318 314
319 skb_pull(skb, 4); 315 offset += sizeof(u32);
320
321 while (skb->len > 0) {
322 if ((header & 0x07ff) != ((~header >> 16) & 0x07ff))
323 netdev_err(dev->net, "asix_rx_fixup() Bad Header Length\n");
324 316
325 /* get the packet length */ 317 /* get the packet length */
326 size = (u16) (header & 0x000007ff); 318 size = (u16) (header & 0x7ff);
327 319 if (size != ((~header >> 16) & 0x07ff)) {
328 if ((skb->len) - ((size + 1) & 0xfffe) == 0) { 320 netdev_err(dev->net, "asix_rx_fixup() Bad Header Length\n");
329 u8 alignment = (unsigned long)skb->data & 0x3; 321 return 0;
330 if (alignment != 0x2) {
331 /*
332 * not 16bit aligned so use the room provided by
333 * the 32 bit header to align the data
334 *
335 * note we want 16bit alignment as MAC header is
336 * 14bytes thus ip header will be aligned on
337 * 32bit boundary so accessing ipheader elements
338 * using a cast to struct ip header wont cause
339 * an unaligned accesses.
340 */
341 u8 realignment = (alignment + 2) & 0x3;
342 memmove(skb->data - realignment,
343 skb->data,
344 size);
345 skb->data -= realignment;
346 skb_set_tail_pointer(skb, size);
347 }
348 return 2;
349 } 322 }
350 323
351 if (size > dev->net->mtu + ETH_HLEN) { 324 if ((size > dev->net->mtu + ETH_HLEN) ||
325 (size + offset > skb->len)) {
352 netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n", 326 netdev_err(dev->net, "asix_rx_fixup() Bad RX Length %d\n",
353 size); 327 size);
354 return 0; 328 return 0;
355 } 329 }
356 ax_skb = skb_clone(skb, GFP_ATOMIC); 330 ax_skb = netdev_alloc_skb_ip_align(dev->net, size);
357 if (ax_skb) { 331 if (!ax_skb)
358 u8 alignment = (unsigned long)packet & 0x3;
359 ax_skb->len = size;
360
361 if (alignment != 0x2) {
362 /*
363 * not 16bit aligned use the room provided by
364 * the 32 bit header to align the data
365 */
366 u8 realignment = (alignment + 2) & 0x3;
367 memmove(packet - realignment, packet, size);
368 packet -= realignment;
369 }
370 ax_skb->data = packet;
371 skb_set_tail_pointer(ax_skb, size);
372 usbnet_skb_return(dev, ax_skb);
373 } else {
374 return 0; 332 return 0;
375 }
376
377 skb_pull(skb, (size + 1) & 0xfffe);
378 333
379 if (skb->len < sizeof(header)) 334 skb_put(ax_skb, size);
380 break; 335 memcpy(ax_skb->data, skb->data + offset, size);
336 usbnet_skb_return(dev, ax_skb);
381 337
382 head = (u8 *) skb->data; 338 offset += (size + 1) & 0xfffe;
383 memcpy(&header, head, sizeof(header));
384 le32_to_cpus(&header);
385 packet = head + sizeof(header);
386 skb_pull(skb, 4);
387 } 339 }
388 340
389 if (skb->len < 0) { 341 if (skb->len != offset) {
390 netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d\n", 342 netdev_err(dev->net, "asix_rx_fixup() Bad SKB Length %d\n",
391 skb->len); 343 skb->len);
392 return 0; 344 return 0;
@@ -1541,7 +1493,7 @@ static const struct driver_info ax88772_info = {
1541 .status = asix_status, 1493 .status = asix_status,
1542 .link_reset = ax88772_link_reset, 1494 .link_reset = ax88772_link_reset,
1543 .reset = ax88772_reset, 1495 .reset = ax88772_reset,
1544 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR, 1496 .flags = FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET,
1545 .rx_fixup = asix_rx_fixup, 1497 .rx_fixup = asix_rx_fixup,
1546 .tx_fixup = asix_tx_fixup, 1498 .tx_fixup = asix_tx_fixup,
1547}; 1499};
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 3a539a9cac54..7adc9f6b0ea1 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * cdc_ncm.c 2 * cdc_ncm.c
3 * 3 *
4 * Copyright (C) ST-Ericsson 2010-2011 4 * Copyright (C) ST-Ericsson 2010-2012
5 * Contact: Alexey Orishko <alexey.orishko@stericsson.com> 5 * Contact: Alexey Orishko <alexey.orishko@stericsson.com>
6 * Original author: Hans Petter Selasky <hans.petter.selasky@stericsson.com> 6 * Original author: Hans Petter Selasky <hans.petter.selasky@stericsson.com>
7 * 7 *
@@ -47,20 +47,19 @@
47#include <linux/mii.h> 47#include <linux/mii.h>
48#include <linux/crc32.h> 48#include <linux/crc32.h>
49#include <linux/usb.h> 49#include <linux/usb.h>
50#include <linux/timer.h> 50#include <linux/hrtimer.h>
51#include <linux/spinlock.h>
52#include <linux/atomic.h> 51#include <linux/atomic.h>
53#include <linux/usb/usbnet.h> 52#include <linux/usb/usbnet.h>
54#include <linux/usb/cdc.h> 53#include <linux/usb/cdc.h>
55 54
56#define DRIVER_VERSION "04-Aug-2011" 55#define DRIVER_VERSION "14-Mar-2012"
57 56
58/* CDC NCM subclass 3.2.1 */ 57/* CDC NCM subclass 3.2.1 */
59#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10 58#define USB_CDC_NCM_NDP16_LENGTH_MIN 0x10
60 59
61/* Maximum NTB length */ 60/* Maximum NTB length */
62#define CDC_NCM_NTB_MAX_SIZE_TX 16384 /* bytes */ 61#define CDC_NCM_NTB_MAX_SIZE_TX 32768 /* bytes */
63#define CDC_NCM_NTB_MAX_SIZE_RX 16384 /* bytes */ 62#define CDC_NCM_NTB_MAX_SIZE_RX 32768 /* bytes */
64 63
65/* Minimum value for MaxDatagramSize, ch. 6.2.9 */ 64/* Minimum value for MaxDatagramSize, ch. 6.2.9 */
66#define CDC_NCM_MIN_DATAGRAM_SIZE 1514 /* bytes */ 65#define CDC_NCM_MIN_DATAGRAM_SIZE 1514 /* bytes */
@@ -68,19 +67,18 @@
68#define CDC_NCM_MIN_TX_PKT 512 /* bytes */ 67#define CDC_NCM_MIN_TX_PKT 512 /* bytes */
69 68
70/* Default value for MaxDatagramSize */ 69/* Default value for MaxDatagramSize */
71#define CDC_NCM_MAX_DATAGRAM_SIZE 2048 /* bytes */ 70#define CDC_NCM_MAX_DATAGRAM_SIZE 8192 /* bytes */
72 71
73/* 72/*
74 * Maximum amount of datagrams in NCM Datagram Pointer Table, not counting 73 * Maximum amount of datagrams in NCM Datagram Pointer Table, not counting
75 * the last NULL entry. Any additional datagrams in NTB would be discarded. 74 * the last NULL entry.
76 */ 75 */
77#define CDC_NCM_DPT_DATAGRAMS_MAX 32 76#define CDC_NCM_DPT_DATAGRAMS_MAX 40
78
79/* Maximum amount of IN datagrams in NTB */
80#define CDC_NCM_DPT_DATAGRAMS_IN_MAX 0 /* unlimited */
81 77
82/* Restart the timer, if amount of datagrams is less than given value */ 78/* Restart the timer, if amount of datagrams is less than given value */
83#define CDC_NCM_RESTART_TIMER_DATAGRAM_CNT 3 79#define CDC_NCM_RESTART_TIMER_DATAGRAM_CNT 3
80#define CDC_NCM_TIMER_PENDING_CNT 2
81#define CDC_NCM_TIMER_INTERVAL (400UL * NSEC_PER_USEC)
84 82
85/* The following macro defines the minimum header space */ 83/* The following macro defines the minimum header space */
86#define CDC_NCM_MIN_HDR_SIZE \ 84#define CDC_NCM_MIN_HDR_SIZE \
@@ -94,10 +92,10 @@ struct cdc_ncm_data {
94}; 92};
95 93
96struct cdc_ncm_ctx { 94struct cdc_ncm_ctx {
97 struct cdc_ncm_data rx_ncm;
98 struct cdc_ncm_data tx_ncm; 95 struct cdc_ncm_data tx_ncm;
99 struct usb_cdc_ncm_ntb_parameters ncm_parm; 96 struct usb_cdc_ncm_ntb_parameters ncm_parm;
100 struct timer_list tx_timer; 97 struct hrtimer tx_timer;
98 struct tasklet_struct bh;
101 99
102 const struct usb_cdc_ncm_desc *func_desc; 100 const struct usb_cdc_ncm_desc *func_desc;
103 const struct usb_cdc_header_desc *header_desc; 101 const struct usb_cdc_header_desc *header_desc;
@@ -117,6 +115,7 @@ struct cdc_ncm_ctx {
117 struct sk_buff *tx_rem_skb; 115 struct sk_buff *tx_rem_skb;
118 116
119 spinlock_t mtx; 117 spinlock_t mtx;
118 atomic_t stop;
120 119
121 u32 tx_timer_pending; 120 u32 tx_timer_pending;
122 u32 tx_curr_offset; 121 u32 tx_curr_offset;
@@ -132,10 +131,13 @@ struct cdc_ncm_ctx {
132 u16 tx_modulus; 131 u16 tx_modulus;
133 u16 tx_ndp_modulus; 132 u16 tx_ndp_modulus;
134 u16 tx_seq; 133 u16 tx_seq;
134 u16 rx_seq;
135 u16 connected; 135 u16 connected;
136}; 136};
137 137
138static void cdc_ncm_tx_timeout(unsigned long arg); 138static void cdc_ncm_txpath_bh(unsigned long param);
139static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx);
140static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *hr_timer);
139static const struct driver_info cdc_ncm_info; 141static const struct driver_info cdc_ncm_info;
140static struct usb_driver cdc_ncm_driver; 142static struct usb_driver cdc_ncm_driver;
141static const struct ethtool_ops cdc_ncm_ethtool_ops; 143static const struct ethtool_ops cdc_ncm_ethtool_ops;
@@ -361,27 +363,25 @@ size_err:
361 if (err < 0) { 363 if (err < 0) {
362 pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n", 364 pr_debug("GET_MAX_DATAGRAM_SIZE failed, use size=%u\n",
363 CDC_NCM_MIN_DATAGRAM_SIZE); 365 CDC_NCM_MIN_DATAGRAM_SIZE);
364 kfree(max_datagram_size);
365 } else { 366 } else {
366 ctx->max_datagram_size = 367 ctx->max_datagram_size =
367 le16_to_cpu(*max_datagram_size); 368 le16_to_cpu(*max_datagram_size);
368 /* Check Eth descriptor value */ 369 /* Check Eth descriptor value */
369 if (eth_max_sz < CDC_NCM_MAX_DATAGRAM_SIZE) { 370 if (ctx->max_datagram_size > eth_max_sz)
370 if (ctx->max_datagram_size > eth_max_sz)
371 ctx->max_datagram_size = eth_max_sz; 371 ctx->max_datagram_size = eth_max_sz;
372 } else { 372
373 if (ctx->max_datagram_size > 373 if (ctx->max_datagram_size > CDC_NCM_MAX_DATAGRAM_SIZE)
374 CDC_NCM_MAX_DATAGRAM_SIZE) 374 ctx->max_datagram_size =
375 ctx->max_datagram_size =
376 CDC_NCM_MAX_DATAGRAM_SIZE; 375 CDC_NCM_MAX_DATAGRAM_SIZE;
377 }
378 376
379 if (ctx->max_datagram_size < CDC_NCM_MIN_DATAGRAM_SIZE) 377 if (ctx->max_datagram_size < CDC_NCM_MIN_DATAGRAM_SIZE)
380 ctx->max_datagram_size = 378 ctx->max_datagram_size =
381 CDC_NCM_MIN_DATAGRAM_SIZE; 379 CDC_NCM_MIN_DATAGRAM_SIZE;
382 380
383 /* if value changed, update device */ 381 /* if value changed, update device */
384 err = usb_control_msg(ctx->udev, 382 if (ctx->max_datagram_size !=
383 le16_to_cpu(*max_datagram_size)) {
384 err = usb_control_msg(ctx->udev,
385 usb_sndctrlpipe(ctx->udev, 0), 385 usb_sndctrlpipe(ctx->udev, 0),
386 USB_CDC_SET_MAX_DATAGRAM_SIZE, 386 USB_CDC_SET_MAX_DATAGRAM_SIZE,
387 USB_TYPE_CLASS | USB_DIR_OUT 387 USB_TYPE_CLASS | USB_DIR_OUT
@@ -389,14 +389,14 @@ size_err:
389 0, 389 0,
390 iface_no, max_datagram_size, 390 iface_no, max_datagram_size,
391 2, 1000); 391 2, 1000);
392 kfree(max_datagram_size); 392 if (err < 0)
393max_dgram_err: 393 pr_debug("SET_MAX_DGRAM_SIZE failed\n");
394 if (err < 0) 394 }
395 pr_debug("SET_MAX_DATAGRAM_SIZE failed\n");
396 } 395 }
397 396 kfree(max_datagram_size);
398 } 397 }
399 398
399max_dgram_err:
400 if (ctx->netdev->mtu != (ctx->max_datagram_size - ETH_HLEN)) 400 if (ctx->netdev->mtu != (ctx->max_datagram_size - ETH_HLEN))
401 ctx->netdev->mtu = ctx->max_datagram_size - ETH_HLEN; 401 ctx->netdev->mtu = ctx->max_datagram_size - ETH_HLEN;
402 402
@@ -441,8 +441,6 @@ static void cdc_ncm_free(struct cdc_ncm_ctx *ctx)
441 if (ctx == NULL) 441 if (ctx == NULL)
442 return; 442 return;
443 443
444 del_timer_sync(&ctx->tx_timer);
445
446 if (ctx->tx_rem_skb != NULL) { 444 if (ctx->tx_rem_skb != NULL) {
447 dev_kfree_skb_any(ctx->tx_rem_skb); 445 dev_kfree_skb_any(ctx->tx_rem_skb);
448 ctx->tx_rem_skb = NULL; 446 ctx->tx_rem_skb = NULL;
@@ -469,7 +467,11 @@ static int cdc_ncm_bind(struct usbnet *dev, struct usb_interface *intf)
469 if (ctx == NULL) 467 if (ctx == NULL)
470 return -ENODEV; 468 return -ENODEV;
471 469
472 init_timer(&ctx->tx_timer); 470 hrtimer_init(&ctx->tx_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
471 ctx->tx_timer.function = &cdc_ncm_tx_timer_cb;
472 ctx->bh.data = (unsigned long)ctx;
473 ctx->bh.func = cdc_ncm_txpath_bh;
474 atomic_set(&ctx->stop, 0);
473 spin_lock_init(&ctx->mtx); 475 spin_lock_init(&ctx->mtx);
474 ctx->netdev = dev->net; 476 ctx->netdev = dev->net;
475 477
@@ -579,11 +581,7 @@ advance:
579 if (temp) 581 if (temp)
580 goto error2; 582 goto error2;
581 583
582 dev_info(&dev->udev->dev, "MAC-Address: " 584 dev_info(&dev->udev->dev, "MAC-Address: %pM\n", dev->net->dev_addr);
583 "0x%02x:0x%02x:0x%02x:0x%02x:0x%02x:0x%02x\n",
584 dev->net->dev_addr[0], dev->net->dev_addr[1],
585 dev->net->dev_addr[2], dev->net->dev_addr[3],
586 dev->net->dev_addr[4], dev->net->dev_addr[5]);
587 585
588 dev->in = usb_rcvbulkpipe(dev->udev, 586 dev->in = usb_rcvbulkpipe(dev->udev,
589 ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 587 ctx->in_ep->desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK);
@@ -621,6 +619,13 @@ static void cdc_ncm_unbind(struct usbnet *dev, struct usb_interface *intf)
621 if (ctx == NULL) 619 if (ctx == NULL)
622 return; /* no setup */ 620 return; /* no setup */
623 621
622 atomic_set(&ctx->stop, 1);
623
624 if (hrtimer_active(&ctx->tx_timer))
625 hrtimer_cancel(&ctx->tx_timer);
626
627 tasklet_kill(&ctx->bh);
628
624 /* disconnect master --> disconnect slave */ 629 /* disconnect master --> disconnect slave */
625 if (intf == ctx->control && ctx->data) { 630 if (intf == ctx->control && ctx->data) {
626 usb_set_intfdata(ctx->data, NULL); 631 usb_set_intfdata(ctx->data, NULL);
@@ -791,7 +796,7 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
791 ctx->tx_curr_last_offset = last_offset; 796 ctx->tx_curr_last_offset = last_offset;
792 /* set the pending count */ 797 /* set the pending count */
793 if (n < CDC_NCM_RESTART_TIMER_DATAGRAM_CNT) 798 if (n < CDC_NCM_RESTART_TIMER_DATAGRAM_CNT)
794 ctx->tx_timer_pending = 2; 799 ctx->tx_timer_pending = CDC_NCM_TIMER_PENDING_CNT;
795 goto exit_no_skb; 800 goto exit_no_skb;
796 801
797 } else { 802 } else {
@@ -871,44 +876,49 @@ cdc_ncm_fill_tx_frame(struct cdc_ncm_ctx *ctx, struct sk_buff *skb)
871 876
872 /* return skb */ 877 /* return skb */
873 ctx->tx_curr_skb = NULL; 878 ctx->tx_curr_skb = NULL;
879 ctx->netdev->stats.tx_packets += ctx->tx_curr_frame_num;
874 return skb_out; 880 return skb_out;
875 881
876exit_no_skb: 882exit_no_skb:
883 /* Start timer, if there is a remaining skb */
884 if (ctx->tx_curr_skb != NULL)
885 cdc_ncm_tx_timeout_start(ctx);
877 return NULL; 886 return NULL;
878} 887}
879 888
880static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx) 889static void cdc_ncm_tx_timeout_start(struct cdc_ncm_ctx *ctx)
881{ 890{
882 /* start timer, if not already started */ 891 /* start timer, if not already started */
883 if (timer_pending(&ctx->tx_timer) == 0) { 892 if (!(hrtimer_active(&ctx->tx_timer) || atomic_read(&ctx->stop)))
884 ctx->tx_timer.function = &cdc_ncm_tx_timeout; 893 hrtimer_start(&ctx->tx_timer,
885 ctx->tx_timer.data = (unsigned long)ctx; 894 ktime_set(0, CDC_NCM_TIMER_INTERVAL),
886 ctx->tx_timer.expires = jiffies + ((HZ + 999) / 1000); 895 HRTIMER_MODE_REL);
887 add_timer(&ctx->tx_timer);
888 }
889} 896}
890 897
891static void cdc_ncm_tx_timeout(unsigned long arg) 898static enum hrtimer_restart cdc_ncm_tx_timer_cb(struct hrtimer *timer)
892{ 899{
893 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)arg; 900 struct cdc_ncm_ctx *ctx =
894 u8 restart; 901 container_of(timer, struct cdc_ncm_ctx, tx_timer);
895 902
896 spin_lock(&ctx->mtx); 903 if (!atomic_read(&ctx->stop))
897 if (ctx->tx_timer_pending != 0) { 904 tasklet_schedule(&ctx->bh);
898 ctx->tx_timer_pending--; 905 return HRTIMER_NORESTART;
899 restart = 1; 906}
900 } else {
901 restart = 0;
902 }
903 907
904 spin_unlock(&ctx->mtx); 908static void cdc_ncm_txpath_bh(unsigned long param)
909{
910 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)param;
905 911
906 if (restart) { 912 spin_lock_bh(&ctx->mtx);
907 spin_lock(&ctx->mtx); 913 if (ctx->tx_timer_pending != 0) {
914 ctx->tx_timer_pending--;
908 cdc_ncm_tx_timeout_start(ctx); 915 cdc_ncm_tx_timeout_start(ctx);
909 spin_unlock(&ctx->mtx); 916 spin_unlock_bh(&ctx->mtx);
910 } else if (ctx->netdev != NULL) { 917 } else if (ctx->netdev != NULL) {
918 spin_unlock_bh(&ctx->mtx);
919 netif_tx_lock_bh(ctx->netdev);
911 usbnet_start_xmit(NULL, ctx->netdev); 920 usbnet_start_xmit(NULL, ctx->netdev);
921 netif_tx_unlock_bh(ctx->netdev);
912 } 922 }
913} 923}
914 924
@@ -917,7 +927,6 @@ cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
917{ 927{
918 struct sk_buff *skb_out; 928 struct sk_buff *skb_out;
919 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0]; 929 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
920 u8 need_timer = 0;
921 930
922 /* 931 /*
923 * The Ethernet API we are using does not support transmitting 932 * The Ethernet API we are using does not support transmitting
@@ -929,19 +938,9 @@ cdc_ncm_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
929 if (ctx == NULL) 938 if (ctx == NULL)
930 goto error; 939 goto error;
931 940
932 spin_lock(&ctx->mtx); 941 spin_lock_bh(&ctx->mtx);
933 skb_out = cdc_ncm_fill_tx_frame(ctx, skb); 942 skb_out = cdc_ncm_fill_tx_frame(ctx, skb);
934 if (ctx->tx_curr_skb != NULL) 943 spin_unlock_bh(&ctx->mtx);
935 need_timer = 1;
936
937 /* Start timer, if there is a remaining skb */
938 if (need_timer)
939 cdc_ncm_tx_timeout_start(ctx);
940
941 if (skb_out)
942 dev->net->stats.tx_packets += ctx->tx_curr_frame_num;
943
944 spin_unlock(&ctx->mtx);
945 return skb_out; 944 return skb_out;
946 945
947error: 946error:
@@ -954,108 +953,103 @@ error:
954static int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in) 953static int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
955{ 954{
956 struct sk_buff *skb; 955 struct sk_buff *skb;
957 struct cdc_ncm_ctx *ctx; 956 struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
958 int sumlen; 957 int len;
959 int actlen;
960 int temp;
961 int nframes; 958 int nframes;
962 int x; 959 int x;
963 int offset; 960 int offset;
961 struct usb_cdc_ncm_nth16 *nth16;
962 struct usb_cdc_ncm_ndp16 *ndp16;
963 struct usb_cdc_ncm_dpe16 *dpe16;
964 964
965 ctx = (struct cdc_ncm_ctx *)dev->data[0];
966 if (ctx == NULL) 965 if (ctx == NULL)
967 goto error; 966 goto error;
968 967
969 actlen = skb_in->len; 968 if (skb_in->len < (sizeof(struct usb_cdc_ncm_nth16) +
970 sumlen = CDC_NCM_NTB_MAX_SIZE_RX; 969 sizeof(struct usb_cdc_ncm_ndp16))) {
971
972 if (actlen < (sizeof(ctx->rx_ncm.nth16) + sizeof(ctx->rx_ncm.ndp16))) {
973 pr_debug("frame too short\n"); 970 pr_debug("frame too short\n");
974 goto error; 971 goto error;
975 } 972 }
976 973
977 memcpy(&(ctx->rx_ncm.nth16), ((u8 *)skb_in->data), 974 nth16 = (struct usb_cdc_ncm_nth16 *)skb_in->data;
978 sizeof(ctx->rx_ncm.nth16));
979 975
980 if (le32_to_cpu(ctx->rx_ncm.nth16.dwSignature) != 976 if (le32_to_cpu(nth16->dwSignature) != USB_CDC_NCM_NTH16_SIGN) {
981 USB_CDC_NCM_NTH16_SIGN) {
982 pr_debug("invalid NTH16 signature <%u>\n", 977 pr_debug("invalid NTH16 signature <%u>\n",
983 le32_to_cpu(ctx->rx_ncm.nth16.dwSignature)); 978 le32_to_cpu(nth16->dwSignature));
984 goto error; 979 goto error;
985 } 980 }
986 981
987 temp = le16_to_cpu(ctx->rx_ncm.nth16.wBlockLength); 982 len = le16_to_cpu(nth16->wBlockLength);
988 if (temp > sumlen) { 983 if (len > ctx->rx_max) {
989 pr_debug("unsupported NTB block length %u/%u\n", temp, sumlen); 984 pr_debug("unsupported NTB block length %u/%u\n", len,
985 ctx->rx_max);
990 goto error; 986 goto error;
991 } 987 }
992 988
993 temp = le16_to_cpu(ctx->rx_ncm.nth16.wNdpIndex); 989 if ((ctx->rx_seq + 1) != le16_to_cpu(nth16->wSequence) &&
994 if ((temp + sizeof(ctx->rx_ncm.ndp16)) > actlen) { 990 (ctx->rx_seq || le16_to_cpu(nth16->wSequence)) &&
995 pr_debug("invalid DPT16 index\n"); 991 !((ctx->rx_seq == 0xffff) && !le16_to_cpu(nth16->wSequence))) {
992 pr_debug("sequence number glitch prev=%d curr=%d\n",
993 ctx->rx_seq, le16_to_cpu(nth16->wSequence));
994 }
995 ctx->rx_seq = le16_to_cpu(nth16->wSequence);
996
997 len = le16_to_cpu(nth16->wNdpIndex);
998 if ((len + sizeof(struct usb_cdc_ncm_ndp16)) > skb_in->len) {
999 pr_debug("invalid DPT16 index <%u>\n",
1000 le16_to_cpu(nth16->wNdpIndex));
996 goto error; 1001 goto error;
997 } 1002 }
998 1003
999 memcpy(&(ctx->rx_ncm.ndp16), ((u8 *)skb_in->data) + temp, 1004 ndp16 = (struct usb_cdc_ncm_ndp16 *)(((u8 *)skb_in->data) + len);
1000 sizeof(ctx->rx_ncm.ndp16));
1001 1005
1002 if (le32_to_cpu(ctx->rx_ncm.ndp16.dwSignature) != 1006 if (le32_to_cpu(ndp16->dwSignature) != USB_CDC_NCM_NDP16_NOCRC_SIGN) {
1003 USB_CDC_NCM_NDP16_NOCRC_SIGN) {
1004 pr_debug("invalid DPT16 signature <%u>\n", 1007 pr_debug("invalid DPT16 signature <%u>\n",
1005 le32_to_cpu(ctx->rx_ncm.ndp16.dwSignature)); 1008 le32_to_cpu(ndp16->dwSignature));
1006 goto error; 1009 goto error;
1007 } 1010 }
1008 1011
1009 if (le16_to_cpu(ctx->rx_ncm.ndp16.wLength) < 1012 if (le16_to_cpu(ndp16->wLength) < USB_CDC_NCM_NDP16_LENGTH_MIN) {
1010 USB_CDC_NCM_NDP16_LENGTH_MIN) {
1011 pr_debug("invalid DPT16 length <%u>\n", 1013 pr_debug("invalid DPT16 length <%u>\n",
1012 le32_to_cpu(ctx->rx_ncm.ndp16.dwSignature)); 1014 le32_to_cpu(ndp16->dwSignature));
1013 goto error; 1015 goto error;
1014 } 1016 }
1015 1017
1016 nframes = ((le16_to_cpu(ctx->rx_ncm.ndp16.wLength) - 1018 nframes = ((le16_to_cpu(ndp16->wLength) -
1017 sizeof(struct usb_cdc_ncm_ndp16)) / 1019 sizeof(struct usb_cdc_ncm_ndp16)) /
1018 sizeof(struct usb_cdc_ncm_dpe16)); 1020 sizeof(struct usb_cdc_ncm_dpe16));
1019 nframes--; /* we process NDP entries except for the last one */ 1021 nframes--; /* we process NDP entries except for the last one */
1020 1022
1021 pr_debug("nframes = %u\n", nframes); 1023 len += sizeof(struct usb_cdc_ncm_ndp16);
1022
1023 temp += sizeof(ctx->rx_ncm.ndp16);
1024 1024
1025 if ((temp + nframes * (sizeof(struct usb_cdc_ncm_dpe16))) > actlen) { 1025 if ((len + nframes * (sizeof(struct usb_cdc_ncm_dpe16))) >
1026 skb_in->len) {
1026 pr_debug("Invalid nframes = %d\n", nframes); 1027 pr_debug("Invalid nframes = %d\n", nframes);
1027 goto error; 1028 goto error;
1028 } 1029 }
1029 1030
1030 if (nframes > CDC_NCM_DPT_DATAGRAMS_MAX) { 1031 dpe16 = (struct usb_cdc_ncm_dpe16 *)(((u8 *)skb_in->data) + len);
1031 pr_debug("Truncating number of frames from %u to %u\n",
1032 nframes, CDC_NCM_DPT_DATAGRAMS_MAX);
1033 nframes = CDC_NCM_DPT_DATAGRAMS_MAX;
1034 }
1035
1036 memcpy(&(ctx->rx_ncm.dpe16), ((u8 *)skb_in->data) + temp,
1037 nframes * (sizeof(struct usb_cdc_ncm_dpe16)));
1038 1032
1039 for (x = 0; x < nframes; x++) { 1033 for (x = 0; x < nframes; x++, dpe16++) {
1040 offset = le16_to_cpu(ctx->rx_ncm.dpe16[x].wDatagramIndex); 1034 offset = le16_to_cpu(dpe16->wDatagramIndex);
1041 temp = le16_to_cpu(ctx->rx_ncm.dpe16[x].wDatagramLength); 1035 len = le16_to_cpu(dpe16->wDatagramLength);
1042 1036
1043 /* 1037 /*
1044 * CDC NCM ch. 3.7 1038 * CDC NCM ch. 3.7
1045 * All entries after first NULL entry are to be ignored 1039 * All entries after first NULL entry are to be ignored
1046 */ 1040 */
1047 if ((offset == 0) || (temp == 0)) { 1041 if ((offset == 0) || (len == 0)) {
1048 if (!x) 1042 if (!x)
1049 goto error; /* empty NTB */ 1043 goto error; /* empty NTB */
1050 break; 1044 break;
1051 } 1045 }
1052 1046
1053 /* sanity checking */ 1047 /* sanity checking */
1054 if (((offset + temp) > actlen) || 1048 if (((offset + len) > skb_in->len) ||
1055 (temp > CDC_NCM_MAX_DATAGRAM_SIZE) || (temp < ETH_HLEN)) { 1049 (len > ctx->rx_max) || (len < ETH_HLEN)) {
1056 pr_debug("invalid frame detected (ignored)" 1050 pr_debug("invalid frame detected (ignored)"
1057 "offset[%u]=%u, length=%u, skb=%p\n", 1051 "offset[%u]=%u, length=%u, skb=%p\n",
1058 x, offset, temp, skb_in); 1052 x, offset, len, skb_in);
1059 if (!x) 1053 if (!x)
1060 goto error; 1054 goto error;
1061 break; 1055 break;
@@ -1064,9 +1058,9 @@ static int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
1064 skb = skb_clone(skb_in, GFP_ATOMIC); 1058 skb = skb_clone(skb_in, GFP_ATOMIC);
1065 if (!skb) 1059 if (!skb)
1066 goto error; 1060 goto error;
1067 skb->len = temp; 1061 skb->len = len;
1068 skb->data = ((u8 *)skb_in->data) + offset; 1062 skb->data = ((u8 *)skb_in->data) + offset;
1069 skb_set_tail_pointer(skb, temp); 1063 skb_set_tail_pointer(skb, len);
1070 usbnet_skb_return(dev, skb); 1064 usbnet_skb_return(dev, skb);
1071 } 1065 }
1072 } 1066 }
diff --git a/drivers/net/usb/kaweth.c b/drivers/net/usb/kaweth.c
index d034d9c42548..df2a2cf35a99 100644
--- a/drivers/net/usb/kaweth.c
+++ b/drivers/net/usb/kaweth.c
@@ -1098,13 +1098,7 @@ err_fw:
1098 dev_info(&intf->dev, "Statistics collection: %x\n", kaweth->configuration.statistics_mask); 1098 dev_info(&intf->dev, "Statistics collection: %x\n", kaweth->configuration.statistics_mask);
1099 dev_info(&intf->dev, "Multicast filter limit: %x\n", kaweth->configuration.max_multicast_filters & ((1 << 15) - 1)); 1099 dev_info(&intf->dev, "Multicast filter limit: %x\n", kaweth->configuration.max_multicast_filters & ((1 << 15) - 1));
1100 dev_info(&intf->dev, "MTU: %d\n", le16_to_cpu(kaweth->configuration.segment_size)); 1100 dev_info(&intf->dev, "MTU: %d\n", le16_to_cpu(kaweth->configuration.segment_size));
1101 dev_info(&intf->dev, "Read MAC address %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", 1101 dev_info(&intf->dev, "Read MAC address %pM\n", kaweth->configuration.hw_addr);
1102 (int)kaweth->configuration.hw_addr[0],
1103 (int)kaweth->configuration.hw_addr[1],
1104 (int)kaweth->configuration.hw_addr[2],
1105 (int)kaweth->configuration.hw_addr[3],
1106 (int)kaweth->configuration.hw_addr[4],
1107 (int)kaweth->configuration.hw_addr[5]);
1108 1102
1109 if(!memcmp(&kaweth->configuration.hw_addr, 1103 if(!memcmp(&kaweth->configuration.hw_addr,
1110 &bcast_addr, 1104 &bcast_addr,
diff --git a/drivers/net/usb/mcs7830.c b/drivers/net/usb/mcs7830.c
index a29aa9cf9f6e..c434b6ba0337 100644
--- a/drivers/net/usb/mcs7830.c
+++ b/drivers/net/usb/mcs7830.c
@@ -239,7 +239,7 @@ static int mcs7830_set_mac_address(struct net_device *netdev, void *p)
239 return -EBUSY; 239 return -EBUSY;
240 240
241 if (!is_valid_ether_addr(addr->sa_data)) 241 if (!is_valid_ether_addr(addr->sa_data))
242 return -EINVAL; 242 return -EADDRNOTAVAIL;
243 243
244 ret = mcs7830_hif_set_mac_address(dev, addr->sa_data); 244 ret = mcs7830_hif_set_mac_address(dev, addr->sa_data);
245 245
diff --git a/drivers/net/usb/pegasus.c b/drivers/net/usb/pegasus.c
index 5d99b8cacd7d..752393092325 100644
--- a/drivers/net/usb/pegasus.c
+++ b/drivers/net/usb/pegasus.c
@@ -1332,10 +1332,8 @@ static int pegasus_probe(struct usb_interface *intf,
1332 usb_get_dev(dev); 1332 usb_get_dev(dev);
1333 1333
1334 net = alloc_etherdev(sizeof(struct pegasus)); 1334 net = alloc_etherdev(sizeof(struct pegasus));
1335 if (!net) { 1335 if (!net)
1336 dev_err(&intf->dev, "can't allocate %s\n", "device");
1337 goto out; 1336 goto out;
1338 }
1339 1337
1340 pegasus = netdev_priv(net); 1338 pegasus = netdev_priv(net);
1341 pegasus->dev_index = dev_index; 1339 pegasus->dev_index = dev_index;
diff --git a/drivers/net/usb/rtl8150.c b/drivers/net/usb/rtl8150.c
index 0710b4ca9252..6dda2fe5b15b 100644
--- a/drivers/net/usb/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
@@ -894,10 +894,8 @@ static int rtl8150_probe(struct usb_interface *intf,
894 struct net_device *netdev; 894 struct net_device *netdev;
895 895
896 netdev = alloc_etherdev(sizeof(rtl8150_t)); 896 netdev = alloc_etherdev(sizeof(rtl8150_t));
897 if (!netdev) { 897 if (!netdev)
898 err("Out of memory");
899 return -ENOMEM; 898 return -ENOMEM;
900 }
901 899
902 dev = netdev_priv(netdev); 900 dev = netdev_priv(netdev);
903 901
diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c
index 3b017bbd2a22..187d01ccb973 100644
--- a/drivers/net/usb/smsc75xx.c
+++ b/drivers/net/usb/smsc75xx.c
@@ -615,7 +615,7 @@ static void smsc75xx_init_mac_address(struct usbnet *dev)
615 } 615 }
616 616
617 /* no eeprom, or eeprom values are invalid. generate random MAC */ 617 /* no eeprom, or eeprom values are invalid. generate random MAC */
618 random_ether_addr(dev->net->dev_addr); 618 eth_hw_addr_random(dev->net);
619 netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr"); 619 netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr");
620} 620}
621 621
diff --git a/drivers/net/usb/smsc95xx.c b/drivers/net/usb/smsc95xx.c
index d45520e6dd48..5f19f84d3494 100644
--- a/drivers/net/usb/smsc95xx.c
+++ b/drivers/net/usb/smsc95xx.c
@@ -614,7 +614,7 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
614 } 614 }
615 615
616 /* no eeprom, or eeprom values are invalid. generate random MAC */ 616 /* no eeprom, or eeprom values are invalid. generate random MAC */
617 random_ether_addr(dev->net->dev_addr); 617 eth_hw_addr_random(dev->net);
618 netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr\n"); 618 netif_dbg(dev, ifup, dev->net, "MAC address set to random_ether_addr\n");
619} 619}
620 620
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 59681f01a54e..4b8b52ca09d8 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1336,10 +1336,8 @@ usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
1336 1336
1337 // set up our own records 1337 // set up our own records
1338 net = alloc_etherdev(sizeof(*dev)); 1338 net = alloc_etherdev(sizeof(*dev));
1339 if (!net) { 1339 if (!net)
1340 dbg ("can't kmalloc dev");
1341 goto out; 1340 goto out;
1342 }
1343 1341
1344 /* netdev_printk() needs this so do it as early as possible */ 1342 /* netdev_printk() needs this so do it as early as possible */
1345 SET_NETDEV_DEV(net, &udev->dev); 1343 SET_NETDEV_DEV(net, &udev->dev);
@@ -1537,7 +1535,7 @@ int usbnet_resume (struct usb_interface *intf)
1537 1535
1538 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) { 1536 if (test_bit(EVENT_DEV_OPEN, &dev->flags)) {
1539 if (!(dev->txq.qlen >= TX_QLEN(dev))) 1537 if (!(dev->txq.qlen >= TX_QLEN(dev)))
1540 netif_start_queue(dev->net); 1538 netif_tx_wake_all_queues(dev->net);
1541 tasklet_schedule (&dev->bh); 1539 tasklet_schedule (&dev->bh);
1542 } 1540 }
1543 } 1541 }