ia64/xen-unstable

changeset 10603:de263308be3b

[NET] More net protocol and GSO changes.
From: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@dhcp93.uk.xensource.com
date Thu Jun 29 19:02:45 2006 +0100 (2006-06-29)
parents 3dfc2583a4f1
children 7a11e60d2f42
files 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
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Jun 29 16:59:47 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Thu Jun 29 19:02:45 2006 +0100
     1.3 @@ -663,6 +663,34 @@ static void netbk_fill_frags(struct sk_b
     1.4  	}
     1.5  }
     1.6  
     1.7 +int netbk_get_extras(netif_t *netif, struct netif_extra_info *extras,
     1.8 +		     int work_to_do)
     1.9 +{
    1.10 +	struct netif_extra_info *extra;
    1.11 +	RING_IDX cons = netif->tx.req_cons;
    1.12 +
    1.13 +	do {
    1.14 +		if (unlikely(work_to_do-- <= 0)) {
    1.15 +			DPRINTK("Missing extra info\n");
    1.16 +			return -EBADR;
    1.17 +		}
    1.18 +
    1.19 +		extra = (struct netif_extra_info *)
    1.20 +			RING_GET_REQUEST(&netif->tx, cons);
    1.21 +		if (unlikely(!extra->type ||
    1.22 +			     extra->type >= XEN_NETIF_EXTRA_TYPE_MAX)) {
    1.23 +			netif->tx.req_cons = ++cons;
    1.24 +			DPRINTK("Invalid extra type: %d\n", extra->type);
    1.25 +			return -EINVAL;
    1.26 +		}
    1.27 +
    1.28 +		memcpy(&extras[extra->type - 1], extra, sizeof(*extra));
    1.29 +		netif->tx.req_cons = ++cons;
    1.30 +	} while (extra->flags & XEN_NETIF_EXTRA_FLAG_MORE);
    1.31 +
    1.32 +	return work_to_do;
    1.33 +}
    1.34 +
    1.35  /* Called after netfront has transmitted */
    1.36  static void net_tx_action(unsigned long unused)
    1.37  {
    1.38 @@ -670,7 +698,7 @@ static void net_tx_action(unsigned long 
    1.39  	struct sk_buff *skb;
    1.40  	netif_t *netif;
    1.41  	netif_tx_request_t txreq;
    1.42 -	struct netif_tx_extra txtra;
    1.43 +	struct netif_tx_extra extras[XEN_NETIF_EXTRA_TYPE_MAX - 1];
    1.44  	u16 pending_idx;
    1.45  	RING_IDX i;
    1.46  	gnttab_map_grant_ref_t *mop;
    1.47 @@ -732,16 +760,15 @@ static void net_tx_action(unsigned long 
    1.48  		work_to_do--;
    1.49  		netif->tx.req_cons = ++i;
    1.50  
    1.51 +		memset(extras, 0, sizeof(extras));
    1.52  		if (txreq.flags & NETTXF_extra_info) {
    1.53 -			if (work_to_do-- <= 0) {
    1.54 -				DPRINTK("Missing extra info\n");
    1.55 -				netbk_tx_err(netif, &txreq, i);
    1.56 +			work_to_do = netbk_get_extras(netif, extras,
    1.57 +						      work_to_do);
    1.58 +			if (unlikely(work_to_do < 0)) {
    1.59 +				netbk_tx_err(netif, &txreq, 0);
    1.60  				continue;
    1.61  			}
    1.62 -
    1.63 -			memcpy(&txtra, RING_GET_REQUEST(&netif->tx, i),
    1.64 -			       sizeof(txtra));
    1.65 -			netif->tx.req_cons = ++i;
    1.66 +			i = netif->tx.req_cons;
    1.67  		}
    1.68  
    1.69  		ret = netbk_count_requests(netif, &txreq, work_to_do);
    1.70 @@ -751,7 +778,7 @@ static void net_tx_action(unsigned long 
    1.71  		}
    1.72  		i += ret;
    1.73  
    1.74 -		if (unlikely(ret > MAX_SKB_FRAGS + 1)) {
    1.75 +		if (unlikely(ret > MAX_SKB_FRAGS)) {
    1.76  			DPRINTK("Too many frags\n");
    1.77  			netbk_tx_err(netif, &txreq, i);
    1.78  			continue;
    1.79 @@ -788,10 +815,21 @@ static void net_tx_action(unsigned long 
    1.80  		/* Packets passed to netif_rx() must have some headroom. */
    1.81  		skb_reserve(skb, 16);
    1.82  
    1.83 -		if (txreq.flags & NETTXF_gso) {
    1.84 -			skb_shinfo(skb)->gso_size = txtra.u.gso.size;
    1.85 -			skb_shinfo(skb)->gso_segs = txtra.u.gso.segs;
    1.86 -			skb_shinfo(skb)->gso_type = txtra.u.gso.type;
    1.87 +		if (extras[XEN_NETIF_EXTRA_TYPE_GSO - 1].type) {
    1.88 +			struct netif_tx_extra *gso;
    1.89 +			gso = &extras[XEN_NETIF_EXTRA_TYPE_GSO - 1];
    1.90 +
    1.91 +			if (gso->u.gso.type != XEN_NETIF_GSO_TCPV4) {
    1.92 +				DPRINTK("Bad GSO type.\n");
    1.93 +				kfree_skb(skb);
    1.94 +				netbk_tx_err(netif, &txreq, i);
    1.95 +				break;
    1.96 +			}
    1.97 +
    1.98 +			skb_shinfo(skb)->gso_size = gso->u.gso.size;
    1.99 +			skb_shinfo(skb)->gso_segs = gso->u.gso.segs;
   1.100 +			skb_shinfo(skb)->gso_type =
   1.101 +				SKB_GSP_TCPV4 | SKB_GSO_DOSGY;
   1.102  		}
   1.103  
   1.104  		gnttab_set_map_op(mop, MMAP_VADDR(pending_idx),
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Thu Jun 29 16:59:47 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/xenbus.c	Thu Jun 29 19:02:45 2006 +0100
     2.3 @@ -101,11 +101,13 @@ static int netback_probe(struct xenbus_d
     2.4  			goto abort_transaction;
     2.5  		}
     2.6  
     2.7 +#if 0 /* KAF: After the protocol is finalised. */
     2.8  		err = xenbus_printf(xbt, dev->nodename, "feature-tso", "%d", 1);
     2.9  		if (err) {
    2.10  			message = "writing feature-tso";
    2.11  			goto abort_transaction;
    2.12  		}
    2.13 +#endif
    2.14  
    2.15  		err = xenbus_transaction_end(xbt, 0);
    2.16  	} while (err == -EAGAIN);
     3.1 --- a/xen/include/public/io/netif.h	Thu Jun 29 16:59:47 2006 +0100
     3.2 +++ b/xen/include/public/io/netif.h	Thu Jun 29 19:02:45 2006 +0100
     3.3 @@ -23,8 +23,9 @@
     3.4   * This is the 'wire' format for packets:
     3.5   *  Request 1: netif_tx_request -- NETTXF_* (any flags)
     3.6   * [Request 2: netif_tx_extra]  (only if request 1 has NETTXF_extra_info)
     3.7 - *  Request 3: netif_tx_request -- NETTXF_more_data
     3.8 + * [Request 3: netif_tx_extra]  (only if request 2 has XEN_NETIF_EXTRA_MORE)
     3.9   *  Request 4: netif_tx_request -- NETTXF_more_data
    3.10 + *  Request 5: netif_tx_request -- NETTXF_more_data
    3.11   *  ...
    3.12   *  Request N: netif_tx_request -- 0
    3.13   */
    3.14 @@ -41,12 +42,9 @@
    3.15  #define _NETTXF_more_data      (2)
    3.16  #define  NETTXF_more_data      (1U<<_NETTXF_more_data)
    3.17  
    3.18 -/* Packet has GSO fields in the following descriptor (netif_tx_extra.u.gso). */
    3.19 -#define _NETTXF_gso            (3)
    3.20 -#define  NETTXF_gso            (1U<<_NETTXF_gso)
    3.21 -
    3.22 -/* This descriptor is followed by an extra-info descriptor (netif_tx_extra). */
    3.23 -#define  NETTXF_extra_info     (NETTXF_gso)
    3.24 +/* Packet to be followed by extra descriptor(s). */
    3.25 +#define _NETTXF_extra_info     (3)
    3.26 +#define  NETTXF_extra_info     (1U<<_NETTXF_extra_info)
    3.27  
    3.28  struct netif_tx_request {
    3.29      grant_ref_t gref;      /* Reference to buffer page */
    3.30 @@ -57,14 +55,45 @@ struct netif_tx_request {
    3.31  };
    3.32  typedef struct netif_tx_request netif_tx_request_t;
    3.33  
    3.34 -/* This structure needs to fit within netif_tx_request for compatibility. */
    3.35 -struct netif_tx_extra {
    3.36 +/* Types of netif_extra_info descriptors. */
    3.37 +#define XEN_NETIF_EXTRA_TYPE_NONE  (0)  /* Never used - invalid */
    3.38 +#define XEN_NETIF_EXTRA_TYPE_GSO   (1)  /* u.gso */
    3.39 +#define XEN_NETIF_EXTRA_TYPE_MAX   (2)
    3.40 +
    3.41 +/* netif_extra_info flags. */
    3.42 +#define _XEN_NETIF_EXTRA_FLAG_MORE (0)
    3.43 +#define XEN_NETIF_EXTRA_FLAG_MORE  (1U<<_XEN_NETIF_EXTRA_MORE)
    3.44 +
    3.45 +/* GSO types - only TCPv4 currently supported. */
    3.46 +#define XEN_NETIF_GSO_TCPV4        (1)
    3.47 +
    3.48 +/*
    3.49 + * This structure needs to fit within both netif_tx_request and
    3.50 + * netif_rx_response for compatibility.
    3.51 + */
    3.52 +struct netif_extra_info {
    3.53 +    uint8_t type;  /* XEN_NETIF_EXTRA_TYPE_* */
    3.54 +    uint8_t flags; /* XEN_NETIF_EXTRA_FLAG_* */
    3.55 +
    3.56      union {
    3.57 -        /* NETTXF_gso: Generic Segmentation Offload. */
    3.58 -        struct netif_tx_gso {
    3.59 -            uint16_t size;	   /* GSO MSS. */
    3.60 -            uint16_t segs;	   /* GSO segment count. */
    3.61 -            uint16_t type;	   /* GSO type. */
    3.62 +        struct {
    3.63 +            /*
    3.64 +             * Maximum payload size of each segment.  For example, for TCP this
    3.65 +             * is just the path MSS.
    3.66 +             */
    3.67 +            uint16_t size;
    3.68 +
    3.69 +            /*
    3.70 +             * Number of GSO segments.  This is the number of segments that
    3.71 +             * have to be generated for this packet given the MSS.
    3.72 +             */
    3.73 +            uint16_t segs;
    3.74 +
    3.75 +            /*
    3.76 +             * GSO type.  This determines the protocol of the packet and any
    3.77 +             * extra features required to segment the packet properly.
    3.78 +             */
    3.79 +            uint16_t type; /* XEN_NETIF_GSO_* */
    3.80          } gso;
    3.81      } u;
    3.82  };