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
  11. init_module
  12. cleanup_module

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

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