ia64/xen-unstable

changeset 10094:b9b316bfab15

[NET] front: Add a sysfs interface for tuning the receive buffer values.
Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
author kaf24@firebug.cl.cam.ac.uk
date Thu May 18 10:21:11 2006 +0100 (2006-05-18)
parents 6f957675015d
children cb4d2fc638ec
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 18 10:15:14 2006 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c	Thu May 18 10:21:11 2006 +0100
     1.3 @@ -1072,6 +1072,146 @@ static struct ethtool_ops network_ethtoo
     1.4  	.set_tx_csum = ethtool_op_set_tx_csum,
     1.5  };
     1.6  
     1.7 +#ifdef CONFIG_SYSFS
     1.8 +static ssize_t show_rxbuf_min(struct class_device *cd, char *buf)
     1.9 +{
    1.10 +	struct net_device *netdev = container_of(cd, struct net_device,
    1.11 +						 class_dev);
    1.12 +	struct netfront_info *info = netdev_priv(netdev);
    1.13 +
    1.14 +	return sprintf(buf, "%u\n", info->rx_min_target);
    1.15 +}
    1.16 +
    1.17 +static ssize_t store_rxbuf_min(struct class_device *cd,
    1.18 +			       const char *buf, size_t len)
    1.19 +{
    1.20 +	struct net_device *netdev = container_of(cd, struct net_device,
    1.21 +						 class_dev);
    1.22 +	struct netfront_info *np = netdev_priv(netdev);
    1.23 +	char *endp;
    1.24 +	unsigned long target;
    1.25 +
    1.26 +	if (!capable(CAP_NET_ADMIN))
    1.27 +		return -EPERM;
    1.28 +
    1.29 +	target = simple_strtoul(buf, &endp, 0);
    1.30 +	if (endp == buf)
    1.31 +		return -EBADMSG;
    1.32 +
    1.33 +	if (target < RX_MIN_TARGET)
    1.34 +		target = RX_MIN_TARGET;
    1.35 +	if (target > RX_MAX_TARGET)
    1.36 +		target = RX_MAX_TARGET;
    1.37 +
    1.38 +	spin_lock(&np->rx_lock);
    1.39 +	if (target > np->rx_max_target)
    1.40 +		np->rx_max_target = target;
    1.41 +	np->rx_min_target = target;
    1.42 +	if (target > np->rx_target)
    1.43 +		np->rx_target = target;
    1.44 +
    1.45 +	network_alloc_rx_buffers(netdev);
    1.46 +
    1.47 +	spin_unlock(&np->rx_lock);
    1.48 +	return len;
    1.49 +}
    1.50 +
    1.51 +static ssize_t show_rxbuf_max(struct class_device *cd, char *buf)
    1.52 +{
    1.53 +	struct net_device *netdev = container_of(cd, struct net_device,
    1.54 +						 class_dev);
    1.55 +	struct netfront_info *info = netdev_priv(netdev);
    1.56 +
    1.57 +	return sprintf(buf, "%u\n", info->rx_max_target);
    1.58 +}
    1.59 +
    1.60 +static ssize_t store_rxbuf_max(struct class_device *cd,
    1.61 +			       const char *buf, size_t len)
    1.62 +{
    1.63 +	struct net_device *netdev = container_of(cd, struct net_device,
    1.64 +						 class_dev);
    1.65 +	struct netfront_info *np = netdev_priv(netdev);
    1.66 +	char *endp;
    1.67 +	unsigned long target;
    1.68 +
    1.69 +	if (!capable(CAP_NET_ADMIN))
    1.70 +		return -EPERM;
    1.71 +
    1.72 +	target = simple_strtoul(buf, &endp, 0);
    1.73 +	if (endp == buf)
    1.74 +		return -EBADMSG;
    1.75 +
    1.76 +	if (target < RX_MIN_TARGET)
    1.77 +		target = RX_MIN_TARGET;
    1.78 +	if (target > RX_MAX_TARGET)
    1.79 +		target = RX_MAX_TARGET;
    1.80 +
    1.81 +	spin_lock(&np->rx_lock);
    1.82 +	if (target < np->rx_min_target)
    1.83 +		np->rx_min_target = target;
    1.84 +	np->rx_max_target = target;
    1.85 +	if (target < np->rx_target)
    1.86 +		np->rx_target = target;
    1.87 +
    1.88 +	network_alloc_rx_buffers(netdev);
    1.89 +
    1.90 +	spin_unlock(&np->rx_lock);
    1.91 +	return len;
    1.92 +}
    1.93 +
    1.94 +static ssize_t show_rxbuf_cur(struct class_device *cd, char *buf)
    1.95 +{
    1.96 +	struct net_device *netdev = container_of(cd, struct net_device,
    1.97 +						 class_dev);
    1.98 +	struct netfront_info *info = netdev_priv(netdev);
    1.99 +
   1.100 +	return sprintf(buf, "%u\n", info->rx_target);
   1.101 +}
   1.102 +
   1.103 +static const struct class_device_attribute xennet_attrs[] = {
   1.104 +	__ATTR(rxbuf_min, S_IRUGO|S_IWUSR, show_rxbuf_min, store_rxbuf_min),
   1.105 +	__ATTR(rxbuf_max, S_IRUGO|S_IWUSR, show_rxbuf_max, store_rxbuf_max),
   1.106 +	__ATTR(rxbuf_cur, S_IRUGO, show_rxbuf_cur, NULL),
   1.107 +};
   1.108 +
   1.109 +static int xennet_sysfs_addif(struct net_device *netdev)
   1.110 +{
   1.111 +	int i;
   1.112 +	int error = 0;
   1.113 +
   1.114 +	for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
   1.115 +		error = class_device_create_file(&netdev->class_dev, 
   1.116 +						 &xennet_attrs[i]);
   1.117 +		if (error)
   1.118 +			goto fail;
   1.119 +	}
   1.120 +	return 0;
   1.121 +
   1.122 + fail:
   1.123 +	while (--i >= 0)
   1.124 +		class_device_remove_file(&netdev->class_dev,
   1.125 +					 &xennet_attrs[i]);
   1.126 +	return error;
   1.127 +}
   1.128 +
   1.129 +static void xennet_sysfs_delif(struct net_device *netdev)
   1.130 +{
   1.131 +	int i;
   1.132 +
   1.133 +	for (i = 0; i < ARRAY_SIZE(xennet_attrs); i++) {
   1.134 +		class_device_remove_file(&netdev->class_dev,
   1.135 +					 &xennet_attrs[i]);
   1.136 +	}
   1.137 +}
   1.138 +
   1.139 +#else /* !CONFIG_SYSFS */
   1.140 +
   1.141 +#define xennet_sysfs_addif(dev) (0)
   1.142 +#define xennet_sysfs_delif(dev) do { } while(0)
   1.143 +
   1.144 +#endif
   1.145 +
   1.146 +
   1.147  /*
   1.148   * Nothing to do here. Virtual interface is point-to-point and the
   1.149   * physical interface is probably promiscuous anyway.
   1.150 @@ -1157,12 +1297,20 @@ static int __devinit create_netdev(int h
   1.151  	SET_MODULE_OWNER(netdev);
   1.152  	SET_NETDEV_DEV(netdev, &dev->dev);
   1.153  
   1.154 -	if ((err = register_netdev(netdev)) != 0) {
   1.155 +	err = register_netdev(netdev);
   1.156 +	if (err) {
   1.157  		printk(KERN_WARNING "%s> register_netdev err=%d\n",
   1.158  		       __FUNCTION__, err);
   1.159  		goto exit_free_rx;
   1.160  	}
   1.161  
   1.162 +	err = xennet_sysfs_addif(netdev);
   1.163 +	if (err) {
   1.164 +		/* This can be non-fatal: it only means no tuning parameters */
   1.165 +		printk(KERN_WARNING "%s> add sysfs failed err=%d\n",
   1.166 +		       __FUNCTION__, err);
   1.167 +	}
   1.168 +
   1.169  	np->netdev = netdev;
   1.170  	if (val)
   1.171  		*val = netdev;
   1.172 @@ -1235,6 +1383,7 @@ static void close_netdev(struct netfront
   1.173  {
   1.174  	del_timer_sync(&info->rx_refill_timer);
   1.175  
   1.176 +	xennet_sysfs_delif(info->netdev);
   1.177  	unregister_netdev(info->netdev);
   1.178  }
   1.179  
   1.180 @@ -1304,8 +1453,6 @@ static struct notifier_block notifier_in
   1.181  
   1.182  static int __init netif_init(void)
   1.183  {
   1.184 -	int err = 0;
   1.185 -
   1.186  	if (xen_start_info->flags & SIF_INITDOMAIN)
   1.187  		return 0;
   1.188