ia64/xen-unstable

changeset 4742:e238f090090a

bitkeeper revision 1.1389.1.31 (42775864fB4WMRbJ6EQfNqZrBAGwDA)

Merge firebug.cl.cam.ac.uk:/local/scratch/kaf24/xen-2.0-testing.bk
into firebug.cl.cam.ac.uk:/local/scratch/kaf24/xen-unstable.bk
author kaf24@firebug.cl.cam.ac.uk
date Tue May 03 10:54:28 2005 +0000 (2005-05-03)
parents 32475149e395 43161b1d961e
children 744388e70e60
files linux-2.6.11-xen-sparse/drivers/xen/netfront/netfront.c
line diff
     1.1 --- a/linux-2.6.11-xen-sparse/drivers/xen/netfront/netfront.c	Tue May 03 07:46:23 2005 +0000
     1.2 +++ b/linux-2.6.11-xen-sparse/drivers/xen/netfront/netfront.c	Tue May 03 10:54:28 2005 +0000
     1.3 @@ -39,6 +39,7 @@
     1.4  #include <linux/skbuff.h>
     1.5  #include <linux/init.h>
     1.6  #include <linux/bitops.h>
     1.7 +#include <linux/proc_fs.h>
     1.8  #include <net/sock.h>
     1.9  #include <net/pkt_sched.h>
    1.10  #include <net/arp.h>
    1.11 @@ -85,6 +86,16 @@ static unsigned long rx_pfn_array[NETIF_
    1.12  static multicall_entry_t rx_mcl[NETIF_RX_RING_SIZE+1];
    1.13  static mmu_update_t rx_mmu[NETIF_RX_RING_SIZE];
    1.14  
    1.15 +#ifdef CONFIG_PROC_FS
    1.16 +static int xennet_proc_init(void);
    1.17 +static int xennet_proc_addif(struct net_device *dev);
    1.18 +static void xennet_proc_delif(struct net_device *dev);
    1.19 +#else
    1.20 +#define xennet_proc_init()   (0)
    1.21 +#define xennet_proc_addif(d) (0)
    1.22 +#define xennet_proc_delif(d) ((void)0)
    1.23 +#endif
    1.24 +
    1.25  static struct list_head dev_list;
    1.26  
    1.27  struct net_private
    1.28 @@ -120,7 +131,7 @@ struct net_private
    1.29      /* Receive-ring batched refills. */
    1.30  #define RX_MIN_TARGET 8
    1.31  #define RX_MAX_TARGET NETIF_RX_RING_SIZE
    1.32 -    int rx_target;
    1.33 +    int rx_min_target, rx_max_target, rx_target;
    1.34      struct sk_buff_head rx_batch;
    1.35  
    1.36      /*
    1.37 @@ -413,8 +424,8 @@ static void network_alloc_rx_buffers(str
    1.38  
    1.39      /* Adjust our floating fill target if we risked running out of buffers. */
    1.40      if (((req_prod - np->rx->resp_prod) < (np->rx_target / 4)) &&
    1.41 -         ((np->rx_target *= 2) > RX_MAX_TARGET))
    1.42 -        np->rx_target = RX_MAX_TARGET;
    1.43 +         ((np->rx_target *= 2) > np->rx_max_target))
    1.44 +        np->rx_target = np->rx_max_target;
    1.45  }
    1.46  
    1.47  
    1.48 @@ -646,8 +657,8 @@ static int netif_poll(struct net_device 
    1.49      /* If we get a callback with very few responses, reduce fill target. */
    1.50      /* NB. Note exponential increase, linear decrease. */
    1.51      if (((np->rx->req_prod - np->rx->resp_prod) > ((3*np->rx_target) / 4)) &&
    1.52 -         (--np->rx_target < RX_MIN_TARGET))
    1.53 -        np->rx_target = RX_MIN_TARGET;
    1.54 +         (--np->rx_target < np->rx_min_target))
    1.55 +        np->rx_target = np->rx_min_target;
    1.56  
    1.57      network_alloc_rx_buffers(dev);
    1.58  
    1.59 @@ -938,7 +949,9 @@ static int create_netdev(int handle, str
    1.60      spin_lock_init(&np->rx_lock);
    1.61  
    1.62      skb_queue_head_init(&np->rx_batch);
    1.63 -    np->rx_target = RX_MIN_TARGET;
    1.64 +    np->rx_target     = RX_MIN_TARGET;
    1.65 +    np->rx_min_target = RX_MIN_TARGET;
    1.66 +    np->rx_max_target = RX_MAX_TARGET;
    1.67  
    1.68      /* Initialise {tx,rx}_skbs to be a free chain containing every entry. */
    1.69      for (i = 0; i <= NETIF_TX_RING_SIZE; i++)
    1.70 @@ -957,11 +970,17 @@ static int create_netdev(int handle, str
    1.71          printk(KERN_WARNING "%s> register_netdev err=%d\n", __FUNCTION__, err);
    1.72          goto exit;
    1.73      }
    1.74 +
    1.75 +    if ((err = xennet_proc_addif(dev)) != 0) {
    1.76 +        unregister_netdev(dev);
    1.77 +        goto exit;
    1.78 +    }
    1.79 +
    1.80      np->dev = dev;
    1.81      list_add(&np->list, &dev_list);
    1.82  
    1.83    exit:
    1.84 -    if ((err != 0) && (dev != NULL ))
    1.85 +    if ((err != 0) && (dev != NULL))
    1.86          kfree(dev);
    1.87      else if (val != NULL)
    1.88          *val = dev;
    1.89 @@ -1238,6 +1257,9 @@ static int __init netif_init(void)
    1.90      if (xen_start_info.flags & SIF_INITDOMAIN)
    1.91          return 0;
    1.92  
    1.93 +    if ((err = xennet_proc_init()) != 0)
    1.94 +        return err;
    1.95 +
    1.96      IPRINTK("Initialising virtual ethernet driver.\n");
    1.97      INIT_LIST_HEAD(&dev_list);
    1.98      (void)register_inetaddr_notifier(&notifier_inetdev);
    1.99 @@ -1295,6 +1317,153 @@ void netif_resume(void)
   1.100      }
   1.101  }
   1.102  
   1.103 +#ifdef CONFIG_PROC_FS
   1.104 +
   1.105 +#define TARGET_MIN 0UL
   1.106 +#define TARGET_MAX 1UL
   1.107 +#define TARGET_CUR 2UL
   1.108 +
   1.109 +static int xennet_proc_read(
   1.110 +    char *page, char **start, off_t off, int count, int *eof, void *data)
   1.111 +{
   1.112 +    struct net_device *dev = (struct net_device *)((unsigned long)data & ~3UL);
   1.113 +    struct net_private *np = netdev_priv(dev);
   1.114 +    int len = 0, which_target = (int)data & 3;
   1.115 +    
   1.116 +    switch (which_target)
   1.117 +    {
   1.118 +    case TARGET_MIN:
   1.119 +        len = sprintf(page, "%d\n", np->rx_min_target);
   1.120 +        break;
   1.121 +    case TARGET_MAX:
   1.122 +        len = sprintf(page, "%d\n", np->rx_max_target);
   1.123 +        break;
   1.124 +    case TARGET_CUR:
   1.125 +        len = sprintf(page, "%d\n", np->rx_target);
   1.126 +        break;
   1.127 +    }
   1.128 +
   1.129 +    *eof = 1;
   1.130 +    return len;
   1.131 +}
   1.132 +
   1.133 +static int xennet_proc_write(
   1.134 +    struct file *file, const char __user *buffer,
   1.135 +    unsigned long count, void *data)
   1.136 +{
   1.137 +    struct net_device *dev = (struct net_device *)((unsigned long)data & ~3UL);
   1.138 +    struct net_private *np = netdev_priv(dev);
   1.139 +    int which_target = (int)data & 3;
   1.140 +    char string[64];
   1.141 +    long target;
   1.142 +
   1.143 +    if (!capable(CAP_SYS_ADMIN))
   1.144 +        return -EPERM;
   1.145 +
   1.146 +    if (count <= 1)
   1.147 +        return -EBADMSG; /* runt */
   1.148 +    if (count > sizeof(string))
   1.149 +        return -EFBIG;   /* too long */
   1.150 +
   1.151 +    if (copy_from_user(string, buffer, count))
   1.152 +        return -EFAULT;
   1.153 +    string[sizeof(string)-1] = '\0';
   1.154 +
   1.155 +    target = simple_strtol(string, NULL, 10);
   1.156 +    if (target < RX_MIN_TARGET)
   1.157 +        target = RX_MIN_TARGET;
   1.158 +    if (target > RX_MAX_TARGET)
   1.159 +        target = RX_MAX_TARGET;
   1.160 +
   1.161 +    spin_lock(&np->rx_lock);
   1.162 +
   1.163 +    switch (which_target)
   1.164 +    {
   1.165 +    case TARGET_MIN:
   1.166 +        if (target > np->rx_max_target)
   1.167 +            np->rx_max_target = target;
   1.168 +        np->rx_min_target = target;
   1.169 +        if (target > np->rx_target)
   1.170 +            np->rx_target = target;
   1.171 +        break;
   1.172 +    case TARGET_MAX:
   1.173 +        if (target < np->rx_min_target)
   1.174 +            np->rx_min_target = target;
   1.175 +        np->rx_max_target = target;
   1.176 +        if (target < np->rx_target)
   1.177 +            np->rx_target = target;
   1.178 +        break;
   1.179 +    case TARGET_CUR:
   1.180 +        break;
   1.181 +    }
   1.182 +
   1.183 +    network_alloc_rx_buffers(dev);
   1.184 +
   1.185 +    spin_unlock(&np->rx_lock);
   1.186 +
   1.187 +    return count;
   1.188 +}
   1.189 +
   1.190 +static int xennet_proc_init(void)
   1.191 +{
   1.192 +    if (proc_mkdir("xen/net", NULL) == NULL)
   1.193 +        return -ENOMEM;
   1.194 +    return 0;
   1.195 +}
   1.196 +
   1.197 +static int xennet_proc_addif(struct net_device *dev)
   1.198 +{
   1.199 +    struct proc_dir_entry *dir, *min, *max, *cur;
   1.200 +    char name[30];
   1.201 +
   1.202 +    sprintf(name, "xen/net/%s", dev->name);
   1.203 +
   1.204 +    dir = proc_mkdir(name, NULL);
   1.205 +    if (!dir)
   1.206 +        goto nomem;
   1.207 +
   1.208 +    min = create_proc_entry("rxbuf_min", 0644, dir);
   1.209 +    max = create_proc_entry("rxbuf_max", 0644, dir);
   1.210 +    cur = create_proc_entry("rxbuf_cur", 0444, dir);
   1.211 +    if (!min || !max || !cur)
   1.212 +        goto nomem;
   1.213 +
   1.214 +    min->read_proc  = xennet_proc_read;
   1.215 +    min->write_proc = xennet_proc_write;
   1.216 +    min->data       = (void *)((unsigned long)dev | TARGET_MIN);
   1.217 +
   1.218 +    max->read_proc  = xennet_proc_read;
   1.219 +    max->write_proc = xennet_proc_write;
   1.220 +    max->data       = (void *)((unsigned long)dev | TARGET_MAX);
   1.221 +
   1.222 +    cur->read_proc  = xennet_proc_read;
   1.223 +    cur->write_proc = xennet_proc_write;
   1.224 +    cur->data       = (void *)((unsigned long)dev | TARGET_CUR);
   1.225 +
   1.226 +    return 0;
   1.227 +
   1.228 + nomem:
   1.229 +    xennet_proc_delif(dev);
   1.230 +    return -ENOMEM;
   1.231 +}
   1.232 +
   1.233 +static void xennet_proc_delif(struct net_device *dev)
   1.234 +{
   1.235 +    char name[30];
   1.236 +
   1.237 +    sprintf(name, "xen/net/%s/rxbuf_min", dev->name);
   1.238 +    remove_proc_entry(name, NULL);
   1.239 +
   1.240 +    sprintf(name, "xen/net/%s/rxbuf_max", dev->name);
   1.241 +    remove_proc_entry(name, NULL);
   1.242 +
   1.243 +    sprintf(name, "xen/net/%s/rxbuf_cur", dev->name);
   1.244 +    remove_proc_entry(name, NULL);
   1.245 +
   1.246 +    sprintf(name, "xen/net/%s", dev->name);
   1.247 +    remove_proc_entry(name, NULL);
   1.248 +}
   1.249 +
   1.250 +#endif
   1.251  
   1.252  module_init(netif_init);
   1.253 -