fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / net / mac8390.c
index 0a8094e..a12bb64 100644 (file)
@@ -7,15 +7,14 @@
    This software may be used and distributed according to the terms of
    the GNU Public License, incorporated herein by reference.  */
 
-/* 2000-02-28: support added for Dayna and Kinetics cards by 
+/* 2000-02-28: support added for Dayna and Kinetics cards by
    A.G.deWijn@phys.uu.nl */
 /* 2000-04-04: support added for Dayna2 by bart@etpmod.phys.tue.nl */
 /* 2001-04-18: support for DaynaPort E/LC-M by rayk@knightsmanor.org */
 /* 2001-05-15: support for Cabletron ported from old daynaport driver
- * and fixed access to Sonic Sys card which masquerades as a Farallon 
+ * and fixed access to Sonic Sys card which masquerades as a Farallon
  * by rayk@knightsmanor.org */
 
-#include <linux/version.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/netdevice.h>
 #include <linux/etherdevice.h>
 #include <linux/skbuff.h>
+#include <linux/bitops.h>
 
 #include <asm/system.h>
-#include <asm/bitops.h>
 #include <asm/io.h>
 #include <asm/dma.h>
 #include <asm/hwtest.h>
 #include <asm/macints.h>
 
-#include "8390.h"
+static char version[] =
+       "mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";
 
-#if (LINUX_VERSION_CODE < 0x02030e)
-#define net_device device
-#endif
+#define EI_SHIFT(x)    (ei_local->reg_offset[x])
+#define ei_inb(port)   in_8(port)
+#define ei_outb(val,port)  out_8(port,val)
+#define ei_inb_p(port)   in_8(port)
+#define ei_outb_p(val,port)  out_8(port,val)
+
+#include "lib8390.c"
 
 #define WD_START_PG                    0x00    /* First page of TX buffer */
 #define CABLETRON_RX_START_PG          0x00    /* First page of RX buffer */
@@ -60,7 +64,7 @@
 #define KINETICS_8390_BASE     0x80000
 #define KINETICS_8390_MEM      0x00000
 
-#define CABLETRON_8390_BASE    0x90000 
+#define CABLETRON_8390_BASE    0x90000
 #define CABLETRON_8390_MEM     0x00000
 
 enum mac8390_type {
@@ -121,9 +125,6 @@ static int useresources[] = {
        1, /* dayna-lc */
 };
 
-static char version[] __initdata =
-       "mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";
-               
 extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
 extern int mac8390_memsize(unsigned long membase);
 extern int mac8390_memtest(struct net_device * dev);
@@ -173,7 +174,7 @@ enum mac8390_type __init mac8390_ident(struct nubus_dev * dev)
 {
        if (dev->dr_sw == NUBUS_DRSW_ASANTE)
                return MAC8390_ASANTE;
-       if (dev->dr_sw == NUBUS_DRSW_FARALLON) 
+       if (dev->dr_sw == NUBUS_DRSW_FARALLON)
                return MAC8390_FARALLON;
        if (dev->dr_sw == NUBUS_DRSW_KINETICS)
                return MAC8390_KINETICS;
@@ -192,7 +193,7 @@ int __init mac8390_memsize(unsigned long membase)
 {
        unsigned long flags;
        int i, j;
-       
+
        local_irq_save(flags);
        /* Check up to 32K in 4K increments */
        for (i = 0; i < 8; i++) {
@@ -202,7 +203,7 @@ int __init mac8390_memsize(unsigned long membase)
                   RAM end located */
                if (hwreg_present(m) == 0)
                        break;
-               
+
                /* write a distinctive byte */
                *m = 0xA5A0 | i;
                /* check that we read back what we wrote */
@@ -229,7 +230,7 @@ struct net_device * __init mac8390_probe(int unit)
        int version_disp = 0;
        struct nubus_dev * ndev = NULL;
        int err = -ENODEV;
-       
+
        struct nubus_dir dir;
        struct nubus_dirent ent;
        int offset;
@@ -242,7 +243,7 @@ struct net_device * __init mac8390_probe(int unit)
        if (!MACH_IS_MAC)
                return ERR_PTR(-ENODEV);
 
-       dev = alloc_ei_netdev();
+       dev = ____alloc_ei_netdev(0);
        if (!dev)
                return ERR_PTR(-ENOMEM);
 
@@ -278,7 +279,7 @@ struct net_device * __init mac8390_probe(int unit)
                               dev->name, ndev->board->slot);
                        continue;
                }
-               
+
                /* Get the MAC address */
                if ((nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent)) == -1) {
                        printk(KERN_INFO "%s: Couldn't get MAC address!\n",
@@ -287,7 +288,7 @@ struct net_device * __init mac8390_probe(int unit)
                } else {
                        nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
                        /* Some Sonic Sys cards masquerade as Farallon */
-                       if (cardtype == MAC8390_FARALLON && 
+                       if (cardtype == MAC8390_FARALLON &&
                                        dev->dev_addr[0] == 0x0 &&
                                        dev->dev_addr[1] == 0x40 &&
                                        dev->dev_addr[2] == 0x10) {
@@ -295,7 +296,7 @@ struct net_device * __init mac8390_probe(int unit)
                                cardtype = MAC8390_SONICSYS;
                        }
                }
-               
+
                if (useresources[cardtype] == 1) {
                        nubus_rewinddir(&dir);
                        if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, &ent) == -1) {
@@ -323,10 +324,10 @@ struct net_device * __init mac8390_probe(int unit)
                        switch (cardtype) {
                                case MAC8390_KINETICS:
                                case MAC8390_DAYNA: /* it's the same */
-                                       dev->base_addr = 
+                                       dev->base_addr =
                                                (int)(ndev->board->slot_addr +
                                                DAYNA_8390_BASE);
-                                       dev->mem_start = 
+                                       dev->mem_start =
                                                (int)(ndev->board->slot_addr +
                                                DAYNA_8390_MEM);
                                        dev->mem_end =
@@ -348,11 +349,11 @@ struct net_device * __init mac8390_probe(int unit)
                                         */
                                        i = (void *)dev->base_addr;
                                        *i = 0x21;
-                                       dev->mem_end = 
+                                       dev->mem_end =
                                                dev->mem_start +
                                                mac8390_memsize(dev->mem_start);
                                        break;
-                                       
+
                                default:
                                        printk(KERN_ERR "Card type %s is"
                                                        " unsupported, sorry\n",
@@ -438,12 +439,12 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
        };
 
        int access_bitmode;
-       
+
        /* Now fill in our stuff */
        dev->open = &mac8390_open;
        dev->stop = &mac8390_close;
 #ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = ei_poll;
+       dev->poll_controller = __ei_poll;
 #endif
 
        /* GAR, ei_status is actually a macro even though it looks global */
@@ -464,7 +465,7 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
                ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
                ei_status.rmem_end = dev->mem_end;
        }
-       
+
        /* Fill in model-specific information and functions */
        switch(type) {
        case MAC8390_SONICSYS:
@@ -514,8 +515,8 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
                printk(KERN_ERR "Card type %s is unsupported, sorry\n", cardname[type]);
                return -ENODEV;
        }
-               
-       NS8390_init(dev, 0);
+
+       __NS8390_init(dev, 0);
 
        /* Good, done, now spit out some messages */
        printk(KERN_INFO "%s: %s in slot %X (type %s)\n",
@@ -530,25 +531,25 @@ static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * nd
                }
        }
        printk(" IRQ %d, shared memory at %#lx-%#lx,  %d-bit access.\n",
-                  dev->irq, dev->mem_start, dev->mem_end-1, 
+                  dev->irq, dev->mem_start, dev->mem_end-1,
                   access_bitmode?32:16);
        return 0;
 }
 
 static int mac8390_open(struct net_device *dev)
 {
-       ei_open(dev);
-       if (request_irq(dev->irq, ei_interrupt, 0, "8390 Ethernet", dev)) {
+       __ei_open(dev);
+       if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) {
                printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
                return -EAGAIN;
-       }       
+       }
        return 0;
 }
 
 static int mac8390_close(struct net_device *dev)
 {
        free_irq(dev->irq, dev);
-       ei_close(dev);
+       __ei_close(dev);
        return 0;
 }
 
@@ -564,55 +565,52 @@ static void mac8390_no_reset(struct net_device *dev)
 /* directly from daynaport.c by Alan Cox */
 static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
 {
-       volatile unsigned short *ptr;
-       unsigned short *target=to;
+       volatile unsigned char *ptr;
+       unsigned char *target=to;
        from<<=1;       /* word, skip overhead */
-       ptr=(unsigned short *)(dev->mem_start+from);
+       ptr=(unsigned char *)(dev->mem_start+from);
        /* Leading byte? */
        if (from&2) {
-               *((char *)target)++ = *(((char *)ptr++)-1);
+               *target++ = ptr[-1];
+               ptr += 2;
                count--;
        }
        while(count>=2)
        {
-               *target++=*ptr++;       /* Copy and */
-               ptr++;                  /* skip cruft */
+               *(unsigned short *)target = *(unsigned short volatile *)ptr;
+               ptr += 4;                       /* skip cruft */
+               target += 2;
                count-=2;
        }
        /* Trailing byte? */
        if(count)
-       {
-               /* Big endian */
-               unsigned short v=*ptr;
-               *((char *)target)=v>>8;
-       }
+               *target = *ptr;
 }
 
 static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count)
 {
        volatile unsigned short *ptr;
-       const unsigned short *src=from;
+       const unsigned char *src=from;
        to<<=1; /* word, skip overhead */
        ptr=(unsigned short *)(dev->mem_start+to);
        /* Leading byte? */
        if (to&2) { /* avoid a byte write (stomps on other data) */
-               ptr[-1] = (ptr[-1]&0xFF00)|*((unsigned char *)src)++;
+               ptr[-1] = (ptr[-1]&0xFF00)|*src++;
                ptr++;
                count--;
        }
        while(count>=2)
        {
-               *ptr++=*src++;          /* Copy and */
+               *ptr++=*(unsigned short *)src;          /* Copy and */
                ptr++;                  /* skip cruft */
+               src += 2;
                count-=2;
        }
        /* Trailing byte? */
        if(count)
        {
-               /* Big endian */
-               unsigned short v=*src;
                /* card doesn't like byte writes */
-               *ptr=(*ptr&0x00FF)|(v&0xFF00);
+               *ptr=(*ptr&0x00FF)|(*src << 8);
        }
 }
 
@@ -647,7 +645,7 @@ static void sane_block_output(struct net_device *dev, int count,
                              const unsigned char *buf, int start_page)
 {
        long shmem = (start_page - WD_START_PG)<<8;
-       
+
        memcpy_toio((char *)dev->mem_start + shmem, buf, count);
 }
 
@@ -689,12 +687,12 @@ static void dayna_block_output(struct net_device *dev, int count, const unsigned
                                int start_page)
 {
        long shmem = (start_page - WD_START_PG)<<8;
-       
+
        dayna_memcpy_tocard(dev, shmem, buf, count);
 }
 
 /* Cabletron block I/O */
-static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, 
+static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
        int ring_page)
 {
        unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
@@ -758,4 +756,4 @@ static void word_memcpy_fromcard(void *tp, const void *fp, int count)
                *to++=*from++;
 }
 
-       
+