Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f3cd60b authored by Max Filippov's avatar Max Filippov Committed by Chris Zankel
Browse files

xtensa: ISS: clean up iss-network driver



No functional changes, remove dead/unused code, clean checkpatch warnings,
replace strlen of constant strings with sizeof.

Signed-off-by: default avatarMax Filippov <jcmvbkbc@gmail.com>
Signed-off-by: default avatarChris Zankel <chris@zankel.net>
parent ea1d3ed3
Loading
Loading
Loading
Loading
+52 −124
Original line number Original line Diff line number Diff line
@@ -57,7 +57,6 @@ static LIST_HEAD(devices);
struct tuntap_info {
struct tuntap_info {
	char dev_name[IFNAMSIZ];
	char dev_name[IFNAMSIZ];
	int fixed_config;
	int fixed_config;
	unsigned char gw[ETH_ALEN];
	int fd;
	int fd;
};
};


@@ -67,7 +66,6 @@ struct tuntap_info {
/* This structure contains out private information for the driver. */
/* This structure contains out private information for the driver. */


struct iss_net_private {
struct iss_net_private {

	struct list_head device_list;
	struct list_head device_list;
	struct list_head opened_list;
	struct list_head opened_list;


@@ -126,25 +124,6 @@ static char *split_if_spec(char *str, ...)
}
}




#if 0
/* Adjust SKB. */

struct sk_buff *ether_adjust_skb(struct sk_buff *skb, int extra)
{
	if ((skb != NULL) && (skb_tailroom(skb) < extra)) {
		struct sk_buff *skb2;

		skb2 = skb_copy_expand(skb, 0, extra, GFP_ATOMIC);
		dev_kfree_skb(skb);
		skb = skb2;
	}
	if (skb != NULL)
		skb_put(skb, extra);

	return skb;
}
#endif

/* Return the IP address as a string for a given device. */
/* Return the IP address as a string for a given device. */


static void dev_ip_addr(void *d, char *buf, char *bin_buf)
static void dev_ip_addr(void *d, char *buf, char *bin_buf)
@@ -154,11 +133,13 @@ static void dev_ip_addr(void *d, char *buf, char *bin_buf)
	struct in_ifaddr *in;
	struct in_ifaddr *in;
	__be32 addr;
	__be32 addr;


	if ((ip == NULL) || ((in = ip->ifa_list) == NULL)) {
	if (ip == NULL || ip->ifa_list == NULL) {
		printk(KERN_WARNING "Device not assigned an IP address!\n");
		pr_warn("Device not assigned an IP address!\n");
		return;
		return;
	}
	}


	in = ip->ifa_list;

	addr = in->ifa_address;
	addr = in->ifa_address;
	sprintf(buf, "%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff,
	sprintf(buf, "%d.%d.%d.%d", addr & 0xff, (addr >> 8) & 0xff,
		(addr >> 16) & 0xff, addr >> 24);
		(addr >> 16) & 0xff, addr >> 24);
@@ -173,7 +154,7 @@ static void dev_ip_addr(void *d, char *buf, char *bin_buf)


/* Set Ethernet address of the specified device. */
/* Set Ethernet address of the specified device. */


static void inline set_ether_mac(void *d, unsigned char *addr)
static inline void set_ether_mac(void *d, unsigned char *addr)
{
{
	struct net_device *dev = d;
	struct net_device *dev = d;
	memcpy(dev->dev_addr, addr, ETH_ALEN);
	memcpy(dev->dev_addr, addr, ETH_ALEN);
@@ -194,19 +175,21 @@ static int tuntap_open(struct iss_net_private *lp)
	if (!lp->tp.info.tuntap.fixed_config)
	if (!lp->tp.info.tuntap.fixed_config)
		return -EINVAL;
		return -EINVAL;


	if ((fd = simc_open("/dev/net/tun", 02, 0)) < 0) {	/* O_RDWR */
	fd = simc_open("/dev/net/tun", 02, 0); /* O_RDWR */
		printk("Failed to open /dev/net/tun, returned %d "
	if (fd < 0) {
		       "(errno = %d)\n", fd, errno);
		pr_err("Failed to open /dev/net/tun, returned %d (errno = %d)\n",
		       fd, errno);
		return fd;
		return fd;
	}
	}


	memset(&ifr, 0, sizeof ifr);
	memset(&ifr, 0, sizeof(ifr));
	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
	ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
	strlcpy(ifr.ifr_name, dev_name, sizeof ifr.ifr_name);
	strlcpy(ifr.ifr_name, dev_name, sizeof(ifr.ifr_name));


	if ((err = simc_ioctl(fd, TUNSETIFF, (void*) &ifr)) < 0) {
	err = simc_ioctl(fd, TUNSETIFF, &ifr);
		printk("Failed to set interface, returned %d "
	if (err < 0) {
		       "(errno = %d)\n", err, errno);
		pr_err("Failed to set interface, returned %d (errno = %d)\n",
		       err, errno);
		simc_close(fd);
		simc_close(fd);
		return err;
		return err;
	}
	}
@@ -217,22 +200,12 @@ static int tuntap_open(struct iss_net_private *lp)


static void tuntap_close(struct iss_net_private *lp)
static void tuntap_close(struct iss_net_private *lp)
{
{
#if 0
	if (lp->tp.info.tuntap.fixed_config)
		iter_addresses(lp->tp.info.tuntap.dev, close_addr, lp->host.dev_name);
#endif
	simc_close(lp->tp.info.tuntap.fd);
	simc_close(lp->tp.info.tuntap.fd);
	lp->tp.info.tuntap.fd = -1;
	lp->tp.info.tuntap.fd = -1;
}
}


static int tuntap_read(struct iss_net_private *lp, struct sk_buff **skb)
static int tuntap_read(struct iss_net_private *lp, struct sk_buff **skb)
{
{
#if 0
	*skb = ether_adjust_skb(*skb, ETH_HEADER_OTHER);
	if (*skb == NULL)
		return -ENOMEM;
#endif

	return simc_read(lp->tp.info.tuntap.fd,
	return simc_read(lp->tp.info.tuntap.fd,
			(*skb)->data, (*skb)->dev->mtu + ETH_HEADER_OTHER);
			(*skb)->data, (*skb)->dev->mtu + ETH_HEADER_OTHER);
}
}
@@ -259,40 +232,36 @@ static int tuntap_poll(struct iss_net_private *lp)


static int tuntap_probe(struct iss_net_private *lp, int index, char *init)
static int tuntap_probe(struct iss_net_private *lp, int index, char *init)
{
{
	const int len = strlen(TRANSPORT_TUNTAP_NAME);
	char *dev_name = NULL, *mac_str = NULL, *rem = NULL;
	char *dev_name = NULL, *mac_str = NULL, *rem = NULL;


	/* Transport should be 'tuntap': ethX=tuntap,mac,dev_name */
	/* Transport should be 'tuntap': ethX=tuntap,mac,dev_name */


	if (strncmp(init, TRANSPORT_TUNTAP_NAME, len))
	if (strncmp(init, TRANSPORT_TUNTAP_NAME,
		    sizeof(TRANSPORT_TUNTAP_NAME) - 1))
		return 0;
		return 0;


	if (*(init += strlen(TRANSPORT_TUNTAP_NAME)) == ',') {
	init += sizeof(TRANSPORT_TUNTAP_NAME) - 1;
		if ((rem=split_if_spec(init+1, &mac_str, &dev_name)) != NULL) {
	if (*init == ',') {
			printk("Extra garbage on specification : '%s'\n", rem);
		rem = split_if_spec(init + 1, &mac_str, &dev_name);
		if (rem != NULL) {
			pr_err("Extra garbage on specification : '%s'\n", rem);
			return 0;
			return 0;
		}
		}
	} else if (*init != '\0') {
	} else if (*init != '\0') {
		printk("Invalid argument: %s. Skipping device!\n", init);
		pr_err("Invalid argument: %s. Skipping device!\n", init);
		return 0;
		return 0;
	}
	}


	if (dev_name) {
	if (dev_name) {
		strncpy(lp->tp.info.tuntap.dev_name, dev_name,
		strlcpy(lp->tp.info.tuntap.dev_name, dev_name,
			 sizeof lp->tp.info.tuntap.dev_name);
			 sizeof(lp->tp.info.tuntap.dev_name));
		lp->tp.info.tuntap.fixed_config = 1;
		lp->tp.info.tuntap.fixed_config = 1;
	} else
	} else
		strcpy(lp->tp.info.tuntap.dev_name, TRANSPORT_TUNTAP_NAME);
		strcpy(lp->tp.info.tuntap.dev_name, TRANSPORT_TUNTAP_NAME);




#if 0
	if (setup_etheraddr(mac_str, lp->mac))
		lp->have_mac = 1;
#endif
	lp->mtu = TRANSPORT_TUNTAP_MTU;
	lp->mtu = TRANSPORT_TUNTAP_MTU;


	//lp->info.tuntap.gate_addr = gate_addr;

	lp->tp.info.tuntap.fd = -1;
	lp->tp.info.tuntap.fd = -1;


	lp->tp.open = tuntap_open;
	lp->tp.open = tuntap_open;
@@ -302,12 +271,7 @@ static int tuntap_probe(struct iss_net_private *lp, int index, char *init)
	lp->tp.protocol = tuntap_protocol;
	lp->tp.protocol = tuntap_protocol;
	lp->tp.poll = tuntap_poll;
	lp->tp.poll = tuntap_poll;


	printk("TUN/TAP backend - ");
	pr_info("TUN/TAP backend -\n");
#if 0
	if (lp->host.gate_addr != NULL)
		printk("IP = %s", lp->host.gate_addr);
#endif
	printk("\n");


	return 1;
	return 1;
}
}
@@ -327,7 +291,8 @@ static int iss_net_rx(struct net_device *dev)


	/* Try to allocate memory, if it fails, try again next round. */
	/* Try to allocate memory, if it fails, try again next round. */


	if ((skb = dev_alloc_skb(dev->mtu + 2 + ETH_HEADER_OTHER)) == NULL) {
	skb = dev_alloc_skb(dev->mtu + 2 + ETH_HEADER_OTHER);
	if (skb == NULL) {
		lp->stats.rx_dropped++;
		lp->stats.rx_dropped++;
		return 0;
		return 0;
	}
	}
@@ -347,7 +312,6 @@ static int iss_net_rx(struct net_device *dev)


		lp->stats.rx_bytes += skb->len;
		lp->stats.rx_bytes += skb->len;
		lp->stats.rx_packets++;
		lp->stats.rx_packets++;
	//	netif_rx(skb);
		netif_rx_ni(skb);
		netif_rx_ni(skb);
		return pkt_len;
		return pkt_len;
	}
	}
@@ -378,11 +342,11 @@ static int iss_net_poll(void)
		spin_unlock(&lp->lock);
		spin_unlock(&lp->lock);


		if (err < 0) {
		if (err < 0) {
			printk(KERN_ERR "Device '%s' read returned %d, "
			pr_err("Device '%s' read returned %d, shutting it down\n",
			       "shutting it down\n", lp->dev->name, err);
			       lp->dev->name, err);
			dev_close(lp->dev);
			dev_close(lp->dev);
		} else {
		} else {
			// FIXME reactivate_fd(lp->fd, ISS_ETH_IRQ);
			/* FIXME reactivate_fd(lp->fd, ISS_ETH_IRQ); */
		}
		}
	}
	}


@@ -396,11 +360,8 @@ static void iss_net_timer(unsigned long priv)
	struct iss_net_private *lp = (struct iss_net_private *)priv;
	struct iss_net_private *lp = (struct iss_net_private *)priv;


	spin_lock(&lp->lock);
	spin_lock(&lp->lock);

	iss_net_poll();
	iss_net_poll();

	mod_timer(&lp->timer, jiffies + lp->timer_val);
	mod_timer(&lp->timer, jiffies + lp->timer_val);

	spin_unlock(&lp->lock);
	spin_unlock(&lp->lock);
}
}


@@ -408,12 +369,13 @@ static void iss_net_timer(unsigned long priv)
static int iss_net_open(struct net_device *dev)
static int iss_net_open(struct net_device *dev)
{
{
	struct iss_net_private *lp = netdev_priv(dev);
	struct iss_net_private *lp = netdev_priv(dev);
	char addr[sizeof "255.255.255.255\0"];
	char addr[sizeof("255.255.255.255\0")];
	int err;
	int err;


	spin_lock(&lp->lock);
	spin_lock(&lp->lock);


	if ((err = lp->tp.open(lp)) < 0)
	err = lp->tp.open(lp);
	if (err < 0)
		goto out;
		goto out;


	if (!lp->have_mac) {
	if (!lp->have_mac) {
@@ -448,7 +410,6 @@ out:
static int iss_net_close(struct net_device *dev)
static int iss_net_close(struct net_device *dev)
{
{
	struct iss_net_private *lp = netdev_priv(dev);
	struct iss_net_private *lp = netdev_priv(dev);
printk("iss_net_close!\n");
	netif_stop_queue(dev);
	netif_stop_queue(dev);
	spin_lock(&lp->lock);
	spin_lock(&lp->lock);


@@ -490,7 +451,7 @@ static int iss_net_start_xmit(struct sk_buff *skb, struct net_device *dev)


	} else {
	} else {
		netif_start_queue(dev);
		netif_start_queue(dev);
		printk(KERN_ERR "iss_net_start_xmit: failed(%d)\n", len);
		pr_err("iss_net_start_xmit: failed(%d)\n", len);
	}
	}


	spin_unlock_irqrestore(&lp->lock, flags);
	spin_unlock_irqrestore(&lp->lock, flags);
@@ -508,22 +469,10 @@ static struct net_device_stats *iss_net_get_stats(struct net_device *dev)


static void iss_net_set_multicast_list(struct net_device *dev)
static void iss_net_set_multicast_list(struct net_device *dev)
{
{
#if 0
	if (dev->flags & IFF_PROMISC)
		return;
	else if (!netdev_mc_empty(dev))
		dev->flags |= IFF_ALLMULTI;
	else
		dev->flags &= ~IFF_ALLMULTI;
#endif
}
}


static void iss_net_tx_timeout(struct net_device *dev)
static void iss_net_tx_timeout(struct net_device *dev)
{
{
#if 0
	dev->trans_start = jiffies;
	netif_wake_queue(dev);
#endif
}
}


static int iss_net_set_mac(struct net_device *dev, void *addr)
static int iss_net_set_mac(struct net_device *dev, void *addr)
@@ -542,22 +491,6 @@ static int iss_net_set_mac(struct net_device *dev, void *addr)


static int iss_net_change_mtu(struct net_device *dev, int new_mtu)
static int iss_net_change_mtu(struct net_device *dev, int new_mtu)
{
{
#if 0
	struct iss_net_private *lp = netdev_priv(dev);
	int err = 0;

	spin_lock(&lp->lock);

	// FIXME not needed new_mtu = transport_set_mtu(new_mtu, &lp->user);

	if (new_mtu < 0)
		err = new_mtu;
	else
		dev->mtu = new_mtu;

	spin_unlock(&lp->lock);
	return err;
#endif
	return -EINVAL;
	return -EINVAL;
}
}


@@ -582,7 +515,6 @@ static const struct net_device_ops iss_netdev_ops = {
	.ndo_validate_addr	= eth_validate_addr,
	.ndo_validate_addr	= eth_validate_addr,
	.ndo_change_mtu		= iss_net_change_mtu,
	.ndo_change_mtu		= iss_net_change_mtu,
	.ndo_set_mac_address	= iss_net_set_mac,
	.ndo_set_mac_address	= iss_net_set_mac,
	//.ndo_do_ioctl		= iss_net_ioctl,
	.ndo_tx_timeout		= iss_net_tx_timeout,
	.ndo_tx_timeout		= iss_net_tx_timeout,
	.ndo_set_rx_mode	= iss_net_set_multicast_list,
	.ndo_set_rx_mode	= iss_net_set_multicast_list,
};
};
@@ -593,24 +525,24 @@ static int iss_net_configure(int index, char *init)
	struct iss_net_private *lp;
	struct iss_net_private *lp;
	int err;
	int err;


	if ((dev = alloc_etherdev(sizeof *lp)) == NULL) {
	dev = alloc_etherdev(sizeof(*lp));
		printk(KERN_ERR "eth_configure: failed to allocate device\n");
	if (dev == NULL) {
		pr_err("eth_configure: failed to allocate device\n");
		return 1;
		return 1;
	}
	}


	/* Initialize private element. */
	/* Initialize private element. */


	lp = netdev_priv(dev);
	lp = netdev_priv(dev);
	*lp = ((struct iss_net_private) {
	*lp = (struct iss_net_private) {
		.device_list		= LIST_HEAD_INIT(lp->device_list),
		.device_list		= LIST_HEAD_INIT(lp->device_list),
		.opened_list		= LIST_HEAD_INIT(lp->opened_list),
		.opened_list		= LIST_HEAD_INIT(lp->opened_list),
		.lock			= __SPIN_LOCK_UNLOCKED(lp.lock),
		.lock			= __SPIN_LOCK_UNLOCKED(lp.lock),
		.dev			= dev,
		.dev			= dev,
		.index			= index,
		.index			= index,
		//.fd                   = -1,
		.mac			= { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0 },
		.mac			= { 0xfe, 0xfd, 0x0, 0x0, 0x0, 0x0 },
		.have_mac		= 0,
		.have_mac		= 0,
		});
		};


	/*
	/*
	 * Try all transport protocols.
	 * Try all transport protocols.
@@ -618,7 +550,7 @@ static int iss_net_configure(int index, char *init)
	 */
	 */


	if (!tuntap_probe(lp, index, init)) {
	if (!tuntap_probe(lp, index, init)) {
		printk("Invalid arguments. Skipping device!\n");
		pr_err("Invalid arguments. Skipping device!\n");
		goto errout;
		goto errout;
	}
	}


@@ -648,7 +580,7 @@ static int iss_net_configure(int index, char *init)
	 * netdevice, that is OK, register_netdev{,ice}() will notice this
	 * netdevice, that is OK, register_netdev{,ice}() will notice this
	 * and fail.
	 * and fail.
	 */
	 */
	snprintf(dev->name, sizeof dev->name, "eth%d", index);
	snprintf(dev->name, sizeof(dev->name), "eth%d", index);


	dev->netdev_ops = &iss_netdev_ops;
	dev->netdev_ops = &iss_netdev_ops;
	dev->mtu = lp->mtu;
	dev->mtu = lp->mtu;
@@ -660,7 +592,7 @@ static int iss_net_configure(int index, char *init)
	rtnl_unlock();
	rtnl_unlock();


	if (err) {
	if (err) {
		printk("Error registering net device!\n");
		pr_err("Error registering net device!\n");
		/* XXX: should we call ->remove() here? */
		/* XXX: should we call ->remove() here? */
		free_netdev(dev);
		free_netdev(dev);
		return 1;
		return 1;
@@ -669,16 +601,11 @@ static int iss_net_configure(int index, char *init)
	init_timer(&lp->tl);
	init_timer(&lp->tl);
	lp->tl.function = iss_net_user_timer_expire;
	lp->tl.function = iss_net_user_timer_expire;


#if 0
	if (lp->have_mac)
		set_ether_mac(dev, lp->mac);
#endif
	return 0;
	return 0;


errout:
errout:
	// FIXME: unregister; free, etc..
	/* FIXME: unregister; free, etc.. */
	return -EIO;
	return -EIO;

}
}


/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
@@ -717,7 +644,8 @@ static int __init iss_net_setup(char *str)
		printk(ERR "Device %d is negative\n", n);
		printk(ERR "Device %d is negative\n", n);
		return 1;
		return 1;
	}
	}
	if (*(str = end) != '=') {
	str = end;
	if (*str != '=') {
		printk(ERR "Expected '=' after device number\n");
		printk(ERR "Expected '=' after device number\n");
		return 1;
		return 1;
	}
	}
@@ -739,7 +667,7 @@ static int __init iss_net_setup(char *str)


	new = alloc_bootmem(sizeof(*new));
	new = alloc_bootmem(sizeof(*new));
	if (new == NULL) {
	if (new == NULL) {
		printk("Alloc_bootmem failed\n");
		printk(ERR "Alloc_bootmem failed\n");
		return 1;
		return 1;
	}
	}