ia64/linux-2.6.18-xen.hg

changeset 243:9c9881c9037b

netfront/back: Configure network acceleration using ethernet device name.
Signed-off-by: Kieran Mansley <kmansley@solarflare.com>
author Keir Fraser <keir@xensource.com>
date Wed Oct 03 14:58:45 2007 +0100 (2007-10-03)
parents 01ad7d0797c6
children df158d6b9e57
files drivers/xen/netback/accel.c drivers/xen/netback/common.h drivers/xen/netfront/netfront.c
line diff
     1.1 --- a/drivers/xen/netback/accel.c	Wed Oct 03 14:53:41 2007 +0100
     1.2 +++ b/drivers/xen/netback/accel.c	Wed Oct 03 14:58:45 2007 +0100
     1.3 @@ -55,15 +55,24 @@ static spinlock_t accelerators_lock;
     1.4   * compatible (i.e. if the accelerator should be used by the
     1.5   * backend) 
     1.6   */
     1.7 -static int match_accelerator(struct backend_info *be, 
     1.8 +static int match_accelerator(struct xenbus_device *xendev,
     1.9 +			     struct backend_info *be, 
    1.10  			     struct netback_accelerator *accelerator)
    1.11  {
    1.12 -	/*
    1.13 -	 * This could do with being more sophisticated.  For example,
    1.14 -	 * determine which hardware is being used by each backend from
    1.15 -	 * the bridge and network topology of the domain
    1.16 -	 */
    1.17 -	return be->accelerator == NULL;
    1.18 +	int rc = 0;
    1.19 +	char *eth_name = xenbus_read(XBT_NIL, xendev->nodename, "accel", NULL);
    1.20 +	
    1.21 +	if (IS_ERR(eth_name)) {
    1.22 +		/* Probably means not present */
    1.23 +		DPRINTK("%s: no match due to xenbus_read accel error %d\n", 
    1.24 +			__FUNCTION__, PTR_ERR(eth_name));
    1.25 +		return 0;
    1.26 +	} else {
    1.27 +		if (!strcmp(eth_name, accelerator->eth_name))
    1.28 +			rc = 1;
    1.29 +		kfree(eth_name);
    1.30 +		return rc;
    1.31 +	}
    1.32  }
    1.33  
    1.34  /*
    1.35 @@ -80,7 +89,7 @@ static int netback_accelerator_tell_back
    1.36  	if (!strcmp("vif", xendev->devicetype)) {
    1.37  		struct backend_info *be = xendev->dev.driver_data;
    1.38  
    1.39 -		if (match_accelerator(be, accelerator)) {
    1.40 +		if (match_accelerator(xendev, be, accelerator)) {
    1.41  			be->accelerator = accelerator;
    1.42  			atomic_inc(&be->accelerator->use_count);
    1.43  			be->accelerator->hooks->probe(xendev);
    1.44 @@ -94,12 +103,12 @@ static int netback_accelerator_tell_back
    1.45   * Entry point for an netback accelerator plugin module.  Called to
    1.46   * advertise its presence, and connect to any suitable backends.
    1.47   */
    1.48 -void netback_connect_accelerator(int id, const char *frontend, 
    1.49 +void netback_connect_accelerator(int id, const char *eth_name, 
    1.50  				 struct netback_accel_hooks *hooks)
    1.51  {
    1.52  	struct netback_accelerator *new_accelerator = 
    1.53  		kmalloc(sizeof(struct netback_accelerator), GFP_KERNEL);
    1.54 -	unsigned frontend_len, flags;
    1.55 +	unsigned eth_name_len, flags;
    1.56  
    1.57  	if (!new_accelerator) {
    1.58  		DPRINTK("%s: failed to allocate memory for accelerator\n",
    1.59 @@ -109,15 +118,15 @@ void netback_connect_accelerator(int id,
    1.60  
    1.61  	new_accelerator->id = id;
    1.62  	
    1.63 -	frontend_len = strlen(frontend)+1;
    1.64 -	new_accelerator->frontend = kmalloc(frontend_len, GFP_KERNEL);
    1.65 -	if (!new_accelerator->frontend) {
    1.66 -		DPRINTK("%s: failed to allocate memory for frontend string\n",
    1.67 +	eth_name_len = strlen(eth_name)+1;
    1.68 +	new_accelerator->eth_name = kmalloc(eth_name_len, GFP_KERNEL);
    1.69 +	if (!new_accelerator->eth_name) {
    1.70 +		DPRINTK("%s: failed to allocate memory for eth_name string\n",
    1.71  			__FUNCTION__);
    1.72  		kfree(new_accelerator);
    1.73  		return;
    1.74  	}
    1.75 -	strlcpy(new_accelerator->frontend, frontend, frontend_len);
    1.76 +	strlcpy(new_accelerator->eth_name, eth_name, eth_name_len);
    1.77  	
    1.78  	new_accelerator->hooks = hooks;
    1.79  
    1.80 @@ -136,7 +145,25 @@ EXPORT_SYMBOL_GPL(netback_connect_accele
    1.81  
    1.82  
    1.83  /* 
    1.84 - * Disconnect an accerator plugin module that has previously been
    1.85 + * Remove the link from backend state to a particular accelerator
    1.86 + */ 
    1.87 +static int netback_accelerator_cleanup_backend(struct device *dev, void *arg)
    1.88 +{
    1.89 +	struct netback_accelerator *accelerator = 
    1.90 +		(struct netback_accelerator *)arg;
    1.91 +	struct xenbus_device *xendev = to_xenbus_device(dev);
    1.92 +
    1.93 +	if (!strcmp("vif", xendev->devicetype)) {
    1.94 +		struct backend_info *be = xendev->dev.driver_data;
    1.95 +		if (be->accelerator == accelerator)
    1.96 +			be->accelerator = NULL;
    1.97 +	}
    1.98 +	return 0;
    1.99 +}
   1.100 +
   1.101 +
   1.102 +/* 
   1.103 + * Disconnect an accelerator plugin module that has previously been
   1.104   * connected.
   1.105   *
   1.106   * This should only be allowed when there are no remaining users -
   1.107 @@ -144,18 +171,22 @@ EXPORT_SYMBOL_GPL(netback_connect_accele
   1.108   * they should have already been removed.  This is enforced through a
   1.109   * usage count and BUG_ON(use!=0), but should be made more user-friendly
   1.110   */
   1.111 -void netback_disconnect_accelerator(int id, const char *frontend)
   1.112 +void netback_disconnect_accelerator(int id, const char *eth_name)
   1.113  {
   1.114  	struct netback_accelerator *accelerator, *next;
   1.115  	unsigned flags;
   1.116  
   1.117  	spin_lock_irqsave(&accelerators_lock, flags);
   1.118  	list_for_each_entry_safe(accelerator, next, &accelerators_list, link) {
   1.119 -		if (strcmp(frontend, accelerator->frontend)) {
   1.120 +		if (strcmp(eth_name, accelerator->eth_name)) {
   1.121  			BUG_ON(atomic_read(&accelerator->use_count) != 0);
   1.122  			list_del(&accelerator->link);
   1.123  			spin_unlock_irqrestore(&accelerators_lock, flags);
   1.124 -			kfree(accelerator->frontend);
   1.125 +
   1.126 +			xenbus_for_each_backend(accelerator, 
   1.127 +						netback_accelerator_cleanup_backend);
   1.128 +				
   1.129 +			kfree(accelerator->eth_name);
   1.130  			kfree(accelerator);
   1.131  			return;
   1.132  		}
   1.133 @@ -177,7 +208,7 @@ void netback_probe_accelerators(struct b
   1.134  	 */
   1.135  	spin_lock_irqsave(&accelerators_lock, flags);
   1.136  	list_for_each_entry(accelerator, &accelerators_list, link) { 
   1.137 -		if (match_accelerator(be, accelerator)) {
   1.138 +		if (match_accelerator(dev, be, accelerator)) {
   1.139  			be->accelerator = accelerator;
   1.140  			atomic_inc(&be->accelerator->use_count);
   1.141  			be->accelerator->hooks->probe(dev);
     2.1 --- a/drivers/xen/netback/common.h	Wed Oct 03 14:53:41 2007 +0100
     2.2 +++ b/drivers/xen/netback/common.h	Wed Oct 03 14:58:45 2007 +0100
     2.3 @@ -133,7 +133,7 @@ struct netback_accel_hooks {
     2.4  struct netback_accelerator {
     2.5  	struct list_head link;
     2.6  	int id;
     2.7 -	char *frontend;
     2.8 +	char *eth_name;
     2.9  	atomic_t use_count;
    2.10  	struct netback_accel_hooks *hooks;
    2.11  };
    2.12 @@ -150,10 +150,10 @@ struct backend_info {
    2.13  };
    2.14  
    2.15  /* Connect an accelerator plugin module to netback */
    2.16 -extern void netback_connect_accelerator(int id, const char *frontend, 
    2.17 +extern void netback_connect_accelerator(int id, const char *eth_name, 
    2.18  					struct netback_accel_hooks *hooks);
    2.19 -/* Disconnect a previously connected accelerator pluging module */
    2.20 -extern void netback_disconnect_accelerator(int id, const char *frontend);
    2.21 +/* Disconnect a previously connected accelerator plugin module */
    2.22 +extern void netback_disconnect_accelerator(int id, const char *eth_name);
    2.23  
    2.24  
    2.25  extern
     3.1 --- a/drivers/xen/netfront/netfront.c	Wed Oct 03 14:53:41 2007 +0100
     3.2 +++ b/drivers/xen/netfront/netfront.c	Wed Oct 03 14:58:45 2007 +0100
     3.3 @@ -1761,7 +1761,7 @@ static int network_connect(struct net_de
     3.4  
     3.5  	feature_accel = 1;
     3.6  	accel_frontend = xenbus_read(XBT_NIL, np->xbdev->otherend, 
     3.7 -				     "accel", &accel_len);
     3.8 +				     "accel-frontend", &accel_len);
     3.9  	if (IS_ERR(accel_frontend)) 
    3.10  		feature_accel = 0;
    3.11