WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] [NET] back: Add TSO support

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] [NET] back: Add TSO support
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Jun 2006 13:50:25 +0000
Delivery-date: Wed, 28 Jun 2006 06:53:56 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 2245974798126074c31521b0903cc7e67e8aec23
# Parent  bb46d03f5f1d59a41d2daeb3f30aced203eef1bd
[NET] back: Add TSO support

This patch adds TCP Segmentation Offload (TSO) support to the backend.
It also advertises this fact through xenbus so that the frontend can
detect this and send through TSO requests only if it is supported.

This is done using an extra request slot which is indicated by a flag
in the first slot.  In future checksum offload can be done in the same
way.

The extra request slot must not be generated if the backend does not
support the appropriate feature bits.  For now this is simply feature-tso.

If the frontend detects the presence of the appropriate feature bits,
it may generate TX requests which have the appropriate request flags
set that indicates the presence of an extra request slot with the extra
information.

On the backend the extra request slot is read if and only if the request
flags are set in the TX request.

This protocol allows more feature bits to be added in future without
breaking compatibility.  At least the hardware checksum bit is planned.

Even though only TSO is supported for now the code actually supports
GSO so it can be applied to any other protocol.  The only missing bit
is the detection of host support for a specific GSO protocol.  Once that
is added we can advertise all supported protocols to the guest.

Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>
---
 linux-2.6-xen-sparse/drivers/xen/netback/interface.c |    8 +-
 linux-2.6-xen-sparse/drivers/xen/netback/netback.c   |   51 ++++++++++++++-----
 linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c    |    6 ++
 xen/include/public/io/netif.h                        |   33 +++++++++++-
 4 files changed, 81 insertions(+), 17 deletions(-)

diff -r bb46d03f5f1d -r 224597479812 
linux-2.6-xen-sparse/drivers/xen/netback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c      Wed Jun 28 
12:03:57 2006 +0100
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c      Wed Jun 28 
12:04:32 2006 +0100
@@ -37,9 +37,9 @@ static void __netif_up(netif_t *netif)
 static void __netif_up(netif_t *netif)
 {
        struct net_device *dev = netif->dev;
-       spin_lock_bh(&dev->xmit_lock);
+       netif_tx_lock_bh(dev);
        netif->active = 1;
-       spin_unlock_bh(&dev->xmit_lock);
+       netif_tx_unlock_bh(dev);
        enable_irq(netif->irq);
        netif_schedule_work(netif);
 }
@@ -48,9 +48,9 @@ static void __netif_down(netif_t *netif)
 {
        struct net_device *dev = netif->dev;
        disable_irq(netif->irq);
-       spin_lock_bh(&dev->xmit_lock);
+       netif_tx_lock_bh(dev);
        netif->active = 0;
-       spin_unlock_bh(&dev->xmit_lock);
+       netif_tx_unlock_bh(dev);
        netif_deschedule_work(netif);
 }
 
diff -r bb46d03f5f1d -r 224597479812 
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Wed Jun 28 
12:03:57 2006 +0100
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Wed Jun 28 
12:04:32 2006 +0100
@@ -490,14 +490,16 @@ inline static void net_tx_action_dealloc
        }
 }
 
-static void netbk_tx_err(netif_t *netif, RING_IDX end)
+static void netbk_tx_err(netif_t *netif, netif_tx_request_t *txp, RING_IDX end)
 {
        RING_IDX cons = netif->tx.req_cons;
 
        do {
-               netif_tx_request_t *txp = RING_GET_REQUEST(&netif->tx, cons);
                make_tx_response(netif, txp, NETIF_RSP_ERROR);
-       } while (++cons < end);
+               if (++cons >= end)
+                       break;
+               txp = RING_GET_REQUEST(&netif->tx, cons);
+       } while (1);
        netif->tx.req_cons = cons;
        netif_schedule_work(netif);
        netif_put(netif);
@@ -508,7 +510,7 @@ static int netbk_count_requests(netif_t 
 {
        netif_tx_request_t *first = txp;
        RING_IDX cons = netif->tx.req_cons;
-       int frags = 1;
+       int frags = 0;
 
        while (txp->flags & NETTXF_more_data) {
                if (frags >= work_to_do) {
@@ -543,7 +545,7 @@ static gnttab_map_grant_ref_t *netbk_get
        skb_frag_t *frags = shinfo->frags;
        netif_tx_request_t *txp;
        unsigned long pending_idx = *((u16 *)skb->data);
-       RING_IDX cons = netif->tx.req_cons + 1;
+       RING_IDX cons = netif->tx.req_cons;
        int i, start;
 
        /* Skip first skb fragment if it is on same page as header fragment. */
@@ -668,6 +670,7 @@ static void net_tx_action(unsigned long 
        struct sk_buff *skb;
        netif_t *netif;
        netif_tx_request_t txreq;
+       struct netif_tx_extra txtra;
        u16 pending_idx;
        RING_IDX i;
        gnttab_map_grant_ref_t *mop;
@@ -726,22 +729,37 @@ static void net_tx_action(unsigned long 
                }
                netif->remaining_credit -= txreq.size;
 
+               work_to_do--;
+               netif->tx.req_cons = ++i;
+
+               if (txreq.flags & NETTXF_extra_info) {
+                       if (work_to_do-- <= 0) {
+                               DPRINTK("Missing extra info\n");
+                               netbk_tx_err(netif, &txreq, i);
+                               continue;
+                       }
+
+                       memcpy(&txtra, RING_GET_REQUEST(&netif->tx, i),
+                              sizeof(txtra));
+                       netif->tx.req_cons = ++i;
+               }
+
                ret = netbk_count_requests(netif, &txreq, work_to_do);
                if (unlikely(ret < 0)) {
-                       netbk_tx_err(netif, i - ret);
+                       netbk_tx_err(netif, &txreq, i - ret);
                        continue;
                }
                i += ret;
 
                if (unlikely(ret > MAX_SKB_FRAGS + 1)) {
                        DPRINTK("Too many frags\n");
-                       netbk_tx_err(netif, i);
+                       netbk_tx_err(netif, &txreq, i);
                        continue;
                }
 
                if (unlikely(txreq.size < ETH_HLEN)) {
                        DPRINTK("Bad packet size: %d\n", txreq.size);
-                       netbk_tx_err(netif, i);
+                       netbk_tx_err(netif, &txreq, i);
                        continue; 
                }
 
@@ -750,25 +768,31 @@ static void net_tx_action(unsigned long 
                        DPRINTK("txreq.offset: %x, size: %u, end: %lu\n", 
                                txreq.offset, txreq.size, 
                                (txreq.offset &~PAGE_MASK) + txreq.size);
-                       netbk_tx_err(netif, i);
+                       netbk_tx_err(netif, &txreq, i);
                        continue;
                }
 
                pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
 
                data_len = (txreq.size > PKT_PROT_LEN &&
-                           ret < MAX_SKB_FRAGS + 1) ?
+                           ret < MAX_SKB_FRAGS) ?
                        PKT_PROT_LEN : txreq.size;
 
                skb = alloc_skb(data_len+16, GFP_ATOMIC);
                if (unlikely(skb == NULL)) {
                        DPRINTK("Can't allocate a skb in start_xmit.\n");
-                       netbk_tx_err(netif, i);
+                       netbk_tx_err(netif, &txreq, i);
                        break;
                }
 
                /* Packets passed to netif_rx() must have some headroom. */
                skb_reserve(skb, 16);
+
+               if (txreq.flags & NETTXF_gso) {
+                       skb_shinfo(skb)->gso_size = txtra.u.gso.size;
+                       skb_shinfo(skb)->gso_segs = txtra.u.gso.segs;
+                       skb_shinfo(skb)->gso_type = txtra.u.gso.type;
+               }
 
                gnttab_set_map_op(mop, MMAP_VADDR(pending_idx),
                                  GNTMAP_host_map | GNTMAP_readonly,
@@ -782,7 +806,7 @@ static void net_tx_action(unsigned long 
 
                __skb_put(skb, data_len);
 
-               skb_shinfo(skb)->nr_frags = ret - 1;
+               skb_shinfo(skb)->nr_frags = ret;
                if (data_len < txreq.size) {
                        skb_shinfo(skb)->nr_frags++;
                        skb_shinfo(skb)->frags[0].page =
@@ -908,6 +932,9 @@ static void make_tx_response(netif_t *ne
        resp = RING_GET_RESPONSE(&netif->tx, i);
        resp->id     = txp->id;
        resp->status = st;
+
+       if (txp->flags & NETTXF_extra_info)
+               RING_GET_RESPONSE(&netif->tx, ++i)->status = NETIF_RSP_NULL;
 
        netif->tx.rsp_prod_pvt = ++i;
        RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&netif->tx, notify);
diff -r bb46d03f5f1d -r 224597479812 
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Wed Jun 28 12:03:57 
2006 +0100
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c Wed Jun 28 12:04:32 
2006 +0100
@@ -101,6 +101,12 @@ static int netback_probe(struct xenbus_d
                        goto abort_transaction;
                }
 
+               err = xenbus_printf(xbt, dev->nodename, "feature-tso", "%d", 1);
+               if (err) {
+                       message = "writing feature-tso";
+                       goto abort_transaction;
+               }
+
                err = xenbus_transaction_end(xbt, 0);
        } while (err == -EAGAIN);
 
diff -r bb46d03f5f1d -r 224597479812 xen/include/public/io/netif.h
--- a/xen/include/public/io/netif.h     Wed Jun 28 12:03:57 2006 +0100
+++ b/xen/include/public/io/netif.h     Wed Jun 28 12:04:32 2006 +0100
@@ -19,6 +19,16 @@
  * the appropriate req_event or rsp_event field in the shared ring.
  */
 
+/*
+ * This is the 'wire' format for packets:
+ *  Request 1: netif_tx_request -- NETTXF_* (any flags)
+ * [Request 2: netif_tx_extra]  (only if request 1 has NETTXF_extra_info)
+ *  Request 3: netif_tx_request -- NETTXF_more_data
+ *  Request 4: netif_tx_request -- NETTXF_more_data
+ *  ...
+ *  Request N: netif_tx_request -- 0
+ */
+
 /* Protocol checksum field is blank in the packet (hardware offload)? */
 #define _NETTXF_csum_blank     (0)
 #define  NETTXF_csum_blank     (1U<<_NETTXF_csum_blank)
@@ -27,9 +37,16 @@
 #define _NETTXF_data_validated (1)
 #define  NETTXF_data_validated (1U<<_NETTXF_data_validated)
 
-/* Packet continues in the request. */
+/* Packet continues in the next request descriptor. */
 #define _NETTXF_more_data      (2)
 #define  NETTXF_more_data      (1U<<_NETTXF_more_data)
+
+/* Packet has GSO fields in the following descriptor (netif_tx_extra.u.gso). */
+#define _NETTXF_gso            (3)
+#define  NETTXF_gso            (1U<<_NETTXF_gso)
+
+/* This descriptor is followed by an extra-info descriptor (netif_tx_extra). */
+#define  NETTXF_extra_info     (NETTXF_gso)
 
 struct netif_tx_request {
     grant_ref_t gref;      /* Reference to buffer page */
@@ -39,6 +56,18 @@ struct netif_tx_request {
     uint16_t size;         /* Packet size in bytes.       */
 };
 typedef struct netif_tx_request netif_tx_request_t;
+
+/* This structure needs to fit within netif_tx_request for compatibility. */
+struct netif_tx_extra {
+    union {
+        /* NETTXF_gso: Generic Segmentation Offload. */
+        struct netif_tx_gso {
+            uint16_t size;        /* GSO MSS. */
+            uint16_t segs;        /* GSO segment count. */
+            uint16_t type;        /* GSO type. */
+        } gso;
+    } u;
+};
 
 struct netif_tx_response {
     uint16_t id;
@@ -78,6 +107,8 @@ DEFINE_RING_TYPES(netif_rx, struct netif
 #define NETIF_RSP_DROPPED         -2
 #define NETIF_RSP_ERROR           -1
 #define NETIF_RSP_OKAY             0
+/* No response: used for auxiliary requests (e.g., netif_tx_extra). */
+#define NETIF_RSP_NULL             1
 
 #endif
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] [NET] back: Add TSO support, Xen patchbot-unstable <=