All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usbnet: allow rx_process() to ignore packets
@ 2010-09-04 21:52 Ondrej Zary
  2010-09-04 23:24 ` David Brownell
  0 siblings, 1 reply; 11+ messages in thread
From: Ondrej Zary @ 2010-09-04 21:52 UTC (permalink / raw)
  To: David Brownell; +Cc: netdev, Kernel development list

Allow rx_process() to ignore a packet without incrementing error counters if 
rx_fixup() returns value other than 0 or 1 (e.g. 2).

This allows to simplify rx_fixup() functions of drivers who do complex 
processing there. Currently, drivers must process the last packet in a 
special way - leave it for usbnet to process. This is not easily possible 
when a driver (like the new cx82310_eth) needs to process packets that cross 
URB (and thus skb) boundaries. With this patch, the driver can process all 
packets in the skb and just return 2 at the end.

Also fix asix driver that was returning 2 at one place before this change 
(probably by mistake).

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>

--- linux-2.6.36-rc3-orig/drivers/net/usb/usbnet.c	2010-08-29 17:36:04.000000000 +0200
+++ linux-2.6.36-rc3/drivers/net/usb/usbnet.c	2010-09-04 23:47:14.000000000 +0200
@@ -385,18 +385,24 @@ static int rx_submit (struct usbnet *dev
 
 static inline void rx_process (struct usbnet *dev, struct sk_buff *skb)
 {
-	if (dev->driver_info->rx_fixup &&
-	    !dev->driver_info->rx_fixup (dev, skb))
-		goto error;
-	// else network stack removes extra byte if we forced a short packet
+	int fixup = 1;
 
-	if (skb->len)
-		usbnet_skb_return (dev, skb);
-	else {
-		netif_dbg(dev, rx_err, dev->net, "drop\n");
-error:
+	if (dev->driver_info->rx_fixup)
+		fixup = dev->driver_info->rx_fixup(dev, skb);
+
+	switch (fixup) {
+	case 1:	/* skb is correct */
+		if (skb->len) {
+			usbnet_skb_return(dev, skb);
+			break;
+		} else
+			netif_dbg(dev, rx_err, dev->net, "drop\n");
+		/* fall through */
+	case 0: /* skb is incorrect */
 		dev->net->stats.rx_errors++;
-		skb_queue_tail (&dev->done, skb);
+		/* fall through */
+	default: /* skb does not need processing */
+		skb_queue_tail(&dev->done, skb);
 	}
 }
 
--- linux-2.6.36-rc3-orig/drivers/net/usb/asix.c	2010-08-29 17:36:04.000000000 +0200
+++ linux-2.6.36-rc3/drivers/net/usb/asix.c	2010-09-04 23:48:42.000000000 +0200
@@ -341,7 +341,7 @@ static int asix_rx_fixup(struct usbnet *
 				skb->data -= realignment;
 				skb_set_tail_pointer(skb, size);
 			}
-			return 2;
+			return 1;
 		}
 
 		if (size > dev->net->mtu + ETH_HLEN) {


-- 
Ondrej Zary

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: [PATCH] usbnet: allow rx_process() to ignore packets
@ 2010-09-08  0:46 David Brownell
  0 siblings, 0 replies; 11+ messages in thread
From: David Brownell @ 2010-09-08  0:46 UTC (permalink / raw)
  To: Ondrej Zary; +Cc: David Brownell, netdev, Kernel development list

[-- Attachment #1: Type: text/plain, Size: 728 bytes --]

--- On Tue, 9/7/10, Ondrej Zary <linux@rainbow-software.org> wrote:
> 
> It's not a garbage, just a packet that is not yet
> complete.

Sorry, I guess I was being dense.

I thought packets were by definition complete... :)

I think you're saying this is one of N fragments
which the minidriver will be re-assembling into
a bigger packet, before somehow passing it up
the stack...

I attach my doc update patch.  (should be the
same as what I sent before.  Consider my apology
for using an attachment as repeated here; my email
setup remains partly broken).  Can you send
a version of your defrag-enabling patch which
applies on top of it, and documents your new
calling convention (with a third return case
for rx_process() too?

[-- Attachment #2: rxfix --]
[-- Type: application/octet-stream, Size: 2492 bytes --]

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Subject: usbnet: doc updates

Provide more documentation about the rx_fixup() calling convention,
to help reduce some recently-observed confusion.

Also summarize the equivalence of USB and network TX/RX queues, to
help highlight the roles of the fixup() routines with link protocols
using the CPU-intensive packet batching models.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
---


 include/linux/usb/usbnet.h |   31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

--- a/include/linux/usb/usbnet.h
+++ b/include/linux/usb/usbnet.h
@@ -22,8 +22,22 @@
 #ifndef	__LINUX_USB_USBNET_H
 #define	__LINUX_USB_USBNET_H
 
-/* interface from usbnet core to each USB networking link we handle */
+/** interface from usbnet core to each USB networking link we handle.
+ *
+ * Note that the design center for usbnet has one IEEE packet per URB,
+ * and maps network TX and RX queues directly to the
+ * USB hardware TX/RX queues, minimizing software and hardware overhead.
+ * Some link protocols (like RNDIS and CDC NCM) promote  less efficient
+ * designs which involve batching multiple IEEE packets in each URB,
+ * with increased TX overhead to copy IEEE packets into TX URBs' data
+ * buffers in tx_fixup() routines, plus unbatching work in rx_fixup() too.
+ * Sometimes the TX overhead can be minimized on Linux by not batching, but
+ * this usually won't work for RX because of the need to interoperate with
+ * implementations which batch on TX.
+ */
+
 struct usbnet {
+
 	/* housekeeping */
 	struct usb_device	*udev;
 	struct usb_interface	*intf;
@@ -113,7 +127,20 @@ struct driver_info {
 	/* link reset handling, called from defer_kevent */
 	int	(*link_reset)(struct usbnet *);
 
-	/* fixup rx packet (strip framing) */
+	/* fixup rx packet ( by stripping framing from URB/SKB.
+	 *
+	 * If SKB batches one or more packets, pass all but one of them
+	 * up the stack (clone SKB and fixup each clone before netif_rx)).
+	 *
+
+	 * When you leave one packet in SKB (intended usage), return
+	 * nonzero and ensure skb-len is nonzero.  the packet will be
+	 * passed up the network stack and accounted properly.
+	 *
+	 * return zero to indicate errors such as too much header or
+	 * data, or a bad checksum; the packet will be dropped
+	 * and accounted as an error.
+	*/
 	int	(*rx_fixup)(struct usbnet *dev, struct sk_buff *skb);
 
 	/* fixup tx packet (add framing) */

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

end of thread, other threads:[~2010-09-11 21:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-04 21:52 [PATCH] usbnet: allow rx_process() to ignore packets Ondrej Zary
2010-09-04 23:24 ` David Brownell
2010-09-05 16:16   ` Ondrej Zary
2010-09-05 21:35     ` David Brownell
2010-09-07 20:02       ` Ondrej Zary
2010-09-10 21:35       ` [PATCH v2] usbnet: do not count empty skbs as errors in rx_process() Ondrej Zary
2010-09-11 19:07         ` David Brownell
2010-09-11 20:22           ` Ondrej Zary
2010-09-11 21:15             ` David Brownell
2010-09-11 21:21               ` Ondrej Zary
  -- strict thread matches above, loose matches on Subject: below --
2010-09-08  0:46 [PATCH] usbnet: allow rx_process() to ignore packets David Brownell

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.