rndis_wlan: cleanup: rename and remove local pointers
[linux-2.6.git] / drivers / net / ns83820.c
index b0127c7..ff44961 100644 (file)
@@ -1,4 +1,4 @@
-#define VERSION "0.22"
+#define VERSION "0.23"
 /* ns83820.c by Benjamin LaHaise with contributions.
  *
  * Questions/comments/discussion to linux-ns83820@kvack.org.
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/delay.h>
-#include <linux/smp_lock.h>
 #include <linux/workqueue.h>
 #include <linux/init.h>
 #include <linux/ip.h>  /* for iph */
@@ -414,10 +413,10 @@ struct rx_info {
 
        struct sk_buff  *skbs[NR_RX_DESC];
 
-       u32             *next_rx_desc;
+       __le32          *next_rx_desc;
        u16             next_rx, next_empty;
 
-       u32             *descs;
+       __le32          *descs;
        dma_addr_t      phy_descs;
 };
 
@@ -427,6 +426,7 @@ struct ns83820 {
        u8                      __iomem *base;
 
        struct pci_dev          *pci_dev;
+       struct net_device       *ndev;
 
 #ifdef NS83820_VLAN_ACCEL_SUPPORT
        struct vlan_group       *vlgrp;
@@ -459,7 +459,7 @@ struct ns83820 {
        struct sk_buff  *tx_skbs[NR_TX_DESC];
 
        char            pad[16] __attribute__((aligned(16)));
-       u32             *tx_descs;
+       __le32          *tx_descs;
        dma_addr_t      tx_phy_descs;
 
        struct timer_list       tx_watchdog;
@@ -506,18 +506,6 @@ static void ns83820_vlan_rx_register(struct net_device *ndev, struct vlan_group
        spin_unlock(&dev->tx_lock);
        spin_unlock_irq(&dev->misc_lock);
 }
-
-static void ns83820_vlan_rx_kill_vid(struct net_device *ndev, unsigned short vid)
-{
-       struct ns83820 *dev = PRIV(ndev);
-
-       spin_lock_irq(&dev->misc_lock);
-       spin_lock(&dev->tx_lock);
-       if (dev->vlgrp)
-               dev->vlgrp->vlan_devices[vid] = NULL;
-       spin_unlock(&dev->tx_lock);
-       spin_unlock_irq(&dev->misc_lock);
-}
 #endif
 
 /* Packet Receiver
@@ -533,7 +521,7 @@ static void ns83820_vlan_rx_kill_vid(struct net_device *ndev, unsigned short vid
  * conditions, still route realtime traffic with as low jitter as
  * possible.
  */
-static inline void build_rx_desc(struct ns83820 *dev, u32 *desc, dma_addr_t link, dma_addr_t buf, u32 cmdsts, u32 extsts)
+static inline void build_rx_desc(struct ns83820 *dev, __le32 *desc, dma_addr_t link, dma_addr_t buf, u32 cmdsts, u32 extsts)
 {
        desc_addr_set(desc + DESC_LINK, link);
        desc_addr_set(desc + DESC_BUFPTR, buf);
@@ -547,7 +535,7 @@ static inline int ns83820_add_rx_skb(struct ns83820 *dev, struct sk_buff *skb)
 {
        unsigned next_empty;
        u32 cmdsts;
-       u32 *sg;
+       __le32 *sg;
        dma_addr_t buf;
 
        next_empty = dev->rx_info.next_empty;
@@ -597,17 +585,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->dev = ndev;
+               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);
@@ -624,17 +608,16 @@ 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);
 }
 
 /* REFILL */
-static inline void queue_refill(void *_dev)
+static inline void queue_refill(struct work_struct *work)
 {
-       struct net_device *ndev = _dev;
-       struct ns83820 *dev = PRIV(ndev);
+       struct ns83820 *dev = container_of(work, struct ns83820, tq_refill);
+       struct net_device *ndev = dev->ndev;
 
        rx_refill(ndev, GFP_KERNEL);
        if (dev->rx_info.up)
@@ -646,8 +629,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" };
@@ -845,8 +827,7 @@ static void ns83820_cleanup_rx(struct ns83820 *dev)
        }
 }
 
-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)*/ {
@@ -867,14 +848,14 @@ 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;
        unsigned next_rx;
        int rx_rc, len;
-       u32 cmdsts, *desc;
+       u32 cmdsts;
+       __le32 *desc;
        unsigned long flags;
        int nr = 0;
 
@@ -1010,7 +991,8 @@ static inline void kick_tx(struct ns83820 *dev)
 static void do_tx_done(struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
-       u32 cmdsts, tx_done_idx, *desc;
+       u32 cmdsts, tx_done_idx;
+       __le32 *desc;
 
        dprintk("do_tx_done(%p)\n", ndev);
        tx_done_idx = dev->tx_done_idx;
@@ -1077,7 +1059,7 @@ static void ns83820_cleanup_tx(struct ns83820 *dev)
                struct sk_buff *skb = dev->tx_skbs[i];
                dev->tx_skbs[i] = NULL;
                if (skb) {
-                       u32 *desc = dev->tx_descs + (i * DESC_SIZE);
+                       __le32 *desc = dev->tx_descs + (i * DESC_SIZE);
                        pci_unmap_single(dev->pci_dev,
                                        desc_addr_get(desc + DESC_BUFPTR),
                                        le32_to_cpu(desc[DESC_CMDSTS]) & CMDSTS_LEN_MASK,
@@ -1107,7 +1089,7 @@ static int ns83820_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
        skb_frag_t *frag;
        int stopped = 0;
        int do_intr = 0;
-       volatile u32 *first_desc;
+       volatile __le32 *first_desc;
 
        dprintk("ns83820_hard_start_xmit\n");
 
@@ -1155,9 +1137,9 @@ again:
        extsts = 0;
        if (skb->ip_summed == CHECKSUM_PARTIAL) {
                extsts |= EXTSTS_IPPKT;
-               if (IPPROTO_TCP == skb->nh.iph->protocol)
+               if (IPPROTO_TCP == ip_hdr(skb)->protocol)
                        extsts |= EXTSTS_TCPPKT;
-               else if (IPPROTO_UDP == skb->nh.iph->protocol)
+               else if (IPPROTO_UDP == ip_hdr(skb)->protocol)
                        extsts |= EXTSTS_UDPPKT;
        }
 
@@ -1180,7 +1162,7 @@ again:
        first_desc = dev->tx_descs + (free_idx * DESC_SIZE);
 
        for (;;) {
-               volatile u32 *desc = dev->tx_descs + (free_idx * DESC_SIZE);
+               volatile __le32 *desc = dev->tx_descs + (free_idx * DESC_SIZE);
 
                dprintk("frag[%3u]: %4u @ 0x%08Lx\n", free_idx, len,
                        (unsigned long long)buf);
@@ -1258,6 +1240,149 @@ static struct net_device_stats *ns83820_get_stats(struct net_device *ndev)
        return &dev->stats;
 }
 
+/* Let ethtool retrieve info */
+static int ns83820_get_settings(struct net_device *ndev,
+                               struct ethtool_cmd *cmd)
+{
+       struct ns83820 *dev = PRIV(ndev);
+       u32 cfg, tanar, tbicr;
+       int have_optical = 0;
+       int fullduplex   = 0;
+
+       /*
+        * Here's the list of available ethtool commands from other drivers:
+        *      cmd->advertising =
+        *      cmd->speed =
+        *      cmd->duplex =
+        *      cmd->port = 0;
+        *      cmd->phy_address =
+        *      cmd->transceiver = 0;
+        *      cmd->autoneg =
+        *      cmd->maxtxpkt = 0;
+        *      cmd->maxrxpkt = 0;
+        */
+
+       /* read current configuration */
+       cfg   = readl(dev->base + CFG) ^ SPDSTS_POLARITY;
+       tanar = readl(dev->base + TANAR);
+       tbicr = readl(dev->base + TBICR);
+
+       if (dev->CFG_cache & CFG_TBI_EN) {
+               /* we have an optical interface */
+               have_optical = 1;
+               fullduplex = (cfg & CFG_DUPSTS) ? 1 : 0;
+
+       } else {
+               /* We have copper */
+               fullduplex = (cfg & CFG_DUPSTS) ? 1 : 0;
+        }
+
+       cmd->supported = SUPPORTED_Autoneg;
+
+       /* we have optical interface */
+       if (dev->CFG_cache & CFG_TBI_EN) {
+               cmd->supported |= SUPPORTED_1000baseT_Half |
+                                       SUPPORTED_1000baseT_Full |
+                                       SUPPORTED_FIBRE;
+               cmd->port       = PORT_FIBRE;
+       } /* TODO: else copper related  support */
+
+       cmd->duplex = fullduplex ? DUPLEX_FULL : DUPLEX_HALF;
+       switch (cfg / CFG_SPDSTS0 & 3) {
+       case 2:
+               cmd->speed = SPEED_1000;
+               break;
+       case 1:
+               cmd->speed = SPEED_100;
+               break;
+       default:
+               cmd->speed = SPEED_10;
+               break;
+       }
+       cmd->autoneg = (tbicr & TBICR_MR_AN_ENABLE) ? 1: 0;
+       return 0;
+}
+
+/* Let ethool change settings*/
+static int ns83820_set_settings(struct net_device *ndev,
+                               struct ethtool_cmd *cmd)
+{
+       struct ns83820 *dev = PRIV(ndev);
+       u32 cfg, tanar;
+       int have_optical = 0;
+       int fullduplex   = 0;
+
+       /* read current configuration */
+       cfg = readl(dev->base + CFG) ^ SPDSTS_POLARITY;
+       tanar = readl(dev->base + TANAR);
+
+       if (dev->CFG_cache & CFG_TBI_EN) {
+               /* we have optical */
+               have_optical = 1;
+               fullduplex   = (tanar & TANAR_FULL_DUP);
+
+       } else {
+               /* we have copper */
+               fullduplex = cfg & CFG_DUPSTS;
+       }
+
+       spin_lock_irq(&dev->misc_lock);
+       spin_lock(&dev->tx_lock);
+
+       /* Set duplex */
+       if (cmd->duplex != fullduplex) {
+               if (have_optical) {
+                       /*set full duplex*/
+                       if (cmd->duplex == DUPLEX_FULL) {
+                               /* force full duplex */
+                               writel(readl(dev->base + TXCFG)
+                                       | TXCFG_CSI | TXCFG_HBI | TXCFG_ATP,
+                                       dev->base + TXCFG);
+                               writel(readl(dev->base + RXCFG) | RXCFG_RX_FD,
+                                       dev->base + RXCFG);
+                               /* Light up full duplex LED */
+                               writel(readl(dev->base + GPIOR) | GPIOR_GP1_OUT,
+                                       dev->base + GPIOR);
+                       } else {
+                               /*TODO: set half duplex */
+                       }
+
+               } else {
+                       /*we have copper*/
+                       /* TODO: Set duplex for copper cards */
+               }
+               printk(KERN_INFO "%s: Duplex set via ethtool\n",
+               ndev->name);
+       }
+
+       /* Set autonegotiation */
+       if (1) {
+               if (cmd->autoneg == AUTONEG_ENABLE) {
+                       /* restart auto negotiation */
+                       writel(TBICR_MR_AN_ENABLE | TBICR_MR_RESTART_AN,
+                               dev->base + TBICR);
+                       writel(TBICR_MR_AN_ENABLE, dev->base + TBICR);
+                               dev->linkstate = LINK_AUTONEGOTIATE;
+
+                       printk(KERN_INFO "%s: autoneg enabled via ethtool\n",
+                               ndev->name);
+               } else {
+                       /* disable auto negotiation */
+                       writel(0x00000000, dev->base + TBICR);
+               }
+
+               printk(KERN_INFO "%s: autoneg %s via ethtool\n", ndev->name,
+                               cmd->autoneg ? "ENABLED" : "DISABLED");
+       }
+
+       phy_intr(ndev);
+       spin_unlock(&dev->tx_lock);
+       spin_unlock_irq(&dev->misc_lock);
+
+       return 0;
+}
+/* end ethtool get/set support -df */
+
 static void ns83820_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *info)
 {
        struct ns83820 *dev = PRIV(ndev);
@@ -1274,8 +1399,10 @@ static u32 ns83820_get_link(struct net_device *ndev)
 }
 
 static const struct ethtool_ops ops = {
-       .get_drvinfo = ns83820_get_drvinfo,
-       .get_link = ns83820_get_link
+       .get_settings    = ns83820_get_settings,
+       .set_settings    = ns83820_set_settings,
+       .get_drvinfo     = ns83820_get_drvinfo,
+       .get_link        = ns83820_get_link
 };
 
 /* this function is called in irq context from the ISR */
@@ -1455,7 +1582,8 @@ static int ns83820_stop(struct net_device *ndev)
 static void ns83820_tx_timeout(struct net_device *ndev)
 {
        struct ns83820 *dev = PRIV(ndev);
-        u32 tx_done_idx, *desc;
+        u32 tx_done_idx;
+       __le32 *desc;
        unsigned long flags;
 
        spin_lock_irqsave(&dev->tx_lock, flags);
@@ -1592,7 +1720,7 @@ static void ns83820_set_multicast(struct net_device *ndev)
        else
                and_mask &= ~(RFCR_AAU | RFCR_AAM);
 
-       if (ndev->flags & IFF_ALLMULTI)
+       if (ndev->flags & IFF_ALLMULTI || ndev->mc_count)
                or_mask |= RFCR_AAM;
        else
                and_mask &= ~RFCR_AAM;
@@ -1827,6 +1955,7 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
        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 &&
@@ -1841,19 +1970,21 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
 
        ndev = alloc_etherdev(sizeof(struct ns83820));
        dev = PRIV(ndev);
+
        err = -ENOMEM;
        if (!dev)
                goto out;
 
+       dev->ndev = ndev;
+
        spin_lock_init(&dev->rx_info.lock);
        spin_lock_init(&dev->tx_lock);
        spin_lock_init(&dev->misc_lock);
        dev->pci_dev = pci_dev;
 
-       SET_MODULE_OWNER(ndev);
        SET_NETDEV_DEV(ndev, &pci_dev->dev);
 
-       INIT_WORK(&dev->tq_refill, queue_refill, ndev);
+       INIT_WORK(&dev->tq_refill, queue_refill);
        tasklet_init(&dev->rx_tasklet, rx_action, (unsigned long)ndev);
 
        err = pci_enable_device(pci_dev);
@@ -2081,7 +2212,6 @@ static int __devinit ns83820_init_one(struct pci_dev *pci_dev, const struct pci_
        /* 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;
-       ndev->vlan_rx_kill_vid = ns83820_vlan_rx_kill_vid;
 #endif
 
        if (using_dac) {
@@ -2090,13 +2220,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: %02x:%02x:%02x:%02x:%02x:%02x io=0x%08lx irq=%d f=%s\n",
+       printk(KERN_INFO "%s: ns83820 v" VERSION ": DP83820 v%u.%u: %s io=0x%08lx irq=%d f=%s\n",
                ndev->name,
                (unsigned)readl(dev->base + SRR) >> 8,
                (unsigned)readl(dev->base + SRR) & 0xff,
-               ndev->dev_addr[0], ndev->dev_addr[1],
-               ndev->dev_addr[2], ndev->dev_addr[3],
-               ndev->dev_addr[4], ndev->dev_addr[5],
+               print_mac(mac, ndev->dev_addr),
                addr, pci_dev->irq,
                (ndev->features & NETIF_F_HIGHDMA) ? "h,sg" : "sg"
                );