ia64/xen-unstable

changeset 10859:2e91ad1a89ce

[NET] back: Replace netif->status with netif_carrier_ok

The connection status to the frontend can be represented using
netif_carrier_ok instead of netif->status. As a result, we delay
the construction of the dev qdisc until the carrier comes on. This
is a prerequisite for adding a tx queue.

By the same token, netif->active is now simply the conjunction of
netif_running and netif_carrier_ok so it too can be removed.

Because netif_carrier_off/netif_carrier_on and rtnl_lock all entail
memory barriers, there is no need to have extra memory barriers around
them.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
author kfraser@localhost.localdomain
date Fri Jul 28 17:04:55 2006 +0100 (2006-07-28)
parents 275660d492c6
children 23c37bc942da
files linux-2.6-xen-sparse/drivers/xen/netback/common.h linux-2.6-xen-sparse/drivers/xen/netback/interface.c linux-2.6-xen-sparse/drivers/xen/netback/netback.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Fri Jul 28 17:03:26 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h	Fri Jul 28 17:04:55 2006 +0100
     1.3 @@ -86,8 +86,6 @@ typedef struct netif_st {
     1.4  	struct timer_list credit_timeout;
     1.5  
     1.6  	/* Miscellaneous private stuff. */
     1.7 -	enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
     1.8 -	int active;
     1.9  	struct list_head list;  /* scheduling list */
    1.10  	atomic_t         refcnt;
    1.11  	struct net_device *dev;
     2.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Fri Jul 28 17:03:26 2006 +0100
     2.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c	Fri Jul 28 17:04:55 2006 +0100
     2.3 @@ -36,28 +36,20 @@
     2.4  
     2.5  static void __netif_up(netif_t *netif)
     2.6  {
     2.7 -	struct net_device *dev = netif->dev;
     2.8 -	netif_tx_lock_bh(dev);
     2.9 -	netif->active = 1;
    2.10 -	netif_tx_unlock_bh(dev);
    2.11  	enable_irq(netif->irq);
    2.12  	netif_schedule_work(netif);
    2.13  }
    2.14  
    2.15  static void __netif_down(netif_t *netif)
    2.16  {
    2.17 -	struct net_device *dev = netif->dev;
    2.18  	disable_irq(netif->irq);
    2.19 -	netif_tx_lock_bh(dev);
    2.20 -	netif->active = 0;
    2.21 -	netif_tx_unlock_bh(dev);
    2.22  	netif_deschedule_work(netif);
    2.23  }
    2.24  
    2.25  static int net_open(struct net_device *dev)
    2.26  {
    2.27  	netif_t *netif = netdev_priv(dev);
    2.28 -	if (netif->status == CONNECTED)
    2.29 +	if (netif_carrier_ok(dev))
    2.30  		__netif_up(netif);
    2.31  	netif_start_queue(dev);
    2.32  	return 0;
    2.33 @@ -67,7 +59,7 @@ static int net_close(struct net_device *
    2.34  {
    2.35  	netif_t *netif = netdev_priv(dev);
    2.36  	netif_stop_queue(dev);
    2.37 -	if (netif->status == CONNECTED)
    2.38 +	if (netif_carrier_ok(dev))
    2.39  		__netif_down(netif);
    2.40  	return 0;
    2.41  }
    2.42 @@ -93,11 +85,12 @@ netif_t *netif_alloc(domid_t domid, unsi
    2.43  		return ERR_PTR(-ENOMEM);
    2.44  	}
    2.45  
    2.46 +	netif_carrier_off(dev);
    2.47 +
    2.48  	netif = netdev_priv(dev);
    2.49  	memset(netif, 0, sizeof(*netif));
    2.50  	netif->domid  = domid;
    2.51  	netif->handle = handle;
    2.52 -	netif->status = DISCONNECTED;
    2.53  	atomic_set(&netif->refcnt, 1);
    2.54  	init_waitqueue_head(&netif->waiting_to_free);
    2.55  	netif->dev = dev;
    2.56 @@ -256,11 +249,9 @@ int netif_map(netif_t *netif, unsigned l
    2.57  	netif->rx_req_cons_peek = 0;
    2.58  
    2.59  	netif_get(netif);
    2.60 -	wmb(); /* Other CPUs see new state before interface is started. */
    2.61  
    2.62  	rtnl_lock();
    2.63 -	netif->status = CONNECTED;
    2.64 -	wmb();
    2.65 +	netif_carrier_on(netif->dev);
    2.66  	if (netif_running(netif->dev))
    2.67  		__netif_up(netif);
    2.68  	rtnl_unlock();
    2.69 @@ -296,20 +287,13 @@ static void netif_free(netif_t *netif)
    2.70  
    2.71  void netif_disconnect(netif_t *netif)
    2.72  {
    2.73 -	switch (netif->status) {
    2.74 -	case CONNECTED:
    2.75 +	if (netif_carrier_ok(netif->dev)) {
    2.76  		rtnl_lock();
    2.77 -		netif->status = DISCONNECTING;
    2.78 -		wmb();
    2.79 +		netif_carrier_off(netif->dev);
    2.80  		if (netif_running(netif->dev))
    2.81  			__netif_down(netif);
    2.82  		rtnl_unlock();
    2.83  		netif_put(netif);
    2.84 -		/* fall through */
    2.85 -	case DISCONNECTED:
    2.86 -		netif_free(netif);
    2.87 -		break;
    2.88 -	default:
    2.89 -		BUG();
    2.90  	}
    2.91 +	netif_free(netif);
    2.92  }
     3.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Fri Jul 28 17:03:26 2006 +0100
     3.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c	Fri Jul 28 17:04:55 2006 +0100
     3.3 @@ -143,7 +143,7 @@ int netif_be_start_xmit(struct sk_buff *
     3.4  	BUG_ON(skb->dev != dev);
     3.5  
     3.6  	/* Drop the packet if the target domain has no receive buffers. */
     3.7 -	if (!netif->active || 
     3.8 +	if (unlikely(!netif_running(dev) || !netif_carrier_ok(dev)) ||
     3.9  	    (netif->rx_req_cons_peek == netif->rx.sring->req_prod) ||
    3.10  	    ((netif->rx_req_cons_peek - netif->rx.rsp_prod_pvt) ==
    3.11  	     NET_RX_RING_SIZE))
    3.12 @@ -404,7 +404,9 @@ static void add_to_net_schedule_list_tai
    3.13  		return;
    3.14  
    3.15  	spin_lock_irq(&net_schedule_list_lock);
    3.16 -	if (!__on_net_schedule_list(netif) && netif->active) {
    3.17 +	if (!__on_net_schedule_list(netif) &&
    3.18 +	    likely(netif_running(netif->dev) &&
    3.19 +		   netif_carrier_ok(netif->dev))) {
    3.20  		list_add_tail(&netif->list, &net_schedule_list);
    3.21  		netif_get(netif);
    3.22  	}