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

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