root/drivers/net/hp.c

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

DEFINITIONS

This source file includes following definitions.
  1. hp_probe
  2. hp_probe1
  3. hp_reset_8390
  4. hp_block_input
  5. hp_block_output
  6. hp_init_card
  7. init_module
  8. cleanup_module

   1 /* hp.c: A HP LAN ethernet driver for linux. */
   2 /*
   3         Written 1993-94 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 HP PC-LAN adaptors.
  16 
  17         Sources:
  18           The Crynwr packet driver.
  19 */
  20 
  21 static const char *version =
  22         "hp.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  23 
  24 
  25 #ifdef MODULE
  26 #include <linux/module.h>
  27 #include <linux/version.h>
  28 #endif
  29 
  30 #include <linux/kernel.h>
  31 #include <linux/sched.h>
  32 #include <linux/errno.h>
  33 #include <linux/ioport.h>
  34 #include <asm/system.h>
  35 #include <asm/io.h>
  36 
  37 #include <linux/netdevice.h>
  38 #include "8390.h"
  39 
  40 extern struct device *init_etherdev(struct device *dev, int sizeof_private,
  41                                                                         unsigned long *mem_startp);
  42 
  43 /* A zero-terminated list of I/O addresses to be probed. */
  44 static unsigned int hppclan_portlist[] =
  45 { 0x300, 0x320, 0x340, 0x280, 0x2C0, 0x200, 0x240, 0};
  46 
  47 #define HP_IO_EXTENT    32
  48 
  49 #define HP_DATAPORT             0x0c    /* "Remote DMA" data port. */
  50 #define HP_ID                   0x07
  51 #define HP_CONFIGURE    0x08    /* Configuration register. */
  52 #define  HP_RUN                 0x01    /* 1 == Run, 0 == reset. */
  53 #define  HP_IRQ                 0x0E    /* Mask for software-configured IRQ line. */
  54 #define  HP_DATAON              0x10    /* Turn on dataport */
  55 #define NIC_OFFSET              0x10    /* Offset the 8390 registers. */
  56 
  57 #define HP_START_PG             0x00    /* First page of TX buffer */
  58 #define HP_8BSTOP_PG    0x80    /* Last page +1 of RX ring */
  59 #define HP_16BSTOP_PG   0xFF    /* Same, for 16 bit cards. */
  60 
  61 int hp_probe(struct device *dev);
  62 int hp_probe1(struct device *dev, int ioaddr);
  63 
  64 static void hp_reset_8390(struct device *dev);
  65 static int hp_block_input(struct device *dev, int count,
  66                                                   char *buf, int ring_offset);
  67 static void hp_block_output(struct device *dev, int count,
  68                                                         const unsigned char *buf, const start_page);
  69 static void hp_init_card(struct device *dev);
  70 
  71 /* The map from IRQ number to HP_CONFIGURE register setting. */
  72 /* My default is IRQ5      0  1  2  3  4  5  6  7  8  9 10 11 */
  73 static char irqmap[16] = { 0, 0, 4, 6, 8,10, 0,14, 0, 4, 2,12,0,0,0,0};
  74 
  75 /* NE2000, et.al. bug-fix code */
  76 static int ne8390_rw_bugfix = 0;
  77 
  78 
  79 /*      Probe for an HP LAN adaptor.
  80         Also initialize the card and fill in STATION_ADDR with the station
  81         address. */
  82 #ifdef HAVE_DEVLIST
  83 struct netdev_entry netcard_drv =
  84 {"hp", hp_probe1, HP_IO_EXTENT, hppclan_portlist};
  85 #else
  86 
  87 int hp_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  88 {
  89         int i;
  90         int base_addr = dev ? dev->base_addr : 0;
  91 
  92         if (base_addr > 0x1ff)          /* Check a single specified location. */
  93                 return hp_probe1(dev, base_addr);
  94         else if (base_addr != 0)        /* Don't probe at all. */
  95                 return ENXIO;
  96 
  97         for (i = 0; hppclan_portlist[i]; i++) {
  98                 int ioaddr = hppclan_portlist[i];
  99                 if (check_region(ioaddr, HP_IO_EXTENT))
 100                         continue;
 101                 if (hp_probe1(dev, ioaddr) == 0)
 102                         return 0;
 103         }
 104 
 105         return ENODEV;
 106 }
 107 #endif
 108 
 109 int hp_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 110 {
 111         int i, board_id, wordmode;
 112         const char *name;
 113 
 114         /* Check for the HP physical address, 08 00 09 xx xx xx. */
 115         /* This really isn't good enough: we may pick up HP LANCE boards
 116            also!  Avoid the lance 0x5757 signature. */
 117         if (inb(ioaddr) != 0x08
 118                 || inb(ioaddr+1) != 0x00
 119                 || inb(ioaddr+2) != 0x09
 120                 || inb(ioaddr+14) == 0x57)
 121                 return ENODEV;
 122 
 123         /* Set up the parameters based on the board ID.
 124            If you have additional mappings, please mail them to me -djb. */
 125         if ((board_id = inb(ioaddr + HP_ID)) & 0x80) {
 126                 name = "HP27247";
 127                 wordmode = 1;
 128         } else {
 129                 name = "HP27250";
 130                 wordmode = 0;
 131         }
 132 
 133         if (dev == NULL)
 134                 dev = init_etherdev(0, sizeof(struct ei_device), 0);
 135 
 136         /* Grab the region so we can find another board if something fails. */
 137         request_region(ioaddr, HP_IO_EXTENT,"hp");
 138 
 139         printk("%s: %s (ID %02x) at %#3x,", dev->name, name, board_id, ioaddr);
 140 
 141         for(i = 0; i < ETHER_ADDR_LEN; i++)
 142                 printk(" %2.2x", dev->dev_addr[i] = inb(ioaddr + i));
 143 
 144         /* Snarf the interrupt now.  Someday this could be moved to open(). */
 145         if (dev->irq < 2) {
 146                 int irq_16list[] = { 11, 10, 5, 3, 4, 7, 9, 0};
 147                 int irq_8list[] = { 7, 5, 3, 4, 9, 0};
 148                 int *irqp = wordmode ? irq_16list : irq_8list;
 149                 do {
 150                         int irq = *irqp;
 151                         if (request_irq (irq, NULL, 0, "bogus") != -EBUSY) {
 152                                 autoirq_setup(0);
 153                                 /* Twinkle the interrupt, and check if it's seen. */
 154                                 outb_p(irqmap[irq] | HP_RUN, ioaddr + HP_CONFIGURE);
 155                                 outb_p( 0x00 | HP_RUN, ioaddr + HP_CONFIGURE);
 156                                 if (irq == autoirq_report(0)             /* It's a good IRQ line! */
 157                                         && request_irq (irq, &ei_interrupt, 0, "hp") == 0) {
 158                                         printk(" selecting IRQ %d.\n", irq);
 159                                         dev->irq = *irqp;
 160                                         break;
 161                                 }
 162                         }
 163                 } while (*++irqp);
 164                 if (*irqp == 0) {
 165                         printk(" no free IRQ lines.\n");
 166                         return EBUSY;
 167                 }
 168         } else {
 169                 if (dev->irq == 2)
 170                         dev->irq = 9;
 171                 if (request_irq(dev->irq, ei_interrupt, 0, "hp")) {
 172                         printk (" unable to get IRQ %d.\n", dev->irq);
 173                         return EBUSY;
 174                 }
 175         }
 176 
 177         if (ei_debug > 1)
 178                 printk(version);
 179 
 180         /* Set the base address to point to the NIC, not the "real" base! */
 181         dev->base_addr = ioaddr + NIC_OFFSET;
 182 
 183         ethdev_init(dev);
 184 
 185         ei_status.name = name;
 186         ei_status.word16 = wordmode;
 187         ei_status.tx_start_page = HP_START_PG;
 188         ei_status.rx_start_page = HP_START_PG + TX_PAGES;
 189         ei_status.stop_page = wordmode ? HP_16BSTOP_PG : HP_8BSTOP_PG;
 190 
 191         ei_status.reset_8390 = &hp_reset_8390;
 192         ei_status.block_input = &hp_block_input;
 193         ei_status.block_output = &hp_block_output;
 194         hp_init_card(dev);
 195 
 196         return 0;
 197 }
 198 
 199 static void
 200 hp_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 201 {
 202         int hp_base = dev->base_addr - NIC_OFFSET;
 203         int saved_config = inb_p(hp_base + HP_CONFIGURE);
 204 
 205         if (ei_debug > 1) printk("resetting the 8390 time=%ld...", jiffies);
 206         outb_p(0x00, hp_base + HP_CONFIGURE);
 207         ei_status.txing = 0;
 208         /* Pause just a few cycles for the hardware reset to take place. */
 209         SLOW_DOWN_IO;
 210         SLOW_DOWN_IO;
 211 
 212         outb_p(saved_config, hp_base + HP_CONFIGURE);
 213         SLOW_DOWN_IO; SLOW_DOWN_IO;
 214         
 215         if ((inb_p(hp_base+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
 216                 printk("%s: hp_reset_8390() did not complete.\n", dev->name);
 217 
 218         if (ei_debug > 1) printk("8390 reset done (%ld).", jiffies);
 219         return;
 220 }
 221 
 222 /* Block input and output, similar to the Crynwr packet driver.  If you
 223    porting to a new ethercard look at the packet driver source for hints.
 224    The HP LAN doesn't use shared memory -- we put the packet
 225    out through the "remote DMA" dataport. */
 226 
 227 static int
 228 hp_block_input(struct device *dev, int count, char *buf, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 229 {
 230         int nic_base = dev->base_addr;
 231         int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 232         int xfer_count = count;
 233 
 234         outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 235         outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
 236         outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 237         outb_p(count >> 8, nic_base + EN0_RCNTHI);
 238         outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
 239         outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
 240         outb_p(E8390_RREAD+E8390_START, nic_base);
 241         if (ei_status.word16) {
 242           insw(nic_base - NIC_OFFSET + HP_DATAPORT,buf,count>>1);
 243           if (count & 0x01)
 244                 buf[count-1] = inb(nic_base - NIC_OFFSET + HP_DATAPORT), xfer_count++;
 245         } else {
 246                 insb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 247         }
 248         /* This is for the ALPHA version only, remove for later releases. */
 249         if (ei_debug > 0) {                     /* DMA termination address check... */
 250           int high = inb_p(nic_base + EN0_RSARHI);
 251           int low = inb_p(nic_base + EN0_RSARLO);
 252           int addr = (high << 8) + low;
 253           /* Check only the lower 8 bits so we can ignore ring wrap. */
 254           if (((ring_offset + xfer_count) & 0xff) != (addr & 0xff))
 255                 printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
 256                            dev->name, ring_offset + xfer_count, addr);
 257         }
 258         outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 259         return ring_offset + count;
 260 }
 261 
 262 static void
 263 hp_block_output(struct device *dev, int count,
     /* [previous][next][first][last][top][bottom][index][help] */
 264                                 const unsigned char *buf, const start_page)
 265 {
 266         int nic_base = dev->base_addr;
 267         int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 268 
 269         outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 270         /* Round the count up for word writes.  Do we need to do this?
 271            What effect will an odd byte count have on the 8390?
 272            I should check someday. */
 273         if (ei_status.word16 && (count & 0x01))
 274           count++;
 275         /* We should already be in page 0, but to be safe... */
 276         outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base);
 277 
 278         if (ne8390_rw_bugfix) {
 279                 /* Handle the read-before-write bug the same way as the
 280                    Crynwr packet driver -- the NatSemi method doesn't work. */
 281                 outb_p(0x42, nic_base + EN0_RCNTLO);
 282                 outb_p(0,       nic_base + EN0_RCNTHI);
 283                 outb_p(0xff, nic_base + EN0_RSARLO);
 284                 outb_p(0x00, nic_base + EN0_RSARHI);
 285 #define NE_CMD          0x00
 286                 outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
 287                 /* Make certain that the dummy read has occurred. */
 288                 inb_p(0x61);
 289                 inb_p(0x61);
 290         }
 291 
 292         outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 293         outb_p(count >> 8,       nic_base + EN0_RCNTHI);
 294         outb_p(0x00, nic_base + EN0_RSARLO);
 295         outb_p(start_page, nic_base + EN0_RSARHI);
 296 
 297         outb_p(E8390_RWRITE+E8390_START, nic_base);
 298         if (ei_status.word16) {
 299                 /* Use the 'rep' sequence for 16 bit boards. */
 300                 outsw(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count>>1);
 301         } else {
 302                 outsb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 303         }
 304 
 305         /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here -- it's broken! */
 306 
 307         /* This is for the ALPHA version only, remove for later releases. */
 308         if (ei_debug > 0) {                     /* DMA termination address check... */
 309           int high = inb_p(nic_base + EN0_RSARHI);
 310           int low  = inb_p(nic_base + EN0_RSARLO);
 311           int addr = (high << 8) + low;
 312           if ((start_page << 8) + count != addr)
 313                 printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
 314                            dev->name, (start_page << 8) + count, addr);
 315         }
 316         outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 317         return;
 318 }
 319 
 320 /* This function resets the ethercard if something screws up. */
 321 static void
 322 hp_init_card(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 323 {
 324         int irq = dev->irq;
 325         NS8390_init(dev, 0);
 326         outb_p(irqmap[irq&0x0f] | HP_RUN,
 327                    dev->base_addr - NIC_OFFSET + HP_CONFIGURE);
 328         return;
 329 }
 330 
 331 #ifdef MODULE
 332 char kernel_version[] = UTS_RELEASE;
 333 static struct device dev_hp = {
 334         "        " /*"hp"*/, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, hp_probe };
 335 
 336 int io = 0;
 337 int irq = 0;
 338 
 339 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 340 {
 341         dev_hp.base_addr = io;
 342         dev_hp.irq       = irq;
 343         if (register_netdev(&dev_hp) != 0) {
 344                 printk("hp: register_netdev() returned non-zero.\n");
 345                 return -EIO;
 346         }
 347         return 0;
 348 }
 349 
 350 void
 351 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 352 {
 353         if (MOD_IN_USE)
 354                 printk("hp: device busy, remove delayed\n");
 355         else
 356         {
 357                 unregister_netdev(&dev_hp);
 358         }
 359 }
 360 #endif /* MODULE */
 361 
 362 /*
 363  * Local variables:
 364  * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp.c"
 365  * version-control: t
 366  * kept-new-versions: 5
 367  * tab-width: 4
 368  * c-indent-level: 4
 369  * End:
 370  */

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