All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] usbnet: Fix tx_packets stat for FLAG_MULTI_FRAME drivers
@ 2015-02-26 19:34 Ben Hutchings
       [not found] ` <1424979277.4444.39.camel-2NU49sBE5Aze9VDwLV8dzJPsBRI6B4nW9dF7HbQ/qKg@public.gmane.org>
  2015-02-28 19:28 ` David Miller
  0 siblings, 2 replies; 3+ messages in thread
From: Ben Hutchings @ 2015-02-26 19:34 UTC (permalink / raw)
  To: netdev-u79uwXL29TY76Z2rM5mHXA, Oliver Neukum
  Cc: ct-linux-kernel, linux-usb-u79uwXL29TY76Z2rM5mHXA

Currently the usbnet core does not update the tx_packets statistic for
drivers with FLAG_MULTI_PACKET and there is no hook in the TX
completion path where they could do this.

cdc_ncm and dependent drivers are bumping tx_packets stat on the
transmit path while asix and sr9800 aren't updating it at all.

Add a packet count in struct skb_data so these drivers can fill it
in, initialise it to 1 for other drivers, and add the packet count
to the tx_packets statistic on completion.

Signed-off-by: Ben Hutchings <ben.hutchings-4yDnlxn2s6sWdaTGBSpHTA@public.gmane.org>
---
I have only tested the asix driver after this change; I think cdc_ncm
and one of the non-multi-packet drivers should also be tested before
it's applied.

Ben.

 drivers/net/usb/asix_common.c |    2 ++
 drivers/net/usb/cdc_ncm.c     |    3 ++-
 drivers/net/usb/sr9800.c      |    1 +
 drivers/net/usb/usbnet.c      |    5 +++--
 include/linux/usb/usbnet.h    |   12 ++++++++++++
 5 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/usb/asix_common.c b/drivers/net/usb/asix_common.c
index 5c55f11572ba..724a9b50df7a 100644
--- a/drivers/net/usb/asix_common.c
+++ b/drivers/net/usb/asix_common.c
@@ -188,6 +188,8 @@ struct sk_buff *asix_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
 		memcpy(skb_tail_pointer(skb), &padbytes, sizeof(padbytes));
 		skb_put(skb, sizeof(padbytes));
 	}
+
+	usbnet_set_skb_tx_stats(skb, 1);
 	return skb;
 }
 
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c
index 80a844e0ae03..70cbea551139 100644
--- a/drivers/net/usb/cdc_ncm.c
+++ b/drivers/net/usb/cdc_ncm.c
@@ -1172,7 +1172,6 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
 
 	/* return skb */
 	ctx->tx_curr_skb = NULL;
-	dev->net->stats.tx_packets += ctx->tx_curr_frame_num;
 
 	/* keep private stats: framing overhead and number of NTBs */
 	ctx->tx_overhead += skb_out->len - ctx->tx_curr_frame_payload;
@@ -1184,6 +1183,8 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign)
 	 */
 	dev->net->stats.tx_bytes -= skb_out->len - ctx->tx_curr_frame_payload;
 
+	usbnet_set_skb_tx_stats(skb_out, n);
+
 	return skb_out;
 
 exit_no_skb:
diff --git a/drivers/net/usb/sr9800.c b/drivers/net/usb/sr9800.c
index b94a0fbb8b3b..7650cdc8fe6b 100644
--- a/drivers/net/usb/sr9800.c
+++ b/drivers/net/usb/sr9800.c
@@ -144,6 +144,7 @@ static struct sk_buff *sr_tx_fixup(struct usbnet *dev, struct sk_buff *skb,
 		skb_put(skb, sizeof(padbytes));
 	}
 
+	usbnet_set_skb_tx_stats(skb, 1);
 	return skb;
 }
 
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index 449835f4331e..0f3ff285f6a1 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -1188,8 +1188,7 @@ static void tx_complete (struct urb *urb)
 	struct usbnet		*dev = entry->dev;
 
 	if (urb->status == 0) {
-		if (!(dev->driver_info->flags & FLAG_MULTI_PACKET))
-			dev->net->stats.tx_packets++;
+		dev->net->stats.tx_packets += entry->packets;
 		dev->net->stats.tx_bytes += entry->length;
 	} else {
 		dev->net->stats.tx_errors++;
@@ -1348,6 +1347,8 @@ netdev_tx_t usbnet_start_xmit (struct sk_buff *skb,
 			urb->transfer_flags |= URB_ZERO_PACKET;
 	}
 	entry->length = urb->transfer_buffer_length = length;
+	if (!(info->flags & FLAG_MULTI_PACKET))
+		usbnet_set_skb_tx_stats(skb, 1);
 
 	spin_lock_irqsave(&dev->txq.lock, flags);
 	retval = usb_autopm_get_interface_async(dev->intf);
diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
index d9a4905e01d0..ff3fb2bd0e90 100644
--- a/include/linux/usb/usbnet.h
+++ b/include/linux/usb/usbnet.h
@@ -228,8 +228,20 @@ struct skb_data {	/* skb->cb is one of these */
 	struct usbnet		*dev;
 	enum skb_state		state;
 	size_t			length;
+	unsigned long		packets;
 };
 
+/* Drivers that set FLAG_MULTI_PACKET must call this in their
+ * tx_fixup method before returning an skb.
+ */
+static inline void
+usbnet_set_skb_tx_stats(struct sk_buff *skb, unsigned long packets)
+{
+	struct skb_data *entry = (struct skb_data *) skb->cb;
+
+	entry->packets = packets;
+}
+
 extern int usbnet_open(struct net_device *net);
 extern int usbnet_stop(struct net_device *net);
 extern netdev_tx_t usbnet_start_xmit(struct sk_buff *skb,
-- 
1.7.10.4



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] usbnet: Fix tx_packets stat for FLAG_MULTI_FRAME drivers
       [not found] ` <1424979277.4444.39.camel-2NU49sBE5Aze9VDwLV8dzJPsBRI6B4nW9dF7HbQ/qKg@public.gmane.org>
@ 2015-02-27  8:50   ` Bjørn Mork
  0 siblings, 0 replies; 3+ messages in thread
From: Bjørn Mork @ 2015-02-27  8:50 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: netdev-u79uwXL29TY76Z2rM5mHXA, Oliver Neukum, ct-linux-kernel,
	linux-usb-u79uwXL29TY76Z2rM5mHXA

Ben Hutchings <ben.hutchings-4yDnlxn2s6sWdaTGBSpHTA@public.gmane.org> writes:

> Currently the usbnet core does not update the tx_packets statistic for
> drivers with FLAG_MULTI_PACKET and there is no hook in the TX
> completion path where they could do this.
>
> cdc_ncm and dependent drivers are bumping tx_packets stat on the
> transmit path while asix and sr9800 aren't updating it at all.
>
> Add a packet count in struct skb_data so these drivers can fill it
> in, initialise it to 1 for other drivers, and add the packet count
> to the tx_packets statistic on completion.
>
> Signed-off-by: Ben Hutchings <ben.hutchings-4yDnlxn2s6sWdaTGBSpHTA@public.gmane.org>
> ---
> I have only tested the asix driver after this change; I think cdc_ncm
> and one of the non-multi-packet drivers should also be tested before
> it's applied.

Looks very good to me.  I did a quick test with an MBIM device (the
cdc_mbim driver uses the parts of cdc_ncm you modify here), and it
worked as expected.

Thanks for doing this.  My only complaint was a wishlist for a similar
byte fixup, but then I noticed that you already did that :-)

Tested-by: Bjørn Mork <bjorn-yOkvZcmFvRU@public.gmane.org>



Bjørn
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] usbnet: Fix tx_packets stat for FLAG_MULTI_FRAME drivers
  2015-02-26 19:34 [PATCH net-next] usbnet: Fix tx_packets stat for FLAG_MULTI_FRAME drivers Ben Hutchings
       [not found] ` <1424979277.4444.39.camel-2NU49sBE5Aze9VDwLV8dzJPsBRI6B4nW9dF7HbQ/qKg@public.gmane.org>
@ 2015-02-28 19:28 ` David Miller
  1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-02-28 19:28 UTC (permalink / raw)
  To: ben.hutchings; +Cc: netdev, oliver, linux-kernel, linux-usb

From: Ben Hutchings <ben.hutchings@codethink.co.uk>
Date: Thu, 26 Feb 2015 19:34:37 +0000

> Currently the usbnet core does not update the tx_packets statistic for
> drivers with FLAG_MULTI_PACKET and there is no hook in the TX
> completion path where they could do this.
> 
> cdc_ncm and dependent drivers are bumping tx_packets stat on the
> transmit path while asix and sr9800 aren't updating it at all.
> 
> Add a packet count in struct skb_data so these drivers can fill it
> in, initialise it to 1 for other drivers, and add the packet count
> to the tx_packets statistic on completion.
> 
> Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk>

Applied, thanks Ben.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-02-28 19:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-26 19:34 [PATCH net-next] usbnet: Fix tx_packets stat for FLAG_MULTI_FRAME drivers Ben Hutchings
     [not found] ` <1424979277.4444.39.camel-2NU49sBE5Aze9VDwLV8dzJPsBRI6B4nW9dF7HbQ/qKg@public.gmane.org>
2015-02-27  8:50   ` Bjørn Mork
2015-02-28 19:28 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.