de4x5: Remove developer debug feature about set/clear promisc
[pandora-kernel.git] / drivers / net / tulip / de4x5.c
index 41f34bb..617ef41 100644 (file)
 static char version[] __devinitdata = "de4x5.c:V0.546 2001/02/22 davies@maniac.ultranet.com\n";
 
 #define c_char const char
-#define TWIDDLE(a) (u_short)le16_to_cpu(get_unaligned((__le16 *)(a)))
 
 /*
 ** MII Information
@@ -911,7 +910,7 @@ static int     de4x5_init(struct net_device *dev);
 static int     de4x5_sw_reset(struct net_device *dev);
 static int     de4x5_rx(struct net_device *dev);
 static int     de4x5_tx(struct net_device *dev);
-static int     de4x5_ast(struct net_device *dev);
+static void    de4x5_ast(struct net_device *dev);
 static int     de4x5_txur(struct net_device *dev);
 static int     de4x5_rx_ovfc(struct net_device *dev);
 
@@ -984,11 +983,9 @@ static int     test_bad_enet(struct net_device *dev, int status);
 static int     an_exception(struct de4x5_private *lp);
 static char    *build_setup_frame(struct net_device *dev, int mode);
 static void    disable_ast(struct net_device *dev);
-static void    enable_ast(struct net_device *dev, u32 time_out);
 static long    de4x5_switch_mac_port(struct net_device *dev);
 static int     gep_rd(struct net_device *dev);
 static void    gep_wr(s32 data, struct net_device *dev);
-static void    timeout(struct net_device *dev, void (*fn)(u_long data), u_long data, u_long msec);
 static void    yawn(struct net_device *dev, int state);
 static void    de4x5_parse_params(struct net_device *dev);
 static void    de4x5_dbg_open(struct net_device *dev);
@@ -1139,6 +1136,8 @@ de4x5_hw_init(struct net_device *dev, u_long iobase, struct device *gendev)
        lp->gendev = gendev;
        spin_lock_init(&lp->lock);
        init_timer(&lp->timer);
+       lp->timer.function = (void (*)(unsigned long))de4x5_ast;
+       lp->timer.data = (unsigned long)dev;
        de4x5_parse_params(dev);
 
        /*
@@ -1311,7 +1310,7 @@ de4x5_open(struct net_device *dev)
     lp->state = OPEN;
     de4x5_dbg_open(dev);
 
-    if (request_irq(dev->irq, (void *)de4x5_interrupt, IRQF_SHARED,
+    if (request_irq(dev->irq, de4x5_interrupt, IRQF_SHARED,
                                                     lp->adapter_name, dev)) {
        printk("de4x5_open(): Requested IRQ%d is busy - attemping FAST/SHARE...", dev->irq);
        if (request_irq(dev->irq, de4x5_interrupt, IRQF_DISABLED | IRQF_SHARED,
@@ -1737,27 +1736,29 @@ de4x5_tx(struct net_device *dev)
     return 0;
 }
 
-static int
+static void
 de4x5_ast(struct net_device *dev)
 {
-    struct de4x5_private *lp = netdev_priv(dev);
-    int next_tick = DE4X5_AUTOSENSE_MS;
+       struct de4x5_private *lp = netdev_priv(dev);
+       int next_tick = DE4X5_AUTOSENSE_MS;
+       int dt;
 
-    disable_ast(dev);
+       if (lp->useSROM)
+               next_tick = srom_autoconf(dev);
+       else if (lp->chipset == DC21140)
+               next_tick = dc21140m_autoconf(dev);
+       else if (lp->chipset == DC21041)
+               next_tick = dc21041_autoconf(dev);
+       else if (lp->chipset == DC21040)
+               next_tick = dc21040_autoconf(dev);
+       lp->linkOK = 0;
 
-    if (lp->useSROM) {
-       next_tick = srom_autoconf(dev);
-    } else if (lp->chipset == DC21140) {
-       next_tick = dc21140m_autoconf(dev);
-    } else if (lp->chipset == DC21041) {
-       next_tick = dc21041_autoconf(dev);
-    } else if (lp->chipset == DC21040) {
-       next_tick = dc21040_autoconf(dev);
-    }
-    lp->linkOK = 0;
-    enable_ast(dev, next_tick);
+       dt = (next_tick * HZ) / 1000;
 
-    return 0;
+       if (!dt)
+               dt = 1;
+
+       mod_timer(&lp->timer, jiffies + dt);
 }
 
 static int
@@ -2174,7 +2175,7 @@ srom_search(struct net_device *dev, struct pci_dev *pdev)
        for (j=0, i=0; i<ETH_ALEN; i++) {
            j += (u_char) *((u_char *)&lp->srom + SROM_HWADD + i);
        }
-       if ((j != 0) && (j != 0x5fa)) {
+       if (j != 0 && j != 6 * 0xff) {
            last.chipset = device;
            last.bus = pb;
            last.irq = irq;
@@ -2371,30 +2372,19 @@ static struct pci_driver de4x5_pci_driver = {
 static int
 autoconf_media(struct net_device *dev)
 {
-    struct de4x5_private *lp = netdev_priv(dev);
-    u_long iobase = dev->base_addr;
-    int next_tick = DE4X5_AUTOSENSE_MS;
+       struct de4x5_private *lp = netdev_priv(dev);
+       u_long iobase = dev->base_addr;
 
-    lp->linkOK = 0;
-    lp->c_media = AUTO;                     /* Bogus last media */
-    disable_ast(dev);
-    inl(DE4X5_MFC);                         /* Zero the lost frames counter */
-    lp->media = INIT;
-    lp->tcount = 0;
+       disable_ast(dev);
 
-    if (lp->useSROM) {
-       next_tick = srom_autoconf(dev);
-    } else if (lp->chipset == DC21040) {
-       next_tick = dc21040_autoconf(dev);
-    } else if (lp->chipset == DC21041) {
-       next_tick = dc21041_autoconf(dev);
-    } else if (lp->chipset == DC21140) {
-       next_tick = dc21140m_autoconf(dev);
-    }
+       lp->c_media = AUTO;                     /* Bogus last media */
+       inl(DE4X5_MFC);                         /* Zero the lost frames counter */
+       lp->media = INIT;
+       lp->tcount = 0;
 
-    enable_ast(dev, next_tick);
+       de4x5_ast(dev);
 
-    return (lp->media);
+       return lp->media;
 }
 
 /*
@@ -4018,20 +4008,22 @@ DevicePresent(struct net_device *dev, u_long aprom_addr)
            outl(0, aprom_addr);       /* Reset Ethernet Address ROM Pointer */
        }
     } else {                           /* Read new srom */
-       u_short tmp, *p = (short *)((char *)&lp->srom + SROM_HWADD);
+       u_short tmp;
+       __le16 *p = (__le16 *)((char *)&lp->srom + SROM_HWADD);
        for (i=0; i<(ETH_ALEN>>1); i++) {
            tmp = srom_rd(aprom_addr, (SROM_HWADD>>1) + i);
-           *p = le16_to_cpu(tmp);
-           j += *p++;
+           j += tmp;   /* for check for 0:0:0:0:0:0 or ff:ff:ff:ff:ff:ff */
+           *p = cpu_to_le16(tmp);
        }
-       if ((j == 0) || (j == 0x2fffd)) {
-           return;
+       if (j == 0 || j == 3 * 0xffff) {
+               /* could get 0 only from all-0 and 3 * 0xffff only from all-1 */
+               return;
        }
 
-       p=(short *)&lp->srom;
+       p = (__le16 *)&lp->srom;
        for (i=0; i<(sizeof(struct de4x5_srom)>>1); i++) {
            tmp = srom_rd(aprom_addr, i);
-           *p++ = le16_to_cpu(tmp);
+           *p++ = cpu_to_le16(tmp);
        }
        de4x5_dbg_srom((struct de4x5_srom *)&lp->srom);
     }
@@ -4175,7 +4167,7 @@ de4x5_bad_srom(struct de4x5_private *lp)
 {
     int i, status = 0;
 
-    for (i=0; i<sizeof(enet_det)/ETH_ALEN; i++) {
+    for (i = 0; i < ARRAY_SIZE(enet_det); i++) {
        if (!de4x5_strncmp((char *)&lp->srom, (char *)&enet_det[i], 3) &&
            !de4x5_strncmp((char *)&lp->srom+0x10, (char *)&enet_det[i], 3)) {
            if (i == 0) {
@@ -4195,7 +4187,7 @@ de4x5_strncmp(char *a, char *b, int n)
 {
     int ret=0;
 
-    for (;n && !ret;n--) {
+    for (;n && !ret; n--) {
        ret = *a++ - *b++;
     }
 
@@ -4412,7 +4404,7 @@ srom_infoleaf_info(struct net_device *dev)
        }
     }
 
-    lp->infoleaf_offset = TWIDDLE(p+1);
+       lp->infoleaf_offset = get_unaligned_le16(p + 1);
 
     return 0;
 }
@@ -4483,7 +4475,7 @@ srom_exec(struct net_device *dev, u_char *p)
 
     while (count--) {
        gep_wr(((lp->chipset==DC21140) && (lp->ibn!=5) ?
-                                                  *p++ : TWIDDLE(w++)), dev);
+                                                  *p++ : get_unaligned_le16(w++)), dev);
        mdelay(2);                          /* 2ms per action */
     }
 
@@ -4718,10 +4710,10 @@ type1_infoblock(struct net_device *dev, u_char count, u_char *p)
        lp->active = *p++;
        lp->phy[lp->active].gep = (*p ? p : NULL); p += (*p + 1);
        lp->phy[lp->active].rst = (*p ? p : NULL); p += (*p + 1);
-       lp->phy[lp->active].mc  = TWIDDLE(p); p += 2;
-       lp->phy[lp->active].ana = TWIDDLE(p); p += 2;
-       lp->phy[lp->active].fdx = TWIDDLE(p); p += 2;
-       lp->phy[lp->active].ttm = TWIDDLE(p);
+       lp->phy[lp->active].mc  = get_unaligned_le16(p); p += 2;
+       lp->phy[lp->active].ana = get_unaligned_le16(p); p += 2;
+       lp->phy[lp->active].fdx = get_unaligned_le16(p); p += 2;
+       lp->phy[lp->active].ttm = get_unaligned_le16(p);
        return 0;
     } else if ((lp->media == INIT) && (lp->timeout < 0)) {
         lp->ibn = 1;
@@ -4758,16 +4750,16 @@ type2_infoblock(struct net_device *dev, u_char count, u_char *p)
        lp->infoblock_media = (*p) & MEDIA_CODE;
 
         if ((*p++) & EXT_FIELD) {
-           lp->cache.csr13 = TWIDDLE(p); p += 2;
-           lp->cache.csr14 = TWIDDLE(p); p += 2;
-           lp->cache.csr15 = TWIDDLE(p); p += 2;
+           lp->cache.csr13 = get_unaligned_le16(p); p += 2;
+           lp->cache.csr14 = get_unaligned_le16(p); p += 2;
+           lp->cache.csr15 = get_unaligned_le16(p); p += 2;
        } else {
            lp->cache.csr13 = CSR13;
            lp->cache.csr14 = CSR14;
            lp->cache.csr15 = CSR15;
        }
-        lp->cache.gepc = ((s32)(TWIDDLE(p)) << 16); p += 2;
-        lp->cache.gep  = ((s32)(TWIDDLE(p)) << 16);
+        lp->cache.gepc = ((s32)(get_unaligned_le16(p)) << 16); p += 2;
+        lp->cache.gep  = ((s32)(get_unaligned_le16(p)) << 16);
        lp->infoblock_csr6 = OMR_SIA;
        lp->useMII = false;
 
@@ -4799,10 +4791,10 @@ type3_infoblock(struct net_device *dev, u_char count, u_char *p)
        if (MOTO_SROM_BUG) lp->active = 0;
        lp->phy[lp->active].gep = (*p ? p : NULL); p += (2 * (*p) + 1);
        lp->phy[lp->active].rst = (*p ? p : NULL); p += (2 * (*p) + 1);
-       lp->phy[lp->active].mc  = TWIDDLE(p); p += 2;
-       lp->phy[lp->active].ana = TWIDDLE(p); p += 2;
-       lp->phy[lp->active].fdx = TWIDDLE(p); p += 2;
-       lp->phy[lp->active].ttm = TWIDDLE(p); p += 2;
+       lp->phy[lp->active].mc  = get_unaligned_le16(p); p += 2;
+       lp->phy[lp->active].ana = get_unaligned_le16(p); p += 2;
+       lp->phy[lp->active].fdx = get_unaligned_le16(p); p += 2;
+       lp->phy[lp->active].ttm = get_unaligned_le16(p); p += 2;
        lp->phy[lp->active].mci = *p;
        return 0;
     } else if ((lp->media == INIT) && (lp->timeout < 0)) {
@@ -4842,8 +4834,8 @@ type4_infoblock(struct net_device *dev, u_char count, u_char *p)
         lp->cache.csr13 = CSR13;              /* Hard coded defaults */
        lp->cache.csr14 = CSR14;
        lp->cache.csr15 = CSR15;
-        lp->cache.gepc = ((s32)(TWIDDLE(p)) << 16); p += 2;
-        lp->cache.gep  = ((s32)(TWIDDLE(p)) << 16); p += 2;
+        lp->cache.gepc = ((s32)(get_unaligned_le16(p)) << 16); p += 2;
+        lp->cache.gep  = ((s32)(get_unaligned_le16(p)) << 16); p += 2;
        csr6 = *p++;
        flags = *p++;
 
@@ -5160,22 +5152,11 @@ build_setup_frame(struct net_device *dev, int mode)
     return pa;                     /* Points to the next entry */
 }
 
-static void
-enable_ast(struct net_device *dev, u32 time_out)
-{
-    timeout(dev, (void *)&de4x5_ast, (u_long)dev, time_out);
-
-    return;
-}
-
 static void
 disable_ast(struct net_device *dev)
 {
-    struct de4x5_private *lp = netdev_priv(dev);
-
-    del_timer(&lp->timer);
-
-    return;
+       struct de4x5_private *lp = netdev_priv(dev);
+       del_timer_sync(&lp->timer);
 }
 
 static long
@@ -5244,29 +5225,6 @@ gep_rd(struct net_device *dev)
     return 0;
 }
 
-static void
-timeout(struct net_device *dev, void (*fn)(u_long data), u_long data, u_long msec)
-{
-    struct de4x5_private *lp = netdev_priv(dev);
-    int dt;
-
-    /* First, cancel any pending timer events */
-    del_timer(&lp->timer);
-
-    /* Convert msec to ticks */
-    dt = (msec * HZ) / 1000;
-    if (dt==0) dt=1;
-
-    /* Set up timer */
-    init_timer(&lp->timer);
-    lp->timer.expires = jiffies + dt;
-    lp->timer.function = fn;
-    lp->timer.data = data;
-    add_timer(&lp->timer);
-
-    return;
-}
-
 static void
 yawn(struct net_device *dev, int state)
 {
@@ -5556,22 +5514,6 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        netif_wake_queue(dev);                      /* Unlock the TX ring */
        break;
 
-    case DE4X5_SET_PROM:             /* Set Promiscuous Mode */
-       if (!capable(CAP_NET_ADMIN)) return -EPERM;
-       omr = inl(DE4X5_OMR);
-       omr |= OMR_PR;
-       outl(omr, DE4X5_OMR);
-       dev->flags |= IFF_PROMISC;
-       break;
-
-    case DE4X5_CLR_PROM:             /* Clear Promiscuous Mode */
-       if (!capable(CAP_NET_ADMIN)) return -EPERM;
-       omr = inl(DE4X5_OMR);
-       omr &= ~OMR_PR;
-       outl(omr, DE4X5_OMR);
-       dev->flags &= ~IFF_PROMISC;
-       break;
-
     case DE4X5_SAY_BOO:              /* Say "Boo!" to the kernel log file */
        if (!capable(CAP_NET_ADMIN)) return -EPERM;
        printk("%s: Boo!\n", dev->name);