ia64/xen-unstable

changeset 11802:7da100019e00

[NET] front: Do not read features from backend until it enters InitWait.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Oct 13 18:04:33 2006 +0100 (2006-10-13)
parents efea4c3b8bcc
children b725c9e51a7c edcd3a25a2bd
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	Fri Oct 13 17:10:27 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Fri Oct 13 18:04:33 2006 +0100
     1.3 @@ -229,9 +229,8 @@ static inline grant_ref_t xennet_get_rx_
     1.4  #define WPRINTK(fmt, args...)				\
     1.5  	printk(KERN_WARNING "netfront: " fmt, ##args)
     1.6  
     1.7 -static int talk_to_backend(struct xenbus_device *, struct netfront_info *);
     1.8  static int setup_device(struct xenbus_device *, struct netfront_info *);
     1.9 -static struct net_device *create_netdev(int, struct xenbus_device *);
    1.10 +static struct net_device *create_netdev(struct xenbus_device *);
    1.11  
    1.12  static void netfront_closing(struct xenbus_device *);
    1.13  
    1.14 @@ -241,7 +240,7 @@ static int open_netdev(struct netfront_i
    1.15  static void close_netdev(struct netfront_info *);
    1.16  static void netif_free(struct netfront_info *);
    1.17  
    1.18 -static void network_connect(struct net_device *);
    1.19 +static int network_connect(struct net_device *);
    1.20  static void network_tx_buf_gc(struct net_device *);
    1.21  static void network_alloc_rx_buffers(struct net_device *);
    1.22  static int send_fake_arp(struct net_device *);
    1.23 @@ -264,8 +263,7 @@ static inline int xennet_can_sg(struct n
    1.24  /**
    1.25   * Entry point to this code when a new device is created.  Allocate the basic
    1.26   * structures and the ring buffers for communication with the backend, and
    1.27 - * inform the backend of the appropriate details for those.  Switch to
    1.28 - * Connected state.
    1.29 + * inform the backend of the appropriate details for those.
    1.30   */
    1.31  static int __devinit netfront_probe(struct xenbus_device *dev,
    1.32  				    const struct xenbus_device_id *id)
    1.33 @@ -273,26 +271,8 @@ static int __devinit netfront_probe(stru
    1.34  	int err;
    1.35  	struct net_device *netdev;
    1.36  	struct netfront_info *info;
    1.37 -	unsigned int feature_rx_copy, feature_rx_flip, use_copy;
    1.38  
    1.39 -	err = xenbus_scanf(XBT_NIL, dev->otherend, "feature-rx-copy", "%u",
    1.40 -			   &feature_rx_copy);
    1.41 -	if (err != 1)
    1.42 -		feature_rx_copy = 0;
    1.43 -	err = xenbus_scanf(XBT_NIL, dev->otherend, "feature-rx-flip", "%u",
    1.44 -			   &feature_rx_flip);
    1.45 -	if (err != 1)
    1.46 -		feature_rx_flip = 1;
    1.47 -
    1.48 -	/*
    1.49 -	 * Copy packets on receive path if:
    1.50 -	 *  (a) This was requested by user, and the backend supports it; or
    1.51 -	 *  (b) Flipping was requested, but this is unsupported by the backend.
    1.52 -	 */
    1.53 -	use_copy = (MODPARM_rx_copy && feature_rx_copy) ||
    1.54 -		(MODPARM_rx_flip && !feature_rx_flip);
    1.55 -
    1.56 -	netdev = create_netdev(use_copy, dev);
    1.57 +	netdev = create_netdev(dev);
    1.58  	if (IS_ERR(netdev)) {
    1.59  		err = PTR_ERR(netdev);
    1.60  		xenbus_dev_fatal(dev, err, "creating netdev");
    1.61 @@ -302,23 +282,13 @@ static int __devinit netfront_probe(stru
    1.62  	info = netdev_priv(netdev);
    1.63  	dev->dev.driver_data = info;
    1.64  
    1.65 -	err = talk_to_backend(dev, info);
    1.66 -	if (err)
    1.67 -		goto fail_backend;
    1.68 -
    1.69  	err = open_netdev(info);
    1.70  	if (err)
    1.71 -		goto fail_open;
    1.72 -
    1.73 -	IPRINTK("Created netdev %s with %sing receive path.\n",
    1.74 -		netdev->name, info->copying_receiver ? "copy" : "flipp");
    1.75 +		goto fail;
    1.76  
    1.77  	return 0;
    1.78  
    1.79 - fail_open:
    1.80 -	xennet_sysfs_delif(info->netdev);
    1.81 -	unregister_netdev(netdev);
    1.82 - fail_backend:
    1.83 + fail:
    1.84  	free_netdev(netdev);
    1.85  	dev->dev.driver_data = NULL;
    1.86  	return err;
    1.87 @@ -338,7 +308,7 @@ static int netfront_resume(struct xenbus
    1.88  	DPRINTK("%s\n", dev->nodename);
    1.89  
    1.90  	netif_disconnect_backend(info);
    1.91 -	return talk_to_backend(dev, info);
    1.92 +	return 0;
    1.93  }
    1.94  
    1.95  static int xen_net_read_mac(struct xenbus_device *dev, u8 mac[])
    1.96 @@ -449,7 +419,7 @@ again:
    1.97  	xenbus_transaction_end(xbt, 1);
    1.98  	xenbus_dev_fatal(dev, err, "%s", message);
    1.99   destroy_ring:
   1.100 -	netif_free(info);
   1.101 +	netif_disconnect_backend(info);
   1.102   out:
   1.103  	return err;
   1.104  }
   1.105 @@ -539,7 +509,10 @@ static void backend_changed(struct xenbu
   1.106  		break;
   1.107  
   1.108  	case XenbusStateInitWait:
   1.109 -		network_connect(netdev);
   1.110 +		if (network_connect(netdev) != 0) {
   1.111 +			netif_free(np);
   1.112 +			break;
   1.113 +		}
   1.114  		xenbus_switch_state(dev, XenbusStateConnected);
   1.115  		(void)send_fake_arp(netdev);
   1.116  		break;
   1.117 @@ -1644,16 +1617,41 @@ static void xennet_set_features(struct n
   1.118  		xennet_set_tso(dev, 1);
   1.119  }
   1.120  
   1.121 -static void network_connect(struct net_device *dev)
   1.122 +static int network_connect(struct net_device *dev)
   1.123  {
   1.124  	struct netfront_info *np = netdev_priv(dev);
   1.125 -	int i, requeue_idx;
   1.126 +	int i, requeue_idx, err;
   1.127  	struct sk_buff *skb;
   1.128  	grant_ref_t ref;
   1.129  	netif_rx_request_t *req;
   1.130 +	unsigned int feature_rx_copy, feature_rx_flip;
   1.131 +
   1.132 +	err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
   1.133 +			   "feature-rx-copy", "%u", &feature_rx_copy);
   1.134 +	if (err != 1)
   1.135 +		feature_rx_copy = 0;
   1.136 +	err = xenbus_scanf(XBT_NIL, np->xbdev->otherend,
   1.137 +			   "feature-rx-flip", "%u", &feature_rx_flip);
   1.138 +	if (err != 1)
   1.139 +		feature_rx_flip = 1;
   1.140 +
   1.141 +	/*
   1.142 +	 * Copy packets on receive path if:
   1.143 +	 *  (a) This was requested by user, and the backend supports it; or
   1.144 +	 *  (b) Flipping was requested, but this is unsupported by the backend.
   1.145 +	 */
   1.146 +	np->copying_receiver = ((MODPARM_rx_copy && feature_rx_copy) ||
   1.147 +				(MODPARM_rx_flip && !feature_rx_flip));
   1.148 +
   1.149 +	err = talk_to_backend(np->xbdev, np);
   1.150 +	if (err)
   1.151 +		return err;
   1.152  
   1.153  	xennet_set_features(dev);
   1.154  
   1.155 +	IPRINTK("device %s has %sing receive path.\n",
   1.156 +		dev->name, np->copying_receiver ? "copy" : "flipp");
   1.157 +
   1.158  	spin_lock_irq(&np->tx_lock);
   1.159  	spin_lock(&np->rx_lock);
   1.160  
   1.161 @@ -1709,6 +1707,8 @@ static void network_connect(struct net_d
   1.162  
   1.163  	spin_unlock(&np->rx_lock);
   1.164  	spin_unlock_irq(&np->tx_lock);
   1.165 +
   1.166 +	return 0;
   1.167  }
   1.168  
   1.169  static void netif_uninit(struct net_device *dev)
   1.170 @@ -1874,8 +1874,7 @@ static void network_set_multicast_list(s
   1.171  {
   1.172  }
   1.173  
   1.174 -static struct net_device * __devinit
   1.175 -create_netdev(int copying_receiver, struct xenbus_device *dev)
   1.176 +static struct net_device * __devinit create_netdev(struct xenbus_device *dev)
   1.177  {
   1.178  	int i, err = 0;
   1.179  	struct net_device *netdev = NULL;
   1.180 @@ -1890,7 +1889,6 @@ create_netdev(int copying_receiver, stru
   1.181  
   1.182  	np                   = netdev_priv(netdev);
   1.183  	np->xbdev            = dev;
   1.184 -	np->copying_receiver = copying_receiver;
   1.185  
   1.186  	netif_carrier_off(netdev);
   1.187  
   1.188 @@ -2021,10 +2019,12 @@ static int open_netdev(struct netfront_i
   1.189  
   1.190  	err = xennet_sysfs_addif(info->netdev);
   1.191  	if (err) {
   1.192 -		/* This can be non-fatal: it only means no tuning parameters */
   1.193 +		unregister_netdev(info->netdev);
   1.194  		printk(KERN_WARNING "%s: add sysfs failed err=%d\n",
   1.195  		       __FUNCTION__, err);
   1.196 +		return err;
   1.197  	}
   1.198 +
   1.199  	return 0;
   1.200  }
   1.201