ia64/xen-unstable

changeset 10173:c9c40f6baba0

[NET] front: Use netif_carrier to model backend-connection state.

The tristate backend_state really only needs to be a boolean. In fact
other virtualisation network drivers such as the s390 already model this
using netif_carrier_*. So by converting backend_state over to the net
carrier flag we can tap into existing infrastructure rather than creating
new ones.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
author kaf24@firebug.cl.cam.ac.uk
date Thu May 25 14:29:21 2006 +0100 (2006-05-25)
parents e0bbba2b9850
children 0f162a135140
files linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu May 25 14:15:49 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu May 25 14:29:21 2006 +0100
     1.3 @@ -89,12 +89,6 @@ struct netfront_info {
     1.4  	unsigned int handle;
     1.5  	unsigned int evtchn, irq;
     1.6  
     1.7 -	/* What is the status of our connection to the remote backend? */
     1.8 -#define BEST_CLOSED       0
     1.9 -#define BEST_DISCONNECTED 1
    1.10 -#define BEST_CONNECTED    2
    1.11 -	unsigned int backend_state;
    1.12 -
    1.13  	/* Receive-ring batched refills. */
    1.14  #define RX_MIN_TARGET 8
    1.15  #define RX_DFL_MIN_TARGET 64
    1.16 @@ -144,14 +138,6 @@ static inline unsigned short get_id_from
    1.17  	return id;
    1.18  }
    1.19  
    1.20 -#ifdef DEBUG
    1.21 -static const char *be_state_name[] = {
    1.22 -	[BEST_CLOSED]       = "closed",
    1.23 -	[BEST_DISCONNECTED] = "disconnected",
    1.24 -	[BEST_CONNECTED]    = "connected",
    1.25 -};
    1.26 -#endif
    1.27 -
    1.28  #define DPRINTK(fmt, args...) pr_debug("netfront (%s:%d) " fmt, \
    1.29                                         __FUNCTION__, __LINE__, ##args)
    1.30  #define IPRINTK(fmt, args...)				\
    1.31 @@ -342,7 +328,6 @@ static int setup_device(struct xenbus_de
    1.32  	}
    1.33  	memset(txs, 0, PAGE_SIZE);
    1.34  	memset(rxs, 0, PAGE_SIZE);
    1.35 -	info->backend_state = BEST_DISCONNECTED;
    1.36  
    1.37  	SHARED_RING_INIT(txs);
    1.38  	FRONT_RING_INIT(&info->tx, txs, PAGE_SIZE);
    1.39 @@ -465,7 +450,7 @@ static void network_tx_buf_gc(struct net
    1.40  	struct netfront_info *np = netdev_priv(dev);
    1.41  	struct sk_buff *skb;
    1.42  
    1.43 -	if (np->backend_state != BEST_CONNECTED)
    1.44 +	if (unlikely(!netif_carrier_ok(dev)))
    1.45  		return;
    1.46  
    1.47  	do {
    1.48 @@ -527,7 +512,7 @@ static void network_alloc_rx_buffers(str
    1.49  	struct xen_memory_reservation reservation;
    1.50  	grant_ref_t ref;
    1.51  
    1.52 -	if (unlikely(np->backend_state != BEST_CONNECTED))
    1.53 +	if (unlikely(!netif_carrier_ok(dev)))
    1.54  		return;
    1.55  
    1.56  	/*
    1.57 @@ -662,7 +647,7 @@ static int network_start_xmit(struct sk_
    1.58  
    1.59  	spin_lock_irq(&np->tx_lock);
    1.60  
    1.61 -	if (np->backend_state != BEST_CONNECTED) {
    1.62 +	if (unlikely(!netif_carrier_ok(dev))) {
    1.63  		spin_unlock_irq(&np->tx_lock);
    1.64  		goto drop;
    1.65  	}
    1.66 @@ -748,7 +733,7 @@ static int netif_poll(struct net_device 
    1.67  
    1.68  	spin_lock(&np->rx_lock);
    1.69  
    1.70 -	if (np->backend_state != BEST_CONNECTED) {
    1.71 +	if (unlikely(!netif_carrier_ok(dev))) {
    1.72  		spin_unlock(&np->rx_lock);
    1.73  		return 0;
    1.74  	}
    1.75 @@ -1041,7 +1026,7 @@ static void network_connect(struct net_d
    1.76  	 * domain a kick because we've probably just requeued some
    1.77  	 * packets.
    1.78  	 */
    1.79 -	np->backend_state = BEST_CONNECTED;
    1.80 +	netif_carrier_on(dev);
    1.81  	notify_remote_via_irq(np->irq);
    1.82  	network_tx_buf_gc(dev);
    1.83  
    1.84 @@ -1055,7 +1040,7 @@ static void show_device(struct netfront_
    1.85  	if (np) {
    1.86  		IPRINTK("<vif handle=%u %s(%s) evtchn=%u tx=%p rx=%p>\n",
    1.87  			np->handle,
    1.88 -			be_state_name[np->backend_state],
    1.89 +			netif_carrier_ok(np->netdev) ? "on" : "off",
    1.90  			netif_running(np->netdev) ? "open" : "closed",
    1.91  			np->evtchn,
    1.92  			np->tx,
    1.93 @@ -1241,10 +1226,11 @@ static struct net_device * __devinit cre
    1.94  	}
    1.95  
    1.96  	np                = netdev_priv(netdev);
    1.97 -	np->backend_state = BEST_CLOSED;
    1.98  	np->handle        = handle;
    1.99  	np->xbdev         = dev;
   1.100  
   1.101 +	netif_carrier_off(netdev);
   1.102 +
   1.103  	spin_lock_init(&np->tx_lock);
   1.104  	spin_lock_init(&np->rx_lock);
   1.105  
   1.106 @@ -1392,7 +1378,7 @@ static void netif_disconnect_backend(str
   1.107  	/* Stop old i/f to prevent errors whilst we rebuild the state. */
   1.108  	spin_lock_irq(&info->tx_lock);
   1.109  	spin_lock(&info->rx_lock);
   1.110 -	info->backend_state = BEST_DISCONNECTED;
   1.111 +	netif_carrier_off(info->netdev);
   1.112  	spin_unlock(&info->rx_lock);
   1.113  	spin_unlock_irq(&info->tx_lock);
   1.114