drivers/net/skge.c: Use netif_printk macros
[safe/jmp/linux-2.6] / drivers / net / skge.c
index 18a7b66..ffa55df 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/crc32.h>
 #include <linux/dma-mapping.h>
 #include <linux/debugfs.h>
+#include <linux/sched.h>
 #include <linux/seq_file.h>
 #include <linux/mii.h>
 #include <asm/irq.h>
@@ -77,7 +78,7 @@ static int debug = -1;        /* defaults above */
 module_param(debug, int, 0);
 MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)");
 
-static const struct pci_device_id skge_id_table[] = {
+static DEFINE_PCI_DEVICE_TABLE(skge_id_table) = {
        { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940) },
        { PCI_DEVICE(PCI_VENDOR_ID_3COM, PCI_DEVICE_ID_3COM_3C940B) },
        { PCI_DEVICE(PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE) },
@@ -215,7 +216,7 @@ static void skge_wol_init(struct skge_port *skge)
        if (skge->wol & WAKE_MAGIC)
                ctrl |= WOL_CTL_ENA_PME_ON_MAGIC_PKT|WOL_CTL_ENA_MAGIC_PKT_UNIT;
        else
-               ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;;
+               ctrl |= WOL_CTL_DIS_PME_ON_MAGIC_PKT|WOL_CTL_DIS_MAGIC_PKT_UNIT;
 
        ctrl |= WOL_CTL_DIS_PME_ON_PATTERN|WOL_CTL_DIS_PATTERN_UNIT;
        skge_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
@@ -237,8 +238,8 @@ static int skge_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
        struct skge_port *skge = netdev_priv(dev);
        struct skge_hw *hw = skge->hw;
 
-       if ((wol->wolopts & ~wol_supported(hw))
-           || !device_can_wakeup(&hw->pdev->dev))
+       if ((wol->wolopts & ~wol_supported(hw)) ||
+           !device_can_wakeup(&hw->pdev->dev))
                return -EOPNOTSUPP;
 
        skge->wol = wol->wolopts;
@@ -575,9 +576,10 @@ static void skge_get_pauseparam(struct net_device *dev,
 {
        struct skge_port *skge = netdev_priv(dev);
 
-       ecmd->rx_pause = (skge->flow_control == FLOW_MODE_SYMMETRIC)
-               || (skge->flow_control == FLOW_MODE_SYM_OR_REM);
-       ecmd->tx_pause = ecmd->rx_pause || (skge->flow_control == FLOW_MODE_LOC_SEND);
+       ecmd->rx_pause = ((skge->flow_control == FLOW_MODE_SYMMETRIC) ||
+                         (skge->flow_control == FLOW_MODE_SYM_OR_REM));
+       ecmd->tx_pause = (ecmd->rx_pause ||
+                         (skge->flow_control == FLOW_MODE_LOC_SEND));
 
        ecmd->autoneg = ecmd->rx_pause || ecmd->tx_pause;
 }
@@ -1072,13 +1074,11 @@ static void skge_link_up(struct skge_port *skge)
        netif_carrier_on(skge->netdev);
        netif_wake_queue(skge->netdev);
 
-       if (netif_msg_link(skge)) {
-               printk(KERN_INFO PFX
-                      "%s: Link is up at %d Mbps, %s duplex, flow control %s\n",
-                      skge->netdev->name, skge->speed,
-                      skge->duplex == DUPLEX_FULL ? "full" : "half",
-                      skge_pause(skge->flow_status));
-       }
+       netif_info(skge, link, skge->netdev,
+                  "Link is up at %d Mbps, %s duplex, flow control %s\n",
+                  skge->speed,
+                  skge->duplex == DUPLEX_FULL ? "full" : "half",
+                  skge_pause(skge->flow_status));
 }
 
 static void skge_link_down(struct skge_port *skge)
@@ -1087,8 +1087,7 @@ static void skge_link_down(struct skge_port *skge)
        netif_carrier_off(skge->netdev);
        netif_stop_queue(skge->netdev);
 
-       if (netif_msg_link(skge))
-               printk(KERN_INFO PFX "%s: Link is down.\n", skge->netdev->name);
+       netif_info(skge, link, skge->netdev, "Link is down\n");
 }
 
 
@@ -1790,9 +1789,8 @@ static void genesis_mac_intr(struct skge_hw *hw, int port)
        struct skge_port *skge = netdev_priv(dev);
        u16 status = xm_read16(hw, port, XM_ISRC);
 
-       if (netif_msg_intr(skge))
-               printk(KERN_DEBUG PFX "%s: mac interrupt status 0x%x\n",
-                      dev->name, status);
+       netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
+                    "mac interrupt status 0x%x\n", status);
 
        if (hw->phy_type == SK_PHY_XMAC && (status & XM_IS_INP_ASS)) {
                xm_link_down(hw, port);
@@ -1896,9 +1894,8 @@ static inline void bcom_phy_intr(struct skge_port *skge)
        u16 isrc;
 
        isrc = xm_phy_read(hw, port, PHY_BCOM_INT_STAT);
-       if (netif_msg_intr(skge))
-               printk(KERN_DEBUG PFX "%s: phy interrupt status 0x%x\n",
-                      skge->netdev->name, isrc);
+       netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
+                    "phy interrupt status 0x%x\n", isrc);
 
        if (isrc & PHY_B_IS_PSE)
                printk(KERN_ERR PFX "%s: uncorrectable pair swap error\n",
@@ -2296,9 +2293,8 @@ static void yukon_mac_intr(struct skge_hw *hw, int port)
        struct skge_port *skge = netdev_priv(dev);
        u8 status = skge_read8(hw, SK_REG(port, GMAC_IRQ_SRC));
 
-       if (netif_msg_intr(skge))
-               printk(KERN_DEBUG PFX "%s: mac interrupt status 0x%x\n",
-                      dev->name, status);
+       netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
+                    "mac interrupt status 0x%x\n", status);
 
        if (status & GM_IS_RX_FF_OR) {
                ++dev->stats.rx_fifo_errors;
@@ -2377,9 +2373,8 @@ static void yukon_phy_intr(struct skge_port *skge)
        istatus = gm_phy_read(hw, port, PHY_MARV_INT_STAT);
        phystat = gm_phy_read(hw, port, PHY_MARV_PHY_STAT);
 
-       if (netif_msg_intr(skge))
-               printk(KERN_DEBUG PFX "%s: phy interrupt status 0x%x 0x%x\n",
-                      skge->netdev->name, istatus, phystat);
+       netif_printk(skge, intr, KERN_DEBUG, skge->netdev,
+                    "phy interrupt status 0x%x 0x%x\n", istatus, phystat);
 
        if (istatus & PHY_M_IS_AN_COMPL) {
                if (gm_phy_read(hw, port, PHY_MARV_AUNE_LP)
@@ -2496,9 +2491,6 @@ static int skge_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
        }
 
        case SIOCSMIIREG:
-               if (!capable(CAP_NET_ADMIN))
-                       return -EPERM;
-
                spin_lock_bh(&hw->phy_lock);
                if (hw->chip_id == CHIP_ID_GENESIS)
                        err = xm_phy_write(hw, skge->port, data->reg_num & 0x1f,
@@ -2572,8 +2564,7 @@ static int skge_up(struct net_device *dev)
        if (!is_valid_ether_addr(dev->dev_addr))
                return -EINVAL;
 
-       if (netif_msg_ifup(skge))
-               printk(KERN_INFO PFX "%s: enabling interface\n", dev->name);
+       netif_info(skge, ifup, skge->netdev, "enabling interface\n");
 
        if (dev->mtu > RX_BUF_SIZE)
                skge->rx_buf_size = dev->mtu + ETH_HLEN;
@@ -2671,10 +2662,9 @@ static int skge_down(struct net_device *dev)
        if (skge->mem == NULL)
                return 0;
 
-       if (netif_msg_ifdown(skge))
-               printk(KERN_INFO PFX "%s: disabling interface\n", dev->name);
+       netif_info(skge, ifdown, skge->netdev, "disabling interface\n");
 
-       netif_stop_queue(dev);
+       netif_tx_disable(dev);
 
        if (hw->chip_id == CHIP_ID_GENESIS && hw->phy_type == SK_PHY_XMAC)
                del_timer_sync(&skge->link_timer);
@@ -2746,7 +2736,8 @@ static inline int skge_avail(const struct skge_ring *ring)
                + (ring->to_clean - ring->to_use) - 1;
 }
 
-static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t skge_xmit_frame(struct sk_buff *skb,
+                                  struct net_device *dev)
 {
        struct skge_port *skge = netdev_priv(dev);
        struct skge_hw *hw = skge->hw;
@@ -2780,8 +2771,8 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
                /* This seems backwards, but it is what the sk98lin
                 * does.  Looks like hardware is wrong?
                 */
-               if (ipip_hdr(skb)->protocol == IPPROTO_UDP
-                   && hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
+               if (ipip_hdr(skb)->protocol == IPPROTO_UDP &&
+                   hw->chip_rev == 0 && hw->chip_id == CHIP_ID_YUKON)
                        control = BMU_TCP_CHECK;
                else
                        control = BMU_UDP_CHECK;
@@ -2825,9 +2816,9 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
 
        skge_write8(hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_START);
 
-       if (unlikely(netif_msg_tx_queued(skge)))
-               printk(KERN_DEBUG "%s: tx queued, slot %td, len %d\n",
-                      dev->name, e - skge->tx_ring.start, skb->len);
+       netif_printk(skge, tx_queued, KERN_DEBUG, skge->netdev,
+                    "tx queued, slot %td, len %d\n",
+                    e - skge->tx_ring.start, skb->len);
 
        skge->tx_ring.to_use = e->next;
        smp_wmb();
@@ -2837,8 +2828,6 @@ static int skge_xmit_frame(struct sk_buff *skb, struct net_device *dev)
                netif_stop_queue(dev);
        }
 
-       dev->trans_start = jiffies;
-
        return NETDEV_TX_OK;
 }
 
@@ -2860,9 +2849,8 @@ static void skge_tx_free(struct skge_port *skge, struct skge_element *e,
                               PCI_DMA_TODEVICE);
 
        if (control & BMU_EOF) {
-               if (unlikely(netif_msg_tx_done(skge)))
-                       printk(KERN_DEBUG PFX "%s: tx done slot %td\n",
-                              skge->netdev->name, e - skge->tx_ring.start);
+               netif_printk(skge, tx_done, KERN_DEBUG, skge->netdev,
+                            "tx done slot %td\n", e - skge->tx_ring.start);
 
                dev_kfree_skb(e->skb);
        }
@@ -2881,18 +2869,17 @@ static void skge_tx_clean(struct net_device *dev)
        }
 
        skge->tx_ring.to_clean = e;
-       netif_wake_queue(dev);
 }
 
 static void skge_tx_timeout(struct net_device *dev)
 {
        struct skge_port *skge = netdev_priv(dev);
 
-       if (netif_msg_timer(skge))
-               printk(KERN_DEBUG PFX "%s: tx timeout\n", dev->name);
+       netif_printk(skge, timer, KERN_DEBUG, skge->netdev, "tx timeout\n");
 
        skge_write8(skge->hw, Q_ADDR(txqaddr[skge->port], Q_CSR), CSR_STOP);
        skge_tx_clean(dev);
+       netif_wake_queue(dev);
 }
 
 static int skge_change_mtu(struct net_device *dev, int new_mtu)
@@ -2934,7 +2921,7 @@ static void genesis_set_multicast(struct net_device *dev)
        struct skge_port *skge = netdev_priv(dev);
        struct skge_hw *hw = skge->hw;
        int port = skge->port;
-       int i, count = dev->mc_count;
+       int i, count = netdev_mc_count(dev);
        struct dev_mc_list *list = dev->mc_list;
        u32 mode;
        u8 filter[8];
@@ -2951,8 +2938,8 @@ static void genesis_set_multicast(struct net_device *dev)
        else {
                memset(filter, 0, sizeof(filter));
 
-               if (skge->flow_status == FLOW_STAT_REM_SEND
-                   || skge->flow_status == FLOW_STAT_SYMMETRIC)
+               if (skge->flow_status == FLOW_STAT_REM_SEND ||
+                   skge->flow_status == FLOW_STAT_SYMMETRIC)
                        genesis_add_filter(filter, pause_mc_addr);
 
                for (i = 0; list && i < count; i++, list = list->next)
@@ -2975,8 +2962,8 @@ static void yukon_set_multicast(struct net_device *dev)
        struct skge_hw *hw = skge->hw;
        int port = skge->port;
        struct dev_mc_list *list = dev->mc_list;
-       int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND
-                       || skge->flow_status == FLOW_STAT_SYMMETRIC);
+       int rx_pause = (skge->flow_status == FLOW_STAT_REM_SEND ||
+                       skge->flow_status == FLOW_STAT_SYMMETRIC);
        u16 reg;
        u8 filter[8];
 
@@ -2989,7 +2976,7 @@ static void yukon_set_multicast(struct net_device *dev)
                reg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
        else if (dev->flags & IFF_ALLMULTI)     /* all multicast */
                memset(filter, 0xff, sizeof(filter));
-       else if (dev->mc_count == 0 && !rx_pause)/* no multicast */
+       else if (netdev_mc_empty(dev) && !rx_pause)/* no multicast */
                reg &= ~GM_RXCR_MCF_ENA;
        else {
                int i;
@@ -2998,7 +2985,7 @@ static void yukon_set_multicast(struct net_device *dev)
                if (rx_pause)
                        yukon_add_filter(filter, pause_mc_addr);
 
-               for (i = 0; list && i < dev->mc_count; i++, list = list->next)
+               for (i = 0; list && i < netdev_mc_count(dev); i++, list = list->next)
                        yukon_add_filter(filter, list->dmi_addr);
        }
 
@@ -3056,10 +3043,9 @@ static struct sk_buff *skge_rx_get(struct net_device *dev,
        struct sk_buff *skb;
        u16 len = control & BMU_BBC;
 
-       if (unlikely(netif_msg_rx_status(skge)))
-               printk(KERN_DEBUG PFX "%s: rx slot %td status 0x%x len %d\n",
-                      dev->name, e - skge->rx_ring.start,
-                      status, len);
+       netif_printk(skge, rx_status, KERN_DEBUG, skge->netdev,
+                    "rx slot %td status 0x%x len %d\n",
+                    e - skge->rx_ring.start, status, len);
 
        if (len > skge->rx_buf_size)
                goto error;
@@ -3074,11 +3060,10 @@ static struct sk_buff *skge_rx_get(struct net_device *dev,
                goto error;
 
        if (len < RX_COPY_THRESHOLD) {
-               skb = netdev_alloc_skb(dev, len + 2);
+               skb = netdev_alloc_skb_ip_align(dev, len);
                if (!skb)
                        goto resubmit;
 
-               skb_reserve(skb, 2);
                pci_dma_sync_single_for_cpu(skge->hw->pdev,
                                            pci_unmap_addr(e, mapaddr),
                                            len, PCI_DMA_FROMDEVICE);
@@ -3089,11 +3074,11 @@ static struct sk_buff *skge_rx_get(struct net_device *dev,
                skge_rx_reuse(e, skge->rx_buf_size);
        } else {
                struct sk_buff *nskb;
-               nskb = netdev_alloc_skb(dev, skge->rx_buf_size + NET_IP_ALIGN);
+
+               nskb = netdev_alloc_skb_ip_align(dev, skge->rx_buf_size);
                if (!nskb)
                        goto resubmit;
 
-               skb_reserve(nskb, NET_IP_ALIGN);
                pci_unmap_single(skge->hw->pdev,
                                 pci_unmap_addr(e, mapaddr),
                                 pci_unmap_len(e, maplen),
@@ -3114,10 +3099,9 @@ static struct sk_buff *skge_rx_get(struct net_device *dev,
        return skb;
 error:
 
-       if (netif_msg_rx_err(skge))
-               printk(KERN_DEBUG PFX "%s: rx err, slot %td control 0x%x status 0x%x\n",
-                      dev->name, e - skge->rx_ring.start,
-                      control, status);
+       netif_printk(skge, rx_err, KERN_DEBUG, skge->netdev,
+                    "rx err, slot %td control 0x%x status 0x%x\n",
+                    e - skge->rx_ring.start, control, status);
 
        if (skge->hw->chip_id == CHIP_ID_GENESIS) {
                if (status & (XMR_FS_RUNT|XMR_FS_LNG_ERR))
@@ -3856,8 +3840,10 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
        skge->speed = -1;
        skge->advertising = skge_supported_modes(hw);
 
-       if (device_may_wakeup(&hw->pdev->dev))
+       if (device_can_wakeup(&hw->pdev->dev)) {
                skge->wol = wol_supported(hw) & WAKE_MAGIC;
+               device_set_wakeup_enable(&hw->pdev->dev, skge->wol);
+       }
 
        hw->dev[port] = dev;
 
@@ -3886,9 +3872,7 @@ static void __devinit skge_show_addr(struct net_device *dev)
 {
        const struct skge_port *skge = netdev_priv(dev);
 
-       if (netif_msg_probe(skge))
-               printk(KERN_INFO PFX "%s: addr %pM\n",
-                      dev->name, dev->dev_addr);
+       netif_info(skge, probe, skge->netdev, "addr %pM\n", dev->dev_addr);
 }
 
 static int __devinit skge_probe(struct pci_dev *pdev,
@@ -3915,9 +3899,9 @@ static int __devinit skge_probe(struct pci_dev *pdev,
        if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
                using_dac = 1;
                err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
-       } else if (!(err = pci_set_dma_mask(pdev, DMA_32BIT_MASK))) {
+       } else if (!(err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)))) {
                using_dac = 0;
-               err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
+               err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
        }
 
        if (err) {
@@ -3937,16 +3921,19 @@ static int __devinit skge_probe(struct pci_dev *pdev,
 #endif
 
        err = -ENOMEM;
-       hw = kzalloc(sizeof(*hw), GFP_KERNEL);
+       /* space for skge@pci:0000:04:00.0 */
+       hw = kzalloc(sizeof(*hw) + strlen(DRV_NAME "@pci:" )
+                    + strlen(pci_name(pdev)) + 1, GFP_KERNEL);
        if (!hw) {
                dev_err(&pdev->dev, "cannot allocate hardware struct\n");
                goto err_out_free_regions;
        }
+       sprintf(hw->irq_name, DRV_NAME "@pci:%s", pci_name(pdev));
 
        hw->pdev = pdev;
        spin_lock_init(&hw->hw_lock);
        spin_lock_init(&hw->phy_lock);
-       tasklet_init(&hw->phy_task, &skge_extirq, (unsigned long) hw);
+       tasklet_init(&hw->phy_task, skge_extirq, (unsigned long) hw);
 
        hw->regs = ioremap_nocache(pci_resource_start(pdev, 0), 0x4000);
        if (!hw->regs) {
@@ -3976,7 +3963,7 @@ static int __devinit skge_probe(struct pci_dev *pdev,
                goto err_out_free_netdev;
        }
 
-       err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, dev->name, hw);
+       err = request_irq(pdev->irq, skge_intr, IRQF_SHARED, hw->irq_name, hw);
        if (err) {
                dev_err(&pdev->dev, "%s: cannot assign irq %d\n",
                       dev->name, pdev->irq);
@@ -3984,14 +3971,17 @@ static int __devinit skge_probe(struct pci_dev *pdev,
        }
        skge_show_addr(dev);
 
-       if (hw->ports > 1 && (dev1 = skge_devinit(hw, 1, using_dac))) {
-               if (register_netdev(dev1) == 0)
+       if (hw->ports > 1) {
+               dev1 = skge_devinit(hw, 1, using_dac);
+               if (dev1 && register_netdev(dev1) == 0)
                        skge_show_addr(dev1);
                else {
                        /* Failure to register second port need not be fatal */
                        dev_warn(&pdev->dev, "register of second port failed\n");
                        hw->dev[1] = NULL;
-                       free_netdev(dev1);
+                       hw->ports = 1;
+                       if (dev1)
+                               free_netdev(dev1);
                }
        }
        pci_set_drvdata(pdev, hw);