b43: N-PHY: implement overriding RF control intc
[safe/jmp/linux-2.6] / drivers / net / ns83820.c
index ea71f6d..1f6327d 100644 (file)
 #include <linux/compiler.h>
 #include <linux/prefetch.h>
 #include <linux/ethtool.h>
+#include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/if_vlan.h>
 #include <linux/rtnetlink.h>
@@ -409,7 +410,7 @@ static int lnksts = 0;              /* CFG_LNKSTS bit polarity */
 struct rx_info {
        spinlock_t      lock;
        int             up;
-       long            idle;
+       unsigned long   idle;
 
        struct sk_buff  *skbs[NR_RX_DESC];
 
@@ -585,16 +586,13 @@ static inline int rx_refill(struct net_device *ndev, gfp_t gfp)
        for (i=0; i<NR_RX_DESC; i++) {
                struct sk_buff *skb;
                long res;
+
                /* extra 16 bytes for alignment */
-               skb = __dev_alloc_skb(REAL_RX_BUF_SIZE+16, gfp);
+               skb = __netdev_alloc_skb(ndev, REAL_RX_BUF_SIZE+16, gfp);
                if (unlikely(!skb))
                        break;
 
-               res = (long)skb->data & 0xf;
-               res = 0x10 - res;
-               res &= 0xf;
-               skb_reserve(skb, res);
-
+               skb_reserve(skb, skb->data - PTR_ALIGN(skb->data, 16));
                if (gfp != GFP_ATOMIC)
                        spin_lock_irqsave(&dev->rx_info.lock, flags);
                res = ns83820_add_rx_skb(dev, skb);
@@ -611,8 +609,7 @@ static inline int rx_refill(struct net_device *ndev, gfp_t gfp)
        return i ? 0 : -ENOMEM;
 }
 
-static void FASTCALL(rx_refill_atomic(struct net_device *ndev));
-static void fastcall rx_refill_atomic(struct net_device *ndev)
+static void rx_refill_atomic(struct net_device *ndev)
 {
        rx_refill(ndev, GFP_ATOMIC);
 }
@@ -633,8 +630,7 @@ static inline void clear_rx_desc(struct ns83820 *dev, unsigned i)
        build_rx_desc(dev, dev->rx_info.descs + (DESC_SIZE * i), 0, 0, CMDSTS_OWN, 0);
 }
 
-static void FASTCALL(phy_intr(struct net_device *ndev));
-static void fastcall phy_intr(struct net_device *ndev)
+static void phy_intr(struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
        static const char *speeds[] = { "10", "100", "1000", "1000(?)", "1000F" };
@@ -652,8 +648,8 @@ static void fastcall phy_intr(struct net_device *ndev)
                dprintk("phy_intr: tbisr=%08x, tanar=%08x, tanlpar=%08x\n",
                        tbisr, tanar, tanlpar);
 
-               if ( (fullduplex = (tanlpar & TANAR_FULL_DUP)
-                     && (tanar & TANAR_FULL_DUP)) ) {
+               if ( (fullduplex = (tanlpar & TANAR_FULL_DUP) &&
+                     (tanar & TANAR_FULL_DUP)) ) {
 
                        /* both of us are full duplex */
                        writel(readl(dev->base + TXCFG)
@@ -665,12 +661,12 @@ static void fastcall phy_intr(struct net_device *ndev)
                        writel(readl(dev->base + GPIOR) | GPIOR_GP1_OUT,
                               dev->base + GPIOR);
 
-               } else if(((tanlpar & TANAR_HALF_DUP)
-                          && (tanar & TANAR_HALF_DUP))
-                       || ((tanlpar & TANAR_FULL_DUP)
-                           && (tanar & TANAR_HALF_DUP))
-                       || ((tanlpar & TANAR_HALF_DUP)
-                           && (tanar & TANAR_FULL_DUP))) {
+               } else if (((tanlpar & TANAR_HALF_DUP) &&
+                           (tanar & TANAR_HALF_DUP)) ||
+                          ((tanlpar & TANAR_FULL_DUP) &&
+                           (tanar & TANAR_HALF_DUP)) ||
+                          ((tanlpar & TANAR_HALF_DUP) &&
+                           (tanar & TANAR_FULL_DUP))) {
 
                        /* one or both of us are half duplex */
                        writel((readl(dev->base + TXCFG)
@@ -724,16 +720,16 @@ static void fastcall phy_intr(struct net_device *ndev)
 
        newlinkstate = (cfg & CFG_LNKSTS) ? LINK_UP : LINK_DOWN;
 
-       if (newlinkstate & LINK_UP
-           && dev->linkstate != newlinkstate) {
+       if (newlinkstate & LINK_UP &&
+           dev->linkstate != newlinkstate) {
                netif_start_queue(ndev);
                netif_wake_queue(ndev);
                printk(KERN_INFO "%s: link now %s mbps, %s duplex and up.\n",
                        ndev->name,
                        speeds[speed],
                        fullduplex ? "full" : "half");
-       } else if (newlinkstate & LINK_DOWN
-                  && dev->linkstate != newlinkstate) {
+       } else if (newlinkstate & LINK_DOWN &&
+                  dev->linkstate != newlinkstate) {
                netif_stop_queue(ndev);
                printk(KERN_INFO "%s: link now down.\n", ndev->name);
        }
@@ -827,13 +823,11 @@ static void ns83820_cleanup_rx(struct ns83820 *dev)
                struct sk_buff *skb = dev->rx_info.skbs[i];
                dev->rx_info.skbs[i] = NULL;
                clear_rx_desc(dev, i);
-               if (skb)
-                       kfree_skb(skb);
+               kfree_skb(skb);
        }
 }
 
-static void FASTCALL(ns83820_rx_kick(struct net_device *ndev));
-static void fastcall ns83820_rx_kick(struct net_device *ndev)
+static void ns83820_rx_kick(struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
        /*if (nr_rx_empty(dev) >= NR_RX_DESC/4)*/ {
@@ -854,8 +848,7 @@ static void fastcall ns83820_rx_kick(struct net_device *ndev)
 /* rx_irq
  *
  */
-static void FASTCALL(rx_irq(struct net_device *ndev));
-static void fastcall rx_irq(struct net_device *ndev)
+static void rx_irq(struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
        struct rx_info *info = &dev->rx_info;
@@ -1085,7 +1078,8 @@ static void ns83820_cleanup_tx(struct ns83820 *dev)
  * while trying to track down a bug in either the zero copy code or
  * the tx fifo (hence the MAX_FRAG_LEN).
  */
-static int ns83820_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
+static netdev_tx_t ns83820_hard_start_xmit(struct sk_buff *skb,
+                                          struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
        u32 free_idx, cmdsts, extsts;
@@ -1105,7 +1099,7 @@ again:
        if (unlikely(dev->CFG_cache & CFG_LNKSTS)) {
                netif_stop_queue(ndev);
                if (unlikely(dev->CFG_cache & CFG_LNKSTS))
-                       return 1;
+                       return NETDEV_TX_BUSY;
                netif_start_queue(ndev);
        }
 
@@ -1123,7 +1117,7 @@ again:
                        netif_start_queue(ndev);
                        goto again;
                }
-               return 1;
+               return NETDEV_TX_BUSY;
        }
 
        if (free_idx == dev->tx_intr_idx) {
@@ -1212,9 +1206,7 @@ again:
        if (stopped && (dev->tx_done_idx != tx_done_idx) && start_tx_okay(dev))
                netif_start_queue(ndev);
 
-       /* set the transmit start time to catch transmit timeouts */
-       ndev->trans_start = jiffies;
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static void ns83820_update_stats(struct ns83820 *dev)
@@ -1634,7 +1626,7 @@ static void ns83820_tx_watch(unsigned long data)
                );
 #endif
 
-       if (time_after(jiffies, ndev->trans_start + 1*HZ) &&
+       if (time_after(jiffies, dev_trans_start(ndev) + 1*HZ) &&
            dev->tx_done_idx != dev->tx_free_idx) {
                printk(KERN_DEBUG "%s: ns83820_tx_watch: %u %u %d\n",
                        ndev->name,
@@ -1955,20 +1947,35 @@ static void ns83820_probe_phy(struct net_device *ndev)
 }
 #endif
 
-static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_device_id *id)
+static const struct net_device_ops netdev_ops = {
+       .ndo_open               = ns83820_open,
+       .ndo_stop               = ns83820_stop,
+       .ndo_start_xmit         = ns83820_hard_start_xmit,
+       .ndo_get_stats          = ns83820_get_stats,
+       .ndo_change_mtu         = ns83820_change_mtu,
+       .ndo_set_multicast_list = ns83820_set_multicast,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_tx_timeout         = ns83820_tx_timeout,
+#ifdef NS83820_VLAN_ACCEL_SUPPORT
+       .ndo_vlan_rx_register   = ns83820_vlan_rx_register,
+#endif
+};
+
+static int __devinit ns83820_init_one(struct pci_dev *pci_dev,
+                                     const struct pci_device_id *id)
 {
        struct net_device *ndev;
        struct ns83820 *dev;
        long addr;
        int err;
        int using_dac = 0;
-       DECLARE_MAC_BUF(mac);
 
        /* See if we can set the dma mask early on; failure is fatal. */
        if (sizeof(dma_addr_t) == 8 &&
-               !pci_set_dma_mask(pci_dev, DMA_64BIT_MASK)) {
+               !pci_set_dma_mask(pci_dev, DMA_BIT_MASK(64))) {
                using_dac = 1;
-       } else if (!pci_set_dma_mask(pci_dev, DMA_32BIT_MASK)) {
+       } else if (!pci_set_dma_mask(pci_dev, DMA_BIT_MASK(32))) {
                using_dac = 0;
        } else {
                dev_warn(&pci_dev->dev, "pci_set_dma_mask failed!\n");
@@ -2048,14 +2055,8 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
                ndev->name, le32_to_cpu(readl(dev->base + 0x22c)),
                pci_dev->subsystem_vendor, pci_dev->subsystem_device);
 
-       ndev->open = ns83820_open;
-       ndev->stop = ns83820_stop;
-       ndev->hard_start_xmit = ns83820_hard_start_xmit;
-       ndev->get_stats = ns83820_get_stats;
-       ndev->change_mtu = ns83820_change_mtu;
-       ndev->set_multicast_list = ns83820_set_multicast;
+       ndev->netdev_ops = &netdev_ops;
        SET_ETHTOOL_OPS(ndev, &ops);
-       ndev->tx_timeout = ns83820_tx_timeout;
        ndev->watchdog_timeo = 5 * HZ;
        pci_set_drvdata(pci_dev, ndev);
 
@@ -2218,7 +2219,6 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
 #ifdef NS83820_VLAN_ACCEL_SUPPORT
        /* We also support hardware vlan acceleration */
        ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
-       ndev->vlan_rx_register = ns83820_vlan_rx_register;
 #endif
 
        if (using_dac) {
@@ -2227,12 +2227,11 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
                ndev->features |= NETIF_F_HIGHDMA;
        }
 
-       printk(KERN_INFO "%s: ns83820 v" VERSION ": DP83820 v%u.%u: %s io=0x%08lx irq=%d f=%s\n",
+       printk(KERN_INFO "%s: ns83820 v" VERSION ": DP83820 v%u.%u: %pM io=0x%08lx irq=%d f=%s\n",
                ndev->name,
                (unsigned)readl(dev->base + SRR) >> 8,
                (unsigned)readl(dev->base + SRR) & 0xff,
-               print_mac(mac, ndev->dev_addr),
-               addr, pci_dev->irq,
+               ndev->dev_addr, addr, pci_dev->irq,
                (ndev->features & NETIF_F_HIGHDMA) ? "h,sg" : "sg"
                );