]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/net/smsc911x.c
Merge branch 'docs-next' of git://git.lwn.net/linux-2.6
[karo-tx-linux.git] / drivers / net / smsc911x.c
index fe517880fc970baad53ac6ccde0c73eb53486f91..dc3f1108884d0709159246031c6252e1f42079f6 100644 (file)
@@ -77,19 +77,16 @@ struct smsc911x_data {
        unsigned int generation;
 
        /* device configuration (copied from platform_data during probe) */
-       unsigned int irq_polarity;
-       unsigned int irq_type;
-       phy_interface_t phy_interface;
+       struct smsc911x_platform_config config;
 
        /* This needs to be acquired before calling any of below:
         * smsc911x_mac_read(), smsc911x_mac_write()
         */
        spinlock_t mac_lock;
 
-#if (!SMSC_CAN_USE_32BIT)
-       /* spinlock to ensure 16-bit accesses are serialised */
+       /* spinlock to ensure 16-bit accesses are serialised.
+        * unused with a 32-bit bus */
        spinlock_t dev_lock;
-#endif
 
        struct phy_device *phy_dev;
        struct mii_bus *mii_bus;
@@ -121,70 +118,56 @@ struct smsc911x_data {
        unsigned int hashlo;
 };
 
-#if SMSC_CAN_USE_32BIT
-
-static inline u32 smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg)
-{
-       return readl(pdata->ioaddr + reg);
-}
-
-static inline void smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg,
-                                     u32 val)
-{
-       writel(val, pdata->ioaddr + reg);
-}
-
-/* Writes a packet to the TX_DATA_FIFO */
-static inline void
-smsc911x_tx_writefifo(struct smsc911x_data *pdata, unsigned int *buf,
-                     unsigned int wordcount)
-{
-       writesl(pdata->ioaddr + TX_DATA_FIFO, buf, wordcount);
-}
-
-/* Reads a packet out of the RX_DATA_FIFO */
-static inline void
-smsc911x_rx_readfifo(struct smsc911x_data *pdata, unsigned int *buf,
-                    unsigned int wordcount)
-{
-       readsl(pdata->ioaddr + RX_DATA_FIFO, buf, wordcount);
-}
-
-#else                          /* SMSC_CAN_USE_32BIT */
-
-/* These 16-bit access functions are significantly slower, due to the locking
+/* The 16-bit access functions are significantly slower, due to the locking
  * necessary.  If your bus hardware can be configured to do this for you
  * (in response to a single 32-bit operation from software), you should use
  * the 32-bit access functions instead. */
 
 static inline u32 smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg)
 {
-       unsigned long flags;
-       u32 data;
-
-       /* these two 16-bit reads must be performed consecutively, so must
-        * not be interrupted by our own ISR (which would start another
-        * read operation) */
-       spin_lock_irqsave(&pdata->dev_lock, flags);
-       data = ((readw(pdata->ioaddr + reg) & 0xFFFF) |
-               ((readw(pdata->ioaddr + reg + 2) & 0xFFFF) << 16));
-       spin_unlock_irqrestore(&pdata->dev_lock, flags);
+       if (pdata->config.flags & SMSC911X_USE_32BIT)
+               return readl(pdata->ioaddr + reg);
+
+       if (pdata->config.flags & SMSC911X_USE_16BIT) {
+               u32 data;
+               unsigned long flags;
+
+               /* these two 16-bit reads must be performed consecutively, so
+                * must not be interrupted by our own ISR (which would start
+                * another read operation) */
+               spin_lock_irqsave(&pdata->dev_lock, flags);
+               data = ((readw(pdata->ioaddr + reg) & 0xFFFF) |
+                       ((readw(pdata->ioaddr + reg + 2) & 0xFFFF) << 16));
+               spin_unlock_irqrestore(&pdata->dev_lock, flags);
+
+               return data;
+       }
 
-       return data;
+       BUG();
 }
 
 static inline void smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg,
                                      u32 val)
 {
-       unsigned long flags;
+       if (pdata->config.flags & SMSC911X_USE_32BIT) {
+               writel(val, pdata->ioaddr + reg);
+               return;
+       }
+
+       if (pdata->config.flags & SMSC911X_USE_16BIT) {
+               unsigned long flags;
+
+               /* these two 16-bit writes must be performed consecutively, so
+                * must not be interrupted by our own ISR (which would start
+                * another read operation) */
+               spin_lock_irqsave(&pdata->dev_lock, flags);
+               writew(val & 0xFFFF, pdata->ioaddr + reg);
+               writew((val >> 16) & 0xFFFF, pdata->ioaddr + reg + 2);
+               spin_unlock_irqrestore(&pdata->dev_lock, flags);
+               return;
+       }
 
-       /* these two 16-bit writes must be performed consecutively, so must
-        * not be interrupted by our own ISR (which would start another
-        * read operation) */
-       spin_lock_irqsave(&pdata->dev_lock, flags);
-       writew(val & 0xFFFF, pdata->ioaddr + reg);
-       writew((val >> 16) & 0xFFFF, pdata->ioaddr + reg + 2);
-       spin_unlock_irqrestore(&pdata->dev_lock, flags);
+       BUG();
 }
 
 /* Writes a packet to the TX_DATA_FIFO */
@@ -192,8 +175,18 @@ static inline void
 smsc911x_tx_writefifo(struct smsc911x_data *pdata, unsigned int *buf,
                      unsigned int wordcount)
 {
-       while (wordcount--)
-               smsc911x_reg_write(pdata, TX_DATA_FIFO, *buf++);
+       if (pdata->config.flags & SMSC911X_USE_32BIT) {
+               writesl(pdata->ioaddr + TX_DATA_FIFO, buf, wordcount);
+               return;
+       }
+
+       if (pdata->config.flags & SMSC911X_USE_16BIT) {
+               while (wordcount--)
+                       smsc911x_reg_write(pdata, TX_DATA_FIFO, *buf++);
+               return;
+       }
+
+       BUG();
 }
 
 /* Reads a packet out of the RX_DATA_FIFO */
@@ -201,11 +194,19 @@ static inline void
 smsc911x_rx_readfifo(struct smsc911x_data *pdata, unsigned int *buf,
                     unsigned int wordcount)
 {
-       while (wordcount--)
-               *buf++ = smsc911x_reg_read(pdata, RX_DATA_FIFO);
-}
+       if (pdata->config.flags & SMSC911X_USE_32BIT) {
+               readsl(pdata->ioaddr + RX_DATA_FIFO, buf, wordcount);
+               return;
+       }
 
-#endif                         /* SMSC_CAN_USE_32BIT */
+       if (pdata->config.flags & SMSC911X_USE_16BIT) {
+               while (wordcount--)
+                       *buf++ = smsc911x_reg_read(pdata, RX_DATA_FIFO);
+               return;
+       }
+
+       BUG();
+}
 
 /* waits for MAC not busy, with timeout.  Only called by smsc911x_mac_read
  * and smsc911x_mac_write, so assumes mac_lock is held */
@@ -641,28 +642,6 @@ static int smsc911x_phy_loopbacktest(struct net_device *dev)
 }
 #endif                         /* USE_PHY_WORK_AROUND */
 
-static u8 smsc95xx_resolve_flowctrl_fulldplx(u16 lcladv, u16 rmtadv)
-{
-       u8 cap = 0;
-
-       if (lcladv & ADVERTISE_PAUSE_CAP) {
-               if (lcladv & ADVERTISE_PAUSE_ASYM) {
-                       if (rmtadv & LPA_PAUSE_CAP)
-                               cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
-                       else if (rmtadv & LPA_PAUSE_ASYM)
-                               cap = FLOW_CTRL_RX;
-               } else {
-                       if (rmtadv & LPA_PAUSE_CAP)
-                               cap = FLOW_CTRL_TX | FLOW_CTRL_RX;
-               }
-       } else if (lcladv & ADVERTISE_PAUSE_ASYM) {
-               if ((rmtadv & LPA_PAUSE_CAP) && (rmtadv & LPA_PAUSE_ASYM))
-                       cap = FLOW_CTRL_TX;
-       }
-
-       return cap;
-}
-
 static void smsc911x_phy_update_flowcontrol(struct smsc911x_data *pdata)
 {
        struct phy_device *phy_dev = pdata->phy_dev;
@@ -673,7 +652,7 @@ static void smsc911x_phy_update_flowcontrol(struct smsc911x_data *pdata)
        if (phy_dev->duplex == DUPLEX_FULL) {
                u16 lcladv = phy_read(phy_dev, MII_ADVERTISE);
                u16 rmtadv = phy_read(phy_dev, MII_LPA);
-               u8 cap = smsc95xx_resolve_flowctrl_fulldplx(lcladv, rmtadv);
+               u8 cap = mii_resolve_flowctrl_fdx(lcladv, rmtadv);
 
                if (cap & FLOW_CTRL_RX)
                        flow = 0xFFFF0002;
@@ -790,7 +769,7 @@ static int smsc911x_mii_probe(struct net_device *dev)
        }
 
        phydev = phy_connect(dev, phydev->dev.bus_id,
-               &smsc911x_phy_adjust_link, 0, pdata->phy_interface);
+               &smsc911x_phy_adjust_link, 0, pdata->config.phy_interface);
 
        if (IS_ERR(phydev)) {
                pr_err("%s: Could not attach to PHY\n", dev->name);
@@ -843,7 +822,6 @@ static int __devinit smsc911x_mii_init(struct platform_device *pdev,
                pdata->mii_bus->irq[i] = PHY_POLL;
 
        pdata->mii_bus->parent = &pdev->dev;
-       dev_set_drvdata(&pdev->dev, &pdata->mii_bus);
 
        pdata->using_extphy = 0;
 
@@ -1005,7 +983,7 @@ static int smsc911x_poll(struct napi_struct *napi, int budget)
                        /* We processed all packets available.  Tell NAPI it can
                         * stop polling then re-enable rx interrupts */
                        smsc911x_reg_write(pdata, INT_STS, INT_STS_RSFL_);
-                       netif_rx_complete(dev, napi);
+                       netif_rx_complete(napi);
                        temp = smsc911x_reg_read(pdata, INT_EN);
                        temp |= INT_EN_RSFL_EN_;
                        smsc911x_reg_write(pdata, INT_EN, temp);
@@ -1205,14 +1183,14 @@ static int smsc911x_open(struct net_device *dev)
        /* Set interrupt deassertion to 100uS */
        intcfg = ((10 << 24) | INT_CFG_IRQ_EN_);
 
-       if (pdata->irq_polarity) {
+       if (pdata->config.irq_polarity) {
                SMSC_TRACE(IFUP, "irq polarity: active high");
                intcfg |= INT_CFG_IRQ_POL_;
        } else {
                SMSC_TRACE(IFUP, "irq polarity: active low");
        }
 
-       if (pdata->irq_type) {
+       if (pdata->config.irq_type) {
                SMSC_TRACE(IFUP, "irq type: push-pull");
                intcfg |= INT_CFG_IRQ_TYPE_;
        } else {
@@ -1288,8 +1266,6 @@ static int smsc911x_stop(struct net_device *dev)
        struct smsc911x_data *pdata = netdev_priv(dev);
        unsigned int temp;
 
-       BUG_ON(!pdata->phy_dev);
-
        /* Disable all device interrupts */
        temp = smsc911x_reg_read(pdata, INT_CFG);
        temp &= ~INT_CFG_IRQ_EN_;
@@ -1304,7 +1280,8 @@ static int smsc911x_stop(struct net_device *dev)
        smsc911x_tx_update_txcounters(dev);
 
        /* Bring the PHY down */
-       phy_stop(pdata->phy_dev);
+       if (pdata->phy_dev)
+               phy_stop(pdata->phy_dev);
 
        SMSC_TRACE(IFDOWN, "Interface stopped");
        return 0;
@@ -1507,13 +1484,13 @@ static irqreturn_t smsc911x_irqhandler(int irq, void *dev_id)
        }
 
        if (likely(intsts & inten & INT_STS_RSFL_)) {
-               if (likely(netif_rx_schedule_prep(dev, &pdata->napi))) {
+               if (likely(netif_rx_schedule_prep(&pdata->napi))) {
                        /* Disable Rx interrupts */
                        temp = smsc911x_reg_read(pdata, INT_EN);
                        temp &= (~INT_EN_RSFL_EN_);
                        smsc911x_reg_write(pdata, INT_EN, temp);
                        /* Schedule a NAPI poll */
-                       __netif_rx_schedule(dev, &pdata->napi);
+                       __netif_rx_schedule(&pdata->napi);
                } else {
                        SMSC_WARNING(RX_ERR,
                                "netif_rx_schedule_prep failed");
@@ -1525,7 +1502,7 @@ static irqreturn_t smsc911x_irqhandler(int irq, void *dev_id)
 }
 
 #ifdef CONFIG_NET_POLL_CONTROLLER
-void smsc911x_poll_controller(struct net_device *dev)
+static void smsc911x_poll_controller(struct net_device *dev)
 {
        disable_irq(dev->irq);
        smsc911x_irqhandler(0, dev);
@@ -1740,7 +1717,7 @@ static int smsc911x_ethtool_set_eeprom(struct net_device *dev,
        return ret;
 }
 
-static struct ethtool_ops smsc911x_ethtool_ops = {
+static const struct ethtool_ops smsc911x_ethtool_ops = {
        .get_settings = smsc911x_ethtool_getsettings,
        .set_settings = smsc911x_ethtool_setsettings,
        .get_link = ethtool_op_get_link,
@@ -1755,6 +1732,19 @@ static struct ethtool_ops smsc911x_ethtool_ops = {
        .set_eeprom = smsc911x_ethtool_set_eeprom,
 };
 
+static const struct net_device_ops smsc911x_netdev_ops = {
+       .ndo_open               = smsc911x_open,
+       .ndo_stop               = smsc911x_stop,
+       .ndo_start_xmit         = smsc911x_hard_start_xmit,
+       .ndo_get_stats          = smsc911x_get_stats,
+       .ndo_set_multicast_list = smsc911x_set_multicast_list,
+       .ndo_do_ioctl           = smsc911x_do_ioctl,
+       .ndo_validate_addr      = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = smsc911x_poll_controller,
+#endif
+};
+
 /* Initializing private device structures, only called from probe */
 static int __devinit smsc911x_init(struct net_device *dev)
 {
@@ -1767,9 +1757,7 @@ static int __devinit smsc911x_init(struct net_device *dev)
        SMSC_TRACE(PROBE, "IRQ: %d", dev->irq);
        SMSC_TRACE(PROBE, "PHY will be autodetected.");
 
-#if (!SMSC_CAN_USE_32BIT)
        spin_lock_init(&pdata->dev_lock);
-#endif
 
        if (pdata->ioaddr == 0) {
                SMSC_WARNING(PROBE, "pdata->ioaddr: 0x00000000");
@@ -1852,20 +1840,11 @@ static int __devinit smsc911x_init(struct net_device *dev)
        smsc911x_reg_write(pdata, INT_EN, 0);
 
        ether_setup(dev);
-       dev->open = smsc911x_open;
-       dev->stop = smsc911x_stop;
-       dev->hard_start_xmit = smsc911x_hard_start_xmit;
-       dev->get_stats = smsc911x_get_stats;
-       dev->set_multicast_list = smsc911x_set_multicast_list;
        dev->flags |= IFF_MULTICAST;
-       dev->do_ioctl = smsc911x_do_ioctl;
        netif_napi_add(dev, &pdata->napi, smsc911x_poll, SMSC_NAPI_WEIGHT);
+       dev->netdev_ops = &smsc911x_netdev_ops;
        dev->ethtool_ops = &smsc911x_ethtool_ops;
 
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = smsc911x_poll_controller;
-#endif                         /* CONFIG_NET_POLL_CONTROLLER */
-
        return 0;
 }
 
@@ -1895,7 +1874,7 @@ static int __devexit smsc911x_drv_remove(struct platform_device *pdev)
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
                                           "smsc911x-memory");
        if (!res)
-               platform_get_resource(pdev, IORESOURCE_MEM, 0);
+               res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 
        release_mem_region(res->start, res->end - res->start);
 
@@ -1910,6 +1889,7 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
 {
        struct net_device *dev;
        struct smsc911x_data *pdata;
+       struct smsc911x_platform_config *config = pdev->dev.platform_data;
        struct resource *res;
        unsigned int intcfg = 0;
        int res_size;
@@ -1918,6 +1898,13 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
 
        pr_info("%s: Driver version %s.\n", SMSC_CHIPNAME, SMSC_DRV_VERSION);
 
+       /* platform data specifies irq & dynamic bus configuration */
+       if (!pdev->dev.platform_data) {
+               pr_warning("%s: platform_data not provided\n", SMSC_CHIPNAME);
+               retval = -ENODEV;
+               goto out_0;
+       }
+
        res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
                                           "smsc911x-memory");
        if (!res)
@@ -1949,15 +1936,8 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
        dev->irq = platform_get_irq(pdev, 0);
        pdata->ioaddr = ioremap_nocache(res->start, res_size);
 
-       /* copy config parameters across if present, otherwise pdata
-        * defaults to zeros */
-       if (pdev->dev.platform_data) {
-               struct smsc911x_platform_config *config =
-                       pdev->dev.platform_data;
-               pdata->irq_polarity = config->irq_polarity;
-               pdata->irq_type  = config->irq_type;
-               pdata->phy_interface = config->phy_interface;
-       }
+       /* copy config parameters across to pdata */
+       memcpy(&pdata->config, config, sizeof(pdata->config));
 
        pdata->dev = dev;
        pdata->msg_enable = ((1 << debug) - 1);
@@ -1974,10 +1954,10 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev)
                goto out_unmap_io_3;
 
        /* configure irq polarity and type before connecting isr */
-       if (pdata->irq_polarity == SMSC911X_IRQ_POLARITY_ACTIVE_HIGH)
+       if (pdata->config.irq_polarity == SMSC911X_IRQ_POLARITY_ACTIVE_HIGH)
                intcfg |= INT_CFG_IRQ_POL_;
 
-       if (pdata->irq_type == SMSC911X_IRQ_TYPE_PUSH_PULL)
+       if (pdata->config.irq_type == SMSC911X_IRQ_TYPE_PUSH_PULL)
                intcfg |= INT_CFG_IRQ_TYPE_;
 
        smsc911x_reg_write(pdata, INT_CFG, intcfg);