root/drivers/net/apricot.c

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

DEFINITIONS

This source file includes following definitions.
  1. init_rx_bufs
  2. remove_rx_bufs
  3. init_i596_mem
  4. i596_rx
  5. i596_cleanup_cmd
  6. i596_reset
  7. i596_add_cmd
  8. i596_open
  9. i596_start_xmit
  10. print_eth
  11. apricot_probe
  12. i596_interrupt
  13. i596_close
  14. i596_get_stats
  15. set_multicast_list
  16. init_module
  17. cleanup_module

   1 /* apricot.c: An Apricot 82596 ethernet driver for linux. */
   2 /*
   3     Apricot
   4         Written 1994 by Mark Evans.
   5         This driver is for the Apricot 82596 bus-master interface
   6 
   7         Modularised 12/94 Mark Evans
   8     
   9     Driver skeleton 
  10         Written 1993 by Donald Becker.
  11         Copyright 1993 United States Government as represented by the Director,
  12         National Security Agency.  This software may only be used and distributed
  13         according to the terms of the GNU Public License as modified by SRC,
  14         incorporated herein by reference.
  15 
  16         The author may be reached as becker@super.org or
  17         C/O Supercomputing Research Ctr., 17100 Science Dr., Bowie MD 20715
  18     
  19 
  20 */
  21 
  22 static char *version = "apricot.c:v0.2 05/12/94\n";
  23 
  24 #include <linux/config.h>
  25 #include <linux/kernel.h>
  26 #include <linux/sched.h>
  27 #include <linux/string.h>
  28 #include <linux/ptrace.h>
  29 #include <linux/errno.h>
  30 #include <linux/ioport.h>
  31 #include <linux/malloc.h>
  32 #include <linux/interrupt.h>
  33 #include <asm/bitops.h>
  34 #include <asm/io.h>
  35 #include <asm/dma.h>
  36 
  37 #include <linux/netdevice.h>
  38 #include <linux/etherdevice.h>
  39 #include <linux/skbuff.h>
  40 
  41 #ifdef MODULE
  42 #include <linux/module.h>
  43 #include <linux/version.h>
  44 #endif
  45 
  46 #ifndef HAVE_PORTRESERVE
  47 #define check_region(addr, size)        0
  48 #define snarf_region(addr, size)        do ; while(0)
  49 #endif
  50 
  51 #ifndef HAVE_ALLOC_SKB
  52 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
  53 #define kfree_skbmem(buff, size) kfree_s(buff,size)
  54 #endif
  55 
  56 #define APRICOT_DEBUG 1
  57 
  58 #ifdef APRICOT_DEBUG
  59 int i596_debug = APRICOT_DEBUG;
  60 #else
  61 int i596_debug = 1;
  62 #endif
  63 
  64 #define APRICOT_TOTAL_SIZE 17
  65 
  66 #define I596_NULL -1
  67 
  68 #define CMD_EOL         0x8000  /* The last command of the list, stop. */
  69 #define CMD_SUSP        0x4000  /* Suspend after doing cmd. */
  70 #define CMD_INTR        0x2000  /* Interrupt after doing cmd. */
  71 
  72 #define CMD_FLEX        0x0008  /* Enable flexible memory model */
  73 
  74 enum commands {
  75         CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
  76         CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7};
  77 
  78 #define STAT_C          0x8000  /* Set to 0 after execution */
  79 #define STAT_B          0x4000  /* Command being executed */
  80 #define STAT_OK         0x2000  /* Command executed ok */
  81 #define STAT_A          0x1000  /* Command aborted */
  82 
  83 #define  CUC_START      0x0100
  84 #define  CUC_RESUME     0x0200
  85 #define  CUC_SUSPEND    0x0300
  86 #define  CUC_ABORT      0x0400
  87 #define  RX_START       0x0010
  88 #define  RX_RESUME      0x0020
  89 #define  RX_SUSPEND     0x0030
  90 #define  RX_ABORT       0x0040
  91 
  92 struct i596_cmd {
  93     unsigned short status;
  94     unsigned short command;
  95     struct i596_cmd *next;
  96 };
  97 
  98 #define EOF             0x8000
  99 #define SIZE_MASK       0x3fff
 100 
 101 struct i596_tbd {
 102     unsigned short size;
 103     unsigned short pad;
 104     struct i596_tbd *next;
 105     char *data;
 106 };
 107 
 108 struct tx_cmd {
 109     struct i596_cmd cmd;
 110     struct i596_tbd *tbd;
 111     unsigned short size;
 112     unsigned short pad;
 113 };
 114 
 115 struct i596_rfd {
 116     unsigned short stat;
 117     unsigned short cmd;
 118     struct i596_rfd *next;
 119     long rbd; 
 120     unsigned short count;
 121     unsigned short size;
 122     char data[1532];
 123 };
 124 
 125 #define RX_RING_SIZE 8
 126 
 127 struct i596_scb {
 128     unsigned short status;
 129     unsigned short command;
 130     struct i596_cmd *cmd;
 131     struct i596_rfd *rfd;
 132     unsigned long crc_err;
 133     unsigned long align_err;
 134     unsigned long resource_err;
 135     unsigned long over_err;
 136     unsigned long rcvdt_err;
 137     unsigned long short_err;
 138     unsigned short t_on;
 139     unsigned short t_off;
 140 };
 141 
 142 struct i596_iscp {
 143     unsigned long stat;
 144     struct i596_scb *scb;
 145 };
 146 
 147 struct i596_scp {
 148     unsigned long sysbus;
 149     unsigned long pad;
 150     struct i596_iscp *iscp;
 151 };
 152 
 153 struct i596_private {
 154     struct i596_scp scp;
 155     struct i596_iscp iscp;
 156     struct i596_scb scb;
 157     struct i596_cmd set_add;
 158     char eth_addr[8];
 159     struct i596_cmd set_conf;
 160     char i596_config[16];
 161     struct i596_cmd tdr;
 162     unsigned long stat;
 163     int last_restart;
 164     struct i596_rfd *rx_tail;
 165     struct i596_cmd *cmd_tail;
 166     struct i596_cmd *cmd_head;
 167     int cmd_backlog;
 168     unsigned long last_cmd;
 169     struct enet_statistics stats;
 170 };
 171 
 172 char init_setup[] = {
 173         0x8E,   /* length, prefetch on */
 174         0xC8,   /* fifo to 8, monitor off */
 175         0x80,   /* don't save bad frames */
 176         0x2E,   /* No source address insertion, 8 byte preamble */
 177         0x00,   /* priority and backoff defaults */
 178         0x60,   /* interframe spacing */
 179         0x00,   /* slot time LSB */
 180         0xf2,   /* slot time and retries */
 181         0x00,   /* promiscuous mode */
 182         0x00,   /* collision detect */
 183         0x40,   /* minimum frame length */
 184         0xff,   
 185         0x00,
 186         0x7f    /*  *multi IA */ };
 187 
 188 static int i596_open(struct device *dev);
 189 static int i596_start_xmit(struct sk_buff *skb, struct device *dev);
 190 static void i596_interrupt(int reg_ptr);
 191 static int i596_close(struct device *dev);
 192 static struct enet_statistics *i596_get_stats(struct device *dev);
 193 static void i596_add_cmd(struct device *dev, struct i596_cmd *cmd);
 194 static void print_eth(char *);
 195 #ifdef HAVE_MULTICAST
 196 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 197 #endif
 198 
 199 
 200 static inline int
 201 init_rx_bufs(struct device *dev, int num)
     /* [previous][next][first][last][top][bottom][index][help] */
 202 {
 203     struct i596_private *lp = (struct i596_private *)dev->priv;
 204     int i;
 205     struct i596_rfd *rfd;
 206 
 207     lp->scb.rfd = (struct i596_rfd *)I596_NULL;
 208 
 209     if (i596_debug > 1) printk ("%s: init_rx_bufs %d.\n", dev->name, num);
 210 
 211     for (i = 0; i < num; i++)
 212     {
 213         if (!(rfd = (struct i596_rfd *)kmalloc(sizeof(struct i596_rfd), GFP_KERNEL)))
 214             break;
 215 
 216         rfd->stat = 0x0000;
 217         rfd->rbd = I596_NULL;
 218         rfd->count = 0;
 219         rfd->size = 1532;
 220         if (i == 0)
 221         {
 222             rfd->cmd = CMD_EOL;
 223             lp->rx_tail = rfd;
 224         }
 225         else
 226             rfd->cmd = 0x0000;
 227 
 228         rfd->next = lp->scb.rfd;
 229         lp->scb.rfd = rfd;
 230     }
 231 
 232     if (i != 0)
 233       lp->rx_tail->next = lp->scb.rfd;
 234 
 235     return (i);
 236 }
 237 
 238 static inline void
 239 remove_rx_bufs(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 240 {
 241     struct i596_private *lp = (struct i596_private *)dev->priv;
 242     struct i596_rfd *rfd = lp->scb.rfd;
 243 
 244     lp->rx_tail->next = (struct i596_rfd *)I596_NULL;
 245 
 246     do
 247     {
 248         lp->scb.rfd = rfd->next;
 249         kfree_s(rfd, sizeof(struct i596_rfd));
 250         rfd = lp->scb.rfd;
 251     }
 252     while (rfd != lp->rx_tail);
 253 }
 254 
 255 static inline void
 256 init_i596_mem(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 257 {
 258     struct i596_private *lp = (struct i596_private *)dev->priv;
 259     short ioaddr = dev->base_addr;
 260     int boguscnt = 100;
 261 
 262     /* change the scp address */
 263     outw(0, ioaddr);
 264     outw(0, ioaddr);
 265     outb(4, ioaddr+0xf);
 266     outw(((((int)&lp->scp) & 0xffff) | 2), ioaddr);
 267     outw((((int)&lp->scp)>>16) & 0xffff, ioaddr);
 268 
 269     lp->last_cmd = jiffies;
 270 
 271     lp->scp.sysbus = 0x00440000;
 272     lp->scp.iscp = &(lp->iscp);
 273     lp->iscp.scb = &(lp->scb);
 274     lp->iscp.stat = 0x0001;
 275     lp->cmd_backlog = 0;
 276 
 277     lp->cmd_head = lp->scb.cmd = (struct i596_cmd *) I596_NULL;
 278 
 279     if (i596_debug > 2) printk("%s: starting i82596.\n", dev->name);
 280 
 281     (void) inb (ioaddr+0x10);
 282     outb(4, ioaddr+0xf);
 283     outw(0, ioaddr+4);
 284 
 285     while (lp->iscp.stat)
 286         if (--boguscnt == 0)
 287         {
 288             printk("%s: i82596 initialization timed out with status %4.4x, cmd %4.4x.\n",
 289                    dev->name, lp->scb.status, lp->scb.command);
 290             break;
 291         }
 292 
 293     lp->scb.command = 0;
 294 
 295     memcpy (lp->i596_config, init_setup, 14);
 296     lp->set_conf.command = CmdConfigure;
 297     i596_add_cmd(dev, &lp->set_conf);
 298 
 299     memcpy (lp->eth_addr, dev->dev_addr, 6);
 300     lp->set_add.command = CmdSASetup;
 301     i596_add_cmd(dev, &lp->set_add);
 302 
 303     lp->tdr.command = CmdTDR;
 304     i596_add_cmd(dev, &lp->tdr);
 305 
 306     boguscnt = 200;
 307     while (lp->scb.status, lp->scb.command)
 308         if (--boguscnt == 0)
 309         {
 310             printk("%s: receive unit start timed out with status %4.4x, cmd %4.4x.\n",
 311                    dev->name, lp->scb.status, lp->scb.command);
 312             break;
 313         }
 314 
 315     lp->scb.command = RX_START;
 316     outw(0, ioaddr+4);
 317 
 318     boguscnt = 200;
 319     while (lp->scb.status, lp->scb.command)
 320         if (--boguscnt == 0)
 321         {
 322             printk("i82596 init timed out with status %4.4x, cmd %4.4x.\n",
 323                 lp->scb.status, lp->scb.command);
 324             break;
 325         }
 326 
 327     return;
 328 }
 329 
 330 static inline int
 331 i596_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 332 {
 333     struct i596_private *lp = (struct i596_private *)dev->priv;
 334     int frames = 0;
 335 
 336     if (i596_debug > 3) printk ("i596_rx()\n");
 337 
 338     while ((lp->scb.rfd->stat) & STAT_C)
 339     {
 340         if (i596_debug >2) print_eth(lp->scb.rfd->data);
 341 
 342         if ((lp->scb.rfd->stat) & STAT_OK)
 343         {
 344             /* a good frame */
 345             int pkt_len = lp->scb.rfd->count & 0x3fff;
 346             struct sk_buff *skb = alloc_skb(pkt_len, GFP_ATOMIC);
 347 
 348             frames++;
 349 
 350             if (skb == NULL)
 351             {
 352                 printk ("%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
 353                 lp->stats.rx_dropped++;
 354                 break;
 355             }
 356 
 357             skb->len = pkt_len;
 358             skb->dev = dev;             
 359             memcpy(skb->data, lp->scb.rfd->data, pkt_len);
 360 
 361             netif_rx(skb);
 362             lp->stats.rx_packets++;
 363 
 364             if (i596_debug > 4) print_eth(skb->data);
 365         }
 366         else
 367         {
 368             lp->stats.rx_errors++;
 369             if ((lp->scb.rfd->stat) & 0x0001) lp->stats.collisions++;
 370             if ((lp->scb.rfd->stat) & 0x0080) lp->stats.rx_length_errors++;
 371             if ((lp->scb.rfd->stat) & 0x0100) lp->stats.rx_over_errors++;
 372             if ((lp->scb.rfd->stat) & 0x0200) lp->stats.rx_fifo_errors++;
 373             if ((lp->scb.rfd->stat) & 0x0400) lp->stats.rx_frame_errors++;
 374             if ((lp->scb.rfd->stat) & 0x0800) lp->stats.rx_crc_errors++;
 375             if ((lp->scb.rfd->stat) & 0x1000) lp->stats.rx_length_errors++;
 376         }
 377 
 378         lp->scb.rfd->stat = 0;
 379         lp->rx_tail->cmd = 0;
 380         lp->rx_tail = lp->scb.rfd;
 381         lp->scb.rfd = lp->scb.rfd->next;
 382         lp->rx_tail->count = 0;
 383         lp->rx_tail->cmd = CMD_EOL;
 384 
 385     }
 386 
 387     if (i596_debug > 3) printk ("frames %d\n", frames);
 388 
 389     return 0;
 390 }
 391 
 392 static inline void
 393 i596_cleanup_cmd(struct i596_private *lp)
     /* [previous][next][first][last][top][bottom][index][help] */
 394 {
 395     struct i596_cmd *ptr;
 396     int boguscnt = 100;
 397 
 398     if (i596_debug > 4) printk ("i596_cleanup_cmd\n");
 399 
 400     while (lp->cmd_head != (struct i596_cmd *) I596_NULL)
 401     {
 402         ptr = lp->cmd_head;
 403 
 404         lp->cmd_head = lp->cmd_head->next;
 405         lp->cmd_backlog--;
 406 
 407         switch ((ptr->command) & 0x7)
 408         {
 409             case CmdTx:
 410             {
 411                 struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
 412                 struct sk_buff *skb = ((struct sk_buff *)(tx_cmd->tbd->data)) -1;
 413 
 414                 dev_kfree_skb(skb, FREE_WRITE);
 415 
 416                 lp->stats.tx_errors++;
 417                 lp->stats.tx_aborted_errors++;
 418 
 419                 ptr->next = (struct i596_cmd * ) I596_NULL;
 420                 kfree_s((unsigned char *)tx_cmd, (sizeof (struct tx_cmd) + sizeof (struct i596_tbd)));
 421                 break;
 422             }
 423             case CmdMulticastList:
 424             {
 425                 unsigned short count = *((unsigned short *) (ptr + 1));
 426 
 427                 ptr->next = (struct i596_cmd * ) I596_NULL;
 428                 kfree_s((unsigned char *)ptr, (sizeof (struct i596_cmd) + count + 2));
 429                 break;
 430             }
 431             default:
 432                 ptr->next = (struct i596_cmd * ) I596_NULL;
 433         }
 434     }
 435 
 436     while (lp->scb.status, lp->scb.command)
 437         if (--boguscnt == 0)
 438         {
 439             printk("i596_cleanup_cmd timed out with status %4.4x, cmd %4.4x.\n",
 440                 lp->scb.status, lp->scb.command);
 441             break;
 442         }
 443 
 444     lp->scb.cmd = lp->cmd_head;
 445 }
 446 
 447 static inline void
 448 i596_reset(struct device *dev, struct i596_private *lp, int ioaddr)
     /* [previous][next][first][last][top][bottom][index][help] */
 449 {
 450     int boguscnt = 100;
 451 
 452     if (i596_debug > 4) printk ("i596_reset\n");
 453 
 454     while (lp->scb.status, lp->scb.command)
 455         if (--boguscnt == 0)
 456         {
 457             printk("i596_reset timed out with status %4.4x, cmd %4.4x.\n",
 458                 lp->scb.status, lp->scb.command);
 459             break;
 460         }
 461 
 462     dev->start = 0;
 463     dev->tbusy = 1;
 464 
 465     lp->scb.command = CUC_ABORT|RX_ABORT;
 466     outw(0, ioaddr+4);
 467 
 468     /* wait for shutdown */
 469     boguscnt = 400;
 470 
 471     while ((lp->scb.status, lp->scb.command) || lp->scb.command)
 472         if (--boguscnt == 0)
 473         {
 474             printk("i596_reset 2 timed out with status %4.4x, cmd %4.4x.\n",
 475                 lp->scb.status, lp->scb.command);
 476             break;
 477         }
 478 
 479     i596_cleanup_cmd(lp);
 480     i596_rx(dev);
 481 
 482     dev->start = 1;
 483     dev->tbusy = 0;
 484     dev->interrupt = 0;
 485     init_i596_mem(dev);
 486 }
 487 
 488 static void i596_add_cmd(struct device *dev, struct i596_cmd *cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 489 {
 490     struct i596_private *lp = (struct i596_private *)dev->priv;
 491     int ioaddr = dev->base_addr;
 492     unsigned long flags;
 493     int boguscnt = 100;
 494 
 495     if (i596_debug > 4) printk ("i596_add_cmd\n");
 496 
 497     cmd->status = 0;
 498     cmd->command |= (CMD_EOL|CMD_INTR);
 499     cmd->next = (struct i596_cmd *) I596_NULL;
 500 
 501     save_flags(flags);
 502     cli();
 503     if (lp->cmd_head != (struct i596_cmd *) I596_NULL)
 504         lp->cmd_tail->next = cmd;
 505     else 
 506     {
 507         lp->cmd_head = cmd;
 508         while (lp->scb.status, lp->scb.command)
 509             if (--boguscnt == 0)
 510             {
 511                 printk("i596_add_cmd timed out with status %4.4x, cmd %4.4x.\n",
 512                    lp->scb.status, lp->scb.command);
 513                 break;
 514             }
 515 
 516         lp->scb.cmd = cmd;
 517         lp->scb.command = CUC_START;
 518         outw (0, ioaddr+4);
 519     }
 520     lp->cmd_tail = cmd;
 521     lp->cmd_backlog++;
 522 
 523     lp->cmd_head = lp->scb.cmd;
 524     restore_flags(flags);
 525 
 526     if (lp->cmd_backlog > 16) 
 527     {
 528         int tickssofar = jiffies - lp->last_cmd;
 529 
 530         if (tickssofar < 25) return;
 531 
 532         printk("%s: command unit timed out, status resetting.\n", dev->name);
 533 
 534         i596_reset(dev, lp, ioaddr);
 535     }
 536 }
 537 
 538 static int
 539 i596_open(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 540 {
 541     int i;
 542 
 543     if (i596_debug > 1)
 544         printk("%s: i596_open() irq %d.\n", dev->name, dev->irq);
 545 
 546     if (request_irq(dev->irq, &i596_interrupt, 0, "apricot"))
 547         return -EAGAIN;
 548 
 549     irq2dev_map[dev->irq] = dev;
 550 
 551      i = init_rx_bufs(dev, RX_RING_SIZE);
 552 
 553     if ((i = init_rx_bufs(dev, RX_RING_SIZE)) < RX_RING_SIZE)
 554         printk("%s: only able to allocate %d receive buffers\n", dev->name, i);
 555 
 556     if (i < 4)
 557     {
 558         free_irq(dev->irq);
 559         irq2dev_map[dev->irq] = 0;
 560         return -EAGAIN;
 561     }
 562 
 563     dev->tbusy = 0;
 564     dev->interrupt = 0;
 565     dev->start = 1;
 566 #ifdef MODULE
 567     MOD_INC_USE_COUNT;
 568 #endif
 569 
 570     /* Initialize the 82596 memory */
 571     init_i596_mem(dev);
 572 
 573     return 0;                   /* Always succeed */
 574 }
 575 
 576 static int
 577 i596_start_xmit(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 578 {
 579     struct i596_private *lp = (struct i596_private *)dev->priv;
 580     int ioaddr = dev->base_addr;
 581     struct tx_cmd *tx_cmd;
 582 
 583     if (i596_debug > 2) printk ("%s: Apricot start xmit\n", dev->name);
 584 
 585     /* Transmitter timeout, serious problems. */
 586     if (dev->tbusy) {
 587         int tickssofar = jiffies - dev->trans_start;
 588         if (tickssofar < 5)
 589             return 1;
 590         printk("%s: transmit timed out, status resetting.\n",
 591                dev->name);
 592         lp->stats.tx_errors++;
 593         /* Try to restart the adaptor */
 594         if (lp->last_restart == lp->stats.tx_packets) {
 595             if (i596_debug > 1) printk ("Resetting board.\n");
 596 
 597             /* Shutdown and restart */
 598             i596_reset(dev,lp, ioaddr);
 599         } else {
 600             /* Issue a channel attention signal */
 601             if (i596_debug > 1) printk ("Kicking board.\n");
 602 
 603             lp->scb.command = CUC_START|RX_START;
 604             outw(0, ioaddr+4);
 605 
 606             lp->last_restart = lp->stats.tx_packets;
 607         }
 608         dev->tbusy = 0;
 609         dev->trans_start = jiffies;
 610     }
 611 
 612     /* If some higher level thinks we've misses a tx-done interrupt
 613        we are passed NULL. n.b. dev_tint handles the cli()/sti()
 614        itself. */
 615     if (skb == NULL) {
 616         dev_tint(dev);
 617         return 0;
 618     }
 619 
 620     /* shouldn't happen */
 621     if (skb->len <= 0) return 0;
 622 
 623     if (i596_debug > 3) printk("%s: i596_start_xmit() called\n", dev->name);
 624 
 625     /* Block a timer-based transmit from overlapping.  This could better be
 626        done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
 627     if (set_bit(0, (void*)&dev->tbusy) != 0)
 628         printk("%s: Transmitter access conflict.\n", dev->name);
 629     else
 630     {
 631         short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
 632         dev->trans_start = jiffies;
 633 
 634         tx_cmd = (struct tx_cmd *) kmalloc ((sizeof (struct tx_cmd) + sizeof (struct i596_tbd)), GFP_ATOMIC);
 635         if (tx_cmd == NULL)
 636         {
 637             printk ("%s: i596_xmit Memory squeeze, dropping packet.\n", dev->name);
 638             lp->stats.tx_dropped++;
 639 
 640             dev_kfree_skb(skb, FREE_WRITE);
 641         }
 642         else
 643         {
 644             tx_cmd->tbd = (struct i596_tbd *) (tx_cmd + 1);
 645             tx_cmd->tbd->next = (struct i596_tbd *) I596_NULL;
 646 
 647             tx_cmd->cmd.command = CMD_FLEX|CmdTx;
 648 
 649             tx_cmd->pad = 0;
 650             tx_cmd->size = 0;
 651             tx_cmd->tbd->pad = 0;
 652             tx_cmd->tbd->size = EOF | length;
 653 
 654             tx_cmd->tbd->data = skb->data;
 655 
 656             if (i596_debug > 3) print_eth(skb->data);
 657 
 658             i596_add_cmd(dev, (struct i596_cmd *)tx_cmd);
 659 
 660             lp->stats.tx_packets++;
 661         }
 662     }
 663 
 664     dev->tbusy = 0;
 665 
 666     return 0;
 667 }
 668 
 669 
 670 static void print_eth(char *add)
     /* [previous][next][first][last][top][bottom][index][help] */
 671 {
 672     int i;
 673 
 674     printk ("Dest  ");
 675     for (i = 0; i < 6; i++)
 676         printk(" %2.2X", (unsigned char)add[i]);
 677     printk ("\n");
 678 
 679     printk ("Source");
 680     for (i = 0; i < 6; i++)
 681         printk(" %2.2X", (unsigned char)add[i+6]);
 682     printk ("\n");
 683     printk ("type %2.2X%2.2X\n", (unsigned char)add[12], (unsigned char)add[13]);
 684 }
 685 
 686 int apricot_probe(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 687 {
 688     int i;
 689     struct i596_private *lp;
 690     int checksum = 0;
 691     int ioaddr = 0x300;
 692     char eth_addr[6];
 693     
 694     /* this is easy the ethernet interface can only be at 0x300 */
 695     /* first check nothing is already registered here */
 696 
 697     if (check_region(ioaddr, APRICOT_TOTAL_SIZE))
 698         return ENODEV;
 699 
 700     for (i = 0; i < 8; i++)
 701     {
 702         eth_addr[i] = inb(ioaddr+8+i);
 703         checksum += eth_addr[i];
 704      }
 705 
 706     /* checksum is a multiple of 0x100, got this wrong first time
 707        some machines have 0x100, some 0x200. The DOS driver doesn't
 708        even bother with the checksum */
 709 
 710     if (checksum % 0x100) return ENODEV;
 711 
 712     /* Some other boards trip the checksum.. but then appear as ether
 713        address 0. Trap these - AC */
 714        
 715     if(memcmp(eth_addr,"\x00\x00\x49",3)!= 0)
 716         return ENODEV;
 717 
 718     snarf_region(ioaddr, APRICOT_TOTAL_SIZE);
 719 
 720     dev->base_addr = ioaddr;
 721     ether_setup(dev);
 722     printk("%s: Apricot 82596 at %#3x,", dev->name, ioaddr);
 723 
 724     for (i = 0; i < 6; i++)
 725         printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]);
 726 
 727     dev->base_addr = ioaddr;
 728     dev->irq = 10;
 729     printk(" IRQ %d.\n", dev->irq);
 730 
 731     if (i596_debug > 0) printk(version);
 732 
 733     /* The APRICOT-specific entries in the device structure. */
 734     dev->open = &i596_open;
 735     dev->stop = &i596_close;
 736     dev->hard_start_xmit = &i596_start_xmit;
 737     dev->get_stats = &i596_get_stats;
 738 #ifdef HAVE_MULTICAST
 739     dev->set_multicast_list = &set_multicast_list;
 740 #endif
 741 
 742     dev->mem_start = (int)kmalloc(sizeof(struct i596_private)+ 0x0f, GFP_KERNEL);
 743     /* align for scp */
 744     dev->priv = (void *)((dev->mem_start + 0xf) & 0xfffffff0);
 745 
 746     lp = (struct i596_private *)dev->priv;
 747     lp->scb.command = 0;
 748     lp->scb.cmd = (struct i596_cmd *) I596_NULL;
 749     lp->scb.rfd = (struct i596_rfd *)I596_NULL;
 750 
 751     return 0;
 752 }
 753 
 754 static void
 755 i596_interrupt(int reg_ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
 756 {
 757     int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
 758     struct device *dev = (struct device *)(irq2dev_map[irq]);
 759     struct i596_private *lp;
 760     short ioaddr;
 761     int boguscnt = 200;
 762     unsigned short status, ack_cmd = 0;
 763 
 764     if (dev == NULL) {
 765         printk ("i596_interrupt(): irq %d for unknown device.\n", irq);
 766         return;
 767     }
 768 
 769     if (i596_debug > 3) printk ("%s: i596_interrupt(): irq %d\n",dev->name, irq);
 770 
 771     if (dev->interrupt)
 772         printk("%s: Re-entering the interrupt handler.\n", dev->name);
 773 
 774     dev->interrupt = 1;
 775 
 776     ioaddr = dev->base_addr;
 777 
 778     lp = (struct i596_private *)dev->priv;
 779 
 780     while (lp->scb.status, lp->scb.command)
 781         if (--boguscnt == 0)
 782             {
 783                 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev->name, lp->scb.status, lp->scb.command);
 784                 break;
 785             }
 786     status = lp->scb.status;
 787 
 788     if (i596_debug > 4)
 789         printk("%s: i596 interrupt, status %4.4x.\n", dev->name, status);
 790 
 791     ack_cmd = status & 0xf000;
 792 
 793     if ((status & 0x8000) || (status & 0x2000))
 794     {
 795         struct i596_cmd *ptr;
 796 
 797         if ((i596_debug > 4) && (status & 0x8000))
 798             printk("%s: i596 interrupt completed command.\n", dev->name);
 799         if ((i596_debug > 4) && (status & 0x2000))
 800             printk("%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700);
 801 
 802         while ((lp->cmd_head != (struct i596_cmd *) I596_NULL) && (lp->cmd_head->status & STAT_C))
 803         {
 804             ptr = lp->cmd_head;
 805 
 806             lp->cmd_head = lp->cmd_head->next;
 807             lp->cmd_backlog--;
 808 
 809             switch ((ptr->command) & 0x7)
 810             {
 811                 case CmdTx:
 812                 {
 813                     struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
 814                     struct sk_buff *skb = ((struct sk_buff *)(tx_cmd->tbd->data)) -1;
 815 
 816                     dev_kfree_skb(skb, FREE_WRITE);
 817 
 818                     if ((ptr->status) & STAT_OK)
 819                     {
 820                         if (i596_debug >2) print_eth(skb->data);
 821                     }
 822                     else
 823                     {
 824                         lp->stats.tx_errors++;
 825                         if ((ptr->status) & 0x0020) lp->stats.collisions++;
 826                         if (!((ptr->status) & 0x0040)) lp->stats.tx_heartbeat_errors++;
 827                         if ((ptr->status) & 0x0400) lp->stats.tx_carrier_errors++;
 828                         if ((ptr->status) & 0x0800) lp->stats.collisions++;
 829                         if ((ptr->status) & 0x1000) lp->stats.tx_aborted_errors++;
 830                     }
 831 
 832 
 833                     ptr->next = (struct i596_cmd * ) I596_NULL;
 834                     kfree_s((unsigned char *)tx_cmd, (sizeof (struct tx_cmd) + sizeof (struct i596_tbd)));
 835                     break;
 836                 }
 837                 case CmdMulticastList:
 838                 {
 839                     unsigned short count = *((unsigned short *) (ptr + 1));
 840 
 841                     ptr->next = (struct i596_cmd * ) I596_NULL;
 842                     kfree_s((unsigned char *)ptr, (sizeof (struct i596_cmd) + count + 2));
 843                     break;
 844                 }
 845                 case CmdTDR:
 846                 {
 847                     unsigned long status = *((unsigned long *) (ptr + 1));
 848 
 849                     if (status & 0x8000)
 850                     {
 851                         if (i596_debug > 3)
 852                             printk("%s: link ok.\n", dev->name);
 853                     }
 854                     else
 855                     {
 856                         if (status & 0x4000)
 857                             printk("%s: Transceiver problem.\n", dev->name);
 858                         if (status & 0x2000)
 859                             printk("%s: Termination problem.\n", dev->name);
 860                         if (status & 0x1000)
 861                             printk("%s: Short circuit.\n", dev->name);
 862 
 863                         printk("%s: Time %ld.\n", dev->name, status & 0x07ff);
 864                     }
 865                 }
 866                 default:
 867                     ptr->next = (struct i596_cmd * ) I596_NULL;
 868 
 869                 lp->last_cmd = jiffies;
 870             }
 871         }
 872 
 873         ptr = lp->cmd_head;
 874         while ((ptr != (struct i596_cmd *) I596_NULL) && (ptr != lp->cmd_tail))
 875         {
 876             ptr->command &= 0x1fff;
 877             ptr = ptr->next;
 878         }
 879 
 880         if ((lp->cmd_head != (struct i596_cmd *) I596_NULL) && (dev->start)) ack_cmd |= CUC_START;
 881         lp->scb.cmd = lp->cmd_head;
 882     }
 883 
 884     if ((status & 0x1000) || (status & 0x4000))
 885     {
 886         if ((i596_debug > 4) && (status & 0x4000))
 887             printk("%s: i596 interrupt received a frame.\n", dev->name);
 888         if ((i596_debug > 4) && (status & 0x1000))
 889             printk("%s: i596 interrupt receive unit inactive %x.\n", dev->name, status & 0x0070);
 890 
 891         i596_rx(dev);
 892 
 893         if (dev->start) ack_cmd |= RX_START;
 894     }
 895 
 896     /* acknowledge the interrupt */
 897 
 898 /*
 899     if ((lp->scb.cmd != (struct i596_cmd *) I596_NULL) && (dev->start)) ack_cmd | = CUC_START;
 900 */
 901     boguscnt = 100;
 902     while (lp->scb.status, lp->scb.command)
 903         if (--boguscnt == 0)
 904             {
 905                 printk("%s: i596 interrupt, timeout status %4.4x command %4.4x.\n", dev->name, lp->scb.status, lp->scb.command);
 906                 break;
 907             }
 908     lp->scb.command = ack_cmd;
 909 
 910     (void) inb (ioaddr+0x10);
 911     outb (4, ioaddr+0xf);
 912     outw (0, ioaddr+4);
 913 
 914     if (i596_debug > 4)
 915         printk("%s: exiting interrupt.\n", dev->name);
 916 
 917     dev->interrupt = 0;
 918     return;
 919 }
 920 
 921 static int
 922 i596_close(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 923 {
 924     int ioaddr = dev->base_addr;
 925     struct i596_private *lp = (struct i596_private *)dev->priv;
 926     int boguscnt = 200;
 927 
 928     dev->start = 0;
 929     dev->tbusy = 1;
 930 
 931     if (i596_debug > 1)
 932         printk("%s: Shutting down ethercard, status was %4.4x.\n",
 933                dev->name, lp->scb.status);
 934 
 935     lp->scb.command = CUC_ABORT|RX_ABORT;
 936     outw(0, ioaddr+4);
 937 
 938     i596_cleanup_cmd(lp);
 939 
 940     while (lp->scb.status, lp->scb.command)
 941         if (--boguscnt == 0)
 942         {
 943             printk("%s: close timed timed out with status %4.4x, cmd %4.4x.\n",
 944                    dev->name, lp->scb.status, lp->scb.command);
 945             break;
 946         }
 947     free_irq(dev->irq);
 948     irq2dev_map[dev->irq] = 0;
 949     remove_rx_bufs(dev);
 950 #ifdef MODULE
 951     MOD_DEC_USE_COUNT;
 952 #endif
 953 
 954 
 955     return 0;
 956 }
 957 
 958 static struct enet_statistics *
 959 i596_get_stats(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 960 {
 961     struct i596_private *lp = (struct i596_private *)dev->priv;
 962 
 963     return &lp->stats;
 964 }
 965 
 966 #ifdef HAVE_MULTICAST
 967 /* Set or clear the multicast filter for this adaptor.
 968    num_addrs == -1      Promiscuous mode, receive all packets
 969    num_addrs == 0       Normal mode, clear multicast list
 970    num_addrs > 0        Multicast mode, receive normal and MC packets, and do
 971                         best-effort filtering.
 972  */
 973 static void
 974 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
     /* [previous][next][first][last][top][bottom][index][help] */
 975 {
 976     struct i596_private *lp = (struct i596_private *)dev->priv;
 977     struct i596_cmd *cmd;
 978 
 979     if (i596_debug > 1)
 980         printk ("%s: set multicast list %d\n", dev->name, num_addrs);
 981 
 982     if (num_addrs > 0) {
 983         cmd = (struct i596_cmd *) kmalloc(sizeof(struct i596_cmd)+2+num_addrs*6, GFP_ATOMIC);
 984         if (cmd == NULL)
 985         {
 986             printk ("%s: set_multicast Memory squeeze.\n", dev->name);
 987             return;
 988         }
 989 
 990             cmd->command = CmdMulticastList;
 991             *((unsigned short *) (cmd + 1)) = num_addrs * 6;
 992             memcpy (((char *)(cmd + 1))+2, addrs, num_addrs * 6);
 993             print_eth (((char *)(cmd + 1)) + 2);
 994                 
 995             i596_add_cmd(dev, cmd);
 996     } else
 997     {
 998         if (lp->set_conf.next != (struct i596_cmd * ) I596_NULL) return;
 999         if (num_addrs == 0)
1000             lp->i596_config[8] &= ~0x01;
1001         else
1002             lp->i596_config[8] |= 0x01;
1003 
1004         i596_add_cmd(dev, &lp->set_conf);
1005     }
1006 
1007 }
1008 #endif
1009 
1010 #ifdef HAVE_DEVLIST
1011 static unsigned int apricot_portlist[] = {0x300, 0};
1012 struct netdev_entry apricot_drv = 
1013 {"apricot", apricot_probe, APRICOT_TOTAL_SIZE, apricot_portlist};
1014 #endif
1015 
1016 #ifdef MODULE
1017 char kernel_version[] = UTS_RELEASE;
1018 static struct device dev_apricot = {
1019   "        ", /* device name inserted by /linux/drivers/net/net_init.c */
1020   0, 0, 0, 0,
1021   0x300, 10,
1022   0, 0, 0, NULL, apricot_probe };
1023 
1024 int
1025 init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1026 {
1027   if (register_netdev(&dev_apricot) != 0)
1028     return -EIO;
1029   return 0;
1030 }
1031 
1032 void
1033 cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1034 {
1035   if (MOD_IN_USE)
1036     printk("%s: device busy, remove delayed\n", dev_apricot.name);
1037   else
1038   {
1039     unregister_netdev(&dev_apricot);
1040     kfree_s((void *)dev_apricot.mem_start, sizeof(struct i596_private) + 0xf);
1041     dev_apricot.priv = NULL;
1042   }
1043 }
1044 #endif /* MODULE */
1045 
1046 /*
1047  * Local variables:
1048  *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c apricot.c"
1049  * End:
1050  */

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