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
  8. init_module
  9. cleanup_module

   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 const char *version =
  41         "smc-ultra.c:v1.12 1/18/95 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  42 
  43 
  44 #ifdef MODULE
  45 #include <linux/module.h>
  46 #include <linux/version.h>
  47 #endif
  48 
  49 #include <linux/kernel.h>
  50 #include <linux/sched.h>
  51 #include <linux/errno.h>
  52 #include <linux/string.h>
  53 #include <asm/io.h>
  54 #include <asm/system.h>
  55 
  56 #include <linux/netdevice.h>
  57 #include "8390.h"
  58 extern struct device *init_etherdev(struct device *dev, int sizeof_private,
  59                                                                         unsigned long *mem_startp);
  60 
  61 /* A zero-terminated list of I/O addresses to be probed. */
  62 static unsigned int ultra_portlist[] =
  63 {0x200, 0x220, 0x240, 0x280, 0x300, 0x340, 0x380, 0};
  64 
  65 int ultra_probe(struct device *dev);
  66 int ultra_probe1(struct device *dev, int ioaddr);
  67 
  68 static int ultra_open(struct device *dev);
  69 static void ultra_reset_8390(struct device *dev);
  70 static int ultra_block_input(struct device *dev, int count,
  71                                                   char *buf, int ring_offset);
  72 static void ultra_block_output(struct device *dev, int count,
  73                                                         const unsigned char *buf, const start_page);
  74 static int ultra_close_card(struct device *dev);
  75 
  76 
  77 #define START_PG                0x00    /* First page of TX buffer */
  78 
  79 #define ULTRA_CMDREG    0               /* Offset to ASIC command register. */
  80 #define  ULTRA_RESET    0x80    /* Board reset, in ULTRA_CMDREG. */
  81 #define  ULTRA_MEMENB   0x40    /* Enable the shared memory. */
  82 #define ULTRA_NIC_OFFSET  16    /* NIC register offset from the base_addr. */
  83 #define ULTRA_IO_EXTENT 32
  84 
  85 /*      Probe for the Ultra.  This looks like a 8013 with the station
  86         address PROM at I/O ports <base>+8 to <base>+13, with a checksum
  87         following.
  88 */
  89 #ifdef HAVE_DEVLIST
  90 struct netdev_entry ultra_drv =
  91 {"ultra", ultra_probe1, NETCARD_IO_EXTENT, netcard_portlist};
  92 #else
  93 
  94 int ultra_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  95 {
  96         int i;
  97         int base_addr = dev ? dev->base_addr : 0;
  98 
  99         if (base_addr > 0x1ff)          /* Check a single specified location. */
 100                 return ultra_probe1(dev, base_addr);
 101         else if (base_addr != 0)        /* Don't probe at all. */
 102                 return ENXIO;
 103 
 104         for (i = 0; ultra_portlist[i]; i++) {
 105                 int ioaddr = ultra_portlist[i];
 106                 if (check_region(ioaddr, ULTRA_IO_EXTENT))
 107                         continue;
 108                 if (ultra_probe1(dev, ioaddr) == 0)
 109                         return 0;
 110         }
 111 
 112         return ENODEV;
 113 }
 114 #endif
 115 
 116 int ultra_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 117 {
 118         int i;
 119         int checksum = 0;
 120         const char *model_name;
 121         unsigned char eeprom_irq = 0;
 122         /* Values from various config regs. */
 123         unsigned char num_pages, irqreg, addr;
 124         unsigned char idreg = inb(ioaddr + 7);
 125         unsigned char reg4 = inb(ioaddr + 4) & 0x7f;
 126 
 127         /* Check the ID nibble. */
 128         if ((idreg & 0xF0) != 0x20                      /* SMC Ultra */
 129                 && (idreg & 0xF0) != 0x40)              /* SMC EtherEZ */
 130                 return ENODEV;
 131 
 132         /* Select the station address register set. */
 133         outb(reg4, ioaddr + 4);
 134 
 135         for (i = 0; i < 8; i++)
 136                 checksum += inb(ioaddr + 8 + i);
 137         if ((checksum & 0xff) != 0xFF)
 138                 return ENODEV;
 139 
 140         if (dev == NULL)
 141                 dev = init_etherdev(0, sizeof(struct ei_device), 0);
 142         if (dev == NULL) /* Still.. */
 143                 return ENOMEM; /* Out of memory ?? */
 144 
 145         model_name = (idreg & 0xF0) == 0x20 ? "SMC Ultra" : "SMC EtherEZ";
 146 
 147         printk("%s: %s at %#3x,", dev->name, model_name, ioaddr);
 148 
 149         for (i = 0; i < 6; i++)
 150                 printk(" %2.2X", dev->dev_addr[i] = inb(ioaddr + 8 + i));
 151 
 152         /* Switch from the station address to the alternate register set and
 153            read the useful registers there. */
 154         outb(0x80 | reg4, ioaddr + 4);
 155 
 156         /* Enabled FINE16 mode to avoid BIOS ROM width mismatches @ reboot. */
 157         outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
 158         irqreg = inb(ioaddr + 0xd);
 159         addr = inb(ioaddr + 0xb);
 160 
 161         /* Switch back to the station address register set so that the MS-DOS driver
 162            can find the card after a warm boot. */
 163         outb(reg4, ioaddr + 4);
 164 
 165         if (dev->irq < 2) {
 166                 unsigned char irqmap[] = {0, 9, 3, 5, 7, 10, 11, 15};
 167                 int irq;
 168 
 169                 /* The IRQ bits are split. */
 170                 irq = irqmap[((irqreg & 0x40) >> 4) + ((irqreg & 0x0c) >> 2)];
 171 
 172                 if (irq == 0) {
 173                         printk(", failed to detect IRQ line.\n");
 174                         return -EAGAIN;
 175                 }
 176                 dev->irq = irq;
 177                 eeprom_irq = 1;
 178         }
 179 
 180 
 181         /* OK, we are certain this is going to work.  Setup the device. */
 182         request_region(ioaddr, ULTRA_IO_EXTENT, model_name);
 183 
 184         /* The 8390 isn't at the base address, so fake the offset */
 185         dev->base_addr = ioaddr+ULTRA_NIC_OFFSET;
 186 
 187         {
 188                 int addr_tbl[4] = {0x0C0000, 0x0E0000, 0xFC0000, 0xFE0000};
 189                 short num_pages_tbl[4] = {0x20, 0x40, 0x80, 0xff};
 190 
 191                 dev->mem_start = ((addr & 0x0f) << 13) + addr_tbl[(addr >> 6) & 3] ;
 192                 num_pages = num_pages_tbl[(addr >> 4) & 3];
 193         }
 194 
 195         ethdev_init(dev);
 196 
 197         ei_status.name = model_name;
 198         ei_status.word16 = 1;
 199         ei_status.tx_start_page = START_PG;
 200         ei_status.rx_start_page = START_PG + TX_PAGES;
 201         ei_status.stop_page = num_pages;
 202 
 203         dev->rmem_start = dev->mem_start + TX_PAGES*256;
 204         dev->mem_end = dev->rmem_end
 205                 = dev->mem_start + (ei_status.stop_page - START_PG)*256;
 206 
 207         printk(",%s IRQ %d memory %#lx-%#lx.\n", eeprom_irq ? "" : "assigned ",
 208                    dev->irq, dev->mem_start, dev->mem_end-1);
 209         if (ei_debug > 0)
 210                 printk(version);
 211 
 212         ei_status.reset_8390 = &ultra_reset_8390;
 213         ei_status.block_input = &ultra_block_input;
 214         ei_status.block_output = &ultra_block_output;
 215         dev->open = &ultra_open;
 216         dev->stop = &ultra_close_card;
 217         NS8390_init(dev, 0);
 218 
 219         return 0;
 220 }
 221 
 222 static int
 223 ultra_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 224 {
 225         int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
 226         int rc;
 227 
 228         if (request_irq(dev->irq, ei_interrupt, 0, ei_status.name))
 229                 return -EAGAIN;
 230 
 231         outb(ULTRA_MEMENB, ioaddr);     /* Enable memory, 16 bit mode. */
 232         outb(0x80, ioaddr + 5);
 233         outb(0x01, ioaddr + 6);         /* Enable interrupts and memory. */
 234         rc = ei_open(dev);
 235         if (rc != 0) return rc;
 236 #ifdef MODULE
 237         MOD_INC_USE_COUNT;
 238 #endif
 239         return 0;
 240 }
 241 
 242 static void
 243 ultra_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 244 {
 245         int cmd_port = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC base addr */
 246 
 247         outb(ULTRA_RESET, cmd_port);
 248         if (ei_debug > 1) printk("resetting Ultra, t=%ld...", jiffies);
 249         ei_status.txing = 0;
 250 
 251         outb(ULTRA_MEMENB, cmd_port);
 252 
 253         if (ei_debug > 1) printk("reset done\n");
 254         return;
 255 }
 256 
 257 /* Block input and output are easy on shared memory ethercards, the only
 258    complication is when the ring buffer wraps. */
 259 
 260 static int
 261 ultra_block_input(struct device *dev, int count, char *buf, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 262 {
 263         void *xfer_start = (void *)(dev->mem_start + ring_offset
 264                                                                 - (START_PG<<8));
 265 
 266         /* Enable shared memory. */
 267         outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
 268 
 269         if (xfer_start + count > (void*) dev->rmem_end) {
 270                 /* We must wrap the input move. */
 271                 int semi_count = (void*)dev->rmem_end - xfer_start;
 272                 memcpy(buf, xfer_start, semi_count);
 273                 count -= semi_count;
 274                 memcpy(buf + semi_count, (char *)dev->rmem_start, count);
 275                 outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* Disable memory. */
 276                 return dev->rmem_start + count;
 277         }
 278         memcpy(buf, xfer_start, count);
 279 
 280         outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* Disable memory. */
 281         return ring_offset + count;
 282 }
 283 
 284 static void
 285 ultra_block_output(struct device *dev, int count, const unsigned char *buf,
     /* [previous][next][first][last][top][bottom][index][help] */
 286                                 int start_page)
 287 {
 288         unsigned char *shmem
 289                 = (unsigned char *)dev->mem_start + ((start_page - START_PG)<<8);
 290 
 291         /* Enable shared memory. */
 292         outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
 293 
 294         memcpy(shmem, buf, count);
 295 
 296         outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* Disable memory. */
 297 }
 298 
 299 static int
 300 ultra_close_card(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 301 {
 302         int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* CMDREG */
 303 
 304         dev->start = 0;
 305         dev->tbusy = 1;
 306 
 307         if (ei_debug > 1)
 308                 printk("%s: Shutting down ethercard.\n", dev->name);
 309 
 310         outb(0x00, ioaddr + 6);         /* Disable interrupts. */
 311         free_irq(dev->irq);
 312         irq2dev_map[dev->irq] = 0;
 313 
 314         NS8390_init(dev, 0);
 315 
 316         /* We should someday disable shared memory and change to 8-bit mode
 317            "just in case"... */
 318 
 319 #ifdef MODULE
 320         MOD_DEC_USE_COUNT;
 321 #endif
 322 
 323         return 0;
 324 }
 325 
 326 #ifdef MODULE
 327 char kernel_version[] = UTS_RELEASE;
 328 static struct device dev_ultra = {
 329         "        " /*"smc-ultra"*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, ultra_probe };
 330 
 331 int io = 0;
 332 int irq = 0;
 333 
 334 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 335 {
 336         dev_ultra.base_addr = io;
 337         dev_ultra.irq       = irq;
 338         if (register_netdev(&dev_ultra) != 0) {
 339                 printk("smc-ultra: register_netdev() returned non-zero.\n");
 340                 return -EIO;
 341         }
 342         return 0;
 343 }
 344 
 345 void
 346 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 347 {
 348         if (MOD_IN_USE)
 349                 printk("smc-ultra: device busy, remove delayed\n");
 350         else
 351         {
 352                 unregister_netdev(&dev_ultra);
 353         }
 354 }
 355 #endif /* MODULE */
 356 
 357 
 358 /*
 359  * Local variables:
 360  *  compile-command: "gcc -D__KERNEL__ -Wall -O6 -I/usr/src/linux/net/inet -c smc-ultra.c"
 361  *  version-control: t
 362  *  kept-new-versions: 5
 363  *  c-indent-level: 4
 364  *  tab-width: 4
 365  * End:
 366  */

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