drivers/net/skge.c: Use netif_printk macros
[safe/jmp/linux-2.6] / drivers / net / macb.c
index a04da4e..7a5f897 100644 (file)
@@ -189,18 +189,11 @@ static void macb_handle_link_change(struct net_device *dev)
 static int macb_mii_probe(struct net_device *dev)
 {
        struct macb *bp = netdev_priv(dev);
-       struct phy_device *phydev = NULL;
+       struct phy_device *phydev;
        struct eth_platform_data *pdata;
-       int phy_addr;
-
-       /* find the first phy */
-       for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
-               if (bp->mii_bus->phy_map[phy_addr]) {
-                       phydev = bp->mii_bus->phy_map[phy_addr];
-                       break;
-               }
-       }
+       int ret;
 
+       phydev = phy_find_first(bp->mii_bus);
        if (!phydev) {
                printk (KERN_ERR "%s: no PHY found\n", dev->name);
                return -1;
@@ -210,17 +203,13 @@ static int macb_mii_probe(struct net_device *dev)
        /* TODO : add pin_irq */
 
        /* attach the mac to the phy */
-       if (pdata && pdata->is_rmii) {
-               phydev = phy_connect(dev, phydev->dev.bus_id,
-                       &macb_handle_link_change, 0, PHY_INTERFACE_MODE_RMII);
-       } else {
-               phydev = phy_connect(dev, phydev->dev.bus_id,
-                       &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII);
-       }
-
-       if (IS_ERR(phydev)) {
+       ret = phy_connect_direct(dev, phydev, &macb_handle_link_change, 0,
+                                pdata && pdata->is_rmii ?
+                                PHY_INTERFACE_MODE_RMII :
+                                PHY_INTERFACE_MODE_MII);
+       if (ret) {
                printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
-               return PTR_ERR(phydev);
+               return ret;
        }
 
        /* mask with MAC supported features */
@@ -241,7 +230,7 @@ static int macb_mii_init(struct macb *bp)
        struct eth_platform_data *pdata;
        int err = -ENXIO, i;
 
-       /* Enable managment port */
+       /* Enable management port */
        macb_writel(bp, NCR, MACB_BIT(MPE));
 
        bp->mii_bus = mdiobus_alloc();
@@ -316,10 +305,15 @@ static void macb_tx(struct macb *bp)
        dev_dbg(&bp->pdev->dev, "macb_tx status = %02lx\n",
                (unsigned long)status);
 
-       if (status & MACB_BIT(UND)) {
+       if (status & (MACB_BIT(UND) | MACB_BIT(TSR_RLE))) {
                int i;
-               printk(KERN_ERR "%s: TX underrun, resetting buffers\n",
-                       bp->dev->name);
+               printk(KERN_ERR "%s: TX %s, resetting buffers\n",
+                       bp->dev->name, status & MACB_BIT(UND) ?
+                       "underrun" : "retry limit exceeded");
+
+               /* Transfer ongoing, disable transmitter, to avoid confusion */
+               if (status & MACB_BIT(TGO))
+                       macb_writel(bp, NCR, macb_readl(bp, NCR) & ~MACB_BIT(TE));
 
                head = bp->tx_head;
 
@@ -343,6 +337,10 @@ static void macb_tx(struct macb *bp)
                }
 
                bp->tx_head = bp->tx_tail = 0;
+
+               /* Enable the transmitter again */
+               if (status & MACB_BIT(TGO))
+                       macb_writel(bp, NCR, macb_readl(bp, NCR) | MACB_BIT(TE));
        }
 
        if (!(status & MACB_BIT(COMP)))
@@ -505,7 +503,6 @@ static int macb_rx(struct macb *bp, int budget)
 static int macb_poll(struct napi_struct *napi, int budget)
 {
        struct macb *bp = container_of(napi, struct macb, napi);
-       struct net_device *dev = bp->dev;
        int work_done;
        u32 status;
 
@@ -513,36 +510,18 @@ static int macb_poll(struct napi_struct *napi, int budget)
        macb_writel(bp, RSR, status);
 
        work_done = 0;
-       if (!status) {
-               /*
-                * This may happen if an interrupt was pending before
-                * this function was called last time, and no packets
-                * have been received since.
-                */
-               netif_rx_complete(napi);
-               goto out;
-       }
 
        dev_dbg(&bp->pdev->dev, "poll: status = %08lx, budget = %d\n",
                (unsigned long)status, budget);
 
-       if (!(status & MACB_BIT(REC))) {
-               dev_warn(&bp->pdev->dev,
-                        "No RX buffers complete, status = %02lx\n",
-                        (unsigned long)status);
-               netif_rx_complete(napi);
-               goto out;
-       }
-
        work_done = macb_rx(bp, budget);
        if (work_done < budget)
-               netif_rx_complete(napi);
+               napi_complete(napi);
 
        /*
         * We've done what we can to clean the buffers. Make sure we
         * get notified when new packets arrive.
         */
-out:
        macb_writel(bp, IER, MACB_RX_INT_FLAGS);
 
        /* TODO: Handle errors */
@@ -571,7 +550,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
                }
 
                if (status & MACB_RX_INT_FLAGS) {
-                       if (netif_rx_schedule_prep(&bp->napi)) {
+                       if (napi_schedule_prep(&bp->napi)) {
                                /*
                                 * There's no point taking any more interrupts
                                 * until we have processed the buffers
@@ -579,11 +558,12 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
                                macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
                                dev_dbg(&bp->pdev->dev,
                                        "scheduling RX softirq\n");
-                               __netif_rx_schedule(&bp->napi);
+                               __napi_schedule(&bp->napi);
                        }
                }
 
-               if (status & (MACB_BIT(TCOMP) | MACB_BIT(ISR_TUND)))
+               if (status & (MACB_BIT(TCOMP) | MACB_BIT(ISR_TUND) |
+                           MACB_BIT(ISR_RLE)))
                        macb_tx(bp);
 
                /*
@@ -608,12 +588,28 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
        return IRQ_HANDLED;
 }
 
+#ifdef CONFIG_NET_POLL_CONTROLLER
+/*
+ * Polling receive - used by netconsole and other diagnostic tools
+ * to allow network i/o with interrupts disabled.
+ */
+static void macb_poll_controller(struct net_device *dev)
+{
+       unsigned long flags;
+
+       local_irq_save(flags);
+       macb_interrupt(dev->irq, dev);
+       local_irq_restore(flags);
+}
+#endif
+
 static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
        struct macb *bp = netdev_priv(dev);
        dma_addr_t mapping;
        unsigned int len, entry;
        u32 ctrl;
+       unsigned long flags;
 
 #ifdef DEBUG
        int i;
@@ -629,17 +625,17 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
 #endif
 
        len = skb->len;
-       spin_lock_irq(&bp->lock);
+       spin_lock_irqsave(&bp->lock, flags);
 
        /* This is a hard error, log it. */
        if (TX_BUFFS_AVAIL(bp) < 1) {
                netif_stop_queue(dev);
-               spin_unlock_irq(&bp->lock);
+               spin_unlock_irqrestore(&bp->lock, flags);
                dev_err(&bp->pdev->dev,
                        "BUG! Tx Ring full when queue awake!\n");
                dev_dbg(&bp->pdev->dev, "tx_head = %u, tx_tail = %u\n",
                        bp->tx_head, bp->tx_tail);
-               return 1;
+               return NETDEV_TX_BUSY;
        }
 
        entry = bp->tx_head;
@@ -668,11 +664,11 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
        if (TX_BUFFS_AVAIL(bp) < 1)
                netif_stop_queue(dev);
 
-       spin_unlock_irq(&bp->lock);
+       spin_unlock_irqrestore(&bp->lock, flags);
 
        dev->trans_start = jiffies;
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static void macb_free_consistent(struct macb *bp)
@@ -894,7 +890,7 @@ static void macb_sethashtable(struct net_device *dev)
        mc_filter[0] = mc_filter[1] = 0;
 
        curr = dev->mc_list;
-       for (i = 0; i < dev->mc_count; i++, curr = curr->next) {
+       for (i = 0; i < netdev_mc_count(dev); i++, curr = curr->next) {
                if (!curr) break;       /* unexpected end of list */
 
                bitnr = hash_get_index(curr->dmi_addr);
@@ -927,7 +923,7 @@ static void macb_set_rx_mode(struct net_device *dev)
                macb_writel(bp, HRB, -1);
                macb_writel(bp, HRT, -1);
                cfg |= MACB_BIT(NCFGR_MTI);
-       } else if (dev->mc_count > 0) {
+       } else if (!netdev_mc_empty(dev)) {
                /* Enable specific multicasts */
                macb_sethashtable(dev);
                cfg |= MACB_BIT(NCFGR_MTI);
@@ -1069,10 +1065,10 @@ static void macb_get_drvinfo(struct net_device *dev,
 
        strcpy(info->driver, bp->pdev->dev.driver->name);
        strcpy(info->version, "$Revision: 1.14 $");
-       strcpy(info->bus_info, bp->pdev->dev.bus_id);
+       strcpy(info->bus_info, dev_name(&bp->pdev->dev));
 }
 
-static struct ethtool_ops macb_ethtool_ops = {
+static const struct ethtool_ops macb_ethtool_ops = {
        .get_settings           = macb_get_settings,
        .set_settings           = macb_set_settings,
        .get_drvinfo            = macb_get_drvinfo,
@@ -1093,6 +1089,21 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        return phy_mii_ioctl(phydev, if_mii(rq), cmd);
 }
 
+static const struct net_device_ops macb_netdev_ops = {
+       .ndo_open               = macb_open,
+       .ndo_stop               = macb_close,
+       .ndo_start_xmit         = macb_start_xmit,
+       .ndo_set_multicast_list = macb_set_rx_mode,
+       .ndo_get_stats          = macb_get_stats,
+       .ndo_do_ioctl           = macb_ioctl,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = macb_poll_controller,
+#endif
+};
+
 static int __init macb_probe(struct platform_device *pdev)
 {
        struct eth_platform_data *pdata;
@@ -1168,12 +1179,7 @@ static int __init macb_probe(struct platform_device *pdev)
                goto err_out_iounmap;
        }
 
-       dev->open = macb_open;
-       dev->stop = macb_close;
-       dev->hard_start_xmit = macb_start_xmit;
-       dev->get_stats = macb_get_stats;
-       dev->set_multicast_list = macb_set_rx_mode;
-       dev->do_ioctl = macb_ioctl;
+       dev->netdev_ops = &macb_netdev_ops;
        netif_napi_add(dev, &bp->napi, macb_poll, 64);
        dev->ethtool_ops = &macb_ethtool_ops;
 
@@ -1226,8 +1232,8 @@ static int __init macb_probe(struct platform_device *pdev)
 
        phydev = bp->phy_dev;
        printk(KERN_INFO "%s: attached PHY driver [%s] "
-               "(mii_bus:phy_addr=%s, irq=%d)\n",
-               dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
+               "(mii_bus:phy_addr=%s, irq=%d)\n", dev->name,
+               phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
 
        return 0;