root/drivers/net/smc-ultra.c

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

DEFINITIONS

This source file includes following definitions.
  1. ultra_probe
  2. ultra_probe1
  3. ultra_open
  4. ultra_reset_8390
  5. ultra_block_input
  6. ultra_block_output
  7. ultra_close_card

   1 /* smc-ultra.c: A SMC Ultra ethernet driver for linux. */
   2 /*
   3         Written 1993,1994,1995 by Donald Becker.
   4 
   5         Copyright 1993 United States Government as represented by the
   6         Director, National Security Agency.
   7 
   8         This software may be used and distributed according to the terms
   9         of the GNU Public License, incorporated herein by reference.
  10 
  11         The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
  12         Center of Excellence in Space Data and Information Sciences
  13                 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
  14 
  15         This is a driver for the SMC Ultra and SMC EtherEZ ethercards.
  16 
  17         This driver uses the cards in the 8390-compatible, shared memory mode.
  18         Most of the run-time complexity is handled by the generic code in
  19         8390.c.  The code in this file is responsible for
  20 
  21                 ultra_probe()           Detecting and initializing the card.
  22                 ultra_probe1()  
  23 
  24                 ultra_open()            The card-specific details of starting, stopping
  25                 ultra_reset_8390()      and resetting the 8390 NIC core.
  26                 ultra_close()
  27 
  28                 ultra_block_input()             Routines for reading and writing blocks of
  29                 ultra_block_output()    packet buffer memory.
  30 
  31         This driver enables the shared memory only when doing the actual data
  32         transfers to avoid a bug in early version of the card that corrupted
  33         data transferred by a AHA1542.
  34 
  35         This driver does not support the programmed-I/O data transfer mode of
  36         the EtherEZ.  That support (if available) is smc-ez.c.  Nor does it
  37         use the non-8390-compatible "Altego" mode. (No support currently planned.)
  38 */
  39 
  40 static char *version =
  41         "smc-ultra.c:v1.12 1/18/95 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  42 
  43 #include <linux/kernel.h>
  44 #include <linux/sched.h>
  45 #include <linux/errno.h>
  46 #include <linux/string.h>
  47 #include <asm/io.h>
  48 #include <asm/system.h>
  49 
  50 #include <linux/netdevice.h>
  51 #include "8390.h"
  52 extern struct device *init_etherdev(struct device *dev, int sizeof_private,
  53                                                                         unsigned long *mem_startp);
  54 
  55 /* A zero-terminated list of I/O addresses to be probed. */
  56 static unsigned int ultra_portlist[] =
  57 {0x200, 0x220, 0x240, 0x280, 0x300, 0x340, 0x380, 0};
  58 
  59 int ultra_probe(struct device *dev);
  60 int ultra_probe1(struct device *dev, int ioaddr);
  61 
  62 static int ultra_open(struct device *dev);
  63 static void ultra_reset_8390(struct device *dev);
  64 static int ultra_block_input(struct device *dev, int count,
  65                                                   char *buf, int ring_offset);
  66 static void ultra_block_output(struct device *dev, int count,
  67                                                         const unsigned char *buf, const start_page);
  68 static int ultra_close_card(struct device *dev);
  69 
  70 
  71 #define START_PG                0x00    /* First page of TX buffer */
  72 
  73 #define ULTRA_CMDREG    0               /* Offset to ASIC command register. */
  74 #define  ULTRA_RESET    0x80    /* Board reset, in ULTRA_CMDREG. */
  75 #define  ULTRA_MEMENB   0x40    /* Enable the shared memory. */
  76 #define ULTRA_NIC_OFFSET  16    /* NIC register offset from the base_addr. */
  77 #define ULTRA_IO_EXTENT 32
  78 
  79 /*      Probe for the Ultra.  This looks like a 8013 with the station
  80         address PROM at I/O ports <base>+8 to <base>+13, with a checksum
  81         following.
  82 */
  83 #ifdef HAVE_DEVLIST
  84 struct netdev_entry ultra_drv =
  85 {"ultra", ultra_probe1, NETCARD_IO_EXTENT, netcard_portlist};
  86 #else
  87 
  88 int ultra_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  89 {
  90         int i;
  91         int base_addr = dev ? dev->base_addr : 0;
  92 
  93         if (base_addr > 0x1ff)          /* Check a single specified location. */
  94                 return ultra_probe1(dev, base_addr);
  95         else if (base_addr != 0)        /* Don't probe at all. */
  96                 return ENXIO;
  97 
  98         for (i = 0; ultra_portlist[i]; i++) {
  99                 int ioaddr = ultra_portlist[i];
 100                 if (check_region(ioaddr, ULTRA_IO_EXTENT))
 101                         continue;
 102                 if (ultra_probe1(dev, ioaddr) == 0)
 103                         return 0;
 104         }
 105 
 106         return ENODEV;
 107 }
 108 #endif
 109 
 110 int ultra_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 111 {
 112         int i;
 113         int checksum = 0;
 114         char *model_name;
 115         unsigned char eeprom_irq = 0;
 116         /* Values from various config regs. */
 117         unsigned char num_pages, irqreg, addr;
 118         unsigned char idreg = inb(ioaddr + 7);
 119         unsigned char reg4 = inb(ioaddr + 4) & 0x7f;
 120 
 121         /* Check the ID nibble. */
 122         if ((idreg & 0xF0) != 0x20                      /* SMC Ultra */
 123                 && (idreg & 0xF0) != 0x40)              /* SMC EtherEZ */
 124                 return ENODEV;
 125 
 126         /* Select the station address register set. */
 127         outb(reg4, ioaddr + 4);
 128 
 129         for (i = 0; i < 8; i++)
 130                 checksum += inb(ioaddr + 8 + i);
 131         if ((checksum & 0xff) != 0xFF)
 132                 return ENODEV;
 133 
 134         if (dev == NULL)
 135                 dev = init_etherdev(0, sizeof(struct ei_device), 0);
 136 
 137         model_name = (idreg & 0xF0) == 0x20 ? "SMC Ultra" : "SMC EtherEZ";
 138 
 139         printk("%s: %s at %#3x,", dev->name, model_name, ioaddr);
 140 
 141         for (i = 0; i < 6; i++)
 142                 printk(" %2.2X", dev->dev_addr[i] = inb(ioaddr + 8 + i));
 143 
 144         /* Switch from the station address to the alternate register set and
 145            read the useful registers there. */
 146         outb(0x80 | reg4, ioaddr + 4);
 147 
 148         /* Enabled FINE16 mode to avoid BIOS ROM width mismatches @ reboot. */
 149         outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
 150         irqreg = inb(ioaddr + 0xd);
 151         addr = inb(ioaddr + 0xb);
 152 
 153         /* Switch back to the station address register set so that the MS-DOS driver
 154            can find the card after a warm boot. */
 155         outb(reg4, ioaddr + 4);
 156 
 157         if (dev->irq < 2) {
 158                 unsigned char irqmap[] = {0, 9, 3, 5, 7, 10, 11, 15};
 159                 int irq;
 160 
 161                 /* The IRQ bits are split. */
 162                 irq = irqmap[((irqreg & 0x40) >> 4) + ((irqreg & 0x0c) >> 2)];
 163 
 164                 if (irq == 0) {
 165                         printk(", failed to detect IRQ line.\n");
 166                         return -EAGAIN;
 167                 }
 168                 dev->irq = irq;
 169                 eeprom_irq = 1;
 170         }
 171 
 172 
 173         /* OK, we are certain this is going to work.  Setup the device. */
 174         request_region(ioaddr, 32, model_name);
 175 
 176         /* The 8390 isn't at the base address, so fake the offset */
 177         dev->base_addr = ioaddr+ULTRA_NIC_OFFSET;
 178 
 179         {
 180                 int addr_tbl[4] = {0x0C0000, 0x0E0000, 0xFC0000, 0xFE0000};
 181                 short num_pages_tbl[4] = {0x20, 0x40, 0x80, 0xff};
 182 
 183                 dev->mem_start = ((addr & 0x0f) << 13) + addr_tbl[(addr >> 6) & 3] ;
 184                 num_pages = num_pages_tbl[(addr >> 4) & 3];
 185         }
 186 
 187         ethdev_init(dev);
 188 
 189         ei_status.name = model_name;
 190         ei_status.word16 = 1;
 191         ei_status.tx_start_page = START_PG;
 192         ei_status.rx_start_page = START_PG + TX_PAGES;
 193         ei_status.stop_page = num_pages;
 194 
 195         dev->rmem_start = dev->mem_start + TX_PAGES*256;
 196         dev->mem_end = dev->rmem_end
 197                 = dev->mem_start + (ei_status.stop_page - START_PG)*256;
 198 
 199         printk(",%s IRQ %d memory %#lx-%#lx.\n", eeprom_irq ? "" : "assigned ",
 200                    dev->irq, dev->mem_start, dev->mem_end-1);
 201         if (ei_debug > 0)
 202                 printk(version);
 203 
 204         ei_status.reset_8390 = &ultra_reset_8390;
 205         ei_status.block_input = &ultra_block_input;
 206         ei_status.block_output = &ultra_block_output;
 207         dev->open = &ultra_open;
 208         dev->stop = &ultra_close_card;
 209         NS8390_init(dev, 0);
 210 
 211         return 0;
 212 }
 213 
 214 static int
 215 ultra_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 216 {
 217         int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
 218 
 219         if (request_irq(dev->irq, ei_interrupt, 0, ei_status.name))
 220                 return -EAGAIN;
 221 
 222         outb(ULTRA_MEMENB, ioaddr);     /* Enable memory, 16 bit mode. */
 223         outb(0x80, ioaddr + 5);
 224         outb(0x01, ioaddr + 6);         /* Enable interrupts and memory. */
 225         return ei_open(dev);
 226 }
 227 
 228 static void
 229 ultra_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 230 {
 231         int cmd_port = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC base addr */
 232 
 233         outb(ULTRA_RESET, cmd_port);
 234         if (ei_debug > 1) printk("resetting Ultra, t=%ld...", jiffies);
 235         ei_status.txing = 0;
 236 
 237         outb(ULTRA_MEMENB, cmd_port);
 238 
 239         if (ei_debug > 1) printk("reset done\n");
 240         return;
 241 }
 242 
 243 /* Block input and output are easy on shared memory ethercards, the only
 244    complication is when the ring buffer wraps. */
 245 
 246 static int
 247 ultra_block_input(struct device *dev, int count, char *buf, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 248 {
 249         void *xfer_start = (void *)(dev->mem_start + ring_offset
 250                                                                 - (START_PG<<8));
 251 
 252         /* Enable shared memory. */
 253         outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
 254 
 255         if (xfer_start + count > (void*) dev->rmem_end) {
 256                 /* We must wrap the input move. */
 257                 int semi_count = (void*)dev->rmem_end - xfer_start;
 258                 memcpy(buf, xfer_start, semi_count);
 259                 count -= semi_count;
 260                 memcpy(buf + semi_count, (char *)dev->rmem_start, count);
 261                 outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* Disable memory. */
 262                 return dev->rmem_start + count;
 263         }
 264         memcpy(buf, xfer_start, count);
 265 
 266         outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* Disable memory. */
 267         return ring_offset + count;
 268 }
 269 
 270 static void
 271 ultra_block_output(struct device *dev, int count, const unsigned char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
 272                                 int start_page)
 273 {
 274         unsigned char *shmem
 275                 = (unsigned char *)dev->mem_start + ((start_page - START_PG)<<8);
 276 
 277         /* Enable shared memory. */
 278         outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
 279 
 280         memcpy(shmem, buf, count);
 281 
 282         outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* Disable memory. */
 283 }
 284 
 285 static int
 286 ultra_close_card(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 287 {
 288         int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* CMDREG */
 289 
 290         dev->start = 0;
 291         dev->tbusy = 1;
 292 
 293         if (ei_debug > 1)
 294                 printk("%s: Shutting down ethercard.\n", dev->name);
 295 
 296         outb(0x00, ioaddr + 6);         /* Disable interrupts. */
 297         free_irq(dev->irq);
 298         irq2dev_map[dev->irq] = 0;
 299 
 300         NS8390_init(dev, 0);
 301 
 302         /* We should someday disable shared memory and change to 8-bit mode
 303            "just in case"... */
 304 
 305         return 0;
 306 }
 307 
 308 
 309 /*
 310  * Local variables:
 311  *  compile-command: "gcc -D__KERNEL__ -Wall -O6 -I/usr/src/linux/net/inet -c smc-ultra.c"
 312  *  version-control: t
 313  *  kept-new-versions: 5
 314  *  c-indent-level: 4
 315  *  tab-width: 4
 316  * End:
 317  */

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