root/drivers/net/e2100.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mem_on
  2. mem_off
  3. e2100_probe
  4. e21_probe1
  5. e21_open
  6. e21_reset_8390
  7. e21_block_input
  8. e21_block_output
  9. e21_close

   1 /* e2100.c: A Cabletron E2100 series ethernet driver for linux. */
   2 /*
   3         Written 1993-1994 by Donald Becker.
   4 
   5         Copyright 1994 by Donald Becker.
   6         Copyright 1993 United States Government as represented by the
   7         Director, National Security Agency.  This software may be used and
   8         distributed according to the terms of the GNU Public License,
   9         incorporated herein by reference.
  10 
  11         This is a driver for the Cabletron E2100 series ethercards.
  12 
  13         The Author may be reached as becker@cesdis.gsfc.nasa.gov, or
  14         C/O Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  15 
  16         The E2100 series ethercard is a fairly generic shared memory 8390
  17         implementation.  The only unusual aspect is the way the shared memory
  18         registers are set: first you do an inb() in what is normally the
  19         station address region, and the low three bits of next outb() *address*
  20         is used as the write value for that register.  Either someone wasn't
  21         too used to dem bit en bites, or they were trying to obfuscate the
  22         programming     interface.
  23 
  24         There is an additional complication when setting the window on the packet
  25         buffer.  You must first do a read into the packet buffer region with the
  26         low 8 address bits the address setting the page for the start of the packet
  27         buffer window, and then do the above operation.  See mem_on() for details.
  28 
  29         One bug on the chip is that even a hard reset won't disable the memory
  30         window, usually resulting in a hung machine if mem_off() isn't called.
  31         If this happens, you must power down the machine for about 30 seconds.
  32 */
  33 
  34 static char *version =
  35         "e2100.c:v1.01 7/21/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  36 
  37 #include <linux/config.h>
  38 #include <linux/kernel.h>
  39 #include <linux/sched.h>
  40 #include <linux/errno.h>
  41 #include <linux/string.h>
  42 #include <asm/io.h>
  43 #include <asm/system.h>
  44 #include <linux/ioport.h>
  45 
  46 #include <linux/netdevice.h>
  47 #include "8390.h"
  48 
  49 static int e21_probe_list[] = {0x300, 0x280, 0x380, 0x220, 0};
  50 
  51 /* Offsets from the base_addr.
  52    Read from the ASIC register, and the low three bits of the next outb()
  53    address is used to set the corresponding register. */
  54 #define E21_NIC_OFFSET  0               /* Offset to the 8390 NIC. */
  55 #define E21_ASIC                0x10
  56 #define E21_MEM_ENABLE  0x10
  57 #define  E21_MEM_ON             0x05    /* Enable memory in 16 bit mode. */
  58 #define  E21_MEM_ON_8   0x07    /* Enable memory in  8 bit mode. */
  59 #define E21_MEM_BASE    0x11    
  60 #define E21_IRQ_LOW             0x12    /* The low three bits of the IRQ number. */
  61 #define E21_IRQ_HIGH    0x14    /* The high IRQ bit and media select ...  */
  62 #define E21_MEDIA               0x14    /* (alias). */
  63 #define  E21_ALT_IFPORT 0x02    /* Set to use the other (BNC,AUI) port. */
  64 #define  E21_BIG_MEM    0x04    /* Use a bigger (64K) buffer (we don't) */
  65 #define E21_SAPROM              0x10    /* Offset to station address data. */
  66 #define E21_IO_EXTENT    0x20
  67 
  68 extern inline void mem_on(short port, volatile char *mem_base,
     /* [previous][next][first][last][top][bottom][index][help] */
  69                                                   unsigned char start_page )
  70 {
  71         /* This is a little weird: set the shared memory window by doing a
  72            read.  The low address bits specify the starting page. */
  73         mem_base[start_page];
  74         inb(port + E21_MEM_ENABLE);
  75         outb(E21_MEM_ON, port + E21_MEM_ENABLE + E21_MEM_ON);
  76 }
  77 
  78 extern inline void mem_off(short port)
     /* [previous][next][first][last][top][bottom][index][help] */
  79 {
  80         inb(port + E21_MEM_ENABLE);
  81         outb(0x00, port + E21_MEM_ENABLE);
  82 }
  83 
  84 /* In other drivers I put the TX pages first, but the E2100 window circuitry
  85    is designed to have a 4K Tx region last. The windowing circuitry wraps the
  86    window at 0x2fff->0x0000 so that the packets at e.g. 0x2f00 in the RX ring
  87    appear contiguously in the window. */
  88 #define E21_RX_START_PG         0x00    /* First page of RX buffer */
  89 #define E21_RX_STOP_PG          0x30    /* Last page +1 of RX ring */
  90 #define E21_BIG_RX_STOP_PG      0xF0    /* Last page +1 of RX ring */
  91 #define E21_TX_START_PG         E21_RX_STOP_PG  /* First page of TX buffer */
  92 
  93 int e2100_probe(struct device *dev);
  94 int e21_probe1(struct device *dev, int ioaddr);
  95 
  96 static int e21_open(struct device *dev);
  97 static void e21_reset_8390(struct device *dev);
  98 static int e21_block_input(struct device *dev, int count,
  99                                                    char *buf, int ring_offset);
 100 static void e21_block_output(struct device *dev, int count,
 101                                                          const unsigned char *buf, const start_page);
 102 static int e21_close(struct device *dev);
 103 
 104 
 105 /*  Probe for the E2100 series ethercards.  These cards have an 8390 at the
 106         base address and the station address at both offset 0x10 and 0x18.  I read
 107         the station address from offset 0x18 to avoid the dataport of NE2000
 108         ethercards, and look for Ctron's unique ID (first three octets of the
 109         station address).
 110  */
 111 
 112 int e2100_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 113 {
 114         int *port;
 115         int base_addr = dev->base_addr;
 116 
 117         if (base_addr > 0x1ff)          /* Check a single specified location. */
 118                 return e21_probe1(dev, base_addr);
 119         else if (base_addr != 0)        /* Don't probe at all. */
 120                 return ENXIO;
 121 
 122         for (port = e21_probe_list; *port; port++) {
 123                 if (check_region(*port, E21_IO_EXTENT))
 124                         continue;
 125                 if (e21_probe1(dev, *port) == 0)
 126                         return 0;
 127         }
 128 
 129         return ENODEV;
 130 }
 131 
 132 int e21_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 133 {
 134         int i, status;
 135         unsigned char *station_addr = dev->dev_addr;
 136 
 137         /* First check the station address for the Ctron prefix. */
 138         if (inb(ioaddr + E21_SAPROM + 0) != 0x00
 139                 || inb(ioaddr + E21_SAPROM + 1) != 0x00
 140                 || inb(ioaddr + E21_SAPROM + 2) != 0x1d)
 141                 return ENODEV;
 142 
 143         /* Verify by making certain that there is a 8390 at there. */
 144         outb(E8390_NODMA + E8390_STOP, ioaddr);
 145         SLOW_DOWN_IO;
 146         status = inb(ioaddr);
 147         if (status != 0x21 && status != 0x23)
 148                 return ENODEV;
 149 
 150         /* Grab the region so we can find a different board if IRQ select fails. */
 151         snarf_region(ioaddr, E21_IO_EXTENT);
 152 
 153         /* Read the station address PROM.  */
 154         for (i = 0; i < 6; i++)
 155                 station_addr[i] = inb(ioaddr + E21_SAPROM + i);
 156 
 157         inb(ioaddr + E21_MEDIA);                /* Point to media selection. */
 158         outb(0, ioaddr + E21_ASIC);     /* and disable the secondary interface. */
 159 
 160         printk("%s: E21** at %#3x,", dev->name, ioaddr);
 161         for (i = 0; i < 6; i++)
 162                 printk(" %02X", station_addr[i]);
 163 
 164         if (dev->irq < 2) {
 165                 int irqlist[] = {15,11,10,12,5,9,3,4}, i;
 166                 for (i = 0; i < 8; i++)
 167                         if (request_irq (irqlist[i], NULL, 0, "bogus") != -EBUSY) {
 168                                 dev->irq = irqlist[i];
 169                                 break;
 170                         }
 171                 if (i >= 8) {
 172                         printk(" unable to get IRQ %d.\n", dev->irq);
 173                         return EAGAIN;
 174                 }
 175         } else if (dev->irq == 2)       /* Fixup luser bogosity: IRQ2 is really IRQ9 */
 176                 dev->irq = 9;
 177 
 178         /* The 8390 is at the base address. */
 179         dev->base_addr = ioaddr;
 180 
 181         ethdev_init(dev);
 182 
 183         ei_status.name = "E2100";
 184         ei_status.word16 = 1;
 185         ei_status.tx_start_page = E21_TX_START_PG;
 186         ei_status.rx_start_page = E21_RX_START_PG;
 187         ei_status.stop_page = E21_RX_STOP_PG;
 188     ei_status.saved_irq = dev->irq;
 189 
 190         /* Check the media port used.  The port can be passed in on the
 191            low mem_end bits. */
 192         if (dev->mem_end & 15)
 193                 dev->if_port = dev->mem_end & 7;
 194         else {
 195                 dev->if_port = 0;
 196                 inb(ioaddr + E21_MEDIA);        /* Turn automatic media detection on. */
 197                 for(i = 0; i < 6; i++)
 198                         if (station_addr[i] != inb(ioaddr + E21_SAPROM + 8 + i)) {
 199                                 dev->if_port = 1;
 200                                 break;
 201                         }
 202         }
 203 
 204         /* Never map in the E21 shared memory unless you are actively using it.
 205            Also, the shared memory has effective only one setting -- spread all
 206            over the 128K region! */
 207         if (dev->mem_start == 0)
 208                 dev->mem_start = 0xd0000;
 209         
 210 #ifdef notdef
 211         /* These values are unused.  The E2100 has a 2K window into the packet
 212            buffer.  The window can be set to start on any page boundary. */
 213         dev->rmem_start = dev->mem_start + TX_PAGES*256;
 214         dev->mem_end = dev->rmem_end = dev->mem_start + 2*1024;
 215 #endif
 216 
 217         printk(", IRQ %d, %s media, memory @ %#lx.\n", dev->irq,
 218                    dev->if_port ? "secondary" : "primary", dev->mem_start);
 219 
 220         if (ei_debug > 0)
 221                 printk(version);
 222 
 223         ei_status.reset_8390 = &e21_reset_8390;
 224         ei_status.block_input = &e21_block_input;
 225         ei_status.block_output = &e21_block_output;
 226         dev->open = &e21_open;
 227         dev->stop = &e21_close;
 228         NS8390_init(dev, 0);
 229 
 230         return 0;
 231 }
 232 
 233 static int
 234 e21_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 235 {
 236         short ioaddr = dev->base_addr;
 237 
 238         if (request_irq(dev->irq, ei_interrupt, 0, "e2100")) {
 239                 return EBUSY;
 240         }
 241         irq2dev_map[dev->irq] = dev;
 242 
 243         /* Set the interrupt line and memory base on the hardware. */
 244         inb(ioaddr + E21_IRQ_LOW);
 245         outb(0, ioaddr + E21_ASIC + (dev->irq & 7));
 246         inb(ioaddr + E21_IRQ_HIGH);                     /* High IRQ bit, and if_port. */
 247         outb(0, ioaddr + E21_ASIC + (dev->irq > 7 ? 1:0)
 248                    + (dev->if_port ? E21_ALT_IFPORT : 0));
 249         inb(ioaddr + E21_MEM_BASE);
 250         outb(0, ioaddr + E21_ASIC + ((dev->mem_start >> 17) & 7));
 251 
 252         return ei_open(dev);
 253 }
 254 
 255 static void
 256 e21_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 257 {
 258         short ioaddr = dev->base_addr;
 259 
 260         outb(0x01, ioaddr);
 261         if (ei_debug > 1) printk("resetting the E2180x3 t=%ld...", jiffies);
 262         ei_status.txing = 0;
 263 
 264         /* Set up the ASIC registers, just in case something changed them. */
 265 
 266         if (ei_debug > 1) printk("reset done\n");
 267         return;
 268 }
 269 
 270 /*  Block input and output are easy on shared memory ethercards.
 271         The E21xx makes block_input() especially easy by wrapping the top
 272         ring buffer to the bottom automatically. */
 273 static int
 274 e21_block_input(struct device *dev, int count, char *buf, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 275 {
 276         short ioaddr = dev->base_addr;
 277         char *shared_mem = (char *)dev->mem_start;
 278         int start_page = (ring_offset>>8);
 279 
 280         mem_on(ioaddr, shared_mem, start_page);
 281 
 282         /* We'll always get a 4 byte header read first. */
 283         if (count == 4)
 284                 ((int*)buf)[0] = ((int*)shared_mem)[0];
 285         else
 286                 memcpy(buf, shared_mem + (ring_offset & 0xff), count);
 287 
 288         /* Turn off memory access: we would need to reprogram the window anyway. */
 289         mem_off(ioaddr);
 290 
 291         return 0;
 292 }
 293 
 294 static void
 295 e21_block_output(struct device *dev, int count, const unsigned char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
 296                                  int start_page)
 297 {
 298         short ioaddr = dev->base_addr;
 299         volatile char *shared_mem = (char *)dev->mem_start;
 300 
 301         /* Set the shared memory window start by doing a read, with the low address
 302            bits specifying the starting page. */
 303         *(shared_mem + start_page);
 304         mem_on(ioaddr, shared_mem, start_page);
 305 
 306         memcpy((char*)shared_mem, buf, count);
 307         mem_off(ioaddr);
 308 }
 309 
 310 static int
 311 e21_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 312 {
 313         short ioaddr = dev->base_addr;
 314 
 315         if (ei_debug > 1)
 316                 printk("%s: Shutting down ethercard.\n", dev->name);
 317 
 318     free_irq(dev->irq);
 319     dev->irq = ei_status.saved_irq;
 320 
 321         /* Shut off the interrupt line and secondary interface. */
 322         inb(ioaddr + E21_IRQ_LOW);
 323         outb(0, ioaddr + E21_ASIC);
 324         inb(ioaddr + E21_IRQ_HIGH);                     /* High IRQ bit, and if_port. */
 325         outb(0, ioaddr + E21_ASIC);
 326 
 327     irq2dev_map[dev->irq] = NULL;
 328 
 329         NS8390_init(dev, 0);
 330 
 331         /* Double-check that the memory has been turned off, because really
 332            really bad things happen if it isn't. */
 333         mem_off(ioaddr);
 334 
 335         return 0;
 336 }
 337 
 338 #ifdef HAVE_DEVLIST
 339 struct netdev_entry e21_drv =
 340 {"e21", e21_probe1, E21_IO_EXTENT, e21_probe_list};
 341 #endif
 342 
 343 
 344 /*
 345  * Local variables:
 346  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c e2100.c"
 347  *  version-control: t
 348  *  tab-width: 4
 349  *  kept-new-versions: 5
 350  * End:
 351  */

/* [previous][next][first][last][top][bottom][index][help] */