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

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