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), 0);
 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         if (dev->priv == NULL)
 267                 dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
 268         memset(dev->priv, 0, sizeof(struct net_local));
 269 
 270         dev->open               = net_open;
 271         dev->stop               = net_close;
 272         dev->hard_start_xmit = net_send_packet;
 273         dev->get_stats  = net_get_stats;
 274         dev->set_multicast_list = &set_multicast_list;
 275 
 276         /* Fill in the fields of 'dev' with ethernet-generic values. */
 277            
 278         ether_setup(dev);
 279         return 0;
 280 }
 281 
 282 static int read_eeprom(int ioaddr, int location)
     /* [previous][next][first][last][top][bottom][index][help] */
 283 {
 284         int i;
 285         unsigned short retval = 0;
 286         short ee_addr = ioaddr + EEPROM_Ctrl;
 287         short ee_daddr = ioaddr + EEPROM_Data;
 288         int read_cmd = location | EE_READ_CMD;
 289         short ctrl_val = EE_CS;
 290         
 291         outb(ctrl_val, ee_addr);
 292         
 293         /* Shift the read command bits out. */
 294         for (i = 9; i >= 0; i--) {
 295                 short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0;
 296                 outb(dataval, ee_daddr);
 297                 outb(EE_CS | EE_SHIFT_CLK, ee_addr);    /* EEPROM clock tick. */
 298                 eeprom_delay();
 299                 outb(EE_CS, ee_addr);   /* Finish EEPROM a clock tick. */
 300                 eeprom_delay();
 301         }
 302         outb(EE_CS, ee_addr);
 303         
 304         for (i = 16; i > 0; i--) {
 305                 outb(EE_CS | EE_SHIFT_CLK, ee_addr);
 306                 eeprom_delay();
 307                 retval = (retval << 1) | ((inb(ee_daddr) & EE_DATA_READ) ? 1 : 0);
 308                 outb(EE_CS, ee_addr);
 309                 eeprom_delay();
 310         }
 311 
 312         /* Terminate the EEPROM access. */
 313         ctrl_val &= ~EE_CS;
 314         outb(ctrl_val | EE_SHIFT_CLK, ee_addr);
 315         eeprom_delay();
 316         outb(ctrl_val, ee_addr);
 317         eeprom_delay();
 318         return retval;
 319 }
 320 
 321 
 322 
 323 static int net_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 324 {
 325         struct net_local *lp = (struct net_local *)dev->priv;
 326         int ioaddr = dev->base_addr;
 327         int i;
 328 
 329         /* Powerup the chip, initialize config register 1, and select bank 0. */
 330         outb(0xe0, ioaddr + CONFIG_1);
 331 
 332         /* Set the station address in bank zero. */
 333         for (i = 0; i < 6; i++)
 334                 outb(dev->dev_addr[i], ioaddr + 8 + i);
 335 
 336         /* Switch to bank 1 and set the multicast table to accept none. */
 337         outb(0xe4, ioaddr + 7);
 338         for (i = 0; i < 8; i++)
 339                 outb(0x00, ioaddr + 8 + i);
 340 
 341         /* Set the configuration register 0 to 32K 100ns. byte-wide memory, 16 bit
 342            bus access, and two 4K Tx queues. */
 343         outb(0xda, ioaddr + CONFIG_0);
 344 
 345         /* Same config 0, except enable the Rx and Tx. */
 346         outb(0x5a, ioaddr + CONFIG_0);
 347         /* Switch to register bank 2 for the run-time registers. */
 348         outb(0xe8, ioaddr + CONFIG_1);
 349 
 350         lp->tx_started = 0;
 351         lp->tx_queue = 0;
 352         lp->tx_queue_len = 0;
 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         dev->tbusy = 0;
 359         dev->interrupt = 0;
 360         dev->start = 1;
 361 
 362 #ifdef MODULE
 363         MOD_INC_USE_COUNT;
 364 #endif
 365 
 366         return 0;
 367 }
 368 
 369 static int
 370 net_send_packet(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 371 {
 372         struct net_local *lp = (struct net_local *)dev->priv;
 373         int ioaddr = dev->base_addr;
 374 
 375         if (dev->tbusy) {
 376                 /* If we get here, some higher level has decided we are broken.
 377                    There should really be a "kick me" function call instead. */
 378                 int tickssofar = jiffies - dev->trans_start;
 379                 if (tickssofar < 10)
 380                         return 1;
 381                 printk("%s: transmit timed out with status %04x, %s?\n", dev->name,
 382                            inw(ioaddr + STATUS), inb(ioaddr + TX_STATUS) & 0x80
 383                            ? "IRQ conflict" : "network cable problem");
 384                 printk("%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n",
 385                            dev->name, inw(ioaddr + 0), inw(ioaddr + 2), inw(ioaddr + 4),
 386                            inw(ioaddr + 6), inw(ioaddr + 8), inw(ioaddr + 10),
 387                            inw(ioaddr + 12), inw(ioaddr + 14));
 388                 lp->stats.tx_errors++;
 389                 /* ToDo: We should try to restart the adaptor... */
 390                 outw(0xffff, ioaddr + 24);
 391                 outw(0xffff, ioaddr + TX_STATUS);
 392                 outw(0xe85a, ioaddr + CONFIG_0);
 393                 outw(0x8100, ioaddr + TX_INTR);
 394                 dev->tbusy=0;
 395                 dev->trans_start = jiffies;
 396                 lp->tx_started = 0;
 397                 lp->tx_queue = 0;
 398                 lp->tx_queue_len = 0;
 399         }
 400 
 401         /* If some higher layer thinks we've missed an tx-done interrupt
 402            we are passed NULL. Caution: dev_tint() handles the cli()/sti()
 403            itself. */
 404         if (skb == NULL) {
 405                 dev_tint(dev);
 406                 return 0;
 407         }
 408 
 409         /* Block a timer-based transmit from overlapping.  This could better be
 410            done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
 411         if (set_bit(0, (void*)&dev->tbusy) != 0)
 412                 printk("%s: Transmitter access conflict.\n", dev->name);
 413         else {
 414                 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
 415                 unsigned char *buf = skb->data;
 416 
 417                 /* Turn off the possible Tx interrupts. */
 418                 outb(0x00, ioaddr + TX_INTR);
 419                 
 420                 outw(length, ioaddr + DATAPORT);
 421                 outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1);
 422 
 423                 lp->tx_queue++;
 424                 lp->tx_queue_len += length + 2;
 425 
 426                 if (lp->tx_started == 0) {
 427                         /* If the Tx is idle, always trigger a transmit. */
 428                         outb(0x80 | lp->tx_queue, ioaddr + TX_START);
 429                         lp->tx_queue = 0;
 430                         lp->tx_queue_len = 0;
 431                         dev->trans_start = jiffies;
 432                         lp->tx_started = 1;
 433                         dev->tbusy = 0;
 434                 } else if (lp->tx_queue_len < 4096 - 1502)
 435                         /* Yes, there is room for one more packet. */
 436                         dev->tbusy = 0;
 437 
 438                 /* Turn on Tx interrupts back on. */
 439                 outb(0x82, ioaddr + TX_INTR);
 440         }
 441         dev_kfree_skb (skb, FREE_WRITE);
 442 
 443         return 0;
 444 }
 445 
 446 /* The typical workload of the driver:
 447    Handle the network interface interrupts. */
 448 static void
 449 net_interrupt(int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 450 {
 451         struct device *dev = (struct device *)(irq2dev_map[irq]);
 452         struct net_local *lp;
 453         int ioaddr, status;
 454 
 455         if (dev == NULL) {
 456                 printk ("at1700_interrupt(): irq %d for unknown device.\n", irq);
 457                 return;
 458         }
 459         dev->interrupt = 1;
 460 
 461         ioaddr = dev->base_addr;
 462         lp = (struct net_local *)dev->priv;
 463         status = inw(ioaddr + TX_STATUS);
 464         outw(status, ioaddr + TX_STATUS);
 465 
 466         if (net_debug > 4)
 467                 printk("%s: Interrupt with status %04x.\n", dev->name, status);
 468         if (status & 0xff00
 469                 ||  (inb(ioaddr + RX_MODE) & 0x40) == 0) {                      /* Got a packet(s). */
 470                 net_rx(dev);
 471         }
 472         if (status & 0x00ff) {
 473                 if (status & 0x80) {
 474                         lp->stats.tx_packets++;
 475                         if (lp->tx_queue) {
 476                                 outb(0x80 | lp->tx_queue, ioaddr + TX_START);
 477                                 lp->tx_queue = 0;
 478                                 lp->tx_queue_len = 0;
 479                                 dev->trans_start = jiffies;
 480                                 dev->tbusy = 0;
 481                                 mark_bh(NET_BH);        /* Inform upper layers. */
 482                         } else {
 483                                 lp->tx_started = 0;
 484                                 /* Turn on Tx interrupts off. */
 485                                 outb(0x00, ioaddr + TX_INTR);
 486                                 dev->tbusy = 0;
 487                                 mark_bh(NET_BH);        /* Inform upper layers. */
 488                         }
 489                 }
 490         }
 491 
 492         dev->interrupt = 0;
 493         return;
 494 }
 495 
 496 /* We have a good packet(s), get it/them out of the buffers. */
 497 static void
 498 net_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 499 {
 500         struct net_local *lp = (struct net_local *)dev->priv;
 501         int ioaddr = dev->base_addr;
 502         int boguscount = 5;
 503 
 504         while ((inb(ioaddr + RX_MODE) & 0x40) == 0) {
 505                 ushort status = inw(ioaddr + DATAPORT);
 506                 ushort pkt_len = inw(ioaddr + DATAPORT);
 507 
 508                 if (net_debug > 4)
 509                         printk("%s: Rxing packet mode %02x status %04x.\n",
 510                                    dev->name, inb(ioaddr + RX_MODE), status);
 511 #ifndef final_version
 512                 if (status == 0) {
 513                         outb(0x05, ioaddr + 14);
 514                         break;
 515                 }
 516 #endif
 517 
 518                 if ((status & 0xF0) != 0x20) {  /* There was an error. */
 519                         lp->stats.rx_errors++;
 520                         if (status & 0x08) lp->stats.rx_length_errors++;
 521                         if (status & 0x04) lp->stats.rx_frame_errors++;
 522                         if (status & 0x02) lp->stats.rx_crc_errors++;
 523                         if (status & 0x01) lp->stats.rx_over_errors++;
 524                 } else {
 525                         /* Malloc up new buffer. */
 526                         struct sk_buff *skb;
 527 
 528                         if (pkt_len > 1550) {
 529                                 printk("%s: The AT1700 claimed a very large packet, size %d.\n",
 530                                            dev->name, pkt_len);
 531                                 /* Prime the FIFO and then flush the packet. */
 532                                 inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
 533                                 outb(0x05, ioaddr + 14);
 534                                 lp->stats.rx_errors++;
 535                                 break;
 536                         }
 537                         skb = dev_alloc_skb(pkt_len+3);
 538                         if (skb == NULL) {
 539                                 printk("%s: Memory squeeze, dropping packet (len %d).\n",
 540                                            dev->name, pkt_len);
 541                                 /* Prime the FIFO and then flush the packet. */
 542                                 inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT);
 543                                 outb(0x05, ioaddr + 14);
 544                                 lp->stats.rx_dropped++;
 545                                 break;
 546                         }
 547                         skb->dev = dev;
 548                         skb_reserve(skb,2);
 549 
 550                         insw(ioaddr + DATAPORT, skb_put(skb,pkt_len), (pkt_len + 1) >> 1);
 551                         skb->protocol=eth_type_trans(skb, dev);
 552                         netif_rx(skb);
 553                         lp->stats.rx_packets++;
 554                 }
 555                 if (--boguscount <= 0)
 556                         break;
 557         }
 558 
 559         /* If any worth-while packets have been received, dev_rint()
 560            has done a mark_bh(NET_BH) for us and will work on them
 561            when we get to the bottom-half routine. */
 562         {
 563                 int i;
 564                 for (i = 0; i < 20; i++) {
 565                         if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40)
 566                                 break;
 567                         inw(ioaddr + DATAPORT);                         /* dummy status read */
 568                         outb(0x05, ioaddr + 14);
 569                 }
 570 
 571                 if (net_debug > 5)
 572                         printk("%s: Exint Rx packet with mode %02x after %d ticks.\n", 
 573                                    dev->name, inb(ioaddr + RX_MODE), i);
 574         }
 575         return;
 576 }
 577 
 578 /* The inverse routine to net_open(). */
 579 static int net_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 580 {
 581         int ioaddr = dev->base_addr;
 582 
 583         dev->tbusy = 1;
 584         dev->start = 0;
 585 
 586         /* Set configuration register 0 to disable Tx and Rx. */
 587         outb(0xda, ioaddr + CONFIG_0);
 588 
 589         /* Update the statistics -- ToDo. */
 590 
 591         /* Power-down the chip.  Green, green, green! */
 592         outb(0x00, ioaddr + CONFIG_1);
 593 
 594 #ifdef MODULE
 595         MOD_DEC_USE_COUNT;
 596 #endif
 597 
 598         return 0;
 599 }
 600 
 601 /* Get the current statistics.  This may be called with the card open or
 602    closed. */
 603 static struct enet_statistics *
 604 net_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 605 {
 606         struct net_local *lp = (struct net_local *)dev->priv;
 607 
 608         cli();
 609         /* ToDo: Update the statistics from the device registers. */
 610         sti();
 611 
 612         return &lp->stats;
 613 }
 614 
 615 /* Set or clear the multicast filter for this adaptor.
 616    num_addrs == -1      Promiscuous mode, receive all packets
 617    num_addrs == 0       Normal mode, clear multicast list
 618    num_addrs > 0        Multicast mode, receive normal and MC packets, and do
 619                         best-effort filtering.
 620  */
 621 static void
 622 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 623 {
 624         short ioaddr = dev->base_addr;
 625         if (num_addrs) {
 626                 outb(3, ioaddr + RX_MODE);      /* Enable promiscuous mode */
 627         } else
 628                 outb(2, ioaddr + RX_MODE);      /* Disable promiscuous, use normal mode */
 629 }
 630 #ifdef MODULE
 631 char kernel_version[] = UTS_RELEASE;
 632 static char devicename[9] = { 0, };
 633 static struct device dev_at1700 = {
 634         devicename, /* device name is inserted by linux/drivers/net/net_init.c */
 635         0, 0, 0, 0,
 636         0, 0,
 637         0, 0, 0, NULL, at1700_probe };
 638 
 639 int io = 0x260;
 640 int irq = 0;
 641 
 642 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 643 {
 644         if (io == 0)
 645                 printk("at1700: You should not use auto-probing with insmod!\n");
 646         dev_at1700.base_addr = io;
 647         dev_at1700.irq       = irq;
 648         if (register_netdev(&dev_at1700) != 0) {
 649                 printk("at1700: register_netdev() returned non-zero.\n");
 650                 return -EIO;
 651         }
 652         return 0;
 653 }
 654 
 655 void
 656 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 657 {
 658         if (MOD_IN_USE)
 659                 printk("at1700: device busy, remove delayed\n");
 660         else
 661         {
 662                 unregister_netdev(&dev_at1700);
 663 
 664                 /* If we don't do this, we can't re-insmod it later. */
 665                 free_irq(dev_at1700.irq);
 666                 irq2dev_map[dev_at1700.irq] = NULL;
 667                 release_region(dev_at1700.base_addr, AT1700_IO_EXTENT);
 668         }
 669 }
 670 #endif /* MODULE */
 671 
 672 /*
 673  * Local variables:
 674  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c at1700.c"
 675  *  version-control: t
 676  *  kept-new-versions: 5
 677  *  tab-width: 4
 678  *  c-indent-level: 4
 679  * End:
 680  */

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