root/net/inet/hp.c

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

DEFINITIONS

This source file includes following definitions.
  1. hp_probe
  2. hpprobe1
  3. hp_reset_8390
  4. hp_block_input
  5. hp_block_output
  6. hp_init_card

   1 /* hp.c: A HP LAN ethernet driver for linux. */
   2 /*
   3     Written 1993 by Donald Becker.
   4     Copyright 1993 United States Government as represented by the
   5     Director, National Security Agency.  This software may be used and
   6     distributed according to the terms of the GNU Public License,
   7     incorporated herein by reference.
   8 
   9     This is a driver for the HP LAN adaptors.
  10 
  11     The Author may be reached as becker@super.org or
  12     C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
  13 */
  14 
  15 static char *version =
  16     "hp.c:v0.99.13 8/30/93 Donald Becker (becker@super.org)\n";
  17 
  18 #include <linux/config.h>
  19 #include <linux/kernel.h>
  20 #include <linux/sched.h>
  21 #include <linux/errno.h>
  22 #include <asm/system.h>
  23 #include <asm/io.h>
  24 #ifndef port_read
  25 #include "iow.h"
  26 #endif
  27 
  28 #include "dev.h"
  29 #include "8390.h"
  30 
  31 #define HP_DATAPORT     0x0c    /* "Remote DMA" data port. */
  32 #define HP_ID           0x07
  33 #define HP_CONFIGURE    0x08    /* Configuration register. */
  34 #define  HP_RUN         0x01    /* 1 == Run, 0 == reset. */
  35 #define  HP_IRQ         0x0E    /* Mask for software-configured IRQ line. */
  36 #define  HP_DATAON      0x10    /* Turn on dataport */
  37 #define NIC_OFFSET      0x10    /* Offset the 8390 registers. */
  38 
  39 #define HP_START_PG     0x00    /* First page of TX buffer */
  40 #define HP_8BSTOP_PG    0x80    /* Last page +1 of RX ring */
  41 #define HP_16BSTOP_PG   0xFF    /* Last page +1 of RX ring */
  42 
  43 int hp_probe(struct device *dev);
  44 int hpprobe1(int ioaddr, struct device *dev);
  45 
  46 static void hp_reset_8390(struct device *dev);
  47 static int hp_block_input(struct device *dev, int count,
  48                           char *buf, int ring_offset);
  49 static void hp_block_output(struct device *dev, int count,
  50                             const unsigned char *buf, const start_page);
  51 static void hp_init_card(struct device *dev);
  52 
  53 /* The map from IRQ number to HP_CONFIGURE register setting. */
  54 /* My default is IRQ5      0  1  2  3  4  5  6  7  8  9 10 11 */
  55 static char irqmap[16] = { 0, 0, 4, 6, 8,10, 0,14, 0, 4, 2,12,0,0,0,0};
  56 
  57 
  58 /*  Probe for an HP LAN adaptor.
  59     Also initialize the card and fill in STATION_ADDR with the station
  60    address. */
  61 
  62 int hp_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  63 {
  64     int *port, ports[] = {0x300, 0x320, 0x340, 0x280, 0x2C0, 0x200, 0x240, 0};
  65     short ioaddr = dev->base_addr;
  66 
  67     if (ioaddr < 0)
  68         return ENXIO;           /* Don't probe at all. */
  69     if (ioaddr > 0x100)
  70         return ! hpprobe1(ioaddr, dev);
  71 
  72     for (port = &ports[0]; *port; port++) {
  73 #ifdef HAVE_PORTRESERVE
  74         if (check_region(*port, 32))
  75             continue;
  76 #endif
  77         if (inb_p(*port) != 0xff && hpprobe1(*port, dev)) {
  78             return 0;
  79         }
  80     }
  81     dev->base_addr = ioaddr;
  82     return ENODEV;
  83 }
  84 
  85 int hpprobe1(int ioaddr, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  86 {
  87   int i;
  88   unsigned char *station_addr = dev->dev_addr;
  89   int tmp;
  90 
  91   /* Check for the HP physical address, 08 00 09 xx xx xx. */
  92   if (inb(ioaddr) != 0x08
  93       || inb(ioaddr+1) != 0x00
  94       || inb(ioaddr+2) != 0x09)
  95       return 0;
  96 
  97   /* Good enough, we will assume everything works. */
  98   ethdev_init(dev);
  99 
 100   ei_status.tx_start_page = HP_START_PG;
 101   ei_status.rx_start_page = HP_START_PG + TX_PAGES;
 102   /* Set up the rest of the parameters. */
 103   if ((tmp = inb(ioaddr + HP_ID)) & 0x80) {
 104       ei_status.name = "HP27247";
 105       ei_status.word16 = 1;
 106       ei_status.stop_page = HP_16BSTOP_PG; /* Safe (if small) value */
 107   } else {
 108       ei_status.name = "HP27250";
 109       ei_status.word16 = 0;
 110       ei_status.stop_page = HP_8BSTOP_PG;
 111   }
 112 
 113   printk("%s: %s at %#3x,", dev->name, ei_status.name, ioaddr);
 114 
 115   for(i = 0; i < ETHER_ADDR_LEN; i++)
 116       printk(" %2.2x", station_addr[i] = inb(ioaddr + i));
 117 
 118 
 119   /* Set the base address to point to the NIC, not the "real" base! */
 120   dev->base_addr = ioaddr + NIC_OFFSET;
 121 
 122   /* Snarf the interrupt now.  Someday this could be moved to open(). */
 123   if (dev->irq < 2) {
 124       int irq_16list[] = { 11, 10, 5, 3, 4, 7, 9, 0};
 125       int irq_8list[] = { 7, 5, 3, 4, 9, 0};
 126       int *irqp = ei_status.word16 ? irq_16list : irq_8list;
 127       do {
 128           if (request_irq (dev->irq = *irqp, NULL) != -EBUSY) {
 129               autoirq_setup(0);
 130               /* Twinkle the interrupt, and check if it's seen. */
 131               outb_p(irqmap[dev->irq] | HP_RUN, ioaddr + HP_CONFIGURE);
 132               outb_p( 0x00 | HP_RUN, ioaddr + HP_CONFIGURE);
 133               if (dev->irq == autoirq_report(0)  /* It's a good IRQ line! */
 134                   && request_irq (dev->irq, &ei_interrupt) == 0) {
 135                   printk(" selecting IRQ %d.\n", dev->irq);
 136                   break;
 137               }
 138           }
 139       } while (*++irqp);
 140       if (*irqp == 0) {
 141           printk(" no free IRQ lines.\n");
 142           return 0;
 143       }
 144   } else {
 145       if (dev->irq == 2)
 146           dev->irq = 9;
 147       if (irqaction(dev->irq, &ei_sigaction)) {
 148           printk (" unable to get IRQ %d.\n", dev->irq);
 149           return 0;
 150       }
 151   }
 152 
 153 #ifdef HAVE_PORTRESERVE
 154     snarf_region(ioaddr, 32);
 155 #endif
 156 
 157   if (ei_debug > 1)
 158       printk(version);
 159 
 160   ei_status.reset_8390 = &hp_reset_8390;
 161   ei_status.block_input = &hp_block_input;
 162   ei_status.block_output = &hp_block_output;
 163   hp_init_card(dev);
 164   return dev->base_addr;
 165 }
 166 
 167 static void
 168 hp_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 169 {
 170     int hp_base = dev->base_addr - NIC_OFFSET;
 171     int saved_config = inb_p(hp_base + HP_CONFIGURE);
 172     int reset_start_time = jiffies;
 173 
 174     if (ei_debug > 1) printk("resetting the 8390 time=%d...", jiffies);
 175     outb_p(0x00, hp_base + HP_CONFIGURE);
 176     ei_status.txing = 0;
 177 
 178     sti();
 179     /* We shouldn't use the boguscount for timing, but this hasn't been
 180        checked yet, and you could hang your machine if jiffies break... */
 181     {
 182         int boguscount = 150000;
 183         while(jiffies - reset_start_time < 2)
 184             if (boguscount-- < 0) {
 185                 printk("jiffy failure (t=%d)...", jiffies);
 186                 break;
 187             }
 188     }
 189 
 190     outb_p(saved_config, hp_base + HP_CONFIGURE);
 191     while ((inb_p(hp_base+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
 192         if (jiffies - reset_start_time > 2) {
 193             printk("%s: hp_reset_8390() did not complete.\n", dev->name);
 194             return;
 195         }
 196     if (ei_debug > 1) printk("8390 reset done (%d).", jiffies);
 197 }
 198 
 199 /* Block input and output, similar to the Crynwr packet driver.  If you
 200    porting to a new ethercard look at the packet driver source for hints.
 201    The HP LAN doesn't use shared memory -- we put the packet
 202    out through the "remote DMA" dataport. */
 203 
 204 static int
 205 hp_block_input(struct device *dev, int count, char *buf, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 206 {
 207     int nic_base = dev->base_addr;
 208     int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 209     int xfer_count = count;
 210 
 211     outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 212     outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
 213     outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 214     outb_p(count >> 8, nic_base + EN0_RCNTHI);
 215     outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
 216     outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
 217     outb_p(E8390_RREAD+E8390_START, nic_base);
 218     if (ei_status.word16) {
 219       port_read(nic_base - NIC_OFFSET + HP_DATAPORT,buf,count>>1);
 220       if (count & 0x01)
 221         buf[count-1] = inb(nic_base - NIC_OFFSET + HP_DATAPORT), xfer_count++;
 222     } else {
 223         port_read_b(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 224     }
 225     /* This is for the ALPHA version only, remove for later releases. */
 226     if (ei_debug > 0) {         /* DMA termination address check... */
 227       int high = inb_p(nic_base + EN0_RSARHI);
 228       int low = inb_p(nic_base + EN0_RSARLO);
 229       int addr = (high << 8) + low;
 230       /* Check only the lower 8 bits so we can ignore ring wrap. */
 231       if (((ring_offset + xfer_count) & 0xff) != (addr & 0xff))
 232         printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
 233                dev->name, ring_offset + xfer_count, addr);
 234     }
 235     outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 236     return ring_offset + count;
 237 }
 238 
 239 static void
 240 hp_block_output(struct device *dev, int count,
     /* [previous][next][first][last][top][bottom][index][help] */
 241                 const unsigned char *buf, const start_page)
 242 {
 243     int nic_base = dev->base_addr;
 244     int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 245 
 246     outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 247     /* Round the count up for word writes.  Do we need to do this?
 248        What effect will an odd byte count have on the 8390?
 249        I should check someday. */
 250     if (ei_status.word16 && (count & 0x01))
 251       count++;
 252     /* We should already be in page 0, but to be safe... */
 253     outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base);
 254 
 255 #ifdef ei8390_bug
 256     /* Handle the read-before-write bug the same way as the
 257        Crynwr packet driver -- the NatSemi method doesn't work. */
 258     outb_p(0x42, nic_base + EN0_RCNTLO);
 259     outb_p(0,   nic_base + EN0_RCNTHI);
 260     outb_p(0xff, nic_base + EN0_RSARLO);
 261     outb_p(0x00, nic_base + EN0_RSARHI);
 262     outb_p(E8390_RREAD+E8390_START, EN_CMD);
 263     /* Make certain that the dummy read has occured. */
 264     inb_p(0x61);
 265     inb_p(0x61);
 266 #endif
 267 
 268     outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 269     outb_p(count >> 8,   nic_base + EN0_RCNTHI);
 270     outb_p(0x00, nic_base + EN0_RSARLO);
 271     outb_p(start_page, nic_base + EN0_RSARHI);
 272 
 273     outb_p(E8390_RWRITE+E8390_START, nic_base);
 274     if (ei_status.word16) {
 275         /* Use the 'rep' sequence for 16 bit boards. */
 276         port_write(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count>>1);
 277     } else {
 278         port_write_b(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 279     }
 280 
 281     /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here -- it's broken! */
 282 
 283     /* This is for the ALPHA version only, remove for later releases. */
 284     if (ei_debug > 0) {         /* DMA termination address check... */
 285       int high = inb_p(nic_base + EN0_RSARHI);
 286       int low  = inb_p(nic_base + EN0_RSARLO);
 287       int addr = (high << 8) + low;
 288       if ((start_page << 8) + count != addr)
 289         printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
 290                dev->name, (start_page << 8) + count, addr);
 291     }
 292     outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 293     return;
 294 }
 295 
 296 /* This function resets the ethercard if something screws up. */
 297 static void
 298 hp_init_card(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 299 {
 300     int irq = dev->irq;
 301     NS8390_init(dev, 0);
 302     outb_p(irqmap[irq&0x0f] | HP_RUN,
 303            dev->base_addr - NIC_OFFSET + HP_CONFIGURE);
 304     return;
 305 }
 306 
 307 
 308 /*
 309  * Local variables:
 310  *  compile-command: "gcc -DKERNEL -Wall -O6 -fomit-frame-pointer -I/usr/src/linux/net/tcp -c hp.c"
 311  *  version-control: t
 312  *  kept-new-versions: 5
 313  * End:
 314  */

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