linux-bk/drivers/net/82596.c
<<
>>
Prefs
   1/* 82596.c: A generic 82596 ethernet driver for linux. */
   2/*
   3   Based on Apricot.c
   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
  10   Modified to support the 82596 ethernet chips on 680x0 VME boards.
  11   by Richard Hirst <richard@sleepie.demon.co.uk>
  12   Renamed to be 82596.c
  13
  14   980825:  Changed to receive directly in to sk_buffs which are
  15   allocated at open() time.  Eliminates copy on incoming frames
  16   (small ones are still copied).  Shared data now held in a
  17   non-cached page, so we can run on 68060 in copyback mode.
  18
  19   TBD:
  20   * look at deferring rx frames rather than discarding (as per tulip)
  21   * handle tx ring full as per tulip
  22   * performace test to tune rx_copybreak
  23
  24   Most of my modifications relate to the braindead big-endian
  25   implementation by Intel.  When the i596 is operating in
  26   'big-endian' mode, it thinks a 32 bit value of 0x12345678
  27   should be stored as 0x56781234.  This is a real pain, when
  28   you have linked lists which are shared by the 680x0 and the
  29   i596.
  30
  31   Driver skeleton
  32   Written 1993 by Donald Becker.
  33   Copyright 1993 United States Government as represented by the Director,
  34   National Security Agency. This software may only be used and distributed
  35   according to the terms of the GNU General Public License as modified by SRC,
  36   incorporated herein by reference.
  37
  38   The author may be reached as becker@scyld.com, or C/O
  39   Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
  40
  41 */
  42
  43#include <linux/config.h>
  44#include <linux/module.h>
  45
  46#include <linux/kernel.h>
  47#include <linux/sched.h>
  48#include <linux/string.h>
  49#include <linux/errno.h>
  50#include <linux/ioport.h>
  51#include <linux/slab.h>
  52#include <linux/interrupt.h>
  53#include <linux/delay.h>
  54#include <linux/netdevice.h>
  55#include <linux/etherdevice.h>
  56#include <linux/skbuff.h>
  57#include <linux/init.h>
  58
  59#include <asm/bitops.h>
  60#include <asm/io.h>
  61#include <asm/dma.h>
  62#include <asm/pgtable.h>
  63#include <asm/pgalloc.h>
  64
  65static char version[] __initdata =
  66        "82596.c $Revision: 1.5 $\n";
  67
  68/* DEBUG flags
  69 */
  70
  71#define DEB_INIT        0x0001
  72#define DEB_PROBE       0x0002
  73#define DEB_SERIOUS     0x0004
  74#define DEB_ERRORS      0x0008
  75#define DEB_MULTI       0x0010
  76#define DEB_TDR         0x0020
  77#define DEB_OPEN        0x0040
  78#define DEB_RESET       0x0080
  79#define DEB_ADDCMD      0x0100
  80#define DEB_STATUS      0x0200
  81#define DEB_STARTTX     0x0400
  82#define DEB_RXADDR      0x0800
  83#define DEB_TXADDR      0x1000
  84#define DEB_RXFRAME     0x2000
  85#define DEB_INTS        0x4000
  86#define DEB_STRUCT      0x8000
  87#define DEB_ANY         0xffff
  88
  89
  90#define DEB(x,y)        if (i596_debug & (x)) y
  91
  92
  93#if defined(CONFIG_MVME16x_NET) || defined(CONFIG_MVME16x_NET_MODULE)
  94#define ENABLE_MVME16x_NET
  95#endif
  96#if defined(CONFIG_BVME6000_NET) || defined(CONFIG_BVME6000_NET_MODULE)
  97#define ENABLE_BVME6000_NET
  98#endif
  99#if defined(CONFIG_APRICOT) || defined(CONFIG_APRICOT_MODULE)
 100#define ENABLE_APRICOT
 101#endif
 102
 103#ifdef ENABLE_MVME16x_NET
 104#include <asm/mvme16xhw.h>
 105#endif
 106#ifdef ENABLE_BVME6000_NET
 107#include <asm/bvme6000hw.h>
 108#endif
 109
 110/*
 111 * Define various macros for Channel Attention, word swapping etc., dependent
 112 * on architecture.  MVME and BVME are 680x0 based, otherwise it is Intel.
 113 */
 114
 115#ifdef __mc68000__
 116#define WSWAPrfd(x)  ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
 117#define WSWAPrbd(x)  ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
 118#define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16)))
 119#define WSWAPscb(x)  ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
 120#define WSWAPcmd(x)  ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
 121#define WSWAPtbd(x)  ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
 122#define WSWAPchar(x) ((char *)            (((u32)(x)<<16) | ((((u32)(x)))>>16)))
 123#define ISCP_BUSY       0x00010000
 124#define MACH_IS_APRICOT 0
 125#else
 126#define WSWAPrfd(x)     ((struct i596_rfd *)(x))
 127#define WSWAPrbd(x)     ((struct i596_rbd *)(x))
 128#define WSWAPiscp(x)    ((struct i596_iscp *)(x))
 129#define WSWAPscb(x)     ((struct i596_scb *)(x))
 130#define WSWAPcmd(x)     ((struct i596_cmd *)(x))
 131#define WSWAPtbd(x)     ((struct i596_tbd *)(x))
 132#define WSWAPchar(x)    ((char *)(x))
 133#define ISCP_BUSY       0x0001
 134#define MACH_IS_APRICOT 1
 135#endif
 136
 137/*
 138 * The MPU_PORT command allows direct access to the 82596. With PORT access
 139 * the following commands are available (p5-18). The 32-bit port command
 140 * must be word-swapped with the most significant word written first.
 141 * This only applies to VME boards.
 142 */
 143#define PORT_RESET              0x00    /* reset 82596 */
 144#define PORT_SELFTEST           0x01    /* selftest */
 145#define PORT_ALTSCP             0x02    /* alternate SCB address */
 146#define PORT_ALTDUMP            0x03    /* Alternate DUMP address */
 147
 148static int i596_debug = (DEB_SERIOUS|DEB_PROBE);
 149
 150MODULE_AUTHOR("Richard Hirst");
 151MODULE_DESCRIPTION("i82596 driver");
 152MODULE_LICENSE("GPL");
 153
 154MODULE_PARM(i596_debug, "i");
 155MODULE_PARM_DESC(i596_debug, "i82596 debug mask");
 156
 157
 158/* Copy frames shorter than rx_copybreak, otherwise pass on up in
 159 * a full sized sk_buff.  Value of 100 stolen from tulip.c (!alpha).
 160 */
 161static int rx_copybreak = 100;
 162
 163#define PKT_BUF_SZ      1536
 164#define MAX_MC_CNT      64
 165
 166#define I596_TOTAL_SIZE 17
 167
 168#define I596_NULL ((void *)0xffffffff)
 169
 170#define CMD_EOL         0x8000  /* The last command of the list, stop. */
 171#define CMD_SUSP        0x4000  /* Suspend after doing cmd. */
 172#define CMD_INTR        0x2000  /* Interrupt after doing cmd. */
 173
 174#define CMD_FLEX        0x0008  /* Enable flexible memory model */
 175
 176enum commands {
 177        CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
 178        CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7
 179};
 180
 181#define STAT_C          0x8000  /* Set to 0 after execution */
 182#define STAT_B          0x4000  /* Command being executed */
 183#define STAT_OK         0x2000  /* Command executed ok */
 184#define STAT_A          0x1000  /* Command aborted */
 185
 186#define  CUC_START      0x0100
 187#define  CUC_RESUME     0x0200
 188#define  CUC_SUSPEND    0x0300
 189#define  CUC_ABORT      0x0400
 190#define  RX_START       0x0010
 191#define  RX_RESUME      0x0020
 192#define  RX_SUSPEND     0x0030
 193#define  RX_ABORT       0x0040
 194
 195#define TX_TIMEOUT      5
 196
 197
 198struct i596_reg {
 199        unsigned short porthi;
 200        unsigned short portlo;
 201        unsigned long ca;
 202};
 203
 204#define EOF             0x8000
 205#define SIZE_MASK       0x3fff
 206
 207struct i596_tbd {
 208        unsigned short size;
 209        unsigned short pad;
 210        struct i596_tbd *next;
 211        char *data;
 212};
 213
 214/* The command structure has two 'next' pointers; v_next is the address of
 215 * the next command as seen by the CPU, b_next is the address of the next
 216 * command as seen by the 82596.  The b_next pointer, as used by the 82596
 217 * always references the status field of the next command, rather than the
 218 * v_next field, because the 82596 is unaware of v_next.  It may seem more
 219 * logical to put v_next at the end of the structure, but we cannot do that
 220 * because the 82596 expects other fields to be there, depending on command
 221 * type.
 222 */
 223
 224struct i596_cmd {
 225        struct i596_cmd *v_next;        /* Address from CPUs viewpoint */
 226        unsigned short status;
 227        unsigned short command;
 228        struct i596_cmd *b_next;        /* Address from i596 viewpoint */
 229};
 230
 231struct tx_cmd {
 232        struct i596_cmd cmd;
 233        struct i596_tbd *tbd;
 234        unsigned short size;
 235        unsigned short pad;
 236        struct sk_buff *skb;    /* So we can free it after tx */
 237};
 238
 239struct tdr_cmd {
 240        struct i596_cmd cmd;
 241        unsigned short status;
 242        unsigned short pad;
 243};
 244
 245struct mc_cmd {
 246        struct i596_cmd cmd;
 247        short mc_cnt;
 248        char mc_addrs[MAX_MC_CNT*6];
 249};
 250
 251struct sa_cmd {
 252        struct i596_cmd cmd;
 253        char eth_addr[8];
 254};
 255
 256struct cf_cmd {
 257        struct i596_cmd cmd;
 258        char i596_config[16];
 259};
 260
 261struct i596_rfd {
 262        unsigned short stat;
 263        unsigned short cmd;
 264        struct i596_rfd *b_next;        /* Address from i596 viewpoint */
 265        struct i596_rbd *rbd;
 266        unsigned short count;
 267        unsigned short size;
 268        struct i596_rfd *v_next;        /* Address from CPUs viewpoint */
 269        struct i596_rfd *v_prev;
 270};
 271
 272struct i596_rbd {
 273    unsigned short count;
 274    unsigned short zero1;
 275    struct i596_rbd *b_next;
 276    unsigned char *b_data;              /* Address from i596 viewpoint */
 277    unsigned short size;
 278    unsigned short zero2;
 279    struct sk_buff *skb;
 280    struct i596_rbd *v_next;
 281    struct i596_rbd *b_addr;            /* This rbd addr from i596 view */
 282    unsigned char *v_data;              /* Address from CPUs viewpoint */
 283};
 284
 285#define TX_RING_SIZE 64
 286#define RX_RING_SIZE 16
 287
 288struct i596_scb {
 289        unsigned short status;
 290        unsigned short command;
 291        struct i596_cmd *cmd;
 292        struct i596_rfd *rfd;
 293        unsigned long crc_err;
 294        unsigned long align_err;
 295        unsigned long resource_err;
 296        unsigned long over_err;
 297        unsigned long rcvdt_err;
 298        unsigned long short_err;
 299        unsigned short t_on;
 300        unsigned short t_off;
 301};
 302
 303struct i596_iscp {
 304        unsigned long stat;
 305        struct i596_scb *scb;
 306};
 307
 308struct i596_scp {
 309        unsigned long sysbus;
 310        unsigned long pad;
 311        struct i596_iscp *iscp;
 312};
 313
 314struct i596_private {
 315        volatile struct i596_scp scp;
 316        volatile struct i596_iscp iscp;
 317        volatile struct i596_scb scb;
 318        struct sa_cmd sa_cmd;
 319        struct cf_cmd cf_cmd;
 320        struct tdr_cmd tdr_cmd;
 321        struct mc_cmd mc_cmd;
 322        unsigned long stat;
 323        int last_restart __attribute__((aligned(4)));
 324        struct i596_rfd *rfd_head;
 325        struct i596_rbd *rbd_head;
 326        struct i596_cmd *cmd_tail;
 327        struct i596_cmd *cmd_head;
 328        int cmd_backlog;
 329        unsigned long last_cmd;
 330        struct net_device_stats stats;
 331        struct i596_rfd rfds[RX_RING_SIZE];
 332        struct i596_rbd rbds[RX_RING_SIZE];
 333        struct tx_cmd tx_cmds[TX_RING_SIZE];
 334        struct i596_tbd tbds[TX_RING_SIZE];
 335        int next_tx_cmd;
 336        spinlock_t lock;
 337};
 338
 339static char init_setup[] =
 340{
 341        0x8E,                   /* length, prefetch on */
 342        0xC8,                   /* fifo to 8, monitor off */
 343#ifdef CONFIG_VME
 344        0xc0,                   /* don't save bad frames */
 345#else
 346        0x80,                   /* don't save bad frames */
 347#endif
 348        0x2E,                   /* No source address insertion, 8 byte preamble */
 349        0x00,                   /* priority and backoff defaults */
 350        0x60,                   /* interframe spacing */
 351        0x00,                   /* slot time LSB */
 352        0xf2,                   /* slot time and retries */
 353        0x00,                   /* promiscuous mode */
 354        0x00,                   /* collision detect */
 355        0x40,                   /* minimum frame length */
 356        0xff,
 357        0x00,
 358        0x7f /*  *multi IA */ };
 359
 360static int i596_open(struct net_device *dev);
 361static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
 362static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs);
 363static int i596_close(struct net_device *dev);
 364static struct net_device_stats *i596_get_stats(struct net_device *dev);
 365static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
 366static void i596_tx_timeout (struct net_device *dev);
 367static void print_eth(unsigned char *buf, char *str);
 368static void set_multicast_list(struct net_device *dev);
 369
 370static int rx_ring_size = RX_RING_SIZE;
 371static int ticks_limit = 25;
 372static int max_cmd_backlog = TX_RING_SIZE-1;
 373
 374
 375static inline void CA(struct net_device *dev)
 376{
 377#ifdef ENABLE_MVME16x_NET
 378        if (MACH_IS_MVME16x) {
 379                ((struct i596_reg *) dev->base_addr)->ca = 1;
 380        }
 381#endif
 382#ifdef ENABLE_BVME6000_NET
 383        if (MACH_IS_BVME6000) {
 384                volatile u32 i;
 385
 386                i = *(volatile u32 *) (dev->base_addr);
 387        }
 388#endif
 389#ifdef ENABLE_APRICOT
 390        if (MACH_IS_APRICOT) {
 391                outw(0, (short) (dev->base_addr) + 4);
 392        }
 393#endif
 394}
 395
 396
 397static inline void MPU_PORT(struct net_device *dev, int c, volatile void *x)
 398{
 399#ifdef ENABLE_MVME16x_NET
 400        if (MACH_IS_MVME16x) {
 401                struct i596_reg *p = (struct i596_reg *) (dev->base_addr);
 402                p->porthi = ((c) | (u32) (x)) & 0xffff;
 403                p->portlo = ((c) | (u32) (x)) >> 16;
 404        }
 405#endif
 406#ifdef ENABLE_BVME6000_NET
 407        if (MACH_IS_BVME6000) {
 408                u32 v = (u32) (c) | (u32) (x);
 409                v = ((u32) (v) << 16) | ((u32) (v) >> 16);
 410                *(volatile u32 *) dev->base_addr = v;
 411                udelay(1);
 412                *(volatile u32 *) dev->base_addr = v;
 413        }
 414#endif
 415}
 416
 417
 418static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
 419{
 420        while (--delcnt && lp->iscp.stat)
 421                udelay(10);
 422        if (!delcnt) {
 423                printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
 424                     dev->name, str, lp->scb.status, lp->scb.command);
 425                return -1;
 426        }
 427        else
 428                return 0;
 429}
 430
 431
 432static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
 433{
 434        while (--delcnt && lp->scb.command)
 435                udelay(10);
 436        if (!delcnt) {
 437                printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
 438                     dev->name, str, lp->scb.status, lp->scb.command);
 439                return -1;
 440        }
 441        else
 442                return 0;
 443}
 444
 445
 446static inline int wait_cfg(struct net_device *dev, struct i596_cmd *cmd, int delcnt, char *str)
 447{
 448        volatile struct i596_cmd *c = cmd;
 449        
 450        while (--delcnt && c->command)
 451                udelay(10);
 452        if (!delcnt) {
 453                printk(KERN_ERR "%s: %s.\n", dev->name, str);
 454                return -1;
 455        }
 456        else
 457                return 0;
 458}
 459
 460 
 461static void i596_display_data(struct net_device *dev)
 462{
 463        struct i596_private *lp = (struct i596_private *) dev->priv;
 464        struct i596_cmd *cmd;
 465        struct i596_rfd *rfd;
 466        struct i596_rbd *rbd;
 467
 468        printk(KERN_ERR "lp and scp at %p, .sysbus = %08lx, .iscp = %p\n",
 469               &lp->scp, lp->scp.sysbus, lp->scp.iscp);
 470        printk(KERN_ERR "iscp at %p, iscp.stat = %08lx, .scb = %p\n",
 471               &lp->iscp, lp->iscp.stat, lp->iscp.scb);
 472        printk(KERN_ERR "scb at %p, scb.status = %04x, .command = %04x,"
 473                " .cmd = %p, .rfd = %p\n",
 474               &lp->scb, lp->scb.status, lp->scb.command,
 475                lp->scb.cmd, lp->scb.rfd);
 476        printk(KERN_ERR "   errors: crc %lx, align %lx, resource %lx,"
 477               " over %lx, rcvdt %lx, short %lx\n",
 478                lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,
 479                lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);
 480        cmd = lp->cmd_head;
 481        while (cmd != I596_NULL) {
 482                printk(KERN_ERR "cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n",
 483                  cmd, cmd->status, cmd->command, cmd->b_next);
 484                cmd = cmd->v_next;
 485        }
 486        rfd = lp->rfd_head;
 487        printk(KERN_ERR "rfd_head = %p\n", rfd);
 488        do {
 489                printk(KERN_ERR "   %p .stat %04x, .cmd %04x, b_next %p, rbd %p,"
 490                        " count %04x\n",
 491                        rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,
 492                        rfd->count);
 493                rfd = rfd->v_next;
 494        } while (rfd != lp->rfd_head);
 495        rbd = lp->rbd_head;
 496        printk(KERN_ERR "rbd_head = %p\n", rbd);
 497        do {
 498                printk(KERN_ERR "   %p .count %04x, b_next %p, b_data %p, size %04x\n",
 499                        rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
 500                rbd = rbd->v_next;
 501        } while (rbd != lp->rbd_head);
 502}
 503
 504
 505#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
 506static void i596_error(int irq, void *dev_id, struct pt_regs *regs)
 507{
 508        struct net_device *dev = dev_id;
 509#ifdef ENABLE_MVME16x_NET
 510        if (MACH_IS_MVME16x) {
 511                volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
 512
 513                pcc2[0x28] = 1;
 514                pcc2[0x2b] = 0x1d;
 515        }
 516#endif
 517#ifdef ENABLE_BVME6000_NET
 518        if (MACH_IS_BVME6000) {
 519                volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
 520
 521                *ethirq = 1;
 522                *ethirq = 3;
 523        }
 524#endif
 525        printk(KERN_ERR "%s: Error interrupt\n", dev->name);
 526        i596_display_data(dev);
 527}
 528#endif
 529
 530static inline void init_rx_bufs(struct net_device *dev)
 531{
 532        struct i596_private *lp = (struct i596_private *)dev->priv;
 533        int i;
 534        struct i596_rfd *rfd;
 535        struct i596_rbd *rbd;
 536
 537        /* First build the Receive Buffer Descriptor List */
 538
 539        for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
 540                struct sk_buff *skb = dev_alloc_skb(PKT_BUF_SZ);
 541
 542                if (skb == NULL)
 543                        panic("82596: alloc_skb() failed");
 544                skb->dev = dev;
 545                rbd->v_next = rbd+1;
 546                rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1));
 547                rbd->b_addr = WSWAPrbd(virt_to_bus(rbd));
 548                rbd->skb = skb;
 549                rbd->v_data = skb->tail;
 550                rbd->b_data = WSWAPchar(virt_to_bus(skb->tail));
 551                rbd->size = PKT_BUF_SZ;
 552#ifdef __mc68000__
 553                cache_clear(virt_to_phys(skb->tail), PKT_BUF_SZ);
 554#endif
 555        }
 556        lp->rbd_head = lp->rbds;
 557        rbd = lp->rbds + rx_ring_size - 1;
 558        rbd->v_next = lp->rbds;
 559        rbd->b_next = WSWAPrbd(virt_to_bus(lp->rbds));
 560
 561        /* Now build the Receive Frame Descriptor List */
 562
 563        for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) {
 564                rfd->rbd = I596_NULL;
 565                rfd->v_next = rfd+1;
 566                rfd->v_prev = rfd-1;
 567                rfd->b_next = WSWAPrfd(virt_to_bus(rfd+1));
 568                rfd->cmd = CMD_FLEX;
 569        }
 570        lp->rfd_head = lp->rfds;
 571        lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
 572        rfd = lp->rfds;
 573        rfd->rbd = lp->rbd_head;
 574        rfd->v_prev = lp->rfds + rx_ring_size - 1;
 575        rfd = lp->rfds + rx_ring_size - 1;
 576        rfd->v_next = lp->rfds;
 577        rfd->b_next = WSWAPrfd(virt_to_bus(lp->rfds));
 578        rfd->cmd = CMD_EOL|CMD_FLEX;
 579}
 580
 581static inline void remove_rx_bufs(struct net_device *dev)
 582{
 583        struct i596_private *lp = (struct i596_private *)dev->priv;
 584        struct i596_rbd *rbd;
 585        int i;
 586
 587        for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
 588                if (rbd->skb == NULL)
 589                        break;
 590                dev_kfree_skb(rbd->skb);
 591        }
 592}
 593
 594
 595static void rebuild_rx_bufs(struct net_device *dev)
 596{
 597        struct i596_private *lp = (struct i596_private *) dev->priv;
 598        int i;
 599
 600        /* Ensure rx frame/buffer descriptors are tidy */
 601
 602        for (i = 0; i < rx_ring_size; i++) {
 603                lp->rfds[i].rbd = I596_NULL;
 604                lp->rfds[i].cmd = CMD_FLEX;
 605        }
 606        lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX;
 607        lp->rfd_head = lp->rfds;
 608        lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
 609        lp->rbd_head = lp->rbds;
 610        lp->rfds[0].rbd = WSWAPrbd(virt_to_bus(lp->rbds));
 611}
 612
 613
 614static int init_i596_mem(struct net_device *dev)
 615{
 616        struct i596_private *lp = (struct i596_private *) dev->priv;
 617#if !defined(ENABLE_MVME16x_NET) && !defined(ENABLE_BVME6000_NET)
 618        short ioaddr = dev->base_addr;
 619#endif
 620        unsigned long flags;
 621
 622        MPU_PORT(dev, PORT_RESET, 0);
 623
 624        udelay(100);            /* Wait 100us - seems to help */
 625
 626#if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
 627#ifdef ENABLE_MVME16x_NET
 628        if (MACH_IS_MVME16x) {
 629                volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
 630
 631                /* Disable all ints for now */
 632                pcc2[0x28] = 1;
 633                pcc2[0x2a] = 0x48;
 634                /* Following disables snooping.  Snooping is not required
 635                 * as we make appropriate use of non-cached pages for
 636                 * shared data, and cache_push/cache_clear.
 637                 */
 638                pcc2[0x2b] = 0x08;
 639        }
 640#endif
 641#ifdef ENABLE_BVME6000_NET
 642        if (MACH_IS_BVME6000) {
 643                volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
 644
 645                *ethirq = 1;
 646        }
 647#endif
 648
 649        /* change the scp address */
 650
 651        MPU_PORT(dev, PORT_ALTSCP, (void *)virt_to_bus(&lp->scp));
 652
 653#elif defined(ENABLE_APRICOT)
 654
 655        {
 656                u32 scp = virt_to_bus(&lp->scp);
 657
 658                /* change the scp address */
 659                outw(0, ioaddr);
 660                outw(0, ioaddr);
 661                outb(4, ioaddr + 0xf);
 662                outw(scp | 2, ioaddr);
 663                outw(scp >> 16, ioaddr);
 664        }
 665#endif
 666
 667        lp->last_cmd = jiffies;
 668
 669#ifdef ENABLE_MVME16x_NET
 670        if (MACH_IS_MVME16x)
 671                lp->scp.sysbus = 0x00000054;
 672#endif
 673#ifdef ENABLE_BVME6000_NET
 674        if (MACH_IS_BVME6000)
 675                lp->scp.sysbus = 0x0000004c;
 676#endif
 677#ifdef ENABLE_APRICOT
 678        if (MACH_IS_APRICOT)
 679                lp->scp.sysbus = 0x00440000;
 680#endif
 681
 682        lp->scp.iscp = WSWAPiscp(virt_to_bus(&(lp->iscp)));
 683        lp->iscp.scb = WSWAPscb(virt_to_bus(&(lp->scb)));
 684        lp->iscp.stat = ISCP_BUSY;
 685        lp->cmd_backlog = 0;
 686
 687        lp->cmd_head = lp->scb.cmd = I596_NULL;
 688
 689#ifdef ENABLE_BVME6000_NET
 690        if (MACH_IS_BVME6000) {
 691                lp->scb.t_on  = 7 * 25;
 692                lp->scb.t_off = 1 * 25;
 693        }
 694#endif
 695
 696        DEB(DEB_INIT,printk(KERN_DEBUG "%s: starting i82596.\n", dev->name));
 697
 698#if defined(ENABLE_APRICOT)
 699        (void) inb(ioaddr + 0x10);
 700        outb(4, ioaddr + 0xf);
 701#endif
 702        CA(dev);
 703
 704        if (wait_istat(dev,lp,1000,"initialization timed out"))
 705                goto failed;
 706        DEB(DEB_INIT,printk(KERN_DEBUG "%s: i82596 initialization successful\n", dev->name));
 707
 708        /* Ensure rx frame/buffer descriptors are tidy */
 709        rebuild_rx_bufs(dev);
 710        lp->scb.command = 0;
 711
 712#ifdef ENABLE_MVME16x_NET
 713        if (MACH_IS_MVME16x) {
 714                volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
 715
 716                /* Enable ints, etc. now */
 717                pcc2[0x2a] = 0x55;      /* Edge sensitive */
 718                pcc2[0x2b] = 0x15;
 719        }
 720#endif
 721#ifdef ENABLE_BVME6000_NET
 722        if (MACH_IS_BVME6000) {
 723                volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
 724
 725                *ethirq = 3;
 726        }
 727#endif
 728
 729
 730        DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdConfigure\n", dev->name));
 731        memcpy(lp->cf_cmd.i596_config, init_setup, 14);
 732        lp->cf_cmd.cmd.command = CmdConfigure;
 733        i596_add_cmd(dev, &lp->cf_cmd.cmd);
 734
 735        DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdSASetup\n", dev->name));
 736        memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, 6);
 737        lp->sa_cmd.cmd.command = CmdSASetup;
 738        i596_add_cmd(dev, &lp->sa_cmd.cmd);
 739
 740        DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdTDR\n", dev->name));
 741        lp->tdr_cmd.cmd.command = CmdTDR;
 742        i596_add_cmd(dev, &lp->tdr_cmd.cmd);
 743
 744        spin_lock_irqsave (&lp->lock, flags);
 745
 746        if (wait_cmd(dev,lp,1000,"timed out waiting to issue RX_START")) {
 747                spin_unlock_irqrestore (&lp->lock, flags);
 748                goto failed;
 749        }
 750        DEB(DEB_INIT,printk(KERN_DEBUG "%s: Issuing RX_START\n", dev->name));
 751        lp->scb.command = RX_START;
 752        CA(dev);
 753
 754        spin_unlock_irqrestore (&lp->lock, flags);
 755
 756        if (wait_cmd(dev,lp,1000,"RX_START not processed"))
 757                goto failed;
 758        DEB(DEB_INIT,printk(KERN_DEBUG "%s: Receive unit started OK\n", dev->name));
 759        return 0;
 760
 761failed:
 762        printk(KERN_CRIT "%s: Failed to initialise 82596\n", dev->name);
 763        MPU_PORT(dev, PORT_RESET, 0);
 764        return -1;
 765}
 766
 767static inline int i596_rx(struct net_device *dev)
 768{
 769        struct i596_private *lp = (struct i596_private *)dev->priv;
 770        struct i596_rfd *rfd;
 771        struct i596_rbd *rbd;
 772        int frames = 0;
 773
 774        DEB(DEB_RXFRAME,printk(KERN_DEBUG "i596_rx(), rfd_head %p, rbd_head %p\n",
 775                        lp->rfd_head, lp->rbd_head));
 776
 777        rfd = lp->rfd_head;             /* Ref next frame to check */
 778
 779        while ((rfd->stat) & STAT_C) {  /* Loop while complete frames */
 780                if (rfd->rbd == I596_NULL)
 781                        rbd = I596_NULL;
 782                else if (rfd->rbd == lp->rbd_head->b_addr)
 783                        rbd = lp->rbd_head;
 784                else {
 785                        printk(KERN_CRIT "%s: rbd chain broken!\n", dev->name);
 786                        /* XXX Now what? */
 787                        rbd = I596_NULL;
 788                }
 789                DEB(DEB_RXFRAME, printk(KERN_DEBUG "  rfd %p, rfd.rbd %p, rfd.stat %04x\n",
 790                        rfd, rfd->rbd, rfd->stat));
 791                
 792                if (rbd != I596_NULL && ((rfd->stat) & STAT_OK)) {
 793                        /* a good frame */
 794                        int pkt_len = rbd->count & 0x3fff;
 795                        struct sk_buff *skb = rbd->skb;
 796                        int rx_in_place = 0;
 797
 798                        DEB(DEB_RXADDR,print_eth(rbd->v_data, "received"));
 799                        frames++;
 800
 801                        /* Check if the packet is long enough to just accept
 802                         * without copying to a properly sized skbuff.
 803                         */
 804
 805                        if (pkt_len > rx_copybreak) {
 806                                struct sk_buff *newskb;
 807
 808                                /* Get fresh skbuff to replace filled one. */
 809                                newskb = dev_alloc_skb(PKT_BUF_SZ);
 810                                if (newskb == NULL) {
 811                                        skb = NULL;     /* drop pkt */
 812                                        goto memory_squeeze;
 813                                }
 814                                /* Pass up the skb already on the Rx ring. */
 815                                skb_put(skb, pkt_len);
 816                                rx_in_place = 1;
 817                                rbd->skb = newskb;
 818                                newskb->dev = dev;
 819                                rbd->v_data = newskb->tail;
 820                                rbd->b_data = WSWAPchar(virt_to_bus(newskb->tail));
 821#ifdef __mc68000__
 822                                cache_clear(virt_to_phys(newskb->tail), PKT_BUF_SZ);
 823#endif
 824                        }
 825                        else
 826                                skb = dev_alloc_skb(pkt_len + 2);
 827memory_squeeze:
 828                        if (skb == NULL) {
 829                                /* XXX tulip.c can defer packets here!! */
 830                                printk(KERN_WARNING "%s: i596_rx Memory squeeze, dropping packet.\n", dev->name);
 831                                lp->stats.rx_dropped++;
 832                        }
 833                        else {
 834                                skb->dev = dev;
 835                                if (!rx_in_place) {
 836                                        /* 16 byte align the data fields */
 837                                        skb_reserve(skb, 2);
 838                                        memcpy(skb_put(skb,pkt_len), rbd->v_data, pkt_len);
 839                                }
 840                                skb->protocol=eth_type_trans(skb,dev);
 841                                skb->len = pkt_len;
 842#ifdef __mc68000__
 843                                cache_clear(virt_to_phys(rbd->skb->tail),
 844                                                pkt_len);
 845#endif
 846                                netif_rx(skb);
 847                                dev->last_rx = jiffies;
 848                                lp->stats.rx_packets++;
 849                                lp->stats.rx_bytes+=pkt_len;
 850                        }
 851                }
 852                else {
 853                        DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: Error, rfd.stat = 0x%04x\n",
 854                                        dev->name, rfd->stat));
 855                        lp->stats.rx_errors++;
 856                        if ((rfd->stat) & 0x0001)
 857                                lp->stats.collisions++;
 858                        if ((rfd->stat) & 0x0080)
 859                                lp->stats.rx_length_errors++;
 860                        if ((rfd->stat) & 0x0100)
 861                                lp->stats.rx_over_errors++;
 862                        if ((rfd->stat) & 0x0200)
 863                                lp->stats.rx_fifo_errors++;
 864                        if ((rfd->stat) & 0x0400)
 865                                lp->stats.rx_frame_errors++;
 866                        if ((rfd->stat) & 0x0800)
 867                                lp->stats.rx_crc_errors++;
 868                        if ((rfd->stat) & 0x1000)
 869                                lp->stats.rx_length_errors++;
 870                }
 871
 872                /* Clear the buffer descriptor count and EOF + F flags */
 873
 874                if (rbd != I596_NULL && (rbd->count & 0x4000)) {
 875                        rbd->count = 0;
 876                        lp->rbd_head = rbd->v_next;
 877                }
 878
 879                /* Tidy the frame descriptor, marking it as end of list */
 880
 881                rfd->rbd = I596_NULL;
 882                rfd->stat = 0;
 883                rfd->cmd = CMD_EOL|CMD_FLEX;
 884                rfd->count = 0;
 885
 886                /* Remove end-of-list from old end descriptor */
 887
 888                rfd->v_prev->cmd = CMD_FLEX;
 889
 890                /* Update record of next frame descriptor to process */
 891
 892                lp->scb.rfd = rfd->b_next;
 893                lp->rfd_head = rfd->v_next;
 894                rfd = lp->rfd_head;
 895        }
 896
 897        DEB(DEB_RXFRAME,printk(KERN_DEBUG "frames %d\n", frames));
 898
 899        return 0;
 900}
 901
 902
 903static inline void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
 904{
 905        struct i596_cmd *ptr;
 906
 907        while (lp->cmd_head != I596_NULL) {
 908                ptr = lp->cmd_head;
 909                lp->cmd_head = ptr->v_next;
 910                lp->cmd_backlog--;
 911
 912                switch ((ptr->command) & 0x7) {
 913                case CmdTx:
 914                        {
 915                                struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
 916                                struct sk_buff *skb = tx_cmd->skb;
 917
 918                                dev_kfree_skb(skb);
 919
 920                                lp->stats.tx_errors++;
 921                                lp->stats.tx_aborted_errors++;
 922
 923                                ptr->v_next = ptr->b_next = I596_NULL;
 924                                tx_cmd->cmd.command = 0;  /* Mark as free */
 925                                break;
 926                        }
 927                default:
 928                        ptr->v_next = ptr->b_next = I596_NULL;
 929                }
 930        }
 931
 932        wait_cmd(dev,lp,100,"i596_cleanup_cmd timed out");
 933        lp->scb.cmd = I596_NULL;
 934}
 935
 936static inline void i596_reset(struct net_device *dev, struct i596_private *lp, int ioaddr)
 937{
 938        unsigned long flags;
 939
 940        DEB(DEB_RESET,printk(KERN_DEBUG "i596_reset\n"));
 941
 942        spin_lock_irqsave (&lp->lock, flags);
 943
 944        wait_cmd(dev,lp,100,"i596_reset timed out");
 945
 946        netif_stop_queue(dev);
 947
 948        lp->scb.command = CUC_ABORT | RX_ABORT;
 949        CA(dev);
 950
 951        /* wait for shutdown */
 952        wait_cmd(dev,lp,1000,"i596_reset 2 timed out");
 953        spin_unlock_irqrestore (&lp->lock, flags);
 954
 955        i596_cleanup_cmd(dev,lp);
 956        i596_rx(dev);
 957
 958        netif_start_queue(dev);
 959        init_i596_mem(dev);
 960}
 961
 962static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
 963{
 964        struct i596_private *lp = (struct i596_private *) dev->priv;
 965        int ioaddr = dev->base_addr;
 966        unsigned long flags;
 967
 968        DEB(DEB_ADDCMD,printk(KERN_DEBUG "i596_add_cmd\n"));
 969
 970        cmd->status = 0;
 971        cmd->command |= (CMD_EOL | CMD_INTR);
 972        cmd->v_next = cmd->b_next = I596_NULL;
 973
 974        spin_lock_irqsave (&lp->lock, flags);
 975
 976        if (lp->cmd_head != I596_NULL) {
 977                lp->cmd_tail->v_next = cmd;
 978                lp->cmd_tail->b_next = WSWAPcmd(virt_to_bus(&cmd->status));
 979        } else {
 980                lp->cmd_head = cmd;
 981                wait_cmd(dev,lp,100,"i596_add_cmd timed out");
 982                lp->scb.cmd = WSWAPcmd(virt_to_bus(&cmd->status));
 983                lp->scb.command = CUC_START;
 984                CA(dev);
 985        }
 986        lp->cmd_tail = cmd;
 987        lp->cmd_backlog++;
 988
 989        spin_unlock_irqrestore (&lp->lock, flags);
 990
 991        if (lp->cmd_backlog > max_cmd_backlog) {
 992                unsigned long tickssofar = jiffies - lp->last_cmd;
 993
 994                if (tickssofar < ticks_limit)
 995                        return;
 996
 997                printk(KERN_NOTICE "%s: command unit timed out, status resetting.\n", dev->name);
 998
 999                i596_reset(dev, lp, ioaddr);
1000        }
1001}
1002
1003static int i596_open(struct net_device *dev)
1004{
1005        int res = 0;
1006
1007        DEB(DEB_OPEN,printk(KERN_DEBUG "%s: i596_open() irq %d.\n", dev->name, dev->irq));
1008
1009        if (request_irq(dev->irq, &i596_interrupt, 0, "i82596", dev)) {
1010                printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq);
1011                return -EAGAIN;
1012        }
1013#ifdef ENABLE_MVME16x_NET
1014        if (MACH_IS_MVME16x) {
1015                if (request_irq(0x56, &i596_error, 0, "i82596_error", dev))
1016                        return -EAGAIN;
1017        }
1018#endif
1019        init_rx_bufs(dev);
1020
1021        netif_start_queue(dev);
1022
1023        MOD_INC_USE_COUNT;
1024
1025        /* Initialize the 82596 memory */
1026        if (init_i596_mem(dev)) {
1027                res = -EAGAIN;
1028                free_irq(dev->irq, dev);
1029        }
1030
1031        return res;
1032}
1033
1034static void i596_tx_timeout (struct net_device *dev)
1035{
1036        struct i596_private *lp = (struct i596_private *) dev->priv;
1037        int ioaddr = dev->base_addr;
1038
1039        /* Transmitter timeout, serious problems. */
1040        DEB(DEB_ERRORS,printk(KERN_ERR "%s: transmit timed out, status resetting.\n",
1041                        dev->name));
1042
1043        lp->stats.tx_errors++;
1044
1045        /* Try to restart the adaptor */
1046        if (lp->last_restart == lp->stats.tx_packets) {
1047                DEB(DEB_ERRORS,printk(KERN_ERR "Resetting board.\n"));
1048                /* Shutdown and restart */
1049                i596_reset (dev, lp, ioaddr);
1050        } else {
1051                /* Issue a channel attention signal */
1052                DEB(DEB_ERRORS,printk(KERN_ERR "Kicking board.\n"));
1053                lp->scb.command = CUC_START | RX_START;
1054                CA (dev);
1055                lp->last_restart = lp->stats.tx_packets;
1056        }
1057
1058        dev->trans_start = jiffies;
1059        netif_wake_queue (dev);
1060}
1061
1062
1063static int i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
1064{
1065        struct i596_private *lp = (struct i596_private *) dev->priv;
1066        struct tx_cmd *tx_cmd;
1067        struct i596_tbd *tbd;
1068        short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1069        dev->trans_start = jiffies;
1070
1071        DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%x) called\n", dev->name,
1072                                skb->len, (unsigned int)skb->data));
1073
1074        netif_stop_queue(dev);
1075
1076        tx_cmd = lp->tx_cmds + lp->next_tx_cmd;
1077        tbd = lp->tbds + lp->next_tx_cmd;
1078
1079        if (tx_cmd->cmd.command) {
1080                printk(KERN_NOTICE "%s: xmit ring full, dropping packet.\n",
1081                                dev->name);
1082                lp->stats.tx_dropped++;
1083
1084                dev_kfree_skb(skb);
1085        } else {
1086                if (++lp->next_tx_cmd == TX_RING_SIZE)
1087                        lp->next_tx_cmd = 0;
1088                tx_cmd->tbd = WSWAPtbd(virt_to_bus(tbd));
1089                tbd->next = I596_NULL;
1090
1091                tx_cmd->cmd.command = CMD_FLEX | CmdTx;
1092                tx_cmd->skb = skb;
1093
1094                tx_cmd->pad = 0;
1095                tx_cmd->size = 0;
1096                tbd->pad = 0;
1097                tbd->size = EOF | length;
1098
1099                tbd->data = WSWAPchar(virt_to_bus(skb->data));
1100
1101#ifdef __mc68000__
1102                cache_push(virt_to_phys(skb->data), length);
1103#endif
1104                DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));
1105                i596_add_cmd(dev, &tx_cmd->cmd);
1106
1107                lp->stats.tx_packets++;
1108                lp->stats.tx_bytes += length;
1109        }
1110
1111        netif_start_queue(dev);
1112
1113        return 0;
1114}
1115
1116static void print_eth(unsigned char *add, char *str)
1117{
1118        int i;
1119
1120        printk(KERN_DEBUG "i596 0x%p, ", add);
1121        for (i = 0; i < 6; i++)
1122                printk(" %02X", add[i + 6]);
1123        printk(" -->");
1124        for (i = 0; i < 6; i++)
1125                printk(" %02X", add[i]);
1126        printk(" %02X%02X, %s\n", add[12], add[13], str);
1127}
1128
1129int __init i82596_probe(struct net_device *dev)
1130{
1131        int i;
1132        struct i596_private *lp;
1133        char eth_addr[8];
1134        static int probed;
1135
1136        if (probed)
1137                return -ENODEV;
1138        probed++;
1139#ifdef ENABLE_MVME16x_NET
1140        if (MACH_IS_MVME16x) {
1141                if (mvme16x_config & MVME16x_CONFIG_NO_ETHERNET) {
1142                        printk(KERN_NOTICE "Ethernet probe disabled - chip not present\n");
1143                        return -ENODEV;
1144                }
1145                memcpy(eth_addr, (void *) 0xfffc1f2c, 6);       /* YUCK! Get addr from NOVRAM */
1146                dev->base_addr = MVME_I596_BASE;
1147                dev->irq = (unsigned) MVME16x_IRQ_I596;
1148        }
1149#endif
1150#ifdef ENABLE_BVME6000_NET
1151        if (MACH_IS_BVME6000) {
1152                volatile unsigned char *rtc = (unsigned char *) BVME_RTC_BASE;
1153                unsigned char msr = rtc[3];
1154                int i;
1155
1156                rtc[3] |= 0x80;
1157                for (i = 0; i < 6; i++)
1158                        eth_addr[i] = rtc[i * 4 + 7];   /* Stored in RTC RAM at offset 1 */
1159                rtc[3] = msr;
1160                dev->base_addr = BVME_I596_BASE;
1161                dev->irq = (unsigned) BVME_IRQ_I596;
1162        }
1163#endif
1164#ifdef ENABLE_APRICOT
1165        {
1166                int checksum = 0;
1167                int ioaddr = 0x300;
1168
1169                /* this is easy the ethernet interface can only be at 0x300 */
1170                /* first check nothing is already registered here */
1171
1172                if (!request_region(ioaddr, I596_TOTAL_SIZE, dev->name)) {
1173                        printk(KERN_ERR "82596: IO address 0x%04x in use\n", ioaddr);
1174                        return -EBUSY;
1175                }
1176
1177                for (i = 0; i < 8; i++) {
1178                        eth_addr[i] = inb(ioaddr + 8 + i);
1179                        checksum += eth_addr[i];
1180                }
1181
1182                /* checksum is a multiple of 0x100, got this wrong first time
1183                   some machines have 0x100, some 0x200. The DOS driver doesn't
1184                   even bother with the checksum.
1185                   Some other boards trip the checksum.. but then appear as
1186                   ether address 0. Trap these - AC */
1187
1188                if ((checksum % 0x100) || 
1189                    (memcmp(eth_addr, "\x00\x00\x49", 3) != 0)) {
1190                        release_region(ioaddr, I596_TOTAL_SIZE);
1191                        return -ENODEV;
1192                }
1193
1194                dev->base_addr = ioaddr;
1195                dev->irq = 10;
1196        }
1197#endif
1198        dev->mem_start = (int)__get_free_pages(GFP_ATOMIC, 0);
1199        if (!dev->mem_start) {
1200#ifdef ENABLE_APRICOT
1201                release_region(dev->base_addr, I596_TOTAL_SIZE);
1202#endif
1203                return -ENOMEM;
1204        }
1205
1206        ether_setup(dev);
1207        DEB(DEB_PROBE,printk(KERN_INFO "%s: 82596 at %#3lx,", dev->name, dev->base_addr));
1208
1209        for (i = 0; i < 6; i++)
1210                DEB(DEB_PROBE,printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]));
1211
1212        DEB(DEB_PROBE,printk(" IRQ %d.\n", dev->irq));
1213
1214        DEB(DEB_PROBE,printk(KERN_INFO "%s", version));
1215
1216        /* The 82596-specific entries in the device structure. */
1217        dev->open = i596_open;
1218        dev->stop = i596_close;
1219        dev->hard_start_xmit = i596_start_xmit;
1220        dev->get_stats = i596_get_stats;
1221        dev->set_multicast_list = set_multicast_list;
1222        dev->tx_timeout = i596_tx_timeout;
1223        dev->watchdog_timeo = TX_TIMEOUT;
1224
1225        dev->priv = (void *)(dev->mem_start);
1226
1227        lp = (struct i596_private *) dev->priv;
1228        DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%d bytes), lp->scb at 0x%08lx\n",
1229                        dev->name, (unsigned long)lp,
1230                        sizeof(struct i596_private), (unsigned long)&lp->scb));
1231        memset((void *) lp, 0, sizeof(struct i596_private));
1232
1233#ifdef __mc68000__
1234        cache_push(virt_to_phys((void *)(dev->mem_start)), 4096);
1235        cache_clear(virt_to_phys((void *)(dev->mem_start)), 4096);
1236        kernel_set_cachemode((void *)(dev->mem_start), 4096, IOMAP_NOCACHE_SER);
1237#endif
1238        lp->scb.command = 0;
1239        lp->scb.cmd = I596_NULL;
1240        lp->scb.rfd = I596_NULL;
1241        lp->lock = SPIN_LOCK_UNLOCKED;
1242
1243        return 0;
1244}
1245
1246static void i596_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1247{
1248        struct net_device *dev = dev_id;
1249        struct i596_private *lp;
1250        short ioaddr;
1251        unsigned short status, ack_cmd = 0;
1252
1253#ifdef ENABLE_BVME6000_NET
1254        if (MACH_IS_BVME6000) {
1255                if (*(char *) BVME_LOCAL_IRQ_STAT & BVME_ETHERR) {
1256                        i596_error(irq, dev_id, regs);
1257                        return;
1258                }
1259        }
1260#endif
1261        if (dev == NULL) {
1262                printk(KERN_ERR "i596_interrupt(): irq %d for unknown device.\n", irq);
1263                return;
1264        }
1265
1266        ioaddr = dev->base_addr;
1267        lp = (struct i596_private *) dev->priv;
1268
1269        spin_lock (&lp->lock);
1270
1271        wait_cmd(dev,lp,100,"i596 interrupt, timeout");
1272        status = lp->scb.status;
1273
1274        DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt, IRQ %d, status %4.4x.\n",
1275                        dev->name, irq, status));
1276
1277        ack_cmd = status & 0xf000;
1278
1279        if ((status & 0x8000) || (status & 0x2000)) {
1280                struct i596_cmd *ptr;
1281
1282                if ((status & 0x8000))
1283                        DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt completed command.\n", dev->name));
1284                if ((status & 0x2000))
1285                        DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700));
1286
1287                while ((lp->cmd_head != I596_NULL) && (lp->cmd_head->status & STAT_C)) {
1288                        ptr = lp->cmd_head;
1289
1290                        DEB(DEB_STATUS,printk(KERN_DEBUG "cmd_head->status = %04x, ->command = %04x\n",
1291                                       lp->cmd_head->status, lp->cmd_head->command));
1292                        lp->cmd_head = ptr->v_next;
1293                        lp->cmd_backlog--;
1294
1295                        switch ((ptr->command) & 0x7) {
1296                        case CmdTx:
1297                            {
1298                                struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
1299                                struct sk_buff *skb = tx_cmd->skb;
1300
1301                                if ((ptr->status) & STAT_OK) {
1302                                        DEB(DEB_TXADDR,print_eth(skb->data, "tx-done"));
1303                                } else {
1304                                        lp->stats.tx_errors++;
1305                                        if ((ptr->status) & 0x0020)
1306                                                lp->stats.collisions++;
1307                                        if (!((ptr->status) & 0x0040))
1308                                                lp->stats.tx_heartbeat_errors++;
1309                                        if ((ptr->status) & 0x0400)
1310                                                lp->stats.tx_carrier_errors++;
1311                                        if ((ptr->status) & 0x0800)
1312                                                lp->stats.collisions++;
1313                                        if ((ptr->status) & 0x1000)
1314                                                lp->stats.tx_aborted_errors++;
1315                                }
1316
1317                                dev_kfree_skb_irq(skb);
1318
1319                                tx_cmd->cmd.command = 0; /* Mark free */
1320                                break;
1321                            }
1322                        case CmdTDR:
1323                            {
1324                                unsigned short status = ((struct tdr_cmd *)ptr)->status;
1325
1326                                if (status & 0x8000) {
1327                                        DEB(DEB_TDR,printk(KERN_INFO "%s: link ok.\n", dev->name));
1328                                } else {
1329                                        if (status & 0x4000)
1330                                                printk(KERN_ERR "%s: Transceiver problem.\n", dev->name);
1331                                        if (status & 0x2000)
1332                                                printk(KERN_ERR "%s: Termination problem.\n", dev->name);
1333                                        if (status & 0x1000)
1334                                                printk(KERN_ERR "%s: Short circuit.\n", dev->name);
1335
1336                                        DEB(DEB_TDR,printk(KERN_INFO "%s: Time %d.\n", dev->name, status & 0x07ff));
1337                                }
1338                                break;
1339                            }
1340                        case CmdConfigure:
1341                        case CmdMulticastList:
1342                                /* Zap command so set_multicast_list() knows it is free */
1343                                ptr->command = 0;
1344                                break;
1345                        }
1346                        ptr->v_next = ptr->b_next = I596_NULL;
1347                        lp->last_cmd = jiffies;
1348                }
1349
1350                ptr = lp->cmd_head;
1351                while ((ptr != I596_NULL) && (ptr != lp->cmd_tail)) {
1352                        ptr->command &= 0x1fff;
1353                        ptr = ptr->v_next;
1354                }
1355
1356                if ((lp->cmd_head != I596_NULL))
1357                        ack_cmd |= CUC_START;
1358                lp->scb.cmd = WSWAPcmd(virt_to_bus(&lp->cmd_head->status));
1359        }
1360        if ((status & 0x1000) || (status & 0x4000)) {
1361                if ((status & 0x4000))
1362                        DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt received a frame.\n", dev->name));
1363                i596_rx(dev);
1364                /* Only RX_START if stopped - RGH 07-07-96 */
1365                if (status & 0x1000) {
1366                        if (netif_running(dev)) {
1367                                DEB(DEB_ERRORS,printk(KERN_ERR "%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status));
1368                                ack_cmd |= RX_START;
1369                                lp->stats.rx_errors++;
1370                                lp->stats.rx_fifo_errors++;
1371                                rebuild_rx_bufs(dev);
1372                        }
1373                }
1374        }
1375        wait_cmd(dev,lp,100,"i596 interrupt, timeout");
1376        lp->scb.command = ack_cmd;
1377
1378#ifdef ENABLE_MVME16x_NET
1379        if (MACH_IS_MVME16x) {
1380                /* Ack the interrupt */
1381
1382                volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
1383
1384                pcc2[0x2a] |= 0x08;
1385        }
1386#endif
1387#ifdef ENABLE_BVME6000_NET
1388        if (MACH_IS_BVME6000) {
1389                volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
1390
1391                *ethirq = 1;
1392                *ethirq = 3;
1393        }
1394#endif
1395#ifdef ENABLE_APRICOT
1396        (void) inb(ioaddr + 0x10);
1397        outb(4, ioaddr + 0xf);
1398#endif
1399        CA(dev);
1400
1401        DEB(DEB_INTS,printk(KERN_DEBUG "%s: exiting interrupt.\n", dev->name));
1402
1403        spin_unlock (&lp->lock);
1404        return;
1405}
1406
1407static int i596_close(struct net_device *dev)
1408{
1409        struct i596_private *lp = (struct i596_private *) dev->priv;
1410        unsigned long flags;
1411
1412        netif_stop_queue(dev);
1413
1414        DEB(DEB_INIT,printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x.\n",
1415                       dev->name, lp->scb.status));
1416
1417        save_flags(flags);
1418        cli();
1419
1420        wait_cmd(dev,lp,100,"close1 timed out");
1421        lp->scb.command = CUC_ABORT | RX_ABORT;
1422        CA(dev);
1423
1424        wait_cmd(dev,lp,100,"close2 timed out");
1425        restore_flags(flags);
1426        DEB(DEB_STRUCT,i596_display_data(dev));
1427        i596_cleanup_cmd(dev,lp);
1428
1429#ifdef ENABLE_MVME16x_NET
1430        if (MACH_IS_MVME16x) {
1431                volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
1432
1433                /* Disable all ints */
1434                pcc2[0x28] = 1;
1435                pcc2[0x2a] = 0x40;
1436                pcc2[0x2b] = 0x40;      /* Set snooping bits now! */
1437        }
1438#endif
1439#ifdef ENABLE_BVME6000_NET
1440        if (MACH_IS_BVME6000) {
1441                volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
1442
1443                *ethirq = 1;
1444        }
1445#endif
1446
1447        free_irq(dev->irq, dev);
1448        remove_rx_bufs(dev);
1449        MOD_DEC_USE_COUNT;
1450
1451        return 0;
1452}
1453
1454static struct net_device_stats *
1455 i596_get_stats(struct net_device *dev)
1456{
1457        struct i596_private *lp = (struct i596_private *) dev->priv;
1458
1459        return &lp->stats;
1460}
1461
1462/*
1463 *    Set or clear the multicast filter for this adaptor.
1464 */
1465
1466static void set_multicast_list(struct net_device *dev)
1467{
1468        struct i596_private *lp = (struct i596_private *) dev->priv;
1469        int config = 0, cnt;
1470
1471        DEB(DEB_MULTI,printk(KERN_DEBUG "%s: set multicast list, %d entries, promisc %s, allmulti %s\n",
1472                dev->name, dev->mc_count,
1473                dev->flags & IFF_PROMISC  ? "ON" : "OFF",
1474                dev->flags & IFF_ALLMULTI ? "ON" : "OFF"));
1475
1476        if (wait_cfg(dev, &lp->cf_cmd.cmd, 1000, "config change request timed out"))
1477                return;
1478
1479        if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) {
1480                lp->cf_cmd.i596_config[8] |= 0x01;
1481                config = 1;
1482        }
1483        if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) {
1484                lp->cf_cmd.i596_config[8] &= ~0x01;
1485                config = 1;
1486        }
1487        if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) {
1488                lp->cf_cmd.i596_config[11] &= ~0x20;
1489                config = 1;
1490        }
1491        if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) {
1492                lp->cf_cmd.i596_config[11] |= 0x20;
1493                config = 1;
1494        }
1495        if (config) {
1496                lp->cf_cmd.cmd.command = CmdConfigure;
1497                i596_add_cmd(dev, &lp->cf_cmd.cmd);
1498        }
1499
1500        cnt = dev->mc_count;
1501        if (cnt > MAX_MC_CNT)
1502        {
1503                cnt = MAX_MC_CNT;
1504                printk(KERN_ERR "%s: Only %d multicast addresses supported",
1505                        dev->name, cnt);
1506        }
1507        
1508        if (dev->mc_count > 0) {
1509                struct dev_mc_list *dmi;
1510                unsigned char *cp;
1511                struct mc_cmd *cmd;
1512
1513                if (wait_cfg(dev, &lp->mc_cmd.cmd, 1000, "multicast list change request timed out"))
1514                        return;
1515                cmd = &lp->mc_cmd;
1516                cmd->cmd.command = CmdMulticastList;
1517                cmd->mc_cnt = dev->mc_count * 6;
1518                cp = cmd->mc_addrs;
1519                for (dmi = dev->mc_list; cnt && dmi != NULL; dmi = dmi->next, cnt--, cp += 6) {
1520                        memcpy(cp, dmi->dmi_addr, 6);
1521                        if (i596_debug > 1)
1522                                DEB(DEB_MULTI,printk(KERN_INFO "%s: Adding address %02x:%02x:%02x:%02x:%02x:%02x\n",
1523                                                dev->name, cp[0],cp[1],cp[2],cp[3],cp[4],cp[5]));
1524                }
1525                i596_add_cmd(dev, &cmd->cmd);
1526        }
1527}
1528
1529#ifdef MODULE
1530static struct net_device dev_82596 = { init: i82596_probe };
1531
1532#ifdef ENABLE_APRICOT
1533static int io = 0x300;
1534static int irq = 10;
1535MODULE_PARM(irq, "i");
1536MODULE_PARM_DESC(irq, "Apricot IRQ number");
1537#endif
1538
1539MODULE_PARM(debug, "i");
1540MODULE_PARM_DESC(debug, "i82596 debug mask");
1541static int debug = -1;
1542
1543int init_module(void)
1544{
1545#ifdef ENABLE_APRICOT
1546        dev_82596.base_addr = io;
1547        dev_82596.irq = irq;
1548#endif
1549        if (debug >= 0)
1550                i596_debug = debug;
1551        if (register_netdev(&dev_82596) != 0)
1552                return -EIO;
1553        return 0;
1554}
1555
1556void cleanup_module(void)
1557{
1558        unregister_netdev(&dev_82596);
1559#ifdef __mc68000__
1560        /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING,
1561         * XXX which may be invalid (CONFIG_060_WRITETHROUGH)
1562         */
1563
1564        kernel_set_cachemode((void *)(dev_82596.mem_start), 4096,
1565                        IOMAP_FULL_CACHING);
1566#endif
1567        free_page ((u32)(dev_82596.mem_start));
1568        dev_82596.priv = NULL;
1569#ifdef ENABLE_APRICOT
1570        /* If we don't do this, we can't re-insmod it later. */
1571        release_region(dev_82596.base_addr, I596_TOTAL_SIZE);
1572#endif
1573}
1574
1575#endif                          /* MODULE */
1576
1577/*
1578 * Local variables:
1579 *  compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c 82596.c"
1580 * End:
1581 */
1582
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.