Re: [PATCH] Ethernet driver for the WIZnet W5300 chip

From: Tobias Klauser
Date: Wed Mar 14 2012 - 11:37:39 EST


On 2012-03-14 at 14:00:35 +0100, Mike Sinkovsky <msink@xxxxxxxxxxxxx> wrote:

[snip]

> +static int w5300_set_macaddr(struct net_device *ndev, void *addr)
> +{
> + struct dev_private *priv = netdev_priv(ndev);
> + struct sockaddr *sock_addr = addr;
> +
> + if (is_multicast_ether_addr(sock_addr->sa_data))
> + return -EADDRNOTAVAIL;

This should probably be

if (!is_valid_ether_addr(sock_addr->sa_data))
return -EADDRNOTAVAIL;

> + memcpy(ndev->dev_addr, sock_addr->sa_data, ETH_ALEN);
> + write_macaddr(priv);

You'll also want to reset NET_ADDR_RANDOM in ndev->addr_assign_type
since you seem to generate a random address in w5300_probe().

> +
> + return 0;
> +}
> +

[snip]

> +static int __devinit w5300_probe(struct platform_device *pdev)
> +{
> + struct net_device *ndev;
> + struct dev_private *priv;
> + struct resource *mem;
> + void __iomem *mem_base;
> + int mem_size;
> + int irq;
> + int err;
> +
> + ndev = alloc_etherdev(sizeof(*priv));
> + if (!ndev) {
> + err = -ENOMEM;
> + goto err_do_devfree;
> + }
> +
> + mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + irq = platform_get_irq(pdev, 0);
> + if (!mem || irq < 0) {
> + err = -ENXIO;
> + goto err_do_devfree;
> + }
> + mem_size = resource_size(mem);
> +
> + if (!request_mem_region(mem->start, mem_size, KBUILD_MODNAME)) {
> + err = -EBUSY;
> + goto err_do_devfree;
> + }
> + mem_base = ioremap(mem->start, mem_size);
> + if (!mem_base) {
> + err = -ENOMEM;
> + goto err_do_memrelease;
> + }
> +
> + SET_NETDEV_DEV(ndev, &pdev->dev);
> + platform_set_drvdata(pdev, ndev);
> + priv = netdev_priv(ndev);
> + priv->ndev = ndev;
> + priv->base = mem_base;
> + priv->promisc_mode = false;
> + spin_lock_init(&priv->reg_lock);
> +
> + ndev->mem_start = mem->start;
> + ndev->mem_end = mem->start + mem_size - 1;
> + ndev->irq = irq;
> + ndev->netdev_ops = &netdev_ops;
> + ndev->watchdog_timeo = 2 * HZ;
> + ether_setup(ndev);
> + dev_hw_addr_random(ndev, ndev->dev_addr);

This is eth_hw_addr_random(ndev) in net-next now.

> + reset_chip(priv);
> + if (read_IDR(priv) != 0x5300) {
> + err = -ENODEV;
> + goto err_do_iounmap;
> + }
> +
> + err = request_irq(ndev->irq, w5300_start_rx,
> + IRQ_TYPE_LEVEL_LOW, ndev->name, ndev);
> + if (err)
> + goto err_do_iounmap;
> +
> + netif_napi_add(ndev, &priv->napi, w5300_napi_poll, 16);
> + err = register_netdev(ndev);
> + if (err)
> + goto err_do_irqfree;
> +
> + netdev_info(ndev, "at 0x%lX irq %d\n", ndev->mem_start, ndev->irq);
> + return 0;
> +
> +err_do_irqfree:
> + free_irq(ndev->irq, ndev);
> +err_do_iounmap:
> + iounmap(mem_base);
> +err_do_memrelease:
> + release_mem_region(mem->start, resource_size(mem));
> +err_do_devfree:
> + free_netdev(ndev);
> + platform_set_drvdata(pdev, NULL);
> + return err;
> +}
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/