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 #ifdef MODULE
  25 #include <linux/module.h>
  26 #include <linux/version.h>
  27 #endif
  28 
  29 #include <linux/kernel.h>
  30 #include <linux/sched.h>
  31 #include <linux/string.h>
  32 #include <linux/ptrace.h>
  33 #include <linux/errno.h>
  34 #include <linux/ioport.h>
  35 #include <linux/malloc.h>
  36 #include <linux/interrupt.h>
  37 #include <asm/bitops.h>
  38 #include <asm/io.h>
  39 #include <asm/dma.h>
  40 
  41 #include <linux/netdevice.h>
  42 #include <linux/etherdevice.h>
  43 #include <linux/skbuff.h>
  44 
  45 #ifndef HAVE_PORTRESERVE
  46 #define check_region(addr, size)        0
  47 #define request_region(addr, size,name) do ; while(0)
  48 #endif
  49 
  50 #ifndef HAVE_ALLOC_SKB
  51 #define alloc_skb(size, priority) (struct sk_buff *) kmalloc(size,priority)
  52 #define kfree_skbmem(buff, size) kfree_s(buff,size)
  53 #endif
  54 
  55 #define APRICOT_DEBUG 1
  56 
  57 #ifdef APRICOT_DEBUG
  58 int i596_debug = APRICOT_DEBUG;
  59 #else
  60 int i596_debug = 1;
  61 #endif
  62 
  63 #define APRICOT_TOTAL_SIZE 17
  64 
  65 #define I596_NULL -1
  66 
  67 #define CMD_EOL         0x8000  /* The last command of the list, stop. */
  68 #define CMD_SUSP        0x4000  /* Suspend after doing cmd. */
  69 #define CMD_INTR        0x2000  /* Interrupt after doing cmd. */
  70 
  71 #define CMD_FLEX        0x0008  /* Enable flexible memory model */
  72 
  73 enum commands {
  74         CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
  75         CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7};
  76 
  77 #define STAT_C          0x8000  /* Set to 0 after execution */
  78 #define STAT_B          0x4000  /* Command being executed */
  79 #define STAT_OK         0x2000  /* Command executed ok */
  80 #define STAT_A          0x1000  /* Command aborted */
  81 
  82 #define  CUC_START      0x0100
  83 #define  CUC_RESUME     0x0200
  84 #define  CUC_SUSPEND    0x0300
  85 #define  CUC_ABORT      0x0400
  86 #define  RX_START       0x0010
  87 #define  RX_RESUME      0x0020
  88 #define  RX_SUSPEND     0x0030
  89 #define  RX_ABORT       0x0040
  90 
  91 struct i596_cmd {
  92     unsigned short status;
  93     unsigned short command;
  94     struct i596_cmd *next;
  95 };
  96 
  97 #define EOF             0x8000
  98 #define SIZE_MASK       0x3fff
  99 
 100 struct i596_tbd {
 101     unsigned short size;
 102     unsigned short pad;
 103     struct i596_tbd *next;
 104     char *data;
 105 };
 106 
 107 struct tx_cmd {
 108     struct i596_cmd cmd;
 109     struct i596_tbd *tbd;
 110     unsigned short size;
 111     unsigned short pad;
 112 };
 113 
 114 struct i596_rfd {
 115     unsigned short stat;
 116     unsigned short cmd;
 117     struct i596_rfd *next;
 118     long rbd; 
 119     unsigned short count;
 120     unsigned short size;
 121     char data[1532];
 122 };
 123 
 124 #define RX_RING_SIZE 8
 125 
 126 struct i596_scb {
 127     unsigned short status;
 128     unsigned short command;
 129     struct i596_cmd *cmd;
 130     struct i596_rfd *rfd;
 131     unsigned long crc_err;
 132     unsigned long align_err;
 133     unsigned long resource_err;
 134     unsigned long over_err;
 135     unsigned long rcvdt_err;
 136     unsigned long short_err;
 137     unsigned short t_on;
 138     unsigned short t_off;
 139 };
 140 
 141 struct i596_iscp {
 142     unsigned long stat;
 143     struct i596_scb *scb;
 144 };
 145 
 146 struct i596_scp {
 147     unsigned long sysbus;
 148     unsigned long pad;
 149     struct i596_iscp *iscp;
 150 };
 151 
 152 struct i596_private {
 153     struct i596_scp scp;
 154     struct i596_iscp iscp;
 155     struct i596_scb scb;
 156     struct i596_cmd set_add;
 157     char eth_addr[8];
 158     struct i596_cmd set_conf;
 159     char i596_config[16];
 160     struct i596_cmd tdr;
 161     unsigned long stat;
 162     int last_restart;
 163     struct i596_rfd *rx_tail;
 164     struct i596_cmd *cmd_tail;
 165     struct i596_cmd *cmd_head;
 166     int cmd_backlog;
 167     unsigned long last_cmd;
 168     struct enet_statistics stats;
 169 };
 170 
 171 char init_setup[] = {
 172         0x8E,   /* length, prefetch on */
 173         0xC8,   /* fifo to 8, monitor off */
 174         0x80,   /* don't save bad frames */
 175         0x2E,   /* No source address insertion, 8 byte preamble */
 176         0x00,   /* priority and backoff defaults */
 177         0x60,   /* interframe spacing */
 178         0x00,   /* slot time LSB */
 179         0xf2,   /* slot time and retries */
 180         0x00,   /* promiscuous mode */
 181         0x00,   /* collision detect */
 182         0x40,   /* minimum frame length */
 183         0xff,   
 184         0x00,
 185         0x7f    /*  *multi IA */ };
 186 
 187 static int i596_open(struct device *dev);
 188 static int i596_start_xmit(struct sk_buff *skb, struct device *dev);
 189 static void i596_interrupt(int irq, struct pt_regs *regs);
 190 static int i596_close(struct device *dev);
 191 static struct enet_statistics *i596_get_stats(struct device *dev);
 192 static void i596_add_cmd(struct device *dev, struct i596_cmd *cmd);
 193 static void print_eth(char *);
 194 #ifdef HAVE_MULTICAST
 195 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
 196 #endif
 197 
 198 
 199 static inline int
 200 init_rx_bufs(struct device *dev, int num)
     /* [previous][next][first][last][top][bottom][index][help] */
 201 {
 202     struct i596_private *lp = (struct i596_private *)dev->priv;
 203     int i;
 204     struct i596_rfd *rfd;
 205 
 206     lp->scb.rfd = (struct i596_rfd *)I596_NULL;
 207 
 208     if (i596_debug > 1) printk ("%s: init_rx_bufs %d.\n", dev->name, num);
 209 
 210     for (i = 0; i < num; i++)
 211     {
 212         if (!(rfd = (struct i596_rfd *)kmalloc(sizeof(struct i596_rfd), GFP_KERNEL)))
 213             break;
 214 
 215         rfd->stat = 0x0000;
 216         rfd->rbd = I596_NULL;
 217         rfd->count = 0;
 218         rfd->size = 1532;
 219         if (i == 0)
 220         {
 221             rfd->cmd = CMD_EOL;
 222             lp->rx_tail = rfd;
 223         }
 224         else
 225             rfd->cmd = 0x0000;
 226 
 227         rfd->next = lp->scb.rfd;
 228         lp->scb.rfd = rfd;
 229     }
 230 
 231     if (i != 0)
 232       lp->rx_tail->next = lp->scb.rfd;
 233 
 234     return (i);
 235 }
 236 
 237 static inline void
 238 remove_rx_bufs(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 239 {
 240     struct i596_private *lp = (struct i596_private *)dev->priv;
 241     struct i596_rfd *rfd = lp->scb.rfd;
 242 
 243     lp->rx_tail->next = (struct i596_rfd *)I596_NULL;
 244 
 245     do
 246     {
 247         lp->scb.rfd = rfd->next;
 248         kfree_s(rfd, sizeof(struct i596_rfd));
 249         rfd = lp->scb.rfd;
 250     }
 251     while (rfd != lp->rx_tail);
 252 }
 253 
 254 static inline void
 255 init_i596_mem(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 256 {
 257     struct i596_private *lp = (struct i596_private *)dev->priv;
 258     short ioaddr = dev->base_addr;
 259     int boguscnt = 100;
 260 
 261     /* change the scp address */
 262     outw(0, ioaddr);
 263     outw(0, ioaddr);
 264     outb(4, ioaddr+0xf);
 265     outw(((((int)&lp->scp) & 0xffff) | 2), ioaddr);
 266     outw((((int)&lp->scp)>>16) & 0xffff, ioaddr);
 267 
 268     lp->last_cmd = jiffies;
 269 
 270     lp->scp.sysbus = 0x00440000;
 271     lp->scp.iscp = &(lp->iscp);
 272     lp->iscp.scb = &(lp->scb);
 273     lp->iscp.stat = 0x0001;
 274     lp->cmd_backlog = 0;
 275 
 276     lp->cmd_head = lp->scb.cmd = (struct i596_cmd *) I596_NULL;
 277 
 278     if (i596_debug > 2) printk("%s: starting i82596.\n", dev->name);
 279 
 280     (void) inb (ioaddr+0x10);
 281     outb(4, ioaddr+0xf);
 282     outw(0, ioaddr+4);
 283 
 284     while (lp->iscp.stat)
 285         if (--boguscnt == 0)
 286         {
 287             printk("%s: i82596 initialization timed out with status %4.4x, cmd %4.4x.\n",
 288                    dev->name, lp->scb.status, lp->scb.command);
 289             break;
 290         }
 291 
 292     lp->scb.command = 0;
 293 
 294     memcpy (lp->i596_config, init_setup, 14);
 295     lp->set_conf.command = CmdConfigure;
 296     i596_add_cmd(dev, &lp->set_conf);
 297 
 298     memcpy (lp->eth_addr, dev->dev_addr, 6);
 299     lp->set_add.command = CmdSASetup;
 300     i596_add_cmd(dev, &lp->set_add);
 301 
 302     lp->tdr.command = CmdTDR;
 303     i596_add_cmd(dev, &lp->tdr);
 304 
 305     boguscnt = 200;
 306     while (lp->scb.status, lp->scb.command)
 307         if (--boguscnt == 0)
 308         {
 309             printk("%s: receive unit start timed out with status %4.4x, cmd %4.4x.\n",
 310                    dev->name, lp->scb.status, lp->scb.command);
 311             break;
 312         }
 313 
 314     lp->scb.command = RX_START;
 315     outw(0, ioaddr+4);
 316 
 317     boguscnt = 200;
 318     while (lp->scb.status, lp->scb.command)
 319         if (--boguscnt == 0)
 320         {
 321             printk("i82596 init timed out with status %4.4x, cmd %4.4x.\n",
 322                 lp->scb.status, lp->scb.command);
 323             break;
 324         }
 325 
 326     return;
 327 }
 328 
 329 static inline int
 330 i596_rx(struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 331 {
 332     struct i596_private *lp = (struct i596_private *)dev->priv;
 333     int frames = 0;
 334 
 335     if (i596_debug > 3) printk ("i596_rx()\n");
 336 
 337     while ((lp->scb.rfd->stat) & STAT_C)
 338     {
 339         if (i596_debug >2) print_eth(lp->scb.rfd->data);
 340 
 341         if ((lp->scb.rfd->stat) & STAT_OK)
 342         {
 343             /* a good frame */
 344             int pkt_len = lp->scb.rfd->count & 0x3fff;
 345             struct sk_buff *skb = alloc_skb(pkt_len, GFP_ATOMIC);
 346 
 347             frames++;
 348 
 349             if (skb == NULL)
 350             {
 351                 printk ("%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
 352                 lp->stats.rx_dropped++;
 353                 break;
 354             }
 355 
 356             skb->len = pkt_len;
 357             skb->dev = dev;             
 358             memcpy(skb->data, lp->scb.rfd->data, pkt_len);
 359 
 360             skb->protocol=eth_type_trans(skb,dev);
 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     request_region(ioaddr, APRICOT_TOTAL_SIZE,"apricot");
 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     memset((void *)lp, 0, sizeof(struct i596_private));
 748     lp->scb.command = 0;
 749     lp->scb.cmd = (struct i596_cmd *) I596_NULL;
 750     lp->scb.rfd = (struct i596_rfd *)I596_NULL;
 751 
 752     return 0;
 753 }
 754 
 755 static void
 756 i596_interrupt(int irq, struct pt_regs *regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 757 {
 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] */