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
  7. init_module
  8. cleanup_module

   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 const char *version =
  22         "hp.c:v1.10 9/23/94 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
  23 
  24 
  25 #ifdef MODULE
  26 #include <linux/module.h>
  27 #include <linux/version.h>
  28 #endif
  29 
  30 #include <linux/kernel.h>
  31 #include <linux/sched.h>
  32 #include <linux/errno.h>
  33 #include <linux/ioport.h>
  34 #include <asm/system.h>
  35 #include <asm/io.h>
  36 
  37 #include <linux/netdevice.h>
  38 #include <linux/etherdevice.h>
  39 #include "8390.h"
  40 
  41 /* A zero-terminated list of I/O addresses to be probed. */
  42 static unsigned int hppclan_portlist[] =
  43 { 0x300, 0x320, 0x340, 0x280, 0x2C0, 0x200, 0x240, 0};
  44 
  45 #define HP_IO_EXTENT    32
  46 
  47 #define HP_DATAPORT             0x0c    /* "Remote DMA" data port. */
  48 #define HP_ID                   0x07
  49 #define HP_CONFIGURE    0x08    /* Configuration register. */
  50 #define  HP_RUN                 0x01    /* 1 == Run, 0 == reset. */
  51 #define  HP_IRQ                 0x0E    /* Mask for software-configured IRQ line. */
  52 #define  HP_DATAON              0x10    /* Turn on dataport */
  53 #define NIC_OFFSET              0x10    /* Offset the 8390 registers. */
  54 
  55 #define HP_START_PG             0x00    /* First page of TX buffer */
  56 #define HP_8BSTOP_PG    0x80    /* Last page +1 of RX ring */
  57 #define HP_16BSTOP_PG   0xFF    /* Same, for 16 bit cards. */
  58 
  59 int hp_probe(struct device *dev);
  60 int hp_probe1(struct device *dev, int ioaddr);
  61 
  62 static void hp_reset_8390(struct device *dev);
  63 static int hp_block_input(struct device *dev, int count,
  64                                                   char *buf, int ring_offset);
  65 static void hp_block_output(struct device *dev, int count,
  66                                                         const unsigned char *buf, const start_page);
  67 static void hp_init_card(struct device *dev);
  68 
  69 /* The map from IRQ number to HP_CONFIGURE register setting. */
  70 /* My default is IRQ5      0  1  2  3  4  5  6  7  8  9 10 11 */
  71 static char irqmap[16] = { 0, 0, 4, 6, 8,10, 0,14, 0, 4, 2,12,0,0,0,0};
  72 
  73 
  74 /*      Probe for an HP LAN adaptor.
  75         Also initialize the card and fill in STATION_ADDR with the station
  76         address. */
  77 #ifdef HAVE_DEVLIST
  78 struct netdev_entry netcard_drv =
  79 {"hp", hp_probe1, HP_IO_EXTENT, hppclan_portlist};
  80 #else
  81 
  82 int hp_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84         int i;
  85         int base_addr = dev ? dev->base_addr : 0;
  86 
  87         if (base_addr > 0x1ff)          /* Check a single specified location. */
  88                 return hp_probe1(dev, base_addr);
  89         else if (base_addr != 0)        /* Don't probe at all. */
  90                 return ENXIO;
  91 
  92         for (i = 0; hppclan_portlist[i]; i++) {
  93                 int ioaddr = hppclan_portlist[i];
  94                 if (check_region(ioaddr, HP_IO_EXTENT))
  95                         continue;
  96                 if (hp_probe1(dev, ioaddr) == 0)
  97                         return 0;
  98         }
  99 
 100         return ENODEV;
 101 }
 102 #endif
 103 
 104 int hp_probe1(struct device *dev, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 105 {
 106         int i, board_id, wordmode;
 107         const char *name;
 108 
 109         /* Check for the HP physical address, 08 00 09 xx xx xx. */
 110         /* This really isn't good enough: we may pick up HP LANCE boards
 111            also!  Avoid the lance 0x5757 signature. */
 112         if (inb(ioaddr) != 0x08
 113                 || inb(ioaddr+1) != 0x00
 114                 || inb(ioaddr+2) != 0x09
 115                 || inb(ioaddr+14) == 0x57)
 116                 return ENODEV;
 117 
 118         /* Set up the parameters based on the board ID.
 119            If you have additional mappings, please mail them to me -djb. */
 120         if ((board_id = inb(ioaddr + HP_ID)) & 0x80) {
 121                 name = "HP27247";
 122                 wordmode = 1;
 123         } else {
 124                 name = "HP27250";
 125                 wordmode = 0;
 126         }
 127 
 128         if (dev == NULL)
 129                 dev = init_etherdev(0, sizeof(struct ei_device), 0);
 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         /* Grab the region so we can find another board if something fails. */
 170         request_region(ioaddr, HP_IO_EXTENT,"hp");
 171 
 172         if (ei_debug > 1)
 173                 printk(version);
 174 
 175         /* Set the base address to point to the NIC, not the "real" base! */
 176         dev->base_addr = ioaddr + NIC_OFFSET;
 177 
 178         ethdev_init(dev);
 179 
 180         ei_status.name = name;
 181         ei_status.word16 = wordmode;
 182         ei_status.tx_start_page = HP_START_PG;
 183         ei_status.rx_start_page = HP_START_PG + TX_PAGES;
 184         ei_status.stop_page = wordmode ? HP_16BSTOP_PG : HP_8BSTOP_PG;
 185 
 186         ei_status.reset_8390 = &hp_reset_8390;
 187         ei_status.block_input = &hp_block_input;
 188         ei_status.block_output = &hp_block_output;
 189         hp_init_card(dev);
 190 
 191         return 0;
 192 }
 193 
 194 static void
 195 hp_reset_8390(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 196 {
 197         int hp_base = dev->base_addr - NIC_OFFSET;
 198         int saved_config = inb_p(hp_base + HP_CONFIGURE);
 199 
 200         if (ei_debug > 1) printk("resetting the 8390 time=%ld...", jiffies);
 201         outb_p(0x00, hp_base + HP_CONFIGURE);
 202         ei_status.txing = 0;
 203         /* Pause just a few cycles for the hardware reset to take place. */
 204         SLOW_DOWN_IO;
 205         SLOW_DOWN_IO;
 206 
 207         outb_p(saved_config, hp_base + HP_CONFIGURE);
 208         SLOW_DOWN_IO; SLOW_DOWN_IO;
 209         
 210         if ((inb_p(hp_base+NIC_OFFSET+EN0_ISR) & ENISR_RESET) == 0)
 211                 printk("%s: hp_reset_8390() did not complete.\n", dev->name);
 212 
 213         if (ei_debug > 1) printk("8390 reset done (%ld).", jiffies);
 214         return;
 215 }
 216 
 217 /* Block input and output, similar to the Crynwr packet driver.  If you
 218    porting to a new ethercard look at the packet driver source for hints.
 219    The HP LAN doesn't use shared memory -- we put the packet
 220    out through the "remote DMA" dataport. */
 221 
 222 static int
 223 hp_block_input(struct device *dev, int count, char *buf, int ring_offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 224 {
 225         int nic_base = dev->base_addr;
 226         int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 227         int xfer_count = count;
 228 
 229         outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 230         outb_p(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base);
 231         outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 232         outb_p(count >> 8, nic_base + EN0_RCNTHI);
 233         outb_p(ring_offset & 0xff, nic_base + EN0_RSARLO);
 234         outb_p(ring_offset >> 8, nic_base + EN0_RSARHI);
 235         outb_p(E8390_RREAD+E8390_START, nic_base);
 236         if (ei_status.word16) {
 237           insw(nic_base - NIC_OFFSET + HP_DATAPORT,buf,count>>1);
 238           if (count & 0x01)
 239                 buf[count-1] = inb(nic_base - NIC_OFFSET + HP_DATAPORT), xfer_count++;
 240         } else {
 241                 insb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 242         }
 243         /* This is for the ALPHA version only, remove for later releases. */
 244         if (ei_debug > 0) {                     /* DMA termination address check... */
 245           int high = inb_p(nic_base + EN0_RSARHI);
 246           int low = inb_p(nic_base + EN0_RSARLO);
 247           int addr = (high << 8) + low;
 248           /* Check only the lower 8 bits so we can ignore ring wrap. */
 249           if (((ring_offset + xfer_count) & 0xff) != (addr & 0xff))
 250                 printk("%s: RX transfer address mismatch, %#4.4x vs. %#4.4x (actual).\n",
 251                            dev->name, ring_offset + xfer_count, addr);
 252         }
 253         outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 254         return ring_offset + count;
 255 }
 256 
 257 static void
 258 hp_block_output(struct device *dev, int count,
     /* [previous][next][first][last][top][bottom][index][help] */
 259                                 const unsigned char *buf, const start_page)
 260 {
 261         int nic_base = dev->base_addr;
 262         int saved_config = inb_p(nic_base - NIC_OFFSET + HP_CONFIGURE);
 263 
 264         outb_p(saved_config | HP_DATAON, nic_base - NIC_OFFSET + HP_CONFIGURE);
 265         /* Round the count up for word writes.  Do we need to do this?
 266            What effect will an odd byte count have on the 8390?
 267            I should check someday. */
 268         if (ei_status.word16 && (count & 0x01))
 269           count++;
 270         /* We should already be in page 0, but to be safe... */
 271         outb_p(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base);
 272 
 273 #ifdef NE8390_RW_BUGFIX
 274         /* Handle the read-before-write bug the same way as the
 275            Crynwr packet driver -- the NatSemi method doesn't work. */
 276         outb_p(0x42, nic_base + EN0_RCNTLO);
 277         outb_p(0,       nic_base + EN0_RCNTHI);
 278         outb_p(0xff, nic_base + EN0_RSARLO);
 279         outb_p(0x00, nic_base + EN0_RSARHI);
 280 #define NE_CMD          0x00
 281         outb_p(E8390_RREAD+E8390_START, nic_base + NE_CMD);
 282         /* Make certain that the dummy read has occurred. */
 283         inb_p(0x61);
 284         inb_p(0x61);
 285 #endif
 286 
 287         outb_p(count & 0xff, nic_base + EN0_RCNTLO);
 288         outb_p(count >> 8,       nic_base + EN0_RCNTHI);
 289         outb_p(0x00, nic_base + EN0_RSARLO);
 290         outb_p(start_page, nic_base + EN0_RSARHI);
 291 
 292         outb_p(E8390_RWRITE+E8390_START, nic_base);
 293         if (ei_status.word16) {
 294                 /* Use the 'rep' sequence for 16 bit boards. */
 295                 outsw(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count>>1);
 296         } else {
 297                 outsb(nic_base - NIC_OFFSET + HP_DATAPORT, buf, count);
 298         }
 299 
 300         /* DON'T check for 'inb_p(EN0_ISR) & ENISR_RDC' here -- it's broken! */
 301 
 302         /* This is for the ALPHA version only, remove for later releases. */
 303         if (ei_debug > 0) {                     /* DMA termination address check... */
 304           int high = inb_p(nic_base + EN0_RSARHI);
 305           int low  = inb_p(nic_base + EN0_RSARLO);
 306           int addr = (high << 8) + low;
 307           if ((start_page << 8) + count != addr)
 308                 printk("%s: TX Transfer address mismatch, %#4.4x vs. %#4.4x.\n",
 309                            dev->name, (start_page << 8) + count, addr);
 310         }
 311         outb_p(saved_config & (~HP_DATAON), nic_base - NIC_OFFSET + HP_CONFIGURE);
 312         return;
 313 }
 314 
 315 /* This function resets the ethercard if something screws up. */
 316 static void
 317 hp_init_card(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 318 {
 319         int irq = dev->irq;
 320         NS8390_init(dev, 0);
 321         outb_p(irqmap[irq&0x0f] | HP_RUN,
 322                    dev->base_addr - NIC_OFFSET + HP_CONFIGURE);
 323         return;
 324 }
 325 
 326 #ifdef MODULE
 327 char kernel_version[] = UTS_RELEASE;
 328 static char devicename[9] = { 0, };
 329 static struct device dev_hp = {
 330         devicename, /* device name is inserted by linux/drivers/net/net_init.c */
 331         0, 0, 0, 0,
 332         0, 0,
 333         0, 0, 0, NULL, hp_probe };
 334 
 335 int io = 300;
 336 int irq = 0;
 337 
 338 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 339 {
 340         if (io == 0)
 341                 printk("hp: You should not use auto-probing with insmod!\n");
 342         dev_hp.base_addr = io;
 343         dev_hp.irq       = irq;
 344         if (register_netdev(&dev_hp) != 0) {
 345                 printk("hp: register_netdev() returned non-zero.\n");
 346                 return -EIO;
 347         }
 348         return 0;
 349 }
 350 
 351 void
 352 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 353 {
 354         if (MOD_IN_USE)
 355                 printk("hp: device busy, remove delayed\n");
 356         else
 357         {
 358                 int ioaddr = dev_hp.base_addr - NIC_OFFSET;
 359 
 360                 unregister_netdev(&dev_hp);
 361 
 362                 /* If we don't do this, we can't re-insmod it later. */
 363                 free_irq(dev_hp.irq);
 364                 release_region(ioaddr, HP_IO_EXTENT);
 365         }
 366 }
 367 #endif /* MODULE */
 368 
 369 /*
 370  * Local variables:
 371  * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c hp.c"
 372  * version-control: t
 373  * kept-new-versions: 5
 374  * tab-width: 4
 375  * c-indent-level: 4
 376  * End:
 377  */

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