kernel: backport upstream usbnet fix (fixes #19455)
[openwrt.git] / target / linux / generic / patches-3.18 / 082-usbnet-Fix-tx_packets-stat-for-FLAG_MULTI_FRAME-driv.patch
1 From: Ben Hutchings <ben.hutchings@codethink.co.uk>
2 Date: Thu, 26 Feb 2015 19:34:37 +0000
3 Subject: [PATCH] usbnet: Fix tx_packets stat for FLAG_MULTI_FRAME drivers
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 Currently the usbnet core does not update the tx_packets statistic for
9 drivers with FLAG_MULTI_PACKET and there is no hook in the TX
10 completion path where they could do this.
11
12 cdc_ncm and dependent drivers are bumping tx_packets stat on the
13 transmit path while asix and sr9800 aren't updating it at all.
14
15 Add a packet count in struct skb_data so these drivers can fill it
16 in, initialise it to 1 for other drivers, and add the packet count
17 to the tx_packets statistic on completion.
18
19 Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>
20 Tested-by: Bjørn Mork <bjorn@mork.no>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
22 ---
23
24 --- a/drivers/net/usb/asix_common.c
25 +++ b/drivers/net/usb/asix_common.c
26 @@ -188,6 +188,8 @@ struct sk_buff *asix_tx_fixup(struct usb
27                 memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
28                 skb_put(skb, sizeof(padbytes));
29         }
30 +
31 +       usbnet_set_skb_tx_stats(skb, 1);
32         return skb;
33  }
34  
35 --- a/drivers/net/usb/cdc_ncm.c
36 +++ b/drivers/net/usb/cdc_ncm.c
37 @@ -1172,7 +1172,6 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev
38  
39         /* return skb */
40         ctx->tx_curr_skb = NULL;
41 -       dev->net->stats.tx_packets += ctx->tx_curr_frame_num;
42  
43         /* keep private stats: framing overhead and number of NTBs */
44         ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload;
45 @@ -1184,6 +1183,8 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev
46          */
47         dev->net->stats.tx_bytes -= skb_out->len - ctx->tx_curr_frame_payload;
48  
49 +       usbnet_set_skb_tx_stats(skb_out, n);
50 +
51         return skb_out;
52  
53  exit_no_skb:
54 --- a/drivers/net/usb/sr9800.c
55 +++ b/drivers/net/usb/sr9800.c
56 @@ -144,6 +144,7 @@ static struct sk_buff *sr_tx_fixup(struc
57                 skb_put(skb, sizeof(padbytes));
58         }
59  
60 +       usbnet_set_skb_tx_stats(skb, 1);
61         return skb;
62  }
63  
64 --- a/drivers/net/usb/usbnet.c
65 +++ b/drivers/net/usb/usbnet.c
66 @@ -1189,8 +1189,7 @@ static void tx_complete (struct urb *urb
67         struct usbnet           *dev = entry->dev;
68  
69         if (urb->status == 0) {
70 -               if (!(dev->driver_info->flags & FLAG_MULTI_PACKET))
71 -                       dev->net->stats.tx_packets++;
72 +               dev->net->stats.tx_packets += entry->packets;
73                 dev->net->stats.tx_bytes += entry->length;
74         } else {
75                 dev->net->stats.tx_errors++;
76 @@ -1349,6 +1348,8 @@ netdev_tx_t usbnet_start_xmit (struct sk
77                         urb->transfer_flags |= URB_ZERO_PACKET;
78         }
79         entry->length = urb->transfer_buffer_length = length;
80 +       if (!(info->flags & FLAG_MULTI_PACKET))
81 +               usbnet_set_skb_tx_stats(skb, 1);
82  
83         spin_lock_irqsave(&dev->txq.lock, flags);
84         retval = usb_autopm_get_interface_async(dev->intf);
85 --- a/include/linux/usb/usbnet.h
86 +++ b/include/linux/usb/usbnet.h
87 @@ -228,8 +228,20 @@ struct skb_data {  /* skb->cb is one of t
88         struct usbnet           *dev;
89         enum skb_state          state;
90         size_t                  length;
91 +       unsigned long           packets;
92  };
93  
94 +/* Drivers that set FLAG_MULTI_PACKET must call this in their
95 + * tx_fixup method before returning an skb.
96 + */
97 +static inline void
98 +usbnet_set_skb_tx_stats(struct sk_buff *skb, unsigned long packets)
99 +{
100 +       struct skb_data *entry = (struct skb_data *) skb->cb;
101 +
102 +       entry->packets = packets;
103 +}
104 +
105  extern int usbnet_open(struct net_device *net);
106  extern int usbnet_stop(struct net_device *net);
107  extern netdev_tx_t usbnet_start_xmit(struct sk_buff *skb,