rtc: sh-rtc: Handle rtc_device_register() failure properly.
[safe/jmp/linux-2.6] / drivers / net / smc911x.c
index 797ab91..dd18af0 100644 (file)
@@ -77,7 +77,6 @@ static const char version[] =
 #include <linux/skbuff.h>
 
 #include <asm/io.h>
-#include <asm/irq.h>
 
 #include "smc911x.h"
 
@@ -116,13 +115,6 @@ struct smc911x_local {
         */
        struct sk_buff *pending_tx_skb;
 
-       /*
-        * these are things that the kernel wants me to keep, so users
-        * can find out semi-useless statistics of how well the card is
-        * performing
-        */
-       struct net_device_stats stats;
-
        /* version/revision of the SMC911x chip */
        u16 version;
        u16 revision;
@@ -148,6 +140,8 @@ struct smc911x_local {
        int tx_throttle;
        spinlock_t lock;
 
+       struct net_device *netdev;
+
 #ifdef SMC_USE_DMA
        /* DMA needs the physical address of the chip */
        u_long physaddr;
@@ -314,8 +308,8 @@ static void smc911x_reset(struct net_device *dev)
        if (lp->pending_tx_skb != NULL) {
                dev_kfree_skb (lp->pending_tx_skb);
                lp->pending_tx_skb = NULL;
-               lp->stats.tx_errors++;
-               lp->stats.tx_aborted_errors++;
+               dev->stats.tx_errors++;
+               dev->stats.tx_aborted_errors++;
        }
 }
 
@@ -448,14 +442,14 @@ static inline void         smc911x_rcv(struct net_device *dev)
        pkt_len = (status & RX_STS_PKT_LEN_) >> 16;
        if (status & RX_STS_ES_) {
                /* Deal with a bad packet */
-               lp->stats.rx_errors++;
+               dev->stats.rx_errors++;
                if (status & RX_STS_CRC_ERR_)
-                       lp->stats.rx_crc_errors++;
+                       dev->stats.rx_crc_errors++;
                else {
                        if (status & RX_STS_LEN_ERR_)
-                               lp->stats.rx_length_errors++;
+                               dev->stats.rx_length_errors++;
                        if (status & RX_STS_MCAST_)
-                               lp->stats.multicast++;
+                               dev->stats.multicast++;
                }
                /* Remove the bad packet data from the RX FIFO */
                smc911x_drop_pkt(dev);
@@ -466,7 +460,7 @@ static inline void   smc911x_rcv(struct net_device *dev)
                if (unlikely(skb == NULL)) {
                        PRINTK( "%s: Low memory, rcvd packet dropped.\n",
                                dev->name);
-                       lp->stats.rx_dropped++;
+                       dev->stats.rx_dropped++;
                        smc911x_drop_pkt(dev);
                        return;
                }
@@ -497,14 +491,13 @@ static inline void         smc911x_rcv(struct net_device *dev)
                SMC_SET_RX_CFG(RX_CFG_RX_END_ALGN4_ | ((2<<8) & RX_CFG_RXDOFF_));
                SMC_PULL_DATA(data, pkt_len+2+3);
 
-               DBG(SMC_DEBUG_PKTS, "%s: Received packet\n", dev->name,);
+               DBG(SMC_DEBUG_PKTS, "%s: Received packet\n", dev->name);
                PRINT_PKT(data, ((pkt_len - 4) <= 64) ? pkt_len - 4 : 64);
                dev->last_rx = jiffies;
-               skb->dev = dev;
                skb->protocol = eth_type_trans(skb, dev);
                netif_rx(skb);
-               lp->stats.rx_packets++;
-               lp->stats.rx_bytes += pkt_len-4;
+               dev->stats.rx_packets++;
+               dev->stats.rx_bytes += pkt_len-4;
 #endif
        }
 }
@@ -616,8 +609,8 @@ static int smc911x_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
                printk("%s: No Tx free space %d < %d\n",
                        dev->name, free, skb->len);
                lp->pending_tx_skb = NULL;
-               lp->stats.tx_errors++;
-               lp->stats.tx_dropped++;
+               dev->stats.tx_errors++;
+               dev->stats.tx_dropped++;
                dev_kfree_skb(skb);
                return 0;
        }
@@ -667,8 +660,8 @@ static void smc911x_tx(struct net_device *dev)
                        dev->name,
                        (SMC_GET_TX_FIFO_INF() & TX_FIFO_INF_TSUSED_) >> 16);
                tx_status = SMC_GET_TX_STS_FIFO();
-               lp->stats.tx_packets++;
-               lp->stats.tx_bytes+=tx_status>>16;
+               dev->stats.tx_packets++;
+               dev->stats.tx_bytes+=tx_status>>16;
                DBG(SMC_DEBUG_TX, "%s: Tx FIFO tag 0x%04x status 0x%04x\n",
                        dev->name, (tx_status & 0xffff0000) >> 16,
                        tx_status & 0x0000ffff);
@@ -676,22 +669,22 @@ static void smc911x_tx(struct net_device *dev)
                 * full-duplex mode */
                if ((tx_status & TX_STS_ES_) && !(lp->ctl_rfduplx &&
                    !(tx_status & 0x00000306))) {
-                       lp->stats.tx_errors++;
+                       dev->stats.tx_errors++;
                }
                if (tx_status & TX_STS_MANY_COLL_) {
-                       lp->stats.collisions+=16;
-                       lp->stats.tx_aborted_errors++;
+                       dev->stats.collisions+=16;
+                       dev->stats.tx_aborted_errors++;
                } else {
-                       lp->stats.collisions+=(tx_status & TX_STS_COLL_CNT_) >> 3;
+                       dev->stats.collisions+=(tx_status & TX_STS_COLL_CNT_) >> 3;
                }
                /* carrier error only has meaning for half-duplex communication */
                if ((tx_status & (TX_STS_LOC_ | TX_STS_NO_CARR_)) &&
                    !lp->ctl_rfduplx) {
-                       lp->stats.tx_carrier_errors++;
+                       dev->stats.tx_carrier_errors++;
                }
                if (tx_status & TX_STS_LATE_COLL_) {
-                       lp->stats.collisions++;
-                       lp->stats.tx_aborted_errors++;
+                       dev->stats.collisions++;
+                       dev->stats.tx_aborted_errors++;
                }
        }
 }
@@ -948,10 +941,11 @@ static void smc911x_phy_check_media(struct net_device *dev, int init)
  * of autonegotiation.)  If the RPC ANEG bit is cleared, the selection
  * is controlled by the RPC SPEED and RPC DPLX bits.
  */
-static void smc911x_phy_configure(void *data)
+static void smc911x_phy_configure(struct work_struct *work)
 {
-       struct net_device *dev = data;
-       struct smc911x_local *lp = netdev_priv(dev);
+       struct smc911x_local *lp = container_of(work, struct smc911x_local,
+                                               phy_configure);
+       struct net_device *dev = lp->netdev;
        unsigned long ioaddr = dev->base_addr;
        int phyaddr = lp->mii.phy_id;
        int my_phy_caps; /* My PHY capabilities */
@@ -965,11 +959,11 @@ static void smc911x_phy_configure(void *data)
         * We should not be called if phy_type is zero.
         */
        if (lp->phy_type == 0)
-                goto smc911x_phy_configure_exit;
+                goto smc911x_phy_configure_exit_nolock;
 
        if (smc911x_phy_reset(dev, phyaddr)) {
                printk("%s: PHY reset timed out\n", dev->name);
-               goto smc911x_phy_configure_exit;
+               goto smc911x_phy_configure_exit_nolock;
        }
        spin_lock_irqsave(&lp->lock, flags);
 
@@ -1038,6 +1032,7 @@ static void smc911x_phy_configure(void *data)
 
 smc911x_phy_configure_exit:
        spin_unlock_irqrestore(&lp->lock, flags);
+smc911x_phy_configure_exit_nolock:
        lp->work_pending = 0;
 }
 
@@ -1119,11 +1114,11 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
                /* Handle various error conditions */
                if (status & INT_STS_RXE_) {
                        SMC_ACK_INT(INT_STS_RXE_);
-                       lp->stats.rx_errors++;
+                       dev->stats.rx_errors++;
                }
                if (status & INT_STS_RXDFH_INT_) {
                        SMC_ACK_INT(INT_STS_RXDFH_INT_);
-                       lp->stats.rx_dropped+=SMC_GET_RX_DROP();
+                       dev->stats.rx_dropped+=SMC_GET_RX_DROP();
                 }
                /* Undocumented interrupt-what is the right thing to do here? */
                if (status & INT_STS_RXDF_INT_) {
@@ -1138,8 +1133,8 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
                                cr &= ~MAC_CR_RXEN_;
                                SMC_SET_MAC_CR(cr);
                                DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name);
-                               lp->stats.rx_errors++;
-                               lp->stats.rx_fifo_errors++;
+                               dev->stats.rx_errors++;
+                               dev->stats.rx_fifo_errors++;
                        }
                        SMC_ACK_INT(INT_STS_RDFL_);
                }
@@ -1150,8 +1145,8 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
                                SMC_SET_MAC_CR(cr);
                                rx_overrun=1;
                                DBG(SMC_DEBUG_RX, "%s: RX overrun\n", dev->name);
-                               lp->stats.rx_errors++;
-                               lp->stats.rx_fifo_errors++;
+                               dev->stats.rx_errors++;
+                               dev->stats.rx_fifo_errors++;
                        }
                        SMC_ACK_INT(INT_STS_RDFO_);
                }
@@ -1228,7 +1223,7 @@ static irqreturn_t smc911x_interrupt(int irq, void *dev_id)
                }
 #endif
 
-               /* Handle PHY interupt condition */
+               /* Handle PHY interrupt condition */
                if (status & INT_STS_PHY_INT_) {
                        DBG(SMC_DEBUG_MISC, "%s: PHY irq\n", dev->name);
                        smc911x_phy_interrupt(dev);
@@ -1303,11 +1298,10 @@ smc911x_rx_dma_irq(int dma, void *data)
        lp->current_rx_skb = NULL;
        PRINT_PKT(skb->data, skb->len);
        dev->last_rx = jiffies;
-       skb->dev = dev;
        skb->protocol = eth_type_trans(skb, dev);
        netif_rx(skb);
-       lp->stats.rx_packets++;
-       lp->stats.rx_bytes += skb->len;
+       dev->stats.rx_packets++;
+       dev->stats.rx_bytes += skb->len;
 
        spin_lock_irqsave(&lp->lock, flags);
        pkts = (SMC_GET_RX_FIFO_INF() & RX_FIFO_INF_RXSUSED_) >> 16;
@@ -1495,6 +1489,8 @@ static void smc911x_set_multicast_list(struct net_device *dev)
 static int
 smc911x_open(struct net_device *dev)
 {
+       struct smc911x_local *lp = netdev_priv(dev);
+
        DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
 
        /*
@@ -1511,7 +1507,7 @@ smc911x_open(struct net_device *dev)
        smc911x_reset(dev);
 
        /* Configure the PHY, initialize the link state */
-       smc911x_phy_configure(dev);
+       smc911x_phy_configure(&lp->phy_configure);
 
        /* Turn on Tx + Rx */
        smc911x_enable(dev);
@@ -1565,19 +1561,6 @@ static int smc911x_close(struct net_device *dev)
 }
 
 /*
- * Get the current statistics.
- * This may be called with the card open or closed.
- */
-static struct net_device_stats *smc911x_query_statistics(struct net_device *dev)
-{
-       struct smc911x_local *lp = netdev_priv(dev);
-       DBG(SMC_DEBUG_FUNC, "%s: --> %s\n", dev->name, __FUNCTION__);
-
-
-       return &lp->stats;
-}
-
-/*
  * Ethtool support
  */
 static int
@@ -1653,7 +1636,7 @@ smc911x_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
 {
        strncpy(info->driver, CARDNAME, sizeof(info->driver));
        strncpy(info->version, version, sizeof(info->version));
-       strncpy(info->bus_info, dev->class_dev.dev->bus_id, sizeof(info->bus_info));
+       strncpy(info->bus_info, dev->dev.parent->bus_id, sizeof(info->bus_info));
 }
 
 static int smc911x_ethtool_nwayreset(struct net_device *dev)
@@ -2053,14 +2036,13 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
        dev->hard_start_xmit = smc911x_hard_start_xmit;
        dev->tx_timeout = smc911x_timeout;
        dev->watchdog_timeo = msecs_to_jiffies(watchdog);
-       dev->get_stats = smc911x_query_statistics;
        dev->set_multicast_list = smc911x_set_multicast_list;
        dev->ethtool_ops = &smc911x_ethtool_ops;
 #ifdef CONFIG_NET_POLL_CONTROLLER
        dev->poll_controller = smc911x_poll_controller;
 #endif
 
-       INIT_WORK(&lp->phy_configure, smc911x_phy_configure, dev);
+       INIT_WORK(&lp->phy_configure, smc911x_phy_configure);
        lp->mii.phy_id_mask = 0x1f;
        lp->mii.reg_num_mask = 0x1f;
        lp->mii.force_media = 0;
@@ -2080,12 +2062,11 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
        lp->ctl_rspeed = 100;
 
        /* Grab the IRQ */
-       retval = request_irq(dev->irq, &smc911x_interrupt, IRQF_SHARED, dev->name, dev);
+       retval = request_irq(dev->irq, &smc911x_interrupt,
+                       IRQF_SHARED | SMC_IRQ_SENSE, dev->name, dev);
        if (retval)
                goto err_out;
 
-       set_irq_type(dev->irq, IRQT_FALLING);
-
 #ifdef SMC_USE_DMA
        lp->rxdma = SMC_DMA_REQUEST(dev, smc911x_rx_dma_irq);
        lp->txdma = SMC_DMA_REQUEST(dev, smc911x_tx_dma_irq);
@@ -2154,6 +2135,7 @@ static int smc911x_drv_probe(struct platform_device *pdev)
 {
        struct net_device *ndev;
        struct resource *res;
+       struct smc911x_local *lp;
        unsigned int *addr;
        int ret;
 
@@ -2178,11 +2160,12 @@ static int smc911x_drv_probe(struct platform_device *pdev)
                ret = -ENOMEM;
                goto release_1;
        }
-       SET_MODULE_OWNER(ndev);
        SET_NETDEV_DEV(ndev, &pdev->dev);
 
        ndev->dma = (unsigned char)-1;
        ndev->irq = platform_get_irq(pdev, 0);
+       lp = netdev_priv(ndev);
+       lp->netdev = ndev;
 
        addr = ioremap(res->start, SMC911X_IO_EXTENT);
        if (!addr) {
@@ -2204,7 +2187,6 @@ out:
        }
 #ifdef SMC_USE_DMA
        else {
-               struct smc911x_local *lp = netdev_priv(ndev);
                lp->physaddr = res->start;
                lp->dev = &pdev->dev;
        }
@@ -2275,7 +2257,7 @@ static int smc911x_drv_resume(struct platform_device *dev)
                        smc911x_reset(ndev);
                        smc911x_enable(ndev);
                        if (lp->phy_type != 0)
-                               smc911x_phy_configure(ndev);
+                               smc911x_phy_configure(&lp->phy_configure);
                        netif_device_attach(ndev);
                }
        }