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

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