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

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