root/drivers/net/at1700.c

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

DEFINITIONS

This source file includes following definitions.
  1. at1700_probe
  2. at1700_probe1
  3. read_eeprom
  4. net_open
  5. net_send_packet
  6. net_interrupt
  7. net_rx
  8. net_close
  9. net_get_stats
  10. set_multicast_list

   1 /* at1700.c: A network device driver for  the Allied Telesis AT1700.
   2 
   3    Written 1993 by Donald Becker.  This is a alpha test limited release.
   4    This version may only be used and distributed according to the terms of the
   5    GNU Public License, incorporated herein by reference.
   6 
   7    The author may be reached as becker@super.org or
   8    C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
   9 
  10    This is a device driver for the Allied Telesis AT1700, which is a
  11    straight-foward Fujitsu MB86965 implementation.
  12 */
  13 
  14 static char *version =
  15         "at1700.c:v0.03 11/16/93  Donald Becker (becker@super.org)\n";
  16 
  17 #include <linux/config.h>
  18 
  19 /*
  20   Sources:
  21     The Fujitsu MB86695 datasheet.
  22 */
  23 
  24 #include <linux/kernel.h>
  25 #include <linux/sched.h>
  26 #include <linux/types.h>
  27 #include <linux/fcntl.h>
  28 #include <linux/interrupt.h>
  29 #include <linux/ptrace.h>
  30 #include <linux/ioport.h>
  31 #include <linux/in.h>
  32 #include <linux/malloc.h>
  33 #include <asm/system.h>
  34 #include <asm/bitops.h>
  35 #include <asm/io.h>
  36 #include <asm/dma.h>
  37 #include <errno.h>
  38 #include <memory.h>
  39 
  40 #include "dev.h"
  41 #include "iow.h"
  42 #include "eth.h"
  43 #include "skbuff.h"
  44 #include "arp.h"
  45 
  46 #ifndef HAVE_AUTOIRQ
  47 /* From auto_irq.c, in ioport.h for later versions. */
  48 extern void autoirq_setup(int waittime);
  49 extern int autoirq_report(int waittime);
  50 /* The map from IRQ number (as passed to the interrupt handler) to
  51    'struct device'. */
  52 extern struct device *irq2dev_map[16];
  53 #endif
  54 
  55 #ifndef HAVE_ALLOC_SKB
  56 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
  57 #define kfree_skbmem(addr, size) kfree_s(addr,size);
  58 #endif
  59 
  60 /* use 0 for production, 1 for verification, >2 for debug */
  61 #ifndef NET_DEBUG
  62 #define NET_DEBUG 2
  63 #endif
  64 static unsigned int net_debug = NET_DEBUG;
  65 
  66 typedef unsigned char uchar;
  67 
  68 /* Information that need to be kept for each board. */
  69 struct net_local {
  70         struct enet_statistics stats;
  71         long open_time;                         /* Useless example local info. */
  72         uint tx_started:1;                      /* Number of packet on the Tx queue. */
  73         uchar tx_queue;                         /* Number of packet on the Tx queue. */
  74         ushort tx_queue_len;            /* Current length of the Tx queue. */
  75 };
  76 
  77 
  78 /* Offsets from the base address. */
  79 #define STATUS                  0
  80 #define TX_STATUS               0
  81 #define RX_STATUS               1
  82 #define TX_INTR                 2               /* Bit-mapped interrupt enable registers. */
  83 #define RX_INTR                 3
  84 #define TX_MODE                 4
  85 #define RX_MODE                 5
  86 #define CONFIG_0                6               /* Misc. configuration settings. */
  87 #define CONFIG_1                7
  88 /* Run-time register bank 2 definitions. */
  89 #define DATAPORT                8               /* Word-wide DMA or programmed-I/O dataport. */
  90 #define TX_START                10
  91 #define MODE13                  13
  92 #define EEPROM_Ctrl     16
  93 #define EEPROM_Data     17
  94 
  95 /*  EEPROM_Ctrl bits. */
  96 #define EE_SHIFT_CLK    0x40    /* EEPROM shift clock, in reg. 16. */
  97 #define EE_CS                   0x20    /* EEPROM chip select, in reg. 16. */
  98 #define EE_DATA_WRITE   0x80    /* EEPROM chip data in, in reg. 17. */
  99 #define EE_DATA_READ    0x80    /* EEPROM chip data out, in reg. 17. */
 100 
 101 /* Delay between EEPROM clock transitions. */
 102 #define eeprom_delay()  do { int _i = 40; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
 103 
 104 /* The EEPROM commands include the alway-set leading bit. */
 105 #define EE_WRITE_CMD    (5 << 6)
 106 #define EE_READ_CMD             (6 << 6)
 107 #define EE_ERASE_CMD    (7 << 6)
 108 
 109 
 110 /* Index to functions, as function prototypes. */
 111 
 112 extern int at1700_probe(struct device *dev);
 113 
 114 static int at1700_probe1(struct device *dev, short ioaddr);
 115 static int read_eeprom(int ioaddr, int location);
 116 static int net_open(struct device *dev);
 117 static int      net_send_packet(struct sk_buff *skb, struct device *dev);
 118 static void net_interrupt(int reg_ptr);
 119 static void net_rx(struct device *dev);
 120 static int net_close(struct device *dev);
 121 static struct enet_statistics *net_get_stats(struct device *dev);
 122 #ifdef HAVE_MULTICAST
 123 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 124 #endif
 125 
 126 
 127 /* Check for a network adaptor of this type, and return '0' iff one exists.
 128    If dev->base_addr == 0, probe all likely locations.
 129    If dev->base_addr == 1, always return failure.
 130    If dev->base_addr == 2, alloate space for the device and return success
 131    (detachable devices only).
 132    */
 133 int
 134 at1700_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 135 {
 136         short ports[] = {0x300, 0x280, 0x380, 0x320, 0x340, 0x260, 0x2a0, 0x240, 0};
 137         short *port, base_addr = dev->base_addr;
 138 
 139         if (base_addr > 0x1ff)          /* Check a single specified location. */
 140                 return at1700_probe1(dev, base_addr);
 141         else if (base_addr > 0)         /* Don't probe at all. */
 142                 return ENXIO;
 143 
 144         for (port = &ports[0]; *port; port++) {
 145                 int ioaddr = *port;
 146 #ifdef HAVE_PORTRESERVE
 147                 if (check_region(ioaddr, 32))
 148                         continue;
 149 #endif
 150                 if (inw(ioaddr) != 0x0000)
 151                         continue;
 152                 if (at1700_probe1(dev, ioaddr) == 0)
 153                         return 0;
 154         }
 155 
 156         return ENODEV;                  /* ENODEV would be more accurate. */
 157 }
 158 
 159 int at1700_probe1(struct device *dev, short ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161         unsigned short signature[4]         = {0x0000, 0xffff, 0x41f6, 0xefb6};
 162         unsigned short signature_invalid[4] = {0x0000, 0xffff, 0x00f0, 0x2f00};
 163         char irqmap[4] = {3, 4, 5, 9};
 164         unsigned short *station_address = (unsigned short *)dev->dev_addr;
 165         unsigned int i, irq;
 166 
 167         /* Resetting the chip doesn't reset the ISA interface, so don't bother.
 168            That means we have to be careful with the register values we probe for.
 169            */
 170         for (i = 0; i < 4; i++)
 171                 if ((inw(ioaddr + 2*i) | signature_invalid[i]) != signature[i]) {
 172                         if (net_debug > 1)
 173                                 printk("AT1700 signature match failed at %d (%04x vs. %04x)\n",
 174                                            i, inw(ioaddr + 2*i), signature[i]);
 175                         return -ENODEV;
 176                 }
 177 #ifdef HAVE_PORTRESERVE
 178         /* Grab the region so that we can find another board if the IRQ request
 179            fails. */
 180         snarf_region(ioaddr, 32);
 181 #endif
 182 
 183         irq = irqmap[ read_eeprom(ioaddr, 0) >> 14 ];
 184 
 185         /* Snarf the interrupt vector now. */
 186         if (request_irq(irq, &net_interrupt)) {
 187                 printk ("AT1700 found at %#3x, but it's unusable due to a conflict on"
 188                                 "IRQ %d.\n", ioaddr, irq);
 189                 return EAGAIN;
 190         }
 191 
 192         printk("%s: AT1700 found at %#3x, IRQ %d, address ", dev->name,
 193                    ioaddr, irq);
 194 
 195         dev->base_addr = ioaddr;
 196         dev->irq = irq;
 197         irq2dev_map[irq] = dev;
 198 
 199         for(i = 0; i < 3; i++) {
 200                 unsigned short eeprom_val = read_eeprom(ioaddr, 4+i);
 201                 printk("%04x", eeprom_val);
 202                 station_address[i] = ntohs(eeprom_val);
 203         }
 204 
 205         /* The EEPROM word 12 bit 0x0400 means use regular 100 ohm 10baseT signals,
 206            rather than 150 ohm shielded twisted pair compansation.
 207            0x0000 == auto-sense the interface
 208            0x0800 == use TP interface
 209            0x1800 == use coax interface
 210            */
 211         {
 212                 char *porttype[] = {"auto-sense", "10baseT", "auto-sense", "10base2"};
 213                 ushort setup_value = read_eeprom(ioaddr, 12);
 214 
 215                 dev->if_port = setup_value >> 8;
 216                 printk(" %s interface (%04x).\n", porttype[(dev->if_port>>3) & 3],
 217                            setup_value);
 218         }
 219 
 220         /* Set the station address in bank zero. */
 221         outb(0xe0, ioaddr + 7);
 222         for (i = 0; i < 6; i++)
 223                 outb(dev->dev_addr[i], ioaddr + 8 + i);
 224 
 225         /* Switch to bank 1 and set the multicast table to accept none. */
 226         outb(0xe4, ioaddr + 7);
 227         for (i = 0; i < 8; i++)
 228                 outb(0x00, ioaddr + 8 + i);
 229 
 230         /* Set the configuration register 0 to 32K 100ns. byte-wide memory, 16 bit
 231            bus access, two 4K Tx queues, and disabled Tx and Rx. */
 232         outb(0xda, ioaddr + CONFIG_0);
 233 
 234         /* Switch to bank 2 and lock our I/O address. */
 235         outb(0xe8, ioaddr + 7);
 236         outb(dev->if_port, MODE13);
 237 
 238         /* Power-down the chip.  Aren't we green! */
 239         outb(0x00, ioaddr + CONFIG_1);
 240 
 241         if (net_debug)
 242                 printk(version);
 243 
 244         /* Initialize the device structure. */
 245         dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
 246         memset(dev->priv, 0, sizeof(struct net_local));
 247 
 248         dev->open               = net_open;
 249         dev->stop               = net_close;
 250         dev->hard_start_xmit = net_send_packet;
 251         dev->get_stats  = net_get_stats;
 252 #ifdef HAVE_MULTICAST
 253         dev->set_multicast_list = &set_multicast_list;
 254 #endif
 255 
 256         /* Fill in the fields of the device structure with ethernet-generic values.
 257            This should be in a common file instead of per-driver.  */
 258         for (i = 0; i < DEV_NUMBUFFS; i++)
 259                 dev->buffs[i] = NULL;
 260 
 261         dev->hard_header        = eth_header;
 262         dev->add_arp            = eth_add_arp;
 263         dev->queue_xmit         = dev_queue_xmit;
 264         dev->rebuild_header     = eth_rebuild_header;
 265         dev->type_trans         = eth_type_trans;
 266 
 267         dev->type               = ARPHRD_ETHER;
 268         dev->hard_header_len = ETH_HLEN;
 269         dev->mtu                = 1500; /* eth_mtu */
 270         dev->addr_len   = ETH_ALEN;
 271         for (i = 0; i < ETH_ALEN; i++) {
 272                 dev->broadcast[i]=0xff;
 273         }
 274 
 275         /* New-style flags. */
 276         dev->flags              = IFF_BROADCAST;
 277         dev->family             = AF_INET;
 278         dev->pa_addr    = 0;
 279         dev->pa_brdaddr = 0;
 280         dev->pa_mask    = 0;
 281         dev->pa_alen    = sizeof(unsigned long);
 282 
 283         return 0;
 284 }
 285 
 286 static int read_eeprom(int ioaddr, int location)
     /* [previous][next][first][last][top][bottom][index][help] */
 287 {
 288         int i;
 289         unsigned short retval = 0;
 290         short ee_addr = ioaddr + EEPROM_Ctrl;
 291         short ee_daddr = ioaddr + EEPROM_Data;
 292         int read_cmd = location | EE_READ_CMD;
 293         short ctrl_val = EE_CS;
 294         
 295         outb(ctrl_val, ee_addr);
 296         
 297         /* Shift the read command bits out. */
 298         for (i = 9; i >= 0; i--) {
 299                 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
 300                 outb(dataval, ee_daddr);
 301                 outb(EE_CS | EE_SHIFT_CLK, ee_addr);    /* EEPROM clock tick. */
 302                 eeprom_delay();
 303                 outb(EE_CS, ee_addr);   /* Finish EEPROM a clock tick. */
 304                 eeprom_delay();
 305         }
 306         outb(EE_CS, ee_addr);
 307         
 308         for (i = 16; i > 0; i--) {
 309                 outb(EE_CS | EE_SHIFT_CLK, ee_addr);
 310                 eeprom_delay();
 311                 retval = (retval << 1) | ((inb(ee_daddr) & EE_DATA_READ) ? 1 : 0);
 312                 outb(EE_CS, ee_addr);
 313                 eeprom_delay();
 314         }
 315 
 316         /* Terminate the EEPROM access. */
 317         ctrl_val &= ~EE_CS;
 318         outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
 319         eeprom_delay();
 320         outb(ctrl_val, ee_addr);
 321         eeprom_delay();
 322         return retval;
 323 }
 324 
 325 
 326 
 327 static int net_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 328 {
 329         struct net_local *lp = (struct net_local *)dev->priv;
 330         int ioaddr = dev->base_addr;
 331         int i;
 332 
 333         /* Powerup the chip, initialize config register 1, and select bank 0. */
 334         outb(0xe0, ioaddr + CONFIG_1);
 335 
 336         /* Set the station address in bank zero. */
 337         for (i = 0; i < 6; i++)
 338                 outb(dev->dev_addr[i], ioaddr + 8 + i);
 339 
 340         /* Switch to bank 1 and set the multicast table to accept none. */
 341         outb(0xe4, ioaddr + 7);
 342         for (i = 0; i < 8; i++)
 343                 outb(0x00, ioaddr + 8 + i);
 344 
 345         /* Set the configuration register 0 to 32K 100ns. byte-wide memory, 16 bit
 346            bus access, and two 4K Tx queues. */
 347         outb(0xda, ioaddr + CONFIG_0);
 348 
 349         /* Same config 0, except enable the Rx and Tx. */
 350         outb(0x5a, ioaddr + CONFIG_0);
 351         /* Switch to register bank 2 for the run-time registers. */
 352         outb(0xe8, ioaddr + CONFIG_1);
 353 
 354         /* Turn on Rx interrupts, leave Tx interrupts off until packet Tx. */
 355         outb(0x00, ioaddr + TX_INTR);
 356         outb(0x81, ioaddr + RX_INTR);
 357 
 358         lp->open_time = jiffies;
 359 
 360         dev->tbusy = 0;
 361         dev->interrupt = 0;
 362         dev->start = 1;
 363 
 364         return 0;
 365 }
 366 
 367 static int
 368 net_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 369 {
 370         struct net_local *lp = (struct net_local *)dev->priv;
 371         int ioaddr = dev->base_addr;
 372 
 373         if (dev->tbusy) {
 374                 /* If we get here, some higher level has decided we are broken.
 375                    There should really be a "kick me" function call instead. */
 376                 int tickssofar = jiffies - dev->trans_start;
 377                 if (tickssofar < 10)
 378                         return 1;
 379                 printk("%s: transmit timed out with status %04x, %s?\n", dev->name,
 380                            inw(ioaddr + STATUS), inb(ioaddr + TX_STATUS) & 0x80
 381                            ? "IRQ conflict" : "network cable problem");
 382                 printk("%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n",
 383                            dev->name, inw(ioaddr + 0), inw(ioaddr + 2), inw(ioaddr + 4),
 384                            inw(ioaddr + 6), inw(ioaddr + 8), inw(ioaddr + 10),
 385                            inw(ioaddr + 12), inw(ioaddr + 14));
 386                 lp->stats.tx_errors++;
 387                 /* ToDo: We should try to restart the adaptor... */
 388                 outw(0xffff, ioaddr + 24);
 389                 outw(0xffff, ioaddr + TX_STATUS);
 390                 outw(0xe85a, ioaddr + CONFIG_0);
 391                 outw(0x8100, ioaddr + TX_INTR);
 392                 dev->tbusy=0;
 393                 dev->trans_start = jiffies;
 394         }
 395 
 396         /* If some higher layer thinks we've missed an tx-done interrupt
 397            we are passed NULL. Caution: dev_tint() handles the cli()/sti()
 398            itself. */
 399         if (skb == NULL) {
 400                 dev_tint(dev);
 401                 return 0;
 402         }
 403 
 404         /* For ethernet, fill in the header.  This should really be done by a
 405            higher level, rather than duplicated for each ethernet adaptor. */
 406         if (!skb->arp  &&  dev->rebuild_header(skb+1, dev)) {
 407                 skb->dev = dev;
 408                 arp_queue (skb);
 409                 return 0;
 410         }
 411         skb->arp=1;
 412 
 413         /* Block a timer-based transmit from overlapping.  This could better be
 414            done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
 415         if (set_bit(0, (void*)&dev->tbusy) != 0)
 416                 printk("%s: Transmitter access conflict.\n", dev->name);
 417         else {
 418                 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
 419                 unsigned char *buf = (void *)(skb+1);
 420 
 421                 if (net_debug > 4)
 422                         printk("%s: Transmitting a packet of length %d.\n", dev->name,
 423                                    skb->len);
 424 
 425                 /* Turn off the possible Tx interrupts. */
 426                 outb(0x00, ioaddr + TX_INTR);
 427                 
 428                 outw(length, ioaddr + DATAPORT);
 429                 port_write(ioaddr + DATAPORT, buf, (length + 1) >> 1);
 430 
 431                 lp->tx_queue++;
 432                 lp->tx_queue_len += length + 2;
 433 
 434                 if (lp->tx_started == 0) {
 435                         /* If the Tx is idle, always trigger a transmit. */
 436                         outb(0x80 | lp->tx_queue, ioaddr + TX_START);
 437                         lp->tx_queue = 0;
 438                         lp->tx_queue_len = 0;
 439                         dev->trans_start = jiffies;
 440                         lp->tx_started = 1;
 441                 } else if (lp->tx_queue_len < 4096 - 1502)      /* Room for one more packet? */
 442                         dev->tbusy = 0;
 443 
 444                 /* Turn on Tx interrupts back on. */
 445                 outb(0x82, ioaddr + TX_INTR);
 446         }
 447         if (skb->free)
 448                 kfree_skb (skb, FREE_WRITE);
 449 
 450         return 0;
 451 }
 452 
 453 /* The typical workload of the driver:
 454    Handle the network interface interrupts. */
 455 static void
 456 net_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 457 {
 458         int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 459         struct device *dev = (struct device *)(irq2dev_map[irq]);
 460         struct net_local *lp;
 461         int ioaddr, status;
 462 
 463         if (dev == NULL) {
 464                 printk ("at1700_interrupt(): irq %d for unknown device.\n", irq);
 465                 return;
 466         }
 467         dev->interrupt = 1;
 468 
 469         ioaddr = dev->base_addr;
 470         lp = (struct net_local *)dev->priv;
 471         status = inw(ioaddr + TX_STATUS);
 472         outw(status, ioaddr + TX_STATUS);
 473 
 474         if (net_debug > 4)
 475                 printk("%s: Interrupt with status %04x.\n", dev->name, status);
 476         if (status & 0xff00
 477                 ||  (inb(ioaddr + RX_MODE) & 0x40) == 0) {                      /* Got a packet(s). */
 478                 net_rx(dev);
 479         }
 480         if (status & 0x00ff) {
 481                 if (status & 0x80) {
 482                         lp->stats.tx_packets++;
 483                         if (lp->tx_queue) {
 484                                 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
 485                                 lp->tx_queue = 0;
 486                                 lp->tx_queue_len = 0;
 487                                 dev->trans_start = jiffies;
 488                                 dev->tbusy = 0;
 489                                 mark_bh(INET_BH);       /* Inform upper layers. */
 490                         } else {
 491                                 lp->tx_started = 0;
 492                                 /* Turn on Tx interrupts off. */
 493                                 outb(0x00, ioaddr + TX_INTR);
 494                                 dev->tbusy = 0;
 495                         }
 496                 }
 497         }
 498 
 499         return;
 500 }
 501 
 502 /* We have a good packet(s), get it/them out of the buffers. */
 503 static void
 504 net_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 505 {
 506         struct net_local *lp = (struct net_local *)dev->priv;
 507         int ioaddr = dev->base_addr;
 508         int boguscount = 5;
 509 
 510         while ((inb(ioaddr + RX_MODE) & 0x40) == 0) {
 511                 ushort status = inw(ioaddr + DATAPORT);
 512 
 513                 if (net_debug > 4)
 514                         printk("%s: Rxing packet mode %02x status %04x.\n",
 515                                    dev->name, inb(ioaddr + RX_MODE), status);
 516 #ifndef final_version
 517                 if (status == 0) {
 518                         outb(0x05, ioaddr + 14);
 519                         break;
 520                 }
 521 #endif
 522 
 523                 if ((status & 0xF0) != 0x20) {  /* There was an error. */
 524                         lp->stats.rx_errors++;
 525                         if (status & 0x08) lp->stats.rx_length_errors++;
 526                         if (status & 0x04) lp->stats.rx_frame_errors++;
 527                         if (status & 0x02) lp->stats.rx_crc_errors++;
 528                         if (status & 0x01) lp->stats.rx_over_errors++;
 529                 } else {
 530                         ushort pkt_len = inw(ioaddr + DATAPORT);
 531                         /* Malloc up new buffer. */
 532                         int sksize = sizeof(struct sk_buff) + pkt_len;
 533                         struct sk_buff *skb;
 534 
 535                         if (pkt_len > 1550) {
 536                                 printk("%s: The AT1700 claimed a very large packet, size %d.\n",
 537                                            dev->name, pkt_len);
 538                                 outb(0x05, ioaddr + 14);
 539                                 lp->stats.rx_errors++;
 540                                 break;
 541                         }
 542                         skb = alloc_skb(sksize, GFP_ATOMIC);
 543                         if (skb == NULL) {
 544                                 printk("%s: Memory squeeze, dropping packet (len %d).\n",
 545                                            dev->name, pkt_len);
 546                                 outb(0x05, ioaddr + 14);
 547                                 lp->stats.rx_dropped++;
 548                                 break;
 549                         }
 550                         skb->mem_len = sksize;
 551                         skb->mem_addr = skb;
 552                         skb->len = pkt_len;
 553                         skb->dev = dev;
 554 
 555                         /* 'skb+1' points to the start of sk_buff data area. */
 556                         port_read(ioaddr + DATAPORT, (void *)(skb+1), (pkt_len + 1) >> 1);
 557 
 558                         if (net_debug > 5) {
 559                                 int i;
 560                                 printk("%s: Rxed packet of length %d: ", dev->name, pkt_len);
 561                                 for (i = 0; i < 14; i++)
 562                                         printk(" %02x", ((unsigned char*)(skb + 1))[i]);
 563                                 printk(".\n");
 564                         }
 565 
 566 #ifdef HAVE_NETIF_RX
 567                         netif_rx(skb);
 568 #else
 569                         skb->lock = 0;
 570                         if (dev_rint((unsigned char*)skb, pkt_len, IN_SKBUFF, dev) != 0) {
 571                                 kfree_s(skb, sksize);
 572                                 lp->stats.rx_dropped++;
 573                                 break;
 574                         }
 575 #endif
 576                         lp->stats.rx_packets++;
 577                 }
 578                 if (--boguscount <= 0)
 579                         break;
 580         }
 581 
 582         /* If any worth-while packets have been received, dev_rint()
 583            has done a mark_bh(INET_BH) for us and will work on them
 584            when we get to the bottom-half routine. */
 585         {
 586                 int i;
 587                 for (i = 0; i < 20; i++) {
 588                         if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40)
 589                                 break;
 590                         outb(0x05, ioaddr + 14);
 591                 }
 592 
 593                 if (net_debug > 5)
 594                         printk("%s: Exint Rx packet with mode %02x after %d ticks.\n", 
 595                                    dev->name, inb(ioaddr + RX_MODE), i);
 596         }
 597         return;
 598 }
 599 
 600 /* The inverse routine to net_open(). */
 601 static int net_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 602 {
 603         struct net_local *lp = (struct net_local *)dev->priv;
 604         int ioaddr = dev->base_addr;
 605 
 606         lp->open_time = 0;
 607 
 608         dev->tbusy = 1;
 609         dev->start = 0;
 610 
 611         /* Set configuration register 0 to disable Tx and Rx. */
 612         outb(0xda, ioaddr + CONFIG_0);
 613 
 614         /* Update the statistics -- ToDo. */
 615 
 616         /* Power-down the chip.  Green, green, green! */
 617         outb(0x00, ioaddr + CONFIG_1);
 618 
 619         return 0;
 620 }
 621 
 622 /* Get the current statistics.  This may be called with the card open or
 623    closed. */
 624 static struct enet_statistics *
 625 net_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 626 {
 627         struct net_local *lp = (struct net_local *)dev->priv;
 628 
 629         cli();
 630         /* ToDo: Update the statistics from the device registers. */
 631         sti();
 632 
 633         return &lp->stats;
 634 }
 635 
 636 #ifdef HAVE_MULTICAST
 637 /* Set or clear the multicast filter for this adaptor.
 638    num_addrs == -1      Promiscuous mode, receive all packets
 639    num_addrs == 0       Normal mode, clear multicast list
 640    num_addrs > 0        Multicast mode, receive normal and MC packets, and do
 641                         best-effort filtering.
 642  */
 643 static void
 644 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 645 {
 646         short ioaddr = dev->base_addr;
 647         if (num_addrs) {
 648                 outw(3, ioaddr + RX_MODE);      /* Enable promiscuous mode */
 649         } else
 650                 outw(2, ioaddr + RX_MODE);      /* Disable promiscuous, use normal mode */
 651 }
 652 #endif
 653 
 654 /*
 655  * Local variables:
 656  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c at1700.c"
 657  *  version-control: t
 658  *  kept-new-versions: 5
 659  *  tab-width: 4
 660  * End:
 661  */

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