root/net/inet/hp.c

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

DEFINITIONS

This source file includes following definitions.
  1. hpprobe
  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.12+ 8/12/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 hpprobe(int ioaddr, 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 hpprobe(int ioaddr,  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 
  66     if (ioaddr > 0x100)
  67         return hpprobe1(ioaddr, dev);
  68 
  69     for (port = &ports[0]; *port; port++)
  70         if (inb_p(*port) != 0xff && hpprobe1(*port, dev))
  71             return dev->base_addr;
  72     return 0;
  73 }
  74 
  75 int hpprobe1(int ioaddr, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77   int i;
  78   unsigned char *station_addr = dev->dev_addr;
  79   int tmp;
  80 
  81   /* Check for the HP physical address, 08 00 09 xx xx xx. */
  82   if (inb(ioaddr) != 0x08
  83       || inb(ioaddr+1) != 0x00
  84       || inb(ioaddr+2) != 0x09)
  85       return 0;
  86 
  87   /* Good enough, we will assume everything works. */
  88   ethdev_init(dev);
  89 
  90   ei_status.tx_start_page = HP_START_PG;
  91   ei_status.rx_start_page = HP_START_PG + TX_PAGES;
  92   /* Set up the rest of the parameters. */
  93   if ((tmp = inb(ioaddr + HP_ID)) & 0x80) {
  94       ei_status.name = "HP27247";
  95       ei_status.word16 = 1;
  96       ei_status.stop_page = HP_16BSTOP_PG; /* Safe (if small) value */
  97   } else {
  98       ei_status.name = "HP27250";
  99       ei_status.word16 = 0;
 100       ei_status.stop_page = HP_8BSTOP_PG;
 101   }
 102 
 103   printk("%s: %s at %#3x,", dev->name, ei_status.name, ioaddr);
 104 
 105   for(i = 0; i < ETHER_ADDR_LEN; i++)
 106       printk(" %2.2x", station_addr[i] = inb(ioaddr + i));
 107 
 108 
 109   /* Set the base address to point to the NIC, not the "real" base! */
 110   dev->base_addr = ioaddr + NIC_OFFSET;
 111 
 112   /* Snarf the interrupt now.  Someday this could be moved to open(). */
 113   if (dev->irq < 2) {
 114       int irq_16list[] = { 11, 10, 5, 3, 4, 7, 9, 0};
 115       int irq_8list[] = { 7, 5, 3, 4, 9, 0};
 116       int *irqp = ei_status.word16 ? irq_16list : irq_8list;
 117       do {
 118           if (request_irq (dev->irq = *irqp, NULL) != -EBUSY) {
 119               autoirq_setup(0);
 120               /* Twinkle the interrupt, and check if it's seen. */
 121               outb_p(irqmap[dev->irq] | HP_RUN, ioaddr + HP_CONFIGURE);
 122               outb_p( 0x00 | HP_RUN, ioaddr + HP_CONFIGURE);
 123               if (dev->irq == autoirq_report(0)  /* It's a good IRQ line! */
 124                   && request_irq (dev->irq, &ei_interrupt) == 0) {
 125                   printk(" selecting IRQ %d.\n", dev->irq);
 126                   break;
 127               }
 128           }
 129       } while (*++irqp);
 130       if (*irqp == 0) {
 131           printk(" no free IRQ lines.\n");
 132           return 0;
 133       }
 134   } else {
 135       if (dev->irq == 2)
 136           dev->irq = 9;
 137       if (irqaction(dev->irq, &ei_sigaction)) {
 138           printk (" unable to get IRQ %d.\n", dev->irq);
 139           return 0;
 140       }
 141   }
 142 
 143   if (ei_debug > 1)
 144       printk(version);
 145 
 146   ei_status.reset_8390 = &hp_reset_8390;
 147   ei_status.block_input = &hp_block_input;
 148   ei_status.block_output = &hp_block_output;
 149   hp_init_card(dev);
 150   return dev->base_addr;
 151 }
 152 
 153 static void
 154 hp_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 155 {
 156     int hp_base = dev->base_addr - NIC_OFFSET;
 157     int saved_config = inb_p(hp_base + HP_CONFIGURE);
 158     int reset_start_time = jiffies;
 159 
 160     if (ei_debug > 1) printk("resetting the 8390 time=%d...", jiffies);
 161     outb_p(0x00, hp_base + HP_CONFIGURE);
 162     ei_status.txing = 0;
 163 
 164     sti();
 165     /* We shouldn't use the boguscount for timing, but this hasn't been
 166        checked yet, and you could hang your machine if jiffies break... */
 167     {
 168         int boguscount = 150000;
 169         while(jiffies - reset_start_time < 2)
 170             if (boguscount-- < 0) {
 171                 printk("jiffy failure (t=%d)...", jiffies);
 172                 break;
 173             }
 174     }
 175 
 176     outb_p(saved_config, hp_base + HP_CONFIGURE);
 177     while ((inb_p(hp_base+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
 178         if (jiffies - reset_start_time > 2) {
 179             printk("%s: hp_reset_8390() did not complete.\n", dev->name);
 180             return;
 181         }
 182     if (ei_debug > 1) printk("8390 reset done.", jiffies);
 183 }
 184 
 185 /* Block input and output, similar to the Crynwr packet driver.  If you
 186    porting to a new ethercard look at the packet driver source for hints.
 187    The HP LAN doesn't use shared memory -- we put the packet
 188    out through the "remote DMA" dataport. */
 189 
 190 static int
 191 hp_block_input(struct device *dev, int count, char *buf, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 192 {
 193     int nic_base = dev->base_addr;
 194     int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 195     int xfer_count = count;
 196 
 197     outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 198     outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
 199     outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 200     outb_p(count >> 8, nic_base + EN0_RCNTHI);
 201     outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
 202     outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
 203     outb_p(E8390_RREAD+E8390_START, nic_base);
 204     if (ei_status.word16) {
 205       port_read(nic_base - NIC_OFFSET + HP_DATAPORT,buf,count>>1);
 206       if (count & 0x01)
 207         buf[count-1] = inb(nic_base - NIC_OFFSET + HP_DATAPORT), xfer_count++;
 208     } else {
 209         port_read_b(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 210     }
 211     /* This is for the ALPHA version only, remove for later releases. */
 212     if (ei_debug > 0) {         /* DMA termination address check... */
 213       int high = inb_p(nic_base + EN0_RSARHI);
 214       int low = inb_p(nic_base + EN0_RSARLO);
 215       int addr = (high << 8) + low;
 216       /* Check only the lower 8 bits so we can ignore ring wrap. */
 217       if (((ring_offset + xfer_count) & 0xff) != (addr & 0xff))
 218         printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
 219                dev->name, ring_offset + xfer_count, addr);
 220     }
 221     outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 222     return ring_offset + count;
 223 }
 224 
 225 static void
 226 hp_block_output(struct device *dev, int count,
     /* [previous][next][first][last][top][bottom][index][help] */
 227                 const unsigned char *buf, const start_page)
 228 {
 229     int nic_base = dev->base_addr;
 230     int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 231 
 232     outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 233     /* Round the count up for word writes.  Do we need to do this?
 234        What effect will an odd byte count have on the 8390?
 235        I should check someday. */
 236     if (ei_status.word16 && (count & 0x01))
 237       count++;
 238     /* We should already be in page 0, but to be safe... */
 239     outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base);
 240 
 241 #ifdef ei8390_bug
 242     /* Handle the read-before-write bug the same way as the
 243        Crynwr packet driver -- the NatSemi method doesn't work. */
 244     outb_p(0x42, nic_base + EN0_RCNTLO);
 245     outb_p(0,   nic_base + EN0_RCNTHI);
 246     outb_p(0xff, nic_base + EN0_RSARLO);
 247     outb_p(0x00, nic_base + EN0_RSARHI);
 248     outb_p(E8390_RREAD+E8390_START, EN_CMD);
 249     /* Make certain that the dummy read has occured. */
 250     inb_p(0x61);
 251     inb_p(0x61);
 252 #endif
 253 
 254     outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 255     outb_p(count >> 8,   nic_base + EN0_RCNTHI);
 256     outb_p(0x00, nic_base + EN0_RSARLO);
 257     outb_p(start_page, nic_base + EN0_RSARHI);
 258 
 259     outb_p(E8390_RWRITE+E8390_START, nic_base);
 260     if (ei_status.word16) {
 261         /* Use the 'rep' sequence for 16 bit boards. */
 262         port_write(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count>>1);
 263     } else {
 264         port_write_b(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 265     }
 266 
 267     /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here -- it's broken! */
 268 
 269     /* This is for the ALPHA version only, remove for later releases. */
 270     if (ei_debug > 0) {         /* DMA termination address check... */
 271       int high = inb_p(nic_base + EN0_RSARHI);
 272       int low  = inb_p(nic_base + EN0_RSARLO);
 273       int addr = (high << 8) + low;
 274       if ((start_page << 8) + count != addr)
 275         printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
 276                dev->name, (start_page << 8) + count, addr);
 277     }
 278     outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 279     return;
 280 }
 281 
 282 /* This function resets the ethercard if something screws up. */
 283 static void
 284 hp_init_card(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 285 {
 286     int irq = dev->irq;
 287     NS8390_init(dev, 0);
 288     outb_p(irqmap[irq&0x0f] | HP_RUN,
 289            dev->base_addr - NIC_OFFSET + HP_CONFIGURE);
 290     return;
 291 }
 292 
 293 
 294 /*
 295  * Local variables:
 296  *  compile-command: "gcc -DKERNEL -Wall -O6 -fomit-frame-pointer -I/usr/src/linux/net/tcp -c hp.c"
 297  *  version-control: t
 298  *  kept-new-versions: 5
 299  * End:
 300  */

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