ia64/xen-unstable

changeset 11201:41130540891e

[NET] front: Improve correctness when there is no connection to backend driver.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Thu Aug 17 19:11:14 2006 +0100 (2006-08-17)
parents a73aa6ec4c76
children c39d7d8379ad
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 Aug 17 18:45:59 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu Aug 17 19:11:14 2006 +0100
     1.3 @@ -456,7 +456,8 @@ static int setup_device(struct xenbus_de
     1.4  
     1.5  	memcpy(netdev->dev_addr, info->mac, ETH_ALEN);
     1.6  	err = bind_evtchn_to_irqhandler(info->evtchn, netif_int,
     1.7 -					SA_SAMPLE_RANDOM, netdev->name, netdev);
     1.8 +					SA_SAMPLE_RANDOM, netdev->name,
     1.9 +					netdev);
    1.10  	if (err < 0)
    1.11  		goto fail;
    1.12  	info->irq = err;
    1.13 @@ -535,11 +536,14 @@ static int network_open(struct net_devic
    1.14  
    1.15  	memset(&np->stats, 0, sizeof(np->stats));
    1.16  
    1.17 -	network_alloc_rx_buffers(dev);
    1.18 -	np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
    1.19 -
    1.20 -	if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
    1.21 -		netif_rx_schedule(dev);
    1.22 +	spin_lock(&np->rx_lock);
    1.23 +	if (netif_carrier_ok(dev)) {
    1.24 +		network_alloc_rx_buffers(dev);
    1.25 +		np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
    1.26 +		if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
    1.27 +			netif_rx_schedule(dev);
    1.28 +	}
    1.29 +	spin_unlock(&np->rx_lock);
    1.30  
    1.31  	netif_start_queue(dev);
    1.32  
    1.33 @@ -568,8 +572,7 @@ static void network_tx_buf_gc(struct net
    1.34  	struct netfront_info *np = netdev_priv(dev);
    1.35  	struct sk_buff *skb;
    1.36  
    1.37 -	if (unlikely(!netif_carrier_ok(dev)))
    1.38 -		return;
    1.39 +	BUG_ON(!netif_carrier_ok(dev));
    1.40  
    1.41  	do {
    1.42  		prod = np->tx.sring->rsp_prod;
    1.43 @@ -961,12 +964,15 @@ static irqreturn_t netif_int(int irq, vo
    1.44  	unsigned long flags;
    1.45  
    1.46  	spin_lock_irqsave(&np->tx_lock, flags);
    1.47 -	network_tx_buf_gc(dev);
    1.48 -	spin_unlock_irqrestore(&np->tx_lock, flags);
    1.49  
    1.50 -	if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx) &&
    1.51 -	    likely(netif_running(dev)))
    1.52 -		netif_rx_schedule(dev);
    1.53 +	if (likely(netif_carrier_ok(dev))) {
    1.54 +		network_tx_buf_gc(dev);
    1.55 +		/* Under tx_lock: protects access to rx shared-ring indexes. */
    1.56 +		if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
    1.57 +			netif_rx_schedule(dev);
    1.58 +	}
    1.59 +
    1.60 +	spin_unlock_irqrestore(&np->tx_lock, flags);
    1.61  
    1.62  	return IRQ_HANDLED;
    1.63  }