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

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