[NET] back: Add TSO support
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 28 Jun 2006 11:04:32 +0000 (12:04 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Wed, 28 Jun 2006 11:04:32 +0000 (12:04 +0100)
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@gondor.apana.org.au>
Signed-off-by: Keir Fraser <keir@xensource.com>
linux-2.6-xen-sparse/drivers/xen/netback/interface.c
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c
xen/include/public/io/netif.h

index dbd8a7e804d3558292a533aacca54d76341c5b9e..3d5db4452fe8f1ce042a505322181e622e262284 100644 (file)
@@ -37,9 +37,9 @@
 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);
 }
 
index 0d8d3410a0c8ca6ee506571ab1561f903bc96bdd..77a8330a71376c906dd73da4bc9762b089e719ed 100644 (file)
@@ -490,14 +490,16 @@ inline static void net_tx_action_dealloc(void)
        }
 }
 
-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, netif_tx_request_t *txp,
 {
        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_requests(netif_t *netif,
        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 unused)
        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 unused)
                }
                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,26 +768,32 @@ static void net_tx_action(unsigned long unused)
                        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,
                                  txreq.gref, netif->domid);
@@ -782,7 +806,7 @@ static void net_tx_action(unsigned long unused)
 
                __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 =
@@ -909,6 +933,9 @@ static void make_tx_response(netif_t *netif,
        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);
        if (notify)
index 2ac87b5dc8117caa2590b8342ae7f714b553f545..eb70aae1890f40435d8d3e39393a36e40b9bdeea 100644 (file)
@@ -101,6 +101,12 @@ static int netback_probe(struct xenbus_device *dev,
                        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);
 
index eac61494239f2a39e8f1fa9968e375b838202b35..622fce5c4235e188a341f3690ced6d3cc49cd987 100644 (file)
  * 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)
 #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 */
     uint16_t offset;       /* Offset within buffer page */
@@ -40,6 +57,18 @@ struct netif_tx_request {
 };
 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;
     int16_t  status;       /* NETIF_RSP_* */
@@ -78,6 +107,8 @@ DEFINE_RING_TYPES(netif_rx, struct netif_rx_request, struct netif_rx_response);
 #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