root/drivers/net/hp.c

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

DEFINITIONS

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

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