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

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