adm5120: don't use IRQF_DISABLED flag in the switch driver
[openwrt/svn-archive/archive.git] / target / linux / adm5120 / files / drivers / net / adm5120sw.c
index ff933cf7cf8ad4e44655115217e0b1f6c4a87ee0..09cb9097e87d7afc2265309a35ca32623281c17a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ADM5120 built-in ethernet switch driver
  *
- *  Copyright (C) 2007,2008 Gabor Juhos <juhosg at openwrt.org>
+ *  Copyright (C) 2007-2008 Gabor Juhos <juhosg@openwrt.org>
  *
  *  This code was based on a driver for Linux 2.6.xx by Jeroen Vreeken.
  *    Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2005
 #include <linux/ioport.h>
 #include <linux/spinlock.h>
 #include <linux/platform_device.h>
+#include <linux/io.h>
+#include <linux/irq.h>
 
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
 
-#include <linux/io.h>
-#include <linux/irq.h>
-
 #include <asm/mipsregs.h>
 
-#include <adm5120_info.h>
-#include <adm5120_defs.h>
-#include <adm5120_irq.h>
-#include <adm5120_switch.h>
+#include <asm/mach-adm5120/adm5120_info.h>
+#include <asm/mach-adm5120/adm5120_defs.h>
+#include <asm/mach-adm5120/adm5120_switch.h>
 
 #include "adm5120sw.h"
 
 /* ------------------------------------------------------------------------ */
 
 struct adm5120_if_priv {
+       struct net_device *dev;
+
        unsigned int    vlan_no;
        unsigned int    port_mask;
+
+#ifdef CONFIG_ADM5120_SWITCH_NAPI
+       struct napi_struct napi;
+#endif
 };
 
 struct dma_desc {
@@ -333,7 +337,6 @@ static void sw_dump_regs(void)
        SW_DBG("rlda: %08X\n", t);
 }
 
-
 /* ------------------------------------------------------------------------ */
 
 static inline void adm5120_rx_dma_update(struct dma_desc *desc,
@@ -495,9 +498,11 @@ static void adm5120_switch_tx(void)
 }
 
 #ifdef CONFIG_ADM5120_SWITCH_NAPI
-static int adm5120_if_poll(struct net_device *dev, int *budget)
+static int adm5120_if_poll(struct napi_struct *napi, int limit)
 {
-       int limit = min(dev->quota, *budget);
+       struct adm5120_if_priv *priv = container_of(napi,
+                               struct adm5120_if_priv, napi);
+       struct net_device *dev = priv->dev;
        int done;
        u32 status;
 
@@ -509,13 +514,10 @@ static int adm5120_if_poll(struct net_device *dev, int *budget)
        SW_DBG("%s: processing RX ring\n", dev->name);
        done = adm5120_switch_rx(limit);
 
-       *budget -= done;
-       dev->quota -= done;
-
        status = sw_int_status() & SWITCH_INTS_POLL;
        if ((done < limit) && (!status)) {
                SW_DBG("disable polling mode for %s\n", dev->name);
-               netif_rx_complete(dev);
+               napi_complete(napi);
                sw_int_unmask(SWITCH_INTS_POLL);
                return 0;
        }
@@ -541,10 +543,12 @@ static irqreturn_t adm5120_switch_irq(int irq, void *dev_id)
 
        if (status & SWITCH_INTS_POLL) {
                struct net_device *dev = dev_id;
+               struct adm5120_if_priv *priv = netdev_priv(dev);
+
                sw_dump_intr_mask("poll ints", status);
                SW_DBG("enable polling mode for %s\n", dev->name);
                sw_int_mask(SWITCH_INTS_POLL);
-               netif_rx_schedule(dev);
+               napi_schedule(&priv->napi);
        }
 #else
        sw_int_ack(status);
@@ -779,14 +783,33 @@ static void adm5120_switch_set_vlan_ports(unsigned int vlan, u32 ports)
 
 /* ------------------------------------------------------------------------ */
 
+#ifdef CONFIG_ADM5120_SWITCH_NAPI
+static inline void adm5120_if_napi_enable(struct net_device *dev)
+{
+       struct adm5120_if_priv *priv = netdev_priv(dev);
+       napi_enable(&priv->napi);
+}
+
+static inline void adm5120_if_napi_disable(struct net_device *dev)
+{
+       struct adm5120_if_priv *priv = netdev_priv(dev);
+       napi_disable(&priv->napi);
+}
+#else
+static inline void adm5120_if_napi_enable(struct net_device *dev) {}
+static inline void adm5120_if_napi_disable(struct net_device *dev) {}
+#endif /* CONFIG_ADM5120_SWITCH_NAPI */
+
 static int adm5120_if_open(struct net_device *dev)
 {
        u32 t;
        int err;
        int i;
 
-       err = request_irq(dev->irq, adm5120_switch_irq,
-               (IRQF_SHARED | IRQF_DISABLED), dev->name, dev);
+       adm5120_if_napi_enable(dev);
+
+       err = request_irq(dev->irq, adm5120_switch_irq, IRQF_SHARED,
+                         dev->name, dev);
        if (err) {
                SW_ERR("unable to get irq for %s\n", dev->name);
                goto err;
@@ -809,6 +832,7 @@ static int adm5120_if_open(struct net_device *dev)
        return 0;
 
 err:
+       adm5120_if_napi_disable(dev);
        return err;
 }
 
@@ -818,6 +842,7 @@ static int adm5120_if_stop(struct net_device *dev)
        int i;
 
        netif_stop_queue(dev);
+       adm5120_if_napi_disable(dev);
 
        /* disable port if not assigned to other devices */
        t = sw_read_reg(SWITCH_REG_PORT_CONF0);
@@ -948,9 +973,12 @@ static void adm5120_if_set_multicast_list(struct net_device *dev)
 
 static int adm5120_if_set_mac_address(struct net_device *dev, void *p)
 {
-       struct sockaddr *addr = p;
+       int ret;
+
+       ret = eth_mac_addr(dev, p);
+       if (ret)
+               return ret;
 
-       memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
        adm5120_write_mac(dev);
        return 0;
 }
@@ -992,6 +1020,18 @@ static int adm5120_if_do_ioctl(struct net_device *dev, struct ifreq *rq,
        return 0;
 }
 
+static const struct net_device_ops adm5120sw_netdev_ops = {
+        .ndo_open               = adm5120_if_open,
+        .ndo_stop               = adm5120_if_stop,
+        .ndo_start_xmit         = adm5120_if_hard_start_xmit,
+        .ndo_set_multicast_list = adm5120_if_set_multicast_list,
+        .ndo_do_ioctl           = adm5120_if_do_ioctl,
+        .ndo_tx_timeout         = adm5120_if_tx_timeout,
+        .ndo_validate_addr      = eth_validate_addr,
+        .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = adm5120_if_set_mac_address,
+};
+
 static struct net_device *adm5120_if_alloc(void)
 {
        struct net_device *dev;
@@ -1001,22 +1041,17 @@ static struct net_device *adm5120_if_alloc(void)
        if (!dev)
                return NULL;
 
+       priv = netdev_priv(dev);
+       priv->dev = dev;
+
        dev->irq                = ADM5120_IRQ_SWITCH;
-       dev->open               = adm5120_if_open;
-       dev->hard_start_xmit    = adm5120_if_hard_start_xmit;
-       dev->stop               = adm5120_if_stop;
-       dev->set_multicast_list = adm5120_if_set_multicast_list;
-       dev->do_ioctl           = adm5120_if_do_ioctl;
-       dev->tx_timeout         = adm5120_if_tx_timeout;
+       dev->netdev_ops         = &adm5120sw_netdev_ops;
        dev->watchdog_timeo     = TX_TIMEOUT;
-       dev->set_mac_address    = adm5120_if_set_mac_address;
+
 #ifdef CONFIG_ADM5120_SWITCH_NAPI
-       dev->poll               = adm5120_if_poll;
-       dev->weight             = 64;
+       netif_napi_add(dev, &priv->napi, adm5120_if_poll, 64);
 #endif
 
-       SET_MODULE_OWNER(dev);
-
        return dev;
 }
 
@@ -1172,6 +1207,6 @@ module_init(adm5120_switch_mod_init);
 module_exit(adm5120_switch_mod_exit);
 
 MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Gabor Juhos <juhosg at openwrt.org>");
+MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
 MODULE_DESCRIPTION(DRV_DESC);
 MODULE_VERSION(DRV_VERSION);